Skip to content

Commit

Permalink
chore: fix fileUtils.findFilesWithExtension to exclude folders using …
Browse files Browse the repository at this point in the history
…absolute paths
  • Loading branch information
KRJOH3 committed Apr 18, 2024
1 parent 82d6a90 commit 1a61643
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';
*
* @param {string} dir - The directory to start searching from.
* @param {string[]} extensions - The list of file extensions to match.
* @param {string[]} excludedFolders - Folders to exclude from the search.
* @param {string[]} excludedFolders - Folders to exclude from the search, should be absolute paths.
* @returns {string[]} - An array of file paths that match the given extensions.
*/
export function findFilesWithExtension(
Expand All @@ -15,12 +15,13 @@ export function findFilesWithExtension(
excludedFolders: string[],
): string[] {
let files: string[] = [];

const absDir = path.resolve(dir);
try {
const items = fs.readdirSync(dir);

items.forEach((item) => {
const itemPath = path.join(dir, item);
const absItemPath = path.resolve(itemPath);
let stat;

try {
Expand All @@ -36,7 +37,7 @@ export function findFilesWithExtension(
}

if (stat.isDirectory()) {
if (!excludedFolders.includes(item)) {
if (!excludedFolders.includes(absItemPath)) {
files = files.concat(
findFilesWithExtension(itemPath, extensions, excludedFolders),
);
Expand Down

0 comments on commit 1a61643

Please sign in to comment.