fix: out of memory exception with node-linker=hoisted (#5988)

ref #5909
This commit is contained in:
Zoltan Kochan
2023-01-27 06:11:43 +02:00
committed by GitHub
parent bc4c97aace
commit 04efe86469
2 changed files with 29 additions and 15 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/headless": patch
"pnpm": patch
---
Fixed out of memory error that sometimes happens when `node-linker` is set to `hoisted`.

View File

@@ -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'
@@ -19,6 +20,8 @@ import {
DependenciesGraph,
} from './lockfileToDepGraph'
const limitLinking = pLimit(16)
export async function linkHoistedModules (
storeController: StoreController,
graph: DependenciesGraph,
@@ -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)
})