fix: linking optional dependencies (#7949)

close #7943
This commit is contained in:
Zoltan Kochan
2024-04-17 17:35:05 +02:00
committed by GitHub
parent dd43b0f6bc
commit b3961cb19d
3 changed files with 16 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Fixed an issue where optional dependencies were not linked into the dependent's node_modules [#7943](https://github.com/pnpm/pnpm/issues/7943).

View File

@@ -689,3 +689,12 @@ test('optional dependency is hardlinked to the store if it does not require a bu
})
)
})
// Covers https://github.com/pnpm/pnpm/issues/7943
test('complex scenario with same optional dependencies appearing in many places of the dependency graph', async () => {
prepareEmpty()
await addDependenciesToPackage({}, ['@storybook/addon-essentials@7.6.17', 'storybook@7.6.17', 'vite@5.2.8'], testDefaults())
expect(fs.readdirSync('node_modules/.pnpm/esbuild@0.18.20/node_modules/@esbuild').length).toEqual(1)
expect(fs.readdirSync('node_modules/.pnpm/esbuild@0.20.2/node_modules/@esbuild').length).toEqual(1)
})

View File

@@ -277,7 +277,7 @@ function buildTree (
}
const childNodeId = createNodeId(parentNodeId, child.depPath)
childrenNodeIds[child.alias] = childNodeId
installable = installable && !ctx.skipped.has(child.depPath)
installable = installable || !ctx.skipped.has(child.depPath)
ctx.dependenciesTree.set(childNodeId, {
children: () => buildTree(ctx,
childNodeId,