Skip to content

fix(vite-plugin-angular): support build.lib + dedupe diagnostics on the Angular Compilation API path#2353

Merged
brandonroberts merged 2 commits into
betafrom
fix/2324-lib-mode-compilation-api
May 30, 2026
Merged

fix(vite-plugin-angular): support build.lib + dedupe diagnostics on the Angular Compilation API path#2353
brandonroberts merged 2 commits into
betafrom
fix/2324-lib-mode-compilation-api

Conversation

@brandonroberts

Copy link
Copy Markdown
Member

PR Checklist

The experimental.useAngularCompilationAPI path 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

  • Primary scope: vite-plugin-angular
  • Secondary scopes: —

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

What is the new behavior?

All changes are scoped to the useAngularCompilationAPI (Angular Compilation API) path in angular-vite-plugin.ts.

build.lib compatibility (#2324)

  • No longer forces declaration: true / inlineSources: true for library builds on this path. The path has no mechanism to 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 content and was returned to Vite as the module source (export declare class …[PARSE_ERROR]). The unpaired inlineSources also tripped TS5051, because this path forces sourceMap off.
  • Forces whole-program transpilation (isolatedModules: false) for emit so TypeScript strips type annotations. emitAffectedFiles() otherwise skips full TS emit when isolatedModules is enabled with no sourcemap, leaving annotations like App_Factory(__ngFactoryType__: any) that Rolldown can't parse. This is side-effect-free for currently-working builds (any build with isolatedModules: true was already failing); the user's editor/tsc still enforces isolatedModules.
  • Legacy compilation path: only sets inlineSources when 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 in transform — 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.
  • The file:line:column from each diagnostic's location is now folded into the message, restoring the origin that was previously discarded (warnings showed text only).
  • Grouping logic extracted into an exported, unit-tested groupDiagnosticsByFile helper.

Test plan

  • nx format:check (prettier --check on the changed files — clean)
  • pnpm build (built the affected package via nx build vite-plugin-angular — succeeds)
  • pnpm test (nx test vite-plugin-angular — 1165 passed, incl. 6 new groupDiagnosticsByFile tests)
  • Manual verification

Manual verification ran real vite build --mode production with the rebuilt plugin across a matrix:

Path build.lib isolatedModules Result
Compilation API not set ✅ builds, type-free output
Compilation API true ✅ builds (was: TS5051 / : any)
Compilation API ❌ rollupOptions true ✅ builds
Legacy true ✅ builds (unregressed)

For #2317, a project with two components each carrying an unused standalone import produced exactly one NG8113 per 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?

  • Yes
  • No

Other information

The isolatedModules: true type-stripping issue surfaced while fixing #2324 and also affected the non-build.lib compilation API path; it is fixed here for both.

🤖 Generated with Claude Code

…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>
@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit dc91e2d
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/6a1b396122439a00070770fa
😎 Deploy Preview https://deploy-preview-2353--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit dc91e2d
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/6a1b39617e1d1d0008b6b4c7
😎 Deploy Preview https://deploy-preview-2353--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit dc91e2d
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/6a1b396142b6080008f92650
😎 Deploy Preview https://deploy-preview-2353--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e0ebda31-38b6-4f61-968a-bdc463ffd9a2

📥 Commits

Reviewing files that changed from the base of the PR and between 2b687d0 and dc91e2d.

📒 Files selected for processing (1)
  • packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts

📝 Walkthrough

Walkthrough

This PR fixes two critical bugs in the experimental Angular Compilation API plugin. First, it introduces a groupDiagnosticsByFile() utility that groups diagnostics by file and formats messages with location info (file:line:column: text), preventing the N×M duplication bug where global diagnostics were attached to every emitted file. Second, it corrects TypeScript compiler option handling: removes unconditional declaration/inlineSources mutations in lib-mode builds, adds logic to disable isolatedModules for non-test builds, and makes inlineSources conditional on sourceMap/inlineSourceMap to avoid TS5051 errors. Tests validate the diagnostic grouping utility across all scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commit style with supported package scope 'vite-plugin-angular' and clearly describes the two main fixes: build.lib support and diagnostic deduplication on the Angular Compilation API path.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing both fixes (#2324 and #2317), test results, manual verification matrix, and scope limitations to the Compilation API path.
Linked Issues check ✅ Passed All code objectives from #2324 and #2317 are met: build.lib compatibility via compiler option fixes and .d.ts filtering, diagnostics deduplication via grouping by file, location preservation via file:line:column folding into messages, and exported groupDiagnosticsByFile helper with unit tests.
Out of Scope Changes check ✅ Passed All changes are properly scoped to the useAngularCompilationAPI path with two minor exceptions: isolatedModules fix applies to both Compilation API variants (but needed for correctness), and legacy path inlineSources handling is adjusted only to match Compilation API constraints.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…pilation-api

# Conflicts:
#	packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
@github-actions github-actions Bot added the scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular label May 30, 2026
@brandonroberts brandonroberts merged commit 61e8a56 into beta May 30, 2026
24 checks passed
@brandonroberts brandonroberts deleted the fix/2324-lib-mode-compilation-api branch May 30, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular

Projects

None yet

1 participant