Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
stash resolved data on data._resolved
Browse files Browse the repository at this point in the history
Close #3054
  • Loading branch information
isaacs committed Jan 15, 2013
1 parent 17c99c6 commit aaf7dab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
67 changes: 56 additions & 11 deletions lib/cache.js
Expand Up @@ -301,6 +301,10 @@ function addRemoteTarball (u, shasum, name, cb_) {
if (iF.length > 1) return

function cb (er, data) {
if (data) {
data._from = u
data._resolved = u
}
unlock(u, function () {
var c
while (c = iF.shift()) c(er, data)
Expand Down Expand Up @@ -449,15 +453,46 @@ function cloneGitRemote (p, u, co, cb) {
}

function archiveGitRemote (p, u, co, cb) {
exec( npm.config.get("git"), ["fetch", "-a", "origin"], gitEnv(), false, p
, function (er, code, stdout, stderr) {
var git = npm.config.get("git")
var archive = ["fetch", "-a", "origin"]
var resolve = ["rev-list", "-n1", co]
var env = gitEnv()

var errState = null
var n = 0
var resolved = null
var tmp

exec(git, archive, env, false, p, function (er, code, stdout, stderr) {
stdout = (stdout + "\n" + stderr).trim()
if (er) {
log.error("git fetch -a origin ("+u+")", stdout)
return cb(er)
return next(er)
}
log.verbose("git fetch -a origin ("+u+")", stdout)
var tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), "tmp.tgz")
tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), "tmp.tgz")
next()
})

exec(git, resolve, env, false, p, function (er, code, stdout, stderr) {
stdout = (stdout + "\n" + stderr).trim()
if (er) {
log.error("Failed resolving git HEAD (" + u + ")", stderr)
return next(er)
}
log.verbose("git rev-list -n1 " + co, stdout)
var parsed = url.parse(u)
parsed.hash = stdout
resolved = url.format(parsed)
next()
})

function next (er) {
if (errState) return
if (er) return cb(errState = er)

if (++n < 2) return

mkdir(path.dirname(tmp), function (er) {
if (er) return cb(er)
var gzip = zlib.createGzip({ level: 9 })
Expand All @@ -473,10 +508,13 @@ function archiveGitRemote (p, u, co, cb) {
})

cp.stdout.pipe(gzip).pipe(out).on("close", function() {
addLocalTarball(tmp, cb)
addLocalTarball(tmp, function(er, data) {
if (data) data._resolved = resolved
cb(er, data)
})
})
})
})
}
}

var gitEnv_
Expand Down Expand Up @@ -507,6 +545,7 @@ function addNamed (name, x, data, cb_) {
if (iF.length > 1) return

function cb (er, data) {
if (data) data._from = k
unlock(k, function () {
var c
while (c = iF.shift()) c(er, data)
Expand Down Expand Up @@ -714,6 +753,7 @@ function addLocal (p, name, cb_) {
log.error("addLocal", "Could not install %s", p)
return cb_(er)
}
data._from = p
return cb_(er, data)
})
}
Expand Down Expand Up @@ -752,16 +792,21 @@ function maybeGithub (p, name, er, cb) {
})
}

function addLocalTarball (p, name, cb) {
if (typeof cb !== "function") cb = name, name = ""
function addLocalTarball (p, name, cb_) {
if (typeof cb_ !== "function") cb_ = name, name = ""
// if it's a tar, and not in place,
// then unzip to .tmp, add the tmp folder, and clean up tmp
if (p.indexOf(npm.tmp) === 0) return addTmpTarball(p, name, cb)
if (p.indexOf(npm.tmp) === 0) return addTmpTarball(p, name, cb_)

if (p.indexOf(npm.cache) === 0) {
if (path.basename(p) !== "package.tgz") return cb(new Error(
if (path.basename(p) !== "package.tgz") return cb_(new Error(
"Not a valid cache tarball name: "+p))
return addPlacedTarball(p, name, cb)
return addPlacedTarball(p, name, cb_)
}

function cb (er, data) {
if (data) data._resolved = p
return cb_(er, data)
}

// just copy it over and then add the temp tarball file.
Expand Down
2 changes: 1 addition & 1 deletion lib/install.js
Expand Up @@ -615,7 +615,7 @@ function targetResolver (where, context, deps) {
return cb(null, [])
}

if (data) data._from = what
if (data && !data._from) data._from = what

return cb(er, data)
})
Expand Down

0 comments on commit aaf7dab

Please sign in to comment.