Skip to content

Commit b7f3679

Browse files
feat: support webpack 5
1 parent 74efb8a commit b7f3679

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/LintDirtyModulesPlugin.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ export default class LintDirtyModulesPlugin {
1212
}
1313

1414
apply(compilation, callback) {
15+
const fileTimestamps = compilation.fileTimestamps || new Map();
16+
1517
if (this.isFirstRun) {
1618
this.isFirstRun = false;
17-
this.prevTimestamps = compilation.fileTimestamps;
19+
this.prevTimestamps = fileTimestamps;
1820
callback();
1921
return;
2022
}
2123

2224
const dirtyOptions = { ...this.options };
2325
const glob = dirtyOptions.files.join('|').replace(/\\/g, '/');
24-
const changedFiles = this.getChangedFiles(compilation.fileTimestamps, glob);
26+
const changedFiles = this.getChangedFiles(fileTimestamps, glob);
2527

26-
this.prevTimestamps = compilation.fileTimestamps;
28+
this.prevTimestamps = fileTimestamps;
2729

2830
if (changedFiles.length) {
2931
dirtyOptions.files = changedFiles;
@@ -34,8 +36,15 @@ export default class LintDirtyModulesPlugin {
3436
}
3537

3638
getChangedFiles(fileTimestamps, glob) {
37-
const hasFileChanged = (filename, timestamp) => {
38-
const prevTimestamp = this.prevTimestamps.get(filename);
39+
const getTimestamps = (fileSystemInfoEntry) => {
40+
return fileSystemInfoEntry && fileSystemInfoEntry.timestamp
41+
? fileSystemInfoEntry.timestamp
42+
: fileSystemInfoEntry;
43+
};
44+
45+
const hasFileChanged = (filename, fileSystemInfoEntry) => {
46+
const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
47+
const timestamp = getTimestamps(fileSystemInfoEntry);
3948

4049
return (prevTimestamp || this.startTime) < (timestamp || Infinity);
4150
};

src/LintDirtyModulesPlugin.test.js renamed to test/LintDirtyModulesPlugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('lint dirty modules only', () => {
4747
});
4848

4949
it('not linter if files are not changed', () => {
50-
const fileTimestamps = new Map([['not-changed.js', 1]]);
50+
const fileTimestamps = new Map([['not-changed.js', { timestamp: 1 }]]);
5151

5252
plugin.isFirstRun = false;
5353
plugin.prevTimestamps = fileTimestamps;

0 commit comments

Comments
 (0)