From efa59eefb15cdaa0be409576f97fe28f4413be81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjam=C3=ADn=20Vicente?= Date: Sun, 8 Nov 2026 19:45:37 -0300 Subject: [PATCH] fix(vite): add Ivy members to .d.ts chunks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dts plugin only augmented declaration outputs of type `asset`, but rolldown-plugin-dts (and so tsdown) emits declarations as chunks. The published `.d.ts` then had no `ɵfac` / `ɵcmp` members, and Angular rejected the library's standalone components (NG2012: "Component imports must be standalone components, directives, pipes, or must be NgModules"). Augment `.d.ts` chunks through their `code`, and assets through their `source` as before. Fixes #681 --- napi/angular-compiler/test/dts.test.ts | 22 ++++++++++++++++++ napi/angular-compiler/vite-plugin/index.ts | 26 ++++++++++++++-------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/napi/angular-compiler/test/dts.test.ts b/napi/angular-compiler/test/dts.test.ts index 3337a997a..3834a9b9c 100644 --- a/napi/angular-compiler/test/dts.test.ts +++ b/napi/angular-compiler/test/dts.test.ts @@ -526,6 +526,28 @@ describe('angular() dts plugin (#104)', () => { expect(out).toContain('static ɵcmp: i0.ɵɵComponentDeclaration { + const { transform, dts } = getPlugins('partial') + await runTransform(transform) + + const js = 'export class LibButtonComponent {}\n' + const bundle = { + 'index.d.mts': { + type: 'chunk' as const, + fileName: 'index.d.mts', + code: 'export declare class LibButtonComponent {\n}\n', + }, + 'index.mjs': { type: 'chunk' as const, fileName: 'index.mjs', code: js }, + } + await runGenerateBundle(dts, bundle) + + const out = bundle['index.d.mts'].code + expect(out).toContain('import * as i0 from "@angular/core";') + expect(out).toContain('static ɵfac: i0.ɵɵFactoryDeclaration { const { transform, dts } = getPlugins('full') await runTransform(transform) diff --git a/napi/angular-compiler/vite-plugin/index.ts b/napi/angular-compiler/vite-plugin/index.ts index 0b4230fef..2a0b660e4 100644 --- a/napi/angular-compiler/vite-plugin/index.ts +++ b/napi/angular-compiler/vite-plugin/index.ts @@ -1777,17 +1777,25 @@ export function angular(options: PluginOptions = {}): Plugin[] { const declarations = Array.from(byClassName.values()) for (const file of Object.values(bundle)) { - if (file.type !== 'asset') continue if (!/\.d\.[cm]?ts$/.test(file.fileName)) continue - const source = - typeof file.source === 'string' - ? file.source - : Buffer.from(file.source).toString('utf-8') - - const augmented = injectDtsDeclarations(source, declarations) - if (augmented !== source) { - file.source = augmented + // rolldown-plugin-dts (and so tsdown) emits declarations as + // chunks; other generators emit them as assets. + if (file.type === 'chunk') { + const augmented = injectDtsDeclarations(file.code, declarations) + if (augmented !== file.code) { + file.code = augmented + } + } else if (file.type === 'asset') { + const source = + typeof file.source === 'string' + ? file.source + : Buffer.from(file.source).toString('utf-8') + + const augmented = injectDtsDeclarations(source, declarations) + if (augmented !== source) { + file.source = augmented + } } } },