Skip to content

Commit 9273024

Browse files
committed
refactor: Rename internal popup mv2Key option to actionType (#2249)
1 parent 7d08e9f commit 9273024

5 files changed

Lines changed: 36 additions & 17 deletions

File tree

packages/wxt/src/core/utils/__tests__/manifest.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Manifest Utils', () => {
3838
fakePopupEntrypoint({
3939
options: {
4040
// @ts-expect-error: Force this to be undefined instead of inheriting the random value
41-
mv2Key: type ?? null,
41+
actionType: type ?? null,
4242
defaultIcon: {
4343
'16': '/icon/16.png',
4444
},
@@ -135,7 +135,7 @@ describe('Manifest Utils', () => {
135135
const popup = fakePopupEntrypoint({
136136
options: {
137137
// @ts-expect-error: Force this to be undefined
138-
mv2Key: null,
138+
actionType: null,
139139
defaultArea: 'navbar',
140140
},
141141
outputDir: outDir,
@@ -165,7 +165,7 @@ describe('Manifest Utils', () => {
165165
const popup = fakePopupEntrypoint({
166166
options: {
167167
// @ts-expect-error: Force this to be undefined
168-
mv2Key: null,
168+
actionType: null,
169169
themeIcons,
170170
},
171171
outputDir: outDir,
@@ -191,7 +191,7 @@ describe('Manifest Utils', () => {
191191
const popup = fakePopupEntrypoint({
192192
options: {
193193
// @ts-expect-error: Force this to be undefined
194-
mv2Key: null,
194+
actionType: null,
195195
defaultArea: 'menupanel',
196196
},
197197
outputDir: outDir,
@@ -560,7 +560,7 @@ describe('Manifest Utils', () => {
560560
fakePopupEntrypoint({
561561
options: {
562562
// @ts-expect-error: Force undefined instead of the random value
563-
mv2Key: null,
563+
actionType: null,
564564
},
565565
outputDir: outDir,
566566
skipped: false,
@@ -782,7 +782,7 @@ describe('Manifest Utils', () => {
782782
const popup = fakePopupEntrypoint({
783783
options: {
784784
// @ts-expect-error: Force undefined
785-
mv2Key: null,
785+
actionType: null,
786786
themeIcons: userThemeIcons,
787787
},
788788
outputDir: outDir,

packages/wxt/src/core/utils/building/find-entrypoints.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,34 @@ async function getPopupEntrypoint(
280280
{
281281
...perBrowserOptions,
282282
defaultTitle: title,
283-
mv2Key: type,
283+
actionType: type,
284284
},
285285
wxt.config.browser,
286286
);
287-
if (strictOptions.mv2Key && strictOptions.mv2Key !== 'page_action')
288-
strictOptions.mv2Key = 'browser_action';
287+
if (strictOptions.actionType && strictOptions.actionType !== 'page_action')
288+
strictOptions.actionType = 'browser_action';
289+
290+
// Sync deprecated `mv2Key` with `actionType` via getter/setter so modules
291+
// that read or write either property stay in sync.
292+
const opts = { ...strictOptions, themeIcons } as PopupEntrypoint['options'];
293+
let _actionType = opts.actionType;
294+
Object.defineProperty(opts, 'actionType', {
295+
get: () => _actionType,
296+
set: (v: typeof _actionType) => (_actionType = v),
297+
enumerable: true,
298+
configurable: true,
299+
});
300+
Object.defineProperty(opts, 'mv2Key', {
301+
get: () => _actionType,
302+
set: (v: typeof _actionType) => (_actionType = v),
303+
enumerable: true,
304+
configurable: true,
305+
});
289306

290307
return {
291308
type: 'popup',
292309
name: 'popup',
293-
options: { ...strictOptions, themeIcons },
310+
options: opts,
294311
inputPath: info.inputPath,
295312
outputDir: wxt.config.outDir,
296313
};

packages/wxt/src/core/utils/manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ function addEntrypoints(
292292

293293
const actionKey =
294294
manifest.manifest_version === 2
295-
? (popup.options.mv2Key ?? 'browser_action')
295+
? (popup.options.actionType ?? 'browser_action')
296296
: wxt.config.browser === 'firefox'
297-
? (popup.options.mv2Key ?? 'action')
297+
? (popup.options.actionType ?? 'action')
298298
: 'action';
299299

300300
manifest[actionKey] = {

packages/wxt/src/core/utils/testing/fake-objects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const fakePopupEntrypoint = fakeObjectCreator<PopupEntrypoint>(() => ({
139139
'64': 'icon/64.png',
140140
},
141141
]),
142-
mv2Key: faker.helpers.arrayElement([
142+
actionType: faker.helpers.arrayElement([
143143
'browser_action',
144144
'page_action',
145145
undefined,

packages/wxt/src/types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,14 @@ export interface ThemeIcon {
722722

723723
export interface PopupEntrypointOptions extends BaseEntrypointOptions {
724724
/**
725-
* Defaults to "browser_action" to be equivalent to MV3's "action" key.
725+
* The type of action to use in the manifest.
726726
*
727-
* This option name is bad - it is also respected for Firefox MV3 (though
728-
* `browser_action` is converted to `action`) to allow using a `page_action`
729-
* in MV3.
727+
* In MV2, defaults to `"browser_action"`. In MV3, `"browser_action"` is
728+
* converted to `"action"`, while `"page_action"` is kept as-is (Firefox MV3
729+
* only).
730730
*/
731+
actionType?: PerBrowserOption<'browser_action' | 'page_action'>;
732+
/** @deprecated Use `actionType` instead. */
731733
mv2Key?: PerBrowserOption<'browser_action' | 'page_action'>;
732734
defaultIcon?: Record<string, string>;
733735
defaultTitle?: PerBrowserOption<string>;

0 commit comments

Comments
 (0)