fix: minVersion returns the true minimum for > in includePrerelease mode#890
Open
spokodev wants to merge 1 commit into
Open
fix: minVersion returns the true minimum for > in includePrerelease mode#890spokodev wants to merge 1 commit into
> in includePrerelease mode#890spokodev wants to merge 1 commit into
Conversation
… 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`).
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.
What
minVersionreturns "the lowest version that can possibly match the given range", but for a>X.Y.Zbound inincludePrereleasemode it skips the lowest prerelease of the next version:1.0.1-0also satisfies>1.0.0underincludePrereleaseand is lower than1.0.1:so
1.0.1is not the minimum.Root cause
For a
>comparator that already carries a prerelease,minVersionappends.0to reach the lowest prerelease (>1.0.0-0→1.0.0-0.0). The plain>X.Y.Zbranch only didpatch++and never considered prereleases — even whenincludePrereleaseputs them in scope.Fix
After bumping the patch for a prerelease-less
>bound, append the-0prerelease when the range includes prereleases, so>1.0.0yields1.0.1-0. Default (non-includePrerelease) mode is unchanged —>1.0.0still yields1.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 onmainand pass with the fix; the existing default-mode case['>1.0.0', '1.0.1']is untouched and the ranges suite stays green.