Skip to content

Commit

Permalink
fix(npm): Widen range only if necessary (#9630)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Apr 19, 2021
1 parent 0355a75 commit 8b8d776
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/versioning/hex/index.spec.ts
Expand Up @@ -198,7 +198,7 @@ describe(getName(__filename), () => {
currentVersion: '1.2.3',
newVersion: '2.0.7',
})
).toEqual('>= 1.0.0 or <= 2.0.7');
).toEqual('>= 1.0.0 or <= 2.0.0');
expect(
hexScheme.getNewValue({
currentValue: '>= 1.0.0 or <= 2.0.0',
Expand Down
34 changes: 34 additions & 0 deletions lib/versioning/npm/index.spec.ts
Expand Up @@ -325,4 +325,38 @@ describe('semver.getNewValue()', () => {
})
).toEqual('>= 1.0.1 < 2');
});
it('widens', () => {
expect(
semver.getNewValue({
currentValue: '<=1.2.3',
rangeStrategy: 'widen',
currentVersion: '1.0.0',
newVersion: '1.2.3',
})
).toEqual('<=1.2.3');
expect(
semver.getNewValue({
currentValue: '<=1.2.3',
rangeStrategy: 'widen',
currentVersion: '1.0.0',
newVersion: '1.2.4',
})
).toEqual('<=1.2.4');
expect(
semver.getNewValue({
currentValue: '>=1.2.3',
rangeStrategy: 'widen',
currentVersion: '1.0.0',
newVersion: '1.2.3',
})
).toEqual('>=1.2.3');
expect(
semver.getNewValue({
currentValue: '>=1.2.3',
rangeStrategy: 'widen',
currentVersion: '1.0.0',
newVersion: '1.2.1',
})
).toEqual('>=1.2.3 || 1.2.1');
});
});
3 changes: 3 additions & 0 deletions lib/versioning/npm/range.ts
Expand Up @@ -75,6 +75,9 @@ export function getNewValue({
const parsedRange = parseRange(currentValue);
const element = parsedRange[parsedRange.length - 1];
if (rangeStrategy === 'widen') {
if (satisfies(newVersion, currentValue)) {
return currentValue;
}
const newValue = getNewValue({
currentValue,
rangeStrategy: 'replace',
Expand Down

0 comments on commit 8b8d776

Please sign in to comment.