Skip to content

Commit c12e7be

Browse files
fix: use finishModules if thread is less than or equal 1 (#95)
1 parent 6fc6874 commit c12e7be

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ class ESLintWebpackPlugin {
8888
let lint;
8989
/** @type {import('./linter').Reporter} */
9090
let report;
91+
/** @type number */
92+
let threads;
9193

9294
try {
93-
({ lint, report } = linter(this.key, options, compilation));
95+
({ lint, report, threads } = linter(this.key, options, compilation));
9496
} catch (e) {
9597
compilation.errors.push(e);
9698
return;
@@ -112,13 +114,17 @@ class ESLintWebpackPlugin {
112114
!isMatch(file, exclude, { dot: true })
113115
) {
114116
files.push(file);
117+
118+
if (threads > 1) {
119+
lint(file);
120+
}
115121
}
116122
}
117123
});
118124

119125
// Lint all files added
120126
compilation.hooks.finishModules.tap(this.key, () => {
121-
if (files.length > 0) {
127+
if (files.length > 0 && threads <= 1) {
122128
lint(files);
123129
}
124130
});

src/linter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const resultStorage = new WeakMap();
2424
* @param {string|undefined} key
2525
* @param {Options} options
2626
* @param {Compilation} compilation
27-
* @returns {{lint: Linter, report: Reporter}}
27+
* @returns {{lint: Linter, report: Reporter, threads: number}}
2828
*/
2929
export default function linter(key, options, compilation) {
3030
/** @type {ESLint} */
@@ -36,20 +36,24 @@ export default function linter(key, options, compilation) {
3636
/** @type {() => Promise<void>} */
3737
let cleanup;
3838

39+
/** @type number */
40+
let threads;
41+
3942
/** @type {Promise<LintResult[]>[]} */
4043
const rawResults = [];
4144

4245
const crossRunResultStorage = getResultStorage(compilation);
4346

4447
try {
45-
({ eslint, lintFiles, cleanup } = getESLint(key, options));
48+
({ eslint, lintFiles, cleanup, threads } = getESLint(key, options));
4649
} catch (e) {
4750
throw new ESLintError(e.message);
4851
}
4952

5053
return {
5154
lint,
5255
report,
56+
threads,
5357
};
5458

5559
/**

0 commit comments

Comments
 (0)