ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.49k stars 783 forks source link

feat: Support providing custom TypeScript transformers #5602

Open maxpatiiuk opened 5 months ago

maxpatiiuk commented 5 months ago

Prerequisites

Describe the Feature Request

We need an ability to provide a custom TypeScript transformer plugin to Stencil to modify the code BEFORE Stencil extracts data from the AST.

https://github.com/ionic-team/stencil/blob/962372f3d2ceb1c25573b845ee34d2ccb40945ff/src/compiler/transpile/transpile-module.ts#L114-L122

Describe the Use Case

Stencil allows to define a rollup plugin that would transform the output code.

However, current implementation is very limited because rollup plugins are called after Stencil pulled the data from the AST for each component and transformed the code using TypeScript plugins.

This means:

Describe Preferred Solution

Ability to provide a custom TypeScript transformer in the stencil.config.ts file that would be called before Stencil extracts data from the AST and begins it's transformation.

Describe Alternatives

Expose buildCtx and compilerCtx objects to Rollup plugins so that they could modify the Stencil's compiler meta or internal file system before Stencil outputs the built files.

A partial solution may also be to expose the cmpMeta to the component at run-time to let it dynamically define watchers and to let it get a list of all the props/states available on the component (to integrate each prop with an external reactivity library)

Without this, our "hacky" solution may be to use Stencil's Core Compiler API rather than the CLI directly (we would have to create our own CLI) to provide a custom file system object that would modify the source files before Stencil extracts component meta from the AST

Related Code

No response

Additional Information

Requested by: Esri

Related issues:

alicewriteswrongs commented 5 months ago

Hey @maxpatiiuk, thanks for writing up the feature request!

I'm just curious, what is it that you're trying to do via your rollup plugin that you're unable to do? Just to get a sense of what the use-case for this is for your team.

maxpatiiuk commented 5 months ago

Sure. We have several use cases that would be much easier to resolve with a TypeScript transformer (until Stencil supports all of this natively):

In general, most things are motivated by:

alicewriteswrongs commented 5 months ago

Thanks for providing that breakdown! I know that code re-use and extensibility / composition is a pain point in Stencil at present and it is something that we want to address for sure.

I'm going to circulate what you shared among the team and we'll noodle on it a bit!