Luke Oliff.

TIL: Semantic Versioning With the semver CLI

·TIL·1 min read·Luke Oliff

MAJOR.MINOR.PATCH is a simple system made tedious by manual arithmetic. The semver CLI does the math for you.

npm install -g semver

Check if a version satisfies a range.

semver -r '>=1.0.0 <2.0.0' 1.5.0
1.5.0

Increment a version component.

semver -i minor 1.2.3
1.3.0

The -i flag bumps major, minor, or patch. Output the new version number without doing the addition yourself.

semver -i prerelease --preid rc 1.0.0
1.0.0-rc.0

Pre-release versions and build metadata are supported.

How is this useful in CI?

Pipe the current version from package.json into semver -i patch for automated version bumps in release pipelines.