Socket
Socket
Sign inDemoInstall

zx

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zx - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

2

index.d.ts

@@ -30,2 +30,4 @@ // Copyright 2021 Google LLC

export function sleep(ms: number): Promise<void>
export function question(query?: string, options?: QuestionOptions): Promise<string>

@@ -32,0 +34,0 @@

2

package.json
{
"name": "zx",
"version": "1.5.0",
"version": "1.6.0",
"description": "A tool for writing better scripts",

@@ -5,0 +5,0 @@ "main": "index.mjs",

@@ -24,4 +24,4 @@ # 🐚 zx

JavaScript is a perfect choice, but standard Node.js library
requires additional hassle before using. `zx` package provides
useful wrappers around `child_process`, escapes arguments and
requires additional hassle before using. The `zx` package provides
useful wrappers around `child_process`, escapes arguments and
gives sensible defaults.

@@ -38,6 +38,6 @@

Write your scripts in a file with `.mjs` extension in order to
be able to use `await` on top level. If you prefer `.js` extension,
wrap your script in something like `void async function () {...}()`.
be able to use `await` on top level. If you prefer the `.js` extension,
wrap your scripts in something like `void async function () {...}()`.
Add next shebang at the beginning of your script:
Add the following shebang to the beginning of your `zx` scripts:
```bash

@@ -47,3 +47,3 @@ #!/usr/bin/env zx

Now you will be able to run your script as:
Now you will be able to run your script like so:
```bash

@@ -54,3 +54,3 @@ chmod +x ./script.mjs

Or via `zx` bin:
Or via the `zx` executable:

@@ -61,9 +61,9 @@ ```bash

When using `zx` via bin or shebang, all `$`, `cd`, `fetch`, etc
are available without imports.
When using `zx` via the executable or a shebang, all of the functions
(`$`, `cd`, `fetch`, etc) are available straight away without any imports.
### ``$`command` ``
Executes given string using `exec` function
from `child_process` package and returns `Promise<ProcessOutput>`.
Executes a given string using the `exec` function from the
`child_process` package and returns `Promise<ProcessOutput>`.

@@ -75,3 +75,3 @@ ```js

Example. Upload files in parallel:
For example, to upload files in parallel:

@@ -85,3 +85,4 @@ ```js

If executed program returns non-zero exit code, `ProcessOutput` will be thrown.
If the executed program returns a non-zero exit code,
`ProcessOutput` will be thrown.

@@ -110,7 +111,7 @@ ```js

Changes working directory.
Changes the current working directory.
```js
cd('/tmp')
await $`pwd` // outputs /tmp
await $`pwd` // outputs /tmp
```

@@ -120,3 +121,4 @@

This is a wrapper around [node-fetch](https://www.npmjs.com/package/node-fetch) package.
A wrapper around the [node-fetch](https://www.npmjs.com/package/node-fetch) package.
```js

@@ -131,3 +133,3 @@ let resp = await fetch('http://wttr.in')

This is a wrapper around [readline](https://nodejs.org/api/readline.html) package.
A wrapper around the [readline](https://nodejs.org/api/readline.html) package.

@@ -149,4 +151,16 @@ ```ts

### `sleep()`
A wrapper around the `setTimeout` function.
```ts
function sleep(ms: number): Promise<void>
```
Usage:
```js
await sleep(1000)
```
### `chalk` package

@@ -164,3 +178,3 @@

The [fs](https://nodejs.org/api/fs.html) package is available without importing
inside scripts.
inside scripts. It is asyncronous by default.

@@ -171,8 +185,2 @@ ```js

Promisified version imported by default. Same as if you write:
```js
import {promises as fs} from 'fs'
```
### `os` package

@@ -197,3 +205,3 @@

Specifies command what will be added to all command.
Specifies the command what will be prefixed to all commands run.

@@ -204,14 +212,13 @@ Default is `set -euo pipefail;`.

Specifies a function what will be used for escaping special characters in
command substitution.
Specifies a function what will be used for escaping special characters during
command substitution.
Default is [shq](https://www.npmjs.com/package/shq)
package.
Default is the [shq](https://www.npmjs.com/package/shq) package.
### `$.verbose`
Specifies verbosity. Default: `true`.
Specifies verbosity. Default is `true`.
In verbose mode prints executed commands with outputs of it. Same as
`set -x` in bash.
Verbose mode prints all executed commands along with their outputs.
The is the same as using `set -x` in Bash.

@@ -221,9 +228,16 @@ ### `__filename` & `__dirname`

In [ESM](https://nodejs.org/api/esm.html) modules, Node.js does not provide
`__filename` and `__dirname` globals. As such globals really handy in scripts,
`zx` provides such globals, so they can be used in `.mjs` files (via using `zx`
binary).
`__filename` and `__dirname` globals. As such globals are really handy in scripts,
`zx` provides these for use in `.mjs` files (when using the `zx` executable).
### `require`
In [ESM](https://nodejs.org/api/modules.html#modules_module_createrequire_filename) `require` is not defined,
but sometimes it's convenient to have this legacy api in global.
```js
require('./version.js')
```
### Importing from other scripts
It's possible to use `$` and others with explicit import.
It is possible to make use of `$` and other functions via explicit imports:

@@ -245,3 +259,3 @@ ```js

If arg to `zx` bin starts with `https://`, it will be downloaded and executed.
If the argument to the `zx` executable starts with `https://`, the file will be downloaded and executed.

@@ -248,0 +262,0 @@ ```bash

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc