MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / importsOf

Function importsOf

__tests__/python-import-module-target.test.ts:29–40  ·  view source on GitHub ↗

The `imports` edges out of a file or a function in it, as `kind:name@file`.

(fromFile: string)

Source from the content-addressed store, hash-verified

27
28/** The `imports` edges out of a file or a function in it, as `kind:name@file`. */
29function 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
42afterEach(() => {
43 cg?.close();

Calls 4

mapMethod · 0.80
getNodeMethod · 0.80
getNodesByKindMethod · 0.65
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected