Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-05-15 04:47:43 +0400
committerisaacs <i@izs.me>2014-05-15 04:47:43 +0400
commit0404aa49d0affc618b7b15b63eb07cdd7d49906a (patch)
tree0e7e46fc4eb901a674e1048e4de56165699f5815
parent1e24837688308266c00e379cdbb8aeae85dd717f (diff)
addLocalTarball: Use pkgData instead of name/version
-rw-r--r--lib/cache/add-local-tarball.js30
-rw-r--r--lib/cache/add-local.js4
-rw-r--r--lib/cache/add-remote-git.js2
-rw-r--r--lib/cache/add-remote-tarball.js2
4 files changed, 24 insertions, 14 deletions
diff --git a/lib/cache/add-local-tarball.js b/lib/cache/add-local-tarball.js
index 0373a3077..7a65b7080 100644
--- a/lib/cache/add-local-tarball.js
+++ b/lib/cache/add-local-tarball.js
@@ -20,30 +20,31 @@ var mkdir = require("mkdirp")
module.exports = addLocalTarball
-function addLocalTarball (p, name, version, shasum, cb_) {
+function addLocalTarball (p, pkgData, shasum, cb_) {
assert(typeof p === "string", "must have path")
assert(typeof cb_ === "function", "must have callback")
- if (name === undefined || name === null) name = ""
- if (!version) version = ""
+ if (!pkgData) pkgData = {}
+ var name = pkgData.name || ""
+ var version = pkgData.version || ""
// If we don't have a shasum yet, then get the shasum now.
if (!shasum) {
return sha.get(p, function (er, shasum) {
if (er) return cb_(er)
- addLocalTarball(p, name, version, shasum, cb_)
+ addLocalTarball(p, pkgData, shasum, cb_)
})
}
// if it's a tar, and not in place,
// then unzip to .tmp, add the tmp folder, and clean up tmp
if (pathIsInside(p, npm.tmp))
- return addTmpTarball(p, name, version, shasum, cb_)
+ return addTmpTarball(p, pkgData, shasum, cb_)
if (pathIsInside(p, npm.cache)) {
if (path.basename(p) !== "package.tgz") return cb_(new Error(
"Not a valid cache tarball name: "+p))
- return addPlacedTarball(p, name, shasum, cb_)
+ return addPlacedTarball(p, pkgData, shasum, cb_)
}
function cb (er, data) {
@@ -196,9 +197,12 @@ function addPlacedTarball_ (p, name, uid, gid, resolvedSum, cb) {
}
}
-function addTmpTarball (tgz, name, version, shasum, cb) {
+function addTmpTarball (tgz, pkgData, shasum, cb) {
+ assert(typeof cb === "function", "must have callback function")
// Just have a placeholder here so we can move it into place after.
var tmp = false
+ var version = pkgData.version || ""
+ var name = pkgData.name || ""
if (!version) {
tmp = true
version = 'tmp_' + crypto.randomBytes(6).toString('hex')
@@ -226,7 +230,7 @@ function addTmpTarball (tgz, name, version, shasum, cb) {
readJson(pj, function (er, data) {
if (er) return cb(er)
if (version === data.version && name === data.name && !tmp) {
- addTmpTarball_(tgz, data, name, version, shasum, cb)
+ addTmpTarball_(tgz, data, shasum, cb)
} else {
var old = pdir
name = data.name
@@ -240,7 +244,7 @@ function addTmpTarball (tgz, name, version, shasum, cb) {
if (er) return cb(er)
rm(old, function(er) {
if (er) return cb(er)
- addTmpTarball_(tgz, data, name, version, shasum, cb)
+ addTmpTarball_(tgz, data, shasum, cb)
})
})
})
@@ -250,8 +254,14 @@ function addTmpTarball (tgz, name, version, shasum, cb) {
}
}
-function addTmpTarball_ (tgz, data, name, version, shasum, cb) {
+function addTmpTarball_ (tgz, data, shasum, cb) {
+ assert(typeof cb === "function", "must have callback function")
cb = once(cb)
+ var name = data.name
+ var version = data.version
+ assert(name, "should have package name by now")
+ assert(version, "should have package version by now")
+
var target = path.resolve(npm.cache, name, version, "package.tgz")
var read = fs.createReadStream(tgz)
var write = fs.createWriteStream(target)
diff --git a/lib/cache/add-local.js b/lib/cache/add-local.js
index 66d4412a0..b5902190f 100644
--- a/lib/cache/add-local.js
+++ b/lib/cache/add-local.js
@@ -55,7 +55,7 @@ function addLocal (p, name, cb_) {
return cb(er)
}
if (s.isDirectory()) addLocalDirectory(p, name, null, cb)
- else addLocalTarball(p, name, cb)
+ else addLocalTarball(p, { name: name }, null, cb)
})
})
}
@@ -103,7 +103,7 @@ function addLocalDirectory (p, name, shasum, cb) {
chownr(made || tgz, cs.uid, cs.gid, function (er) {
if (er) return cb(er)
- addLocalTarball(tgz, name, version, shasum, cb)
+ addLocalTarball(tgz, data, shasum, cb)
})
})
})
diff --git a/lib/cache/add-remote-git.js b/lib/cache/add-remote-git.js
index 35a0dae4b..2168d189f 100644
--- a/lib/cache/add-remote-git.js
+++ b/lib/cache/add-remote-git.js
@@ -262,7 +262,7 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
})
cp.stdout.pipe(gzip).pipe(out).on("close", function() {
- addLocalTarball(tmp, "", "", null, function(er, data) {
+ addLocalTarball(tmp, null, null, function(er, data) {
if (data) data._resolved = resolved
cb(er, data)
})
diff --git a/lib/cache/add-remote-tarball.js b/lib/cache/add-remote-tarball.js
index eae305f10..b14da7721 100644
--- a/lib/cache/add-remote-tarball.js
+++ b/lib/cache/add-remote-tarball.js
@@ -40,7 +40,7 @@ function addRemoteTarball (u, shasum, pkgData, cb_) {
function next (er, resp, shasum) {
if (er) return cb(er)
- addLocalTarball(tmp, pkgData.name, pkgData.version, shasum, cb)
+ addLocalTarball(tmp, pkgData, shasum, cb)
}
lock(u, function (er) {