mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
entc/gen: fix module version extraction when running entc as a package
This commit is contained in:
committed by
Ariel Mashraki
parent
59069b7449
commit
51b63c17c0
@@ -650,11 +650,22 @@ func (g *Graph) templates() (*Template, []GraphTemplate) {
|
||||
return templates, external
|
||||
}
|
||||
|
||||
// ModuleInfo returns the entc binary module version.
|
||||
// ModuleInfo returns the entgo.io/ent version.
|
||||
func (Config) ModuleInfo() (m debug.Module) {
|
||||
const pkg = "entgo.io/ent"
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
m = info.Main
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// Was running as a CLI (ent/cmd/ent).
|
||||
if info.Main.Path == pkg {
|
||||
return info.Main
|
||||
}
|
||||
// Or, as a main package (ent/entc).
|
||||
for _, dep := range info.Deps {
|
||||
if dep.Path == pkg {
|
||||
return *dep
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user