如果你不再希望维护某个软件包,或者希望鼓励用户更新到新的或不同的版本,你可以弃用它。弃用软件包或版本将在用户安装时在终端显示一条信息。

🌐 If you no longer wish to maintain a package, or if you would like to encourage users to update to a new or different version, you can deprecate it. Deprecating a package or version will print a message to the terminal when a user installs it.

弃用警告或消息可以显示任意内容。你可能希望包含一条消息,鼓励用户更新到特定版本,或使用其他受支持的软件包。

🌐 A deprecation warning or message can say anything. You may wish to include a message encouraging users to update to a specific version, or an alternate, supported package.

注意: 我们强烈建议弃用软件包或软件包版本,而不是取消发布,因为取消发布会将软件包完全从注册表中移除,这意味着任何依赖它的人将无法再使用它,而且不会有任何警告。

弃用整个包

🌐 Deprecating an entire package

弃用整个包会将其从 npm 网站的搜索结果中删除,并且包页面上也会显示弃用消息。

🌐 Deprecating an entire package will remove it from search results on the npm website and a deprecation message will also be displayed on the package page.

Screenshot of package deprecation

弃用一个软件包是删除软件包的一种替代方法,如果你的软件包不符合撤销发布要求

🌐 Deprecating a package is an alternative to deleting a package if your package does not meet the unpublishing requirements.

使用网站

🌐 Using the website

  1. 在 npm“登录”页面上,输入您的帐户详细信息并单击登录 Screenshot of npm login dialog
  2. 导航到你想要弃用的包的包页面,将 <your-package-name> 替换为你的包名:https://www.npmjs.com/package/<your-package-name>

  3. 点击 设置

    Screenshot showing the settings tab on a package page
  4. 在“弃用包”下,点击 弃用包

    Screenshot showing the deprecate package button
  5. 如果你确定要继续,请输入你的包名称,然后点击 弃用包

    Screenshot showing the deprecate package confirmation

使用命令行

🌐 Using the command line

要弃用整个包,请运行以下命令,将 <package-name> 替换为你的包名,将 "<message>" 替换为你的弃用信息:

npm deprecate <package-name> "<message>"

如果你已启用 两步验证,请在命令 --otp=123456 中添加一次性密码(其中 123456 是你的认证器应用提供的代码)。

🌐 If you have enabled two-factor authentication, add a one-time password to the command, --otp=123456 (where 123456 is the code from your authenticator app).

弃用单个版本的包

🌐 Deprecating a single version of a package

当你弃用某个版本的包时,该版本的包页面上将显示一条红色消息,类似于弃用整个包。

🌐 When you deprecate a version of a package, a red message will be displayed on that version's package page, similar to deprecating an entire package.

Screenshot of package deprecation for a particular version

使用命令行

🌐 Using the command line

要弃用某个软件包版本,请运行以下命令,将 <package-name> 替换为你的软件包名称,<version> 替换为你的版本号,"<message>" 替换为你的弃用信息:

npm deprecate <package-name>@<version> "<message>"

CLI 也将接受 <version> 的版本范围。

🌐 The CLI will also accept version ranges for <version>.

如果你有两步验证,请在命令中添加一次性密码,--otp=123456(其中 123456 是你的身份验证器提供的代码)。

🌐 If you have two-factor auth, add a one-time password to the command, --otp=123456 (where 123456 is the code from your authenticator).

取消弃用包或版本

🌐 Undeprecating a package or version

要取消对某个包的弃用,请在上述命令中的某一条中将 "<message>" 替换为 ""(空字符串)。

例如,要取消弃用整个包,请运行以下命令,将 <package-name> 替换为你的包名称,将 <version> 替换为你的版本号:

🌐 For example, to undeprecate an entire package, run the following command, replacing <package-name> with the name of your package, and <version> with your version number:

npm deprecate <package-name> ""

或者仅取消弃用单个软件包版本,请运行以下命令,将 <package-name> 替换为你的软件包名称,将 <version> 替换为你的版本号:

🌐 Or to undeprecate only a single package version, run the following command, replacing <package-name> with the name of your package, and <version> with your version number:

npm deprecate <package-name>@<version> ""

如果你有两步验证,请在命令中添加一次性密码,--otp=123456(其中 123456 是你的身份验证器提供的代码)。

🌐 If you have two-factor auth, add a one-time password to the command, --otp=123456 (where 123456 is the code from your authenticator).

将弃用的包转移到 npm

🌐 Transferring a deprecated package to npm

如果你不再维护某个软件包,但其他用户依赖它,并且你希望将其从你的用户资料中移除,你可以将其转移到由 npm 注册表拥有的 @npm 用户账户。

🌐 If you are no longer maintaining a package, but other users depend on it, and you'd like to remove it from your user profile, you can transfer it to the @npm user account, which is owned by the npm registry.

注意: 一旦你将一个包转移到 npm 账户,你将无法再更新它。

要将一个包转移到 npm 用户账户,请按顺序运行以下两个命令,将 <user> 替换为你的 npm 用户名,将 <package-name> 替换为你想要转移的包:

🌐 To transfer a package to the npm user account, run the following two commands in order, replacing <user> with your npm user name, and <package-name> with the package you want to transfer:

npm owner add npm <package-name>
npm owner rm <user> <package-name>

如果你有两步验证,请在命令中添加一次性密码,--otp=123456(其中 123456 是你的身份验证器提供的代码)。

🌐 If you have two-factor auth, add a one-time password to the command, --otp=123456 (where 123456 is the code from your authenticator).