fix: Allow zipping hidden files in sources by listing them explicitly in includeSources (#674)

This commit is contained in:
Aaron
2024-05-25 16:43:51 -05:00
committed by GitHub
parent b98a5c378e
commit 7b849b80cb
2 changed files with 47 additions and 6 deletions
+44
View File
@@ -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);
});
});
+3 -6
View File
@@ -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 = [