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

Transformers with transpileOnly #1051

Closed
thetutlage opened this issue May 22, 2020 · 10 comments · May be fixed by techsysvbo/kubernetes-tutorials#3
Closed

Transformers with transpileOnly #1051

thetutlage opened this issue May 22, 2020 · 10 comments · May be fixed by techsysvbo/kubernetes-tutorials#3
Labels
bug you can do this Good candidate for a pull request.

Comments

@thetutlage
Copy link
Contributor

I have read the readme file and it does mention that the transformers are not supported with the transpileOnly mode.

I do see that the source code is using ts.transpileModule which does support custom transformers. So my question is mainly to understand the reasoning behind not allowing transformers, when the underlying API of typescript allows it?

@thetutlage thetutlage changed the title Transformers with traspileOnly Transformers with transpileOnly May 22, 2020
@cspotcode
Copy link
Collaborator

Git blame offers some context.

https://github.com/TypeStrong/ts-node/blame/master/src/index.ts#L789
#879

Transformers get access to the typechecker, which isn't available in transpileOnly mode.

If you want to use transformers in transpileOnly mode, I recommend using ttypescript via our compiler option. This will let you configure transformers via your tsconfig file.

ttypescript is a drop-in replacement for typescript with comprehensive transformer support. ts-node supports using alternative compilers.

https://github.com/cevek/ttypescript/tree/master/packages/ttypescript

@thetutlage
Copy link
Contributor Author

thetutlage commented May 23, 2020

Transformers get access to the typechecker

Yup, but there are other transformers as well. For example: A transformer to process path aliases and can be done in transpile only mode as well.

If you want to use transformers in transpileOnly mode, I recommend using ttypescript via our compiler option. This will let you configure transformers via your tsconfig file.

Yes, but don't want to use that.

The main question was, if transpileModule from compiler API accept the transfomers (with whatever limited capability), then why we cannot pass those transformers to typescript vs deciding to remove them all together

@cspotcode
Copy link
Collaborator

Looking at our source code again, it looks like transformers actually are supported in transpileOnly mode. The README's not super-clear, but it says that you cannot pass a factory function to our transformers option, but you can pass an object.

@thetutlage
Copy link
Contributor Author

thetutlage commented May 23, 2020

The code right now only accepts the compilerOptions and not the transformers. https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L492-L494

Whereas the options Typescript accepts are following.

interface TranspileOptions {
  compilerOptions?: CompilerOptions;
  fileName?: string;
  reportDiagnostics?: boolean;
  moduleName?: string;
  renamedDependencies?: MapLike<string>;
  transformers?: CustomTransformers;
}

@cspotcode
Copy link
Collaborator

This is what I'm looking at:

image

Which matches the type signature in our README.

@thetutlage
Copy link
Contributor Author

If types are working doesn't mean the runtime code is also working. The source code reference I shared with you clearly shows that transformers are not passed to the transpileModule method.

Check this out

CleanShot 2020-05-23 at 13 20 24

@cspotcode cspotcode added bug you can do this Good candidate for a pull request. labels May 23, 2020
@cspotcode
Copy link
Collaborator

In that case, marked as "bug" and "help wanted." We'll accept a pull request that fixes it.

@thetutlage
Copy link
Contributor Author

Sure, I will do a PR. Just wanted to understand, if we both expect it to work. Thanks 😄

@cspotcode
Copy link
Collaborator

This is (finally) published in v9.0.0: https://github.com/TypeStrong/ts-node/releases/tag/v9.0.0

@zyf0330
Copy link

zyf0330 commented Jul 27, 2021

Hello, ts-node -T -C ttypescript still fails, why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug you can do this Good candidate for a pull request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants