pnpm approve-builds

添加于:v10.1.0

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

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

使用方法#

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

pnpm approve-builds esbuild fsevents !core-js

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).

在软件包名称前加上 ! 即可拒绝该软件包。只有上述提及的包会受到影响;其余包不受影响。

Since v11.26.0, a decision is saved even when nothing is awaiting approval, so a policy can be written before the package is installed. 指定的包如果不在等待批准之列,会以警告而非错误的形式报告,并且不会重新构建:它可能尚未安装,而重新构建它需要项目可能没有的锁文件。如果参数没有指定任何包,会在写入任何内容之前被拒绝。

安装过程中,尚未在 allowBuilds 中列出的、具有被忽略的构建的软件包会自动添加到 pnpm-workspace.yaml 中,并带有占位符值,因此您可以手动将其设置为 true 或 false。

Since v11.23.0, writing allowBuilds also removes onlyBuiltDependencies, onlyBuiltDependenciesFile, neverBuiltDependencies, and ignoredBuiltDependencies from pnpm-workspace.yaml. allowBuilds replaced those settings in pnpm 11 and they have been ignored since, so a workspace migrated from pnpm 10 kept them around looking active.

配置项#

--all#

添加于:v10.32.0

无需交互式提示即可批准所有待处理的构建。

--global, -g#

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

pnpm gathers the packages awaiting approval across every isolated install group, asks about them once, and writes a single policy into the pnpm-workspace.yaml of the global packages directory. Only the groups that actually contain an approved package are then rebuilt.

Removed in v11.0.0, back in v11.24.0

Isolated global installs gave every install group its own manifest, and pnpm approve-builds -g was removed rather than made to guess which one to write to. Since v11.24.0 it writes one policy for all of them, so it works again. From v11.0.0 until v11.24.0, use --allow-build when installing globally (e.g. pnpm add -g --allow-build=esbuild esbuild), or answer the prompt pnpm shows during a global install. Both options remain available if you prefer to decide at install time.