diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-01-23 06:56:30 -0800 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-01-23 23:19:27 +0100 |
commit | f5b35dbda45c466eda888a4451591c66e8671faf (patch) | |
tree | fe89dd3e105a3693bd0776c678813dadae21065d /deps/npm/lib/cache/add-remote-git.js | |
parent | f3fed5193caaac151acd555a7523068ee269801c (diff) | |
download | node-new-f5b35dbda45c466eda888a4451591c66e8671faf.tar.gz |
deps: upgrade npm to 2.3.0
* Windows improvements: no more uid is undefined errors, use `%COMSPEC%`
when set in preference to hardcoded `cmd`, improved handling of Git
remotes.
* Add caching based on Last-Modified / If-Modified-Since headers in
addition to Etag-based cache validation.
PR-URL: https://github.com/iojs/io.js/pull/573
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/npm/lib/cache/add-remote-git.js')
-rw-r--r-- | deps/npm/lib/cache/add-remote-git.js | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/deps/npm/lib/cache/add-remote-git.js b/deps/npm/lib/cache/add-remote-git.js index 1ad925eec3..c829a4fe6d 100644 --- a/deps/npm/lib/cache/add-remote-git.js +++ b/deps/npm/lib/cache/add-remote-git.js @@ -14,6 +14,7 @@ var mkdir = require("mkdirp") , addLocal = require("./add-local.js") , realizePackageSpecifier = require("realize-package-specifier") , normalizeGitUrl = require("normalize-git-url") + , randomBytes = require("crypto").pseudoRandomBytes // only need uniqueness var remotes = path.resolve(npm.config.get("cache"), "_git-remotes") var templates = path.join(remotes, "_templates") @@ -211,11 +212,23 @@ function resolveHead (p, u, co, origUrl, cb) { * this has to be two steps. */ function cache (p, u, treeish, resolved, cb) { - var tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), treeish) - git.whichAndExec( - [ "clone", p, tmp ], - { cwd : p, env : gitEnv() }, - function (er, stdout, stderr) { + // generate a unique filename + randomBytes(6, function (er, random) { + if (er) return cb(er) + + var tmp = path.join( + npm.tmp, + "git-cache-"+random.toString("hex"), + treeish + ) + + mkdir(tmp, function (er) { + if (er) return cb(er) + + git.whichAndExec(["clone", p, tmp], { cwd : p, env : gitEnv() }, clone) + }) + + function clone (er, stdout, stderr) { stdout = (stdout + "\n" + stderr).trim() if (er) { log.error("Failed to clone "+resolved+" from "+u, stderr) @@ -224,34 +237,32 @@ function cache (p, u, treeish, resolved, cb) { log.verbose("git clone", "from", p) log.verbose("git clone", stdout) - git.whichAndExec( - [ "checkout", treeish ], - { cwd : tmp, env : gitEnv() }, - function (er, stdout, stderr) { - stdout = (stdout + "\n" + stderr).trim() - if (er) { - log.error("Failed to check out "+treeish, stderr) - return cb(er) - } - log.verbose("git checkout", stdout) + git.whichAndExec(["checkout", treeish], { cwd : tmp, env : gitEnv() }, checkout) + } - realizePackageSpecifier(tmp, function (er, spec) { - if (er) { - log.error("Failed to map", tmp, "to a package specifier") - return cb(er) - } + function checkout (er, stdout, stderr) { + stdout = (stdout + "\n" + stderr).trim() + if (er) { + log.error("Failed to check out "+treeish, stderr) + return cb(er) + } + log.verbose("git checkout", stdout) - // https://github.com/npm/npm/issues/6400 - // ensure pack logic is applied - addLocal(spec, null, function (er, data) { - if (data) data._resolved = resolved - cb(er, data) - }) - }) + realizePackageSpecifier(tmp, function (er, spec) { + if (er) { + log.error("Failed to map", tmp, "to a package specifier") + return cb(er) } - ) + + // https://github.com/npm/npm/issues/6400 + // ensure pack logic is applied + addLocal(spec, null, function (er, data) { + if (data) data._resolved = resolved + cb(er, data) + }) + }) } - ) + }) } var gitEnv_ |