eslint-webpack-plugin
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [2.4.0](https://github.com/webpack-contrib/eslint-webpack-plugin/compare/v2.3.0...v2.4.0) (2020-11-20) | ||
### Features | ||
* threads ([#39](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/39)) ([1e38fc7](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/1e38fc77fd575d9e56be0da6a206ded54a8f7c34)) | ||
## [2.3.0](https://github.com/webpack-contrib/eslint-webpack-plugin/compare/v2.2.1...v2.3.0) (2020-11-13) | ||
@@ -7,0 +14,0 @@ |
/** @typedef {import('eslint').ESLint} ESLint */ | ||
/** @typedef {import('eslint').ESLint.LintResult} LintResult */ | ||
/** @typedef {import('./options').Options} Options */ | ||
/** @typedef {() => Promise<void>} AsyncTask */ | ||
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */ | ||
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */ | ||
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** | ||
* @param {Options} options | ||
* @returns {{ESLint: ESLint, eslint: ESLint}} | ||
* @returns {Linter} | ||
*/ | ||
export default function getESLint( | ||
options: Options | ||
): { | ||
ESLint: import('eslint').ESLint; | ||
eslint: import('eslint').ESLint; | ||
}; | ||
export function loadESLint(options: Options): Linter; | ||
/** | ||
* @param {number} poolSize | ||
* @param {Options} options | ||
* @returns {Linter} | ||
*/ | ||
export function loadESLintThreaded(poolSize: number, options: Options): Linter; | ||
/** | ||
* @param {Options} options | ||
* @returns {Linter} | ||
*/ | ||
export default function getESLint({ threads, ...options }: Options): Linter; | ||
export type ESLint = import('eslint').ESLint; | ||
export type LintResult = import('eslint').ESLint.LintResult; | ||
export type Options = { | ||
@@ -29,2 +41,16 @@ context?: string | undefined; | ||
outputReport?: import('./options').OutputReport | undefined; | ||
threads?: number | boolean | undefined; | ||
}; | ||
export type AsyncTask = () => Promise<void>; | ||
export type LintTask = (files: string | string[]) => Promise<LintResult[]>; | ||
export type Worker = JestWorker & { | ||
lintFiles: LintTask; | ||
}; | ||
export type Linter = { | ||
threads: number; | ||
ESLint: ESLint; | ||
eslint: ESLint; | ||
lintFiles: LintTask; | ||
cleanup: AsyncTask; | ||
}; | ||
import JestWorker from 'jest-worker'; |
@@ -40,2 +40,3 @@ export class ESLintWebpackPlugin { | ||
outputReport?: import('./options').OutputReport | undefined; | ||
threads?: number | boolean | undefined; | ||
}; |
@@ -15,6 +15,8 @@ /** @typedef {import('eslint').ESLint} ESLint */ | ||
* @param {Options} options | ||
* @param {Compilation} compilation | ||
* @returns {{lint: Linter, report: Reporter}} | ||
*/ | ||
export default function linter( | ||
options: Options | ||
options: Options, | ||
compilation: Compilation | ||
): { | ||
@@ -45,2 +47,3 @@ lint: Linter; | ||
outputReport?: import('./options').OutputReport | undefined; | ||
threads?: number | boolean | undefined; | ||
}; | ||
@@ -47,0 +50,0 @@ export type FormatterFunction = ( |
@@ -31,2 +31,3 @@ /** @typedef {import("eslint").ESLint.Options} ESLintOptions */ | ||
* @property {OutputReport=} outputReport | ||
* @property {number|boolean=} threads | ||
*/ | ||
@@ -69,2 +70,3 @@ /** | ||
outputReport?: OutputReport | undefined; | ||
threads?: (number | boolean) | undefined; | ||
}; |
@@ -6,33 +6,104 @@ "use strict"; | ||
}); | ||
exports.loadESLint = loadESLint; | ||
exports.loadESLintThreaded = loadESLintThreaded; | ||
exports.default = getESLint; | ||
var _os = _interopRequireDefault(require("os")); | ||
var _jestWorker = _interopRequireDefault(require("jest-worker")); | ||
var _options = require("./options"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** @typedef {import('eslint').ESLint} ESLint */ | ||
/** @typedef {import('eslint').ESLint.LintResult} LintResult */ | ||
/** @typedef {import('./options').Options} Options */ | ||
/** @typedef {() => Promise<void>} AsyncTask */ | ||
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */ | ||
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */ | ||
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** | ||
* @param {Options} options | ||
* @returns {{ESLint: ESLint, eslint: ESLint}} | ||
* @returns {Linter} | ||
*/ | ||
function getESLint(options) { | ||
let { | ||
function loadESLint(options) { | ||
const { | ||
eslintPath | ||
} = options; | ||
if (!eslintPath) { | ||
eslintPath = 'eslint'; | ||
} | ||
const { | ||
ESLint | ||
} = require(eslintPath); // Filter out loader options before passing the options to ESLint. | ||
} = require(eslintPath || 'eslint'); // Filter out loader options before passing the options to ESLint. | ||
const eslint = new ESLint((0, _options.getESLintOptions)(options)); | ||
const lintFiles = eslint.lintFiles.bind(eslint); | ||
return { | ||
threads: 1, | ||
ESLint, | ||
eslint | ||
eslint, | ||
lintFiles, | ||
// no-op for non-threaded | ||
cleanup: async () => {} | ||
}; | ||
} | ||
/** | ||
* @param {number} poolSize | ||
* @param {Options} options | ||
* @returns {Linter} | ||
*/ | ||
function loadESLintThreaded(poolSize, options) { | ||
const { | ||
eslintPath = 'eslint' | ||
} = options; | ||
const source = require.resolve('./worker'); | ||
const workerOptions = { | ||
enableWorkerThreads: true, | ||
numWorkers: poolSize, | ||
setupArgs: [{ | ||
eslintPath, | ||
eslintOptions: (0, _options.getESLintOptions)(options) | ||
}] | ||
}; | ||
const local = loadESLint(options); | ||
/** @type {Worker} */ | ||
// prettier-ignore | ||
const worker = | ||
/** @type {Worker} */ | ||
new _jestWorker.default(source, workerOptions); | ||
return { ...local, | ||
threads: poolSize, | ||
lintFiles: files => worker.lintFiles(files), | ||
cleanup: async () => { | ||
worker.end(); | ||
} | ||
}; | ||
} | ||
/** | ||
* @param {Options} options | ||
* @returns {Linter} | ||
*/ | ||
function getESLint({ | ||
threads, | ||
...options | ||
}) { | ||
const max = typeof threads !== 'number' ? threads ? _os.default.cpus().length - 1 : 1 : | ||
/* istanbul ignore next */ | ||
threads; | ||
return max > 1 ? loadESLintThreaded(max, options) : loadESLint(options); | ||
} |
@@ -74,31 +74,30 @@ "use strict"; | ||
const exclude = (0, _utils.parseFoldersToGlobs)(options.exclude, []); | ||
/** @type {import('./linter').Linter} */ | ||
compiler.hooks.thisCompilation.tap(ESLINT_PLUGIN, compilation => { | ||
/** @type {import('./linter').Linter} */ | ||
let lint; | ||
/** @type {import('./linter').Reporter} */ | ||
let lint; | ||
/** @type {import('./linter').Reporter} */ | ||
let report; | ||
let report; | ||
try { | ||
({ | ||
lint, | ||
report | ||
} = (0, _linter.default)(options, compilation)); | ||
} catch (e) { | ||
compilation.errors.push(e); | ||
return; | ||
} // @ts-ignore | ||
try { | ||
({ | ||
lint, | ||
report | ||
} = (0, _linter.default)(options)); | ||
} catch (e) { | ||
compiler.hooks.thisCompilation.tap(ESLINT_PLUGIN, compilation => compilation.errors.push(e)); | ||
return; | ||
} // @ts-ignore | ||
const processModule = module => { | ||
const file = module.resource; | ||
const processModule = module => { | ||
const file = module.resource; | ||
if (file && _micromatch.default.isMatch(file, wanted) && !_micromatch.default.isMatch(file, exclude)) { | ||
// Queue file for linting. | ||
lint(file); | ||
} | ||
}; // Gather Files to lint | ||
if (file && _micromatch.default.isMatch(file, wanted) && !_micromatch.default.isMatch(file, exclude)) { | ||
// Queue file for linting. | ||
lint(file); | ||
} | ||
}; | ||
compiler.hooks.thisCompilation.tap(ESLINT_PLUGIN, compilation => { | ||
// Gather Files to lint | ||
compilation.hooks.succeedModule.tap(ESLINT_PLUGIN, processModule); // await and interpret results | ||
@@ -105,0 +104,0 @@ |
@@ -42,5 +42,6 @@ "use strict"; | ||
* @param {Options} options | ||
* @param {Compilation} compilation | ||
* @returns {{lint: Linter, report: Reporter}} | ||
*/ | ||
function linter(options) { | ||
function linter(options, compilation) { | ||
/** @type {ESLint} */ | ||
@@ -51,2 +52,8 @@ let ESLint; | ||
let eslint; | ||
/** @type {(files: string|string[]) => Promise<LintResult[]>} */ | ||
let lintFiles; | ||
/** @type {() => Promise<void>} */ | ||
let cleanup; | ||
/** @type {Promise<LintResult[]>[]} */ | ||
@@ -59,3 +66,5 @@ | ||
ESLint, | ||
eslint | ||
eslint, | ||
lintFiles, | ||
cleanup | ||
} = (0, _getESLint.default)(options)); | ||
@@ -75,3 +84,6 @@ } catch (e) { | ||
function lint(files) { | ||
rawResults.push(eslint.lintFiles(files)); | ||
rawResults.push(lintFiles(files).catch(e => { | ||
compilation.errors.push(e); | ||
return []; | ||
})); | ||
} | ||
@@ -82,3 +94,4 @@ | ||
const results = await removeIgnoredWarnings(eslint, // Get the current results, resetting the rawResults to empty | ||
await flatten(rawResults.splice(0, rawResults.length))); // do not analyze if there are no results or eslint config | ||
await flatten(rawResults.splice(0, rawResults.length))); | ||
await cleanup(); // do not analyze if there are no results or eslint config | ||
@@ -85,0 +98,0 @@ if (!results || results.length < 1) { |
@@ -50,2 +50,3 @@ "use strict"; | ||
* @property {OutputReport=} outputReport | ||
* @property {number|boolean=} threads | ||
*/ | ||
@@ -60,2 +61,3 @@ | ||
extensions: 'js', | ||
threads: true, | ||
...pluginOptions | ||
@@ -62,0 +64,0 @@ }; // @ts-ignore |
@@ -78,4 +78,8 @@ { | ||
] | ||
}, | ||
"threads": { | ||
"description": "Set to true to auto-selected based on number of cpus. Set to a number greater than 1 to set an explicit maximum. Set to false, 1 or less to disable and only run in main process.", | ||
"anyOf": [{ "type": "number" }, { "type": "boolean" }] | ||
} | ||
} | ||
} |
{ | ||
"name": "eslint-webpack-plugin", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A ESLint plugin for webpack", | ||
@@ -28,3 +28,3 @@ "license": "MIT", | ||
"security": "npm audit", | ||
"lint:prettier": "prettier --list-different .", | ||
"lint:prettier": "prettier -w --list-different .", | ||
"lint:js": "eslint --cache .", | ||
@@ -52,2 +52,3 @@ "lint:types": "tsc --pretty --noEmit", | ||
"arrify": "^2.0.1", | ||
"jest-worker": "^26.6.2", | ||
"micromatch": "^4.0.2", | ||
@@ -91,3 +92,6 @@ "schema-utils": "^3.0.0" | ||
"webpack" | ||
] | ||
], | ||
"jest": { | ||
"testTimeout": 60000 | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
46315
21
958
7
4
+ Addedjest-worker@^26.6.2
+ Addedjest-worker@26.6.2(transitive)