diff options
author | isaacs <i@izs.me> | 2013-01-09 15:21:30 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-01-09 15:21:30 -0800 |
commit | aa742ddf80f104bc4f13321668a4ede0c518cd4a (patch) | |
tree | d5edb83aca0a793d82349dacf228cc3689bbf16e /deps/npm/lib | |
parent | 7a2ae4c930224e9c8e9090b6aa3437833f415452 (diff) | |
download | node-new-aa742ddf80f104bc4f13321668a4ede0c518cd4a.tar.gz |
npm: Upgrade to v1.2.0
Diffstat (limited to 'deps/npm/lib')
-rw-r--r-- | deps/npm/lib/cache.js | 14 | ||||
-rw-r--r-- | deps/npm/lib/dedupe.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/deprecate.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/install.js | 108 | ||||
-rw-r--r-- | deps/npm/lib/ls.js | 17 | ||||
-rw-r--r-- | deps/npm/lib/outdated.js | 2 | ||||
-rw-r--r-- | deps/npm/lib/publish.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/run-script.js | 3 | ||||
-rw-r--r-- | deps/npm/lib/uninstall.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/unpublish.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/utils/lifecycle.js | 1 |
11 files changed, 112 insertions, 39 deletions
diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js index c2f870bf18..07f4d3ed73 100644 --- a/deps/npm/lib/cache.js +++ b/deps/npm/lib/cache.js @@ -136,6 +136,7 @@ function read (name, ver, forceBypass, cb) { } readJson(jsonFile, function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return addNamed(name, ver, c) deprCheck(data) c(er, data) @@ -414,7 +415,7 @@ function gitEnv () { if (gitEnv_) return gitEnv_ gitEnv_ = {} for (var k in process.env) { - if (!~['GIT_PROXY_COMMAND'].indexOf(k) && k.match(/^GIT/)) continue + if (!~['GIT_PROXY_COMMAND','GIT_SSH'].indexOf(k) && k.match(/^GIT/)) continue gitEnv_[k] = process.env[k] } return gitEnv_ @@ -601,6 +602,7 @@ function addNameVersion (name, ver, data, cb) { if (!er) readJson( path.join( npm.cache, name, ver , "package", "package.json" ) , function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return fetchit() return cb(null, data) }) @@ -664,10 +666,16 @@ function addLocal (p, name, cb_) { } function maybeGithub (p, name, er, cb) { - var u = "git://github.com/" + p + var u = "https://github.com/" + p , up = url.parse(u) + if (up.hash && up.hash[0] === "#") + up.hash = up.hash.slice(1) + + var ref = encodeURIComponent(up.hash || "master") + up.pathname = path.join(up.pathname, "tarball", ref).replace(/\\/g, "/") + u = url.format(up) log.info("maybeGithub", "Attempting to fetch %s from %s", p, u) - return addRemoteGit(u, up, name, function (er2, data) { + return addRemoteTarball(u, null, name, function (er2, data) { if (er2) return cb(er) return cb(null, data) }) diff --git a/deps/npm/lib/dedupe.js b/deps/npm/lib/dedupe.js index 67481c6dbb..51c6fca90f 100644 --- a/deps/npm/lib/dedupe.js +++ b/deps/npm/lib/dedupe.js @@ -265,6 +265,7 @@ function readInstalled (dir, counter, parent, cb) { }) readJson(path.resolve(dir, "package.json"), function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return cb() // not a package, probably. counter[data.name] = counter[data.name] || 0 counter[data.name]++ diff --git a/deps/npm/lib/deprecate.js b/deps/npm/lib/deprecate.js index c9e724e69d..1ba4305cd7 100644 --- a/deps/npm/lib/deprecate.js +++ b/deps/npm/lib/deprecate.js @@ -25,7 +25,7 @@ var semver = require("semver") function deprecate (args, cb) { var pkg = args[0] , msg = args[1] - if (msg === undefined) return cb(new Error(deprecate.usage)) + if (msg === undefined) return cb("Usage: " + deprecate.usage) // fetch the data and make sure it exists. pkg = pkg.split(/@/) var name = pkg.shift() diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js index ecb5d0d76d..4741c34c7b 100644 --- a/deps/npm/lib/install.js +++ b/deps/npm/lib/install.js @@ -13,13 +13,16 @@ module.exports = install -install.usage = "npm install <tarball file>" - + "\nnpm install <tarball url>" - + "\nnpm install <folder>" +install.usage = "npm install" + "\nnpm install <pkg>" + "\nnpm install <pkg>@<tag>" + "\nnpm install <pkg>@<version>" + "\nnpm install <pkg>@<version range>" + + "\nnpm install <folder>" + + "\nnpm install <tarball file>" + + "\nnpm install <tarball url>" + + "\nnpm install <git:// url>" + + "\nnpm install <github username>/<github project>" + "\n\nCan specify one or more: npm install ./foo.tgz bar@stable /some/folder" + "\nIf no argument is supplied and ./npm-shrinkwrap.json is " + "\npresent, installs dependencies specified in the shrinkwrap." @@ -133,13 +136,19 @@ function install (args, cb_) { , parsed = url.parse(target.replace(/^git\+/, "git")) target = dep + "@" + target return target - }), where, context, cb) + }), where, context, function(er, results) { + if (er) return cb(er, results) + lifecycle(data, "prepublish", where, function(er) { + return cb(er, results) + }) + }) }) } // initial "family" is the name:version of the root, if it's got // a package.json file. readJson(path.resolve(where, "package.json"), function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) data = null var context = { family: {} , ancestors: {} @@ -276,9 +285,9 @@ function save (where, installed, tree, pretty, cb) { } catch (ex) { er = ex } + if (er) { return cb(null, installed, tree, pretty) - } var deps = npm.config.get("save-optional") ? "optionalDependencies" @@ -442,10 +451,13 @@ function installManyTop_ (what, where, context, cb) { return path.resolve(nm, p, "package.json") }), function (jsonfile, cb) { readJson(jsonfile, function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return cb(null, []) return cb(null, [[data.name, data.version]]) }) }, function (er, packages) { + // if there's nothing in node_modules, then don't freak out. + if (er) packages = [] // add all the existing packages to the family list. // however, do not add to the ancestors list. packages.forEach(function (p) { @@ -521,6 +533,7 @@ function targetResolver (where, context, deps) { if (er) return alreadyInstalledManually = [] asyncMap(inst, function (pkg, cb) { readJson(path.resolve(nm, pkg, "package.json"), function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) // error means it's not a package, most likely. if (er) return cb(null, []) @@ -640,6 +653,7 @@ function localLink (target, where, context, cb) { , parent = context.parent readJson(jsonFile, function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er || data._id === target._id) { if (er) { install( path.resolve(npm.globalDir, "..") @@ -896,39 +910,65 @@ function write (target, targetFolder, context, cb_) { // before continuing to installing dependencies, check for a shrinkwrap. var opt = { dev: npm.config.get("dev") } readDependencies(context, targetFolder, opt, function (er, data, wrap) { - var deps = Object.keys(data.dependencies || {}) - - // don't install bundleDependencies, unless they're missing. - if (data.bundleDependencies) { - deps = deps.filter(function (d) { - return data.bundleDependencies.indexOf(d) === -1 || - bundled.indexOf(d) === -1 - }) - } - - var newcontext = { family: family + var deps = prepareForInstallMany(data, "dependencies", bundled, wrap, + family) + var depsTargetFolder = targetFolder + var depsContext = { family: family , ancestors: context.ancestors , parent: target , explicit: false , wrap: wrap } - installMany(deps.filter(function (d) { - // prefer to not install things that are satisfied by - // something in the "family" list, unless we're installing - // from a shrinkwrap. - return wrap || !semver.satisfies(family[d], data.dependencies[d]) - }).map(function (d) { - var t = data.dependencies[d] - , parsed = url.parse(t.replace(/^git\+/, "git")) - t = d + "@" + t - return t - }), targetFolder, newcontext, function (er, d) { - log.verbose("about to build", targetFolder) - if (er) return cb(er) - npm.commands.build( [targetFolder] - , npm.config.get("global") - , true - , function (er) { return cb(er, d) }) - }) + + var peerDeps = prepareForInstallMany(data, "peerDependencies", bundled, + wrap, family) + var pdTargetFolder = path.resolve(targetFolder, "..", "..") + var pdContext = context + + var actions = + [ [ installManyAndBuild, deps, depsTargetFolder, depsContext ] ] + + if (peerDeps.length > 0) { + actions.push( + [ installManyAndBuild, peerDeps, pdTargetFolder, pdContext ] + ) + } + + chain(actions, cb) }) }) } + +function installManyAndBuild (deps, targetFolder, context, cb) { + installMany(deps, targetFolder, context, function (er, d) { + log.verbose("about to build", targetFolder) + if (er) return cb(er) + npm.commands.build( [targetFolder] + , npm.config.get("global") + , true + , function (er) { return cb(er, d) }) + }) +} + +function prepareForInstallMany (packageData, depsKey, bundled, wrap, family) { + var deps = Object.keys(packageData[depsKey] || {}) + + // don't install bundleDependencies, unless they're missing. + if (packageData.bundleDependencies) { + deps = deps.filter(function (d) { + return packageData.bundleDependencies.indexOf(d) === -1 || + bundled.indexOf(d) === -1 + }) + } + + return deps.filter(function (d) { + // prefer to not install things that are satisfied by + // something in the "family" list, unless we're installing + // from a shrinkwrap. + return wrap || !semver.satisfies(family[d], packageData[depsKey][d]) + }).map(function (d) { + var t = packageData[depsKey][d] + , parsed = url.parse(t.replace(/^git\+/, "git")) + t = d + "@" + t + return t + }) +} diff --git a/deps/npm/lib/ls.js b/deps/npm/lib/ls.js index 8a4d6277f2..637064eab6 100644 --- a/deps/npm/lib/ls.js +++ b/deps/npm/lib/ls.js @@ -68,7 +68,7 @@ function ls (args, silent, cb) { }) } -// only include +// only include function filter (data, args) { } @@ -112,6 +112,14 @@ function getLite (data, noname) { + " " + (data.path || "") ) } + if (data.peerInvalid) { + lite.peerInvalid = true + lite.problems = lite.problems || [] + lite.problems.push( "peer invalid: " + + data.name + "@" + data.version + + " " + (data.path || "") ) + } + if (data.dependencies) { var deps = Object.keys(data.dependencies) if (deps.length) lite.dependencies = deps.map(function (d) { @@ -244,6 +252,12 @@ function makeArchy_ (data, long, dir, depth, parent, d) { + (color ? "\033[0m" : "") } + if (data.peerInvalid) { + out.label += " " + (color ? "\033[31;40m" : "") + + "peer invalid" + + (color ? "\033[0m" : "") + } + if (data.extraneous && data.path !== dir) { out.label += " " + (color ? "\033[32;40m" : "") + "extraneous" @@ -331,4 +345,5 @@ function makeParseable_ (data, long, dir, depth, parent, d) { + ":" + (data.realPath !== data.path ? data.realPath : "") + (data.extraneous ? ":EXTRANEOUS" : "") + (data.invalid ? ":INVALID" : "") + + (data.peerInvalid ? ":PEERINVALID" : "") } diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js index 33c182c997..bb9f93eadf 100644 --- a/deps/npm/lib/outdated.js +++ b/deps/npm/lib/outdated.js @@ -76,6 +76,7 @@ function outdated_ (args, dir, parentHas, cb) { var deps = null readJson(path.resolve(dir, "package.json"), function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) deps = (er) ? true : (d.dependencies || {}) return next() }) @@ -89,6 +90,7 @@ function outdated_ (args, dir, parentHas, cb) { asyncMap(pkgs, function (pkg, cb) { var jsonFile = path.resolve(dir, "node_modules", pkg, "package.json") readJson(jsonFile, function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) cb(null, er ? [] : [[d.name, d.version]]) }) }, function (er, pvs) { diff --git a/deps/npm/lib/publish.js b/deps/npm/lib/publish.js index bb6a4cede0..027ea59553 100644 --- a/deps/npm/lib/publish.js +++ b/deps/npm/lib/publish.js @@ -32,6 +32,7 @@ function publish (args, isRetry, cb) { var arg = args[0] // if it's a local folder, then run the prepublish there, first. readJson(path.resolve(arg, "package.json"), function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) // error is ok. could be publishing a url or tarball // however, that means that we will not have automatically run // the prepublish script, since that gets run when adding a folder diff --git a/deps/npm/lib/run-script.js b/deps/npm/lib/run-script.js index 4af74eefde..d509cc86e0 100644 --- a/deps/npm/lib/run-script.js +++ b/deps/npm/lib/run-script.js @@ -25,6 +25,7 @@ runScript.completion = function (opts, cb) { // or a package, in which case, complete against its scripts var json = path.join(npm.prefix, "package.json") return readJson(json, function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) if (er) d = {} var scripts = Object.keys(d.scripts || {}) console.error("local scripts", scripts) @@ -35,6 +36,7 @@ runScript.completion = function (opts, cb) { var pkgDir = path.resolve( pref, "node_modules" , argv[2], "package.json" ) readJson(pkgDir, function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) if (er) d = {} var scripts = Object.keys(d.scripts || {}) return cb(null, scripts) @@ -55,6 +57,7 @@ runScript.completion = function (opts, cb) { if (npm.config.get("global")) scripts = [], next() else readJson(path.join(npm.prefix, "package.json"), function (er, d) { + if (er && er.code !== "ENOENT") return cb(er) d = d || {} scripts = Object.keys(d.scripts || {}) next() diff --git a/deps/npm/lib/uninstall.js b/deps/npm/lib/uninstall.js index b4dbd1de08..275088ef70 100644 --- a/deps/npm/lib/uninstall.js +++ b/deps/npm/lib/uninstall.js @@ -30,6 +30,7 @@ function uninstall (args, 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) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return cb(uninstall.usage) uninstall_( [pkg.name] , npm.dir diff --git a/deps/npm/lib/unpublish.js b/deps/npm/lib/unpublish.js index def308525c..c0056e7768 100644 --- a/deps/npm/lib/unpublish.js +++ b/deps/npm/lib/unpublish.js @@ -56,6 +56,7 @@ function unpublish (args, cb) { // read the package name and version out of that. var cwdJson = path.join(process.cwd(), "package.json") return readJson(cwdJson, function (er, data) { + if (er && er.code !== "ENOENT") return cb(er) if (er) return cb("Usage:\n"+unpublish.usage) gotProject(data.name, data.version, cb) }) diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js index 97adb96585..825edc9b98 100644 --- a/deps/npm/lib/utils/lifecycle.js +++ b/deps/npm/lib/utils/lifecycle.js @@ -49,6 +49,7 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) { var env = makeEnv(pkg) env.npm_lifecycle_event = stage 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 // even if it's never used, sh freaks out. |