Build + index a throwaway project from a `{ relPath: source }` map.
( prefix: string, files: Record<string, string>, )
| 34 | |
| 35 | /** Build + index a throwaway project from a `{ relPath: source }` map. */ |
| 36 | async function buildProject( |
| 37 | prefix: string, |
| 38 | files: Record<string, string>, |
| 39 | ): Promise<{ dir: string; cg: CodeGraph; handler: ToolHandler }> { |
| 40 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); |
| 41 | for (const [rel, body] of Object.entries(files)) { |
| 42 | const abs = path.join(dir, rel); |
| 43 | fs.mkdirSync(path.dirname(abs), { recursive: true }); |
| 44 | fs.writeFileSync(abs, body.trimStart()); |
| 45 | } |
| 46 | const cg = CodeGraph.initSync(dir); |
| 47 | await cg.indexAll(); |
| 48 | return { dir, cg, handler: new ToolHandler(cg) }; |
| 49 | } |
| 50 | |
| 51 | const cleanup = (dir: string, cg?: CodeGraph) => { |
| 52 | if (cg) cg.destroy(); |
no test coverage detected