fix: Ignore manifest.manifest_version option and warn about incorrect usage (#1419)

This commit is contained in:
Aaron
2025-02-12 08:43:44 -06:00
committed by GitHub
parent 5775c9ce0f
commit 30b8ba495d
2 changed files with 34 additions and 0 deletions
@@ -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', () => {
+6
View File
@@ -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,