diff --git a/src/core/utils/building/get-internal-config.ts b/src/core/utils/building/get-internal-config.ts index cbc991c3..83c4d13a 100644 --- a/src/core/utils/building/get-internal-config.ts +++ b/src/core/utils/building/get-internal-config.ts @@ -241,8 +241,9 @@ function resolveInternalZipConfig( sourcesTemplate: '{{name}}-{{version}}-sources.zip', artifactTemplate: '{{name}}-{{version}}-{{browser}}.zip', sourcesRoot: root, + includeSources: [], ...mergedConfig.zip, - ignoredSources: [ + excludeSources: [ '**/node_modules', // WXT files '**/web-ext.config.ts', @@ -252,7 +253,7 @@ function resolveInternalZipConfig( '**/__tests__/**', '**/*.+(test|spec).?(c|m)+(j|t)s?(x)', // From user - ...(mergedConfig.zip?.ignoredSources ?? []), + ...(mergedConfig.zip?.excludeSources ?? []), ], }; } diff --git a/src/core/utils/testing/fake-objects.ts b/src/core/utils/testing/fake-objects.ts index aaa9317e..626ba557 100644 --- a/src/core/utils/testing/fake-objects.ts +++ b/src/core/utils/testing/fake-objects.ts @@ -232,7 +232,8 @@ export const fakeInternalConfig = fakeObjectCreator(() => { }, zip: { artifactTemplate: '{{name}}-{{version}}.zip', - ignoredSources: [], + includeSources: [], + excludeSources: [], sourcesRoot: fakeDir(), sourcesTemplate: '{{name}}-sources.zip', name: faker.person.firstName().toLowerCase(), diff --git a/src/core/zip.ts b/src/core/zip.ts index b7f6047a..323a2b50 100644 --- a/src/core/zip.ts +++ b/src/core/zip.ts @@ -62,10 +62,15 @@ export async function zip(config?: InlineConfig): Promise { saveTo: sourcesZipPath, filter(path) { const relativePath = relative(internalConfig.zip.sourcesRoot, path); - const matchedPattern = internalConfig.zip.ignoredSources.find( - (pattern) => minimatch(relativePath, pattern), + + return ( + internalConfig.zip.includeSources.some((pattern) => + minimatch(relativePath, pattern), + ) || + !internalConfig.zip.excludeSources.some((pattern) => + minimatch(relativePath, pattern), + ) ); - return matchedPattern == null; }, }); zipFiles.push(sourcesZipPath); diff --git a/src/types/external.ts b/src/types/external.ts index 47212325..b1adff43 100644 --- a/src/types/external.ts +++ b/src/types/external.ts @@ -143,6 +143,19 @@ export interface InlineConfig { * @default config.root */ sourcesRoot?: string; + /** + * [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to include when + * creating a ZIP of all your source code for Firefox. Patterns are relative to your + * `config.zip.sourcesRoot`. + * + * This setting overrides `excludeSources`. So if a file matches both lists, it is included in the ZIP. + * + * @example + * [ + * "coverage", // Ignore the coverage directory in the `sourcesRoot` + * ] + */ + includeSources?: string[]; /** * [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to exclude when * creating a ZIP of all your source code for Firefox. Patterns are relative to your @@ -155,7 +168,7 @@ export interface InlineConfig { * "coverage", // Ignore the coverage directory in the `sourcesRoot` * ] */ - ignoredSources?: string[]; + excludeSources?: string[]; }; /** diff --git a/src/types/internal.ts b/src/types/internal.ts index 769d0406..3d7601a6 100644 --- a/src/types/internal.ts +++ b/src/types/internal.ts @@ -40,7 +40,8 @@ export interface InternalConfig { name?: string; artifactTemplate: string; sourcesTemplate: string; - ignoredSources: string[]; + includeSources: string[]; + excludeSources: string[]; sourcesRoot: string; }; transformManifest: (manifest: Manifest.WebExtensionManifest) => void;