Skip to content

Commit

Permalink
refactor(extract): rewrites gatherInitialSources reduce with flatMap (#…
Browse files Browse the repository at this point in the history
…842)

## Description, Motivation and Context

- rewrites a reduce with a flatMap so it's easier to read & maintain

## How Has This Been Tested?

- [ ] green ci

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [x] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij committed Sep 24, 2023
1 parent 4bce7f8 commit 48ce9ab
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/extract/gather-initial-sources.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,21 @@ function gatherScannableFilesFromDirectory(pDirectoryName, pOptions) {
.filter((pFullPathToFile) =>
shouldNotBeExcluded(pathToPosix(pFullPathToFile), pOptions),
)
.reduce((pSum, pFullPathToFile) => {
.flatMap((pFullPathToFile) => {
let lStat = statSync(join(pOptions.baseDir, pFullPathToFile), {
throwIfNoEntry: false,
});

if (lStat) {
if (lStat.isDirectory()) {
return pSum.concat(
gatherScannableFilesFromDirectory(pFullPathToFile, pOptions),
);
return gatherScannableFilesFromDirectory(pFullPathToFile, pOptions);
}
if (fileIsScannable(pOptions, pFullPathToFile)) {
return pSum.concat(pFullPathToFile);
return pFullPathToFile;
}
}
return pSum;
}, [])
return [];
})
.map((pFullPathToFile) => pathToPosix(pFullPathToFile))
.filter((pFullPathToFile) => shouldBeIncluded(pFullPathToFile, pOptions));
}
Expand Down Expand Up @@ -108,7 +106,7 @@ export default function gatherInitialSources(
if (lScannedGlob.isGlob) {
return expandGlob(lOptions.baseDir, lScannedGlob);
}
return pathToPosix(normalize(pFileDirectoryOrGlob));
return normalize(pFileDirectoryOrGlob);
})
.flatMap((pFileOrDirectory) => {
if (statSync(join(lOptions.baseDir, pFileOrDirectory)).isDirectory()) {
Expand Down

0 comments on commit 48ce9ab

Please sign in to comment.