1
1
import globby , { sync as globbySync , GlobbyOptions } from 'globby' ;
2
2
import unixify from 'unixify' ;
3
- import { extname } from 'path' ;
3
+ import { extname , join } from 'path' ;
4
4
import { statSync , readFileSync , promises as fsPromises } from 'fs' ;
5
5
import { DocumentNode , parse } from 'graphql' ;
6
+ import { createRequire } from 'module' ;
7
+ import { cwd } from 'process' ;
6
8
7
9
const { readFile, stat } = fsPromises ;
8
10
@@ -113,6 +115,7 @@ const LoadFilesDefaultOptions: LoadFilesOptions = {
113
115
requireMethod : null ,
114
116
globOptions : {
115
117
absolute : true ,
118
+ cwd : cwd ( ) ,
116
119
} ,
117
120
exportNames : DEFAULT_EXPORT_NAMES ,
118
121
recursive : true ,
@@ -139,7 +142,7 @@ export function loadFilesSync<T = any>(
139
142
) ;
140
143
141
144
const extractExports = execOptions . extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY ( execOptions . exportNames ?? [ ] ) ;
142
- const requireMethod = execOptions . requireMethod || require ;
145
+ const requireMethod = execOptions . requireMethod || createRequire ( join ( options ?. globOptions ?. cwd || cwd ( ) , 'noop.js' ) ) ;
143
146
144
147
return relevantPaths
145
148
. map ( path => {
@@ -225,7 +228,15 @@ export async function loadFiles(
225
228
) ;
226
229
227
230
const extractExports = execOptions . extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY ( execOptions . exportNames ?? [ ] ) ;
228
- const defaultRequireMethod = ( path : string ) => import ( path ) . catch ( async ( ) => require ( path ) ) ;
231
+ const defaultRequireMethod = ( path : string ) =>
232
+ import ( path ) . catch ( importError => {
233
+ const cwdRequire = createRequire ( join ( options ?. globOptions ?. cwd || cwd ( ) , 'noop.js' ) ) ;
234
+ try {
235
+ return cwdRequire ( path ) ;
236
+ } catch ( e ) {
237
+ throw importError ;
238
+ }
239
+ } ) ;
229
240
const requireMethod = execOptions . requireMethod || defaultRequireMethod ;
230
241
231
242
return Promise . all (
1 commit comments
vercel[bot] commentedon Dec 17, 2021
Successfully deployed to the following URLs: