diff options
Diffstat (limited to 'fs/walk.ts')
| -rw-r--r-- | fs/walk.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/fs/walk.ts b/fs/walk.ts index 10393ae0b..f2a9b6c57 100644 --- a/fs/walk.ts +++ b/fs/walk.ts @@ -95,15 +95,26 @@ function include(f: FileInfo, options: WalkOptions): Boolean { if (options.exts && !options.exts.some(ext => f.path.endsWith(ext))) { return false; } - if (options.match && !options.match.some(pattern => pattern.test(f.path))) { + if (options.match && !patternTest(options.match, f.path)) { return false; } - if (options.skip && options.skip.some(pattern => pattern.test(f.path))) { + if (options.skip && patternTest(options.skip, f.path)) { return false; } return true; } +function patternTest(patterns: RegExp[], path: string) { + // Forced to reset last index on regex while iterating for have + // consistent results. + // See: https://stackoverflow.com/a/1520853 + return patterns.some(pattern => { + let r = pattern.test(path); + pattern.lastIndex = 0; + return r; + }); +} + async function resolve(f: FileInfo): Promise<FileInfo> { // This is the full path, unfortunately if we were to make it relative // it could resolve to a symlink and cause an infinite loop. |
