fix: Fix the parse error when package.json is generated by wasm-bindgen
When building one of my projects, I kept running into this issue:
wasm-pack build --target web
Error:
Finished `release` profile [optimized] target(s) in 0.05s
Error: invalid type: map, expected a string at line 2 column 18
Caused by: invalid type: map, expected a string at line 2 column 18
Root Cause
The issue originates in the step_create_json and the fn write_package_json. During the build process, the following package.json was generated by wasm-bindgen:
{
"dependencies": {
"web-tree-sitter-sg": "0.22.2"
}
}
While this package.json is valid, the code incorrectly attempted to parse the entire file as a HashMap<String, String>. This led to a failure when merging dependencies because the dependencies field itself is a map, not a string.
Fix
This PR updates the parsing logic to correctly handle the package.json structure.
Make sure these boxes are checked! 📦✅
- [x] You have the latest version of
rustfmtinstalled
$ rustup component add rustfmt
- [x] You ran
cargo fmton the code base before submitting - [ ] You reference which issue is being closed in the PR text
✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨
Bumping this PR. Any blockers for merging this?