The `imports` edges out of a file or a function in it, as `kind:name@file`.
(fromFile: string)
| 27 | |
| 28 | /** The `imports` edges out of a file or a function in it, as `kind:name@file`. */ |
| 29 | function importsOf(fromFile: string): string[] { |
| 30 | const file = cg!.getNodesByKind('file').find((n) => n.filePath === fromFile)!; |
| 31 | expect(file, `${fromFile} should be indexed`).toBeDefined(); |
| 32 | const sources = [file, ...cg!.getNodesByKind('function').filter((n) => n.filePath === fromFile)]; |
| 33 | return sources |
| 34 | .flatMap((n) => cg!.getOutgoingEdges(n.id)) |
| 35 | .filter((e) => e.kind === 'imports') |
| 36 | .map((e) => cg!.getNode(e.target)) |
| 37 | .filter((n): n is NonNullable<typeof n> => !!n) |
| 38 | .map((n) => `${n.kind}:${n.name}@${n.filePath}`) |
| 39 | .sort(); |
| 40 | } |
| 41 | |
| 42 | afterEach(() => { |
| 43 | cg?.close(); |
no test coverage detected