From 4ab660b2d1a471a978eb75a583336f00d9010843 Mon Sep 17 00:00:00 2001 From: JongKyung Lee Date: Thu, 22 Oct 2026 15:35:59 +0900 Subject: [PATCH] fix(cli): support -g for vp toolchain --global --- .../fixtures/command_toolchain/snapshots.toml | 1 + .../snapshots/toolchain_json.md | 107 ++++++++++++++++++ crates/vp_global_cli/src/cli.rs | 16 ++- docs/guide/upgrade.md | 2 +- packages/cli/binding/src/cli/types.rs | 2 +- rfcs/toolchain-command.md | 2 +- 6 files changed, 126 insertions(+), 4 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots.toml index bfd7114acc..8a86983094 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots.toml @@ -24,6 +24,7 @@ name = "toolchain_json" vp = "global" steps = [ { argv = ["vp", "toolchain", "vite", "--json", "--global"], tty = false, comment = "JSON contains one node per ID and no CLI header" }, + { argv = ["vp", "toolchain", "vite", "--json", "-g"], tty = false, comment = "the short global flag supports filters and JSON output" }, ] [[case]] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots/toolchain_json.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots/toolchain_json.md index 90e84fddd7..337dfe3778 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots/toolchain_json.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_toolchain/snapshots/toolchain_json.md @@ -106,3 +106,110 @@ JSON contains one node per ID and no CLI header ] } ``` + +## `vp toolchain vite --json -g` + +the short global flag supports filters and JSON output + +``` +{ + "schemaVersion": 1, + "source": { + "scope": "global", + "path": "/.vite-plus/current/node_modules/vite-plus", + "vitePlusVersion": "" + }, + "nodes": [ + { + "id": "vite-plus", + "name": "vite-plus", + "version": "", + "kind": "package", + "delivery": [ + "dependency" + ], + "aliases": [] + }, + { + "id": "vite-plus-core", + "name": "@voidzero-dev/vite-plus-core", + "version": "", + "kind": "package", + "delivery": [ + "dependency" + ], + "aliases": [ + "vite-plus-core" + ] + }, + { + "id": "vite", + "name": "vite", + "version": "", + "kind": "tool", + "delivery": [ + "bundled" + ], + "aliases": [] + }, + { + "id": "rolldown", + "name": "rolldown", + "version": "", + "kind": "tool", + "delivery": [ + "bundled", + "compiled" + ], + "aliases": [] + }, + { + "id": "oxc", + "name": "oxc", + "version": "", + "kind": "engine", + "delivery": [ + "compiled" + ], + "aliases": [] + }, + { + "id": "oxc-resolver", + "name": "oxc-resolver", + "version": "", + "kind": "engine", + "delivery": [ + "compiled" + ], + "aliases": [] + } + ], + "edges": [ + { + "from": "vite-plus", + "to": "vite-plus-core", + "relationship": "depends-on" + }, + { + "from": "vite-plus-core", + "to": "vite", + "relationship": "bundles" + }, + { + "from": "vite", + "to": "rolldown", + "relationship": "uses" + }, + { + "from": "rolldown", + "to": "oxc", + "relationship": "compiles" + }, + { + "from": "rolldown", + "to": "oxc-resolver", + "relationship": "compiles" + } + ] +} +``` diff --git a/crates/vp_global_cli/src/cli.rs b/crates/vp_global_cli/src/cli.rs index 75349fca90..c4ba970c5d 100644 --- a/crates/vp_global_cli/src/cli.rs +++ b/crates/vp_global_cli/src/cli.rs @@ -220,7 +220,7 @@ pub enum Commands { json: bool, /// Use the global Vite+ toolchain - #[arg(long)] + #[arg(short = 'g', long)] global: bool, }, @@ -1344,6 +1344,20 @@ mod tests { assert_eq!(raw_subcommand(&argv(&["vp", "--version"])), None); } + #[test] + fn parses_toolchain_global_flags() { + for flag in ["--global", "-g"] { + let parsed = try_parse_args_from(argv(&["vp", "toolchain", "vite", "--json", flag])) + .expect("toolchain global flag should parse"); + let Some(Commands::Toolchain { tools, json, global }) = parsed.command else { + panic!("expected toolchain command"); + }; + assert_eq!(tools, vec!["vite"]); + assert!(json); + assert!(global); + } + } + #[test] fn parses_sync_versions_as_machine_readable_global_command() { let parsed = try_parse_args_from(argv(&["vp", "sync-versions", "--json"])) diff --git a/docs/guide/upgrade.md b/docs/guide/upgrade.md index c775b2d918..9deb0c8a59 100644 --- a/docs/guide/upgrade.md +++ b/docs/guide/upgrade.md @@ -22,7 +22,7 @@ vp toolchain vite rolldown oxc vp toolchain --json ``` -The command uses the local `vite-plus` package when the project has one. Use `--global` to show the release for the global `vp` command: +The command uses the local `vite-plus` package when the project has one. Use `--global` or `-g` to show the release for the global `vp` command: ```bash vp toolchain --global diff --git a/packages/cli/binding/src/cli/types.rs b/packages/cli/binding/src/cli/types.rs index 6fbd6ddcb9..14bf05a5fa 100644 --- a/packages/cli/binding/src/cli/types.rs +++ b/packages/cli/binding/src/cli/types.rs @@ -118,7 +118,7 @@ pub struct ToolchainArgs { pub json: bool, /// Use the global Vite+ toolchain - #[arg(long)] + #[arg(short = 'g', long)] pub global: bool, } diff --git a/rfcs/toolchain-command.md b/rfcs/toolchain-command.md index 5680dba125..7a407cccbc 100644 --- a/rfcs/toolchain-command.md +++ b/rfcs/toolchain-command.md @@ -108,7 +108,7 @@ Arguments: Options: --json Print the graph as JSON - --global Use the global Vite+ toolchain + -g, --global Use the global Vite+ toolchain -h, --help Print help ```