Giter VIP home page Giter VIP logo

Comments (15)

antonmedv avatar antonmedv commented on May 7, 2024 30

After thinking 💭 zx targets only node. And there’s already a few deno implementations.

from zx.

Minigugus avatar Minigugus commented on May 7, 2024 13

Here is a working Deno version if you're interested https://deno.land/x/zx_deno. All features but chalk are preserved (replaced with deno.land/std/fmt/colors.ts): f021edc...Minigugus:main

deno install -A --unstable https://deno.land/x/zx_deno/mod.mjs

from zx.

mono0x avatar mono0x commented on May 7, 2024 13

Currently, it seems to the zx works with Deno thanks to AsyncLocalStorage becoming ready on Deno.

import "npm:[email protected]/globals";
await $`echo "Hello, world!"`;
❯ deno --version
deno 1.30.3 (release, x86_64-unknown-linux-gnu)
v8 10.9.194.5
typescript 4.9.4

❯ deno run -A hello.ts
$ echo "Hello, world!"
Hello, world!

from zx.

Minigugus avatar Minigugus commented on May 7, 2024 9

@antonmedv Another solution could be to enhance the api exposed by zx so that users that wants compatibility just have to avoid backend specific code. For instance question, cd and fetch works in the same way for both the Node and Deno version, so maybe we could add zx versions of read, mkdir, open, and so on? At the same time, it would allow to transpose bash commands into zx functions (eg. for await (const file of ls(pwd())))

from zx.

Minigugus avatar Minigugus commented on May 7, 2024 4

@josh-hemphill My fork use https://deno.land/[email protected]/node/os.ts and https://deno.land/[email protected]/node/fs.ts in order to preserve scripts compatibility with the original zx package, but they aren't stable yet 😕

And indeed, Deno is fine here, for instance it can run remote code natively, it have a native fetch implementation and the global Deno object provides mostly the same features as the fs and os packages.

It is even possible to run a remote zx script without an installation step in 1 command line: deno run -A --unstable https://deno.land/x/zx_deno/zx.mjs https://deno.land/x/zx_deno/examples/parallel.mjs 😮

EDIT: It is now available on deno.land: https://deno.land/x/zx_deno

from zx.

Guergeiro avatar Guergeiro commented on May 7, 2024 3

@ry why not use Deno in first place? 😋

from zx.

antonmedv avatar antonmedv commented on May 7, 2024 1

Fair point, so it’s better to have two separate implementation for different backends.

from zx.

antonmedv avatar antonmedv commented on May 7, 2024 1

Wow! Supper impressive)

from zx.

antonmedv avatar antonmedv commented on May 7, 2024

@ry this is definitely a good idea. Will take a look at how to do it.

from zx.

josh-hemphill avatar josh-hemphill commented on May 7, 2024

I was just thinking of this, Minigugus beat me to it. Deno would also make it really simple to distribute a simple binary that already has all the zx shortcuts pre-bundled, and distribute it to package managers if it gains enough traction.

@Minigugus what unstable features is your fork using?

from zx.

antonmedv avatar antonmedv commented on May 7, 2024

Cool! I wonder if it possible to use compatibility later to make zx able to run on nodejs and deno simultaneously.

from zx.

Minigugus avatar Minigugus commented on May 7, 2024

@antonmedv Thanks to the os and fs compatibility modules in the Deno standard library, a lot of zx scripts are already compatible. However, every script than manipulates global objects like process, Buffer, Deno, window, and so on is not compatible because theses objects that are plateform-specific, and add polyfills for both Node and Deno is way beyond zx... 😕

from zx.

jl4386 avatar jl4386 commented on May 7, 2024

found this one too: https://github.com/linux-china/dx

from zx.

kidonng avatar kidonng commented on May 7, 2024

Adding some info here. While a direct Deno port is not available, zx is working fine through Deno's Node compat layer:

> deno eval '
    import "https://esm.sh/[email protected]/src/[email protected]"
   
    const name = "zx"
    const runtime = "Deno"
    $`echo ${name} ❤️ ${runtime}`
'
$ echo zx ❤️ Deno
zx ❤️ Deno

Gotchas:

  • Any version newer than 6.1.0 throws an error, due to AsyncLocalStorage not implemented:

    > deno eval '
        import "https://esm.sh/[email protected]/build/[email protected]"
    '
    error: Uncaught SyntaxError: The requested module 
    'https://deno.land/[email protected]/node/async_hooks.ts' does not provide an export named 
    'AsyncLocalStorage'
        at <anonymous> (https://esm.sh/v87/[email protected]/X-ZC9jaGFsa0A0LjEuMg/deno/core.js:2:607)
    
  • chalk needs to be pinned to 4.x as esm.sh doesn't support the way newer versions import dependencies. This is not a Deno issue per se, it can also be avoided by e.g. importing zx bundled with dependencies.

from zx.

antonmedv avatar antonmedv commented on May 7, 2024

This why I don’t think supporting both runtimes is something I want to do)

from zx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.