What is semantic software versioning?

Versioning is an essential element to consider when publishing or using production-ready software. It helps us understand and maintain different varieties of the software that we produce.

Versioning is also useful when you want to roll back to the previous version of the software in case of any problems.

Semantic versioning has a particular syntax. Let’s look at the syntax first.

  1. The major increments when significant changes in your application break the backward compatibility.
  2. The minor increments when new features are introduced, supporting the backward compatibility.
  3. The patch adds up if there are any backward compatible bug fixes.

While developing any software, we might have specific dependencies. For example, we might use react-bootstrap, Axios, react-scripts, etc.

Keeping track of stable versions/new features of individual software can be tricky, especially when the number of dependencies is growing.

On this occasion, we can take advantage of the software version scopes so that if new software is released, you can use it only if it’s available in the scope. In this way, you can ensure that your software doesn’t break due to dependencies.

Let’s look at how to use these ranges.

Comparators

A version range is a collection of comparators that define versions that satisfy the degree. And a comparator consists of an operator and version.

The group of primitive operators is as follows:

  • < Less than
  • <= Less than or equal to
  • > Greater than
  • >= Greater than or equal to
  • = Equal. This operator is the default, so it is optional.

Examples:

  1. The comparator >=1.2.7 resembles the versions 1.2.7, 1.2.8, and 1.3.9, except the versions 1.2.5 or 1.1.1.

  2. The range >=1.3.7 <1.4.0 resembles the versions 1.3.7 and 1.3.99, but not 1.3.6, 1.4.0, or 1.1.1.

We can also join by the || (or) operator.

  1. The range 1.2.6 || >=1.2.9 <2.0.0 would match 1.2.6, 1.2.9, and 1.4.6, but not the versions 1.2.8 or 2.0.0.

Hyphen ranges

Hyphen ranges specify the inclusive set. For example, if we define the range 3.4.5 - 5.6.7, it will be equivalent to >=3.4.5 <=5.6.7.

For the partial versions, 0 is considered for the missing place.

For example, 2.3 - 5 means >=2.3.0 <=5.0.0

X-ranges

X-ranges is similar to the partial versions, but we use X or x or * instead of blank spaces.

For example:

  1. 1.x will be >=1.0.0 <2.0.0
  2. 1.2.x will be >=1.2.0 <1.3.0
  3. Similarly, * will be >=0.0.0

Tilde ranges

Tilde ranges allow patch level changes if minor and major are present. For example, if you provide ~1.2.3, it will enable this range to >=1.2.3 <1.3.0.

If the minor is missing, then minor level changes are allowed. For example, if you specify ~1, it will enable releases ranging >=1.0.0 <2.0.0.

Caret ranges

Caret ranges will update you to all later minor/patch versions without incrementing the major version. For example ^2.3.4 will use releases ranging >=2.3.4 <3.0.0

You can also combine X-ranges with this. For example, ^0.x will allow >=0.0.0 <1.0.0

Free Resources