npm/node-semver

[BUG] Raw includes build only before modification

skeletorXVI opened this issue · 2 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When creating a new instance of the SemVer class form a version string with a build, the build segment is included in the raw field.

Expected Behavior

The build segment should either be or not be part of the raw field, but not a mix of both.

Steps To Reproduce

Copy and run the following example code which should log true but instead logs false.

const { SemVer } = require("semver");

const freshInstance = new SemVer("1.0.0-rc.2+build.4");
const modifiedInstance = new SemVer("1.0.0-rc.1+build.4");
modifiedInstance.inc("prerelease", "rc");
console.log(freshInstance.raw === modifiedInstance.raw);

Environment

  • yarn: 3.5.0
  • Node: v16.19.1
  • OS: Pop!Os 22.04
  • semver: 7.5.1
ljharb commented

semver in the node ecosystem doesn't really use the build segment. just curious, what's your use case?

We actually use it in GitHub Actions within my companies organization to automatically validate and generate releases.

The only reason I noticed this inconsistency has to do with the fact that it broke the unit tests when adding a new feature.