* The static directory prefix of each `include` pattern — the literal leading * path up to the first glob segment — trailing-slashed, used to (a) walk only * the opted-in subtrees in `collectIncludedFiles` and (b) let `ScopeIgnore` keep * the watcher descending toward them. `Tools/` stays `Tools/
(patterns: string[])
| 732 | * nested under a broader root are collapsed so each subtree is walked once. |
| 733 | */ |
| 734 | function includeStaticRoots(patterns: string[]): string[] { |
| 735 | const roots = new Set<string>(); |
| 736 | for (const pattern of patterns) { |
| 737 | let p = pattern.replace(/^\/+/, ''); |
| 738 | const trailingSlash = p.endsWith('/'); |
| 739 | if (trailingSlash) p = p.slice(0, -1); |
| 740 | const segs = p.split('/').filter(Boolean); |
| 741 | const lead: string[] = []; |
| 742 | for (const s of segs) { |
| 743 | if (GLOB_META.test(s)) break; |
| 744 | lead.push(s); |
| 745 | } |
| 746 | const hadWildcard = lead.length < segs.length; |
| 747 | // A wholly-literal pattern with no trailing slash names a file (or a dir we |
| 748 | // can't tell apart) — drop its last segment so we walk the containing dir |
| 749 | // and let the matcher pick the file. A trailing slash or a glob means the |
| 750 | // remaining `lead` is already the directory to walk. |
| 751 | if (!hadWildcard && !trailingSlash && lead.length > 0) lead.pop(); |
| 752 | if (lead.length === 0) { |
| 753 | roots.clear(); |
| 754 | roots.add(''); |
| 755 | return ['']; // a top-level glob forces a whole-tree walk; nothing narrower matters |
| 756 | } |
| 757 | roots.add(lead.join('/') + '/'); |
| 758 | } |
| 759 | // Collapse roots nested under a broader one (e.g. drop `a/b/` if `a/` is present). |
| 760 | const all = [...roots]; |
| 761 | return all.filter((r) => !all.some((other) => other !== r && r.startsWith(other))); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * A folder's real path, for the include walk's cycle guard. The OS's realpath |
no test coverage detected