1
1
package mod
2
2
3
3
import (
4
+ "fmt"
4
5
"io"
5
6
"regexp"
6
7
"strconv"
@@ -90,21 +91,22 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
90
91
if p .useMinVersion {
91
92
if toolchainVer := toolchainVersion (modFileParsed .Toolchain , modFileParsed .Go ); toolchainVer != "" {
92
93
pkgs ["stdlib" ] = ftypes.Package {
93
- ID : packageID ("stdlib" , toolchainVer ),
94
- Name : "stdlib" ,
95
- Version : toolchainVer ,
94
+ ID : packageID ("stdlib" , toolchainVer ),
95
+ Name : "stdlib" ,
96
+ // Our versioning library doesn't support canonical (goX.Y.Z) format,
97
+ // So we need to add `v` prefix for consistency (with module and dependency versions).
98
+ Version : fmt .Sprintf ("v%s" , toolchainVer ),
96
99
Relationship : ftypes .RelationshipDirect , // Considered a direct dependency as the main module depends on the standard packages.
97
100
}
98
101
}
99
102
}
100
103
101
104
// Main module
102
105
if m := modFileParsed .Module ; m != nil {
103
- ver := strings .TrimPrefix (m .Mod .Version , "v" )
104
106
pkgs [m .Mod .Path ] = ftypes.Package {
105
- ID : packageID (m .Mod .Path , ver ),
107
+ ID : packageID (m .Mod .Path , m . Mod . Version ),
106
108
Name : m .Mod .Path ,
107
- Version : ver ,
109
+ Version : m . Mod . Version ,
108
110
ExternalReferences : p .GetExternalRefs (m .Mod .Path ),
109
111
Relationship : ftypes .RelationshipRoot ,
110
112
}
@@ -116,11 +118,10 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
116
118
if skipIndirect && require .Indirect {
117
119
continue
118
120
}
119
- ver := strings .TrimPrefix (require .Mod .Version , "v" )
120
121
pkgs [require .Mod .Path ] = ftypes.Package {
121
- ID : packageID (require .Mod .Path , ver ),
122
+ ID : packageID (require .Mod .Path , require . Mod . Version ),
122
123
Name : require .Mod .Path ,
123
- Version : ver ,
124
+ Version : require . Mod . Version ,
124
125
Relationship : lo .Ternary (require .Indirect , ftypes .RelationshipIndirect , ftypes .RelationshipDirect ),
125
126
ExternalReferences : p .GetExternalRefs (require .Mod .Path ),
126
127
}
@@ -136,7 +137,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
136
137
}
137
138
138
139
// If the replace directive has a version on the left side, make sure it matches the version that was imported.
139
- if rep .Old .Version != "" && old .Version != rep .Old .Version [ 1 :] {
140
+ if rep .Old .Version != "" && old .Version != rep .Old .Version {
140
141
continue
141
142
}
142
143
@@ -153,9 +154,9 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
153
154
154
155
// Add replaced package to package register.
155
156
pkgs [rep .New .Path ] = ftypes.Package {
156
- ID : packageID (rep .New .Path , rep .New .Version [ 1 :] ),
157
+ ID : packageID (rep .New .Path , rep .New .Version ),
157
158
Name : rep .New .Path ,
158
- Version : rep .New .Version [ 1 :] ,
159
+ Version : rep .New .Version ,
159
160
Relationship : old .Relationship ,
160
161
ExternalReferences : p .GetExternalRefs (rep .New .Path ),
161
162
}
0 commit comments