curlconverter / curlconverter

Transpile curl commands into Python, JavaScript and 27 other languages
https://curlconverter.com
MIT License
7.17k stars 867 forks source link

Remove Top Level Await #609

Open j-mendez opened 5 months ago

j-mendez commented 5 months ago

Top level await makes the module incompatible with frameworks like astro.js and make it so that even using the module in an API route like nextjs.

Workaround for current top level imports.


let somethingExportable;

(async () => {
  /// logic to update somethingExportable
})()

export default somethingExportable;
verhovsky commented 5 months ago

To parse Bash code, curlconverter uses tree-sitter with tree-sitter-bash, which is a C library that is compiled into WASM for the browser. Loading these WASM files (there's two) has to be async for the network request or for WebAssembly.instantiate() I guess.

We could make all of curlconverter's toPython(), etc. functions async instead of using top-level async at the beginning to wait for the files to load but that would be a lot of work because on node.js there's no top-level async because tree-sitter's Node.js bindings aren't async since they don't need to load any files. So we would have to have two separate libraries on npm for curlconverter and curlconverter-web with different index.d.ts files with different signatures. It would also just be surprising, why would transforming a string into a string be async?