zx icon indicating copy to clipboard operation
zx copied to clipboard

Feature req: bundler option/ js runtime

Open danikhan632 opened this issue 3 years ago • 6 comments

Enable the use of webpack/bundler and an alternative JS runtime such as Deno/ Bun.js

current implementation relies on slow/long setup

  • feature would bundle node_modules and index.mjs to a single file
  • additionally, packaging a lite JS runtime in an shell script would make deployments ideal

really love this repo, let me know I can help make this happen

danikhan632 avatar Nov 01 '22 03:11 danikhan632

Now sure about deno/bun. Zx uses nodejs stuff. For example, async_hooks package.

Bundled version can be created, I think.

antonmedv avatar Nov 01 '22 07:11 antonmedv

No chance to enable async_hooks in bun for now: https://github.com/oven-sh/bun/issues/158.

antongolub avatar Nov 01 '22 09:11 antongolub

Bundled version can be created, I think. @antonmedv I'd love to work on the bundling feature, if I wanted to merge or if I needed some clarity would that be okay?

danikhan632 avatar Nov 01 '22 13:11 danikhan632

@danikhan632

Just FYI: I've experimented a bit with this and found some caveats. (tried both esbuild / rollup, parcel) didn't have the energy to go webpack

  • https://github.com/chalk/supports-color/issues/113
  • Creating a bundle that both supports to be run with a node and a zx shebang. (Error: Dynamic require of "path" is not supported )
  • I had good luck with esbuild, but it doesn't support types by design, and my goal is to use the same distribution both on dev & and prod.
  • For now, I'm just executing the bundled file with zx, but it would be nice to create a vanilla esm build (that also contains types)

borestad avatar Nov 07 '22 07:11 borestad

[Not] sure about deno/bun. Zx uses nodejs stuff. For example, async_hooks package.

Deno has pretty good support for a lot of node/npm stuff now:

I just tried this out of over-optimistic curiosity:

deno install --allow-all npm:[email protected]

And it appears to install correctly, but then throws this when trying to run a script with zx:

error: Could not resolve 'node:repl' from 'file:///home/joe/.cache/deno/npm/registry.npmjs.org/zx/7.1.1/build/repl.js'.

Caused by:
    [ERR_UNSUPPORTED_ESM_URL_SCHEME] Only file and data URLS are supported by the default ESM loader. Received protocol 'node'

I'm guessing that a deno.json config file (pointing to a Deno-specific import map) would be needed to work around this sort of problem.

josephrocca avatar Jan 13 '23 20:01 josephrocca

Well, I haVE AN IDEA TO CRETEASE A STRIPPEN dOWN VERSION OF ZX FOR ONLY $. This can hgelp./

antonmedv avatar Jan 13 '23 21:01 antonmedv