(paths: string[] | undefined)
| 262 | } |
| 263 | |
| 264 | function makePathFilter(paths: string[] | undefined): (p: string) => boolean { |
| 265 | if (paths === undefined || paths.length === 0) return () => true; |
| 266 | // Match either an exact path or a directory prefix. Globs are |
| 267 | // not supported on this surface; the docs call this out |
| 268 | // explicitly under the `diff` command reference. |
| 269 | const exact = new Set(paths.map((p) => normalizePath(p))); |
| 270 | const prefixes = [...exact].map((p) => `${p}/`); |
| 271 | return (candidate) => { |
| 272 | const c = normalizePath(candidate); |
| 273 | if (exact.has(c)) return true; |
| 274 | for (const prefix of prefixes) if (c.startsWith(prefix)) return true; |
| 275 | return false; |
| 276 | }; |
| 277 | } |
| 278 | |
| 279 | function normalizePath(p: string): string { |
| 280 | // Drop leading './' and trailing '/'. |
no test coverage detected