|
| 1 | +diff --git a/bundler/worker-wasm/index.js b/bundler/worker-wasm/index.js |
| 2 | +index e933a032a55715e7ba3c7fe4c44949212f5ac499..8e0a51a40b058860c1e2f0e9a0b15d366a2eb7ef 100644 |
| 3 | +--- a/bundler/worker-wasm/index.js |
| 4 | ++++ b/bundler/worker-wasm/index.js |
| 5 | +@@ -1,5 +1,39 @@ |
| 6 | +-import * as wasm from "./index_bg.wasm"; |
| 7 | ++import * as wasmModule from "./index_bg.wasm"; |
| 8 | + export * from "./index_bg.js"; |
| 9 | +-import { __wbg_set_wasm } from "./index_bg.js"; |
| 10 | +-__wbg_set_wasm(wasm); |
| 11 | +-wasm.__wbindgen_start(); |
| 12 | ++import * as wasmBindings from "./index_bg.js"; |
| 13 | ++ |
| 14 | ++const { __wbg_set_wasm } = wasmBindings; |
| 15 | ++ |
| 16 | ++let wasmExports = wasmModule; |
| 17 | ++ |
| 18 | ++const hasClientConfigFactory = value => typeof value?.clientconfiguration_new === "function"; |
| 19 | ++ |
| 20 | ++if (!hasClientConfigFactory(wasmExports)) { |
| 21 | ++ const candidate = wasmModule?.default ?? wasmModule; |
| 22 | ++ |
| 23 | ++ try { |
| 24 | ++ if (candidate instanceof WebAssembly.Module) { |
| 25 | ++ const instance = new WebAssembly.Instance(candidate, { |
| 26 | ++ "./index_bg.js": wasmBindings, |
| 27 | ++ }); |
| 28 | ++ wasmExports = instance.exports; |
| 29 | ++ } |
| 30 | ++ else if (candidate?.instance?.exports && hasClientConfigFactory(candidate.instance.exports)) { |
| 31 | ++ wasmExports = candidate.instance.exports; |
| 32 | ++ } |
| 33 | ++ } |
| 34 | ++ catch (error) { |
| 35 | ++ console.warn("Failed to instantiate @nimiq/core worker wasm module", error); |
| 36 | ++ } |
| 37 | ++} |
| 38 | ++ |
| 39 | ++__wbg_set_wasm(wasmExports); |
| 40 | ++ |
| 41 | ++// Guard __wbindgen_start to only run once per JavaScript runtime |
| 42 | ++// This prevents "SetGlobalDefaultError" when Cloudflare Workers reuse runtimes |
| 43 | ++if (typeof wasmExports?.__wbindgen_start === "function") { |
| 44 | ++ if (!globalThis.__nimiq_wasm_started) { |
| 45 | ++ wasmExports.__wbindgen_start(); |
| 46 | ++ globalThis.__nimiq_wasm_started = true; |
| 47 | ++ } |
| 48 | ++} |
| 49 | +diff --git a/package.json b/package.json |
| 50 | +index fe1cafe8d2cb222f9827f3729decafec5d588fff..18479b6acedf2a6ba9c285468740545849e5aeb1 100644 |
| 51 | +--- a/package.json |
| 52 | ++++ b/package.json |
| 53 | +@@ -26,6 +26,14 @@ |
| 54 | + "browser": "./web/index.js", |
| 55 | + "import": "./web/index.js", |
| 56 | + "types": "./types/web.d.ts" |
| 57 | ++ }, |
| 58 | ++ "./bundler/worker-wasm": { |
| 59 | ++ "import": "./bundler/worker-wasm/index.js", |
| 60 | ++ "browser": "./bundler/worker-wasm/index.js", |
| 61 | ++ "types": "./types/wasm/bundler.d.ts" |
| 62 | ++ }, |
| 63 | ++ "./bundler/worker-wasm/index_bg.wasm": { |
| 64 | ++ "import": "./bundler/worker-wasm/index_bg.wasm" |
| 65 | + } |
| 66 | + }, |
| 67 | + "homepage": "https://nimiq.com", |
0 commit comments