diff options
author | isaacs <i@izs.me> | 2013-05-14 14:37:59 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-05-14 14:37:59 -0700 |
commit | f7b10f5445248981a39f0f82e10fca7234fca08a (patch) | |
tree | 839a30d65dcdc93e3e7ddaebe2666eb1c27fb306 /deps/npm/lib | |
parent | ca38def146c2255503103159677df40c169ccefa (diff) | |
download | android-node-v8-f7b10f5445248981a39f0f82e10fca7234fca08a.tar.gz android-node-v8-f7b10f5445248981a39f0f82e10fca7234fca08a.tar.bz2 android-node-v8-f7b10f5445248981a39f0f82e10fca7234fca08a.zip |
npm: Upgrade to 1.2.21
Diffstat (limited to 'deps/npm/lib')
-rw-r--r-- | deps/npm/lib/adduser.js | 31 | ||||
-rw-r--r-- | deps/npm/lib/bugs.js | 3 | ||||
-rw-r--r-- | deps/npm/lib/build.js | 48 | ||||
-rw-r--r-- | deps/npm/lib/cache.js | 112 | ||||
-rw-r--r-- | deps/npm/lib/config.js | 5 | ||||
-rw-r--r-- | deps/npm/lib/docs.js | 3 | ||||
-rw-r--r-- | deps/npm/lib/edit.js | 12 | ||||
-rw-r--r-- | deps/npm/lib/explore.js | 12 | ||||
-rw-r--r-- | deps/npm/lib/help.js | 10 | ||||
-rw-r--r-- | deps/npm/lib/init.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/install.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/npm.js | 4 | ||||
-rw-r--r-- | deps/npm/lib/rebuild.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/submodule.js | 76 | ||||
-rw-r--r-- | deps/npm/lib/unbuild.js | 36 | ||||
-rw-r--r-- | deps/npm/lib/utils/completion/remote-packages.js | 58 | ||||
-rw-r--r-- | deps/npm/lib/utils/completion/users.js | 23 | ||||
-rw-r--r-- | deps/npm/lib/utils/error-handler.js | 19 | ||||
-rw-r--r-- | deps/npm/lib/utils/exec.js | 85 | ||||
-rw-r--r-- | deps/npm/lib/utils/fetch.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/utils/find-prefix.js | 7 | ||||
-rw-r--r-- | deps/npm/lib/utils/lifecycle.js | 15 | ||||
-rw-r--r-- | deps/npm/lib/utils/sha.js | 51 | ||||
-rw-r--r-- | deps/npm/lib/version.js | 62 |
24 files changed, 303 insertions, 376 deletions
diff --git a/deps/npm/lib/adduser.js b/deps/npm/lib/adduser.js index 2d6d6bcd0c..c3ba5fc32e 100644 --- a/deps/npm/lib/adduser.js +++ b/deps/npm/lib/adduser.js @@ -5,6 +5,7 @@ var log = require("npmlog") , npm = require("./npm.js") , registry = npm.registry , read = require("read") + , userValidate = require("npm-user-validate") , crypto try { @@ -35,6 +36,7 @@ function adduser (args, cb) { } function readUsername (c, u, cb) { + var v = userValidate.username read({prompt: "Username: ", default: c.u}, function (er, un) { if (er) { return cb(er.message === "cancelled" ? er.message : er) @@ -49,18 +51,9 @@ function readUsername (c, u, cb) { return readUsername(c, u, cb) } - if (un !== un.toLowerCase()) { - log.warn('Username must be lowercase') - return readUsername(c, u, cb) - } - - if (un !== encodeURIComponent(un)) { - log.warn('Username may not contain non-url-safe chars') - return readUsername(c, u, cb) - } - - if (un.charAt(0) === '.') { - log.warn('Username may not start with "."') + var error = v(un) + if (error) { + log.warn(error.message) return readUsername(c, u, cb) } @@ -71,6 +64,8 @@ function readUsername (c, u, cb) { } function readPassword (c, u, cb) { + var v = userValidate.pw + if (!c.changed) { u.p = c.p return cb() @@ -84,8 +79,9 @@ function readPassword (c, u, cb) { return readPassword(c, u, cb) } - if (pw.match(/['!:@"]/)) { - log.warn('Sorry, passwords cannot contain these characters: \'!:@"') + var error = v(pw) + if (error) { + log.warn(error.message) return readPassword(c, u, cb) } @@ -95,6 +91,8 @@ function readPassword (c, u, cb) { } function readEmail (c, u, cb) { + var v = userValidate.email + read({prompt: "Email: ", default: c.e}, function (er, em) { if (er) { return cb(er.message === "cancelled" ? er.message : er) @@ -104,8 +102,9 @@ function readEmail (c, u, cb) { return readEmail(c, u, cb) } - if (!em.match(/^.+@.+\..+$/)) { - log.warn('Email must be an email address') + var error = v(em) + if (error) { + log.warn(error.message) return readEmail(c, u, cb) } diff --git a/deps/npm/lib/bugs.js b/deps/npm/lib/bugs.js index fa66dc3e41..bcbf2bebb1 100644 --- a/deps/npm/lib/bugs.js +++ b/deps/npm/lib/bugs.js @@ -3,8 +3,7 @@ module.exports = bugs bugs.usage = "npm bugs <pkgname>" -var exec = require("./utils/exec.js") - , npm = require("./npm.js") +var npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") , opener = require("opener") diff --git a/deps/npm/lib/build.js b/deps/npm/lib/build.js index b7ae08869d..5076e39125 100644 --- a/deps/npm/lib/build.js +++ b/deps/npm/lib/build.js @@ -83,16 +83,41 @@ function linkStuff (pkg, folder, global, didRB, cb) { log.verbose("linkStuff", [global, gnm, gtop, parent]) log.info("linkStuff", pkg._id) - if (top && pkg.preferGlobal && !global) { - log.warn("prefer global", pkg._id + " should be installed with -g") - } + shouldWarn(pkg, folder, global, function() { + asyncMap( [linkBins, linkMans, !didRB && rebuildBundles] + , function (fn, cb) { + if (!fn) return cb() + log.verbose(fn.name, pkg._id) + fn(pkg, folder, parent, gtop, cb) + }, cb) + }) +} - asyncMap( [linkBins, linkMans, !didRB && rebuildBundles] - , function (fn, cb) { - if (!fn) return cb() - log.verbose(fn.name, pkg._id) - fn(pkg, folder, parent, gtop, cb) - }, cb) +function shouldWarn(pkg, folder, global, cb) { + var parent = path.dirname(folder) + , top = parent === npm.dir + , cwd = process.cwd() + + readJson(path.resolve(cwd, "package.json"), function(er, topPkg) { + if (er) return cb(er) + + var linkedPkg = path.basename(cwd) + , currentPkg = path.basename(folder) + + // 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).indexOf(currentPkg) === -1) { + + if (top && pkg.preferGlobal && !global) { + log.warn("prefer global", pkg._id + " should be installed with -g") + } + } + } + + cb() + }) } function rebuildBundles (pkg, folder, parent, gtop, cb) { @@ -171,6 +196,7 @@ function linkBin (from, to, gently, cb) { function linkMans (pkg, folder, parent, gtop, cb) { if (!pkg.man || !gtop || process.platform === "win32") return cb() + var manRoot = path.resolve(npm.config.get("prefix"), "share", "man") asyncMap(pkg.man, function (man, cb) { if (typeof man !== "string") return cb() @@ -179,13 +205,13 @@ function linkMans (pkg, folder, parent, gtop, cb) { , sxn = parseMan[2] , gz = parseMan[3] || "" , bn = path.basename(stem) - , manSrc = path.join( folder, man ) , manDest = path.join( manRoot , "man"+sxn , (bn.indexOf(pkg.name) === 0 ? bn : pkg.name + "-" + bn) + "." + sxn + gz ) - linkIfExists(manSrc, manDest, gtop && folder, cb) + + linkIfExists(man, manDest, gtop && folder, cb) }, cb) } diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js index 2007442249..90d8226d0b 100644 --- a/deps/npm/lib/cache.js +++ b/deps/npm/lib/cache.js @@ -58,8 +58,8 @@ cache.lock = lock cache.unlock = unlock var mkdir = require("mkdirp") - , exec = require("./utils/exec.js") , spawn = require("child_process").spawn + , exec = require("child_process").execFile , once = require("once") , fetch = require("./utils/fetch.js") , npm = require("./npm.js") @@ -69,7 +69,7 @@ var mkdir = require("mkdirp") , registry = npm.registry , log = require("npmlog") , path = require("path") - , sha = require("./utils/sha.js") + , sha = require("sha") , asyncMap = require("slide").asyncMap , semver = require("semver") , tar = require("./utils/tar.js") @@ -81,6 +81,7 @@ var mkdir = require("mkdirp") , retry = require("retry") , zlib = require("zlib") , chmodr = require("chmodr") + , which = require("which") cache.usage = "npm cache add <tarball file>" + "\nnpm cache add <folder>" @@ -267,7 +268,7 @@ function add (args, cb) { case "git+ftp:": case "git+ssh:": //p.protocol = p.protocol.replace(/^git([^:])/, "$1") - return addRemoteGit(spec, p, name, cb) + return addRemoteGit(spec, p, name, false, cb) default: // if we have a name and a spec, then try name@spec // if not, then try just spec (which may try name@"" if not found) @@ -366,7 +367,8 @@ function addRemoteTarball_(u, tmp, shasum, cb) { // 4. cd cacheDir && git fetch -a origin // 5. git archive /tmp/random.tgz // 6. addLocalTarball(/tmp/random.tgz) <gitref> --format=tar --prefix=package/ -function addRemoteGit (u, parsed, name, cb_) { +// silent flag is used if this should error quietly +function addRemoteGit (u, parsed, name, silent, cb_) { if (typeof cb_ !== "function") cb_ = name, name = null if (!inFlightURLs[u]) inFlightURLs[u] = [] @@ -410,7 +412,7 @@ function addRemoteGit (u, parsed, name, cb_) { p = path.join(npm.config.get("cache"), "_git-remotes", v) - checkGitDir(p, u, co, origUrl, function(er, data) { + checkGitDir(p, u, co, origUrl, silent, function(er, data) { chmodr(p, npm.modes.file, function(erChmod) { if (er) return cb(er, data) return cb(erChmod, data) @@ -419,54 +421,76 @@ function addRemoteGit (u, parsed, name, cb_) { }) } -function checkGitDir (p, u, co, origUrl, cb) { +function checkGitDir (p, u, co, origUrl, silent, cb) { fs.stat(p, function (er, s) { - if (er) return cloneGitRemote(p, u, co, origUrl, cb) + if (er) return cloneGitRemote(p, u, co, origUrl, silent, cb) if (!s.isDirectory()) return rm(p, function (er){ if (er) return cb(er) - cloneGitRemote(p, u, co, origUrl, cb) + cloneGitRemote(p, u, co, origUrl, silent, cb) }) var git = npm.config.get("git") - var args = ["config", "--get", "remote.origin.url"] + var args = [ "config", "--get", "remote.origin.url" ] var env = gitEnv() - exec(git, args, env, false, p, function (er, code, stdout, stderr) { - stdoutTrimmed = (stdout + "\n" + stderr).trim() - if (er || u !== stdout.trim()) { - log.warn( "`git config --get remote.origin.url` returned " - + "wrong result ("+u+")", stdoutTrimmed ) - return rm(p, function (er){ - if (er) return cb(er) - cloneGitRemote(p, u, co, origUrl, cb) - }) + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) } - log.verbose("git remote.origin.url", stdoutTrimmed) - archiveGitRemote(p, u, co, origUrl, cb) + exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) { + stdoutTrimmed = (stdout + "\n" + stderr).trim() + if (er || u !== stdout.trim()) { + log.warn( "`git config --get remote.origin.url` returned " + + "wrong result ("+u+")", stdoutTrimmed ) + return rm(p, function (er){ + if (er) return cb(er) + cloneGitRemote(p, u, co, origUrl, silent, cb) + }) + } + log.verbose("git remote.origin.url", stdoutTrimmed) + archiveGitRemote(p, u, co, origUrl, cb) + }) }) }) } -function cloneGitRemote (p, u, co, origUrl, cb) { +function cloneGitRemote (p, u, co, origUrl, silent, cb) { mkdir(p, function (er) { if (er) return cb(er) - exec( npm.config.get("git"), ["clone", "--mirror", u, p], gitEnv(), false - , function (er, code, stdout, stderr) { - stdout = (stdout + "\n" + stderr).trim() - if (er) { - log.error("git clone " + u, stdout) - return cb(er) + + var git = npm.config.get("git") + var args = [ "clone", "--mirror", u, p ] + var env = gitEnv() + + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) } - log.verbose("git clone " + u, stdout) - archiveGitRemote(p, u, co, origUrl, cb) + exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) { + stdout = (stdout + "\n" + stderr).trim() + if (er) { + if (silent) { + log.verbose("git clone " + u, stdout) + } else { + log.error("git clone " + u, stdout) + } + return cb(er) + } + log.verbose("git clone " + u, stdout) + archiveGitRemote(p, u, co, origUrl, cb) + }) }) }) } function archiveGitRemote (p, u, co, origUrl, cb) { var git = npm.config.get("git") - var archive = ["fetch", "-a", "origin"] - var resolve = ["rev-list", "-n1", co] + var archive = [ "fetch", "-a", "origin" ] + var resolve = [ "rev-list", "-n1", co ] var env = gitEnv() var errState = null @@ -474,7 +498,7 @@ function archiveGitRemote (p, u, co, origUrl, cb) { var resolved = null var tmp - exec(git, archive, env, false, p, function (er, code, stdout, stderr) { + exec(git, archive, {cwd: p, env: env}, function (er, stdout, stderr) { stdout = (stdout + "\n" + stderr).trim() if (er) { log.error("git fetch -a origin ("+u+")", stdout) @@ -486,7 +510,7 @@ function archiveGitRemote (p, u, co, origUrl, cb) { }) function resolveHead () { - exec(git, resolve, env, false, p, function (er, code, stdout, stderr) { + exec(git, resolve, {cwd: p, env: env}, function (er, stdout, stderr) { stdout = (stdout + "\n" + stderr).trim() if (er) { log.error("Failed resolving git HEAD (" + u + ")", stderr) @@ -797,14 +821,28 @@ function addLocal (p, name, cb_) { function maybeGithub (p, name, er, cb) { var u = "git://github.com/" + p , up = url.parse(u) - log.info("maybeGithub", "Attempting to fetch %s from %s", p, u) + log.info("maybeGithub", "Attempting %s from %s", p, u) + + return addRemoteGit(u, up, name, true, function (er2, data) { + if (er2) { + var upriv = "git+ssh://git@github.com:" + p + , uppriv = url.parse(upriv) + + log.info("maybeGithub", "Attempting %s from %s", p, upriv) - return addRemoteGit(u, up, name, function (er2, data) { - if (er2) return cb(er) + return addRemoteGit(upriv, uppriv, false, name, function (er3, data) { + if (er3) return cb(er) + success(upriv, data) + }) + } + success(u, data) + }) + + function success (u, data) { data._from = u data._fromGithub = true return cb(null, data) - }) + } } function addLocalTarball (p, name, shasum, cb_) { diff --git a/deps/npm/lib/config.js b/deps/npm/lib/config.js index 27a5f3546b..dfd51c84a3 100644 --- a/deps/npm/lib/config.js +++ b/deps/npm/lib/config.js @@ -11,11 +11,12 @@ config.usage = "npm config set <key> <value>" var log = require("npmlog") , npm = require("./npm.js") - , exec = require("./utils/exec.js") + , spawn = require("child_process").spawn , fs = require("graceful-fs") , npmconf = require("npmconf") , types = npmconf.defs.types , ini = require("ini") + , editor = require("editor") config.completion = function (opts, cb) { var argv = opts.conf.argv.remain @@ -93,7 +94,7 @@ function edit (cb) { , "utf8" , function (er) { if (er) return cb(er) - exec(e, [f], cb) + editor(f, { editor: e }, cb) } ) }) diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js index ffa91aa6bd..ff2e381f8d 100644 --- a/deps/npm/lib/docs.js +++ b/deps/npm/lib/docs.js @@ -10,8 +10,7 @@ docs.completion = function (opts, cb) { }) } -var exec = require("./utils/exec.js") - , npm = require("./npm.js") +var npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") , opener = require("opener") diff --git a/deps/npm/lib/edit.js b/deps/npm/lib/edit.js index 0ffe723bc1..791dc60cfd 100644 --- a/deps/npm/lib/edit.js +++ b/deps/npm/lib/edit.js @@ -7,22 +7,24 @@ edit.usage = "npm edit <pkg>" edit.completion = require("./utils/completion/installed-shallow.js") var npm = require("./npm.js") - , exec = require("./utils/exec.js") + , spawn = require("child_process").spawn , path = require("path") , fs = require("graceful-fs") + , editor = require("editor") function edit (args, cb) { var p = args[0] if (args.length !== 1 || !p) return cb(edit.usage) - var editor = npm.config.get("editor") - if (!editor) return cb(new Error( + var e = npm.config.get("editor") + if (!e) return cb(new Error( "No editor set. Set the 'editor' config, or $EDITOR environ.")) p = p.split("/") .join("/node_modules/") .replace(/(\/node_modules)+/, "/node_modules") - fs.lstat(path.resolve(npm.dir, p), function (er) { + var f = path.resolve(npm.dir, p) + fs.lstat(f, function (er) { if (er) return cb(er) - exec(editor, [path.resolve(npm.dir, p)], function (er) { + editor(f, { editor: e }, function (er) { if (er) return cb(er) npm.commands.rebuild(args, cb) }) diff --git a/deps/npm/lib/explore.js b/deps/npm/lib/explore.js index 8392c91728..8b55115e0e 100644 --- a/deps/npm/lib/explore.js +++ b/deps/npm/lib/explore.js @@ -1,4 +1,4 @@ -// npm expore <pkg>[@<version>] +// npm explore <pkg>[@<version>] // open a subshell to the package folder. module.exports = explore @@ -6,7 +6,7 @@ explore.usage = "npm explore <pkg> [ -- <cmd>]" explore.completion = require("./utils/completion/installed-shallow.js") var npm = require("./npm.js") - , exec = require("./utils/exec.js") + , spawn = require("child_process").spawn , path = require("path") , fs = require("graceful-fs") @@ -17,15 +17,17 @@ function explore (args, cb) { if (args) args = ["-c", args] else args = [] - var editor = npm.config.get("editor") - , cwd = path.resolve(npm.dir, p) + var cwd = path.resolve(npm.dir, p) + var sh = npm.config.get("shell") fs.stat(cwd, function (er, s) { if (er || !s.isDirectory()) return cb(new Error( "It doesn't look like "+p+" is installed.")) if (!args.length) console.log( "\nExploring "+cwd+"\n"+ "Type 'exit' or ^D when finished\n") - exec(npm.config.get("shell"), args, null, true, cwd, function (er) { + + var shell = spawn(sh, args, { cwd: cwd, customFds: [0, 1, 2] }) + shell.on("close", function (er) { // only fail if non-interactive. if (!args.length) return cb() cb(er) diff --git a/deps/npm/lib/help.js b/deps/npm/lib/help.js index a8b1f2d4d2..8faef1c2c5 100644 --- a/deps/npm/lib/help.js +++ b/deps/npm/lib/help.js @@ -10,7 +10,7 @@ help.completion = function (opts, cb) { var fs = require("graceful-fs") , path = require("path") - , exec = require("./utils/exec.js") + , spawn = require("child_process").spawn , npm = require("./npm.js") , log = require("npmlog") , opener = require("opener") @@ -60,7 +60,9 @@ function help (args, cb) { switch (viewer) { case "woman": var a = ["-e", "(woman-find-file \"" + sectionPath + "\")"] - exec("emacsclient", a, env, true, cb) + var conf = { env: env, customFds: [ 0, 1, 2] } + var woman = spawn("emacsclient", a, conf) + woman.on("close", cb) break case "browser": @@ -68,7 +70,9 @@ function help (args, cb) { break default: - exec("man", [num, section], env, true, cb) + var conf = { env: env, customFds: [ 0, 1, 2] } + var man = spawn("man", [num, section], conf) + man.on("close", cb) } } ) diff --git a/deps/npm/lib/init.js b/deps/npm/lib/init.js index e05a4a2407..d064ae8bcc 100644 --- a/deps/npm/lib/init.js +++ b/deps/npm/lib/init.js @@ -27,7 +27,7 @@ function init (args, cb) { ,"Press ^C at any time to quit." ].join("\n")) - initJson(dir, initFile, npm.config.get(), function (er, data) { + initJson(dir, initFile, npm.config, function (er, data) { log.resume() log.silly('package data', data) log.info('init', 'written successfully') diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js index 4db8d58ef2..cb59a789fa 100644 --- a/deps/npm/lib/install.js +++ b/deps/npm/lib/install.js @@ -93,7 +93,7 @@ function install (args, cb_) { var tree = treeify(installed || []) , pretty = prettify(tree, installed).trim() - if (pretty) console.log(pretty) + if (pretty) log.write(pretty) save(where, installed, tree, pretty, cb_) }) } diff --git a/deps/npm/lib/npm.js b/deps/npm/lib/npm.js index 2028b34f02..9a6a69c2f2 100644 --- a/deps/npm/lib/npm.js +++ b/deps/npm/lib/npm.js @@ -11,8 +11,8 @@ if (typeof WScript !== "undefined") { } -// FIXME there really ought to be a path.split in node core -require("path").SPLIT_CHAR = process.platform === "win32" ? "\\" : "/" +// monkey-patch support for 0.6 child processes +require('child-process-close') var EventEmitter = require("events").EventEmitter , npm = module.exports = new EventEmitter diff --git a/deps/npm/lib/rebuild.js b/deps/npm/lib/rebuild.js index 0c97cf85dc..35bb454d73 100644 --- a/deps/npm/lib/rebuild.js +++ b/deps/npm/lib/rebuild.js @@ -8,7 +8,6 @@ var readInstalled = require("read-installed") , npm = require("./npm.js") , asyncMap = require("slide").asyncMap , fs = require("graceful-fs") - , exec = require("./utils/exec.js") rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" diff --git a/deps/npm/lib/submodule.js b/deps/npm/lib/submodule.js index c1523984c9..ccb9d58335 100644 --- a/deps/npm/lib/submodule.js +++ b/deps/npm/lib/submodule.js @@ -5,10 +5,11 @@ module.exports = submodule var npm = require("./npm.js") - , exec = require("./utils/exec.js") + , exec = require("child_process").execFile , cache = require("./cache.js") , asyncMap = require("slide").asyncMap , chain = require("slide").chain + , which = require("which") submodule.usage = "npm submodule <pkg>" @@ -55,37 +56,64 @@ function submodule_ (pkg, cb) { } function updateSubmodule (name, cb) { - exec( npm.config.get("git"), [ "submodule", "update", "--init" - , "node_modules/" + name ] - , null, true, npm.prefix, cb) + var git = npm.config.get("git") + var args = [ "submodule", "update", "--init", "node_modules/", name ] + + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) + } + + exec(git, args, cb) + }) } function addSubmodule (name, url, cb) { - exec( npm.config.get("git"), [ "submodule", "add", url - , "node_modules/" + name ] - , null, true, npm.prefix, function (er) { - if (er) return cb(er) - updateSubmodule(name, cb) + var git = npm.config.get("git") + var args = [ "submodule", "add", url, "node_modules/", name ] + + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) + } + + exec(git, args, function (er) { + if (er) return cb(er) + updateSubmodule(name, cb) + }) }) } var getSubmodules = function getSubmodules (cb) { - exec( npm.config.get("git"), ["submodule", "status"], null, false - , npm.prefix, function (er, code, stdout, stderr) { - if (er) return cb(er) - res = stdout.trim().split(/\n/).map(function (line) { - return line.trim().split(/\s+/)[1] - }).filter(function (line) { - // only care about submodules in the node_modules folder. - return line && line.match(/^node_modules\//) - }).map(function (line) { - return line.replace(/^node_modules\//g, "") + var git = npm.config.get("git") + var arg = [ "submodule", "status" ] + + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) + } + exec(git, args, function (er, stdout, stderr) { + if (er) return cb(er) + res = stdout.trim().split(/\n/).map(function (line) { + return line.trim().split(/\s+/)[1] + }).filter(function (line) { + // only care about submodules in the node_modules folder. + return line && line.match(/^node_modules\//) + }).map(function (line) { + return line.replace(/^node_modules\//g, "") + }) + + // memoize. + getSubmodules = function (cb) { return cb(null, res) } + + cb(null, res) }) - - // memoize. - getSubmodules = function (cb) { return cb(null, res) } - - cb(null, res) }) } diff --git a/deps/npm/lib/unbuild.js b/deps/npm/lib/unbuild.js index 1cbf054e1c..c89a538f21 100644 --- a/deps/npm/lib/unbuild.js +++ b/deps/npm/lib/unbuild.js @@ -76,19 +76,27 @@ function rmMans (pkg, folder, parent, top, cb) { } var manRoot = path.resolve(npm.config.get("prefix"), "share", "man") asyncMap(pkg.man, function (man, cb) { - var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/) - , stem = parseMan[1] - , sxn = parseMan[2] - , gz = parseMan[3] || "" - , bn = path.basename(stem) - , manDest = path.join( manRoot - , "man"+sxn - , (bn.indexOf(pkg.name) === 0 ? bn - : pkg.name + "-" + bn) - + "." + sxn + gz - ) - gentlyRm( manDest - , !npm.config.get("force") && folder - , cb ) + if (Array.isArray(man)) { + man.forEach(rm) + } else { + rm(man) + } + + function rm(man) { + var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/) + , stem = parseMan[1] + , sxn = parseMan[2] + , gz = parseMan[3] || "" + , bn = path.basename(stem) + , manDest = path.join( manRoot + , "man"+sxn + , (bn.indexOf(pkg.name) === 0 ? bn + : pkg.name + "-" + bn) + + "." + sxn + gz + ) + gentlyRm( manDest + , !npm.config.get("force") && folder + , cb ) + } }, cb) } diff --git a/deps/npm/lib/utils/completion/remote-packages.js b/deps/npm/lib/utils/completion/remote-packages.js deleted file mode 100644 index 18d812caa9..0000000000 --- a/deps/npm/lib/utils/completion/remote-packages.js +++ /dev/null @@ -1,58 +0,0 @@ - -module.exports = remotePackages - -var npm = require("../../npm.js") - , registry = npm.registry - , containsSingleMatch = require("./contains-single-match.js") - , getCompletions = require("./get-completions.js") - -/* - Looks up remote packages for CLI tab-completion. - - NOTE: If doVersion is true, versions in the form <name>@<version> - will be completed. - - If doTag is true, tags in the form <name>@<tag> will be - completed. - - If recurring in true, sequences of multiple packages can be - completed. i.e. for schemes such as: - npm <command> <name>[@<version> [<name>[@<version>] ...] -*/ -function remotePackages (args, index, doVersion, doTag - , recurring, cb) { - if (recurring || index < 3) { - var name = (args.length + 1 === index) ? args[args.length - 1] : "" - if (name === undefined) name = "" - if (name.indexOf("/") !== -1) return cb(null, []) - // use up-to 1 hour stale cache. not super urgent. - registry.get("/", 3600, function (er, d) { - if (er) return cb(er) - var remoteList = Object.keys(d) - , found = remoteList.indexOf(name) - , unique = found && containsSingleMatch(name, remoteList) - , simpleMatches = getCompletions(name, remoteList) - , uniqueMatch = unique && simpleMatches[0] - , addTag = doTag && (unique || found || name.indexOf("@") !== -1) - , addVer = doVersion && (unique || found || name.indexOf("@") !== -1) - , list = [] - , pieces = (uniqueMatch || name).split("@") - , pkgname = pieces[0] - , extras = [] - if (unique && !addTag && !addVer) return cb(null, [uniqueMatch]) - if (d[pkgname] && (addTag || addVer)) { - if (d[pkgname].versions && addVer) { - extras = extras.concat(Object.keys(d[pkgname].versions)) - } - if (d[pkgname]["dist-tags"] && addTag) { - extras = extras.concat(Object.keys(d[pkgname]["dist-tags"])) - } - list = getCompletions(name, list.concat(extras.map(function (e) { - return pkgname + "@" + e - }))) - } - if (!unique) list = list.concat(getCompletions(name, remoteList)) - return cb(null, list) - }) - } -} diff --git a/deps/npm/lib/utils/completion/users.js b/deps/npm/lib/utils/completion/users.js deleted file mode 100644 index 1dc6dbb914..0000000000 --- a/deps/npm/lib/utils/completion/users.js +++ /dev/null @@ -1,23 +0,0 @@ - -module.exports = users - -var npm = require("../../npm") - , registry = npm.registry - , containsSingleMatch = require("./contains-single-match.js") - , getCompletions = require("./get-completions.js") - , log = require("npmlog") - -function users (args, index, cb) { - var name = (args.length + 1 === index) ? args[args.length - 1] : "" - if (name === undefined) name = "" - // use up-to 1 day stale cache. doesn't change much - log.warn("users completion", "About to fetch") - registry.get("/-/users", 24*60*60, function (er, d) { - log.warn("userdata", d) - log.warn("name", name) - if (er) return cb(er) - var remoteList = Object.keys(d) - , simpleMatches = getCompletions(name, remoteList) - return cb(null, simpleMatches) - }) -} diff --git a/deps/npm/lib/utils/error-handler.js b/deps/npm/lib/utils/error-handler.js index 88ce742798..83d9ede176 100644 --- a/deps/npm/lib/utils/error-handler.js +++ b/deps/npm/lib/utils/error-handler.js @@ -124,6 +124,15 @@ function errorHandler (er) { ].join("\n")) break + case "ENOGIT": + er.code = "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": er.code = "EJSONPARSE" log.error("", er.message) @@ -215,6 +224,16 @@ function errorHandler (er) { log.error("peerinvalid", [er.message].concat(peerErrors).join("\n")) break + case "ENOTFOUND": + 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 "ENOTSUP": if (er.required) { log.error("notsup", [er.message diff --git a/deps/npm/lib/utils/exec.js b/deps/npm/lib/utils/exec.js deleted file mode 100644 index 360367cbff..0000000000 --- a/deps/npm/lib/utils/exec.js +++ /dev/null @@ -1,85 +0,0 @@ -module.exports = exec -exec.spawn = spawn - -var log = require("npmlog") - , child_process = require("child_process") - , util = require("util") - , npm = require("../npm.js") - , myUID = process.getuid ? process.getuid() : null - , myGID = process.getgid ? process.getgid() : null - , isRoot = process.getuid && myUID === 0 - , constants = require("constants") - , uidNumber = require("uid-number") - , once = require("once") - -function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { - if (typeof cb !== "function") cb = gid, gid = null - if (typeof cb !== "function") cb = uid, uid = null - if (typeof cb !== "function") cb = cwd, cwd = null - if (typeof cb !== "function") cb = takeOver, takeOver = true - if (typeof cb !== "function") cb = env, env = process.env - gid = gid == null ? myGID : gid - uid = uid == null ? myUID : uid - if (!isRoot) { - if (npm.config.get("unsafe-perm")) { - uid = myUID - gid = myGID - } else if (uid !== myUID || gid !== myGID) { - var e = new Error("EPERM: setuid() operation not permitted") - e.errno = constants.EPERM - return cb(e) - } - } - if (uid !== myUID) { - log.verbose("set uid", "from=%s to=%s", myUID, uid) - } - - if (uid && gid && (isNaN(uid) || isNaN(gid))) { - // get the numeric values - return uidNumber(uid, gid, function (er, uid, gid) { - if (er) return cb(er) - exec(cmd, args, env, takeOver, cwd, uid, gid, cb) - }) - } - - log.silly("exec", cmd+" "+args.map(JSON.stringify).join(" ")) - var stdout = "" - , stderr = "" - , cp = spawn(cmd, args, env, takeOver, cwd, uid, gid) - cb = once(cb) - cp.on("error", cb) - cp.stdout && cp.stdout.on("data", function (chunk) { - if (chunk) stdout += chunk - }) - cp.stderr && cp.stderr.on("data", function (chunk) { - if (chunk) stderr += chunk - }) - cp.on("close", function (code) { - var er = null - if (code) er = new Error("`"+cmd - +(args.length ? " " - + args.map(JSON.stringify).join(" ") - : "") - +"` failed with "+code) - cb(er, code, stdout, stderr) - }) - return cp -} - - -function spawn (c, a, env, takeOver, cwd, uid, gid) { - var fds = [ 0, 1, 2 ] - , opts = { customFds : takeOver ? fds : [-1,-1,-1] - , env : env || process.env - , cwd : cwd || null } - , cp - - if (uid && !isNaN(uid)) opts.uid = +uid - if (gid && !isNaN(gid)) opts.gid = +gid - - var name = c +" "+ a.map(JSON.stringify).join(" ") - log.silly([c, a, opts.cwd], "spawning") - cp = child_process.spawn(c, a, opts) - cp.name = name - return cp -} diff --git a/deps/npm/lib/utils/fetch.js b/deps/npm/lib/utils/fetch.js index 526b836a2c..e92b68d14a 100644 --- a/deps/npm/lib/utils/fetch.js +++ b/deps/npm/lib/utils/fetch.js @@ -31,7 +31,7 @@ function fetch_ (remote, local, headers, cb) { fstr.on("error", function (er) { cb(er) - fstr.close() + fstr.destroy() }) var req = makeRequest(remote, fstr, headers) diff --git a/deps/npm/lib/utils/find-prefix.js b/deps/npm/lib/utils/find-prefix.js index c3ff85f593..a61d9e136d 100644 --- a/deps/npm/lib/utils/find-prefix.js +++ b/deps/npm/lib/utils/find-prefix.js @@ -34,7 +34,12 @@ function findPrefix_ (p, original, cb) { } fs.readdir(p, function (er, files) { // an error right away is a bad sign. - if (er && p === original) return cb(er) + // unless the prefix was simply a non + // existent directory. + if (er && p === original) { + if (er.code === "ENOENT") return cb(null, original); + return cb(er) + } // walked up too high or something. if (er) return cb(null, original) diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js index 3f0042f819..1f9da46716 100644 --- a/deps/npm/lib/utils/lifecycle.js +++ b/deps/npm/lib/utils/lifecycle.js @@ -3,7 +3,7 @@ exports = module.exports = lifecycle exports.cmd = cmd var log = require("npmlog") - , exec = require("./exec.js") + , spawn = require("child_process").spawn , npm = require("../npm.js") , path = require("path") , fs = require("graceful-fs") @@ -149,9 +149,10 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) { + "\n> " + cmd + "\n" console.log(note) - exec( sh, [shFlag, cmd], env, true, wd - , user, group - , function (er, code, stdout, stderr) { + + var conf = { cwd: wd, env: env, customFds: [ 0, 1, 2] } + var proc = spawn(sh, [shFlag, cmd], conf) + proc.on("close", function (er, stdout, stderr) { if (er && !npm.ROLLBACK) { log.info(pkg._id, "Failed to exec "+stage+" script") er.message = pkg._id + " " @@ -185,9 +186,9 @@ function runHookLifecycle (pkg, env, wd, unsafe, cb) { fs.stat(hook, function (er) { if (er) return cb() - exec( "sh", ["-c", cmd], env, true, wd - , user, group - , function (er) { + var conf = { cwd: wd, env: env, customFds: [ 0, 1, 2] } + var proc = spawn("sh", ["-c", cmd], conf) + proc.on("close", function (er) { if (er) { er.message += "\nFailed to exec "+stage+" hook script" log.info(pkg._id, er) diff --git a/deps/npm/lib/utils/sha.js b/deps/npm/lib/utils/sha.js deleted file mode 100644 index a4212011a7..0000000000 --- a/deps/npm/lib/utils/sha.js +++ /dev/null @@ -1,51 +0,0 @@ - -var fs = require("graceful-fs") - , crypto = require("crypto") - , log = require("npmlog") - , binding - -try { binding = process.binding("crypto") } -catch (e) { - var er = new Error( "crypto binding not found.\n" - + "Please build node with openssl.\n" - + e.message ) - throw er -} - -exports.check = check -exports.get = get - -function check (file, sum, cb) { - get(file, function (er, actual) { - if (er) { - log.error("shasum", "error getting shasum") - return cb(er) - } - var expected = sum.toLowerCase().trim() - , ok = actual === expected - cb(ok ? null : new Error( - "shasum check failed for "+file+"\n" - +"Expected: "+expected+"\n" - +"Actual: "+actual)) - }) -} - -function get (file, cb) { - var h = crypto.createHash("sha1") - , s = fs.createReadStream(file) - , errState = null - s.on("error", function (er) { - if (errState) return - log.silly("shasum", "error", er) - return cb(errState = er) - }).on("data", function (chunk) { - if (errState) return - log.silly("shasum", "updated bytes", chunk.length) - h.update(chunk) - }).on("end", function () { - if (errState) return - var actual = h.digest("hex").toLowerCase().trim() - log.info("shasum", actual+"\n"+file) - cb(null, actual) - }) -} diff --git a/deps/npm/lib/version.js b/deps/npm/lib/version.js index fb00e21d3c..73cd163f45 100644 --- a/deps/npm/lib/version.js +++ b/deps/npm/lib/version.js @@ -2,12 +2,13 @@ module.exports = version -var exec = require("./utils/exec.js") +var exec = require("child_process").execFile , semver = require("semver") , path = require("path") , fs = require("graceful-fs") , chain = require("slide").chain , log = require("npmlog") + , which = require("which") , npm = require("./npm.js") version.usage = "npm version [<newversion> | major | minor | patch | build]\n" @@ -72,30 +73,43 @@ function version (args, silent, cb_) { } function checkGit (data, cb) { - exec( npm.config.get("git"), ["status", "--porcelain"], process.env, false - , function (er, code, stdout, stderr) { - var lines = stdout.trim().split("\n").filter(function (line) { - return line.trim() && !line.match(/^\?\? /) - }).map(function (line) { - return line.trim() - }) - if (lines.length) return cb(new Error( - "Git working directory not clean.\n"+lines.join("\n"))) - write(data, function (er) { - if (er) return cb(er) - var message = npm.config.get("message").replace(/%s/g, data.version) - , sign = npm.config.get("sign-git-tag") - , flag = sign ? "-sm" : "-am" - chain - ( [ [ exec, npm.config.get("git") - , ["add","package.json"], process.env, false ] - , [ exec, npm.config.get("git") - , ["commit", "-m", message ], process.env, false ] - , [ exec, npm.config.get("git") - , ["tag", "v"+data.version, flag, message], process.env, false ] ] - , cb ) - }) + var git = npm.config.get("git") + var args = [ "status", "--porcelain" ] + var env = process.env + + // check for git + which(git, function (err) { + if (err) { + err.code = "ENOGIT" + return cb(err) + } + + gitFound() }) + + function gitFound () { + exec(git, args, {env: env}, function (er, stdout, stderr) { + var lines = stdout.trim().split("\n").filter(function (line) { + return line.trim() && !line.match(/^\?\? /) + }).map(function (line) { + return line.trim() + }) + if (lines.length) return cb(new Error( + "Git working directory not clean.\n"+lines.join("\n"))) + write(data, function (er) { + if (er) return cb(er) + var message = npm.config.get("message").replace(/%s/g, data.version) + , sign = npm.config.get("sign-git-tag") + , flag = sign ? "-sm" : "-am" + chain + ( [ [ exec, git, [ "add", "package.json" ], {env: process.env} ] + , [ exec, git, [ "commit", "-m", message ], {env: process.env} ] + , [ exec, git, [ "tag", "v" + data.version, flag, message ] + , {env: process.env} ] ] + , cb ) + }) + }) + } } function write (data, cb) { |