Skip to content

Commit 420b750

Browse files
fix: child compiler lint
1 parent 5393f25 commit 420b750

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ESLintWebpackPlugin {
6262
// Do not re-hook
6363
if (
6464
// @ts-ignore
65-
compiler.hooks.thisCompilation.taps.find(({ name }) => name === this.key)
65+
compiler.hooks.compilation.taps.find(({ name }) => name === this.key)
6666
) {
6767
return;
6868
}
@@ -83,7 +83,7 @@ class ESLintWebpackPlugin {
8383
[]
8484
);
8585

86-
compiler.hooks.thisCompilation.tap(this.key, (compilation) => {
86+
compiler.hooks.compilation.tap(this.key, (compilation) => {
8787
/** @type {import('./linter').Linter} */
8888
let lint;
8989
/** @type {import('./linter').Reporter} */

test/child-compiler.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import webpack from 'webpack';
2+
3+
import conf from './utils/conf';
4+
5+
const PLUGIN_NAME = 'ChildPlugin';
6+
class ChildPlugin {
7+
constructor(options) {
8+
this.options = webpack.config.getNormalizedWebpackOptions(options);
9+
}
10+
11+
apply(compiler) {
12+
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
13+
const childCompiler = compilation.createChildCompiler(PLUGIN_NAME);
14+
webpack.EntryOptionPlugin.applyEntryOption(
15+
childCompiler,
16+
compilation.compiler.context,
17+
this.options.entry
18+
);
19+
childCompiler.runAsChild(() => {
20+
callback();
21+
});
22+
});
23+
}
24+
}
25+
26+
describe('child compiler', () => {
27+
it('should have linting process', (done) => {
28+
const config = conf('good', { threads: false });
29+
config.plugins.push(
30+
new ChildPlugin({
31+
entry: {
32+
child: './child-entry',
33+
},
34+
})
35+
);
36+
webpack(config).run((err, stats) => {
37+
expect(err).toBeNull();
38+
expect(stats.hasErrors()).toBe(false);
39+
expect(stats.hasWarnings()).toBe(true);
40+
done();
41+
});
42+
});
43+
});

test/fixtures/child-entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello from child-entry.js");

0 commit comments

Comments
 (0)