@nx/eslint
Version:
29 lines (28 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveESLintClass = resolveESLintClass;
const flat_config_1 = require("../utils/flat-config");
async function resolveESLintClass(opts) {
try {
const shouldESLintUseFlatConfig = typeof opts?.useFlatConfigOverrideVal === 'boolean'
? opts.useFlatConfigOverrideVal
: (0, flat_config_1.useFlatConfig)();
// In eslint 8.57.0 (the final v8 version), a dedicated API was added for resolving the correct ESLint class.
const eslintModule = (await import('eslint'));
if (typeof eslintModule.loadESLint === 'function') {
return (await eslintModule.loadESLint({
useFlatConfig: shouldESLintUseFlatConfig,
}));
}
// Explicitly use the FlatESLint and LegacyESLint classes here because the ESLint class points at a different one based on ESLint v8 vs ESLint v9
// But the decision on which one to use is not just based on the major version of ESLint.
const { LegacyESLint, FlatESLint } = await import('eslint/use-at-your-own-risk');
// LegacyESLint's type no longer structurally matches the flat ESLint class
// in v9 type defs (new static members like defaultConfig, fromOptionsModule),
// but at runtime either class is an appropriate return value here.
return (shouldESLintUseFlatConfig ? FlatESLint : LegacyESLint);
}
catch {
throw new Error('Unable to find `eslint`. Ensure a valid `eslint` version is installed.');
}
}