Repository navigation
[TypeGen]: clear stale manifests when generation becomes empty - #23
Conversation
MistyKuu
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Summary
Removing the final
[GenerateTypes]attribute or fluent.WithGeneratedTypes(...)registration leaves the previous on-disk manifest inobj. 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
How was this verified?
289 passed, 0 failed, 0 skipped in the full TypeGen Release suite.
Five package-level regression cases pack the actual generator and abstractions, install them into isolated consumer projects, and preserve
objacross 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 --checkpasses.Checklist
master, focused on a single changedocs/src/content/docs/[Package]: …prefix