From cef4fccd54827897df84c35fb7a8fc5f689578e2 Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 14:25:07 +0800 Subject: [PATCH 1/6] fix(cli): error on `vp install -g` with no package names `--global` was silently ignored when no packages were provided, causing a regular workspace install instead. Now emits an actionable error and exits with code 1. Co-Authored-By: Claude Sonnet 4.6 --- crates/vite_global_cli/src/cli.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/vite_global_cli/src/cli.rs b/crates/vite_global_cli/src/cli.rs index 96423ce367..ba3b3145ed 100644 --- a/crates/vite_global_cli/src/cli.rs +++ b/crates/vite_global_cli/src/cli.rs @@ -1684,6 +1684,15 @@ pub async fn run_command_with_options( .await; } + // No packages provided — reject if --global was passed + if global { + vite_shared::output::error( + "`vp install -g` requires at least one package name.\n\ + To reinstall all globally installed packages, use `vp update -g`.", + ); + return Ok(exit_status(1)); + } + // No packages provided, run regular install let options = InstallCommandOptions { prod, From a9f373a6ae91e1a64614554959444ee9e3914d2c Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 14:25:11 +0800 Subject: [PATCH 2/6] test(snap): add global install no-args error snap test Verifies that `vp install -g` without package names exits with code 1 and prints an actionable error message. Co-Authored-By: Claude Sonnet 4.6 --- .../snap-tests-global/command-install-g-no-args/package.json | 3 +++ .../cli/snap-tests-global/command-install-g-no-args/snap.txt | 3 +++ .../snap-tests-global/command-install-g-no-args/steps.json | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 packages/cli/snap-tests-global/command-install-g-no-args/package.json create mode 100644 packages/cli/snap-tests-global/command-install-g-no-args/snap.txt create mode 100644 packages/cli/snap-tests-global/command-install-g-no-args/steps.json diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/package.json b/packages/cli/snap-tests-global/command-install-g-no-args/package.json new file mode 100644 index 0000000000..b337dd1ac0 --- /dev/null +++ b/packages/cli/snap-tests-global/command-install-g-no-args/package.json @@ -0,0 +1,3 @@ +{ + "name": "command-install-g-no-args" +} diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/snap.txt b/packages/cli/snap-tests-global/command-install-g-no-args/snap.txt new file mode 100644 index 0000000000..67dfd6319f --- /dev/null +++ b/packages/cli/snap-tests-global/command-install-g-no-args/snap.txt @@ -0,0 +1,3 @@ +[1]> vp install -g # No packages provided — should error and not run workspace install +error: `vp install -g` requires at least one package name. +To reinstall all globally installed packages, use `vp update -g`. diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/steps.json b/packages/cli/snap-tests-global/command-install-g-no-args/steps.json new file mode 100644 index 0000000000..6336d1fcc5 --- /dev/null +++ b/packages/cli/snap-tests-global/command-install-g-no-args/steps.json @@ -0,0 +1,5 @@ +{ + "ignoredPlatforms": ["win32"], + "env": {}, + "commands": ["vp install -g # No packages provided — should error and not run workspace install"] +} From e7cb1b114459d48c27198bb647c41de766e6cd48 Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 14:34:19 +0800 Subject: [PATCH 3/6] test(snap): remove unnecessary win32 exclusion from install-g-no-args test The guard is pure Rust logic with no platform-specific behavior. Co-Authored-By: Claude Sonnet 4.6 --- .../cli/snap-tests-global/command-install-g-no-args/steps.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/steps.json b/packages/cli/snap-tests-global/command-install-g-no-args/steps.json index 6336d1fcc5..09876551b0 100644 --- a/packages/cli/snap-tests-global/command-install-g-no-args/steps.json +++ b/packages/cli/snap-tests-global/command-install-g-no-args/steps.json @@ -1,5 +1,4 @@ { - "ignoredPlatforms": ["win32"], "env": {}, "commands": ["vp install -g # No packages provided — should error and not run workspace install"] } From cecb5208c2069e0d00b269fd084e4bd648e96c77 Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 14:41:37 +0800 Subject: [PATCH 4/6] chore: adjust --- .../snap-tests-global/command-install-g-no-args/steps.json | 4 ---- .../package.json | 0 .../snap.txt | 2 +- .../command-install-globally-no-args/steps.json | 4 ++++ 4 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 packages/cli/snap-tests-global/command-install-g-no-args/steps.json rename packages/cli/snap-tests-global/{command-install-g-no-args => command-install-globally-no-args}/package.json (100%) rename packages/cli/snap-tests-global/{command-install-g-no-args => command-install-globally-no-args}/snap.txt (58%) create mode 100644 packages/cli/snap-tests-global/command-install-globally-no-args/steps.json diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/steps.json b/packages/cli/snap-tests-global/command-install-g-no-args/steps.json deleted file mode 100644 index 09876551b0..0000000000 --- a/packages/cli/snap-tests-global/command-install-g-no-args/steps.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "env": {}, - "commands": ["vp install -g # No packages provided — should error and not run workspace install"] -} diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/package.json b/packages/cli/snap-tests-global/command-install-globally-no-args/package.json similarity index 100% rename from packages/cli/snap-tests-global/command-install-g-no-args/package.json rename to packages/cli/snap-tests-global/command-install-globally-no-args/package.json diff --git a/packages/cli/snap-tests-global/command-install-g-no-args/snap.txt b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt similarity index 58% rename from packages/cli/snap-tests-global/command-install-g-no-args/snap.txt rename to packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt index 67dfd6319f..aedfcf2997 100644 --- a/packages/cli/snap-tests-global/command-install-g-no-args/snap.txt +++ b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt @@ -1,3 +1,3 @@ -[1]> vp install -g # No packages provided — should error and not run workspace install +[1]> vp install -g # Should error when no packages provided error: `vp install -g` requires at least one package name. To reinstall all globally installed packages, use `vp update -g`. diff --git a/packages/cli/snap-tests-global/command-install-globally-no-args/steps.json b/packages/cli/snap-tests-global/command-install-globally-no-args/steps.json new file mode 100644 index 0000000000..8d3374a47b --- /dev/null +++ b/packages/cli/snap-tests-global/command-install-globally-no-args/steps.json @@ -0,0 +1,4 @@ +{ + "env": {}, + "commands": ["vp install -g # Should error when no packages provided"] +} From 8e50922242956a627757e0a8b2104dc6289ce4de Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 14:45:56 +0800 Subject: [PATCH 5/6] adjust clap config --- crates/vite_global_cli/src/cli.rs | 13 ++----------- .../snap-tests-global/cli-helper-message/snap.txt | 3 +-- .../command-install-globally-no-args/snap.txt | 8 ++++++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/vite_global_cli/src/cli.rs b/crates/vite_global_cli/src/cli.rs index ba3b3145ed..df1eec770a 100644 --- a/crates/vite_global_cli/src/cli.rs +++ b/crates/vite_global_cli/src/cli.rs @@ -145,8 +145,8 @@ pub enum Commands { #[arg(long)] save_catalog: bool, - /// Install globally (only when adding packages) - #[arg(short = 'g', long)] + /// Install globally (requires package names) + #[arg(short = 'g', long, requires = "packages")] global: bool, /// Node.js version to use for global installation (only with -g) @@ -1684,15 +1684,6 @@ pub async fn run_command_with_options( .await; } - // No packages provided — reject if --global was passed - if global { - vite_shared::output::error( - "`vp install -g` requires at least one package name.\n\ - To reinstall all globally installed packages, use `vp update -g`.", - ); - return Ok(exit_status(1)); - } - // No packages provided, run regular install let options = InstallCommandOptions { prod, diff --git a/packages/cli/snap-tests-global/cli-helper-message/snap.txt b/packages/cli/snap-tests-global/cli-helper-message/snap.txt index f5a046f346..2ea8db26e7 100644 --- a/packages/cli/snap-tests-global/cli-helper-message/snap.txt +++ b/packages/cli/snap-tests-global/cli-helper-message/snap.txt @@ -103,7 +103,7 @@ Options: --save-peer Save to peerDependencies (only when adding packages) -O, --save-optional Save to optionalDependencies (only when adding packages) --save-catalog Save the new dependency to the default catalog (only when adding packages) - -g, --global Install globally (only when adding packages) + -g, --global Install globally (requires package names) --node Node.js version to use for global installation (only with -g) -h, --help Print help @@ -413,4 +413,3 @@ Options: -h, --help Print help Documentation: https://viteplus.dev/guide/upgrade - diff --git a/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt index aedfcf2997..8f5e9cd7f6 100644 --- a/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt +++ b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt @@ -1,3 +1,7 @@ [1]> vp install -g # Should error when no packages provided -error: `vp install -g` requires at least one package name. -To reinstall all globally installed packages, use `vp update -g`. +error: the following required arguments were not provided: + ... + +Usage: vp install --global ... [-- ...] + +For more information, try '--help'. From 5d7c40e0c8406a6b26df6bc7af790a361d31fb36 Mon Sep 17 00:00:00 2001 From: Liang Mi Date: Sat, 25 Apr 2026 15:05:41 +0800 Subject: [PATCH 6/6] fix snapshots --- packages/cli/snap-tests-global/cli-helper-message/snap.txt | 1 + .../snap-tests-global/command-install-globally-no-args/snap.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/snap-tests-global/cli-helper-message/snap.txt b/packages/cli/snap-tests-global/cli-helper-message/snap.txt index 2ea8db26e7..62ef3c4a48 100644 --- a/packages/cli/snap-tests-global/cli-helper-message/snap.txt +++ b/packages/cli/snap-tests-global/cli-helper-message/snap.txt @@ -413,3 +413,4 @@ Options: -h, --help Print help Documentation: https://viteplus.dev/guide/upgrade + diff --git a/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt index 8f5e9cd7f6..dee0a0ad54 100644 --- a/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt +++ b/packages/cli/snap-tests-global/command-install-globally-no-args/snap.txt @@ -1,4 +1,4 @@ -[1]> vp install -g # Should error when no packages provided +[2]> vp install -g # Should error when no packages provided error: the following required arguments were not provided: ...