diff --git a/fs/glob.ts b/fs/glob.ts index 921c9b565b79..b4f060e7d425 100644 --- a/fs/glob.ts +++ b/fs/glob.ts @@ -109,9 +109,7 @@ export async function* expandGlob( const globOptions: GlobOptions = { extended, globstar, strict }; yield* walk(root, { match: [globToRegExp(absGlob, globOptions)], - skip: absExclude.map( - (s: string): RegExp => globToRegExp(s, { ...globOptions, flags: "g" }) - ), + skip: absExclude.map((s: string): RegExp => globToRegExp(s, globOptions)), includeDirs }); } @@ -136,9 +134,7 @@ export function* expandGlobSync( const globOptions: GlobOptions = { extended, globstar, strict }; yield* walkSync(root, { match: [globToRegExp(absGlob, globOptions)], - skip: absExclude.map( - (s: string): RegExp => globToRegExp(s, { ...globOptions, flags: "g" }) - ), + skip: absExclude.map((s: string): RegExp => globToRegExp(s, globOptions)), includeDirs }); } diff --git a/fs/walk.ts b/fs/walk.ts index d986ef47f5a4..c60230b33c34 100644 --- a/fs/walk.ts +++ b/fs/walk.ts @@ -75,6 +75,8 @@ export async function* walk( if (options.includeDirs && include(root, options)) { const rootInfo = await stat(root); yield { filename: root, info: rootInfo }; + } else if (patternTest(options.skip || [], root)) { + return; } let ls: FileInfo[] = []; try { @@ -117,6 +119,8 @@ export function* walkSync( if (options.includeDirs && include(root, options)) { const rootInfo = statSync(root); yield { filename: root, info: rootInfo }; + } else if (patternTest(options.skip || [], root)) { + return; } let ls: FileInfo[] = []; try {