fix(vite-plugin-angular): support build.lib + dedupe diagnostics on the Angular Compilation API path#2353
Conversation
…he Angular Compilation API path The `useAngularCompilationAPI` path was incompatible with Vite's library mode and duplicated diagnostics across every emitted file. build.lib (#2324): - Stop forcing `declaration: true` / `inlineSources: true` for lib builds on the compilation API path. That path can't write `.d.ts` to disk, and `@angular/build`'s `emitAffectedFiles()` keys outputs by source file (last-write-wins), so the emitted `.d.ts` overwrote the `.js` and was fed back to Vite as the module source. The unpaired `inlineSources` also tripped TS5051 since this path forces `sourceMap` off. - Force whole-program transpilation (`isolatedModules: false`) for emit so TypeScript strips type annotations. `emitAffectedFiles()` otherwise skips full TS emit when `isolatedModules` is on with no sourcemap, leaving types like `App_Factory(__ngFactoryType__: any)` that Rolldown can't parse. Currently-working builds are unaffected; only the otherwise-broken case changes. The user's editor/`tsc` still enforces `isolatedModules`. - Legacy path: only set `inlineSources` when a sourcemap option is present, avoiding the same unpaired-option inconsistency. Diagnostics (#2317): - Group `diagnoseFiles()` results by their source file and attach each to its own emitted file, so every diagnostic is reported once instead of the whole global list being duplicated across every emitted file (an N×M explosion). The `file:line:column` from `location` is now folded into the message, restoring the origin that was previously discarded. - Extract the grouping into `groupDiagnosticsByFile` and unit-test it. Closes #2324 Closes #2317 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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR fixes two critical bugs in the experimental Angular Compilation API plugin. First, it introduces a Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
…pilation-api # Conflicts: # packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
PR Checklist
The
experimental.useAngularCompilationAPIpath was incompatible with Vite's library mode (build.lib) and duplicated diagnostics across every emitted file. This fixes both.Closes #2324
Closes #2317
Affected scope
Recommended merge strategy for maintainer [optional]
What is the new behavior?
All changes are scoped to the
useAngularCompilationAPI(Angular Compilation API) path inangular-vite-plugin.ts.build.libcompatibility (#2324)declaration: true/inlineSources: truefor library builds on this path. The path has no mechanism to write.d.tsto disk, and@angular/build'semitAffectedFiles()keys outputs by source file (last-write-wins) — so the emitted.d.tsoverwrote the.jscontent and was returned to Vite as the module source (export declare class …→[PARSE_ERROR]). The unpairedinlineSourcesalso tripped TS5051, because this path forcessourceMapoff.isolatedModules: false) for emit so TypeScript strips type annotations.emitAffectedFiles()otherwise skips full TS emit whenisolatedModulesis enabled with no sourcemap, leaving annotations likeApp_Factory(__ngFactoryType__: any)that Rolldown can't parse. This is side-effect-free for currently-working builds (any build withisolatedModules: truewas already failing); the user's editor/tscstill enforcesisolatedModules.inlineSourceswhen a sourcemap option is present, avoiding the same unpaired-option inconsistency.Diagnostics dedup + location (#2317)
diagnoseFiles()returns whole-program diagnostics that were attached to every emitted file, then re-emitted per file intransform— an N×M explosion (e.g. 485 warnings × 85 files ≈ 41k log lines). Diagnostics are now grouped by their source file and attached only to that file, so each is reported exactly once.file:line:columnfrom each diagnostic'slocationis now folded into the message, restoring the origin that was previously discarded (warnings showed text only).groupDiagnosticsByFilehelper.Test plan
nx format:check(prettier--checkon the changed files — clean)pnpm build(built the affected package vianx build vite-plugin-angular— succeeds)pnpm test(nx test vite-plugin-angular— 1165 passed, incl. 6 newgroupDiagnosticsByFiletests)Manual verification ran real
vite build --mode productionwith the rebuilt plugin across a matrix:build.libisolatedModulestrue: any)truetrueFor #2317, a project with two components each carrying an unused standalone import produced exactly one
NG8113per file (e.g.a.component.ts:3:50: NG8113: All imports are unused) across 245 emitted modules — previously this duplicated per emitted file.Does this PR introduce a breaking change?
Other information
The
isolatedModules: truetype-stripping issue surfaced while fixing #2324 and also affected the non-build.libcompilation API path; it is fixed here for both.🤖 Generated with Claude Code