Skip to content

Commit 4086fda

Browse files
committed
feat(wasm-mps): add --target web build for browser-safe WASM init
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
1 parent 75ccf91 commit 4086fda

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/wasm-mps/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ dist/esm/js/wasm:
6464
dist/cjs/js/wasm:
6565
$(call BUILD,$@,nodejs)
6666

67+
.PHONY: dist/web/js/wasm
68+
dist/web/js/wasm:
69+
$(call BUILD,$@,web)
70+
6771
.PHONY: lint
6872
lint:
6973
cargo fmt --check

packages/wasm-mps/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"files": [
1212
"dist/esm/js/**/*",
1313
"dist/cjs/js/**/*",
14-
"dist/cjs/package.json"
14+
"dist/cjs/package.json",
15+
"dist/web/js/**/*"
1516
],
1617
"exports": {
1718
".": {
@@ -23,6 +24,10 @@
2324
"types": "./dist/cjs/js/index.d.ts",
2425
"default": "./dist/cjs/js/index.js"
2526
}
27+
},
28+
"./web": {
29+
"types": "./dist/web/js/wasm/wasm_mps.d.ts",
30+
"default": "./dist/web/js/wasm/wasm_mps.js"
2631
}
2732
},
2833
"main": "./dist/cjs/js/index.js",
@@ -35,7 +40,7 @@
3540
"scripts": {
3641
"test": "npm run test:mocha",
3742
"test:mocha": "mocha --recursive test",
38-
"build:wasm": "make js/wasm && make dist/esm/js/wasm && make dist/cjs/js/wasm",
43+
"build:wasm": "make js/wasm && make dist/esm/js/wasm && make dist/cjs/js/wasm && make dist/web/js/wasm",
3944
"build:ts-esm": "tsc",
4045
"build:ts-cjs": "tsc --project tsconfig.cjs.json",
4146
"build:ts": "npm run build:ts-esm && npm run build:ts-cjs",

0 commit comments

Comments
 (0)