* 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[])
| 616 | * → "/home/user/proj" |
| 617 | */ |
| 618 | function computeCommonPrefix(paths: string[]): string { |
| 619 | if (paths.length === 0) return ''; |
| 620 | const dirs = paths.map(p => { |
| 621 | const norm = p.replace(/\\/g, '/'); |
| 622 | return norm.substring(0, norm.lastIndexOf('/')); |
| 623 | }); |
| 624 | const first = dirs[0].split('/'); |
| 625 | let common = first; |
| 626 | for (let i = 1; i < dirs.length; i++) { |
| 627 | const parts = dirs[i].split('/'); |
| 628 | const newCommon: string[] = []; |
| 629 | for (let j = 0; j < Math.min(common.length, parts.length); j++) { |
| 630 | if (common[j] === parts[j]) newCommon.push(common[j]); |
| 631 | else break; |
| 632 | } |
| 633 | common = newCommon; |
| 634 | } |
| 635 | return common.join('/'); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Lazily create (or return cached) Folder nodes for the repo-relative segments only. |
no test coverage detected