Return

Package Build Pipeline and Type Safety in CI

ARCHITECTURE

Situation

The monorepo packages (@juun/db, @juun/api) were exporting raw source files directly, relying on transpilePackages in Next.js config. Unlike @juun/ui which required this workaround due to RSC directive limitations (timeline #18), these packages contain no "use client" or "use server" directives—making them viable candidates for proper bundling. CI pipeline skipped building these packages, missing potential type errors that would only surface at runtime. OpenAPI type generation ran in CI with network dependencies, causing unreliable builds.

Task

  • Establish proper package build pipeline with type declaration generation
  • Enable full TypeScript validation in CI without transpilation blind spots
  • Remove network dependencies from CI by committing generated types

Action

1. Added Build Pipeline to @juun/db

@juun/api already had tsup configured. Added equivalent setup to @juun/db:

tsup configuration:

  • CJS + ESM dual format output
  • Type declarations with dts: true
  • 5 entry points: index, client, post, timeline, test-connection
  • Node.js platform target for Prisma compatibility
  • Tree-shaking and minification enabled

package.json exports migration: From src to dist

Similar pattern applied to /client, /post, /timeline sub-paths.

2. CI Pipeline Enhancement

Build stages for each packages added before Next.js type generation to ensure workspace packages have type declarations available for downstream consumers.

3. OpenAPI Type Management

  • Removed generated types from .gitignore
  • Updated pre-commit hook to generate types before type checks

Generates fresh OpenAPI types locally (where network is available) and commits them, eliminating network dependency in CI.

Result

Migrated from "transpile on-demand" to "build once, consume everywhere" architecture. CI now performs full TypeScript validation against built type declarations, catching errors that previously surfaced only at runtime.

transpilePackages remains in next.config.ts for now but is effectively redundant—Next.js consumes the built artifacts rather than raw source. This can be removed in a future cleanup once stability is confirmed.

OpenAPI types are committed to git and refreshed via pre-commit hook, making CI builds deterministic. Trade-off: CI build time increased by ~15-20 seconds for package builds; local commits add 2-3 seconds for OpenAPI generation when API specs change.

This completes the architectural cleanup started in timeline #18: UI components stay in-app (RSC limitation), while framework-agnostic packages now build properly.