Skip to content

Commit 72c7c67

Browse files
committed
Replace dependency version with version prefix
1 parent 232d7ef commit 72c7c67

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ReplaceVersion.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = {
77

88
const regexVersionVariable = new RegExp(dependency.group + ":" + dependency.name + ":\\${?(\\w+)}?", "ig")
99

10+
// 'de.kevcodez:pubg-api-wrapper:$myVar'
11+
// 'de.kevcodez:pubg-api-wrapper:${myVar}'
1012
const versionWithVariableMatches = regexVersionVariable.exec(modifiedBody)
1113
if (versionWithVariableMatches && versionWithVariableMatches.length === 2) {
1214
const variableName = versionWithVariableMatches[1]
@@ -19,18 +21,29 @@ module.exports = {
1921
})
2022
}
2123

24+
// compile 'de.kevcodez:pubg-api-wrapper:1.0.0'
2225
const regexVersionInline = new RegExp(`${dependency.group}:${dependency.name}:${dependency.oldVersion}`, "g")
2326
if (regexVersionInline.exec(modifiedBody)) {
2427
modifiedBody = modifiedBody.replace(regexVersionInline, `${dependency.group}:${dependency.name}:${dependency.version}`)
2528
}
2629

27-
const regexVersionWithPrefix = new RegExp(`${dependency.group}("|')(\\s+)?version(\\s+)?("|')${oldVersion}("|')`)
28-
const regexVersionWithPrefixMatches = regexVersionWithPrefix.exec(modifiedBody)
30+
// id 'com.github.ben-manes.versions' version "0.21.0"
31+
const regexPluginVersionWithPrefix = new RegExp(`${dependency.group}("|')(\\s+)?version(\\s+)?("|')${oldVersion}("|')`)
32+
const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix.exec(modifiedBody)
2933
if (regexVersionWithPrefixMatches) {
3034
regexVersionWithPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => {
3135
modifiedBody = modifiedBody.replace(match, match.replace(oldVersion, newVersion))
3236
})
3337
}
38+
39+
// compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1'
40+
const regexDependencyWithVersionPrefix = new RegExp(`${dependency.name}('|"),(\\s+)?version:(\\s+)('|")${dependency.oldVersion}('|")`)
41+
const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix.exec(modifiedBody)
42+
if (regexDependencyWithVersionPrefixMatches) {
43+
regexDependencyWithVersionPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => {
44+
modifiedBody = modifiedBody.replace(match, match.replace(oldVersion, newVersion))
45+
})
46+
}
3447

3548
return modifiedBody
3649
}

__tests__/ReplaceVersion.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ test('Replace plugin version with double quotation marks', () => {
5858
const replacedVersion = ReplaceVersion.replace(`id 'com.github.ben-manes.versions' version "0.21.0"`, pluginDependency)
5959

6060
expect(replacedVersion).toBe(`id 'com.github.ben-manes.versions' version "0.22.0"`)
61+
})
62+
test('Replace version with version prefix in dependency', () => {
63+
const replacedVersion = ReplaceVersion.replace(`compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1'`, dependency)
64+
65+
expect(replacedVersion).toBe(`compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '1.0.0'`)
6166
})

0 commit comments

Comments
 (0)