From 7dcf7fc33d560f370d50fa5d91670657d908f034 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Fri, 13 Feb 2026 01:35:15 +0100 Subject: [PATCH 1/3] Refactor `getFiles` to use async/await and improve clarity in glob result handling --- src/fs/glob.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fs/glob.ts b/src/fs/glob.ts index 682c836..2cfb446 100644 --- a/src/fs/glob.ts +++ b/src/fs/glob.ts @@ -65,9 +65,9 @@ export const ignoreFunc = ( * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns. * @return A promise that resolves to an array of file paths. */ -export function getFiles(args: Args, pattern: Patterns) { - // Execute the glob search with the built patterns - return new Glob(pattern.include, { +export async function getFiles(args: Args, pattern: Patterns): Promise { + // 1. Create the Glob instance + const g = new Glob(pattern.include, { ignore: { ignored: (p: Path) => ignoreFunc(p, pattern.exclude), }, @@ -75,4 +75,7 @@ export function getFiles(args: Args, pattern: Patterns) { cwd: args.paths.cwd, root: args.paths.root ? path.resolve(args.paths.root) : undefined, }); + + // 2. Return the walk() promise, which resolves to an array of all file paths + return g.walk(); } From 36dec93802cc4f2c092a561293159173357e9909 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Fri, 13 Feb 2026 01:36:08 +0100 Subject: [PATCH 2/3] Update `taskRunner` to track progress with progress bar updates using `finally` --- src/parser/taskRunner.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/parser/taskRunner.ts b/src/parser/taskRunner.ts index d3ce770..9c4d202 100644 --- a/src/parser/taskRunner.ts +++ b/src/parser/taskRunner.ts @@ -19,7 +19,13 @@ export async function taskRunner( progressBar: SingleBar, ) { const messages: string[] = []; - await Promise.allSettled(tasks) + // Create a new array of promises that update the bar when they finish. + const tasksWithProgress = tasks.map((task) => + task.finally(() => { + progressBar.increment(); + }) + ); + await Promise.allSettled(tasksWithProgress) .then((strings) => { /** * Return the strings that are not rejected (they are fulfilled) From b19ecd2ae1e3fcf608e739dc1b1466a01b047424 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Fri, 13 Feb 2026 01:36:18 +0100 Subject: [PATCH 3/3] Refactor `process` and `exec` to improve async handling, enhance progress bar updates, and streamline file processing --- src/parser/exec.ts | 4 ++-- src/parser/process.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/parser/exec.ts b/src/parser/exec.ts index c56bd88..338e231 100644 --- a/src/parser/exec.ts +++ b/src/parser/exec.ts @@ -45,9 +45,9 @@ export async function exec(args: Args): Promise { * Extract the strings from the files */ const patterns = getPatterns(args); - const files = await processFiles(patterns, args); + const files = await processFiles(patterns, args, progressBar); - progressBar.update(2, { + progressBar.start(files.length, 0, { filename: `Found ${files.length} files... `, }); diff --git a/src/parser/process.ts b/src/parser/process.ts index bfa6308..fc7fcf0 100644 --- a/src/parser/process.ts +++ b/src/parser/process.ts @@ -24,17 +24,17 @@ export async function processFiles( const tasks: Promise[] = []; let processedFilesCount = 0; - const files = getFiles(args, patterns); + const files = await getFiles(args, patterns); if (progressBar) { - progressBar.setTotal(Object.values(files).length); + progressBar.setTotal(files.length); progressBar.update(0, { - filename: `Found ${Object.values(files).length} files`, + filename: `Found ${files.length} files`, }); } - // loop through the files and parse them - for await (const file of files) { + // Loop through the array + for (const file of files) { processedFilesCount++; const filename = path.basename(file); const ext = path.extname(file).replace(/^./, ""); @@ -56,8 +56,9 @@ export async function processFiles( } if (progressBar) { - progressBar.update(processedFilesCount, { filename: filename }); - progressBar.render(); + progressBar.update(processedFilesCount, { + filename: `${path.basename(file)} (Valid: ${tasks.length})` + }); } }