Skip to content

Commit 6e04822

Browse files
committed
chore(mcp): simplify listFilesRecursive using fs.readdir recursive option
1 parent bdc207e commit 6e04822

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

packages/playwright-core/src/tools/backend/response.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,13 @@ function sanitizeUnicode(text: string): string {
366366
}
367367

368368
async function listFilesRecursive(dir: string): Promise<{ path: string, size: number, mtimeMs: number }[]> {
369-
const result: { path: string, size: number, mtimeMs: number }[] = [];
370-
async function walk(current: string) {
371-
let entries: fs.Dirent[];
372-
try {
373-
entries = await fs.promises.readdir(current, { withFileTypes: true });
374-
} catch {
375-
return;
376-
}
377-
for (const entry of entries) {
378-
const full = path.join(current, entry.name);
379-
if (entry.isDirectory()) {
380-
await walk(full);
381-
} else if (entry.isFile()) {
382-
try {
383-
const stat = await fs.promises.stat(full);
384-
result.push({ path: full, size: stat.size, mtimeMs: stat.mtimeMs });
385-
} catch {
386-
}
387-
}
388-
}
389-
}
390-
await walk(dir);
391-
return result;
369+
const entries = await fs.promises.readdir(dir, { recursive: true, withFileTypes: true });
370+
const files = entries.filter(e => e.isFile());
371+
return Promise.all(files.map(async e => {
372+
const full = path.join(e.parentPath, e.name);
373+
const { size, mtimeMs } = await fs.promises.stat(full);
374+
return { path: full, size, mtimeMs };
375+
}));
392376
}
393377

394378
function parseSections(text: string): Map<string, string> {

0 commit comments

Comments
 (0)