fix: cli crash with auto-install-peers=true (#5394)

ref #5390
ref #5372
This commit is contained in:
Zoltan Kochan
2022-09-23 01:29:33 +03:00
committed by GitHub
parent 56aeba4bae
commit 77f7cee488
3 changed files with 15 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Don't crash when auto-install-peers is true and the project has many complex circular dependencies.

View File

@@ -341,3 +341,9 @@ test('auto install peer deps in a workspace. test #2', async () => {
},
], await testDefaults({ autoInstallPeers: true }))
})
// This test may be removed if autoInstallPeers will become true by default
test('installation on a package with many complex circular dependencies does not fail when auto install peers is on', async () => {
prepareEmpty()
await addDependenciesToPackage({}, ['webpack@4.46.0'], await testDefaults({ autoInstallPeers: true }))
})

View File

@@ -158,7 +158,7 @@ export interface ResolutionContext {
virtualStoreDir: string
updateMatching?: (pkgName: string) => boolean
workspacePackages?: WorkspacePackages
missingPeersOfChildrenByPkgId: Record<string, { parentNodeId: string, missingPeersOfChildren: MissingPeersOfChildren }>
missingPeersOfChildrenByPkgId: Record<string, { parentImporterId: string, missingPeersOfChildren: MissingPeersOfChildren }>
}
export type MissingPeers = Record<string, string>
@@ -1278,7 +1278,7 @@ async function resolveDependency (
let missingPeersOfChildren!: MissingPeersOfChildren | undefined
if (!nodeIdContains(options.parentPkg.nodeId, depPath)) {
if (ctx.missingPeersOfChildrenByPkgId[pkgResponse.body.id]) {
if (!options.parentPkg.nodeId.startsWith(ctx.missingPeersOfChildrenByPkgId[pkgResponse.body.id].parentNodeId)) {
if (!options.parentPkg.nodeId.startsWith(ctx.missingPeersOfChildrenByPkgId[pkgResponse.body.id].parentImporterId)) {
missingPeersOfChildren = ctx.missingPeersOfChildrenByPkgId[pkgResponse.body.id].missingPeersOfChildren
}
} else {
@@ -1289,7 +1289,7 @@ async function resolveDependency (
get: pShare(p.promise),
}
ctx.missingPeersOfChildrenByPkgId[pkgResponse.body.id] = {
parentNodeId: options.parentPkg.nodeId,
parentImporterId: options.parentPkg.nodeId.substring(0, options.parentPkg.nodeId.indexOf('>', 1) + 1),
missingPeersOfChildren,
}
}