diff --git a/fs/indexed-pkg-importer/src/importIndexedDir.ts b/fs/indexed-pkg-importer/src/importIndexedDir.ts index 41e04303128..5b5994bfbef 100644 --- a/fs/indexed-pkg-importer/src/importIndexedDir.ts +++ b/fs/indexed-pkg-importer/src/importIndexedDir.ts @@ -126,6 +126,7 @@ async function moveOrMergeModulesDirs (src: string, dest: string) { return case 'ENOTEMPTY': case 'EPERM': // This error code is thrown on Windows + // The newly added dependency might have node_modules if it has bundled dependencies. await mergeModulesDirs(src, dest) return default: diff --git a/pkg-manager/core/src/install/index.ts b/pkg-manager/core/src/install/index.ts index 00c8392791e..a4ea065d367 100644 --- a/pkg-manager/core/src/install/index.ts +++ b/pkg-manager/core/src/install/index.ts @@ -344,7 +344,7 @@ export async function mutateModules ( nodeVersion: opts.nodeVersion, pnpmVersion: opts.packageManager.name === 'pnpm' ? opts.packageManager.version : '', }, - currentDependenciesLocations: ctx.modulesFile?.locations, + currentHoistedLocations: ctx.modulesFile?.hoistedLocations, patchedDependencies: patchedDependenciesWithResolvedPath, selectedProjectDirs: projects.map((project) => project.rootDir), allProjects: ctx.projects, @@ -1178,7 +1178,7 @@ const installInContext: InstallFunction = async (projects, ctx, opts) => { nodeVersion: opts.nodeVersion, pnpmVersion: opts.packageManager.name === 'pnpm' ? opts.packageManager.version : '', }, - currentDependenciesLocations: ctx.modulesFile?.locations, + currentHoistedLocations: ctx.modulesFile?.hoistedLocations, selectedProjectDirs: projects.map((project) => project.rootDir), allProjects: ctx.projects, prunedAt: ctx.modulesFile?.prunedAt, diff --git a/pkg-manager/headless/src/index.ts b/pkg-manager/headless/src/index.ts index 6a62c33c250..88ebbb1645e 100644 --- a/pkg-manager/headless/src/index.ts +++ b/pkg-manager/headless/src/index.ts @@ -120,7 +120,7 @@ export interface HeadlessOptions { hoistedDependencies: HoistedDependencies hoistPattern?: string[] publicHoistPattern?: string[] - currentDependenciesLocations?: Record + currentHoistedLocations?: Record lockfileDir: string modulesDir?: string virtualStoreDir?: string @@ -284,7 +284,7 @@ export async function headlessInstall (opts: HeadlessOptions) { directDependenciesByImporterId, graph, hierarchy, - locations, + hoistedLocations, pkgLocationsByDepPath, prevGraph, symlinkedDirectDependenciesByImporterId, @@ -530,7 +530,7 @@ export async function headlessInstall (opts: HeadlessOptions) { included: opts.include, injectedDeps, layoutVersion: LAYOUT_VERSION, - locations, + hoistedLocations, nodeLinker: opts.nodeLinker, packageManager: `${opts.packageManager.name}@${opts.packageManager.version}`, pendingBuilds: opts.pendingBuilds, diff --git a/pkg-manager/headless/src/lockfileToDepGraph.ts b/pkg-manager/headless/src/lockfileToDepGraph.ts index 62a9b820891..bbd68ac6900 100644 --- a/pkg-manager/headless/src/lockfileToDepGraph.ts +++ b/pkg-manager/headless/src/lockfileToDepGraph.ts @@ -80,7 +80,7 @@ export interface LockfileToDepGraphResult { directDependenciesByImporterId: DirectDependenciesByImporterId graph: DependenciesGraph hierarchy?: DepHierarchy - locations?: Record + hoistedLocations?: Record symlinkedDirectDependenciesByImporterId?: DirectDependenciesByImporterId prevGraph?: DependenciesGraph pkgLocationsByDepPath?: Record diff --git a/pkg-manager/headless/src/lockfileToHoistedDepGraph.ts b/pkg-manager/headless/src/lockfileToHoistedDepGraph.ts index 7e88873e8a0..a284e979ce6 100644 --- a/pkg-manager/headless/src/lockfileToHoistedDepGraph.ts +++ b/pkg-manager/headless/src/lockfileToHoistedDepGraph.ts @@ -32,7 +32,7 @@ export interface LockfileToHoistedDepGraphOptions { externalDependencies?: Set importerIds: string[] include: IncludedDependencies - currentDependenciesLocations?: Record + currentHoistedLocations?: Record lockfileDir: string nodeVersion: string pnpmVersion: string @@ -74,10 +74,10 @@ async function _lockfileToHoistedDepGraph ( lockfile, graph, pkgLocationsByDepPath: {}, + hoistedLocations: {} as Record, } - const locations: Record = {} const hierarchy = { - [opts.lockfileDir]: await fetchDeps(fetchDepsOpts, modulesDir, tree.dependencies, locations), + [opts.lockfileDir]: await fetchDeps(fetchDepsOpts, modulesDir, tree.dependencies), } const directDependenciesByImporterId: DirectDependenciesByImporterId = { '.': directDepsMap(Object.keys(hierarchy[opts.lockfileDir]), graph), @@ -89,7 +89,7 @@ async function _lockfileToHoistedDepGraph ( const importerId = reference.replace('workspace:', '') const projectDir = path.join(opts.lockfileDir, importerId) const modulesDir = path.join(projectDir, 'node_modules') - const nextHierarchy = (await fetchDeps(fetchDepsOpts, modulesDir, rootDep.dependencies, locations)) + const nextHierarchy = (await fetchDeps(fetchDepsOpts, modulesDir, rootDep.dependencies)) hierarchy[projectDir] = nextHierarchy const importer = lockfile.importers[importerId] @@ -104,7 +104,7 @@ async function _lockfileToHoistedDepGraph ( hierarchy, pkgLocationsByDepPath: fetchDepsOpts.pkgLocationsByDepPath, symlinkedDirectDependenciesByImporterId, - locations, + hoistedLocations: fetchDepsOpts.hoistedLocations, } } @@ -139,10 +139,10 @@ async function fetchDeps ( graph: DependenciesGraph lockfile: Lockfile pkgLocationsByDepPath: Record + hoistedLocations: Record } & LockfileToHoistedDepGraphOptions, modules: string, deps: Set, - locations: Record ): Promise { const depHierarchy = {} await Promise.all(Array.from(deps).map(async (dep) => { @@ -180,7 +180,7 @@ async function fetchDeps ( const depLocation = path.relative(opts.lockfileDir, dir) const resolution = pkgSnapshotToResolution(depPath, pkgSnapshot, opts.registries) let fetchResponse!: ReturnType - const skipFetch = opts.currentDependenciesLocations?.[depPath]?.includes(depLocation) + const skipFetch = opts.currentHoistedLocations?.[depPath]?.includes(depLocation) if (skipFetch) { fetchResponse = {} as any // eslint-disable-line @typescript-eslint/no-explicit-any } else { @@ -225,11 +225,11 @@ async function fetchDeps ( opts.pkgLocationsByDepPath[depPath] = [] } opts.pkgLocationsByDepPath[depPath].push(dir) - depHierarchy[dir] = await fetchDeps(opts, path.join(dir, 'node_modules'), dep.dependencies, locations) - if (!locations[depPath]) { - locations[depPath] = [] + depHierarchy[dir] = await fetchDeps(opts, path.join(dir, 'node_modules'), dep.dependencies) + if (!opts.hoistedLocations[depPath]) { + opts.hoistedLocations[depPath] = [] } - locations[depPath].push(depLocation) + opts.hoistedLocations[depPath].push(depLocation) opts.graph[dir].children = getChildren(pkgSnapshot, opts.pkgLocationsByDepPath, opts) })) return depHierarchy diff --git a/pkg-manager/modules-yaml/src/index.ts b/pkg-manager/modules-yaml/src/index.ts index 9269bc5df5d..0029cc669fd 100644 --- a/pkg-manager/modules-yaml/src/index.ts +++ b/pkg-manager/modules-yaml/src/index.ts @@ -31,7 +31,7 @@ export interface Modules { storeDir: string virtualStoreDir: string injectedDeps?: Record - locations?: Record + hoistedLocations?: Record } export async function readModulesManifest (modulesDir: string): Promise {