Comments (15)
After thinking 💭 zx targets only node. And there’s already a few deno implementations.
from zx.
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.
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.
@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.
@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.
@ry why not use Deno in first place? 😋
from zx.
Fair point, so it’s better to have two separate implementation for different backends.
from zx.
Wow! Supper impressive)
from zx.
@ry this is definitely a good idea. Will take a look at how to do it.
from zx.
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.
Cool! I wonder if it possible to use compatibility later to make zx able to run on nodejs and deno simultaneously.
from zx.
@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.
found this one too: https://github.com/linux-china/dx
from zx.
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.
This why I don’t think supporting both runtimes is something I want to do)
from zx.
Related Issues (20)
- An easy way to specify stdin HOT 3
- Replacing globby with a lighter alternative HOT 3
- Problem with Nested double quote and single quote command
- Windows: Create process not expected to return HOT 6
- feat request: provide formatters shortcuts
- feat req: provide `signal` opt
- Setting stdio/err to inherit throws error HOT 1
- Typo in 8.0 release description HOT 1
- Feature request: automatically add a newline after commands that don't end their output with one HOT 4
- The type for `glob` is `any` after 8.0.0 HOT 5
- Port listening doesn't stop when using `CTRL+C` HOT 11
- Feature request: add `usePwsh` helper for PowerShell 7+ HOT 3
- Why zx instead of Python ? HOT 2
- Markdown script didn't work for CRLF file
- Is Node.js 12.17.0 supported for zx as a package ? HOT 7
- Single file executable?
- Docs: Typo in setup docs
- fetch's document link is wrong HOT 4
- bun compatibility: get rid of async_hooks.createHook call HOT 3
- cannot concatenate strings with ${} HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zx.