-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(swc/plugin): support context
for the plugin transform
#3568
Conversation
Actually I'm slightly leaning toward to 2 at this moment. We'll need to figure out what properties we'll expose in that case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Can you rebase it?
7b94c4f
to
b569a83
Compare
Yup, was doing it already. 🚢 |
b569a83
to
f56701b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename variables.
crates/swc/src/config/mod.rs
Outdated
@@ -424,6 +428,9 @@ impl Options { | |||
40, | |||
NodeModulesResolver::new(TargetEnv::Node, Default::default(), true), | |||
); | |||
let plugin_context = PluginContext { | |||
source_file_name: source_file_name.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use base
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_file_name
is used to control sourcemap, and base
is the filename.
It's named base
because the parameter is introduced because of paths
support, but I think it's a bad name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I was confused by name actually.
f56701b
to
add326e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Description:
From discussion #3540 (comment).
Plugin may need additional data other than config to plugin itself, mostly state around swc/core. Some examples like
or possibly more. This PR attempts to resolve those by forwarding new param named
context
.There are few possible approaches to enable this.
Obviously, this is not preferrable as we'll continously expand signatures and each time we add new param it'll cause breaking changes.
This is most clear interface signature. However, have same pitfall as first. Each time we add new properties into struct, it'll be a breaking change since our serialization does not support add-only / versioned
Current approach. Safe to add new properties since it's string, plugin can try to pick up necessary properties for their use.
Though I picked 3rd, I'm currently bit debating 2 also - if we can add enough context properties in experimental phase, we can stabilize those to avoid frequent breaking changes. The part I'm not sure is how frequent we'll need to change this context information. Would like to hear thoughts, and update PR into second if needed.
BREAKING CHANGE:
Plugin will need to accept 3rd param in any case, it could be a string or a typed struct.
Related issue (if exists):
#3540 (comment).