Skip to content

Commit

Permalink
fix: peer dependency is not unlinked when adding a new dependency (#6274
Browse files Browse the repository at this point in the history
)

close #6272
  • Loading branch information
zkochan committed Mar 24, 2023
1 parent f835994 commit 634d687
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/real-eels-approve.md
Original file line number Diff line number Diff line change
@@ -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).
9 changes: 6 additions & 3 deletions pkg-manager/resolve-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
35 changes: 35 additions & 0 deletions pnpm/test/monorepo/peerDependencies.ts
Original file line number Diff line number Diff line change
@@ -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)')
})

0 comments on commit 634d687

Please sign in to comment.