Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (dependencyLockfile.peerDependencies && dependencyLockfile.dependencies) {
// This is done to guarantee that the dependency will be relinked with the
// up-to-date peer dependencies
// Covered by test: "peer dependency is grouped with dependency when peer is resolved not from a top dependency"
R.keys(dependencyLockfile.peerDependencies).forEach((peer) => {
delete dependencyLockfile.dependencies![peer]
})
}
const depPath = dp.resolve(registries, relDepPath)
return {
currentResolution: pkgSnapshotToResolution(relDepPath, dependencyLockfile, registries),
dependencyLockfile,
depPath,
optionalDependencyNames: R.keys(dependencyLockfile.optionalDependencies),
pkgId: packageIdFromSnapshot(relDepPath, dependencyLockfile, registries),
relDepPath,
resolvedDependencies: {
...dependencyLockfile.dependencies,
...dependencyLockfile.optionalDependencies,
},
}
} else {
return {
pkgId: dp.tryGetPackageId(registries, relDepPath) || relDepPath, // Does it make sense to set pkgId when we're not sure?
relDepPath,
}
}
}
},
],
])
packageRegistry.set(name, packageStore)
}
}
for (const [relDepPath, pkgSnapshot] of R.toPairs(lockfile.packages || {})) {
const { name, version, peersSuffix } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot)
const pnpVersion = toPnPVersion(version, peersSuffix)
let packageStore = packageRegistry.get(name)
if (!packageStore) {
packageStore = new Map()
packageRegistry.set(name, packageStore)
}
const packageId = packageIdFromSnapshot(relDepPath, pkgSnapshot, opts.registries)
// TODO: what about packages that are built?
// Also, storeController has .getPackageLocation()
let packageLocation
if (peersSuffix) {
packageLocation = path.relative(opts.lockfileDirectory, path.join(
opts.storeDirectory,
'virtual',
`${name}-virtual-${version}_${peersSuffix}`,
))
} else {
packageLocation = path.relative(opts.lockfileDirectory, path.join(
opts.storeDirectory,
pkgIdToFilename(packageId, opts.lockfileDirectory),
'node_modules',
name,
))
function getPkgsDepPaths (
registries: Registries,
packages: PackageSnapshots,
): {[depPath: string]: string} {
const pkgIdsByDepPath = {}
for (const relDepPath of Object.keys(packages)) {
const depPath = dp.resolve(registries, relDepPath)
pkgIdsByDepPath[depPath] = packageIdFromSnapshot(relDepPath, packages[relDepPath], registries)
}
return pkgIdsByDepPath
}