| 145 | const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') |
| 146 | |
| 147 | const listFiles = async (dir: string) => { |
| 148 | const out: string[] = [] |
| 149 | const stack = [dir] |
| 150 | while (stack.length) { |
| 151 | const d = stack.pop()! |
| 152 | if (!(await exists(d))) continue |
| 153 | const entries = await fs.readdir(d, { withFileTypes: true }) |
| 154 | for (const e of entries) { |
| 155 | const full = path.join(d, e.name) |
| 156 | if (e.isDirectory()) stack.push(full) |
| 157 | else if (/\.(tsx|ts)$/.test(e.name) && !e.name.endsWith('.d.ts')) out.push(full) |
| 158 | } |
| 159 | } |
| 160 | return out |
| 161 | } |
| 162 | |
| 163 | const importSpecifiers = (code: string) => { |
| 164 | const re = |