Update loc count library

This version will count lines of code in each file serially. It still
runs all file system operations asynchronously. The only difference now
is that it will only count one file at a time. It is slower, but it
is able to count large repositories without running out of memory.
This commit is contained in:
Andrew Eisenberg
2021-05-12 16:33:05 -07:00
parent 4c0671c518
commit ddcb299283
7 changed files with 23 additions and 19 deletions

View File

@@ -166,7 +166,9 @@ export class LocDir {
};
} = {};
await Promise.all(paths.map(async (pathItem) => {
// We _could_ use Promise.all to count the files in parallel, but that
// would lead to out of memory errors when there are many files.
for (const pathItem of paths) {
const fullPath = slash(path.join(this.cwd, pathItem));
if (
!pathItem ||
@@ -174,7 +176,7 @@ export class LocDir {
!(await fs.pathExists(fullPath)) ||
(await fs.stat(fullPath)).isDirectory()
) {
return;
continue;
}
const file = new LocFile(fullPath);
const fileLineInfo = await file.getFileInfo();
@@ -192,7 +194,7 @@ export class LocDir {
[fileLineInfo.languages]: language,
};
files.push(fullPath);
}));
}
return {
files,