diff --git a/src/manifest.rs b/src/manifest.rs index 36e69dfe..2cc39193 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -1,5 +1,6 @@ //! Reading and writing Cargo.toml and package.json manifests. +use std::collections::HashMap; use std::fs::File; use std::io::prelude::*; use std::path::Path; @@ -15,7 +16,7 @@ use PBAR; #[derive(Deserialize)] struct CargoManifest { package: CargoPackage, - dependencies: Option, + dependencies: Option>, lib: Option, } @@ -30,11 +31,15 @@ struct CargoPackage { } #[derive(Deserialize)] -struct CargoDependencies { - #[serde(rename = "wasm-bindgen")] - wasm_bindgen: Option, +#[serde(untagged)] +enum CargoDependency { + Simple(String), + Detailed(DetailedCargoDependency), } +#[derive(Deserialize)] +struct DetailedCargoDependency {} + #[derive(Deserialize)] struct CargoLib { #[serde(rename = "crate-type")] @@ -177,9 +182,11 @@ pub fn check_crate_config(path: &Path, step: &Step) -> Result<(), Error> { } fn check_wasm_bindgen(path: &Path) -> Result<(), Error> { - if read_cargo_toml(path)?.dependencies.map_or(false, |x| { - !x.wasm_bindgen.unwrap_or("".to_string()).is_empty() - }) { + let cargo_toml = read_cargo_toml(path)?; + if cargo_toml + .dependencies + .map_or(false, |deps| deps.contains_key("wasm-bindgen")) + { return Ok(()); } Error::crate_config(&format!( diff --git a/tests/fixtures/serde-feature/Cargo.toml b/tests/fixtures/serde-feature/Cargo.toml new file mode 100644 index 00000000..67055852 --- /dev/null +++ b/tests/fixtures/serde-feature/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "serde-serialize" +description = "an example rust->wasm crate" +version = "0.1.0" +authors = ["Ashley Williams "] +license = "WTFPL" +repository = "https://github.com/ashleygwilliams/wasm-pack" + +[lib] +crate-type = ["cdylib"] + +[dependencies.wasm-bindgen] +version = "^0.2" +features = ["serde-serialize"] diff --git a/tests/fixtures/serde-feature/README.md b/tests/fixtures/serde-feature/README.md new file mode 100644 index 00000000..8fbd2b3b --- /dev/null +++ b/tests/fixtures/serde-feature/README.md @@ -0,0 +1,2 @@ +# js-hello-world +> an example rust -> wasm project diff --git a/tests/fixtures/serde-feature/src/lib.rs b/tests/fixtures/serde-feature/src/lib.rs new file mode 100644 index 00000000..9e44b28c --- /dev/null +++ b/tests/fixtures/serde-feature/src/lib.rs @@ -0,0 +1,15 @@ +#![feature(proc_macro, wasm_import_module, wasm_custom_section)] + +extern crate wasm_bindgen; + +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern { + fn alert(s: &str); +} + +#[wasm_bindgen] +pub fn greet(name: &str) { + alert(&format!("Hello, {}!", name)); +} diff --git a/tests/manifest/main.rs b/tests/manifest/main.rs index 9594b8ac..e9e765ca 100644 --- a/tests/manifest/main.rs +++ b/tests/manifest/main.rs @@ -50,6 +50,14 @@ fn it_checks_has_cdylib_wrong_crate_type() { ); } +#[test] +fn it_recognizes_a_map_during_depcheck() { + let step = wasm_pack::progressbar::Step::new(1); + assert!( + manifest::check_crate_config(&PathBuf::from("tests/fixtures/serde-feature"), &step).is_ok() + ); +} + #[test] fn it_creates_a_package_json_default_path() { let step = wasm_pack::progressbar::Step::new(1);