Skip to content

fix: do not leapfrog when pre-incrementing an existing prerelease - #957

Open
waw666waw666 wants to merge 1 commit into
npm:mainfrom
waw666waw666:fix/pre-increments-on-prerelease
Open

waw666waw666 wants to merge 1 commit into
npm:mainfrom
waw666waw666:fix/pre-increments-on-prerelease

Conversation

@waw666waw666

Copy link
Copy Markdown

Fixes #751

premajor and preminor always incremented the major/minor component
before adding the prerelease, even when the version was already a
prerelease of that exact release:

semver.inc('2.0.0-pre', 'premajor') // '3.0.0-0', expected '2.0.0-0'
semver.inc('1.2.0-pre', 'preminor') // '1.3.0-0', expected '1.2.0-0'

The non-pre increments already handle this case: major on
2.0.0-pre returns 2.0.0 without bumping, and minor on 1.2.0-5
returns 1.2.0. The pre* variants now mirror those conditions
exactly — premajor only bumps the major when the minor or patch is
non-zero or there is no prerelease, and preminor only bumps the
minor when the patch is non-zero or there is no prerelease.

prepatch is intentionally unchanged: the existing fixtures pin
1.2.0-1 + prepatch to 1.2.1-0, so its "next patch as a
prerelease" semantics are preserved.

One existing fixture is corrected as part of this fix:
1.2.0-dev + preminor previously expected 1.3.0-beta, which is
the leapfrogging behaviour reported in #751 (minor on the same
input returns 1.2.0); it now expects 1.2.0-beta.

New increment fixtures cover already-at-target prereleases for both
premajor and preminor, with and without an explicit identifier.
They fail without this change and pass with it. The full tap suite
passes with 100% coverage, and eslint is clean on the changed files.

@waw666waw666
waw666waw666 requested a review from a team as a code owner November 22, 2026 00:59
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] inc premajor, preminor, and prepatch do the wrong thing if the version is already a pre-release.

1 participant