File tree 5 files changed +37
-2
lines changed
5 files changed +37
-2
lines changed Original file line number Diff line number Diff line change
1
+ exports [ 'go.mod updateContent updates a commit dependency 1' ] = `
2
+ module example.com/hello/world
3
+
4
+ go 1.23.0
5
+
6
+ replace example.com/foo/bar/v2 => ../../foo/bar
7
+
8
+ require (
9
+ \texample.com/foo/bar/v2 v2.1.0
10
+ \texample.com/foo/baz v1.2.3
11
+ \texample.com/car/dar v0.1.2 // indirect
12
+ )
13
+
14
+ `
15
+
1
16
exports [ 'go.mod updateContent updates dependencies 1' ] = `
2
17
module example.com/hello/world
3
18
@@ -8,6 +23,7 @@ replace example.com/foo/bar/v2 => ../../foo/bar
8
23
require (
9
24
\texample.com/foo/bar/v2 v2.1.3
10
25
\texample.com/foo/baz v1.2.3
26
+ \texample.com/car/dar v0.1.1-0.20250203122516-4c838e530ecb // indirect
11
27
)
12
28
13
29
`
Original file line number Diff line number Diff line change @@ -32,7 +32,9 @@ export class GoMod extends DefaultUpdater {
32
32
}
33
33
34
34
for ( const [ pkgName , pkgVersion ] of this . versionsMap ) {
35
- const regex = new RegExp ( `${ pkgName } v\\d+\\.\\d+\\.\\d+` , 'g' ) ;
35
+ // Easy version is v1.2.3
36
+ // But if depending on a commit it could be v0.1.1-0.20250203122516-4c838e530ecb
37
+ const regex = new RegExp ( `${ pkgName } v\\d+\\.\\d+\\.\\d+[^\\s]*` , 'g' ) ;
36
38
// Is the dep in the go.mod file?
37
39
const deps = regex . exec ( payload ) ;
38
40
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {DefaultUpdater} from '../default';
17
17
export class VersionGo extends DefaultUpdater {
18
18
updateContent ( content : string ) : string {
19
19
return content . replace (
20
- / c o n s t V e r s i o n = " [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] ( - \w + ) ? " / ,
20
+ / c o n s t V e r s i o n = " \d + \. \d + \. \d [ ^ \s ] * " / ,
21
21
`const Version = "${ this . version . toString ( ) } "`
22
22
) ;
23
23
}
Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ replace example.com/foo/bar/v2 => ../../foo/bar
7
7
require (
8
8
example.com/foo/bar/v2 v2.1.0
9
9
example.com/foo/baz v1.2.3
10
+ example.com/car/dar v0.1.1-0.20250203122516-4c838e530ecb // indirect
10
11
)
Original file line number Diff line number Diff line change @@ -55,5 +55,21 @@ describe('go.mod', () => {
55
55
const newContent = updater . updateContent ( oldContent ) ;
56
56
snapshot ( newContent ) ;
57
57
} ) ;
58
+ it ( 'updates a commit dependency' , async ( ) => {
59
+ const oldContent = readFileSync (
60
+ resolve ( fixturesPath , './go.mod' ) ,
61
+ 'utf8'
62
+ ) . replace ( / \r \n / g, '\n' ) ;
63
+ const updatedVersions = new Map ( ) ;
64
+ updatedVersions . set ( 'example.com/car/dar' , Version . parse ( 'v0.1.2' ) ) ;
65
+
66
+ const updater = new GoMod ( {
67
+ version : Version . parse ( 'v2.3.4' ) ,
68
+ versionsMap : updatedVersions ,
69
+ } ) ;
70
+ const newContent = updater . updateContent ( oldContent ) ;
71
+ snapshot ( newContent ) ;
72
+ expect ( newContent ) . to . include ( 'example.com/car/dar v0.1.2 // indirect' ) ;
73
+ } ) ;
58
74
} ) ;
59
75
} ) ;
You can’t perform that action at this time.
0 commit comments