diff options
author | isaacs <i@izs.me> | 2010-05-03 07:47:34 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-05-03 07:47:34 +0400 |
commit | 12087998c4046520ea7c4ba213353987b6353181 (patch) | |
tree | b4fc14a79b43af9347416256f79d04688a663504 /lib | |
parent | 4468e84082c080fc8ff59ba6c58f38361c1cd2d8 (diff) |
Fix a few minor bugs, and DRY up the registry data fetch
Diffstat (limited to 'lib')
-rw-r--r-- | lib/install.js | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/lib/install.js b/lib/install.js index d9594bed9..bbf115368 100644 --- a/lib/install.js +++ b/lib/install.js @@ -38,7 +38,7 @@ function registryInstall (pkglist, cb) { }) var defTag = npm.config.get("tag") || "stable" - + // While the list is not empty: // a. If it's a range, and a satisfying version is already installed, // then move on to the next @@ -78,6 +78,7 @@ function registryInstall (pkglist, cb) { seen[pkg] = true function tarballHandler (er, data) { + if (er) return cb(er) log(data, "fetched tarball") npm.set(data) installedPackages[data.name] = installedPackages[data.name] || {} @@ -107,19 +108,22 @@ function registryInstall (pkglist, cb) { , exact = semver.valid(ver) , tag = (!exact && !range) pkg = pkg.join("@") - if (tag) { - tag = ver || defTag - // must fetch data to know how to solve this. - var data = npm.get(name) - if (!data) return registry.get(name, function (er, data) { + // must fetch data to know how to solve this. + var data = npm.get(name) + if (!data) { + log(name, "fetch data") + return registry.get(name, function (er, data) { if (!data) er = new Error("not found in registry: "+name) if (er) return cb(er) npm.set(name, data) seen[pkg] = false return F(pkg) }) + } + // now we know that we have the data. - // now we know that we have the data. + if (tag) { + tag = ver || defTag if (!data["dist-tags"] || !(tag in data["dist-tags"])) { return cb(new Error( "Tag "+tag+" not found for package "+name)) @@ -142,13 +146,6 @@ function registryInstall (pkglist, cb) { return F(pkglist.shift()) } var data = npm.get(name) - if (!data) return registry.get(name, function (er, data) { - if (!data) er = new Error("not found in registry: "+name) - if (er) return cb(er) - npm.set(name, data) - seen[pkg] = false - return F(pkg) - }) // make sure this version exists. if (!(ver in data.versions)) { return cb(new Error( @@ -181,16 +178,9 @@ function registryInstall (pkglist, cb) { if (!seen[satis]) pkglist.push(satis) return F(pkglist.shift()) } - // new thing. fetch from registry. favor stable version. + // new thing. fetch from registry. favor defTag version. var data = npm.get(name) - if (!data) return registry.get(name, function (er, data) { - if (!data) er = new Error("not found in registry: "+name) - if (er) return cb(er) - npm.set(name, data) - seen[pkg] = false - F(pkg) - }) - var stable = data["dist-tags"] && data["dist-tags"].stable + , stable = data["dist-tags"] && data["dist-tags"][defTag] if (stable && semver.satisfies(stable, range)) { stable = name + "@" + stable if (!seen[stable]) pkglist.push(stable) @@ -235,7 +225,7 @@ function installLocalTarball (tarball, cb) { Date.now()+"-"+Math.random()) chain ( [mkdir, folder] - , [unpackTar, target, folder] + , [unpackTar, tarball, folder] , function (er) { if (er) return cb(er) readJson(path.join(folder, "package.json"), function (er,data) { |