Skip to content

Commit 05ca998

Browse files
committed
fix: Merge manifest option from both inline and user config
1 parent 145038c commit 05ca998

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

e2e/tests/user-config.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,23 @@ describe('User Config', () => {
5656
`);
5757
});
5858

59-
it('should accept a function for a manifest', async () => {
59+
it('should merge inline and user config based manifests', async () => {
6060
const project = new TestProject();
61+
project.addFile(
62+
'wxt.config.ts',
63+
`import { defineConfig } from 'wxt';
64+
export default defineConfig({
65+
manifest: ({ mode, browser }) => ({
66+
// @ts-expect-error
67+
example_customization: [mode, browser],
68+
})
69+
})`,
70+
);
6171

6272
await project.build({
6373
// @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-
],
74+
manifest: ({ manifestVersion, command }) => ({
75+
example_customization: [String(manifestVersion), command],
7176
}),
7277
});
7378

src/core/utils/getInternalConfig.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
2+
ConfigEnv,
23
ExtensionRunnerConfig,
34
InlineConfig,
45
InternalConfig,
56
UserConfig,
67
UserManifest,
8+
UserManifestFn,
79
} from '../types';
810
import path, { resolve } from 'node:path';
911
import * as vite from 'vite';
@@ -32,15 +34,6 @@ export async function getInternalConfig(
3234
const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
3335
const logger = config.logger ?? consola;
3436

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-
4437
const baseConfig: InternalConfigNoUserDirs = {
4538
root,
4639
outDir,
@@ -52,7 +45,6 @@ export async function getInternalConfig(
5245
command,
5346
logger,
5447
vite: config.vite ?? {},
55-
manifest,
5648
imports: config.imports ?? {},
5749
runnerConfig: await loadConfig<ExtensionRunnerConfig>({
5850
name: 'web-ext',
@@ -92,6 +84,12 @@ export async function getInternalConfig(
9284
const wxtDir = resolve(srcDir, '.wxt');
9385
const typesDir = resolve(wxtDir, 'types');
9486

87+
// Merge manifest sources
88+
const env: ConfigEnv = { mode, browser, manifestVersion, command };
89+
const userManifest = await resolveManifestConfig(env, userConfig.manifest);
90+
const inlineManifest = await resolveManifestConfig(env, config.manifest);
91+
const manifest = vite.mergeConfig(userManifest, inlineManifest);
92+
9593
const finalConfig: InternalConfig = {
9694
...merged,
9795
srcDir,
@@ -100,6 +98,7 @@ export async function getInternalConfig(
10098
wxtDir: wxtDir,
10199
typesDir,
102100
fsCache: createFsCache(wxtDir),
101+
manifest,
103102
};
104103

105104
// Customize the default vite config
@@ -137,5 +136,20 @@ export async function getInternalConfig(
137136
*/
138137
type InternalConfigNoUserDirs = Omit<
139138
InternalConfig,
140-
'srcDir' | 'publicDir' | 'entrypointsDir' | 'wxtDir' | 'typesDir' | 'fsCache'
139+
| 'srcDir'
140+
| 'publicDir'
141+
| 'entrypointsDir'
142+
| 'wxtDir'
143+
| 'typesDir'
144+
| 'fsCache'
145+
| 'manifest'
141146
>;
147+
148+
async function resolveManifestConfig(
149+
env: ConfigEnv,
150+
manifest: UserManifest | Promise<UserManifest> | UserManifestFn | undefined,
151+
): Promise<UserManifest> {
152+
return await (typeof manifest === 'function'
153+
? manifest(env)
154+
: manifest ?? {});
155+
}

0 commit comments

Comments
 (0)