Skip to content

Implement incremental TypeScript compilation and caching for monorepo builds #337

Description

@Lakes41

Background

With a 9-package monorepo spanning Docusaurus docs, Next.js apps, TypeScript libraries, and Discord/API services, full workspace rebuilds are slow and I/O-intensive. Currently, pnpm -r build compiles all packages sequentially regardless of what changed, taking 30+ seconds even when only one file is modified.

Problem

  1. No incremental compilation: Each pnpm build runs tsc fresh, recompiling all TypeScript files
  2. No build cache: TypeScript doesn't persist compilation state between runs
  3. No dependency awareness: Packages rebuild even if their dependencies didn't change
  4. Slow iteration: Developers wait for full builds during development cycles

This becomes critical in a Stellar/Soroban migration where frequent iterative changes are expected.

Expected Outcome

  • TypeScript incremental mode enabled across all packages
  • Build times reduced for incremental changes (3-5s vs. 30+s)
  • Clear build cache strategy documented
  • Developer experience improved for fast iteration

Suggested Implementation

  1. Enable incremental compilation in tsconfig.base.json:

    {
      "compilerOptions": {
        "incremental": true,
        "tsBuildInfoFile": "./dist/.tsbuildinfo",
        "composite": false
      }
    }
  2. (Optional) Use TypeScript project references for monorepo builds:

    • Create a root tsconfig.json with references to each package's tsconfig.json
    • Use tsc -b (build mode) instead of tsc to leverage project references
    • Enables true incremental, dependency-aware builds
  3. Add .tsbuildinfo to .gitignore (build artifact)

  4. Update build scripts:

    "build": "tsc -b",
    "build:clean": "rm -rf dist .tsbuildinfo && tsc"
  5. Benchmark:

    time pnpm -r build  # First run: full compile
    echo '// change' >> packages/contracts/src/index.ts
    time pnpm -r build  # Second run: incremental
  6. Document in monorepo README.md:

    ## Build Caching
    - Incremental builds are enabled by default
    - First build is slower; subsequent builds reuse cached data
    - Clean builds: `pnpm build:clean`

Acceptance Criteria

  • Incremental compilation is enabled in tsconfig.base.json (or each package's tsconfig)
  • First full build succeeds; .tsbuildinfo files are created in each package's dist/
  • Incremental builds (after minor changes) complete in <10 seconds
  • .tsbuildinfo is ignored by Git
  • Build documentation updated with caching strategy
  • Team verifies faster iteration cycle during development

Affected Files/Directories

  • tsconfig.base.json or each packages/*/tsconfig.json
  • .gitignore (add .tsbuildinfo)
  • README.md (document build caching)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Third CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsadvancedAdvanced difficulty tasks requiring significant domain knowledge and implementation effortbuildBuild configuration, compilation, packaging, and build-system improvementsperformancePerformance optimization or latency/throughput improvement work

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions