feat(vite): augment library .d.ts with Ivy type declarations (#104)#341
Merged
Conversation
Library builds (`compilationMode: 'partial'`) now emit Angular's Ivy `.d.ts` type declarations (`static ɵfac`, `static ɵcmp`, …) so consumers get full template type-checking against a published library. The compiler already returns these per-class members on the transform result (`dtsDeclarations`); this wires them through the Vite plugin. A new post-enforce `dtsPlugin` collects declarations during `transform` and, in `generateBundle`, splices them into the `.d.ts` assets emitted by a separate declaration generator (rolldown-plugin-dts, vite-plugin-dts, tsdown, tsc), adding the required `import * as i0 from "@angular/core"`. The plugin does not generate the base `.d.ts` itself — it augments existing ones. No-op outside partial mode. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b97478d13d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Key the collected Ivy `.d.ts` declarations by module id instead of class name so `vite build --watch` can drop a module's prior entries before re-transforming it. Eviction runs ahead of the quick decorator early-return, so removing a decorator no longer leaves stale `ɵfac`/`ɵcmp` metadata to be re-injected into a now-plain class. generateBundle flattens module entries into a class-name map (last write wins), matching prior behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Brooooooklyn
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #104 — library
.d.tssupport at the plugin layer.When building an Angular library with
compilationMode: 'partial', the plugin now augments the emitted.d.tswith Angular's Ivy type declarations (static ɵfac,static ɵcmp, …) so downstream consumers get full template type-checking against the published library.The compiler already returns these per-class members on the transform result (
dtsDeclarations, added in #86/#101); this PR wires them through the Vite plugin.How it works
transform(partial mode only),result.dtsDeclarationsare collected, keyed by class name.dtsPlugin(enforce: 'post') runs ingenerateBundle, after the user's declaration generator has emitted its.d.tsassets, and splices the members into the matching classes — addingimport * as i0 from "@angular/core"where needed.compilationMode: 'partial'.The plugin does not generate the base
.d.tsitself — a declaration generator (rolldown-plugin-dts,vite-plugin-dts,tsdown, ortsc) produces them; we augment them.Changes
vite-plugin/utils/dts.ts—injectDtsDeclarationsinjector (idempotent; skips unmatched classes; preserves leading triple-slash refs).vite-plugin/index.ts— collect declarations duringtransform; new post-enforcedtsPluginaugmenting.d.tsbundle assets.test/dts.test.ts— 7 tests, including an end-to-end run through the real Rust compiler.README.md— "Library builds (.d.ts)" section.Notes
oxfmt,oxlint).🤖 Generated with Claude Code