mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 02:53:15 -04:00
fix: out-of-memory error during peers resolution (#7149)
This commit is contained in:
6
.changeset/olive-apricots-change.md
Normal file
6
.changeset/olive-apricots-change.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/resolve-dependencies": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Optimize peers resolution to avoid out-of-memory exceptions in some rare cases, when there are too many circular dependencies and peer dependencies [#7149](https://github.com/pnpm/pnpm/pull/7149).
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
} from '@pnpm/types'
|
||||
import { depPathToFilename, createPeersFolderSuffix } from '@pnpm/dependency-path'
|
||||
import mapValues from 'ramda/src/map'
|
||||
import partition from 'ramda/src/partition'
|
||||
import pick from 'ramda/src/pick'
|
||||
import scan from 'ramda/src/scan'
|
||||
import {
|
||||
@@ -497,7 +498,12 @@ function resolvePeersOfChildren<T extends PartialResolvedPackage> (
|
||||
const allResolvedPeers = new Map<string, string>()
|
||||
const allMissingPeers = new Set<string>()
|
||||
|
||||
for (const childNodeId of Object.values(children)) {
|
||||
// Partition children based on whether they're repeated in parentPkgs.
|
||||
// This impacts the efficiency of graph traversal and prevents potential out-of-memory errors.mes can even lead to out-of-memory exceptions.
|
||||
const [repeated, notRepeated] = partition(([alias]) => parentPkgs[alias] != null, Object.entries(children))
|
||||
|
||||
// Resolving non-repeated nodes before repeated nodes proved to be slightly faster.
|
||||
for (const [, childNodeId] of [...notRepeated, ...repeated]) {
|
||||
const { resolvedPeers, missingPeers } = resolvePeersOfNode(childNodeId, parentPkgs, ctx)
|
||||
for (const [k, v] of resolvedPeers) {
|
||||
allResolvedPeers.set(k, v)
|
||||
|
||||
Reference in New Issue
Block a user