Index `files` and return each call edge as ` -> `.
(files: Record<string, string>, withFiles = false)
| 35 | |
| 36 | /** Index `files` and return each call edge as `<refName> -> <target qualified name>`. */ |
| 37 | async function callsOf(files: Record<string, string>, withFiles = false): Promise<string[]> { |
| 38 | const root = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-ts-array-recv-')); |
| 39 | roots.push(root); |
| 40 | for (const [file, text] of Object.entries(files)) { |
| 41 | fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true }); |
| 42 | fs.writeFileSync(path.join(root, file), text); |
| 43 | } |
| 44 | const graph = await CodeGraph.init(root, { index: true }); |
| 45 | graphs.push(graph); |
| 46 | const nodes = graph.getFiles().flatMap((f) => graph.getNodesInFile(f.path)); |
| 47 | const byId = new Map(nodes.map((n) => [n.id, n])); |
| 48 | return graph.getOutgoingEdgesFrom(nodes.map((n) => n.id), ['calls']) |
| 49 | .map((e) => { |
| 50 | const source = byId.get(e.source); |
| 51 | const target = byId.get(e.target); |
| 52 | return withFiles |
| 53 | ? `${source?.filePath}: ${e.metadata?.refName} -> ${target?.filePath}::${target?.qualifiedName}` |
| 54 | : `${e.metadata?.refName} -> ${target?.qualifiedName}`; |
| 55 | }) |
| 56 | .sort(); |
| 57 | } |
| 58 | |
| 59 | const CLASSES = { |
| 60 | 'package.json': JSON.stringify({ name: 'app' }), |
no test coverage detected