Skip to content
Merged
4 changes: 4 additions & 0 deletions packages/wxt-demo/wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default defineConfig({
},
zip: {
downloadPackages: ['sass'],
exclude: [
'**/*.json', // Exclude all .json files
'!manifest.json', // Include manifest.json
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on, I'm looking at this code now, and based on the old logic:

options?.include?.some((pattern) => minimatch(relativePath, pattern)) || !options?.exclude?.some((pattern) => minimatch(relativePath, pattern))

Couldn't you have just added mainfest.json to include, since include has priority over exclude?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but original issue was to include this negate feature in exclude parameter. Maybe you can explain this to @skube.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm not understanding something, but I don't see an include option under the zip property.

Copy link
Contributor Author

@nishu-murmu nishu-murmu Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, there isn't.
@aklinker1 that options.includes you're mentioning is taking includeSources
that is different option.
WindowsTerminal_lANMUO72n7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, duh 👍

},
analysis: {
open: true,
Expand Down
26 changes: 25 additions & 1 deletion packages/wxt/src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ async function zipDir(
},
): Promise<void> {
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,
Expand All @@ -121,9 +135,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