Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// dep link out of the edgesIn set. Choose the edge with the fewest
// number of `node_modules` sections in the requestor path, and then
// lexically sort afterwards.
const edge = [...node.edgesIn].filter(edge => edge.valid).sort((a, b) => {
const aloc = a.from.location.split('node_modules')
const bloc = b.from.location.split('node_modules')
/* istanbul ignore next - sort calling order is indeterminate */
return aloc.length > bloc.length ? 1
: bloc.length > aloc.length ? -1
: aloc[aloc.length - 1].localeCompare(bloc[bloc.length - 1])
})[0]
// if we don't have one, just an empty object so nothing matches below
// This will effectively just save the version and resolved, as if it's
// a standard version/range dep, which is a reasonable default.
const spec = !edge ? {}
: npa.resolve(node.name, edge.spec, edge.from.realpath)
const rSpec = specFromResolved(node.resolved)
if (node.target)
lock.version = `file:${relpath(this.path, node.realpath)}`
else if (spec && (spec.type === 'file' || spec.type === 'remote'))
lock.version = spec.saveSpec
else if (spec && spec.type === 'git' || rSpec && rSpec.type === 'git') {
lock.version = node.resolved
/* istanbul ignore else - don't think there are any cases where a git
* spec (or indeed, ANY npa spec) doesn't have a .raw member */
if (spec.raw)
lock.from = spec.raw
} else if (!node.isRoot &&
node.package &&
node.package.name &&
private async hasMismatchedPeer(manifest: PackageManifest): Promise {
for (const peer in manifest.peerDependencies) {
let peerIdentifier;
try {
peerIdentifier = npa.resolve(peer, manifest.peerDependencies[peer]);
} catch {
this.logger.warn(`Invalid peer dependency ${peer} found in package.`);
continue;
}
if (peerIdentifier.type === 'version' || peerIdentifier.type === 'range') {
try {
const version = await this.findProjectVersion(peer);
if (!version) {
continue;
}
// tslint:disable-next-line:no-any
const options = { includePrerelease: true } as any;
if (
function childDependencySpecifier (tree, name, spec, where) {
return npa.resolve(name, spec, where || packageRelativePath(tree))
}
return tree.forEachAsync((dep, next) => {
if (!this.checkDepEnv(dep)) { return }
const depPath = dep.path(this.prefix)
const spec = npa.resolve(dep.name, dep.version, this.prefix)
if (dep.isRoot) {
return next()
} else if (spec.type === 'directory') {
const relative = path.relative(path.dirname(depPath), spec.fetchSpec)
this.log.silly('extractTree', `${dep.name}@${spec.fetchSpec} -> ${depPath} (symlink)`)
return mkdirp(path.dirname(depPath))
.then(() => symlinkAsync(relative, depPath, 'junction'))
.catch(
() => rimraf(depPath)
.then(() => symlinkAsync(relative, depPath, 'junction'))
).then(() => next())
.then(() => {
this.pkgCount++
cg.completeWork(1)
})
} else {
function hasModernMeta (child) {
if (!child) return false
const resolved = child.package._resolved && npa.resolve(moduleName(child), child.package._resolved)
const version = npa.resolve(moduleName(child), child.package.version)
return child.isTop ||
isLink(child) ||
child.fromBundle || child.package._inBundle ||
child.package._integrity || child.package._shasum ||
(resolved && resolved.type === 'git') || (version && version.type === 'git')
}
var allDependencies = Object.keys(deps).map((dep) => {
return npa.resolve(dep, deps[dep])
}).filter((dep) => {
return isRegistry(dep) &&
return unbuild([unpackTarget], true).then(() => {
const opts = npmConfig({dmode, fmode, uid, gid, offline: true})
return pacote.extract(npa.resolve(pkg, ver), unpackTarget, opts)
})
}
return fs.stat(path.join(arg, 'package.json'), (err) => {
if (err) {
var version = matchingDep(tree, spec.name)
if (version) {
try {
return fetchPackageMetadata(npa.resolve(spec.name, version), where, done)
} catch (e) {
return done(e)
}
} else {
return fetchPackageMetadata(spec, where, done)
}
} else {
try {
return fetchPackageMetadata(npa('file:' + arg), where, done)
} catch (e) {
return done(e)
}
}
})
} else {
return tree.forEachAsync((dep, next) => {
if (!this.checkDepEnv(dep)) { return }
const spec = npa.resolve(dep.name, dep.version)
const depPath = dep.path(this.prefix)
return next()
.then(() => readJson(depPath, 'package.json'))
.then(pkg => (spec.registry || spec.type === 'directory')
? pkg
: this.updateFromField(dep, pkg).then(() => pkg)
)
.then(pkg => (pkg.scripts && pkg.scripts.install)
? pkg
: this.updateInstallScript(dep, pkg).then(() => pkg)
)
.tap(pkg => { pkgJsons.set(dep, pkg) })
}, {concurrency: 100, Promise: BB})
.then(() => pkgJsons)
.then(from => npa.resolve(dep.name, from))
.then(from => { pkg._from = from.toString() })