fix(terraform): handle greater than with full version (#9632)

This commit is contained in:
Sebastian Poxhofer 2021-04-19 21:43:13 +02:00 committed by GitHub
parent 8b8d7767bc
commit df2f451e37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View file

@ -67,6 +67,30 @@ describe('semver.getNewValue()', () => {
newVersion: '2.0.7',
})
).toEqual('~> 2.0.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.0',
rangeStrategy: 'replace',
currentVersion: '0.14.1',
newVersion: '0.15.0',
})
).toEqual('~> 0.15.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.0',
rangeStrategy: 'replace',
currentVersion: '0.14.1',
newVersion: '0.15.1',
})
).toEqual('~> 0.15.0');
expect(
semver.getNewValue({
currentValue: '~> 0.14.6',
rangeStrategy: 'replace',
currentVersion: '0.14.6',
newVersion: '0.15.0',
})
).toEqual('~> 0.15.0');
});
it('handles comma dividers', () => {
expect(

View file

@ -36,10 +36,14 @@ function getNewValue({
newVersion,
}: NewValueConfig): string {
if (/~>\s*0\.\d+/.test(currentValue) && npm.getMajor(newVersion) === 0) {
return currentValue.replace(
/(~>\s*0\.).*$/,
`$1${npm.getMinor(newVersion)}`
);
const testFullVersion = /(~>\s*0\.)(\d+)\.\d$/;
let replaceValue = '';
if (testFullVersion.test(currentValue)) {
replaceValue = `$1${npm.getMinor(newVersion)}.0`;
} else {
replaceValue = `$1${npm.getMinor(newVersion)}$3`;
}
return currentValue.replace(/(~>\s*0\.)(\d+)(.*)$/, replaceValue);
}
// handle special ~> 1.2 case
if (/(~>\s*)\d+\.\d+$/.test(currentValue)) {