为了保持 JavaScript 生态系统的健康、可靠和安全,每次你对你拥有的 npm 包进行重大更新时,我们建议你在遵循 语义版本规范package.json 文件 中发布具有更新版本号的包的新版本。遵循语义版本控制规范有助于其他依赖你的代码的开发者了解给定版本的更改程度,并在必要时调整自己的代码。

¥To keep the JavaScript ecosystem healthy, reliable, and secure, every time you make significant updates to an npm package you own, we recommend publishing a new version of the package with an updated version number in the package.json file that follows the semantic versioning spec. Following the semantic versioning spec helps other developers who depend on your code understand the extent of changes in a given version, and adjust their own code if necessary.

注意:如果你引入的更改破坏了包依赖,我们强烈建议增加版本主编号;详情见下文。

¥Note: If you introduce a change that breaks a package dependency, we strongly recommend incrementing the version major number; see below for details.

递增已发布包中的语义版本

¥Incrementing semantic versions in published packages

为了帮助依赖你的代码的开发者,我们建议你从 1.0.0 开始你的包版本并按如下方式递增:

¥To help developers who rely on your code, we recommend starting your package version at 1.0.0 and incrementing as follows:

代码状态阶段规则示例版本
首次发布新产品从 1.0.0 开始1.0.0
向后兼容的缺陷修复补丁版本增加第三个数字1.0.1
向后兼容的新功能次要版本增加中间数字并将最后一位重置为零1.1.0
破坏向后兼容性的更改主要版本增加第一位数字并将中间和最后一位数字重置为零2.0.0

使用语义版本控制来指定包可以接受的更新类型

¥Using semantic versioning to specify update types your package can accept

你可以从包的 package.json 文件中的依赖中指定包可以接受的更新类型。

¥You can specify which update types your package can accept from dependencies in your package's package.json file.

例如,要指定最高 1.0.4 的可接受版本范围,请使用以下语法:

¥For example, to specify acceptable version ranges up to 1.0.4, use the following syntax:

  • 补丁发布:1.01.0.x~1.0.4

    ¥Patch releases: 1.0 or 1.0.x or ~1.0.4

  • 次要版本:11.x^1.0.4

    ¥Minor releases: 1 or 1.x or ^1.0.4

  • 主要版本:*x

    ¥Major releases: * or x

有关语义版本控制语法的更多信息,请参阅 npm semver 计算器

¥For more information on semantic versioning syntax, see the npm semver calculator.

示例

¥Example

"dependencies": {
"my_dep": "^1.0.0",
"another_dep": "~2.2.0"
},

资源

¥Resources

npm 中文网 - 粤ICP备13048890号