diff --git a/crates/bun/platform/src/actions/run_target.rs b/crates/bun/platform/src/actions/run_target.rs index 0a8b89a85b2..d7313d2c25b 100644 --- a/crates/bun/platform/src/actions/run_target.rs +++ b/crates/bun/platform/src/actions/run_target.rs @@ -2,27 +2,11 @@ use crate::target_hash::BunTargetHash; use moon_bun_tool::BunTool; use moon_config::{HasherConfig, HasherOptimization}; use moon_node_lang::PackageJson; -use moon_process::Command; use moon_project::Project; -use moon_task::Task; use moon_tool::DependencyManager; use rustc_hash::FxHashMap; use std::path::Path; -// This is like the function above, but is for situations where the tool -// has not been configured, and should default to the global "bun" found -// in the user's shell. -pub fn create_target_command_without_tool( - _project: &Project, - task: &Task, - _working_dir: &Path, -) -> miette::Result { - let mut command = Command::new(&task.command); - command.args(&task.args).envs(&task.env); - - Ok(command) -} - pub async fn create_target_hasher( bun: Option<&BunTool>, project: &Project, diff --git a/crates/bun/platform/src/bun_platform.rs b/crates/bun/platform/src/bun_platform.rs index 0851779dbf4..65099dd6a87 100644 --- a/crates/bun/platform/src/bun_platform.rs +++ b/crates/bun/platform/src/bun_platform.rs @@ -14,7 +14,7 @@ use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; -use moon_tool::{Tool, ToolManager}; +use moon_tool::{prepend_path_env_var, Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::{async_trait, path}; use proto_core::ProtoEnvironment; @@ -382,17 +382,22 @@ impl Platform for BunPlatform { _context: &ActionContext, project: &Project, task: &Task, - _runtime: &Runtime, - working_dir: &Path, + runtime: &Runtime, + _working_dir: &Path, ) -> miette::Result { - let command = actions::create_target_command_without_tool(project, task, working_dir)?; - - Ok(command) - } + let mut command = Command::new(&task.command); + command.args(&task.args); + command.envs(&task.env); + + if let Ok(tool) = self.toolchain.get_for_version(&runtime.requirement) { + command.env( + "PROTO_BUN_VERSION", + tool.tool.get_resolved_version().to_string(), + ); + } - fn get_run_target_paths(&self, working_dir: &Path) -> Vec { let mut paths = vec![]; - let mut current_dir = working_dir; + let mut current_dir = project.root.as_path(); loop { paths.push(current_dir.join("node_modules").join(".bin")); @@ -409,7 +414,12 @@ impl Platform for BunPlatform { }; } - paths.extend(get_bun_env_paths(&self.proto_env)); - paths + if !runtime.requirement.is_global() { + paths.extend(get_bun_env_paths(&self.proto_env)); + } + + command.env("PATH", prepend_path_env_var(paths)); + + Ok(command) } } diff --git a/crates/bun/tool/src/bun_tool.rs b/crates/bun/tool/src/bun_tool.rs index 5b35ea035a5..201e5122eaa 100644 --- a/crates/bun/tool/src/bun_tool.rs +++ b/crates/bun/tool/src/bun_tool.rs @@ -130,18 +130,18 @@ impl DependencyManager<()> for BunTool { fn create_command(&self, _parent: &()) -> miette::Result { let mut cmd = Command::new("bun"); - cmd.env( - "PATH", - prepend_path_env_var(get_bun_env_paths(&self.proto_env)), - ); - if !self.global { cmd.env( - "PROTO_BUN_VERSION", - self.tool.get_resolved_version().to_string(), + "PATH", + prepend_path_env_var(get_bun_env_paths(&self.proto_env)), ); } + cmd.env( + "PROTO_BUN_VERSION", + self.tool.get_resolved_version().to_string(), + ); + Ok(cmd) } diff --git a/crates/core/platform/src/platform.rs b/crates/core/platform/src/platform.rs index 453e8f81a83..282b74117ed 100644 --- a/crates/core/platform/src/platform.rs +++ b/crates/core/platform/src/platform.rs @@ -13,7 +13,7 @@ use moon_task::Task; use moon_tool::Tool; use rustc_hash::FxHashMap; use std::collections::BTreeMap; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::sync::Arc; #[async_trait] @@ -162,6 +162,4 @@ pub trait Platform: Send + Sync { runtime: &Runtime, working_dir: &Path, ) -> miette::Result; - - fn get_run_target_paths(&self, working_dir: &Path) -> Vec; } diff --git a/crates/core/runner/src/runner.rs b/crates/core/runner/src/runner.rs index 3253e3e41c7..19625a9180d 100644 --- a/crates/core/runner/src/runner.rs +++ b/crates/core/runner/src/runner.rs @@ -17,7 +17,6 @@ use moon_project::Project; use moon_target::{TargetError, TargetScope}; use moon_task::Task; use moon_terminal::{label_checkpoint, Checkpoint}; -use moon_tool::prepend_path_env_var; use moon_utils::{is_ci, is_test_env, path, time}; use moon_workspace::Workspace; use rustc_hash::FxHashMap; @@ -244,18 +243,14 @@ impl<'a> Runner<'a> { color::path(working_dir) ); - let platform = PlatformManager::read().get(task.platform)?; - let mut command = platform + let mut command = PlatformManager::read() + .get(task.platform)? .create_run_target_command(context, project, task, runtime, working_dir) .await?; command .cwd(working_dir) .envs(self.create_env_vars().await?) - .env( - "PATH", - prepend_path_env_var(platform.get_run_target_paths(&project.root)), - ) // We need to handle non-zero's manually .set_error_on_nonzero(false); diff --git a/crates/deno/platform/src/platform.rs b/crates/deno/platform/src/deno_platform.rs similarity index 97% rename from crates/deno/platform/src/platform.rs rename to crates/deno/platform/src/deno_platform.rs index 9ebb0cd78cf..567b26d6b64 100644 --- a/crates/deno/platform/src/platform.rs +++ b/crates/deno/platform/src/deno_platform.rs @@ -350,17 +350,20 @@ impl Platform for DenoPlatform { _context: &ActionContext, _project: &Project, task: &Task, - _runtime: &Runtime, - working_dir: &Path, + runtime: &Runtime, + _working_dir: &Path, ) -> miette::Result { let mut command = Command::new(&task.command); + command.args(&task.args); + command.envs(&task.env); - command.args(&task.args).envs(&task.env).cwd(working_dir); + if !runtime.requirement.is_global() { + command.env( + "PATH", + prepend_path_env_var(get_deno_env_paths(&self.proto_env)), + ); + } Ok(command) } - - fn get_run_target_paths(&self, _working_dir: &Path) -> Vec { - get_deno_env_paths(&self.proto_env) - } } diff --git a/crates/deno/platform/src/lib.rs b/crates/deno/platform/src/lib.rs index 7181581893a..fe3a5ec5389 100644 --- a/crates/deno/platform/src/lib.rs +++ b/crates/deno/platform/src/lib.rs @@ -1,6 +1,6 @@ mod bins_hash; +mod deno_platform; mod deps_hash; -mod platform; mod target_hash; -pub use platform::*; +pub use deno_platform::*; diff --git a/crates/node/platform/src/node_platform.rs b/crates/node/platform/src/node_platform.rs index c0eee339279..e6377d4807c 100644 --- a/crates/node/platform/src/node_platform.rs +++ b/crates/node/platform/src/node_platform.rs @@ -17,6 +17,7 @@ use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; +use moon_tool::prepend_path_env_var; use moon_tool::{Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::{async_trait, path}; @@ -430,10 +431,10 @@ impl Platform for NodePlatform { context: &ActionContext, project: &Project, task: &Task, - _runtime: &Runtime, + runtime: &Runtime, working_dir: &Path, ) -> miette::Result { - let command = actions::create_target_command_without_tool( + let mut command = actions::create_target_command_without_tool( &self.config, context, project, @@ -441,12 +442,43 @@ impl Platform for NodePlatform { working_dir, )?; - Ok(command) - } + if let Ok(node) = self.toolchain.get_for_version(&runtime.requirement) { + command.env( + "PROTO_NODE_VERSION", + node.tool.get_resolved_version().to_string(), + ); + + if let Ok(npm) = node.get_npm() { + command.env( + "PROTO_NPM_VERSION", + npm.tool.get_resolved_version().to_string(), + ); + } + + if let Ok(pnpm) = node.get_pnpm() { + command.env( + "PROTO_PNPM_VERSION", + pnpm.tool.get_resolved_version().to_string(), + ); + } + + if let Ok(yarn) = node.get_yarn() { + command.env( + "PROTO_YARN_VERSION", + yarn.tool.get_resolved_version().to_string(), + ); + } + + if let Ok(bun) = node.get_bun() { + command.env( + "PROTO_BUN_VERSION", + bun.tool.get_resolved_version().to_string(), + ); + } + } - fn get_run_target_paths(&self, working_dir: &Path) -> Vec { let mut paths = vec![]; - let mut current_dir = working_dir; + let mut current_dir = project.root.as_path(); loop { paths.push(current_dir.join("node_modules").join(".bin")); @@ -463,7 +495,12 @@ impl Platform for NodePlatform { }; } - paths.extend(get_node_env_paths(&self.proto_env)); - paths + if !runtime.requirement.is_global() { + paths.extend(get_node_env_paths(&self.proto_env)); + } + + command.env("PATH", prepend_path_env_var(paths)); + + Ok(command) } } diff --git a/crates/node/tool/src/bun_tool.rs b/crates/node/tool/src/bun_tool.rs index dcaa5a718b4..e1e5f3f7b00 100644 --- a/crates/node/tool/src/bun_tool.rs +++ b/crates/node/tool/src/bun_tool.rs @@ -46,18 +46,18 @@ impl BunTool { fn internal_create_command(&self) -> miette::Result { let mut cmd = Command::new("bun"); - cmd.env( - "PATH", - prepend_path_env_var(get_node_env_paths(&self.proto_env)), - ); - if !self.global { cmd.env( - "PROTO_BUN_VERSION", - self.tool.get_resolved_version().to_string(), + "PATH", + prepend_path_env_var(get_node_env_paths(&self.proto_env)), ); } + cmd.env( + "PROTO_BUN_VERSION", + self.tool.get_resolved_version().to_string(), + ); + Ok(cmd) } } diff --git a/crates/node/tool/src/node_tool.rs b/crates/node/tool/src/node_tool.rs index 8174193dc38..6988cbea859 100644 --- a/crates/node/tool/src/node_tool.rs +++ b/crates/node/tool/src/node_tool.rs @@ -113,14 +113,16 @@ impl NodeTool { _ => { let mut cmd = Command::new(self.get_npx_path()?); cmd.args(["--silent", "--", package]); - cmd.env( - "PATH", - prepend_path_env_var(get_node_env_paths(&self.proto_env)), - ); cmd.env( "PROTO_NODE_VERSION", self.tool.get_resolved_version().to_string(), ); + if !self.global { + cmd.env( + "PATH", + prepend_path_env_var(get_node_env_paths(&self.proto_env)), + ); + } cmd } }; diff --git a/crates/node/tool/src/npm_tool.rs b/crates/node/tool/src/npm_tool.rs index 50a046180f6..171f3b8741b 100644 --- a/crates/node/tool/src/npm_tool.rs +++ b/crates/node/tool/src/npm_tool.rs @@ -114,22 +114,22 @@ impl DependencyManager for NpmTool { fn create_command(&self, node: &NodeTool) -> miette::Result { let mut cmd = Command::new("npm"); - cmd.env( - "PATH", - prepend_path_env_var(get_node_env_paths(&self.proto_env)), - ); - if !self.global { cmd.env( - "PROTO_NPM_VERSION", - self.tool.get_resolved_version().to_string(), - ); - cmd.env( - "PROTO_NODE_VERSION", - node.tool.get_resolved_version().to_string(), + "PATH", + prepend_path_env_var(get_node_env_paths(&self.proto_env)), ); } + cmd.env( + "PROTO_NPM_VERSION", + self.tool.get_resolved_version().to_string(), + ); + cmd.env( + "PROTO_NODE_VERSION", + node.tool.get_resolved_version().to_string(), + ); + Ok(cmd) } diff --git a/crates/node/tool/src/pnpm_tool.rs b/crates/node/tool/src/pnpm_tool.rs index 16d2187abbe..4d0629ec830 100644 --- a/crates/node/tool/src/pnpm_tool.rs +++ b/crates/node/tool/src/pnpm_tool.rs @@ -122,22 +122,22 @@ impl DependencyManager for PnpmTool { fn create_command(&self, node: &NodeTool) -> miette::Result { let mut cmd = Command::new("pnpm"); - cmd.env( - "PATH", - prepend_path_env_var(get_node_env_paths(&self.proto_env)), - ); - if !self.global { cmd.env( - "PROTO_PNPM_VERSION", - self.tool.get_resolved_version().to_string(), - ); - cmd.env( - "PROTO_NODE_VERSION", - node.tool.get_resolved_version().to_string(), + "PATH", + prepend_path_env_var(get_node_env_paths(&self.proto_env)), ); } + cmd.env( + "PROTO_PNPM_VERSION", + self.tool.get_resolved_version().to_string(), + ); + cmd.env( + "PROTO_NODE_VERSION", + node.tool.get_resolved_version().to_string(), + ); + Ok(cmd) } diff --git a/crates/node/tool/src/yarn_tool.rs b/crates/node/tool/src/yarn_tool.rs index 06d0c130abc..641507cffb9 100644 --- a/crates/node/tool/src/yarn_tool.rs +++ b/crates/node/tool/src/yarn_tool.rs @@ -184,22 +184,22 @@ impl DependencyManager for YarnTool { fn create_command(&self, node: &NodeTool) -> miette::Result { let mut cmd = Command::new("yarn"); - cmd.env( - "PATH", - prepend_path_env_var(get_node_env_paths(&self.proto_env)), - ); - if !self.global { cmd.env( - "PROTO_YARN_VERSION", - self.tool.get_resolved_version().to_string(), - ); - cmd.env( - "PROTO_NODE_VERSION", - node.tool.get_resolved_version().to_string(), + "PATH", + prepend_path_env_var(get_node_env_paths(&self.proto_env)), ); } + cmd.env( + "PROTO_YARN_VERSION", + self.tool.get_resolved_version().to_string(), + ); + cmd.env( + "PROTO_NODE_VERSION", + node.tool.get_resolved_version().to_string(), + ); + Ok(cmd) } diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index 34d74c76ea1..a3bf81290e2 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -21,7 +21,7 @@ use moon_rust_lang::{ use moon_rust_tool::{get_rust_env_paths, RustTool}; use moon_task::Task; use moon_terminal::{print_checkpoint, Checkpoint}; -use moon_tool::{Tool, ToolManager}; +use moon_tool::{prepend_path_env_var, Tool, ToolManager}; use moon_utils::async_trait; use proto_core::ProtoEnvironment; use rustc_hash::FxHashMap; @@ -505,7 +505,7 @@ impl Platform for RustPlatform { _project: &Project, task: &Task, runtime: &Runtime, - working_dir: &Path, + _working_dir: &Path, ) -> miette::Result { let mut command = Command::new(&task.command); let mut args = vec![]; @@ -534,16 +534,14 @@ impl Platform for RustPlatform { } } - command - .args(&args) - .args(&task.args) - .envs(&task.env) - .cwd(working_dir); + command.args(&args); + command.args(&task.args); + command.envs(&task.env); + command.env( + "PATH", + prepend_path_env_var(get_rust_env_paths(&self.proto_env)), + ); Ok(command) } - - fn get_run_target_paths(&self, _working_dir: &Path) -> Vec { - get_rust_env_paths(&self.proto_env) - } } diff --git a/crates/system/platform/src/system_platform.rs b/crates/system/platform/src/system_platform.rs index c61a7ff1606..e38f92eda9e 100644 --- a/crates/system/platform/src/system_platform.rs +++ b/crates/system/platform/src/system_platform.rs @@ -7,7 +7,7 @@ use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; -use moon_tool::{get_proto_paths, Tool}; +use moon_tool::{get_proto_paths, prepend_path_env_var, Tool}; use moon_utils::async_trait; use proto_core::ProtoEnvironment; use std::path::{Path, PathBuf}; @@ -86,7 +86,7 @@ impl Platform for SystemPlatform { _context: &ActionContext, _project: &Project, task: &Task, - _runtime: &Runtime, + runtime: &Runtime, working_dir: &Path, ) -> miette::Result { let mut command = Command::new(&task.command); @@ -108,10 +108,13 @@ impl Platform for SystemPlatform { command.envs(&task.env); - Ok(command) - } + if !runtime.requirement.is_global() { + command.env( + "PATH", + prepend_path_env_var(get_proto_paths(&self.proto_env)), + ); + } - fn get_run_target_paths(&self, _working_dir: &Path) -> Vec { - get_proto_paths(&self.proto_env) + Ok(command) } }