From a8312fde1b13904af0b2a5027137d572a4a1728f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 20 Nov 2023 16:45:18 -0800 Subject: [PATCH] Update depman. --- crates/common/src/lib.rs | 16 ++++++++++++++++ crates/node-depman/src/proto.rs | 7 ++++--- crates/node/src/proto.rs | 16 +--------------- 3 files changed, 21 insertions(+), 18 deletions(-) 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,