1001Ferramentas
⬆️Dev

Semver Bump

Bump a SemVer version (major/minor/patch/prerelease). Accepts optional "v" prefix.

Semantic version bump, including from a prerelease

Pick the current version and the kind of increment, and the page applies the semantic versioning rules. The case that usually surprises people is the prerelease: when the current version is something like 1.2.3-rc.1, a patch bump returns 1.2.3, not 1.2.4 — because the prerelease was already reserving that number, and releasing is precisely dropping the suffix.

The full rule follows what npm's semver does. Major increments except when minor and patch are already zero and a prerelease exists; minor increments except when patch is zero and a prerelease exists; patch increments except when a prerelease exists. In every case the build metadata is dropped, because semver does not treat it as part of the version's identity.

Worth recalling the precedence rule, which is what makes sense of all this: a version with a prerelease comes BEFORE the same version without one, so 1.0.0-rc.1 is less than 1.0.0. That is why a range like caret followed by 1.0.0 matches no prerelease by default — anyone wanting to test a candidate has to ask for it explicitly.

Frequently asked questions

Why does the caret behave differently on version zero?
Because it allows whatever does not touch the leftmost non-zero digit. In 1.2.3 that digit is the major, so it accepts up to 1.x.x; in 0.2.3 it is the minor, so it accepts only 0.2.x. It is the rule that catches most people out, and it exists because before version 1 the standard promises no stability at all.
What is build metadata for, then?
It stamps the artefact's origin — commit hash, CI build number — without affecting ordering or dependency resolution. Two versions differing only in build are considered the same version, and the standard says behaviour on encountering both is undefined. So do not use build to distinguish releases.
Which prerelease identifier does the page use?
Starting from a released version, it reserves the next patch with the suffix rc.0, the commonest convention. npm with no argument would use just the number zero. Starting from an existing prerelease, it advances the last numeric identifier and keeps the name you were already using, be it alpha, beta or anything else.

Related Tools