Skip to content

Commit

Permalink
fix: Exclude skipped entrypoints from manifest (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 authored Dec 10, 2024
1 parent 413cd93 commit 2309626
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
35 changes: 32 additions & 3 deletions packages/wxt/src/core/utils/__tests__/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Manifest Utils', () => {
defaultTitle: 'Default Iitle',
},
outputDir: outDir,
skipped: false,
});

it('should include an action for mv3', async () => {
Expand Down Expand Up @@ -209,6 +210,7 @@ describe('Manifest Utils', () => {
chromeStyle: true,
browserStyle: true,
},
skipped: false,
});

it('should include a options_ui and chrome_style for chrome', async () => {
Expand Down Expand Up @@ -265,6 +267,7 @@ describe('Manifest Utils', () => {
persistent: true,
type: 'module',
},
skipped: false,
});

describe('MV3', () => {
Expand Down Expand Up @@ -368,7 +371,7 @@ describe('Manifest Utils', () => {

describe('icons', () => {
it('should auto-discover icons with the correct name', async () => {
const entrypoints = fakeArray(fakeEntrypoint);
const entrypoints = fakeArray(() => fakeEntrypoint({ skipped: false }));
const buildOutput = fakeBuildOutput({
publicAssets: [
{ type: 'asset', fileName: 'icon-16.png' },
Expand Down Expand Up @@ -396,7 +399,7 @@ describe('Manifest Utils', () => {
});

it('should return undefined when no icons are found', async () => {
const entrypoints = fakeArray(fakeEntrypoint);
const entrypoints = fakeArray(() => fakeEntrypoint({ skipped: false }));
const buildOutput = fakeBuildOutput({
publicAssets: [
{ type: 'asset', fileName: 'logo.png' },
Expand All @@ -413,7 +416,7 @@ describe('Manifest Utils', () => {
});

it('should allow icons to be overwritten from the wxt.config.ts file', async () => {
const entrypoints = fakeArray(fakeEntrypoint);
const entrypoints = fakeArray(() => fakeEntrypoint({ skipped: false }));
const buildOutput = fakeBuildOutput({
publicAssets: [
{ type: 'asset', fileName: 'icon-16.png' },
Expand Down Expand Up @@ -837,6 +840,7 @@ describe('Manifest Utils', () => {
options: {
registration: 'runtime',
},
skipped: false,
});

const entrypoints = [cs];
Expand Down Expand Up @@ -902,6 +906,7 @@ describe('Manifest Utils', () => {
async (browser) => {
const sidepanel = fakeSidepanelEntrypoint({
outputDir: outDir,
skipped: false,
});
const buildOutput = fakeBuildOutput();

Expand Down Expand Up @@ -934,6 +939,7 @@ describe('Manifest Utils', () => {
async (browser) => {
const sidepanel = fakeSidepanelEntrypoint({
outputDir: outDir,
skipped: false,
});
const buildOutput = fakeBuildOutput();

Expand Down Expand Up @@ -1617,6 +1623,29 @@ describe('Manifest Utils', () => {
expect(actual.content_security_policy).toEqual(expectedCsp);
});
});

it('should not add skipped entrypoints to manifest', async () => {
const popup = fakePopupEntrypoint({ skipped: true });
const content = fakeContentScriptEntrypoint({ skipped: true });
const sidePanel = fakeSidepanelEntrypoint({ skipped: true });
const buildOutput = fakeBuildOutput();

setFakeWxt({
config: {
command: 'build',
manifestVersion: 3,
},
});

const { manifest } = await generateManifest(
[popup, content, sidePanel],
buildOutput,
);

expect(manifest.action).toBeUndefined();
expect(manifest.sidebar_action).toBeUndefined();
expect(manifest.content_scripts).toBeUndefined();
});
});

describe('stripPathFromMatchPattern', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/wxt/src/core/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export async function writeManifest(
* Generates the manifest based on the config and entrypoints.
*/
export async function generateManifest(
entrypoints: Entrypoint[],
allEntrypoints: Entrypoint[],
buildOutput: Omit<BuildOutput, 'manifest'>,
): Promise<{ manifest: Manifest.WebExtensionManifest; warnings: any[][] }> {
const entrypoints = allEntrypoints.filter((entry) => !entry.skipped);

const warnings: any[][] = [];
const pkg = await getPackageJson();

Expand Down
5 changes: 3 additions & 2 deletions packages/wxt/src/core/utils/testing/fake-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
UserManifest,
Wxt,
SidepanelEntrypoint,
BaseEntrypoint,
} from '../../../types';
import { mock } from 'vitest-mock-extended';
import { vi } from 'vitest';
Expand Down Expand Up @@ -50,15 +51,15 @@ export function fakeDir(root = process.cwd()): string {
return resolve(root, faker.string.alphanumeric());
}

export const fakeEntrypoint = () =>
export const fakeEntrypoint = (options?: DeepPartial<BaseEntrypoint>) =>
faker.helpers.arrayElement([
fakePopupEntrypoint,
fakeGenericEntrypoint,
fakeOptionsEntrypoint,
fakeBackgroundEntrypoint,
fakeContentScriptEntrypoint,
fakeUnlistedScriptEntrypoint,
])();
])(options);

export const fakeContentScriptEntrypoint =
fakeObjectCreator<ContentScriptEntrypoint>(() => ({
Expand Down

0 comments on commit 2309626

Please sign in to comment.