CLI & Node.js 设置

命令行设置#

[no-]color#

  • 默认值: auto
  • 类型:auto、tcp、ipc

设置输出的颜色.

  • auto - 当标准输出是终端或 TTY 时,输出会带有颜色。
  • always - 忽略终端和 pipe 之间的区别。 You'll rarely want this; in most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the pnpm command to force it to use color codes. The default setting is almost always what you'll want.
  • never - 关闭颜色. 这是 --no-color 使用的设置。

loglevel#

  • 默认值: auto
  • 类型:debug、info、warn、error

将显示大于等于给定级别的日志。你可以改为传递 --silent 来关闭所有输出日志。

reporter#

Selects the log reporter. See --reporter for the available reporters and terminal-dependent defaults.

useBetaCli#

  • 默认值: false
  • 类型:Boolean

启用 CLI 测试版功能的实验性选项。这意味着你使用的 CLI 功能可能会有一些不兼容的更改或潜在错误的更改。

recursiveInstall#

  • 默认值:true
  • 类型:Boolean

如果启用此选项,则 pnpm install 的行为将变为 pnpm install -r,这意味着在所有工作区或子目录包上执行安装操作。

否则,pnpm install 将只在当前目录中构建包。

engineStrict#

  • 默认值: false
  • 类型:Boolean

如果启用该选项,pnpm 将不安装任何声明与当前 Node 版本不兼容的包。

但无论该属性设置成什么值,如果项目(不是依赖项)在其 engines 字段中指定了不兼容的版本,则安装将始终失败。

npmPath#

  • 类型:路径

Pnpm 用于某些操作(例如发布)的 npm 的二进制文件的位置。

pmOnFail#

添加于:v11.0.0

  • 默认值: download
  • 类型:download, error, warn, ignore

当运行的 pnpm 版本与声明的版本不匹配时,覆盖 packageManager 字段和 devEngines.packageManager 的 onFail 行为。

  • download: download and run the declared pnpm version (this is the default and matches the previous managePackageManagerVersions: true behavior).
  • error: fail the command (equivalent to the previous packageManagerStrictVersion: true).
  • warn: print a warning but continue (equivalent to the previous packageManagerStrict: false or COREPACK_ENABLE_STRICT=0).
  • ignore: skip the check entirely (equivalent to the previous managePackageManagerVersions: false). 当版本管理由外部工具处理时很有用,如 asdf、mise 或 Volta。

A part of the configuration pnpm cannot read does not stop it from switching to the declared pnpm version, which reads the configuration itself. pnpm leaves out the file or setting it cannot read, and every other source still applies, so it switches only when the pmOnFail from the environment or a readable file is download.

可以通过 CLI 标志、环境变量或 pnpm-workspace.yaml 文件进行设置:

pnpm install --pm-on-fail=ignore
pnpm_config_pm_on_fail=ignore pnpm install
pnpm-workspace.yaml
pmOnFail: ignore

此设置取代了已移除的 managePackageManagerVersions、packageManagerStrict 和 packageManagerStrictVersion 设置,以及 COREPACK_ENABLE_STRICT 环境变量。

迁移:

已移除的设置 替换为
managePackageManagerVersions: true pmOnFail: download(默认)
managePackageManagerVersions: false pmOnFail: ignore
packageManagerStrict: false pmOnFail: warn
packageManagerStrictVersion: true pmOnFail: error
COREPACK_ENABLE_STRICT=0 pmOnFail: warn

另请参阅 pnpm with,了解如何在不更改此设置的情况下运行特定版本的 pnpm。

Node.js settings#

nodeVersion#

  • 默认值:node -v 的返回值,不带 v 前缀
  • 类型:精确的 semver 版本(不是范围)

检查程序包的 engines 设置时使用的 Node.js 版本

如果你想阻止项目的贡献者添加新的不兼容的依赖项,请在项目根目录的 .npmrc 文件中使用 nodeVersion 和 engineStrict:

pnpm-workspace.yaml
nodeVersion: 12.22.0
engineStrict: true

这样一来,即使有人正在使用 Node.js v22,也无法安装不支持 Node.js v12.22.0 的新依赖项。

runtimeOnFail#

添加于:v11.0.0

  • 默认值:undefined
  • 类型:download, error, warn, ignore

覆盖根项目 package.json 中 devEngines.runtime(以及 engines.runtime)的 onFail 字段。 This is useful when you want a different local behavior than what is written in the manifest, for instance, forcing pnpm to download the declared runtime even when the manifest sets onFail: "warn":

pnpm-workspace.yaml
runtimeOnFail: download

nodeDownloadMirrors#

添加于:v11.0.0

  • 默认值:undefined
  • 类型:** Record <string, string>**

在 pnpm-workspace.yaml 中配置自定义 Node.js 下载镜像。键名是发布通道 (release、rc、nightly 、v8-canary等)值是基础 URL。

以下是如何配置 pnpm 从中国镜像下载 Node.js:

pnpm-workspace.yaml
nodeDownloadMirrors:
  release: https://npmmirror.com/mirrors/node/
  rc: https://npmmirror.com/mirrors/node-rc/
  nightly: https://npmmirror.com/mirrors/node-nightly/

Since v11.26.0, downloads from a mirror carry the npm registry credentials configured for that URL, including bearer tokens, basic auth, and tokenHelper, so a mirror behind an authenticating proxy works without a separate credential.