fix(vite-plugin-angular): aggregate and locate template diagnostics on the default compilation path#2354
Conversation
…n the default compilation path The default (non Compilation API) path reported diagnostics one file at a time from the `transform` hook and threw on the first errored file, so a production build aborted before the remaining files were ever checked, and build mode collected no diagnostics at all. Reported messages also dropped the source location and mishandled message chains (`[object Object]` warnings, truncated error chains). Accumulate diagnostics across every emitted file and report them together: - Collect per-file diagnostics for every emitted file (not just watch mode) and report them once in a new `buildEnd` hook instead of aborting at the first errored module. `transform` still reports per-module in watch/serve so the dev overlay points at the edited file. - Format every diagnostic as `file:line:column: message`, matching the Compilation API path's `groupDiagnosticsByFile` output. Location-less diagnostics fall back to the bare message. - Flatten message chains via `flattenDiagnosticMessageText` for both errors and warnings, fixing the `[object Object]` warning output. Reporting is unconditional; which diagnostics exist is still governed by `disableTypeChecking` inside `getDiagnosticsForSourceFile` (syntactic-only by default, full semantic + Angular template when type checking is enabled), so the default config now surfaces syntax errors at build time with locations while the type-checking opt-in reaches parity with the Compilation API path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThis PR refactors diagnostic reporting in the Angular Vite plugin to support deferred build-mode reporting. Two new utility functions are exported: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Checklist
Diagnostics on the default (non Compilation API) compilation path were reported one file at a time from the
transformhook, which threw on the first errored file — so a production build aborted before the remaining files were ever checked, and build mode collected no diagnostics at all. Reported messages also discarded the source location and mishandledts.DiagnosticMessageChain(warnings rendered as[object Object], error chains were truncated).Closes #
Affected scope
vite-plugin-angularRecommended merge strategy for maintainer [optional]
What is the new behavior?
Diagnostics are now accumulated across every emitted file and reported together, at parity with the Compilation API path:
buildEndhook, instead of aborting the build at the first errored module.transformstill reports per-module in watch/serve so the dev overlay points at the edited file.file:line:column: message, mirroring the Compilation API path'sgroupDiagnosticsByFile. Location-less (program-wide / option) diagnostics fall back to the bare message.flattenDiagnosticMessageText, fixing the[object Object]warning output and truncated error chains.Reporting is unconditional; which diagnostics exist is still governed by
disableTypeCheckinginsidegetDiagnosticsForSourceFile— syntactic-only by default, full semantic + Angular template diagnostics when type checking is enabled. So with the default config, builds now surface syntax errors withfile:line:column, and thedisableTypeChecking: falseopt-in reaches full parity with the Compilation API path.Test plan
Ran for the affected package:
npx nx test vite-plugin-angular— 1171 passed, 23 skipped (incl. 6 new unit tests forcollectEmittedDiagnosticsandformatDiagnosticWithLocation)npx tsc --noEmit -p packages/vite-plugin-angular/tsconfig.lib.json— cleannpx prettier --checkon the changed files — cleannx format:checkpnpm buildpnpm testManual verification
(Full-repo
format:check/buildand end-to-end manual verification left for CI / maintainer.)Does this PR introduce a breaking change?
With the default config (
disableTypeChecking: true), build mode now surfaces syntactic errors that were previously emitted silently. This is a correctness fix rather than a breaking change: a file with a TypeScript syntax error already produces broken output and a non-running app, so failing the build reports an existing failure instead of breaking working software. Semantic/template type-checking remains opt-in and unchanged by default.Other information
The aggregation and
buildEndreporting are shared by both compilation paths, so the Compilation API path also moves from per-filetransformreporting to aggregatedbuildEndreporting in build mode.🤖 Generated with Claude Code