Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/completion/file-completion.js17
-rw-r--r--lib/utils/completion/installed-deep.js28
-rw-r--r--lib/utils/completion/installed-shallow.js54
-rw-r--r--lib/utils/depr-check.js6
-rw-r--r--lib/utils/error-handler.js565
-rw-r--r--lib/utils/git.js23
-rw-r--r--lib/utils/lifecycle.js258
-rw-r--r--lib/utils/link.js42
-rw-r--r--lib/utils/locker.js58
-rw-r--r--lib/utils/map-to-registry.js38
-rw-r--r--lib/utils/pulse-till-done.js8
-rw-r--r--lib/utils/read-local-package.js10
-rw-r--r--lib/utils/spawn.js12
-rw-r--r--lib/utils/umask.js6
-rw-r--r--lib/utils/warn-deprecated.js5
15 files changed, 623 insertions, 507 deletions
diff --git a/lib/utils/completion/file-completion.js b/lib/utils/completion/file-completion.js
index 6ce2f8346..78777a025 100644
--- a/lib/utils/completion/file-completion.js
+++ b/lib/utils/completion/file-completion.js
@@ -1,21 +1,24 @@
module.exports = fileCompletion
-var mkdir = require("mkdirp")
- , path = require("path")
- , glob = require("glob")
+var mkdir = require('mkdirp')
+var path = require('path')
+var glob = require('glob')
function fileCompletion (root, req, depth, cb) {
- if (typeof cb !== "function") cb = depth, depth = Infinity
+ if (typeof cb !== 'function') {
+ cb = depth
+ depth = Infinity
+ }
mkdir(root, function (er) {
if (er) return cb(er)
// can be either exactly the req, or a descendent
- var pattern = root + "/{" + req + "," + req + "/**/*}"
- , opts = { mark: true, dot: true, maxDepth: depth }
+ var pattern = root + '/{' + req + ',' + req + '/**/*}'
+ var opts = { mark: true, dot: true, maxDepth: depth }
glob(pattern, opts, function (er, files) {
if (er) return cb(er)
return cb(null, (files || []).map(function (f) {
- var tail = f.substr(root.length + 1).replace(/^\//, "")
+ var tail = f.substr(root.length + 1).replace(/^\//, '')
return path.join(req, tail)
}))
})
diff --git a/lib/utils/completion/installed-deep.js b/lib/utils/completion/installed-deep.js
index 5fb67d263..146a4d790 100644
--- a/lib/utils/completion/installed-deep.js
+++ b/lib/utils/completion/installed-deep.js
@@ -1,21 +1,25 @@
module.exports = installedDeep
-var npm = require("../../npm.js")
- , readInstalled = require("read-installed")
+var npm = require('../../npm.js')
+var readInstalled = require('read-installed')
function installedDeep (opts, cb) {
var local
- , global
- , depth = npm.config.get("depth")
- , opt = { depth: depth, dev: true }
+ var global
+ var depth = npm.config.get('depth')
+ var opt = { depth: depth, dev: true }
- if (npm.config.get("global")) local = [], next()
- else readInstalled(npm.prefix, opt, function (er, data) {
- local = getNames(data || {})
+ if (npm.config.get('global')) {
+ local = []
next()
- })
+ } else {
+ readInstalled(npm.prefix, opt, function (er, data) {
+ local = getNames(data || {})
+ next()
+ })
+ }
- readInstalled(npm.config.get("prefix"), opt, function (er, data) {
+ readInstalled(npm.config.get('prefix'), opt, function (er, data) {
global = getNames(data || {})
next()
})
@@ -37,9 +41,9 @@ function installedDeep (opts, cb) {
function next () {
if (!local || !global) return
- if (!npm.config.get("global")) {
+ if (!npm.config.get('global')) {
global = global.map(function (g) {
- return [g, "-g"]
+ return [g, '-g']
})
}
var names = local.concat(global)
diff --git a/lib/utils/completion/installed-shallow.js b/lib/utils/completion/installed-shallow.js
index 8d64649d5..bf692fede 100644
--- a/lib/utils/completion/installed-shallow.js
+++ b/lib/utils/completion/installed-shallow.js
@@ -1,31 +1,39 @@
module.exports = installedShallow
-var npm = require("../../npm.js")
- , fs = require("graceful-fs")
- , path = require("path")
- , readJson = require("read-package-json")
- , asyncMap = require("slide").asyncMap
+var npm = require('../../npm.js')
+var fs = require('graceful-fs')
+var path = require('path')
+var readJson = require('read-package-json')
+var asyncMap = require('slide').asyncMap
function installedShallow (opts, filter, cb) {
- if (typeof cb !== "function") cb = filter, filter = null
+ if (typeof cb !== 'function') {
+ cb = filter
+ filter = null
+ }
var conf = opts.conf
- , args = conf.argv.remain
+ var args = conf.argv.remain
if (args.length > 3) return cb()
var local
- , global
- , localDir = npm.dir
- , globalDir = npm.globalDir
- if (npm.config.get("global")) local = [], next()
- else fs.readdir(localDir, function (er, pkgs) {
- local = (pkgs || []).filter(function (p) {
- return p.charAt(0) !== "."
- })
+ var global
+ var localDir = npm.dir
+ var globalDir = npm.globalDir
+ if (npm.config.get('global')) {
+ local = []
next()
- })
+ } else {
+ fs.readdir(localDir, function (er, pkgs) {
+ local = (pkgs || []).filter(function (p) {
+ return p.charAt(0) !== '.'
+ })
+ next()
+ })
+ }
+
fs.readdir(globalDir, function (er, pkgs) {
global = (pkgs || []).filter(function (p) {
- return p.charAt(0) !== "."
+ return p.charAt(0) !== '.'
})
next()
})
@@ -37,7 +45,7 @@ function installedShallow (opts, filter, cb) {
function filterInstalled (local, global, filter, cb) {
var fl
- , fg
+ var fg
if (!filter) {
fl = local
@@ -46,7 +54,7 @@ function filterInstalled (local, global, filter, cb) {
}
asyncMap(local, function (p, cb) {
- readJson(path.join(npm.dir, p, "package.json"), function (er, d) {
+ readJson(path.join(npm.dir, p, 'package.json'), function (er, d) {
if (!d || !filter(d)) return cb(null, [])
return cb(null, d.name)
})
@@ -57,7 +65,7 @@ function filterInstalled (local, global, filter, cb) {
var globalDir = npm.globalDir
asyncMap(global, function (p, cb) {
- readJson(path.join(globalDir, p, "package.json"), function (er, d) {
+ readJson(path.join(globalDir, p, 'package.json'), function (er, d) {
if (!d || !filter(d)) return cb(null, [])
return cb(null, d.name)
})
@@ -68,12 +76,12 @@ function filterInstalled (local, global, filter, cb) {
function next () {
if (!fg || !fl) return
- if (!npm.config.get("global")) {
+ if (!npm.config.get('global')) {
fg = fg.map(function (g) {
- return [g, "-g"]
+ return [g, '-g']
})
}
- console.error("filtered", fl, fg)
+ console.error('filtered', fl, fg)
return cb(null, fl.concat(fg))
}
}
diff --git a/lib/utils/depr-check.js b/lib/utils/depr-check.js
index 7166348b0..89cf40273 100644
--- a/lib/utils/depr-check.js
+++ b/lib/utils/depr-check.js
@@ -1,13 +1,13 @@
-var log = require("npmlog")
+var log = require('npmlog')
var deprecated = {}
- , deprWarned = {}
+var deprWarned = {}
module.exports = function deprCheck (data) {
if (deprecated[data._id]) data.deprecated = deprecated[data._id]
if (data.deprecated) deprecated[data._id] = data.deprecated
else return
if (!deprWarned[data._id]) {
deprWarned[data._id] = true
- log.warn("deprecated", "%s: %s", data._id, data.deprecated)
+ log.warn('deprecated', '%s: %s', data._id, data.deprecated)
}
}
diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js
index 09dca8a94..10bf7b5a6 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -2,45 +2,47 @@
module.exports = errorHandler
var cbCalled = false
- , log = require("npmlog")
- , npm = require("../npm.js")
- , rm = require("rimraf")
- , itWorked = false
- , path = require("path")
- , wroteLogFile = false
- , exitCode = 0
- , rollbacks = npm.rollbacks
- , chain = require("slide").chain
- , writeStream = require("fs-write-stream-atomic")
- , nameValidator = require("validate-npm-package-name")
-
-
-process.on("exit", function (code) {
+var log = require('npmlog')
+var npm = require('../npm.js')
+var rm = require('rimraf')
+var itWorked = false
+var path = require('path')
+var wroteLogFile = false
+var exitCode = 0
+var rollbacks = npm.rollbacks
+var chain = require('slide').chain
+var writeStream = require('fs-write-stream-atomic')
+var nameValidator = require('validate-npm-package-name')
+
+process.on('exit', function (code) {
log.disableProgress()
if (!npm.config || !npm.config.loaded) return
if (code) itWorked = false
- if (itWorked) log.info("ok")
+ if (itWorked) log.info('ok')
else {
if (!cbCalled) {
- log.error("", "cb() never called!")
+ log.error('', 'cb() never called!')
}
if (wroteLogFile) {
// just a line break
- if (log.levels[log.level] <= log.levels.error) console.error("")
-
- log.error("",
- ["Please include the following file with any support request:"
- ," " + path.resolve("npm-debug.log")
- ].join("\n"))
+ if (log.levels[log.level] <= log.levels.error) console.error('')
+
+ log.error(
+ '',
+ [
+ 'Please include the following file with any support request:',
+ ' ' + path.resolve('npm-debug.log')
+ ].join('\n')
+ )
wroteLogFile = false
}
if (code) {
- log.error("code", code)
+ log.error('code', code)
}
}
- var doExit = npm.config.get("_exit")
+ var doExit = npm.config.get('_exit')
if (doExit) {
// actually exit.
if (exitCode === 0 && !itWorked) {
@@ -55,9 +57,9 @@ process.on("exit", function (code) {
function exit (code, noLog) {
exitCode = exitCode || process.exitCode || code
- var doExit = npm.config ? npm.config.get("_exit") : true
- log.verbose("exit", [code, doExit])
- if (log.level === "silent") noLog = true
+ var doExit = npm.config ? npm.config.get('_exit') : true
+ log.verbose('exit', [code, doExit])
+ if (log.level === 'silent') noLog = true
if (rollbacks.length) {
chain(rollbacks.map(function (f) {
@@ -66,22 +68,22 @@ function exit (code, noLog) {
}
}), function (er) {
if (er) {
- log.error("error rolling back", er)
+ log.error('error rolling back', er)
if (!code) errorHandler(er)
- else if (noLog) rm("npm-debug.log", reallyExit.bind(null, er))
+ else if (noLog) rm('npm-debug.log', reallyExit.bind(null, er))
else writeLogFile(reallyExit.bind(this, er))
} else {
if (!noLog && code) writeLogFile(reallyExit)
- else rm("npm-debug.log", reallyExit)
+ else rm('npm-debug.log', reallyExit)
}
})
rollbacks.length = 0
}
else if (code && !noLog) writeLogFile(reallyExit)
- else rm("npm-debug.log", reallyExit)
+ else rm('npm-debug.log', reallyExit)
function reallyExit (er) {
- if (er && !code) code = typeof er.errno === "number" ? er.errno : 1
+ if (er && !code) code = typeof er.errno === 'number' ? er.errno : 1
// truncate once it's been written.
log.record.length = 0
@@ -91,299 +93,384 @@ function exit (code, noLog) {
// just emit a fake exit event.
// if we're really exiting, then let it exit on its own, so that
// in-process stuff can finish or clean up first.
- if (!doExit) process.emit("exit", code)
+ if (!doExit) process.emit('exit', code)
}
}
-
function errorHandler (er) {
log.disableProgress()
- // console.error("errorHandler", er)
+ // console.error('errorHandler', er)
if (!npm.config || !npm.config.loaded) {
// logging won't work unless we pretend that it's ready
- er = er || new Error("Exit prior to config file resolving.")
+ er = er || new Error('Exit prior to config file resolving.')
console.error(er.stack || er.message)
}
if (cbCalled) {
- er = er || new Error("Callback called more than once.")
+ er = er || new Error('Callback called more than once.')
}
cbCalled = true
if (!er) return exit(0)
- if (typeof er === "string") {
- log.error("", er)
+ if (typeof er === 'string') {
+ log.error('', er)
return exit(1, true)
} else if (!(er instanceof Error)) {
- log.error("weird error", er)
+ log.error('weird error', er)
return exit(1, true)
}
var m = er.code || er.message.match(/^(?:Error: )?(E[A-Z]+)/)
- if (m && !er.code) er.code = m
-
- ; [ "type"
- , "fstream_path"
- , "fstream_unc_path"
- , "fstream_type"
- , "fstream_class"
- , "fstream_finish_call"
- , "fstream_linkpath"
- , "stack"
- , "fstream_stack"
- , "statusCode"
- , "pkgid"
- ].forEach(function (k) {
- var v = er[k]
- if (!v) return
- if (k === "fstream_stack") v = v.join("\n")
- log.verbose(k, v)
- })
+ if (m && !er.code) {
+ er.code = m
+ }
- log.verbose("cwd", process.cwd())
-
- var os = require("os")
- // log.error("System", os.type() + " " + os.release())
- // log.error("command", process.argv.map(JSON.stringify).join(" "))
- // log.error("node -v", process.version)
- // log.error("npm -v", npm.version)
- log.error("", os.type() + " " + os.release())
- log.error("argv", process.argv.map(JSON.stringify).join(" "))
- log.error("node", process.version)
- log.error("npm ", "v" + npm.version)
-
- ; [ "file"
- , "path"
- , "code"
- , "errno"
- , "syscall"
- ].forEach(function (k) {
- var v = er[k]
- if (v) log.error(k, v)
- })
+ ;[
+ 'type',
+ 'fstream_path',
+ 'fstream_unc_path',
+ 'fstream_type',
+ 'fstream_class',
+ 'fstream_finish_call',
+ 'fstream_linkpath',
+ 'stack',
+ 'fstream_stack',
+ 'statusCode',
+ 'pkgid'
+ ].forEach(function (k) {
+ var v = er[k]
+ if (!v) return
+ if (k === 'fstream_stack') v = v.join('\n')
+ log.verbose(k, v)
+ })
+
+ log.verbose('cwd', process.cwd())
+
+ var os = require('os')
+ // log.error('System', os.type() + ' ' + os.release())
+ // log.error('command', process.argv.map(JSON.stringify).join(' '))
+ // log.error('node -v', process.version)
+ // log.error('npm -v', npm.version)
+ log.error('', os.type() + ' ' + os.release())
+ log.error('argv', process.argv.map(JSON.stringify).join(' '))
+ log.error('node', process.version)
+ log.error('npm ', 'v' + npm.version)
+
+ ;[
+ 'file',
+ 'path',
+ 'code',
+ 'errno',
+ 'syscall'
+ ].forEach(function (k) {
+ var v = er[k]
+ if (v) log.error(k, v)
+ })
// just a line break
- if (log.levels[log.level] <= log.levels.error) console.error("")
+ 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"))
+ 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"))
+ 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 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"))
+ case 'ELIFECYCLE':
+ log.error('', er.message)
+ 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("", ["","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"))
+ case 'ENOGIT':
+ 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."
- ,"","This is not a bug in npm."
- ,"Tell the package author to fix their package.json file."
- ].join("\n"), "JSON.parse")
+ 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?
- case "E404":
+ case 'E404':
var msg = [er.message]
- if (er.pkgid && er.pkgid !== "-") {
- msg.push("", "'" + er.pkgid + "' is not in the npm registry.")
+ if (er.pkgid && er.pkgid !== '-') {
+ msg.push('', "'" + er.pkgid + "' is not in the npm registry.")
var valResult = nameValidator(er.pkgid)
if (valResult.validForNewPackages) {
- msg.push("You should bug the author to publish it (or use the name yourself!)")
+ 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", "")
+ 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)
+ 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("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.")
+ 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"))
+ 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"))
+ 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"))
+ 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"))
+ 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"))
+ 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"))
+ 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"))
+ case 'ENEEDAUTH':
+ log.error(
+ 'need auth',
+ [
+ er.message,
+ 'You need to authorize this machine using `npm adduser`'
+ ].join('\n')
+ )
break
- case "EPEERINVALID":
+ case 'EPEERINVALID':
var peerErrors = Object.keys(er.peersDepending).map(function (peer) {
- return "Peer " + peer + " wants " + er.packageName + "@"
- + er.peersDepending[peer]
+ return 'Peer ' + peer + ' wants ' +
+ er.packageName + '@' + er.peersDepending[peer]
})
- log.error("peerinvalid", [er.message].concat(peerErrors).join("\n"))
+ 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"))
+ 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"))
+ 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":
- var 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"))
+ 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
- case "ENOTSUP":
+ 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"))
+ 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
-
- 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"))
+ /*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"))
+ 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"))
+ 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"))
+ 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
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"))
+ 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
}
- exit(typeof er.errno === "number" ? er.errno : 1)
+ exit(typeof er.errno === 'number' ? er.errno : 1)
}
var writingLogFile = false
@@ -392,22 +479,22 @@ function writeLogFile (cb) {
writingLogFile = true
wroteLogFile = true
- var fstr = writeStream("npm-debug.log")
- , os = require("os")
- , out = ""
+ var fstr = writeStream('npm-debug.log')
+ var os = require('os')
+ var out = ''
log.record.forEach(function (m) {
var pref = [m.id, m.level]
if (m.prefix) pref.push(m.prefix)
- pref = pref.join(" ")
+ pref = pref.join(' ')
m.message.trim().split(/\r?\n/).map(function (line) {
- return (pref + " " + line).trim()
+ return (pref + ' ' + line).trim()
}).forEach(function (line) {
out += line + os.EOL
})
})
fstr.end(out)
- fstr.on("close", cb)
+ fstr.on('close', cb)
}
diff --git a/lib/utils/git.js b/lib/utils/git.js
index 9c80ea553..2d9da1086 100644
--- a/lib/utils/git.js
+++ b/lib/utils/git.js
@@ -1,20 +1,19 @@
-
// handle some git configuration for windows
exports.spawn = spawnGit
exports.chainableExec = chainableExec
exports.whichAndExec = whichAndExec
-var exec = require("child_process").execFile
- , spawn = require("./spawn")
- , npm = require("../npm.js")
- , which = require("which")
- , git = npm.config.get("git")
- , assert = require("assert")
- , log = require("npmlog")
+var exec = require('child_process').execFile
+var spawn = require('./spawn')
+var npm = require('../npm.js')
+var which = require('which')
+var git = npm.config.get('git')
+var assert = require('assert')
+var log = require('npmlog')
function prefixGitArgs () {
- return process.platform === "win32" ? ["-c", "core.longpaths=true"] : []
+ return process.platform === 'win32' ? ['-c', 'core.longpaths=true'] : []
}
function execGit (args, options, cb) {
@@ -24,7 +23,7 @@ function execGit (args, options, cb) {
}
function spawnGit (args, options) {
- log.info("git", args)
+ log.info('git', args)
return spawn(git, prefixGitArgs().concat(args || []), options)
}
@@ -38,11 +37,11 @@ function whichGit (cb) {
}
function whichAndExec (args, options, cb) {
- assert.equal(typeof cb, "function", "no callback provided")
+ assert.equal(typeof cb, 'function', 'no callback provided')
// check for git
whichGit(function (err) {
if (err) {
- err.code = "ENOGIT"
+ err.code = 'ENOGIT'
return cb(err)
}
diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js
index 8f9233488..7d5699fb5 100644
--- a/lib/utils/lifecycle.js
+++ b/lib/utils/lifecycle.js
@@ -2,20 +2,20 @@ exports = module.exports = lifecycle
exports.cmd = cmd
exports.makeEnv = makeEnv
-var log = require("npmlog")
-var spawn = require("./spawn")
-var npm = require("../npm.js")
-var path = require("path")
-var fs = require("graceful-fs")
-var chain = require("slide").chain
-var Stream = require("stream").Stream
-var PATH = "PATH"
-var uidNumber = require("uid-number")
-var umask = require("./umask")
-
-// windows calls it's path "Path" usually, but this is not guaranteed.
-if (process.platform === "win32") {
- PATH = "Path"
+var log = require('npmlog')
+var spawn = require('./spawn')
+var npm = require('../npm.js')
+var path = require('path')
+var fs = require('graceful-fs')
+var chain = require('slide').chain
+var Stream = require('stream').Stream
+var PATH = 'PATH'
+var uidNumber = require('uid-number')
+var umask = require('./umask')
+
+// windows calls it's path 'Path' usually, but this is not guaranteed.
+if (process.platform === 'win32') {
+ PATH = 'Path'
Object.keys(process.env).forEach(function (e) {
if (e.match(/^PATH$/i)) {
PATH = e
@@ -24,12 +24,21 @@ if (process.platform === "win32") {
}
function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
- if (typeof cb !== "function") cb = failOk, failOk = false
- if (typeof cb !== "function") cb = unsafe, unsafe = false
- if (typeof cb !== "function") cb = wd, wd = null
+ if (typeof cb !== 'function') {
+ cb = failOk
+ failOk = false
+ }
+ if (typeof cb !== 'function') {
+ cb = unsafe
+ unsafe = false
+ }
+ if (typeof cb !== 'function') {
+ cb = wd
+ wd = null
+ }
while (pkg && pkg._data) pkg = pkg._data
- if (!pkg) return cb(new Error("Invalid package data"))
+ if (!pkg) return cb(new Error('Invalid package data'))
log.info(stage, pkg._id)
if (!pkg.scripts || npm.config.get('ignore-scripts')) pkg.scripts = {}
@@ -37,12 +46,15 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
validWd(wd || path.resolve(npm.dir, pkg.name), function (er, wd) {
if (er) return cb(er)
- unsafe = unsafe || npm.config.get("unsafe-perm")
+ unsafe = unsafe || npm.config.get('unsafe-perm')
- if ((wd.indexOf(npm.dir) !== 0 || path.basename(wd) !== pkg.name)
- && !unsafe && pkg.scripts[stage]) {
- log.warn( "cannot run in wd", "%s %s (wd=%s)"
- , pkg._id, pkg.scripts[stage], wd)
+ if ((wd.indexOf(npm.dir) !== 0 || path.basename(wd) !== pkg.name) &&
+ !unsafe &&
+ pkg.scripts[stage]) {
+ log.warn(
+ 'cannot run in wd',
+ '%s %s (wd=%s)', pkg._id, pkg.scripts[stage], wd
+ )
return cb()
}
@@ -52,38 +64,31 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
env.npm_node_execpath = env.NODE = env.NODE || process.execPath
env.npm_execpath = require.main.filename
- // "nobody" typically doesn't have permission to write to /tmp
+ // 'nobody' typically doesn't have permission to write to /tmp
// even if it's never used, sh freaks out.
- if (!npm.config.get("unsafe-perm")) env.TMPDIR = wd
+ if (!npm.config.get('unsafe-perm')) env.TMPDIR = wd
lifecycle_(pkg, stage, wd, env, unsafe, failOk, cb)
})
}
-function checkForLink (pkg, cb) {
- var f = path.join(npm.dir, pkg.name)
- fs.lstat(f, function (er, s) {
- cb(null, !(er || !s.isSymbolicLink()))
- })
-}
-
function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
var pathArr = []
- , p = wd.split("node_modules")
- , acc = path.resolve(p.shift())
+ var p = wd.split('node_modules')
+ var acc = path.resolve(p.shift())
p.forEach(function (pp) {
- pathArr.unshift(path.join(acc, "node_modules", ".bin"))
- acc = path.join(acc, "node_modules", pp)
+ pathArr.unshift(path.join(acc, 'node_modules', '.bin'))
+ acc = path.join(acc, 'node_modules', pp)
})
- pathArr.unshift(path.join(acc, "node_modules", ".bin"))
+ pathArr.unshift(path.join(acc, 'node_modules', '.bin'))
// we also unshift the bundled node-gyp-bin folder so that
// the bundled one will be used for installing things.
- pathArr.unshift(path.join(__dirname, "..", "..", "bin", "node-gyp-bin"))
+ pathArr.unshift(path.join(__dirname, '..', '..', 'bin', 'node-gyp-bin'))
if (env[PATH]) pathArr.push(env[PATH])
- env[PATH] = pathArr.join(process.platform === "win32" ? ";" : ":")
+ env[PATH] = pathArr.join(process.platform === 'win32' ? ';' : ':')
var packageLifecycle = pkg.scripts && pkg.scripts.hasOwnProperty(stage)
@@ -94,21 +99,24 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
function done (er) {
if (er) {
- if (npm.config.get("force")) {
- log.info("forced, continuing", er)
+ if (npm.config.get('force')) {
+ log.info('forced, continuing', er)
er = null
} else if (failOk) {
- log.warn("continuing anyway", er.message)
+ log.warn('continuing anyway', er.message)
er = null
}
}
cb(er)
}
- chain
- ( [ packageLifecycle && [runPackageLifecycle, pkg, env, wd, unsafe]
- , [runHookLifecycle, pkg, env, wd, unsafe] ]
- , done )
+ chain(
+ [
+ packageLifecycle && [runPackageLifecycle, pkg, env, wd, unsafe],
+ [runHookLifecycle, pkg, env, wd, unsafe]
+ ],
+ done
+ )
}
function validWd (d, cb) {
@@ -116,7 +124,7 @@ function validWd (d, cb) {
if (er || !st.isDirectory()) {
var p = path.dirname(d)
if (p === d) {
- return cb(new Error("Could not find suitable wd"))
+ return cb(new Error('Could not find suitable wd'))
}
return validWd(p, cb)
}
@@ -127,17 +135,16 @@ function validWd (d, cb) {
function runPackageLifecycle (pkg, env, wd, unsafe, cb) {
// run package lifecycle scripts in the package root, or the nearest parent.
var stage = env.npm_lifecycle_event
- , cmd = env.npm_lifecycle_script
+ var cmd = env.npm_lifecycle_script
- var note = "\n> " + pkg._id + " " + stage + " " + wd
- + "\n> " + cmd + "\n"
+ var note = '\n> ' + pkg._id + ' ' + stage + ' ' + wd +
+ '\n> ' + cmd + '\n'
runCmd(note, cmd, pkg, env, stage, wd, unsafe, cb)
}
-
var running = false
var queue = []
-function dequeue() {
+function dequeue () {
running = false
if (queue.length) {
var r = queue.shift()
@@ -153,17 +160,17 @@ function runCmd (note, cmd, pkg, env, stage, wd, unsafe, cb) {
running = true
log.pause()
- var user = unsafe ? null : npm.config.get("user")
- , group = unsafe ? null : npm.config.get("group")
+ var user = unsafe ? null : npm.config.get('user')
+ var group = unsafe ? null : npm.config.get('group')
if (log.level !== 'silent') {
log.clearProgress()
console.log(note)
log.showProgress()
}
- log.verbose("unsafe-perm in lifecycle", unsafe)
+ log.verbose('unsafe-perm in lifecycle', unsafe)
- if (process.platform === "win32") {
+ if (process.platform === 'win32') {
unsafe = true
}
@@ -184,34 +191,35 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
process.nextTick(dequeue)
}
- var conf = { cwd: wd
- , env: env
- , stdio: [ 0, 1, 2 ]
- }
+ var conf = {
+ cwd: wd,
+ env: env,
+ stdio: [ 0, 1, 2 ]
+ }
if (!unsafe) {
conf.uid = uid ^ 0
conf.gid = gid ^ 0
}
- var sh = "sh"
- var shFlag = "-c"
+ var sh = 'sh'
+ var shFlag = '-c'
- if (process.platform === "win32") {
- sh = process.env.comspec || "cmd"
- shFlag = "/c"
+ if (process.platform === 'win32') {
+ sh = process.env.comspec || 'cmd'
+ shFlag = '/c'
conf.windowsVerbatimArguments = true
}
log.disableProgress()
var proc = spawn(sh, [shFlag, cmd], conf)
- proc.on("error", procError)
- proc.on("close", function (code, signal) {
+ proc.on('error', procError)
+ proc.on('close', function (code, signal) {
if (signal) {
- process.kill(process.pid, signal);
+ process.kill(process.pid, signal)
} else if (code) {
- var er = new Error("Exit status " + code)
+ var er = new Error('Exit status ' + code)
}
procError(er)
})
@@ -219,12 +227,11 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
function procError (er) {
log.enableProgress()
if (er && !npm.ROLLBACK) {
- log.info(pkg._id, "Failed to exec "+stage+" script")
- er.message = pkg._id + " "
- + stage + ": `" + cmd +"`\n"
- + er.message
- if (er.code !== "EPERM") {
- er.code = "ELIFECYCLE"
+ log.info(pkg._id, 'Failed to exec ' + stage + ' script')
+ er.message = pkg._id + ' ' + stage + ': `' + cmd + '`\n' +
+ er.message
+ if (er.code !== 'EPERM') {
+ er.code = 'ELIFECYCLE'
}
er.pkgid = pkg._id
er.stage = stage
@@ -232,33 +239,30 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
er.pkgname = pkg.name
return cb(er)
} else if (er) {
- log.error(pkg._id+"."+stage, er)
- log.error(pkg._id+"."+stage, "continuing anyway")
+ log.error(pkg._id + '.' + stage, er)
+ log.error(pkg._id + '.' + stage, 'continuing anyway')
return cb()
}
cb(er)
}
}
-
function runHookLifecycle (pkg, env, wd, unsafe, cb) {
// check for a hook script, run if present.
var stage = env.npm_lifecycle_event
- , hook = path.join(npm.dir, ".hooks", stage)
- , user = unsafe ? null : npm.config.get("user")
- , group = unsafe ? null : npm.config.get("group")
- , cmd = hook
+ var hook = path.join(npm.dir, '.hooks', stage)
+ var cmd = hook
fs.stat(hook, function (er) {
if (er) return cb()
- var note = "\n> " + pkg._id + " " + stage + " " + wd
- + "\n> " + cmd
+ var note = '\n> ' + pkg._id + ' ' + stage + ' ' + wd +
+ '\n> ' + cmd
runCmd(note, hook, pkg, env, stage, wd, unsafe, cb)
})
}
function makeEnv (data, prefix, env) {
- prefix = prefix || "npm_package_"
+ prefix = prefix || 'npm_package_'
if (!env) {
env = {}
for (var i in process.env) if (!i.match(/^npm_/)) {
@@ -266,83 +270,89 @@ function makeEnv (data, prefix, env) {
}
// npat asks for tap output
- if (npm.config.get("npat")) env.TAP = 1
+ if (npm.config.get('npat')) env.TAP = 1
// express and others respect the NODE_ENV value.
- if (npm.config.get("production")) env.NODE_ENV = "production"
+ if (npm.config.get('production')) env.NODE_ENV = 'production'
- } else if (!data.hasOwnProperty("_lifecycleEnv")) {
- Object.defineProperty(data, "_lifecycleEnv",
- { value : env
- , enumerable : false
- })
+ } else if (!data.hasOwnProperty('_lifecycleEnv')) {
+ Object.defineProperty(data, '_lifecycleEnv',
+ {
+ value: env,
+ enumerable: false
+ }
+ )
}
- for (var i in data) if (i.charAt(0) !== "_") {
- var envKey = (prefix+i).replace(/[^a-zA-Z0-9_]/g, '_')
- if (i === "readme") {
+ for (i in data) if (i.charAt(0) !== '_') {
+ var envKey = (prefix + i).replace(/[^a-zA-Z0-9_]/g, '_')
+ if (i === 'readme') {
continue
}
- if (data[i] && typeof(data[i]) === "object") {
+ if (data[i] && typeof data[i] === 'object') {
try {
// quick and dirty detection for cyclical structures
JSON.stringify(data[i])
- makeEnv(data[i], envKey+"_", env)
+ makeEnv(data[i], envKey + '_', env)
} catch (ex) {
// usually these are package objects.
// just get the path and basic details.
var d = data[i]
- makeEnv( { name: d.name, version: d.version, path:d.path }
- , envKey+"_", env)
+ makeEnv(
+ { name: d.name, version: d.version, path: d.path },
+ envKey + '_',
+ env
+ )
}
} else {
env[envKey] = String(data[i])
- env[envKey] = -1 !== env[envKey].indexOf("\n")
- ? 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
+ if (prefix !== 'npm_package_') return env
- prefix = "npm_config_"
+ prefix = 'npm_config_'
var pkgConfig = {}
- , keys = npm.config.keys
- , pkgVerConfig = {}
- , namePref = data.name + ":"
- , verPref = data.name + "@" + data.version + ":"
+ var keys = npm.config.keys
+ var pkgVerConfig = {}
+ var namePref = data.name + ':'
+ var verPref = data.name + '@' + data.version + ':'
keys.forEach(function (i) {
- if (i.charAt(0) === "_" && i.indexOf("_"+namePref) !== 0) {
+ if (i.charAt(0) === '_' && i.indexOf('_' + namePref) !== 0) {
return
}
var value = npm.config.get(i)
if (value instanceof Stream || Array.isArray(value)) return
if (i.match(/umask/)) value = umask.toString(value)
- if (!value) value = ""
- else if (typeof value === "number") value = "" + value
- else if (typeof value !== "string") value = JSON.stringify(value)
+ if (!value) value = ''
+ else if (typeof value === 'number') value = '' + value
+ else if (typeof value !== 'string') value = JSON.stringify(value)
- value = -1 !== value.indexOf("\n")
+ value = value.indexOf('\n') !== -1
? JSON.stringify(value)
: value
- i = i.replace(/^_+/, "")
+ i = i.replace(/^_+/, '')
+ var k
if (i.indexOf(namePref) === 0) {
- var k = i.substr(namePref.length).replace(/[^a-zA-Z0-9_]/g, "_")
- pkgConfig[ k ] = value
+ k = i.substr(namePref.length).replace(/[^a-zA-Z0-9_]/g, '_')
+ pkgConfig[k] = value
} else if (i.indexOf(verPref) === 0) {
- var k = i.substr(verPref.length).replace(/[^a-zA-Z0-9_]/g, "_")
- pkgVerConfig[ k ] = value
+ k = i.substr(verPref.length).replace(/[^a-zA-Z0-9_]/g, '_')
+ pkgVerConfig[k] = value
}
- var envKey = (prefix+i).replace(/[^a-zA-Z0-9_]/g, "_")
+ var envKey = (prefix + i).replace(/[^a-zA-Z0-9_]/g, '_')
env[envKey] = value
})
- prefix = "npm_package_config_"
+ prefix = 'npm_package_config_'
;[pkgConfig, pkgVerConfig].forEach(function (conf) {
for (var i in conf) {
- var envKey = (prefix+i)
+ var envKey = (prefix + i)
env[envKey] = conf[i]
}
})
@@ -352,10 +362,10 @@ function makeEnv (data, prefix, env) {
function cmd (stage) {
function CMD (args, cb) {
- npm.commands["run-script"]([stage].concat(args), cb)
+ npm.commands['run-script']([stage].concat(args), cb)
}
- CMD.usage = "npm "+stage+" [-- <args>]"
- var installedShallow = require("./completion/installed-shallow.js")
+ CMD.usage = 'npm ' + stage + ' [-- <args>]'
+ var installedShallow = require('./completion/installed-shallow.js')
CMD.completion = function (opts, cb) {
installedShallow(opts, function (d) {
return d.scripts && d.scripts[stage]
diff --git a/lib/utils/link.js b/lib/utils/link.js
index 1376f292f..1091f4683 100644
--- a/lib/utils/link.js
+++ b/lib/utils/link.js
@@ -1,13 +1,12 @@
-
module.exports = link
link.ifExists = linkIfExists
-var fs = require("graceful-fs")
- , chain = require("slide").chain
- , mkdir = require("mkdirp")
- , rm = require("./gently-rm.js")
- , path = require("path")
- , npm = require("../npm.js")
+var fs = require('graceful-fs')
+var chain = require('slide').chain
+var mkdir = require('mkdirp')
+var rm = require('./gently-rm.js')
+var path = require('path')
+var npm = require('../npm.js')
function linkIfExists (from, to, gently, cb) {
fs.stat(from, function (er) {
@@ -27,13 +26,19 @@ function linkIfExists (from, to, gently, cb) {
}
function link (from, to, gently, abs, cb) {
- if (typeof cb !== "function") cb = abs, abs = false
- if (typeof cb !== "function") cb = gently, gently = null
- if (npm.config.get("force")) gently = false
+ if (typeof cb !== 'function') {
+ cb = abs
+ abs = false
+ }
+ if (typeof cb !== 'function') {
+ cb = gently
+ gently = null
+ }
+ if (npm.config.get('force')) gently = false
to = path.resolve(to)
var target = from = path.resolve(from)
- if (!abs && process.platform !== "win32") {
+ if (!abs && process.platform !== 'win32') {
// junctions on windows must be absolute
target = path.relative(path.dirname(to), from)
// if there is no folder in common, then it will be much
@@ -41,10 +46,13 @@ function link (from, to, gently, abs, cb) {
if (target.length >= from.length) target = from
}
- chain
- ( [ [fs, "stat", from]
- , [rm, to, gently]
- , [mkdir, path.dirname(to)]
- , [fs, "symlink", target, to, "junction"] ]
- , cb)
+ chain(
+ [
+ [fs, 'stat', from],
+ [rm, to, gently],
+ [mkdir, path.dirname(to)],
+ [fs, 'symlink', target, to, 'junction']
+ ],
+ cb
+ )
}
diff --git a/lib/utils/locker.js b/lib/utils/locker.js
index 4a8f37271..9cd8b2c4f 100644
--- a/lib/utils/locker.js
+++ b/lib/utils/locker.js
@@ -1,38 +1,39 @@
-var crypto = require("crypto")
-var resolve = require("path").resolve
+var crypto = require('crypto')
+var resolve = require('path').resolve
-var lockfile = require("lockfile")
-var log = require("npmlog")
-var mkdirp = require("mkdirp")
+var lockfile = require('lockfile')
+var log = require('npmlog')
-var npm = require("../npm.js")
+var npm = require('../npm.js')
var correctMkdir = require('../utils/correct-mkdir.js')
var installLocks = {}
function lockFileName (base, name) {
- var c = name.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
- , p = resolve(base, name)
- , h = crypto.createHash("sha1").update(p).digest("hex")
- , l = resolve(npm.cache, "_locks")
+ var c = name.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '')
+ var p = resolve(base, name)
+ var h = crypto.createHash('sha1').update(p).digest('hex')
+ var l = resolve(npm.cache, '_locks')
- return resolve(l, c.substr(0, 24)+"-"+h.substr(0, 16)+".lock")
+ return resolve(l, c.substr(0, 24) + '-' + h.substr(0, 16) + '.lock')
}
function lock (base, name, cb) {
- var lockDir = resolve(npm.cache, "_locks")
+ var lockDir = resolve(npm.cache, '_locks')
correctMkdir(lockDir, function (er) {
if (er) return cb(er)
- var opts = { stale: npm.config.get("cache-lock-stale")
- , retries: npm.config.get("cache-lock-retries")
- , wait: npm.config.get("cache-lock-wait") }
+ var opts = {
+ stale: npm.config.get('cache-lock-stale'),
+ retries: npm.config.get('cache-lock-retries'),
+ wait: npm.config.get('cache-lock-wait')
+ }
var lf = lockFileName(base, name)
lockfile.lock(lf, opts, function (er) {
- if (er) log.warn("locking", lf, "failed", er)
+ if (er) log.warn('locking', lf, 'failed', er)
if (!er) {
- log.verbose("lock", "using", lf, "for", resolve(base, name))
+ log.verbose('lock', 'using', lf, 'for', resolve(base, name))
installLocks[lf] = true
}
@@ -43,33 +44,30 @@ function lock (base, name, cb) {
function unlock (base, name, cb) {
var lf = lockFileName(base, name)
- , locked = installLocks[lf]
+ var locked = installLocks[lf]
if (locked === false) {
return process.nextTick(cb)
- }
- else if (locked === true) {
+ } else if (locked === true) {
lockfile.unlock(lf, function (er) {
if (er) {
- log.warn("unlocking", lf, "failed", er)
- }
- else {
+ log.warn('unlocking', lf, 'failed', er)
+ } else {
installLocks[lf] = false
- log.verbose("unlock", "done using", lf, "for", resolve(base, name))
+ log.verbose('unlock', 'done using', lf, 'for', resolve(base, name))
}
cb(er)
})
- }
- else {
+ } else {
var notLocked = new Error(
- "Attempt to unlock " + resolve(base, name) + ", which hasn't been locked"
+ 'Attempt to unlock ' + resolve(base, name) + ", which hasn't been locked"
)
- notLocked.code = "ENOTLOCKED"
+ notLocked.code = 'ENOTLOCKED'
throw notLocked
}
}
module.exports = {
- lock : lock,
- unlock : unlock
+ lock: lock,
+ unlock: unlock
}
diff --git a/lib/utils/map-to-registry.js b/lib/utils/map-to-registry.js
index bd68a26d4..34046d191 100644
--- a/lib/utils/map-to-registry.js
+++ b/lib/utils/map-to-registry.js
@@ -1,56 +1,56 @@
-var url = require("url")
+var url = require('url')
-var log = require("npmlog")
- , npa = require("npm-package-arg")
+var log = require('npmlog')
+var npa = require('npm-package-arg')
module.exports = mapToRegistry
-function mapToRegistry(name, config, cb) {
- log.silly("mapToRegistry", "name", name)
+function mapToRegistry (name, config, cb) {
+ log.silly('mapToRegistry', 'name', name)
var registry
// the name itself takes precedence
var data = npa(name)
if (data.scope) {
// the name is definitely scoped, so escape now
- name = name.replace("/", "%2f")
+ name = name.replace('/', '%2f')
- log.silly("mapToRegistry", "scope (from package name)", data.scope)
+ log.silly('mapToRegistry', 'scope (from package name)', data.scope)
- registry = config.get(data.scope + ":registry")
+ registry = config.get(data.scope + ':registry')
if (!registry) {
- log.verbose("mapToRegistry", "no registry URL found in name for scope", data.scope)
+ log.verbose('mapToRegistry', 'no registry URL found in name for scope', data.scope)
}
}
// ...then --scope=@scope or --scope=scope
- var scope = config.get("scope")
+ var scope = config.get('scope')
if (!registry && scope) {
// I'm an enabler, sorry
- if (scope.charAt(0) !== "@") scope = "@" + scope
+ if (scope.charAt(0) !== '@') scope = '@' + scope
- log.silly("mapToRegistry", "scope (from config)", scope)
+ log.silly('mapToRegistry', 'scope (from config)', scope)
- registry = config.get(scope + ":registry")
+ registry = config.get(scope + ':registry')
if (!registry) {
- log.verbose("mapToRegistry", "no registry URL found in config for scope", scope)
+ log.verbose('mapToRegistry', 'no registry URL found in config for scope', scope)
}
}
// ...and finally use the default registry
if (!registry) {
- log.silly("mapToRegistry", "using default registry")
- registry = config.get("registry")
+ log.silly('mapToRegistry', 'using default registry')
+ registry = config.get('registry')
}
- log.silly("mapToRegistry", "registry", registry)
+ log.silly('mapToRegistry', 'registry', registry)
var auth = config.getCredentialsByURI(registry)
// normalize registry URL so resolution doesn't drop a piece of registry URL
- var normalized = registry.slice(-1) !== "/" ? registry+"/" : registry
+ var normalized = registry.slice(-1) !== '/' ? registry + '/' : registry
var uri = url.resolve(normalized, name)
- log.silly("mapToRegistry", "uri", uri)
+ log.silly('mapToRegistry', 'uri', uri)
cb(null, uri, auth, normalized)
}
diff --git a/lib/utils/pulse-till-done.js b/lib/utils/pulse-till-done.js
index 85fb288d1..fc6450e00 100644
--- a/lib/utils/pulse-till-done.js
+++ b/lib/utils/pulse-till-done.js
@@ -1,4 +1,4 @@
-"use strict"
+'use strict'
var validate = require('aproba')
var log = require('npmlog')
@@ -7,13 +7,13 @@ var pulse
module.exports = function (prefix, cb) {
validate('SF', [prefix, cb])
- if (!pulsers ++) {
+ if (!pulsers++) {
pulse = setInterval(function () {
- log.gauge.pulse("network")
+ log.gauge.pulse('network')
}, 250)
}
return function () {
- if (!-- pulsers) {
+ if (!--pulsers) {
clearInterval(pulse)
}
cb.apply(null, arguments)
diff --git a/lib/utils/read-local-package.js b/lib/utils/read-local-package.js
index ca6d61321..27ca7b4e3 100644
--- a/lib/utils/read-local-package.js
+++ b/lib/utils/read-local-package.js
@@ -1,12 +1,12 @@
exports = module.exports = readLocalPkg
-var npm = require("../npm.js")
- , readJson = require("read-package-json")
+var npm = require('../npm.js')
+var readJson = require('read-package-json')
function readLocalPkg (cb) {
- if (npm.config.get("global")) return cb()
- var path = require("path")
- readJson(path.resolve(npm.prefix, "package.json"), function (er, d) {
+ if (npm.config.get('global')) return cb()
+ var path = require('path')
+ readJson(path.resolve(npm.prefix, 'package.json'), function (er, d) {
return cb(er, d && d.name)
})
}
diff --git a/lib/utils/spawn.js b/lib/utils/spawn.js
index 74684521f..e389d83e0 100644
--- a/lib/utils/spawn.js
+++ b/lib/utils/spawn.js
@@ -1,16 +1,16 @@
module.exports = spawn
-var _spawn = require("child_process").spawn
-var EventEmitter = require("events").EventEmitter
+var _spawn = require('child_process').spawn
+var EventEmitter = require('events').EventEmitter
function spawn (cmd, args, options) {
var raw = _spawn(cmd, args, options)
var cooked = new EventEmitter()
- raw.on("error", function (er) {
+ raw.on('error', function (er) {
er.file = cmd
- cooked.emit("error", er)
- }).on("close", function (code, signal) {
+ cooked.emit('error', er)
+ }).on('close', function (code, signal) {
// Create ENOENT error because Node.js v0.8 will not emit
// an `error` event if the command could not be found.
if (code === 127) {
@@ -21,7 +21,7 @@ function spawn (cmd, args, options) {
er.file = cmd
cooked.emit('error', er)
} else {
- cooked.emit("close", code, signal)
+ cooked.emit('close', code, signal)
}
})
diff --git a/lib/utils/umask.js b/lib/utils/umask.js
index 6ccb4a119..2dde1befa 100644
--- a/lib/utils/umask.js
+++ b/lib/utils/umask.js
@@ -1,5 +1,5 @@
-var umask = require("umask")
-var npmlog = require("npmlog")
+var umask = require('umask')
+var npmlog = require('npmlog')
var _fromString = umask.fromString
module.exports = umask
@@ -8,7 +8,7 @@ module.exports = umask
umask.fromString = function (val) {
_fromString(val, function (err, result) {
if (err) {
- npmlog.warn("invalid umask", err.message)
+ npmlog.warn('invalid umask', err.message)
}
val = result
})
diff --git a/lib/utils/warn-deprecated.js b/lib/utils/warn-deprecated.js
index ec821b9bd..fe5c5ec82 100644
--- a/lib/utils/warn-deprecated.js
+++ b/lib/utils/warn-deprecated.js
@@ -1,6 +1,6 @@
module.exports = warnDeprecated
-var log = require("npmlog")
+var log = require('npmlog')
var deprecations = {}
@@ -11,8 +11,7 @@ function warnDeprecated (type) {
deprecations[type] = {}
messages.forEach(function (m) { log.warn(type, m) })
}
- }
- else {
+ } else {
if (!deprecations[type]) deprecations[type] = {}
if (!deprecations[type][instance]) {