feat: use serde to build package json and check npm package name#2428
Merged
feat: use serde to build package json and check npm package name#2428
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens TypeScript bindings project generation by validating the generated npm package name and updating package.json via JSON parsing/serialization (instead of raw string replacement) to prevent invalid or injectable package.json output.
Changes:
- Add
validate_npm_package_name(with tests) to enforce npm naming rules, including scoped names. - Validate the
--output-dirbasename / contract name before generating the TS bindings project. - Update TS project template handling to set
package.json.namethroughserde_json, enablingpreserve_order.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/soroban-cli/src/commands/contract/bindings/typescript.rs | Validates --output-dir basename as an npm package name and introduces a new CLI error variant. |
| cmd/crates/soroban-spec-typescript/src/lib.rs | Adds npm package name validation helper and unit tests. |
| cmd/crates/soroban-spec-typescript/src/boilerplate.rs | Switches package.json update to serde_json parsing/serialization; adds tests for name setting and invalid input. |
| cmd/crates/soroban-spec-typescript/Cargo.toml | Enables serde_json’s preserve_order feature to keep template key ordering stable. |
| Cargo.lock | Updates lockfile to include new transitive dependency introduced by preserve_order. |
fnando
reviewed
Mar 6, 2026
fnando
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Use serde to modify package.json file during typescript binding generation. And check that the npm package name is valid.
Why
Fixes the issue where users can create invalid package.json files
Known limitations
None