Skip to content

Commit

Permalink
fix: cli crash with auto-install-peers=true (#5394)
Browse files Browse the repository at this point in the history
ref #5390
ref #5372
  • Loading branch information
zkochan committed Sep 22, 2022
1 parent 56aeba4 commit 77f7cee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-wolves-destroy.md
@@ -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.
6 changes: 6 additions & 0 deletions packages/core/test/install/autoInstallPeers.ts
Expand Up @@ -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 }))
})
6 changes: 3 additions & 3 deletions packages/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -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>
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
Expand Down

0 comments on commit 77f7cee

Please sign in to comment.