Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Update depman.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 21, 2023
1 parent 0213419 commit a8312fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
16 changes: 16 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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
}
7 changes: 4 additions & 3 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -393,6 +393,7 @@ pub fn pre_run(Json(input): Json<RunHook>) -> FnResult<()> {

#[plugin_fn]
pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBinsOutput>> {
let env = get_proto_environment()?;
let mut bin_path = None;
let package_path = input.context.tool_dir.join("package.json");
let manager = PackageManager::detect();
Expand Down Expand Up @@ -436,7 +437,7 @@ pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBi
Ok(Json(LocateBinsOutput {
bin_path: bin_path.map(PathBuf::from),
fallback_last_globals_dir: true,
globals_lookup_dirs: vec!["$PROTO_HOME/tools/node/globals/bin".into()],
globals_lookup_dirs: get_globals_dirs(&env),
..LocateBinsOutput::default()
}))
}
Expand Down
16 changes: 1 addition & 15 deletions crates/node/src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use extism_pdk::*;
use node_common::{commands, NodeDistLTS, NodeDistVersion, PackageJson};
use node_common::{commands, get_globals_dirs, NodeDistLTS, NodeDistVersion, PackageJson};
use proto_pdk::*;

#[host_fn]
Expand Down Expand Up @@ -199,20 +199,6 @@ pub fn download_prebuilt(
}))
}

pub fn get_globals_dirs(env: &HostEnvironment) -> Vec<String> {
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<LocateExecutablesInput>,
Expand Down

0 comments on commit a8312fd

Please sign in to comment.