wxt 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,292 @@
1
+ export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
+ import * as vite from 'vite';
3
+ import { Manifest } from 'webextension-polyfill';
4
+ import { UnimportOptions } from 'unimport';
5
+ import { LogLevel } from 'consola';
6
+ import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
7
+
8
+ interface InlineConfig {
9
+ /**
10
+ * Your project's root directory containing the `package.json` used to fill out the
11
+ * `manifest.json`.
12
+ *
13
+ * @default process.cwd()
14
+ */
15
+ root?: string;
16
+ /**
17
+ * Directory containing all source code. Set to `"src"` to move all source code to a `src/`
18
+ * directory.
19
+ *
20
+ * @default config.root
21
+ */
22
+ srcDir?: string;
23
+ /**
24
+ * Directory containing files that will be copied to the output directory as-is.
25
+ *
26
+ * @default "${config.root}/public"
27
+ */
28
+ publicDir?: string;
29
+ /**
30
+ * @default "${config.srcDir}/entrypoints"
31
+ */
32
+ entrypointsDir?: string;
33
+ /**
34
+ * > Only available when using the JS API. Not available in `wxt.config.ts` files
35
+ *
36
+ * Path to `wxt.config.ts` file or `false` to disable config file discovery.
37
+ *
38
+ * @default "wxt.config.ts"
39
+ */
40
+ configFile?: string | false;
41
+ /**
42
+ * Set to `true` to show debug logs. Overriden by the command line `--debug` option.
43
+ *
44
+ * @default false
45
+ */
46
+ debug?: boolean;
47
+ /**
48
+ * Explicitly set a mode to run in. This will override the default mode for each command, and can
49
+ * be overridden by the command line `--mode` option.
50
+ */
51
+ mode?: string;
52
+ /**
53
+ * Customize auto-import options. Set to `false` to disable auto-imports.
54
+ *
55
+ * For example, to add a directory to auto-import from, you can use:
56
+ *
57
+ * ```ts
58
+ * export default defineConfig({
59
+ * imports: {
60
+ * dirs: ["some-directory"]
61
+ * }
62
+ * })
63
+ * ```
64
+ */
65
+ imports?: Partial<UnimportOptions> | false;
66
+ /**
67
+ * Explicitly set a browser to build for. This will override the default browser for each command,
68
+ * and can be overridden by the command line `--browser` option.
69
+ *
70
+ * @default
71
+ * "chrome"
72
+ */
73
+ browser?: TargetBrowser;
74
+ /**
75
+ * Explicitly set a manifest version to target. This will override the default manifest version
76
+ * for each command, and can be overridden by the command line `--mv2` or `--mv3` option.
77
+ */
78
+ manifestVersion?: TargetManifestVersion;
79
+ /**
80
+ * Override the logger used.
81
+ *
82
+ * @default
83
+ * consola
84
+ */
85
+ logger?: Logger;
86
+ /**
87
+ * Return custom Vite options from a function. See
88
+ * <https://vitejs.dev/config/shared-options.html>.
89
+ *
90
+ * [`root`](#root), [`configFile`](#configfile), and [`mode`](#mode) should be set in WXT's config
91
+ * instead of Vite's.
92
+ *
93
+ * This is a function because any vite plugins added need to be recreated for each individual
94
+ * build step, incase they have internal state causing them to fail when reused.
95
+ */
96
+ vite?: (env: ConfigEnv) => WxtViteConfig | Promise<WxtViteConfig>;
97
+ /**
98
+ * Customize the `manifest.json` output. Can be an object, promise, or function that returns an
99
+ * object or promise.
100
+ */
101
+ manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
102
+ /**
103
+ * Custom runner options. Options set here can be overridden in a `web-ext.config.ts` file.
104
+ */
105
+ runner?: ExtensionRunnerConfig;
106
+ zip?: {
107
+ /**
108
+ * Configure the filename output when zipping files.
109
+ *
110
+ * Available template variables:
111
+ *
112
+ * - `{{name}}` - The project's name converted to kebab-case
113
+ * - `{{version}}` - The version_name or version from the manifest
114
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
115
+ * - `{{manifestVersion}}` - Either "2" or "3"
116
+ *
117
+ * @default "{{name}}-{{version}}-{{browser}}.zip"
118
+ */
119
+ artifactTemplate?: string;
120
+ /**
121
+ * Configure the filename output when zipping files.
122
+ *
123
+ * Available template variables:
124
+ *
125
+ * - `{{name}}` - The project's name converted to kebab-case
126
+ * - `{{version}}` - The version_name or version from the manifest
127
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
128
+ * - `{{manifestVersion}}` - Either "2" or "3"
129
+ *
130
+ * @default "{{name}}-{{version}}-sources.zip"
131
+ */
132
+ sourcesTemplate?: string;
133
+ /**
134
+ * Override the artifactTemplate's `{name}` template variable. Defaults to the `package.json`'s
135
+ * name, or if that doesn't exist, the current working directories name.
136
+ */
137
+ name?: string;
138
+ /**
139
+ * Root directory to ZIP when generating the sources ZIP.
140
+ *
141
+ * @default config.root
142
+ */
143
+ sourcesRoot?: string;
144
+ /**
145
+ * [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to exclude when
146
+ * creating a ZIP of all your source code for Firfox. Patterns are relative to your
147
+ * `config.zip.sourcesRoot`.
148
+ *
149
+ * Hidden files, node_modules, and tests are ignored by default.
150
+ *
151
+ * @example
152
+ * [
153
+ * "coverage", // Ignore the coverage directory in the `sourcesRoot`
154
+ * ]
155
+ */
156
+ ignoredSources?: string[];
157
+ };
158
+ /**
159
+ * Transform the final manifest before it's written to the file system. Edit the `manifest`
160
+ * parameter directly, do not return a new object. Return values are ignored.
161
+ *
162
+ * @example
163
+ * defineConfig({
164
+ * // Add a CSS-only content script.
165
+ * transformManifest(manifest) {
166
+ * manifest.content_scripts.push({
167
+ * matches: ["*://google.com/*"],
168
+ * css: ["content-scripts/some-example.css"],
169
+ * });
170
+ * }
171
+ * })
172
+ */
173
+ transformManifest?: (manifest: Manifest.WebExtensionManifest) => void;
174
+ analysis?: {
175
+ /**
176
+ * Explicitly include bundle analysis when running `wxt build`. This can be overridden by the
177
+ * command line `--analysis` option.
178
+ *
179
+ * @default false
180
+ */
181
+ enabled?: boolean;
182
+ /**
183
+ * When running `wxt build --analyze` or setting `analysis.enabled` to true, customize how the
184
+ * bundle will be visualized. See
185
+ * [`rollup-plugin-visualizer`](https://github.com/btd/rollup-plugin-visualizer#how-to-use-generated-files)
186
+ * for more details.
187
+ *
188
+ * @default "treemap"
189
+ */
190
+ template?: PluginVisualizerOptions['template'];
191
+ };
192
+ }
193
+ type TargetBrowser = string;
194
+ type TargetManifestVersion = 2 | 3;
195
+ interface Logger {
196
+ debug(...args: any[]): void;
197
+ log(...args: any[]): void;
198
+ info(...args: any[]): void;
199
+ warn(...args: any[]): void;
200
+ error(...args: any[]): void;
201
+ fatal(...args: any[]): void;
202
+ success(...args: any[]): void;
203
+ level: LogLevel;
204
+ }
205
+ /**
206
+ * Manifest customization available in the `wxt.config.ts` file. You cannot configure entrypoints
207
+ * here, they are configured inline.
208
+ */
209
+ type UserManifest = Partial<Omit<Manifest.WebExtensionManifest, 'action' | 'background' | 'browser_action' | 'chrome_url_overrides' | 'devtools_page' | 'manifest_version' | 'options_page' | 'options_ui' | 'sandbox' | 'page_action' | 'popup' | 'sidepanel' | 'sidebar_action'>>;
210
+ type UserManifestFn = (env: ConfigEnv) => UserManifest | Promise<UserManifest>;
211
+ interface ConfigEnv {
212
+ mode: string;
213
+ command: 'build' | 'serve';
214
+ /**
215
+ * Browser passed in from the CLI
216
+ */
217
+ browser: TargetBrowser;
218
+ /**
219
+ * Manifest version passed in from the CLI
220
+ */
221
+ manifestVersion: 2 | 3;
222
+ }
223
+ /**
224
+ * Configure how the browser starts up.
225
+ */
226
+ interface ExtensionRunnerConfig {
227
+ /**
228
+ * Whether or not to open the browser with the extension installed in dev mode.
229
+ *
230
+ * @default false
231
+ */
232
+ disabled?: boolean;
233
+ /**
234
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#browser-console
235
+ */
236
+ openConsole?: boolean;
237
+ /**
238
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#devtools
239
+ */
240
+ openDevtools?: boolean;
241
+ /**
242
+ * List of browser names and the binary that should be used to open the browser.
243
+ *
244
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-binary
245
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#firefox
246
+ */
247
+ binaries?: Record<string, string>;
248
+ /**
249
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#firefox-profile
250
+ */
251
+ firefoxProfile?: string;
252
+ /**
253
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-profile
254
+ */
255
+ chromiumProfile?: string;
256
+ /**
257
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#pref
258
+ */
259
+ firefoxPrefs?: Record<string, string>;
260
+ /**
261
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#args
262
+ */
263
+ firefoxArgs?: string[];
264
+ /**
265
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#args
266
+ */
267
+ chromiumArgs?: string[];
268
+ /**
269
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#start-url
270
+ */
271
+ startUrls?: string[];
272
+ }
273
+ type WxtViteConfig = Omit<vite.UserConfig, 'root' | 'configFile' | 'mode'>;
274
+
275
+ /**
276
+ * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
277
+ *
278
+ * ```ts
279
+ * // vitest.config.ts
280
+ * import { defineConfig } from 'vitest/config';
281
+ * import { AutoImport } from 'wxt/testing';
282
+ *
283
+ * export default defineConfig({
284
+ * plugins: [AutoImport()],
285
+ * });
286
+ * ```
287
+ *
288
+ * @param inlineConfig Customize WXT's config for testing. Any config specified here overrides the config from your `wxt.config.ts` file.
289
+ */
290
+ declare function WxtVitest(inlineConfig?: InlineConfig): vite.PluginOption;
291
+
292
+ export { WxtVitest };
@@ -0,0 +1,292 @@
1
+ export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
+ import * as vite from 'vite';
3
+ import { Manifest } from 'webextension-polyfill';
4
+ import { UnimportOptions } from 'unimport';
5
+ import { LogLevel } from 'consola';
6
+ import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
7
+
8
+ interface InlineConfig {
9
+ /**
10
+ * Your project's root directory containing the `package.json` used to fill out the
11
+ * `manifest.json`.
12
+ *
13
+ * @default process.cwd()
14
+ */
15
+ root?: string;
16
+ /**
17
+ * Directory containing all source code. Set to `"src"` to move all source code to a `src/`
18
+ * directory.
19
+ *
20
+ * @default config.root
21
+ */
22
+ srcDir?: string;
23
+ /**
24
+ * Directory containing files that will be copied to the output directory as-is.
25
+ *
26
+ * @default "${config.root}/public"
27
+ */
28
+ publicDir?: string;
29
+ /**
30
+ * @default "${config.srcDir}/entrypoints"
31
+ */
32
+ entrypointsDir?: string;
33
+ /**
34
+ * > Only available when using the JS API. Not available in `wxt.config.ts` files
35
+ *
36
+ * Path to `wxt.config.ts` file or `false` to disable config file discovery.
37
+ *
38
+ * @default "wxt.config.ts"
39
+ */
40
+ configFile?: string | false;
41
+ /**
42
+ * Set to `true` to show debug logs. Overriden by the command line `--debug` option.
43
+ *
44
+ * @default false
45
+ */
46
+ debug?: boolean;
47
+ /**
48
+ * Explicitly set a mode to run in. This will override the default mode for each command, and can
49
+ * be overridden by the command line `--mode` option.
50
+ */
51
+ mode?: string;
52
+ /**
53
+ * Customize auto-import options. Set to `false` to disable auto-imports.
54
+ *
55
+ * For example, to add a directory to auto-import from, you can use:
56
+ *
57
+ * ```ts
58
+ * export default defineConfig({
59
+ * imports: {
60
+ * dirs: ["some-directory"]
61
+ * }
62
+ * })
63
+ * ```
64
+ */
65
+ imports?: Partial<UnimportOptions> | false;
66
+ /**
67
+ * Explicitly set a browser to build for. This will override the default browser for each command,
68
+ * and can be overridden by the command line `--browser` option.
69
+ *
70
+ * @default
71
+ * "chrome"
72
+ */
73
+ browser?: TargetBrowser;
74
+ /**
75
+ * Explicitly set a manifest version to target. This will override the default manifest version
76
+ * for each command, and can be overridden by the command line `--mv2` or `--mv3` option.
77
+ */
78
+ manifestVersion?: TargetManifestVersion;
79
+ /**
80
+ * Override the logger used.
81
+ *
82
+ * @default
83
+ * consola
84
+ */
85
+ logger?: Logger;
86
+ /**
87
+ * Return custom Vite options from a function. See
88
+ * <https://vitejs.dev/config/shared-options.html>.
89
+ *
90
+ * [`root`](#root), [`configFile`](#configfile), and [`mode`](#mode) should be set in WXT's config
91
+ * instead of Vite's.
92
+ *
93
+ * This is a function because any vite plugins added need to be recreated for each individual
94
+ * build step, incase they have internal state causing them to fail when reused.
95
+ */
96
+ vite?: (env: ConfigEnv) => WxtViteConfig | Promise<WxtViteConfig>;
97
+ /**
98
+ * Customize the `manifest.json` output. Can be an object, promise, or function that returns an
99
+ * object or promise.
100
+ */
101
+ manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
102
+ /**
103
+ * Custom runner options. Options set here can be overridden in a `web-ext.config.ts` file.
104
+ */
105
+ runner?: ExtensionRunnerConfig;
106
+ zip?: {
107
+ /**
108
+ * Configure the filename output when zipping files.
109
+ *
110
+ * Available template variables:
111
+ *
112
+ * - `{{name}}` - The project's name converted to kebab-case
113
+ * - `{{version}}` - The version_name or version from the manifest
114
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
115
+ * - `{{manifestVersion}}` - Either "2" or "3"
116
+ *
117
+ * @default "{{name}}-{{version}}-{{browser}}.zip"
118
+ */
119
+ artifactTemplate?: string;
120
+ /**
121
+ * Configure the filename output when zipping files.
122
+ *
123
+ * Available template variables:
124
+ *
125
+ * - `{{name}}` - The project's name converted to kebab-case
126
+ * - `{{version}}` - The version_name or version from the manifest
127
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
128
+ * - `{{manifestVersion}}` - Either "2" or "3"
129
+ *
130
+ * @default "{{name}}-{{version}}-sources.zip"
131
+ */
132
+ sourcesTemplate?: string;
133
+ /**
134
+ * Override the artifactTemplate's `{name}` template variable. Defaults to the `package.json`'s
135
+ * name, or if that doesn't exist, the current working directories name.
136
+ */
137
+ name?: string;
138
+ /**
139
+ * Root directory to ZIP when generating the sources ZIP.
140
+ *
141
+ * @default config.root
142
+ */
143
+ sourcesRoot?: string;
144
+ /**
145
+ * [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to exclude when
146
+ * creating a ZIP of all your source code for Firfox. Patterns are relative to your
147
+ * `config.zip.sourcesRoot`.
148
+ *
149
+ * Hidden files, node_modules, and tests are ignored by default.
150
+ *
151
+ * @example
152
+ * [
153
+ * "coverage", // Ignore the coverage directory in the `sourcesRoot`
154
+ * ]
155
+ */
156
+ ignoredSources?: string[];
157
+ };
158
+ /**
159
+ * Transform the final manifest before it's written to the file system. Edit the `manifest`
160
+ * parameter directly, do not return a new object. Return values are ignored.
161
+ *
162
+ * @example
163
+ * defineConfig({
164
+ * // Add a CSS-only content script.
165
+ * transformManifest(manifest) {
166
+ * manifest.content_scripts.push({
167
+ * matches: ["*://google.com/*"],
168
+ * css: ["content-scripts/some-example.css"],
169
+ * });
170
+ * }
171
+ * })
172
+ */
173
+ transformManifest?: (manifest: Manifest.WebExtensionManifest) => void;
174
+ analysis?: {
175
+ /**
176
+ * Explicitly include bundle analysis when running `wxt build`. This can be overridden by the
177
+ * command line `--analysis` option.
178
+ *
179
+ * @default false
180
+ */
181
+ enabled?: boolean;
182
+ /**
183
+ * When running `wxt build --analyze` or setting `analysis.enabled` to true, customize how the
184
+ * bundle will be visualized. See
185
+ * [`rollup-plugin-visualizer`](https://github.com/btd/rollup-plugin-visualizer#how-to-use-generated-files)
186
+ * for more details.
187
+ *
188
+ * @default "treemap"
189
+ */
190
+ template?: PluginVisualizerOptions['template'];
191
+ };
192
+ }
193
+ type TargetBrowser = string;
194
+ type TargetManifestVersion = 2 | 3;
195
+ interface Logger {
196
+ debug(...args: any[]): void;
197
+ log(...args: any[]): void;
198
+ info(...args: any[]): void;
199
+ warn(...args: any[]): void;
200
+ error(...args: any[]): void;
201
+ fatal(...args: any[]): void;
202
+ success(...args: any[]): void;
203
+ level: LogLevel;
204
+ }
205
+ /**
206
+ * Manifest customization available in the `wxt.config.ts` file. You cannot configure entrypoints
207
+ * here, they are configured inline.
208
+ */
209
+ type UserManifest = Partial<Omit<Manifest.WebExtensionManifest, 'action' | 'background' | 'browser_action' | 'chrome_url_overrides' | 'devtools_page' | 'manifest_version' | 'options_page' | 'options_ui' | 'sandbox' | 'page_action' | 'popup' | 'sidepanel' | 'sidebar_action'>>;
210
+ type UserManifestFn = (env: ConfigEnv) => UserManifest | Promise<UserManifest>;
211
+ interface ConfigEnv {
212
+ mode: string;
213
+ command: 'build' | 'serve';
214
+ /**
215
+ * Browser passed in from the CLI
216
+ */
217
+ browser: TargetBrowser;
218
+ /**
219
+ * Manifest version passed in from the CLI
220
+ */
221
+ manifestVersion: 2 | 3;
222
+ }
223
+ /**
224
+ * Configure how the browser starts up.
225
+ */
226
+ interface ExtensionRunnerConfig {
227
+ /**
228
+ * Whether or not to open the browser with the extension installed in dev mode.
229
+ *
230
+ * @default false
231
+ */
232
+ disabled?: boolean;
233
+ /**
234
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#browser-console
235
+ */
236
+ openConsole?: boolean;
237
+ /**
238
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#devtools
239
+ */
240
+ openDevtools?: boolean;
241
+ /**
242
+ * List of browser names and the binary that should be used to open the browser.
243
+ *
244
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-binary
245
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#firefox
246
+ */
247
+ binaries?: Record<string, string>;
248
+ /**
249
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#firefox-profile
250
+ */
251
+ firefoxProfile?: string;
252
+ /**
253
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-profile
254
+ */
255
+ chromiumProfile?: string;
256
+ /**
257
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#pref
258
+ */
259
+ firefoxPrefs?: Record<string, string>;
260
+ /**
261
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#args
262
+ */
263
+ firefoxArgs?: string[];
264
+ /**
265
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#args
266
+ */
267
+ chromiumArgs?: string[];
268
+ /**
269
+ * @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#start-url
270
+ */
271
+ startUrls?: string[];
272
+ }
273
+ type WxtViteConfig = Omit<vite.UserConfig, 'root' | 'configFile' | 'mode'>;
274
+
275
+ /**
276
+ * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
277
+ *
278
+ * ```ts
279
+ * // vitest.config.ts
280
+ * import { defineConfig } from 'vitest/config';
281
+ * import { AutoImport } from 'wxt/testing';
282
+ *
283
+ * export default defineConfig({
284
+ * plugins: [AutoImport()],
285
+ * });
286
+ * ```
287
+ *
288
+ * @param inlineConfig Customize WXT's config for testing. Any config specified here overrides the config from your `wxt.config.ts` file.
289
+ */
290
+ declare function WxtVitest(inlineConfig?: InlineConfig): vite.PluginOption;
291
+
292
+ export { WxtVitest };