Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
standardize
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Mar 23, 2018
1 parent c8f8564 commit 311e555
Show file tree
Hide file tree
Showing 137 changed files with 898 additions and 913 deletions.
2 changes: 1 addition & 1 deletion bin/npm-cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode
// windows: running "npm blah" in this folder will invoke WSH, not node.
/*global WScript*/
/* global WScript */
if (typeof WScript !== 'undefined') {
WScript.echo(
'npm does not work when run\n' +
Expand Down
3 changes: 2 additions & 1 deletion lib/access.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint-disable standard/no-callback-literal */

var resolve = require('path').resolve

Expand All @@ -21,7 +22,7 @@ access.usage =
'npm access edit [<package>]'

access.subcommands = ['public', 'restricted', 'grant', 'revoke',
'ls-packages', 'ls-collaborators', 'edit']
'ls-packages', 'ls-collaborators', 'edit']

access.completion = function (opts, cb) {
var argv = opts.conf.argv.remain
Expand Down
2 changes: 1 addition & 1 deletion lib/adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ adduser.usage = usage(
function adduser (args, cb) {
if (!crypto) {
return cb(new Error(
'You must compile node with ssl support to use the adduser feature'
'You must compile node with ssl support to use the adduser feature'
))
}

Expand Down
60 changes: 30 additions & 30 deletions lib/auth/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,38 @@ module.exports.login = (creds, registry, scope, cb) => {

function login (conf) {
return profile.login(openerPromise, loginPrompter, conf)
.catch((err) => {
if (err.code === 'EOTP') throw err
const u = conf.creds.username
const p = conf.creds.password
const e = conf.creds.email
if (!(u && p && e)) throw err
return profile.adduserCouch(u, e, p, conf)
})
.catch((err) => {
if (err.code !== 'EOTP') throw err
return read.otp('Authenticator provided OTP:').then((otp) => {
conf.auth.otp = otp
.catch((err) => {
if (err.code === 'EOTP') throw err
const u = conf.creds.username
const p = conf.creds.password
return profile.loginCouch(u, p, conf)
const e = conf.creds.email
if (!(u && p && e)) throw err
return profile.adduserCouch(u, e, p, conf)
})
}).then((result) => {
const newCreds = {}
if (result && result.token) {
newCreds.token = result.token
} else {
newCreds.username = conf.creds.username
newCreds.password = conf.creds.password
newCreds.email = conf.creds.email
newCreds.alwaysAuth = npm.config.get('always-auth')
}
.catch((err) => {
if (err.code !== 'EOTP') throw err
return read.otp('Authenticator provided OTP:').then((otp) => {
conf.auth.otp = otp
const u = conf.creds.username
const p = conf.creds.password
return profile.loginCouch(u, p, conf)
})
}).then((result) => {
const newCreds = {}
if (result && result.token) {
newCreds.token = result.token
} else {
newCreds.username = conf.creds.username
newCreds.password = conf.creds.password
newCreds.email = conf.creds.email
newCreds.alwaysAuth = npm.config.get('always-auth')
}

const usermsg = conf.creds.username ? ' user ' + conf.creds.username : ''
conf.log.info('login', 'Authorized' + usermsg)
const scopeMessage = conf.scope ? ' to scope ' + conf.scope : ''
const userout = conf.creds.username ? ' as ' + conf.creds.username : ''
output('Logged in%s%s on %s.', userout, scopeMessage, conf.registry)
return newCreds
})
const usermsg = conf.creds.username ? ' user ' + conf.creds.username : ''
conf.log.info('login', 'Authorized' + usermsg)
const scopeMessage = conf.scope ? ' to scope ' + conf.scope : ''
const userout = conf.creds.username ? ' as ' + conf.creds.username : ''
output('Logged in%s%s on %s.', userout, scopeMessage, conf.registry)
return newCreds
})
}
4 changes: 2 additions & 2 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function rebuildBundles (pkg, folder, cb) {
if (!npm.config.get('rebuild-bundle')) return cb()

var deps = Object.keys(pkg.dependencies || {})
.concat(Object.keys(pkg.devDependencies || {}))
.concat(Object.keys(pkg.devDependencies || {}))
var bundles = pkg.bundleDependencies || pkg.bundledDependencies || []

fs.readdir(path.resolve(folder, 'node_modules'), function (er, files) {
Expand All @@ -119,7 +119,7 @@ function rebuildBundles (pkg, folder, cb) {
chain(files.filter(function (file) {
// rebuild if:
// not a .folder, like .bin or .hooks
return !file.match(/^[\._-]/) &&
return !file.match(/^[._-]/) &&
// not some old 0.x style bundle
file.indexOf('@') === -1 &&
// either not a dep, or explicitly bundled
Expand Down
1 change: 1 addition & 0 deletions lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint-disable standard/no-callback-literal */

const BB = require('bluebird')

Expand Down
14 changes: 7 additions & 7 deletions lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function ci (args, cb) {
config: npm.config,
log: npmlog
})
.run()
.then(
(details) => console.error(`added ${details.pkgCount} packages in ${
details.runTime / 1000
}s`)
)
.then(() => cb(), cb)
.run()
.then(
(details) => console.error(`added ${details.pkgCount} packages in ${
details.runTime / 1000
}s`)
)
.then(() => cb(), cb)
}
4 changes: 2 additions & 2 deletions lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function completion (args, cb) {
if (isWindowsShell) {
var e = new Error('npm completion supported only in MINGW / Git bash on Windows')
e.code = 'ENOTSUP'
e.errno = require('constants').ENOTSUP
e.errno = require('constants').ENOTSUP // eslint-disable-line node/no-deprecated-api
return cb(e)
}

Expand Down Expand Up @@ -150,7 +150,7 @@ function dumpScript (cb) {

fs.readFile(p, 'utf8', function (er, d) {
if (er) return cb(er)
d = d.replace(/^\#\!.*?\n/, '')
d = d.replace(/^#!.*?\n/, '')

process.stdout.write(d, function () { cb() })
process.stdout.on('error', function (er) {
Expand Down
9 changes: 5 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable standard/no-callback-literal */
module.exports = config

var log = require('npmlog')
Expand Down Expand Up @@ -39,7 +40,7 @@ config.completion = function (opts, cb) {
// todo: complete with valid values, if possible.
if (argv.length > 3) return cb(null, [])
// fallthrough
/*eslint no-fallthrough:0*/
/* eslint no-fallthrough:0 */
case 'get':
case 'delete':
case 'rm':
Expand Down Expand Up @@ -89,7 +90,7 @@ function edit (cb) {
data = [
';;;;',
'; npm ' + (npm.config.get('global')
? 'globalconfig' : 'userconfig') + ' file',
? 'globalconfig' : 'userconfig') + ' file',
'; this is a simple ini-formatted file',
'; lines that start with semi-colons are comments.',
'; read `npm help config` for help on the various options',
Expand All @@ -111,8 +112,8 @@ function edit (cb) {
.replace(/\n/g, '\n; ')
.split('\n'))
}, []))
.concat([''])
.join(os.EOL)
.concat([''])
.join(os.EOL)
writeFileAtomic(
f,
data,
Expand Down
18 changes: 10 additions & 8 deletions lib/config/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ exports.defs = configDefs

Object.defineProperty(exports, 'defaults', { get: function () {
return configDefs.defaults
}, enumerable: true })
},
enumerable: true })

Object.defineProperty(exports, 'types', { get: function () {
return configDefs.types
}, enumerable: true })
},
enumerable: true })

exports.validate = validate

var myUid = process.env.SUDO_UID !== undefined
? process.env.SUDO_UID : (process.getuid && process.getuid())
? process.env.SUDO_UID : (process.getuid && process.getuid())
var myGid = process.env.SUDO_GID !== undefined
? process.env.SUDO_GID : (process.getgid && process.getgid())
? process.env.SUDO_GID : (process.getgid && process.getgid())

var loading = false
var loadCbs = []
Expand Down Expand Up @@ -274,7 +276,7 @@ Conf.prototype.save = function (where, cb) {
if (cb) return cb(er)
else return this.emit('error', er)
}
this._saving --
this._saving--
if (this._saving === 0) {
if (cb) cb()
this.emit('save')
Expand All @@ -283,7 +285,7 @@ Conf.prototype.save = function (where, cb) {

then = then.bind(this)
done = done.bind(this)
this._saving ++
this._saving++

var mode = where === 'user' ? '0600' : '0666'
if (!data.trim()) {
Expand Down Expand Up @@ -354,8 +356,8 @@ Conf.prototype.addEnv = function (env) {
// leave first char untouched, even if
// it is a '_' - convert all other to '-'
var p = k.toLowerCase()
.replace(/^npm_config_/, '')
.replace(/(?!^)_/g, '-')
.replace(/^npm_config_/, '')
.replace(/(?!^)_/g, '-')
conf[p] = env[k]
})
return CC.prototype.addEnv.call(this, '', conf, 'env')
Expand Down
10 changes: 5 additions & 5 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (home) process.env.HOME = home
else home = path.resolve(temp, 'npm-' + uidOrPid)

var cacheExtra = process.platform === 'win32' ? 'npm-cache' : '.npm'
var cacheRoot = process.platform === 'win32' && process.env.APPDATA || home
var cacheRoot = (process.platform === 'win32' && process.env.APPDATA) || home
var cache = path.resolve(cacheRoot, cacheExtra)

var globalPrefix
Expand Down Expand Up @@ -152,7 +152,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
globalconfig: path.resolve(globalPrefix, 'etc', 'npmrc'),
'global-style': false,
group: process.platform === 'win32' ? 0
: process.env.SUDO_GID || (process.getgid && process.getgid()),
: process.env.SUDO_GID || (process.getgid && process.getgid()),
'ham-it-up': false,
heading: 'npm',
'if-present': false,
Expand Down Expand Up @@ -384,9 +384,9 @@ function getLocalAddresses () {
return interfaces[nic].filter(function (addr) {
return addr.family === 'IPv4'
})
.map(function (addr) {
return addr.address
})
.map(function (addr) {
return addr.address
})
}).reduce(function (curr, next) {
return curr.concat(next)
}, []).concat(undefined)
Expand Down
12 changes: 6 additions & 6 deletions lib/config/fetch-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function fromPacote (opts) {

function getCacheMode (opts) {
return opts.offline
? 'only-if-cached'
: opts.preferOffline
? 'force-cache'
: opts.preferOnline
? 'no-cache'
: 'default'
? 'only-if-cached'
: opts.preferOffline
? 'force-cache'
: opts.preferOnline
? 'no-cache'
: 'default'
}

function getHeaders (uri, registry, opts) {
Expand Down
6 changes: 3 additions & 3 deletions lib/config/get-credentials-by-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function getCredentialsByURI (uri) {
var userDef = this.get('username')
var passDef = this.get('_password')
if (authDef && !(userDef && passDef)) {
authDef = new Buffer(authDef, 'base64').toString()
authDef = Buffer.from(authDef, 'base64').toString()
authDef = authDef.split(':')
userDef = authDef.shift()
passDef = authDef.join(':')
}

if (this.get(nerfed + ':_password')) {
c.password = new Buffer(this.get(nerfed + ':_password'), 'base64').toString('utf8')
c.password = Buffer.from(this.get(nerfed + ':_password'), 'base64').toString('utf8')
} else if (nerfed === defnerf && passDef) {
c.password = passDef
}
Expand All @@ -65,7 +65,7 @@ function getCredentialsByURI (uri) {
}

if (c.username && c.password) {
c.auth = new Buffer(c.username + ':' + c.password).toString('base64')
c.auth = Buffer.from(c.username + ':' + c.password).toString('base64')
}

return c
Expand Down
2 changes: 1 addition & 1 deletion lib/config/load-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function loadPrefix (cb) {
Object.defineProperty(this, 'localPrefix',
{ set: function (prefix) { p = prefix },
get: function () { return p },
enumerable: true })
enumerable: true })

// try to guess at a good node_modules location.
// If we are *explicitly* given a prefix on the cli, then
Expand Down
2 changes: 1 addition & 1 deletion lib/config/set-credentials-by-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function setCredentialsByURI (uri, c) {

this.del(nerfed + ':_authToken', 'user')

var encoded = new Buffer(c.password, 'utf8').toString('base64')
var encoded = Buffer.from(c.password, 'utf8').toString('base64')
this.set(nerfed + ':_password', encoded, 'user')
this.set(nerfed + ':username', c.username, 'user')
this.set(nerfed + ':email', c.email, 'user')
Expand Down
1 change: 1 addition & 0 deletions lib/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable standard/no-callback-literal */
var npm = require('./npm.js')
var mapToRegistry = require('./utils/map-to-registry.js')
var npa = require('npm-package-arg')
Expand Down
1 change: 1 addition & 0 deletions lib/dist-tag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable standard/no-callback-literal */
module.exports = distTag

var log = require('npmlog')
Expand Down
4 changes: 2 additions & 2 deletions lib/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function edit (args, cb) {
))
}
p = p.split('/')
.join('/node_modules/')
.replace(/(\/node_modules)+/, '/node_modules')
.join('/node_modules/')
.replace(/(\/node_modules)+/, '/node_modules')
var f = path.resolve(npm.dir, p)
fs.lstat(f, function (er) {
if (er) return cb(er)
Expand Down
Loading

0 comments on commit 311e555

Please sign in to comment.