Skip to content

Commit

Permalink
fix: support webpack 5 (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Dec 4, 2019
1 parent 25e293d commit 3d9e544
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"peerDependencies": {
"stylelint": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
"webpack": "^4.0.0"
"webpack": "^4.0.0 || ^5.0.0"
},
"dependencies": {
"arrify": "^2.0.1",
Expand Down
19 changes: 14 additions & 5 deletions src/LintDirtyModulesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ export default class LintDirtyModulesPlugin {
}

apply(compilation, callback) {
const fileTimestamps = compilation.fileTimestamps || new Map();

if (this.isFirstRun) {
this.isFirstRun = false;
this.prevTimestamps = compilation.fileTimestamps;
this.prevTimestamps = fileTimestamps;
callback();
return;
}

const dirtyOptions = { ...this.options };
const glob = dirtyOptions.files.join('|').replace(/\\/g, '/');
const changedFiles = this.getChangedFiles(compilation.fileTimestamps, glob);
const changedFiles = this.getChangedFiles(fileTimestamps, glob);

this.prevTimestamps = compilation.fileTimestamps;
this.prevTimestamps = fileTimestamps;

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

getChangedFiles(fileTimestamps, glob) {
const hasFileChanged = (filename, timestamp) => {
const prevTimestamp = this.prevTimestamps.get(filename);
const getTimestamps = (fileSystemInfoEntry) => {
return fileSystemInfoEntry && fileSystemInfoEntry.timestamp
? fileSystemInfoEntry.timestamp
: fileSystemInfoEntry;
};

const hasFileChanged = (filename, fileSystemInfoEntry) => {
const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
const timestamp = getTimestamps(fileSystemInfoEntry);

return (prevTimestamp || this.startTime) < (timestamp || Infinity);
};
Expand Down
2 changes: 1 addition & 1 deletion test/LintDirtyModulesPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('lint dirty modules only', () => {
});

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

plugin.isFirstRun = false;
plugin.prevTimestamps = fileTimestamps;
Expand Down

0 comments on commit 3d9e544

Please sign in to comment.