Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function install_ (pkg, reg, seen, mustHave, pkglist, cb) {
log.verbose(pkg, "install_")
if (seen[pkg]) return cb() // repeat, skip it
seen[pkg] = true
// it's a local thing or a url if it has a / in it.
if (pkg.indexOf("/") !== -1 || pkg === ".") {
log.silly(pkg, "install local")
return cache.add(pkg, finisher(pkg, reg, pkglist, cb))
}
// now we know it's not a URL or file,
// so handle it like a tag, version, or range.
pkg = pkg.split("@")
var name = pkg[0]
, defTag = npm.config.get("tag")
, ver = pkg.slice(1).join("@").trim() || defTag
, range = semver.validRange(ver)
, exact = semver.valid(ver)
, tag = !exact && !range && range !== "" && ver
log.verbose([pkg, mustHave], "must install?")
pkg = pkg.join("@")
seen[name+"@"+ver] = true
function _source(pkg, reg, pkglist, cb) {
log.verbose(pkg, "_source");
// it's a local thing or a url if it has a / in it.
if (pkg.indexOf("/") !== -1 || pkg === ".") {
log.silly(pkg, "install local");
return cache.add(pkg, finisher(pkg, reg, pkglist, cb));
}
// now we know it's not a URL or file,
// so handle it like a tag, version, or range.
pkg = pkg.split("@");
var name = pkg[0],
defTag = npm.config.get("tag"),
ver = pkg.slice(1).join("@").trim() || defTag,
range = semver.validRange(ver),
exact = semver.valid(ver),
tag = !exact && !range && range !== "" && ver,
pkg = pkg.join("@");
// at this point, assume that it has to be debianized
if (exact) {
getData(name, function (er, data) {
if (er) return cb(er)
log.silly(data, pkg)
if (tag) {
log.verbose(tag, pkg+" tag")
var tags = data["dist-tags"]
if (!tags[tag]) return log.er(cb, "Tag not found: "+data.name+"@"+tag)(er)
install_(data.name+"@"+tags[tag], reg, seen, mustHave, pkglist, cb)
} else {
log.verbose(tag, pkg+" range")
// prefer the default tag version.
var defTag = npm.config.get("tag")
, satis
defTag = defTag && data["dist-tags"] && data["dist-tags"][defTag]
if (semver.satisfies(defTag, range)) satis = defTag
else satis = semver.maxSatisfying(Object.keys(data.versions), range)
if (!satis) return cb(new Error(
"No satisfying version found for '"+data.name+"'@'"+range+"'"))
getData(name, function (er, data) {
if (er) return cb(er);
log.silly(data, pkg);
if (tag) {
log.verbose(tag, pkg + " tag");
var tags = data["dist-tags"];
if (!tags[tag]) return log.er(cb, "Tag not found: " + data.name + "@" + tag)(er);
_source(data.name + "@" + tags[tag], reg, pkglist, cb);
} else {
log.verbose(tag, pkg + " range");
// prefer the default tag version.
var defTag = npm.config.get("tag"), satis;
defTag = defTag && data["dist-tags"] && data["dist-tags"][defTag];
if (semver.satisfies(defTag, range)) satis = defTag;
else satis = semver.maxSatisfying(Object.keys(data.versions), range);
if (!satis) return cb(new Error(
"No satisfying version found for '" + data.name + "'@'" + range + "'"));
_source(data.name + "@" + satis, reg, pkglist, cb);