Skip to content
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

Plugin system rewrite for swc and spack #1321

Closed
4 tasks
kdy1 opened this issue Jan 8, 2021 · 11 comments
Closed
4 tasks

Plugin system rewrite for swc and spack #1321

kdy1 opened this issue Jan 8, 2021 · 11 comments

Comments

@kdy1
Copy link
Member

kdy1 commented Jan 8, 2021

swc

We should

  • Allow specifying plugin in .swcrc file.

This requires calling js function from rust. See https://docs.rs/napi/1.1.1/napi/struct.JsFunction.html for apis for it.
We should create a sync::channel and call the stored js function javascript thread because the javascript function is not Send nor Sync.

  • Support calling babel plugins

It can done by converting the ast of swc into the one of babel. As ast node of babel does not have methods, so converting to json using newtype structs will work.

spack

  • Allow writing plugin with javascript

Requirement is same as above.

  • Allow using webpack plugins.

I'm not sure how hard this will be.

@kdy1 kdy1 added this to the v2.0 milestone Jan 8, 2021
@mfeckie
Copy link
Contributor

mfeckie commented Jan 8, 2021

What format would the plugins take in .swcrc?

{
  "plugins" [] // Array of strings? functions?
}

@kdy1
Copy link
Member Author

kdy1 commented Jan 8, 2021

@mfeckie

It should be string for now. In future, we may add support for javascript functions within .swcrc.js, just like babel.

@mfeckie
Copy link
Contributor

mfeckie commented Jan 8, 2021

{
  "plugins": ["my-plugin"]
}

The user would have this item in their package.json

  "my-plugin": "x.x.x"

And my-plugin would be built and published via napi-rs or would it be plain JS and napi-rs would only be used withing swc to make it callable?

@kdy1
Copy link
Member Author

kdy1 commented Jan 8, 2021

I think plugins should be written in plain javascript.

The ast definition changes over time, and it means native binaries should be rebuilt frequently. It's bad for plugin users.

@dwoznicki
Copy link
Contributor

dwoznicki commented Jan 8, 2021

Allow using webpack plugins.

I'm quite interested in spack as a replacement for webpack. I'll try looking into this, but I'm not familiar with this code base yet, so I might not be able.

@kdy1
Copy link
Member Author

kdy1 commented Jan 14, 2021

Are you guys working on this?
I'm asking this because I'm going to work on this if nobody is working on it.

@mfeckie
Copy link
Contributor

mfeckie commented Jan 14, 2021 via email

@dwoznicki
Copy link
Contributor

dwoznicki commented Jan 14, 2021

Yeah, I haven't gotten far either. I've managed to get bundle() to accept an array of plugin functions and execute them in Rust, but I'm still trying to figure out the internals of webpack's plugin system. Here's the small amount I've done so far, if it's any help.

@mischnic
Copy link
Contributor

mischnic commented Apr 4, 2021

Are there plans to support plugins written in Rust?

@kdy1
Copy link
Member Author

kdy1 commented Apr 4, 2021

@mischnic No. Managing two plugin APIs is too much for now.

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 17, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants