summaryrefslogtreecommitdiff
path: root/deps/npm/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-10-24 09:21:59 -0700
committerisaacs <i@izs.me>2013-10-24 09:22:13 -0700
commitf6f176e10872cac9dcdcd46a92c9ebfe4740f117 (patch)
tree2928003417e60d9bad43056b8579171bf0e75552 /deps/npm/lib
parent808a968409b6c6cc305506efd3caa4477a376125 (diff)
downloadandroid-node-v8-f6f176e10872cac9dcdcd46a92c9ebfe4740f117.tar.gz
android-node-v8-f6f176e10872cac9dcdcd46a92c9ebfe4740f117.tar.bz2
android-node-v8-f6f176e10872cac9dcdcd46a92c9ebfe4740f117.zip
npm@1.3.12
Diffstat (limited to 'deps/npm/lib')
-rw-r--r--deps/npm/lib/cache.js5
-rw-r--r--deps/npm/lib/dedupe.js9
-rw-r--r--deps/npm/lib/docs.js14
-rw-r--r--deps/npm/lib/ls.js2
-rw-r--r--deps/npm/lib/outdated.js58
-rw-r--r--deps/npm/lib/repo.js10
-rw-r--r--deps/npm/lib/unbuild.js5
-rw-r--r--deps/npm/lib/utils/error-handler.js2
-rw-r--r--deps/npm/lib/utils/lifecycle.js71
9 files changed, 123 insertions, 53 deletions
diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js
index a8bd6b388f..a576a8f29c 100644
--- a/deps/npm/lib/cache.js
+++ b/deps/npm/lib/cache.js
@@ -1122,7 +1122,10 @@ function addLocalDirectory (p, name, shasum, cb) {
getCacheStat(function (er, cs) {
mkdir(path.dirname(tgz), function (er, made) {
if (er) return cb(er)
- tar.pack(tgz, p, data, false, function (er) {
+
+ var fancy = p.indexOf(npm.tmp) !== 0
+ && p.indexOf(npm.cache) !== 0
+ tar.pack(tgz, p, data, fancy, function (er) {
if (er) {
log.error( "addLocalDirectory", "Could not pack %j to %j"
, p, tgz )
diff --git a/deps/npm/lib/dedupe.js b/deps/npm/lib/dedupe.js
index 648397b7ac..34e71177c7 100644
--- a/deps/npm/lib/dedupe.js
+++ b/deps/npm/lib/dedupe.js
@@ -248,7 +248,14 @@ function findVersions (npm, summary, cb) {
npm.registry.get(name, function (er, data) {
var regVersions = er ? [] : Object.keys(data.versions)
var locMatch = bestMatch(versions, ranges)
- var regMatch = bestMatch(regVersions, ranges)
+ var regMatch;
+ var tag = npm.config.get("tag");
+ var distTags = data["dist-tags"];
+ if (distTags && distTags[tag] && data.versions[distTags[tag]]) {
+ regMatch = distTags[tag]
+ } else {
+ regMatch = bestMatch(regVersions, ranges)
+ }
cb(null, [[name, has, loc, locMatch, regMatch, locs]])
})
diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js
index ff2e381f8d..78e8d3eaac 100644
--- a/deps/npm/lib/docs.js
+++ b/deps/npm/lib/docs.js
@@ -1,4 +1,3 @@
-
module.exports = docs
docs.usage = "npm docs <pkgname>"
@@ -17,9 +16,16 @@ var npm = require("./npm.js")
function docs (args, cb) {
if (!args.length) return cb(docs.usage)
- var n = args[0].split("@").shift()
- registry.get(n + "/latest", 3600, function (er, d) {
- if (er) return cb(er)
+ var project = args[0]
+ var npmName = project.split("@").shift()
+ registry.get(project + "/latest", 3600, function (er, d) {
+ if (er) {
+ if (project.split("/").length !== 2) return cb(er)
+
+ var url = "https://github.com/" + project + "#readme"
+ return opener(url, { command: npm.config.get("browser") }, cb)
+ }
+
var homepage = d.homepage
, repo = d.repository || d.repositories
, url = homepage ? homepage
diff --git a/deps/npm/lib/ls.js b/deps/npm/lib/ls.js
index 842b612cca..194aae6354 100644
--- a/deps/npm/lib/ls.js
+++ b/deps/npm/lib/ls.js
@@ -63,6 +63,8 @@ function ls (args, silent, cb) {
}
console.log(out)
+ if (args.length && !data._found) process.exitCode = 1
+
// if any errors were found, then complain and exit status 1
if (lite.problems && lite.problems.length) {
er = lite.problems.join('\n')
diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js
index d9ef3ca0b9..2624844b5f 100644
--- a/deps/npm/lib/outdated.js
+++ b/deps/npm/lib/outdated.js
@@ -45,6 +45,7 @@ function makePretty (p) {
, dir = path.resolve(p[0], "node_modules", dep)
, has = p[2]
, want = p[3]
+ , latest = p[4]
// XXX add --json support
// Should match (more or less) the output of ls --json
@@ -61,8 +62,10 @@ function makePretty (p) {
if (!npm.config.get("global")) {
dir = path.relative(process.cwd(), dir)
}
- return dep + "@" + want + " " + dir
+ return dep + " " + dir
+ " current=" + (has || "MISSING")
+ + " wanted=" + want
+ + " latest=" + latest
}
function outdated_ (args, dir, parentHas, cb) {
@@ -78,6 +81,17 @@ function outdated_ (args, dir, parentHas, cb) {
readJson(path.resolve(dir, "package.json"), function (er, d) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
deps = (er) ? true : (d.dependencies || {})
+ var doUpdate = npm.config.get("dev") ||
+ (!npm.config.get("production") &&
+ !Object.keys(parentHas).length &&
+ !npm.config.get("global"))
+ if (!er && d && doUpdate) {
+ Object.keys(d.devDependencies || {}).forEach(function (k) {
+ if (!(k in parentHas)) {
+ deps[k] = d.devDependencies[k]
+ }
+ })
+ }
return next()
})
@@ -143,29 +157,35 @@ function shouldUpdate (args, dir, dep, has, req, cb) {
, cb )
}
- function doIt (shouldHave) {
- cb(null, [[ dir, dep, curr && curr.version, shouldHave, req ]])
+ function doIt (wanted, latest) {
+ cb(null, [[ dir, dep, curr && curr.version, wanted, latest, req ]])
}
if (args.length && args.indexOf(dep) === -1) {
return skip()
}
- // so, we can conceivably update this. find out if we need to.
- cache.add(dep, req, function (er, d) {
- // if this fails, then it means we can't update this thing.
- // it's probably a thing that isn't published.
- if (er) return skip()
-
- // check that the url origin hasn't changed (#1727) and that
- // there is no newer version available
- var dFromUrl = d._from && url.parse(d._from).protocol
- var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
-
- if (!curr || dFromUrl && cFromUrl && d._from !== curr.from
- || d.version !== curr.version)
- doIt(d.version)
- else
- skip()
+ var registry = npm.registry
+ // search for the latest package
+ registry.get(dep + "/latest", function (er, l) {
+ if (er) return cb()
+ // so, we can conceivably update this. find out if we need to.
+ cache.add(dep, req, function (er, d) {
+ // if this fails, then it means we can't update this thing.
+ // it's probably a thing that isn't published.
+ if (er) return skip()
+
+ // check that the url origin hasn't changed (#1727) and that
+ // there is no newer version available
+ var dFromUrl = d._from && url.parse(d._from).protocol
+ var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
+
+ if (!curr || dFromUrl && cFromUrl && d._from !== curr.from
+ || d.version !== curr.version
+ || d.version !== l.version)
+ doIt(d.version, l.version)
+ else
+ skip()
+ })
})
}
diff --git a/deps/npm/lib/repo.js b/deps/npm/lib/repo.js
index 19066c8228..c91e593bfd 100644
--- a/deps/npm/lib/repo.js
+++ b/deps/npm/lib/repo.js
@@ -15,6 +15,7 @@ var npm = require("./npm.js")
, log = require("npmlog")
, opener = require("opener")
, github = require('github-url-from-git')
+ , githubUserRepo = require("github-url-from-username-repo")
function repo (args, cb) {
if (!args.length) return cb(repo.usage)
@@ -23,7 +24,14 @@ function repo (args, cb) {
if (er) return cb(er)
var r = d.repository;
if (!r) return cb(new Error('no repository'));
- var url = github(r.url);
+ // XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
+ // from https://github.com/isaacs/npm-www/issues/418
+ if (githubUserRepo(r.url))
+ r.url = githubUserRepo(r.url)
+
+ var url = github(r.url)
+ if (!url)
+ return cb(new Error('no repository: could not get url'))
opener(url, { command: npm.config.get("browser") }, cb)
})
}
diff --git a/deps/npm/lib/unbuild.js b/deps/npm/lib/unbuild.js
index ec34d5688c..57688f0692 100644
--- a/deps/npm/lib/unbuild.js
+++ b/deps/npm/lib/unbuild.js
@@ -20,7 +20,10 @@ function unbuild (args, silent, cb) {
asyncMap(args, unbuild_(silent), cb)
}
-function unbuild_ (silent) { return function (folder, cb) {
+function unbuild_ (silent) { return function (folder, cb_) {
+ function cb (er) {
+ cb_(er, path.relative(npm.root, folder))
+ }
folder = path.resolve(folder)
delete build._didBuild[folder]
log.info(folder, "unbuild")
diff --git a/deps/npm/lib/utils/error-handler.js b/deps/npm/lib/utils/error-handler.js
index 8637592ab1..a82f97ec1d 100644
--- a/deps/npm/lib/utils/error-handler.js
+++ b/deps/npm/lib/utils/error-handler.js
@@ -44,7 +44,7 @@ process.on("exit", function (code) {
})
function exit (code, noLog) {
- exitCode = exitCode || code
+ exitCode = exitCode || process.exitCode || code
var doExit = npm.config.get("_exit")
log.verbose("exit", [code, doExit])
diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js
index 1f9da46716..32fb28f367 100644
--- a/deps/npm/lib/utils/lifecycle.js
+++ b/deps/npm/lib/utils/lifecycle.js
@@ -8,9 +8,9 @@ var log = require("npmlog")
, path = require("path")
, fs = require("graceful-fs")
, chain = require("slide").chain
- , constants = require("constants")
, Stream = require("stream").Stream
, PATH = "PATH"
+ , uidNumber = require("uid-number")
// windows calls it's path "Path" usually, but this is not guaranteed.
if (process.platform === "win32") {
@@ -132,38 +132,68 @@ 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
- , user = unsafe ? null : npm.config.get("user")
- , group = unsafe ? null : npm.config.get("group")
, cmd = env.npm_lifecycle_script
- , sh = "sh"
- , shFlag = "-c"
+
+ var note = "\n> " + pkg._id + " " + stage + " " + wd
+ + "\n> " + cmd + "\n"
+ console.log(note)
+ runCmd(cmd, pkg, env, stage, wd, unsafe, cb)
+}
+
+function runCmd (cmd, pkg, env, stage, wd, unsafe, cb) {
+ var user = unsafe ? null : npm.config.get("user")
+ , group = unsafe ? null : npm.config.get("group")
+
+ log.verbose("unsafe-perm in lifecycle", unsafe)
+
+ if (process.platform === "win32") {
+ unsafe = true
+ }
+
+ if (unsafe) {
+ runCmd_(cmd, pkg, env, wd, stage, unsafe, 0, 0, cb)
+ } else {
+ uidNumber(user, group, function (er, uid, gid) {
+ runCmd_(cmd, pkg, env, wd, stage, unsafe, uid, gid, cb)
+ })
+ }
+}
+
+function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb) {
+ var sh = "sh"
+ var shFlag = "-c"
if (process.platform === "win32") {
sh = "cmd"
shFlag = "/c"
}
- log.verbose("unsafe-perm in lifecycle", unsafe)
-
- var note = "\n> " + pkg._id + " " + stage + " " + wd
- + "\n> " + cmd + "\n"
+ var conf = { cwd: wd
+ , env: env
+ , stdio: [ 0, 1, 2 ]
+ }
- console.log(note)
+ if (!unsafe) {
+ conf.uid = uid
+ conf.gid = gid
+ }
- var conf = { cwd: wd, env: env, customFds: [ 0, 1, 2] }
var proc = spawn(sh, [shFlag, cmd], conf)
- proc.on("close", function (er, stdout, stderr) {
+ proc.on("close", function (code) {
+ if (code) {
+ var er = new Error("Exit status " + code)
+ }
if (er && !npm.ROLLBACK) {
log.info(pkg._id, "Failed to exec "+stage+" script")
er.message = pkg._id + " "
- + stage + ": `" + env.npm_lifecycle_script+"`\n"
+ + stage + ": `" + cmd +"`\n"
+ er.message
if (er.code !== "EPERM") {
er.code = "ELIFECYCLE"
}
er.pkgid = pkg._id
er.stage = stage
- er.script = env.npm_lifecycle_script
+ er.script = cmd
er.pkgname = pkg.name
return cb(er)
} else if (er) {
@@ -175,6 +205,7 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) {
})
}
+
function runHookLifecycle (pkg, env, wd, unsafe, cb) {
// check for a hook script, run if present.
var stage = env.npm_lifecycle_event
@@ -185,17 +216,7 @@ function runHookLifecycle (pkg, env, wd, unsafe, cb) {
fs.stat(hook, function (er) {
if (er) return cb()
-
- 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)
- }
- if (npm.ROLLBACK) return cb()
- cb(er)
- })
+ runCmd(hook, pkg, env, stage, wd, unsafe, cb)
})
}