You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method .inc takes an additional identifier string argument that will append the value of the string as a prerelease identifier: semver.inc('1.2.3', 'prerelease', 'beta') // '1.2.4-beta.0'
This functionality is great the issue I have however is that it does not follow the Semantic Versioning 2.0.0 pattern. For example, semver.org itself had two release candidates for version 2.0.0, 2.0.0-rc.1 and 2.0.0-rc.2.
Based on semver.org's very own use case as an example, It would seem to me that the quoted example above should return 1.2.4.beta.1.
Here is an example of how I would typically increment my version numbers over time:
const semver = require('semver'); var ver = '0.1.0'; console.log(ver); // 0.1.0initial version ver = semver.inc(ver, 'minor'); console.log(ver); // 0.2.0 ver = semver.inc(ver, 'minor'); console.log(ver); // 0.3.0 ver = semver.inc(ver, 'patch'); console.log(ver); // 0.3.1 ver = semver.inc(ver, 'patch'); console.log(ver); // 0.3.2 ver = semver.inc(ver, 'premajor', 'rc'); console.log(ver); // 1.0.0-rc.0expecting1.0.0-rc.1 ver = semver.inc(ver, 'prerelease', 'rc'); console.log(ver); // 1.0.0-rc.1expecting1.0.0-rc.2 ver = semver.inc(ver, 'major'); console.log(ver); // 1.0.0 ver = semver.inc(ver, 'minor'); console.log(ver); // 1.1.0 ver = semver.inc(ver, 'minor'); console.log(ver); // 1.2.0 ver = semver.inc(ver, 'patch'); console.log(ver); // 1.2.1 ver = semver.inc(ver, 'patch'); console.log(ver); // 1.2.2 ver = semver.inc(ver, 'premajor', 'rc'); console.log(ver); // 2.0.0-rc.0expecting2.0.0-rc.1 ver = semver.inc(ver, 'major'); console.log(ver); // 2.0.0
As you can see when I increment to a premajor release candidate I am expecting it to start as rc.1 and not rc.0 like it does now. In my opinion having it start at zero does not make any sense as that would be like starting with an initial version of '0.0.0' instead of '0.1.0' as recommended by semver.org.
Now I understand that many people may prefer that all prerelease tags start with zero which is why I am suggesting an additional option to the method .inc as apposed to changing the current functionality.
I have a suggestion as to how to add the functionality I am looking for without removing the existing functionality. This would be to add an optional parameter that indicates if a prerelease identifier is zero-based or one-based, with the default being zero-based to keep current functionality.
I looked at the code in SemVer.prototype.inc = function(release, identifier) {, specifically case 'pre':, at the if (identifier) { block, and I was able to get my expected behavior to work by changing [identifier, 0] to [identifier, 1] and also this.prerelease.push(0); to this.prerelease.push(1);.
I am hoping you can look into adding this as an option to the method so that everyone can choose between zero-based or one-based prerelease identifier numbering based on what they feel is their own best use case.
Thank you,
Bryan
The text was updated successfully, but these errors were encountered:
bryanfarrell
changed the title
method .inc - option to set prerelease identifier initial numerical value
method .inc - option to set prerelease identifier numbering to be zero-based or one-based
Jul 6, 2018
darcyclarke
changed the title
method .inc - option to set prerelease identifier numbering to be zero-based or one-based
[FEATURE] method .inc - option to set prerelease identifier numbering to be zero-based or one-based
Jul 28, 2022
It would be great to get feedback on how others would expect this to work. The code I linked to above is only being used by the CLI and its dependencies at the moment, but it would be great to get that behavior directly from semver.
Hello,
As stated in the documentation:
This functionality is great the issue I have however is that it does not follow the Semantic Versioning 2.0.0 pattern. For example, semver.org itself had two release candidates for version 2.0.0, 2.0.0-rc.1 and 2.0.0-rc.2.
Based on semver.org's very own use case as an example, It would seem to me that the quoted example above should return 1.2.4.beta.1.
Here is an example of how I would typically increment my version numbers over time:
const semver = require('semver');
var ver = '0.1.0'; console.log(ver); // 0.1.0
initial versionver = semver.inc(ver, 'minor'); console.log(ver); // 0.2.0
ver = semver.inc(ver, 'minor'); console.log(ver); // 0.3.0
ver = semver.inc(ver, 'patch'); console.log(ver); // 0.3.1
ver = semver.inc(ver, 'patch'); console.log(ver); // 0.3.2
ver = semver.inc(ver, 'premajor', 'rc'); console.log(ver); // 1.0.0-rc.0
expecting 1.0.0-rc.1ver = semver.inc(ver, 'prerelease', 'rc'); console.log(ver); // 1.0.0-rc.1
expecting 1.0.0-rc.2ver = semver.inc(ver, 'major'); console.log(ver); // 1.0.0
ver = semver.inc(ver, 'minor'); console.log(ver); // 1.1.0
ver = semver.inc(ver, 'minor'); console.log(ver); // 1.2.0
ver = semver.inc(ver, 'patch'); console.log(ver); // 1.2.1
ver = semver.inc(ver, 'patch'); console.log(ver); // 1.2.2
ver = semver.inc(ver, 'premajor', 'rc'); console.log(ver); // 2.0.0-rc.0
expecting 2.0.0-rc.1ver = semver.inc(ver, 'major'); console.log(ver); // 2.0.0
As you can see when I increment to a premajor release candidate I am expecting it to start as rc.1 and not rc.0 like it does now. In my opinion having it start at zero does not make any sense as that would be like starting with an initial version of '0.0.0' instead of '0.1.0' as recommended by semver.org.
Now I understand that many people may prefer that all prerelease tags start with zero which is why I am suggesting an additional option to the method .inc as apposed to changing the current functionality.
I have a suggestion as to how to add the functionality I am looking for without removing the existing functionality. This would be to add an optional parameter that indicates if a prerelease identifier is zero-based or one-based, with the default being zero-based to keep current functionality.
I looked at the code in
SemVer.prototype.inc = function(release, identifier) {
, specificallycase 'pre':
, at theif (identifier) {
block, and I was able to get my expected behavior to work by changing[identifier, 0]
to[identifier, 1]
and alsothis.prerelease.push(0);
tothis.prerelease.push(1);
.I am hoping you can look into adding this as an option to the method so that everyone can choose between zero-based or one-based prerelease identifier numbering based on what they feel is their own best use case.
Thank you,
Bryan
The text was updated successfully, but these errors were encountered: