Skip to content

fix(deps): make the circular-dependency check actually check - #780

Merged
thinkclay merged 2 commits into
mainfrom
fix/777-circular-deps
Sep 17, 2026
Merged

thinkclay merged 2 commits into
mainfrom
fix/777-circular-deps

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

pnpm check-circular-deps was nx show projects --json > /dev/null — it listed
projects and threw them away. test:deps and test:deps:strict both call it, so
both had always passed, and a circular import could land with nothing noticing
(#777).

Wiring scripts/check-circular-deps.sh in as it stood would have replaced one
no-op with a better-looking one. madge defaults to JavaScript extensions, so
pointed at this repo it reports:

Processed 0 files (270ms)
✔ No circular dependency found!

A green check that read nothing. So the script now passes --extensions ts,tsx,
and treats a root that yields no files as an error — that is the failure this
issue is about, and it would otherwise have recurred one layer down. It also
reads madge's exit code instead of string-matching its success message, takes
several roots, and quotes its arguments.

check-circular-deps now runs against apps/scaffald, packages/scf-core and
packages/supabase/functions: ~1,770 files in about 12s, fast enough for the
pre-push path, so it stays in test:deps rather than strict only.

The first real run found three cycles, all one barrel importing its own
consumers:

trpc/routers/utils/storage-backends/index.ts > dropbox-backend.ts
trpc/routers/utils/storage-backends/index.ts > google-drive-backend.ts
trpc/routers/utils/storage-backends/index.ts > supabase-backend.ts

index.ts both declared the IStorageBackend contract and re-exported the three
implementations, each of which imported the contract back from it. The imports
are import type, so nothing broke at runtime — but it is a real cycle in the
module graph and stops being harmless the first time one of them needs a value.
The contract moves to types.ts; index.ts is a barrel of re-exports; the
backends import from types.ts.

Verified in every direction rather than on one green run:

all three roots      ✓ 234 / 1177 / 358 files, exit 0
deliberate 2-file cycle in scf-core   ✗ "Found 1 circular dependency", exit 1
cycle removed                          ✓ exit 0
root with no ts files                  ✗ "processed no files", exit 1
path that does not exist               ✗ "not a directory", exit 1

scripts/README.md gains a Dependency checks section and drops this script from
"Manual tools (not wired to package.json)", which it no longer is.

Closes #777


🤖 Generated with Claude Code

thinkclay and others added 2 commits September 16, 2026 20:37
`pnpm check-circular-deps` was `nx show projects --json > /dev/null` — it listed
projects and threw them away. `test:deps` and `test:deps:strict` both call it, so
both had always passed, and a circular import could land with nothing noticing
(#777).

Wiring `scripts/check-circular-deps.sh` in as it stood would have replaced one
no-op with a better-looking one. madge defaults to JavaScript extensions, so
pointed at this repo it reports:

    Processed 0 files (270ms)
    ✔ No circular dependency found!

A green check that read nothing. So the script now passes `--extensions ts,tsx`,
and **treats a root that yields no files as an error** — that is the failure this
issue is about, and it would otherwise have recurred one layer down. It also
reads madge's exit code instead of string-matching its success message, takes
several roots, and quotes its arguments.

`check-circular-deps` now runs against `apps/scaffald`, `packages/scf-core` and
`packages/supabase/functions`: ~1,770 files in about 12s, fast enough for the
pre-push path, so it stays in `test:deps` rather than `strict` only.

**The first real run found three cycles**, all one barrel importing its own
consumers:

    trpc/routers/utils/storage-backends/index.ts > dropbox-backend.ts
    trpc/routers/utils/storage-backends/index.ts > google-drive-backend.ts
    trpc/routers/utils/storage-backends/index.ts > supabase-backend.ts

`index.ts` both declared the `IStorageBackend` contract and re-exported the three
implementations, each of which imported the contract back from it. The imports
are `import type`, so nothing broke at runtime — but it is a real cycle in the
module graph and stops being harmless the first time one of them needs a value.
The contract moves to `types.ts`; `index.ts` is a barrel of re-exports; the
backends import from `types.ts`.

Verified in every direction rather than on one green run:

    all three roots      ✓ 234 / 1177 / 358 files, exit 0
    deliberate 2-file cycle in scf-core   ✗ "Found 1 circular dependency", exit 1
    cycle removed                          ✓ exit 0
    root with no ts files                  ✗ "processed no files", exit 1
    path that does not exist               ✗ "not a directory", exit 1

`scripts/README.md` gains a Dependency checks section and drops this script from
"Manual tools (not wired to package.json)", which it no longer is.

Closes #777

Co-Authored-By: Claude Opus 5 <[email protected]>
`supabase:typecheck` failed on the previous commit:

    storage-router.ts(12,3): error TS2305: Module
      './storage-backends/index.ts' has no exported member 'StorageRouterResult'

Splitting the contract out of the barrel was right; listing the re-exports by
hand was not. I enumerated six and `types.ts` declares seven, so the barrel
silently narrowed its own surface — which is the one thing a barrel exists to
prevent.

`export *` instead. There is no reason to maintain that list by hand.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm test:deps never runs the circular-dependency check — check-circular-deps is a no-op

1 participant