From 3b8a202ba4f3cd4fe62e896326b39ddbc0744249 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Thu, 29 Jun 2023 21:47:47 +0200 Subject: [PATCH] refactor: avoid async for iterating over dir entries Also uses nicer functional pipeline instead of loops. --- src/main/helpers/fs.helpers.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/helpers/fs.helpers.ts b/src/main/helpers/fs.helpers.ts index 0cb4002a..98792642 100644 --- a/src/main/helpers/fs.helpers.ts +++ b/src/main/helpers/fs.helpers.ts @@ -55,14 +55,11 @@ export async function getFoldersInFolder(folderPath: string, opts?: {ignoreSymli export async function getFilesInFolder(folderPath: string): Promise { if(!(await pathExist(folderPath))){ return []; } - const files = await readdir(folderPath, {withFileTypes: true}); + const dirEntries = await readdir(folderPath, {withFileTypes: true}) - const promises = files.map(async file => { - if(file.isFile()){ return path.join(folderPath, file.name); } - return undefined; - }); - - return (await Promise.all(promises)).filter(file => file); + return dirEntries + .filter(entry => entry.isFile()) + .map(file => path.join(folderPath, file.name)); } export function moveFolderContent(src: string, dest: string): Observable{