@@ -2,8 +2,9 @@ import { promises as fsPromises, readFileSync, statSync } from 'fs';
22import { createRequire } from 'module' ;
33import { extname , join } from 'path' ;
44import { cwd } from 'process' ;
5- import globby , { GlobbyOptions , sync as globbySync } from 'globby ' ;
5+ import { fileURLToPath } from 'url ' ;
66import { DocumentNode , parse } from 'graphql' ;
7+ import { GlobOptions , globSync , glob as tinyglobby } from 'tinyglobby' ;
78import unixify from 'unixify' ;
89
910const { readFile, stat } = fsPromises ;
@@ -63,8 +64,8 @@ async function isDirectory(path: string) {
6364 }
6465}
6566
66- function scanForFilesSync ( globStr : string | string [ ] , globOptions : GlobbyOptions = { } ) : string [ ] {
67- return globbySync ( globStr , { absolute : true , ...globOptions } ) ;
67+ function scanForFilesSync ( globStr : string | string [ ] , globOptions : GlobOptions = { } ) : string [ ] {
68+ return globSync ( globStr , { absolute : true , ...globOptions } ) ;
6869}
6970
7071function formatExtension ( extension : string ) : string {
@@ -98,8 +99,8 @@ export interface LoadFilesOptions {
9899 useRequire ?: boolean ;
99100 // An alternative to `require` to use if `require` would be used to load a file
100101 requireMethod ?: any ;
101- // Additional options to pass to globby
102- globOptions ?: GlobbyOptions ;
102+ // Additional options to pass to tinyglobby
103+ globOptions ?: GlobOptions ;
103104 // Named exports to extract from each file. Defaults to ['typeDefs', 'schema']
104105 exportNames ?: string [ ] ;
105106 // Load files from nested directories. Set to `false` to only search the top-level directory.
@@ -148,10 +149,12 @@ export function loadFilesSync<T = any>(
148149 options . globOptions ,
149150 ) ;
150151
152+ const cwd = options ?. globOptions ?. cwd ;
153+ const normalizedCwd = cwd instanceof URL ? fileURLToPath ( cwd ) : cwd ;
151154 const extractExports =
152155 execOptions . extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY ( execOptions . exportNames ?? [ ] ) ;
153156 const requireMethod =
154- execOptions . requireMethod || createRequire ( join ( options ?. globOptions ?. cwd || cwd ( ) , 'noop.js' ) ) ;
157+ execOptions . requireMethod || createRequire ( join ( normalizedCwd || cwd ( ) , 'noop.js' ) ) ;
155158
156159 return relevantPaths
157160 . map ( path => {
@@ -183,9 +186,9 @@ export function loadFilesSync<T = any>(
183186
184187async function scanForFiles (
185188 globStr : string | string [ ] ,
186- globOptions : GlobbyOptions = { } ,
189+ globOptions : GlobOptions = { } ,
187190) : Promise < string [ ] > {
188- return globby ( globStr , { absolute : true , ...globOptions } ) ;
191+ return tinyglobby ( globStr , { absolute : true , ...globOptions } ) ;
189192}
190193
191194const checkExtension = (
@@ -248,12 +251,14 @@ export async function loadFiles(
248251 options . globOptions ,
249252 ) ;
250253
254+ const cwd = options ?. globOptions ?. cwd ;
255+ const normalizedCwd = cwd instanceof URL ? fileURLToPath ( cwd ) : cwd ;
251256 const extractExports =
252257 execOptions . extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY ( execOptions . exportNames ?? [ ] ) ;
253258 const defaultRequireMethod = ( path : string ) =>
254259 import ( path )
255260 . catch ( importError => {
256- const cwdRequire = createRequire ( join ( options ?. globOptions ?. cwd || cwd ( ) , 'noop.js' ) ) ;
261+ const cwdRequire = createRequire ( join ( normalizedCwd || cwd ( ) , 'noop.js' ) ) ;
257262 try {
258263 return cwdRequire ( path ) ;
259264 } catch ( e ) {
0 commit comments