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.
Files changed (141) hide show
  1. package/bin/wxt-publish-extension.mjs +4 -3
  2. package/dist/browser.d.mts +7 -6
  3. package/dist/browser.mjs +6 -5
  4. package/dist/builtin-modules/index.mjs +1 -3
  5. package/dist/builtin-modules/unimport.mjs +1 -3
  6. package/dist/cli/cli-utils.mjs +5 -6
  7. package/dist/cli/commands.mjs +1 -3
  8. package/dist/cli/index.mjs +1 -3
  9. package/dist/core/build.d.mts +9 -8
  10. package/dist/core/build.mjs +10 -11
  11. package/dist/core/builders/vite/index.mjs +27 -25
  12. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
  13. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
  14. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
  15. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
  16. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
  17. package/dist/core/builders/vite/plugins/download.mjs +15 -11
  18. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
  19. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
  20. package/dist/core/builders/vite/plugins/globals.mjs +1 -3
  21. package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
  22. package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
  23. package/dist/core/builders/vite/plugins/index.mjs +18 -19
  24. package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
  25. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
  26. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
  27. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
  28. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
  29. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
  30. package/dist/core/clean.d.mts +7 -7
  31. package/dist/core/clean.mjs +6 -7
  32. package/dist/core/create-server.d.mts +6 -5
  33. package/dist/core/create-server.mjs +12 -11
  34. package/dist/core/define-config.mjs +1 -2
  35. package/dist/core/define-web-ext-config.d.mts +3 -4
  36. package/dist/core/define-web-ext-config.mjs +4 -7
  37. package/dist/core/generate-wxt-dir.mjs +8 -9
  38. package/dist/core/index.mjs +10 -11
  39. package/dist/core/initialize.mjs +10 -11
  40. package/dist/core/keyboard-shortcuts.mjs +2 -6
  41. package/dist/core/package-managers/bun.mjs +1 -3
  42. package/dist/core/package-managers/deno.mjs +1 -2
  43. package/dist/core/package-managers/index.mjs +1 -3
  44. package/dist/core/package-managers/npm.mjs +3 -5
  45. package/dist/core/package-managers/pnpm.mjs +1 -3
  46. package/dist/core/package-managers/yarn.mjs +1 -3
  47. package/dist/core/prepare.mjs +1 -3
  48. package/dist/core/resolve-config.mjs +20 -23
  49. package/dist/core/runners/index.mjs +1 -3
  50. package/dist/core/runners/manual.mjs +2 -6
  51. package/dist/core/runners/safari.mjs +3 -4
  52. package/dist/core/runners/web-ext.mjs +2 -6
  53. package/dist/core/runners/wsl.mjs +3 -4
  54. package/dist/core/utils/arrays.mjs +4 -11
  55. package/dist/core/utils/building/build-entrypoints.mjs +8 -9
  56. package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
  57. package/dist/core/utils/building/find-entrypoints.mjs +16 -11
  58. package/dist/core/utils/building/group-entrypoints.mjs +3 -4
  59. package/dist/core/utils/building/index.mjs +7 -8
  60. package/dist/core/utils/building/internal-build.mjs +13 -13
  61. package/dist/core/utils/building/rebuild.mjs +10 -10
  62. package/dist/core/utils/cache.mjs +6 -8
  63. package/dist/core/utils/constants.mjs +3 -4
  64. package/dist/core/utils/content-scripts.mjs +3 -4
  65. package/dist/core/utils/content-security-policy.mjs +2 -5
  66. package/dist/core/utils/entrypoints.mjs +6 -10
  67. package/dist/core/utils/env.mjs +2 -6
  68. package/dist/core/utils/environments/browser-environment.mjs +1 -3
  69. package/dist/core/utils/environments/environment.mjs +1 -2
  70. package/dist/core/utils/environments/extension-environment.mjs +1 -3
  71. package/dist/core/utils/environments/index.mjs +3 -4
  72. package/dist/core/utils/eslint.mjs +1 -2
  73. package/dist/core/utils/fs.mjs +23 -14
  74. package/dist/core/utils/globals.mjs +1 -2
  75. package/dist/core/utils/i18n.mjs +1 -2
  76. package/dist/core/utils/index.mjs +2 -3
  77. package/dist/core/utils/log/index.mjs +5 -6
  78. package/dist/core/utils/log/printBuildSummary.mjs +1 -3
  79. package/dist/core/utils/log/printFileList.mjs +3 -5
  80. package/dist/core/utils/log/printHeader.mjs +1 -3
  81. package/dist/core/utils/log/printTable.mjs +1 -2
  82. package/dist/core/utils/manifest.mjs +23 -31
  83. package/dist/core/utils/minimatch-multiple.mjs +5 -7
  84. package/dist/core/utils/network.mjs +3 -5
  85. package/dist/core/utils/number.mjs +1 -2
  86. package/dist/core/utils/package.mjs +3 -5
  87. package/dist/core/utils/paths.d.mts +2 -2
  88. package/dist/core/utils/paths.mjs +7 -9
  89. package/dist/core/utils/strings.mjs +4 -7
  90. package/dist/core/utils/syntax-errors.mjs +1 -3
  91. package/dist/core/utils/time.mjs +2 -5
  92. package/dist/core/utils/transform.mjs +8 -6
  93. package/dist/core/utils/validation.mjs +1 -2
  94. package/dist/core/utils/virtual-modules.mjs +9 -15
  95. package/dist/core/utils/wsl.mjs +2 -6
  96. package/dist/core/wxt.mjs +7 -9
  97. package/dist/core/zip.d.mts +1 -0
  98. package/dist/core/zip.mjs +11 -10
  99. package/dist/index.d.mts +0 -1
  100. package/dist/index.mjs +1 -2
  101. package/dist/modules.d.mts +64 -61
  102. package/dist/modules.mjs +70 -66
  103. package/dist/testing/fake-browser.mjs +1 -2
  104. package/dist/testing/index.mjs +1 -2
  105. package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
  106. package/dist/testing/wxt-vitest-plugin.mjs +5 -5
  107. package/dist/types.d.mts +455 -435
  108. package/dist/utils/app-config.mjs +1 -3
  109. package/dist/utils/content-script-context.d.mts +49 -39
  110. package/dist/utils/content-script-context.mjs +36 -31
  111. package/dist/utils/content-script-ui/iframe.d.mts +12 -13
  112. package/dist/utils/content-script-ui/iframe.mjs +1 -3
  113. package/dist/utils/content-script-ui/integrated.d.mts +8 -7
  114. package/dist/utils/content-script-ui/integrated.mjs +1 -3
  115. package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
  116. package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
  117. package/dist/utils/content-script-ui/shared.mjs +1 -3
  118. package/dist/utils/content-script-ui/types.d.mts +29 -34
  119. package/dist/utils/content-script-ui/types.mjs +1 -1
  120. package/dist/utils/define-app-config.d.mts +4 -3
  121. package/dist/utils/define-app-config.mjs +5 -5
  122. package/dist/utils/define-background.mjs +1 -2
  123. package/dist/utils/define-content-script.mjs +1 -2
  124. package/dist/utils/define-unlisted-script.mjs +1 -2
  125. package/dist/utils/define-wxt-plugin.mjs +1 -2
  126. package/dist/utils/inject-script.mjs +1 -3
  127. package/dist/utils/internal/custom-events.mjs +3 -4
  128. package/dist/utils/internal/location-watcher.mjs +4 -6
  129. package/dist/utils/internal/logger.mjs +2 -5
  130. package/dist/utils/match-patterns.mjs +2 -3
  131. package/dist/utils/split-shadow-root-css.d.mts +6 -2
  132. package/dist/utils/split-shadow-root-css.mjs +7 -4
  133. package/dist/utils/storage.mjs +2 -3
  134. package/dist/version.mjs +2 -3
  135. package/dist/virtual/background-entrypoint.mjs +4 -16
  136. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
  137. package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
  138. package/dist/virtual/mock-browser.mjs +1 -3
  139. package/dist/virtual/reload-html.mjs +3 -10
  140. package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
  141. package/package.json +17 -19
package/dist/modules.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import glob from "fast-glob";
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
- * export default defineWxtModule(async (wxt, options) => {
26
- * const entrypointPath = "/path/to/my-entrypoint.ts";
27
- * addEntrypoint(wxt, {
28
- * type: "content-script",
29
- * name: "some-name",
30
- * inputPath: entrypointPath,
31
- * outputDir: wxt.config.outDir,
32
- * options: await wxt.builder.importEntrypoint(entrypointPath),
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("**/*", { cwd: dir });
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
- * up individual builds. Config in the project's `wxt.config.ts` file takes
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
- * export default defineWxtModule((wxt, options) => {
77
+ * export default defineWxtModule((wxt, options) => {
80
78
  * addViteConfig(wxt, () => ({
81
- * build: {
82
- * sourceMaps: true,
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
- * the `main` function, plugins are executed.
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
- * file to load at runtime.
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 ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
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 [auto-scanned](https://github.com/unjs/unimport?tab=readme-ov-file#exports-auto-scan)),
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
- * @param wxt The wxt instance provided by the module's setup function.
127
- * @param preset The preset to add to the project.
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
- * export default defineWxtModule((wxt) => {
132
+ * export default defineWxtModule((wxt) => {
131
133
  * // Built-in preset:
132
134
  * addImportPreset(wxt, "vue");
133
135
  * // Custom preset:
134
136
  * addImportPreset(wxt, {
135
- * from: "vue",
136
- * imports: ["ref", "reactive", ...],
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
- * be absolute or relative to the project's root directory.
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
- * import path from 'node:path';
164
+ * import path from 'node:path';
160
165
  *
161
- * export default defineWxtModule((wxt) => {
162
- * const i18nPath = path.resolve(wxt.config.wxtDir, "i18n.ts");
166
+ * export default defineWxtModule((wxt) => {
167
+ * const i18nPath = path.resolve(wxt.config.wxtDir, 'i18n.ts');
163
168
  *
164
- * // Generate the file
165
- * wxt.hooks.hook("prepare:types", (_, entries) => {
166
- * entries.push({
167
- * path: i18nPath,
168
- * text: `export const i18n = ...`,
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
- * // Add alias
173
- * addAlias(wxt, "#i18n", i18nPath);
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 };
@@ -1,3 +1,2 @@
1
1
  import { fakeBrowser } from "@webext-core/fake-browser";
2
-
3
- export { fakeBrowser };
2
+ export { fakeBrowser };
@@ -1,4 +1,3 @@
1
1
  import { fakeBrowser } from "./fake-browser.mjs";
2
2
  import { WxtVitest } from "./wxt-vitest-plugin.mjs";
3
-
4
- export { WxtVitest, fakeBrowser };
3
+ export { WxtVitest, fakeBrowser };
@@ -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 extension, based on the `<root>/wxt.config.ts`
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 here overrides the config from your `wxt.config.ts` file.
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 extension, based on the `<root>/wxt.config.ts`
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 here overrides the config from your `wxt.config.ts` file.
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 };