Closed mattem closed 3 years ago
I have approx. this thing landing for Angular to plugin the new Ivy compiler ngtsc
as a transformer plugin. Additionally a plugin can contribute program diagnostics (by proxying the ts.Program
like a LanguageService plugin does) and can contribute files to the root program (by proxying the ts.CompilerHost
)
In the first pass we're adding this specifically for the Angular compiler, then when we've iterated on it a couple times we'll commit to a public API allowing rules to contribute plugins of their own.
/cc @mprobst
Update: ts_library
has the compile_angular_templates
attribute but it's still not functional. Will pick it up again this quarter.
@rictic is adding this right now for lit-html support. Let's have a design discussion here about what you need. Is it only CustomTransformers? You don't need to augment the diagnostics or emit additional files right?
There is pending proposal for TSC plugins from the Microsoft team, so we should be careful to align with that, and not invent something future incompatible.
I am not sure if waiting on Angular is viable, as taking away capabilities is always a lot more painful and hard than giving them, and Angular right now has full control over the compilation.
@mattem can you describe the purpose of your transformers?
For lit-html we have two use cases. One is contributing diagnostics, and the other is build-time optimization. I'm working on the diagnostics part right now (just doing the minimal work necessary to hook up https://github.com/runem/ts-lit-plugin).
Will probably be a few months before I start work on the build-time optimization, but from what I've seen so far it looks like the transformer API will do fine.
@rictic We use a transformer to generate toMessage
and fromMessage
methods to convert to and from our JSON API messages and the class instance. The class and its properties etc are annotated, these annotations are then stripped and converted into the methods.
We don't generate any new files, just modify the AST, however it does contribute diagnostics iirc.
I'm going to pick up the Angular transformer again soon, I think we can make the hooks you need. You might need a macro or rule wrapper around ts_library as I don't think we're ready to commit to a general plugin mechanism in starlark yet, which would be different from internal usage at google
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!
This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"
🚀 feature request
Relevant Rules
ts_library
Description
We'd like to access the Typescript transformer API from the
ts_library
rule, with the ability to 'plugin' custom transformers.Currently we have our own wrapped TSC, which adds in our transformer pipelines and is then invoked on the code that requires it.
Describe the solution you'd like
java_library
andjava_binary
have theplugins
attribute that can be used with annotation processors, perhaps an API similar to that? (Admittedly I haven't looked at the implementation of rules_typescript to know how possible this is)Describe alternatives you've considered
None so far, open to suggestions 😄