From eda4eb3c94b2a346c545cca916ac7c07ede62202 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sun, 29 Sep 2019 03:11:03 +0100 Subject: [PATCH] fs/walk.ts: Don't traverse directories matching a skip pattern In other words, support path prefixes when specifying excludes. This aligns with the file matchers of the test runner and prettier. It's less redundant since this cannot be achieved efficiently on the client-end. --- fs/glob.ts | 8 ++------ fs/walk.ts | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) 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 {