# ynpx

> `npx` equivalent in yarn, with multi-package-manager support (pnpm, yarn, npm)

Latest version **3.0.4** (published 2026-04-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install ynpx
pnpm add ynpx
yarn add ynpx
bun add ynpx
```

Provides the commands `ypx`, `ynpx`, `yypx`.

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2026-04-26 |
| First published | 2020-01-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 24 |
| Unpacked size | 214.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Maintainers | bluelovers |
| Keywords | yarn, run, local, bin, scripts, script, package, project, npx, dlx, npm, npm exec, shell, npm bin, cli, ypx, ynpx, yypx, yarn-tool, npm run, yarn run, alias, global, pnpm, package-manager, temp-directory, execute, run-local |

## Links

- npm: https://www.npmjs.com/package/ynpx
- Repository: https://github.com/bluelovers/ws-ypx
- Homepage: https://github.com/bluelovers/ws-ypx/tree/master/packages/ypx#readme
- Issues: https://github.com/bluelovers/ws-ypx/issues
- npm.io page: https://npm.io/package/ynpx

## Dependencies (24)

- [tmp](https://npm.io/package/tmp.md) ^0.2.5
- [tslib](https://npm.io/package/tslib.md) >=2
- [which](https://npm.io/package/which.md) ^6.0.1
- [yargs](https://npm.io/package/yargs.md) <18 >=17.7.2
- [lodash](https://npm.io/package/lodash.md) ^4.18.1
- [upath2](https://npm.io/package/upath2.md) ^3.1.23
- [ts-type](https://npm.io/package/ts-type.md) ^3.0.13
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.3.4
- [bin-exists](https://npm.io/package/bin-exists.md) ^0.2.1
- [camel-case](https://npm.io/package/camel-case.md) ^4.1.2
- [debug-color2](https://npm.io/package/debug-color2.md) ^1.3.2
- [crlf-normalize](https://npm.io/package/crlf-normalize.md) ^1.0.20
- [@ynpx/ynpx-argv](https://npm.io/package/@ynpx/ynpx-argv.md) ^1.0.19
- [cross-spawn-extra](https://npm.io/package/cross-spawn-extra.md) ^3.0.3
- [@yarn-tool/env-path](https://npm.io/package/@yarn-tool/env-path.md) ^2.0.14
- [lazy-aggregate-error](https://npm.io/package/lazy-aggregate-error.md) ^1.0.21
- [@yarn-tool/get-pkg-bin](https://npm.io/package/@yarn-tool/get-pkg-bin.md) ^3.0.10
- [@yarn-tool/npa-to-deps](https://npm.io/package/@yarn-tool/npa-to-deps.md) ^3.0.7
- [@yarn-tool/require-resolve](https://npm.io/package/@yarn-tool/require-resolve.md) ^4.0.8
- [@yarn-tool/update-notifier](https://npm.io/package/@yarn-tool/update-notifier.md) ^1.0.47
- [@yarn-tool/normalize-deps-value](https://npm.io/package/@yarn-tool/normalize-deps-value.md) ^2.0.8
- [@yarn-tool/npm-package-arg-util](https://npm.io/package/@yarn-tool/npm-package-arg-util.md) ^2.0.7
- [@yarn-tool/detect-package-manager](https://npm.io/package/@yarn-tool/detect-package-manager.md) ^1.0.9

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.0.4 (latest) — 2026-04-26
- 3.0.3 — 2026-03-12
- 3.0.2 — 2026-03-09
- 3.0.1 — 2026-03-09
- 2.1.6 — 2022-10-30
- 2.1.5 — 2022-08-28
- 2.1.4 — 2022-08-16
- 2.1.3 — 2022-07-07
- 2.1.2 — 2022-02-06
- 2.1.1 — 2021-08-26
- 2.0.10 — 2021-06-22
- 2.0.9 — 2021-06-05
- 2.0.8 — 2021-05-17
- 2.0.7 — 2021-02-09
- 2.0.6 — 2020-07-30
- … 33 more at https://npm.io/package/ynpx/versions

## README

![.github/workflows/test.yml](https://github.com/bluelovers/ws-ypx/workflows/.github/workflows/test.yml/badge.svg)

# ynpx

> `npx` equivalent in yarn with multi-package-manager support (pnpm, yarn, npm)

此模組名稱為 `ynpx` 而非 `ypx`。YNPX 是 `npx` 的 Yarn 等價實現，支援多種套件管理器。
This module name is `ynpx` not `ypx`. YNPX is an `npx` equivalent in yarn with multi-package-manager support.

---

## Features

- **v3+ Auto-Detection**: From v3, automatically detect and use `pnpm`, `yarn`, or `npm` / 從 v3 開始，自動偵測並使用 pnpm、yarn 或 npm
- **Multi-Package-Manager Support**: Auto-detect and use `pnpm`, `yarn`, or `npm` / 自動偵測並使用 pnpm、yarn 或 npm
- **Fast Execution**: Cache packages for faster subsequent runs / 快取套件以加速後續執行
- **Temporary Environment**: Isolated temp directory for each execution / 每次執行時建立隔離的臨時目錄
- **Flexible Configuration**: Support for `.yarnrc`, `.npmrc`, and custom configs / 支援 .yarnrc、.npmrc 和自訂配置
- **Debug Mode**: Keep temp directories after execution for debugging / 調試模式：執行後保留臨時目錄以便除錯

> First run (when not have cache), need a long wait

![image](https://github.com/bluelovers/ws-ypx/raw/master/packages/ypx/docs/image.png)

> Second run only need 5.x sec

![image_1](https://github.com/bluelovers/ws-ypx/raw/master/packages/ypx/docs/image_1.png)

## Install

```bash
# 使用 npm 安裝 / Install with npm
npm install -g ynpx

# 使用 yarn 安裝 / Install with yarn
yarn global add ynpx

# 使用 pnpm 安裝 / Install with pnpm
pnpm add -g ynpx
```

## Usage

### Basic Usage

```bash
ynpx jest
ynpx -p esm -p mocha --prefer-offline -- "!(node_modules)/**/*.{test,spec}.{ts,tsx}"
```

### Package Manager Selection

> **v3+ Feature**: From v3, `ynpx` will auto-detect available package managers automatically.

By default, `ynpx` will auto-detect available package managers in the order: `pnpm` → `yarn` → `npm`.

You can specify a preferred package manager:

```bash
# Use npm specifically
ynpx --npmClient npm jest

# Use pnpm specifically  
ynpx --pm pnpm jest

# Try yarn first, fallback to npm
ynpx --npmClient yarn --npmClient npm jest
```

### Command Options

| Option | Alias | Description | 選項說明 |
|--------|-------|-------------|
| `--package` | `-p` | Specify packages to install | 指定要安裝的套件 |
| `--npmClient` | `--pm` | Specify package manager (npm, yarn, pnpm) | 指定套件管理器 (npm, yarn, pnpm) |
| `--quiet` | `-q` | Suppress output | 抑制輸出 |
| `--prefer-offline` | | Use offline cache first | 優先使用離線快取 |
| `--ignore-existing` | | Skip checking if packages exist | 跳過檢查套件是否存在 |
| `--no-install` | | Skip package installation | 跳過套件安裝 |
| `--shamefully-hoist` | | Flat node_modules (for pnpm) | 扁平化 node_modules (適用於 pnpm) |
| `--userconfig` | `--rc` | Specify yarnrc config file | 指定 yarnrc 配置文件 |
| `--cwd` | | Set working directory | 設定工作目錄 | 設定工作目錄 |
| `--debugMode` | | Keep temp directories after execution for debugging | 執行後保留臨時目錄以便除錯 |

### Examples

```bash
# Run mocha with TypeScript support
ynpx -p esm -p ts-node -p mocha -- -r esm

# Run in quiet mode
ynpx -q cowsay -- "ynpx"

# Use offline cache
ynpx --prefer-offline jest
```

> ynpx -q cowsay -- "workflows test"

![image_2](https://github.com/bluelovers/ws-ypx/raw/master/packages/ypx/docs/image_2.png)

### Aliases

After install you can use alias names:

```bash
ynpx mocha
yypx mocha
ypx mocha
```

## Module Structure

The `ynpx` package consists of the following modules:

| Module | Description |
|--------|-------------|
| `createTemporaryDirectory` | Creates temp directories for package installation |
| `installDependencies` | Handles package installation with multi-PM support |
| `findCommand` | Locates package binaries |
| `handleEnv` | Manages environment variables and PATH |
| `handleOptions` | Processes CLI arguments |
| `initConfig` | Generates configuration files |
| `initTemporaryPackage` | Initializes temp package structure |
| `logger` | Provides colored console output |
| `types` | TypeScript type definitions |
| `util` | Utility functions |
| `err` | Custom error classes |

## Related Tools

- [yarn-tool](https://www.npmjs.com/package/yarn-tool)

## Links

- https://github.com/yarnpkg/yarn/issues/3937
- https://github.com/bluelovers/ws-ypx

## License

ISC

---
_Source: https://npm.io/package/ynpx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
