Skip to content

Commit

Permalink
fix(scanner)!: limit patterns scanned from modules/ dir (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes authored Sep 28, 2024
1 parent 2917029 commit 286c18c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/core/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,37 @@ export async function scanTasks(nitro: Nitro) {
}

export async function scanModules(nitro: Nitro) {
const files = await scanFiles(nitro, "modules");
const files = await scanFiles(nitro, "modules", [
"*/index.{js,mjs,cjs,ts,mts,cts}",
"*.{js,mjs,cjs,ts,mts,cts}",
]);
return files.map((f) => f.fullPath);
}

async function scanFiles(nitro: Nitro, name: string): Promise<FileInfo[]> {
async function scanFiles(
nitro: Nitro,
name: string,
patterns: string | string[] = [GLOB_SCAN_PATTERN]
): Promise<FileInfo[]> {
const files = await Promise.all(
nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))
nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name, patterns))
).then((r) => r.flat());
return files;
}

async function scanDir(
nitro: Nitro,
dir: string,
name: string
name: string,
patterns: string | string[]
): Promise<FileInfo[]> {
const fileNames = await globby(join(name, GLOB_SCAN_PATTERN), {
const globbyPattern: string[] = [];
// Normalize patterns to an array
for (const pattern of Array.isArray(patterns) ? patterns : [patterns]) {
globbyPattern.push(join(name, pattern));
}

const fileNames = await globby(globbyPattern, {
cwd: dir,
dot: true,
ignore: nitro.options.ignore,
Expand Down

0 comments on commit 286c18c

Please sign in to comment.