Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crosslink/internal/crosslink.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Crosslink(rc RunConfig) error {
return fmt.Errorf("failed to identify root module: %w", err)
}

graph, err := buildDepedencyGraph(rc, rootModulePath)
graph, err := buildDependencyGraph(rc, rootModulePath)
if err != nil {
return fmt.Errorf("failed to build dependency graph: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion crosslink/internal/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// Creates a dependency graph for all intra-repository go.mod files. Only adds
// modules that fall under the root module namespace.
// returns map of module path -> moduleInfo
func buildDepedencyGraph(rc RunConfig, rootModulePath string) (map[string]*moduleInfo, error) {
func buildDependencyGraph(rc RunConfig, rootModulePath string) (map[string]*moduleInfo, error) {
moduleMap := make(map[string]*moduleInfo)

err := forGoModFiles(rc, func(_ string, modPath string, modContents *modfile.File) error {
Expand Down
2 changes: 1 addition & 1 deletion crosslink/internal/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestBuildDependencyGraph(t *testing.T) {
t.Fatalf("error identifying root module: %v", err)
}

receivedMap, err := buildDepedencyGraph(test.config, rootModulePath)
receivedMap, err := buildDependencyGraph(test.config, rootModulePath)

if assert.NoError(t, err, "error message on graph build %s") {
assert.Equal(t, len(test.expected), len(receivedMap), "Module count does not match")
Expand Down
31 changes: 18 additions & 13 deletions crosslink/internal/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"go.uber.org/zap"
"golang.org/x/mod/modfile"
)

// Prune prunes the go.mod replace statements.
Expand All @@ -32,7 +33,7 @@ func Prune(rc RunConfig) error {
return fmt.Errorf("failed to identify root module: %w", err)
}

graph, err := buildDepedencyGraph(rc, rootModulePath)
graph, err := buildDependencyGraph(rc, rootModulePath)
if err != nil {
return fmt.Errorf("failed to build dependency graph: %w", err)
}
Expand All @@ -55,6 +56,7 @@ func pruneReplace(rootModulePath string, module *moduleInfo, rc RunConfig) {
modContents := module.moduleContents

// check to see if its intra dependency and no longer present
var toPrune []*modfile.Replace
for _, rep := range modContents.Replace {
// skip excluded
if _, exists := rc.ExcludedPaths[rep.Old.Path]; exists {
Expand All @@ -65,19 +67,22 @@ func pruneReplace(rootModulePath string, module *moduleInfo, rc RunConfig) {
}

if _, ok := module.requiredReplaceStatements[rep.Old.Path]; strings.Contains(rep.Old.Path, rootModulePath) && !ok {
if rc.Verbose {
rc.Logger.Debug("Pruning replace statement",
zap.String("module", modContents.Module.Mod.Path),
zap.String("replace_statement", rep.Old.Path+" => "+rep.New.Path))
}
err := modContents.DropReplace(rep.Old.Path, rep.Old.Version)
if err != nil {
rc.Logger.Error("error dropping replace statement",
zap.Error(err),
zap.String("module", modContents.Module.Mod.Path),
zap.String("replace_statement", rep.Old.Path+" => "+rep.New.Path))
}
toPrune = append(toPrune, rep)
}
}

for _, rep := range toPrune {
if rc.Verbose {
rc.Logger.Debug("Pruning replace statement",
zap.String("module", modContents.Module.Mod.Path),
zap.String("replace_statement", rep.Old.Path+" => "+rep.New.Path))
}
err := modContents.DropReplace(rep.Old.Path, rep.Old.Version)
if err != nil {
rc.Logger.Error("error dropping replace statement",
zap.Error(err),
zap.String("module", modContents.Module.Mod.Path),
zap.String("replace_statement", rep.Old.Path+" => "+rep.New.Path))
}
}
module.moduleContents = modContents
Expand Down
2 changes: 0 additions & 2 deletions crosslink/internal/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"golang.org/x/mod/modfile"
)

// TODO: Add cleanup to os.removeall

func TestPrune(t *testing.T) {
lg, _ := zap.NewDevelopment()
tests := []struct {
Expand Down
Loading