// A WASI host, so the acceptance table can run a wasm32 build without a // wasmtime or wasmer being installed. Node has had node:wasi since 16; it is // still flagged experimental, hence --no-warnings at the call site, and before // Node 20 it needs --experimental-wasi-unstable-preview1 as well. The // acceptance test probes rather than assumes: if this file cannot run the // module, the wasm case is skipped with what went wrong. // // preopens is empty on purpose. sand-headless reads nothing and writes one // line to stdout, which is the whole point of it being the cross-target case. import { WASI } from 'node:wasi'; import { readFile } from 'node:fs/promises'; const [, , file, ...rest] = process.argv; const wasi = new WASI({ version: 'preview1', args: [file, ...rest], env: {}, preopens: {}, returnOnExit: true, }); const mod = await WebAssembly.compile(await readFile(file)); const inst = await WebAssembly.instantiate(mod, wasi.getImportObject()); process.exitCode = wasi.start(inst);