Skip to content

Commit

Permalink
fix: Ignore manifest.manifest_version option and warn about incorre…
Browse files Browse the repository at this point in the history
…ct usage (#1419)
  • Loading branch information
aklinker1 authored Feb 12, 2025
1 parent 5775c9c commit 30b8ba4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/wxt/src/core/utils/__tests__/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/wxt/src/core/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 30b8ba4

Please sign in to comment.