pnpm approve-builds

在安装期间批准依赖项运行脚本。

已批准的依赖项会被添加到 pnpm-workspace.yaml 文件中的 [allowBuilds] 映射里,取值为 true;而未批准的依赖项则取值为 false。如果你愿意,你也可以手动更新这些设置。

自 v12.11.0 起,当 pnpm-workspace.yaml 已有 permissions 设置时,这些决定会改为作为 build 能力写入其中。要同时审查 agent 技能,请使用 pnpm approve。

使用方法#

你可以不带任何参数运行 pnpm approve-builds 来获得交互式提示,或者将包名作为位置参数传递:

pnpm approve-builds esbuild fsevents !core-js

A bare name only approves default-registry dependencies. To approve a file:, git, or tarball dependency, use the full selector shown by pnpm ignored-builds. For example, run pnpm approve-builds 'example@file:../example'.

Running pnpm approve-builds without package arguments or --all when packages are awaiting approval requires an interactive terminal outside CI (ERR_PNPM_APPROVE_BUILDS_NON_INTERACTIVE).

在软件包名称前加上 ! 即可拒绝该软件包。只有上述提及的包会受到影响;其余包不受影响。已批准但仍在等待批准的包会立即重新构建。同时将某个包指定为已批准和已拒绝会失败,并报错 ERR_PNPM_APPROVE_BUILDS_CONTRADICTING_ARGS。

自 v12.4.0 起,即使没有任何内容在等待批准,也会保存决策,因此可以在安装包之前就写好策略。指定的包如果不在等待批准之列,会以警告而非错误的形式报告,并且不会重新构建:它可能尚未安装,而重新构建它需要项目可能没有的锁文件。如果参数没有指定任何包,会在写入任何内容之前被拒绝。

在安装期间,构建被忽略且尚未列入 allowBuilds 的包会自动添加到 pnpm-workspace.yaml,并带有占位值 set this to true or false,以便你可以手动将它们设置为 true 或 false。

写入 allowBuilds 还会从 pnpm-workspace.yaml 中移除已忽略的旧版设置 onlyBuiltDependencies、onlyBuiltDependenciesFile、neverBuiltDependencies 和 ignoredBuiltDependencies。

配置项#

--all#

无需交互式提示即可批准所有待处理的构建。不能与包名组合使用(ERR_PNPM_APPROVE_BUILDS_ALL_WITH_ARGS)。

--global, -g#

批准全局安装的包的构建。

pnpm gathers the packages awaiting approval across every isolated install group, asks about them once, and writes the decisions to globalPackagesConfig.permissions in the global config.yaml. Only the groups that actually contain an approved package are then rebuilt.