Skip to content

Commit e4b2a52

Browse files
fengmk2claude
andcommitted
refactor: print vite version at end of runMain
Move version printing from installVitePlus to the end of runMain, after runViteInstall completes. Print the multi-line vite --version output directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4a0bd0e commit e4b2a52

File tree

3 files changed

+50
-61
lines changed

3 files changed

+50
-61
lines changed

dist/index.mjs

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

src/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { saveState, getState, setFailed } from "@actions/core";
1+
import { saveState, getState, setFailed, info, setOutput, warning } from "@actions/core";
2+
import { getExecOutput } from "@actions/exec";
23
import { getInputs } from "./inputs.js";
34
import { installVitePlus } from "./install-viteplus.js";
45
import { runViteInstall } from "./run-install.js";
56
import { restoreCache } from "./cache-restore.js";
67
import { saveCache } from "./cache-save.js";
7-
import { State } from "./types.js";
8+
import { State, Outputs } from "./types.js";
89
import type { Inputs } from "./types.js";
910

1011
async function runMain(inputs: Inputs): Promise<void> {
@@ -23,6 +24,26 @@ async function runMain(inputs: Inputs): Promise<void> {
2324
if (inputs.runInstall.length > 0) {
2425
await runViteInstall(inputs);
2526
}
27+
28+
// Print version info at the end
29+
await printViteVersion();
30+
}
31+
32+
async function printViteVersion(): Promise<void> {
33+
try {
34+
const result = await getExecOutput("vite", ["--version"], { silent: true });
35+
const versionOutput = result.stdout.trim();
36+
info(versionOutput);
37+
38+
// Extract global version for output (e.g., "- Global: v0.0.0" -> "0.0.0")
39+
const globalMatch = versionOutput.match(/Global:\s*v?([\d.]+[^\s]*)/i);
40+
const version = globalMatch?.[1] || "unknown";
41+
saveState(State.InstalledVersion, version);
42+
setOutput(Outputs.Version, version);
43+
} catch (error) {
44+
warning(`Could not get vite version: ${error}`);
45+
setOutput(Outputs.Version, "unknown");
46+
}
2647
}
2748

2849
async function runPost(inputs: Inputs): Promise<void> {

src/install-viteplus.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { info, debug, warning, saveState, setOutput, addPath } from "@actions/core";
1+
import { info, debug, warning, addPath } from "@actions/core";
22
import { exec, getExecOutput } from "@actions/exec";
33
import type { Inputs } from "./types.js";
4-
import { PACKAGE_NAME, GITHUB_REGISTRY, State, Outputs } from "./types.js";
4+
import { PACKAGE_NAME, GITHUB_REGISTRY } from "./types.js";
55

66
export async function installVitePlus(inputs: Inputs): Promise<void> {
77
const { version, registry, githubToken } = inputs;
@@ -52,42 +52,10 @@ export async function installVitePlus(inputs: Inputs): Promise<void> {
5252
throw new Error(`Failed to install ${PACKAGE_NAME}. Exit code: ${exitCode}`);
5353
}
5454

55-
// Verify installation and get version
56-
const installedVersion = await getInstalledVersion();
57-
info(`Successfully installed ${PACKAGE_NAME}@${installedVersion}`);
58-
59-
// Save state for outputs
60-
saveState(State.InstalledVersion, installedVersion);
61-
setOutput(Outputs.Version, installedVersion);
62-
6355
// Ensure global bin is in PATH
6456
await ensureGlobalBinInPath();
6557
}
6658

67-
async function getInstalledVersion(): Promise<string> {
68-
try {
69-
const result = await getExecOutput("vite", ["--version"], {
70-
silent: true,
71-
});
72-
return result.stdout.trim();
73-
} catch {
74-
// Fallback: check npm list
75-
try {
76-
const result = await getExecOutput(
77-
"npm",
78-
["list", "-g", PACKAGE_NAME, "--depth=0", "--json"],
79-
{ silent: true },
80-
);
81-
const data = JSON.parse(result.stdout) as {
82-
dependencies?: Record<string, { version?: string }>;
83-
};
84-
return data.dependencies?.[PACKAGE_NAME]?.version || "unknown";
85-
} catch {
86-
return "unknown";
87-
}
88-
}
89-
}
90-
9159
async function ensureGlobalBinInPath(): Promise<void> {
9260
try {
9361
// Use 'npm config get prefix' instead of deprecated 'npm bin -g'

0 commit comments

Comments
 (0)