ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
831 stars 129 forks source link

Add custom transformers option #589

Closed layershifter closed 5 years ago

layershifter commented 5 years ago

Fixes #502.


Adds functionality to use custom transformers: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

Available via getCustomTransformers() option, the idea taken from awesome-typescript-loader.

layershifter commented 5 years ago

@ivogabe can you please review?

ivogabe commented 5 years ago

Thanks @layershifter for the PR! Sorry for the delay, I've been busy with other projects and didn't have time to take a look at this yet. Overall the changes look good, though I was wondering whether it is a large limitation that we don't pass a ts.Program to getCustomTransformers? That seems to be the difference with awesome-typescript-loader. Correct me if I'm wrong, but I assume that we cannot pass the project to the getCustomTransformers as we don't have one when isolatedModules is enabled, as we are then using a file-based compiler.

An alternative would be to change the type to (string | ((program?: ts.Program) => ts.CustomTransformers | undefined)), and only pass the program if isolatedModules is disabled. I assume that you would need the ts.Program if you need some type info of the program and we simply don't have that with isolatedModules enabled. If you need that type info, you should just not use isolatedModules. What do you think about that? If you want to make the change, you should call getCustomTransformers in the FileCompiler and ProjectCompiler and not in checkAndNormalizeSettings.

layershifter commented 5 years ago

@ivogabe thanks for feedback!

Correct me if I'm wrong

Nope, you're fully right.

(string | ((program?: ts.Program) => ts.CustomTransformers | undefined))

Looks good to me because I have already thought about this :+1: I will make these changes tomorrow.

ivogabe commented 5 years ago

Great! Let me know if you run into any problems.

layershifter commented 5 years ago

@ivogabe it seems that I made all requested changes. Can you please take a look? 😄

ivogabe commented 5 years ago

Thanks Alexander for your work! Changes look good. It will be part of the next release.

Yugloocamai commented 4 years ago

I am unable to get this feature working following the example in the docs :( The transformer is never called, even though it's imported successfully.