diff --git a/src/index/generateTrees/buildGraph.ts b/src/index/generateTrees/buildGraph.ts index d7aed39..66a15aa 100644 --- a/src/index/generateTrees/buildGraph.ts +++ b/src/index/generateTrees/buildGraph.ts @@ -1,4 +1,5 @@ import path from "path"; + import { findEdges } from "../shared/findEdges"; import { Graph, OldGraph } from "./shared/Graph"; import { findSharedParent } from "./shared/findSharedParent"; @@ -13,6 +14,7 @@ export function buildGraph(files: string[]) { const totalFiles: string[] = []; let numForwardSlashes = 0; let numBackSlashes = 0; + for (let file of files) { if (file === ".git") { continue; diff --git a/src/index/generateTrees/buildGraph/addEdge.ts b/src/index/generateTrees/buildGraph/addEdge.ts index bf9ba27..5325f73 100644 --- a/src/index/generateTrees/buildGraph/addEdge.ts +++ b/src/index/generateTrees/buildGraph/addEdge.ts @@ -4,5 +4,6 @@ export function addEdgeToGraph([start, end]: [string, string], graph: Graph) { if (!(start in graph)) { graph[start] = []; } + if (graph[start].includes(end)) return; graph[start].push(end); } diff --git a/tests/__snapshots__/end-to-end.test.ts.snap b/tests/__snapshots__/end-to-end.test.ts.snap index 8b6de26..e03ec9e 100644 --- a/tests/__snapshots__/end-to-end.test.ts.snap +++ b/tests/__snapshots__/end-to-end.test.ts.snap @@ -337,6 +337,33 @@ import \\"@testing-library/jest-dom/extend-expect\\"; " `; +exports[`end-to-end duplicate-imports 1`] = ` +"duplicate-imports +├── index +│ ├── routes +│ │ └── home.js +│ └── routes.js +└── index.js" +`; + +exports[`end-to-end duplicate-imports: duplicate-imports/index.js 1`] = ` +"/* eslint-disable*/ + +import { five } from \\"./index/routes\\"; +import { five } from \\"./index/routes\\"; +" +`; + +exports[`end-to-end duplicate-imports: duplicate-imports/index/routes.js 1`] = ` +"export * from \\"./routes/home\\"; +" +`; + +exports[`end-to-end duplicate-imports: duplicate-imports/index/routes/home.js 1`] = ` +"export const five = 5; +" +`; + exports[`end-to-end duplicates 1`] = ` "duplicates ├── index diff --git a/tests/fixtures/duplicate-imports/home.js b/tests/fixtures/duplicate-imports/home.js new file mode 100644 index 0000000..607f324 --- /dev/null +++ b/tests/fixtures/duplicate-imports/home.js @@ -0,0 +1 @@ +export const five = 5; diff --git a/tests/fixtures/duplicate-imports/index.js b/tests/fixtures/duplicate-imports/index.js new file mode 100644 index 0000000..076f869 --- /dev/null +++ b/tests/fixtures/duplicate-imports/index.js @@ -0,0 +1,4 @@ +/* eslint-disable*/ + +import { five } from "./routes"; +import { five } from "./routes"; diff --git a/tests/fixtures/duplicate-imports/routes.js b/tests/fixtures/duplicate-imports/routes.js new file mode 100644 index 0000000..84d36cd --- /dev/null +++ b/tests/fixtures/duplicate-imports/routes.js @@ -0,0 +1 @@ +export * from "./home";