Skip to content

Commit

Permalink
feat: allow zipping hidden files by listing them explicitly in `inclu…
Browse files Browse the repository at this point in the history
…deSources` (#902)
  • Loading branch information
hikiko4ern authored Aug 8, 2024
1 parent 36cfcd0 commit 0ab32e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
47 changes: 42 additions & 5 deletions packages/wxt/e2e/tests/zip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ describe('Zipping', () => {
expect(await project.fileExists(sourcesZip)).toBe(true);
});

// TODO: Fix #738 and re-enable
it.skip('should not zip hidden files into sources by default', async () => {
it('should not zip hidden files into sources by default', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
Expand All @@ -108,6 +107,7 @@ describe('Zipping', () => {
'export default defineBackground(() => {});',
);
project.addFile('.env');
project.addFile('.hidden-dir/file');
const unzipDir = project.resolvePath('.output/test-1.0.0-sources');
const sourcesZip = project.resolvePath('.output/test-1.0.0-sources.zip');

Expand All @@ -116,10 +116,37 @@ describe('Zipping', () => {
});
await extract(sourcesZip, { dir: unzipDir });
expect(await project.fileExists(unzipDir, '.env')).toBe(false);
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(false);
});

// TODO: Fix #738 and re-enable
it.skip('should allow zipping hidden files into sources when explicitly listed', async () => {
it('should not zip files inside hidden directories if only the directory is specified', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
});
project.addFile(
'entrypoints/background.ts',
'export default defineBackground(() => {});',
);
project.addFile('.hidden-dir/file');
project.addFile('.hidden-dir/nested/file');
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: ['.hidden-dir'],
},
});
await extract(sourcesZip, { dir: unzipDir });
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(false);
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file')).toBe(
false,
);
});

it('should allow zipping hidden files into sources when explicitly listed', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
Expand All @@ -129,16 +156,26 @@ describe('Zipping', () => {
'export default defineBackground(() => {});',
);
project.addFile('.env');
project.addFile('.hidden-dir/file');
project.addFile('.hidden-dir/nested/file1');
project.addFile('.hidden-dir/nested/file2');
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'],
includeSources: ['.env', '.hidden-dir/file', '.hidden-dir/nested/**'],
},
});
await extract(sourcesZip, { dir: unzipDir });
expect(await project.fileExists(unzipDir, '.env')).toBe(true);
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(true);
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file1')).toBe(
true,
);
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file2')).toBe(
true,
);
});
});
4 changes: 1 addition & 3 deletions packages/wxt/src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ async function zipDir(
): Promise<void> {
const archive = new JSZip();
const files = (
await glob('**/*', {
await glob(['**/*', ...(options?.include || [])], {
cwd: directory,
// Ignore node_modules, otherwise this glob step takes forever
ignore: ['**/node_modules'],
onlyFiles: true,
// TODO: Fix #738
// dot: true,
})
).filter((relativePath) => {
return (
Expand Down

0 comments on commit 0ab32e5

Please sign in to comment.