Skip to content

Commit 04172cc

Browse files
committed
Refactor: enhance glob exclude handling by separating directories and file/glob patterns
1 parent 3a7d897 commit 04172cc

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/fs/glob.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,26 @@ export function classifyExcludes(excludedPatterns: string[]) {
6464
* @return A promise that resolves to an array of file paths.
6565
*/
6666
export async function getFiles(args: Args, pattern: Patterns): Promise<string[]> {
67-
// 1. Create the Glob instance
67+
const { dirs, filePatterns } = classifyExcludes(pattern.exclude);
68+
6869
const g = new Glob(pattern.include, {
6970
ignore: {
70-
ignored: (p: Path) => ignoreFunc(p, pattern.exclude),
71+
// Prune entire directory subtrees — glob won't enter these dirs at all
72+
childrenIgnored: (p: Path) => dirs.some((d) => p.isNamed(d)),
73+
// Filter individual files by name or glob pattern
74+
ignored: (p: Path) =>
75+
filePatterns.some((fp) => {
76+
const type = detectPatternType(fp);
77+
if (type === "file") {
78+
return p.isNamed(fp);
79+
}
80+
return minimatch(p.relative(), fp);
81+
}),
7182
},
7283
nodir: true,
7384
cwd: args.paths.cwd,
7485
root: args.paths.root ? path.resolve(args.paths.root) : undefined,
7586
});
7687

77-
// 2. Return the walk() promise, which resolves to an array of all file paths
7888
return g.walk();
7989
}

0 commit comments

Comments
 (0)