Direct AOT compilation from JavaScript and TypeScript to WebAssembly GC.
bun install --trust https://github.com/loopdive/js2nm_js2wasm_wasi_p1.ts
Raw WASI Preview 1 syscalls over linear memory |
wasi_snapshot_preview1(fd_read/fd_write) +wasm:memory(intrinsic, lowers inline) | sync blockingfd_read/fd_writeloop | onlywasi_snapshot_preview1|wasmtime/wasmer/wazero| standalone WASI P1 command module (owns + exports its ownmemory)
nm_js2wasm_node_fs.ts
Node synchronous
node:fsfd IO |node:fs(readSync/writeSync) | syncreadSync/writeSyncread-until loop | onlywasi_snapshot_preview1(inlined); or anode:fsinterface with--link node:fs|wasmtimeand unmodified under realnode| standalone WASI P1 command module (or anode:fs-linkable module)
nm_js2wasam_node_process.ts
Node async streaming stdio |
process.stdin(global) Readable +process.stdout.write| async event-driven'data'/'end', incremental framing | onlywasi_snapshot_preview1|wasmtime(drives the injected fd0 reactor / event loop) | standalone WASI P1 command module with an event loop
nm_js2wasm_deno.ts
Deno stdio surface (
Deno.stdin/Deno.stdout) | (lands separately) | sync (readSync/writeSync) | (WASI-targeted; filled in when it lands)| Deno / a WASI runtime | standalone WASI module
See Five hosts, one wire protocol — a comparison.
bun build ./node_modules/@loopdive/js2/examples/native-messaging/nm_js2wasm_wasi_p1.ts --no-bundle --outfile=nm_js2wasm_wasi_p1.jsbun ./node_modules/@loopdive/js2/src/cli.ts nm_js2wasm_wasi_p1.js --wit --target wasi -o .bun compile_hosts.jsbun build ./node_modules/@loopdive/js2/src/cli.ts --target=node --minify --outfile=js2wasm.js - Navigate to
chrome://extensions. - Toggle
Developer mode. - Click
Load unpacked. - Select
native-messaging-js2wasmfolder. - Note the generated extension ID.
- Open
nm_js2wasm.jsonin a text editor, set"path"to absolute path ofnm_js2wasm.sh(executes your localwasmtimeor other WebAssembly runtime and the compilednm_js2wasm_wasi_p1.wasmornm_js2wasm_<node|fs|node_process|deno>.wasmfile), andchrome-extension://<ID>/using ID from 5 in"allowed_origins"array; and make surewasmtimeis inPATHandnm_js2wasm.shis executable. - Copy the
nm_js2wasm.jsonfile to Chrome or Chromium configuration folder, e.g., Chromium on Linux~/.config/chromium/NativeMessagingHosts; Chrome dev channel on Linux~/.config/google-chrome-unstable/NativeMessagingHosts. - To test click
service workerlink in panel of unpacked extension which is DevTools forbackground.jsin MV3ServiceWorker, observe echo'ed message fromjs2wasmNative Messaging host. To disconnect runport.disconnect().
The Native Messaging host echoes back the message passed.
For differences between OS and browser implementations see Chrome incompatibilities.
Do What the Fuck You Want to Public License WTFPLv2