1- import nativeFs from 'node:fs' ;
1+ import { readdir , readdirSync , realpath , realpathSync , stat , statSync } from 'node:fs' ;
22import { resolve } from 'node:path' ;
33import { fileURLToPath } from 'node:url' ;
44import { buildCrawler } from './crawler.ts' ;
5- import type { Crawler , FileSystemAdapter , GlobInput , GlobOptions , InternalOptions , RelativeMapper } from './types.ts' ;
5+ import type { Crawler , GlobInput , GlobOptions , InternalOptions , RelativeMapper } from './types.ts' ;
66import { BACKSLASHES , ensureStringArray , isReadonlyArray , log } from './utils.ts' ;
77
88function formatPaths ( paths : string [ ] , mapper ?: false | RelativeMapper ) {
@@ -14,17 +14,6 @@ function formatPaths(paths: string[], mapper?: false | RelativeMapper) {
1414 return paths ;
1515}
1616
17- const fsKeys = [ 'readdir' , 'readdirSync' , 'realpath' , 'realpathSync' , 'stat' , 'statSync' ] ;
18-
19- function normalizeFs ( fs ?: Record < string , unknown > ) : FileSystemAdapter | undefined {
20- if ( fs && fs !== nativeFs ) {
21- for ( const key of fsKeys ) {
22- fs [ key ] = ( fs [ key ] ? fs : ( nativeFs as Record < string , unknown > ) ) [ key ] ;
23- }
24- }
25- return fs ;
26- }
27-
2817// Object containing all default options to ensure there is no hidden state difference
2918// between false and undefined.
3019const defaultOptions : GlobOptions = {
@@ -42,7 +31,15 @@ function getOptions(options?: GlobOptions): InternalOptions {
4231 opts . cwd = ( opts . cwd instanceof URL ? fileURLToPath ( opts . cwd ) : resolve ( opts . cwd ) ) . replace ( BACKSLASHES , '/' ) ;
4332 // Default value of [] will be inserted here if ignore is undefined
4433 opts . ignore = ensureStringArray ( opts . ignore ) ;
45- opts . fs = normalizeFs ( opts . fs ) ;
34+
35+ opts . fs &&= {
36+ readdir : opts . fs . readdir || readdir ,
37+ readdirSync : opts . fs . readdirSync || readdirSync ,
38+ realpath : opts . fs . realpath || realpath ,
39+ realpathSync : opts . fs . realpathSync || realpathSync ,
40+ stat : opts . fs . stat || stat ,
41+ statSync : opts . fs . statSync || statSync
42+ } ;
4643
4744 if ( opts . debug ) {
4845 log ( 'globbing with options:' , opts ) ;
0 commit comments