Skip to content

Commit

Permalink
Merge pull request goretk#59 from goretk/bug/fix-package-classification
Browse files Browse the repository at this point in the history
Fix for package classification
  • Loading branch information
TcM1911 committed May 20, 2022
2 parents 6f9db44 + 648ffc8 commit 141f38f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion package.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,24 @@ func (c *ModPackageClassifier) Classify(pkg *Package) PackageClass {
return ClassMain
}

if strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Main.Path) {
// If the build info path is not an empty string and the package has the path as a substring, it is part of the main module.
if c.modInfo.Path != "" && (strings.HasPrefix(pkg.Filepath, c.modInfo.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Path)) {
return ClassMain
}

// If the main module path is not an empty string and the package has the path as a substring, it is part of the main module.
if c.modInfo.Main.Path != "" && (strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Main.Path)) {
return ClassMain
}

// Check if the package is a direct dependency.
for _, dep := range c.modInfo.Deps {
if strings.HasPrefix(pkg.Filepath, dep.Path) || strings.HasPrefix(pkg.Name, dep.Path) {
// If the vendor it matched on has the version of "(devel)", it is treated as part of
// the main module.
if dep.Version == "(devel)" {
return ClassMain
}
return ClassVendor
}
}
Expand Down

0 comments on commit 141f38f

Please sign in to comment.