Repository: rustwasm/wasm-pack (rust)

Issue:
wasm-bindgen dep check should not fail on dep map
I poked around other issues and didn't see any related info, so sorry if I'm missing something here... I was playing around with an existing `wasm-pack`-happy project by enabling [`wasm-bindgen`'s "serde-serialize" feature](https://github.com/rustwasm/wasm-bindgen/blob/f437e06463fb096af04afaa405ad116b2e8f2ef7/src/lib.rs#L187)... everything was all good until I tried rerunning the project through wasm-pack:

```
❯ wasm-pack init -t nodejs
invalid type: map, expected a string for key `dependencies.wasm-bindgen`
Caused by: invalid type: map, expected a string for key `dependencies.wasm-bindgen`
```

Is there anything I can do to work around this?

Happy Cargo.toml:

```toml
[dependencies]
wasm-bindgen = "^0.2"
```

Unhappy Cargo.toml:

```toml
[dependencies.wasm-bindgen]
version = "^0.2"
features = ["serde-serialize"]
```

----

```
❯ rustc --version        
rustc 1.29.0-nightly (874dec25e 2018-07-21)
❯ wasm-pack --version
wasm-pack 0.4.1
❯ wasm-bindgen --version
wasm-bindgen 0.2.13
❯ uname -a
# OSX 10.13.5
Darwin sloveless.local 17.6.0 Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64
```

Wonderful project! TIA!

Pull request:
fix(depcheck): don't fail on dep map
fixes #221 

Patch:
diff --git a/src/manifest.rs b/src/manifest.rs
index 36e69df..2cc3919 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<CargoDependencies>,
+    dependencies: Option<HashMap<String, CargoDependency>>,
     lib: Option<CargoLib>,
 }
 
@@ -30,11 +31,15 @@ struct CargoPackage {
 }
 
 #[derive(Deserialize)]
-struct CargoDependencies {
-    #[serde(rename = "wasm-bindgen")]
-    wasm_bindgen: Option<String>,
+#[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!(


Test patch:
diff --git a/tests/fixtures/serde-feature/Cargo.toml b/tests/fixtures/serde-feature/Cargo.toml
new file mode 100644
index 0000000..6705585
--- /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 <ashley666ashley@gmail.com>"]
+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 0000000..8fbd2b3
--- /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 0000000..9e44b28
--- /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 9594b8a..e9e765c 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);