Skip to content

Commit

Permalink
fix: edge cases for bump/update-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 12, 2021
1 parent e61a32a commit cadace3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface LookupUpdate {
commitMessageAction?: string;
displayFrom?: string;
displayTo?: string;
isBump?: boolean;
isLockfileUpdate?: boolean;
isPin?: boolean;
isRange?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ Array [
"newValue": "~1.0.1",
"releaseTimestamp": "2014-03-11T18:47:17.560Z",
"toVersion": "1.0.1",
"updateType": "minor",
"updateType": "patch",
},
Object {
"fromVersion": "1.0.0",
Expand Down Expand Up @@ -1726,7 +1726,7 @@ Array [
"0.4.2",
],
"toVersion": "0.4.4",
"updateType": "minor",
"updateType": "patch",
},
Object {
"fromVersion": "0.4.4",
Expand Down
3 changes: 3 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('workers/repository/process/lookup', () => {
config.rangeStrategy = 'update-lockfile';
config.depName = 'q';
config.datasource = datasourceNpmId;
config.separateMinorPatch = true;
config.lockedVersion = '0.4.0';
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
Expand Down Expand Up @@ -840,6 +841,7 @@ describe('workers/repository/process/lookup', () => {
config.rangeStrategy = 'bump';
config.currentValue = '~1.0.0';
config.depName = 'q';
config.separateMinorPatch = true;
config.datasource = datasourceNpmId;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
Expand All @@ -866,6 +868,7 @@ describe('workers/repository/process/lookup', () => {
config.currentValue = '>=0.9.0';
config.depName = 'q';
config.datasource = datasourceNpmId;
config.separateMajorMinor = false;
nock('https://registry.npmjs.org').get('/q').reply(200, qJson);
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
Expand Down
37 changes: 13 additions & 24 deletions lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ function getType(
fromVersion: string,
toVersion: string
): UpdateType {
const { versioning, rangeStrategy, currentValue } = config;
const { versioning } = config;
const version = allVersioning.get(versioning);
if (rangeStrategy === 'bump' && version.matches(toVersion, currentValue)) {
return 'bump';
}
if (version.getMajor(toVersion) > version.getMajor(fromVersion)) {
return 'major';
}
Expand Down Expand Up @@ -118,9 +115,6 @@ function getFromVersion(
function getBucket(config: LookupUpdateConfig, update: LookupUpdate): string {
const { separateMajorMinor, separateMultipleMajor } = config;
const { updateType, newMajor } = update;
if (updateType === 'lockfileUpdate') {
return updateType;
}
if (
!separateMajorMinor ||
config.major.automerge === true ||
Expand Down Expand Up @@ -331,7 +325,6 @@ export async function lookupUpdates(
);
continue; // eslint-disable-line no-continue
}
update.updateType = 'lockfileUpdate';
update.fromVersion = lockedVersion;
update.displayFrom = lockedVersion;
update.displayTo = toVersion;
Expand Down Expand Up @@ -376,6 +369,18 @@ export async function lookupUpdates(
if (sortedUpdates.length) {
update.skippedOverVersions = sortedUpdates.map((u) => u.toVersion);
}
if (
rangeStrategy === 'update-lockfile' &&
currentValue === update.newValue
) {
update.isLockfileUpdate = true;
}
if (
rangeStrategy === 'bump' &&
version.matches(toVersion, currentValue)
) {
update.isBump = true;
}
res.updates.push(update);
}
} else if (!currentValue) {
Expand Down Expand Up @@ -441,22 +446,6 @@ export async function lookupUpdates(
}
}
}
for (const update of res.updates) {
const { updateType, fromVersion, toVersion } = update;
if (['bump', 'lockfileUpdate'].includes(updateType)) {
update[updateType === 'bump' ? 'isBump' : 'isLockfileUpdate'] = true;
if (version.getMajor(toVersion) > version.getMajor(fromVersion)) {
update.updateType = 'major';
} else if (
config.separateMinorPatch &&
version.getMinor(toVersion) === version.getMinor(fromVersion)
) {
update.updateType = 'patch';
} else {
update.updateType = 'minor';
}
}
}
if (res.updates.length) {
delete res.skipReason;
}
Expand Down

0 comments on commit cadace3

Please sign in to comment.