(root: string, path: string)
| 126 | const parseImportsCache = new Map<string, Promise<ImportReference[]>>(); |
| 127 | |
| 128 | export async function parseImports(root: string, path: string): Promise<ImportReference[]> { |
| 129 | if (!isJavaScript(path)) return []; // TODO traverse CSS, too |
| 130 | const filePath = join(root, path); |
| 131 | let promise = parseImportsCache.get(filePath); |
| 132 | if (promise) return promise; |
| 133 | promise = (async function () { |
| 134 | try { |
| 135 | const source = await readFile(filePath, "utf-8"); |
| 136 | const body = parseProgram(source); |
| 137 | return findImports(body, path, source); |
| 138 | } catch (error: any) { |
| 139 | console.warn(`unable to fetch or parse ${path}: ${error.message}`); |
| 140 | return []; |
| 141 | } |
| 142 | })(); |
| 143 | parseImportsCache.set(filePath, promise); |
| 144 | return promise; |
| 145 | } |
no test coverage detected