|
1 | 1 | diff --git a/bundler/main-wasm/index.js b/bundler/main-wasm/index.js |
2 | | -index e933a032a55715e7ba3c7fe4c44949212f5ac499..9ce1989f2556faef79b3124dc7097693cece7ab0 100644 |
3 | 2 | --- a/bundler/main-wasm/index.js |
4 | 3 | +++ b/bundler/main-wasm/index.js |
5 | | -@@ -1,5 +1,11 @@ |
6 | | - import * as wasm from "./index_bg.wasm"; |
| 4 | +@@ -1,5 +1,34 @@ |
| 5 | +-import * as wasm from "./index_bg.wasm"; |
| 6 | ++import * as wasmModule from "./index_bg.wasm"; |
7 | 7 | export * from "./index_bg.js"; |
8 | | - import { __wbg_set_wasm } from "./index_bg.js"; |
| 8 | +-import { __wbg_set_wasm } from "./index_bg.js"; |
9 | 9 | -__wbg_set_wasm(wasm); |
10 | 10 | -wasm.__wbindgen_start(); |
| 11 | ++import * as wasmBindings from "./index_bg.js"; |
11 | 12 | + |
12 | | -+const wasmExports = typeof wasm === 'object' && wasm !== null && 'default' in wasm ? wasm.default : wasm; |
| 13 | ++const { __wbg_set_wasm } = wasmBindings; |
| 14 | ++ |
| 15 | ++let wasmExports = wasmModule; |
| 16 | ++ |
| 17 | ++const hasClientConfigFactory = value => typeof value?.clientconfiguration_new === "function"; |
| 18 | ++ |
| 19 | ++if (!hasClientConfigFactory(wasmExports)) { |
| 20 | ++ const candidate = wasmModule?.default ?? wasmModule; |
| 21 | ++ |
| 22 | ++ try { |
| 23 | ++ if (candidate instanceof WebAssembly.Module) { |
| 24 | ++ const instance = new WebAssembly.Instance(candidate, { |
| 25 | ++ "./index_bg.js": wasmBindings, |
| 26 | ++ }); |
| 27 | ++ wasmExports = instance.exports; |
| 28 | ++ } |
| 29 | ++ else if (candidate?.instance?.exports && hasClientConfigFactory(candidate.instance.exports)) { |
| 30 | ++ wasmExports = candidate.instance.exports; |
| 31 | ++ } |
| 32 | ++ } |
| 33 | ++ catch (error) { |
| 34 | ++ console.warn("Failed to instantiate @nimiq/core wasm module", error); |
| 35 | ++ } |
| 36 | ++} |
13 | 37 | + |
14 | 38 | +__wbg_set_wasm(wasmExports); |
15 | 39 | + |
16 | | -+if (typeof wasmExports?.__wbindgen_start === 'function') { |
17 | | -+ wasmExports.__wbindgen_start(); |
| 40 | ++if (typeof wasmExports?.__wbindgen_start === "function") { |
| 41 | ++ wasmExports.__wbindgen_start(); |
18 | 42 | +} |
| 43 | + |
| 44 | +diff --git a/bundler/worker-wasm/index.js b/bundler/worker-wasm/index.js |
| 45 | +--- a/bundler/worker-wasm/index.js |
| 46 | ++++ b/bundler/worker-wasm/index.js |
| 47 | +@@ -1,5 +1,34 @@ |
| 48 | +-import * as wasm from "./index_bg.wasm"; |
| 49 | ++import * as wasmModule from "./index_bg.wasm"; |
| 50 | + export * from "./index_bg.js"; |
| 51 | +-import { __wbg_set_wasm } from "./index_bg.js"; |
| 52 | +-__wbg_set_wasm(wasm); |
| 53 | +-wasm.__wbindgen_start(); |
| 54 | ++import * as wasmBindings from "./index_bg.js"; |
| 55 | ++ |
| 56 | ++const { __wbg_set_wasm } = wasmBindings; |
| 57 | ++ |
| 58 | ++let wasmExports = wasmModule; |
| 59 | ++ |
| 60 | ++const hasClientConfigFactory = value => typeof value?.clientconfiguration_new === "function"; |
| 61 | ++ |
| 62 | ++if (!hasClientConfigFactory(wasmExports)) { |
| 63 | ++ const candidate = wasmModule?.default ?? wasmModule; |
| 64 | ++ |
| 65 | ++ try { |
| 66 | ++ if (candidate instanceof WebAssembly.Module) { |
| 67 | ++ const instance = new WebAssembly.Instance(candidate, { |
| 68 | ++ "./index_bg.js": wasmBindings, |
| 69 | ++ }); |
| 70 | ++ wasmExports = instance.exports; |
| 71 | ++ } |
| 72 | ++ else if (candidate?.instance?.exports && hasClientConfigFactory(candidate.instance.exports)) { |
| 73 | ++ wasmExports = candidate.instance.exports; |
| 74 | ++ } |
| 75 | ++ } |
| 76 | ++ catch (error) { |
| 77 | ++ console.warn("Failed to instantiate @nimiq/core worker wasm module", error); |
| 78 | ++ } |
| 79 | ++} |
| 80 | ++ |
| 81 | ++__wbg_set_wasm(wasmExports); |
| 82 | ++ |
| 83 | ++if (typeof wasmExports?.__wbindgen_start === "function") { |
| 84 | ++ wasmExports.__wbindgen_start(); |
| 85 | ++} |
| 86 | + |
| 87 | +diff --git a/bundler/index.js b/bundler/index.js |
| 88 | +--- a/bundler/index.js |
| 89 | ++++ b/bundler/index.js |
| 90 | +@@ -28,3 +28,9 @@ |
| 91 | + export * from './main-wasm/index.js'; |
| 92 | + export { Client }; |
| 93 | + export * from '../lib/bundler/index.mjs'; |
| 94 | ++ |
| 95 | ++// Add init function for compatibility with web version |
| 96 | ++const init = async () => { |
| 97 | ++ // No-op: WASM is already initialized by main-wasm/index.js |
| 98 | ++}; |
| 99 | ++export default init; |
| 100 | + |
| 101 | +diff --git a/package.json b/package.json |
| 102 | +--- a/package.json |
| 103 | ++++ b/package.json |
| 104 | +@@ -26,6 +26,11 @@ |
| 105 | + "browser": "./web/index.js", |
| 106 | + "import": "./web/index.js", |
| 107 | + "types": "./types/web.d.ts" |
| 108 | ++ }, |
| 109 | ++ "./bundler/worker-wasm": { |
| 110 | ++ "import": "./bundler/worker-wasm/index.js", |
| 111 | ++ "browser": "./bundler/worker-wasm/index.js", |
| 112 | ++ "types": "./types/wasm/bundler.d.ts" |
| 113 | + } |
| 114 | + }, |
| 115 | + "homepage": "https://nimiq.com", |
0 commit comments