From 218e5eb2a2e71c35fc160fccbbf2da8ebc6f9caf Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 14:31:04 +0200 Subject: [PATCH 1/7] feat: change default behaviour of `getUnimportEslintOptions` true flag --- packages/wxt/src/core/resolve-config.ts | 25 ++++++++++++++----------- packages/wxt/src/types.ts | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/wxt/src/core/resolve-config.ts b/packages/wxt/src/core/resolve-config.ts index 9e7903a76..243c0a335 100644 --- a/packages/wxt/src/core/resolve-config.ts +++ b/packages/wxt/src/core/resolve-config.ts @@ -1,19 +1,19 @@ import { loadConfig } from 'c12'; import { resolve as esmResolve } from 'import-meta-resolve'; import { + ConfigEnv, InlineConfig, + Logger, ResolvedConfig, + ResolvedEslintrc, UserConfig, - ConfigEnv, - UserManifestFn, UserManifest, + UserManifestFn, WebExtConfig, - WxtResolvedUnimportOptions, - Logger, WxtCommand, WxtModule, WxtModuleWithMetadata, - ResolvedEslintrc, + WxtResolvedUnimportOptions, } from '../types'; import path from 'node:path'; import { createFsCache } from './utils/cache'; @@ -511,18 +511,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 >= 9) enabled = major; else enabled = false; break; case true: - enabled = 8; + enabled = major; break; default: enabled = inlineEnabled; @@ -532,7 +535,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, }; diff --git a/packages/wxt/src/types.ts b/packages/wxt/src/types.ts index 46561536a..42dc3e0c8 100644 --- a/packages/wxt/src/types.ts +++ b/packages/wxt/src/types.ts @@ -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'; @@ -1579,10 +1579,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. * From c4de8f9d947eaa54f879a698801d5526ca73ea65 Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 14:53:02 +0200 Subject: [PATCH 2/7] docs: update ESLint configuration examples for auto-imports --- docs/guide/essentials/config/auto-imports.md | 51 +++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/docs/guide/essentials/config/auto-imports.md b/docs/guide/essentials/config/auto-imports.md index 86b29503a..57fd11176 100644 --- a/docs/guide/essentials/config/auto-imports.md +++ b/docs/guide/essentials/config/auto-imports.md @@ -18,15 +18,19 @@ By default, WXT automatically sets up auto-imports for all of it's own APIs and - `/hooks/*` - `/utils/*` -All named and default exports from files in these directories are available everywhere else in your project without having to import them. +All named and default exports from files in these directories are available everywhere else in your project without +having to import them. -To see the complete list of auto-imported APIs, run [`wxt prepare`](/api/cli/wxt-prepare) and look at your project's `.wxt/types/imports-module.d.ts` file. +To see the complete list of auto-imported APIs, run [`wxt prepare`](/api/cli/wxt-prepare) and look at your project's +`.wxt/types/imports-module.d.ts` file. ## TypeScript -For TypeScript and your editor to recognize auto-imported variables, you need to run the [`wxt prepare` command](/api/cli/wxt-prepare). +For TypeScript and your editor to recognize auto-imported variables, you need to run the [ +`wxt prepare` command](/api/cli/wxt-prepare). -Add this command to your `postinstall` script so your editor has everything it needs to report type errors after installing dependencies: +Add this command to your `postinstall` script so your editor has everything it needs to report type errors after +installing dependencies: ```jsonc // package.json @@ -39,25 +43,31 @@ Add this command to your `postinstall` script so your editor has everything it n ## ESLint -ESLint doesn't know about the auto-imported variables unless they are explicitly defined in the ESLint's `globals`. By default, WXT will generate the config if it detects ESLint is installed in your project. If the config isn't generated automatically, you can manually tell WXT to generate it. +ESLint doesn't know about the auto-imported variables unless they are explicitly defined in the ESLint's `globals`. By +default, WXT will generate the config if it detects ESLint is installed in your project. If the config isn't generated +automatically, you can manually tell WXT to generate it. :::code-group -```ts [ESLint 9] +### ESLint 8 + +```ts [ESLint 8] export default defineConfig({ imports: { eslintrc: { - enabled: 9, + enabled: 8, }, }, }); ``` -```ts [ESLint 8] +### ESLint 9+ + +```ts [ESLint 9+] export default defineConfig({ imports: { eslintrc: { - enabled: 8, + enabled: 9 | 10, }, }, }); @@ -69,6 +79,18 @@ Then in your ESLint config, import and use the generated file: :::code-group +### ESLint 8 + +```js [ESLint 8] +// .eslintrc.mjs +export default { + extends: ['./.wxt/eslintrc-auto-import.json'], + // The rest of your config... +}; +``` + +### ESLint 9+ + ```js [ESLint 9] // eslint.config.mjs import autoImports from './.wxt/eslint-auto-imports.mjs'; @@ -81,14 +103,6 @@ export default [ ]; ``` -```js [ESLint 8] -// .eslintrc.mjs -export default { - extends: ['./.wxt/eslintrc-auto-import.json'], - // The rest of your config... -}; -``` - ::: ## Disabling Auto-imports @@ -113,6 +127,7 @@ import { } from '#imports'; ``` -To learn more about how the `#imports` module works, read the [related blog post](/blog/2024-12-06-using-imports-module). +To learn more about how the `#imports` module works, read +the [related blog post](/blog/2024-12-06-using-imports-module). If you've disabled auto-imports, you should still use `#imports` to import all of WXT's APIs from a single place. From 4dee411ec8dc84d9ed3b7aed7672eed49085157d Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 14:59:57 +0200 Subject: [PATCH 3/7] fix: correct logic for determining inlineEnabled version handling --- packages/wxt/src/core/resolve-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wxt/src/core/resolve-config.ts b/packages/wxt/src/core/resolve-config.ts index 243c0a335..1c7291dec 100644 --- a/packages/wxt/src/core/resolve-config.ts +++ b/packages/wxt/src/core/resolve-config.ts @@ -520,7 +520,7 @@ async function getUnimportEslintOptions( switch (inlineEnabled) { case 'auto': if (isNaN(major)) enabled = false; - if (major <= 8) enabled = 8; + else if (major <= 8) enabled = 8; else if (major >= 9) enabled = major; else enabled = false; break; From 1512b62447f7629722084369fe2619956f7047ff Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 15:11:43 +0200 Subject: [PATCH 4/7] adjust tests to new approach --- .../__snapshots__/auto-imports.test.ts.snap | 56 +++++++++++++++++++ packages/wxt/e2e/tests/auto-imports.test.ts | 4 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap b/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap index 868663acb..adb3e7b1b 100644 --- a/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap +++ b/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap @@ -175,6 +175,62 @@ exports[`Auto Imports > eslintrc > "enabled: true" should output a JSON config f " `; +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": { + "AutoMount": true, + "AutoMountOptions": true, + "Browser": true, + "ContentScriptAnchoredOptions": true, + "ContentScriptAppendMode": true, + "ContentScriptContext": true, + "ContentScriptInlinePositioningOptions": true, + "ContentScriptModalPositioningOptions": true, + "ContentScriptOverlayAlignment": true, + "ContentScriptOverlayPositioningOptions": true, + "ContentScriptPositioningOptions": true, + "ContentScriptUi": true, + "ContentScriptUiOptions": true, + "IframeContentScriptUi": true, + "IframeContentScriptUiOptions": true, + "InjectScriptOptions": true, + "IntegratedContentScriptUi": true, + "IntegratedContentScriptUiOptions": true, + "InvalidMatchPattern": true, + "MatchPattern": true, + "MigrationError": true, + "ScriptPublicPath": true, + "ShadowRootContentScriptUi": true, + "ShadowRootContentScriptUiOptions": true, + "StopAutoMount": true, + "StorageArea": true, + "StorageAreaChanges": true, + "StorageItemKey": true, + "WxtAppConfig": true, + "WxtStorage": true, + "WxtStorageItem": true, + "WxtWindowEventMap": true, + "browser": true, + "createIframeUi": true, + "createIntegratedUi": true, + "createShadowRootUi": true, + "defineAppConfig": true, + "defineBackground": true, + "defineContentScript": true, + "defineUnlistedScript": true, + "defineWxtPlugin": true, + "fakeBrowser": true, + "getAppConfig": true, + "injectScript": true, + "storage": true, + "useAppConfig": true + } +} +" +`; + exports[`Auto Imports > eslintrc > should allow customizing the output 1`] = ` "example.json ---------------------------------------- diff --git a/packages/wxt/e2e/tests/auto-imports.test.ts b/packages/wxt/e2e/tests/auto-imports.test.ts index f1c305b54..8e82f7eee 100644 --- a/packages/wxt/e2e/tests/auto-imports.test.ts +++ b/packages/wxt/e2e/tests/auto-imports.test.ts @@ -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', ``); @@ -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(); }); From a6c4e1b9de2d5cda6642aa30feccab4238e36708 Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 15:17:20 +0200 Subject: [PATCH 5/7] Remove eslint 10 from auto-imports.md --- docs/guide/essentials/config/auto-imports.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/essentials/config/auto-imports.md b/docs/guide/essentials/config/auto-imports.md index 57fd11176..c2b9df107 100644 --- a/docs/guide/essentials/config/auto-imports.md +++ b/docs/guide/essentials/config/auto-imports.md @@ -61,13 +61,13 @@ export default defineConfig({ }); ``` -### ESLint 9+ +### ESLint 9 -```ts [ESLint 9+] +```ts [ESLint 9] export default defineConfig({ imports: { eslintrc: { - enabled: 9 | 10, + enabled: 9, }, }, }); @@ -89,7 +89,7 @@ export default { }; ``` -### ESLint 9+ +### ESLint 9 ```js [ESLint 9] // eslint.config.mjs From ae6c068a3a499ad1a5538518faefabae129c4a69 Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 15:23:40 +0200 Subject: [PATCH 6/7] fix: markdown lint errors --- docs/guide/essentials/config/auto-imports.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/guide/essentials/config/auto-imports.md b/docs/guide/essentials/config/auto-imports.md index c2b9df107..e4cec1956 100644 --- a/docs/guide/essentials/config/auto-imports.md +++ b/docs/guide/essentials/config/auto-imports.md @@ -26,8 +26,8 @@ To see the complete list of auto-imported APIs, run [`wxt prepare`](/api/cli/wxt ## TypeScript -For TypeScript and your editor to recognize auto-imported variables, you need to run the [ -`wxt prepare` command](/api/cli/wxt-prepare). +For TypeScript and your editor to recognize auto-imported variables, you need to run the +[`wxt prepare` command](/api/cli/wxt-prepare). Add this command to your `postinstall` script so your editor has everything it needs to report type errors after installing dependencies: @@ -49,7 +49,7 @@ automatically, you can manually tell WXT to generate it. :::code-group -### ESLint 8 +**ESLint 8** ```ts [ESLint 8] export default defineConfig({ @@ -61,7 +61,7 @@ export default defineConfig({ }); ``` -### ESLint 9 +**ESLint 9** ```ts [ESLint 9] export default defineConfig({ @@ -79,7 +79,7 @@ Then in your ESLint config, import and use the generated file: :::code-group -### ESLint 8 +**ESLint 8** ```js [ESLint 8] // .eslintrc.mjs @@ -89,7 +89,7 @@ export default { }; ``` -### ESLint 9 +**ESLint 9** ```js [ESLint 9] // eslint.config.mjs From 7a85e74efe69d9c46bb812882f6d651e83724435 Mon Sep 17 00:00:00 2001 From: PatrykKuniczak Date: Fri, 24 Apr 2026 15:44:10 +0200 Subject: [PATCH 7/7] fix: remove old snapshot of auto-imports test "enabled: true ..." --- .../__snapshots__/auto-imports.test.ts.snap | 56 ------------------- 1 file changed, 56 deletions(-) diff --git a/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap b/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap index adb3e7b1b..83bcb6845 100644 --- a/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap +++ b/packages/wxt/e2e/tests/__snapshots__/auto-imports.test.ts.snap @@ -119,62 +119,6 @@ export default { " `; -exports[`Auto Imports > eslintrc > "enabled: true" should output a JSON config file compatible with ESlint 8 1`] = ` -".wxt/eslintrc-auto-import.json ----------------------------------------- -{ - "globals": { - "AutoMount": true, - "AutoMountOptions": true, - "Browser": true, - "ContentScriptAnchoredOptions": true, - "ContentScriptAppendMode": true, - "ContentScriptContext": true, - "ContentScriptInlinePositioningOptions": true, - "ContentScriptModalPositioningOptions": true, - "ContentScriptOverlayAlignment": true, - "ContentScriptOverlayPositioningOptions": true, - "ContentScriptPositioningOptions": true, - "ContentScriptUi": true, - "ContentScriptUiOptions": true, - "IframeContentScriptUi": true, - "IframeContentScriptUiOptions": true, - "InjectScriptOptions": true, - "IntegratedContentScriptUi": true, - "IntegratedContentScriptUiOptions": true, - "InvalidMatchPattern": true, - "MatchPattern": true, - "MigrationError": true, - "ScriptPublicPath": true, - "ShadowRootContentScriptUi": true, - "ShadowRootContentScriptUiOptions": true, - "StopAutoMount": true, - "StorageArea": true, - "StorageAreaChanges": true, - "StorageItemKey": true, - "WxtAppConfig": true, - "WxtStorage": true, - "WxtStorageItem": true, - "WxtWindowEventMap": true, - "browser": true, - "createIframeUi": true, - "createIntegratedUi": true, - "createShadowRootUi": true, - "defineAppConfig": true, - "defineBackground": true, - "defineContentScript": true, - "defineUnlistedScript": true, - "defineWxtPlugin": true, - "fakeBrowser": true, - "getAppConfig": true, - "injectScript": true, - "storage": true, - "useAppConfig": true - } -} -" -`; - exports[`Auto Imports > eslintrc > "enabled: true" should output a JSON config file compatible with ESlint of package.json 1`] = ` ".wxt/eslint-auto-imports.mjs ----------------------------------------