mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
fix: widening support in composer with "less than" range (#10775)
This commit is contained in:
parent
6deaa50c91
commit
d6b2a85efc
2 changed files with 52 additions and 1 deletions
|
@ -312,6 +312,8 @@ describe('semver.getNewValue()', () => {
|
|||
newVersion: '5.1.0',
|
||||
})
|
||||
).toEqual('~1.2 || ~2.0 || ~3.0 || ~5.0');
|
||||
});
|
||||
it('handles widen strategy', () => {
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '^1.2',
|
||||
|
@ -352,6 +354,46 @@ describe('semver.getNewValue()', () => {
|
|||
newVersion: '2.1.0',
|
||||
})
|
||||
).toEqual('^1.0 || ^2.0');
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '>=1.0 <3.0',
|
||||
rangeStrategy: 'widen',
|
||||
currentVersion: '2.9.0',
|
||||
newVersion: '4.1.0',
|
||||
})
|
||||
).toEqual('>=1.0 <4.2');
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '>=1.0 <3.0',
|
||||
rangeStrategy: 'widen',
|
||||
currentVersion: '2.9.0',
|
||||
newVersion: '2.9.5',
|
||||
})
|
||||
).toEqual('>=1.0 <3.0');
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '>=1.0 <3.0',
|
||||
rangeStrategy: 'widen',
|
||||
currentVersion: '2.9.0',
|
||||
newVersion: '3.0',
|
||||
})
|
||||
).toEqual('>=1.0 <3.1');
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '>=1.0.0 <=3.0.4',
|
||||
rangeStrategy: 'widen',
|
||||
currentVersion: '2.9.0',
|
||||
newVersion: '3.0.5',
|
||||
})
|
||||
).toEqual('>=1.0.0 <=3.0.5');
|
||||
expect(
|
||||
semver.getNewValue({
|
||||
currentValue: '~1.0 || >=3.0 <=4.0',
|
||||
rangeStrategy: 'widen',
|
||||
currentVersion: '2.9.0',
|
||||
newVersion: '5.0.0',
|
||||
})
|
||||
).toEqual('~1.0 || >=3.0 <=5.0');
|
||||
});
|
||||
it('returns newVersion if unsupported', () => {
|
||||
expect(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { coerce } from 'semver';
|
||||
import { parseRange } from 'semver-utils';
|
||||
import { logger } from '../../logger';
|
||||
import { api as npm } from '../npm';
|
||||
import type { NewValueConfig, VersioningApi } from '../types';
|
||||
|
@ -189,11 +190,19 @@ function getNewValue({
|
|||
});
|
||||
if (rangeStrategy === 'replace') {
|
||||
newValue = replacementValue;
|
||||
} else {
|
||||
const parsedRange = parseRange(replacementValue);
|
||||
const element = parsedRange[parsedRange.length - 1];
|
||||
if (element.operator?.startsWith('<')) {
|
||||
const splitCurrent = currentValue.split(element.operator);
|
||||
splitCurrent.pop();
|
||||
newValue = splitCurrent.join(element.operator) + replacementValue;
|
||||
} else {
|
||||
newValue = currentValue + ' || ' + replacementValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!newValue) {
|
||||
logger.warn(
|
||||
|
|
Loading…
Reference in a new issue