diff options
author | Sebastiaan Deckers <seb@ninja.sg> | 2015-10-13 06:12:34 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-10-22 01:16:34 +0300 |
commit | 40c1b0f5cba5c4ecbcea8e9a7def9965682c2701 (patch) | |
tree | bdc117586e05a4f01ba0faed1adbea2eeb2248c4 /lib | |
parent | 8946cb3f321995792a3009f6372a6f87e81873ed (diff) |
src: Update formatting to be compatible with standard@5
PR-URL: https://github.com/npm/npm/pull/9954
Diffstat (limited to 'lib')
-rw-r--r-- | lib/build.js | 2 | ||||
-rw-r--r-- | lib/cache.js | 1 | ||||
-rw-r--r-- | lib/cache/add-local-tarball.js | 2 | ||||
-rw-r--r-- | lib/cache/caching-client.js | 2 | ||||
-rw-r--r-- | lib/completion.js | 6 | ||||
-rw-r--r-- | lib/config.js | 28 | ||||
-rw-r--r-- | lib/config/core.js | 1 | ||||
-rw-r--r-- | lib/config/load-cafile.js | 1 | ||||
-rw-r--r-- | lib/config/load-prefix.js | 6 | ||||
-rw-r--r-- | lib/dedupe.js | 8 | ||||
-rw-r--r-- | lib/help-search.js | 41 | ||||
-rw-r--r-- | lib/install.js | 4 | ||||
-rw-r--r-- | lib/install/action/extract.js | 9 | ||||
-rw-r--r-- | lib/install/mutate-into-logical-tree.js | 6 | ||||
-rw-r--r-- | lib/link.js | 6 | ||||
-rw-r--r-- | lib/npm.js | 22 | ||||
-rw-r--r-- | lib/outdated.js | 4 | ||||
-rw-r--r-- | lib/repo.js | 2 | ||||
-rw-r--r-- | lib/run-script.js | 1 | ||||
-rw-r--r-- | lib/search.js | 22 | ||||
-rw-r--r-- | lib/utils/completion/installed-deep.js | 2 | ||||
-rw-r--r-- | lib/utils/deep-sort-object.js | 1 | ||||
-rw-r--r-- | lib/utils/error-handler.js | 576 | ||||
-rw-r--r-- | lib/utils/lifecycle.js | 9 | ||||
-rw-r--r-- | lib/utils/tar.js | 6 |
25 files changed, 381 insertions, 387 deletions
diff --git a/lib/build.js b/lib/build.js index b6d2da3ad..e9da59a23 100644 --- a/lib/build.js +++ b/lib/build.js @@ -133,12 +133,10 @@ function shouldWarn (pkg, folder, global, cb) { // current searched package is the linked package on first call if (linkedPkg !== currentPkg) { - // don't generate a warning if it's listed in dependencies if (Object.keys(topPkg.dependencies || {}) .concat(Object.keys(topPkg.devDependencies || {})) .indexOf(currentPkg) === -1) { - if (top && pkg.preferGlobal && !global) { log.warn('prefer global', packageId(pkg) + ' should be installed with -g') } diff --git a/lib/cache.js b/lib/cache.js index b4b04819c..eb5a1e413 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -92,7 +92,6 @@ cache.usage = 'npm cache add <tarball file>' + '\nnpm cache clean [<pkg>[@<version>]]' cache.completion = function (opts, cb) { - var argv = opts.conf.argv.remain if (argv.length === 2) { return cb(null, ['add', 'ls', 'clean']) diff --git a/lib/cache/add-local-tarball.js b/lib/cache/add-local-tarball.js index 00710cf52..7d747ea80 100644 --- a/lib/cache/add-local-tarball.js +++ b/lib/cache/add-local-tarball.js @@ -153,7 +153,6 @@ function addTmpTarball_ (tgz, data, shasum, cb) { getCacheStat(function (er, cs) { if (er) return cb(er) mkdir(pkg, function (er, created) { - // chown starting from the first dir created by mkdirp, // or the root dir, if none had to be created, so that // we know that we get all the children. @@ -167,7 +166,6 @@ function addTmpTarball_ (tgz, data, shasum, cb) { var fin = cs.uid && cs.gid ? chown : done read.on('error', cb).pipe(write).on('error', cb).on('close', fin) }) - }) function done () { diff --git a/lib/cache/caching-client.js b/lib/cache/caching-client.js index 77d8d66cb..f70271127 100644 --- a/lib/cache/caching-client.js +++ b/lib/cache/caching-client.js @@ -31,7 +31,7 @@ inherits(CachingRegistryClient, RegistryClient) CachingRegistryClient.prototype._invalidatingRequest = function (uri, params, cb) { var client = this - this._request.call(this, uri, params, function () { + this._request(uri, params, function () { var args = arguments var method = params.method diff --git a/lib/completion.js b/lib/completion.js index e9a838d48..4aa3ae13a 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -9,9 +9,8 @@ var configDefs = npmconf.defs var configTypes = configDefs.types var shorthands = configDefs.shorthands var nopt = require('nopt') -var configNames = Object.keys(configTypes).filter(function (e) { - return e.charAt(0) !== '_' - }) +var configNames = Object.keys(configTypes) + .filter(function (e) { return e.charAt(0) !== '_' }) var shorthandNames = Object.keys(shorthands) var allConfs = configNames.concat(shorthandNames) var once = require('once') @@ -167,7 +166,6 @@ function dumpScript (cb) { if (er.errno === 'EPIPE') er = null cb(er) }) - }) } diff --git a/lib/config.js b/lib/config.js index 305e6bc8a..8570537d0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -73,8 +73,8 @@ function edit (cb) { if (er) data = '' data = [ ';;;;', - '; npm ' + (npm.config.get('global') ? - 'globalconfig' : 'userconfig') + ' file', + '; npm ' + (npm.config.get('global') + ? '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', @@ -86,18 +86,18 @@ function edit (cb) { '; all options with default values', ';;;;' ]).concat(Object.keys(npmconf.defaults).reduce(function (arr, key) { - var obj = {} - obj[key] = npmconf.defaults[key] - if (key === 'logstream') return arr - return arr.concat( - ini.stringify(obj) - .replace(/\n$/m, '') - .replace(/^/g, '; ') - .replace(/\n/g, '\n; ') - .split('\n')) - }, [])) - .concat(['']) - .join(os.EOL) + var obj = {} + obj[key] = npmconf.defaults[key] + if (key === 'logstream') return arr + return arr.concat( + ini.stringify(obj) + .replace(/\n$/m, '') + .replace(/^/g, '; ') + .replace(/\n/g, '\n; ') + .split('\n')) + }, [])) + .concat(['']) + .join(os.EOL) writeFileAtomic( f, data, diff --git a/lib/config/core.js b/lib/config/core.js index 0c6d3ecdb..d1306eb4c 100644 --- a/lib/config/core.js +++ b/lib/config/core.js @@ -297,7 +297,6 @@ Conf.prototype.save = function (where, cb) { fs.writeFile(target.path, data, 'utf8', function (er) { if (er) return then(er) if (where === 'user' && myUid && myGid) { - fs.chown(target.path, +myUid, +myGid, then) } else { then() diff --git a/lib/config/load-cafile.js b/lib/config/load-cafile.js index 1bf9cc490..de8f61625 100644 --- a/lib/config/load-cafile.js +++ b/lib/config/load-cafile.js @@ -8,7 +8,6 @@ function loadCAFile (cafilePath, cb) { fs.readFile(cafilePath, 'utf8', afterCARead.bind(this)) function afterCARead (er, cadata) { - if (er) { // previous cafile no longer exists, so just continue on gracefully if (er.code === 'ENOENT') return cb() diff --git a/lib/config/load-prefix.js b/lib/config/load-prefix.js index 01a925280..bb5d9f3be 100644 --- a/lib/config/load-prefix.js +++ b/lib/config/load-prefix.js @@ -7,7 +7,8 @@ function loadPrefix (cb) { var cli = this.list[0] Object.defineProperty(this, 'prefix', - { set: function (prefix) { + { + set: function (prefix) { var g = this.get('global') this[g ? 'globalPrefix' : 'localPrefix'] = prefix }.bind(this), @@ -19,7 +20,8 @@ function loadPrefix (cb) { }) Object.defineProperty(this, 'globalPrefix', - { set: function (prefix) { + { + set: function (prefix) { this.set('prefix', prefix) }.bind(this), get: function () { diff --git a/lib/dedupe.js b/lib/dedupe.js index 66360a652..2cb85990c 100644 --- a/lib/dedupe.js +++ b/lib/dedupe.js @@ -68,9 +68,9 @@ Deduper.prototype.loadIdealTree = function (cb) { [this, this.finishTracker, 'cloneCurrentTree'], [this.newTracker(this.progress.loadIdealTree, 'loadAllDepsIntoIdealTree', 10)], - [function (next) { + [ function (next) { loadExtraneous(self.idealTree, self.progress.loadAllDepsIntoIdealTree, next) - }], + } ], [this, this.finishTracker, 'loadAllDepsIntoIdealTree'], [this, function (next) { recalculateMetadata(this.idealTree, log, next) }] @@ -151,10 +151,10 @@ function hoistChildren_ (tree, diff, seen, next) { chain([ [recalculateMetadata, hoistTo, log], [hoistChildren_, child, diff, seen], - [function (next) { + [ function (next) { moveRemainingChildren(child, diff) next() - }] + } ] ], done) } else { done() diff --git a/lib/help-search.js b/lib/help-search.js index 16f389027..8a138feeb 100644 --- a/lib/help-search.js +++ b/lib/help-search.js @@ -161,11 +161,12 @@ function formatResults (args, results, cb) { var out = results.map(function (res) { var out = res.cmd - var r = Object.keys(res.hits).map(function (k) { - return k + ':' + res.hits[k] - }).sort(function (a, b) { - return a > b ? 1 : -1 - }).join(' ') + var r = Object.keys(res.hits) + .map(function (k) { + return k + ':' + res.hits[k] + }).sort(function (a, b) { + return a > b ? 1 : -1 + }).join(' ') out += ((new Array(Math.max(1, cols - out.length - r.length))) .join(' ')) + r @@ -175,25 +176,25 @@ function formatResults (args, results, cb) { out = '\n\n' + out + '\n' + (new Array(cols)).join('—') + '\n' + res.lines.map(function (line, i) { - if (line === null || i > 3) return '' - for (var out = line, a = 0, l = args.length; a < l; a++) { - var finder = out.toLowerCase().split(args[a].toLowerCase()) - var newOut = '' - var p = 0 + if (line === null || i > 3) return '' + for (var out = line, a = 0, l = args.length; a < l; a++) { + var finder = out.toLowerCase().split(args[a].toLowerCase()) + var newOut = '' + var p = 0 - finder.forEach(function (f) { - newOut += out.substr(p, f.length) + finder.forEach(function (f) { + newOut += out.substr(p, f.length) - var hilit = out.substr(p + f.length, args[a].length) - if (npm.color) hilit = color.bgBlack(color.red(hilit)) - newOut += hilit + var hilit = out.substr(p + f.length, args[a].length) + if (npm.color) hilit = color.bgBlack(color.red(hilit)) + newOut += hilit - p += f.length + args[a].length - }) - } + p += f.length + args[a].length + }) + } - return newOut - }).join('\n').trim() + return newOut + }).join('\n').trim() return out }).join('\n') diff --git a/lib/install.js b/lib/install.js index 385505428..773ed5405 100644 --- a/lib/install.js +++ b/lib/install.js @@ -351,9 +351,9 @@ Installer.prototype.loadIdealTree = function (cb) { [this, this.loadAllDepsIntoIdealTree], [this, this.finishTracker, 'loadAllDepsIntoIdealTree'], - [this, function (next) { recalculateMetadata(this.idealTree, log, next) } ], + [this, function (next) { recalculateMetadata(this.idealTree, log, next) }], [this, this.debugTree, 'idealTree:prePrune', 'idealTree'], - [this, function (next) { next(pruneTree(this.idealTree)) } ] + [this, function (next) { next(pruneTree(this.idealTree)) }] ], cb) } diff --git a/lib/install/action/extract.js b/lib/install/action/extract.js index 7a73f04e9..b42776849 100644 --- a/lib/install/action/extract.js +++ b/lib/install/action/extract.js @@ -11,8 +11,9 @@ module.exports = function (top, buildpath, pkg, log, next) { var group = up ? null : npm.config.get('group') cache.unpack(pkg.package.name, pkg.package.version , buildpath - , null, null, user, group, function (er) { - if (er) return next(er) - updatePackageJson(pkg, buildpath, next) - }) + , null, null, user, group, + function (er) { + if (er) return next(er) + updatePackageJson(pkg, buildpath, next) + }) } diff --git a/lib/install/mutate-into-logical-tree.js b/lib/install/mutate-into-logical-tree.js index 6053cfc7d..833aa94c9 100644 --- a/lib/install/mutate-into-logical-tree.js +++ b/lib/install/mutate-into-logical-tree.js @@ -19,9 +19,9 @@ var mutateIntoLogicalTree = module.exports = function (tree) { var flat = flattenTree(tree) function getNode (flatname) { - return flatname.substr(0, 5) === '#DEV:' ? - flat[flatname.substr(5)] : - flat[flatname] + return flatname.substr(0, 5) === '#DEV:' + ? flat[flatname.substr(5)] + : flat[flatname] } Object.keys(flat).sort().forEach(function (flatname) { diff --git a/lib/link.js b/lib/link.js index 9a62b0633..7ee518419 100644 --- a/lib/link.js +++ b/lib/link.js @@ -114,14 +114,14 @@ function linkInstall (pkgs, cb) { if (npm.config.get('dry-run')) return resultPrinter(pkg, pp, target, rp, cb) chain( [ - [function (cb) { + [ function (cb) { log.verbose('link', 'symlinking %s to %s', pp, target) cb() - }], + } ], [symlink, pp, target], // do not run any scripts rp && [build, [target], npm.config.get('global'), build._noLC, true], - [resultPrinter, pkg, pp, target, rp ] + [resultPrinter, pkg, pp, target, rp] ], cb ) diff --git a/lib/npm.js b/lib/npm.js index 264ad3636..b714a8248 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -162,8 +162,8 @@ ] var littleGuys = [ 'isntall' ] var fullList = cmdList.concat(aliasNames).filter(function (c) { - return plumbing.indexOf(c) === -1 - }) + return plumbing.indexOf(c) === -1 + }) var abbrevs = abbrev(fullList) // we have our reasons @@ -387,7 +387,8 @@ } Object.defineProperty(npm, 'prefix', - { get: function () { + { + get: function () { return npm.config.get('global') ? npm.globalPrefix : npm.localPrefix }, set: function (r) { @@ -399,7 +400,8 @@ }) Object.defineProperty(npm, 'bin', - { get: function () { + { + get: function () { if (npm.config.get('global')) return npm.globalBin return path.resolve(npm.root, '.bin') }, @@ -407,7 +409,8 @@ }) Object.defineProperty(npm, 'globalBin', - { get: function () { + { + get: function () { var b = npm.globalPrefix if (process.platform !== 'win32') b = path.resolve(b, 'bin') return b @@ -415,7 +418,8 @@ }) Object.defineProperty(npm, 'dir', - { get: function () { + { + get: function () { if (npm.config.get('global')) return npm.globalDir return path.resolve(npm.prefix, 'node_modules') }, @@ -423,7 +427,8 @@ }) Object.defineProperty(npm, 'globalDir', - { get: function () { + { + get: function () { return (process.platform !== 'win32') ? path.resolve(npm.globalPrefix, 'lib', 'node_modules') : path.resolve(npm.globalPrefix, 'node_modules') @@ -443,7 +448,8 @@ var tmpFolder var rand = require('crypto').randomBytes(4).toString('hex') Object.defineProperty(npm, 'tmp', - { get: function () { + { + get: function () { if (!tmpFolder) tmpFolder = 'npm-' + process.pid + '-' + rand return path.resolve(npm.config.get('tmp'), tmpFolder) }, diff --git a/lib/outdated.js b/lib/outdated.js index 40506f2af..44dd8bf00 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -326,9 +326,9 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) { function doIt (wanted, latest) { if (!long) { - return cb(null, [[ tree, dep, curr && curr.version, wanted, latest, req, null, pkgpath]]) + return cb(null, [[tree, dep, curr && curr.version, wanted, latest, req, null, pkgpath]]) } - cb(null, [[ tree, dep, curr && curr.version, wanted, latest, req, type, pkgpath]]) + cb(null, [[tree, dep, curr && curr.version, wanted, latest, req, type, pkgpath]]) } if (args.length && args.indexOf(dep) === -1) return skip() diff --git a/lib/repo.js b/lib/repo.js index 4bd200aff..caaf422cf 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -47,5 +47,5 @@ function unknownHostedUrl (url) { : 'http:' return protocol + '//' + (url.host || '') + url.path.replace(/\.git$/, '') - } catch(e) {} + } catch (e) {} } diff --git a/lib/run-script.js b/lib/run-script.js index 8c99c29b8..ef5e65600 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -11,7 +11,6 @@ runScript.usage = 'npm run-script <command> [-- <args>...]' + '\n\nalias: npm run' runScript.completion = function (opts, cb) { - // see if there's already a package specified. var argv = opts.conf.argv.remain diff --git a/lib/search.js b/lib/search.js index a029d62eb..4877417f0 100644 --- a/lib/search.js +++ b/lib/search.js @@ -196,16 +196,16 @@ function prettify (data, args) { var output = columnify( lines, { - include: columns, - truncate: truncate, - config: { - name: { maxWidth: 40, truncate: false, truncateMarker: '' }, - description: { maxWidth: 60 }, - author: { maxWidth: 20 }, - date: { maxWidth: 11 }, - version: { maxWidth: 11 }, - keywords: { maxWidth: Infinity } - } + include: columns, + truncate: truncate, + config: { + name: { maxWidth: 40, truncate: false, truncateMarker: '' }, + description: { maxWidth: 60 }, + author: { maxWidth: 20 }, + date: { maxWidth: 11 }, + version: { maxWidth: 11 }, + keywords: { maxWidth: Infinity } + } } ) output = trimToMaxWidth(output) @@ -214,7 +214,7 @@ function prettify (data, args) { return output } -var colors = [31, 33, 32, 36, 34, 35 ] +var colors = [31, 33, 32, 36, 34, 35] var cl = colors.length function addColorMarker (str, arg, i) { diff --git a/lib/utils/completion/installed-deep.js b/lib/utils/completion/installed-deep.js index 146a4d790..dc9bfbee8 100644 --- a/lib/utils/completion/installed-deep.js +++ b/lib/utils/completion/installed-deep.js @@ -49,6 +49,4 @@ function installedDeep (opts, cb) { var names = local.concat(global) return cb(null, names) } - } - diff --git a/lib/utils/deep-sort-object.js b/lib/utils/deep-sort-object.js index aa34eb7dd..c8003c207 100644 --- a/lib/utils/deep-sort-object.js +++ b/lib/utils/deep-sort-object.js @@ -10,4 +10,3 @@ module.exports = function deepSortObject (obj, sortBy) { }) return obj } - diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js index cd61f7912..f18540c9a 100644 --- a/lib/utils/error-handler.js +++ b/lib/utils/error-handler.js @@ -171,316 +171,316 @@ function errorHandler (er) { if (log.levels[log.level] <= log.levels.error) console.error('') switch (er.code) { - case 'ECONNREFUSED': - log.error('', er) - log.error( - '', - [ - '\nIf you are behind a proxy, please make sure that the', - "'proxy' config is set properly. See: 'npm help config'" - ].join('\n') - ) - break - - case 'EACCES': - case 'EPERM': - log.error('', er) - log.error('', ['\nPlease try running this command again as root/Administrator.' - ].join('\n')) - break - - case 'ELIFECYCLE': - log.error('', er.message) - log.error( - '', - [ + case 'ECONNREFUSED': + log.error('', er) + log.error( '', - 'Failed at the ' + er.pkgid + ' ' + er.stage + " script '" + er.script + "'.", - 'This is most likely a problem with the ' + er.pkgname + ' package,', - 'not with npm itself.', - 'Tell the author that this fails on your system:', - ' ' + er.script, - 'You can get their info via:', - ' npm owner ls ' + er.pkgname, - 'There is likely additional logging output above.' - ].join('\n') - ) - break - - case 'ENOGIT': - log.error('', er.message) - log.error( - '', - [ + [ + '\nIf you are behind a proxy, please make sure that the', + "'proxy' config is set properly. See: 'npm help config'" + ].join('\n') + ) + break + + case 'EACCES': + case 'EPERM': + log.error('', er) + log.error('', ['\nPlease try running this command again as root/Administrator.' + ].join('\n')) + break + + case 'ELIFECYCLE': + log.error('', er.message) + log.error( '', - 'Failed using git.', - 'This is most likely not a problem with npm itself.', - 'Please check if you have git installed and in your PATH.' - ].join('\n') - ) - break - - case 'EJSONPARSE': - log.error('', er.message) - log.error('', 'File: ' + er.file) - log.error( - '', - [ - 'Failed to parse package.json data.', - 'package.json must be actual JSON, not just JavaScript.', + [ + '', + 'Failed at the ' + er.pkgid + ' ' + er.stage + " script '" + er.script + "'.", + 'This is most likely a problem with the ' + er.pkgname + ' package,', + 'not with npm itself.', + 'Tell the author that this fails on your system:', + ' ' + er.script, + 'You can get their info via:', + ' npm owner ls ' + er.pkgname, + 'There is likely additional logging output above.' + ].join('\n') + ) + break + + case 'ENOGIT': + log.error('', er.message) + log.error( '', - 'This is not a bug in npm.', - 'Tell the package author to fix their package.json file.' - ].join('\n'), - 'JSON.parse' - ) - break + [ + '', + 'Failed using git.', + 'This is most likely not a problem with npm itself.', + 'Please check if you have git installed and in your PATH.' + ].join('\n') + ) + break + + case 'EJSONPARSE': + log.error('', er.message) + log.error('', 'File: ' + er.file) + log.error( + '', + [ + 'Failed to parse package.json data.', + 'package.json must be actual JSON, not just JavaScript.', + '', + 'This is not a bug in npm.', + 'Tell the package author to fix their package.json file.' + ].join('\n'), + 'JSON.parse' + ) + break - // TODO(isaacs) - // Add a special case here for E401 and E403 explaining auth issues? + // TODO(isaacs) + // Add a special case here for E401 and E403 explaining auth issues? - case 'E404': - var msg = [er.message] - if (er.pkgid && er.pkgid !== '-') { - msg.push('', "'" + er.pkgid + "' is not in the npm registry.") + case 'E404': + var msg = [er.message] + if (er.pkgid && er.pkgid !== '-') { + msg.push('', "'" + er.pkgid + "' is not in the npm registry.") - var valResult = nameValidator(er.pkgid) + var valResult = nameValidator(er.pkgid) - if (valResult.validForNewPackages) { - msg.push('You should bug the author to publish it (or use the name yourself!)') - } else { - msg.push('Your package name is not valid, because', '') + if (valResult.validForNewPackages) { + msg.push('You should bug the author to publish it (or use the name yourself!)') + } else { + msg.push('Your package name is not valid, because', '') - var errorsArray = (valResult.errors || []).concat(valResult.warnings || []) - errorsArray.forEach(function (item, idx) { - msg.push(' ' + (idx + 1) + '. ' + item) - }) + var errorsArray = (valResult.errors || []).concat(valResult.warnings || []) + errorsArray.forEach(function (item, idx) { + msg.push(' ' + (idx + 1) + '. ' + item) + }) + } + + if (er.parent) { + msg.push("It was specified as a dependency of '" + er.parent + "'") + } + msg.push( + '\nNote that you can also install from a', + 'tarball, folder, http url, or git url.' + ) } + // There's no need to have 404 in the message as well. + msg[0] = msg[0].replace(/^404\s+/, '') + log.error('404', msg.join('\n')) + break - if (er.parent) { - msg.push("It was specified as a dependency of '" + er.parent + "'") - } - msg.push( - '\nNote that you can also install from a', - 'tarball, folder, http url, or git url.' + case 'EPUBLISHCONFLICT': + log.error( + 'publish fail', + [ + 'Cannot publish over existing version.', + "Update the 'version' field in package.json and try again.", + '', + 'To automatically increment version numbers, see:', + ' npm help version' + ].join('\n') ) - } - // There's no need to have 404 in the message as well. - msg[0] = msg[0].replace(/^404\s+/, '') - log.error('404', msg.join('\n')) - break - - case 'EPUBLISHCONFLICT': - log.error( - 'publish fail', - [ - 'Cannot publish over existing version.', - "Update the 'version' field in package.json and try again.", - '', - 'To automatically increment version numbers, see:', - ' npm help version' - ].join('\n') - ) - break - - case 'EISGIT': - log.error( - 'git', - [ - er.message, - ' ' + er.path, - 'Refusing to remove it. Update manually,', - 'or move it out of the way first.' - ].join('\n') - ) - break - - case 'ECYCLE': - log.error( - 'cycle', - [ - er.message, - 'While installing: ' + er.pkgid, - 'Found a pathological dependency case that npm cannot solve.', - 'Please report this to the package author.' - ].join('\n') - ) - break - - case 'EBADPLATFORM': - log.error( - 'notsup', - [ - er.message, - 'Not compatible with your operating system or architecture: ' + er.pkgid, - 'Valid OS: ' + er.os.join(','), - 'Valid Arch: ' + er.cpu.join(','), - 'Actual OS: ' + process.platform, - 'Actual Arch: ' + process.arch - ].join('\n') - ) - break - - case 'EEXIST': - log.error( - [ - er.message, - 'File exists: ' + er.path, - 'Move it away, and try again.' - ].join('\n') - ) - break - - case 'ENEEDAUTH': - log.error( - 'need auth', - [ - er.message, - 'You need to authorize this machine using `npm adduser`' - ].join('\n') - ) - break - - case 'EPEERINVALID': - var peerErrors = Object.keys(er.peersDepending).map(function (peer) { - return 'Peer ' + peer + ' wants ' + - er.packageName + '@' + er.peersDepending[peer] - }) - log.error('peerinvalid', [er.message].concat(peerErrors).join('\n')) - break - - case 'ECONNRESET': - case 'ENOTFOUND': - case 'ETIMEDOUT': - case 'EAI_FAIL': - log.error( - 'network', - [ - er.message, - 'This is most likely not a problem with npm itself', - 'and is related to network connectivity.', - 'In most cases you are behind a proxy or have bad network settings.', - '\nIf you are behind a proxy, please make sure that the', - "'proxy' config is set properly. See: 'npm help config'" - ].join('\n') - ) - break - - case 'ENOPACKAGEJSON': - log.error( - 'package.json', - [ - er.message, - 'This is most likely not a problem with npm itself.', - "npm can't find a package.json file in your current directory." - ].join('\n') - ) - break - - case 'ETARGET': - msg = [ - er.message, - 'This is most likely not a problem with npm itself.', - 'In most cases you or one of your dependencies are requesting', - "a package version that doesn't exist." - ] - if (er.parent) { - msg.push("\nIt was specified as a dependency of '" + er.parent + "'\n") - } - log.error('notarget', msg.join('\n')) - break + break - case 'ENOTSUP': - if (er.required) { + case 'EISGIT': + log.error( + 'git', + [ + er.message, + ' ' + er.path, + 'Refusing to remove it. Update manually,', + 'or move it out of the way first.' + ].join('\n') + ) + break + + case 'ECYCLE': + log.error( + 'cycle', + [ + er.message, + 'While installing: ' + er.pkgid, + 'Found a pathological dependency case that npm cannot solve.', + 'Please report this to the package author.' + ].join('\n') + ) + break + + case 'EBADPLATFORM': log.error( 'notsup', [ er.message, - 'Not compatible with your version of node/npm: ' + er.pkgid, - 'Required: ' + JSON.stringify(er.required), - 'Actual: ' + JSON.stringify({ - npm: npm.version, - node: npm.config.get('node-version') - }) + 'Not compatible with your operating system or architecture: ' + er.pkgid, + 'Valid OS: ' + er.os.join(','), + 'Valid Arch: ' + er.cpu.join(','), + 'Actual OS: ' + process.platform, + 'Actual Arch: ' + process.arch ].join('\n') ) break - } // else passthrough - /*eslint no-fallthrough:0*/ - case 'ENOSPC': - log.error( - 'nospc', - [ - er.message, - 'This is most likely not a problem with npm itself', - 'and is related to insufficient space on your system.' - ].join('\n') - ) - break - - case 'EROFS': - log.error( - 'rofs', - [ - er.message, - 'This is most likely not a problem with npm itself', - 'and is related to the file system being read-only.', - '\nOften virtualized file systems, or other file systems', - "that don't support symlinks, give this error." - ].join('\n') - ) - break - - case 'ENOENT': - log.error( - 'enoent', - [ - er.message, - 'This is most likely not a problem with npm itself', - 'and is related to npm not being able to find a file.', - er.file ? "\nCheck if the file '" + er.file + "' is present." : '' - ].join('\n') - ) - break - - case 'EMISSINGARG': - case 'EUNKNOWNTYPE': - case 'EINVALIDTYPE': - case 'ETOOMANYARGS': - log.error( - 'typeerror', - [ - er.stack, - 'This is an error with npm itself. Please report this error at:', - ' <http://github.com/npm/npm/issues>' - ].join('\n') - ) - break - - case 'EISDIR': - log.error( - 'eisdir', - [ + case 'EEXIST': + log.error( + [ + er.message, + 'File exists: ' + er.path, + 'Move it away, and try again.' + ].join('\n') + ) + break + + case 'ENEEDAUTH': + log.error( + 'need auth', + [ + er.message, + 'You need to authorize this machine using `npm adduser`' + ].join('\n') + ) + break + + case 'EPEERINVALID': + var peerErrors = Object.keys(er.peersDepending).map(function (peer) { + return 'Peer ' + peer + ' wants ' + + er.packageName + '@' + er.peersDepending[peer] + }) + log.error('peerinvalid', [er.message].concat(peerErrors).join('\n')) + break + + case 'ECONNRESET': + case 'ENOTFOUND': + case 'ETIMEDOUT': + case 'EAI_FAIL': + log.error( + 'network', + [ + er.message, + 'This is most likely not a problem with npm itself', + 'and is related to network connectivity.', + 'In most cases you are behind a proxy or have bad network settings.', + '\nIf you are behind a proxy, please make sure that the', + "'proxy' config is set properly. See: 'npm help config'" + ].join('\n') + ) + break + + case 'ENOPACKAGEJSON': + log.error( + 'package.json', + [ + er.message, + 'This is most likely not a problem with npm itself.', + "npm can't find a package.json file in your current directory." + ].join('\n') + ) + break + + case 'ETARGET': + msg = [ er.message, - 'This is most likely not a problem with npm itself', - 'and is related to npm not being able to find a package.json in', - 'a package you are trying to install.' - ].join('\n') - ) - break - - default: - log.error('', er.message || er) - log.error( - '', - [ + 'This is most likely not a problem with npm itself.', + 'In most cases you or one of your dependencies are requesting', + "a package version that doesn't exist." + ] + if (er.parent) { + msg.push("\nIt was specified as a dependency of '" + er.parent + "'\n") + } + log.error('notarget', msg.join('\n')) + break + + case 'ENOTSUP': + if (er.required) { + log.error( + 'notsup', + [ + er.message, + 'Not compatible with your version of node/npm: ' + er.pkgid, + 'Required: ' + JSON.stringify(er.required), + 'Actual: ' + JSON.stringify({ + npm: npm.version, + node: npm.config.get('node-version') + }) + ].join('\n') + ) + break + } // else passthrough + /*eslint no-fallthrough:0*/ + + case 'ENOSPC': + log.error( + 'nospc', + [ + er.message, + 'This is most likely not a problem with npm itself', + 'and is related to insufficient space on your system.' + ].join('\n') + ) + break + + case 'EROFS': + log.error( + 'rofs', + [ + er.message, + 'This is most likely not a problem with npm itself', + 'and is related to the file system being read-only.', + '\nOften virtualized file systems, or other file systems', + "that don't support symlinks, give this error." + ].join('\n') + ) + break + + case 'ENOENT': + log.error( + 'enoent', + [ + er.message, + 'This is most likely not a problem with npm itself', + 'and is related to npm not being able to find a file.', + er.file ? "\nCheck if the file '" + er.file + "' is present." : '' + ].join('\n') + ) + break + + case 'EMISSINGARG': + case 'EUNKNOWNTYPE': + case 'EINVALIDTYPE': + case 'ETOOMANYARGS': + log.error( + 'typeerror', + [ + er.stack, + 'This is an error with npm itself. Please report this error at:', + ' <http://github.com/npm/npm/issues>' + ].join('\n') + ) + break + + case 'EISDIR': + log.error( + 'eisdir', + [ + er.message, + 'This is most likely not a problem with npm itself', + 'and is related to npm not being able to find a package.json in', + 'a package you are trying to install.' + ].join('\n') + ) + break + + default: + log.error('', er.message || er) + log.error( '', - 'If you need help, you may report this error at:', - ' <https://github.com/npm/npm/issues>' - ].join('\n') - ) - break + [ + '', + 'If you need help, you may report this error at:', + ' <https://github.com/npm/npm/issues>' + ].join('\n') + ) + break } exit(typeof er.errno === 'number' ? er.errno : 1) diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 766145f18..e2ec37c24 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -189,7 +189,6 @@ function runCmd (note, cmd, pkg, env, stage, wd, unsafe, cb) { } function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) { - function cb (er) { cb_.apply(null, arguments) log.resume() @@ -280,7 +279,6 @@ function makeEnv (data, prefix, env) { // express and others respect the NODE_ENV value. if (npm.config.get('production')) env.NODE_ENV = 'production' - } else if (!data.hasOwnProperty('_lifecycleEnv')) { Object.defineProperty(data, '_lifecycleEnv', { @@ -312,11 +310,10 @@ function makeEnv (data, prefix, env) { } } else { env[envKey] = String(data[i]) - env[envKey] = env[envKey].indexOf('\n') !== -1 ? - JSON.stringify(env[envKey]) : - env[envKey] + env[envKey] = env[envKey].indexOf('\n') !== -1 + ? JSON.stringify(env[envKey]) + : env[envKey] } - } if (prefix !== 'npm_package_') return env diff --git a/lib/utils/tar.js b/lib/utils/tar.js index 806bb75a9..8eb2311d0 100644 --- a/lib/utils/tar.js +++ b/lib/utils/tar.js @@ -235,9 +235,9 @@ function unpack_ (tarball, unpackTarget, dMode, fMode, uid, gid, cb) { dMode, fMode, uid, gid, function (er, folder) { - if (er) return cb(er) - readJson(path.resolve(folder, 'package.json'), cb) - }) + if (er) return cb(er) + readJson(path.resolve(folder, 'package.json'), cb) + }) }) } |