fix: Handle edge case where eslint version cannot be found

This commit is contained in:
Aaron
2026-07-25 21:15:59 -05:00
parent f69b594401
commit ab679ba413
2 changed files with 25 additions and 15 deletions
+22 -12
View File
@@ -376,7 +376,11 @@ async function getUnimportOptions(
config: InlineConfig,
): Promise<WxtResolvedUnimportOptions> {
const disabled = config.imports === false;
const eslintrc = await getUnimportEslintOptions(wxtDir, config.imports);
const eslintrc = await getUnimportEslintOptions(
logger,
wxtDir,
config.imports,
);
// mlly sometimes picks up things as exports that aren't. That's what this array contains.
const invalidExports = ['options'];
@@ -516,28 +520,34 @@ async function getUnimportOptions(
}
async function getUnimportEslintOptions(
logger: Logger,
wxtDir: string,
options: InlineConfig['imports'],
): Promise<ResolvedEslintrc> {
const inlineEnabled =
options === false ? false : (options?.eslintrc?.enabled ?? 'auto');
let enabled: ResolvedEslintrc['enabled'];
const version = await getEslintVersion();
let major = parseInt(version[0]) as Exclude<
ResolvedEslintrc['enabled'],
false
>;
const major = parseInt(version[0]);
let enabled: ResolvedEslintrc['enabled'];
switch (inlineEnabled) {
case 'auto':
if (isNaN(major)) enabled = false;
else if (major <= 8) enabled = 8;
else if (major >= 9) enabled = major;
else enabled = false;
break;
case true:
enabled = major;
if (isNaN(major)) {
if (inlineEnabled === true) {
logger.warn(
'Could not determine installed ESLint version, `eslint-auto-imports.mjs` not generated',
);
}
enabled = false;
} else if (major <= 8) {
enabled = 8;
} else if (major >= 9) {
enabled = 9;
} else {
enabled = false;
}
break;
default:
enabled = inlineEnabled;
+3 -3
View File
@@ -1646,16 +1646,16 @@ export interface Eslintrc {
* When true, generates a file that can be used by ESLint to know which
* variables are valid globals.
*
* - `true`: Version of `package.json``.
* - `false`: Don't generate the file.
* - `'auto'`: Check if eslint is installed, and if it is, generate a compatible
* config file.
* - `true`: Same as `'auto'`.
* - `false`: Don't generate the file.
* - `8`: Generate a config file compatible with ESLint 8.
* - `9`: Generate a config file compatible with ESLint 9.
*
* @default 'auto'
*/
enabled?: false | true | 'auto' | 8 | 9;
enabled?: 'auto' | boolean | 8 | 9;
/**
* File path to save the generated eslint config.
*