node-semver
node-semver copied to clipboard
[DOCS] How do I get to 1.0.0-5 using increments?
I tried this:
> s = require('semver')
> v='0.0.0'
'0.0.0'
> v = s.inc(v, 'premajor')
'1.0.0-0'
> v = s.inc(v, 'premajor')
'2.0.0-0'
> v = s.inc(v, 'premajor')
'3.0.0-0'
> v = s.inc(v, 'premajor')
I would expect 1.0.0-0
, 1.0.0-1
, 1.0.0-2
and so on -- as I can have a number of pre-releases before I do s.inc(v, 'major')
, right?
Is this just my misunderstanding or is it a bug? And if this behaviour is expected, how do I get to e.g. 1.0.0-5 using the inc
function? Or should I use the undocumented pre
option from https://github.com/npm/node-semver/blob/master/semver.js#L457 ?
Btw, the same applies to inc
with preminor
or prepatch
.
Working as designed. Doc patch welcome!
> v='0.0.0'
'0.0.0'
> v = s.inc(v, 'premajor')
'1.0.0-0'
> v = s.inc(v, 'pre')
'1.0.0-1'
> v = s.inc(v, 'pre')
'1.0.0-2'
> v = s.inc(v, 'pre')
'1.0.0-3'
> v = s.inc(v, 'pre')
'1.0.0-4'
> v = s.inc(v, 'pre')
'1.0.0-5'
Ok, well, but then pre
wasn't documented for a reason. Comment in the linked source:
// This probably shouldn't be used publicly.
// 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
Hm. That's a good point. Maybe we could just include that caveat in the documentation for inc(v,'pre')
?
Suggest closing this since you can use prerelease
instead of undocumented pre
:
> npx semver -i premajor 0.0.0
1.0.0-0
> npx semver -i prerelease 1.0.0-0
1.0.0-1
> npx semver -i prerelease 1.0.0-1
1.0.0-2
thank you @mbtools