Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore non dependency keys in package json #1969

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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