* Files that do something on the way down, most first. * * Over-fetched before filtering, because the two things that shrink the list — * tests and the per-directory cap — are only knowable after the rows come back, * and a project whose noisiest module-level callers are all test files would *
(cg: CodeGraph, limit: number)
| 241 | * otherwise answer with an empty list. |
| 242 | */ |
| 243 | function executableFiles(cg: CodeGraph, limit: number): WireList<WireEntryFile> { |
| 244 | const ranked = withoutPreviews(cg, cg.getTopCallingFiles(SCAN_ROWS)); |
| 245 | |
| 246 | const kept: Array<{ node: Node; calls: number; reaches: number }> = []; |
| 247 | const perDir = new Map<string, number>(); |
| 248 | let eligible = 0; |
| 249 | |
| 250 | for (const row of ranked) { |
| 251 | if (isTestFile(row.filePath)) continue; |
| 252 | eligible += 1; |
| 253 | if (kept.length >= limit) continue; |
| 254 | const dir = directoryOf(row.filePath); |
| 255 | const taken = perDir.get(dir) ?? 0; |
| 256 | if (taken >= MAX_FILES_PER_DIR) continue; |
| 257 | const node = cg.getNode(row.nodeId); |
| 258 | if (!node) continue; |
| 259 | perDir.set(dir, taken + 1); |
| 260 | kept.push({ node, calls: row.calls, reaches: row.reaches }); |
| 261 | } |
| 262 | |
| 263 | const dependents = cg.getFileDependentCounts(kept.map((k) => k.node.filePath)); |
| 264 | const items: WireEntryFile[] = kept.map(({ node, calls, reaches }) => ({ |
| 265 | ...toNodeRef(node), |
| 266 | calls, |
| 267 | reaches, |
| 268 | dependents: dependents.get(node.filePath) ?? 0, |
| 269 | })); |
| 270 | |
| 271 | // `eligible` counts every non-test file the scan saw: a floor, never an |
| 272 | // overstatement. |
| 273 | return wireList(items, Math.max(eligible, items.length)); |
| 274 | } |
| 275 | |
| 276 | /** A Swift file read for its `#Preview` blocks, at most. */ |
| 277 | const MAX_PREVIEW_SCAN = 1024 * 1024; |
no test coverage detected