()
| 54 | |
| 55 | // ── Load Go wasm_exec.js runtime ───────────────────────────────────── |
| 56 | function loadWasmExecJs() { |
| 57 | const goRoot = execSync("go env GOROOT", { encoding: "utf8" }).trim(); |
| 58 | // Go 1.24+ moved wasm_exec.js from misc/wasm/ to lib/wasm/ |
| 59 | let wasmExecPath = join(goRoot, "lib/wasm/wasm_exec.js"); |
| 60 | if (!existsSync(wasmExecPath)) { |
| 61 | wasmExecPath = join(goRoot, "misc/wasm/wasm_exec.js"); |
| 62 | } |
| 63 | if (!existsSync(wasmExecPath)) { |
| 64 | throw new Error(`wasm_exec.js not found in ${goRoot}/lib/wasm/ or ${goRoot}/misc/wasm/`); |
| 65 | } |
| 66 | // wasm_exec.js expects a global `require` for Node.js |
| 67 | globalThis.require = createRequire(import.meta.url); |
| 68 | // Load the wasm_exec.js script (it defines globalThis.Go) |
| 69 | const script = readFileSync(wasmExecPath, "utf8"); |
| 70 | // Use indirect eval to run in global scope |
| 71 | const fn = new Function(script); |
| 72 | fn(); |
| 73 | } |
| 74 | |
| 75 | // ── Instantiate wasm module ────────────────────────────────────────── |
| 76 | async function instantiateWasm() { |
no test coverage detected