Skip to content

Commit e2d9b14

Browse files
committed
fix: stop intercepting vite as a vp command in task scripts
`VitePlusCommandHandler` was intercepting both `vp` and `vite` program names in task scripts. This caused `vp run dev` to fail with "Invalid vite task command" when a package.json script used bare `vite` (e.g. `"dev": "vite"`), because `vite` is a separate tool, not a vp alias. Only intercept `vp` commands now; `vite` runs verbatim as an external process. Closes #1176
1 parent e4862b2 commit e2d9b14

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,12 @@ impl CommandHandler for VitePlusCommandHandler {
551551
&mut self,
552552
command: &mut ScriptCommand,
553553
) -> anyhow::Result<HandledCommand> {
554-
// Intercept both "vp" and "vite" commands in task scripts.
555-
// "vp" is the conventional alias used in vite-plus task configs.
556-
// "vite" must also be intercepted so that `vite test`, `vite build`, etc.
557-
// in task scripts are synthesized in-session rather than spawning a new CLI process.
554+
// Only intercept "vp" commands in task scripts.
555+
// "vite" is a separate tool and should always run verbatim.
558556
let program = command.program.as_str();
559-
if program != "vp" && program != "vite" {
557+
if program != "vp" {
560558
return Ok(HandledCommand::Verbatim);
561559
}
562-
// Parse "vp <args>" using CLIArgs — always use "vp" as the program name
563-
// so clap shows "Usage: vp ..." even if the original command was "vite ..."
564560
let cli_args = match CLIArgs::try_parse_from(
565561
iter::once("vp").chain(command.args.iter().map(Str::as_str)),
566562
) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "command-run-script-vite-program",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "vite",
6+
"dev-help": "vite -h",
7+
"dev-version": "vite --version"
8+
},
9+
"packageManager": "pnpm@10.19.0"
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const fs = require('fs');
2+
fs.mkdirSync('node_modules/.bin', { recursive: true });
3+
fs.writeFileSync(
4+
'node_modules/.bin/vite',
5+
'#!/usr/bin/env node\nconst args = process.argv.slice(2);\nconsole.log(args.length ? "vite " + args.join(" ") : "vite");\n',
6+
{ mode: 0o755 },
7+
);
8+
fs.writeFileSync('node_modules/.bin/vite.cmd', '@node "%~dp0\\vite" %*\n');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
> node setup-bin.js
2+
> vp run dev # should run vite binary, not parse as vp subcommand
3+
VITE+ - The Unified Toolchain for the Web
4+
5+
$ vite ⊘ cache disabled
6+
vite
7+
8+
9+
> vp run dev-help # should run vite -h, not parse as vp subcommand
10+
VITE+ - The Unified Toolchain for the Web
11+
12+
$ vite -h ⊘ cache disabled
13+
vite -h
14+
15+
16+
> vp run dev-version # should run vite --version, not parse as vp subcommand
17+
VITE+ - The Unified Toolchain for the Web
18+
19+
$ vite --version ⊘ cache disabled
20+
vite --version
21+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
{ "command": "node setup-bin.js", "ignoreOutput": true },
4+
"vp run dev # should run vite binary, not parse as vp subcommand",
5+
"vp run dev-help # should run vite -h, not parse as vp subcommand",
6+
"vp run dev-version # should run vite --version, not parse as vp subcommand"
7+
]
8+
}

0 commit comments

Comments
 (0)