Skip to content

设置

¥Setup

要求

¥Requirements

  • Linux、macOS 或 Windows

    ¥Linux, macOS, or Windows

  • JavaScript 运行时:

    ¥JavaScript Runtime:

    • Node.js 12.17.0 或更高版本

      ¥Node.js 12.17.0 or later

    • Bun 1.0.0 或更高版本

      ¥Bun 1.0.0 or later

    • Deno 1.x

  • 某种 bash 或 PowerShell

    ¥Some kind of bash or PowerShell

安装

¥Install

bash
npm install zx
bash
bun install zx
bash
deno install -A npm:zx

# zx requires additional permissions: --allow-read --allow-sys --allow-env --allow-run
bash
brew install zx

开发快照版本发布到 dev 标签 下的 npm:npm i zx@dev

¥Dev snapshot versions are published to npm under the dev tag: npm i zx@dev.

Bash

zx 主要依赖于 bash,因此请确保它在你的环境中可用。如果你使用的是 Windows,请考虑使用 Linux 的 Windows 子系统git 重击。默认情况下,zx 查找 bash 二进制文件,但你可以通过调用 usePowerShell()usePwsh() 切换到 PowerShell。

¥zx mostly relies on bash, so make sure it's available in your environment. If you're on Windows, consider using Windows Subsystem for Linux or Git Bash. By default, zx looks for bash binary, but you can switch to PowerShell by invoking usePowerShell() or usePwsh().

js
import { useBash, usePowerShell, usePwsh } from 'zx'

usePowerShell() // Use PowerShell.exe
usePwsh()       // Rely on pwsh binary (PowerShell v7+)
useBash()       // Switch back to bash

¥Package

混合

¥Hybrid

zx 作为 混合包 分发:它提供 CJS 和 ESM 入口点。

¥zx is distributed as a hybrid package: it provides both CJS and ESM entry points.

js
import { $ } from 'zx'

const { $ } = require('zx')

它还具有内置的 TypeScript libdef。

¥It has also built-in TypeScript libdefs.

ts
import { type Options } from 'zx'

const opts: Options = {
  quiet: true,
  timeout: '5s'
}

打包式

¥Bundled

我们使用 esbuild 生成静态构建,使我们能够同时解决多个问题:

¥We use esbuild to produce a static build that allows us to solve several issues at once:

  • 减少 pkg 大小并缩短安装时间。

    ¥Reduce the pkg size and install time.

  • 使 npx (yarn dlx / Bunx) 调用可重现。

    ¥Make npx (yarn dlx / bunx) invocations reproducible.

  • 提供对各种 Node.js 版本的支持:从 12 点到 22 点。

    ¥Provide support for wide range of Node.js versions: from 12 to 22.

  • 让审计变得更容易:完整代码集中在一处。

    ¥Make auditing easier: complete code in one place.

合成

¥Composite

zx 导出多个适合不同用例的入口点:

¥zx exports several entry points adapted for different use cases:

  • zx - 主要入口点,提供所有功能。

    ¥zx – the main entry point, provides all the features.

  • zx/global - 使用 zx 函数填充全局范围。

    ¥zx/global – to populate the global scope with zx functions.

  • zx/cli - 从命令行运行 zx 脚本。

    ¥zx/cli – to run zx scripts from the command line.

  • zx/core - 使用 zx 模板生成器作为 3rd 方库的一部分,并具有交替的实用程序集。

    ¥zx/core – to use zx template spawner as part of 3rd party libraries with alternating set of utilities.

google/zx 中文网 - 粤ICP备13048890号