@@ -3,51 +3,63 @@ module.exports = {
33 const oldVersion = dependency . oldVersion
44 const newVersion = dependency . version
55
6- let modifiedBody = body
6+ const replaceActions = [ ]
77
88 const regexVersionVariable = new RegExp ( dependency . group + ":" + dependency . name + ":\\${?(\\w+)}?" , "ig" )
99
1010 // 'de.kevcodez:pubg-api-wrapper:$myVar'
1111 // 'de.kevcodez:pubg-api-wrapper:${myVar}'
12- const versionWithVariableMatches = regexVersionVariable . exec ( modifiedBody )
12+ const versionWithVariableMatches = regexVersionVariable . exec ( body )
1313 if ( versionWithVariableMatches && versionWithVariableMatches . length === 2 ) {
1414 const variableName = versionWithVariableMatches [ 1 ]
1515
1616 const regexVariableDefinition = new RegExp ( `(${ variableName } (\\s+)?=(\\s+)?('|")${ oldVersion } ('|"))` , "ig" )
17- const regexVariableDefinitionMatches = regexVariableDefinition . exec ( modifiedBody )
17+ const regexVariableDefinitionMatches = regexVariableDefinition . exec ( body )
1818
1919 if ( regexVariableDefinitionMatches && regexVariableDefinitionMatches . length ) {
2020 regexVariableDefinitionMatches . filter ( it => it . includes ( dependency . oldVersion ) ) . forEach ( match => {
21- modifiedBody = modifiedBody . replace ( match , match . replace ( dependency . oldVersion , dependency . version ) )
21+ replaceActions . push ( {
22+ searchValue : match ,
23+ replaceValue : match . replace ( dependency . oldVersion , dependency . version )
24+ } )
2225 } )
2326 }
2427 }
2528
2629 // compile 'de.kevcodez:pubg-api-wrapper:1.0.0'
2730 const regexVersionInline = new RegExp ( `${ dependency . group } :${ dependency . name } :${ dependency . oldVersion } ` , "g" )
28- if ( regexVersionInline . exec ( modifiedBody ) ) {
29- modifiedBody = modifiedBody . replace ( regexVersionInline , `${ dependency . group } :${ dependency . name } :${ dependency . version } ` )
31+ if ( regexVersionInline . exec ( body ) ) {
32+ replaceActions . push ( {
33+ searchValue : regexVersionInline ,
34+ replaceValue : `${ dependency . group } :${ dependency . name } :${ dependency . version } `
35+ } )
3036 }
3137
3238 // id 'com.github.ben-manes.versions' version "0.21.0"
3339 // id("com.github.ben-manes.versions") version "0.22.0"
3440 const regexPluginVersionWithPrefix = new RegExp ( `${ dependency . group } ("|')\\)?(\\s+)?version(\\s+)?("|')${ oldVersion } ("|')` )
35- const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix . exec ( modifiedBody )
41+ const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix . exec ( body )
3642 if ( regexVersionWithPrefixMatches && regexVersionWithPrefixMatches . length ) {
3743 regexVersionWithPrefixMatches . filter ( it => it . includes ( oldVersion ) ) . forEach ( match => {
38- modifiedBody = modifiedBody . replace ( match , match . replace ( oldVersion , newVersion ) )
44+ replaceActions . push ( {
45+ searchValue : match ,
46+ replaceValue : match . replace ( oldVersion , newVersion )
47+ } )
3948 } )
4049 }
4150
4251 // compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1'
4352 const regexDependencyWithVersionPrefix = new RegExp ( `${ dependency . name } ('|"),(\\s+)?version:(\\s+)('|")${ dependency . oldVersion } ('|")` )
44- const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix . exec ( modifiedBody )
53+ const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix . exec ( body )
4554 if ( regexDependencyWithVersionPrefixMatches && regexDependencyWithVersionPrefixMatches . length ) {
4655 regexDependencyWithVersionPrefixMatches . filter ( it => it . includes ( oldVersion ) ) . forEach ( match => {
47- modifiedBody = modifiedBody . replace ( match , match . replace ( oldVersion , newVersion ) )
56+ replaceActions . push ( {
57+ searchValue : match ,
58+ replaceValue : match . replace ( oldVersion , newVersion )
59+ } )
4860 } )
4961 }
5062
51- return modifiedBody
63+ return replaceActions
5264 }
5365}
0 commit comments