@@ -260,16 +260,9 @@ async function getFilesFromGitTree(dir, ig, options) {
260
260
/**
261
261
* Recursive helper function for 'preprocessNode'
262
262
*/
263
- async function getFilesFromFs ( dir , rootPath , ig , options ) {
263
+ async function getFilesFromFs ( dir , rootPath , ig , options , parent = [ ] ) {
264
264
const files = await fs . promises . readdir ( dir , { withFileTypes : true } )
265
- const filesAccumulator = [ ]
266
- // Closure to merge the next file depth into this one
267
- const recursiveMerge = async nextRoot => {
268
- Array . prototype . push . apply (
269
- filesAccumulator ,
270
- await getFilesFromFs ( nextRoot , rootPath , ig , options ) ,
271
- )
272
- }
265
+ const filesAccumulator = parent
273
266
for ( const file of files ) {
274
267
const fullPath = path . join ( dir , file . name )
275
268
const relativePath = harmonizeRelativePath (
@@ -286,7 +279,7 @@ async function getFilesFromFs(dir, rootPath, ig, options) {
286
279
}
287
280
// Three cases to consider: directories, files, symlinks
288
281
if ( file . isDirectory ( ) ) {
289
- await recursiveMerge ( fullPath )
282
+ await getFilesFromFs ( fullPath , rootPath , ig , options , filesAccumulator )
290
283
} else if ( file . isSymbolicLink ( ) ) {
291
284
// Allow skipping symbolic links which lead to recursion
292
285
// Disabling this is a big performance advantage on high latency
@@ -297,7 +290,13 @@ async function getFilesFromFs(dir, rootPath, ig, options) {
297
290
const targetStat = await fs . promises . stat ( targetPath )
298
291
// Either add or recurse from the target depending
299
292
if ( targetStat . isDirectory ( ) ) {
300
- await recursiveMerge ( targetPath )
293
+ await getFilesFromFs (
294
+ targetPath ,
295
+ rootPath ,
296
+ ig ,
297
+ options ,
298
+ filesAccumulator ,
299
+ )
301
300
} else {
302
301
filesAccumulator . push ( fileObj )
303
302
}
0 commit comments