fix: dedupe direct deps when headless install is used

This commit is contained in:
Zoltan Kochan
2022-11-28 17:27:00 +02:00
parent 510143083a
commit 32288715d3
3 changed files with 14 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/headless": patch
---
Dedupe direct dependencies.

View File

@@ -95,4 +95,10 @@ test('dedupe direct dependencies', async () => {
expect(fs.readdirSync('project-2/node_modules').sort()).toEqual(['is-odd'])
await projects['project-3'].hasNot('is-negative')
expect(fs.existsSync('project-3/node_modules')).toBeFalsy()
// Test the same with headless install
await mutateModules(importers, await testDefaults({ allProjects, dedupeDirectDeps: true, frozenLockfile: true }))
expect(fs.readdirSync('project-2/node_modules').sort()).toEqual(['is-odd'])
await projects['project-3'].hasNot('is-negative')
expect(fs.existsSync('project-3/node_modules')).toBeFalsy()
})

View File

@@ -340,7 +340,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
await symlinkDirectDependencies({
directDependenciesByImporterId: symlinkedDirectDependenciesByImporterId!,
dedupe: opts.dedupeDirectDeps,
dedupe: Boolean(opts.dedupeDirectDeps),
filteredLockfile,
lockfileDir,
projects: selectedProjects,
@@ -408,6 +408,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
/** Skip linking and due to no project manifest */
if (!opts.ignorePackageManifest) {
await symlinkDirectDependencies({
dedupe: Boolean(opts.dedupeDirectDeps),
directDependenciesByImporterId,
filteredLockfile,
lockfileDir,
@@ -564,7 +565,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
type SymlinkDirectDependenciesOpts = Pick<HeadlessOptions, 'registries' | 'symlink' | 'lockfileDir'> & {
filteredLockfile: Lockfile
dedupe?: boolean
dedupe: boolean
directDependenciesByImporterId: DirectDependenciesByImporterId
projects: Project[]
}