checkFileImporters checks if a file is a hub and shows its importers
(root, filePath string)
| 1375 | |
| 1376 | // checkFileImporters checks if a file is a hub and shows its importers |
| 1377 | func checkFileImporters(root, filePath string) error { |
| 1378 | info := getHubInfoNoFallback(root) |
| 1379 | if info == nil { |
| 1380 | return nil // silently skip if deps unavailable |
| 1381 | } |
| 1382 | |
| 1383 | // Handle absolute paths - convert to relative |
| 1384 | if filepath.IsAbs(filePath) { |
| 1385 | if rel, err := filepath.Rel(root, filePath); err == nil { |
| 1386 | filePath = rel |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | importers := info.Importers[filePath] |
| 1391 | if len(importers) >= 3 { |
| 1392 | fmt.Println() |
| 1393 | fmt.Printf("⚠️ HUB FILE: %s\n", filePath) |
| 1394 | fmt.Printf(" Imported by %d files - changes have wide impact!\n", len(importers)) |
| 1395 | fmt.Println() |
| 1396 | fmt.Println(" Dependents:") |
| 1397 | for i, imp := range importers { |
| 1398 | if i >= 5 { |
| 1399 | fmt.Printf(" ... and %d more\n", len(importers)-5) |
| 1400 | break |
| 1401 | } |
| 1402 | fmt.Printf(" • %s\n", imp) |
| 1403 | } |
| 1404 | fmt.Println() |
| 1405 | } else if len(importers) > 0 { |
| 1406 | fmt.Println() |
| 1407 | fmt.Printf("📍 File: %s\n", filePath) |
| 1408 | fmt.Printf(" Imported by %d file(s): %s\n", len(importers), strings.Join(importers, ", ")) |
| 1409 | fmt.Println() |
| 1410 | } |
| 1411 | |
| 1412 | // Also check if this file imports any hubs |
| 1413 | imports := info.Imports[filePath] |
| 1414 | var hubImports []string |
| 1415 | for _, imp := range imports { |
| 1416 | if info.isHub(imp) { |
| 1417 | hubImports = append(hubImports, imp) |
| 1418 | } |
| 1419 | } |
| 1420 | if len(hubImports) > 0 { |
| 1421 | fmt.Printf(" Imports %d hub(s): %s\n", len(hubImports), strings.Join(hubImports, ", ")) |
| 1422 | fmt.Println() |
| 1423 | } |
| 1424 | |
| 1425 | return nil |
| 1426 | } |
| 1427 | |
| 1428 | // isHub checks if a file is a hub (has 3+ importers) |
| 1429 | func (h *hubInfo) isHub(path string) bool { |