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

Commit

Permalink
fix(webpack): invalidate cache by use of timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Nov 16, 2016
1 parent 80c0eb6 commit 4d6bbd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
25 changes: 5 additions & 20 deletions src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BuildContext, BuildState, File, TaskInfo } from './util/interfaces';
import { BuildError, IgnorableError } from './util/errors';
import { changeExtension, readFileAsync, setContext } from './util/helpers';
import { emit, EventType } from './util/events';
import { extname, join } from 'path';
import { join } from 'path';
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars } from './util/config';
import { Logger } from './logger/logger';
import * as webpackApi from 'webpack';
Expand Down Expand Up @@ -47,26 +47,11 @@ export function webpack(context: BuildContext, configFile: string) {

export function webpackUpdate(event: string, path: string, context: BuildContext, configFile: string) {
const logger = new Logger('webpack update');
const extension = extname(path);

const webpackConfig = getWebpackConfig(context, configFile);
return Promise.resolve().then(() => {
if (extension === '.ts') {
Logger.debug('webpackUpdate: Typescript File Changed');
return typescriptFileChanged(path, context.fileCache);
} else {
Logger.debug('webpackUpdate: Non-Typescript File Changed');
return otherFileChanged(path).then((file: File) => {
return [file];
});
}
})
.then((files: File[]) => {
Logger.debug('webpackUpdate: Starting Incremental Build');
const promisetoReturn = runWebpackIncrementalBuild(false, context, webpackConfig);
emit(EventType.WebpackFilesChanged, [path]);
return promisetoReturn;
}).then((stats: any) => {
Logger.debug('webpackUpdate: Starting Incremental Build');
const promisetoReturn = runWebpackIncrementalBuild(false, context, webpackConfig);
emit(EventType.WebpackFilesChanged, [path]);
return promisetoReturn.then((stats: any) => {
// the webpack incremental build finished, so reset the list of pending promises
pendingPromises = [];
Logger.debug('webpackUpdate: Incremental Build Done, processing Data');
Expand Down
24 changes: 9 additions & 15 deletions src/webpack/watch-memory-system.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { FileCache } from '../util/file-cache';
import { on, EventType } from '../util/events';
import { Logger } from '../logger/logger';

export class WatchMemorySystem {

private changes: Set<string>;
private isAggregating: boolean;
private isListening: boolean;
private lastWatchEventTimestamp: number = Date.now();

private filePathsBeingWatched: string[];
private dirPaths: string[];
Expand Down Expand Up @@ -48,31 +50,23 @@ export class WatchMemorySystem {

startListening() {
this.isListening = true;
on(EventType.WebpackFilesChanged, ((filePaths: string[]) => {
on(EventType.WebpackFilesChanged, () => {
this.changes = new Set<string>();
const filePaths = this.fileCache.getAll().filter(file => file.timestamp >= this.lastWatchEventTimestamp).map(file => file.path);
Logger.debug('filePaths: ', filePaths);
this.lastWatchEventTimestamp = Date.now();
this.processChanges(filePaths);
}));
});
}

processChanges(filePaths: string[]) {
this.immediateCallback(filePaths[0], Date.now());
for ( const path of filePaths) {
this.changes.add(path);
}
// don't bother waiting around, just call doneAggregating right away.
// keep it as a function in case we need to wait via setTimeout a bit in the future
this.doneAggregating(this.changes);
/*if (this.isAggregating) {
// we're currently aggregating file changes into a collection
this.changes.add(filePath);
} else {
// we're starting a new listen, so start a new list of files, and start aggregating the files
this.changes = new Set<string>();
this.changes.add(filePath);
this.isAggregating = true;
setTimeout(() => {
// we're done aggregating files
this.doneAggregating(this.changes);
}, AGGREGATING_DURATION_IN_MILLIS);
}*/
}

doneAggregating(changes: Set<string>) {
Expand Down

0 comments on commit 4d6bbd5

Please sign in to comment.