Skip to content

Commit 112894b

Browse files
authored
refactor(cli): rename vp env run to vp env exec (#553)
1 parent 8a22e14 commit 112894b

21 files changed

Lines changed: 130 additions & 128 deletions

File tree

crates/vite_global_cli/src/cli.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,10 @@ Examples:
650650
vp env use lts # Use latest LTS for this shell session
651651
vp env use # Use project version for this shell session
652652
vp env use --unset # Remove session override
653-
vp env run --node 20 node -v # Run 'node -v' with Node.js 20
654-
vp env run --node lts npm i # Run 'npm i' with latest LTS
655-
vp env run node -v # Shim mode (version auto-resolved)
656-
vp env run npm install # Shim mode (version auto-resolved)
653+
vp env exec --node 20 node -v # Execute 'node -v' with Node.js 20
654+
vp env exec --node lts npm i # Execute 'npm i' with latest LTS
655+
vp env exec node -v # Shim mode (version auto-resolved)
656+
vp env exec npm install # Shim mode (version auto-resolved)
657657
658658
Global Packages:
659659
vp install -g <package> # Install a global package
@@ -766,8 +766,9 @@ pub enum EnvSubcommands {
766766
sort: SortingMethod,
767767
},
768768

769-
/// Run a command with a specific Node.js version
770-
Run {
769+
/// Execute a command with a specific Node.js version
770+
#[command(visible_alias = "run")]
771+
Exec {
771772
/// Node.js version to use (e.g., "20.18.0", "lts", "^20.0.0")
772773
/// If not provided and command is node/npm/npx or a global package binary,
773774
/// version is resolved automatically (same as shim behavior)

crates/vite_global_cli/src/commands/env/run.rs renamed to crates/vite_global_cli/src/commands/env/exec.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! Run command for executing commands with a specific Node.js version.
1+
//! Exec command for executing commands with a specific Node.js version.
22
//!
33
//! Handles two modes:
4-
//! 1. Explicit version: `vp env run --node <version> [--npm <version>] <command>`
5-
//! 2. Shim mode: `vp env run <tool> [args...]` where tool is node/npm/npx or a global package binary
4+
//! 1. Explicit version: `vp env exec --node <version> [--npm <version>] <command>`
5+
//! 2. Shim mode: `vp env exec <tool> [args...]` where tool is node/npm/npx or a global package binary
66
//!
77
//! The shim mode uses the same dispatch logic as Unix symlinks, ensuring identical behavior
88
//! across platforms (used by Windows .cmd wrappers and Git Bash shell scripts).
@@ -17,7 +17,7 @@ use crate::{
1717
shim::{dispatch as shim_dispatch, is_shim_tool},
1818
};
1919

20-
/// Execute the run command.
20+
/// Execute the exec command.
2121
///
2222
/// When `--node` is provided, runs a command with the specified Node.js version.
2323
/// When `--node` is not provided and the command is a shim tool (node/npm/npx or global package),
@@ -28,8 +28,8 @@ pub async fn execute(
2828
command: &[String],
2929
) -> Result<ExitStatus, Error> {
3030
if command.is_empty() {
31-
eprintln!("vp env run: missing command to execute");
32-
eprintln!("Usage: vp env run [--node <version>] <command> [args...]");
31+
eprintln!("vp env exec: missing command to execute");
32+
eprintln!("Usage: vp env exec [--node <version>] <command> [args...]");
3333
return Ok(exit_status(1));
3434
}
3535

@@ -45,7 +45,7 @@ pub async fn execute(
4545
let tool = &command[0];
4646
if is_shim_tool(tool) {
4747
// Clear recursion env var to force fresh version resolution.
48-
// This is needed because `vp env run` may be invoked from within a context
48+
// This is needed because `vp env exec` may be invoked from within a context
4949
// where VITE_PLUS_TOOL_RECURSION is already set (e.g., when pnpm runs through
5050
// the vite-plus shim). Without clearing it, shim_dispatch would passthrough
5151
// to the system node instead of resolving the version.
@@ -67,13 +67,13 @@ pub async fn execute(
6767
}
6868

6969
// Not a shim tool and no --node - error
70-
eprintln!("vp env run: --node is required when running non-shim commands");
71-
eprintln!("Usage: vp env run --node <version> <command> [args...]");
70+
eprintln!("vp env exec: --node is required when running non-shim commands");
71+
eprintln!("Usage: vp env exec --node <version> <command> [args...]");
7272
eprintln!();
7373
eprintln!("For shim tools, --node is optional (version resolved automatically):");
74-
eprintln!(" vp env run node script.js # Core tool");
75-
eprintln!(" vp env run npm install # Core tool");
76-
eprintln!(" vp env run tsc --version # Global package");
74+
eprintln!(" vp env exec node script.js # Core tool");
75+
eprintln!(" vp env exec npm install # Core tool");
76+
eprintln!(" vp env exec tsc --version # Global package");
7777
Ok(exit_status(1))
7878
}
7979

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ const CORE_SHIMS: &[&str] = &["node", "npm", "npx", "vp"];
364364
/// Create a shim for a package binary.
365365
///
366366
/// On Unix: Creates a symlink to ../current/bin/vp
367-
/// On Windows: Creates a .cmd wrapper that calls `vp env run <bin_name>`
367+
/// On Windows: Creates a .cmd wrapper that calls `vp env exec <bin_name>`
368368
async fn create_package_shim(
369369
bin_dir: &vite_path::AbsolutePath,
370370
bin_name: &str,
@@ -405,24 +405,24 @@ async fn create_package_shim(
405405
return Ok(());
406406
}
407407

408-
// Create .cmd wrapper that calls vp env run <bin_name>
408+
// Create .cmd wrapper that calls vp env exec <bin_name>
409409
// Set VITE_PLUS_HOME using %~dp0.. which resolves to the parent of bin/
410410
// This ensures the vp binary knows its home directory
411411
let wrapper_content = format!(
412-
"@echo off\r\nset VITE_PLUS_HOME=%~dp0..\r\n\"%VITE_PLUS_HOME%\\current\\bin\\vp.exe\" env run {} %*\r\nexit /b %ERRORLEVEL%\r\n",
412+
"@echo off\r\nset VITE_PLUS_HOME=%~dp0..\r\n\"%VITE_PLUS_HOME%\\current\\bin\\vp.exe\" env exec {} %*\r\nexit /b %ERRORLEVEL%\r\n",
413413
bin_name
414414
);
415415
tokio::fs::write(&cmd_path, wrapper_content).await?;
416416

417417
// Also create shell script for Git Bash (bin_name without extension)
418-
// Uses explicit "vp env run <bin_name>" instead of symlink+argv[0] because
418+
// Uses explicit "vp env exec <bin_name>" instead of symlink+argv[0] because
419419
// Windows symlinks require admin privileges
420420
let sh_path = bin_dir.join(bin_name);
421421
let sh_content = format!(
422422
r#"#!/bin/sh
423423
VITE_PLUS_HOME="$(dirname "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")")"
424424
export VITE_PLUS_HOME
425-
exec "$VITE_PLUS_HOME/current/bin/vp.exe" env run {} "$@"
425+
exec "$VITE_PLUS_HOME/current/bin/vp.exe" env exec {} "$@"
426426
"#,
427427
bin_name
428428
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod config;
88
mod current;
99
mod default;
1010
mod doctor;
11+
mod exec;
1112
pub mod global_install;
1213
mod list;
1314
mod list_remote;
@@ -16,7 +17,6 @@ mod on;
1617
pub mod package_metadata;
1718
pub mod packages;
1819
mod pin;
19-
mod run;
2020
mod setup;
2121
mod unpin;
2222
mod r#use;
@@ -49,8 +49,8 @@ pub async fn execute(cwd: AbsolutePathBuf, args: EnvArgs) -> Result<ExitStatus,
4949
crate::cli::EnvSubcommands::ListRemote { pattern, lts, all, json, sort } => {
5050
list_remote::execute(pattern, lts, all, json, sort).await
5151
}
52-
crate::cli::EnvSubcommands::Run { node, npm, command } => {
53-
run::execute(node.as_deref(), npm.as_deref(), &command).await
52+
crate::cli::EnvSubcommands::Exec { node, npm, command } => {
53+
exec::execute(node.as_deref(), npm.as_deref(), &command).await
5454
}
5555
crate::cli::EnvSubcommands::Uninstall { version } => {
5656
let provider = vite_js_runtime::NodeProvider::new();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//!
1212
//! On Windows:
1313
//! - bin/vp.cmd is a wrapper script that calls ..\current\bin\vp.exe
14-
//! - bin/node.cmd, bin/npm.cmd, bin/npx.cmd are wrappers calling `vp env run <tool>`
14+
//! - bin/node.cmd, bin/npm.cmd, bin/npx.cmd are wrappers calling `vp env exec <tool>`
1515
1616
use std::process::ExitStatus;
1717

@@ -220,9 +220,9 @@ async fn create_unix_shim(
220220
Ok(())
221221
}
222222

223-
/// Create Windows shims using .cmd wrappers that call `vp env run <tool>`.
223+
/// Create Windows shims using .cmd wrappers that call `vp env exec <tool>`.
224224
///
225-
/// All tools (node, npm, npx) get .cmd wrappers that invoke `vp env run`.
225+
/// All tools (node, npm, npx) get .cmd wrappers that invoke `vp env exec`.
226226
/// Also creates shell scripts (without extension) for Git Bash compatibility.
227227
/// This is consistent with Volta's Windows approach.
228228
#[cfg(windows)]
@@ -233,26 +233,26 @@ async fn create_windows_shim(
233233
) -> Result<(), Error> {
234234
let cmd_path = bin_dir.join(format!("{tool}.cmd"));
235235

236-
// Create .cmd wrapper that calls vp env run <tool>
236+
// Create .cmd wrapper that calls vp env exec <tool>
237237
// Use a for loop to canonicalize VITE_PLUS_HOME path.
238238
// %~dp0.. would produce paths like C:\Users\x\.vite-plus\bin\..
239239
// The for loop resolves this to a clean C:\Users\x\.vite-plus
240240
let cmd_content = format!(
241-
"@echo off\r\nfor %%I in (\"%~dp0..\") do set VITE_PLUS_HOME=%%~fI\r\n\"%VITE_PLUS_HOME%\\current\\bin\\vp.exe\" env run {} %*\r\nexit /b %ERRORLEVEL%\r\n",
241+
"@echo off\r\nfor %%I in (\"%~dp0..\") do set VITE_PLUS_HOME=%%~fI\r\n\"%VITE_PLUS_HOME%\\current\\bin\\vp.exe\" env exec {} %*\r\nexit /b %ERRORLEVEL%\r\n",
242242
tool
243243
);
244244

245245
tokio::fs::write(&cmd_path, cmd_content).await?;
246246

247247
// Also create shell script for Git Bash (tool without extension)
248-
// Uses explicit "vp env run <tool>" instead of symlink+argv[0] because
248+
// Uses explicit "vp env exec <tool>" instead of symlink+argv[0] because
249249
// Windows symlinks require admin privileges
250250
let sh_path = bin_dir.join(tool);
251251
let sh_content = format!(
252252
r#"#!/bin/sh
253253
VITE_PLUS_HOME="$(dirname "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")")"
254254
export VITE_PLUS_HOME
255-
exec "$VITE_PLUS_HOME/current/bin/vp.exe" env run {} "$@"
255+
exec "$VITE_PLUS_HOME/current/bin/vp.exe" env exec {} "$@"
256256
"#,
257257
tool
258258
);

crates/vite_global_cli/src/shim/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! Detection methods:
77
//! - Unix: Symlinks to vp binary preserve argv[0], allowing tool detection
8-
//! - Windows: .cmd wrappers call `vp env run <tool>` directly
8+
//! - Windows: .cmd wrappers call `vp env exec <tool>` directly
99
//! - Legacy: VITE_PLUS_SHIM_TOOL env var (kept for backward compatibility)
1010
1111
mod cache;
@@ -92,7 +92,7 @@ const SHIM_TOOL_ENV_VAR: &str = "VITE_PLUS_SHIM_TOOL";
9292
/// 2. Check `VITE_PLUS_SHIM_TOOL` env var (for shell wrapper scripts)
9393
/// 3. Fall back to argv[0] detection (primary method on Unix with symlinks)
9494
///
95-
/// Note: Modern Windows wrappers use `vp env run <tool>` instead of env vars.
95+
/// Note: Modern Windows wrappers use `vp env exec <tool>` instead of env vars.
9696
///
9797
/// IMPORTANT: This function clears `VITE_PLUS_SHIM_TOOL` after reading it to
9898
/// prevent the env var from leaking to child processes.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Commands:
295295
unpin Remove the .node-version file from current directory (alias for `pin --unpin`)
296296
list List locally installed Node.js versions [aliases: ls]
297297
list-remote List available Node.js versions from the registry [aliases: ls-remote]
298-
run Run a command with a specific Node.js version
298+
exec Execute a command with a specific Node.js version [aliases: run]
299299
uninstall Uninstall a Node.js version [aliases: uni]
300300
install Install a Node.js version [aliases: i]
301301
use Use a specific Node.js version for this shell session
@@ -329,10 +329,10 @@ Examples:
329329
vp env use lts # Use latest LTS for this shell session
330330
vp env use # Use project version for this shell session
331331
vp env use --unset # Remove session override
332-
vp env run --node 20 node -v # Run 'node -v' with Node.js 20
333-
vp env run --node lts npm i # Run 'npm i' with latest LTS
334-
vp env run node -v # Shim mode (version auto-resolved)
335-
vp env run npm install # Shim mode (version auto-resolved)
332+
vp env exec --node 20 node -v # Execute 'node -v' with Node.js 20
333+
vp env exec --node lts npm i # Execute 'npm i' with latest LTS
334+
vp env exec node -v # Shim mode (version auto-resolved)
335+
vp env exec npm install # Shim mode (version auto-resolved)
336336

337337
Global Packages:
338338
vp install -g <package> # Install a global package

packages/global/snap-tests/command-env-run-shim-mode/package.json renamed to packages/global/snap-tests/command-env-exec-shim-mode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "command-env-run-shim-mode",
2+
"name": "command-env-exec-shim-mode",
33
"version": "1.0.0",
44
"private": true,
55
"engines": {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
> vp env exec node -v # Shim mode: version resolved from package.json engines.node
2+
v20.18.0
3+
4+
> vp env exec npm -v # Shim mode: npm uses same version
5+
10.8.2
6+
7+
> vp env exec node -e "console.log('Hello from shim mode')" # Shim mode: run inline script
8+
Hello from shim mode
9+
10+
> vp env exec nonexistent-tool --version || echo 'Expected error: non-shim command requires --node' # Error: non-shim tool
11+
vp env exec: --node is required when running non-shim commands
12+
Usage: vp env exec --node <version> <command> [args...]
13+
14+
For shim tools, --node is optional (version resolved automatically):
15+
vp env exec node script.js # Core tool
16+
vp env exec npm install # Core tool
17+
vp env exec tsc --version # Global package
18+
Expected error: non-shim command requires --node
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env": {},
3+
"ignoredPlatforms": [],
4+
"commands": [
5+
"vp env exec node -v # Shim mode: version resolved from package.json engines.node",
6+
"vp env exec npm -v # Shim mode: npm uses same version",
7+
"vp env exec node -e \"console.log('Hello from shim mode')\" # Shim mode: run inline script",
8+
"vp env exec nonexistent-tool --version || echo 'Expected error: non-shim command requires --node' # Error: non-shim tool"
9+
]
10+
}

0 commit comments

Comments
 (0)