Skip to content

Commit

Permalink
fix: out of memory exception with node-linker=hoisted
Browse files Browse the repository at this point in the history
ref #5909
  • Loading branch information
zkochan committed Jan 27, 2023
1 parent bc4c97a commit d6dbfb9
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions pkg-manager/headless/src/linkHoistedModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PackageFilesResponse,
StoreController,
} from '@pnpm/store-controller-types'
import pLimit from 'p-limit'
import difference from 'ramda/src/difference'
import isEmpty from 'ramda/src/isEmpty'
import rimraf from '@zkochan/rimraf'
Expand All @@ -19,6 +20,8 @@ import {
DependenciesGraph,
} from './lockfileToDepGraph'

const limitLinking = pLimit(16)

export async function linkHoistedModules (
storeController: StoreController,
graph: DependenciesGraph,
Expand Down Expand Up @@ -111,22 +114,27 @@ async function linkAllPkgsInOrder (
patchFileHash: depNode.patchFile?.hash,
})
}
const { importMethod, isBuilt } = await storeController.importPackage(depNode.dir, {
filesResponse,
force: opts.force || depNode.depPath !== prevGraph[dir]?.depPath,
keepModulesDir: true,
requiresBuild: depNode.requiresBuild || depNode.patchFile != null,
sideEffectsCacheKey,
})
if (importMethod) {
progressLogger.debug({
method: importMethod,
requester: opts.lockfileDir,
status: 'imported',
to: depNode.dir,
// Limiting the concurrency here fixes an out of memory error.
// It is not clear why it helps as importing is also limited inside fs.indexed-pkg-importer.
// The out of memory error was reproduced on the teambit/bit repository with the "rootComponents" feature turned on
await limitLinking(async () => {
const { importMethod, isBuilt } = await storeController.importPackage(depNode.dir, {
filesResponse,
force: opts.force || depNode.depPath !== prevGraph[dir]?.depPath,
keepModulesDir: true,
requiresBuild: depNode.requiresBuild || depNode.patchFile != null,
sideEffectsCacheKey,
})
}
depNode.isBuilt = isBuilt
if (importMethod) {
progressLogger.debug({
method: importMethod,
requester: opts.lockfileDir,
status: 'imported',
to: depNode.dir,
})
}
depNode.isBuilt = isBuilt
})
}
return linkAllPkgsInOrder(storeController, graph, prevGraph, deps, dir, opts)
})
Expand Down

0 comments on commit d6dbfb9

Please sign in to comment.