[BUG] Inc function give incorrect version when bumping subsequent pre versions
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
We have found that trying to increment any preversion (premajor, preminor, prepatch) results in wrong version calculation
Expected Behavior
The expected behavior will be the prerelease number to bump on subsequent prereleases
Steps To Reproduce
You can check any of the following test, all failing in increment.js
['1.2.0-dev.2', 'preminor', '1.2.0-dev.3', false, 'dev', false],
['2.0.0-dev.2', 'premajor', '2.0.0-dev.3', false, 'dev', false],
['1.2.1-dev.2', 'prepatch', '1.2.1-dev.3', false, 'dev', false],
Environment
No response
I am trying to address this issue in https://github.com/npm/node-semver/pull/643
Increasing 1.2.0-dev.2 by preminor means bumping a minor and then down to a prerelease of that minor version. So the result that semver gives of 1.3.0-0 is correct. If you need a prerelease identifier you can specify that:
~/D/n/n/b/main (main|✔) $ node -e "console.log(require('.').inc('1.2.0-dev.2', 'preminor'))"
1.3.0-0
~/D/n/n/b/main (main|✔) $ node -e "console.log(require('.').inc('1.2.0-dev.2', 'preminor', 'alpha'))"
1.3.0-alpha.0
The difference between 1.2.0-dev.2 and 1.2.0-dev.3 is only a prerelease
~/D/n/n/b/main (main|✔) $ node -e "console.log(require('.').inc('1.2.0-dev.2', 'prerelease'))"
1.2.0-dev.3
Ref: https://github.com/npm/node-semver#functions
Thanks a lot for your response. Just as a summary before closing this and the associated PR, If I am bumping versions like in the flow you describe, the operations would be:
1.4.3 -> preminor -> 1.5.0-0 -> prerelease -> 1.5.0-1 -> prerelease -> 1.5.0-2 -> minor -> 1.5.0
Yep that looks right.