@@ -3,51 +3,63 @@ module.exports = {
3
3
const oldVersion = dependency . oldVersion
4
4
const newVersion = dependency . version
5
5
6
- let modifiedBody = body
6
+ const replaceActions = [ ]
7
7
8
8
const regexVersionVariable = new RegExp ( dependency . group + ":" + dependency . name + ":\\${?(\\w+)}?" , "ig" )
9
9
10
10
// 'de.kevcodez:pubg-api-wrapper:$myVar'
11
11
// 'de.kevcodez:pubg-api-wrapper:${myVar}'
12
- const versionWithVariableMatches = regexVersionVariable . exec ( modifiedBody )
12
+ const versionWithVariableMatches = regexVersionVariable . exec ( body )
13
13
if ( versionWithVariableMatches && versionWithVariableMatches . length === 2 ) {
14
14
const variableName = versionWithVariableMatches [ 1 ]
15
15
16
16
const regexVariableDefinition = new RegExp ( `(${ variableName } (\\s+)?=(\\s+)?('|")${ oldVersion } ('|"))` , "ig" )
17
- const regexVariableDefinitionMatches = regexVariableDefinition . exec ( modifiedBody )
17
+ const regexVariableDefinitionMatches = regexVariableDefinition . exec ( body )
18
18
19
19
if ( regexVariableDefinitionMatches && regexVariableDefinitionMatches . length ) {
20
20
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
+ } )
22
25
} )
23
26
}
24
27
}
25
28
26
29
// compile 'de.kevcodez:pubg-api-wrapper:1.0.0'
27
30
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
+ } )
30
36
}
31
37
32
38
// id 'com.github.ben-manes.versions' version "0.21.0"
33
39
// id("com.github.ben-manes.versions") version "0.22.0"
34
40
const regexPluginVersionWithPrefix = new RegExp ( `${ dependency . group } ("|')\\)?(\\s+)?version(\\s+)?("|')${ oldVersion } ("|')` )
35
- const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix . exec ( modifiedBody )
41
+ const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix . exec ( body )
36
42
if ( regexVersionWithPrefixMatches && regexVersionWithPrefixMatches . length ) {
37
43
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
+ } )
39
48
} )
40
49
}
41
50
42
51
// compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1'
43
52
const regexDependencyWithVersionPrefix = new RegExp ( `${ dependency . name } ('|"),(\\s+)?version:(\\s+)('|")${ dependency . oldVersion } ('|")` )
44
- const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix . exec ( modifiedBody )
53
+ const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix . exec ( body )
45
54
if ( regexDependencyWithVersionPrefixMatches && regexDependencyWithVersionPrefixMatches . length ) {
46
55
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
+ } )
48
60
} )
49
61
}
50
62
51
- return modifiedBody
63
+ return replaceActions
52
64
}
53
65
}
0 commit comments