From 7b849b80cbc1e47ff0ee34450a2fcb46a29467fa Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 25 May 2024 16:43:51 -0500 Subject: [PATCH] fix: Allow zipping hidden files in sources by listing them explicitly in `includeSources` (#674) --- packages/wxt/e2e/tests/zip.test.ts | 44 ++++++++++++++++++++++++++++++ packages/wxt/src/core/zip.ts | 9 ++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/packages/wxt/e2e/tests/zip.test.ts b/packages/wxt/e2e/tests/zip.test.ts index 2bae2353..a01f5734 100644 --- a/packages/wxt/e2e/tests/zip.test.ts +++ b/packages/wxt/e2e/tests/zip.test.ts @@ -96,4 +96,48 @@ describe('Zipping', () => { expect(await project.fileExists(artifactZip)).toBe(true); expect(await project.fileExists(sourcesZip)).toBe(true); }); + + it('should not zip hidden files into sources by default', async () => { + const project = new TestProject({ + name: 'test', + version: '1.0.0', + }); + project.addFile( + 'entrypoints/background.ts', + 'export default defineBackground(() => {});', + ); + project.addFile('.env'); + 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 }); + console.log(unzipDir); // TODO: Remove log + expect(await project.fileExists(unzipDir, '.env')).toBe(false); + }); + + it('should allow zipping hidden files into sources when explicitly listed', async () => { + const project = new TestProject({ + name: 'test', + version: '1.0.0', + }); + project.addFile( + 'entrypoints/background.ts', + 'export default defineBackground(() => {});', + ); + project.addFile('.env'); + 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', + zip: { + includeSources: ['.env'], + }, + }); + await extract(sourcesZip, { dir: unzipDir }); + expect(await project.fileExists(unzipDir, '.env')).toBe(true); + }); }); diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index d647226c..e0c31e90 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -104,15 +104,12 @@ async function zipDir( // Ignore node_modules, otherwise this glob step takes forever ignore: ['**/node_modules'], onlyFiles: true, + dot: true, }) ).filter((relativePath) => { return ( - wxt.config.zip.includeSources.some((pattern) => - minimatch(relativePath, pattern), - ) || - !wxt.config.zip.excludeSources.some((pattern) => - minimatch(relativePath, pattern), - ) + options?.include?.some((pattern) => minimatch(relativePath, pattern)) || + !options?.exclude?.some((pattern) => minimatch(relativePath, pattern)) ); }); const filesToZip = [