Skip to content

Commit aca2c1d

Browse files
fix: compiler hooks
1 parent 9dc0a9c commit aca2c1d

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/LintDirtyModulesPlugin.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ import { isMatch } from 'micromatch';
33
import linter from './linter';
44

55
export default class LintDirtyModulesPlugin {
6-
constructor(options) {
6+
constructor(compiler, options) {
7+
this.compiler = compiler;
78
this.options = options;
89
this.startTime = Date.now();
910
this.prevTimestamps = {};
1011
this.isFirstRun = true;
1112
}
1213

13-
apply(compiler, callback) {
14+
apply(compilation, callback) {
1415
if (this.isFirstRun) {
1516
this.isFirstRun = false;
16-
this.prevTimestamps = compiler.fileTimestamps;
17+
this.prevTimestamps = compilation.fileTimestamps;
1718
callback();
1819
return;
1920
}
2021

2122
const dirtyOptions = { ...this.options };
2223
const glob = dirtyOptions.files.join('|');
23-
const changedFiles = this.getChangedFiles(compiler.fileTimestamps, glob);
24+
const changedFiles = this.getChangedFiles(compilation.fileTimestamps, glob);
2425

25-
this.prevTimestamps = compiler.fileTimestamps;
26+
this.prevTimestamps = compilation.fileTimestamps;
2627

2728
if (changedFiles.length) {
2829
dirtyOptions.files = changedFiles;
29-
linter(dirtyOptions, compiler, callback);
30+
linter(dirtyOptions, this.compiler, callback);
3031
} else {
3132
callback();
3233
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class StylelintWebpackPlugin {
2222
const plugin = { name: this.constructor.name };
2323

2424
if (options.lintDirtyModulesOnly) {
25-
const lintDirtyModulesPlugin = new LintDirtyModulesPlugin(options);
25+
const lintDirty = new LintDirtyModulesPlugin(compiler, options);
2626
compiler.hooks.emit.tapAsync(plugin, (compilation, callback) => {
27-
lintDirtyModulesPlugin.apply(compilation, callback);
27+
lintDirty.apply(compilation, callback);
2828
});
2929
} else {
3030
compiler.hooks.run.tapAsync(plugin, (compilation, callback) => {

src/linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function linter(options, compiler, callback) {
2121
})
2222
.catch(callback);
2323

24-
compiler.hooks.afterCompile.tapAsync(
24+
compiler.hooks.afterEmit.tapAsync(
2525
'StylelintWebpackPlugin',
2626
(compilation, next) => {
2727
if (warnings.length) {

test/lint-dirty-modules-only.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('lint dirty modules only', () => {
1212
beforeAll(() => {
1313
callback = jest.fn();
1414

15-
plugin = new LintDirtyModulesPlugin({ files: ['**/*.s?(c|a)ss'] });
15+
plugin = new LintDirtyModulesPlugin(null, { files: ['**/*.s?(c|a)ss'] });
1616
plugin.isFirstRun = false;
1717
});
1818

0 commit comments

Comments
 (0)