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

[Feature] add startServiceSync or transformSync #136

Closed
aelbore opened this issue May 23, 2020 · 2 comments
Closed

[Feature] add startServiceSync or transformSync #136

aelbore opened this issue May 23, 2020 · 2 comments

Comments

@aelbore
Copy link

aelbore commented May 23, 2020

  • this is useful in some other plugins that doesnt support async/await/promise i think jest doesnt support yet the process async to the transform
@evanw
Copy link
Owner

evanw commented May 25, 2020

It's good to know that there's a use case for this. I will consider adding something like this to the official API. Unfortunately it's not possible to benefit from the better performance of the service-oriented API synchronously because it uses streams for communication and stream I/O is asynchronous in node.

It's straightforward to use esbuild in node in a synchronous manner, but you're going to have to incur the overhead of creating a new process every time. Depending on what you're doing, that might be fine. Here's an example of how you might do this, which you can use now without official API support:

function transformSync(input) {
  const execFileSync = require('child_process').execFileSync
  const {buffer} = execFileSync('esbuild', ['--loader=tsx'], {input})
  return Buffer(buffer).toString()
}

@evanw
Copy link
Owner

evanw commented Jun 11, 2020

This API is now published in version 0.5.0. The JavaScript API documentation is now here.

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