fix(headless): don't create broken symlinks

close #2916
PR #3032
This commit is contained in:
Zoltan Kochan
2020-12-19 12:21:45 +02:00
committed by GitHub
parent d85caeb420
commit d064b77364
3 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/headless": patch
---
Don't create broken symlinks to skipped optional dependencies, when hoisting.

View File

@@ -223,6 +223,11 @@ export default async (opts: HeadlessOptions) => {
pnpmVersion: opts.currentEngine.pnpmVersion,
} as LockfileToDepGraphOptions
)
if (filteredLockfile.packages) {
for (const skippedDepPath of Array.from(skipped)) {
delete filteredLockfile.packages[skippedDepPath]
}
}
if (opts.enablePnp) {
const importerNames = R.fromPairs(
opts.projects.map(({ manifest, id }) => [id, manifest.name ?? id])

View File

@@ -499,3 +499,27 @@ test('should recreate node_modules with hoisting', async () => {
expect(Object.keys(modulesManifest?.hoistedDependencies ?? {}).length > 0).toBeTruthy()
}
})
test('hoisting should not create a broken symlink to a skipped optional dependency', async () => {
const project = prepareEmpty()
console.log(process.cwd())
await install({
optionalDependencies: {
'not-compatible-with-any-os': '*',
},
}, await testDefaults({ publicHoistPattern: '*' }))
await project.hasNot('dep-of-optional-pkg')
// Verifying the same with headless installation
await rimraf('node_modules')
await install({
optionalDependencies: {
'not-compatible-with-any-os': '*',
},
}, await testDefaults({ publicHoistPattern: '*' }))
await project.hasNot('dep-of-optional-pkg')
})