4 ms·
For something which works across all JS runtimes (Deno, Node) and achieves basically the same, check out the popular JS library Execa[1]. Works like a charm! A
by nathan_phoenix 3y ago
For something which works across all JS runtimes (Deno, Node) and achieves basically the same, check out the popular JS library Execa[1]. Works like a charm!
Another alternative is the ZX shell[2] JS library. Tho haven't tested it.
[1]: https://github.com/sindresorhus/execa https://github.com/sindresorhus/execa
[2]: https://github.com/google/zx https://github.com/google/zx
- neongreen 3y agoI’m using zx and the API seems very similar to what is described in the post. Which bun also acknowledges here: https://github.com/oven-sh/bun/blob/main/docs/runtime/shell.md https://github.com/oven-sh/bun/blob/main/docs/runtime/shell.... I suppose one significant difference is that bun reimplements shell built-ins. I believe that zx simply executes bash or powershell and fails if neither is available.
- qazxcvbnm 3y agoOne thing that surprised me about Node was how slow the default way to shelling out (child_process) could be (probably https://github.com/nodejs/node/issues/14917 https://github.com/nodejs/node/issues/14917). Although according to the linked issue, it has been "fixed", I still ran into a problem during a batch script that was calling imagemagick through a shell for each file in a massive directory; profiling was telling me that starting (not completing) (yes, I was using the async version) the child process increasingly slows, from sub-millisecond for the first few spawns, to eventually hundreds of milliseconds or seconds... Eventually I had to resort to doing only single spawn of a bash script that in turn did all the shelling out. It seems that the linked execa still relies on child_process and therefore has the same issue. It saddens me to see the only package for node that appears to actually fix this and provide a workaround seems to be https://github.com/TritonDataCenter/node-spawn-async https://github.com/TritonDataCenter/node-spawn-async and unmaintained.
- kvakil 3y agoI worked on that Node.js issue. If you can share a repro, I'd love to take a look: https://github.com/nodejs/node/issues/new?assignees=&labels=&projects=&template=1-bug-report.yml https://github.com/nodejs/node/issues/new?assignees=&labels=...
- qazxcvbnm 3y agoThat's very kind of you - I tried making a dead-simple repro just now with Node 20, and it seemed to run without the problem. I'll try reproducing it in a bit with my original use case of imagemagick and see if the issue still exists.
- dsherret 3y agoFor Deno there is https://github.com/dsherret/dax https://github.com/dsherret/dax which is also zx inspired and has a cross platform shell built-in.