* Match a file path against a glob pattern. * * Supports: * - Exact path match * - dir/* — files directly in a directory (single level) * - dir/ — all files under a directory prefix (trailing slash) * - src/** — recursive glob (any depth under src/) * - **\/*.ts — any .ts file at
(filePath, pattern)
| 329 | * - dir/* — files directly in a directory (single level) |
| 330 | * - dir/ — all files under a directory prefix (trailing slash) |
| 331 | * - src/** — recursive glob (any depth under src/) |
| 332 | * - **\/*.ts — any .ts file at any depth |
| 333 | * |
| 334 | * @param {string} filePath - Relative file path, forward-slash separated |
| 335 | * @param {string} pattern - Glob pattern to match against |
| 336 | * @returns {boolean} |
| 337 | */ |
| 338 | function matchPattern(filePath, pattern) { |
| 339 | // Exact match |
| 340 | if (filePath === pattern) return true; |
| 341 | |
| 342 | // Recursive glob: pattern contains ** |
| 343 | if (pattern.includes('**')) { |
| 344 | return matchGlobStar(filePath, pattern); |
| 345 | } |
| 346 | |
| 347 | // Single-level wildcard: pattern ends with /* |
| 348 | if (pattern.endsWith('/*')) { |
| 349 | const dir = pattern.slice(0, -2); |
| 350 | return filePath.startsWith(dir + '/') && !filePath.slice(dir.length + 1).includes('/'); |
| 351 | } |
| 352 | |
| 353 | // Directory prefix: pattern ends with / |
| 354 | if (pattern.endsWith('/')) { |
| 355 | return filePath.startsWith(pattern); |
no test coverage detected