Skip to content

feat(wasm-mps): add --target web build for browser-safe WASM initialisation#266

Merged
Marzooqa merged 1 commit intomasterfrom
WCI-250/wasm-mps-add-target-web-build
Apr 28, 2026
Merged

feat(wasm-mps): add --target web build for browser-safe WASM initialisation#266
Marzooqa merged 1 commit intomasterfrom
WCI-250/wasm-mps-add-target-web-build

Conversation

@bitgo-ai-agent-dev
Copy link
Copy Markdown

Summary

  • Adds dist/web/js/wasm Make target using wasm-pack --target web, generating an async init() default export that fetches and instantiates the WASM binary before any functions are called
  • Adds dist/web/js/**/* to files in package.json so the web build is included in the npm publish
  • Adds ./web subpath export (@bitgo/wasm-mps/web → dist/web/js/wasm/wasm_mps.js) so browser callers can await init() before using any WASM function
  • Adds make dist/web/js/wasm to the build:wasm script

Why

The existing --target bundler ESM build uses a two-file pattern where webpack 5's asyncWebAssembly mode can resolve the module namespace before __wbg_set_wasm runs, leaving wasm as undefined. The --target web build's explicit init() guarantee eliminates this race entirely — the same pattern used by @silencelaboratories/dkls-wasm-ll-web.

Test plan

  • make dist/web/js/wasm builds successfully and produces dist/web/js/wasm/wasm_mps.js with an export default init function
  • import init, { ... } from '@bitgo/wasm-mps/web'; await init(); /* call functions */ works in a webpack 5 asyncWebAssembly browser environment without TypeError
  • Existing ESM and CJS builds are unaffected
  • npm pack --dry-run includes dist/web/js/**/*

Ticket: WCI-250

🤖 Generated with Claude Code

@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot requested a review from a team as a code owner April 28, 2026 09:36
@linear
Copy link
Copy Markdown

linear Bot commented Apr 28, 2026

@Marzooqa Marzooqa force-pushed the WCI-250/wasm-mps-add-target-web-build branch 3 times, most recently from c46b9ca to 4086fda Compare April 28, 2026 10:41
@johnoliverdriscoll
Copy link
Copy Markdown
Contributor

@Marzooqa please rebase off latest head

Add dist/web/js/wasm Makefile target using wasm-pack --target web,
which generates an explicit async init() default export. Callers
await init() before using any WASM function, eliminating the webpack
asyncWebAssembly timing race that left wasm undefined.

Export the build via the ./web subpath export so consumers can import
directly from @bitgo/wasm-mps/web.

Ticket: WCI-250
@Marzooqa Marzooqa force-pushed the WCI-250/wasm-mps-add-target-web-build branch from 4086fda to 8a4703b Compare April 28, 2026 15:26
@Marzooqa Marzooqa enabled auto-merge April 28, 2026 15:27
@Marzooqa Marzooqa merged commit 8b68958 into master Apr 28, 2026
16 checks passed
@Marzooqa Marzooqa deleted the WCI-250/wasm-mps-add-target-web-build branch April 28, 2026 15:36
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.

2 participants