From 4c97177d0c5eedc9b07456f43b5d4e776c287858 Mon Sep 17 00:00:00 2001 From: Mohamad Mohebifar Date: Sun, 24 Nov 2024 16:39:30 -0500 Subject: [PATCH] fix: Fix the parse error when package.json is generated by wasm-bindgen Introduces WasmBindgenPackageJson for deserializing package.json generated by wasm-bindgen --- src/manifest/mod.rs | 10 +++++++--- tests/all/manifest.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index bf715a81..795cb05c 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -144,6 +144,11 @@ struct CrateInformation { max_version: String, } +#[derive(Deserialize, Debug)] +struct WasmBindgenPackageJson { + dependencies: Option>, +} + impl Crate { /// Returns latest wasm-pack version pub fn return_wasm_pack_latest_version() -> Result> { @@ -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::>( - &fs::read_to_string(&pkg_file_path)?, - )?) + serde_json::from_str::(&fs::read_to_string(&pkg_file_path)?)? + .dependencies } else { None }; diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 8d4af2df..c8a191ba 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -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();