fix: handle non-string version selectors in hoistPeers#11048
Merged
zkochan merged 2 commits intoMar 21, 2026
Conversation
gluxon
commented
Mar 21, 2026
| pnpm: patch | ||
| --- | ||
|
|
||
| Improved handling of non-string version selectors in an internal function (e.g. `hoistPeers`). |
Member
Author
There was a problem hiding this comment.
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.
056bd2b to
544875d
Compare
544875d to
18590a3
Compare
gluxon
commented
Mar 21, 2026
| }) | ||
|
|
||
| // Regression test for https://github.com/pnpm/pnpm/pull/11048 | ||
| test('hoistPeers handles version selector with weight', () => { |
Contributor
There was a problem hiding this comment.
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
hoistPeersto recognize object-based version selectors by readingselector.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
approved these changes
Mar 21, 2026
zkochan
added a commit
that referenced
this pull request
Mar 24, 2026
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 forhoistPeersearly.Problem
Object values in
allPreferredVersionscan be one ofVersionSelectorTypeorVersionSelectorWithWeight.pnpm/resolving/resolver-base/src/index.ts
Line 100 in c2eb020
pnpm/resolving/resolver-base/src/index.ts
Lines 106 to 109 in c2eb020
Before this PR, we were only considering
versionand not{ selectorType: 'version', weight: ... }.Changes
Let's consider the selector types that are objects as well.
Note that a version being pushed to the
nonVersionsmap instead ofversionsworks out most of the time, but I think the original intention of this code path was to put exact versions in theversionsmap. I saw a surprising test failure in another PR when experimenting withgetPreferredVersionsFromLockfileAndManifeststo return more version selectors with weights.