diff --git a/.changeset/poor-melons-sneeze.md b/.changeset/poor-melons-sneeze.md new file mode 100644 index 0000000000..75a4bcbbea --- /dev/null +++ b/.changeset/poor-melons-sneeze.md @@ -0,0 +1,5 @@ +--- +"@pnpm/build-modules": major +--- + +`peripheralLocation` in `DependenciesGraphNode` renamed to `dir`. diff --git a/packages/build-modules/src/index.ts b/packages/build-modules/src/index.ts index dbe0fee6fc..6ccced5f25 100644 --- a/packages/build-modules/src/index.ts +++ b/packages/build-modules/src/index.ts @@ -80,7 +80,7 @@ async function buildDependency ( depPath, extraBinPaths: opts.extraBinPaths, optional: depNode.optional, - pkgRoot: depNode.peripheralLocation, + pkgRoot: depNode.dir, prepare: depNode.prepare, rawConfig: opts.rawConfig, rootModulesDir: opts.rootModulesDir, @@ -88,7 +88,7 @@ async function buildDependency ( }) if (hasSideEffects && opts.sideEffectsCacheWrite) { try { - await opts.storeController.upload(depNode.peripheralLocation, { + await opts.storeController.upload(depNode.dir, { engine: ENGINE_NAME, filesIndexFile: depNode.filesIndexFile, }) @@ -110,7 +110,7 @@ async function buildDependency ( } catch (err) { if (depNode.optional) { // TODO: add parents field to the log - const pkg = await readPackageFromDir(path.join(depNode.peripheralLocation)) as DependencyManifest + const pkg = await readPackageFromDir(path.join(depNode.dir)) as DependencyManifest skippedOptionalDependencyLogger.debug({ details: err.toString(), package: { @@ -152,19 +152,19 @@ function getSubgraphToBuild ( } export interface DependenciesGraphNode { + children: {[alias: string]: string}, + dir: string, fetchingBundledManifest?: () => Promise, filesIndexFile: string, + hasBin: boolean, hasBundledDependencies: boolean, - peripheralLocation: string, - children: {[alias: string]: string}, + installable?: boolean, + isBuilt?: boolean, optional: boolean, optionalDependencies: Set, packageId: string, // TODO: this option is currently only needed when running postinstall scripts but even there it should be not used - installable?: boolean, - isBuilt?: boolean, - requiresBuild?: boolean, prepare: boolean, - hasBin: boolean, + requiresBuild?: boolean, } export interface DependenciesGraph { @@ -189,7 +189,7 @@ export async function linkBinsOfDependencies ( return nonOptionalChildren }, {}) - const binPath = path.join(depNode.peripheralLocation, 'node_modules', '.bin') + const binPath = path.join(depNode.dir, 'node_modules/.bin') const pkgs = await Promise.all( Object.keys(childrenToLink) @@ -205,8 +205,8 @@ export async function linkBinsOfDependencies ( .map(async (alias) => { const dep = depGraph[childrenToLink[alias]] return { - location: dep.peripheralLocation, - manifest: await dep.fetchingBundledManifest?.() || (await readPackageFromDir(dep.peripheralLocation) as DependencyManifest), + location: dep.dir, + manifest: await dep.fetchingBundledManifest?.() || (await readPackageFromDir(dep.dir) as DependencyManifest), } }) ) @@ -215,7 +215,7 @@ export async function linkBinsOfDependencies ( // link also the bundled dependencies` bins if (depNode.hasBundledDependencies) { - const bundledModules = path.join(depNode.peripheralLocation, 'node_modules') + const bundledModules = path.join(depNode.dir, 'node_modules') await linkBins(bundledModules, binPath, { warn: opts.warn }) } } diff --git a/packages/headless/src/index.ts b/packages/headless/src/index.ts index 1caefb33fb..208f3b8c11 100644 --- a/packages/headless/src/index.ts +++ b/packages/headless/src/index.ts @@ -421,12 +421,12 @@ async function linkRootPackages ( }) return } - const peripheralLocation = opts.rootDependencies[alias] + const dir = opts.rootDependencies[alias] // Skipping linked packages - if (!peripheralLocation) { + if (!dir) { return } - if ((await symlinkDependency(peripheralLocation, opts.importerModulesDir, alias)).reused) { + if ((await symlinkDependency(dir, opts.importerModulesDir, alias)).reused) { return } const isDev = projectSnapshot.devDependencies?.[alias] @@ -485,17 +485,17 @@ async function lockfileToDepGraph ( const modules = path.join(opts.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules') const packageId = packageIdFromSnapshot(depPath, pkgSnapshot, opts.registries) - const peripheralLocation = path.join(modules, pkgName) + const dir = path.join(modules, pkgName) if ( currentPackages[depPath] && R.equals(currentPackages[depPath].dependencies, lockfile.packages![depPath].dependencies) && R.equals(currentPackages[depPath].optionalDependencies, lockfile.packages![depPath].optionalDependencies) ) { - if (await fs.exists(peripheralLocation)) { + if (await fs.exists(dir)) { return } brokenModulesLogger.debug({ - missing: peripheralLocation, + missing: dir, }) } const resolution = pkgSnapshotToResolution(depPath, pkgSnapshot, opts.registries) @@ -523,9 +523,10 @@ async function lockfileToDepGraph ( .catch(() => { // ignore }) - graph[peripheralLocation] = { + graph[dir] = { children: {}, depPath, + dir, fetchingFiles: fetchResponse.files, filesIndexFile: fetchResponse.filesIndexFile, finishing: fetchResponse.finishing, @@ -536,11 +537,10 @@ async function lockfileToDepGraph ( optional: !!pkgSnapshot.optional, optionalDependencies: new Set(R.keys(pkgSnapshot.optionalDependencies)), packageId, - peripheralLocation, prepare: pkgSnapshot.prepare === true, requiresBuild: pkgSnapshot.requiresBuild === true, } - pkgSnapshotByLocation[peripheralLocation] = pkgSnapshot + pkgSnapshotByLocation[dir] = pkgSnapshot }) ) const ctx = { @@ -555,14 +555,14 @@ async function lockfileToDepGraph ( storeDir: opts.storeDir, virtualStoreDir: opts.virtualStoreDir, } - for (const peripheralLocation of R.keys(graph)) { - const pkgSnapshot = pkgSnapshotByLocation[peripheralLocation] + for (const dir of R.keys(graph)) { + const pkgSnapshot = pkgSnapshotByLocation[dir] const allDeps = { ...pkgSnapshot.dependencies, ...(opts.include.optionalDependencies ? pkgSnapshot.optionalDependencies : {}), } - graph[peripheralLocation].children = await getChildrenPaths(ctx, allDeps) + graph[dir].children = await getChildrenPaths(ctx, allDeps) } for (const importerId of opts.importerIds) { const projectSnapshot = lockfile.importers[importerId] @@ -602,7 +602,7 @@ async function getChildrenPaths ( const childRelDepPath = dp.refToRelative(allDeps[alias], alias) as string const childPkgSnapshot = ctx.pkgSnapshotsByDepPaths[childRelDepPath] if (ctx.graph[childRelDepPath]) { - children[alias] = ctx.graph[childRelDepPath].peripheralLocation + children[alias] = ctx.graph[childRelDepPath].dir } else if (childPkgSnapshot) { const pkgName = nameVerFromPkgSnapshot(childRelDepPath, childPkgSnapshot).name children[alias] = path.join(ctx.virtualStoreDir, pkgIdToFilename(childRelDepPath, ctx.lockfileDir), 'node_modules', pkgName) @@ -621,7 +621,7 @@ export interface DependenciesGraphNode { name: string, fetchingFiles: () => Promise, finishing: () => Promise, - peripheralLocation: string, + dir: string, children: {[alias: string]: string}, optionalDependencies: Set, optional: boolean, @@ -652,7 +652,7 @@ async function linkAllPkgs ( depNodes.map(async (depNode) => { const filesResponse = await depNode.fetchingFiles() - const { isBuilt } = await storeController.importPackage(depNode.peripheralLocation, { + const { isBuilt } = await storeController.importPackage(depNode.dir, { filesResponse, force: opts.force, targetEngine: opts.targetEngine, @@ -682,7 +682,7 @@ async function linkAllBins ( return nonOptionalChildren }, {}) - const binPath = path.join(depNode.peripheralLocation, 'node_modules', '.bin') + const binPath = path.join(depNode.dir, 'node_modules/.bin') const pkgSnapshots = R.props(R.values(childrenToLink), depGraph) if (pkgSnapshots.includes(undefined as any)) { // tslint:disable-line @@ -691,9 +691,9 @@ async function linkAllBins ( const pkgs = await Promise.all( pkgSnapshots .filter(({ hasBin }) => hasBin) - .map(async ({ peripheralLocation }) => ({ - location: peripheralLocation, - manifest: await readPackageFromDir(peripheralLocation) as DependencyManifest, + .map(async ({ dir }) => ({ + location: dir, + manifest: await readPackageFromDir(dir) as DependencyManifest, })) ) @@ -702,7 +702,7 @@ async function linkAllBins ( // link also the bundled dependencies` bins if (depNode.hasBundledDependencies) { - const bundledModules = path.join(depNode.peripheralLocation, 'node_modules') + const bundledModules = path.join(depNode.dir, 'node_modules') await linkBins(bundledModules, binPath, { warn: opts.warn }) } })) diff --git a/packages/supi/src/install/link.ts b/packages/supi/src/install/link.ts index 7ee6e6fe9d..63944651d1 100644 --- a/packages/supi/src/install/link.ts +++ b/packages/supi/src/install/link.ts @@ -217,7 +217,7 @@ export default async function linkPackages ( .map(async ({ rootAlias, depGraphNode }) => { if ( !opts.dryRun && - (await symlinkDependency(depGraphNode.peripheralLocation, modulesDir, rootAlias)).reused + (await symlinkDependency(depGraphNode.dir, modulesDir, rootAlias)).reused ) return const isDev = manifest.devDependencies?.[depGraphNode.name] @@ -442,11 +442,11 @@ async function selectNewFromWantedDeps ( const depNode = depGraph[depPath] if (!depNode) return if (prevRelDepPaths.has(depPath)) { - if (await fs.exists(depNode.peripheralLocation)) { + if (await fs.exists(depNode.dir)) { return } brokenModulesLogger.debug({ - missing: depNode.peripheralLocation, + missing: depNode.dir, }) } newDeps.add(depPath) @@ -470,7 +470,7 @@ async function linkAllPkgs ( depNodes.map(async (depNode) => { const filesResponse = await depNode.fetchingFiles() - const { isBuilt } = await storeController.importPackage(depNode.peripheralLocation, { + const { isBuilt } = await storeController.importPackage(depNode.dir, { filesResponse, force: opts.force, targetEngine: opts.targetEngine, @@ -517,7 +517,7 @@ async function linkAllModules ( }) return } - await limitLinking(() => symlinkDependency(pkg.peripheralLocation, modules, childAlias)) + await limitLinking(() => symlinkDependency(pkg.dir, modules, childAlias)) }) ) }) diff --git a/packages/supi/src/install/resolvePeers.ts b/packages/supi/src/install/resolvePeers.ts index 7b81812188..b966ded07d 100644 --- a/packages/supi/src/install/resolvePeers.ts +++ b/packages/supi/src/install/resolvePeers.ts @@ -29,7 +29,7 @@ export interface DependenciesGraphNode { fetchingFiles: () => Promise, filesIndexFile: string, resolution: Resolution, - peripheralLocation: string, + dir: string, children: {[alias: string]: string}, optionalDependencies: Set, depth: number, @@ -210,7 +210,7 @@ function resolvePeersOfNode ( ctx.pathsByNodeId[nodeId] = depPath if (!ctx.depGraph[depPath] || ctx.depGraph[depPath].depth > node.depth) { - const peripheralLocation = path.join(modules, resolvedPackage.name) + const dir = path.join(modules, resolvedPackage.name) const unknownPeers = Object.keys(unknownResolvedPeersOfChildren) if (unknownPeers.length) { @@ -229,6 +229,7 @@ function resolvePeersOfNode ( depPath, depth: node.depth, dev: resolvedPackage.dev, + dir, fetchingBundledManifest: resolvedPackage.fetchingBundledManifest, fetchingFiles: resolvedPackage.fetchingFiles, filesIndexFile: resolvedPackage.filesIndexFile, @@ -241,7 +242,6 @@ function resolvePeersOfNode ( optional: resolvedPackage.optional, optionalDependencies: resolvedPackage.optionalDependencies, packageId: resolvedPackage.id, - peripheralLocation, prepare: resolvedPackage.prepare, prod: resolvedPackage.prod, requiresBuild: resolvedPackage.requiresBuild,