Skip to content

Add include prerelease flag#299

Merged
piotrooo merged 20 commits intosemver4j:mainfrom
aqding:ading/prerelease-flag
Jun 20, 2025
Merged

Add include prerelease flag#299
piotrooo merged 20 commits intosemver4j:mainfrom
aqding:ading/prerelease-flag

Conversation

@aqding
Copy link
Copy Markdown
Contributor

@aqding aqding commented Oct 10, 2024

Fixes #29

Adds the functionality equivalent of the --include-prerelease flag that will allow for including prerelease versions by default defined in the node semver repo here . The feature is accessible through a new method Semver.satisfies(String range, boolean includePrerelease). All public methods will have include-prerelease default to false to maintain backwards compatibility.

Some of the processors are updated to be able to handle advanced ranges properly, as discussed in this issue. Architecturally, Processor is changed from an interface to an abstract class to better handle some common state.

To include proper support for --include-prerelease, we need to add some additional logic for appending a prerelease identifier to certain ranges. For example, by default, 1.x gets translated to >=1.0.0 <2.0.0. If we just used this same exact logic when considering prereleases, it will not work — 1.0.0-beta will not satisfy the range, and 2.0.0-beta will. So the actual correct range would then be >=1.0.0-0 <2.0.0-0, where 0 is the lowest possible prerelease identifier.
However, note that we cannot just change the range to always be >-1.0.0-0 <2.0.0-0, because that would mean anything with a prerelease identifier would satisfy the range, even if --include-prerelease is not set. This has to do with how prerelease versions interact with comparators, as defined here.

Something else that might be noticed is that, with --include-prerelease, ^1.2.3 translates to >=1.2.3 <2.0.0-0, whereas ^1.2 translates to >=1.2.3-0 <2.0.0-0. This has to do with how x ranges are defined. Specifically, the definition is that:

  • A missing patch version will be a range that matches the major and minor version
  • A missing minor version will be a range that matches the major version

By this logic then, the lowest version that satisfies 1.2.3 is just 1.2.3 (it just so happens to be the only version that satisfies that range, since a range that is a version is just satisfied by the version), while the lowest version that satisfies 1.2 is 1.2.0-0. This is why in Tilde, Caret, and Hyphen ranges, we have the lower bound of the range use the 0 prerelease identifier if a minor or patch version is not specified.

@piotrooo piotrooo added the enhancement New feature or request label Oct 18, 2024
@piotrooo piotrooo changed the title add include prerelease flag Add include prerelease flag Oct 18, 2024
@piotrooo
Copy link
Copy Markdown
Member

Thanks for this contribution! I'll try to look at it in my spare time.

@aqding
Copy link
Copy Markdown
Contributor Author

aqding commented Nov 7, 2024

Hey @piotrooo, this should be ready for review now. Tests are passing and I've updated the PR description with the logic/explanation for the new behavior

@marshallavail
Copy link
Copy Markdown

marshallavail commented Jan 21, 2025

@piotrooo - Hi, just bumping this PR. I am also interested in this feature.

@piotrooo
Copy link
Copy Markdown
Member

@marshallavail, waiting for merge #317. Once it's merged, this PR will need to be aligned. This change requires a separate version.

@aqding
Copy link
Copy Markdown
Contributor Author

aqding commented Jan 31, 2025

@piotrooo, I've merged the changes from main into the branch — we should be good to go now

@sschuberth
Copy link
Copy Markdown
Contributor

@piotrooo, can be move forward with this to unblock my #353?

@piotrooo
Copy link
Copy Markdown
Member

@sschuberth I'll try my best to move this PR forward.

@piotrooo piotrooo force-pushed the ading/prerelease-flag branch from ed5f150 to 18a4ebe Compare June 19, 2025 22:21
@piotrooo
Copy link
Copy Markdown
Member

@aqding First of all, sorry 🙏 for the long wait on the review and feedback.
Second, thank you for the huge amount of work you put into this feature 🙌
I did a bit of refactoring on your code — feel free to check it out if you're interested.

@sschuberth I'm going to merge this into main, but I won't release a new version until you finish your PR.

@piotrooo piotrooo merged commit 5598716 into semver4j:main Jun 20, 2025
5 checks passed
@sschuberth
Copy link
Copy Markdown
Contributor

@sschuberth I'm going to merge this into main, but I won't release a new version until you finish your PR.

Thanks, I'll rebase my PR.

Comment thread pom.xml
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<version>2.22.2</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this downgraded @piotrooo? This now causes

org.junit.platform.commons.JUnitException: OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path.

for me. I'll upgrade it again as part of my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IncludePrerelease flag feature

4 participants