feat(wasm-mps): add --target web build for browser-safe WASM initialisation#267
Closed
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
Closed
feat(wasm-mps): add --target web build for browser-safe WASM initialisation#267bitgo-ai-agent-dev[bot] wants to merge 2 commits into
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
Conversation
Add dist/web/js/wasm Makefile target using wasm-pack --target web, which generates a single ESM file with an explicit async init() default export. This avoids the webpack asyncWebAssembly race where __wbg_set_wasm may not be called before exports are used. Update package.json to include dist/web/js/**/* in published files, expose the ./web subpath export pointing to the generated entry point, and add make dist/web/js/wasm to the build:wasm script. Ticket: WCI-250
Contributor
|
The dev agent pushed another pr 😞 |
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.
Summary
dist/web/js/wasmMakefile target usingwasm-pack --target web, generating a single flat ESM file with an explicit asyncinit()default exportdist/web/js/**/*to thefilesarray inpackage.jsonso the web build is included in the npm publish"./web": "./dist/web/js/wasm/wasm_mps.js"subpath export so consumers can import via@bitgo/wasm-mps/webmake dist/web/js/wasmto thebuild:wasmscriptMotivation
The current
--target bundlerESM build uses a two-file pattern wherewasm_mps.jsimports the.wasmfile and calls__wbg_set_wasm. In webpack 5asyncWebAssemblymode,await import('@bitgo/wasm-mps')can resolve before__wbg_set_wasmis called, leavingwasmasundefinedand causingTypeError: wasm.ed25519_dkg_round0_process is not a function.The
--target webbuild solves this by generating aninit()default export that fetches and instantiates the WASM binary synchronously before returning. Callersawait init()once before using any exported function — guaranteed ready, no webpack timing dependency. This mirrors the pattern used by@silencelaboratories/dkls-wasm-ll-web.Test plan
make dist/web/js/wasmruns without error and producesdist/web/js/wasm/wasm_mps.js(single-file ESM withexport default __wbg_init)npm run build:wasmcompletes and includes all four targets (js/wasm, dist/esm/js/wasm, dist/cjs/js/wasm, dist/web/js/wasm)npm pack --dry-runshowsdist/web/js/**files included@bitgo/wasm-mps/webin a browser bundle resolves to the web entry pointawait init()followed by WASM function calls works without TypeError in webpack 5 asyncWebAssembly modeTicket: WCI-250
🤖 Generated with Claude Code