diff options
author | isaacs <i@izs.me> | 2010-05-03 06:17:14 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-05-03 06:17:14 +0400 |
commit | 78ceb969a90affdb8eece2c678da7fffad33081c (patch) | |
tree | 0a81fcd283413cc23a6c1a91c22ff82627030481 /lib | |
parent | 8f203371b94a9a3d9e9bb43fd6b9761bf67a9de3 (diff) |
Fail when a package isn't found in the registry. Add support for installing a local tarball, so that registry-install can replace install
Diffstat (limited to 'lib')
-rw-r--r-- | lib/registry-install.js | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/lib/registry-install.js b/lib/registry-install.js index f6e231953..d8472d9f5 100644 --- a/lib/registry-install.js +++ b/lib/registry-install.js @@ -76,23 +76,29 @@ function registryInstall (pkglist, cb) { return F(pkglist.shift()) } seen[pkg] = true - if (pkg.match(/^https?:\/\//)) { - return fetchTarball(pkg, function (er, data) { - log(data, "fetched tarball") - if (!npm.get(data._id)) npm.set(data) - installedPackages[data.name] = installedPackages[data.name] || {} - installedPackages[data.name][data.version] = data - installReg[data.name] = installReg[data.name] || {} - installReg[data.name][data.version] = data - installList.push(path.join(data.name, data.version)) - // also make sure to get any dependencies. - if (data.dependencies) for (var dep in data.dependencies) { - dep = dep.trim()+"@"+data.dependencies[dep] - if (!seen[dep]) pkglist.push(dep) - } - F(pkglist.shift()) - }) + + function tarballHandler (er, data) { + log(data, "fetched tarball") + npm.set(data) + installedPackages[data.name] = installedPackages[data.name] || {} + installedPackages[data.name][data.version] = data + installReg[data.name] = installReg[data.name] || {} + installReg[data.name][data.version] = data + installList.push(path.join(data.name, data.version)) + // also make sure to get any dependencies. + if (data.dependencies) for (var dep in data.dependencies) { + dep = dep.trim()+"@"+data.dependencies[dep] + if (!seen[dep]) pkglist.push(dep) + } + F(pkglist.shift()) + } + if (pkg.match(/^(file:|\.|\/)/)) { + pkg = pkg.replace(/^file:(\/\/)?/, '') + if (pkg.charAt(0) !== "/") pkg = path.join(process.cwd(), pkg) + return installLocalTarball(pkg, tarballHandler) } + if (pkg.match(/^https?:\/\//)) return fetchTarball(pkg, tarballHandler) + // now we know it's not a URL, so handle it like a tag, version, or range. pkg = pkg.split("@") var name = pkg[0] @@ -103,10 +109,10 @@ function registryInstall (pkglist, cb) { pkg = pkg.join("@") if (tag) { tag = ver || defTag - log(tag, "registry-install tag") // must fetch data to know how to solve this. 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 @@ -137,6 +143,7 @@ function registryInstall (pkglist, cb) { } 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 @@ -177,6 +184,7 @@ function registryInstall (pkglist, cb) { // new thing. fetch from registry. favor stable version. var data = npm.get(name) if (!data) return registry.get(pkg, function (er, data) { + if (!data) er = new Error("not found in registry: "+pkg) if (er) return cb(er) npm.set(name, data) seen[pkg] = false @@ -205,29 +213,42 @@ function registryInstall (pkglist, cb) { // download the tarball, and move the contents into // the appropriate name/version folder. function fetchTarball (tarball, cb) { - var folder = path.join(npm.tmp, tarball.replace(/[^a-zA-Z0-9]/g, "-")+"-"+ - Date.now()+"-"+Math.random()) - , target = folder + ".tgz" + var target = path.join(npm.tmp, tarball.replace(/[^a-zA-Z0-9]/g, "-")+"-"+ + Date.now()+"-"+Math.random()) + ".tgz" chain ( [mkdir, npm.tmp] - , [mkdir, folder] , [fetch, tarball, target] - , [unpackTar, target, folder] - , function (er) { + , function (er, ok) { if (er) return cb(er) - readJson(path.join(folder, "package.json"), function (er,data) { - log(data, "readJson from "+folder) - chain - ( [moveIntoPlace, folder, data] - , [log, "moved into place", "fuckererrrr"] - , [rm, folder] - , [rm, target] - , function (er) { return cb(er, data) } - ) + installLocalTarball(target, function (er, data) { + if (er) return cb(er) + rm(target, function (er) { + if (er) return cb(er) + cb(data) + }) }) } ) } +function installLocalTarball (tarball, cb) { + var folder = path.join(npm.tmp, tarball.replace(/[^a-zA-Z0-9]/g, "-")+"-"+ + Date.now()+"-"+Math.random()) + chain + ( [mkdir, folder] + , [unpackTar, target, folder] + , function (er) { + if (er) return cb(er) + readJson(path.join(folder, "package.json"), function (er,data) { + chain + ( [moveIntoPlace, folder, data] + , [rm, folder] + , function (er) { return cb(er, data) } + ) + }) + } + ) + +} function unpackTar (tarball, unpackTarget, cb) { exec("tar", ["xzvf", tarball, "--strip", "1", "-C", unpackTarget], cb) |