Skip to content

Commit 5afaf9c

Browse files
committed
feat: add vpr as standalone shorthand for vp run
Add `vpr` as a shim binary that acts as a shorthand for `vp run`, following the same pattern as `vpx` (shorthand for `vp exec`). When invoked, `vpr` delegates to the same run-or-delegate logic: local vite-plus CLI when vite-plus is a dependency, otherwise falls back to `<pm> run`. - Add vpr command module with execute_vpr entry point - Add vpr detection in shim/mod.rs detect_shim_tool() - Add vpr dispatch in shim/dispatch.rs - Add vpr to SHIM_TOOLS in env setup and doctor - Update tip message to mention vpr shorthand - Update run guide, run RFC, and trampoline RFC docs
1 parent dfc2d61 commit 5afaf9c

10 files changed

Lines changed: 89 additions & 7 deletions

File tree

crates/vite_global_cli/src/commands/env/doctor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const KNOWN_VERSION_MANAGERS: &[(&str, &str)] = &[
6363
];
6464

6565
/// Tools that should have shims
66-
const SHIM_TOOLS: &[&str] = &["node", "npm", "npx", "vpx"];
66+
const SHIM_TOOLS: &[&str] = &["node", "npm", "npx", "vpx", "vpr"];
6767

6868
/// Column width for left-side keys in aligned output
6969
const KEY_WIDTH: usize = 18;

crates/vite_global_cli/src/commands/env/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use owo_colors::OwoColorize;
2323
use super::config::{get_bin_dir, get_vp_home};
2424
use crate::{cli::Args, error::Error, help};
2525

26-
/// Tools to create shims for (node, npm, npx, vpx)
27-
const SHIM_TOOLS: &[&str] = &["node", "npm", "npx", "vpx"];
26+
/// Tools to create shims for (node, npm, npx, vpx, vpr)
27+
const SHIM_TOOLS: &[&str] = &["node", "npm", "npx", "vpx", "vpr"];
2828

2929
fn accent_command(command: &str) -> String {
3030
if help::should_style_help() {

crates/vite_global_cli/src/commands/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ pub mod version;
172172
// Category D: Environment Management
173173
pub mod env;
174174

175-
// Standalone binary command
175+
// Standalone binary commands
176+
pub mod vpr;
176177
pub mod vpx;
177178

178179
// Self-Management
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! `vpr` command implementation.
2+
//!
3+
//! Standalone shorthand for `vp run`. Executes tasks via the same
4+
//! run-or-delegate logic: delegates to local vite-plus CLI when
5+
//! vite-plus is a dependency, otherwise falls back to `<pm> run`.
6+
7+
use vite_path::AbsolutePath;
8+
use vite_shared::output;
9+
10+
/// Main entry point for vpr execution.
11+
///
12+
/// Called from shim dispatch when `argv[0]` is `vpr`.
13+
pub async fn execute_vpr(args: &[String], cwd: &AbsolutePath) -> i32 {
14+
if crate::help::maybe_print_unified_delegate_help("run", args, true) {
15+
return 0;
16+
}
17+
18+
let cwd_buf = cwd.to_absolute_path_buf();
19+
match super::run_or_delegate::execute(cwd_buf, args).await {
20+
Ok(status) => status.code().unwrap_or(1),
21+
Err(e) => {
22+
output::error(&e.to_string());
23+
1
24+
}
25+
}
26+
}

crates/vite_global_cli/src/shim/dispatch.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,18 @@ pub async fn dispatch(tool: &str, args: &[String]) -> i32 {
673673
return crate::commands::vpx::execute_vpx(args, &cwd).await;
674674
}
675675

676+
// Handle vpr — standalone shorthand for `vp run`
677+
if tool == "vpr" {
678+
let cwd = match current_dir() {
679+
Ok(path) => path,
680+
Err(e) => {
681+
eprintln!("vp: Failed to get current directory: {e}");
682+
return 1;
683+
}
684+
};
685+
return crate::commands::vpr::execute_vpr(args, &cwd).await;
686+
}
687+
676688
// Check recursion prevention - if already in a shim context, passthrough directly
677689
// Only applies to core tools (node/npm/npx) whose bin dir is prepended to PATH.
678690
// Package binaries are always resolved via metadata lookup, so they can't loop.

crates/vite_global_cli/src/shim/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ pub fn detect_shim_tool(argv0: &str) -> Option<String> {
148148
if argv0_tool == "vpx" {
149149
return Some("vpx".to_string());
150150
}
151+
if argv0_tool == "vpr" {
152+
return Some("vpr".to_string());
153+
}
151154

152155
// Fall back to argv[0] detection (Unix symlinks)
153156
if is_shim_tool(&argv0_tool) { Some(argv0_tool) } else { None }
@@ -264,4 +267,23 @@ mod tests {
264267
let result = detect_shim_tool("vpx.exe");
265268
assert_eq!(result, Some("vpx".to_string()));
266269
}
270+
271+
#[test]
272+
fn test_detect_shim_tool_vpr() {
273+
// vpr should be detected via the argv0 check, same pattern as vpx
274+
// SAFETY: We're in a test
275+
unsafe {
276+
std::env::remove_var(SHIM_TOOL_ENV_VAR);
277+
}
278+
let result = detect_shim_tool("vpr");
279+
assert_eq!(result, Some("vpr".to_string()));
280+
281+
// Also works with full path
282+
let result = detect_shim_tool("/home/user/.vite-plus/bin/vpr");
283+
assert_eq!(result, Some("vpr".to_string()));
284+
285+
// Also works with .exe extension (Windows)
286+
let result = detect_shim_tool("vpr.exe");
287+
assert_eq!(result, Some("vpr".to_string()));
288+
}
267289
}

crates/vite_global_cli/src/tips/use_vpx_or_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Tip for UseVpxOrRun {
1111
}
1212

1313
fn message(&self) -> &'static str {
14-
"Execute a package binary with `vpx <pkg[@version]>`, or a script with `vp run <script>`"
14+
"Execute a package binary with `vpx <pkg[@version]>`, or a script with `vpr <script>` (or `vp run <script>`)"
1515
}
1616
}
1717

docs/guide/run.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
`vp run` runs `package.json` scripts and tasks defined in `vite.config.ts`. It works like `pnpm run`, with caching, dependency ordering, and workspace-aware execution built in.
44

5+
::: tip
6+
`vpr` is available as a standalone shorthand for `vp run`. All examples below work with both `vp run` and `vpr`.
7+
:::
8+
59
## Overview
610

711
Use `vp run` with existing `package.json` scripts:

rfcs/run-without-vite-plus-dependency.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,20 @@ fn test_yarn_run_script() {
427427
}
428428
```
429429

430+
## Standalone Shorthand: `vpr`
431+
432+
`vpr` is available as a standalone binary shorthand for `vp run`, following the same pattern as `vpx` (shorthand for `vp exec`). It is implemented as a shim symlink to the `vp` binary, detected via `argv[0]`, and dispatches to the same `run_or_delegate` logic:
433+
434+
```bash
435+
# These are equivalent:
436+
vpr dev
437+
vp run dev
438+
439+
# Fallback behavior is identical:
440+
vpr build # → <pm> run build (when no vite-plus dependency)
441+
vpr -r build # → delegates to vite-plus task runner (when vite-plus is a dependency)
442+
```
443+
430444
## Backward Compatibility
431445

432446
- **Projects with vite-plus**: No change in behavior. The `has_vite_plus_dependency` check passes, and delegation proceeds as before.

rfcs/trampoline-exe-for-shims.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Implemented
66

77
## Summary
88

9-
Replace Windows `.cmd` wrapper scripts with lightweight trampoline `.exe` binaries for all shim tools (`vp`, `node`, `npm`, `npx`, `vpx`, and globally installed package binaries). This eliminates the `Terminate batch job (Y/N)?` prompt that appears when users press Ctrl+C, providing the same clean signal behavior as direct `.exe` invocation.
9+
Replace Windows `.cmd` wrapper scripts with lightweight trampoline `.exe` binaries for all shim tools (`vp`, `node`, `npm`, `npx`, `vpx`, `vpr`, and globally installed package binaries). This eliminates the `Terminate batch job (Y/N)?` prompt that appears when users press Ctrl+C, providing the same clean signal behavior as direct `.exe` invocation.
1010

1111
## Motivation
1212

@@ -64,7 +64,9 @@ On Unix, shims are symlinks to the `vp` binary. The binary detects the tool name
6464
├── vp → ../current/bin/vp (symlink)
6565
├── node → ../current/bin/vp (symlink)
6666
├── npm → ../current/bin/vp (symlink)
67-
└── npx → ../current/bin/vp (symlink)
67+
├── npx → ../current/bin/vp (symlink)
68+
├── vpx → ../current/bin/vp (symlink)
69+
└── vpr → ../current/bin/vp (symlink)
6870
```
6971

7072
### Windows (Trampoline `.exe` Files)
@@ -76,6 +78,7 @@ On Unix, shims are symlinks to the `vp` binary. The binary detects the tool name
7678
├── npm.exe # Trampoline → sets VITE_PLUS_SHIM_TOOL=npm, spawns vp.exe
7779
├── npx.exe # Trampoline → sets VITE_PLUS_SHIM_TOOL=npx, spawns vp.exe
7880
├── vpx.exe # Trampoline → sets VITE_PLUS_SHIM_TOOL=vpx, spawns vp.exe
81+
├── vpr.exe # Trampoline → sets VITE_PLUS_SHIM_TOOL=vpr, spawns vp.exe
7982
└── tsc.exe # Trampoline → sets VITE_PLUS_SHIM_TOOL=tsc, spawns vp.exe (package shim)
8083
```
8184

0 commit comments

Comments
 (0)