@@ -54,7 +54,7 @@ var purposeMap = map[string]string{
5454 "lib" : "Shared library code" ,
5555 "utils" : "Utility functions" ,
5656 "services" : "Business logic services" ,
57- "middleware" : "HTTP middleware" ,
57+ "middleware" : "HTTP middleware" ,
5858 "cli" : "Command-line interface" ,
5959 "schema" : "Data schema definitions" ,
6060 "renderer" : "Output renderers" ,
@@ -108,6 +108,46 @@ func generateAddFeatureHint(modules map[string]schema.ModuleInfo, entrypoints []
108108 return ""
109109}
110110
111+ func filterRetainedModules (names []string , retained map [string ]bool ) []string {
112+ if len (names ) == 0 {
113+ return nil
114+ }
115+ out := make ([]string , 0 , len (names ))
116+ for _ , name := range names {
117+ if retained [name ] {
118+ out = append (out , name )
119+ }
120+ }
121+ return out
122+ }
123+
124+ func rankMostDepended (modules map [string ]schema.ModuleInfo ) []string {
125+ names := make ([]string , 0 , len (modules ))
126+ for name := range modules {
127+ names = append (names , name )
128+ }
129+ sort .SliceStable (names , func (i , j int ) bool {
130+ ci := len (modules [names [i ]].DependedBy )
131+ cj := len (modules [names [j ]].DependedBy )
132+ if ci != cj {
133+ return ci > cj
134+ }
135+ return names [i ] < names [j ]
136+ })
137+ return names
138+ }
139+
140+ func findIsolatedModules (modules map [string ]schema.ModuleInfo ) []string {
141+ var isolated []string
142+ for name , mod := range modules {
143+ if len (mod .DependsOn ) == 0 && len (mod .DependedBy ) == 0 {
144+ isolated = append (isolated , name )
145+ }
146+ }
147+ sort .Strings (isolated )
148+ return isolated
149+ }
150+
111151// detectDoNotTouch returns paths that should generally not be modified by hand.
112152func detectDoNotTouch (root string ) []string {
113153 candidates := []string {"migrations" , "vendor" , "generated" , "proto" , ".github" }
@@ -439,6 +479,14 @@ func assembleIndex(
439479 allMods = allMods [:maxModules ]
440480 }
441481
482+ retainedModules := make (map [string ]bool , len (allMods ))
483+ for _ , mod := range allMods {
484+ if strings .HasPrefix (mod .Name , "testdata" ) {
485+ continue
486+ }
487+ retainedModules [mod .Name ] = true
488+ }
489+
442490 modules := map [string ]schema.ModuleInfo {}
443491 for _ , mod := range allMods {
444492 if strings .HasPrefix (mod .Name , "testdata" ) {
@@ -491,8 +539,8 @@ func assembleIndex(
491539 FileList : fileList ,
492540 Exports : exports ,
493541 TypeDefs : typeDefs ,
494- DependsOn : mod .DependsOn ,
495- DependedBy : mod .DependedBy ,
542+ DependsOn : filterRetainedModules ( mod .DependsOn , retainedModules ) ,
543+ DependedBy : filterRetainedModules ( mod .DependedBy , retainedModules ) ,
496544 Activity : activityLevel ,
497545 }
498546 }
@@ -504,14 +552,17 @@ func assembleIndex(
504552 if strings .HasPrefix (e .From , "testdata" ) || strings .HasPrefix (e .To , "testdata" ) {
505553 continue
506554 }
555+ if ! retainedModules [e .From ] || ! retainedModules [e .To ] {
556+ continue
557+ }
507558 schemaEdges = append (schemaEdges , [2 ]string {e .From , e .To })
508559 }
509- mostDepended := g . MostDepended ( )
560+ mostDepended := rankMostDepended ( modules )
510561 // Cap most-depended list.
511562 if len (mostDepended ) > 10 {
512563 mostDepended = mostDepended [:10 ]
513564 }
514- isolated := g . Isolated ( )
565+ isolated := findIsolatedModules ( modules )
515566
516567 // --- Git ---
517568 hotFiles := make ([]schema.HotFile , len (activity .HotFiles ))
0 commit comments