docs/adr/00001-support-transformation-plugin-native.md
Technical Story: Issue 2635 <!-- optional -->
SWC wants to support load, run plugins in the native binary for the custom transform behavior. SWC already have preliminary support to load plugins in its node.js JS bindings but it has known limitations.
[option 1] JS-based plugins, including babel plugins
[option 2] Plugins based on abi_stable and native dynamic libraries
[option 3] Wasm plugins based on wasmtime
[option 4] Wasm plugins based on wasmer
Chosen option: [option 4] Wasm plugins based on wasmer
This decision is taken because
plugin_ast) to pass into ffi boundary of the plugin.abi_stable based ffiSWC allow implementing plugins using javascript, and call it from worker threads as required. This includes babel plugins, to make migration from babel more convenient.
parse)napi (renamed to node-api) does not provide a way to get the return value of a function called from other thread than js thread. To workaround this, we should implement a complex request-response system based using lots of mutex.yield from a worker thread when we need to call js plugin. As a result, the when main js thread is busy because of js plugins, worker threads are also blocked without doing any task.abi_stable and native dynamic librariesPlugins are written in rust, and built as native libraries for each platforms. SWC pass data to plugin using special form of AST, which has stable memory representation regardless of the version of rustc.
@swc/wasm has no way to support plugins.wasmtimeSWC embeds wasmtime, loads plugin built as web assembly.
@swc/wasm has no way to support plugins.wasmtime does not support all platforms.wasmerSWC embeds web assembly runtime (https://wasmer.io/), loads plugin built as web assembly.
@swc/wasm can support plugins in future as wasmer officially supports using it within a wasm file.wasmer does not support all platforms.