如果你不再希望维护一个包,或者如果你想鼓励用户更新到新的或不同的版本,你可以 弃用 它。弃用一个包或版本将在用户安装它时向终端打印一条消息。

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

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

¥Note: We strongly recommend deprecating packages or package versions instead of unpublishing them, because unpublishing removes a package from the registry entirely, meaning anyone who relied on it will no longer be able to use it, with no warning.

弃用整个包

¥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>

    ¥Navigate to the package page for the package you want to deprecate, replacing <your-package-name> with the name of your package: https://www.npmjs.com/package/<your-package-name>.

  3. 单击“设置”。

    ¥Click Settings.

    Screenshot showing the settings tab on a package page
  4. 在 "弃用包" 下,单击 Deprecate package

    ¥Under "deprecate package", click Deprecate package.

    Screenshot showing the deprecate package button
  5. 如果你确定要继续,请输入你的包名称并单击 Deprecate package

    ¥If you are sure that you want to continue, enter your package name and click Deprecate package.

    Screenshot showing the deprecate package confirmation

使用命令行

¥Using the command line

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

¥To deprecate an entire package, run the following command, replacing <package-name> with the name of your package, and "<message>" with your deprecation 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>" 替换为弃用消息:

¥To deprecate a package version, run the following command, replacing <package-name> with the name of your package, <version> with your version number, and "<message>" with your deprecation 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>" 替换为 ""(空字符串)。

¥To undeprecate a package, replace "<message>" with "" (an empty string) in one of the above commands.

例如,要取消弃用整个包,请运行以下命令,将 <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 账户后,你将无法再更新它。

¥Note: Once you transfer a package to the npm account, you will no longer be able to update it.

要将包转移到 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).

npm 中文网 - 粤ICP备13048890号