fix: include prereleases in tilde range lower bound with includePrerelease#878
Open
chatman-media wants to merge 1 commit into
Open
fix: include prereleases in tilde range lower bound with includePrerelease#878chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
…lease
A tilde range like ~1.2 is documented as equivalent to the 1.2.x
x-range (>=1.2.0 <1.3.0-0). With { includePrerelease: true }, the
x-range and caret operators lower-bound at -0 (e.g. 1.2.x and ^1.2.*
become >=1.2.0-0 ...) so prereleases such as 1.2.0-rc match, but the
tilde operator did not, leaving its lower bound at >=1.2.0. This made
~1.2.* inconsistent with both its documented x-range equivalent and
the caret operator.
Apply the same -0 lower-bound suffix used by replaceCaret/replaceXRange
to the open tilde forms (~1, ~1.x, ~1.2, ~1.2.x). Fully-specified
tildes (~1.2.3) and explicit-prerelease tildes (~1.2.3-beta) keep their
exact lower bound, matching caret semantics. Default behavior (without
includePrerelease) is unchanged.
Closes npm#512
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.
Closes #512
Problem
A tilde range like `~1.2` is documented in the README as equivalent to the `1.2.x` x-range:
With `{ includePrerelease: true }`, both the x-range and the caret operator lower-bound their open forms at `-0` (the lowest possible prerelease) so that prereleases like `1.2.0-rc` match. The tilde operator did not, leaving its lower bound at `>=1.2.0`:
This makes `~1.2.*` inconsistent with both its documented x-range equivalent and the caret operator. Reported in #512 (and the same root cause as #510 / #736 discussion around tilde + prerelease).
Fix
`replaceCaret` and `replaceXRange` already compute a lower-bound suffix:
and apply it to their open forms. `replaceTilde` was the only one of the three that did not. This change applies the same suffix to the open tilde forms (`~1`, `~1.x`, `~1.2`, `~1.2.x`).
After the fix, `~1.2.` desugars to `>=1.2.0-0 <1.3.0-0` — identical to the `1.2.` x-range it is documented to equal.
Scope / what is intentionally unchanged
Tests
Added failing-then-passing fixtures:
Full suite (`npm test`) and `eslint` pass.