fix(providence): [optimised-glob] use Array.concat for memory efficiency
This commit is contained in:
parent
a1d6dd90a8
commit
0f0991cd62
2 changed files with 17 additions and 7 deletions
5
.changeset/selfish-wasps-switch.md
Normal file
5
.changeset/selfish-wasps-switch.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'providence-analytics': patch
|
||||
---
|
||||
|
||||
[optimised-glob] use Array.concat for memory efficiency
|
||||
|
|
@ -253,12 +253,16 @@ const getAllDirentsFromStartPath = memoize(
|
|||
return dirents;
|
||||
}
|
||||
|
||||
dirents.push(
|
||||
// @ts-expect-error
|
||||
...(await fs.promises.readdir(startPath, { withFileTypes: true, recursive: true })),
|
||||
const direntResult = /** @type {* & DirentWithPath[]} */ (
|
||||
await fs.promises.readdir(startPath, {
|
||||
withFileTypes: true,
|
||||
// @ts-expect-error
|
||||
recursive: true,
|
||||
})
|
||||
);
|
||||
cache[startPath] = dirents;
|
||||
return dirents;
|
||||
|
||||
cache[startPath] = direntResult;
|
||||
return direntResult;
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -401,7 +405,7 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) {
|
|||
/** @type {RegExp[]} */
|
||||
const matchRegexes = [];
|
||||
/** @type {{dirent:nodeFs.Dirent;relativeToCwdPath:string}[]} */
|
||||
const globEntries = [];
|
||||
let globEntries = [];
|
||||
|
||||
for (const glob of globs) {
|
||||
const isNegative = glob.startsWith('!');
|
||||
|
|
@ -431,7 +435,8 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) {
|
|||
cwd,
|
||||
});
|
||||
|
||||
globEntries.push(...allDirEntsRelativeToCwd);
|
||||
// N.B. `globEntries.push(...allDirEntsRelativeToCwd);` can give memory issues for large file trees
|
||||
globEntries = globEntries.concat(allDirEntsRelativeToCwd);
|
||||
} catch (e) {
|
||||
if (!options.suppressErrors) {
|
||||
throw e;
|
||||
|
|
|
|||
Loading…
Reference in a new issue