* Compute the longest common directory prefix of all queued file paths. * e.g. ["/home/user/proj/src/a.ts", "/home/user/proj/lib/b.ts"] * → "/home/user/proj"
(paths: string[])
| 493 | * → "/home/user/proj" |
| 494 | */ |
| 495 | function computeCommonPrefix(paths: string[]): string { |
| 496 | if (paths.length === 0) return ''; |
| 497 | const dirs = paths.map(p => { |
| 498 | const norm = p.replace(/\\/g, '/'); |
| 499 | return norm.substring(0, norm.lastIndexOf('/')); |
| 500 | }); |
| 501 | const first = dirs[0].split('/'); |
| 502 | let common = first; |
| 503 | for (let i = 1; i < dirs.length; i++) { |
| 504 | const parts = dirs[i].split('/'); |
| 505 | const newCommon: string[] = []; |
| 506 | for (let j = 0; j < Math.min(common.length, parts.length); j++) { |
| 507 | if (common[j] === parts[j]) newCommon.push(common[j]); |
| 508 | else break; |
| 509 | } |
| 510 | common = newCommon; |
| 511 | } |
| 512 | return common.join('/'); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Lazily create (or return cached) Folder nodes for the repo-relative segments only. |
no test coverage detected