fix: issue with same package prefix

This commit is contained in:
Kevin Franklin Kim 2023-11-16 11:10:26 +01:00
parent 31ed4250f6
commit 8bdced3acf
No known key found for this signature in database

View File

@ -146,7 +146,7 @@ func parseDir(goPaths []string, gomod config.Namespace, packageName string) (map
fset := token.NewFileSet() fset := token.NewFileSet()
if gomod.ModFile != nil { if gomod.ModFile != nil {
for _, rep := range gomod.ModFile.Replace { for _, rep := range gomod.ModFile.Replace {
if strings.HasPrefix(packageName, rep.Old.Path) { if packageName == rep.Old.Path || strings.HasPrefix(packageName, rep.Old.Path+"/") {
if strings.HasPrefix(rep.New.String(), ".") || strings.HasPrefix(rep.New.Path, "/") { if strings.HasPrefix(rep.New.String(), ".") || strings.HasPrefix(rep.New.Path, "/") {
trace("replacing package with local dir", packageName, rep.Old.String(), rep.New.String()) trace("replacing package with local dir", packageName, rep.Old.String(), rep.New.String())
dir = strings.Replace(packageName, rep.Old.Path, filepath.Join(gomod.Path, rep.New.Path), 1) dir = strings.Replace(packageName, rep.Old.Path, filepath.Join(gomod.Path, rep.New.Path), 1)
@ -159,7 +159,7 @@ func parseDir(goPaths []string, gomod config.Namespace, packageName string) (map
} }
if dir == "" { if dir == "" {
for _, req := range gomod.ModFile.Require { for _, req := range gomod.ModFile.Require {
if strings.HasPrefix(packageName, req.Mod.Path) { if packageName == req.Mod.Path || strings.HasPrefix(packageName, req.Mod.Path+"/") {
trace("resolving mod package", packageName, req.Mod.String()) trace("resolving mod package", packageName, req.Mod.String())
dir = strings.TrimSuffix(path.Join(goPath, "pkg", "mod", req.Mod.String(), strings.TrimPrefix(packageName, req.Mod.Path)), "/") dir = strings.TrimSuffix(path.Join(goPath, "pkg", "mod", req.Mod.String(), strings.TrimPrefix(packageName, req.Mod.Path)), "/")
break break