wxt 0.20.18 → 0.20.20
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.
- package/bin/wxt-publish-extension.mjs +4 -3
- package/dist/browser.d.mts +7 -6
- package/dist/browser.mjs +6 -5
- package/dist/builtin-modules/index.mjs +1 -3
- package/dist/builtin-modules/unimport.mjs +1 -3
- package/dist/cli/cli-utils.mjs +5 -6
- package/dist/cli/commands.mjs +1 -3
- package/dist/cli/index.mjs +1 -3
- package/dist/core/build.d.mts +9 -8
- package/dist/core/build.mjs +10 -11
- package/dist/core/builders/vite/index.mjs +27 -25
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
- package/dist/core/builders/vite/plugins/download.mjs +15 -11
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
- package/dist/core/builders/vite/plugins/globals.mjs +1 -3
- package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
- package/dist/core/builders/vite/plugins/index.mjs +18 -19
- package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
- package/dist/core/clean.d.mts +7 -7
- package/dist/core/clean.mjs +6 -7
- package/dist/core/create-server.d.mts +6 -5
- package/dist/core/create-server.mjs +12 -11
- package/dist/core/define-config.mjs +1 -2
- package/dist/core/define-web-ext-config.d.mts +3 -4
- package/dist/core/define-web-ext-config.mjs +4 -7
- package/dist/core/generate-wxt-dir.mjs +8 -9
- package/dist/core/index.mjs +10 -11
- package/dist/core/initialize.mjs +10 -11
- package/dist/core/keyboard-shortcuts.mjs +2 -6
- package/dist/core/package-managers/bun.mjs +1 -3
- package/dist/core/package-managers/deno.mjs +1 -2
- package/dist/core/package-managers/index.mjs +1 -3
- package/dist/core/package-managers/npm.mjs +3 -5
- package/dist/core/package-managers/pnpm.mjs +1 -3
- package/dist/core/package-managers/yarn.mjs +1 -3
- package/dist/core/prepare.mjs +1 -3
- package/dist/core/resolve-config.mjs +20 -23
- package/dist/core/runners/index.mjs +1 -3
- package/dist/core/runners/manual.mjs +2 -6
- package/dist/core/runners/safari.mjs +3 -4
- package/dist/core/runners/web-ext.mjs +2 -6
- package/dist/core/runners/wsl.mjs +3 -4
- package/dist/core/utils/arrays.mjs +4 -11
- package/dist/core/utils/building/build-entrypoints.mjs +8 -9
- package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
- package/dist/core/utils/building/find-entrypoints.mjs +16 -11
- package/dist/core/utils/building/group-entrypoints.mjs +3 -4
- package/dist/core/utils/building/index.mjs +7 -8
- package/dist/core/utils/building/internal-build.mjs +13 -13
- package/dist/core/utils/building/rebuild.mjs +10 -10
- package/dist/core/utils/cache.mjs +6 -8
- package/dist/core/utils/constants.mjs +3 -4
- package/dist/core/utils/content-scripts.mjs +3 -4
- package/dist/core/utils/content-security-policy.mjs +2 -5
- package/dist/core/utils/entrypoints.mjs +6 -10
- package/dist/core/utils/env.mjs +2 -6
- package/dist/core/utils/environments/browser-environment.mjs +1 -3
- package/dist/core/utils/environments/environment.mjs +1 -2
- package/dist/core/utils/environments/extension-environment.mjs +1 -3
- package/dist/core/utils/environments/index.mjs +3 -4
- package/dist/core/utils/eslint.mjs +1 -2
- package/dist/core/utils/fs.mjs +23 -14
- package/dist/core/utils/globals.mjs +1 -2
- package/dist/core/utils/i18n.mjs +1 -2
- package/dist/core/utils/index.mjs +2 -3
- package/dist/core/utils/log/index.mjs +5 -6
- package/dist/core/utils/log/printBuildSummary.mjs +1 -3
- package/dist/core/utils/log/printFileList.mjs +3 -5
- package/dist/core/utils/log/printHeader.mjs +1 -3
- package/dist/core/utils/log/printTable.mjs +1 -2
- package/dist/core/utils/manifest.mjs +23 -31
- package/dist/core/utils/minimatch-multiple.mjs +5 -7
- package/dist/core/utils/network.mjs +3 -5
- package/dist/core/utils/number.mjs +1 -2
- package/dist/core/utils/package.mjs +3 -5
- package/dist/core/utils/paths.d.mts +2 -2
- package/dist/core/utils/paths.mjs +7 -9
- package/dist/core/utils/strings.mjs +4 -7
- package/dist/core/utils/syntax-errors.mjs +1 -3
- package/dist/core/utils/time.mjs +2 -5
- package/dist/core/utils/transform.mjs +8 -6
- package/dist/core/utils/validation.mjs +1 -2
- package/dist/core/utils/virtual-modules.mjs +9 -15
- package/dist/core/utils/wsl.mjs +2 -6
- package/dist/core/wxt.mjs +7 -9
- package/dist/core/zip.d.mts +1 -0
- package/dist/core/zip.mjs +11 -10
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +1 -2
- package/dist/modules.d.mts +64 -61
- package/dist/modules.mjs +70 -66
- package/dist/testing/fake-browser.mjs +1 -2
- package/dist/testing/index.mjs +1 -2
- package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
- package/dist/testing/wxt-vitest-plugin.mjs +5 -5
- package/dist/types.d.mts +455 -435
- package/dist/utils/app-config.mjs +1 -3
- package/dist/utils/content-script-context.d.mts +49 -39
- package/dist/utils/content-script-context.mjs +36 -31
- package/dist/utils/content-script-ui/iframe.d.mts +12 -13
- package/dist/utils/content-script-ui/iframe.mjs +1 -3
- package/dist/utils/content-script-ui/integrated.d.mts +8 -7
- package/dist/utils/content-script-ui/integrated.mjs +1 -3
- package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
- package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
- package/dist/utils/content-script-ui/shared.mjs +1 -3
- package/dist/utils/content-script-ui/types.d.mts +29 -34
- package/dist/utils/content-script-ui/types.mjs +1 -1
- package/dist/utils/define-app-config.d.mts +4 -3
- package/dist/utils/define-app-config.mjs +5 -5
- package/dist/utils/define-background.mjs +1 -2
- package/dist/utils/define-content-script.mjs +1 -2
- package/dist/utils/define-unlisted-script.mjs +1 -2
- package/dist/utils/define-wxt-plugin.mjs +1 -2
- package/dist/utils/inject-script.mjs +1 -3
- package/dist/utils/internal/custom-events.mjs +3 -4
- package/dist/utils/internal/location-watcher.mjs +4 -6
- package/dist/utils/internal/logger.mjs +2 -5
- package/dist/utils/match-patterns.mjs +2 -3
- package/dist/utils/split-shadow-root-css.d.mts +6 -2
- package/dist/utils/split-shadow-root-css.mjs +7 -4
- package/dist/utils/storage.mjs +2 -3
- package/dist/version.mjs +2 -3
- package/dist/virtual/background-entrypoint.mjs +4 -16
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
- package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
- package/dist/virtual/mock-browser.mjs +1 -3
- package/dist/virtual/reload-html.mjs +3 -10
- package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
- package/package.json +17 -19
package/dist/modules.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import glob from "
|
|
1
|
+
import { glob } from "tinyglobby";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
|
|
4
3
|
//#region src/modules.ts
|
|
5
4
|
function defineWxtModule(module) {
|
|
6
5
|
if (typeof module === "function") return { setup: module };
|
|
@@ -18,20 +17,20 @@ function defineWxtModule(module) {
|
|
|
18
17
|
* To extract entrypoint options from a JS/TS file, use
|
|
19
18
|
* `wxt.builder.importEntrypoint` (see example).
|
|
20
19
|
*
|
|
21
|
-
* @param wxt The wxt instance provided by the module's setup function.
|
|
22
|
-
* @param entrypoint The entrypoint to be bundled along with the extension.
|
|
23
|
-
*
|
|
24
20
|
* @example
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
21
|
+
* export default defineWxtModule(async (wxt, options) => {
|
|
22
|
+
* const entrypointPath = '/path/to/my-entrypoint.ts';
|
|
23
|
+
* addEntrypoint(wxt, {
|
|
24
|
+
* type: 'content-script',
|
|
25
|
+
* name: 'some-name',
|
|
26
|
+
* inputPath: entrypointPath,
|
|
27
|
+
* outputDir: wxt.config.outDir,
|
|
28
|
+
* options: await wxt.builder.importEntrypoint(entrypointPath),
|
|
29
|
+
* });
|
|
33
30
|
* });
|
|
34
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
33
|
+
* @param entrypoint The entrypoint to be bundled along with the extension.
|
|
35
34
|
*/
|
|
36
35
|
function addEntrypoint(wxt, entrypoint) {
|
|
37
36
|
wxt.hooks.hook("entrypoints:resolved", (_, entrypoints) => {
|
|
@@ -43,17 +42,20 @@ function addEntrypoint(wxt, entrypoint) {
|
|
|
43
42
|
* extension's output directory. The directory itself is not copied, just the
|
|
44
43
|
* files inside it. If a filename matches an existing one, it is ignored.
|
|
45
44
|
*
|
|
45
|
+
* @example
|
|
46
|
+
* export default defineWxtModule((wxt, options) => {
|
|
47
|
+
* addPublicAssets(wxt, './dist/prebundled');
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
46
50
|
* @param wxt The wxt instance provided by the module's setup function.
|
|
47
51
|
* @param dir The directory to copy.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* export default defineWxtModule((wxt, options) => {
|
|
51
|
-
* addPublicAssets(wxt, "./dist/prebundled");
|
|
52
|
-
* });
|
|
53
52
|
*/
|
|
54
53
|
function addPublicAssets(wxt, dir) {
|
|
55
54
|
wxt.hooks.hook("build:publicAssets", async (wxt, files) => {
|
|
56
|
-
const moreFiles = await glob("**/*", {
|
|
55
|
+
const moreFiles = await glob("**/*", {
|
|
56
|
+
cwd: dir,
|
|
57
|
+
expandDirectories: false
|
|
58
|
+
});
|
|
57
59
|
if (moreFiles.length === 0) {
|
|
58
60
|
wxt.logger.warn("No files to copy in", dir);
|
|
59
61
|
return;
|
|
@@ -67,22 +69,22 @@ function addPublicAssets(wxt, dir) {
|
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
|
-
* Merge additional vite config for one or more entrypoint "groups" that make
|
|
71
|
-
*
|
|
72
|
+
* Merge additional vite config for one or more entrypoint "groups" that make up
|
|
73
|
+
* individual builds. Config in the project's `wxt.config.ts` file takes
|
|
72
74
|
* precedence over any config added by this function.
|
|
73
75
|
*
|
|
74
|
-
* @param wxt The wxt instance provided by the module's setup function.
|
|
75
|
-
* @param viteConfig A function that returns the vite config the module is
|
|
76
|
-
adding. Same format as `vite` in `wxt.config.ts`.
|
|
77
|
-
*
|
|
78
76
|
* @example
|
|
79
|
-
*
|
|
77
|
+
* export default defineWxtModule((wxt, options) => {
|
|
80
78
|
* addViteConfig(wxt, () => ({
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
79
|
+
* build: {
|
|
80
|
+
* sourceMaps: true,
|
|
81
|
+
* },
|
|
84
82
|
* });
|
|
85
|
-
*
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
86
|
+
* @param viteConfig A function that returns the vite config the module is
|
|
87
|
+
* adding. Same format as `vite` in `wxt.config.ts`.
|
|
86
88
|
*/
|
|
87
89
|
function addViteConfig(wxt, viteConfig) {
|
|
88
90
|
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
@@ -95,17 +97,17 @@ function addViteConfig(wxt, viteConfig) {
|
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
98
|
-
* Add a runtime plugin to the project. In each entrypoint, before executing
|
|
99
|
-
*
|
|
100
|
+
* Add a runtime plugin to the project. In each entrypoint, before executing the
|
|
101
|
+
* `main` function, plugins are executed.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* export default defineWxtModule((wxt) => {
|
|
105
|
+
* addWxtPlugin(wxt, 'wxt-module-analytics/client-plugin');
|
|
106
|
+
* });
|
|
100
107
|
*
|
|
101
108
|
* @param wxt The wxt instance provided by the module's setup function.
|
|
102
109
|
* @param plugin An import from an NPM module, or an absolute file path to the
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* export default defineWxtModule((wxt) => {
|
|
107
|
-
* addWxtPlugin(wxt, "wxt-module-analytics/client-plugin");
|
|
108
|
-
* });
|
|
110
|
+
* file to load at runtime.
|
|
109
111
|
*/
|
|
110
112
|
function addWxtPlugin(wxt, plugin) {
|
|
111
113
|
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
@@ -113,31 +115,34 @@ function addWxtPlugin(wxt, plugin) {
|
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
/**
|
|
116
|
-
* Add an Unimport preset
|
|
118
|
+
* Add an Unimport preset
|
|
119
|
+
* ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|
|
117
120
|
* [custom](https://github.com/unjs/unimport?tab=readme-ov-file#custom-presets),
|
|
118
|
-
* or
|
|
121
|
+
* or
|
|
122
|
+
* [auto-scanned](https://github.com/unjs/unimport?tab=readme-ov-file#exports-auto-scan)),
|
|
119
123
|
* to the project's list of auto-imported utilities.
|
|
120
124
|
*
|
|
121
125
|
* Some things to note:
|
|
122
|
-
* - This function will only de-duplicate built-in preset names. It will not
|
|
123
|
-
* stop you adding duplicate custom or auto-scanned presets.
|
|
124
|
-
* - If the project has disabled imports, this function has no effect.
|
|
125
126
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
127
|
+
* - This function will only de-duplicate built-in preset names. It will not stop
|
|
128
|
+
* you adding duplicate custom or auto-scanned presets.
|
|
129
|
+
* - If the project has disabled imports, this function has no effect.
|
|
128
130
|
*
|
|
129
131
|
* @example
|
|
130
|
-
*
|
|
132
|
+
* export default defineWxtModule((wxt) => {
|
|
131
133
|
* // Built-in preset:
|
|
132
134
|
* addImportPreset(wxt, "vue");
|
|
133
135
|
* // Custom preset:
|
|
134
136
|
* addImportPreset(wxt, {
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
+
* from: "vue",
|
|
138
|
+
* imports: ["ref", "reactive", ...],
|
|
137
139
|
* });
|
|
138
140
|
* // Auto-scanned preset:
|
|
139
141
|
* addImportPreset(wxt, { package: "vue" });
|
|
140
|
-
*
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
145
|
+
* @param preset The preset to add to the project.
|
|
141
146
|
*/
|
|
142
147
|
function addImportPreset(wxt, preset) {
|
|
143
148
|
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
@@ -147,8 +152,8 @@ function addImportPreset(wxt, preset) {
|
|
|
147
152
|
});
|
|
148
153
|
}
|
|
149
154
|
/**
|
|
150
|
-
* Adds an import alias to the project's TSConfig paths and bundler. Path can
|
|
151
|
-
*
|
|
155
|
+
* Adds an import alias to the project's TSConfig paths and bundler. Path can be
|
|
156
|
+
* absolute or relative to the project's root directory.
|
|
152
157
|
*
|
|
153
158
|
* Usually, this is used to provide access to some code generated by your
|
|
154
159
|
* module. In the example below, a `i18n` plugin generates a variable that it
|
|
@@ -156,22 +161,22 @@ function addImportPreset(wxt, preset) {
|
|
|
156
161
|
* to it.
|
|
157
162
|
*
|
|
158
163
|
* @example
|
|
159
|
-
*
|
|
164
|
+
* import path from 'node:path';
|
|
160
165
|
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
166
|
+
* export default defineWxtModule((wxt) => {
|
|
167
|
+
* const i18nPath = path.resolve(wxt.config.wxtDir, 'i18n.ts');
|
|
163
168
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
+
* // Generate the file
|
|
170
|
+
* wxt.hooks.hook('prepare:types', (_, entries) => {
|
|
171
|
+
* entries.push({
|
|
172
|
+
* path: i18nPath,
|
|
173
|
+
* text: `export const i18n = ...`,
|
|
174
|
+
* });
|
|
169
175
|
* });
|
|
170
|
-
* });
|
|
171
176
|
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
177
|
+
* // Add alias
|
|
178
|
+
* addAlias(wxt, '#i18n', i18nPath);
|
|
179
|
+
* });
|
|
175
180
|
*/
|
|
176
181
|
function addAlias(wxt, alias, path) {
|
|
177
182
|
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
@@ -183,6 +188,5 @@ function addAlias(wxt, alias, path) {
|
|
|
183
188
|
wxt.config.alias[alias] = target;
|
|
184
189
|
});
|
|
185
190
|
}
|
|
186
|
-
|
|
187
191
|
//#endregion
|
|
188
|
-
export { addAlias, addEntrypoint, addImportPreset, addPublicAssets, addViteConfig, addWxtPlugin, defineWxtModule };
|
|
192
|
+
export { addAlias, addEntrypoint, addImportPreset, addPublicAssets, addViteConfig, addWxtPlugin, defineWxtModule };
|
package/dist/testing/index.mjs
CHANGED
|
@@ -3,7 +3,8 @@ import * as vite from "vite";
|
|
|
3
3
|
|
|
4
4
|
//#region src/testing/wxt-vitest-plugin.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* Vite plugin that configures Vitest with everything required to test a WXT
|
|
6
|
+
* Vite plugin that configures Vitest with everything required to test a WXT
|
|
7
|
+
* extension, based on the `<root>/wxt.config.ts`
|
|
7
8
|
*
|
|
8
9
|
* ```ts
|
|
9
10
|
* // vitest.config.ts
|
|
@@ -15,7 +16,8 @@ import * as vite from "vite";
|
|
|
15
16
|
* });
|
|
16
17
|
* ```
|
|
17
18
|
*
|
|
18
|
-
* @param inlineConfig Customize WXT's config for testing. Any config specified
|
|
19
|
+
* @param inlineConfig Customize WXT's config for testing. Any config specified
|
|
20
|
+
* here overrides the config from your `wxt.config.ts` file.
|
|
19
21
|
*/
|
|
20
22
|
declare function WxtVitest(inlineConfig?: InlineConfig): Promise<vite.PluginOption[]>;
|
|
21
23
|
//#endregion
|
|
@@ -6,10 +6,10 @@ import { resolveAppConfig } from "../core/builders/vite/plugins/resolveAppConfig
|
|
|
6
6
|
import "../core/builders/vite/plugins/index.mjs";
|
|
7
7
|
import { registerWxt, wxt } from "../core/wxt.mjs";
|
|
8
8
|
import UnimportPlugin from "unimport/unplugin";
|
|
9
|
-
|
|
10
9
|
//#region src/testing/wxt-vitest-plugin.ts
|
|
11
10
|
/**
|
|
12
|
-
* Vite plugin that configures Vitest with everything required to test a WXT
|
|
11
|
+
* Vite plugin that configures Vitest with everything required to test a WXT
|
|
12
|
+
* extension, based on the `<root>/wxt.config.ts`
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* // vitest.config.ts
|
|
@@ -21,7 +21,8 @@ import UnimportPlugin from "unimport/unplugin";
|
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
|
-
* @param inlineConfig Customize WXT's config for testing. Any config specified
|
|
24
|
+
* @param inlineConfig Customize WXT's config for testing. Any config specified
|
|
25
|
+
* here overrides the config from your `wxt.config.ts` file.
|
|
25
26
|
*/
|
|
26
27
|
async function WxtVitest(inlineConfig) {
|
|
27
28
|
await registerWxt("serve", inlineConfig ?? {});
|
|
@@ -35,6 +36,5 @@ async function WxtVitest(inlineConfig) {
|
|
|
35
36
|
plugins.push(UnimportPlugin.vite(wxt.config.imports));
|
|
36
37
|
return plugins;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
39
|
//#endregion
|
|
40
|
-
export { WxtVitest };
|
|
40
|
+
export { WxtVitest };
|