-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce runPluginFirst option #254
Conversation
If set to true WASM plugins will be executed before TS transformations. Enabling this option is required for plugins that mutate decorators as they rely on the standard TS syntax and can't mutate transformed decorators. The existing behavior of running plugins after TS transformers is still the default behavior.
@ArnaudBarre Would you like me to update the readme as well? |
Hey @ArnaudBarre, thanks for your reply! The issue is that when TypeScript transforms decorators, regardless of version, it actually strips the decorators and converts them a different syntax. Thats why plugins that want to transform decorators requires the Once again - this PR is 100% agnostic to decorators version and will be required by all future versions and iterations of the decorators proposal. |
I'm very septical of this SWC api anyway: having either all plugins run before or after the TS transformation (and code lowering) is will not scale well. On vite the capability for plugins to be resister themself as I'm also septical about the need of running code transformation on decorators. What is your need for that? |
I'm the author of wix-incubator/obsidian - a dependency injection (DI) framework for React and React Native applications. DI frameworks commonly use "injection tokens" when injecting dependencies. For example: class Foo {
@inject(Tokens.BAR) bar: Bar; // inject a bar instance
}
// IoC container that maps tokens to dependencies
const container = new Container()
container.bind(Tokens.Bar).to(Bar) Concrete examples of this can be found in the InversifyJS docs or in microsoft/tsyringe both are very popular DI frameworks. Use case 1Personally I find this too verbose so in Obsidian we have Babel and WASM plugins that add the tokens automatically at transformation time.
Use case 2Like all other DI frameworks that are used to follow that Inversion of Control principle, we also have IoC containers. We use Babel and WASM to transform them to improve performance. We use a transformer to slightly alter methods decorated with a
Currently I have to direct users to use unplugin-swc which supports passing the I appreciate the discussion and the time you've taken to consider this feature. Thanks again for maintaining such an excellent project and for being so attentive and responsive 😇 PS, the current version of Obsidian still uses legacy decorators, but in v3 which is in alpha we transitioned to the latest implementation of decorators. |
Hey @ArnaudBarre I would like to re-emphasize three things:
Have a nice weekend, |
The philosophy of the plugin is more to be a faster version of the default one, and while SWC is not entirely a implementation detail, it not something we want people to be too much locked in. Once Vite ships with OXC, for me there are no benefits of downloading a 30MB rust toolchain to do what OXC does already and so I'm not planning to maintain this long after. Otherwise I think that what I could add is an |
Thank you very much for your thoughtful response and the consideration you've put into this matter. As a fellow maintainer of OSS projects - I truly appreciate it. Both options seem good to me. Obviously I'd be happier with option 1 but option 2 works just as well. |
If set to true WASM plugins will be executed before TS transformations. Enabling this option is required for plugins that mutate decorators as they rely on the standard TS syntax and can't mutate transformed decorators. The existing behavior of running plugins after TS transformers is still the default behavior.
Usage