From 0283fb9991ace9abcab1f4978d20d04a3f15e505 Mon Sep 17 00:00:00 2001 From: nishu-murmu Date: Thu, 13 Mar 2025 13:39:59 +0530 Subject: [PATCH 1/5] feat: making negate regex pattern work in zip.exclude --- packages/wxt-demo/wxt.config.ts | 4 ++++ packages/wxt/src/core/zip.ts | 34 ++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/wxt-demo/wxt.config.ts b/packages/wxt-demo/wxt.config.ts index 6961eea29..bca01bfa1 100644 --- a/packages/wxt-demo/wxt.config.ts +++ b/packages/wxt-demo/wxt.config.ts @@ -16,6 +16,10 @@ export default defineConfig({ }, zip: { downloadPackages: ['sass'], + exclude: [ + '**/*.json', // Exclude all .json files + '!manifest.json', // Include manifest.json + ], }, analysis: { open: true, diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index 092d5c27d..8e616ae92 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -113,6 +113,20 @@ async function zipDir( }, ): Promise { const archive = new JSZip(); + + function negateCheck(exclude: string[], relativePath: string) { + return exclude + ?.map((pattern) => { + if (pattern.startsWith('!')) { + if (relativePath.endsWith('.json')) { + console.log(minimatch(relativePath, pattern.slice(1))); + } + return minimatch(relativePath, pattern.slice(1)); + } + return false; + }) + .filter(Boolean); + } const files = ( await glob(['**/*', ...(options?.include || [])], { cwd: directory, @@ -121,9 +135,27 @@ async function zipDir( onlyFiles: true, }) ).filter((relativePath) => { + let shouldExclude = options?.exclude?.some((pattern) => + minimatch(relativePath, pattern), + ); + console.log( + negateCheck(options?.exclude as string[], relativePath), + relativePath, + ); + // shouldExclude = negateCheck(options?.exclude as string[], relativePath) + // ? true + // : shouldExclude; + // if (relativePath.endsWith('.json')) { + // console.log({ + // should: shouldExclude, + // relativePath, + // dd: options?.exclude, + // }); + // } + return ( options?.include?.some((pattern) => minimatch(relativePath, pattern)) || - !options?.exclude?.some((pattern) => minimatch(relativePath, pattern)) + shouldExclude ); }); const filesToZip = [ From 97aed7c0317f4ddb4a596a4a534f0fade7e06cd0 Mon Sep 17 00:00:00 2001 From: nishu-murmu Date: Sun, 16 Mar 2025 20:51:05 +0530 Subject: [PATCH 2/5] feat: exclude files in .zip except those with a bang ! --- packages/wxt/src/core/zip.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index 092d5c27d..babde3acc 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -121,9 +121,23 @@ async function zipDir( onlyFiles: true, }) ).filter((relativePath) => { + function negateCheck() { + return options?.exclude?.some( + (option) => + option.startsWith('!') && minimatch(relativePath, option.slice(1)), + ); + } + if (negateCheck()) { + return true; + } + const updatedExcludeOptions = options?.exclude?.filter( + (option) => !option.startsWith('!'), + ); return ( options?.include?.some((pattern) => minimatch(relativePath, pattern)) || - !options?.exclude?.some((pattern) => minimatch(relativePath, pattern)) + !updatedExcludeOptions?.some((pattern) => + minimatch(relativePath, pattern), + ) ); }); const filesToZip = [ From 1d9ebee16cb87f088252d6e015af1aa1f90e8287 Mon Sep 17 00:00:00 2001 From: nishu-murmu Date: Thu, 10 Apr 2025 16:12:29 +0530 Subject: [PATCH 3/5] chore: removed unused function. --- packages/wxt/src/core/zip.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index d67db5f51..23ae644c2 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -114,19 +114,6 @@ async function zipDir( ): Promise { const archive = new JSZip(); - function negateCheck(exclude: string[], relativePath: string) { - return exclude - ?.map((pattern) => { - if (pattern.startsWith('!')) { - if (relativePath.endsWith('.json')) { - console.log(minimatch(relativePath, pattern.slice(1))); - } - return minimatch(relativePath, pattern.slice(1)); - } - return false; - }) - .filter(Boolean); - } const files = ( await glob(['**/*', ...(options?.include || [])], { cwd: directory, From ac9ecbbd59cf7154b7487b03d9de5ed555acbb1c Mon Sep 17 00:00:00 2001 From: nishu-murmu Date: Thu, 10 Apr 2025 16:15:11 +0530 Subject: [PATCH 4/5] chore: reverting code in wxt.config.ts in wxt-demo. --- packages/wxt-demo/wxt.config.ts | 4 ---- packages/wxt/src/core/zip.ts | 1 - 2 files changed, 5 deletions(-) diff --git a/packages/wxt-demo/wxt.config.ts b/packages/wxt-demo/wxt.config.ts index 91af1e0e6..eee9f5d39 100644 --- a/packages/wxt-demo/wxt.config.ts +++ b/packages/wxt-demo/wxt.config.ts @@ -15,10 +15,6 @@ export default defineConfig({ }, zip: { downloadPackages: ['sass'], - exclude: [ - '**/*.json', // Exclude all .json files - '!manifest.json', // Include manifest.json - ], }, analysis: { open: true, diff --git a/packages/wxt/src/core/zip.ts b/packages/wxt/src/core/zip.ts index 23ae644c2..e155739af 100644 --- a/packages/wxt/src/core/zip.ts +++ b/packages/wxt/src/core/zip.ts @@ -113,7 +113,6 @@ async function zipDir( }, ): Promise { const archive = new JSZip(); - const files = ( await glob(['**/*', ...(options?.include || [])], { cwd: directory, From 628af36ca659cc1de3dce10df4df45f8076d2041 Mon Sep 17 00:00:00 2001 From: nishu-murmu Date: Thu, 10 Apr 2025 23:32:27 +0530 Subject: [PATCH 5/5] chore: adding tests. --- packages/wxt/e2e/tests/zip.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/wxt/e2e/tests/zip.test.ts b/packages/wxt/e2e/tests/zip.test.ts index 3ff265aad..efde648f8 100644 --- a/packages/wxt/e2e/tests/zip.test.ts +++ b/packages/wxt/e2e/tests/zip.test.ts @@ -285,4 +285,26 @@ describe('Zipping', () => { expect(await project.fileExists(sourcesZip)).toBe(false); }, ); + + it('exclude files in .zip except those with a bang !', async () => { + const project = new TestProject({ + name: 'test', + version: '1.0.0', + }); + project.addFile( + 'entrypoints/background.ts', + 'export default defineBackground(() => {});', + ); + const unzipDir = project.resolvePath('.output/test-1.0.0-chrome'); + const sourcesZip = project.resolvePath('.output/test-1.0.0-chrome.zip'); + + await project.zip({ + zip: { + exclude: ['**/*.json', '!manifest.json'], + }, + }); + + await extract(sourcesZip, { dir: unzipDir }); + expect(await project.fileExists(unzipDir, 'manifest.json')).toBe(true); + }); });