npm CLI 11.15.0更新,增加了npm 的分阶段发布和新的安装时控制

转载批注

为应对近期的多次npm投毒事件,npm新增了分阶段发布和新的安装时控制

与直接发布立即将包版本提供给消费者不同,预构建的 tarball 会被上传到预发布队列中,维护者必须明确批准后它才能被安装。该队列在 npmjs.com 和 npm CLI 上均可查看。

正文(机翻)

Today we’re shipping two updates focused on supply-chain security for npm:
今天我们发布了两个专注于 npm 供应链安全的更新:

  1. Staged publishing is generally available.
    分阶段发布功能已正式上线。
  2. New --allow-* install source flags (--allow-file, --allow-remote, --allow-directory) complement the existing --allow-git flag.
    新的 --allow-* 安装源标志( --allow-file--allow-remote--allow-directory )补充了现有的 --allow-git 标志。

Both are available in npm CLI 11.15.0 or newer.
这两个功能在 npm CLI 11.15.0 或更高版本中可用。


[Staged publishing is generally available

预发布功能现已正式上线](Staged publishing and new install-time controls for npm - GitHub Changelog)

Staged publishing is now generally available on npm. Instead of a direct publish that immediately makes a package version available to consumers, the prebuilt tarball is uploaded to a stage queue where a maintainer must explicitly approve it before it becomes installable. The queue is visible both on npmjs.com and in the npm CLI.
npm 上的预发布功能现已正式可用。与直接发布立即将包版本提供给消费者不同,预构建的 tarball 会被上传到预发布队列中,维护者必须明确批准后它才能被安装。该队列在 npmjs.com 和 npm CLI 上均可查看。

Staged publishing reinforces proof of presence on every publish, including those that originate from non-interactive CI/CD workflows and those using trusted publishing with OIDC. A human maintainer with a 2FA challenge is required to approve a staged package before it is released to the registry.
预发布功能加强了每次发布的存在证明,包括那些源自非交互式 CI/CD 工作流和使用 OIDC 可信发布的。在预发布包发布到注册中心之前,需要具有双因素认证挑战的人类维护者进行批准。

Staged publishing is live today, and so are the docs.
预发布功能现已上线,相关文档也已同步更新。

Requirements 要求

  • npm CLI 11.15.0 or newer is required to use npm stage.
    使用 npm stage 需要 npm CLI 11.15.0 或更高版本。
  • Update CI/CD workflows to use npm stage publish instead of npm publish where you want staged behavior.
    将 CI/CD 工作流更新为使用 npm stage publish 而不是 npm publish ,以实现分阶段发布行为。

Recommended setup 推荐配置

We recommend pairing staged publishing with trusted publishing (OIDC). A trusted publishing configuration can be limited to stage-only, which means npm publish from that workflow will be rejected and only npm stage publish is accepted. Your CI workflows continue to run non-interactively, and a maintainer later approves the staged version from the website or the CLI.
我们推荐将分阶段发布与受信任发布(OIDC)结合使用。受信任发布的配置可以限制为仅分阶段,这意味着来自该工作流的 npm publish 将被拒绝,而仅接受 npm stage publish 。您的 CI 工作流继续以非交互方式运行,维护人员稍后从网站或 CLI 批准分阶段版本。

You can also run npm stage publish locally, but the highest-value setup is CI publishing to the stage queue and a maintainer approving from a trusted device.
您也可以在本地运行 npm stage publish ,但最高价值的设置是将 CI 发布到阶段队列,并由维护者从受信任的设备进行批准。

If you already manage trusted publishing configurations in bulk, released Feb 2026, you can use it to migrate your packages to staged publishing. Remember to update your CI workflows to the new CLI version and to use npm stage publish.
如果你已经批量管理可信发布配置(2026 年 2 月发布),你可以使用它将你的包迁移到分阶段发布。请记得将你的 CI 工作流更新到新的 CLI 版本,并使用 npm stage publish

[New install source flags

新安装源标志](Staged publishing and new install-time controls for npm - GitHub Changelog)

In npm 11.10.0 we introduced --allow-git to give you control over whether npm install can resolve dependencies from Git sources. Starting in npm 11.15.0, we are adding three more flags so you can apply the same explicit-allowlist approach to every nonregistry install source:
在 npm 11.10.0 版本中,我们引入了 --allow-git 功能,让您能够控制 npm install 是否可以从 Git 源解析依赖项。从 npm 11.15.0 版本开始,我们将添加三个更多标志,以便您可以将相同的显式白名单方法应用于每个非注册表安装源:

  • --allow-file: Controls installs from local file paths and local tarballs.
    --allow-file : 控制从本地文件路径和本地 tarball 安装。
  • --allow-remote: Controls installs from remote URLs, including https tarballs.
    --allow-remote : 控制从远程 URL 安装,包括 https tarball。
  • --allow-directory: Controls installs from local directories.
    --allow-directory : 控制从本地目录进行安装。
  • --allow-git (existing): Controls installs from any Git source, including github:, gitlab:, git+ URLs, and bare owner/repo shorthands.
    --allow-git (现有): 控制从任何 Git 源安装,包括 github:gitlab:git+ URL,以及裸 owner/repo 短语。

Each flag accepts all (the current default) or none, and can also be set in .npmrc or package.json config.
每个标志接受 all (当前默认值)或 none ,也可以在 .npmrcpackage.json 配置中设置。

Learn more by checking out our docs:
通过查看我们的文档了解更多信息:

As a reminder from the Feb 2026 announcement, --allow-git will change its default from all to none in the next major version of the CLI (v12). The new --allow-file, --allow-remote, and --allow-directory flags are additions in 11.15.0—you can opt into stricter behavior today by setting them to none.
根据 2026 年 2 月的公告提醒,CLI 的下一个主要版本(v12)中, --allow-git 将从 all 更改为 none 。新的 --allow-file--allow-remote--allow-directory 标志是在 11.15.0 中添加的——你可以通过将它们设置为 none 来选择启用更严格的行为。

更多