目录

为了保持 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.

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

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

🌐 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:

Code statusStageRuleExample version
First releaseNew productStart with 1.0.01.0.0
Backward compatible bug fixesPatch releaseIncrement the third digit1.0.1
Backward compatible new featuresMinor releaseIncrement the middle digit and reset last digit to zero1.1.0
Changes that break backward compatibilityMajor releaseIncrement the first digit and reset middle and last digits to zero2.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
  • 小版本更新:11.x^1.0.4
  • 主要版本:*x

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

🌐 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

目录