Skip to content

Commit

Permalink
fix: child compiler lint (#127)
Browse files Browse the repository at this point in the history
* fix: child compiler lint
  • Loading branch information
wood1986 committed Nov 11, 2021
1 parent 7ea55dd commit 18d5f23
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class ESLintWebpackPlugin {
// Do not re-hook
if (
// @ts-ignore
compiler.hooks.thisCompilation.taps.find(({ name }) => name === this.key)
compiler.hooks.compilation.taps.find(({ name }) => name === this.key)
) {
return;
}

compiler.hooks.thisCompilation.tap(this.key, (compilation) => {
compiler.hooks.compilation.tap(this.key, (compilation) => {
/** @type {import('./linter').Linter} */
let lint;
/** @type {import('./linter').Reporter} */
Expand Down
43 changes: 43 additions & 0 deletions test/child-compiler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import webpack from 'webpack';

import conf from './utils/conf';

const PLUGIN_NAME = 'ChildPlugin';
class ChildPlugin {
constructor(options) {
this.options = webpack.config.getNormalizedWebpackOptions(options);
}

apply(compiler) {
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
const childCompiler = compilation.createChildCompiler(PLUGIN_NAME);
webpack.EntryOptionPlugin.applyEntryOption(
childCompiler,
compilation.compiler.context,
this.options.entry
);
childCompiler.runAsChild(() => {
callback();
});
});
}
}

describe('child compiler', () => {
it('should have linting process', (done) => {
const config = conf('good', { threads: false });
config.plugins.push(
new ChildPlugin({
entry: {
child: './child-entry',
},
})
);
webpack(config).run((err, stats) => {
expect(err).toBeNull();
expect(stats.hasErrors()).toBe(false);
expect(stats.hasWarnings()).toBe(true);
done();
});
});
});
1 change: 1 addition & 0 deletions test/fixtures/child-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello from child-entry.js");

0 comments on commit 18d5f23

Please sign in to comment.