diff --git a/packages/cli/binding/src/cli.rs b/packages/cli/binding/src/cli.rs index beae924d1c..8cfdc7dc57 100644 --- a/packages/cli/binding/src/cli.rs +++ b/packages/cli/binding/src/cli.rs @@ -551,16 +551,12 @@ impl CommandHandler for VitePlusCommandHandler { &mut self, command: &mut ScriptCommand, ) -> anyhow::Result { - // Intercept both "vp" and "vite" commands in task scripts. - // "vp" is the conventional alias used in vite-plus task configs. - // "vite" must also be intercepted so that `vite test`, `vite build`, etc. - // in task scripts are synthesized in-session rather than spawning a new CLI process. + // Intercept "vp" commands in task scripts so that `vp test`, `vp build`, etc. + // are synthesized in-session rather than spawning a new CLI process. let program = command.program.as_str(); - if program != "vp" && program != "vite" { + if program != "vp" { return Ok(HandledCommand::Verbatim); } - // Parse "vp " using CLIArgs — always use "vp" as the program name - // so clap shows "Usage: vp ..." even if the original command was "vite ..." let cli_args = match CLIArgs::try_parse_from( iter::once("vp").chain(command.args.iter().map(Str::as_str)), ) { diff --git a/packages/cli/snap-tests-global/command-run-script-vite-program/package.json b/packages/cli/snap-tests-global/command-run-script-vite-program/package.json new file mode 100644 index 0000000000..973009ab8a --- /dev/null +++ b/packages/cli/snap-tests-global/command-run-script-vite-program/package.json @@ -0,0 +1,10 @@ +{ + "name": "command-run-script-vite-program", + "version": "1.0.0", + "scripts": { + "dev": "vite", + "dev-help": "vite -h", + "dev-version": "vite --version" + }, + "packageManager": "pnpm@10.19.0" +} diff --git a/packages/cli/snap-tests-global/command-run-script-vite-program/setup-bin.js b/packages/cli/snap-tests-global/command-run-script-vite-program/setup-bin.js new file mode 100644 index 0000000000..60f70aae3e --- /dev/null +++ b/packages/cli/snap-tests-global/command-run-script-vite-program/setup-bin.js @@ -0,0 +1,8 @@ +const fs = require('fs'); +fs.mkdirSync('node_modules/.bin', { recursive: true }); +fs.writeFileSync( + 'node_modules/.bin/vite', + '#!/usr/bin/env node\nconst args = process.argv.slice(2);\nconsole.log(args.length ? "vite " + args.join(" ") : "vite");\n', + { mode: 0o755 }, +); +fs.writeFileSync('node_modules/.bin/vite.cmd', '@node "%~dp0\\vite" %*\n'); diff --git a/packages/cli/snap-tests-global/command-run-script-vite-program/snap.txt b/packages/cli/snap-tests-global/command-run-script-vite-program/snap.txt new file mode 100644 index 0000000000..f7a8868e56 --- /dev/null +++ b/packages/cli/snap-tests-global/command-run-script-vite-program/snap.txt @@ -0,0 +1,21 @@ +> node setup-bin.js +> vp run dev # should run vite binary, not parse as vp subcommand +VITE+ - The Unified Toolchain for the Web + +$ vite ⊘ cache disabled +vite + + +> vp run dev-help # should run vite -h, not parse as vp subcommand +VITE+ - The Unified Toolchain for the Web + +$ vite -h ⊘ cache disabled +vite -h + + +> vp run dev-version # should run vite --version, not parse as vp subcommand +VITE+ - The Unified Toolchain for the Web + +$ vite --version ⊘ cache disabled +vite --version + diff --git a/packages/cli/snap-tests-global/command-run-script-vite-program/steps.json b/packages/cli/snap-tests-global/command-run-script-vite-program/steps.json new file mode 100644 index 0000000000..de312a699f --- /dev/null +++ b/packages/cli/snap-tests-global/command-run-script-vite-program/steps.json @@ -0,0 +1,8 @@ +{ + "commands": [ + { "command": "node setup-bin.js", "ignoreOutput": true }, + "vp run dev # should run vite binary, not parse as vp subcommand", + "vp run dev-help # should run vite -h, not parse as vp subcommand", + "vp run dev-version # should run vite --version, not parse as vp subcommand" + ] +}