diff --git a/lib/versioning/composer/index.spec.ts b/lib/versioning/composer/index.spec.ts index aa333abe89bcfe0328c971bafb838a8833ba8016..95e746584f8e9fed0cbdc5abfece20ad2790ed37 100644 --- a/lib/versioning/composer/index.spec.ts +++ b/lib/versioning/composer/index.spec.ts @@ -127,6 +127,14 @@ describe('semver.getNewValue()', () => { toVersion: 'V1.1', }) ).toEqual('V1.1'); + expect( + semver.getNewValue({ + currentValue: '^1.0', + rangeStrategy: 'pin', + fromVersion: '1.0', + toVersion: 'V1.1', + }) + ).toEqual('V1.1'); }); it('returns toVersion', () => { expect( @@ -148,6 +156,36 @@ describe('semver.getNewValue()', () => { }) ).toEqual('^1.0'); }); + it('bumps caret to same', () => { + expect( + semver.getNewValue({ + currentValue: '^1.0.0', + rangeStrategy: 'bump', + fromVersion: '1.0.0', + toVersion: '1.3.5', + }) + ).toEqual('^1.3.5'); + }); + it('replaces caret to same', () => { + expect( + semver.getNewValue({ + currentValue: '^1', + rangeStrategy: 'replace', + fromVersion: '1.0.0', + toVersion: '1.3.5', + }) + ).toEqual('^1'); + }); + it('replaces short caret', () => { + expect( + semver.getNewValue({ + currentValue: '^1.0', + rangeStrategy: 'replace', + fromVersion: '1.0.0', + toVersion: '2.3.5', + }) + ).toEqual('^2.0'); + }); it('handles tilde zero', () => { expect( semver.getNewValue({ diff --git a/lib/versioning/composer/index.ts b/lib/versioning/composer/index.ts index cc5d0de45416eb0d19cf1b40cdcc8788514387be..c66b70561ab55d91d5b2f135d0b0853fd63443f1 100644 --- a/lib/versioning/composer/index.ts +++ b/lib/versioning/composer/index.ts @@ -95,6 +95,26 @@ function getNewValue({ let newValue: string; if (isVersion(currentValue)) { newValue = toVersion; + } else if (/^[~^](0\.[1-9][0-9]*)$/.test(currentValue)) { + const operator = currentValue.substr(0, 1); + // handle ~0.4 case first + if (toMajor === 0) { + newValue = `${operator}0.${toMinor}`; + } else { + newValue = `${operator}${toMajor}.0`; + } + } else if (/^[~^]([0-9]*)$/.test(currentValue)) { + // handle ~4 case + const operator = currentValue.substr(0, 1); + newValue = `${operator}${toMajor}`; + } else if (/^[~^]([0-9]*(?:\.[0-9]*)?)$/.test(currentValue)) { + const operator = currentValue.substr(0, 1); + // handle ~4.1 case + if (fromVersion && toMajor > getMajor(fromVersion)) { + newValue = `${operator}${toMajor}.0`; + } else { + newValue = `${operator}${toMajor}.${toMinor}`; + } } else if ( npm.isVersion(padZeroes(toVersion)) && npm.isValid(currentValue) && @@ -106,23 +126,6 @@ function getNewValue({ fromVersion, toVersion: padZeroes(toVersion), }); - } else if (/^~(0\.[1-9][0-9]*)$/.test(currentValue)) { - // handle ~0.4 case first - if (toMajor === 0) { - newValue = `~0.${toMinor}`; - } else { - newValue = `~${toMajor}.0`; - } - } else if (/^~([0-9]*)$/.test(currentValue)) { - // handle ~4 case - newValue = `~${toMajor}`; - } else if (/^~([0-9]*(?:\.[0-9]*)?)$/.test(currentValue)) { - // handle ~4.1 case - if (fromVersion && toMajor > getMajor(fromVersion)) { - newValue = `~${toMajor}.0`; - } else { - newValue = `~${toMajor}.${toMinor}`; - } } if (currentValue.includes(' || ')) { const lastValue = currentValue.split('||').pop().trim();