Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude files in .zip except those with a bang ! #1517

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions packages/wxt/e2e/tests/zip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
12 changes: 11 additions & 1 deletion packages/wxt/src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,19 @@ async function zipDir(
onlyFiles: true,
})
).filter((relativePath) => {
const isNegated = options?.exclude?.some(
(option) =>
option.startsWith('!') && minimatch(relativePath, option.slice(1)),
);
if (isNegated) 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 = [
Expand Down