Skip to content

[TypeGen]: clear stale manifests when generation becomes empty - #23

Merged
MistyKuu merged 3 commits into
MistyKuu:masterfrom
RejectKid:fix-empty-typegen-manifest
Nov 19, 2026
Merged

MistyKuu merged 3 commits into
MistyKuu:masterfrom
RejectKid:fix-empty-typegen-manifest

Conversation

@RejectKid

@RejectKid RejectKid commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removing the final [GenerateTypes] attribute or fluent .WithGeneratedTypes(...) registration leaves the previous on-disk manifest in obj. The MSBuild task replays that manifest, so deleted TypeScript/Zod files return on subsequent builds.

Successful generation passes now emit a valid zero-file manifest even when there are no discovered models or the requested emitters produce no files. This allows both the live-write path and the existing MSBuild task to sweep previously generated files using the current directory marker and banner ownership rules. Handwritten files remain untouched. Syntax errors and fatal TypeGen diagnostics preserve prior output. The empty-run check uses syntax trees so missing symbols supplied by another generator do not prevent cleanup. Endpoint discovery runs only when OpenAPI or TanStack Query output is requested.

Document the cleanup behavior, a one-time rebuild after upgrading, and the existing IDE/file-I/O and shared-output-directory limitations. The existing MSBuild task already processes zero-file manifests. Move the reverse-proxy configuration note from the root README to the TypeGen README as requested in PR #22.

Affected package(s)

ZibStack.NET.TypeGen and its configuration documentation.

Type of change

  • Bug fix
  • Generator / generated-code behavior change

How was this verified?

289 passed, 0 failed, 0 skipped in the full TypeGen Release suite.

$env:MSBUILDDISABLENODEREUSE = '1'
$env:DOTNET_CLI_USE_MSBUILD_SERVER = '0'
dotnet test packages/ZibStack.NET.TypeGen/tests/ZibStack.NET.TypeGen.Tests/ZibStack.NET.TypeGen.Tests.csproj -c Release

Five package-level regression cases pack the actual generator and abstractions, install them into isolated consumer projects, and preserve obj across successive builds. The removal cases reproduced the original bug, and the new GeneratedRegex case also failed before the review fix.

Coverage includes attribute and fluent removal, the empty-emitter case, partial removal while other types remain, output-directory renames, deleted output staying deleted, handwritten file preservation, stable output timestamps, and compiler/configurator/generic-type/Zod-validation failure paths. MSBuild-only consumers disable analyzer-side writes; the live-write consumer verifies cleanup occurs before MSBuild's sweep.

Local test execution used a shortened process-scoped Windows PATH so the existing TypeScript/Zod tests could resolve npx. The Release build has existing nullable and xUnit analyzer warnings; no new warnings were introduced. git diff --check passes.

Checklist

  • Branched from latest upstream master, focused on a single change
  • Tests added or updated, including actual package/MSBuild integration
  • Docs updated under docs/src/content/docs/
  • Build is clean — no new warnings
  • Commit subjects use the [Package]: … prefix

@MistyKuu MistyKuu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the package-level tests are great. One blocker before this can go in.

The empty-run guard never fires in projects that use another source generator. compilation.GetDiagnostics() runs on the compilation the generator receives, which does not contain the output of other generators. Any project with [GeneratedRegex], [LoggerMessage], or types produced by ZibStack.NET.Dto has errors there (CS8795 for unimplemented partial methods, CS0246 for generated types), so the cleanup is skipped and the stale manifest is replayed.

Reproduced with packages packed from this branch (net10.0 consumer, two builds, obj kept):

Consumer After removing the last [GenerateTypes]
TypeGen only FileCount = 0, generated/Example.ts removed
TypeGen + one [GeneratedRegex] partial method FileCount = 1, generated/Example.ts still there

Most real ZibStack consumers combine several generators, so the fix would not reach them.

IDE cost. The package flows transitively (no PrivateAssets/developmentDependency), so every referencing project with no models now hits the empty-result path on every generator run, and in this case runs a full GetDiagnostics() binding pass each time. Removing the model.Classes.Count == 0 early return also means each of those projects now gets a manifest plus EndpointDiscovery.Populate.

Suggestion: check only parse errors (compilation.SyntaxTrees.Any(t => t.GetDiagnostics(ct).Any(d => d.Severity == DiagnosticSeverity.Error))) together with hasGenerationErrors. It is cheap, other generators do not affect it, and all four "failed generation" cases in EmptyManifestBuildTests still hold (syntax error, duplicate configurator, generic type, Zod validation). Please add a removal case with a [GeneratedRegex] in the consumer so this stays covered.

@MistyKuu MistyKuu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all addressed: the syntax-tree check keeps cleanup working alongside other generators, the GeneratedRegex case covers it, and endpoint discovery now runs only for OpenAPI and TanStack Query. Merging.

@MistyKuu
MistyKuu merged commit 3ff1452 into MistyKuu:master Nov 19, 2026
1 check passed
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.

2 participants