From 4c822419c16a4accb29717e2bdde6e04eb360757 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 22 Nov 2024 09:30:24 +0100 Subject: [PATCH] Remove need to depend on js-sys when consuming errors --- Cargo.lock | 1 - crates/bitwarden-core/Cargo.toml | 2 -- crates/bitwarden-error-macro/src/basic/attribute.rs | 2 +- crates/bitwarden-error-macro/src/flat/attribute.rs | 2 +- crates/bitwarden-error/Cargo.toml | 3 ++- crates/bitwarden-error/src/lib.rs | 4 ++++ 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39ecb28b..f41be3aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,7 +357,6 @@ dependencies = [ "chrono", "getrandom", "hmac", - "js-sys", "log", "rand", "rand_chacha", diff --git a/crates/bitwarden-core/Cargo.toml b/crates/bitwarden-core/Cargo.toml index 88fb7916..fe1c6a1c 100644 --- a/crates/bitwarden-core/Cargo.toml +++ b/crates/bitwarden-core/Cargo.toml @@ -23,7 +23,6 @@ secrets = [] # Secrets manager API wasm = [ "bitwarden-error/wasm", "dep:wasm-bindgen", - "dep:js-sys", "dep:tsify-next", ] # WASM support @@ -54,7 +53,6 @@ wasm-bindgen = { workspace = true, optional = true } zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] } zxcvbn = { version = ">=3.0.1, <4.0", optional = true } tsify-next = { workspace = true, optional = true } -js-sys = { workspace = true, optional = true } bitwarden-error = { workspace = true } [target.'cfg(not(target_arch="wasm32"))'.dependencies] diff --git a/crates/bitwarden-error-macro/src/basic/attribute.rs b/crates/bitwarden-error-macro/src/basic/attribute.rs index b060517f..aa050672 100644 --- a/crates/bitwarden-error-macro/src/basic/attribute.rs +++ b/crates/bitwarden-error-macro/src/basic/attribute.rs @@ -43,7 +43,7 @@ fn basic_error_wasm( #[wasm_bindgen(js_name = #is_error_function_name, skip_typescript)] pub fn is_error(error: &JsValue) -> bool { - let name_js_value = js_sys::Reflect::get(&error, &JsValue::from_str("name")).unwrap_or(JsValue::NULL); + let name_js_value = bitwarden_error::js_sys::Reflect::get(&error, &JsValue::from_str("name")).unwrap_or(JsValue::NULL); let name = name_js_value.as_string().unwrap_or_default(); name == #export_as_identifier_str } diff --git a/crates/bitwarden-error-macro/src/flat/attribute.rs b/crates/bitwarden-error-macro/src/flat/attribute.rs index b77791fa..ea71b35f 100644 --- a/crates/bitwarden-error-macro/src/flat/attribute.rs +++ b/crates/bitwarden-error-macro/src/flat/attribute.rs @@ -96,7 +96,7 @@ fn flat_error_wasm( #[wasm_bindgen(js_name = #is_error_function_name, skip_typescript)] pub fn is_error(error: &JsValue) -> bool { - let name_js_value = js_sys::Reflect::get(&error, &JsValue::from_str("name")).unwrap_or(JsValue::NULL); + let name_js_value = bitwarden_error::js_sys::Reflect::get(&error, &JsValue::from_str("name")).unwrap_or(JsValue::NULL); let name = name_js_value.as_string().unwrap_or_default(); name == #export_as_identifier_str } diff --git a/crates/bitwarden-error/Cargo.toml b/crates/bitwarden-error/Cargo.toml index 17fd9fdd..cea59d1d 100644 --- a/crates/bitwarden-error/Cargo.toml +++ b/crates/bitwarden-error/Cargo.toml @@ -10,10 +10,11 @@ license-file.workspace = true keywords.workspace = true [features] -wasm = ["bitwarden-error-macro/wasm", "dep:wasm-bindgen"] +wasm = ["bitwarden-error-macro/wasm", "dep:js-sys", "dep:wasm-bindgen"] [dependencies] bitwarden-error-macro = { workspace = true } +js-sys = { workspace = true, optional = true } wasm-bindgen = { workspace = true, optional = true } [lints] diff --git a/crates/bitwarden-error/src/lib.rs b/crates/bitwarden-error/src/lib.rs index 0eb32f24..d6793c06 100644 --- a/crates/bitwarden-error/src/lib.rs +++ b/crates/bitwarden-error/src/lib.rs @@ -3,6 +3,10 @@ pub mod flat_error; #[cfg(feature = "wasm")] pub mod wasm; +/// Re-export the `js_sys` crate since the proc macro depends on it. +#[cfg(feature = "wasm")] +pub use ::js_sys; + pub mod prelude { pub use bitwarden_error_macro::*;