fix(vite-plugin-angular): respect explicit declaration:false in lib-mode builds#2352
Conversation
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-docs 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)
📝 WalkthroughWalkthroughThe plugin now respects an explicit 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 |
…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>
e839674 to
c768543
Compare
PR Checklist
Closes #2348
Affected scope
Recommended merge strategy for maintainer [optional]
What is the new behavior?
@analogjs/vite-plugin-angularno longer writes generated.d.tsfiles into an app's source directory.Vite's library mode (
build.lib) is also used by application bundlers such as WXT for theirbackground.ts/content.tsentrypoints (not by the popup, which is a normal HTML app build — matching the reported asymmetry). The plugin treated anybuild.libbuild as an Angular library build and force-enabled declaration emit, overriding the user'sdeclaration: 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/...) escapedoutDirand the declarations were written back into the app source tree (e.g.apps/testbed/libs/testbed/util-protocol/index.d.ts).Changes:
declarationsetting. Removed the harddeclaration: falseoverride inreadConfigurationso the resolved tsconfig value flows through, and only auto-enable declarations for lib builds when the user hasn't explicitly setdeclaration: false(config.build?.lib && tsCompilerOptions['declaration'] !== false), in both the Angular Compilation API path and the legacybuilder.emitpath..d.tswhose 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 setsdeclaration: trueby convention), so they continue to emit. An unspecifieddeclarationresolves toundefined, which still enables emit. The only behavior change is that an effectivedeclaration: falseis now respected instead of force-overridden — which is the fix.Test plan
nx format:checkpnpm buildpnpm testDoes this PR introduce a breaking change?
Other information
Root cause:
config.build.libwas 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