feat!: Change default behavior of getUnimportEslintOptions true flag (#2296)
This commit is contained in:
@@ -43,7 +43,7 @@ ESLint doesn't know about the auto-imported variables unless they are explicitly
|
||||
|
||||
:::code-group
|
||||
|
||||
```ts [ESLint 9]
|
||||
```ts [ESLint >=9]
|
||||
export default defineConfig({
|
||||
imports: {
|
||||
eslintrc: {
|
||||
@@ -53,7 +53,7 @@ export default defineConfig({
|
||||
});
|
||||
```
|
||||
|
||||
```ts [ESLint 8]
|
||||
```ts [ESLint <=8]
|
||||
export default defineConfig({
|
||||
imports: {
|
||||
eslintrc: {
|
||||
@@ -69,7 +69,7 @@ Then in your ESLint config, import and use the generated file:
|
||||
|
||||
:::code-group
|
||||
|
||||
```js [ESLint 9]
|
||||
```js [ESLint >=9]
|
||||
// eslint.config.mjs
|
||||
import autoImports from './.wxt/eslint-auto-imports.mjs';
|
||||
|
||||
@@ -81,7 +81,7 @@ export default [
|
||||
];
|
||||
```
|
||||
|
||||
```js [ESLint 8]
|
||||
```js [ESLint <=8]
|
||||
// .eslintrc.mjs
|
||||
export default {
|
||||
extends: ['./.wxt/eslintrc-auto-import.json'],
|
||||
|
||||
@@ -119,8 +119,8 @@ export default {
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Auto Imports > eslintrc > "enabled: true" should output a JSON config file compatible with ESlint 8 1`] = `
|
||||
".wxt/eslintrc-auto-import.json
|
||||
exports[`Auto Imports > eslintrc > "enabled: true" should output a JSON config file compatible with ESlint of package.json 1`] = `
|
||||
".wxt/eslint-auto-imports.mjs
|
||||
----------------------------------------
|
||||
{
|
||||
"globals": {
|
||||
|
||||
@@ -217,7 +217,7 @@ describe('Auto Imports', () => {
|
||||
});
|
||||
|
||||
describe('eslintrc', () => {
|
||||
it('"enabled: true" should output a JSON config file compatible with ESlint 8', async () => {
|
||||
it('"enabled: true" should output a JSON config file compatible with ESlint of package.json', async () => {
|
||||
const project = new TestProject();
|
||||
project.addFile('entrypoints/popup.html', `<html></html>`);
|
||||
|
||||
@@ -230,7 +230,7 @@ describe('Auto Imports', () => {
|
||||
});
|
||||
|
||||
expect(
|
||||
await project.serializeFile('.wxt/eslintrc-auto-import.json'),
|
||||
await project.serializeFile('.wxt/eslint-auto-imports.mjs'),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { loadConfig } from 'c12';
|
||||
import { resolve as esmResolve } from 'import-meta-resolve';
|
||||
import {
|
||||
InlineConfig,
|
||||
ResolvedConfig,
|
||||
UserConfig,
|
||||
ConfigEnv,
|
||||
UserManifestFn,
|
||||
UserManifest,
|
||||
WebExtConfig,
|
||||
WxtResolvedUnimportOptions,
|
||||
InlineConfig,
|
||||
Logger,
|
||||
ResolvedConfig,
|
||||
ResolvedEslintrc,
|
||||
UserConfig,
|
||||
UserManifest,
|
||||
UserManifestFn,
|
||||
WebExtConfig,
|
||||
WxtCommand,
|
||||
WxtModule,
|
||||
WxtModuleWithMetadata,
|
||||
ResolvedEslintrc,
|
||||
WxtResolvedUnimportOptions,
|
||||
ExtensionRunner,
|
||||
} from '../types';
|
||||
import path from 'node:path';
|
||||
@@ -523,18 +523,21 @@ async function getUnimportEslintOptions(
|
||||
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
|
||||
>;
|
||||
|
||||
switch (inlineEnabled) {
|
||||
case 'auto':
|
||||
const version = await getEslintVersion();
|
||||
let major = parseInt(version[0]);
|
||||
if (isNaN(major)) enabled = false;
|
||||
if (major <= 8) enabled = 8;
|
||||
else if (major >= 9) enabled = 9;
|
||||
// NaN
|
||||
else if (major <= 8) enabled = 8;
|
||||
else if (major >= 9) enabled = major;
|
||||
else enabled = false;
|
||||
break;
|
||||
case true:
|
||||
enabled = 8;
|
||||
enabled = major;
|
||||
break;
|
||||
default:
|
||||
enabled = inlineEnabled;
|
||||
@@ -544,7 +547,7 @@ async function getUnimportEslintOptions(
|
||||
enabled,
|
||||
filePath: path.resolve(
|
||||
wxtDir,
|
||||
enabled === 9 ? 'eslint-auto-imports.mjs' : 'eslintrc-auto-import.json',
|
||||
enabled === 8 ? 'eslintrc-auto-import.json' : 'eslint-auto-imports.mjs',
|
||||
),
|
||||
globalsPropValue: true,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type * as vite from 'vite';
|
||||
import { UnimportOptions, Import } from 'unimport';
|
||||
import { Import, UnimportOptions } from 'unimport';
|
||||
import { LogLevel } from 'consola';
|
||||
import type { ContentScriptContext } from './utils/content-script-context';
|
||||
import type { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer';
|
||||
@@ -1646,10 +1646,10 @@ 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 `8`.
|
||||
* - `8`: Generate a config file compatible with ESLint 8.
|
||||
* - `9`: Generate a config file compatible with ESLint 9.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user