Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace var with const/let in repo #119

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module.exports = repo

repo.usage = 'npm repo [<pkg>]'

var openUrl = require('./utils/open-url')
var hostedGitInfo = require('hosted-git-info')
var url_ = require('url')
var fetchPackageMetadata = require('./fetch-package-metadata.js')
const openUrl = require('./utils/open-url')
const hostedGitInfo = require('hosted-git-info')
const url_ = require('url')
const fetchPackageMetadata = require('./fetch-package-metadata.js')

repo.completion = function (opts, cb) {
// FIXME: there used to be registry completion here, but it stopped making
Expand All @@ -14,20 +14,20 @@ repo.completion = function (opts, cb) {
}

function repo (args, cb) {
var n = args.length ? args[0] : '.'
const n = args.length ? args[0] : '.'
fetchPackageMetadata(n, '.', {fullMetadata: true}, function (er, d) {
if (er) return cb(er)
getUrlAndOpen(d, cb)
})
}

function getUrlAndOpen (d, cb) {
var r = d.repository
const r = d.repository
if (!r) return cb(new Error('no repository'))
// XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
// from https://github.com/npm/npm-www/issues/418
var info = hostedGitInfo.fromUrl(r.url)
var url = info ? info.browse() : unknownHostedUrl(r.url)
const info = hostedGitInfo.fromUrl(r.url)
const url = info ? info.browse() : unknownHostedUrl(r.url)

if (!url) return cb(new Error('no repository: could not get url'))

Expand All @@ -36,12 +36,12 @@ function getUrlAndOpen (d, cb) {

function unknownHostedUrl (url) {
try {
var idx = url.indexOf('@')
const idx = url.indexOf('@')
if (idx !== -1) {
url = url.slice(idx + 1).replace(/:([^\d]+)/, '/$1')
}
url = url_.parse(url)
var protocol = url.protocol === 'https:'
const protocol = url.protocol === 'https:'
? 'https:'
: 'http:'
return protocol + '//' + (url.host || '') +
Expand Down