From 192683c92999124f17405dd5c148083a5d857f11 Mon Sep 17 00:00:00 2001 From: Micaiah Reid Date: Fri, 13 Feb 2026 16:29:07 -0500 Subject: [PATCH] fix(kit): gate dirs dep behind feature gate to fix wasm build --- Cargo.lock | 1 + crates/txtx-addon-kit/Cargo.toml | 7 +++++-- crates/txtx-addon-kit/src/types/mod.rs | 16 ++++++++++++++-- crates/txtx-addon-kit/src/types/tests/mod.rs | 9 +++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1917f456..ebee16bc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10461,6 +10461,7 @@ dependencies = [ "dyn-clone", "ed25519-dalek-bip32", "futures", + "getrandom 0.2.15", "hcl-edit", "hex", "highway", diff --git a/crates/txtx-addon-kit/Cargo.toml b/crates/txtx-addon-kit/Cargo.toml index 59c2e3708..64420fbb6 100644 --- a/crates/txtx-addon-kit/Cargo.toml +++ b/crates/txtx-addon-kit/Cargo.toml @@ -35,15 +35,18 @@ hmac = "0.12.0" pbkdf2 = { version = "0.12.2", features = ["simple"], default-features = false } libsecp256k1 = { version = "0.7.0" } keccak-hash = "0.11.0" -dirs = "5.0.1" +dirs = { version = "5.0.1", optional = true } dyn-clone = "1" [dev-dependencies] test-case = "3.3" hiro-system-kit = "0.3.4" +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2", features = ["js"] } + [features] -default=[] +default = ["dirs"] wasm = [] [lib] diff --git a/crates/txtx-addon-kit/src/types/mod.rs b/crates/txtx-addon-kit/src/types/mod.rs index ebd92bc5c..f774ba2b2 100644 --- a/crates/txtx-addon-kit/src/types/mod.rs +++ b/crates/txtx-addon-kit/src/types/mod.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +#[cfg(feature = "dirs")] use std::env; use std::fmt::Display; use std::path::PathBuf; @@ -323,8 +324,18 @@ impl AuthorizationContext { let path_str = input.to_string_lossy(); let loc = if let Some(stripped) = path_str.strip_prefix("~/") { - let home = PathBuf::from(get_home_dir()); - FileLocation::from_path(home.join(stripped)) + #[cfg(feature = "dirs")] + { + let home = PathBuf::from(get_home_dir()); + FileLocation::from_path(home.join(stripped)) + } + #[cfg(not(feature = "dirs"))] + { + let _ = stripped; + return Err( + "Home directory expansion (~/) is not supported in this build".to_string(), + ); + } } // If absolute, use as-is else if input.is_absolute() { @@ -349,6 +360,7 @@ impl AuthorizationContext { /// We set out snap build to set this environment variable to the real home directory, /// because by default, snaps run in a confined environment where the home directory is not /// the user's actual home directory. +#[cfg(feature = "dirs")] fn get_home_dir() -> String { if let Ok(real_home) = env::var("SNAP_REAL_HOME") { let path_buf = PathBuf::from(real_home); diff --git a/crates/txtx-addon-kit/src/types/tests/mod.rs b/crates/txtx-addon-kit/src/types/tests/mod.rs index a357fbd56..e9f8f7932 100644 --- a/crates/txtx-addon-kit/src/types/tests/mod.rs +++ b/crates/txtx-addon-kit/src/types/tests/mod.rs @@ -61,7 +61,16 @@ fn it_rejects_invalid_keys() { } } +#[cfg(feature = "dirs")] #[test_case("~/home/path", dirs::home_dir().unwrap().join("home/path").to_str().unwrap())] +fn test_auth_context_get_path_from_str_home(path_str: &str, expected: &str) { + let auth_context = AuthorizationContext::new(FileLocation::from_path( + Path::new("/workspace/txtx.yml").to_path_buf(), + )); + let result = auth_context.get_file_location_from_path_buf(&PathBuf::from(path_str)).unwrap(); + assert_eq!(result.to_string(), expected); +} + #[test_case("/absolute/path", "/absolute/path")] #[test_case("./relative/path", "/workspace/./relative/path"; "current directory")] #[test_case("../relative/path", "/workspace/../relative/path"; "parent directory")]