diff --git a/.changeset/plenty-jokes-wave.md b/.changeset/plenty-jokes-wave.md new file mode 100644 index 0000000000..ec48c8e31f --- /dev/null +++ b/.changeset/plenty-jokes-wave.md @@ -0,0 +1,6 @@ +--- +"@pnpm/installing.deps-resolver": patch +pnpm: patch +--- + +Improved handling of non-string version selectors in an internal function (e.g. `hoistPeers`). diff --git a/installing/deps-resolver/src/hoistPeers.ts b/installing/deps-resolver/src/hoistPeers.ts index 8b56cbced8..421fa7d278 100644 --- a/installing/deps-resolver/src/hoistPeers.ts +++ b/installing/deps-resolver/src/hoistPeers.ts @@ -29,7 +29,8 @@ export function hoistPeers ( if (opts.allPreferredVersions![peerName]) { const versions: string[] = [] const nonVersions: string[] = [] - for (const [spec, specType] of Object.entries(opts.allPreferredVersions![peerName])) { + for (const [spec, selector] of Object.entries(opts.allPreferredVersions![peerName])) { + const specType = typeof selector === 'string' ? selector : selector.selectorType if (specType === 'version') { versions.push(spec) } else { diff --git a/installing/deps-resolver/test/hoistPeers.test.ts b/installing/deps-resolver/test/hoistPeers.test.ts index a268e5b19c..8a183b6578 100644 --- a/installing/deps-resolver/test/hoistPeers.test.ts +++ b/installing/deps-resolver/test/hoistPeers.test.ts @@ -96,6 +96,21 @@ test('hoistPeers handles workspace: protocol range without throwing', () => { }) }) +// Regression test for https://github.com/pnpm/pnpm/pull/11048 +test('hoistPeers handles version selector with weight', () => { + expect(hoistPeers({ + autoInstallPeers: true, + allPreferredVersions: { + foo: { + '1.0.0': { selectorType: 'version', weight: 1 }, + }, + }, + workspaceRootDeps: [], + }, [['foo', { range: '1' }]])).toStrictEqual({ + foo: '1.0.0', + }) +}) + test('getHoistableOptionalPeers only picks a version that satisfies all optional ranges', () => { expect(getHoistableOptionalPeers({ foo: ['2', '2.1'],