Choosing a Dependency Versioning Strategy
This lesson explains semantic and calendar versioning, version ranges and reproducible builds.
Learning outcomes
After completing this lesson, you will be able to:
- Apply semantic versioning rules.
- Compare SemVer with CalVer.
- Interpret version ranges.
- Explain the role of lock files.
Semantic versioning
Semantic versioning (SemVer) uses the format MAJOR.MINOR.PATCH, and each part carries a meaning about compatibility.
| Part | Raised when | Example change | Example version |
|---|---|---|---|
| MAJOR | A change breaks existing consumers | A public method is removed | 2.4.1 to 3.0.0 |
| MINOR | A backward-compatible feature is added | A new optional parameter | 2.4.1 to 2.5.0 |
| PATCH | A backward-compatible fix is made | A bug fix | 2.4.1 to 2.4.2 |
When a higher part increases, the lower parts reset to zero. Versions below 1.0.0 signal that an API is not yet stable. A prerelease label follows a hyphen, as in 3.0.0-beta.2, and it sorts before the plain version, so 3.0.0-beta.2 is lower than 3.0.0. Build metadata follows a plus sign, as in 3.0.0+build.417, and it is ignored when comparing versions.
The value of SemVer is the contract. A consumer can accept patch and minor updates automatically with reasonable confidence, and treat a major update as a planned piece of work. The contract is only as trustworthy as the publisher's discipline, so a breaking change released as a patch does real damage. API comparison tools can detect this in a pipeline.
The following diagram compares three candidate version numbers for a library release that adds a defect fix and an optional parameter.

Choosing the next version
Calendar versioning
Calendar versioning (CalVer) builds a version from a date, such as 2026.11.0 or 26.11. It says when something was released, and how old it is, rather than how compatible it is. It suits products released on a regular schedule, such as Ubuntu's 24.04, as well as applications and services that consumers do not compile against.
SemVer or CalVer?
Declaring dependencies
Consumers state which versions they accept. Each ecosystem has a slightly different syntax, but the ideas are shared. An exact version accepts only that version. A range accepts a family of versions. The following table shows npm notation as an example.
| Notation | Accepts | Risk |
|---|---|---|
| 1.4.2 | Only 1.4.2 | Misses fixes unless updated |
| ~1.4.2 | 1.4.x, from 1.4.2 upward | Low; patches only |
| ^1.4.2 | 1.x.x, from 1.4.2 upward | Moderate; minor updates are accepted |
| * | Any version | High; a build can change with no code change |
A range alone makes a build non-reproducible, because the same code can resolve to different packages on different days. A lock file, such as package-lock.json or packages.lock.json, solves this by recording the exact resolved version of every direct and transitive dependency. It must be committed. In a pipeline, use the commands that honour it, such as npm ci, which fails if the lock file and manifest disagree.
Teams then take updates deliberately: a tool such as Dependabot proposes a pull request that changes the lock file, tests run, and a person or rule accepts it. This combines reproducibility with currency, and it creates a reviewable record.
Does the range accept it?
Automating versions
Manual version numbers are easy to forget. Common automation options include deriving a version from Conventional Commits, as explained in the module on documentation, and GitVersion, which calculates a version from branches and tags. Azure Pipelines tokens can add a counter, as the next lesson shows, and a prerelease label can identify a branch build, so that 2.5.0-feature-login.17 cannot be mistaken for a release.
Ways to automate a version
Applying SemVer
A shared library is at version 4.2.7. A release fixes one defect and adds an optional parameter to an existing method. Existing callers keep working. Which version should it use?
The correct version is 4.3.0. A backward-compatible feature raises MINOR, which resets PATCH to zero, and the release's defect fix is included in that increment. Version 4.2.8 would hide the new capability, and 5.0.0 would tell consumers to expect a breaking change that does not exist.
Which is lower: 2.0.0-rc.1 or 2.0.0?
Show answer
2.0.0-rc.1. A prerelease label sorts before its release version.
Exam Tips
Remember for the exam
- SemVer: breaking change raises MAJOR, feature raises MINOR, fix raises PATCH.
- 3.0.0-beta.2 sorts before 3.0.0.
- CalVer communicates age; SemVer communicates compatibility.
- Commit a lock file, and use npm ci in pipelines for reproducible builds.
- Automate version numbers from commits, tags or counters.