From fd38e36526fc756566bb1bfa2780e921dcd38372 Mon Sep 17 00:00:00 2001 From: jckail Date: Wed, 8 Jul 2026 23:56:10 -0700 Subject: [PATCH] Fix circular import that broke the web build (OpenAPI generator) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #5 re-exported ./openapi from contracts/index.ts, but openapi.ts imports from ./index — an import cycle (index → openapi → index) that crashed the Next build at load with a TDZ "Cannot access 'v' before initialization" while collecting page data (any route importing @pointup/core/contracts). Break the cycle: expose `buildOpenApiDocument` via a dedicated "@pointup/core/openapi" subpath instead of the contracts barrel. openapi.ts still imports the schemas from ./index (one-directional now); nothing imports back. The web route imports from @pointup/core/openapi. Verified with a runtime import-order check (contracts first, then openapi) — no TDZ. Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/web/src/app/api/v1/openapi.json/route.ts | 2 +- packages/core/package.json | 1 + packages/core/src/contracts/index.ts | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/web/src/app/api/v1/openapi.json/route.ts b/apps/web/src/app/api/v1/openapi.json/route.ts index d4a58f8..07b811e 100644 --- a/apps/web/src/app/api/v1/openapi.json/route.ts +++ b/apps/web/src/app/api/v1/openapi.json/route.ts @@ -1,4 +1,4 @@ -import { buildOpenApiDocument } from "@pointup/core/contracts"; +import { buildOpenApiDocument } from "@pointup/core/openapi"; import { NextResponse } from "next/server"; /** diff --git a/packages/core/package.json b/packages/core/package.json index 7c05c95..8a4add2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -7,6 +7,7 @@ "exports": { ".": "./src/index.ts", "./contracts": "./src/contracts/index.ts", + "./openapi": "./src/contracts/openapi.ts", "./providers": "./src/domain/loyalty/provider.ts", "./db/schema": "./src/infrastructure/db/schema.ts" }, diff --git a/packages/core/src/contracts/index.ts b/packages/core/src/contracts/index.ts index bf39b6c..8c072b7 100644 --- a/packages/core/src/contracts/index.ts +++ b/packages/core/src/contracts/index.ts @@ -795,5 +795,8 @@ export function toIngestDealPageResultDto( }; } -// OpenAPI 3.1 document generated from the schemas above. -export * from "./openapi"; +// The OpenAPI generator (`buildOpenApiDocument`) lives in ./openapi and is +// exposed via the "@pointup/core/openapi" subpath. It is intentionally NOT +// re-exported here: it imports from this module, so re-exporting would create +// an import cycle (index -> openapi -> index) that fails at load with a TDZ +// "Cannot access '...' before initialization" error.