From 30b8ba495d5e470ce7128bb4b9da31b98c424171 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 12 Feb 2025 08:43:44 -0600 Subject: [PATCH] fix: Ignore `manifest.manifest_version` option and warn about incorrect usage (#1419) --- .../src/core/utils/__tests__/manifest.test.ts | 28 +++++++++++++++++++ packages/wxt/src/core/utils/manifest.ts | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/packages/wxt/src/core/utils/__tests__/manifest.test.ts b/packages/wxt/src/core/utils/__tests__/manifest.test.ts index 4e467b09..f474bcad 100644 --- a/packages/wxt/src/core/utils/__tests__/manifest.test.ts +++ b/packages/wxt/src/core/utils/__tests__/manifest.test.ts @@ -21,6 +21,7 @@ import { OutputAsset, } from '../../../types'; import { wxt } from '../../wxt'; +import { mock } from 'vitest-mock-extended'; const outDir = '/output'; const contentScriptOutDir = '/output/content-scripts'; @@ -1646,6 +1647,33 @@ describe('Manifest Utils', () => { expect(manifest.sidebar_action).toBeUndefined(); expect(manifest.content_scripts).toBeUndefined(); }); + + describe('manifest_version', () => { + it('should ignore and log a warning when someone sets `manifest_version` inside the manifest', async () => { + const buildOutput = fakeBuildOutput(); + const expectedVersion = 2; + setFakeWxt({ + logger: mock(), + config: { + command: 'build', + manifestVersion: expectedVersion, + manifest: { + manifest_version: 3, + }, + }, + }); + + const { manifest } = await generateManifest([], buildOutput); + + expect(manifest.manifest_version).toBe(expectedVersion); + expect(wxt.logger.warn).toBeCalledTimes(1); + expect(wxt.logger.warn).toBeCalledWith( + expect.stringContaining( + '`manifest.manifest_version` config was set, but ignored', + ), + ); + }); + }); }); describe('stripPathFromMatchPattern', () => { diff --git a/packages/wxt/src/core/utils/manifest.ts b/packages/wxt/src/core/utils/manifest.ts index 8e55dec5..67f00ac5 100644 --- a/packages/wxt/src/core/utils/manifest.ts +++ b/packages/wxt/src/core/utils/manifest.ts @@ -76,6 +76,12 @@ export async function generateManifest( icons: discoverIcons(buildOutput), }; const userManifest = wxt.config.manifest; + if (userManifest.manifest_version) { + delete userManifest.manifest_version; + wxt.logger.warn( + '`manifest.manifest_version` config was set, but ignored. To change the target manifest version, use the `manifestVersion` option or the `--mv2`/`--mv3` CLI flags.\nSee https://wxt.dev/guide/essentials/target-different-browsers.html#target-a-manifest-version', + ); + } let manifest = defu( userManifest,