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

[DOCS] How do I get to 1.0.0-5 using increments?

Open mik01aj opened this issue 9 years ago • 3 comments

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.

mik01aj avatar Apr 08 '15 14:04 mik01aj

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'

isaacs avatar Apr 08 '15 16:04 isaacs

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.

mik01aj avatar Apr 08 '15 16:04 mik01aj

Hm. That's a good point. Maybe we could just include that caveat in the documentation for inc(v,'pre')?

isaacs avatar Apr 08 '15 17:04 isaacs

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

mbtools avatar Jun 21 '23 07:06 mbtools

thank you @mbtools

wraithgar avatar Jun 21 '23 13:06 wraithgar