diff options
Diffstat (limited to 'deps/npm/lib/cache.js')
-rw-r--r-- | deps/npm/lib/cache.js | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js index a576a8f29..a2f4502c7 100644 --- a/deps/npm/lib/cache.js +++ b/deps/npm/lib/cache.js @@ -753,17 +753,20 @@ function addNameVersion (name, v, data, cb) { } // we got cached data, so let's see if we have a tarball. - fs.stat(path.join(npm.cache, name, ver, "package.tgz"), function (er, s) { - if (!er) readJson( path.join( npm.cache, name, ver - , "package", "package.json" ) - , function (er, data) { + var pkgroot = path.join(npm.cache, name, ver) + var pkgtgz = path.join(pkgroot, "package.tgz") + var pkgjson = path.join(pkgroot, "package", "package.json") + fs.stat(pkgtgz, function (er, s) { + if (!er) { + readJson(pkgjson, function (er, data) { er = needName(er, data) er = needVersion(er, data) - if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) + if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") + return cb(er) if (er) return fetchit() return cb(null, data) }) - else return fetchit() + } else return fetchit() }) function fetchit () { @@ -772,11 +775,18 @@ function addNameVersion (name, v, data, cb) { } // use the same protocol as the registry. - // https registry --> https tarballs. + // https registry --> https tarballs, but + // only if they're the same hostname, or else + // detached tarballs may not work. var tb = url.parse(dist.tarball) - tb.protocol = url.parse(npm.config.get("registry")).protocol - delete tb.href + var rp = url.parse(npm.config.get("registry")) + if (tb.hostname === rp.hostname + && tb.protocol !== rp.protocol) { + tb.protocol = url.parse(npm.config.get("registry")).protocol + delete tb.href + } tb = url.format(tb) + // only add non-shasum'ed packages if --forced. // only ancient things would lack this for good reasons nowadays. if (!dist.shasum && !npm.config.get("force")) { |