Skip to content

Commit ee49837

Browse files
committed
feat: Accept a function for config.manifest
1 parent 67f972e commit ee49837

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.output
22
coverage
33
dist
4+
e2e/project

e2e/tests/user-config.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,27 @@ describe('User Config', () => {
5555
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"version\\":\\"0.0.0\\",\\"version_name\\":\\"0.0.0-test\\",\\"background\\":{\\"service_worker\\":\\"background.js\\"}}"
5656
`);
5757
});
58+
59+
it('should accept a function for a manifest', async () => {
60+
const project = new TestProject();
61+
62+
await project.build({
63+
// @ts-expect-error: Specifically setting an invalid field for the test - it should show up in the snapshot
64+
manifest: ({ mode, browser, manifestVersion, command }) => ({
65+
example_customization: [
66+
mode,
67+
browser,
68+
String(manifestVersion),
69+
command,
70+
],
71+
}),
72+
});
73+
74+
const output = await project.serializeOutput();
75+
expect(output).toMatchInlineSnapshot(`
76+
".output/chrome-mv3/manifest.json
77+
----------------------------------------
78+
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"version\\":\\"0.0.0\\",\\"version_name\\":\\"0.0.0-test\\",\\"example_customization\\":[\\"production\\",\\"chrome\\",\\"3\\",\\"build\\"]}"
79+
`);
80+
});
5881
});

src/core/types/external.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface InlineConfig {
2020
manifestVersion?: TargetManifestVersion;
2121
logger?: Logger;
2222
vite?: Omit<vite.UserConfig, 'root' | 'configFile' | 'mode'>;
23-
manifest?: UserManifest;
23+
manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
2424
server?: WxtDevServer;
2525
runner?: ExtensionRunnerConfig;
2626
}
@@ -226,6 +226,23 @@ export type UserManifest = Omit<
226226
| 'version_name'
227227
>;
228228

229+
export type UserManifestFn = (
230+
env: ConfigEnv,
231+
) => UserManifest | Promise<UserManifest>;
232+
233+
export interface ConfigEnv {
234+
mode: string;
235+
command: 'build' | 'serve';
236+
/**
237+
* Browser passed in from the CLI
238+
*/
239+
browser: TargetBrowser;
240+
/**
241+
* Manifest version passed in from the CLI
242+
*/
243+
manifestVersion: 2 | 3;
244+
}
245+
229246
/**
230247
* Configure how the browser starts up.
231248
*/

src/core/utils/getInternalConfig.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
InlineConfig,
44
InternalConfig,
55
UserConfig,
6+
UserManifest,
67
} from '../types';
78
import path, { resolve } from 'node:path';
89
import * as vite from 'vite';
@@ -31,6 +32,15 @@ export async function getInternalConfig(
3132
const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
3233
const logger = config.logger ?? consola;
3334

35+
const manifest: UserManifest = await (typeof config.manifest === 'function'
36+
? config.manifest({
37+
browser,
38+
command,
39+
manifestVersion,
40+
mode,
41+
})
42+
: config.manifest ?? {});
43+
3444
const baseConfig: InternalConfigNoUserDirs = {
3545
root,
3646
outDir,
@@ -42,7 +52,7 @@ export async function getInternalConfig(
4252
command,
4353
logger,
4454
vite: config.vite ?? {},
45-
manifest: config.manifest ?? {},
55+
manifest,
4656
imports: config.imports ?? {},
4757
runnerConfig: await loadConfig<ExtensionRunnerConfig>({
4858
name: 'web-ext',

0 commit comments

Comments
 (0)