(files: Record<string, string>, fromName: string)
| 20 | let cg: CodeGraph | null = null; |
| 21 | |
| 22 | async function edges(files: Record<string, string>, fromName: string): Promise<string[]> { |
| 23 | tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-2580-')); |
| 24 | for (const [rel, source] of Object.entries(files)) { |
| 25 | fs.mkdirSync(path.dirname(path.join(tempDir, rel)), { recursive: true }); |
| 26 | fs.writeFileSync(path.join(tempDir, rel), source); |
| 27 | } |
| 28 | cg = await CodeGraph.init(tempDir, { index: true }); |
| 29 | cg.resolveReferences(); |
| 30 | const from = cg.getNodesByKind('function').find((n) => n.name === fromName)!; |
| 31 | expect(from).toBeDefined(); |
| 32 | return cg |
| 33 | .getOutgoingEdges(from.id) |
| 34 | .filter((e) => e.kind === 'calls') |
| 35 | .map((e) => [e, cg!.getNode(e.target)] as const) |
| 36 | .filter(([, n]) => n?.kind === 'function') |
| 37 | .map(([e, n]) => `${e.kind} ${n!.name} L${e.line}`); |
| 38 | } |
| 39 | |
| 40 | /** `package main` with the package-level `run`, `body`, and a `main` that calls `call`. */ |
| 41 | function mainGo(body: string, call: string): Record<string, string> { |
no test coverage detected