hbrtl_ext/napibridge reimplements the C++ fivenode TFNModule in Go: it calls
the addon's registered C callbacks (npmRequire/npmCall/npmMethods/npmEnd) over
cgo. FN_REQUIRE(module) gets a handle, enumerates its methods, and builds a PRG
object whose method closures proxy oObj:method(args) to Node; results decode as
scalar / native array|hash / nested object handle (e.g. Buffer). The capi shim
forwards tfn_register_callbacks -> napibridge.StoreCallbacks. Calls run on the
node main thread (sync handleRequest), so the direct tfn_npm_* path needs no
marshaling.
Verified end-to-end (node -> addon -> Go libfivenode -> PRG):
- builtin: oOs:hostname()/platform()/arch() -> real values; oOs:cpus() -> native
array, Len()=10.
- real npm: oQR:imageSync() on qr-image (which goja could NOT run) -> Buffer
handle -> :toString("utf8") -> valid 1138-byte SVG.
Full npm is now reachable in-process. P4 (async/Promise via worker + npmAwait)
remains for async methods like qrcode.toString.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`fnode capi <entry.prg> -o libfivenode.dylib` generates all PRG as library
funcs + a cgo shim exporting the N-API C ABI, and builds buildmode=c-shared.
hb_bridge_handle_request stashes the request (read by PRG via FN_NAPI_REQ,
registered with HB_FUNC) and runs the PRG FN_HANDLE via capiVM.Run, returning
its JSON. capiEnsure calls RegisterLibModules so HB_FUNC/--rtl symbols install
into the VM (vm.Run drains libModules but not dynamicFuncs).
Verified: node → addon → Go libfivenode → PRG parses the request and runs
string/hash/JSON ops (Upper/Len/HB_ISHASH/hb_jsonDecode/Encode), round-trips a
200 response. Supersedes the P1 hand-written cmd/libfivenode (removed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>