Skip to content

fix: minVersion returns the true minimum for > in includePrerelease mode#890

Open
spokodev wants to merge 1 commit into
npm:mainfrom
spokodev:fix/min-version-prerelease-lower-bound
Open

fix: minVersion returns the true minimum for > in includePrerelease mode#890
spokodev wants to merge 1 commit into
npm:mainfrom
spokodev:fix/min-version-prerelease-lower-bound

Conversation

@spokodev

Copy link
Copy Markdown

What

minVersion returns "the lowest version that can possibly match the given range", but for a >X.Y.Z bound in includePrerelease mode it skips the lowest prerelease of the next version:

semver.minVersion('>1.0.0', { includePrerelease: true }) // 1.0.1

1.0.1-0 also satisfies >1.0.0 under includePrerelease and is lower than 1.0.1:

semver.satisfies('1.0.1-0', '>1.0.0', { includePrerelease: true }) // true
semver.lt('1.0.1-0', '1.0.1')                                      // true

so 1.0.1 is not the minimum.

Root cause

For a > comparator that already carries a prerelease, minVersion appends .0 to reach the lowest prerelease (>1.0.0-01.0.0-0.0). The plain >X.Y.Z branch only did patch++ and never considered prereleases — even when includePrerelease puts them in scope.

Fix

After bumping the patch for a prerelease-less > bound, append the -0 prerelease when the range includes prereleases, so >1.0.0 yields 1.0.1-0. Default (non-includePrerelease) mode is unchanged — >1.0.0 still yields 1.0.1.

Tests

Added ['>1.0.0', '1.0.1-0', { includePrerelease: true }] and ['>2 || >1.0.0', '1.0.1-0', { includePrerelease: true }]. Both fail on main and pass with the fix; the existing default-mode case ['>1.0.0', '1.0.1'] is untouched and the ranges suite stays green.

… mode

`minVersion` is documented to return the lowest version that can match a
range, but for a `>X.Y.Z` bound in includePrerelease mode it skipped the
lowest prerelease:

  minVersion('>1.0.0', { includePrerelease: true }) // 1.0.1

`1.0.1-0` also satisfies `>1.0.0` under includePrerelease and is lower than
`1.0.1`, so `1.0.1` is not the minimum. For a `>` comparator that already
carries a prerelease, minVersion already appends `.0` (`>1.0.0-0` ->
`1.0.0-0.0`); the plain `>X.Y.Z` case only did `patch++` and never
considered prereleases, even when they are in scope.

Append the `-0` prerelease after bumping the patch when the range includes
prereleases, so `>1.0.0` yields `1.0.1-0`. Default mode is unchanged
(`>1.0.0` still yields `1.0.1`).
@spokodev
spokodev requested a review from a team as a code owner July 23, 2026 13:31
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.

1 participant