Skip to content

Commit 127a3f7

Browse files
committed
fix: show correct stable versions for patch/minor/major prompt choices on prereleases
Add getNextStableVersion which always produces a stable bump regardless of whether the current version is a prerelease. Use it in the version prompt so patch/minor/major choices correctly display and return stable targets (e.g. 1.0.0) while the suggested/next-prerelease options show the prerelease bump.
1 parent d8d8b70 commit 127a3f7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/core/prompts.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { WorkspacePackage } from "#core/workspace";
22
import type { BumpKind } from "#shared/types";
33
import {
44
getNextPrereleaseVersion,
5+
getNextStableVersion,
56
getNextVersion,
67
getPrereleaseIdentifier,
78
isValidSemver,
@@ -70,9 +71,9 @@ export async function selectVersionPrompt(
7071
...(isCurrentPrerelease
7172
? [{ value: "next-prerelease", title: `next prerelease ${farver.bold(nextDefaultPrerelease)}` }]
7273
: []),
73-
{ value: "patch", title: `patch ${farver.bold(getNextVersion(pkg.version, "patch"))}` },
74-
{ value: "minor", title: `minor ${farver.bold(getNextVersion(pkg.version, "minor"))}` },
75-
{ value: "major", title: `major ${farver.bold(getNextVersion(pkg.version, "major"))}` },
74+
{ value: "patch", title: `patch ${farver.bold(getNextStableVersion(pkg.version, "patch"))}` },
75+
{ value: "minor", title: `minor ${farver.bold(getNextStableVersion(pkg.version, "minor"))}` },
76+
{ value: "major", title: `major ${farver.bold(getNextStableVersion(pkg.version, "major"))}` },
7677
{ value: "prerelease", title: `prerelease ${farver.dim("(choose strategy)")}` },
7778
{ value: "custom", title: "custom" },
7879
];
@@ -175,7 +176,8 @@ export async function selectVersionPrompt(
175176
return prereleaseVersion;
176177
}
177178

178-
return getNextVersion(pkg.version, answers.version as BumpKind);
179+
const stableBump = answers.version as Exclude<BumpKind, "none">;
180+
return getNextStableVersion(pkg.version, stableBump);
179181
}
180182

181183
export async function confirmOverridePrompt(pkg: WorkspacePackage, overrideVersion: string): Promise<"use" | "pick" | null> {

src/operations/semver.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ export function getNextVersion(currentVersion: string, bump: BumpKind): string {
3535
return next;
3636
}
3737

38+
/**
39+
* Like getNextVersion but always produces a stable version, even when
40+
* currentVersion is a prerelease. Use this when the caller explicitly wants
41+
* to promote to a stable release (e.g. patch/minor/major prompt choices).
42+
*/
43+
export function getNextStableVersion(currentVersion: string, bump: Exclude<BumpKind, "none">): string {
44+
if (!isValidSemver(currentVersion)) {
45+
throw new Error(`Cannot bump version for invalid semver: ${currentVersion}`);
46+
}
47+
48+
const next = semver.inc(currentVersion, bump);
49+
if (!next) {
50+
throw new Error(`Failed to bump version ${currentVersion} with bump ${bump}`);
51+
}
52+
53+
return next;
54+
}
55+
3856
export function calculateBumpType(oldVersion: string, newVersion: string): BumpKind {
3957
if (!isValidSemver(oldVersion) || !isValidSemver(newVersion)) {
4058
throw new Error(`Cannot calculate bump type for invalid semver: ${oldVersion} or ${newVersion}`);

0 commit comments

Comments
 (0)