@@ -18,8 +18,8 @@ interface DiscoverFmtPathsOptions {
1818 patterns ?: string [ ] ;
1919 /** Whether files inside node_modules may be discovered. */
2020 withNodeModules ?: boolean ;
21- /** Returns whether a scanned directory can be pruned before traversal. */
22- isDirectoryIgnored ?: ( directoryPath : string ) => boolean ;
21+ /** Returns whether a scanned path can be excluded during traversal. */
22+ isIgnored ?: ( filePath : string , isDirectory : boolean ) => boolean ;
2323}
2424
2525const isErrnoException = ( error : unknown ) : error is NodeJS . ErrnoException =>
@@ -209,7 +209,7 @@ const createTraversalOptions = (
209209 gitIgnore : GitIgnoreMatcher ,
210210 ignoredDirNames : ReadonlySet < string > ,
211211 isIncluded ?: ( filePath : string ) => boolean ,
212- isDirectoryIgnored ?: ( directoryPath : string ) => boolean ,
212+ isIgnored ?: ( filePath : string , isDirectory : boolean ) => boolean ,
213213) => {
214214 return {
215215 followSymlinks : false ,
@@ -221,12 +221,16 @@ const createTraversalOptions = (
221221 }
222222
223223 if ( dirent . isDirectory ( ) ) {
224- return gitIgnore . isIgnored ( targetPath , true ) || isDirectoryIgnored ?.( targetPath ) === true ;
224+ return gitIgnore . isIgnored ( targetPath , true ) || isIgnored ?.( targetPath , true ) === true ;
225+ }
226+
227+ if ( isIncluded !== undefined && ! isIncluded ( targetPath ) ) {
228+ return true ;
225229 }
226230
227231 return (
232+ isIgnored ?.( targetPath , false ) === true ||
228233 isBinaryPath ( targetPath ) ||
229- ( isIncluded !== undefined && ! isIncluded ( targetPath ) ) ||
230234 gitIgnore . isIgnored ( targetPath , false )
231235 ) ;
232236 } ,
@@ -352,7 +356,7 @@ const discoverFmtPaths = async ({
352356 cwd,
353357 patterns : inputPatterns ,
354358 withNodeModules = false ,
355- isDirectoryIgnored ,
359+ isIgnored ,
356360} : DiscoverFmtPathsOptions ) : Promise < string [ ] > => {
357361 const patterns = inputPatterns ?. length ? inputPatterns : [ '.' ] ;
358362 const resolveRelativePath = createRelativePathResolver ( cwd ) ;
@@ -385,7 +389,7 @@ const discoverFmtPaths = async ({
385389 }
386390
387391 await gitIgnore . loadThrough ( rootPath ) ;
388- if ( gitIgnore . isIgnored ( rootPath , true ) || isDirectoryIgnored ?.( rootPath ) === true ) {
392+ if ( gitIgnore . isIgnored ( rootPath , true ) || isIgnored ?.( rootPath , true ) === true ) {
389393 return [ ] ;
390394 }
391395
@@ -406,7 +410,7 @@ const discoverFmtPaths = async ({
406410 return (
407411 await readdir (
408412 rootPath ,
409- createTraversalOptions ( gitIgnore , ignoredDirNames , isIncluded , isDirectoryIgnored ) ,
413+ createTraversalOptions ( gitIgnore , ignoredDirNames , isIncluded , isIgnored ) ,
410414 )
411415 ) . files ;
412416 } ) ,
0 commit comments