Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit f76080a

Browse files
committed
fix: ignore file list entries without files names
1 parent 359cc68 commit f76080a

File tree

1 file changed

+13
-4
lines changed
  • src/middlewares/utils

1 file changed

+13
-4
lines changed

src/middlewares/utils/fs.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ async function listFiles(dir: string, extension: string, depth: number): Promise
1313
const files = await Promise.all(
1414
dirents.map(dirent => {
1515
const res = path.join(dir, dirent.name);
16-
return {file: [res].filter(f => f.endsWith(extension))[0], isDirectory: dirent.isDirectory()} as FsItem;
16+
return {
17+
file: [res].filter(f => f.endsWith(extension))[0],
18+
isDirectory: dirent.isDirectory(),
19+
} as FsItem;
1720
}),
1821
);
1922
return ([] as FsItem[]).concat(...files);
@@ -27,9 +30,13 @@ export async function listRepoFiles(
2730
folder: string,
2831
extension: string,
2932
depth: number,
30-
) {
33+
): Promise<FsItem[]> {
3134
const files = await listFiles(path.join(repoPath, folder), extension, depth);
32-
return files.map(f => {return {file: f.file.slice(repoPath.length + 1), isDirectory: f.isDirectory} as FsItem});
35+
return files
36+
.filter(f => f.file)
37+
.map(f => {
38+
return { file: f.file.slice(repoPath.length + 1), isDirectory: f.isDirectory } as FsItem;
39+
});
3340
}
3441

3542
export async function writeFile(filePath: string, content: Buffer | string) {
@@ -54,7 +61,9 @@ export async function move(from: string, to: string) {
5461
const sourceDir = path.dirname(from);
5562
const destDir = path.dirname(to);
5663
const allFiles = await listFiles(sourceDir, '', 100);
57-
await Promise.all(allFiles.map(item => moveFile(item.file, item.file.replace(sourceDir, destDir))));
64+
await Promise.all(
65+
allFiles.map(item => moveFile(item.file, item.file.replace(sourceDir, destDir))),
66+
);
5867
}
5968

6069
export async function getUpdateDate(repoPath: string, filePath: string) {

0 commit comments

Comments
 (0)