DEV Community

Ayc0
Ayc0

Posted on • Edited on • Originally published at ayc0.github.io

1

Semver: The unknown buildMetadata

I was reading semver's spec and I noticed something weird in the regex:

Screenshot of semver spec saying

This is the 1st time that I ever encountered the mention of buildmetadata.

Let's deconstruct that a bit

When you read the regex, it mentions at the beginning the required major, minor, and patch: a valid semver version needs to be at least MAJOR.MINOR.PATCH, for instance 1.2.3.

Then the version can contain an option prerelease tag starting with a -, for instance 1.2.3-hello and this prelease tag can be anything made of alpha numerics (0-9 or a-z or A-Z), . and -.

But what surprised me is the last one: the buildmetadata prefixed with a + (same thing as the prerelease so any alpha numerics, or ., or -).
So for instance 1.2.3+build is valid, and so is 1.2.3-beta.1+build.linux

Verification

Just to be sure, I run this in runkit, and indeed it can properly parse 1.2.3-pre.release.4+build.meta.5.6 as:

{
  major: 1,
  minor: 2,
  patch: 3,
  prerelease: ["pre", "release", 4], // here 4 is even a number
  build: ["build", "meta", "5", "6"], // but here 5 and 6 are strings
  version: "1.2.3-pre.release.4",
  raw: "1.2.3-pre.release.4+build.meta.5.6"
}
Enter fullscreen mode Exit fullscreen mode

See for yourselves:

semver properly parses  raw `1.2.3-pre.release.4.5+build.meta.6.7` endraw

Discussion

I've seen plenty of times the prerelease being used (and I used it myself a few times too).

For instance, React uses it a lot:

Sample of React versions on NPM with a lot of prereleases

My topic for a conversation with you is: Have you ever seen this used anywhere on NPM (or else where)? And if so, for what purpose?

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay