wxt 0.18.15 → 0.19.0

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 (257) hide show
  1. package/bin/wxt.mjs +1 -1
  2. package/dist/browser/chrome.d.ts +17 -0
  3. package/dist/browser/chrome.mjs +7 -0
  4. package/dist/browser/index.d.ts +18 -0
  5. package/dist/browser/index.mjs +2 -0
  6. package/dist/builtin-modules/index.d.ts +2 -0
  7. package/dist/builtin-modules/index.mjs +2 -0
  8. package/dist/builtin-modules/unimport.d.ts +8 -0
  9. package/dist/builtin-modules/unimport.mjs +99 -0
  10. package/dist/cli/cli-utils.d.ts +25 -0
  11. package/dist/cli/cli-utils.mjs +58 -0
  12. package/dist/cli/commands.d.ts +2 -0
  13. package/dist/cli/commands.mjs +104 -0
  14. package/dist/cli/index.d.ts +1 -0
  15. package/dist/cli/index.mjs +11 -0
  16. package/dist/client/app-config.d.ts +2 -0
  17. package/dist/client/app-config.mjs +4 -0
  18. package/dist/client/content-scripts/content-script-context.d.ts +114 -0
  19. package/dist/client/content-scripts/content-script-context.mjs +169 -0
  20. package/dist/client/content-scripts/custom-events.d.ts +10 -0
  21. package/dist/client/content-scripts/custom-events.mjs +13 -0
  22. package/dist/client/content-scripts/index.d.ts +2 -0
  23. package/dist/client/content-scripts/index.mjs +2 -0
  24. package/dist/client/content-scripts/location-watcher.d.ts +12 -0
  25. package/dist/client/content-scripts/location-watcher.mjs +22 -0
  26. package/dist/client/content-scripts/ui/index.d.ts +23 -0
  27. package/dist/client/content-scripts/ui/index.mjs +188 -0
  28. package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
  29. package/dist/client/content-scripts/ui/types.mjs +0 -0
  30. package/dist/client/index.d.ts +7 -0
  31. package/dist/client/index.mjs +2 -0
  32. package/dist/core/build.d.ts +15 -0
  33. package/dist/core/build.mjs +6 -0
  34. package/dist/core/builders/vite/index.d.ts +3 -0
  35. package/dist/core/builders/vite/index.mjs +285 -0
  36. package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
  37. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
  38. package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
  39. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
  40. package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
  41. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
  42. package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
  43. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
  44. package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
  45. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
  46. package/dist/core/builders/vite/plugins/download.d.ts +10 -0
  47. package/dist/core/builders/vite/plugins/download.mjs +14 -0
  48. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
  49. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
  50. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
  51. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
  52. package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
  53. package/dist/core/builders/vite/plugins/globals.mjs +15 -0
  54. package/dist/core/builders/vite/plugins/index.d.ts +17 -0
  55. package/dist/core/builders/vite/plugins/index.mjs +17 -0
  56. package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
  57. package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
  58. package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
  59. package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
  60. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
  61. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
  62. package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
  63. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
  64. package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
  65. package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
  66. package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
  67. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
  68. package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
  69. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
  70. package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
  71. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
  72. package/dist/core/clean.d.ts +21 -0
  73. package/dist/core/clean.mjs +38 -0
  74. package/dist/core/create-server.d.ts +11 -0
  75. package/dist/core/create-server.mjs +206 -0
  76. package/dist/core/define-config.d.ts +2 -0
  77. package/dist/core/define-config.mjs +3 -0
  78. package/dist/core/define-runner-config.d.ts +2 -0
  79. package/dist/core/define-runner-config.mjs +3 -0
  80. package/dist/core/index.d.ts +8 -0
  81. package/dist/core/index.mjs +8 -0
  82. package/dist/core/initialize.d.ts +5 -0
  83. package/dist/core/initialize.mjs +128 -0
  84. package/dist/core/package-managers/bun.d.ts +2 -0
  85. package/dist/core/package-managers/bun.mjs +19 -0
  86. package/dist/core/package-managers/index.d.ts +2 -0
  87. package/dist/core/package-managers/index.mjs +65 -0
  88. package/dist/core/package-managers/npm.d.ts +17 -0
  89. package/dist/core/package-managers/npm.mjs +58 -0
  90. package/dist/core/package-managers/pnpm.d.ts +2 -0
  91. package/dist/core/package-managers/pnpm.mjs +21 -0
  92. package/dist/core/package-managers/types.d.ts +2 -0
  93. package/dist/core/package-managers/types.mjs +0 -0
  94. package/dist/core/package-managers/yarn.d.ts +2 -0
  95. package/dist/core/package-managers/yarn.mjs +31 -0
  96. package/dist/core/prepare.d.ts +2 -0
  97. package/dist/core/prepare.mjs +8 -0
  98. package/dist/core/runners/index.d.ts +2 -0
  99. package/dist/core/runners/index.mjs +12 -0
  100. package/dist/core/runners/manual.d.ts +5 -0
  101. package/dist/core/runners/manual.mjs +16 -0
  102. package/dist/core/runners/safari.d.ts +5 -0
  103. package/dist/core/runners/safari.mjs +16 -0
  104. package/dist/core/runners/web-ext.d.ts +5 -0
  105. package/dist/core/runners/web-ext.mjs +78 -0
  106. package/dist/core/runners/wsl.d.ts +5 -0
  107. package/dist/core/runners/wsl.mjs +16 -0
  108. package/dist/core/utils/arrays.d.ts +13 -0
  109. package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
  110. package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
  111. package/dist/core/utils/building/build-entrypoints.mjs +47 -0
  112. package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
  113. package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
  114. package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
  115. package/dist/core/utils/building/find-entrypoints.mjs +385 -0
  116. package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
  117. package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
  118. package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
  119. package/dist/core/utils/building/group-entrypoints.mjs +37 -0
  120. package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
  121. package/dist/core/utils/building/import-entrypoint.mjs +97 -0
  122. package/dist/core/utils/building/index.d.ts +9 -0
  123. package/dist/core/utils/building/index.mjs +9 -0
  124. package/dist/core/utils/building/internal-build.d.ts +12 -0
  125. package/dist/core/utils/building/internal-build.mjs +112 -0
  126. package/dist/core/utils/building/rebuild.d.ts +23 -0
  127. package/dist/core/utils/building/rebuild.mjs +39 -0
  128. package/dist/core/utils/building/resolve-config.d.ts +11 -0
  129. package/dist/core/utils/building/resolve-config.mjs +364 -0
  130. package/dist/core/utils/cache.d.ts +8 -0
  131. package/dist/core/utils/cache.mjs +21 -0
  132. package/dist/core/utils/cli.d.ts +3 -0
  133. package/dist/core/utils/cli.mjs +26 -0
  134. package/dist/core/utils/constants.d.ts +5 -0
  135. package/dist/core/utils/constants.mjs +1 -0
  136. package/dist/core/utils/content-scripts.d.ts +11 -0
  137. package/dist/core/utils/content-scripts.mjs +60 -0
  138. package/dist/core/utils/content-security-policy.d.ts +14 -0
  139. package/dist/core/utils/content-security-policy.mjs +39 -0
  140. package/dist/core/utils/entrypoints.d.ts +25 -0
  141. package/dist/core/utils/entrypoints.mjs +31 -0
  142. package/dist/core/utils/eslint.d.ts +1 -0
  143. package/dist/core/utils/eslint.mjs +11 -0
  144. package/dist/core/utils/fs.d.ts +13 -0
  145. package/dist/core/utils/fs.mjs +15 -0
  146. package/dist/core/utils/globals.d.ts +11 -0
  147. package/dist/core/utils/globals.mjs +53 -0
  148. package/dist/core/utils/i18n.d.ts +11 -0
  149. package/dist/core/utils/i18n.mjs +35 -0
  150. package/dist/core/utils/log/index.d.ts +4 -0
  151. package/dist/core/utils/log/index.mjs +4 -0
  152. package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
  153. package/dist/core/utils/log/printBuildSummary.mjs +32 -0
  154. package/dist/core/utils/log/printFileList.d.ts +1 -0
  155. package/dist/core/utils/log/printFileList.mjs +42 -0
  156. package/dist/core/utils/log/printHeader.d.ts +1 -0
  157. package/dist/core/utils/log/printHeader.mjs +7 -0
  158. package/dist/core/utils/log/printTable.d.ts +1 -0
  159. package/dist/core/utils/log/printTable.mjs +22 -0
  160. package/dist/core/utils/manifest.d.ts +44 -0
  161. package/dist/core/utils/manifest.mjs +512 -0
  162. package/dist/core/utils/network.d.ts +7 -0
  163. package/dist/core/utils/network.mjs +38 -0
  164. package/dist/core/utils/package.d.ts +6 -0
  165. package/dist/core/utils/package.mjs +14 -0
  166. package/dist/core/utils/paths.d.ts +11 -0
  167. package/dist/core/utils/paths.mjs +10 -0
  168. package/dist/core/utils/strings.d.ts +14 -0
  169. package/dist/core/utils/strings.mjs +18 -0
  170. package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
  171. package/dist/core/utils/testing/fake-objects.mjs +322 -0
  172. package/dist/core/utils/time.d.ts +9 -0
  173. package/dist/core/utils/time.mjs +17 -0
  174. package/dist/core/utils/transform.d.ts +9 -0
  175. package/dist/core/utils/transform.mjs +17 -0
  176. package/dist/core/utils/types.d.ts +10 -0
  177. package/dist/core/utils/types.mjs +0 -0
  178. package/dist/core/utils/validation.d.ts +15 -0
  179. package/dist/core/utils/validation.mjs +55 -0
  180. package/dist/core/utils/virtual-modules.d.ts +22 -0
  181. package/dist/core/utils/virtual-modules.mjs +14 -0
  182. package/dist/core/utils/wsl.d.ts +4 -0
  183. package/dist/core/utils/wsl.mjs +4 -0
  184. package/dist/core/wxt.d.ts +19 -0
  185. package/dist/core/wxt.mjs +41 -0
  186. package/dist/core/zip.d.ts +7 -0
  187. package/dist/core/zip.mjs +137 -0
  188. package/dist/index.d.ts +4 -79
  189. package/dist/index.mjs +3 -0
  190. package/dist/modules.d.ts +10 -20
  191. package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
  192. package/dist/sandbox/define-app-config.d.ts +19 -0
  193. package/dist/sandbox/define-app-config.mjs +3 -0
  194. package/dist/sandbox/define-background.d.ts +3 -0
  195. package/dist/sandbox/define-background.mjs +4 -0
  196. package/dist/sandbox/define-content-script.d.ts +2 -0
  197. package/dist/sandbox/define-content-script.mjs +3 -0
  198. package/dist/sandbox/define-unlisted-script.d.ts +3 -0
  199. package/dist/sandbox/define-unlisted-script.mjs +4 -0
  200. package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
  201. package/dist/sandbox/define-wxt-plugin.mjs +3 -0
  202. package/dist/sandbox/dev-server-websocket.d.ts +21 -0
  203. package/dist/sandbox/dev-server-websocket.mjs +37 -0
  204. package/dist/sandbox/index.d.ts +11 -0
  205. package/dist/sandbox/index.mjs +6 -0
  206. package/dist/sandbox/utils/logger.d.ts +9 -0
  207. package/dist/sandbox/utils/logger.mjs +15 -0
  208. package/dist/storage.d.ts +39 -16
  209. package/dist/{storage.js → storage.mjs} +30 -41
  210. package/dist/testing/fake-browser.d.ts +1 -0
  211. package/dist/testing/fake-browser.mjs +1 -0
  212. package/dist/testing/index.d.ts +5 -0
  213. package/dist/testing/index.mjs +2 -0
  214. package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
  215. package/dist/testing/wxt-vitest-plugin.mjs +26 -0
  216. package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
  217. package/dist/types.mjs +0 -0
  218. package/dist/version.d.ts +1 -0
  219. package/dist/version.mjs +1 -0
  220. package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
  221. package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
  222. package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
  223. package/dist/virtual/mock-browser.mjs +6 -0
  224. package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
  225. package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
  226. package/package.json +47 -57
  227. package/dist/browser.d.ts +0 -18
  228. package/dist/browser.js +0 -6
  229. package/dist/chunk-BM6QYGAW.js +0 -1063
  230. package/dist/chunk-FNTE2L27.js +0 -7
  231. package/dist/chunk-FP7RYLVL.js +0 -3617
  232. package/dist/chunk-KPD5J7PZ.js +0 -1065
  233. package/dist/chunk-QGM4M3NI.js +0 -37
  234. package/dist/chunk-SGKCDMVR.js +0 -38
  235. package/dist/cli.d.ts +0 -2
  236. package/dist/cli.js +0 -4438
  237. package/dist/client.js +0 -424
  238. package/dist/define-app-config-bg54F_lV.d.ts +0 -294
  239. package/dist/execa-4UBDUBJZ.js +0 -7244
  240. package/dist/execa-QLUM2B3W.js +0 -7245
  241. package/dist/index-nWRfwAJi.d.ts +0 -1401
  242. package/dist/index.cjs +0 -14473
  243. package/dist/index.d.cts +0 -81
  244. package/dist/index.js +0 -696
  245. package/dist/modules.cjs +0 -96
  246. package/dist/modules.d.cts +0 -119
  247. package/dist/modules.js +0 -17
  248. package/dist/prompt-25QIVJDC.js +0 -755
  249. package/dist/prompt-7BMKNSWS.js +0 -754
  250. package/dist/sandbox.d.ts +0 -16
  251. package/dist/sandbox.js +0 -36
  252. package/dist/storage.cjs +0 -439
  253. package/dist/storage.d.cts +0 -200
  254. package/dist/testing.cjs +0 -2815
  255. package/dist/testing.d.cts +0 -30
  256. package/dist/testing.js +0 -40
  257. package/dist/virtual/mock-browser.js +0 -6
@@ -0,0 +1,17 @@
1
+ export * from './devHtmlPrerender';
2
+ export * from './devServerGlobals';
3
+ export * from './download';
4
+ export * from './multipageMove';
5
+ export * from './resolveVirtualModules';
6
+ export * from './tsconfigPaths';
7
+ export * from './noopBackground';
8
+ export * from './cssEntrypoints';
9
+ export * from './bundleAnalysis';
10
+ export * from './globals';
11
+ export * from './extensionApiMock';
12
+ export * from './resolveExtensionApi';
13
+ export * from './entrypointGroupGlobals';
14
+ export * from './defineImportMeta';
15
+ export * from './removeEntrypointMainFunction';
16
+ export * from './wxtPluginLoader';
17
+ export * from './resolveAppConfig';
@@ -0,0 +1,17 @@
1
+ export * from "./devHtmlPrerender.mjs";
2
+ export * from "./devServerGlobals.mjs";
3
+ export * from "./download.mjs";
4
+ export * from "./multipageMove.mjs";
5
+ export * from "./resolveVirtualModules.mjs";
6
+ export * from "./tsconfigPaths.mjs";
7
+ export * from "./noopBackground.mjs";
8
+ export * from "./cssEntrypoints.mjs";
9
+ export * from "./bundleAnalysis.mjs";
10
+ export * from "./globals.mjs";
11
+ export * from "./extensionApiMock.mjs";
12
+ export * from "./resolveExtensionApi.mjs";
13
+ export * from "./entrypointGroupGlobals.mjs";
14
+ export * from "./defineImportMeta.mjs";
15
+ export * from "./removeEntrypointMainFunction.mjs";
16
+ export * from "./wxtPluginLoader.mjs";
17
+ export * from "./resolveAppConfig.mjs";
@@ -0,0 +1,20 @@
1
+ import type * as vite from 'vite';
2
+ import { Entrypoint, ResolvedConfig } from '../../../../types';
3
+ /**
4
+ * Ensures the HTML files output by a multipage build are in the correct location. This does two
5
+ * things:
6
+ *
7
+ * 1. Moves the HMTL files to their final location at `<outDir>/<entrypoint.name>.html`.
8
+ * 2. Updates the bundle so it summarizes the files correctly in the returned build output.
9
+ *
10
+ * Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't need to be modified.
11
+ * HTML files access them via absolute URLs, so we don't need to update any import paths in the HTML
12
+ * files either.
13
+ *
14
+ * THIS PLUGIN SHOULD ONLY BE APPLIED TO MULTIPAGE BUILDS. It should not be added to every build.
15
+ */
16
+ export declare function multipageMove(entrypoints: Entrypoint[], config: ResolvedConfig): vite.Plugin;
17
+ /**
18
+ * Recursively remove all directories that are empty/
19
+ */
20
+ export declare function removeEmptyDirs(dir: string): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import { dirname, extname, resolve, join } from "node:path";
2
+ import { getEntrypointBundlePath } from "../../../utils/entrypoints.mjs";
3
+ import fs, { ensureDir } from "fs-extra";
4
+ import { normalizePath } from "../../../utils/paths.mjs";
5
+ export function multipageMove(entrypoints, config) {
6
+ return {
7
+ name: "wxt:multipage-move",
8
+ async writeBundle(_, bundle) {
9
+ for (const oldBundlePath in bundle) {
10
+ const entrypoint = entrypoints.find(
11
+ (entry) => !!normalizePath(entry.inputPath).endsWith(oldBundlePath)
12
+ );
13
+ if (entrypoint == null) {
14
+ config.logger.debug(
15
+ `No entrypoint found for ${oldBundlePath}, leaving in chunks directory`
16
+ );
17
+ continue;
18
+ }
19
+ const newBundlePath = getEntrypointBundlePath(
20
+ entrypoint,
21
+ config.outDir,
22
+ extname(oldBundlePath)
23
+ );
24
+ if (newBundlePath === oldBundlePath) {
25
+ config.logger.debug(
26
+ "HTML file is already in the correct location",
27
+ oldBundlePath
28
+ );
29
+ continue;
30
+ }
31
+ const oldAbsPath = resolve(config.outDir, oldBundlePath);
32
+ const newAbsPath = resolve(config.outDir, newBundlePath);
33
+ await ensureDir(dirname(newAbsPath));
34
+ await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
35
+ const renamedChunk = {
36
+ ...bundle[oldBundlePath],
37
+ fileName: newBundlePath
38
+ };
39
+ delete bundle[oldBundlePath];
40
+ bundle[newBundlePath] = renamedChunk;
41
+ }
42
+ removeEmptyDirs(config.outDir);
43
+ }
44
+ };
45
+ }
46
+ export async function removeEmptyDirs(dir) {
47
+ const files = await fs.readdir(dir);
48
+ for (const file of files) {
49
+ const filePath = join(dir, file);
50
+ const stats = await fs.stat(filePath);
51
+ if (stats.isDirectory()) {
52
+ await removeEmptyDirs(filePath);
53
+ }
54
+ }
55
+ try {
56
+ await fs.rmdir(dir);
57
+ } catch {
58
+ }
59
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'vite';
2
+ /**
3
+ * In dev mode, if there's not a background script listed, we need to add one so that the web socket
4
+ * connection is setup and the extension reloads HTML pages and content scripts correctly.
5
+ */
6
+ export declare function noopBackground(): Plugin;
@@ -0,0 +1,17 @@
1
+ import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../../utils/constants.mjs";
2
+ export function noopBackground() {
3
+ const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
4
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
5
+ return {
6
+ name: "wxt:noop-background",
7
+ resolveId(id) {
8
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
9
+ },
10
+ load(id) {
11
+ if (id === resolvedVirtualModuleId) {
12
+ return `import { defineBackground } from 'wxt/sandbox';
13
+ export default defineBackground(() => void 0)`;
14
+ }
15
+ }
16
+ };
17
+ }
@@ -0,0 +1,6 @@
1
+ import { ResolvedConfig } from '../../../../types';
2
+ import * as vite from 'vite';
3
+ /**
4
+ * Transforms entrypoints, removing the main function from the entrypoint if it exists.
5
+ */
6
+ export declare function removeEntrypointMainFunction(config: ResolvedConfig, path: string): vite.Plugin;
@@ -0,0 +1,12 @@
1
+ import { normalizePath } from "../../../utils/paths.mjs";
2
+ import { removeMainFunctionCode } from "../../../utils/transform.mjs";
3
+ import { resolve } from "node:path";
4
+ export function removeEntrypointMainFunction(config, path) {
5
+ const absPath = normalizePath(resolve(config.root, path));
6
+ return {
7
+ name: "wxt:remove-entrypoint-main-function",
8
+ transform(code, id) {
9
+ if (id === absPath) return removeMainFunctionCode(code);
10
+ }
11
+ };
12
+ }
@@ -0,0 +1,6 @@
1
+ import type * as vite from 'vite';
2
+ import { ResolvedConfig } from '../../../../types';
3
+ /**
4
+ * When importing `virtual:app-config`, resolve it to the `app.config.ts` file in the project.
5
+ */
6
+ export declare function resolveAppConfig(config: ResolvedConfig): vite.Plugin;
@@ -0,0 +1,26 @@
1
+ import { exists } from "fs-extra";
2
+ import { resolve } from "node:path";
3
+ export function resolveAppConfig(config) {
4
+ const virtualModuleId = "virtual:app-config";
5
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
6
+ const appConfigFile = resolve(config.srcDir, "app.config.ts");
7
+ return {
8
+ name: "wxt:resolve-app-config",
9
+ config() {
10
+ return {
11
+ optimizeDeps: {
12
+ // Prevent ESBuild from attempting to resolve the virtual module
13
+ // while optimizing WXT.
14
+ exclude: [virtualModuleId]
15
+ }
16
+ };
17
+ },
18
+ async resolveId(id) {
19
+ if (id !== virtualModuleId) return;
20
+ return await exists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
21
+ },
22
+ load(id) {
23
+ if (id === resolvedVirtualModuleId) return `export default {}`;
24
+ }
25
+ };
26
+ }
@@ -0,0 +1,10 @@
1
+ import { ResolvedConfig } from '../../../../types';
2
+ import type * as vite from 'vite';
3
+ /**
4
+ * Apply the experimental config for which extension API is used. This only
5
+ * effects the extension API included at RUNTIME - during development, types
6
+ * depend on the import.
7
+ *
8
+ * NOTE: this only works if we import `wxt/browser` instead of using the relative path.
9
+ */
10
+ export declare function resolveExtensionApi(config: ResolvedConfig): vite.Plugin;
@@ -0,0 +1,15 @@
1
+ export function resolveExtensionApi(config) {
2
+ return {
3
+ name: "wxt:resolve-extension-api",
4
+ config() {
5
+ if (config.extensionApi === "webextension-polyfill") return;
6
+ return {
7
+ resolve: {
8
+ alias: [
9
+ { find: /^wxt\/browser$/, replacement: "wxt/browser/chrome" }
10
+ ]
11
+ }
12
+ };
13
+ }
14
+ };
15
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'vite';
2
+ import { ResolvedConfig } from '../../../../types';
3
+ /**
4
+ * Resolve all the virtual modules to the `node_modules/wxt/dist/virtual` directory.
5
+ */
6
+ export declare function resolveVirtualModules(config: ResolvedConfig): Plugin[];
@@ -0,0 +1,30 @@
1
+ import { normalizePath } from "../../../utils/paths.mjs";
2
+ import {
3
+ virtualModuleNames
4
+ } from "../../../utils/virtual-modules.mjs";
5
+ import fs from "fs-extra";
6
+ import { resolve } from "path";
7
+ export function resolveVirtualModules(config) {
8
+ return virtualModuleNames.map((name) => {
9
+ const virtualId = `virtual:wxt-${name}?`;
10
+ const resolvedVirtualId = "\0" + virtualId;
11
+ return {
12
+ name: `wxt:resolve-virtual-${name}`,
13
+ resolveId(id) {
14
+ const index = id.indexOf(virtualId);
15
+ if (index === -1) return;
16
+ const inputPath = normalizePath(id.substring(index + virtualId.length));
17
+ return resolvedVirtualId + inputPath;
18
+ },
19
+ async load(id) {
20
+ if (!id.startsWith(resolvedVirtualId)) return;
21
+ const inputPath = id.replace(resolvedVirtualId, "");
22
+ const template = await fs.readFile(
23
+ resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`),
24
+ "utf-8"
25
+ );
26
+ return template.replace(`virtual:user-${name}`, inputPath);
27
+ }
28
+ };
29
+ });
30
+ }
@@ -0,0 +1,3 @@
1
+ import { ResolvedConfig } from '../../../../types';
2
+ import type * as vite from 'vite';
3
+ export declare function tsconfigPaths(config: ResolvedConfig): vite.Plugin;
@@ -0,0 +1,12 @@
1
+ export function tsconfigPaths(config) {
2
+ return {
3
+ name: "wxt:aliases",
4
+ async config() {
5
+ return {
6
+ resolve: {
7
+ alias: config.alias
8
+ }
9
+ };
10
+ }
11
+ };
12
+ }
@@ -0,0 +1,6 @@
1
+ import type * as vite from 'vite';
2
+ import { ResolvedConfig } from '../../../../types';
3
+ /**
4
+ * Resolve and load plugins for each entrypoint. This handles both JS entrypoints via the `virtual:wxt-plugins` import, and HTML files by adding `virtual:wxt-html-plugins` to the document's `<head>`
5
+ */
6
+ export declare function wxtPluginLoader(config: ResolvedConfig): vite.Plugin;
@@ -0,0 +1,56 @@
1
+ import { parseHTML } from "linkedom";
2
+ import { normalizePath } from "../../../utils/paths.mjs";
3
+ export function wxtPluginLoader(config) {
4
+ const virtualModuleId = "virtual:wxt-plugins";
5
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
6
+ const virtualHtmlModuleId = "virtual:wxt-html-plugins";
7
+ const resolvedVirtualHtmlModuleId = "\0" + virtualHtmlModuleId;
8
+ return {
9
+ name: "wxt:plugin-loader",
10
+ resolveId(id) {
11
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
12
+ if (id === virtualHtmlModuleId) return resolvedVirtualHtmlModuleId;
13
+ },
14
+ load(id) {
15
+ if (id === resolvedVirtualModuleId) {
16
+ const imports = config.plugins.map(
17
+ (plugin, i) => `import initPlugin${i} from '${normalizePath(plugin)}';`
18
+ ).join("\n");
19
+ const initCalls = config.plugins.map((_, i) => ` initPlugin${i}();`).join("\n");
20
+ return `${imports}
21
+
22
+ export function initPlugins() {
23
+ ${initCalls}
24
+ }`;
25
+ }
26
+ if (id === resolvedVirtualHtmlModuleId) {
27
+ return `import { initPlugins } from '${virtualModuleId}';
28
+
29
+ try {
30
+ initPlugins();
31
+ } catch (err) {
32
+ console.error("[wxt] Failed to initialize plugins", err);
33
+ }`;
34
+ }
35
+ },
36
+ transformIndexHtml: {
37
+ // Use "pre" so the new script is added before vite bundles all the scripts
38
+ order: "pre",
39
+ handler(html, _ctx) {
40
+ const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
41
+ const { document } = parseHTML(html);
42
+ const existing = document.querySelector(`script[src='${src}']`);
43
+ if (existing) return;
44
+ const script = document.createElement("script");
45
+ script.type = "module";
46
+ script.src = src;
47
+ if (document.head == null) {
48
+ const newHead = document.createElement("head");
49
+ document.documentElement.prepend(newHead);
50
+ }
51
+ document.head.prepend(script);
52
+ return document.toString();
53
+ }
54
+ }
55
+ };
56
+ }
@@ -0,0 +1,21 @@
1
+ import { InlineConfig } from '../types';
2
+ /**
3
+ * Remove generated/temp files from the directory.
4
+ *
5
+ * @param config Optional config that will override your `<root>/wxt.config.ts`.
6
+ *
7
+ * @example
8
+ * await clean();
9
+ */
10
+ export declare function clean(config?: InlineConfig): Promise<void>;
11
+ /**
12
+ * Remove generated/temp files from the directory.
13
+ *
14
+ * @deprecated
15
+ *
16
+ * @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
17
+ *
18
+ * @example
19
+ * await clean();
20
+ */
21
+ export declare function clean(root?: string): Promise<void>;
@@ -0,0 +1,38 @@
1
+ import path from "node:path";
2
+ import glob from "fast-glob";
3
+ import fs from "fs-extra";
4
+ import pc from "picocolors";
5
+ import { registerWxt, wxt } from "./wxt.mjs";
6
+ export async function clean(config) {
7
+ if (typeof config === "string") {
8
+ config = { root: config };
9
+ }
10
+ await registerWxt("build", config);
11
+ wxt.logger.info("Cleaning Project");
12
+ const root = wxt.config.root;
13
+ const tempDirs = [
14
+ "node_modules/.vite",
15
+ "node_modules/.cache",
16
+ "**/.wxt",
17
+ `${path.relative(root, wxt.config.outBaseDir)}/*`
18
+ ];
19
+ wxt.logger.debug("Looking for:", tempDirs.map(pc.cyan).join(", "));
20
+ const directories = await glob(tempDirs, {
21
+ cwd: root,
22
+ absolute: true,
23
+ onlyDirectories: true,
24
+ deep: 2
25
+ });
26
+ if (directories.length === 0) {
27
+ wxt.logger.debug("No generated files found.");
28
+ return;
29
+ }
30
+ wxt.logger.debug(
31
+ "Found:",
32
+ directories.map((dir) => pc.cyan(path.relative(root, dir))).join(", ")
33
+ );
34
+ for (const directory of directories) {
35
+ await fs.rm(directory, { force: true, recursive: true });
36
+ wxt.logger.debug("Deleted " + pc.cyan(path.relative(root, directory)));
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import { InlineConfig, WxtDevServer } from '../types';
2
+ /**
3
+ * Creates a dev server and pre-builds all the files that need to exist before loading the extension.
4
+ *
5
+ * @example
6
+ * const server = await wxt.createServer({
7
+ * // Enter config...
8
+ * });
9
+ * await server.start();
10
+ */
11
+ export declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
@@ -0,0 +1,206 @@
1
+ import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
2
+ import {
3
+ getContentScriptCssFiles,
4
+ getContentScriptsCssMap
5
+ } from "./utils/manifest.mjs";
6
+ import {
7
+ internalBuild,
8
+ detectDevChanges,
9
+ rebuild,
10
+ findEntrypoints
11
+ } from "./utils/building/index.mjs";
12
+ import { createExtensionRunner } from "./runners/index.mjs";
13
+ import { Mutex } from "async-mutex";
14
+ import pc from "picocolors";
15
+ import { relative } from "node:path";
16
+ import { registerWxt, wxt } from "./wxt.mjs";
17
+ import { unnormalizePath } from "./utils/paths.mjs";
18
+ import {
19
+ getContentScriptJs,
20
+ mapWxtOptionsToRegisteredContentScript
21
+ } from "./utils/content-scripts.mjs";
22
+ export async function createServer(inlineConfig) {
23
+ await registerWxt("serve", inlineConfig, async (config) => {
24
+ const { port, hostname } = config.dev.server;
25
+ const serverInfo = {
26
+ port,
27
+ hostname,
28
+ origin: `http://${hostname}:${port}`
29
+ };
30
+ const server2 = {
31
+ ...serverInfo,
32
+ get watcher() {
33
+ return builderServer.watcher;
34
+ },
35
+ get ws() {
36
+ return builderServer.ws;
37
+ },
38
+ currentOutput: void 0,
39
+ async start() {
40
+ await builderServer.listen();
41
+ wxt.logger.success(`Started dev server @ ${serverInfo.origin}`);
42
+ await buildAndOpenBrowser();
43
+ },
44
+ async stop() {
45
+ await runner.closeBrowser();
46
+ await builderServer.close();
47
+ },
48
+ async restart() {
49
+ await closeAndRecreateRunner();
50
+ await buildAndOpenBrowser();
51
+ },
52
+ transformHtml(url, html, originalUrl) {
53
+ return builderServer.transformHtml(url, html, originalUrl);
54
+ },
55
+ reloadContentScript(payload) {
56
+ server2.ws.send("wxt:reload-content-script", payload);
57
+ },
58
+ reloadPage(path) {
59
+ server2.ws.send("wxt:reload-page", path);
60
+ },
61
+ reloadExtension() {
62
+ server2.ws.send("wxt:reload-extension");
63
+ },
64
+ async restartBrowser() {
65
+ await closeAndRecreateRunner();
66
+ await runner.openBrowser();
67
+ }
68
+ };
69
+ return server2;
70
+ });
71
+ const server = wxt.server;
72
+ let [runner, builderServer] = await Promise.all([
73
+ createExtensionRunner(),
74
+ wxt.builder.createServer(server)
75
+ ]);
76
+ const buildAndOpenBrowser = async () => {
77
+ server.currentOutput = await internalBuild();
78
+ try {
79
+ server.watcher.add(getExternalOutputDependencies(server));
80
+ } catch (err) {
81
+ wxt.config.logger.warn("Failed to register additional file paths:", err);
82
+ }
83
+ await runner.openBrowser();
84
+ };
85
+ const closeAndRecreateRunner = async () => {
86
+ await runner.closeBrowser();
87
+ await wxt.reloadConfig();
88
+ runner = await createExtensionRunner();
89
+ };
90
+ server.ws.on("wxt:background-initialized", () => {
91
+ if (server.currentOutput == null) return;
92
+ reloadContentScripts(server.currentOutput.steps, server);
93
+ });
94
+ const reloadOnChange = createFileReloader(server);
95
+ server.watcher.on("all", reloadOnChange);
96
+ return server;
97
+ }
98
+ function createFileReloader(server) {
99
+ const fileChangedMutex = new Mutex();
100
+ const changeQueue = [];
101
+ return async (event, path) => {
102
+ await wxt.reloadConfig();
103
+ if (path.startsWith(wxt.config.outBaseDir)) return;
104
+ if (path.startsWith(wxt.config.wxtDir)) return;
105
+ changeQueue.push([event, path]);
106
+ await fileChangedMutex.runExclusive(async () => {
107
+ if (server.currentOutput == null) return;
108
+ const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
109
+ if (fileChanges.length === 0) return;
110
+ const changes = detectDevChanges(fileChanges, server.currentOutput);
111
+ if (changes.type === "no-change") return;
112
+ if (changes.type === "full-restart") {
113
+ wxt.logger.info("Config changed, restarting server...");
114
+ server.restart();
115
+ return;
116
+ }
117
+ if (changes.type === "browser-restart") {
118
+ wxt.logger.info("Runner config changed, restarting browser...");
119
+ server.restartBrowser();
120
+ return;
121
+ }
122
+ wxt.logger.info(
123
+ `Changed: ${Array.from(new Set(fileChanges)).map((file) => pc.dim(relative(wxt.config.root, file))).join(", ")}`
124
+ );
125
+ const allEntrypoints = await findEntrypoints();
126
+ try {
127
+ const { output: newOutput } = await rebuild(
128
+ allEntrypoints,
129
+ // TODO: this excludes new entrypoints, so they're not built until the dev command is restarted
130
+ changes.rebuildGroups,
131
+ changes.cachedOutput
132
+ );
133
+ server.currentOutput = newOutput;
134
+ switch (changes.type) {
135
+ case "extension-reload":
136
+ server.reloadExtension();
137
+ wxt.logger.success(`Reloaded extension`);
138
+ break;
139
+ case "html-reload":
140
+ const { reloadedNames } = reloadHtmlPages(
141
+ changes.rebuildGroups,
142
+ server
143
+ );
144
+ wxt.logger.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
145
+ break;
146
+ case "content-script-reload":
147
+ reloadContentScripts(changes.changedSteps, server);
148
+ const rebuiltNames = changes.rebuildGroups.flat().map((entry) => entry.name);
149
+ wxt.logger.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
150
+ break;
151
+ }
152
+ } catch (err) {
153
+ }
154
+ });
155
+ };
156
+ }
157
+ function reloadContentScripts(steps, server) {
158
+ if (wxt.config.manifestVersion === 3) {
159
+ steps.forEach((step) => {
160
+ if (server.currentOutput == null) return;
161
+ const entry = step.entrypoints;
162
+ if (Array.isArray(entry) || entry.type !== "content-script") return;
163
+ const js = getContentScriptJs(wxt.config, entry);
164
+ const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
165
+ const css = getContentScriptCssFiles([entry], cssMap);
166
+ server.reloadContentScript({
167
+ registration: entry.options.registration,
168
+ contentScript: mapWxtOptionsToRegisteredContentScript(
169
+ entry.options,
170
+ js,
171
+ css
172
+ )
173
+ });
174
+ });
175
+ } else {
176
+ server.reloadExtension();
177
+ }
178
+ }
179
+ function reloadHtmlPages(groups, server) {
180
+ const htmlEntries = groups.flat().filter(isHtmlEntrypoint);
181
+ htmlEntries.forEach((entry) => {
182
+ const path = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
183
+ server.reloadPage(path);
184
+ });
185
+ return {
186
+ reloadedNames: htmlEntries.map((entry) => entry.name)
187
+ };
188
+ }
189
+ function getFilenameList(names) {
190
+ return names.map((name) => {
191
+ return pc.cyan(name);
192
+ }).join(pc.dim(", "));
193
+ }
194
+ function getExternalOutputDependencies(server) {
195
+ return server.currentOutput?.steps.flatMap((step, i) => {
196
+ if (Array.isArray(step.entrypoints) && i === 0) {
197
+ return [];
198
+ }
199
+ return step.chunks.flatMap((chunk) => {
200
+ if (chunk.type === "asset") return [];
201
+ return chunk.moduleIds;
202
+ });
203
+ }).filter(
204
+ (file) => !file.includes("node_modules") && !file.startsWith("\0")
205
+ ).map(unnormalizePath).filter((file) => !file.startsWith(wxt.config.root)) ?? [];
206
+ }
@@ -0,0 +1,2 @@
1
+ import { UserConfig } from '../types';
2
+ export declare function defineConfig(config: UserConfig): UserConfig;
@@ -0,0 +1,3 @@
1
+ export function defineConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,2 @@
1
+ import { ExtensionRunnerConfig } from '../types';
2
+ export declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRunnerConfig;
@@ -0,0 +1,3 @@
1
+ export function defineRunnerConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,8 @@
1
+ export * from './build';
2
+ export * from './clean';
3
+ export * from './define-config';
4
+ export * from './define-runner-config';
5
+ export * from './create-server';
6
+ export * from './initialize';
7
+ export * from './prepare';
8
+ export * from './zip';
@@ -0,0 +1,8 @@
1
+ export * from "./build.mjs";
2
+ export * from "./clean.mjs";
3
+ export * from "./define-config.mjs";
4
+ export * from "./define-runner-config.mjs";
5
+ export * from "./create-server.mjs";
6
+ export * from "./initialize.mjs";
7
+ export * from "./prepare.mjs";
8
+ export * from "./zip.mjs";