* The roots the selector offers: the repository root plus every top-level * directory that holds indexed files, biggest first. * * A monorepo's answer to "which project am I looking at" — and on a single * project it is a one-line list nobody has to use.
(
files: ReadonlyArray<{ path: string; symbols: number }>
)
| 839 | * project it is a one-line list nobody has to use. |
| 840 | */ |
| 841 | function rootOptions( |
| 842 | files: ReadonlyArray<{ path: string; symbols: number }> |
| 843 | ): WireMapPayload['roots'] { |
| 844 | const byDir = new Map<string, number>(); |
| 845 | for (const file of files) { |
| 846 | const slash = file.path.indexOf('/'); |
| 847 | if (slash <= 0) continue; |
| 848 | const dir = file.path.slice(0, slash); |
| 849 | byDir.set(dir, (byDir.get(dir) ?? 0) + 1); |
| 850 | } |
| 851 | const dirs = [...byDir] |
| 852 | .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) |
| 853 | .map(([root, count]) => ({ root, label: root, files: count })); |
| 854 | return [{ root: '', label: 'whole repository', files: files.length }, ...dirs]; |
| 855 | } |