Skip to content

Commit

Permalink
fix: Fix the parse error when package.json is generated by wasm-bindgen
Browse files Browse the repository at this point in the history
Introduces WasmBindgenPackageJson for deserializing package.json generated by wasm-bindgen
  • Loading branch information
mohebifar committed Nov 24, 2024
1 parent 32e52ca commit 4c97177
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ struct CrateInformation {
max_version: String,
}

#[derive(Deserialize, Debug)]
struct WasmBindgenPackageJson {
dependencies: Option<HashMap<String, String>>,
}

impl Crate {
/// Returns latest wasm-pack version
pub fn return_wasm_pack_latest_version() -> Result<Option<String>> {
Expand Down Expand Up @@ -629,9 +634,8 @@ impl CrateData {
// we merge the NPM dependencies already specified in it.
let existing_deps = if pkg_file_path.exists() {
// It's just a map of dependency names to versions
Some(serde_json::from_str::<HashMap<String, String>>(
&fs::read_to_string(&pkg_file_path)?,
)?)
serde_json::from_str::<WasmBindgenPackageJson>(&fs::read_to_string(&pkg_file_path)?)?
.dependencies
} else {
None
};
Expand Down
2 changes: 1 addition & 1 deletion tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() {
utils::manifest::create_wbg_package_json(
&out_dir,
r#"
{ "foo": "^1.2.3" }
{"dependencies": {"foo": "^1.2.3"}}
"#,
)
.unwrap();
Expand Down

0 comments on commit 4c97177

Please sign in to comment.