File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,9 @@ func findPackagesInSourceCode(root string) map[string]bool {
181181 return packages
182182}
183183
184+ // Compile the regular expression once
185+ var majorVersionSuffixRegex = regexp .MustCompile (`^/v[1-9][0-9]*(/|$)` )
186+
184187// findPackagesForModule returns the submodules of a given module that are actually used in the source code
185188func findPackagesForModule (modulePath string , usedPackages map [string ]bool ) []string {
186189 var packages []string
@@ -190,9 +193,12 @@ func findPackagesForModule(modulePath string, usedPackages map[string]bool) []st
190193 if strings .HasPrefix (pkg , modulePath ) {
191194 // Extract the part after modulePath
192195 suffix := pkg [len (modulePath ):]
193- matched , _ := regexp .MatchString (`^/v[1-9][0-9]*(/|$)` , suffix )
194196
195- if ! matched {
197+ // If `suffix` begins with a major version suffix then we do not have the right module
198+ // path. For example, if the module path is `example.com/mymodule` and the package path
199+ // is `example.com/mymodule/v2/submodule` then we should not consider it a match - it
200+ // is really a match for the module `example.com/mymodule/v2`.
201+ if ! majorVersionSuffixRegex .MatchString (suffix ) {
196202 packages = append (packages , pkg )
197203 }
198204 }
You can’t perform that action at this time.
0 commit comments