一、版本规范

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

1. 脱字符 ^

限定主版本号(并且对于不同的版本号有不同的更新机制)
Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.(最左侧的非零数字不能改变)

  • ^1.2.1 更新版本范围为 >=1.2.1 && < 2.0.0
  • ^0.2.1 更新版本范围为 >=0.2.1 && < 0.3.0
  • ^0.0.2 更新版本范围为 0.0.2(相当于锁定为 0.0.2 版本)

2. 波浪号 ~

限定次版本号

  • ~1.2.1 更新版本范围为 >=1.2.1 && < 1.3.0
  • ~0.2.1 更新版本范围为 >=0.2.1 && <0.3.0
  • ~0.0.1 更新版本范围为 >=0.0.1 && <0.1.0

3. x or 星号 *

安装「x or *」的最新版

  • 1.x 更新版本范围为 >=1.0.0 && < 2.0.0
  • 1.2.x 更新版本范围为 >=1.2.0 && < 1.3.0

4. 做一些测试

对于主版本非零的情况,都基本没有什么异议,对于主版本为零的情况需要做一些验证
npm 上 axios 的一些版本如下,拿它来做实验
还有 chax 的一些版本

  1. axios 的部分版本
  2. [ '0.5.0','0.5.1','0.5.2','0.5.3','0.5.4' ]
  3. chax 的部分版本
  4. [ '0.0.1', '0.0.2', '0.0.3' ]
  1. yarn add axios@^0.5.1
  2. // 安装版本 axios@0.5.4
  3. yarn add axios@~0.5.1
  4. // 安装版本 axios@0.5.4
  5. yarn add chax@^0.0.2
  6. // 安装版本 chax@0.0.2
  7. yarn add chax@~0.0.2
  8. // 安装版本 chax@0.0.3

二、项目中的版本控制

  • package.json 保存着依赖的版本
  • yarn.lock 可以锁定项目依赖的包的版本号
  • package-lock.json 可以锁定项目依赖的包的版本号
  1. "dependencies":{
  2. "@types/node":"^8.0.33"
  3. }

三、查看版本

示例如下:

  1. yarn info axios versions
  2. npm view axios versions

「@浪里淘沙的小法师」