( sortedPaths: string[], want: number, )
| 54 | * Returns empty array if fewer than `want` core files are available. |
| 55 | */ |
| 56 | export function pickDiverseCoreFiles( |
| 57 | sortedPaths: string[], |
| 58 | want: number, |
| 59 | ): string[] { |
| 60 | const picked: string[] = [] |
| 61 | const seenBasenames = new Set<string>() |
| 62 | const dirTally = new Map<string, number>() |
| 63 | |
| 64 | // Greedy: on each pass allow +1 file per directory. Keeps the |
| 65 | // top-5 from collapsing into a single hot folder while still |
| 66 | // letting a dominant folder contribute multiple files if the |
| 67 | // repo is narrow. |
| 68 | for (let cap = 1; picked.length < want && cap <= want; cap++) { |
| 69 | for (const p of sortedPaths) { |
| 70 | if (picked.length >= want) break |
| 71 | if (!isCoreFile(p)) continue |
| 72 | const lastSep = Math.max(p.lastIndexOf('/'), p.lastIndexOf('\\')) |
| 73 | const base = lastSep >= 0 ? p.slice(lastSep + 1) : p |
| 74 | if (!base || seenBasenames.has(base)) continue |
| 75 | const dir = lastSep >= 0 ? p.slice(0, lastSep) : '.' |
| 76 | if ((dirTally.get(dir) ?? 0) >= cap) continue |
| 77 | picked.push(base) |
| 78 | seenBasenames.add(base) |
| 79 | dirTally.set(dir, (dirTally.get(dir) ?? 0) + 1) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return picked.length >= want ? picked : [] |
| 84 | } |
| 85 | |
| 86 | async function getFrequentlyModifiedFiles(): Promise<string[]> { |
| 87 | if (process.env.NODE_ENV === 'test') return [] |
no test coverage detected