(rootPath, options = {})
| 123 | } |
| 124 | |
| 125 | export async function walkFiles(rootPath, options = {}) { |
| 126 | const files = []; |
| 127 | const { |
| 128 | excludeDirs = [], |
| 129 | skipTopLevel = ["fixtures", "__fixtures__"], |
| 130 | } = options; |
| 131 | const excluded = new Set([...IGNORED_DIRS, ...excludeDirs]); |
| 132 | |
| 133 | async function visit(currentPath, depth = 0) { |
| 134 | const entries = await fs.readdir(currentPath, { withFileTypes: true }); |
| 135 | for (const entry of entries) { |
| 136 | const entryPath = path.join(currentPath, entry.name); |
| 137 | if (entry.isDirectory()) { |
| 138 | if (excluded.has(entry.name)) { |
| 139 | continue; |
| 140 | } |
| 141 | if (depth === 0 && skipTopLevel.includes(entry.name)) { |
| 142 | continue; |
| 143 | } |
| 144 | await visit(entryPath, depth + 1); |
| 145 | continue; |
| 146 | } |
| 147 | if (entry.isFile()) { |
| 148 | files.push(entryPath); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | await visit(rootPath); |
| 154 | return files.sort(); |
| 155 | } |
| 156 | |
| 157 | export async function listImmediateDirectories(rootPath) { |
| 158 | const entries = await fs.readdir(rootPath, { withFileTypes: true }); |
no test coverage detected