Closed titanous closed 1 year ago
This really nice. Thank you. My concern is the substitution of the user's configuration. It just feels wrong and complicates things.
If you are already patching the cli, I would go a step further and introduce a new --plugin multi-option. This can be done during the initialization phase
I agree that adding a CLI flag makes sense. It also may be better for upstream because they can punt on relative paths in the config. I came up with this design when I thought that it could work without modifying SWC at all 😅
I think by adding a new option you can also resolve the issue with the base path in https://github.com/swc-project/swc/pull/6800.
Providing a path using the --plugin option should work in the same way as providing a path using a --config option.
Updated to use CLI arguments added in https://github.com/swc-project/swc/pull/6811
Much better, thanks for the suggestion, @realtimetodie!
Hey @titanous thanks for the contribution, sorry I didn't get to it earlier. I rebased over #146 which mirrored the latest swc version, and dropped your commit that switched to your custom fork.
I think this would be nice to get into the 1.0 :)
https://github.com/swc-project/swc/pull/6835 has now been merged, so as soon as a new version of SWC is released this PR should be ready to go.
upstream cut the release, so I think this is unblocked now @titanous :)
Indeed, the tests are now passing locally and this is ready for review.
The added wasm file is 2MB which will severely bloat our download for users of the ruleset. Can we fetch it with http_file
from somewhere instead?
Yes, we should not add binary files, wasm or not.
Luckily, there is rules_rust which can be used to ceate a plugin with the wasm bindgen rules.
https://bazelbuild.github.io/rules_rust/rust_wasm_bindgen.html
Rust wasm bindgen is a Rust library and CLI tool that facilitates high-level interactions between wasm modules and JavaScript. This would also be a great example for users.
PTAL
PTAL
This PR implements all of the wiring necessary to use SWC plugins.
swc_plugin
macro/rule pair that creates a target with the necessary providers:DefaultInfo
pointing at a wasm file or an npm package containing a wasm file as themain
entrypoint in thepackage.json
SwcPluginConfigInfo
holding the plugin configurationplugins
attr toswc_compile
andswc
, taking a list of plugin targets, along with helpers to inject the plugin config.