Skip to content

Commit

Permalink
Fix: possible stack size limit issues when globbing many files (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Oct 21, 2023
1 parent 0456459 commit 1837a00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ gracefulFs.gracefulify(realFs);
await ProgressBarCLI.stop();
} catch (error) {
await ProgressBarCLI.stop();
logger.error(error);
if (error instanceof Error && error.stack) {
logger.error(error.stack);
} else {
logger.error(error);
}
logger.newLine();
process.exit(1);
}
Expand Down
8 changes: 6 additions & 2 deletions src/polyfill/fsPoly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,18 @@ export default class FsPoly {
return [];
}

if (callback) callback(files.length);
if (callback) {
callback(files.length);
}

for (const file of files) {
const fullPath = path.join(pathLike.toString(), file);
if (await this.isDirectory(fullPath)) {
const subDirFiles = await this.walk(fullPath);
output.push(...subDirFiles);
if (callback) callback(subDirFiles.length - 1);
if (callback) {
callback(subDirFiles.length - 1);
}
} else {
output.push(fullPath);
}
Expand Down
9 changes: 6 additions & 3 deletions src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,16 @@ export default class Options implements OptionsProps {
const uniqueGlobPatterns = globPatterns
.filter((pattern) => pattern)
.reduce(ArrayPoly.reduceUnique(), []);
const globbedPaths = [];
let globbedPaths: string[] = [];
for (const uniqueGlobPattern of uniqueGlobPatterns) {
globbedPaths.push(...(await this.globPath(
const paths = await this.globPath(
uniqueGlobPattern,
requireFiles,
walkCallback ?? ((): void => {}),
)));
);
// NOTE(cemmer): if `paths` is really large, `globbedPaths.push(...paths)` can hit a stack
// size limit
globbedPaths = [...globbedPaths, ...paths];
}

// Filter to non-directories
Expand Down

0 comments on commit 1837a00

Please sign in to comment.