import { existsSync, readdirSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const here = path.dirname(fileURLToPath(import.meta.url)); const src = path.resolve(here, ".."); const candidates = [".ts", ".tsx", ".native.ts", ".native.tsx", "/index.ts", "/index.native.ts"]; function resolveLocal(from: string, specifier: string): string[] { const base = path.resolve(path.dirname(from), specifier); return candidates.map((suffix) => base + suffix).filter((file) => existsSync(file)); } function walk(): { files: Set; packages: Set } { const files = new Set(); const packages = new Set(); const queue = readdirSync(here) .filter( (name) => /\.tsx?$/.test(name) && !name.includes(".spec.") && !name.includes(".fixture."), ) .map((name) => path.join(here, name)); while (queue.length > 0) { const file = queue.pop()!; if (files.has(file)) continue; files.add(file); const text = readFileSync(file, "utf8"); for (const match of text.matchAll(/(?:from|import)\s*\(?\s*"([^"]+)"/g)) { const specifier = match[1]!; if (specifier.startsWith(".")) queue.push(...resolveLocal(file, specifier)); else packages.add(specifier); } } return { files, packages }; } describe("the graph-layout entry's import graph (FZ-8149, LC-294)", () => { const { files, packages } = walk(); const relative = [...files].map((file) => path.relative(src, file)).sort(); it("never reaches React Flow's React runtime, its store or the webview", () => { expect( [...packages].filter( (name) => name === "@xyflow/react" || name.startsWith("react-native-webview"), ), ).toEqual([]); expect( relative.filter( (file) => file === "react-flow/xy.ts" || file.startsWith("dom/") || file.includes("useEdgeObstacles"), ), ).toEqual([]); }); it("draws through NodeGraph's own layout engine and edge path, so there is one of each", () => { for (const shared of [ "layout/dagre.ts", "edges/edgePath.ts", "edges/edgeRoute.ts", "edges/edgeStyle.ts", ]) { expect(relative).toContain(shared); } }); });