Skip to content

Commit a95e569

Browse files
perf: split engine
1 parent 3e7c36e commit a95e569

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/getCLIEngine.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default function getCLIEngine(options, startCli = true) {
2+
let { eslintPath, CLIEngine, cli } = options;
3+
4+
if (!eslintPath) {
5+
eslintPath = 'eslint';
6+
7+
// eslint-disable-next-line no-param-reassign
8+
options.eslintPath = eslintPath;
9+
}
10+
11+
if (!CLIEngine) {
12+
({ CLIEngine } = require(eslintPath));
13+
14+
// eslint-disable-next-line no-param-reassign
15+
options.CLIEngine = CLIEngine;
16+
}
17+
18+
if (!cli && startCli) {
19+
cli = new CLIEngine(options);
20+
21+
// eslint-disable-next-line no-param-reassign
22+
options.cli = cli;
23+
}
24+
25+
return {
26+
eslintPath,
27+
CLIEngine,
28+
cli,
29+
};
30+
}

src/getOptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import validateOptions from 'schema-utils';
22

33
import schema from './options.json';
4+
import getCLIEngine from './getCLIEngine';
45

56
export default function getOptions(pluginOptions) {
67
const options = {
7-
eslintPath: 'eslint',
88
files: '.',
99
...pluginOptions,
1010
};
@@ -14,7 +14,7 @@ export default function getOptions(pluginOptions) {
1414
baseDataPath: 'options',
1515
});
1616

17-
const { CLIEngine } = require(options.eslintPath);
17+
const { CLIEngine } = getCLIEngine(options, false);
1818

1919
options.formatter = getFormatter(CLIEngine, options.formatter);
2020

src/linter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { isAbsolute, join } from 'path';
33
import { writeFileSync, ensureFileSync } from 'fs-extra';
44

55
import ESLintError from './ESLintError';
6+
import getCLIEngine from './getCLIEngine';
67

78
export default function linter(options, compiler, callback) {
89
try {
9-
const { CLIEngine } = require(options.eslintPath);
10-
const cli = new CLIEngine(options);
10+
const { CLIEngine, cli } = getCLIEngine(options);
1111
const report = cli.executeOnFiles(options.files);
1212

1313
// filter ignored files

0 commit comments

Comments
 (0)