Skip to content

Prefer stable versions when resolving range (#774)#800

Open
AMDphreak wants to merge 1 commit intonodejs:mainfrom
AMDphreak:fix/prerelease-selection-774
Open

Prefer stable versions when resolving range (#774)#800
AMDphreak wants to merge 1 commit intonodejs:mainfrom
AMDphreak:fix/prerelease-selection-774

Conversation

@AMDphreak
Copy link

This PR fixes #774 by ensuring that Corepack prefers the latest stable version over newer prereleases when resolving a range (like * or latest), unless a prerelease is explicitly requested.\n\n### Problem\nWhen multiple versions match a range, Corepack currently just sorts them with semver.rcompare. Since prereleases (e.g., 11.0.0-dev...) are considered higher than the latest stable (e.g., 10.4.1), Corepack incorrectly selects the prerelease. This causes issues when prereleases have breaking changes in binary paths or behavior.\n\n### Fix\nIn
esolveDescriptor, we now split matching versions into stable and prerelease sets. We prefer the highest stable version if one exists, and only fallback to prereleases if the requested range specifically targets them (checked via isPrereleaseRange helper).

@AMDphreak AMDphreak force-pushed the fix/prerelease-selection-774 branch from 889ffe4 to b08a894 Compare March 3, 2026 19:56
- Update resolveDescriptor to prefer stable matching versions unless the range explicitly targets prereleases.
- Add isPrereleaseRange helper in semverUtils.
@AMDphreak AMDphreak force-pushed the fix/prerelease-selection-774 branch from b08a894 to 9be199f Compare March 3, 2026 20:07
Copy link
Contributor

@MikeMcC399 MikeMcC399 left a comment

Choose a reason for hiding this comment

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

There are a lot of unrelated formatting changes in this PR, which means that it fails linting, and is difficult to review.

The following should fix the formatting:

corepack yarn lint --fix

Please reformat the text in the original post which includes \n characters instead of actual newlines.

This repo uses release-please so it would need a commit message like fix:

I'm not a maintainer, so I can't approve or process this PR further. It would however be good for issue #774 to be fixed, as it has caused me problems in the past.

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.

Corepack incorrectly selects prerelease/dev versions of pnpm when no version is specified

2 participants