Skip to content

Commit

Permalink
Fix emitted package.json structure (#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaemon authored Aug 27, 2024
1 parent 9d6693a commit 125aa23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
[#4082](https://github.com/rustwasm/wasm-bindgen/pull/4082)
[#4088](https://github.com/rustwasm/wasm-bindgen/pull/4088)

* Fixed emitted `package.json` structure to correctly specify its dependencies
[#4091](https://github.com/rustwasm/wasm-bindgen/pull/4091)

--------------------------------------------------------------------------------

## [0.2.93](https://github.com/rustwasm/wasm-bindgen/compare/0.2.92...0.2.93)
Expand Down
1 change: 1 addition & 0 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ anyhow = "1.0"
base64 = "0.22"
log = "0.4"
rustc-demangle = "0.1.13"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.0"
unicode-ident = "1.0.5"
Expand Down
18 changes: 12 additions & 6 deletions crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,18 @@ impl Output {
}

if !gen.npm_dependencies.is_empty() {
let map = gen
.npm_dependencies
.iter()
.map(|(k, v)| (k, &v.1))
.collect::<BTreeMap<_, _>>();
let json = serde_json::to_string_pretty(&map)?;
#[derive(serde::Serialize)]
struct PackageJson<'a> {
dependencies: BTreeMap<&'a str, &'a str>,
}
let pj = PackageJson {
dependencies: gen
.npm_dependencies
.iter()
.map(|(k, v)| (k.as_str(), v.1.as_str()))
.collect(),
};
let json = serde_json::to_string_pretty(&pj)?;
fs::write(out_dir.join("package.json"), json)?;
}

Expand Down

0 comments on commit 125aa23

Please sign in to comment.