Build + index a throwaway project from a `{ relPath: source }` map.
(prefix: string, files: Record<string, string>)
| 58 | |
| 59 | /** Build + index a throwaway project from a `{ relPath: source }` map. */ |
| 60 | async function buildProject(prefix: string, files: Record<string, string>): Promise<Project> { |
| 61 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); |
| 62 | for (const [rel, body] of Object.entries(files)) { |
| 63 | const abs = path.join(dir, rel); |
| 64 | fs.mkdirSync(path.dirname(abs), { recursive: true }); |
| 65 | fs.writeFileSync(abs, body.trimStart()); |
| 66 | } |
| 67 | const cg = CodeGraph.initSync(dir); |
| 68 | await cg.indexAll(); |
| 69 | return { dir, cg, handler: new ToolHandler(cg) }; |
| 70 | } |
| 71 | |
| 72 | function destroyProject(project?: Project): void { |
| 73 | if (!project) return; |
no test coverage detected