diff options
author | Julien Gilli <julien.gilli@joyent.com> | 2015-03-16 15:55:17 -0700 |
---|---|---|
committer | Julien Gilli <julien.gilli@joyent.com> | 2015-03-16 15:55:17 -0700 |
commit | ae58fc407f916b2abb164453a5b09273c543dbc3 (patch) | |
tree | 4a16fe73f996a54f34cfb553b2995d16c1375b7f /deps/npm/lib | |
parent | 2b64132101f179c30957e3c5f16fc47a8ec942e1 (diff) | |
parent | eb2764a9452baa7cba2d98dc34fa00fc776b0a12 (diff) | |
download | node-merge-review.tar.gz |
Merge remote-tracking branch 'upstream/v0.12'merge-review
Diffstat (limited to 'deps/npm/lib')
-rw-r--r-- | deps/npm/lib/bugs.js | 11 | ||||
-rw-r--r-- | deps/npm/lib/cache/add-remote-git.js | 4 | ||||
-rw-r--r-- | deps/npm/lib/cache/maybe-github.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/config/defaults.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/docs.js | 10 | ||||
-rw-r--r-- | deps/npm/lib/help.js | 22 | ||||
-rw-r--r-- | deps/npm/lib/install.js | 70 | ||||
-rw-r--r-- | deps/npm/lib/ls.js | 16 | ||||
-rw-r--r-- | deps/npm/lib/npm.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/owner.js | 9 | ||||
-rw-r--r-- | deps/npm/lib/repo.js | 11 | ||||
-rw-r--r-- | deps/npm/lib/run-script.js | 49 | ||||
-rw-r--r-- | deps/npm/lib/star.js | 14 | ||||
-rw-r--r-- | deps/npm/lib/uninstall.js | 5 | ||||
-rwxr-xr-x | deps/npm/lib/utils/completion.sh | 4 | ||||
-rw-r--r-- | deps/npm/lib/utils/error-handler.js | 8 | ||||
-rw-r--r-- | deps/npm/lib/utils/git.js | 9 | ||||
-rw-r--r-- | deps/npm/lib/view.js | 8 |
18 files changed, 154 insertions, 102 deletions
diff --git a/deps/npm/lib/bugs.js b/deps/npm/lib/bugs.js index fabbbaf10..306d9bb4b 100644 --- a/deps/npm/lib/bugs.js +++ b/deps/npm/lib/bugs.js @@ -13,14 +13,9 @@ var npm = require("./npm.js") , mapToRegistry = require("./utils/map-to-registry.js") bugs.completion = function (opts, cb) { - if (opts.conf.argv.remain.length > 2) return cb() - mapToRegistry("-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - npm.registry.get(uri, { timeout : 60000, auth : auth }, function (er, list) { - return cb(null, list || []) - }) - }) + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + cb() } function bugs (args, cb) { diff --git a/deps/npm/lib/cache/add-remote-git.js b/deps/npm/lib/cache/add-remote-git.js index c829a4fe6..974c158f9 100644 --- a/deps/npm/lib/cache/add-remote-git.js +++ b/deps/npm/lib/cache/add-remote-git.js @@ -188,7 +188,9 @@ function resolveHead (p, u, co, origUrl, cb) { parsed.hash = stdout var resolved = url.format(parsed) - if (parsed.protocol !== "git:") resolved = "git+" + resolved + if (!/^git[+:]/.test(parsed.protocol)) { + resolved = "git+" + resolved + } // https://github.com/npm/npm/issues/3224 // node incorrectly sticks a / at the start of the path We know that the diff --git a/deps/npm/lib/cache/maybe-github.js b/deps/npm/lib/cache/maybe-github.js index 5ecdb6915..e24099115 100644 --- a/deps/npm/lib/cache/maybe-github.js +++ b/deps/npm/lib/cache/maybe-github.js @@ -11,7 +11,7 @@ module.exports = function maybeGithub (p, cb) { return addRemoteGit(u, true, function (er, data) { if (er) { - var upriv = "git+ssh://git@github.com:" + p + var upriv = "ssh://git@github.com:" + p log.info("maybeGithub", "Attempting %s from %s", p, upriv) return addRemoteGit(upriv, false, function (er, data) { diff --git a/deps/npm/lib/config/defaults.js b/deps/npm/lib/config/defaults.js index a46e74b5b..e49ce210b 100644 --- a/deps/npm/lib/config/defaults.js +++ b/deps/npm/lib/config/defaults.js @@ -160,6 +160,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , group : process.platform === "win32" ? 0 : process.env.SUDO_GID || (process.getgid && process.getgid()) , heading: "npm" + , "if-present": false , "ignore-scripts": false , "init-module": path.resolve(home, ".npm-init.js") , "init-author-name" : "" @@ -262,6 +263,7 @@ exports.types = , "https-proxy" : [null, url] , "user-agent" : String , "heading": String + , "if-present": Boolean , "ignore-scripts": Boolean , "init-module": path , "init-author-name" : String diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js index 9abe740a3..0de2349dd 100644 --- a/deps/npm/lib/docs.js +++ b/deps/npm/lib/docs.js @@ -11,13 +11,9 @@ var npm = require("./npm.js") , mapToRegistry = require("./utils/map-to-registry.js") docs.completion = function (opts, cb) { - mapToRegistry("/-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - npm.registry.get(uri, { timeout : 60000, auth : auth }, function (er, list) { - return cb(null, list || []) - }) - }) + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + cb() } function url (json) { diff --git a/deps/npm/lib/help.js b/deps/npm/lib/help.js index 07d921949..cb1d5715f 100644 --- a/deps/npm/lib/help.js +++ b/deps/npm/lib/help.js @@ -59,19 +59,23 @@ function help (args, cb) { var manroot = path.resolve(__dirname, "..", "man") // legacy - if (section === "global") - section = "folders" - else if (section === "json") - section = "package.json" + if (section === "global") section = "folders" + else if (section === "json") section = "package.json" // find either /section.n or /npm-section.n - var f = "+(npm-" + section + "|" + section + ").[0-9]" + var compext = "\\.+(gz|bz2|lzma|[FYzZ]|xz)$" + var f = "+(npm-" + section + "|" + section + ").[0-9]?(" + compext + ")" return glob(manroot + "/*/" + f, function (er, mans) { - if (er) - return cb(er) + if (er) return cb(er) + + if (!mans.length) return npm.commands["help-search"](args, cb) - if (!mans.length) - return npm.commands["help-search"](args, cb) + mans = mans.map(function (man) { + var ext = path.extname(man) + if (man.match(new RegExp(compext))) man = path.basename(man, ext) + + return man + }) viewMan(pickMan(mans, pref), cb) }) diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js index 7fa9058f3..73580e5af 100644 --- a/deps/npm/lib/install.js +++ b/deps/npm/lib/install.js @@ -32,38 +32,58 @@ install.completion = function (opts, cb) { // install can complete to a folder with a package.json, or any package. // if it has a slash, then it's gotta be a folder // if it starts with https?://, then just give up, because it's a url - // for now, not yet implemented. - mapToRegistry("-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - var options = { auth : auth } - npm.registry.get(uri, options, function (er, pkgs) { - if (er) return cb() - if (!opts.partialWord) return cb(null, pkgs) + if (/^https?:\/\//.test(opts.partialWord)) { + // do not complete to URLs + return cb(null, []) + } - var name = npa(opts.partialWord).name - pkgs = pkgs.filter(function (p) { - return p.indexOf(name) === 0 + if (/\//.test(opts.partialWord)) { + // Complete fully to folder if there is exactly one match and it + // is a folder containing a package.json file. If that is not the + // case we return 0 matches, which will trigger the default bash + // complete. + var lastSlashIdx = opts.partialWord.lastIndexOf("/") + var partialName = opts.partialWord.slice(lastSlashIdx + 1) + var partialPath = opts.partialWord.slice(0, lastSlashIdx) + if (partialPath === "") partialPath = "/" + + function annotatePackageDirMatch (sibling, cb) { + var fullPath = path.join(partialPath, sibling) + if (sibling.slice(0, partialName.length) !== partialName) { + return cb(null, null) // not name match + } + fs.readdir(fullPath, function (err, contents) { + if (err) return cb(null, { isPackage: false }) + + cb( + null, + { + fullPath: fullPath, + isPackage: contents.indexOf("package.json") !== -1 + } + ) }) + } - if (pkgs.length !== 1 && opts.partialWord === name) { - return cb(null, pkgs) - } + return fs.readdir(partialPath, function (err, siblings) { + if (err) return cb(null, []) // invalid dir: no matching - mapToRegistry(pkgs[0], npm.config, function (er, uri) { - if (er) return cb(er) + asyncMap(siblings, annotatePackageDirMatch, function (err, matches) { + if (err) return cb(err) - npm.registry.get(uri, options, function (er, d) { - if (er) return cb() - return cb(null, Object.keys(d["dist-tags"] || {}) - .concat(Object.keys(d.versions || {})) - .map(function (t) { - return pkgs[0] + "@" + t - })) - }) + var cleaned = matches.filter(function (x) { return x !== null }) + if (cleaned.length !== 1) return cb(null, []) + if (!cleaned[0].isPackage) return cb(null, []) + + // Success - only one match and it is a package dir + return cb(null, [cleaned[0].fullPath]) }) }) - }) + } + + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + cb() } var npm = require("./npm.js") diff --git a/deps/npm/lib/ls.js b/deps/npm/lib/ls.js index eee4f2772..05166ee6a 100644 --- a/deps/npm/lib/ls.js +++ b/deps/npm/lib/ls.js @@ -40,6 +40,7 @@ function ls (args, silent, cb) { var opt = { depth: depth, log: log.warn, dev: true } readInstalled(dir, opt, function (er, data) { pruneNestedExtraneous(data) + filterByEnv(data) var bfs = bfsify(data, args) , lite = getLite(bfs) @@ -88,6 +89,21 @@ function pruneNestedExtraneous (data, visited) { } } +function filterByEnv (data) { + var dev = npm.config.get("dev") + var production = npm.config.get("production") + if (dev === production) return + var dependencies = {} + var devDependencies = data.devDependencies || [] + Object.keys(data.dependencies).forEach(function (name) { + var keys = Object.keys(devDependencies) + if (production && keys.indexOf(name) !== -1) return + if (dev && keys.indexOf(name) === -1) return + dependencies[name] = data.dependencies[name] + }) + data.dependencies = dependencies +} + function alphasort (a, b) { a = a.toLowerCase() b = b.toLowerCase() diff --git a/deps/npm/lib/npm.js b/deps/npm/lib/npm.js index 25b7feab6..3cd21cac1 100644 --- a/deps/npm/lib/npm.js +++ b/deps/npm/lib/npm.js @@ -224,7 +224,7 @@ Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { }) return commandCache[a] - }, enumerable: fullList.indexOf(c) !== -1 }) + }, enumerable: fullList.indexOf(c) !== -1, configurable: true }) // make css-case commands callable via camelCase as well if (c.match(/\-([a-z])/)) { diff --git a/deps/npm/lib/owner.js b/deps/npm/lib/owner.js index 3d33a932a..c9adb7922 100644 --- a/deps/npm/lib/owner.js +++ b/deps/npm/lib/owner.js @@ -26,12 +26,9 @@ owner.completion = function (opts, cb) { var byUser, theUser switch (argv[2]) { case "ls": - if (argv.length > 3) return cb() - return mapToRegistry("-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - npm.registry.get(uri, { auth : auth }, cb) - }) + // FIXME: there used to be registry completion here, but it stopped + // making sense somewhere around 50,000 packages on the registry + return cb() case "rm": if (argv.length > 3) { diff --git a/deps/npm/lib/repo.js b/deps/npm/lib/repo.js index 3db4a16bc..1b0454773 100644 --- a/deps/npm/lib/repo.js +++ b/deps/npm/lib/repo.js @@ -15,14 +15,9 @@ var npm = require("./npm.js") , npa = require("npm-package-arg") repo.completion = function (opts, cb) { - if (opts.conf.argv.remain.length > 2) return cb() - mapToRegistry("/-/short", npm.config, function (er, uri) { - if (er) return cb(er) - - npm.registry.get(uri, { timeout : 60000 }, function (er, list) { - return cb(null, list || []) - }) - }) + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + cb() } function repo (args, cb) { diff --git a/deps/npm/lib/run-script.js b/deps/npm/lib/run-script.js index ce8ea0f13..b6aa5fe7e 100644 --- a/deps/npm/lib/run-script.js +++ b/deps/npm/lib/run-script.js @@ -84,31 +84,56 @@ function runScript (args, cb) { function list(cb) { var json = path.join(npm.localPrefix, "package.json") + var cmdList = [ "publish", "install", "uninstall" + , "test", "stop", "start", "restart" + ].reduce(function (l, p) { + return l.concat(["pre" + p, p, "post" + p]) + }, []) return readJson(json, function(er, d) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) if (er) d = {} - var scripts = Object.keys(d.scripts || {}) + var allScripts = Object.keys(d.scripts || {}) + var scripts = [] + var runScripts = [] + allScripts.forEach(function (script) { + if (cmdList.indexOf(script) !== -1) scripts.push(script) + else runScripts.push(script) + }) if (log.level === "silent") { - return cb(null, scripts) + return cb(null, allScripts) } if (npm.config.get("json")) { console.log(JSON.stringify(d.scripts || {}, null, 2)) - return cb(null, scripts) + return cb(null, allScripts) + } + + if (npm.config.get("parseable")) { + allScripts.forEach(function(script) { + console.log(script + ":" + d.scripts[script]) + }) + return cb(null, allScripts) } - var s = ":" - var prefix = "" - if (!npm.config.get("parseable")) { - s = "\n " - prefix = " " - console.log("Available scripts in the %s package:", d.name) + var s = "\n " + var prefix = " " + if (scripts.length) { + console.log("Lifecycle scripts included in %s:", d.name) } scripts.forEach(function(script) { console.log(prefix + script + s + d.scripts[script]) }) - return cb(null, scripts) + if (!scripts.length && runScripts.length) { + console.log("Scripts available in %s via `npm run-script`:", d.name) + } + else if (runScripts.length) { + console.log("\navailable via `npm run-script`:") + } + runScripts.forEach(function(script) { + console.log(prefix + script + s + d.scripts[script]) + }) + return cb(null, allScripts) }) } @@ -116,7 +141,7 @@ function run (pkg, wd, cmd, args, cb) { if (!pkg.scripts) pkg.scripts = {} var cmds - if (cmd === "restart") { + if (cmd === "restart" && !pkg.scripts.restart) { cmds = [ "prestop", "stop", "poststop", "restart", @@ -134,6 +159,8 @@ function run (pkg, wd, cmd, args, cb) { log.verbose("run-script using default platform env: env (Unix)") pkg.scripts[cmd] = "env" } + } else if (npm.config.get("if-present")) { + return cb(null); } else { return cb(new Error("missing script: " + cmd)) } diff --git a/deps/npm/lib/star.js b/deps/npm/lib/star.js index d2e69deb9..1f324336c 100644 --- a/deps/npm/lib/star.js +++ b/deps/npm/lib/star.js @@ -10,17 +10,9 @@ star.usage = "npm star <package> [pkg, pkg, ...]\n" + "npm unstar <package> [pkg, pkg, ...]" star.completion = function (opts, cb) { - mapToRegistry("-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - var params = { - timeout : 60000, - auth : auth - } - npm.registry.get(uri, params, function (er, list) { - return cb(null, list || []) - }) - }) + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + cb() } function star (args, cb) { diff --git a/deps/npm/lib/uninstall.js b/deps/npm/lib/uninstall.js index 68869f579..600c68197 100644 --- a/deps/npm/lib/uninstall.js +++ b/deps/npm/lib/uninstall.js @@ -28,12 +28,11 @@ function uninstall (args, cb) { if (args.length) return uninstall_(args, nm, cb) // remove this package from the global space, if it's installed there - if (npm.config.get("global")) return cb(uninstall.usage) - readJson(path.resolve(npm.prefix, "package.json"), function (er, pkg) { + readJson(path.resolve(npm.localPrefix, "package.json"), function (er, pkg) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) if (er) return cb(uninstall.usage) uninstall_( [pkg.name] - , npm.dir + , npm.globalDir , cb ) }) diff --git a/deps/npm/lib/utils/completion.sh b/deps/npm/lib/utils/completion.sh index d02759059..3c7a3590d 100755 --- a/deps/npm/lib/utils/completion.sh +++ b/deps/npm/lib/utils/completion.sh @@ -21,10 +21,10 @@ if type complete &>/dev/null; then 2>/dev/null)) || return $? IFS="$si" } - complete -F _npm_completion npm + complete -o default -F _npm_completion npm elif type compdef &>/dev/null; then _npm_completion() { - si=$IFS + local si=$IFS compadd -- $(COMP_CWORD=$((CURRENT-1)) \ COMP_LINE=$BUFFER \ COMP_POINT=0 \ diff --git a/deps/npm/lib/utils/error-handler.js b/deps/npm/lib/utils/error-handler.js index 12c6dd407..de12c6363 100644 --- a/deps/npm/lib/utils/error-handler.js +++ b/deps/npm/lib/utils/error-handler.js @@ -304,11 +304,15 @@ function errorHandler (er) { break case "ETARGET": - log.error("notarget", [er.message + 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." - ].join("\n")) + ] + if (er.parent) { + msg.push("\nIt was specified as a dependency of '"+er.parent+"'\n") + } + log.error("notarget", msg.join("\n")) break case "ENOTSUP": diff --git a/deps/npm/lib/utils/git.js b/deps/npm/lib/utils/git.js index 78cb083ee..a312770a8 100644 --- a/deps/npm/lib/utils/git.js +++ b/deps/npm/lib/utils/git.js @@ -18,8 +18,13 @@ function prefixGitArgs () { } function execGit (args, options, cb) { - log.info("git", args) - return exec(git, prefixGitArgs().concat(args || []), options, cb) + log.info('git', args) + var fullArgs = prefixGitArgs().concat(args || []) + return exec(git, fullArgs, options, function (err) { + if (err) log.error('git', fullArgs.join(' ')) + + cb.apply(null, arguments) + }) } function spawnGit (args, options) { diff --git a/deps/npm/lib/view.js b/deps/npm/lib/view.js index bd20ab5a3..47da39b64 100644 --- a/deps/npm/lib/view.js +++ b/deps/npm/lib/view.js @@ -14,11 +14,9 @@ var npm = require("./npm.js") view.completion = function (opts, cb) { if (opts.conf.argv.remain.length <= 2) { - return mapToRegistry("-/short", npm.config, function (er, uri, auth) { - if (er) return cb(er) - - npm.registry.get(uri, { auth : auth }, cb) - }) + // FIXME: there used to be registry completion here, but it stopped making + // sense somewhere around 50,000 packages on the registry + return cb() } // have the package, get the fields. var tag = npm.config.get("tag") |