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

Commit 4d6bbd5

Browse files
committed
fix(webpack): invalidate cache by use of timestamps
1 parent 80c0eb6 commit 4d6bbd5

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

src/webpack.ts

+5-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BuildContext, BuildState, File, TaskInfo } from './util/interfaces';
33
import { BuildError, IgnorableError } from './util/errors';
44
import { changeExtension, readFileAsync, setContext } from './util/helpers';
55
import { emit, EventType } from './util/events';
6-
import { extname, join } from 'path';
6+
import { join } from 'path';
77
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars } from './util/config';
88
import { Logger } from './logger/logger';
99
import * as webpackApi from 'webpack';
@@ -47,26 +47,11 @@ export function webpack(context: BuildContext, configFile: string) {
4747

4848
export function webpackUpdate(event: string, path: string, context: BuildContext, configFile: string) {
4949
const logger = new Logger('webpack update');
50-
const extension = extname(path);
51-
5250
const webpackConfig = getWebpackConfig(context, configFile);
53-
return Promise.resolve().then(() => {
54-
if (extension === '.ts') {
55-
Logger.debug('webpackUpdate: Typescript File Changed');
56-
return typescriptFileChanged(path, context.fileCache);
57-
} else {
58-
Logger.debug('webpackUpdate: Non-Typescript File Changed');
59-
return otherFileChanged(path).then((file: File) => {
60-
return [file];
61-
});
62-
}
63-
})
64-
.then((files: File[]) => {
65-
Logger.debug('webpackUpdate: Starting Incremental Build');
66-
const promisetoReturn = runWebpackIncrementalBuild(false, context, webpackConfig);
67-
emit(EventType.WebpackFilesChanged, [path]);
68-
return promisetoReturn;
69-
}).then((stats: any) => {
51+
Logger.debug('webpackUpdate: Starting Incremental Build');
52+
const promisetoReturn = runWebpackIncrementalBuild(false, context, webpackConfig);
53+
emit(EventType.WebpackFilesChanged, [path]);
54+
return promisetoReturn.then((stats: any) => {
7055
// the webpack incremental build finished, so reset the list of pending promises
7156
pendingPromises = [];
7257
Logger.debug('webpackUpdate: Incremental Build Done, processing Data');

src/webpack/watch-memory-system.ts

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { FileCache } from '../util/file-cache';
22
import { on, EventType } from '../util/events';
3+
import { Logger } from '../logger/logger';
34

45
export class WatchMemorySystem {
56

67
private changes: Set<string>;
78
private isAggregating: boolean;
89
private isListening: boolean;
10+
private lastWatchEventTimestamp: number = Date.now();
911

1012
private filePathsBeingWatched: string[];
1113
private dirPaths: string[];
@@ -48,31 +50,23 @@ export class WatchMemorySystem {
4850

4951
startListening() {
5052
this.isListening = true;
51-
on(EventType.WebpackFilesChanged, ((filePaths: string[]) => {
53+
on(EventType.WebpackFilesChanged, () => {
5254
this.changes = new Set<string>();
55+
const filePaths = this.fileCache.getAll().filter(file => file.timestamp >= this.lastWatchEventTimestamp).map(file => file.path);
56+
Logger.debug('filePaths: ', filePaths);
57+
this.lastWatchEventTimestamp = Date.now();
5358
this.processChanges(filePaths);
54-
}));
59+
});
5560
}
5661

5762
processChanges(filePaths: string[]) {
5863
this.immediateCallback(filePaths[0], Date.now());
5964
for ( const path of filePaths) {
6065
this.changes.add(path);
6166
}
67+
// don't bother waiting around, just call doneAggregating right away.
68+
// keep it as a function in case we need to wait via setTimeout a bit in the future
6269
this.doneAggregating(this.changes);
63-
/*if (this.isAggregating) {
64-
// we're currently aggregating file changes into a collection
65-
this.changes.add(filePath);
66-
} else {
67-
// we're starting a new listen, so start a new list of files, and start aggregating the files
68-
this.changes = new Set<string>();
69-
this.changes.add(filePath);
70-
this.isAggregating = true;
71-
setTimeout(() => {
72-
// we're done aggregating files
73-
this.doneAggregating(this.changes);
74-
}, AGGREGATING_DURATION_IN_MILLIS);
75-
}*/
7670
}
7771

7872
doneAggregating(changes: Set<string>) {

0 commit comments

Comments
 (0)