What Is Semantic Versioning?

semantic versioning

What is Software versioning in general?

According to Wikipedia,

Software versioning in general is the process of assigning either unique version names or unique version numbers to unique states of computer software. One of the method for versioning a software is Semantic Versioning.

Who proposed Semantic Versioning?

The Semantic Versioning specification was originally authored by Tom Preston-Werner, inventor of Gravatar and cofounder of GitHub.

Semantic Versioning is a system of declaring software versions when a developer or group of developers start a software package or make an update to it.

Why Using Semantic Versioning?

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. It can prevent what is called dependency hell.

Tom Preston introduced a brief example on how semantic versioning can prevent dependency hell:

A simple example will demonstrate how Semantic Versioning can make dependency hell a thing of the past. Consider a library called “Firetruck.” It requires a Semantically Versioned package named “Ladder.” At the time that Firetruck is created, Ladder is at version 3.1.0. Since Firetruck uses some functionality that was first introduced in 3.1.0, you can safely specify the Ladder dependency as greater than or equal to 3.1.0 but less than 4.0.0. Now, when Ladder version 3.1.1 and 3.2.0 become available, you can release them to your package management system and know that they will be compatible with existing dependent software.


How To Apply a Semantic Version?

It consists of three numbers with dots in between like in the image 👇

Image from https://devopedia.org/semantic-versioning

npmjs docs provide a brief easy guide on how to version you software packages

Code statusStageRuleExample version
First releaseNew productStart with
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
from https://docs.npmjs.com/about-semantic-versioning#incrementing-semantic-versions-in-published-packages

How To Specify Package Updates You Want For Your Project?

As a package user, it is important to know how you can specify which kind of updates (patch, minor, or major). In package.json file you can clearly permit specific packages updates as follows:

  • Patch releases: 1.0 or 1.0.x or ~1.0.4
  • Minor releases: 1 or 1.x or ^1.0.4
  • Major releases: * or x
"dependencies": {
    "express": "^4.17.1",
    "jasmine": "^3.7.0",
    "jasmine-spec-reporter": "~7.0.0"

In this video from NPM youtube channel you will find an explanation of the semantic versioning and how to specify permitted updates in the package.json file in a good explanation.

Leave a Reply

Your email address will not be published. Required fields are marked *