Skip to content

Conversation

@dani-garcia
Copy link
Member

@dani-garcia dani-garcia commented Jun 25, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-27740

📔 Objective

Previously devs would need to install a version of wasm-bindgen-cli that matches with the version of wasm-bindgen used by the project. This step produces significant friction, specially when wasm-bindgen gets updated, as we need to deal with updating the CI files, and every dev needs to update their environment. It also introduces another avenue for builds to be non-reproducible.

This PR tries to do something similar to what uniffi does, in that we have a simple wrapper crate around the utility. This means that the crate gets versioned in the Cargo.lock like every other dependency.

While I was at it, I've also updated the renovate config to group all the wasm-bindgen crates together, and I've also included a small TS formatting error that was reported in #319. The reason we never saw it is that we always run prettier after, which gets rid of the extra semicolon.

Fixes #319.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@dani-garcia dani-garcia requested a review from coroiu June 25, 2025 20:00
@github-actions

This comment was marked as resolved.

@codecov

This comment was marked as resolved.

@dani-garcia dani-garcia marked this pull request as ready for review June 25, 2025 20:33
@dani-garcia dani-garcia requested a review from a team as a code owner June 25, 2025 20:33
@dani-garcia dani-garcia requested review from justindbaur and removed request for coroiu June 27, 2025 10:13
@sonarqubecloud
Copy link

@dani-garcia dani-garcia marked this pull request as draft June 27, 2025 10:34
@brjsp
Copy link

brjsp commented Aug 21, 2025

Please rebase this on 29c6158

@brjsp
Copy link

brjsp commented Nov 2, 2025

What's the status of this?

@dani-garcia dani-garcia force-pushed the ps/wrap-wasm-bindgen-cli branch from 52dfc42 to 2a91653 Compare November 3, 2025 13:08
@dani-garcia dani-garcia removed the request for review from justindbaur November 3, 2025 13:09
@dani-garcia
Copy link
Member Author

What's the status of this?

@brjsp I was waiting for a new wasm-bindgen release that would simplify the CLI wrapping, and then lost track of it. I've updated this PR to be on top of #540. Once that one is merged, I'll update this one and set it up for review.

@dani-garcia dani-garcia changed the title Wrap wasm-bindgen CLI [PM-27740] Wrap wasm-bindgen CLI Nov 3, 2025
dani-garcia added a commit that referenced this pull request Nov 6, 2025
## 🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-27727

## 📔 Objective

Update WASM-bindgen and removed `VectorIntoJsValue` implementations, as
those types aren't needed anymore and were removed from wasm-bindgen.

The TS typings now include `[Symbol.dispose](): void;` for the Client
classes, so I've updated the TS check script to include the
`esnext.disposable` feature, which we're already using in the clients
repo anyway.

Prerequisite for #330 

## ⏰ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## 🦮 Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or
concerns needing attention
- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or
indications of technical debt
- ⛏ (`:pick:`) for minor or nitpick changes
@dani-garcia dani-garcia force-pushed the ps/wrap-wasm-bindgen-cli branch from 2a91653 to c30858d Compare November 7, 2025 13:13
@dani-garcia dani-garcia marked this pull request as ready for review November 7, 2025 14:27
@claude
Copy link

claude bot commented Nov 7, 2025

Claude finished @dani-garcia's task —— View job


Comprehensive PR Review

This PR successfully eliminates the manual wasm-bindgen-cli installation requirement by wrapping it as a Cargo dependency, improving reproducibility and reducing developer friction. The implementation follows the established uniffi pattern.


Changes Since Last Review

The author has addressed previous feedback:

  • Finding 2 (Missing module-level documentation): ✅ Fixed - Module-level comments added to both wrapper binaries in crates/wasm-bindgen-cli-runner/wasm-bindgen-runner.rs:1-2 and wasm-bindgen-test-runner.rs:1-2
  • Finding 3 (Test runner performance concern): ✅ Resolved - Human confirmed no performance issues in practice
  • Finding 4 (Documentation not reflecting simplified setup): ⚠️ Partially addressed - README no longer lists wasm-bindgen-cli requirement (crates/bitwarden-wasm-internal/README.md:14), but could be more explicit
  • Finding 5 (Inconsistent cargo run invocation): ⚠️ Not addressed - build.sh:50-51 still omits -p wasm-bindgen-cli-runner flag
  • Finding 6 (Documentation improvement): ✅ Addressed by removing the requirement

Additional changes:


Critical Issues

None identified. The implementation is sound and achieves its objectives.


Suggested Improvements

💭 Finding 1: Consider making cargo run invocations consistent between .cargo/config.toml and build.sh.

The test runner in .cargo/config.toml:9 explicitly specifies -p wasm-bindgen-cli-runner:

runner = 'cargo run -p wasm-bindgen-cli-runner --bin wasm-bindgen-test-runner'

However, build.sh:50-51 omits the package specifier:

cargo run --bin wasm-bindgen-runner -- ...

While both work (cargo can infer the package), explicit package specification improves clarity and matches the established pattern. Author previously marked this as resolved, but the code doesn't reflect the change.

Suggested change
cargo run -p wasm-bindgen-cli-runner --bin wasm-bindgen-runner -- --target bundler --out-dir crates/bitwarden-wasm-internal/${NPM_FOLDER} ./target/wasm32-unknown-unknown/${BUILD_FOLDER}/bitwarden_wasm_internal.wasm
cargo run -p wasm-bindgen-cli-runner --bin wasm-bindgen-runner -- --target nodejs --out-dir crates/bitwarden-wasm-internal/${NPM_FOLDER}/node ./target/wasm32-unknown-unknown/${BUILD_FOLDER}/bitwarden_wasm_internal.wasm

🎨 Finding 2: Documentation could more explicitly highlight the improvement.

crates/bitwarden-wasm-internal/README.md:14 simply lists requirements without noting the significant simplification this PR introduces. Consider adding a note that clarifies developers no longer need to manually install and maintain wasm-bindgen-cli.

Suggested addition
### Requirements

- `wasm32-unknown-unknown` rust target.
- `binaryen` installed for `wasm-opt` and `wasm2js`.

**Note:** `wasm-bindgen-cli` is managed as a Cargo dependency and does not require manual installation.

🎨 Finding 3: The wrapper crate's Cargo.toml uses a more specific version range than typical workspace dependencies.

crates/wasm-bindgen-cli-runner/Cargo.toml:24 specifies env_logger = "0.11.1" (exact version), while the workspace pattern typically uses simpler ranges like "0.11". While not incorrect, consistency aids maintainability.

Suggested change
env_logger = "0.11"

Good Practices Observed


Action Items

  1. Optional: Apply Finding 1 for consistency in cargo run invocations
  2. Optional: Apply Finding 2 to document the improvement more explicitly
  3. Optional: Apply Finding 3 for version specification consistency

All action items are suggestions for polish rather than required changes. The PR is functionally complete and ready for merge pending maintainer approval.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

🔍 SDK Breaking Change Detection Results

SDK Version: ps/wrap-wasm-bindgen-cli (ed2d25f)
Completed: 2025-11-17 16:52:17 UTC
Total Time: 216s

Client Status Details
typescript ✅ No breaking changes detected TypeScript compilation passed with new SDK version - View Details

Breaking change detection completed. View SDK workflow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this and it seems like this file is not needed and it's using the config file at the root, so I've removed it.

uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4", "js"] }
validator = { version = ">=0.18.1, <0.21", features = ["derive"] }
wasm-bindgen = { version = ">=0.2.105, <0.3", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.105", features = ["serde-serialize"] }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to pin the version consistently, wasm-bindgen versions can sometimes break things for us even on a patch release.

r##"r#"
export interface {export_as_identifier} extends Error {{
name: "{export_as_identifier}";
}};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semicolon at the end of these is invalid TS syntax which should cause compilation issues, but prettier removes it automatically which means we don't see the issue.

This was reported to me as part of #319, so I've included it here as it's a tiny change, but I can move it to a separate PR.

@dani-garcia dani-garcia requested a review from coroiu November 17, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasm-bindgen-cli should be in Cargo.lock file, not downloaded separately — the current setup makes reproducible OSS builds impossible

3 participants