Skip to content

Commit ef84aa8

Browse files
committed
fix: parse the current 'vp vX' --version output for the version output
vp >= 0.2 prints `vp v0.2.0` instead of the old `Global: v0.2.0`, so the stale regex made the action's `version` output (and state) resolve to "unknown". Extract parsing into parseInstalledVpVersion, support both formats, and unit-test it so a future format change can't silently regress.
1 parent 7c674c8 commit ef84aa8

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

dist/index.mjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
tryResolveVitePlusVersionFromProject,
1515
} from "./version-file.js";
1616
import { configAuthentication, propagateProjectNpmrcAuth } from "./auth.js";
17-
import { getConfiguredProjectDir } from "./utils.js";
17+
import { getConfiguredProjectDir, parseInstalledVpVersion } from "./utils.js";
1818

1919
async function runMain(inputs: Inputs): Promise<void> {
2020
// Mark that post action should run
@@ -85,9 +85,8 @@ async function printViteVersion(cwd: string): Promise<void> {
8585
const versionOutput = result.stdout.trim();
8686
info(versionOutput);
8787

88-
// Extract global version for output (e.g., "- Global: v0.0.0" -> "0.0.0")
89-
const globalMatch = versionOutput.match(/Global:\s*v?([\d.]+[^\s]*)/i);
90-
const version = globalMatch?.[1] || "unknown";
88+
// Extract the installed global version for output (e.g. "vp v0.2.0" -> "0.2.0")
89+
const version = parseInstalledVpVersion(versionOutput);
9190
saveState(State.InstalledVersion, version);
9291
setOutput(Outputs.Version, version);
9392
} catch (error) {

src/utils.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getConfiguredProjectDir,
88
getCacheDirectories,
99
getInstallCwd,
10+
parseInstalledVpVersion,
1011
resolvePath,
1112
} from "./utils.js";
1213
import { LockFileType } from "./types.js";
@@ -470,3 +471,35 @@ describe("getInstallCwd", () => {
470471
expect(getInstallCwd(join(mockWorkspace, "web"), "/custom/path/app")).toBe("/custom/path/app");
471472
});
472473
});
474+
475+
describe("parseInstalledVpVersion", () => {
476+
it("parses the current 'vp vX.Y.Z' format", () => {
477+
const output = [
478+
"vp v0.2.0",
479+
"",
480+
"Local vite-plus:",
481+
" vite-plus Not found",
482+
"",
483+
"Environment:",
484+
" Node.js v24.18.0",
485+
].join("\n");
486+
487+
expect(parseInstalledVpVersion(output)).toBe("0.2.0");
488+
});
489+
490+
it("parses a prerelease version", () => {
491+
expect(parseInstalledVpVersion("vp v0.2.0-beta.1\n")).toBe("0.2.0-beta.1");
492+
});
493+
494+
it("does not mistake the Node.js line for the vp version", () => {
495+
expect(parseInstalledVpVersion("vp v0.2.1\n Node.js v24.18.0")).toBe("0.2.1");
496+
});
497+
498+
it("parses the legacy 'Global: vX.Y.Z' format", () => {
499+
expect(parseInstalledVpVersion("- Global: v0.1.20\n- Local: v0.1.20")).toBe("0.1.20");
500+
});
501+
502+
it("returns 'unknown' when no version can be parsed", () => {
503+
expect(parseInstalledVpVersion("no version here")).toBe("unknown");
504+
});
505+
});

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ export function getVitePlusHome(): string {
1212
return join(home || homedir(), ".vite-plus");
1313
}
1414

15+
/**
16+
* Extract the installed global Vite+ version from `vp --version` output.
17+
*
18+
* vp >= 0.2 prints the global version as `vp v0.2.0` on the first line; older
19+
* builds printed `- Global: v0.2.0`. Support both so the reported `version`
20+
* output stays correct across vp releases (a lone anchored regex silently broke
21+
* when the format changed). Returns "unknown" when neither shape matches.
22+
*/
23+
export function parseInstalledVpVersion(versionOutput: string): string {
24+
const match =
25+
versionOutput.match(/^\s*vp\s+v?(\d[^\s]*)/im) ??
26+
versionOutput.match(/Global:\s*v?(\d[^\s]*)/i);
27+
return match?.[1] ?? "unknown";
28+
}
29+
1530
export function getWorkspaceDir(): string {
1631
return process.env.GITHUB_WORKSPACE || process.cwd();
1732
}

0 commit comments

Comments
 (0)