Skip to content

fix: premajor/preminor/prepatch should respect prerelease status - #892

Open
marceli1404 wants to merge 1 commit into
npm:mainfrom
marceli1404:fix/premajor-prerelease-behavior
Open

fix: premajor/preminor/prepatch should respect prerelease status#892
marceli1404 wants to merge 1 commit into
npm:mainfrom
marceli1404:fix/premajor-prerelease-behavior

Conversation

@marceli1404

Copy link
Copy Markdown

Description

Fixes #751

\premajor, \preminor, and \prepatch\ now delegate to their non-pre counterparts (\major/\minor/\patch) first, which correctly handle the case where the version is already a prerelease.

Root Cause

Previously, the pre-* increment operations would unconditionally bump the version number, even when the current version was a prerelease of the same major/minor/patch.

For example:

  • \semver.inc('2.0.0-pre', 'major')\ → '2.0.0'\ (correct: strips prerelease without bumping major)
  • \semver.inc('2.0.0-pre', 'premajor')\ → '3.0.0-0'\ (wrong: should be '2.0.0-0')

Fix

\premajor\ now calls \inc('major')\ (which checks if the version is already at \x.0.0\ with a prerelease before bumping), then \inc('pre'). Same pattern for \preminor\ and \prepatch.

Test Changes

Updated 6 test expectations that reflected the old buggy behavior:

  • \1.2.0-1\ → \prepatch: \1.2.1-0\ → \1.2.0-0\ (consistent with \patch)
  • \1.2.0-dev\ → \preminor: \1.3.0-beta\ → \1.2.0-beta\ (consistent with \minor)
  • \1.2.0-dev\ → \prepatch: \1.2.1-dev\ → \1.2.0-dev\ (consistent with \patch)

All 51 existing tests pass with 100% coverage.

…#751)

premajor, preminor, and prepatch now delegate to their non-pre
counterparts (major/minor/patch) first, which correctly handle the
case where the version is already a prerelease. Previously they
would unconditionally bump the version number, even when the current
version is a prerelease at x.0.0-something.

Behavior change: prepatch on a prerelease no longer bumps patch
(e.g., 1.2.0-1 → prepatch → 1.2.0-0 instead of 1.2.1-0), which
is consistent with how patch strips the prerelease without bumping.
@marceli1404
marceli1404 requested a review from a team as a code owner July 29, 2026 01:08
@marceli1404

Copy link
Copy Markdown
Author

Friendly bump — this fixes #751 where premajor/preminor/prepatch on an already-prerelease version bumped an extra major/minor/patch. Now semver.inc('2.0.0-pre', 'premajor') returns '2.0.0-0', consistent with inc('2.0.0-pre', 'major')'2.0.0'. All 51 tests pass with 100% coverage. Happy to adjust if you'd prefer a different resolution!

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