unjs / jiti

Runtime Typescript and ESM support for Node.js
MIT License
1.49k stars 52 forks source link

feat: basic top-level await support #239

Closed pi0 closed 1 month ago

pi0 commented 1 month ago

This PR supports basic top level await support via jiti.import() and jiti <path> CLI.

Implementation is fairly basic and adds support by wrapping the module into an async function instead of function that Node.js does.

In order to allow chained usage, since jiti transforms all imports to require internally, we replace = require( patterns to = await require in async contexts to make sure they are resolved. (this is more of a workaround but better than not having it!)

aryaemami59 commented 1 month ago

This is very exciting.