Add NAPI-based WASM runtime for SWC plugins
Replace wasmtime with a NAPI backend that delegates WASM compilation and execution to Node.js's V8 engine. This eliminates ~20MB of wasmtime/Cranelift from the native binary. Architecture: - New crate `swc_plugin_backend_napi` implements the `swc_plugin_runner::runtime` traits (Runtime, Instance, Caller) - A global ThreadsafeFunction bridges background SWC transform threads to the JS main thread where V8's WebAssembly APIs are available - Two Caller types: TsfnCaller (background thread, dispatches via TSFN) and DirectCaller (JS thread, direct memory access during host function callbacks) - JS-side wasm-manager.ts handles WebAssembly.Module/Instance lifecycle Files added: - crates/swc-plugin-backend-napi/ (Cargo.toml + lib.rs) - packages/next/src/build/swc/wasm-manager.ts Files modified: - Cargo.toml: add napi backend to workspace - crates/next-napi-bindings: switch plugin feature from wasmtime to napi - turbopack-ecmascript-plugins: switch from WasmtimeRuntime to NapiRuntime - packages/next/src/build/swc/index.ts: register WASM runtime at load
Showing
Please
register
or
sign in
to comment