diff --git a/.changeset/loud-olives-warn.md b/.changeset/loud-olives-warn.md new file mode 100644 index 0000000000..b759720c16 --- /dev/null +++ b/.changeset/loud-olives-warn.md @@ -0,0 +1,5 @@ +--- +"@pnpm/lockfile-walker": major +--- + +Rename `relDepPath` to `depPath`. diff --git a/packages/audit/src/lockfileToAuditTree.ts b/packages/audit/src/lockfileToAuditTree.ts index b6ab95dd41..84ee7a90d1 100644 --- a/packages/audit/src/lockfileToAuditTree.ts +++ b/packages/audit/src/lockfileToAuditTree.ts @@ -51,8 +51,8 @@ export default function lockfileToAuditTree ( function lockfileToAuditNode (step: LockfileWalkerStep) { const dependencies = {} - for (const { relDepPath, pkgSnapshot, next } of step.dependencies) { - const { name, version } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + for (const { depPath, pkgSnapshot, next } of step.dependencies) { + const { name, version } = nameVerFromPkgSnapshot(depPath, pkgSnapshot) const subdeps = lockfileToAuditNode(next()) const dep: AuditNode = { dev: pkgSnapshot.dev === true, diff --git a/packages/dependencies-hierarchy/src/index.ts b/packages/dependencies-hierarchy/src/index.ts index 7be2854cac..379bcef52c 100644 --- a/packages/dependencies-hierarchy/src/index.ts +++ b/packages/dependencies-hierarchy/src/index.ts @@ -353,18 +353,18 @@ function getPkgInfo ( let optional: true | undefined = undefined let isSkipped: boolean = false let isMissing: boolean = false - const relDepPath = refToRelative(opts.ref, opts.alias) - if (relDepPath) { + const depPath = refToRelative(opts.ref, opts.alias) + if (depPath) { let pkgSnapshot!: PackageSnapshot - if (opts.currentPackages[relDepPath]) { - pkgSnapshot = opts.currentPackages[relDepPath] - const parsed = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + if (opts.currentPackages[depPath]) { + pkgSnapshot = opts.currentPackages[depPath] + const parsed = nameVerFromPkgSnapshot(depPath, pkgSnapshot) name = parsed.name version = parsed.version } else { - pkgSnapshot = opts.wantedPackages[relDepPath] + pkgSnapshot = opts.wantedPackages[depPath] if (pkgSnapshot) { - const parsed = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + const parsed = nameVerFromPkgSnapshot(depPath, pkgSnapshot) name = parsed.name version = parsed.version } else { @@ -372,9 +372,9 @@ function getPkgInfo ( version = opts.ref } isMissing = true - isSkipped = opts.skipped.has(relDepPath) + isSkipped = opts.skipped.has(depPath) } - resolved = pkgSnapshotToResolution(relDepPath, pkgSnapshot, opts.registries)['tarball'] + resolved = pkgSnapshotToResolution(depPath, pkgSnapshot, opts.registries)['tarball'] dev = pkgSnapshot.dev optional = pkgSnapshot.optional } else { diff --git a/packages/filter-lockfile/src/LockfileMissingDependencyError.ts b/packages/filter-lockfile/src/LockfileMissingDependencyError.ts index cc0128367f..50007d962f 100644 --- a/packages/filter-lockfile/src/LockfileMissingDependencyError.ts +++ b/packages/filter-lockfile/src/LockfileMissingDependencyError.ts @@ -2,8 +2,8 @@ import { WANTED_LOCKFILE } from '@pnpm/constants' import PnpmError from '@pnpm/error' export default class LockfileMissingDependencyError extends PnpmError { - constructor (relDepPath: string) { - const message = `Broken lockfile: no entry for '${relDepPath}' in ${WANTED_LOCKFILE}` + constructor (depPath: string) { + const message = `Broken lockfile: no entry for '${depPath}' in ${WANTED_LOCKFILE}` super('LOCKFILE_MISSING_DEPENDENCY', message, { hint: 'This issue is probably caused by a badly resolved merge conflict.\n' + 'To fix the lockfile, run \'pnpm install --no-frozen-lockfile\'.', diff --git a/packages/filter-lockfile/src/filterLockfile.ts b/packages/filter-lockfile/src/filterLockfile.ts index ee4ac0ae87..b193838030 100644 --- a/packages/filter-lockfile/src/filterLockfile.ts +++ b/packages/filter-lockfile/src/filterLockfile.ts @@ -11,15 +11,15 @@ export default function filterLockfile ( } ): Lockfile { let pairs = R.toPairs(lockfile.packages || {}) - .filter(([relDepPath, pkg]) => !opts.skipped.has(relDepPath)) + .filter(([depPath, pkg]) => !opts.skipped.has(depPath)) if (!opts.include.dependencies) { - pairs = pairs.filter(([relDepPath, pkg]) => pkg.dev !== false || pkg.optional) + pairs = pairs.filter(([depPath, pkg]) => pkg.dev !== false || pkg.optional) } if (!opts.include.devDependencies) { - pairs = pairs.filter(([relDepPath, pkg]) => pkg.dev !== true) + pairs = pairs.filter(([depPath, pkg]) => pkg.dev !== true) } if (!opts.include.optionalDependencies) { - pairs = pairs.filter(([relDepPath, pkg]) => !pkg.optional) + pairs = pairs.filter(([depPath, pkg]) => !pkg.optional) } return { importers: Object.keys(lockfile.importers).reduce((acc, importerId) => { diff --git a/packages/filter-lockfile/src/filterLockfileByImporters.ts b/packages/filter-lockfile/src/filterLockfileByImporters.ts index e0a1949ffa..dc4a5a80c0 100644 --- a/packages/filter-lockfile/src/filterLockfileByImporters.ts +++ b/packages/filter-lockfile/src/filterLockfileByImporters.ts @@ -55,14 +55,14 @@ function pkgAllDeps ( failOnMissingDependencies: boolean, } ) { - for (const { pkgSnapshot, relDepPath, next } of step.dependencies) { - pickedPackages[relDepPath] = pkgSnapshot + for (const { pkgSnapshot, depPath, next } of step.dependencies) { + pickedPackages[depPath] = pkgSnapshot pkgAllDeps(next(), pickedPackages, opts) } - for (const relDepPath of step.missing) { + for (const depPath of step.missing) { if (opts.failOnMissingDependencies) { - throw new LockfileMissingDependencyError(relDepPath) + throw new LockfileMissingDependencyError(depPath) } - logger.debug(`No entry for "${relDepPath}" in ${WANTED_LOCKFILE}`) + logger.debug(`No entry for "${depPath}" in ${WANTED_LOCKFILE}`) } } diff --git a/packages/filter-lockfile/src/filterLockfileByImportersAndEngine.ts b/packages/filter-lockfile/src/filterLockfileByImportersAndEngine.ts index 7f5f48857f..37cd87094f 100644 --- a/packages/filter-lockfile/src/filterLockfileByImportersAndEngine.ts +++ b/packages/filter-lockfile/src/filterLockfileByImportersAndEngine.ts @@ -57,8 +57,8 @@ export default function filterByImportersAndEngine ( acc[importerId] = filterImporter(lockfile.importers[importerId], opts.include) if (acc[importerId].optionalDependencies) { for (const depName of Object.keys(acc[importerId].optionalDependencies || {})) { - const relDepPath = dp.refToRelative(acc[importerId].optionalDependencies![depName], depName) - if (relDepPath && !packages[relDepPath]) { + const depPath = dp.refToRelative(acc[importerId].optionalDependencies![depName], depName) + if (depPath && !packages[depPath]) { delete acc[importerId].optionalDependencies![depName] } } @@ -75,7 +75,7 @@ export default function filterByImportersAndEngine ( function pickPkgsWithAllDeps ( pkgSnapshots: PackageSnapshots, - relDepPaths: string[], + depPaths: string[], opts: { currentEngine: { nodeVersion: string, @@ -90,7 +90,7 @@ function pickPkgsWithAllDeps ( } ) { const pickedPackages = {} as PackageSnapshots - pkgAllDeps({ pkgSnapshots, pickedPackages }, relDepPaths, true, opts) + pkgAllDeps({ pkgSnapshots, pickedPackages }, depPaths, true, opts) return pickedPackages } @@ -99,7 +99,7 @@ function pkgAllDeps ( pkgSnapshots: PackageSnapshots, pickedPackages: PackageSnapshots, }, - relDepPaths: string[], + depPaths: string[], parentIsInstallable: boolean, opts: { currentEngine: { @@ -114,31 +114,31 @@ function pkgAllDeps ( skipped: Set, } ) { - for (const relDepPath of relDepPaths) { - if (ctx.pickedPackages[relDepPath]) continue - const pkgSnapshot = ctx.pkgSnapshots[relDepPath] - if (!pkgSnapshot && !relDepPath.startsWith('link:')) { + for (const depPath of depPaths) { + if (ctx.pickedPackages[depPath]) continue + const pkgSnapshot = ctx.pkgSnapshots[depPath] + if (!pkgSnapshot && !depPath.startsWith('link:')) { if (opts.failOnMissingDependencies) { - throw new LockfileMissingDependencyError(relDepPath) + throw new LockfileMissingDependencyError(depPath) } - logger.debug(`No entry for "${relDepPath}" in ${WANTED_LOCKFILE}`) + logger.debug(`No entry for "${depPath}" in ${WANTED_LOCKFILE}`) continue } let installable!: boolean if (!parentIsInstallable) { installable = false - if (!ctx.pickedPackages[relDepPath] && pkgSnapshot.optional === true) { - opts.skipped.add(relDepPath) + if (!ctx.pickedPackages[depPath] && pkgSnapshot.optional === true) { + opts.skipped.add(depPath) } } else { const pkg = { - ...nameVerFromPkgSnapshot(relDepPath, pkgSnapshot), + ...nameVerFromPkgSnapshot(depPath, pkgSnapshot), cpu: pkgSnapshot.cpu, engines: pkgSnapshot.engines, os: pkgSnapshot.os, } - // TODO: relDepPath is not the package ID. Should be fixed - installable = opts.includeIncompatiblePackages || packageIsInstallable(pkgSnapshot.id || relDepPath, pkg, { + // TODO: depPath is not the package ID. Should be fixed + installable = opts.includeIncompatiblePackages || packageIsInstallable(pkgSnapshot.id || depPath, pkg, { engineStrict: opts.engineStrict, lockfileDir: opts.lockfileDir, nodeVersion: opts.currentEngine.nodeVersion, @@ -146,14 +146,14 @@ function pkgAllDeps ( pnpmVersion: opts.currentEngine.pnpmVersion, }) !== false if (!installable) { - if (!ctx.pickedPackages[relDepPath] && pkgSnapshot.optional === true) { - opts.skipped.add(relDepPath) + if (!ctx.pickedPackages[depPath] && pkgSnapshot.optional === true) { + opts.skipped.add(depPath) } } else { - opts.skipped.delete(relDepPath) + opts.skipped.delete(depPath) } } - ctx.pickedPackages[relDepPath] = pkgSnapshot + ctx.pickedPackages[depPath] = pkgSnapshot const nextRelDepPaths = R.toPairs( { ...pkgSnapshot.dependencies, diff --git a/packages/hoist/src/index.ts b/packages/hoist/src/index.ts index 61597b9407..0ad6e806a8 100644 --- a/packages/hoist/src/index.ts +++ b/packages/hoist/src/index.ts @@ -32,9 +32,9 @@ export default async function hoistByLockfile ( const deps = [ { children: directDeps - .reduce((acc, { alias, relDepPath }) => { + .reduce((acc, { alias, depPath }) => { if (!acc[alias]) { - acc[alias] = relDepPath + acc[alias] = depPath } return acc }, {}), @@ -87,9 +87,9 @@ async function getDependencies ( ): Promise { const deps: Dependency[] = [] const nextSteps: LockfileWalkerStep[] = [] - for (const { pkgSnapshot, relDepPath, next } of step.dependencies) { - const pkgName = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot).name - const modules = path.join(opts.virtualStoreDir, pkgIdToFilename(relDepPath, opts.lockfileDir), 'node_modules') + for (const { pkgSnapshot, depPath, next } of step.dependencies) { + const pkgName = nameVerFromPkgSnapshot(depPath, pkgSnapshot).name + const modules = path.join(opts.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules') const allDeps = { ...pkgSnapshot.dependencies, ...pkgSnapshot.optionalDependencies, @@ -99,7 +99,7 @@ async function getDependencies ( children[alias] = dp.refToRelative(allDeps[alias], alias) return children }, {}), - depPath: relDepPath, + depPath, depth, location: path.join(modules, pkgName), }) @@ -107,10 +107,10 @@ async function getDependencies ( nextSteps.push(next()) } - for (const relDepPath of step.missing) { + for (const depPath of step.missing) { // It might make sense to fail if the depPath is not in the skipped list from .modules.yaml // However, the skipped list currently contains package IDs, not dep paths. - logger.debug({ message: `No entry for "${relDepPath}" in ${WANTED_LOCKFILE}` }) + logger.debug({ message: `No entry for "${depPath}" in ${WANTED_LOCKFILE}` }) } return ( diff --git a/packages/lockfile-utils/src/nameVerFromPkgSnapshot.ts b/packages/lockfile-utils/src/nameVerFromPkgSnapshot.ts index b138b081e4..b9e12eebc0 100644 --- a/packages/lockfile-utils/src/nameVerFromPkgSnapshot.ts +++ b/packages/lockfile-utils/src/nameVerFromPkgSnapshot.ts @@ -2,11 +2,11 @@ import { PackageSnapshot } from '@pnpm/lockfile-types' import * as dp from 'dependency-path' export default ( - relDepPath: string, + depPath: string, pkgSnapshot: PackageSnapshot ) => { if (!pkgSnapshot.name) { - const pkgInfo = dp.parse(relDepPath) + const pkgInfo = dp.parse(depPath) return { name: pkgInfo.name as string, peersSuffix: pkgInfo.peersSuffix, diff --git a/packages/lockfile-utils/src/packageIdFromSnapshot.ts b/packages/lockfile-utils/src/packageIdFromSnapshot.ts index 1043c7affe..95981963f7 100644 --- a/packages/lockfile-utils/src/packageIdFromSnapshot.ts +++ b/packages/lockfile-utils/src/packageIdFromSnapshot.ts @@ -3,10 +3,10 @@ import { Registries } from '@pnpm/types' import * as dp from 'dependency-path' export default ( - relDepPath: string, + depPath: string, pkgSnapshot: PackageSnapshot, registries: Registries ) => { if (pkgSnapshot.id) return pkgSnapshot.id - return dp.tryGetPackageId(registries, relDepPath) || relDepPath + return dp.tryGetPackageId(registries, depPath) || depPath } diff --git a/packages/lockfile-utils/src/pkgSnapshotToResolution.ts b/packages/lockfile-utils/src/pkgSnapshotToResolution.ts index ba96f9d845..7649145dc0 100644 --- a/packages/lockfile-utils/src/pkgSnapshotToResolution.ts +++ b/packages/lockfile-utils/src/pkgSnapshotToResolution.ts @@ -7,7 +7,7 @@ import url = require('url') import nameVerFromPkgSnapshot from './nameVerFromPkgSnapshot' export default ( - relDepPath: string, + depPath: string, pkgSnapshot: PackageSnapshot, registries: Registries ): Resolution => { @@ -16,7 +16,7 @@ export default ( return pkgSnapshot.resolution as Resolution } if (!pkgSnapshot.resolution['tarball']) { - const { name } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + const { name } = nameVerFromPkgSnapshot(depPath, pkgSnapshot) const registry = name[0] === '@' && registries[name.split('/')[0]] || registries.default return { ...pkgSnapshot.resolution, @@ -27,7 +27,7 @@ export default ( if (pkgSnapshot.resolution['tarball'].startsWith('file:')) { return pkgSnapshot.resolution as Resolution } - const { name } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + const { name } = nameVerFromPkgSnapshot(depPath, pkgSnapshot) const registry = name[0] === '@' && registries[name.split('/')[0]] || registries.default return { ...pkgSnapshot.resolution, @@ -36,9 +36,9 @@ export default ( } as Resolution function getTarball (registry: string) { - const { name, version } = dp.parse(relDepPath) + const { name, version } = dp.parse(depPath) if (!name || !version) { - throw new Error(`Couldn't get tarball URL from dependency path ${relDepPath}`) + throw new Error(`Couldn't get tarball URL from dependency path ${depPath}`) } return getNpmTarballUrl(name, version, { registry }) } diff --git a/packages/lockfile-walker/src/index.ts b/packages/lockfile-walker/src/index.ts index 2be6385ec4..638dff5bb2 100644 --- a/packages/lockfile-walker/src/index.ts +++ b/packages/lockfile-walker/src/index.ts @@ -4,7 +4,7 @@ import * as dp from 'dependency-path' import R = require('ramda') export type LockedDependency = { - relDepPath: string, + depPath: string, pkgSnapshot: PackageSnapshot, next: () => LockfileWalkerStep, } @@ -55,7 +55,7 @@ export default function lockfileWalker ( ) { const walked = new Set(opts?.skipped ? Array.from(opts?.skipped) : []) const entryNodes = [] as string[] - const directDeps = [] as Array<{ alias: string, relDepPath: string }> + const directDeps = [] as Array<{ alias: string, depPath: string }> importerIds.forEach((importerId) => { const projectSnapshot = lockfile.importers[importerId] @@ -65,10 +65,10 @@ export default function lockfileWalker ( ...(opts?.include?.optionalDependencies === false ? {} : projectSnapshot.optionalDependencies), }) .forEach(([ pkgName, reference ]) => { - const relDepPath = dp.refToRelative(reference, pkgName) - if (relDepPath === null) return - entryNodes.push(relDepPath as string) - directDeps.push({ alias: pkgName, relDepPath }) + const depPath = dp.refToRelative(reference, pkgName) + if (depPath === null) return + entryNodes.push(depPath as string) + directDeps.push({ alias: pkgName, depPath }) }) }) return { @@ -87,29 +87,29 @@ function step ( lockfile: Lockfile, walked: Set, }, - nextRelDepPaths: string[] + nextDepPaths: string[] ) { const result: LockfileWalkerStep = { dependencies: [], links: [], missing: [], } - for (let relDepPath of nextRelDepPaths) { - if (ctx.walked.has(relDepPath)) continue - ctx.walked.add(relDepPath) - const pkgSnapshot = ctx.lockfile.packages?.[relDepPath] + for (let depPath of nextDepPaths) { + if (ctx.walked.has(depPath)) continue + ctx.walked.add(depPath) + const pkgSnapshot = ctx.lockfile.packages?.[depPath] if (!pkgSnapshot) { - if (relDepPath.startsWith('link:')) { - result.links.push(relDepPath) + if (depPath.startsWith('link:')) { + result.links.push(depPath) continue } - result.missing.push(relDepPath) + result.missing.push(depPath) continue } result.dependencies.push({ + depPath, next: () => step(ctx, next({ includeOptionalDependencies: ctx.includeOptionalDependencies }, pkgSnapshot)), pkgSnapshot, - relDepPath, }) } return result diff --git a/packages/modules-cleaner/src/prune.ts b/packages/modules-cleaner/src/prune.ts index 50f9e24638..222bfa51b1 100644 --- a/packages/modules-cleaner/src/prune.ts +++ b/packages/modules-cleaner/src/prune.ts @@ -164,11 +164,11 @@ function getPkgsDepPaths ( registries: Registries, packages: PackageSnapshots, skipped: Set -): {[relDepPath: string]: string} { +): {[depPath: string]: string} { const pkgIdsByDepPath = {} - for (const relDepPath of Object.keys(packages)) { - if (skipped.has(relDepPath)) continue - pkgIdsByDepPath[relDepPath] = packageIdFromSnapshot(relDepPath, packages[relDepPath], registries) + for (const depPath of Object.keys(packages)) { + if (skipped.has(depPath)) continue + pkgIdsByDepPath[depPath] = packageIdFromSnapshot(depPath, packages[depPath], registries) } return pkgIdsByDepPath } diff --git a/packages/plugin-commands-rebuild/src/implementation/index.ts b/packages/plugin-commands-rebuild/src/implementation/index.ts index 5d312b2dcf..9cbab3b9ce 100644 --- a/packages/plugin-commands-rebuild/src/implementation/index.ts +++ b/packages/plugin-commands-rebuild/src/implementation/index.ts @@ -151,7 +151,7 @@ export async function rebuild ( opts ) - ctx.pendingBuilds = ctx.pendingBuilds.filter((relDepPath) => !pkgsThatWereRebuilt.has(relDepPath)) + ctx.pendingBuilds = ctx.pendingBuilds.filter((depPath) => !pkgsThatWereRebuilt.has(depPath)) const scriptsOpts = { extraBinPaths: ctx.extraBinPaths, @@ -194,22 +194,22 @@ function getSubgraphToBuild ( } ) { let currentShouldBeBuilt = false - for (const { relDepPath, next } of step.dependencies) { - if (nodesToBuildAndTransitive.has(relDepPath)) { + for (const { depPath, next } of step.dependencies) { + if (nodesToBuildAndTransitive.has(depPath)) { currentShouldBeBuilt = true } const childShouldBeBuilt = getSubgraphToBuild(next(), nodesToBuildAndTransitive, opts) - || opts.pkgsToRebuild.has(relDepPath) + || opts.pkgsToRebuild.has(depPath) if (childShouldBeBuilt) { - nodesToBuildAndTransitive.add(relDepPath) + nodesToBuildAndTransitive.add(depPath) currentShouldBeBuilt = true } } - for (const relDepPath of step.missing) { + for (const depPath of step.missing) { // It might make sense to fail if the depPath is not in the skipped list from .modules.yaml // However, the skipped list currently contains package IDs, not dep paths. - logger.debug({ message: `No entry for "${relDepPath}" in ${WANTED_LOCKFILE}` }) + logger.debug({ message: `No entry for "${depPath}" in ${WANTED_LOCKFILE}` }) } return currentShouldBeBuilt } @@ -249,9 +249,9 @@ async function _rebuild ( ) const nodesToBuildAndTransitiveArray = Array.from(nodesToBuildAndTransitive) - for (const relDepPath of nodesToBuildAndTransitiveArray) { - const pkgSnapshot = pkgSnapshots[relDepPath] - graph.set(relDepPath, R.toPairs({ ...pkgSnapshot.dependencies, ...pkgSnapshot.optionalDependencies }) + for (const depPath of nodesToBuildAndTransitiveArray) { + const pkgSnapshot = pkgSnapshots[depPath] + graph.set(depPath, R.toPairs({ ...pkgSnapshot.dependencies, ...pkgSnapshot.optionalDependencies }) .map(([ pkgName, reference ]) => dp.refToRelative(reference, pkgName)) .filter((childRelDepPath) => childRelDepPath && nodesToBuildAndTransitive.has(childRelDepPath))) } @@ -261,14 +261,13 @@ async function _rebuild ( }) const chunks = graphSequencerResult.chunks as string[][] const warn = (message: string) => logger.warn({ message, prefix: opts.dir }) - const groups = chunks.map((chunk) => chunk.filter((relDepPath) => ctx.pkgsToRebuild.has(relDepPath)).map((relDepPath) => + const groups = chunks.map((chunk) => chunk.filter((depPath) => ctx.pkgsToRebuild.has(depPath)).map((depPath) => async () => { - const pkgSnapshot = pkgSnapshots[relDepPath] - const depPath = dp.resolve(opts.registries, relDepPath) - const pkgInfo = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) - const pkgRoot = path.join(ctx.virtualStoreDir, pkgIdToFilename(relDepPath, opts.lockfileDir), 'node_modules', pkgInfo.name) + const pkgSnapshot = pkgSnapshots[depPath] + const pkgInfo = nameVerFromPkgSnapshot(depPath, pkgSnapshot) + const pkgRoot = path.join(ctx.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules', pkgInfo.name) try { - const modules = path.join(ctx.virtualStoreDir, pkgIdToFilename(relDepPath, opts.lockfileDir), 'node_modules') + const modules = path.join(ctx.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules') const binPath = path.join(pkgRoot, 'node_modules', '.bin') await linkBins(modules, binPath, { warn }) await runPostinstallHooks({ @@ -281,7 +280,7 @@ async function _rebuild ( rootModulesDir: ctx.rootModulesDir, unsafePerm: opts.unsafePerm || false, }) - pkgsThatWereRebuilt.add(relDepPath) + pkgsThatWereRebuilt.add(depPath) } catch (err) { if (pkgSnapshot.optional) { // TODO: add parents field to the log @@ -308,11 +307,11 @@ async function _rebuild ( await Promise.all( Object .keys(pkgSnapshots) - .filter((relDepPath) => !packageIsIndependent(pkgSnapshots[relDepPath])) - .map((relDepPath) => limitLinking(() => { - const pkgSnapshot = pkgSnapshots[relDepPath] - const pkgInfo = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) - const modules = path.join(ctx.virtualStoreDir, pkgIdToFilename(relDepPath, opts.lockfileDir), 'node_modules') + .filter((depPath) => !packageIsIndependent(pkgSnapshots[depPath])) + .map((depPath) => limitLinking(() => { + const pkgSnapshot = pkgSnapshots[depPath] + const pkgInfo = nameVerFromPkgSnapshot(depPath, pkgSnapshot) + const modules = path.join(ctx.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules') const binPath = path.join(modules, pkgInfo.name, 'node_modules', '.bin') return linkBins(modules, binPath, { warn }) })) diff --git a/packages/plugin-commands-store/src/storeStatus/index.ts b/packages/plugin-commands-store/src/storeStatus/index.ts index 977280d1a9..94d0eb6664 100644 --- a/packages/plugin-commands-store/src/storeStatus/index.ts +++ b/packages/plugin-commands-store/src/storeStatus/index.ts @@ -31,24 +31,24 @@ export default async function (maybeOpts: StoreStatusOptions) { if (!wantedLockfile) return [] const pkgs = Object.keys(wantedLockfile.packages || {}) - .filter((relDepPath) => !skipped.has(relDepPath)) - .map((relDepPath) => { - const pkg = wantedLockfile.packages![relDepPath] + .filter((depPath) => !skipped.has(depPath)) + .map((depPath) => { + const pkg = wantedLockfile.packages![depPath] return { + depPath, integrity: pkg.resolution['integrity'], - pkgPath: dp.resolve(registries, relDepPath), - relDepPath, - ...nameVerFromPkgSnapshot(relDepPath, pkg), + pkgPath: dp.resolve(registries, depPath), + ...nameVerFromPkgSnapshot(depPath, pkg), } }) const cafsDir = path.join(storeDir, 'files') - const modified = await pFilter(pkgs, async ({ integrity, pkgPath, relDepPath, name }) => { + const modified = await pFilter(pkgs, async ({ integrity, pkgPath, depPath, name }) => { const pkgIndexFilePath = integrity ? getFilePathInCafs(cafsDir, integrity, 'index') : path.join(storeDir, pkgPath, 'integrity.json') const { files } = await loadJsonFile(pkgIndexFilePath) - return (await dint.check(path.join(virtualStoreDir, pkgIdToFilename(relDepPath, opts.dir), 'node_modules', name), files)) === false + return (await dint.check(path.join(virtualStoreDir, pkgIdToFilename(depPath, opts.dir), 'node_modules', name), files)) === false }) if (reporter) { diff --git a/packages/resolve-dependencies/src/resolveDependencies.ts b/packages/resolve-dependencies/src/resolveDependencies.ts index 192ad7d643..83f08dd062 100644 --- a/packages/resolve-dependencies/src/resolveDependencies.ts +++ b/packages/resolve-dependencies/src/resolveDependencies.ts @@ -430,17 +430,17 @@ function preferedSatisfiesWanted ( prefix: string, } ) { - const relDepPath = dp.refToRelative(preferredRef, wantedDep.alias) - if (relDepPath === null) return false - const pkgSnapshot = lockfile.packages?.[relDepPath] + const depPath = dp.refToRelative(preferredRef, wantedDep.alias) + if (depPath === null) return false + const pkgSnapshot = lockfile.packages?.[depPath] if (!pkgSnapshot) { logger.warn({ - message: `Could not find preferred package ${relDepPath} in lockfile`, + message: `Could not find preferred package ${depPath} in lockfile`, prefix: opts.prefix, }) return false } - const { version } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot) + const { version } = nameVerFromPkgSnapshot(depPath, pkgSnapshot) return semver.satisfies(version, wantedDep.pref, true) } @@ -454,13 +454,13 @@ function getInfoFromLockfile ( return null } - const relDepPath = dp.refToRelative(reference, pkgName) + const depPath = dp.refToRelative(reference, pkgName) - if (!relDepPath) { + if (!depPath) { return null } - const dependencyLockfile = lockfile.packages?.[relDepPath] + const dependencyLockfile = lockfile.packages?.[depPath] if (dependencyLockfile) { if (dependencyLockfile.peerDependencies && dependencyLockfile.dependencies) { @@ -473,11 +473,11 @@ function getInfoFromLockfile ( } return { - currentResolution: pkgSnapshotToResolution(relDepPath, dependencyLockfile, registries), + currentResolution: pkgSnapshotToResolution(depPath, dependencyLockfile, registries), dependencyLockfile, + depPath, optionalDependencyNames: R.keys(dependencyLockfile.optionalDependencies), - pkgId: packageIdFromSnapshot(relDepPath, dependencyLockfile, registries), - relDepPath, + pkgId: packageIdFromSnapshot(depPath, dependencyLockfile, registries), resolvedDependencies: { ...dependencyLockfile.dependencies, ...dependencyLockfile.optionalDependencies, @@ -485,8 +485,8 @@ function getInfoFromLockfile ( } } else { return { - pkgId: dp.tryGetPackageId(registries, relDepPath) || relDepPath, // Does it make sense to set pkgId when we're not sure? - relDepPath, + depPath, + pkgId: dp.tryGetPackageId(registries, depPath) || depPath, // Does it make sense to set pkgId when we're not sure? } } } @@ -495,7 +495,7 @@ type ResolveDependencyOptions = { alwaysTryWorkspacePackages?: boolean, pkgId?: string, dependentId?: string, - relDepPath?: string, + depPath?: string, parentDependsOnPeer: boolean, parentNodeId: string, currentDepth: number, @@ -521,13 +521,13 @@ async function resolveDependency ( const proceed = update || options.proceed || !options.currentResolution const parentIsInstallable = options.parentIsInstallable === undefined || options.parentIsInstallable - const currentLockfileContainsTheDep = options.relDepPath ? Boolean(ctx.currentLockfile.packages?.[options.relDepPath]) : undefined + const currentLockfileContainsTheDep = options.depPath ? Boolean(ctx.currentLockfile.packages?.[options.depPath]) : undefined const depIsLinked = Boolean( // if package is not in `node_modules/.pnpm-lock.yaml` // we can safely assume that it doesn't exist in `node_modules` currentLockfileContainsTheDep && - options.relDepPath && options.dependencyLockfile && - await exists(path.join(ctx.virtualStoreDir, `${pkgIdToFilename(options.relDepPath, ctx.prefix)}/node_modules/${nameVerFromPkgSnapshot(options.relDepPath, options.dependencyLockfile).name}/package.json`)) && + options.depPath && options.dependencyLockfile && + await exists(path.join(ctx.virtualStoreDir, `${pkgIdToFilename(options.depPath, ctx.prefix)}/node_modules/${nameVerFromPkgSnapshot(options.depPath, options.dependencyLockfile).name}/package.json`)) && (options.currentDepth > 0 || wantedDependency.alias && await exists(path.join(ctx.modulesDir, wantedDependency.alias)))) if (!proceed && depIsLinked) { @@ -616,7 +616,7 @@ async function resolveDependency ( let prepare!: boolean let hasBin!: boolean if ( - !options.update && options.dependencyLockfile && options.relDepPath && + !options.update && options.dependencyLockfile && options.depPath && !pkgResponse.body.updated && // peerDependencies field is also used for transitive peer dependencies which should not be linked // That's why we cannot omit reading package.json of such dependencies. @@ -627,7 +627,7 @@ async function resolveDependency ( prepare = options.dependencyLockfile.prepare === true hasBin = options.dependencyLockfile.hasBin === true pkg = Object.assign( - nameVerFromPkgSnapshot(options.relDepPath, options.dependencyLockfile), + nameVerFromPkgSnapshot(options.depPath, options.dependencyLockfile), options.dependencyLockfile ) } else { diff --git a/packages/supi/src/install/getPreferredVersions.ts b/packages/supi/src/install/getPreferredVersions.ts index 586f479b1e..1d60b86a8f 100644 --- a/packages/supi/src/install/getPreferredVersions.ts +++ b/packages/supi/src/install/getPreferredVersions.ts @@ -36,8 +36,8 @@ function getVersionSpecsByRealNames (deps: Dependencies) { export function getPreferredVersionsFromLockfile (snapshots: PackageSnapshots): PreferredVersions { const preferredVersions: PreferredVersions = {} - for (const [relDepPath, snapshot] of Object.entries(snapshots)) { - const { name, version } = nameVerFromPkgSnapshot(relDepPath, snapshot) + for (const [depPath, snapshot] of Object.entries(snapshots)) { + const { name, version } = nameVerFromPkgSnapshot(depPath, snapshot) if (!preferredVersions[name]) { preferredVersions[name] = { [version]: 'version' } } else {