diff --git a/docs/guide/essentials/publishing.md b/docs/guide/essentials/publishing.md index 7edf7d1de..a7ae7b207 100644 --- a/docs/guide/essentials/publishing.md +++ b/docs/guide/essentials/publishing.md @@ -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. diff --git a/packages/wxt/e2e/tests/hooks.test.ts b/packages/wxt/e2e/tests/hooks.test.ts index 42665c238..c7f4a86a8 100644 --- a/packages/wxt/e2e/tests/hooks.test.ts +++ b/packages/wxt/e2e/tests/hooks.test.ts @@ -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, diff --git a/packages/wxt/e2e/tests/zip.test.ts b/packages/wxt/e2e/tests/zip.test.ts index e20fccc10..3ff265aad 100644 --- a/packages/wxt/e2e/tests/zip.test.ts +++ b/packages/wxt/e2e/tests/zip.test.ts @@ -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) => { diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index 72e6a8a20..092d5c27d 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -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'; @@ -55,6 +55,14 @@ export async function zip(config?: InlineConfig): Promise { 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(); @@ -65,7 +73,7 @@ export async function zip(config?: InlineConfig): Promise { ); 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);