fix: peer dependency is not unlinked when adding a new dependency (#6274)

close #6272
This commit is contained in:
Zoltan Kochan
2023-03-24 03:38:59 +02:00
parent f835994eab
commit 634d6874b7
3 changed files with 47 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Peer dependency is not unlinked when adding a new dependency [#6272](https://github.com/pnpm/pnpm/issues/6272).

View File

@@ -178,9 +178,12 @@ export async function resolveDependencies (
? await getTopParents(
difference(
Object.keys(getAllDependenciesFromManifest(project.manifest)),
resolvedImporter.directDependencies
.filter((dep, index) => project.wantedDependencies[index]?.isNew === true)
.map(({ alias }) => alias) || []
[
...resolvedImporter.directDependencies
.filter((_, index) => project.wantedDependencies[index]?.isNew === true)
.map(({ alias }) => alias) || [],
...resolvedImporter.linkedDependencies.map(({ alias }) => alias),
]
),
project.modulesDir
)

View File

@@ -0,0 +1,35 @@
import { promises as fs } from 'fs'
import { WANTED_LOCKFILE } from '@pnpm/constants'
import type { Lockfile } from '@pnpm/lockfile-types'
import { preparePackages } from '@pnpm/prepare'
import readYamlFile from 'read-yaml-file'
import writeYamlFile from 'write-yaml-file'
import { execPnpm } from '../utils'
// Covers https://github.com/pnpm/pnpm/issues/6272
test('peer dependency is not unlinked when adding a new dependency', async () => {
preparePackages([
{
name: 'project-1',
dependencies: {
'@pnpm.e2e/abc': '1.0.0',
'@pnpm.e2e/peer-a': 'workspace:*',
},
},
{
name: '@pnpm.e2e/peer-a',
version: '1.0.0',
dependencies: {},
},
])
await fs.writeFile('.npmrc', 'auto-install-peers=false', 'utf8')
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
await execPnpm(['install'])
await execPnpm(['--filter=project-1', 'add', 'is-odd@1.0.0'])
const lockfile = await readYamlFile<Lockfile>(WANTED_LOCKFILE)
expect(Object.keys(lockfile!.packages!)).toContain('/@pnpm.e2e/abc@1.0.0(@pnpm.e2e/peer-a@@pnpm.e2e+peer-a)')
})