Skip to content

build: stop touching generated types/routes on every build#209

Merged
antosubash merged 2 commits into
mainfrom
types-fix
May 20, 2026
Merged

build: stop touching generated types/routes on every build#209
antosubash merged 2 commits into
mainfrom
types-fix

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

  • scripts/extract-ts-types.mjs and scripts/extract-routes.mjs now skip writes when the rendered output already matches the file on disk, so a no-op build no longer bumps mtimes on modules/*/src/*/types.ts and routes.ts (which was triggering downstream Vite/MSBuild rebuilds).
  • biome.json adds the generated types.ts and both routes.ts files to files.includes ignores. Biome had been wrapping long arrow expressions in routes.ts; the generator then re-flattened them, leaving every working tree dirty after a fresh build. Committed routes.ts copies are realigned with the generator's output.
  • sm new project now ships the same scripts (embedded via EmbeddedResource, matching the validate-pages.mjs pattern) and adds generate:types / generate:routes npm scripts wired to the scaffolded layout (src/<Project>.Host, src/modules).
  • Fixed a latent bug in ProjectTemplates.BiomeJson(): the single-line string-replace for files.includes had silently been failing since the monorepo's biome.json became multi-line, so scaffolded projects were inheriting modules/**, packages/**, template/** paths that don't exist in their layout. Replaced with a regex swap that emits the correct scaffolded paths plus the new ignores.

Verification

  • Ran two back-to-back dotnet builds; mtimes on all 13 types.ts and both routes.ts files are byte-identical across runs.
  • Manually scaffolded DemoApp via sm new project; diff'd the generated scripts/extract-*.mjs against the canonical files — byte-identical (single source of truth via embedded resources).
  • Local CI passed: biome check (13/13), full frontend build, dotnet build (0 warnings), dotnet test --no-build (19 assemblies, 1024 tests), npm run test:smoke (47 specs).

Test plan

  • CI green on PR
  • Reviewer spot-checks that fresh-clone-then-build doesn't show routes.ts modified in git status

The extract-ts-types.mjs and extract-routes.mjs scripts unconditionally
rewrote per-module types.ts and routes.ts on every build, bumping mtimes
and triggering downstream Vite rebuilds. Add a writeIfChanged guard so
each file is touched only when its content actually differs.

Also stop Biome from reformatting the generated routes.ts (Biome wrapping
long arrow expressions then the generator re-flattening them was producing
a permanent dirty working tree after a fresh build). The committed routes.ts
copies are realigned with the generator's output.
Embed scripts/extract-ts-types.mjs and scripts/extract-routes.mjs as
EmbeddedResources (matching the validate-pages.mjs pattern) and write
them into the scaffold's scripts/ directory. Add matching generate:types
and generate:routes npm scripts to the scaffolded root package.json.

Also fix the scaffolded biome.json: BiomeJson() previously did a fragile
single-line string-replace on the includes array that had silently failed
since the monorepo biome.json became multi-line. Replace the entire
files.includes block via regex and emit paths that match the scaffolded
layout (src/modules/, src/*.Host/ClientApp/), including ignores for the
generated types.ts and routes.ts files so Biome doesn't fight the
generator in scaffolded projects either.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3148227
Status: ✅  Deploy successful!
Preview URL: https://e2a3a568.simplemodule-website.pages.dev
Branch Preview URL: https://types-fix.simplemodule-website.pages.dev

View logs

@antosubash antosubash merged commit 62bac73 into main May 20, 2026
6 checks passed
@antosubash antosubash deleted the types-fix branch May 20, 2026 15:25
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.

1 participant