11import { readFileSync } from 'node:fs' ;
2- import { promisify } from 'node:util' ;
3- import { walk as _walk , type Entry } from '@nodelib/fs.walk' ;
2+ import { fdir } from 'fdir' ;
43import { glob as tinyGlob , type GlobOptions as TinyGlobOptions } from 'tinyglobby' ;
54import picomatch from 'picomatch' ;
65import { GLOBAL_IGNORE_PATTERNS } from '../constants.ts' ;
@@ -9,9 +8,7 @@ import { debugLogObject } from './debug.ts';
98import { isDirectory , isFile } from './fs.ts' ;
109import { timerify } from './Performance.ts' ;
1110import { expandIgnorePatterns , parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.ts' ;
12- import { dirname , join , relative , toPosix } from './path.ts' ;
13-
14- const walk = promisify ( _walk ) ;
11+ import { basename , dirname , join , relative , toPosix } from './path.ts' ;
1512
1613type Options = { gitignore : boolean ; cwd : string } ;
1714
@@ -170,22 +167,23 @@ export const findAndParseGitignores = async (cwd: string, workspaceDirs?: Set<st
170167 }
171168 }
172169
173- const entryFilter = ( entry : Entry ) => {
174- if ( entry . dirent . isFile ( ) && entry . name === '.gitignore' ) {
175- addFile ( entry . path ) ;
176- return true ;
177- }
178- return false ;
170+ const walkGitignores = async ( ) => {
171+ await new fdir ( )
172+ . withFullPaths ( )
173+ . exclude ( ( _dirName : string , dirPath : string ) => {
174+ const absPath = toPosix ( dirPath . endsWith ( '/' ) ? dirPath . slice ( 0 , - 1 ) : dirPath ) ;
175+ return ( isRelevantDir && ! isRelevantDir ( absPath ) ) || getMatcher ( ) ( relative ( cwd , absPath ) ) ;
176+ } )
177+ . filter ( ( filePath : string , isDir : boolean ) => {
178+ if ( isDir || basename ( filePath ) !== '.gitignore' ) return false ;
179+ addFile ( filePath ) ;
180+ return true ;
181+ } )
182+ . crawl ( cwd )
183+ . withPromise ( ) ;
179184 } ;
180185
181- const deepFilter = ( entry : Entry ) =>
182- ( ! isRelevantDir || isRelevantDir ( toPosix ( entry . path ) ) ) && ! getMatcher ( ) ( relative ( cwd , entry . path ) ) ;
183-
184- await walk ( cwd , {
185- concurrency : 16 ,
186- entryFilter,
187- deepFilter,
188- } ) ;
186+ await timerify ( walkGitignores ) ( ) ;
189187
190188 // tinyglobby's `ignore` can't express unignores (see tinyglobby/fast-glob #86). Drop cached
191189 // ignore patterns shadowed by any unignore path (and its ancestor dirs) so glob() sees a
0 commit comments