fix: incorrect results from diff sometimes with prerelease versions#546
fix: incorrect results from diff sometimes with prerelease versions#546
Conversation
`0.0.2-1` => `0.0.3` should be `patch` not `prepatch`
I.e. `1.0.0-1` => `2.0.0-1` should be `major` not `premajor`, because the biggest change is the major version
|
Yeah I think the |
|
Gonna kind of spam those test lines w/ comments sorry for the noise but this deserves a good paper trail |
| ['1.0.0', '1.0.0', null], | ||
| ['1.0.0-1', '1.0.0-1', null], | ||
| ['0.0.2-1', '0.0.2', 'patch'], | ||
| ['0.0.2-1', '0.0.3', 'patch'], |
There was a problem hiding this comment.
The difference is actually two .inc patches, but that's still a patch difference. A good test
> semver.inc('0.0.2-1', 'patch')
'0.0.2'
> semver.inc('0.0.2', 'patch')
'0.0.3'
| ['1.0.0-1', '1.0.0-1', null], | ||
| ['0.0.2-1', '0.0.2', 'patch'], | ||
| ['0.0.2-1', '0.0.3', 'patch'], | ||
| ['0.0.2-1', '0.1.0', 'minor'], |
There was a problem hiding this comment.
> semver.inc('0.0.2-1', 'minor')
'0.1.0'
| ['0.0.2-1', '0.0.2', 'patch'], | ||
| ['0.0.2-1', '0.0.3', 'patch'], | ||
| ['0.0.2-1', '0.1.0', 'minor'], | ||
| ['0.0.2-1', '1.0.0', 'major'], |
There was a problem hiding this comment.
> semver.inc('0.0.2-1', 'major')
'1.0.0'
| ['1.1.0', '1.1.0-pre', 'minor'], | ||
| ['1.1.0-pre-1', '1.1.0-pre-2', 'prerelease'], | ||
| ['1.0.0', '1.0.0', null], | ||
| ['1.0.0-1', '1.0.0-1', null], |
There was a problem hiding this comment.
> semver.eq('1.0.0-1', '1.0.0-1')
true
| ['0.1.0-1', '0.1.0', 'minor'], | ||
| ['1.0.0-1', '1.0.0', 'major'], | ||
| ['0.0.0-1', '0.0.0', 'prerelease'], | ||
| ['1.0.1-1', '1.0.1', 'patch'], |
There was a problem hiding this comment.
> semver.inc('1.0.1-1', 'patch')
'1.0.1'
| ['1.0.0-1', '1.0.0', 'major'], | ||
| ['0.0.0-1', '0.0.0', 'prerelease'], | ||
| ['1.0.1-1', '1.0.1', 'patch'], | ||
| ['0.0.0-1', '0.0.0', 'major'], |
There was a problem hiding this comment.
> semver.inc('0.0.0-1', 'major')
'0.0.0'
| ['0.0.0-1', '0.0.0', 'prerelease'], | ||
| ['1.0.1-1', '1.0.1', 'patch'], | ||
| ['0.0.0-1', '0.0.0', 'major'], | ||
| ['1.0.0-1', '2.0.0', 'major'], |
There was a problem hiding this comment.
Again this is two major .inc operations but that's still a major diff
> semver.inc('1.0.0-1', 'major')
'1.0.0'
> semver.inc('1.0.0', 'major')
'2.0.0'
This still seems like premajor as per my comment on the test fixture: > semver.inc('1.0.0', 'premajor')
'2.0.0-0' |
|
Hmm yeh prerelease to prerelease on a different version is a bit confusing. Maybe prerelease to prerelease should also always be pre* ? |
|
Is the definition of pre* meant to be ‘going to a prerelease version’? If that’s the case those 3 tests should be pre* |
The following inputs previously gave the incorrect result based on my understanding:
0.0.2-1=>0.0.3wasprepatchwhen it should bepatch, as it's doing a patch operation that goes from the first to the second. Fixed with first commit.0.0.0-1=>0.0.0wasprereleasewhen it should bemajor. I think0.0.0-1=>0.0.0should be consistent with1.0.0-1=>1.0.0. Fixed with second commit. This makes it more consistent but not sure if it's actually what people would expect. See below.1.0.0-1=>2.0.0-1waspremajorbut should bemajorbecause the biggest change is the major version. Fixed with third commit.I'm actually not convinced the behaviour for the second point is correct. For any version change where the stable part remains the same and the prerelease gets removed,
npm version patchwould give that result. So should the diff always bepatchfor these cases?I.e
1.1.0-pre=>1.1.0is achievable withnpm version patchandnpm version minor. I personally would have expected the diff between those to bepatch, just like it would be if it was1.1.1-pre=>1.1.1