Skip to content

Commit 78307ea

Browse files
fix: set key in apply
1 parent a6f49ef commit 78307ea

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

declarations/getESLint.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@
1111
*/
1212
export function loadESLint(options: Options): Linter;
1313
/**
14+
* @param {string|undefined} key
1415
* @param {number} poolSize
1516
* @param {Options} options
1617
* @returns {Linter}
1718
*/
18-
export function loadESLintThreaded(poolSize: number, options: Options): Linter;
19+
export function loadESLintThreaded(
20+
key: string | undefined,
21+
poolSize: number,
22+
options: Options
23+
): Linter;
1924
/**
25+
* @param {string|undefined} key
2026
* @param {Options} options
2127
* @returns {Linter}
2228
*/
23-
export default function getESLint({ threads, ...options }: Options): Linter;
29+
export default function getESLint(
30+
key: string | undefined,
31+
{ threads, ...options }: Options
32+
): Linter;
2433
export type ESLint = import('eslint').ESLint;
2534
export type LintResult = import('eslint').ESLint.LintResult;
2635
export type Options = import('./options').PluginOptions &

declarations/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class ESLintWebpackPlugin {
1313
* @returns {void}
1414
*/
1515
apply(compiler: Compiler): void;
16+
key: string | undefined;
1617
/**
1718
*
1819
* @param {Compiler} compiler

declarations/linter.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/**
2+
* @param {string|undefined} key
23
* @param {Options} options
34
* @param {Compilation} compilation
45
* @returns {{lint: Linter, report: Reporter}}
56
*/
67
export default function linter(
8+
key: string | undefined,
79
options: Options,
810
compilation: Compilation
911
): {

src/getESLint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function loadESLint(options) {
4646
}
4747

4848
/**
49-
* @param {string} key
49+
* @param {string|undefined} key
5050
* @param {number} poolSize
5151
* @param {Options} options
5252
* @returns {Linter}
@@ -88,7 +88,7 @@ export function loadESLintThreaded(key, poolSize, options) {
8888
}
8989

9090
/**
91-
* @param {string} key
91+
* @param {string|undefined} key
9292
* @param {Options} options
9393
* @returns {Linter}
9494
*/
@@ -110,7 +110,7 @@ export default function getESLint(key, { threads, ...options }) {
110110
}
111111

112112
/**
113-
* @param {string} key
113+
* @param {string|undefined} key
114114
* @param {Options} options
115115
* @returns {string}
116116
*/

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { parseFiles, parseFoldersToGlobs } from './utils';
1111
/** @typedef {import('./options').Options} Options */
1212

1313
const ESLINT_PLUGIN = 'ESLintWebpackPlugin';
14+
let counter = 0;
1415

1516
export class ESLintWebpackPlugin {
1617
/**
1718
* @param {Options} options
1819
*/
1920
constructor(options = {}) {
20-
this.key = Math.random().toString();
2121
this.options = getOptions(options);
2222
this.run = this.run.bind(this);
2323
}
@@ -27,6 +27,12 @@ export class ESLintWebpackPlugin {
2727
* @returns {void}
2828
*/
2929
apply(compiler) {
30+
// Generate key for each compilation,
31+
// this differentiates one from the other when being cached.
32+
this.key = compiler.name || `${ESLINT_PLUGIN}_${(counter += 1)}`;
33+
34+
// If `lintDirtyModulesOnly` is disabled,
35+
// execute the linter on the build
3036
if (!this.options.lintDirtyModulesOnly) {
3137
compiler.hooks.run.tapPromise(ESLINT_PLUGIN, this.run);
3238
}

src/linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import getESLint from './getESLint';
2121
const resultStorage = new WeakMap();
2222

2323
/**
24-
* @param {string} key
24+
* @param {string|undefined} key
2525
* @param {Options} options
2626
* @param {Compilation} compilation
2727
* @returns {{lint: Linter, report: Reporter}}

0 commit comments

Comments
 (0)