Skip to content

Commit

Permalink
fix: ignore non dependency keys in package json (#1969)
Browse files Browse the repository at this point in the history
resolves #1921
  • Loading branch information
Tarnadas authored and alexcrichton committed Jan 21, 2020
1 parent 0f0d5ee commit 34eb8a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
21 changes: 11 additions & 10 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
15 changes: 3 additions & 12 deletions crates/cli/tests/wasm-bindgen/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand All @@ -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]
Expand Down

0 comments on commit 34eb8a8

Please sign in to comment.