Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
fix(rollup): invalidate cache on template change
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Nov 16, 2016
1 parent 11a949d commit 80c0eb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ function checkDeprecations(context: BuildContext, rollupConfig: RollupConfig) {
}
}

export function invalidateCache() {
cachedBundle = null;
}

let cachedBundle: RollupBundle = null;

Expand Down
10 changes: 10 additions & 0 deletions src/template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { BuildContext, BuildState, File } from './util/interfaces';
import { changeExtension } from './util/helpers';
import { Logger } from './logger/logger';
import { getJsOutputDest } from './bundle';
import { invalidateCache } from './rollup';
import { dirname, extname, join, parse, resolve } from 'path';
import { readFileSync, writeFile } from 'fs';

Expand All @@ -23,6 +25,9 @@ export function templateUpdate(event: string, htmlFilePath: string, context: Bui
const successfullyUpdated = updateCorrespondingJsFile(context, newTemplateContent, htmlFilePath);
bundleSourceText = replaceExistingJsTemplate(bundleSourceText, newTemplateContent, htmlFilePath);

// invaldiate any rollup bundles, if they're not using rollup no harm done
invalidateCache();

if (successfullyUpdated && bundleSourceText) {
// awesome, all good and template updated in the bundle file
const logger = new Logger(`template update`);
Expand Down Expand Up @@ -60,6 +65,11 @@ function updateCorrespondingJsFile(context: BuildContext, newTemplateContent: st
const newContent = replaceExistingJsTemplate(javascriptFile.content, newTemplateContent, existingHtmlTemplatePath);
if (newContent !== javascriptFile.content) {
javascriptFile.content = newContent;
// set the file again to generate a new timestamp
// do the same for the typescript file just to invalidate any caches, etc.
context.fileCache.set(javascriptFile.path, javascriptFile);
const typescriptFilePath = changeExtension(javascriptFile.path, '.ts');
context.fileCache.set(typescriptFilePath, context.fileCache.get(typescriptFilePath));
return true;
}
}
Expand Down

0 comments on commit 80c0eb6

Please sign in to comment.