diff --git a/crates/vite_global_cli/src/cli.rs b/crates/vite_global_cli/src/cli.rs index 3ee71e4a5e..9fbcc2bda4 100644 --- a/crates/vite_global_cli/src/cli.rs +++ b/crates/vite_global_cli/src/cli.rs @@ -1929,7 +1929,7 @@ pub async fn run_command_with_options( return Ok(ExitStatus::default()); } print_runtime_header(render_options.show_header); - commands::run_or_delegate::execute(cwd, &args).await + commands::delegate::execute(cwd, "run", &args).await } Commands::Exec { args } => { diff --git a/crates/vite_global_cli/src/commands/mod.rs b/crates/vite_global_cli/src/commands/mod.rs index 51a53cadfe..7d0f45a839 100644 --- a/crates/vite_global_cli/src/commands/mod.rs +++ b/crates/vite_global_cli/src/commands/mod.rs @@ -182,7 +182,6 @@ pub mod upgrade; // Category C: Local CLI Delegation pub mod delegate; -pub mod run_or_delegate; // Re-export command structs for convenient access pub use add::AddCommand; diff --git a/crates/vite_global_cli/src/commands/run_or_delegate.rs b/crates/vite_global_cli/src/commands/run_or_delegate.rs deleted file mode 100644 index 334dd9e497..0000000000 --- a/crates/vite_global_cli/src/commands/run_or_delegate.rs +++ /dev/null @@ -1,23 +0,0 @@ -//! Run command with fallback to package manager when vite-plus is not a dependency. - -use std::process::ExitStatus; - -use vite_path::AbsolutePathBuf; - -use crate::error::Error; - -/// Execute `vp run `. -/// -/// If vite-plus is a dependency, delegate to the local CLI. -/// If not, fall back to ` run `. -pub async fn execute(cwd: AbsolutePathBuf, args: &[String]) -> Result { - if super::has_vite_plus_dependency(&cwd) { - tracing::debug!("vite-plus is a dependency, delegating to local CLI"); - super::delegate::execute(cwd, "run", args).await - } else { - tracing::debug!("vite-plus is not a dependency, falling back to package manager run"); - super::prepend_js_runtime_to_path_env(&cwd).await?; - let package_manager = super::build_package_manager(&cwd).await?; - Ok(package_manager.run_script_command(args, &cwd).await?) - } -} diff --git a/crates/vite_global_cli/src/commands/vpr.rs b/crates/vite_global_cli/src/commands/vpr.rs index c925d06354..e043b9c8b0 100644 --- a/crates/vite_global_cli/src/commands/vpr.rs +++ b/crates/vite_global_cli/src/commands/vpr.rs @@ -1,8 +1,7 @@ //! `vpr` command implementation. //! -//! Standalone shorthand for `vp run`. Executes tasks via the same -//! run-or-delegate logic: delegates to local vite-plus CLI when -//! vite-plus is a dependency, otherwise falls back to ` run`. +//! Standalone shorthand for `vp run`. Delegates to the local or global +//! vite-plus CLI to execute tasks. use vite_path::AbsolutePath; use vite_shared::output; @@ -16,7 +15,7 @@ pub async fn execute_vpr(args: &[String], cwd: &AbsolutePath) -> i32 { } let cwd_buf = cwd.to_absolute_path_buf(); - match super::run_or_delegate::execute(cwd_buf, args).await { + match super::delegate::execute(cwd_buf, "run", args).await { Ok(status) => status.code().unwrap_or(1), Err(e) => { output::error(&e.to_string()); diff --git a/crates/vite_install/src/commands/mod.rs b/crates/vite_install/src/commands/mod.rs index 06b404633e..948880f6cb 100644 --- a/crates/vite_install/src/commands/mod.rs +++ b/crates/vite_install/src/commands/mod.rs @@ -20,7 +20,6 @@ pub mod prune; pub mod publish; pub mod rebuild; pub mod remove; -pub mod run; pub mod search; pub mod token; pub mod unlink; diff --git a/crates/vite_install/src/commands/run.rs b/crates/vite_install/src/commands/run.rs deleted file mode 100644 index b5bfb95d2d..0000000000 --- a/crates/vite_install/src/commands/run.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::{collections::HashMap, process::ExitStatus}; - -use vite_command::run_command; -use vite_error::Error; -use vite_path::AbsolutePath; - -use crate::package_manager::{ - PackageManager, PackageManagerType, ResolveCommandResult, format_path_env, -}; - -impl PackageManager { - /// Run ` run ` to execute a package.json script. - pub async fn run_script_command( - &self, - args: &[String], - cwd: impl AsRef, - ) -> Result { - let resolve_command = self.resolve_run_script_command(args); - run_command(&resolve_command.bin_path, &resolve_command.args, &resolve_command.envs, cwd) - .await - } - - /// Resolve the ` run ` command. - #[must_use] - pub fn resolve_run_script_command(&self, args: &[String]) -> ResolveCommandResult { - let envs = HashMap::from([("PATH".to_string(), format_path_env(self.get_bin_prefix()))]); - let mut cmd_args: Vec = vec!["run".to_string()]; - cmd_args.extend(args.iter().cloned()); - - let bin_path = match self.client { - PackageManagerType::Pnpm => "pnpm", - PackageManagerType::Npm => "npm", - PackageManagerType::Yarn => "yarn", - PackageManagerType::Bun => "bun", - }; - - ResolveCommandResult { bin_path: bin_path.to_string(), args: cmd_args, envs } - } -} - -#[cfg(test)] -mod tests { - use tempfile::{TempDir, tempdir}; - use vite_path::AbsolutePathBuf; - use vite_str::Str; - - use super::*; - - fn create_temp_dir() -> TempDir { - tempdir().expect("Failed to create temp directory") - } - - fn create_mock_package_manager(pm_type: PackageManagerType, version: &str) -> PackageManager { - let temp_dir = create_temp_dir(); - let temp_dir_path = AbsolutePathBuf::new(temp_dir.path().to_path_buf()).unwrap(); - let install_dir = temp_dir_path.join("install"); - - PackageManager { - client: pm_type, - package_name: pm_type.to_string().into(), - version: Str::from(version), - hash: None, - bin_name: pm_type.to_string().into(), - workspace_root: temp_dir_path.clone(), - is_monorepo: false, - install_dir, - } - } - - #[test] - fn test_pnpm_run_script() { - let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0"); - let result = pm.resolve_run_script_command(&["dev".into()]); - assert_eq!(result.bin_path, "pnpm"); - assert_eq!(result.args, vec!["run", "dev"]); - } - - #[test] - fn test_pnpm_run_script_with_args() { - let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0"); - let result = pm.resolve_run_script_command(&["dev".into(), "--port".into(), "3000".into()]); - assert_eq!(result.bin_path, "pnpm"); - assert_eq!(result.args, vec!["run", "dev", "--port", "3000"]); - } - - #[test] - fn test_npm_run_script() { - let pm = create_mock_package_manager(PackageManagerType::Npm, "11.0.0"); - let result = pm.resolve_run_script_command(&["dev".into()]); - assert_eq!(result.bin_path, "npm"); - assert_eq!(result.args, vec!["run", "dev"]); - } - - #[test] - fn test_npm_run_script_with_args() { - let pm = create_mock_package_manager(PackageManagerType::Npm, "11.0.0"); - let result = pm.resolve_run_script_command(&["dev".into(), "--port".into(), "3000".into()]); - assert_eq!(result.bin_path, "npm"); - assert_eq!(result.args, vec!["run", "dev", "--port", "3000"]); - } - - #[test] - fn test_yarn_run_script() { - let pm = create_mock_package_manager(PackageManagerType::Yarn, "4.0.0"); - let result = pm.resolve_run_script_command(&["build".into()]); - assert_eq!(result.bin_path, "yarn"); - assert_eq!(result.args, vec!["run", "build"]); - } - - #[test] - fn test_run_script_no_args() { - let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0"); - let result = pm.resolve_run_script_command(&[]); - assert_eq!(result.bin_path, "pnpm"); - assert_eq!(result.args, vec!["run"]); - } -} diff --git a/packages/cli/snap-tests-global/command-run-without-vite-plus/snap.txt b/packages/cli/snap-tests-global/command-run-without-vite-plus/snap.txt index a7457d79a9..38529e90a6 100644 --- a/packages/cli/snap-tests-global/command-run-without-vite-plus/snap.txt +++ b/packages/cli/snap-tests-global/command-run-without-vite-plus/snap.txt @@ -1,24 +1,18 @@ -> vp run hello # should fall back to pnpm run when no vite-plus dependency +> vp run hello # should execute via global vite-plus task runner VITE+ - The Unified Toolchain for the Web - -> command-run-without-vite-plus@ hello -> echo hello from script - +$ echo hello from script ⊘ cache disabled hello from script -> vp run greet --arg1 value1 # should pass through args to pnpm run -VITE+ - The Unified Toolchain for the Web - -> command-run-without-vite-plus@ greet -> echo greet --arg1 value1 +> vp run greet --arg1 value1 # should pass through args +VITE+ - The Unified Toolchain for the Web +$ echo greet --arg1 value1 ⊘ cache disabled greet --arg1 value1 -[1]> vp run nonexistent # should show pnpm missing script error -VITE+ - The Unified Toolchain for the Web - ERR_PNPM_NO_SCRIPT  Missing script: nonexistent +[1]> vp run nonexistent # should show task not found error +VITE+ - The Unified Toolchain for the Web -Command "nonexistent" not found. +Task "nonexistent" not found. diff --git a/packages/cli/snap-tests-global/command-run-without-vite-plus/steps.json b/packages/cli/snap-tests-global/command-run-without-vite-plus/steps.json index e87631131e..fa0a1072ea 100644 --- a/packages/cli/snap-tests-global/command-run-without-vite-plus/steps.json +++ b/packages/cli/snap-tests-global/command-run-without-vite-plus/steps.json @@ -1,8 +1,7 @@ { - "ignoredPlatforms": ["win32"], "commands": [ - "vp run hello # should fall back to pnpm run when no vite-plus dependency", - "vp run greet --arg1 value1 # should pass through args to pnpm run", - "vp run nonexistent # should show pnpm missing script error" + "vp run hello # should execute via global vite-plus task runner", + "vp run greet --arg1 value1 # should pass through args", + "vp run nonexistent # should show task not found error" ] } diff --git a/packages/cli/snap-tests-global/command-vpr/snap.txt b/packages/cli/snap-tests-global/command-vpr/snap.txt index bb651a8a5e..ccc2480437 100644 --- a/packages/cli/snap-tests-global/command-vpr/snap.txt +++ b/packages/cli/snap-tests-global/command-vpr/snap.txt @@ -31,21 +31,15 @@ Filter Patterns: Documentation: https://viteplus.dev/guide/run -> vpr hello # should fall back to pnpm run when no vite-plus dependency - -> command-vpr@ hello -> echo hello from script - +> vpr hello # should execute via global vite-plus task runner +$ echo hello from script ⊘ cache disabled hello from script -> vpr greet --arg1 value1 # should pass through args to pnpm run - -> command-vpr@ greet -> echo greet --arg1 value1 +> vpr greet --arg1 value1 # should pass through args +$ echo greet --arg1 value1 ⊘ cache disabled greet --arg1 value1 -[1]> vpr nonexistent # should show pnpm missing script error - ERR_PNPM_NO_SCRIPT  Missing script: nonexistent -Command "nonexistent" not found. +[1]> vpr nonexistent # should show task not found error +Task "nonexistent" not found. diff --git a/packages/cli/snap-tests-global/command-vpr/steps.json b/packages/cli/snap-tests-global/command-vpr/steps.json index 968c32cda9..2ebe60b0f1 100644 --- a/packages/cli/snap-tests-global/command-vpr/steps.json +++ b/packages/cli/snap-tests-global/command-vpr/steps.json @@ -1,8 +1,8 @@ { "commands": [ "vpr -h # should show vp run help", - "vpr hello # should fall back to pnpm run when no vite-plus dependency", - "vpr greet --arg1 value1 # should pass through args to pnpm run", - "vpr nonexistent # should show pnpm missing script error" + "vpr hello # should execute via global vite-plus task runner", + "vpr greet --arg1 value1 # should pass through args", + "vpr nonexistent # should show task not found error" ] } diff --git a/packages/cli/snap-tests-global/delegate-respects-default-node-version/snap.txt b/packages/cli/snap-tests-global/delegate-respects-default-node-version/snap.txt index 0831e4700e..acb96b3bcd 100644 --- a/packages/cli/snap-tests-global/delegate-respects-default-node-version/snap.txt +++ b/packages/cli/snap-tests-global/delegate-respects-default-node-version/snap.txt @@ -6,12 +6,10 @@ VITE+ - The Unified Toolchain for the Web > vp run check-node # Should also use 22.12.0 VITE+ - The Unified Toolchain for the Web - -> delegate-respects-default-node-version@ check-node -> node -e "console.log(process.version)" - +$ node -e "console.log(process.version)" ⊘ cache disabled v + > vp exec node -e "console.log(process.version)" # Should also use 22.12.0 VITE+ - The Unified Toolchain for the Web diff --git a/rfcs/run-without-vite-plus-dependency.md b/rfcs/run-without-vite-plus-dependency.md deleted file mode 100644 index 675b9c9356..0000000000 --- a/rfcs/run-without-vite-plus-dependency.md +++ /dev/null @@ -1,483 +0,0 @@ -# RFC: `vp run` Without vite-plus Dependency - -## Summary - -Allow `vp run