Semantic Versioning

About

Semantic Versioning (SemVer) is a versioning system that help us keep track of what’s going on in projects.

SemVer is a 3-component system in the format:

  • x stands for a major version
  • y stands for a minor version
  • z stands for a patch

Major.Minor.Patch, increment cases:

  • Major version when you make incompatible API changes
  • Minor version when you add functionality in a backwards-compatible manner
  • Patch version when you make backwards-compatible bug fixes

Benefits

  • keep a semantic historical track of a component
  • know which version of a component is no longer backwards compatible
  • avoid dependency hell when using a component in different places
  • allow a component to be distributed correctly with package managers

Pre-release

With Semantic Versioning, pre-releases can be defined by appending a hyphen and an identifier to a version. For example:

  • 1.0.0 -> 1.0.0-alpha.1
  • 1.0.0 -> 1.0.0-alpha.2

How to use that

There are two ways for requiring a lib via semver number.

  • Static: eg: "fancylib": "1.5.4". This mean that you'll get fancyLib version 1.5.4 and that will be fixed in the project. npm install / npm update will not change that version
  • Dynamic. You can use this three symbols ^ ~ * when you specify the semver
    • ^ this can be used at the beginning of the semver. this means that you'll get the latest minor and patch updates for the specified major
    • ~ this can be used at the beginning of the semver. this means that you'll get the latest patch updates for the specified major.minor
    • *This is a wildcard, let's see how it works
      • *.0.0 you'll get the latest major, minor , patch
      • 3.*.0 you'll get the latest minor , patch for the major 3 the same as ^
      • 3.9.* you'll get the latest patch for major 3, minor 9, the same as ~

Is that tricky? You can check what your semver will download in your codebase using this handy tool!

Resources

results matching ""

    No results matching ""