Skip to content

Commit

Permalink
fix(gomod): support replace statement
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki0 committed Nov 28, 2022
1 parent f13d783 commit a9c080c
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions module/go_mod/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,33 @@ func (i *Inspector) InspectProject(ctx context.Context) error {
m.Name = f.Module.Mod.Path
}

var depM = make(map[[2]string]struct{})
var depReplace = make(map[[2]string][2]string)
for _, it := range f.Replace {
depReplace[[2]string{it.Old.Path, it.Old.Version}] = [2]string{it.New.Path, it.New.Version}
depReplace[[2]string{it.Old.Path, ""}] = [2]string{it.New.Path, it.New.Version}
}

for _, it := range f.Require {
if it == nil {
continue
}
depM[[2]string{it.Mod.Path, it.Mod.Version}] = struct{}{}
}
for _, it := range f.Replace {
delete(depM, [2]string{it.Old.Path, it.Old.Version})
depM[[2]string{it.New.Path, it.New.Version}] = struct{}{}
}
for it := range depM {
m.Dependencies = append(m.Dependencies, model.Dependency{
Name: it[0],
Version: it[1],
})
if target, ok := depReplace[[2]string{it.Mod.Path, it.Mod.Version}]; ok {
m.Dependencies = append(m.Dependencies, model.Dependency{
Name: target[0],
Version: target[1],
})
continue
}
if target, ok := depReplace[[2]string{it.Mod.Path, ""}]; ok {
m.Dependencies = append(m.Dependencies, model.Dependency{
Name: target[0],
Version: target[1],
})
continue
}
m.Dependencies = append(m.Dependencies, model.Dependency{Name: it.Mod.Path, Version: it.Mod.Version})
}

task.AddModule(m)
return nil
}

0 comments on commit a9c080c

Please sign in to comment.