Skip to content

Commit

Permalink
feat: store locations of deps when node-linker is set to hoisted
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Dec 14, 2022
1 parent bc18d33 commit 29fc688
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg-manager/headless/src/index.ts
Expand Up @@ -283,6 +283,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
directDependenciesByImporterId,
graph,
hierarchy,
locations,
pkgLocationsByDepPath,
prevGraph,
symlinkedDirectDependenciesByImporterId,
Expand Down Expand Up @@ -528,6 +529,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
included: opts.include,
injectedDeps,
layoutVersion: LAYOUT_VERSION,
locations,
nodeLinker: opts.nodeLinker,
packageManager: `${opts.packageManager.name}@${opts.packageManager.version}`,
pendingBuilds: opts.pendingBuilds,
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/headless/src/lockfileToDepGraph.ts
Expand Up @@ -80,6 +80,7 @@ export interface LockfileToDepGraphResult {
directDependenciesByImporterId: DirectDependenciesByImporterId
graph: DependenciesGraph
hierarchy?: DepHierarchy
locations?: Record<string, string[]>
symlinkedDirectDependenciesByImporterId?: DirectDependenciesByImporterId
prevGraph?: DependenciesGraph
pkgLocationsByDepPath?: Record<string, string[]>
Expand Down
15 changes: 11 additions & 4 deletions pkg-manager/headless/src/lockfileToHoistedDepGraph.ts
Expand Up @@ -74,8 +74,9 @@ async function _lockfileToHoistedDepGraph (
graph,
pkgLocationsByDepPath: {},
}
const locations: Record<string, string[]> = {}
const hierarchy = {
[opts.lockfileDir]: await fetchDeps(fetchDepsOpts, modulesDir, tree.dependencies),
[opts.lockfileDir]: await fetchDeps(fetchDepsOpts, modulesDir, tree.dependencies, locations),
}
const directDependenciesByImporterId: DirectDependenciesByImporterId = {
'.': directDepsMap(Object.keys(hierarchy[opts.lockfileDir]), graph),
Expand All @@ -87,7 +88,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))
const nextHierarchy = (await fetchDeps(fetchDepsOpts, modulesDir, rootDep.dependencies, locations))
hierarchy[projectDir] = nextHierarchy

const importer = lockfile.importers[importerId]
Expand All @@ -102,6 +103,7 @@ async function _lockfileToHoistedDepGraph (
hierarchy,
pkgLocationsByDepPath: fetchDepsOpts.pkgLocationsByDepPath,
symlinkedDirectDependenciesByImporterId,
locations,
}
}

Expand Down Expand Up @@ -138,7 +140,8 @@ async function fetchDeps (
pkgLocationsByDepPath: Record<string, string[]>
} & LockfileToHoistedDepGraphOptions,
modules: string,
deps: Set<HoisterResult>
deps: Set<HoisterResult>,
locations: Record<string, string[]>
): Promise<DepHierarchy> {
const depHierarchy = {}
await Promise.all(Array.from(deps).map(async (dep) => {
Expand Down Expand Up @@ -215,7 +218,11 @@ async function fetchDeps (
opts.pkgLocationsByDepPath[depPath] = []
}
opts.pkgLocationsByDepPath[depPath].push(dir)
depHierarchy[dir] = await fetchDeps(opts, path.join(dir, 'node_modules'), dep.dependencies)
depHierarchy[dir] = await fetchDeps(opts, path.join(dir, 'node_modules'), dep.dependencies, locations)
if (!locations[depPath]) {
locations[depPath] = []
}
locations[depPath].push(path.relative(opts.lockfileDir, dir))
opts.graph[dir].children = getChildren(pkgSnapshot, opts.pkgLocationsByDepPath, opts)
}))
return depHierarchy
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/modules-yaml/src/index.ts
Expand Up @@ -31,6 +31,7 @@ export interface Modules {
storeDir: string
virtualStoreDir: string
injectedDeps?: Record<string, string[]>
locations?: Record<string, string[]>
}

export async function readModulesManifest (modulesDir: string): Promise<Modules | null> {
Expand Down

0 comments on commit 29fc688

Please sign in to comment.