mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 20:41:47 -04:00
fix: resolving peer deps when there are aliased deps (#6709)
close #6588
This commit is contained in:
6
.changeset/chilled-dancers-thank.md
Normal file
6
.changeset/chilled-dancers-thank.md
Normal 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).
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user