diff --git a/ReplaceVersion.js b/ReplaceVersion.js index 50f39ed..35f00fe 100644 --- a/ReplaceVersion.js +++ b/ReplaceVersion.js @@ -24,6 +24,18 @@ module.exports = { }) }) } + + // val PUBG_API_WRAPPER by extra("0.8.1") + const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`) + const regexKotlinValMatches = regexKotlinValExtra.exec(body) + if (regexKotlinValMatches && regexKotlinValMatches.length) { + regexKotlinValMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => { + replaceActions.push({ + searchValue: match, + replaceValue: match.replace(dependency.oldVersion, dependency.version) + }) + }) + } } // compile 'de.kevcodez:pubg-api-wrapper:1.0.0' diff --git a/__tests__/ReplaceVersion.test.js b/__tests__/ReplaceVersion.test.js index a84f59a..531094d 100644 --- a/__tests__/ReplaceVersion.test.js +++ b/__tests__/ReplaceVersion.test.js @@ -81,6 +81,28 @@ test('Replace kotlin plugin version', () => { const replacedVersion = replaceText(`id("com.github.ben-manes.versions") version "0.22.0"`, pluginDependency) expect(replacedVersion).toBe(`id("com.github.ben-manes.versions") version "0.24.0"`) }) +test('Replace kotlin version with extra val without braces in reference', () => { + const replacedVersion = replaceText(` + val PUBG_API_WRAPPER by extra("0.8.1") + + dependencies { + implementation("de.kevcodez:pubg-api-wrapper:$PUBG_API_WRAPPER") + } + `, dependency) + + expect(replacedVersion).toContain(`val PUBG_API_WRAPPER by extra("1.0.0")`) +}) +test('Replace kotlin version with extra val with braces in reference', () => { + const replacedVersion = replaceText(` + val PUBG_API_WRAPPER by extra("0.8.1") + + dependencies { + implementation("de.kevcodez:pubg-api-wrapper:$\{PUBG_API_WRAPPER\}") + } + `, dependency) + + expect(replacedVersion).toContain(`val PUBG_API_WRAPPER by extra("1.0.0")`) +}) function replaceText(source, dependency) { const replaceVersionActions = ReplaceVersion.replace(source, dependency)