/** * Node-only WASM byte loader for Vitest. * * Browser extension builds must not see direct Node built-in imports here; * Vite/Rolldown rewrites those to browser external shims that fail in * extension pages. The split specifier plus @vite-ignore keeps this fallback * out of the browser module graph while still letting Node tests read from * node_modules. */ const WASM_NODE_MODULE_PATH = "node_modules/@subspace/reed-solomon-erasure.wasm/dist/reed_solomon_erasure_bg.wasm"; type NodeFs = { readFileSync(path: string): Uint8Array; }; type NodePath = { resolve(...parts: string[]): string; }; async function importNodeModule(name: string): Promise { return import(/* @vite-ignore */ (`node:${name}`)) as Promise; } export async function readNodeReedSolomonWasmBytes(): Promise> { const [fs, path] = await Promise.all([ importNodeModule("fs"), importNodeModule("path"), ]); const fileBytes = fs.readFileSync(path.resolve(WASM_NODE_MODULE_PATH)); const bytes: Uint8Array = new Uint8Array(fileBytes.byteLength); bytes.set(fileBytes); return bytes; }