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

Pass raw path to transpileModule so that customTransformers could access the raw path #835

Merged
merged 2 commits into from
Sep 15, 2018

Conversation

Brooooooklyn
Copy link
Contributor

If I want write some path based logic in my customTransformer, it couldn't be done now. Because only the filename was passed to typescript.

@johnnyreilly
Copy link
Member

johnnyreilly commented Sep 10, 2018

Could you provide an example of why this is useful / what possibilities this unblocks please?

Also, why transpileOnly specific? (Unless I've misunderstood your PR it's not catering for non-transpile)

And, would the change you are suggesting change the usage for other people already relying on custom transformers? Would this be a breaking change?

@Brooooooklyn
Copy link
Contributor Author

Brooooooklyn commented Sep 10, 2018

Could you provide an example of why this is useful / what possibilities this unblocks please?

Yes, I want to write a typescript transformer plugin like https://github.com/emotion-js/emotion/tree/master/packages/babel-plugin-emotion#sourcemap, and I must inject source-map into output results. Before I do such things, I must access the rawPath of source files.

Also, why transpileOnly specific?

in non-transpile situation, rawPath could get by typescript itself

would the change you are suggesting change the usage for other people already relying on custom transformers? Would this be a breaking change?

Maybe. It would change the value of node.getSourceFile().fileName in custom transformers. from xx.ts to /Users/aaa/bbb/ccc/xx.ts.
But as I know, most of custom transformers are not relying on this value. (only filename is too simply, you can do so little things with it)

@johnnyreilly
Copy link
Member

Before I do such things, I must access the rawPath of source files.

Cool

in non-transpile situation, rawPath could get by typescript itself

Sorry I don't follow your meaning here. Could you expand on this please?

@Brooooooklyn
Copy link
Contributor Author

let me explain it in this way.
if you write a custom transformer, and using it with transpileOnly: true and transpileOnly : false flags.
in transpileOnly: true situation, the value of node.getSourceFile().fileName is xxx.ts
in transpileOnly: false situation, the value of node.getSourceFile().fileName is /Users/aaa/bbb/ccc/xxx.ts, this value is correct for me now, and it was provided by TypeScript (typescript.Program resolve this path and provide it to custom transformer)

@johnnyreilly
Copy link
Member

Ah I see! So this will align the behaviour of transpileOnly: true and transpileOnly: false, is that right?

If that's the case I kind of consider this a bugfix and I think we should take it.

@Brooooooklyn
Copy link
Contributor Author

Brooooooklyn commented Sep 12, 2018

So this will align the behaviour of transpileOnly: true and transpileOnly: false, is that right?

Yes, right

align the behavior of `transpileOnly: true` and `transpileOnly: false`
@johnnyreilly
Copy link
Member

Could you update the package.json to 5.1.1 and put an entry in the changelog please?

@Brooooooklyn
Copy link
Contributor Author

updated

@Brooooooklyn
Copy link
Contributor Author

@johnnyreilly

@johnnyreilly
Copy link
Member

Thanks - quite busy right now but I'll try to put a release out soon.

@Brooooooklyn
Copy link
Contributor Author

thank you😁

@johnnyreilly johnnyreilly merged commit 8cec80d into TypeStrong:master Sep 15, 2018
@johnnyreilly
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants