@@ -20,6 +20,7 @@ import {EsmRenderer} from '../rendering/esm_renderer';
2020import { FileInfo , Renderer } from '../rendering/renderer' ;
2121
2222import { checkMarkerFile , writeMarkerFile } from './build_marker' ;
23+ import { BundleInfo , createBundleInfo } from './bundle' ;
2324import { EntryPoint , EntryPointFormat } from './entry_point' ;
2425
2526/**
@@ -70,27 +71,40 @@ export class Transformer {
7071 const host = ts . createCompilerHost ( options ) ;
7172 const rootDirs = this . getRootDirs ( host , options ) ;
7273 const isCore = entryPoint . name === '@angular/core' ;
73- const r3SymbolsPath = isCore ? this . findR3SymbolsPath ( dirname ( entryPointFilePath ) ) : null ;
74+ const r3SymbolsPath =
75+ isCore ? this . findR3SymbolsPath ( dirname ( entryPointFilePath ) , 'r3_symbols.js' ) : null ;
7476 const rootPaths = r3SymbolsPath ? [ entryPointFilePath , r3SymbolsPath ] : [ entryPointFilePath ] ;
7577 const packageProgram = ts . createProgram ( rootPaths , options , host ) ;
76- console . time ( entryPoint . name + '(dtsmappper creation)' ) ;
78+ const r3SymbolsFile = r3SymbolsPath && packageProgram . getSourceFile ( r3SymbolsPath ) || null ;
79+
80+ // Create the program for processing DTS files if enabled for this format.
7781 const dtsFilePath = entryPoint . typings ;
78- const dtsProgram = transformDts ? ts . createProgram ( [ entryPoint . typings ] , options , host ) : null ;
79- console . timeEnd ( entryPoint . name + '(dtsmappper creation)' ) ;
82+ let dtsProgram : ts . Program | null = null ;
83+ let r3SymbolsDtsFile : ts . SourceFile | null = null ;
84+ if ( transformDts ) {
85+ console . time ( `${ entryPoint . name } (dtsMapper creation)` ) ;
86+ const r3SymbolsDtsPath =
87+ isCore ? this . findR3SymbolsPath ( dirname ( dtsFilePath ) , 'r3_symbols.d.ts' ) : null ;
88+ const rootDtsPaths = r3SymbolsDtsPath ? [ dtsFilePath , r3SymbolsDtsPath ] : [ dtsFilePath ] ;
89+
90+ dtsProgram = ts . createProgram ( rootDtsPaths , options , host ) ;
91+ r3SymbolsDtsFile = r3SymbolsDtsPath && dtsProgram . getSourceFile ( r3SymbolsDtsPath ) || null ;
92+ console . timeEnd ( `${ entryPoint . name } (dtsMapper creation)` ) ;
93+ }
94+
95+ const bundle = createBundleInfo ( isCore , r3SymbolsFile , r3SymbolsDtsFile ) ;
8096 const reflectionHost = this . getHost ( isCore , format , packageProgram , dtsFilePath , dtsProgram ) ;
81- const r3SymbolsFile = r3SymbolsPath && packageProgram . getSourceFile ( r3SymbolsPath ) || null ;
8297
8398 // Parse and analyze the files.
8499 const { decorationAnalyses, switchMarkerAnalyses} =
85100 this . analyzeProgram ( packageProgram , reflectionHost , rootDirs , isCore ) ;
86101
87- console . time ( entryPoint . name + ' (rendering)' ) ;
102+ console . time ( ` ${ entryPoint . name } (rendering)` ) ;
88103 // Transform the source files and source maps.
89- const renderer = this . getRenderer (
90- format , packageProgram , reflectionHost , isCore , r3SymbolsFile , transformDts ) ;
104+ const renderer = this . getRenderer ( format , packageProgram , reflectionHost , bundle , transformDts ) ;
91105 const renderedFiles =
92106 renderer . renderProgram ( packageProgram , decorationAnalyses , switchMarkerAnalyses ) ;
93- console . timeEnd ( entryPoint . name + ' (rendering)' ) ;
107+ console . timeEnd ( ` ${ entryPoint . name } (rendering)` ) ;
94108
95109 // Write out all the transformed files.
96110 renderedFiles . forEach ( file => this . writeFile ( file ) ) ;
@@ -125,17 +139,15 @@ export class Transformer {
125139 }
126140
127141 getRenderer (
128- format : string , program : ts . Program , host : NgccReflectionHost , isCore : boolean ,
129- rewriteCoreImportsTo : ts . SourceFile | null , transformDts : boolean ) : Renderer {
142+ format : string , program : ts . Program , host : NgccReflectionHost , bundle : BundleInfo ,
143+ transformDts : boolean ) : Renderer {
130144 switch ( format ) {
131145 case 'esm2015' :
132146 case 'fesm2015' :
133- return new EsmRenderer (
134- host , isCore , rewriteCoreImportsTo , this . sourcePath , this . targetPath , transformDts ) ;
147+ return new EsmRenderer ( host , bundle , this . sourcePath , this . targetPath , transformDts ) ;
135148 case 'esm5' :
136149 case 'fesm5' :
137- return new Esm5Renderer (
138- host , isCore , rewriteCoreImportsTo , this . sourcePath , this . targetPath , transformDts ) ;
150+ return new Esm5Renderer ( host , bundle , this . sourcePath , this . targetPath , transformDts ) ;
139151 default :
140152 throw new Error ( `Renderer for "${ format } " not yet implemented.` ) ;
141153 }
@@ -162,8 +174,8 @@ export class Transformer {
162174 writeFileSync ( file . path , file . contents , 'utf8' ) ;
163175 }
164176
165- findR3SymbolsPath ( directory : string ) : string | null {
166- const r3SymbolsFilePath = resolve ( directory , 'r3_symbols.js' ) ;
177+ findR3SymbolsPath ( directory : string , fileName : string ) : string | null {
178+ const r3SymbolsFilePath = resolve ( directory , fileName ) ;
167179 if ( existsSync ( r3SymbolsFilePath ) ) {
168180 return r3SymbolsFilePath ;
169181 }
@@ -181,7 +193,7 @@ export class Transformer {
181193 } ) ;
182194
183195 for ( const subDirectory of subDirectories ) {
184- const r3SymbolsFilePath = this . findR3SymbolsPath ( resolve ( directory , subDirectory ) ) ;
196+ const r3SymbolsFilePath = this . findR3SymbolsPath ( resolve ( directory , subDirectory ) , fileName ) ;
185197 if ( r3SymbolsFilePath ) {
186198 return r3SymbolsFilePath ;
187199 }
0 commit comments