fix: do not jump unstable versions implicitly

If the current value is already unstable then we presume the user is happy to take newer unstable versions. However we should not presume that they want to keep jumping versions if so and instead would prefer to stabilise.

Discussed in #2258 but does not close it
This commit is contained in:
Rhys Arkins 2018-08-15 09:40:10 +02:00
parent d376f9db87
commit d2885e5d9e
4 changed files with 54 additions and 45 deletions

View file

@ -18,9 +18,15 @@ function filterVersions(
respectLatest,
allowedVersions,
} = config;
const { getMajor, isGreaterThan, isStable, isValid, matches } = versioning(
versionScheme
);
const {
getMajor,
getMinor,
getPatch,
isGreaterThan,
isStable,
isValid,
matches,
} = versioning(versionScheme);
if (!fromVersion) {
return [];
}
@ -67,7 +73,10 @@ function filterVersions(
// Allow unstable only in current major
return filteredVersions.filter(
version =>
isStable(version) || getMajor(version) === getMajor(fromVersion)
isStable(version) ||
(getMajor(version) === getMajor(fromVersion) &&
getMinor(version) === getMinor(fromVersion) &&
getPatch(version) === getPatch(fromVersion))
);
}

File diff suppressed because one or more lines are too long

View file

@ -201,23 +201,6 @@ exports[`manager/npm/lookup .lookupUpdates() handles github 404 1`] = `Array []`
exports[`manager/npm/lookup .lookupUpdates() handles packagist 1`] = `Array []`;
exports[`manager/npm/lookup .lookupUpdates() handles prerelease jumps 1`] = `
Array [
Object {
"canBeUnpublished": false,
"fromVersion": "2.9.0-rc",
"isRange": true,
"isSingleVersion": false,
"newMajor": 2,
"newMinor": 9,
"newValue": "^2.9.1-insiders",
"releaseTimestamp": "2018-05-16T23:16:36.911Z",
"toVersion": "2.9.1-insiders.20180516",
"updateType": "minor",
},
]
`;
exports[`manager/npm/lookup .lookupUpdates() handles pypi 404 1`] = `Array []`;
exports[`manager/npm/lookup .lookupUpdates() handles unknown purl 1`] = `Array []`;
@ -679,13 +662,13 @@ exports[`manager/npm/lookup .lookupUpdates() should allow unstable versions if t
Array [
Object {
"canBeUnpublished": false,
"fromVersion": "2.3.0-beta.1",
"fromVersion": "3.1.0-dev.20180731",
"isSingleVersion": true,
"newMajor": 2,
"newMinor": 5,
"newValue": "2.5.17-beta.0",
"releaseTimestamp": "2018-03-23T23:29:13.819Z",
"toVersion": "2.5.17-beta.0",
"newMajor": 3,
"newMinor": 1,
"newValue": "3.1.0-dev.20180813",
"releaseTimestamp": "2018-08-13T19:05:14.347Z",
"toVersion": "3.1.0-dev.20180813",
"updateType": "minor",
},
]
@ -719,6 +702,22 @@ Object {
}
`;
exports[`manager/npm/lookup .lookupUpdates() should not jump unstable versions 1`] = `
Array [
Object {
"canBeUnpublished": false,
"fromVersion": "3.0.1-insiders.20180726",
"isSingleVersion": true,
"newMajor": 3,
"newMinor": 0,
"newValue": "3.0.1",
"releaseTimestamp": "2018-07-30T16:21:13.150Z",
"toVersion": "3.0.1",
"updateType": "minor",
},
]
`;
exports[`manager/npm/lookup .lookupUpdates() should treat zero zero caret ranges as pinned 1`] = `
Array [
Object {

View file

@ -641,16 +641,28 @@ describe('manager/npm/lookup', () => {
expect(res.updates[0].newValue).toEqual('2.5.17-beta.0');
});
it('should allow unstable versions if the current version is unstable', async () => {
config.currentValue = '2.3.0-beta.1';
config.depName = 'vue';
config.purl = 'pkg:npm/vue';
config.currentValue = '3.1.0-dev.20180731';
config.depName = 'typescript';
config.purl = 'pkg:npm/typescript';
nock('https://registry.npmjs.org')
.get('/vue')
.reply(200, vueJson);
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('2.5.17-beta.0');
expect(res.updates[0].newValue).toEqual('3.1.0-dev.20180813');
});
it('should not jump unstable versions', async () => {
config.currentValue = '3.0.1-insiders.20180726';
config.depName = 'typescript';
config.purl = 'pkg:npm/typescript';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
expect(res.updates).toHaveLength(1);
expect(res.updates[0].newValue).toEqual('3.0.1');
});
it('should treat zero zero tilde ranges as 0.0.x', async () => {
config.rangeStrategy = 'replace';
@ -715,17 +727,6 @@ describe('manager/npm/lookup', () => {
const res = await lookup.lookupUpdates(config);
expect(res.updates).toHaveLength(0);
});
it('handles prerelease jumps', async () => {
config.currentValue = '^2.9.0-rc';
config.rangeStrategy = 'replace';
config.depName = 'typescript';
config.purl = 'pkg:npm/typescript';
nock('https://registry.npmjs.org')
.get('/typescript')
.reply(200, typescriptJson);
const res = await lookup.lookupUpdates(config);
expect(res.updates).toMatchSnapshot();
});
it('supports in-range caret updates', async () => {
config.rangeStrategy = 'bump';
config.currentValue = '^1.0.0';