diff --git a/.changeset/chilled-dancers-thank.md b/.changeset/chilled-dancers-thank.md new file mode 100644 index 0000000000..36a35ba08e --- /dev/null +++ b/.changeset/chilled-dancers-thank.md @@ -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). diff --git a/pkg-manager/core/test/install/peerDependencies.ts b/pkg-manager/core/test/install/peerDependencies.ts index 12504ed01b..6a2b74fe9e 100644 --- a/pkg-manager/core/test/install/peerDependencies.ts +++ b/pkg-manager/core/test/install/peerDependencies.ts @@ -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(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() diff --git a/pkg-manager/resolve-dependencies/src/resolvePeers.ts b/pkg-manager/resolve-dependencies/src/resolvePeers.ts index 711fe0c9ca..c22ce45c45 100644 --- a/pkg-manager/resolve-dependencies/src/resolvePeers.ts +++ b/pkg-manager/resolve-dependencies/src/resolvePeers.ts @@ -631,9 +631,9 @@ function toPkgByName (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