Skip to content

Commit

Permalink
Remove need to depend on js-sys when consuming errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Nov 22, 2024
1 parent 3cdf320 commit 4c82241
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ secrets = [] # Secrets manager API
wasm = [
"bitwarden-error/wasm",
"dep:wasm-bindgen",
"dep:js-sys",
"dep:tsify-next",
] # WASM support

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-error-macro/src/basic/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-error-macro/src/flat/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions crates/bitwarden-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down

0 comments on commit 4c82241

Please sign in to comment.