bayraktugrul / modview

Effortlessly visualize mod graph with all external dependencies for your Go projects
MIT License
150 stars 5 forks source link

bug: Fix multi root problem for mod has replace statement #3

Closed bayraktugrul closed 2 weeks ago

bayraktugrul commented 2 weeks ago

Title : Fix multiple root nodes in dependency graph by ignoring non-root nodes without version

Description : This PR addresses the issue of multiple root nodes appearing in the dependency graph when replace directives are used in the go.mod file.

The changes ensure that: The root node is always set based on the module directive in go.mod, regardless of the presence of replace directives. During dependency parsing, any node (from or to) that does not contain a version (@) and is not the root module is ignored. This prevents multiple roots from being created.

Using replace directives in go.mod can lead to go mod graph output missing version information for some modules, resulting in multiple root nodes in the generated dependency graph. This change ensures a single root node is maintained, providing a clearer and more accurate visualization of the project's dependencies. It resolves the instability and confusion caused by multiple roots, especially in projects with complex dependency structures (Example: https://github.com/kubernetes/kubernetes).

related past issues: https://github.com/golang/go/issues/40513 https://github.com/golang/go/issues/46365