(baseDir: string, parts: string[])
| 53 | } |
| 54 | |
| 55 | async function expandGlob(baseDir: string, parts: string[]): Promise<string[]> { |
| 56 | if (parts.length === 0) { |
| 57 | // Check if this dir has a package.json |
| 58 | if (await exists(resolve(baseDir, 'package.json'))) { |
| 59 | return [baseDir]; |
| 60 | } |
| 61 | return []; |
| 62 | } |
| 63 | |
| 64 | const [current, ...rest] = parts; |
| 65 | if (current === '*') { |
| 66 | // Match any single directory |
| 67 | const entries = await safeReaddir(baseDir); |
| 68 | const results: string[] = []; |
| 69 | for (const entry of entries) { |
| 70 | const entryPath = resolve(baseDir, entry); |
| 71 | if (await isDirectory(entryPath)) { |
| 72 | results.push(...(await expandGlob(entryPath, rest))); |
| 73 | } |
| 74 | } |
| 75 | return results; |
| 76 | } else if (current === '**') { |
| 77 | // Match any depth |
| 78 | const results: string[] = []; |
| 79 | // Try matching at this level (skip the **) |
| 80 | results.push(...(await expandGlob(baseDir, rest))); |
| 81 | // Try descending into subdirs |
| 82 | const entries = await safeReaddir(baseDir); |
| 83 | for (const entry of entries) { |
| 84 | if (entry.startsWith('.') || entry === 'node_modules') continue; |
| 85 | const entryPath = resolve(baseDir, entry); |
| 86 | if (await isDirectory(entryPath)) { |
| 87 | results.push(...(await expandGlob(entryPath, parts))); // keep the ** in pattern |
| 88 | } |
| 89 | } |
| 90 | return results; |
| 91 | } else { |
| 92 | // Literal directory name |
| 93 | const next = resolve(baseDir, current!); |
| 94 | if (await isDirectory(next)) { |
| 95 | return expandGlob(next, rest); |
| 96 | } |
| 97 | return []; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | async function safeReaddir(dir: string): Promise<string[]> { |
| 102 | try { |
no test coverage detected
searching dependent graphs…