From 18d5f23ecefd1a242f62722e8487ef2bcc39bc8c Mon Sep 17 00:00:00 2001 From: ATNASGDWNGTH <5212215+wood1986@users.noreply.github.com> Date: Thu, 11 Nov 2021 05:10:03 -0800 Subject: [PATCH] fix: child compiler lint (#127) * fix: child compiler lint --- src/index.js | 4 ++-- test/child-compiler.test.js | 43 ++++++++++++++++++++++++++++++++++++ test/fixtures/child-entry.js | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/child-compiler.test.js create mode 100644 test/fixtures/child-entry.js diff --git a/src/index.js b/src/index.js index b7223b6..5710aba 100644 --- a/src/index.js +++ b/src/index.js @@ -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} */ diff --git a/test/child-compiler.test.js b/test/child-compiler.test.js new file mode 100644 index 0000000..5daaffb --- /dev/null +++ b/test/child-compiler.test.js @@ -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(); + }); + }); +}); diff --git a/test/fixtures/child-entry.js b/test/fixtures/child-entry.js new file mode 100644 index 0000000..613650c --- /dev/null +++ b/test/fixtures/child-entry.js @@ -0,0 +1 @@ +console.log("Hello from child-entry.js");