Skip to content

Commit 106e231

Browse files
committed
chore: use async operations in getAllFiles
1 parent 7ba6027 commit 106e231

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

scripts/downlevel-dts/downlevelWorkspace.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const downlevelWorkspace = async (workspacesDir, workspaceName) => {
3737
// Strip comments from downlevel-dts files
3838
try {
3939
await access(downlevelDir);
40-
getAllFiles(downlevelDir).forEach(async (downlevelTypesFilepath) => {
40+
const files = await getAllFiles(downlevelDir);
41+
files.forEach(async (downlevelTypesFilepath) => {
4142
try {
4243
const content = await readFile(downlevelTypesFilepath, "utf8");
4344
await writeFile(downlevelTypesFilepath, stripComments(content));

scripts/downlevel-dts/getAllFiles.mjs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { readdirSync, statSync } from "fs";
1+
import { readdir, stat } from "fs/promises";
22

3-
export const getAllFiles = (dirPath, arrayOfFiles = []) => {
4-
const files = readdirSync(dirPath);
3+
export const getAllFiles = async (dirPath, arrayOfFiles = []) => {
4+
const files = await readdir(dirPath);
55

6-
files.forEach((file) => {
7-
const { isDirectory } = statSync(dirPath + "/" + file);
6+
for (const file of files) {
7+
const { isDirectory } = await stat(dirPath + "/" + file);
88
if (isDirectory()) {
9-
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
9+
const filesInDirectory = await getAllFiles(dirPath + "/" + file, arrayOfFiles);
10+
arrayOfFiles.push(filesInDirectory);
1011
} else {
1112
arrayOfFiles.push(join(dirPath, "/", file));
1213
}
13-
});
14+
}
1415

1516
return arrayOfFiles;
1617
};

0 commit comments

Comments
 (0)