Skip to content

Commit

Permalink
Improve path glob resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Jan 5, 2025
1 parent b148434 commit 51d49f6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions task/utils/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,27 @@ export function resolvePathGlobs(paths: string | string[], cwd?: string): string
* @returns The files matching the path globs
*/
export function getFilesMatchingPathGlobs(paths: string | string[], cwd?: string): string[] {
const resolvedPaths = resolvePathGlobs(paths, cwd);
return resolvedPaths
.flatMap((p) => (fs.lstatSync(p).isDirectory() ? getFilesMatchingPathGlobs(path.join(p, '**', '*.*')) : [p]))
return resolvePathGlobs(paths, cwd)
.flatMap((p) => getFilesInDirectoryRecursive(fs.lstatSync(p).isDirectory() ? p : path.dirname(p)))
.distinct();
}

/**
* Recursively read a directory
* @param directory The directory to read
* @returns The files in the directory
*/
function getFilesInDirectoryRecursive(directory: string): string[] {
const files = fs.readdirSync(directory);
const resolvedFiles = [];
for (const file of files) {
const filePath = path.join(directory, file);
if (fs.lstatSync(filePath as string).isDirectory()) {
resolvedFiles.push(...getFilesInDirectoryRecursive(filePath));
} else if (fs.lstatSync(filePath as string).isFile()) {
resolvedFiles.push(filePath);
}
}
console.log('DIR FILES', directory, resolvedFiles);
return resolvedFiles;
}

0 comments on commit 51d49f6

Please sign in to comment.