From cf4c5b34e7ddcbb9ab0345150a623e5b5dad9790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Sun, 10 Dec 2023 10:49:22 +0800 Subject: [PATCH 1/5] Remove the flags what to expect WASI targets. --- crates/history/src/any.rs | 42 +++++++++++---------------------------- crates/history/src/lib.rs | 4 ---- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/crates/history/src/any.rs b/crates/history/src/any.rs index 288325c5..8313ea89 100644 --- a/crates/history/src/any.rs +++ b/crates/history/src/any.rs @@ -1,8 +1,6 @@ use std::borrow::Cow; -#[cfg(not(target_os = "wasi"))] use crate::browser::BrowserHistory; -#[cfg(not(target_os = "wasi"))] use crate::hash::HashHistory; use crate::history::History; use crate::listener::HistoryListener; @@ -15,10 +13,8 @@ use crate::{error::HistoryResult, query::ToQuery}; #[derive(Clone, PartialEq, Debug)] pub enum AnyHistory { /// A Browser History. - #[cfg(not(target_os = "wasi"))] Browser(BrowserHistory), /// A Hash History - #[cfg(not(target_os = "wasi"))] Hash(HashHistory), /// A Memory History Memory(MemoryHistory), @@ -27,9 +23,8 @@ pub enum AnyHistory { impl History for AnyHistory { fn len(&self) -> usize { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.len(), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.len(), Self::Memory(m) => m.len(), } @@ -37,9 +32,8 @@ impl History for AnyHistory { fn go(&self, delta: isize) { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.go(delta), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.go(delta), Self::Memory(m) => m.go(delta), } @@ -47,9 +41,8 @@ impl History for AnyHistory { fn push<'a>(&self, route: impl Into>) { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.push(route), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.push(route), Self::Memory(m) => m.push(route), } @@ -57,9 +50,8 @@ impl History for AnyHistory { fn replace<'a>(&self, route: impl Into>) { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.replace(route), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.replace(route), Self::Memory(m) => m.replace(route), } @@ -70,9 +62,8 @@ impl History for AnyHistory { T: 'static, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.push_with_state(route, state), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.push_with_state(route, state), Self::Memory(m) => m.push_with_state(route, state), } @@ -83,9 +74,8 @@ impl History for AnyHistory { T: 'static, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.replace_with_state(route, state), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.replace_with_state(route, state), Self::Memory(m) => m.replace_with_state(route, state), } @@ -101,9 +91,8 @@ impl History for AnyHistory { Q: ToQuery, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.push_with_query(route, query), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.push_with_query(route, query), Self::Memory(m) => m.push_with_query(route, query), } @@ -118,9 +107,8 @@ impl History for AnyHistory { Q: ToQuery, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.replace_with_query(route, query), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.replace_with_query(route, query), Self::Memory(m) => m.replace_with_query(route, query), } @@ -138,9 +126,8 @@ impl History for AnyHistory { T: 'static, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.push_with_query_and_state(route, query, state), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.push_with_query_and_state(route, query, state), Self::Memory(m) => m.push_with_query_and_state(route, query, state), } @@ -158,9 +145,8 @@ impl History for AnyHistory { T: 'static, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.replace_with_query_and_state(route, query, state), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.replace_with_query_and_state(route, query, state), Self::Memory(m) => m.replace_with_query_and_state(route, query, state), } @@ -171,9 +157,8 @@ impl History for AnyHistory { CB: Fn() + 'static, { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.listen(callback), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.listen(callback), Self::Memory(m) => m.listen(callback), } @@ -181,23 +166,20 @@ impl History for AnyHistory { fn location(&self) -> Location { match self { - #[cfg(not(target_os = "wasi"))] Self::Browser(m) => m.location(), - #[cfg(not(target_os = "wasi"))] + Self::Hash(m) => m.location(), Self::Memory(m) => m.location(), } } } -#[cfg(not(target_os = "wasi"))] impl From for AnyHistory { fn from(m: BrowserHistory) -> AnyHistory { AnyHistory::Browser(m) } } -#[cfg(not(target_os = "wasi"))] impl From for AnyHistory { fn from(m: HashHistory) -> AnyHistory { AnyHistory::Hash(m) diff --git a/crates/history/src/lib.rs b/crates/history/src/lib.rs index 7d5777ff..9f508808 100644 --- a/crates/history/src/lib.rs +++ b/crates/history/src/lib.rs @@ -4,11 +4,9 @@ #![deny(missing_docs, missing_debug_implementations)] mod any; -#[cfg(not(target_os = "wasi"))] mod browser; #[cfg(feature = "query")] mod error; -#[cfg(not(target_os = "wasi"))] mod hash; mod history; mod listener; @@ -20,9 +18,7 @@ mod state; mod utils; pub use any::AnyHistory; -#[cfg(not(target_os = "wasi"))] pub use browser::BrowserHistory; -#[cfg(not(target_os = "wasi"))] pub use hash::HashHistory; pub use memory::MemoryHistory; From a2944cb498e5a312b5af65cdde75dd12ec65de1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Sun, 10 Dec 2023 11:00:56 +0800 Subject: [PATCH 2/5] Try to fix web_sys imports. --- crates/history/Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/history/Cargo.toml b/crates/history/Cargo.toml index b9b5ba90..cda180dd 100644 --- a/crates/history/Cargo.toml +++ b/crates/history/Cargo.toml @@ -18,11 +18,9 @@ serde = { version = "1", features = ["derive"] } serde-wasm-bindgen = "0.6.0" serde_urlencoded = { version = "0.7", optional = true } thiserror = { version = "1.0", optional = true } - -[target.'cfg(not(target_os = "wasi"))'.dependencies] wasm-bindgen = "0.2" -[target.'cfg(not(target_os = "wasi"))'.dependencies.web-sys] +[dependencies.web-sys] version = "0.3" features = ["History", "Window", "Location", "Url"] From af7f4a0190f29c00d8f9c04e4b3667f58e9e359b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Sun, 10 Dec 2023 11:05:11 +0800 Subject: [PATCH 3/5] Fix pub mod. --- crates/history/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/history/src/lib.rs b/crates/history/src/lib.rs index 9f508808..dcae6d76 100644 --- a/crates/history/src/lib.rs +++ b/crates/history/src/lib.rs @@ -14,7 +14,7 @@ mod location; mod memory; #[cfg(feature = "query")] pub mod query; -mod state; +pub(crate) mod state; mod utils; pub use any::AnyHistory; From f623f9d4cfaf58e7c6f721da899957916e8313c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Sun, 10 Dec 2023 13:09:08 +0800 Subject: [PATCH 4/5] Remove macro on the header. It's my fault... --- crates/history/src/lib.rs | 2 +- crates/history/src/state.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/history/src/lib.rs b/crates/history/src/lib.rs index dcae6d76..9f508808 100644 --- a/crates/history/src/lib.rs +++ b/crates/history/src/lib.rs @@ -14,7 +14,7 @@ mod location; mod memory; #[cfg(feature = "query")] pub mod query; -pub(crate) mod state; +mod state; mod utils; pub use any::AnyHistory; diff --git a/crates/history/src/state.rs b/crates/history/src/state.rs index 7386a421..255c5ced 100644 --- a/crates/history/src/state.rs +++ b/crates/history/src/state.rs @@ -1,5 +1,3 @@ -#![cfg(not(target_os = "wasi"))] - use std::any::Any; use std::collections::HashMap; use std::rc::Rc; From 7cd71ba6b24ffda9c7e8e99a3c818e18e89b3962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Sun, 10 Dec 2023 13:58:31 +0800 Subject: [PATCH 5/5] Update crates/history/Cargo.toml Co-authored-by: Kaede Hoshikawa --- crates/history/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/history/Cargo.toml b/crates/history/Cargo.toml index cda180dd..4a755afc 100644 --- a/crates/history/Cargo.toml +++ b/crates/history/Cargo.toml @@ -18,7 +18,7 @@ serde = { version = "1", features = ["derive"] } serde-wasm-bindgen = "0.6.0" serde_urlencoded = { version = "0.7", optional = true } thiserror = { version = "1.0", optional = true } -wasm-bindgen = "0.2" +wasm-bindgen = "0.2.88" [dependencies.web-sys] version = "0.3"