NPM packages follow semantic versioning

To keep the Javascript ecosystem healthy, reliable, and safe, NPM recommends the use of semantic versioning specifications. Semantic versioning enables developers to understand changes to NPM packages with a given version number.

Version format: Major version number. Second version. Revision number

NPM recommends that the initial version be 1.0.0, and the incrementing rule is as follows:

1.1.0 Major: When you make incompatible API changes, 2.0.0 uses semantic versioning to specify the scope of dependencies that can be updated:

"Dependencies" : {" my_dep ":" ^ 1.0.0 ", "another_dep" : "~ 2.2.0}"Copy the code

Use ^ symbol: same major version number, containing all versions larger than a particular version, e.g. ^2.2.1 uses ~ symbol: same major and minor version number, containing all versions larger than a particular version, e.g. ~2.2.1 uses >,<,=,>=,<=, e.g. >2.0.1 uses – symbol: Specify an inclusion range, such as 1.0.0 to 1.2.0


When importing dependency package versions in pakage.json, you often see version range indications like ^1.2.0 or ~1.2.0 in Dependencies. So, what do we mean by alpha and alpha here?

Details can see NPM’s official documents: docs.npmjs.com/misc/semver…

In the advanced range syntax section of the link above, the notation for version ranges is -x ~ ^

Here is a brief excerpt of the difference between ^ and ~, memo. A complete version number group is represented as: [Major, minor, patch]

  1. Use ~ to indicate ranges

If a minor version is specified, the patch version is allowed to upgrade. If no minor version is specified, the minor version is allowed to upgrade.

~ 1.2.3 > = 1.2.3 < 1.3.0 ~ 1.2 > = 1.2.0 < 1.3.0 ~ 1 > = 1.0.0 < 2.0.0 ~ 0.2.3 > = 0.2.3 < 0.3.0 ~ 0.2 > = 0.2.0 < 0.3.0 ~ 0 > = 0.0.0 < 1.0.0 to 1.2.3-beta.2 >=1.2.3-beta.2 < 1.3.0 (Note: version 1.2.3 allows beta versions higher than beta.2, but 1.2.4-beta.2 is not allowed because it is a beta that belongs to another version group.)

  1. Specify the range with ^

Allows not to change the leftmost version upgrading the version number of non zero, that is, ^ 1.0.0 allow secondary, patch version upgrades, ^ 0.1.0 from allowing patch version upgrades, ^ 0.0 x is not allowed to upgrade.

There are many developers who use the ‘x’ change in ‘0.x’ as an indication of major changes.

A common practice is that ^ is suitable for use when developers may make incompatible changes when upgrading from 0.2.4 to 0.3.0. In general, assuming that there will be no incompatible changes between 0.2.4 and 0.2.5, there can be some new (but not incompatible) changes.

< 2.0.0 ^ ^ 1.2.3 > = 1.2.3 0.2.3 > = 0.2.3 < 0.3.0 ^ 0.0.3 > = 0.0.3 < 0.0.4 ^ 1.2.3 – beta. 2 > = 1.2.3 – beta. 2 < 2.0.0 allow 1.2.3 The beta version is higher than beta-2. ^0.0.3-beta.2 >=0.0.3-beta.2 < 0.0.4 only versions 0.0.3 that are higher than beta-2 are allowed

When resolving the version range with ^, the patch version number missing will be filled with 0, but will be handled flexibly, even if both major and minor versions are 0.

^ 1.2 x > = 1.2.0 < 2.0.0 ^ 0.0 x > = 0.0.0 < 0.1.0 from ^ 0.0 > = 0.0.0 < 0.1.0 from

When the minor or patch version number is missing, it will be treated as 0, but it can be handled flexibly, even if the major version number is 0.

X >= 1.0.0 < 2.0.0 ^0.x >= 0.0.0 < 1.0.0


Reference:

  1. semver.org/lang/zh-CN/
  2. Docs.npmjs.com/about-seman…