Skip to content

Commit

Permalink
fix(auto-install-peers): don't fail on projects with linked deps (#4807)
Browse files Browse the repository at this point in the history
close #4796
  • Loading branch information
zkochan committed May 27, 2022
1 parent ae2f845 commit 45238e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/seven-roses-cover.md
@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---

Don't fail on projects with linked dependencies, when `auto-install-peers` is set to `true` [#4796](https://github.com/pnpm/pnpm/issues/4796).
28 changes: 27 additions & 1 deletion packages/core/test/install/autoInstallPeers.ts
@@ -1,5 +1,5 @@
import { addDependenciesToPackage } from '@pnpm/core'
import { prepareEmpty } from '@pnpm/prepare'
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
import { addDistTag } from '@pnpm/registry-mock'
import { testDefaults } from '../utils'

Expand Down Expand Up @@ -35,3 +35,29 @@ test('do not auto install when there is no common peer dependency range intersec
'/wants-peer-c-2/1.0.0',
])
})

test('don\'t fail on linked package, when peers are auto installed', async () => {
const pkgManifest = {
dependencies: {
linked: 'link:../linked',
},
}
preparePackages([
{
location: 'linked',
package: {
name: 'linked',
peerDependencies: {
'peer-c': '1.0.0',
},
},
},
{
location: 'pkg',
package: pkgManifest,
},
])
process.chdir('pkg')
const updatedManifest = await addDependenciesToPackage(pkgManifest, ['peer-b'], await testDefaults({ autoInstallPeers: true }))
expect(Object.keys(updatedManifest.dependencies ?? {})).toStrictEqual(['linked', 'peer-b'])
})
2 changes: 1 addition & 1 deletion packages/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -254,7 +254,7 @@ export default async function resolveDependencies (
).filter(Boolean) as PkgAddress[]
pkgAddresses.push(...newPkgAddresses)
if (!ctx.autoInstallPeers) break
const allMissingPeers = mergePkgsDeps(newPkgAddresses.map(({ missingPeers }) => missingPeers))
const allMissingPeers = mergePkgsDeps(newPkgAddresses.map(({ missingPeers }) => missingPeers).filter(Boolean))
if (!Object.keys(allMissingPeers).length) break
wantedDependencies = getNonDevWantedDependencies({ dependencies: allMissingPeers })
}
Expand Down

0 comments on commit 45238e3

Please sign in to comment.