Skip to content

Commit

Permalink
support WASI by tweaking cfg attributes (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
zebp committed Jan 26, 2022
1 parent 297224b commit e6e71a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ string_cache_codegen = "0.5"
[features]
node = ["napi", "napi-derive", "napi-build"]

[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(target = "wasm32-unknown-unknown")'.dependencies]
chrono = { version = "0.4", features = ["wasmbind"] }
js-sys = "0.3"
serde-wasm-bindgen = "0.3"
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(target = "wasm32-unknown-unknown"))'.dependencies]
chrono = "0.4"

[patch.crates-io]
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@

use parser::parse_browserslist_query;
use std::cmp::Ordering;
#[cfg(target_arch = "wasm32")]
#[cfg(target = "wasm32-unknown-unknown")]
pub use wasm::browserslist;
pub use {error::Error, opts::Opts, queries::Distrib};

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target = "wasm32-unknown-unknown"))]
mod config;
mod data;
mod error;
Expand All @@ -84,7 +84,7 @@ mod queries;
mod semver;
#[cfg(test)]
mod test;
#[cfg(target_arch = "wasm32")]
#[cfg(target = "wasm32-unknown-unknown")]
mod wasm;

/// Resolve browserslist queries.
Expand Down Expand Up @@ -168,7 +168,7 @@ where
/// // when no config found, it use `defaults` query
/// assert!(!execute(&Opts::new()).unwrap().is_empty());
/// ```
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target = "wasm32-unknown-unknown"))]
pub fn execute(opts: &Opts) -> Result<Vec<Distrib>, Error> {
resolve(config::load(opts)?, opts)
}
4 changes: 2 additions & 2 deletions src/queries/browserslist_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use super::QueryResult;
use crate::opts::Opts;

pub(super) fn browserslist_config(opts: &Opts) -> QueryResult {
#[cfg(target_arch = "wasm32")]
#[cfg(target = "wasm32-unknown-unknown")]
{
crate::resolve(["defaults"], opts)
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target = "wasm32-unknown-unknown"))]
{
crate::execute(opts)
}
Expand Down
6 changes: 3 additions & 3 deletions src/queries/current_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{Distrib, QueryResult};
use crate::error::Error;

pub(super) fn current_node() -> QueryResult {
#[cfg(target_arch = "wasm32")]
#[cfg(target = "wasm32-unknown-unknown")]
{
use js_sys::{global, Reflect};

Expand All @@ -17,7 +17,7 @@ pub(super) fn current_node() -> QueryResult {
Ok(vec![Distrib::new("node", version)])
}

#[cfg(all(not(target_arch = "wasm32"), feature = "node"))]
#[cfg(all(not(target = "wasm32-unknown-unknown"), feature = "node"))]
{
use crate::node::CURRENT_NODE;

Expand All @@ -28,7 +28,7 @@ pub(super) fn current_node() -> QueryResult {
)])
}

#[cfg(all(not(target_arch = "wasm32"), not(feature = "node")))]
#[cfg(all(not(target = "wasm32-unknown-unknown"), not(feature = "node")))]
{
use std::process::Command;

Expand Down

0 comments on commit e6e71a7

Please sign in to comment.