Skip to content

createWasiBin

Implementation signature for createWasiBin (overloads above are public).

Returns a closure-captured BinFunction that lazy-compiles the .wasm on first invocation and memoizes the resulting WebAssembly.Module so subsequent runs skip both asset loading and compilation.

createWasiBin(metaUrl, wasmFile, opts?): BinFunction

Defined in: packages/runtime/src/wasm/create-wasi-bin.ts:86

Build a BinFunction that runs a WASI (wasi_snapshot_preview1) program.

Overloads:

  • Host-side — pass import.meta.url and a path relative to it. Resolved via node:fs on Node, fetch in the browser.
  • Guest-side (registry) — pass an AssetResolver, which reads the bundled .wasm shipped alongside the package.

The compiled WebAssembly.Module is cached on first call, so subsequent invocations skip compilation.

string

string

CreateWasiBinOptions

BinFunction

// Host-side
export const catBin = createWasiBin(import.meta.url, 'cat.wasm')
// Guest-side (registry catalog entry)
export default (resolver: AssetResolver) => ({
bins: { cat: createWasiBin(resolver, 'cat.wasm') },
})

createWasiBin(resolver, wasmFile, opts?): BinFunction

Defined in: packages/runtime/src/wasm/create-wasi-bin.ts:93

Guest-side overload — resolve the .wasm via an AssetResolver.

AssetResolver

string

CreateWasiBinOptions

BinFunction