Skip to content

Commit 4c97177

Browse files
committed
fix: Fix the parse error when package.json is generated by wasm-bindgen
Introduces WasmBindgenPackageJson for deserializing package.json generated by wasm-bindgen
1 parent 32e52ca commit 4c97177

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/manifest/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ struct CrateInformation {
144144
max_version: String,
145145
}
146146

147+
#[derive(Deserialize, Debug)]
148+
struct WasmBindgenPackageJson {
149+
dependencies: Option<HashMap<String, String>>,
150+
}
151+
147152
impl Crate {
148153
/// Returns latest wasm-pack version
149154
pub fn return_wasm_pack_latest_version() -> Result<Option<String>> {
@@ -629,9 +634,8 @@ impl CrateData {
629634
// we merge the NPM dependencies already specified in it.
630635
let existing_deps = if pkg_file_path.exists() {
631636
// It's just a map of dependency names to versions
632-
Some(serde_json::from_str::<HashMap<String, String>>(
633-
&fs::read_to_string(&pkg_file_path)?,
634-
)?)
637+
serde_json::from_str::<WasmBindgenPackageJson>(&fs::read_to_string(&pkg_file_path)?)?
638+
.dependencies
635639
} else {
636640
None
637641
};

tests/all/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() {
332332
utils::manifest::create_wbg_package_json(
333333
&out_dir,
334334
r#"
335-
{ "foo": "^1.2.3" }
335+
{"dependencies": {"foo": "^1.2.3"}}
336336
"#,
337337
)
338338
.unwrap();

0 commit comments

Comments
 (0)