node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

[BUG] inc() may produce invalid semver with ReleaseType: prerelease

Open boxcee opened this issue 5 years ago • 0 comments

What / Why

Given an identifier I want to increment a prerelease version.

Current Behavior

Given an 'invalid' identifier, inc() will produce an invalid semver.

Steps to Reproduce

const identifier = 'hotfix/410';
const incremented = inc(parse('0.0.1'), 'prerelease', identifier);
console.log(!!valid(incremented));
// => false

Expected Behavior

The documentation of inc() specifies this:

Return the version incremented by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if it's not valid

In the case above inc() is not returning null, even though the resulting version is not a valid semver. Either the documentation needs to be changed to 'or null if the ReleaseType is not valid' or inc() needs to check the validity of the semver before returning it.

boxcee avatar Nov 11 '20 08:11 boxcee