Skip to content

Commit

Permalink
fix: Exclude skipped entrypoints from Firefox sources zip (#1238)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Klinker <[email protected]>
  • Loading branch information
nishu-murmu and aklinker1 authored Dec 6, 2024
1 parent 88f126e commit e221252
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/guide/essentials/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ wxt zip

Firefox requires you to upload a ZIP of your source code. This allows them to rebuild your extension and review the code in a readable way. More details can be found in [Firefox's docs](https://extensionworkshop.com/documentation/publish/source-code-submission/).

When running `wxt zip -b firefox`, WXT will zip both your extension and sources. Certain files (such as config files, hidden files, and tests) are automatically excluded from your sources. However, it's important to manually check the ZIP to ensure it only contains the files necessary to rebuild your extension.
When running `wxt zip -b firefox`, WXT will zip both your extension and sources. Certain files (such as config files, hidden files, tests, and excluded entrypoints) are automatically excluded from your sources. However, it's important to manually check the ZIP to ensure it only contains the files necessary to rebuild your extension.

To customize which files are zipped, add the `zip` option to your config file.

Expand Down
2 changes: 1 addition & 1 deletion packages/wxt/e2e/tests/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Hooks', () => {
'build:publicAssets': true,
'build:manifestGenerated': true,
'entrypoints:grouped': true,
'entrypoints:resolved': true,
'entrypoints:resolved': 2,
'vite:build:extendConfig': 1,
'vite:devServer:extendConfig': false,
'zip:start': true,
Expand Down
36 changes: 36 additions & 0 deletions packages/wxt/e2e/tests/zip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ describe('Zipping', () => {
);
});

it('should exclude skipped entrypoints from respective browser sources zip', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
});
project.addFile(
'entrypoints/not-firefox.content.ts',
`export default defineContentScript({
matches: ['*://*/*'],
exclude: ['firefox'],
main() {},
});`,
);
project.addFile(
'entrypoints/all.content.ts',
`export default defineContentScript({
matches: ['*://*/*'],
main(ctx) {},
});
`,
);
const unzipDir = project.resolvePath('.output/test-1.0.0-sources');
const sourcesZip = project.resolvePath('.output/test-1.0.0-sources.zip');

await project.zip({
browser: 'firefox',
});
await extract(sourcesZip, { dir: unzipDir });
expect(
await project.fileExists(unzipDir, 'entrypoints/not-firefox.content.ts'),
).toBe(false);
expect(
await project.fileExists(unzipDir, 'entrypoints/all.content.ts'),
).toBe(true);
});

it.each(['firefox', 'opera'])(
'should create sources zip for "%s" browser when sourcesZip is undefined',
async (browser) => {
Expand Down
12 changes: 10 additions & 2 deletions packages/wxt/src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getPackageJson } from './utils/package';
import { minimatch } from 'minimatch';
import { formatDuration } from './utils/time';
import { printFileList } from './utils/log/printFileList';
import { internalBuild } from './utils/building';
import { findEntrypoints, internalBuild } from './utils/building';
import { registerWxt, wxt } from './wxt';
import JSZip from 'jszip';
import glob from 'fast-glob';
Expand Down Expand Up @@ -55,6 +55,14 @@ export async function zip(config?: InlineConfig): Promise<string[]> {
await wxt.hooks.callHook('zip:extension:done', wxt, outZipPath);

if (wxt.config.zip.zipSources) {
const entrypoints = await findEntrypoints();
const skippedEntrypoints = entrypoints.filter((entry) => entry.skipped);
const excludeSources = [
...wxt.config.zip.excludeSources,
...skippedEntrypoints.map((entry) =>
path.relative(wxt.config.zip.sourcesRoot, entry.inputPath),
),
].map((paths) => paths.replaceAll('\\', '/'));
await wxt.hooks.callHook('zip:sources:start', wxt);
const { overrides, files: downloadedPackages } =
await downloadPrivatePackages();
Expand All @@ -65,7 +73,7 @@ export async function zip(config?: InlineConfig): Promise<string[]> {
);
await zipDir(wxt.config.zip.sourcesRoot, sourcesZipPath, {
include: wxt.config.zip.includeSources,
exclude: wxt.config.zip.excludeSources,
exclude: excludeSources,
transform(absolutePath, zipPath, content) {
if (zipPath.endsWith('package.json')) {
return addOverridesToPackageJson(absolutePath, content, overrides);
Expand Down

0 comments on commit e221252

Please sign in to comment.