File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
packages/ngtools/webpack/src/ivy Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,16 @@ export function angularWebpackLoader(
7474 }
7575
7676 // Write the declaration file in the target dir
77- if ( result . declaration ) {
78- fs . writeFileSync ( this . resourcePath . replace ( '.ts' , '.d.ts' ) , result . declaration ) ;
77+ if ( result . declaration && fileEmitter . compilerOptions . declaration ) {
78+ let target = this . resourcePath . replace ( '.ts' , '.d.ts' ) ;
79+ if ( fileEmitter . compilerOptions . declarationDir ) {
80+ if ( ! fileEmitter . compilerOptions . baseUrl ) {
81+ throw new Error ( 'When declarationDir is specified, baseUrl is required as well' ) ;
82+ }
83+ const relDir = path . relative ( fileEmitter . compilerOptions . baseUrl , target ) ;
84+ target = path . join ( fileEmitter . compilerOptions . declarationDir , relDir ) ;
85+ }
86+ fs . writeFileSync ( target , result . declaration ) ;
7987 }
8088 callback ( undefined , resultContent , resultMap ) ;
8189 } )
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ export class AngularWebpackPlugin {
8585 private readonly requiredFilesToEmit = new Set < string > ( ) ;
8686 private readonly requiredFilesToEmitCache = new Map < string , EmitFileResult | undefined > ( ) ;
8787 private readonly fileEmitHistory = new Map < string , FileEmitHistoryItem > ( ) ;
88+ private compilerOptions ! : CompilerOptions ;
8889
8990 constructor ( options : Partial < AngularWebpackPluginOptions > = { } ) {
9091 this . pluginOptions = {
@@ -186,6 +187,7 @@ export class AngularWebpackPlugin {
186187
187188 // Setup and read TypeScript and Angular compiler configuration
188189 const { compilerOptions, rootNames, errors } = this . loadConfiguration ( ) ;
190+ this . compilerOptions = compilerOptions ;
189191
190192 // Create diagnostics reporter and report configuration file errors
191193 const diagnosticsReporter = createDiagnosticsReporter ( compilation , ( diagnostic ) =>
@@ -325,6 +327,8 @@ export class AngularWebpackPlugin {
325327 compilation . compiler . webpack . NormalModule . getCompilationHooks ( compilation ) . loader . tap (
326328 PLUGIN_NAME ,
327329 ( context ) => {
330+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
331+ fileEmitters ! . compilerOptions = this . compilerOptions ;
328332 const loaderContext = context as typeof context & {
329333 [ AngularPluginSymbol ] ?: FileEmitterCollection ;
330334 } ;
Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { CompilerOptions } from 'typescript' ;
10+
911export const AngularPluginSymbol : unique symbol = Symbol . for ( '@ngtools/webpack[angular-compiler]' ) ;
1012
1113export interface EmitFileResult {
@@ -37,6 +39,8 @@ export class FileEmitterRegistration {
3739export class FileEmitterCollection {
3840 #registrations: FileEmitterRegistration [ ] = [ ] ;
3941
42+ public compilerOptions ! : CompilerOptions ;
43+
4044 register ( ) : FileEmitterRegistration {
4145 const registration = new FileEmitterRegistration ( ) ;
4246 this . #registrations. push ( registration ) ;
You can’t perform that action at this time.
0 commit comments