diff --git a/lib/versioning/hashicorp/index.ts b/lib/versioning/hashicorp/index.ts index eca16e90c11bc2080c0572b32327e6547399645d..c963e84f5d9d8ee8e59e0a341945a0cbcaecf469 100644 --- a/lib/versioning/hashicorp/index.ts +++ b/lib/versioning/hashicorp/index.ts @@ -15,8 +15,9 @@ function hashicorp2npm(input: string): string { return input.replace(regEx(/~>(\s*\d+\.\d+$)/), '^$1').replace(',', ''); } -const isLessThanRange = (version: string, range: string): boolean => - npm.isLessThanRange(hashicorp2npm(version), hashicorp2npm(range)); +function isLessThanRange(version: string, range: string): boolean { + return !!npm.isLessThanRange?.(hashicorp2npm(version), hashicorp2npm(range)); +} export const isValid = (input: string): boolean => !!input && npm.isValid(hashicorp2npm(input)); @@ -24,29 +25,42 @@ export const isValid = (input: string): boolean => const matches = (version: string, range: string): boolean => npm.matches(hashicorp2npm(version), hashicorp2npm(range)); -const getSatisfyingVersion = (versions: string[], range: string): string => - npm.getSatisfyingVersion(versions.map(hashicorp2npm), hashicorp2npm(range)); +function getSatisfyingVersion( + versions: string[], + range: string +): string | null { + return npm.getSatisfyingVersion( + versions.map(hashicorp2npm), + hashicorp2npm(range) + ); +} -const minSatisfyingVersion = (versions: string[], range: string): string => - npm.minSatisfyingVersion(versions.map(hashicorp2npm), hashicorp2npm(range)); +function minSatisfyingVersion( + versions: string[], + range: string +): string | null { + return npm.minSatisfyingVersion( + versions.map(hashicorp2npm), + hashicorp2npm(range) + ); +} function getNewValue({ currentValue, rangeStrategy, currentVersion, newVersion, -}: NewValueConfig): string { +}: NewValueConfig): string | null { if (['replace', 'update-lockfile'].includes(rangeStrategy)) { - if ( - regEx(/~>\s*0\.\d+/).test(currentValue) && - npm.getMajor(newVersion) === 0 - ) { + const minor = npm.getMinor(newVersion); + const major = npm.getMajor(newVersion); + if (regEx(/~>\s*0\.\d+/).test(currentValue) && major === 0 && minor) { const testFullVersion = regEx(/(~>\s*0\.)(\d+)\.\d$/); let replaceValue = ''; if (testFullVersion.test(currentValue)) { - replaceValue = `$<prefix>${npm.getMinor(newVersion)}.0`; + replaceValue = `$<prefix>${minor}.0`; } else { - replaceValue = `$<prefix>${npm.getMinor(newVersion)}$<suffix>`; + replaceValue = `$<prefix>${minor}$<suffix>`; } return currentValue.replace( regEx(`(?<prefix>~>\\s*0\\.)\\d+(?<suffix>.*)$`), @@ -54,10 +68,10 @@ function getNewValue({ ); } // handle special ~> 1.2 case - if (regEx(/(~>\s*)\d+\.\d+$/).test(currentValue)) { + if (major && regEx(/(~>\s*)\d+\.\d+$/).test(currentValue)) { return currentValue.replace( regEx(`(?<prefix>~>\\s*)\\d+\\.\\d+$`), - `$<prefix>${npm.getMajor(newVersion)}.0` + `$<prefix>${major}.0` ); } } diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ba807ea8f82a9af47faa71c7276dbb0948fd0c19..8d6d68893c1db273e8bed5bf1c22f65ea5b70370 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -386,11 +386,7 @@ "lib/util/merge-confidence/index.ts", "lib/util/package-rules.ts", "lib/versioning/api.ts", - "lib/versioning/aws-machine-image/index.ts", "lib/versioning/common.ts", - "lib/versioning/generic.ts", - "lib/versioning/git/index.ts", - "lib/versioning/hashicorp/index.ts", "lib/versioning/helm/index.ts", "lib/versioning/index.ts", "lib/versioning/poetry/index.ts",