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

Function importEdges

__tests__/python-from-import-module-name.test.ts:17–34  ·  view source on GitHub ↗
(files: Record<string, string>, fromFile: string)

Source from the content-addressed store, hash-verified

15let cg: CodeGraph | null = null;
16
17async function importEdges(files: Record<string, string>, fromFile: string): Promise<string[]> {
18 tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-2584-'));
19 for (const [rel, source] of Object.entries(files)) {
20 fs.mkdirSync(path.dirname(path.join(tempDir, rel)), { recursive: true });
21 fs.writeFileSync(path.join(tempDir, rel), source);
22 }
23 cg = await CodeGraph.init(tempDir, { index: true });
24 cg.resolveReferences();
25 const file = cg.getNodesByKind('file').find((n) => n.filePath === fromFile)!;
26 expect(file).toBeDefined();
27 return cg
28 .getOutgoingEdges(file.id)
29 .filter((e) => e.kind === 'imports')
30 .map((e) => cg!.getNode(e.target))
31 .filter((n): n is NonNullable<typeof n> => !!n)
32 .map((n) => `${n.kind}:${n.name}@${n.filePath}`)
33 .sort();
34}
35
36afterEach(() => {
37 cg?.close();

Calls 7

resolveReferencesMethod · 0.80
mapMethod · 0.80
getNodeMethod · 0.80
getNodesByKindMethod · 0.65
joinMethod · 0.45
initMethod · 0.45
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected