You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I understand correctly, I think go mod why -m <module-path> should always show a shortest path unless the target module doesn't exist in the import graph. But it sometimes shows unexpected (main module does not need ...), even if the target module definitely exists in the import graph (can be proven by go mod graph).
$ git clone -q https://github.com/appleboy/gin-jwt.git &&cd gin-jwt
$ go mod graph | grep 'github.com/belogik/goes'
github.com/astaxie/beego@v1.11.1 github.com/belogik/goes@v0.0.0-20151229125003-e54d722c3aff
$ go mod why -m github.com/belogik/goes
# github.com/belogik/goes
(main module does not need module github.com/belogik/goes)
I think the expected output of go mod why -m github.com/belogik/goes here should be:
With this result, we can clearly know exactly how a module enters our import graph. But now we have to know it by using some workarounds like go mod graph | grep '<module-path>', this's inconvenient.
go mod why -m doesn't actually show the shortest path through the module version graph. From go help mod why:
Why shows a shortest path in the import graph from the main module to each of the listed packages. If the -m flag is given, why treats the arguments as a list of modules and finds a path to any package in each of the modules.
So in this case go mod why -m reports that the main module does not need github.com/belogik/goes because no packages in that module are transitively imported by packages in the main module. github.com/belogik/goes is transitively required via go.mod files, so it shows up in the go mod graph output.
Closing because this is working as documented. However, I admit I don't personally find this behavior intuitive, and I think most people expect go mod why -m to operate on the module graph, not the package graph. Maybe we should consider a proposal to change that.
If I understand correctly, I think
go mod why -m <module-path>
should always show a shortest path unless the target module doesn't exist in the import graph. But it sometimes shows unexpected(main module does not need ...)
, even if the target module definitely exists in the import graph (can be proven bygo mod graph
).Try this (from #36423 (comment)):
I think the expected output of
go mod why -m github.com/belogik/goes
here should be:# github.com/belogik/goes github.com/appleboy/gin-jwt/v2 github.com/appleboy/gin-jwt/v2.test github.com/appleboy/gofight/v2 github.com/appleboy/gofight/v2/example github.com/astaxie/beego github.com/astaxie/beego/logs/es github.com/belogik/goes
With this result, we can clearly know exactly how a module enters our import graph. But now we have to know it by using some workarounds like
go mod graph | grep '<module-path>'
, this's inconvenient./cc @bcmills, @jayconrod
The text was updated successfully, but these errors were encountered: