perf: don't duplicate leaf nodes in dependenciesTree (#8751)

This commit is contained in:
Zoltan Kochan
2024-11-13 01:35:29 +01:00
committed by GitHub
parent ee5dde3894
commit 5b91ec49ba
3 changed files with 11 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
Don't duplicate leaf nodes in dependenciesTree.

View File

@@ -219,6 +219,7 @@ export type PeerDependencies = Record<string, PeerDependency>
export interface ResolvedPackage {
id: PkgResolutionId
isLeaf: boolean
resolution: Resolution
prod: boolean
dev: boolean
@@ -1609,6 +1610,7 @@ function getResolvedPackage (
os: options.pkg.os,
libc: options.pkg.libc,
},
isLeaf: pkgIsLeaf(options.pkg),
pkgIdWithPatchHash: options.pkgIdWithPatchHash,
dev: options.wantedDependency.dev,
fetching: options.pkgResponse.fetching!,

View File

@@ -305,6 +305,10 @@ function buildTree (
if (parentIdsContainSequence(parentIds, parentId, child.id) || parentId === child.id) {
continue
}
if (ctx.resolvedPkgsById[child.id].isLeaf) {
childrenNodeIds[child.alias] = child.id as unknown as NodeId
continue
}
const childNodeId = nextNodeId()
childrenNodeIds[child.alias] = childNodeId
installable = installable || !ctx.skipped.has(child.id)