diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2cf382cb..89a8a059 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -137,7 +137,6 @@ jobs: - name: Install wasmtime run: | curl https://wasmtime.dev/install.sh -sSf | bash - source ~/.bashrc - uses: actions/cache@v3 with: diff --git a/crates/history/Cargo.toml b/crates/history/Cargo.toml index bb44afc1..b9b5ba90 100644 --- a/crates/history/Cargo.toml +++ b/crates/history/Cargo.toml @@ -12,7 +12,6 @@ categories = ["api-bindings", "history", "wasm"] rust-version = "1.64" [dependencies] -wasm-bindgen = "0.2" gloo-utils = { version = "0.2.0", path = "../utils" } gloo-events = { version = "0.2.0", path = "../events" } serde = { version = "1", features = ["derive"] } @@ -20,7 +19,10 @@ serde-wasm-bindgen = "0.6.0" serde_urlencoded = { version = "0.7", optional = true } thiserror = { version = "1.0", optional = true } -[dependencies.web-sys] +[target.'cfg(not(target_os = "wasi"))'.dependencies] +wasm-bindgen = "0.2" + +[target.'cfg(not(target_os = "wasi"))'.dependencies.web-sys] version = "0.3" features = ["History", "Window", "Location", "Url"] diff --git a/crates/history/src/any.rs b/crates/history/src/any.rs index 74e9ec43..288325c5 100644 --- a/crates/history/src/any.rs +++ b/crates/history/src/any.rs @@ -1,6 +1,8 @@ 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; @@ -13,8 +15,10 @@ 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), @@ -23,7 +27,9 @@ 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(), } @@ -31,7 +37,9 @@ 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), } @@ -39,7 +47,9 @@ 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), } @@ -47,7 +57,9 @@ 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), } @@ -58,7 +70,9 @@ 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), } @@ -69,7 +83,9 @@ 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), } @@ -85,7 +101,9 @@ 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), } @@ -100,7 +118,9 @@ 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), } @@ -118,7 +138,9 @@ 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), } @@ -136,7 +158,9 @@ 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), } @@ -147,7 +171,9 @@ 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), } @@ -155,19 +181,23 @@ 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 9f508808..7d5777ff 100644 --- a/crates/history/src/lib.rs +++ b/crates/history/src/lib.rs @@ -4,9 +4,11 @@ #![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; @@ -18,7 +20,9 @@ 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; diff --git a/crates/history/src/state.rs b/crates/history/src/state.rs index 255c5ced..7386a421 100644 --- a/crates/history/src/state.rs +++ b/crates/history/src/state.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_os = "wasi"))] + use std::any::Any; use std::collections::HashMap; use std::rc::Rc;