Skip to content

fix: handle non-string version selectors in hoistPeers#11048

Merged
zkochan merged 2 commits into
pnpm:mainfrom
gluxon:gluxon/non-string-version-selectors-in-hoistPeers
Mar 21, 2026
Merged

fix: handle non-string version selectors in hoistPeers#11048
zkochan merged 2 commits into
pnpm:mainfrom
gluxon:gluxon/non-string-version-selectors-in-hoistPeers

Conversation

@gluxon

@gluxon gluxon commented Mar 21, 2026

Copy link
Copy Markdown
Member

Context

While working on #10626, I began hitting test failures as a result of a bug in hoistPeers. Since it'll take me longer to get a PR up addressing #10626, I'd like to create and merge a fix for hoistPeers early.

Problem

Object values in allPreferredVersions can be one of VersionSelectorType or VersionSelectorWithWeight.

export type VersionSelectorType = 'version' | 'range' | 'tag'

export interface VersionSelectorWithWeight {
selectorType: VersionSelectorType
weight: number
}

Before this PR, we were only considering version and not { selectorType: 'version', weight: ... }.

Changes

Let's consider the selector types that are objects as well.

Note that a version being pushed to the nonVersions map instead of versions works out most of the time, but I think the original intention of this code path was to put exact versions in the versions map. I saw a surprising test failure in another PR when experimenting with getPreferredVersionsFromLockfileAndManifests to return more version selectors with weights.

pnpm: patch
---

Improved handling of non-string version selectors in an internal function (e.g. `hoistPeers`).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to hit this bug today since getPreferredVersionsFromLockfileAndManifests always returns string version selectors for non-importer packages.

I can delete the changeset if we think it's not useful given that.

@gluxon gluxon force-pushed the gluxon/non-string-version-selectors-in-hoistPeers branch 3 times, most recently from 056bd2b to 544875d Compare March 21, 2026 19:44
@gluxon gluxon force-pushed the gluxon/non-string-version-selectors-in-hoistPeers branch from 544875d to 18590a3 Compare March 21, 2026 19:56
})

// Regression test for https://github.com/pnpm/pnpm/pull/11048
test('hoistPeers handles version selector with weight', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@gluxon gluxon marked this pull request as ready for review March 21, 2026 19:59
@gluxon gluxon requested a review from zkochan as a code owner March 21, 2026 19:59
Copilot AI review requested due to automatic review settings March 21, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in hoistPeers where PreferredVersions entries that are objects (e.g. { selectorType: 'version', weight: ... }) were not treated as exact versions, leading to incorrect peer hoisting behavior.

Changes:

  • Update hoistPeers to recognize object-based version selectors by reading selector.selectorType.
  • Add a regression test covering version selectors with weights.
  • Add a changeset to publish the fix as a patch.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
installing/deps-resolver/src/hoistPeers.ts Treat object selectors as their selectorType so exact versions are categorized correctly.
installing/deps-resolver/test/hoistPeers.test.ts Adds regression coverage for { selectorType: 'version', weight: ... } selectors.
.changeset/plenty-jokes-wave.md Declares a patch release for the deps-resolver (and pnpm) to ship the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zkochan zkochan merged commit 021f70d into pnpm:main Mar 21, 2026
12 checks passed
zkochan added a commit that referenced this pull request Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants