Skip to content

fix(vite-plugin-angular): respect explicit declaration:false in lib-mode builds#2352

Merged
brandonroberts merged 1 commit into
betafrom
fix/2348-dts-written-to-source
May 30, 2026
Merged

fix(vite-plugin-angular): respect explicit declaration:false in lib-mode builds#2352
brandonroberts merged 1 commit into
betafrom
fix/2348-dts-written-to-source

Conversation

@brandonroberts

Copy link
Copy Markdown
Member

PR Checklist

Closes #2348

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?

@analogjs/vite-plugin-angular no longer writes generated .d.ts files into an app's source directory.

Vite's library mode (build.lib) is also used by application bundlers such as WXT for their background.ts/content.ts entrypoints (not by the popup, which is a normal HTML app build — matching the reported asymmetry). The plugin treated any build.lib build as an Angular library build and force-enabled declaration emit, overriding the user's declaration: false. For a path-mapped workspace library imported from such an entrypoint, the source file lives outside the project root, so its relative-to-root path (../../libs/...) escaped outDir and the declarations were written back into the app source tree (e.g. apps/testbed/libs/testbed/util-protocol/index.d.ts).

Changes:

  1. Respect the user's declaration setting. Removed the hard declaration: false override in readConfiguration so the resolved tsconfig value flows through, and only auto-enable declarations for lib builds when the user hasn't explicitly set declaration: false (config.build?.lib && tsCompilerOptions['declaration'] !== false), in both the Angular Compilation API path and the legacy builder.emit path.
  2. Scope the declaration capture. Skip any .d.ts whose source file lives outside the project root, so a path-mapped library's declarations can never be written back into the source tree.

No regression for conventional library builds: lib builds resolve tsconfig.lib.json (which sets declaration: true by convention), so they continue to emit. An unspecified declaration resolves to undefined, which still enables emit. The only behavior change is that an effective declaration: false is now respected instead of force-overridden — which is the fix.

Test plan

  • nx format:check
  • pnpm build
  • pnpm test
  • Manual verification

Note: dependencies were not installed in my working checkout, so the suite has not been run locally yet — relying on CI / maintainer verification.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Root cause: config.build.lib was overloaded as the signal for "Angular library publish build," but it only means "Vite library bundle," which app bundlers legitimately use for sub-entrypoints.

🤖 Generated with Claude Code

@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit c768543
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/6a1b28fdd20056000834bcea
😎 Deploy Preview https://deploy-preview-2352--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-docs ready!

Name Link
🔨 Latest commit c768543
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/6a1b28fd22e2db00086ca1d6
😎 Deploy Preview https://deploy-preview-2352--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-app ready!

Name Link
🔨 Latest commit c768543
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/6a1b28fd1c9178000832fbfb
😎 Deploy Preview https://deploy-preview-2352--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: 54369edf-f2ea-4915-9dcb-13d30afc5021

📥 Commits

Reviewing files that changed from the base of the PR and between e839674 and c768543.

📒 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

The plugin now respects an explicit declaration: false in user tsconfig for both the Angular Compilation API and non-Compilation-API paths. For library builds, declaration-related compiler options are only enabled when declaration !== false. The emit write-callback filters .d.ts outputs that would escape the project root (absolute paths or containing ..) and resolves declaration output paths under config.build.outDir.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title follows Conventional Commit style with supported scope (vite-plugin-angular) and accurately summarizes the main fix: respecting explicit declaration:false in lib-mode builds.
Description check ✅ Passed Description comprehensively explains the issue, root cause, changes made, and test plan. It clearly relates to the changeset covering the fix for respecting declaration settings and scoping declaration capture.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #2348: stops force-overriding the user's declaration setting and scopes declaration capture to prevent .d.ts files from being written into app source directories when libraries are imported from lib-mode builds.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #2348: TypeScript compiler option handling for declaration emit and declaration file path filtering. No unrelated modifications detected.

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

@github-actions github-actions Bot added the scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular label May 30, 2026
…ode builds

Vite's library mode (`build.lib`) is also used by app bundlers such as WXT
for their `background.ts`/`content.ts` entrypoints. The plugin treated any
`build.lib` build as an Angular library build and force-enabled declaration
emit, writing generated `.d.ts` files. For a path-mapped workspace library
imported from such an entrypoint, the relative-to-root path escaped `outDir`
and the declarations were written back into the app source tree.

Respect an explicit `declaration: false` from the resolved tsconfig instead of
force-overriding it, so app builds going through Vite lib mode opt out of
declaration emit. Conventional library builds resolve `tsconfig.lib.json`
(which sets `declaration: true`) and are unaffected; an unspecified value still
enables emit. Also guard the declaration capture against source files outside
the project root so they can never be written back into the source tree.

Closes #2348

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@brandonroberts brandonroberts force-pushed the fix/2348-dts-written-to-source branch from e839674 to c768543 Compare May 30, 2026 18:14
@brandonroberts brandonroberts merged commit dfa4c95 into beta May 30, 2026
24 checks passed
@brandonroberts brandonroberts deleted the fix/2348-dts-written-to-source branch May 30, 2026 18:39
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

Development

Successfully merging this pull request may close these issues.

vite-plugin-angular writes d.ts files into WXT app source directory

1 participant