构建设置
ignoreScripts#
- 默认值: false
- 类型:Boolean
不执行项目 package.json 及其依赖中定义的任何脚本。
注意
该标记不会阻止 .pnpmfile.mjs 的执行
childConcurrency#
- 默认值:5
- 类型:Number
同时分配的最大子进程数以构建 node_modules。零值或负值会从可用并行度中减去,最小为 1。
sideEffectsCache#
- 默认值:true
- 类型:布尔值或对象
使用且缓存 (pre/post)install 钩子的结果。
当安装前/安装后脚本修改包的内容(例如构建输出)时,pnpm 会将修改后的包保存在全局存储中。在同一台机器上后续安装时,pnpm 会复用这个缓存的预构建版本,从而使安装更快。
注意
你可能想要禁用此设置,如果:
- 安装脚本修改包目录外部的文件(pnpm 无法跟踪或缓存这些更改)。
- 这些脚本执行的副作用与构建包无关。
对象以更详细的方式表达相同含义,是声明远程层级的规范方式:
sideEffectsCache:
read: true
write: true
remote:
org: acme
packages:
- native-addon
read:当缓存中存在构建时,从缓存恢复构建。默认 true。write:将包的构建输出保存到缓存。默认 true。remote:跨机器复用构建;见下文。exclude:其构建从不经过缓存的包;见下文。
sideEffectsCache: true 是同时读取和写入的简写,也是该设置在扩展出远程层级之前的含义。只写不读(read: false, write: true)会填充一个本次运行从不使用的缓存,这正是为他人预热缓存的作业所需要的。
自 v12.2.0 起,--side-effects-cache 和 --no-side-effects-cache 标志以及 PNPM_CONFIG_SIDE_EFFECTS_CACHE 仅切换本地缓存。在 sideEffectsCache.remote 下声明的远程层级会保留,因此一次运行可以关闭本地缓存而不丢失共享缓存。
sideEffectsCacheReadonly#
- 默认值: false
- 类型:Boolean
仅在存在 side effects cache 时使用,不要为新包创建它。
sideEffectsCache: { read: true, write: false } 的旧写法。
sideEffectsCache.remote#
添加于:v12.0.0
- 默认值:undefined
- 类型:Object
选择跨机器复用依赖的构建输出,方式是恢复经过签名、按组织限定作用域的产物,而不是在本地运行该包的生命周期脚本。产物存放在服务器上,由 remoteCache 指定名称:一个以 artifacts.enabled: true 启动的 pnpr 服务器,或者自 v12.12.0 起,一个支持 Turborepo Remote Cache API 的服务器。这是一个概念验证:除非进行配置,否则它处于关闭状态;它会在 Linux/glibc、macOS 和 Windows 上,在 x64 和 arm64 架构上恢复产物。其他操作系统和 libc 系列则在本地构建。
仓库只需声明资格,无需其他内容:
pnprServer: http://127.0.0.1:7677
allowBuilds:
native-addon: true
remoteCache:
org: acme
sideEffectsCache:
remote:
packages:
- native-addon
仅声明 remote 会让 read 和 write 保持默认值,因此本地缓存会像以前一样继续工作。
packages 是资格列表,而不是权限:只有当某个包同时通过 allowBuilds、具有 requiresBuild: true,并且具有经过验证的源完整性时,它才是候选包。在此列出某个包并不会替你审查其构建脚本。在默认的 strictDepBuilds 下,当安装遇到无人裁决的构建时,仍会以 ERR_PNPM_IGNORED_BUILDS 失败;而被 allowBuilds: false 拒绝的包,无论从缓存还是其他途径,都绝不会被构建。
组织和信任材料在 remoteCache 下设置。它们也可以在 sideEffectsCache.remote 下设置,在 v12.12.0 之前它们就位于此处,并且当两者都设置了某个字段时,remoteCache 优先。 Everything describing the act of signing
(publish, keyId, builderId, imageDigest, architectureBaseline,
buildEnv, trustedKeys and privateKey) is refused in
pnpm-workspace.yaml with ERR_PNPM_WORKSPACE_REMOTE_SIDE_EFFECTS_TRUST, and
is read from the global configuration file or the
environment instead. A cloned repository is not a trust root, and must not be
able to turn the machine's signing key into a signing oracle.
Any cache failure (an unreachable server, an unverifiable signature, an incompatible platform, a bad blob) falls back to the ordinary local build. See Shared side-effects cache for the full setup, including the server flag, the trust material, and how an artifact is published.
Since v12.1.0, a restored artifact is saved in the shared store together with its signed origin. Before a later install reuses it, pnpm checks the signature again against the machine's current keys and revalidates its owner, package and source identity, platform, policy, and stored files. A bad remote variant is quarantined for that server and is not selected again.
注意
remoteSideEffectsCache is the older spelling of this setting, and
organization of its org field; both still work.
The two spellings are merged, not chosen between: a field set under both takes
its value from sideEffectsCache.remote, and a field set under only one is kept
either way. That is what lets a repository declare the org in
pnpm-workspace.yaml while the machine supplies the signing key from the global
config under whichever spelling it already used.
sideEffectsCache.exclude#
Added in: v12.14.0
- 默认值:undefined
- 类型:String[]
Packages whose build depends on something pnpm cannot include in the cache key,
such as the system libraries a native addon links against. pnpm builds a listed package in
every project and never restores or saves its build through the side-effects
cache, locally or on a remoteCache server. Under the
global virtual store, each project gets its own
copy of the package, so one project's build never reaches another.
sideEffectsCache:
exclude:
- java
- '@native/*'
- 'sharp@1.0.0 || 2.0.0'
Declaring only exclude leaves read and write at their defaults, so the
cache keeps working for every other package.
Entries use the same patterns as
minimumReleaseAgeExclude:
a package name, a @scope/* wildcard, or name@version with one or more exact
versions. A bare name covers every resolution of the package, git and tarball
URLs included. A name@version entry covers registry versions only.
A package that depends on a listed package gets a project-specific copy under the global virtual store as well, since its copy links to the listed package's.
remoteCache#
Added in: v12.12.0
- 默认值:undefined
- 类型:Object
The server that shares build output between machines, and the keys every
shared artifact is signed and verified with. Both
sideEffectsCache.remote and the task cache of
pnpm pipeline use
it.
With url, artifacts live on a server that speaks the Turborepo Remote Cache
API, such as Vercel Remote Cache or a self-hosted implementation. Without it,
they live on pnprServer.
remoteCache:
org: acme
remoteCache:
url: https://vercel.com/api
team: team_abc123
trustedKeys:
ci-2026: <base64 P-256 SubjectPublicKeyInfo DER public key>
| 字段 | Where it may be set | 含义 |
|---|---|---|
url |
Global config or environment | The API base URL of a Turborepo Remote Cache server, such as https://vercel.com/api. |
team |
Global config or environment | A Vercel team ID (team_...) or team slug. |
org |
Anywhere | The organization that owns the artifacts. On a pnpr server, one of the owners it declares under artifacts.owners. It also names the organization pnpm pipeline --report records a run under. |
trustedKeys |
Global config or environment | The public keys an artifact must be signed by, keyed by key id. |
publish |
Global config or environment | true publishes what this machine builds: dependency builds and pnpm pipeline task results. A task result includes the task's output files and its captured terminal output. Defaults to false. Set under sideEffectsCache.remote, it publishes dependency builds only. |
privateKey, keyId, builderId |
Global config or environment | The key that signs published artifacts, the id consumers trust it under, and a label for the builder. Required with publish. |
imageDigest, architectureBaseline, buildEnv |
Global config or environment | Optional provenance recorded in the signed artifact. |
Every field is also read from the environment as PNPM_REMOTE_CACHE_ followed
by the field name in upper snake case, such as PNPM_REMOTE_CACHE_URL.
trustedKeys and buildEnv take a JSON object there. The environment takes
precedence over both files. A pnpm-workspace.yaml that sets a field marked
"Global config or environment" fails with
ERR_PNPM_WORKSPACE_REMOTE_CACHE_TRUST. A repository that could name the
server could have the machine's token sent to a server of its choosing.
Authenticating with Vercel Remote Cache#
pnpm sends the server the credential its
authentication settings hold for url, as it does for a
registry. Create an access token in your Vercel account settings, under
Tokens, scoped to the team that owns the cache. On your own machine, store
it:
pnpm config set //vercel.com/api/:_authToken "$VERCEL_TOKEN"
In CI, pass it in the environment for the one command instead:
env "pnpm_config_//vercel.com/api/:_authToken=$VERCEL_TOKEN" pnpm pipeline
Use this form rather than _auth. An _auth entry also
routes package requests to its URL.
pnpm does not read the token turbo login stores. That token expires within
hours, and only turbo renews it.
A Turborepo Remote Cache server holds one build per package for each combination of operating system, CPU architecture, and Node.js major, and a later publication replaces it. A machine restores a build when it meets the build's minimum OS or glibc version, and publishes only when it found none it could restore. Publish from the machine with the oldest system you support.
A server that pnpm would send credentials to must use HTTPS or a loopback address. Otherwise the remote cache is not used.
unsafePerm#
- 默认值:如果以 root 身份运行,则为 false,否则为 true
- 类型:Boolean
When set to false, lifecycle scripts run with TMPDIR set to the
package's node_modules/.tmp directory.
nodeOptions#
- 默认值: NULL
- 类型:字符串
通过 NODE_OPTIONS 环境变量传递给 Node.js 的选项。这不会影响 pnpm 本身的执行方式,但会影响生命周期脚本的调用方式。
An empty value, such as --config.node-options= or PNPM_CONFIG_NODE_OPTIONS=, overrides a value from a lower-priority configuration source. With an empty nodeOptions, scripts retain NODE_OPTIONS from the parent environment or extraEnv.
为了保留现有的 NODE_OPTIONS,你可以在配置中使用 ${NODE_OPTIONS} 引用现有的环境变量:环境
nodeOptions: "${NODE_OPTIONS:- } --experimental-vm-modules"
verifyDepsBeforeRun#
- 默认: install
- 类型:install、warn、error、prompt、false
此设置允许在运行脚本之前检查依赖项的状态。检查运行于 pnpm run 和 pnpm exec 命令。支持以下属性值:
install— 如果node_modules不是最新的,则自动运行安装。 If that install fails, for example because the store is read-only or there is no network, pnpm prints a warning and runs the command anyway.warn- 如果node_modules不是最新的,则打印警告。prompt- 如果node_modules不是最新的,则提示用户提供权限。error- 如果node_modules不是最新的,则会引发错误。false——禁用依赖性检查。
A missing lockfile also counts as not up to date. pnpm install restores it from the installed dependencies.
Changing trustLockfile alone does not trigger a dependency reinstall before a script runs. An explicit pnpm install verifies the lockfile when that setting is off.
When the command is filtered, for example pnpm --filter foo run build, the check covers the selected projects and the workspace projects they depend on, and the install it runs is filtered the same way.
After a scope changes registries, a frozen install keeps the locked packages. A filtered command that would resolve dependencies checks whether its selected projects have already been resolved against the new registry. Run an unfiltered pnpm install --no-frozen-lockfile to update every project.
strictDepBuilds#
- 默认值:true
- 类型:Boolean
当启用 strictDepBuilds 时,如果任何依赖项具有未审核的构建脚本(又名安装后脚本),则安装将以非零退出代码退出。
allowBuilds#
包匹配器映射,用于显式允许(true)或禁止(false)脚本执行。
allowBuilds:
esbuild: true
core-js: false
# 未在下方列出的 nx 版本构建脚本将
# 在默认情况下失败,并返回 ERR_PNPM_IGNORED_BUILDS 错误
nx@21.6.4 || 21.6.5: true
nx@21.6.0: false
Exact versions in package matchers ignore SemVer build metadata. A denial also covers a package from a named registry, so nx@21.6.0: false blocks nx@work:21.6.0 too. An approval by name or version covers the default registry only. Approve a named-registry package by its exact key, such as nx@work:21.6.5: true.
Git-hosted packages: a package name on its own never approves builds for a git or tarball dependency, because the name alone does not identify the artifact. Approve one either by its exact resolved path (including the commit) or by its repository URL:
allowBuilds:
# 批准该仓库的任何提交
'foo@git+ssh://git@example.com/org/foo.git': true
# 仅批准这个确切的提交
'bar@git+https://github.com/org/bar.git#abc123': true
仓库形式使受信任的 git 依赖在分支更新后仍可继续运行构建脚本,无需为每个新提交重新批准。该键为包名后接 @ 与 git URL,且不带 #<ref> 后缀。匹配是精确的,所以同一仓库的 git+ssh:// 与 git+https:// URL 属于不同的键。
The repository form also approves git-hosted packages that pnpm downloads as a tarball rather than clones, such as github: dependencies, which are fetched from codeload.github.com. 无论 pnpm 是克隆仓库还是下载 tarball,foo@git+https://github.com/org/foo.git 条目都会批准 foo。 GitLab 与 Bitbucket 的 tarball 下载也按相同方式匹配。 A specific resolved commit can also be approved or denied by its full tarball dep path.
按包名的拒绝不受此限制:foo: false 会阻止 foo,无论它来自注册源还是 git。
默认行为: 未在 allowBuilds 中列出的软件包默认情况下是不允许的,并且将被视为未经审核的软件包。默认情况下会打印错误(strictDepBuilds 默认为 true)。如果将 strictDepBuilds 设置为 false,则会打印一条警告信息。
安装过程中,尚未在 allowBuilds 中列出的、具有被忽略的构建的依赖项会自动添加到 pnpm-workspace.yaml 中,并带有占位符值,因此您可以手动将其设置为 true 或 false。 The --allow-build flag on pnpm add and pnpm approve-builds writes its entries here as well.
Patched packages: since v12.4.0, a patch that adds an install script or a binding.gyp makes the package buildable, and the build goes through the same approval. When strictDepBuilds is false, an unapproved package appears under "Packages awaiting approval". When strictDepBuilds is true, the install fails with ERR_PNPM_IGNORED_BUILDS.
从旧设置迁移
要自动迁移这些设置,请按照 从 v10 迁移到 v11 指南运行 pnpx codemod run pnpm-v10-to-v11。
v11 中已移除以下设置,并替换为 allowBuilds:onlyBuiltDependencies、onlyBuiltDependenciesFile、neverBuiltDependencies、ignoredBuiltDependencies 和 ignoreDependencies。
之前:
onlyBuiltDependencies:
- electron
neverBuiltDependencies:
- core-js
ignoredBuiltDependencies:
- esbuild
之后:
allowBuilds:
electron: true
core-js: false
esbuild: false
permissions#
Added in: v12.11.0
- 类型:Object
What each dependency may do, keyed by package. The keys have the same forms as the keys of allowBuilds. Each entry decides one or more capabilities:
build: the package may run its build scripts. Outranks the package'sallowBuildsentry.skills: pnpm may link the agent skills the package ships into the project's agent skill directories.truelinks every skill the package ships,falselinks none, and a list of skill names links exactly those. See Agent skills.
permissions:
drizzle-kit:
build: true
skills: [guide, migrate]
esbuild:
build: true
some-pkg:
skills: false
A skills list names the only skills of the package that pnpm links, and a skill outside the list is not offered for approval again.
false records a denial, so the package is not offered for approval again. pnpm approve writes these entries.
A build decision is written to permissions only when the file already has a permissions setting. Otherwise it is written to allowBuilds, which older pnpm versions read too.
permissions.rules and permissions.unused#
To choose how pnpm handles unmatched rules, put the package selectors under permissions.rules and set permissions.unused alongside it.
permissions:
unused: warn
rules:
example-tool:
skills: true
warn (the default) reports selectors in permissions or allowBuilds that match no dependency during a full workspace resolution. Both warn and ignore keep the permissions for future installs. The warning covers the workspace and locally included files. It skips rules supplied by config dependencies or added by an updateConfig hook.
skills.dirs#
Added in: v12.11.0
- Default: the agent skill directories detected under the workspace root for projects or the home directory for global packages, plus the directory of the agent running pnpm
- 类型:String[]
The directories that pnpm links approved agent skills into. In a project, paths are relative to the workspace root. In globalPackagesConfig in the global config.yaml, paths are relative to the home directory and must stay inside it. When set, it replaces the detected directories, and pnpm creates the ones that are missing. The first time skills are approved, pnpm approve or pnpm approve -g lists the detected directories and asks which ones to link into, recording the selected directories here. If you select no directories, pnpm keeps using the detected directories.
skills:
dirs:
- .claude/skills
globalPackagesConfig:
skills:
dirs:
- .agents/skills
- .claude/skills
An empty list turns agent skills off. pnpm stops offering them for approval and removes the ones it linked.
dangerouslyAllowAllBuilds#
- 默认值: false
- 类型:Boolean
如果设置为 true,所有从依赖关系生成的脚本(例如preinstall, install)将自动运行,无需批准。 A package whose build is denied, by false in allowBuilds or build: false in permissions, is still blocked, so this setting allows every build except the denied ones. As everywhere else, a package's permissions entry outranks its allowBuilds entry.
警告
This setting allows all dependencies, including transitive ones, to run install scripts, both now and in the future. 即使你当前的依赖图看起来很安全:
- 未来的更新可能会引入新的、不受信任的依赖项。
- 现有的软件包可能会在后续版本中添加脚本。
- 软件包可能会被劫持或破坏并开始执行恶意代码。
For maximum safety, only enable this if you're fully aware of the risks and trust the entire ecosystem you're pulling from. It's recommended to review and allow builds explicitly.