mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 02:53:15 -04:00
fix: peer dependency is not unlinked when adding a new dependency (#6274)
close #6272
This commit is contained in:
6
.changeset/real-eels-approve.md
Normal file
6
.changeset/real-eels-approve.md
Normal 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).
|
||||
@@ -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
|
||||
)
|
||||
|
||||
35
pnpm/test/monorepo/peerDependencies.ts
Normal file
35
pnpm/test/monorepo/peerDependencies.ts
Normal 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)')
|
||||
})
|
||||
Reference in New Issue
Block a user