From 2cc594eb398aab248b1ee6759d20d4c4d866a020 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Sat, 14 Sep 2024 22:00:58 +0100 Subject: [PATCH] FIxed an issue where an input file could be processed twice in some edge cases --- src/utils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index aba04d2..879e7a2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -209,8 +209,11 @@ async function getTargetsPaths( } const result = await getGlobPaths(rootPath, targetGlobs, withNodeModules); - const filesPaths = [...targetFiles, ...result.files]; - const filesNames = [...targetFilesNames, ...result.filesFoundNames]; + const resultFiles = result.files; + const resultFilesFoundNames = [...result.filesFoundNames]; + + const filesPaths = [...without(targetFiles, resultFiles), ...resultFiles]; + const filesNames = [...without(targetFilesNames, resultFilesFoundNames), ...resultFilesFoundNames]; const filesNamesToPaths = result.filesFoundNamesToPaths; for (const fileName in targetFilesNamesToPaths) { @@ -637,6 +640,13 @@ function uniq(values: T[]): T[] { return Array.from(new Set(values)); } +function without(values: T[], exclude: T[]): T[] { + if (!values.length) return values; + if (!exclude.length) return values; + const excludeSet = new Set(exclude); + return values.filter((value) => !excludeSet.has(value)); +} + function zipObjectUnless(keys: T[], values: U[], unless: (value: U) => boolean): Partial> { const map: Partial> = {}; @@ -699,5 +709,6 @@ export { someOf, trimFinalNewline, uniq, + without, zipObjectUnless, };