From a78bf3d79aecd2657bdce6b167fb13a537b785bc Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Thu, 14 Aug 2025 21:13:35 +0300 Subject: [PATCH 1/2] fix: don't re-hook --- src/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index c18640d..b5c849f 100644 --- a/src/index.js +++ b/src/index.js @@ -61,10 +61,11 @@ class StylelintWebpackPlugin { ); } - let isFirstRun = this.options.lintDirtyModulesOnly; + let hasCompilerRunByDirtyModule = this.options.lintDirtyModulesOnly; + compiler.hooks.watchRun.tapPromise(this.key, (compiler) => { - if (isFirstRun) { - isFirstRun = false; + if (hasCompilerRunByDirtyModule) { + hasCompilerRunByDirtyModule = false; return Promise.resolve(); } @@ -81,12 +82,11 @@ class StylelintWebpackPlugin { */ async run(compiler, options, wanted, exclude) { // Do not re-hook - /* istanbul ignore if */ - if ( - compiler.hooks.thisCompilation.taps.some(({ name }) => name === this.key) - ) { - return; - } + const isCompilerHooked = compiler.hooks.compilation.taps.find( + ({ name }) => name === this.key, + ); + + if (isCompilerHooked) return; compiler.hooks.thisCompilation.tap(this.key, (compilation) => { /** @type {import('./linter').Linter} */ From 49df099e1d3ba417e63d23ea93444eb8012c21e2 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Thu, 14 Aug 2025 23:00:17 +0300 Subject: [PATCH 2/2] refactor: logic --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b5c849f..fa5334d 100644 --- a/src/index.js +++ b/src/index.js @@ -82,7 +82,7 @@ class StylelintWebpackPlugin { */ async run(compiler, options, wanted, exclude) { // Do not re-hook - const isCompilerHooked = compiler.hooks.compilation.taps.find( + const isCompilerHooked = compiler.hooks.thisCompilation.taps.find( ({ name }) => name === this.key, );