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

ts-patch can't do async #176

Open
arthurwolf opened this issue Jan 9, 2025 · 1 comment
Open

ts-patch can't do async #176

arthurwolf opened this issue Jan 9, 2025 · 1 comment

Comments

@arthurwolf
Copy link

Hello.

I'm trying to create a ts-patch transformer to transform some code before it's executed.

The problem is the tool I'm trying to call (like much of npm nowadays...) expects an async call.

So I start adding await before the call, and moving up in my code transforming functions to async as I go.

And I hit a wall when I get down to the level of ts-patch / the transformer itself... It expects sync functions, and won't do await / deal with any kind of async function.

Is there any way to get this to work? Some kind of solution I'm not considering?

Any help would be very much appreciated.

Thanks a lot in advance.

@artem1458
Copy link

artem1458 commented Jan 13, 2025

Hello @arthurwolf
The problem is that typescript compiler api is completely synchronous at that moment, that means that transformers can't return a Promise<ts.Node>, only ts.Node

If you need some data that is asynchronous - you should wait for this data before typescript compilation process will be called

You can also check PluginCompiler.ts and ProgramStorage.ts maybe it will help

Also you can share more detailed example of what you're trying to achieve, and maybe I can help find a solution

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

No branches or pull requests

2 participants