wxt 0.20.13 → 0.20.14

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 (278) hide show
  1. package/dist/browser.d.mts +20 -0
  2. package/dist/browser.mjs +18 -3
  3. package/dist/builtin-modules/index.mjs +7 -2
  4. package/dist/builtin-modules/unimport.mjs +69 -75
  5. package/dist/cli/cli-utils.mjs +52 -50
  6. package/dist/cli/commands.mjs +77 -103
  7. package/dist/cli/index.d.mts +1 -0
  8. package/dist/cli/index.mjs +9 -4
  9. package/dist/core/{build.d.ts → build.d.mts} +6 -2
  10. package/dist/core/build.mjs +23 -4
  11. package/dist/core/builders/vite/index.mjs +292 -343
  12. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +11 -12
  13. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +27 -20
  14. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +17 -12
  15. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +104 -136
  16. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -14
  17. package/dist/core/builders/vite/plugins/download.mjs +23 -12
  18. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +18 -14
  19. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +31 -33
  20. package/dist/core/builders/vite/plugins/globals.mjs +14 -13
  21. package/dist/core/builders/vite/plugins/iifeFooter.mjs +17 -11
  22. package/dist/core/builders/vite/plugins/index.mjs +18 -16
  23. package/dist/core/builders/vite/plugins/noopBackground.mjs +21 -15
  24. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +25 -23
  25. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +25 -23
  26. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +27 -26
  27. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
  28. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +41 -47
  29. package/dist/core/{clean.d.ts → clean.d.mts} +7 -3
  30. package/dist/core/clean.mjs +38 -35
  31. package/dist/core/{create-server.d.ts → create-server.d.mts} +6 -2
  32. package/dist/core/create-server.mjs +236 -247
  33. package/dist/core/define-config.d.mts +6 -0
  34. package/dist/core/define-config.mjs +6 -2
  35. package/dist/core/define-web-ext-config.d.mts +13 -0
  36. package/dist/core/define-web-ext-config.mjs +16 -7
  37. package/dist/core/generate-wxt-dir.mjs +109 -148
  38. package/dist/core/index.d.mts +8 -0
  39. package/dist/core/index.mjs +10 -8
  40. package/dist/core/initialize.d.mts +8 -0
  41. package/dist/core/initialize.mjs +110 -124
  42. package/dist/core/keyboard-shortcuts.mjs +30 -28
  43. package/dist/core/package-managers/bun.mjs +18 -16
  44. package/dist/core/package-managers/deno.mjs +12 -8
  45. package/dist/core/package-managers/index.mjs +52 -60
  46. package/dist/core/package-managers/npm.mjs +51 -52
  47. package/dist/core/package-managers/pnpm.mjs +21 -18
  48. package/dist/core/package-managers/yarn.mjs +31 -28
  49. package/dist/core/prepare.d.mts +6 -0
  50. package/dist/core/prepare.mjs +12 -7
  51. package/dist/core/resolve-config.mjs +393 -462
  52. package/dist/core/runners/index.mjs +11 -6
  53. package/dist/core/runners/manual.mjs +16 -14
  54. package/dist/core/runners/safari.mjs +16 -14
  55. package/dist/core/runners/web-ext.mjs +62 -83
  56. package/dist/core/runners/wsl.mjs +16 -14
  57. package/dist/core/utils/arrays.mjs +23 -12
  58. package/dist/core/utils/building/build-entrypoints.mjs +44 -40
  59. package/dist/core/utils/building/detect-dev-changes.mjs +84 -105
  60. package/dist/core/utils/building/find-entrypoints.mjs +275 -359
  61. package/dist/core/utils/building/group-entrypoints.mjs +42 -35
  62. package/dist/core/utils/building/index.mjs +8 -6
  63. package/dist/core/utils/building/internal-build.mjs +87 -102
  64. package/dist/core/utils/building/rebuild.mjs +50 -30
  65. package/dist/core/utils/cache.mjs +29 -18
  66. package/dist/core/utils/constants.mjs +9 -1
  67. package/dist/core/utils/content-scripts.mjs +56 -54
  68. package/dist/core/utils/content-security-policy.mjs +36 -39
  69. package/dist/core/utils/entrypoints.mjs +51 -28
  70. package/dist/core/utils/env.mjs +22 -17
  71. package/dist/core/utils/environments/browser-environment.mjs +13 -12
  72. package/dist/core/utils/environments/environment.mjs +36 -33
  73. package/dist/core/utils/environments/extension-environment.mjs +15 -10
  74. package/dist/core/utils/environments/index.mjs +4 -2
  75. package/dist/core/utils/eslint.mjs +11 -10
  76. package/dist/core/utils/fs.mjs +23 -11
  77. package/dist/core/utils/globals.mjs +53 -51
  78. package/dist/core/utils/i18n.mjs +41 -32
  79. package/dist/core/utils/log/index.mjs +6 -4
  80. package/dist/core/utils/log/printBuildSummary.mjs +20 -25
  81. package/dist/core/utils/log/printFileList.mjs +30 -33
  82. package/dist/core/utils/log/printHeader.mjs +10 -5
  83. package/dist/core/utils/log/printTable.mjs +19 -21
  84. package/dist/core/utils/manifest.mjs +364 -479
  85. package/dist/core/utils/minimatch-multiple.mjs +26 -15
  86. package/dist/core/utils/network.mjs +30 -33
  87. package/dist/core/utils/number.mjs +7 -3
  88. package/dist/core/utils/package.mjs +20 -13
  89. package/dist/core/utils/paths.mjs +26 -7
  90. package/dist/core/utils/strings.mjs +19 -14
  91. package/dist/core/utils/syntax-errors.mjs +14 -16
  92. package/dist/core/utils/time.mjs +19 -15
  93. package/dist/core/utils/transform.mjs +129 -160
  94. package/dist/core/utils/types.d.mts +6 -0
  95. package/dist/core/utils/validation.mjs +43 -50
  96. package/dist/core/utils/virtual-modules.mjs +20 -12
  97. package/dist/core/utils/wsl.mjs +10 -3
  98. package/dist/core/wxt.mjs +66 -60
  99. package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
  100. package/dist/core/zip.mjs +116 -140
  101. package/dist/index.d.mts +12 -0
  102. package/dist/index.mjs +12 -3
  103. package/dist/{modules.d.ts → modules.d.mts} +14 -16
  104. package/dist/modules.mjs +181 -51
  105. package/dist/testing/fake-browser.d.mts +2 -0
  106. package/dist/testing/fake-browser.mjs +3 -1
  107. package/dist/testing/index.d.mts +3 -0
  108. package/dist/testing/index.mjs +4 -2
  109. package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
  110. package/dist/testing/wxt-vitest-plugin.mjs +38 -19
  111. package/dist/types.d.mts +1453 -0
  112. package/dist/utils/app-config.d.mts +6 -0
  113. package/dist/utils/app-config.mjs +8 -2
  114. package/dist/utils/content-script-context.d.mts +137 -0
  115. package/dist/utils/content-script-context.mjs +192 -175
  116. package/dist/utils/content-script-ui/iframe.d.mts +42 -0
  117. package/dist/utils/content-script-ui/iframe.mjs +42 -27
  118. package/dist/utils/content-script-ui/integrated.d.mts +37 -0
  119. package/dist/utils/content-script-ui/integrated.mjs +36 -29
  120. package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
  121. package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
  122. package/dist/utils/content-script-ui/shared.mjs +117 -150
  123. package/dist/utils/content-script-ui/types.d.mts +107 -0
  124. package/dist/utils/content-script-ui/types.mjs +1 -0
  125. package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
  126. package/dist/utils/define-app-config.mjs +22 -2
  127. package/dist/utils/define-background.d.mts +7 -0
  128. package/dist/utils/define-background.mjs +7 -3
  129. package/dist/utils/define-content-script.d.mts +6 -0
  130. package/dist/utils/define-content-script.mjs +6 -2
  131. package/dist/utils/define-unlisted-script.d.mts +7 -0
  132. package/dist/utils/define-unlisted-script.mjs +7 -3
  133. package/dist/utils/define-wxt-plugin.d.mts +6 -0
  134. package/dist/utils/define-wxt-plugin.mjs +6 -2
  135. package/dist/utils/inject-script.d.mts +41 -0
  136. package/dist/utils/inject-script.mjs +44 -34
  137. package/dist/utils/internal/custom-events.d.mts +9 -0
  138. package/dist/utils/internal/custom-events.mjs +18 -10
  139. package/dist/utils/internal/location-watcher.mjs +23 -20
  140. package/dist/utils/internal/logger.mjs +15 -12
  141. package/dist/utils/match-patterns.d.mts +1 -0
  142. package/dist/utils/match-patterns.mjs +3 -1
  143. package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
  144. package/dist/utils/split-shadow-root-css.mjs +16 -7
  145. package/dist/utils/storage.d.mts +1 -0
  146. package/dist/utils/storage.mjs +3 -1
  147. package/dist/version.d.mts +4 -0
  148. package/dist/version.mjs +5 -1
  149. package/dist/virtual/background-entrypoint.d.mts +4 -0
  150. package/dist/virtual/background-entrypoint.mjs +146 -161
  151. package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
  152. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
  153. package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
  154. package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
  155. package/dist/virtual/mock-browser.d.mts +6 -0
  156. package/dist/virtual/mock-browser.mjs +5 -3
  157. package/dist/virtual/reload-html.d.mts +1 -0
  158. package/dist/virtual/reload-html.mjs +60 -53
  159. package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
  160. package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
  161. package/package.json +47 -49
  162. package/dist/browser.d.ts +0 -30
  163. package/dist/builtin-modules/index.d.ts +0 -2
  164. package/dist/builtin-modules/unimport.d.ts +0 -5
  165. package/dist/cli/cli-utils.d.ts +0 -25
  166. package/dist/cli/commands.d.ts +0 -2
  167. package/dist/cli/index.d.ts +0 -1
  168. package/dist/core/builders/vite/index.d.ts +0 -7
  169. package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
  170. package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
  171. package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
  172. package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
  173. package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
  174. package/dist/core/builders/vite/plugins/download.d.ts +0 -10
  175. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
  176. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
  177. package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
  178. package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
  179. package/dist/core/builders/vite/plugins/index.d.ts +0 -16
  180. package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
  181. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
  182. package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
  183. package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
  184. package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
  185. package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
  186. package/dist/core/define-config.d.ts +0 -2
  187. package/dist/core/define-web-ext-config.d.ts +0 -9
  188. package/dist/core/generate-wxt-dir.d.ts +0 -5
  189. package/dist/core/index.d.ts +0 -8
  190. package/dist/core/initialize.d.ts +0 -5
  191. package/dist/core/keyboard-shortcuts.d.ts +0 -12
  192. package/dist/core/package-managers/bun.d.ts +0 -2
  193. package/dist/core/package-managers/deno.d.ts +0 -2
  194. package/dist/core/package-managers/index.d.ts +0 -2
  195. package/dist/core/package-managers/npm.d.ts +0 -17
  196. package/dist/core/package-managers/pnpm.d.ts +0 -2
  197. package/dist/core/package-managers/types.d.ts +0 -2
  198. package/dist/core/package-managers/types.mjs +0 -0
  199. package/dist/core/package-managers/yarn.d.ts +0 -2
  200. package/dist/core/prepare.d.ts +0 -2
  201. package/dist/core/resolve-config.d.ts +0 -11
  202. package/dist/core/runners/index.d.ts +0 -2
  203. package/dist/core/runners/manual.d.ts +0 -5
  204. package/dist/core/runners/safari.d.ts +0 -5
  205. package/dist/core/runners/web-ext.d.ts +0 -5
  206. package/dist/core/runners/wsl.d.ts +0 -5
  207. package/dist/core/utils/arrays.d.ts +0 -13
  208. package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
  209. package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
  210. package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
  211. package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
  212. package/dist/core/utils/building/index.d.ts +0 -6
  213. package/dist/core/utils/building/internal-build.d.ts +0 -12
  214. package/dist/core/utils/building/rebuild.d.ts +0 -23
  215. package/dist/core/utils/cache.d.ts +0 -8
  216. package/dist/core/utils/cli.d.ts +0 -3
  217. package/dist/core/utils/cli.mjs +0 -26
  218. package/dist/core/utils/constants.d.ts +0 -5
  219. package/dist/core/utils/content-scripts.d.ts +0 -12
  220. package/dist/core/utils/content-security-policy.d.ts +0 -14
  221. package/dist/core/utils/entrypoints.d.ts +0 -31
  222. package/dist/core/utils/env.d.ts +0 -5
  223. package/dist/core/utils/environments/browser-environment.d.ts +0 -3
  224. package/dist/core/utils/environments/environment.d.ts +0 -8
  225. package/dist/core/utils/environments/extension-environment.d.ts +0 -6
  226. package/dist/core/utils/environments/index.d.ts +0 -2
  227. package/dist/core/utils/eslint.d.ts +0 -1
  228. package/dist/core/utils/fs.d.ts +0 -13
  229. package/dist/core/utils/globals.d.ts +0 -11
  230. package/dist/core/utils/i18n.d.ts +0 -11
  231. package/dist/core/utils/log/index.d.ts +0 -4
  232. package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
  233. package/dist/core/utils/log/printFileList.d.ts +0 -1
  234. package/dist/core/utils/log/printHeader.d.ts +0 -1
  235. package/dist/core/utils/log/printTable.d.ts +0 -1
  236. package/dist/core/utils/manifest.d.ts +0 -40
  237. package/dist/core/utils/minimatch-multiple.d.ts +0 -15
  238. package/dist/core/utils/network.d.ts +0 -7
  239. package/dist/core/utils/number.d.ts +0 -1
  240. package/dist/core/utils/package.d.ts +0 -6
  241. package/dist/core/utils/paths.d.ts +0 -11
  242. package/dist/core/utils/strings.d.ts +0 -14
  243. package/dist/core/utils/syntax-errors.d.ts +0 -11
  244. package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
  245. package/dist/core/utils/testing/fake-objects.mjs +0 -326
  246. package/dist/core/utils/time.d.ts +0 -9
  247. package/dist/core/utils/transform.d.ts +0 -11
  248. package/dist/core/utils/types.d.ts +0 -13
  249. package/dist/core/utils/types.mjs +0 -0
  250. package/dist/core/utils/validation.d.ts +0 -15
  251. package/dist/core/utils/virtual-modules.d.ts +0 -22
  252. package/dist/core/utils/wsl.d.ts +0 -4
  253. package/dist/core/wxt.d.ts +0 -24
  254. package/dist/index.d.ts +0 -11
  255. package/dist/testing/fake-browser.d.ts +0 -10
  256. package/dist/testing/index.d.ts +0 -10
  257. package/dist/types.d.ts +0 -1459
  258. package/dist/types.mjs +0 -0
  259. package/dist/utils/app-config.d.ts +0 -2
  260. package/dist/utils/content-script-context.d.ts +0 -134
  261. package/dist/utils/content-script-ui/iframe.d.ts +0 -32
  262. package/dist/utils/content-script-ui/integrated.d.ts +0 -34
  263. package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
  264. package/dist/utils/content-script-ui/shared.d.ts +0 -5
  265. package/dist/utils/content-script-ui/types.d.ts +0 -104
  266. package/dist/utils/define-background.d.ts +0 -4
  267. package/dist/utils/define-content-script.d.ts +0 -3
  268. package/dist/utils/define-unlisted-script.d.ts +0 -4
  269. package/dist/utils/define-wxt-plugin.d.ts +0 -3
  270. package/dist/utils/inject-script.d.ts +0 -36
  271. package/dist/utils/internal/custom-events.d.ts +0 -10
  272. package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
  273. package/dist/utils/internal/dev-server-websocket.mjs +0 -37
  274. package/dist/utils/internal/location-watcher.d.ts +0 -12
  275. package/dist/utils/internal/logger.d.ts +0 -9
  276. package/dist/utils/match-patterns.d.ts +0 -5
  277. package/dist/utils/storage.d.ts +0 -5
  278. package/dist/version.d.ts +0 -1
@@ -1,17 +1,23 @@
1
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/utils/define-background';
13
- export default defineBackground(() => void 0)`;
14
- }
15
- }
16
- };
2
+
3
+ //#region src/core/builders/vite/plugins/noopBackground.ts
4
+ /**
5
+ * In dev mode, if there's not a background script listed, we need to add one so that the web socket
6
+ * connection is setup and the extension reloads HTML pages and content scripts correctly.
7
+ */
8
+ function noopBackground() {
9
+ const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
10
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
11
+ return {
12
+ name: "wxt:noop-background",
13
+ resolveId(id) {
14
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
15
+ },
16
+ load(id) {
17
+ if (id === resolvedVirtualModuleId) return `import { defineBackground } from 'wxt/utils/define-background';\nexport default defineBackground(() => void 0)`;
18
+ }
19
+ };
17
20
  }
21
+
22
+ //#endregion
23
+ export { noopBackground };
@@ -1,27 +1,29 @@
1
1
  import { normalizePath } from "../../../utils/paths.mjs";
2
2
  import { removeMainFunctionCode } from "../../../utils/transform.mjs";
3
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: {
9
- order: "pre",
10
- handler(code, id) {
11
- if (id === absPath) {
12
- const newCode = removeMainFunctionCode(code);
13
- config.logger.debug("vite-node transformed entrypoint", path);
14
- config.logger.debug(`Original:
15
- ---
16
- ${code}
17
- ---`);
18
- config.logger.debug(`Transformed:
19
- ---
20
- ${newCode.code}
21
- ---`);
22
- return newCode;
23
- }
24
- }
25
- }
26
- };
4
+
5
+ //#region src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
6
+ /**
7
+ * Transforms entrypoints, removing the main function from the entrypoint if it exists.
8
+ */
9
+ function removeEntrypointMainFunction(config, path) {
10
+ const absPath = normalizePath(resolve(config.root, path));
11
+ return {
12
+ name: "wxt:remove-entrypoint-main-function",
13
+ transform: {
14
+ order: "pre",
15
+ handler(code, id) {
16
+ if (id === absPath) {
17
+ const newCode = removeMainFunctionCode(code);
18
+ config.logger.debug("vite-node transformed entrypoint", path);
19
+ config.logger.debug(`Original:\n---\n${code}\n---`);
20
+ config.logger.debug(`Transformed:\n---\n${newCode.code}\n---`);
21
+ return newCode;
22
+ }
23
+ }
24
+ }
25
+ };
27
26
  }
27
+
28
+ //#endregion
29
+ export { removeEntrypointMainFunction };
@@ -1,26 +1,28 @@
1
1
  import { exists } from "fs-extra";
2
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
- };
3
+
4
+ //#region src/core/builders/vite/plugins/resolveAppConfig.ts
5
+ /**
6
+ * When importing `virtual:app-config`, resolve it to the `app.config.ts` file in the project.
7
+ */
8
+ function resolveAppConfig(config) {
9
+ const virtualModuleId = "virtual:app-config";
10
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
11
+ const appConfigFile = resolve(config.srcDir, "app.config.ts");
12
+ return {
13
+ name: "wxt:resolve-app-config",
14
+ config() {
15
+ return { optimizeDeps: { exclude: [virtualModuleId] } };
16
+ },
17
+ async resolveId(id) {
18
+ if (id !== virtualModuleId) return;
19
+ return await exists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
20
+ },
21
+ load(id) {
22
+ if (id === resolvedVirtualModuleId) return `export default {}`;
23
+ }
24
+ };
26
25
  }
26
+
27
+ //#endregion
28
+ export { resolveAppConfig };
@@ -1,30 +1,31 @@
1
1
  import { normalizePath } from "../../../utils/paths.mjs";
2
- import {
3
- virtualModuleNames
4
- } from "../../../utils/virtual-modules.mjs";
2
+ import { virtualModuleNames } from "../../../utils/virtual-modules.mjs";
5
3
  import fs from "fs-extra";
6
4
  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
- });
5
+
6
+ //#region src/core/builders/vite/plugins/resolveVirtualModules.ts
7
+ /**
8
+ * Resolve all the virtual modules to the `node_modules/wxt/dist/virtual` directory.
9
+ */
10
+ function resolveVirtualModules(config) {
11
+ return virtualModuleNames.map((name) => {
12
+ const virtualId = `virtual:wxt-${name}?`;
13
+ const resolvedVirtualId = "\0" + virtualId;
14
+ return {
15
+ name: `wxt:resolve-virtual-${name}`,
16
+ resolveId(id) {
17
+ const index = id.indexOf(virtualId);
18
+ if (index === -1) return;
19
+ return resolvedVirtualId + normalizePath(id.substring(index + virtualId.length));
20
+ },
21
+ async load(id) {
22
+ if (!id.startsWith(resolvedVirtualId)) return;
23
+ const inputPath = id.replace(resolvedVirtualId, "");
24
+ return (await fs.readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8")).replace(`virtual:user-${name}`, inputPath);
25
+ }
26
+ };
27
+ });
30
28
  }
29
+
30
+ //#endregion
31
+ export { resolveVirtualModules };
@@ -1,12 +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
- };
1
+ //#region src/core/builders/vite/plugins/tsconfigPaths.ts
2
+ function tsconfigPaths(config) {
3
+ return {
4
+ name: "wxt:aliases",
5
+ async config() {
6
+ return { resolve: { alias: config.alias } };
7
+ }
8
+ };
12
9
  }
10
+
11
+ //#endregion
12
+ export { tsconfigPaths };
@@ -1,56 +1,50 @@
1
- import { parseHTML } from "linkedom";
2
1
  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}
2
+ import { parseHTML } from "linkedom";
21
3
 
22
- export function initPlugins() {
23
- ${initCalls}
24
- }`;
25
- }
26
- if (id === resolvedVirtualHtmlModuleId) {
27
- return `import { initPlugins } from '${virtualModuleId}';
4
+ //#region src/core/builders/vite/plugins/wxtPluginLoader.ts
5
+ /**
6
+ * 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>`
7
+ */
8
+ function wxtPluginLoader(config) {
9
+ const virtualModuleId = "virtual:wxt-plugins";
10
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
11
+ const virtualHtmlModuleId = "virtual:wxt-html-plugins";
12
+ const resolvedVirtualHtmlModuleId = "\0" + virtualHtmlModuleId;
13
+ return {
14
+ name: "wxt:plugin-loader",
15
+ resolveId(id) {
16
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
17
+ if (id === virtualHtmlModuleId) return resolvedVirtualHtmlModuleId;
18
+ },
19
+ load(id) {
20
+ if (id === resolvedVirtualModuleId) return `${config.plugins.map((plugin, i) => `import initPlugin${i} from '${normalizePath(plugin)}';`).join("\n")}\n\nexport function initPlugins() {\n${config.plugins.map((_, i) => ` initPlugin${i}();`).join("\n")}\n}`;
21
+ if (id === resolvedVirtualHtmlModuleId) return `import { initPlugins } from '${virtualModuleId}';
28
22
 
29
23
  try {
30
24
  initPlugins();
31
25
  } catch (err) {
32
26
  console.error("[wxt] Failed to initialize plugins", err);
33
27
  }`;
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" ? `${config.dev.server?.origin}/@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
- };
28
+ },
29
+ transformIndexHtml: {
30
+ order: "pre",
31
+ handler(html, _ctx) {
32
+ const src = config.command === "serve" ? `${config.dev.server?.origin}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
33
+ const { document } = parseHTML(html);
34
+ if (document.querySelector(`script[src='${src}']`)) return;
35
+ const script = document.createElement("script");
36
+ script.type = "module";
37
+ script.src = src;
38
+ if (document.head == null) {
39
+ const newHead = document.createElement("head");
40
+ document.documentElement.prepend(newHead);
41
+ }
42
+ document.head.prepend(script);
43
+ return document.toString();
44
+ }
45
+ }
46
+ };
56
47
  }
48
+
49
+ //#endregion
50
+ export { wxtPluginLoader };
@@ -1,4 +1,6 @@
1
- import { InlineConfig } from '../types';
1
+ import { InlineConfig } from "../types.mjs";
2
+
3
+ //#region src/core/clean.d.ts
2
4
  /**
3
5
  * Remove generated/temp files from the directory.
4
6
  *
@@ -7,7 +9,7 @@ import { InlineConfig } from '../types';
7
9
  * @example
8
10
  * await clean();
9
11
  */
10
- export declare function clean(config?: InlineConfig): Promise<void>;
12
+ declare function clean(config?: InlineConfig): Promise<void>;
11
13
  /**
12
14
  * Remove generated/temp files from the directory.
13
15
  *
@@ -18,4 +20,6 @@ export declare function clean(config?: InlineConfig): Promise<void>;
18
20
  * @example
19
21
  * await clean();
20
22
  */
21
- export declare function clean(root?: string): Promise<void>;
23
+ declare function clean(root?: string): Promise<void>;
24
+ //#endregion
25
+ export { clean };
@@ -1,38 +1,41 @@
1
- import path from "node:path";
2
- import glob from "fast-glob";
1
+ import { registerWxt, wxt } from "./wxt.mjs";
3
2
  import fs from "fs-extra";
3
+ import glob from "fast-glob";
4
+ import path from "node:path";
4
5
  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
- }
6
+
7
+ //#region src/core/clean.ts
8
+ async function clean(config) {
9
+ if (typeof config === "string") config = { root: config };
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("Found:", directories.map((dir) => pc.cyan(path.relative(root, dir))).join(", "));
31
+ for (const directory of directories) {
32
+ await fs.rm(directory, {
33
+ force: true,
34
+ recursive: true
35
+ });
36
+ wxt.logger.debug("Deleted " + pc.cyan(path.relative(root, directory)));
37
+ }
38
38
  }
39
+
40
+ //#endregion
41
+ export { clean };
@@ -1,4 +1,6 @@
1
- import { InlineConfig, WxtDevServer } from '../types';
1
+ import { InlineConfig, WxtDevServer } from "../types.mjs";
2
+
3
+ //#region src/core/create-server.d.ts
2
4
  /**
3
5
  * Creates a dev server and pre-builds all the files that need to exist before loading the extension.
4
6
  *
@@ -8,4 +10,6 @@ import { InlineConfig, WxtDevServer } from '../types';
8
10
  * });
9
11
  * await server.start();
10
12
  */
11
- export declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
13
+ declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
14
+ //#endregion
15
+ export { createServer };