Skip to content

Commit e9ef42c

Browse files
committed
feat: intercept vpr commands in task scripts for in-session synthesis
`vpr` in package.json scripts (e.g. `"ready": "vpr hello && vpr dev"`) is now expanded to `vp run` and synthesized in-session, avoiding unnecessary process spawns. Closes #1176
1 parent 110f3c9 commit e9ef42c

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,19 @@ impl CommandHandler for VitePlusCommandHandler {
551551
&mut self,
552552
command: &mut ScriptCommand,
553553
) -> anyhow::Result<HandledCommand> {
554-
// Intercept "vp" commands in task scripts so that `vp test`, `vp build`, etc.
555-
// are synthesized in-session rather than spawning a new CLI process.
554+
// Intercept "vp" and "vpr" commands in task scripts so that `vp test`, `vp build`,
555+
// `vpr build`, etc. are synthesized in-session rather than spawning a new CLI process.
556556
let program = command.program.as_str();
557-
if program != "vp" {
557+
if program != "vp" && program != "vpr" {
558558
return Ok(HandledCommand::Verbatim);
559559
}
560+
// "vpr <args>" is shorthand for "vp run <args>", so prepend "run" for parsing.
560561
let cli_args = match CLIArgs::try_parse_from(
561-
iter::once("vp").chain(command.args.iter().map(Str::as_str)),
562+
iter::once("vp").chain(
563+
if program == "vpr" { Some("run") } else { None }
564+
.into_iter()
565+
.chain(command.args.iter().map(Str::as_str)),
566+
),
562567
) {
563568
Ok(args) => args,
564569
Err(err) if err.kind() == ErrorKind::InvalidSubcommand => {

packages/cli/snap-tests-global/command-run-script-vite-program/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"scripts": {
55
"dev": "vite",
66
"dev-help": "vite -h",
7-
"dev-version": "vite --version"
7+
"dev-version": "vite --version",
8+
"hello": "echo hello from script",
9+
"hello-vpr": "vpr hello",
10+
"ready": "vpr hello-vpr && vpr dev-version"
811
},
912
"packageManager": "pnpm@10.19.0"
1013
}

packages/cli/snap-tests-global/command-run-script-vite-program/snap.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ VITE+ - The Unified Toolchain for the Web
1919
$ vite --version ⊘ cache disabled
2020
vite --version
2121

22+
23+
> vp run hello-vpr # vpr in script should be synthesized in-session
24+
VITE+ - The Unified Toolchain for the Web
25+
26+
$ echo hello from script ⊘ cache disabled
27+
hello from script
28+
29+
30+
> vp run ready # chained vpr commands should both be synthesized
31+
VITE+ - The Unified Toolchain for the Web
32+
33+
$ echo hello from script ⊘ cache disabled
34+
hello from script
35+
36+
$ vite --version ⊘ cache disabled
37+
vite --version
38+
39+
---
40+
vp run: 0/2 cache hit (0%). (Run `vp run --last-details` for full details)

packages/cli/snap-tests-global/command-run-script-vite-program/steps.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{ "command": "node setup-bin.js", "ignoreOutput": true },
44
"vp run dev # should run vite binary, not parse as vp subcommand",
55
"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"
6+
"vp run dev-version # should run vite --version, not parse as vp subcommand",
7+
"vp run hello-vpr # vpr in script should be synthesized in-session",
8+
"vp run ready # chained vpr commands should both be synthesized"
79
]
810
}

0 commit comments

Comments
 (0)