(
files: ReadonlyArray<{ path: string; symbols: number; test: boolean }>,
root: string,
passThrough?: ReadonlySet<string>
)
| 443 | * draw exactly the picture this function exists to avoid. |
| 444 | */ |
| 445 | export function pickDefaultDepth( |
| 446 | files: ReadonlyArray<{ path: string; symbols: number; test: boolean }>, |
| 447 | root: string, |
| 448 | passThrough?: ReadonlySet<string> |
| 449 | ): number { |
| 450 | // Past the deepest directory, a bigger number only renames boxes to |
| 451 | // `src/a/(root files)`. There is nothing below the leaves. |
| 452 | let deepest = DEFAULT_DEPTH; |
| 453 | for (const file of files) { |
| 454 | if (file.test) continue; |
| 455 | const path = toPosixPath(file.path); |
| 456 | if (root && !path.startsWith(`${root}/`)) continue; |
| 457 | const rel = root ? path.slice(root.length + 1) : path; |
| 458 | const dirs = rel.split('/').filter(Boolean).slice(0, -1); |
| 459 | deepest = Math.max(deepest, levelEnds(root, dirs, passThrough).length); |
| 460 | } |
| 461 | |
| 462 | let fallback = DEFAULT_DEPTH; |
| 463 | let fallbackCount = 0; |
| 464 | for (let depth = DEFAULT_DEPTH; depth <= Math.min(MAX_DEPTH, deepest); depth += 1) { |
| 465 | const tally = tallyModules(files, root, depth, passThrough); |
| 466 | if (tally.count === 0) break; |
| 467 | // Deeper only gets more crowded from here. |
| 468 | if (tally.count > MAX_MODULES) break; |
| 469 | const dominated = tally.share > DOMINANT_SHARE && tally.largestFiles >= DOMINANT_MIN_FILES; |
| 470 | if (tally.count >= MIN_MODULES && !dominated) return depth; |
| 471 | // Not a picture yet. Worth keeping only if it drew more than the last one: |
| 472 | // a deeper grouping that splits nothing is the same map with longer labels. |
| 473 | if (tally.count > fallbackCount) { |
| 474 | fallback = depth; |
| 475 | fallbackCount = tally.count; |
| 476 | } |
| 477 | } |
| 478 | return fallback; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * The root and depth the map opens on when the reader named neither. |
no test coverage detected