1
1
import { BuildContext , BuildState , File } from './util/interfaces' ;
2
+ import { changeExtension } from './util/helpers' ;
2
3
import { Logger } from './logger/logger' ;
3
4
import { getJsOutputDest } from './bundle' ;
5
+ import { invalidateCache } from './rollup' ;
4
6
import { dirname , extname , join , parse , resolve } from 'path' ;
5
7
import { readFileSync , writeFile } from 'fs' ;
6
8
@@ -23,6 +25,9 @@ export function templateUpdate(event: string, htmlFilePath: string, context: Bui
23
25
const successfullyUpdated = updateCorrespondingJsFile ( context , newTemplateContent , htmlFilePath ) ;
24
26
bundleSourceText = replaceExistingJsTemplate ( bundleSourceText , newTemplateContent , htmlFilePath ) ;
25
27
28
+ // invaldiate any rollup bundles, if they're not using rollup no harm done
29
+ invalidateCache ( ) ;
30
+
26
31
if ( successfullyUpdated && bundleSourceText ) {
27
32
// awesome, all good and template updated in the bundle file
28
33
const logger = new Logger ( `template update` ) ;
@@ -60,6 +65,11 @@ function updateCorrespondingJsFile(context: BuildContext, newTemplateContent: st
60
65
const newContent = replaceExistingJsTemplate ( javascriptFile . content , newTemplateContent , existingHtmlTemplatePath ) ;
61
66
if ( newContent !== javascriptFile . content ) {
62
67
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 ) ) ;
63
73
return true ;
64
74
}
65
75
}
0 commit comments