fix: installing a new peer dependency

PR #3057
This commit is contained in:
Zoltan Kochan
2021-01-04 02:23:18 +02:00
committed by GitHub
parent 5a5fb72ec5
commit db0c7e1576
3 changed files with 28 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
When a new peer dependency is installed, don't remove the existing regular dependencies of the package that depends on the peer.

View File

@@ -432,15 +432,14 @@ function getDepsToResolve (
const infoFromLockfile = getInfoFromLockfile(wantedLockfile, options.registries, reference, wantedDependency.alias)
if (
!proceedAll &&
infoFromLockfile?.dependencyLockfile?.peerDependencies
(infoFromLockfile?.dependencyLockfile?.peerDependencies != null || !infoFromLockfile)
) {
if (infoFromLockfile?.dependencyLockfile?.peerDependencies) {
Object.keys(infoFromLockfile.dependencyLockfile.peerDependencies).forEach((peerName) => {
allPeers.add(peerName)
})
}
proceed = true
Object.keys(infoFromLockfile.dependencyLockfile.peerDependencies).forEach((peerName) => {
allPeers.add(peerName)
})
}
if (!infoFromLockfile && !proceedAll) {
// In this case we don't know if the package depends on peer dependencies, so we proceed all.
proceedAll = true
for (const extendedWantedDep of extendedWantedDeps) {
if (!extendedWantedDep.proceed) {

View File

@@ -240,12 +240,25 @@ test('strict-peer-dependencies: error is thrown when bad version of resolved pee
test('top peer dependency is linked on subsequent install', async () => {
prepareEmpty()
const manifest = await addDependenciesToPackage({}, ['ajv@4.10.4'], await testDefaults())
const manifest = await addDependenciesToPackage({}, ['peer-c@1.0.0'], await testDefaults())
await addDependenciesToPackage(manifest, ['ajv-keywords@1.5.0'], await testDefaults())
await addDependenciesToPackage(manifest, ['abc-parent-with-ab@1.0.0'], await testDefaults())
expect(await exists(path.resolve('node_modules/.pnpm/ajv-keywords@1.5.0/node_modules/ajv-keywords'))).toBeFalsy()
expect(await exists(path.resolve('node_modules/.pnpm/ajv-keywords@1.5.0_ajv@4.10.4/node_modules/ajv'))).toBeTruthy()
expect(await exists(path.resolve('node_modules/.pnpm/abc-parent-with-ab@1.0.0/node_modules/abc-parent-with-ab'))).toBeFalsy()
expect(await exists(path.resolve('node_modules/.pnpm/abc-parent-with-ab@1.0.0_peer-c@1.0.0/node_modules/abc-parent-with-ab'))).toBeTruthy()
})
test('top peer dependency is linked on subsequent install. Reverse order', async () => {
prepareEmpty()
console.log(process.cwd())
const manifest = await addDependenciesToPackage({}, ['abc-parent-with-ab@1.0.0'], await testDefaults())
await addDependenciesToPackage(manifest, ['peer-c@1.0.0'], await testDefaults())
expect(await exists(path.resolve('node_modules/.pnpm/abc-parent-with-ab@1.0.0/node_modules/abc-parent-with-ab'))).toBeFalsy()
expect(await exists(path.resolve('node_modules/.pnpm/abc-parent-with-ab@1.0.0_peer-c@1.0.0/node_modules/abc-parent-with-ab'))).toBeTruthy()
expect(await exists(path.resolve('node_modules/.pnpm/abc-parent-with-ab@1.0.0_peer-c@1.0.0/node_modules/is-positive'))).toBeTruthy()
})
async function okFile (filename: string) {