File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
1414 tryResolveVitePlusVersionFromProject ,
1515} from "./version-file.js" ;
1616import { configAuthentication , propagateProjectNpmrcAuth } from "./auth.js" ;
17- import { getConfiguredProjectDir } from "./utils.js" ;
17+ import { getConfiguredProjectDir , parseInstalledVpVersion } from "./utils.js" ;
1818
1919async 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 ( / G l o b a l : \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 ) {
Original file line number Diff line number Diff line change 77 getConfiguredProjectDir ,
88 getCacheDirectories ,
99 getInstallCwd ,
10+ parseInstalledVpVersion ,
1011 resolvePath ,
1112} from "./utils.js" ;
1213import { 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+ } ) ;
Original file line number Diff line number Diff 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 * v p \s + v ? ( \d [ ^ \s ] * ) / im) ??
26+ versionOutput . match ( / G l o b a l : \s * v ? ( \d [ ^ \s ] * ) / i) ;
27+ return match ?. [ 1 ] ?? "unknown" ;
28+ }
29+
1530export function getWorkspaceDir ( ) : string {
1631 return process . env . GITHUB_WORKSPACE || process . cwd ( ) ;
1732}
You can’t perform that action at this time.
0 commit comments