Skip to content
Semantic Versioning
step 1/5

Reading — step 1 of 5

Read

~1 min readVersioning & Constraints

Semantic Versioning

Almost every package manager uses semver (Semantic Versioning, semver.org):

MAJOR.MINOR.PATCH
  e.g.  1.2.3
        ^.^.^
        | | +-- bug fixes only
        | +---- backwards-compatible features
        +------ breaking changes

Pre-release suffix: 1.0.0-beta.1, 1.0.0-rc.2 — sort BEFORE 1.0.0. Build metadata: 1.0.0+20240801 — ignored for ordering.

Comparison rules (full ordering):

  1. Compare MAJOR, then MINOR, then PATCH numerically.
  2. A version with a pre-release is LESS than the same version without one.
  3. Pre-release identifiers compare alphabetically OR numerically per field.
0.9.0 < 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-beta < 1.0.0-rc.1 < 1.0.0

Why semver matters for package managers:

  • ^1.2.3 (caret) means "compatible with 1.2.3" — accepts 1.2.4, 1.5.0, but not 2.0.0
  • ~1.2.3 (tilde) means "patch-compatible" — accepts 1.2.4, 1.2.5, but not 1.3.0
  • >=1.2.3 <2.0.0 is the explicit form

A library that breaks API while only bumping minor/patch is BAD CITIZENSHIP. Bump MAJOR or your users break unpredictably. (Looking at you, ESLint 8 -> 9...)

For this lesson: parse + compare semver strings.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…