From 52881affc533e4497cc772acf777861e39ee1e61 Mon Sep 17 00:00:00 2001 From: Mario Reder Date: Tue, 21 Jan 2020 16:25:40 +0100 Subject: [PATCH] fix: ignore non dependency keys in package json resolves #1921 --- crates/cli-support/src/js/mod.rs | 21 +++++++++++---------- crates/cli/tests/wasm-bindgen/npm.rs | 15 +++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 680f42b22ee..c4d348674b8 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -2769,17 +2769,18 @@ impl<'a> Context<'a> { ), }; let mut iter = object.iter(); - let (key, value) = match iter.next() { - Some(pair) => pair, - None => return Ok(()), - }; - if key != "dependencies" || iter.next().is_some() { - bail!( - "NPM manifest found at `{}` can currently only have one key, \ - `dependencies`, and no other fields", - path.display() - ); + let mut value = None; + while let Some((key, v)) = iter.next() { + if key == "dependencies" { + value = Some(v); + break; + } } + let value = if let Some(value) = value { + value + } else { + return Ok(()); + }; let value = match value.as_object() { Some(s) => s, None => bail!( diff --git a/crates/cli/tests/wasm-bindgen/npm.rs b/crates/cli/tests/wasm-bindgen/npm.rs index 2ad9e66f597..bc356a49cb9 100644 --- a/crates/cli/tests/wasm-bindgen/npm.rs +++ b/crates/cli/tests/wasm-bindgen/npm.rs @@ -35,8 +35,8 @@ compatible with the `bundler` and `nodejs` targets } #[test] -fn more_package_json_fields_rejected() { - let (mut cmd, _out_dir) = Project::new("more_package_json_fields_rejected") +fn more_package_json_fields_ignored() { + let (mut cmd, _out_dir) = Project::new("more_package_json_fields_ignored") .file( "src/lib.rs", r#" @@ -63,16 +63,7 @@ fn more_package_json_fields_rejected() { "#, ) .wasm_bindgen(""); - cmd.assert() - .stderr( - str::is_match( - "\ -error: NPM manifest found at `.*` can currently only have one key, .* -", - ) - .unwrap(), - ) - .failure(); + cmd.assert().success(); } #[test]