@@ -49,23 +49,33 @@ func (i *Inspector) InspectProject(ctx context.Context) error {
4949 m .Name = f .Module .Mod .Path
5050 }
5151
52- var depM = make (map [[2 ]string ]struct {})
52+ var depReplace = make (map [[2 ]string ][2 ]string )
53+ for _ , it := range f .Replace {
54+ depReplace [[2 ]string {it .Old .Path , it .Old .Version }] = [2 ]string {it .New .Path , it .New .Version }
55+ depReplace [[2 ]string {it .Old .Path , "" }] = [2 ]string {it .New .Path , it .New .Version }
56+ }
57+
5358 for _ , it := range f .Require {
5459 if it == nil {
5560 continue
5661 }
57- depM [[2 ]string {it .Mod .Path , it .Mod .Version }] = struct {}{}
58- }
59- for _ , it := range f .Replace {
60- delete (depM , [2 ]string {it .Old .Path , it .Old .Version })
61- depM [[2 ]string {it .New .Path , it .New .Version }] = struct {}{}
62- }
63- for it := range depM {
64- m .Dependencies = append (m .Dependencies , model.Dependency {
65- Name : it [0 ],
66- Version : it [1 ],
67- })
62+ if target , ok := depReplace [[2 ]string {it .Mod .Path , it .Mod .Version }]; ok {
63+ m .Dependencies = append (m .Dependencies , model.Dependency {
64+ Name : target [0 ],
65+ Version : target [1 ],
66+ })
67+ continue
68+ }
69+ if target , ok := depReplace [[2 ]string {it .Mod .Path , "" }]; ok {
70+ m .Dependencies = append (m .Dependencies , model.Dependency {
71+ Name : target [0 ],
72+ Version : target [1 ],
73+ })
74+ continue
75+ }
76+ m .Dependencies = append (m .Dependencies , model.Dependency {Name : it .Mod .Path , Version : it .Mod .Version })
6877 }
78+
6979 task .AddModule (m )
7080 return nil
7181}
0 commit comments