Skip to content

Commit acee8b6

Browse files
committed
feat: add vpr as standalone shorthand for vp run (#1178)
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 db75675 commit acee8b6

16 files changed

Lines changed: 168 additions & 9 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
@@ -22,8 +22,8 @@ use owo_colors::OwoColorize;
2222
use super::config::{get_bin_dir, get_vp_home};
2323
use crate::{error::Error, help};
2424

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

2828
fn accent_command(command: &str) -> String {
2929
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/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ pub fn top_level_help_doc() -> HelpDoc {
449449
section_rows(
450450
"Execute",
451451
vec![
452-
row("run", "Run tasks"),
452+
row("run", "Run tasks (also available as standalone `vpr`)"),
453453
row("exec", "Execute a command from local node_modules/.bin"),
454454
row("dlx", "Execute a package binary without installing it as a dependency"),
455455
row("cache", "Manage the task cache"),

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:

packages/cli/snap-tests-global/cli-helper-message/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Develop:
1919
test Run tests
2020

2121
Execute:
22-
run Run tasks
22+
run Run tasks (also available as standalone `vpr`)
2323
exec Execute a command from local node_modules/.bin
2424
dlx Execute a package binary without installing it as a dependency
2525
cache Manage the task cache

0 commit comments

Comments
 (0)