* Minimatch-lite: convert a simple glob to a regex. * Supports *, **, ?, and {a,b} brace expansion (one level). * Not a full glob engine -- covers the patterns used in placement rules.
(glob)
| 61 | * Not a full glob engine -- covers the patterns used in placement rules. |
| 62 | */ |
| 63 | function globToRegex(glob) { |
| 64 | // Expand braces: *.{ts,tsx} -> (.*\.ts|.*\.tsx) |
| 65 | const braceMatch = glob.match(/^(.*)\{([^}]+)\}(.*)$/); |
| 66 | if (braceMatch) { |
| 67 | const [, prefix, options, suffix] = braceMatch; |
| 68 | const alts = options.split(',').map(opt => globToRegex(prefix + opt + suffix).source); |
| 69 | return new RegExp('^(' + alts.join('|') + ')$'); |
| 70 | } |
| 71 | |
| 72 | let re = glob |
| 73 | .replace(/\./g, '\\.') |
| 74 | .replace(/\*\*/g, '__DOUBLESTAR__') |
| 75 | .replace(/\*/g, '[^/]*') |
| 76 | .replace(/__DOUBLESTAR__/g, '.*') |
| 77 | .replace(/\?/g, '[^/]'); |
| 78 | |
| 79 | return new RegExp('^' + re + '$'); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Check if a file path is under a given root directory. |
no outgoing calls
no test coverage detected