Skip to content

fix: return 0.0.0 prerelease lower bounds from minVersion - #945

Closed
thelastbackspace wants to merge 1 commit into
npm:mainfrom
thelastbackspace:fix/934-min-version-zero-prerelease
Closed

thelastbackspace wants to merge 1 commit into
npm:mainfrom
thelastbackspace:fix/934-min-version-zero-prerelease

Conversation

@thelastbackspace

Copy link
Copy Markdown

Summary

minVersion checked 0.0.0 first and returned it whenever it matched, so a lower 0.0.0 prerelease never got a chance:

  • minVersion('>=0.0.0-alpha <1.0.0') returned 0.0.0 instead of 0.0.0-alpha
  • minVersion('*', { includePrerelease: true }) returned 0.0.0 instead of 0.0.0-0

Fix

Check 0.0.0-0 first, since nothing sorts below it. If 0.0.0 matches, I still run the comparator loop and only return its result when it is lower than 0.0.0 (a 0.0.0 prerelease bound); otherwise 0.0.0 is returned like before. The loop now skips the ANY comparator (*), which it never saw before because the 0.0.0 shortcut always returned first.

Without includePrerelease, *, <2, <0.0.1-beta etc. still return 0.0.0. One behavior change to call out: >=0.0.0-0 now returns 0.0.0-0, which does satisfy it.

Testing

Added cases to test/ranges/min-version.js for >= / > 0.0.0 prerelease bounds (also inside || ranges in either order), >=0.0.0-0, and includePrerelease with *, <2 and prerelease bounds. They fail on main and pass with this change.

npx tap test/ranges/min-version.js
npm test

Fixes #934

minVersion returned 0.0.0 as soon as it satisfied the range, before
looking at the comparators, so a lower 0.0.0 prerelease bound
(>=0.0.0-alpha) or 0.0.0-0 under includePrerelease was skipped.

Fixes npm#934
@thelastbackspace
thelastbackspace requested a review from a team as a code owner November 5, 2026 00:12
@jeffkl

jeffkl commented Nov 5, 2026

Copy link
Copy Markdown

Is this a duplicate of #936 ?

@thelastbackspace

Copy link
Copy Markdown
Author

Yes, sorry, I missed #936. Closing this in favour of it.

@jeffkl

jeffkl commented Nov 5, 2026

Copy link
Copy Markdown

No worries, thanks for confirming. Feel free to comment on the other PR.

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.

[BUG] minVersion returns 0.0.0 when a 0.0.0 prerelease is the true minimum

2 participants