11import { BuildContext , BuildState , File } from './util/interfaces' ;
2+ import { changeExtension } from './util/helpers' ;
23import { Logger } from './logger/logger' ;
34import { getJsOutputDest } from './bundle' ;
5+ import { invalidateCache } from './rollup' ;
46import { dirname , extname , join , parse , resolve } from 'path' ;
57import { readFileSync , writeFile } from 'fs' ;
68
@@ -23,6 +25,9 @@ export function templateUpdate(event: string, htmlFilePath: string, context: Bui
2325 const successfullyUpdated = updateCorrespondingJsFile ( context , newTemplateContent , htmlFilePath ) ;
2426 bundleSourceText = replaceExistingJsTemplate ( bundleSourceText , newTemplateContent , htmlFilePath ) ;
2527
28+ // invaldiate any rollup bundles, if they're not using rollup no harm done
29+ invalidateCache ( ) ;
30+
2631 if ( successfullyUpdated && bundleSourceText ) {
2732 // awesome, all good and template updated in the bundle file
2833 const logger = new Logger ( `template update` ) ;
@@ -60,6 +65,11 @@ function updateCorrespondingJsFile(context: BuildContext, newTemplateContent: st
6065 const newContent = replaceExistingJsTemplate ( javascriptFile . content , newTemplateContent , existingHtmlTemplatePath ) ;
6166 if ( newContent !== javascriptFile . content ) {
6267 javascriptFile . content = newContent ;
68+ // set the file again to generate a new timestamp
69+ // do the same for the typescript file just to invalidate any caches, etc.
70+ context . fileCache . set ( javascriptFile . path , javascriptFile ) ;
71+ const typescriptFilePath = changeExtension ( javascriptFile . path , '.ts' ) ;
72+ context . fileCache . set ( typescriptFilePath , context . fileCache . get ( typescriptFilePath ) ) ;
6373 return true ;
6474 }
6575 }
0 commit comments