@@ -18,7 +18,7 @@ import { Logger } from '../logger/logger';
18
18
import * as Constants from '../util/constants' ;
19
19
import { FileCache } from '../util/file-cache' ;
20
20
import { changeExtension , getStringPropertyValue , replaceAll } from '../util/helpers' ;
21
- import { BuildContext , DeepLinkConfigEntry , DeepLinkDecoratorAndClass , DeepLinkPathInfo } from '../util/interfaces' ;
21
+ import { BuildContext , ChangedFile , DeepLinkConfigEntry , DeepLinkDecoratorAndClass , DeepLinkPathInfo } from '../util/interfaces' ;
22
22
import { appendAfter , getClassDeclarations , getTypescriptSourceFile , getNodeStringContent , replaceNode } from '../util/typescript-utils' ;
23
23
24
24
import { transpileTsString } from '../transpile' ;
@@ -299,41 +299,55 @@ export function convertDeepLinkEntryToJsObjectString(entry: DeepLinkConfigEntry)
299
299
return `{ loadChildren: '${ entry . userlandModulePath } ${ LOAD_CHILDREN_SEPARATOR } ${ entry . className } ', name: '${ entry . name } ', segment: ${ segmentString } , priority: '${ entry . priority } ', defaultHistory: [${ defaultHistoryWithQuotes . join ( ', ' ) } ] }` ;
300
300
}
301
301
302
- export function updateAppNgModuleAndFactoryWithDeepLinkConfig ( context : BuildContext , deepLinkString : string ) {
302
+ export function updateAppNgModuleAndFactoryWithDeepLinkConfig ( context : BuildContext , deepLinkString : string , changedFiles : ChangedFile [ ] , isAot : boolean ) {
303
303
const appNgModulePath = getStringPropertyValue ( Constants . ENV_APP_NG_MODULE_PATH ) ;
304
- const appNgModuleFactoryPath = changeExtension ( appNgModulePath , '.ngfactory.ts' ) ;
305
304
const appNgModuleFile = context . fileCache . get ( appNgModulePath ) ;
306
- const appNgModuleFactoryFile = context . fileCache . get ( appNgModuleFactoryPath ) ;
305
+
307
306
if ( ! appNgModuleFile ) {
308
307
throw new Error ( `App NgModule ${ appNgModulePath } not found in cache` ) ;
309
308
}
310
- if ( ! appNgModuleFactoryFile ) {
311
- throw new Error ( `App NgModule Factory ${ appNgModuleFactoryPath } not found in cache` ) ;
312
- }
313
309
314
310
const updatedAppNgModuleContent = getUpdatedAppNgModuleContentWithDeepLinkConfig ( appNgModulePath , appNgModuleFile . content , deepLinkString ) ;
315
- const updatedAppNgModuleFactoryContent = getUpdatedAppNgModuleFactoryContentWithDeepLinksConfig ( appNgModuleFactoryFile . content , deepLinkString ) ;
316
311
317
- // update the typescript files in cache
318
312
context . fileCache . set ( appNgModulePath , { path : appNgModulePath , content : updatedAppNgModuleContent } ) ;
319
- context . fileCache . set ( appNgModuleFactoryPath , { path : appNgModuleFactoryPath , content : updatedAppNgModuleFactoryContent } ) ;
320
313
321
- // transpile the ts to js, and then update the cache
322
314
const appNgModuleOutput = transpileTsString ( context , appNgModulePath , updatedAppNgModuleContent ) ;
323
- const appNgModuleFactoryOutput = transpileTsString ( context , appNgModuleFactoryPath , updatedAppNgModuleFactoryContent ) ;
324
-
325
315
const appNgModuleSourceMapPath = changeExtension ( appNgModulePath , '.js.map' ) ;
326
316
const appNgModulePathJsFile = changeExtension ( appNgModulePath , '.js' ) ;
327
317
context . fileCache . set ( appNgModuleSourceMapPath , { path : appNgModuleSourceMapPath , content : appNgModuleOutput . sourceMapText } ) ;
328
318
context . fileCache . set ( appNgModulePathJsFile , { path : appNgModulePathJsFile , content : appNgModuleOutput . outputText } ) ;
329
319
330
- const appNgModuleFactorySourceMapPath = changeExtension ( appNgModuleFactoryPath , '.js.map' ) ;
331
- const appNgModuleFactoryPathJsFile = changeExtension ( appNgModuleFactoryPath , '.js' ) ;
332
- context . fileCache . set ( appNgModuleFactorySourceMapPath , { path : appNgModuleFactorySourceMapPath , content : appNgModuleFactoryOutput . sourceMapText } ) ;
333
- context . fileCache . set ( appNgModuleFactoryPathJsFile , { path : appNgModuleFactoryPathJsFile , content : appNgModuleFactoryOutput . outputText } ) ;
320
+ if ( changedFiles ) {
321
+ changedFiles . push ( {
322
+ event : 'change' ,
323
+ filePath : appNgModulePath ,
324
+ ext : extname ( appNgModulePath ) . toLowerCase ( )
325
+ } ) ;
326
+ }
334
327
335
- const appNgModuleFileDan = context . fileCache . get ( appNgModulePath ) ;
336
- const appNgModuleFactoryFileDan = context . fileCache . get ( appNgModuleFactoryPath ) ;
328
+ if ( isAot ) {
329
+ const appNgModuleFactoryPath = changeExtension ( appNgModulePath , '.ngfactory.ts' ) ;
330
+ const appNgModuleFactoryFile = context . fileCache . get ( appNgModuleFactoryPath ) ;
331
+ if ( ! appNgModuleFactoryFile ) {
332
+ throw new Error ( `App NgModule Factory ${ appNgModuleFactoryPath } not found in cache` ) ;
333
+ }
334
+ const updatedAppNgModuleFactoryContent = getUpdatedAppNgModuleFactoryContentWithDeepLinksConfig ( appNgModuleFactoryFile . content , deepLinkString ) ;
335
+ context . fileCache . set ( appNgModuleFactoryPath , { path : appNgModuleFactoryPath , content : updatedAppNgModuleFactoryContent } ) ;
336
+ const appNgModuleFactoryOutput = transpileTsString ( context , appNgModuleFactoryPath , updatedAppNgModuleFactoryContent ) ;
337
+
338
+ const appNgModuleFactorySourceMapPath = changeExtension ( appNgModuleFactoryPath , '.js.map' ) ;
339
+ const appNgModuleFactoryPathJsFile = changeExtension ( appNgModuleFactoryPath , '.js' ) ;
340
+ context . fileCache . set ( appNgModuleFactorySourceMapPath , { path : appNgModuleFactorySourceMapPath , content : appNgModuleFactoryOutput . sourceMapText } ) ;
341
+ context . fileCache . set ( appNgModuleFactoryPathJsFile , { path : appNgModuleFactoryPathJsFile , content : appNgModuleFactoryOutput . outputText } ) ;
342
+
343
+ if ( changedFiles ) {
344
+ changedFiles . push ( {
345
+ event : 'change' ,
346
+ filePath : appNgModuleFactoryPath ,
347
+ ext : extname ( appNgModuleFactoryPath ) . toLowerCase ( )
348
+ } ) ;
349
+ }
350
+ }
337
351
}
338
352
339
353
export function getUpdatedAppNgModuleContentWithDeepLinkConfig ( appNgModuleFilePath : string , appNgModuleFileContent : string , deepLinkStringContent : string ) {
0 commit comments