Skip to content

Commit 18d5f23

Browse files
authored
fix: child compiler lint (#127)
* fix: child compiler lint
1 parent 7ea55dd commit 18d5f23

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
@@ -77,12 +77,12 @@ class ESLintWebpackPlugin {
7777
// Do not re-hook
7878
if (
7979
// @ts-ignore
80-
compiler.hooks.thisCompilation.taps.find(({ name }) => name === this.key)
80+
compiler.hooks.compilation.taps.find(({ name }) => name === this.key)
8181
) {
8282
return;
8383
}
8484

85-
compiler.hooks.thisCompilation.tap(this.key, (compilation) => {
85+
compiler.hooks.compilation.tap(this.key, (compilation) => {
8686
/** @type {import('./linter').Linter} */
8787
let lint;
8888
/** @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)