Skip to content

Commit 3d9e544

Browse files
fix: support webpack 5 (#199)
1 parent 25e293d commit 3d9e544

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
],
3636
"peerDependencies": {
3737
"stylelint": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
38-
"webpack": "^4.0.0"
38+
"webpack": "^4.0.0 || ^5.0.0"
3939
},
4040
"dependencies": {
4141
"arrify": "^2.0.1",

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
};

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.scss', 1]]);
50+
const fileTimestamps = new Map([['not-changed.scss', { timestamp: 1 }]]);
5151

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

0 commit comments

Comments
 (0)