diff --git a/CHANGELOG.md b/CHANGELOG.md index 91de0438..3815f6d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ - [Rust](https://github.com/moonrepo/tools/blob/master/tools/rust/CHANGELOG.md) - [Schema (TOML, JSON, YAML)](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md) +## Unreleased + +#### 🐞 Fixes + +- Fixed an issue where the globals directory may not exist for the `pre_run` hook. +- Fixed invalid Nushell syntax generated from `proto activate`. + ## 0.43.1 #### 🐞 Fixes diff --git a/Cargo.lock b/Cargo.lock index a1f368b4..f926762e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3680,9 +3680,9 @@ dependencies = [ [[package]] name = "starbase_shell" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b06f785e095de34294b82e5f81b3501734f9d5f8959a829c5d6b268e2a2db9f" +checksum = "2d7e46a3a3138225aa6b2efa124bd7694ec55084efb010903ccb2621c1339f4f" dependencies = [ "miette 7.4.0", "regex", diff --git a/Cargo.toml b/Cargo.toml index 5b88fe2a..37ba36da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ starbase_archive = { version = "0.9.0", features = [ ] } starbase_events = { version = "0.6.3" } starbase_sandbox = { version = "0.8.0" } -starbase_shell = { version = "0.6.6", features = ["miette"] } +starbase_shell = { version = "0.6.7", features = ["miette"] } starbase_styles = { version = "0.4.7" } starbase_utils = { version = "0.9.1", default-features = false, features = [ "json", diff --git a/crates/cli/src/commands/run.rs b/crates/cli/src/commands/run.rs index 3a30fa97..7a3ea33e 100644 --- a/crates/cli/src/commands/run.rs +++ b/crates/cli/src/commands/run.rs @@ -8,6 +8,7 @@ use proto_core::{detect_version, Id, ProtoError, Tool, UnresolvedVersionSpec}; use proto_pdk_api::{ExecutableConfig, RunHook, RunHookResult}; use proto_shim::exec_command_and_replace; use starbase::AppResult; +use starbase_utils::fs; use std::env; use std::ffi::OsStr; use std::process::Command; @@ -214,6 +215,11 @@ pub async fn run(session: ProtoSession, args: RunArgs) -> AppResult { let globals_dir = tool.locate_globals_dir().await?; let globals_prefix = tool.locate_globals_prefix().await?; + // Ensure directory exists as some tools require it + if let Some(dir) = &globals_dir { + let _ = fs::create_dir_all(dir); + } + tool.plugin .call_func_with( "pre_run", diff --git a/crates/cli/tests/snapshots/activate_test__activate__supports_json_exports.snap b/crates/cli/tests/snapshots/activate_test__activate__supports_json_exports.snap index 48edecfc..bc0cce88 100644 --- a/crates/cli/tests/snapshots/activate_test__activate__supports_json_exports.snap +++ b/crates/cli/tests/snapshots/activate_test__activate__supports_json_exports.snap @@ -9,17 +9,16 @@ def _proto_activate_hook [] { $data | get env | items { |k, v| if $v == null { - hide_env $k + hide-env $k } else { load-env { ($k): $v } } } - let path_list = $env.__ORIG_PATH | split row (char esep) - - $data | get paths | reverse | each { |p| - let path_list = ($path_list | prepend $p) - } + let path_list = [ + ...($data | get paths | default []) + ...($env.__ORIG_PATH | split row (char esep)) + ]; $env.PATH = ($path_list | uniq) } diff --git a/crates/cli/tests/snapshots/outdated_test__outdated__updates_each_file_respectively.snap b/crates/cli/tests/snapshots/outdated_test__outdated__updates_each_file_respectively.snap index 94883595..4c269668 100644 --- a/crates/cli/tests/snapshots/outdated_test__outdated__updates_each_file_respectively.snap +++ b/crates/cli/tests/snapshots/outdated_test__outdated__updates_each_file_respectively.snap @@ -1,9 +1,9 @@ --- source: crates/cli/tests/outdated_test.rs -expression: "vec![fs::read_to_string(sandbox.path().join(\".proto/.prototools\")).unwrap(),\n fs::read_to_string(sandbox.path().join(\"a/.prototools\")).unwrap(),\n fs::read_to_string(sandbox.path().join(\"a/b/.prototools\")).unwrap(),]" +expression: "vec![fs::read_to_string(sandbox.path().join(\".proto/.prototools\")).unwrap(),\nfs::read_to_string(sandbox.path().join(\"a/.prototools\")).unwrap(),\nfs::read_to_string(sandbox.path().join(\"a/b/.prototools\")).unwrap(),]" --- [ "go = \"1.19.13\"\n", "node = \"19.9.0\"\n", - "npm = \"9.9.3\"\n", + "npm = \"9.9.4\"\n", ] diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index 5c257052..3e7b3453 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -32,7 +32,11 @@ pub struct ProtoEnvironment { impl ProtoEnvironment { pub fn new() -> miette::Result { let home = home_dir().ok_or(ProtoError::MissingHomeDir)?; - let root = path_var("PROTO_HOME").unwrap_or_else(|| home.join(".proto")); + let mut root = path_var("PROTO_HOME").unwrap_or_else(|| home.join(".proto")); + + if let Ok(rel_root) = root.strip_prefix("~") { + root = home.join(rel_root); + } Self::from(root, home) }