-
Notifications
You must be signed in to change notification settings - Fork 135
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
How to implement macro with async function inside? #62
Comments
Yes, this is a sad limitation to babel transforms. They are completely synchronous. @threepointone told me this crazy idea to make async node code run synchronously. It's going to be slow, but it works like a charm. Here's an example from real code that I'm using at PayPal: const results = crossSpawn.sync('node', [
'-e',
`require("${spundlePath}")("${localesDir}", "${country}", "${locale}", (err, out) => {console.log(JSON.stringify(out))})`,
])
const en = JSON.parse(results.stdout)['en-US'] That should give you an idea of how to make it run synchronously. There may be a module for this. In any case, I think we should either create a utility and expose that from babel-plugin-macros, or (probably better) create a module that makes this easier. What do you think? |
Can we make babel to accept async function? I'm not aware of implementation details. I will try your code meantime. |
Unfortunately not. But @hzoo may have some other ideas. |
I did this: function syncLqip(path) {
return execSync("node src/lqip.js " + path, { shell: false })
.toString("utf8")
.trim();
} |
I found workaround for my case. Should we close this ticket or keep open to find general solution? |
Maybe we could add a link to this issue in the author.md docs file? |
I've made @kentcdodds solution into a more generic & cleaner micro library: https://github.com/Zemnmez/do-sync |
Very cool @Zemnmez! Thank you 💯 |
babel-plugin-macros
version: 2.1.0node
version: 8.6npm
(oryarn
) version: yarn 1.5.1Relevant code or config
What you did:
What happened:
Reproduction repository:
https://github.com/stereobooster/lqip.macro
Problem description:
I want to implement
lqip.macro
. I'm not sure how to use asynclqip
inbabel-plugin-macros
, which seems to be expecting synchronous code. Am I wrong here? What is the way to work with async functions? ThanksSuggested solution:
The text was updated successfully, but these errors were encountered: