ccorcos / import-cycles

Detect cyclical imports in TypeScript projects
0 stars 1 forks source link

Broken #4

Open ccorcos opened 2 years ago

ccorcos commented 2 years ago

I'm running this in a project of mine and I'm seeing this as a cycle...

/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/renderer.tsx
/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/components/App.tsx
/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/components/Backlinks.tsx
/Users/chet/Code/js/html-editor/packages/desktop/src/app/shared/database/LinkIndex.ts
/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/Environment.tsx
/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/components/ToastRenderer.tsx
/Users/chet/Code/js/html-editor/packages/desktop/src/app/renderer/Environment.tsx

This is the Environment.ts imports.

import React, { createContext, useContext } from "react"
import type { RendererTestHarnessClient } from "../../test/harness/RendererTestHarnessClient"
import { Command } from "../shared/Command"
import type { Config } from "../shared/config"
import { TupleDb } from "../shared/database/TupleSchema"
import { DialogApi, FileSystemApi } from "../shared/ipc"
import { ModuleStateJSON } from "./appState"
import { AppDatabase } from "./services/AppDatabaseService"
import type { KeyboardService } from "./services/KeyboardService"
import { OverlayService } from "./services/OverlayService"
import type { PlatformService } from "./services/PlatformService"
import type { ScrollerService } from "./services/ScrollerService"
import type { TabApiService } from "./services/TabApiService"

This is the ToastRenderer.ts imports.

import React from "react"
import { useEnvironment } from "../Environment"
import { toasterQueries, useToasts } from "../state/ToasterState"

There's no cycle here, but your code says there is.

I also tried debugging your code but it was hard because there's no full dependency map like there was before.

Please do two things:

  1. Refactor your code so that you generate a full map of what imports what else, just like I had before: https://github.com/ccorcos/import-cycles/blob/8a89c78b0c5e77879bf7ba20d3ab875dae0e3938/src/index.ts#L160-L225

  2. Please try to figure out why your code does not work and fix it.

QuentinGruber commented 2 years ago

Just to be sure of something don't you have multiple Environment.ts files ?

ccorcos commented 2 years ago

Nope, just one Environment.ts file.

ccorcos commented 2 years ago

It would be much easier to debug if we started off with a dependency map and then narrowed in on cycles from there.