@@ -235,33 +235,50 @@ function getMarkdownList(
235
235
firstUsageLocation = null
236
236
) {
237
237
let result = "" ;
238
- const currentPath = parentPath
239
- ? `${ parentPath } -> ${ hierarchy . name } `
240
- : hierarchy . name ;
241
-
242
- // Only output leaf nodes (components that aren't used by other components)
243
- if ( ! hierarchy . usedIn || hierarchy . usedIn . length === 0 ) {
244
- const usageLocation = firstUsageLocation
245
- ? ` (${ path . relative ( process . cwd ( ) , firstUsageLocation . file ) } :${
246
- firstUsageLocation . line
247
- } )`
248
- : "" ;
249
- result += `- ${ currentPath } ${ usageLocation } \n` ;
250
- } else {
251
- // Continue traversing the tree
252
- hierarchy . usedIn . forEach ( ( child ) => {
253
- // If this is the root component (Link), look for where it's used in its child
254
- const nextLocation =
255
- ! parentPath &&
256
- hierarchy . locations ?. find ( ( loc ) => loc . file === child . definedIn ) ;
257
- result += getMarkdownList (
258
- child ,
259
- currentPath ,
260
- nextLocation || firstUsageLocation
261
- ) ;
238
+ const pathsByLocation = new Map ( ) ;
239
+ let totalPaths = 0 ; // Add counter for verification
240
+
241
+ function addPath ( path , location ) {
242
+ const locationKey = location
243
+ ? `${ location . file } :${ location . line } `
244
+ : "unknown" ;
245
+ if ( ! pathsByLocation . has ( locationKey ) ) {
246
+ pathsByLocation . set ( locationKey , [ ] ) ;
247
+ }
248
+ pathsByLocation . get ( locationKey ) . push ( path ) ;
249
+ totalPaths ++ ; // Increment counter
250
+ }
251
+
252
+ function processHierarchy ( node , currentPath , usageLocation ) {
253
+ const newPath = currentPath ? `${ currentPath } -> ${ node . name } ` : node . name ;
254
+
255
+ if ( ! node . usedIn || node . usedIn . length === 0 ) {
256
+ addPath ( newPath , usageLocation ) ;
257
+ } else {
258
+ node . usedIn . forEach ( ( child ) => {
259
+ const nextLocation =
260
+ ! currentPath &&
261
+ node . locations ?. find ( ( loc ) => loc . file === child . definedIn ) ;
262
+ processHierarchy ( child , newPath , nextLocation || usageLocation ) ;
263
+ } ) ;
264
+ }
265
+ }
266
+
267
+ processHierarchy ( hierarchy , parentPath , firstUsageLocation ) ;
268
+
269
+ // Format the output with grouped paths
270
+ for ( const [ location , paths ] of pathsByLocation ) {
271
+ result += `- Paths to ${ location } :\n` ;
272
+ paths . forEach ( ( path ) => {
273
+ result += ` • ${ path } \n` ;
262
274
} ) ;
263
275
}
264
276
277
+ // Add verification info
278
+ let groupedTotal = 0 ;
279
+ pathsByLocation . forEach ( ( paths ) => ( groupedTotal += paths . length ) ) ;
280
+ result += `\nVerification: Found ${ totalPaths } total paths, grouped into ${ pathsByLocation . size } locations (${ groupedTotal } total paths in groups)\n` ;
281
+
265
282
return result ;
266
283
}
267
284
0 commit comments