Lesson 3 of 4 Package Management

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.

PartRaised whenExample changeExample version
MAJORA change breaks existing consumersA public method is removed2.4.1 to 3.0.0
MINORA backward-compatible feature is addedA new optional parameter2.4.1 to 2.5.0
PATCHA backward-compatible fix is madeA bug fix2.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 of a library at 4.2.7 for a release with a defect fix and an optional parameter. A backward-compatible feature raises MINOR and resets PATCH, giving 4.3.0, which includes the fix. 4.2.8 would hide the new capability and 5.0.0 would signal a breaking change that does not exist.
SemVer stands for Semantic Versioning.
Scenario questions

Choosing the next version

Exam skills 3.1.3

Apply SemVer rules to each change of a library at version 5.1.3.

Log in to try this activity Interactive activities are free with an account.

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
CommunicatesCompatibility
Example3.2.1
Best forLibraries and APIs with consumers
WeaknessDepends on honest classification
Choose when Consumers need to judge whether an update is safe.
CalVer
CommunicatesAge and release time
Example2026.11.1
Best forScheduled releases and applications
WeaknessSays nothing about breaking changes
Choose when Releases follow a calendar and age matters.
Sort into groups

SemVer or CalVer?

Exam skills 3.1.3

Decide which versioning scheme each product should use.

Log in to try this activity Interactive activities are free with an account.

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.

NotationAcceptsRisk
1.4.2Only 1.4.2Misses fixes unless updated
~1.4.21.4.x, from 1.4.2 upwardLow; patches only
^1.4.21.x.x, from 1.4.2 upwardModerate; minor updates are accepted
*Any versionHigh; 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.

Sort into groups

Does the range accept it?

Exam skills 3.1.3

A package declares <code>^2.3.1</code> for one dependency and <code>~2.3.1</code> for another. Decide which versions each range accepts.

Log in to try this activity Interactive activities are free with an account.

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.

Match the pairs

Ways to automate a version

Exam skills 3.1.3 · 3.1.4

Match each automation approach with how it produces a version.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.