Skip to content

Commit

Permalink
feat: support webpack 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Dec 20, 2019
1 parent 74efb8a commit b7f3679
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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
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.js', 1]]);
const fileTimestamps = new Map([['not-changed.js', { timestamp: 1 }]]);

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

0 comments on commit b7f3679

Please sign in to comment.