fix: resolving peer deps when there are aliased deps (#6709)

close #6588
This commit is contained in:
Zoltan Kochan
2023-06-23 16:11:54 +03:00
committed by GitHub
parent 4e7afec90c
commit e2c3ef313e
3 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
In cases where both aliased and non-aliased dependencies exist to the same package, non-aliased dependencies will be used for resolving peer dependencies, addressing issue [#6588](https://github.com/pnpm/pnpm/issues/6588).

View File

@@ -1443,6 +1443,20 @@ test('when there are several aliased dependencies of the same package, pick the
expect(lockfile.packages['/@pnpm.e2e/abc@1.0.0(@pnpm.e2e/peer-c@2.0.0)']).toBeTruthy()
})
test('when there is an aliases dependency and a non-aliased one, prefer the non-aliased dependency to resolve peers', async () => {
prepareEmpty()
const opts = await testDefaults({ autoInstallPeers: false, strictPeerDependencies: false })
const manifest = await addDependenciesToPackage({}, [
'@pnpm.e2e/peer-c@1.0.0',
'peer-c@npm:@pnpm.e2e/peer-c@2.0.0',
], opts)
await addDependenciesToPackage(manifest, ['@pnpm.e2e/abc@1.0.0'], opts)
const lockfile = await readYamlFile<any>(path.resolve(WANTED_LOCKFILE)) // eslint-disable-line
expect(lockfile.packages['/@pnpm.e2e/abc@1.0.0(@pnpm.e2e/peer-c@1.0.0)']).toBeTruthy()
})
test('in a subdependency, when there are several aliased dependencies of the same package, pick the one with the highest version to resolve peers', async () => {
prepareEmpty()

View File

@@ -631,9 +631,9 @@ function toPkgByName<T extends PartialResolvedPackage> (nodes: Array<{ alias: st
function updateParentRefs (parentRefs: ParentRefs, newAlias: string, pkg: ParentRef) {
const existing = parentRefs[newAlias]
if (existing) {
const existingHasAlias = existing.alias != null || existing.alias !== newAlias
const existingHasAlias = existing.alias != null && existing.alias !== newAlias
if (!existingHasAlias) return
const newHasAlias = pkg.alias != null || pkg.alias !== newAlias
const newHasAlias = pkg.alias != null && pkg.alias !== newAlias
if (newHasAlias && semver.gte(existing.version, pkg.version)) return
}
parentRefs[newAlias] = pkg