diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 2391104..8627a99 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -4,3 +4,19 @@ mod package_json; pub use node_dist::*; pub use package_json::*; + +use proto_pdk_api::HostEnvironment; + +pub fn get_globals_dirs(env: &HostEnvironment) -> Vec { + let mut dirs = vec![]; + + // Windows for some reason removes the /bin suffix when installing into it, + // so we also need to account for the path without /bin. But keep the /bin path + // as the final path and for the install to trigger correctly. + if env.os.is_windows() { + dirs.push("$PROTO_HOME/tools/node/globals".into()); + } + + dirs.push("$PROTO_HOME/tools/node/globals/bin".into()); + dirs +} diff --git a/crates/node-depman/src/proto.rs b/crates/node-depman/src/proto.rs index 94c8709..751db2b 100644 --- a/crates/node-depman/src/proto.rs +++ b/crates/node-depman/src/proto.rs @@ -1,7 +1,7 @@ use crate::npm_registry::parse_registry_response; use crate::package_manager::PackageManager; use extism_pdk::*; -use node_common::{commands, BinField, NodeDistVersion, PackageJson}; +use node_common::{commands, get_globals_dirs, BinField, NodeDistVersion, PackageJson}; use proto_pdk::*; use std::collections::HashMap; use std::fs; @@ -310,7 +310,7 @@ pub fn locate_executables( }; Ok(Json(LocateExecutablesOutput { - globals_lookup_dirs: vec!["$PROTO_HOME/tools/node/globals/bin".into()], + globals_lookup_dirs: get_globals_dirs(&env), primary: Some(primary), secondary, ..LocateExecutablesOutput::default() @@ -393,6 +393,7 @@ pub fn pre_run(Json(input): Json) -> FnResult<()> { #[plugin_fn] pub fn locate_bins(Json(input): Json) -> FnResult> { + let env = get_proto_environment()?; let mut bin_path = None; let package_path = input.context.tool_dir.join("package.json"); let manager = PackageManager::detect(); @@ -436,7 +437,7 @@ pub fn locate_bins(Json(input): Json) -> FnResult Vec { - let mut dirs = vec![]; - - // Windows for some reason removes the /bin suffix when installing into it, - // so we also need to account for the path without /bin. But keep the /bin path - // as the final path and for the install to trigger correctly. - if env.os == HostOS::Windows { - dirs.push("$PROTO_HOME/tools/node/globals".into()); - } - - dirs.push("$PROTO_HOME/tools/node/globals/bin".into()); - dirs -} - #[plugin_fn] pub fn locate_executables( Json(_): Json,