Skip to content

fix: return prerelease of 0.0.0 from minVersion when it is the minimum - #936

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

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

Conversation

@thisisshivamtiwari

Copy link
Copy Markdown

Fixes #934

minVersion checked 0.0.0 before 0.0.0-0 and returned it as soon as it matched. Since every prerelease of 0.0.0 sorts below 0.0.0, that shortcut returned the wrong answer whenever a 0.0.0 prerelease also matches:

semver.minVersion('>=0.0.0-alpha <1.0.0').version              // was '0.0.0', now '0.0.0-alpha'
semver.minVersion('>=0.0.0-0').version                          // was '0.0.0', now '0.0.0-0'
semver.minVersion('*', { includePrerelease: true }).version     // was '0.0.0', now '0.0.0-0'

Changes in ranges/min-version.js:

  • Check 0.0.0-0 first, since it is the lowest possible version.
  • If 0.0.0 matches, still run the normal lower-bound loop and return its result only when it matches and is below 0.0.0. Otherwise return 0.0.0 as before. This keeps every existing result: when the loop finds nothing lower, the answer is still 0.0.0.
  • Skip ANY comparators in the loop. Before this change the loop never saw them, because any range containing * matched 0.0.0 and returned early.

Without includePrerelease, * and <2 still return 0.0.0, which matches the expectation in the issue thread.

Tests

  • Added cases to test/ranges/min-version.js for 0.0.0 prerelease lower bounds (>=, >, in a union, and an impossible prerelease set next to <1 that must still fall back to 0.0.0), plus includePrerelease cases. The new cases fail on main and pass with this change.
  • The test helper now prints the options object with JSON.stringify so the new includePrerelease cases have readable names.
  • npm test (tap with 100% coverage, then eslint and template-oss-check) passes locally.

🤖 Generated with Claude Code

minVersion tried 0.0.0 before 0.0.0-0 and returned it as soon as it
matched, so a lower bound such as >=0.0.0-alpha, or any range with
includePrerelease, gave 0.0.0 instead of the lower prerelease.

Fixes npm#934
@thisisshivamtiwari
thisisshivamtiwari requested a review from a team as a code owner October 29, 2026 02:52
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

1 participant