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
package/dist/index.js DELETED
@@ -1,696 +0,0 @@
1
- import {
2
- detectDevChanges,
3
- findEntrypoints,
4
- formatDuration,
5
- generateTypesDir,
6
- getContentScriptCssFiles,
7
- getContentScriptJs,
8
- getContentScriptsCssMap,
9
- getEntrypointBundlePath,
10
- getPackageJson,
11
- internalBuild,
12
- isHtmlEntrypoint,
13
- kebabCaseAlphanumeric,
14
- mapWxtOptionsToRegisteredContentScript,
15
- normalizePath,
16
- printFileList,
17
- rebuild,
18
- registerWxt,
19
- unnormalizePath,
20
- version,
21
- wxt
22
- } from "./chunk-FP7RYLVL.js";
23
- import "./chunk-BERPNPEZ.js";
24
- import "./chunk-6XSIWUWF.js";
25
- import {
26
- consola
27
- } from "./chunk-BM6QYGAW.js";
28
- import "./chunk-QGM4M3NI.js";
29
-
30
- // src/core/build.ts
31
- async function build(config) {
32
- await registerWxt("build", config);
33
- return await internalBuild();
34
- }
35
-
36
- // src/core/clean.ts
37
- import path from "node:path";
38
- import glob from "fast-glob";
39
- import fs from "fs-extra";
40
- import pc from "picocolors";
41
- async function clean(config) {
42
- if (typeof config === "string") {
43
- config = { root: config };
44
- }
45
- await registerWxt("build", config);
46
- wxt.logger.info("Cleaning Project");
47
- const root = wxt.config.root;
48
- const tempDirs = [
49
- "node_modules/.vite",
50
- "node_modules/.cache",
51
- "**/.wxt",
52
- `${path.relative(root, wxt.config.outBaseDir)}/*`
53
- ];
54
- wxt.logger.debug("Looking for:", tempDirs.map(pc.cyan).join(", "));
55
- const directories = await glob(tempDirs, {
56
- cwd: root,
57
- absolute: true,
58
- onlyDirectories: true,
59
- deep: 2
60
- });
61
- if (directories.length === 0) {
62
- wxt.logger.debug("No generated files found.");
63
- return;
64
- }
65
- wxt.logger.debug(
66
- "Found:",
67
- directories.map((dir) => pc.cyan(path.relative(root, dir))).join(", ")
68
- );
69
- for (const directory of directories) {
70
- await fs.rm(directory, { force: true, recursive: true });
71
- wxt.logger.debug("Deleted " + pc.cyan(path.relative(root, directory)));
72
- }
73
- }
74
-
75
- // src/core/define-config.ts
76
- function defineConfig(config) {
77
- return config;
78
- }
79
-
80
- // src/core/define-runner-config.ts
81
- function defineRunnerConfig(config) {
82
- return config;
83
- }
84
-
85
- // src/core/runners/wsl.ts
86
- import { relative } from "node:path";
87
- function createWslRunner() {
88
- return {
89
- async openBrowser() {
90
- wxt.logger.warn(
91
- `Cannot open browser when using WSL. Load "${relative(
92
- process.cwd(),
93
- wxt.config.outDir
94
- )}" as an unpacked extension manually`
95
- );
96
- },
97
- async closeBrowser() {
98
- }
99
- };
100
- }
101
-
102
- // src/core/runners/web-ext.ts
103
- import defu from "defu";
104
- function createWebExtRunner() {
105
- let runner;
106
- return {
107
- async openBrowser() {
108
- const startTime = Date.now();
109
- if (wxt.config.browser === "firefox" && wxt.config.manifestVersion === 3) {
110
- throw Error(
111
- "Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653"
112
- );
113
- }
114
- const webExtLogger = await import("web-ext-run/util/logger");
115
- webExtLogger.consoleStream.write = ({ level, msg, name }) => {
116
- if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
117
- if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
118
- };
119
- const wxtUserConfig = wxt.config.runnerConfig.config;
120
- const userConfig = {
121
- console: wxtUserConfig?.openConsole,
122
- devtools: wxtUserConfig?.openDevtools,
123
- startUrl: wxtUserConfig?.startUrls,
124
- keepProfileChanges: wxtUserConfig?.keepProfileChanges,
125
- ...wxt.config.browser === "firefox" ? {
126
- firefox: wxtUserConfig?.binaries?.firefox,
127
- firefoxProfile: wxtUserConfig?.firefoxProfile,
128
- prefs: wxtUserConfig?.firefoxPrefs,
129
- args: wxtUserConfig?.firefoxArgs
130
- } : {
131
- chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
132
- chromiumProfile: wxtUserConfig?.chromiumProfile,
133
- chromiumPref: defu(
134
- wxtUserConfig?.chromiumPref,
135
- DEFAULT_CHROMIUM_PREFS
136
- ),
137
- args: wxtUserConfig?.chromiumArgs
138
- }
139
- };
140
- const finalConfig = {
141
- ...userConfig,
142
- target: wxt.config.browser === "firefox" ? "firefox-desktop" : "chromium",
143
- sourceDir: wxt.config.outDir,
144
- // Don't add a "Reload Manager" extension alongside dev extension, WXT
145
- // already handles reloads intenrally.
146
- noReloadManagerExtension: true,
147
- // WXT handles reloads, so disable auto-reload behaviors in web-ext
148
- noReload: true,
149
- noInput: true
150
- };
151
- const options = {
152
- // Don't call `process.exit(0)` after starting web-ext
153
- shouldExitProgram: false
154
- };
155
- wxt.logger.debug("web-ext config:", finalConfig);
156
- wxt.logger.debug("web-ext options:", options);
157
- const webExt = await import("web-ext-run");
158
- runner = await webExt.default.cmd.run(finalConfig, options);
159
- const duration = Date.now() - startTime;
160
- wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
161
- },
162
- async closeBrowser() {
163
- return await runner?.exit();
164
- }
165
- };
166
- }
167
- var WARN_LOG_LEVEL = 40;
168
- var ERROR_LOG_LEVEL = 50;
169
- var DEFAULT_CHROMIUM_PREFS = {
170
- devtools: {
171
- synced_preferences_sync_disabled: {
172
- // Remove content scripts from sourcemap debugger ignore list so stack traces
173
- // and log locations show up properly, see:
174
- // https://github.com/wxt-dev/wxt/issues/236#issuecomment-1915364520
175
- skipContentScripts: false
176
- }
177
- }
178
- };
179
-
180
- // src/core/runners/safari.ts
181
- import { relative as relative2 } from "node:path";
182
- function createSafariRunner() {
183
- return {
184
- async openBrowser() {
185
- wxt.logger.warn(
186
- `Cannot Safari using web-ext. Load "${relative2(
187
- process.cwd(),
188
- wxt.config.outDir
189
- )}" as an unpacked extension manually`
190
- );
191
- },
192
- async closeBrowser() {
193
- }
194
- };
195
- }
196
-
197
- // src/core/runners/manual.ts
198
- import { relative as relative3 } from "node:path";
199
- function createManualRunner() {
200
- return {
201
- async openBrowser() {
202
- wxt.logger.info(
203
- `Load "${relative3(
204
- process.cwd(),
205
- wxt.config.outDir
206
- )}" as an unpacked extension manually`
207
- );
208
- },
209
- async closeBrowser() {
210
- }
211
- };
212
- }
213
-
214
- // src/core/utils/wsl.ts
215
- async function isWsl() {
216
- const { default: isWsl2 } = await import("is-wsl");
217
- return isWsl2;
218
- }
219
-
220
- // src/core/runners/index.ts
221
- async function createExtensionRunner() {
222
- if (wxt.config.browser === "safari") return createSafariRunner();
223
- if (await isWsl()) return createWslRunner();
224
- if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
225
- return createWebExtRunner();
226
- }
227
-
228
- // src/core/create-server.ts
229
- import { Mutex } from "async-mutex";
230
- import pc2 from "picocolors";
231
- import { relative as relative4 } from "node:path";
232
- async function createServer(inlineConfig) {
233
- await registerWxt("serve", inlineConfig, async (config) => {
234
- const { port, hostname } = config.dev.server;
235
- const serverInfo = {
236
- port,
237
- hostname,
238
- origin: `http://${hostname}:${port}`
239
- };
240
- const server2 = {
241
- ...serverInfo,
242
- get watcher() {
243
- return builderServer.watcher;
244
- },
245
- get ws() {
246
- return builderServer.ws;
247
- },
248
- currentOutput: void 0,
249
- async start() {
250
- await builderServer.listen();
251
- wxt.logger.success(`Started dev server @ ${serverInfo.origin}`);
252
- await buildAndOpenBrowser();
253
- },
254
- async stop() {
255
- await runner.closeBrowser();
256
- await builderServer.close();
257
- },
258
- async restart() {
259
- await closeAndRecreateRunner();
260
- await buildAndOpenBrowser();
261
- },
262
- transformHtml(url, html, originalUrl) {
263
- return builderServer.transformHtml(url, html, originalUrl);
264
- },
265
- reloadContentScript(payload) {
266
- server2.ws.send("wxt:reload-content-script", payload);
267
- },
268
- reloadPage(path4) {
269
- server2.ws.send("wxt:reload-page", path4);
270
- },
271
- reloadExtension() {
272
- server2.ws.send("wxt:reload-extension");
273
- },
274
- async restartBrowser() {
275
- await closeAndRecreateRunner();
276
- await runner.openBrowser();
277
- }
278
- };
279
- return server2;
280
- });
281
- const server = wxt.server;
282
- let [runner, builderServer] = await Promise.all([
283
- createExtensionRunner(),
284
- wxt.builder.createServer(server)
285
- ]);
286
- const buildAndOpenBrowser = async () => {
287
- server.currentOutput = await internalBuild();
288
- try {
289
- server.watcher.add(getExternalOutputDependencies(server));
290
- } catch (err) {
291
- wxt.config.logger.warn("Failed to register additional file paths:", err);
292
- }
293
- await runner.openBrowser();
294
- };
295
- const closeAndRecreateRunner = async () => {
296
- await runner.closeBrowser();
297
- await wxt.reloadConfig();
298
- runner = await createExtensionRunner();
299
- };
300
- server.ws.on("wxt:background-initialized", () => {
301
- if (server.currentOutput == null) return;
302
- reloadContentScripts(server.currentOutput.steps, server);
303
- });
304
- const reloadOnChange = createFileReloader(server);
305
- server.watcher.on("all", reloadOnChange);
306
- return server;
307
- }
308
- function createFileReloader(server) {
309
- const fileChangedMutex = new Mutex();
310
- const changeQueue = [];
311
- return async (event, path4) => {
312
- await wxt.reloadConfig();
313
- if (path4.startsWith(wxt.config.outBaseDir)) return;
314
- if (path4.startsWith(wxt.config.wxtDir)) return;
315
- changeQueue.push([event, path4]);
316
- await fileChangedMutex.runExclusive(async () => {
317
- if (server.currentOutput == null) return;
318
- const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
319
- if (fileChanges.length === 0) return;
320
- const changes = detectDevChanges(fileChanges, server.currentOutput);
321
- if (changes.type === "no-change") return;
322
- if (changes.type === "full-restart") {
323
- wxt.logger.info("Config changed, restarting server...");
324
- server.restart();
325
- return;
326
- }
327
- if (changes.type === "browser-restart") {
328
- wxt.logger.info("Runner config changed, restarting browser...");
329
- server.restartBrowser();
330
- return;
331
- }
332
- wxt.logger.info(
333
- `Changed: ${Array.from(new Set(fileChanges)).map((file) => pc2.dim(relative4(wxt.config.root, file))).join(", ")}`
334
- );
335
- const allEntrypoints = await findEntrypoints();
336
- try {
337
- const { output: newOutput } = await rebuild(
338
- allEntrypoints,
339
- // TODO: this excludes new entrypoints, so they're not built until the dev command is restarted
340
- changes.rebuildGroups,
341
- changes.cachedOutput
342
- );
343
- server.currentOutput = newOutput;
344
- switch (changes.type) {
345
- case "extension-reload":
346
- server.reloadExtension();
347
- wxt.logger.success(`Reloaded extension`);
348
- break;
349
- case "html-reload":
350
- const { reloadedNames } = reloadHtmlPages(
351
- changes.rebuildGroups,
352
- server
353
- );
354
- wxt.logger.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
355
- break;
356
- case "content-script-reload":
357
- reloadContentScripts(changes.changedSteps, server);
358
- const rebuiltNames = changes.rebuildGroups.flat().map((entry) => entry.name);
359
- wxt.logger.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
360
- break;
361
- }
362
- } catch (err) {
363
- }
364
- });
365
- };
366
- }
367
- function reloadContentScripts(steps, server) {
368
- if (wxt.config.manifestVersion === 3) {
369
- steps.forEach((step) => {
370
- if (server.currentOutput == null) return;
371
- const entry = step.entrypoints;
372
- if (Array.isArray(entry) || entry.type !== "content-script") return;
373
- const js = getContentScriptJs(wxt.config, entry);
374
- const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
375
- const css = getContentScriptCssFiles([entry], cssMap);
376
- server.reloadContentScript({
377
- registration: entry.options.registration,
378
- contentScript: mapWxtOptionsToRegisteredContentScript(
379
- entry.options,
380
- js,
381
- css
382
- )
383
- });
384
- });
385
- } else {
386
- server.reloadExtension();
387
- }
388
- }
389
- function reloadHtmlPages(groups, server) {
390
- const htmlEntries = groups.flat().filter(isHtmlEntrypoint);
391
- htmlEntries.forEach((entry) => {
392
- const path4 = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
393
- server.reloadPage(path4);
394
- });
395
- return {
396
- reloadedNames: htmlEntries.map((entry) => entry.name)
397
- };
398
- }
399
- function getFilenameList(names) {
400
- return names.map((name) => {
401
- return pc2.cyan(name);
402
- }).join(pc2.dim(", "));
403
- }
404
- function getExternalOutputDependencies(server) {
405
- return server.currentOutput?.steps.flatMap((step, i) => {
406
- if (Array.isArray(step.entrypoints) && i === 0) {
407
- return [];
408
- }
409
- return step.chunks.flatMap((chunk) => {
410
- if (chunk.type === "asset") return [];
411
- return chunk.moduleIds;
412
- });
413
- }).filter(
414
- (file) => !file.includes("node_modules") && !file.startsWith("\0")
415
- ).map(unnormalizePath).filter((file) => !file.startsWith(wxt.config.root)) ?? [];
416
- }
417
-
418
- // src/core/initialize.ts
419
- import prompts from "prompts";
420
- import { downloadTemplate } from "giget";
421
- import fs2 from "fs-extra";
422
- import path2 from "node:path";
423
- import pc3 from "picocolors";
424
- async function initialize(options) {
425
- consola.info("Initalizing new project");
426
- const templates = await listTemplates();
427
- const defaultTemplate = templates.find(
428
- (template) => template.name === options.template?.toLowerCase().trim()
429
- );
430
- const input = await prompts(
431
- [
432
- {
433
- name: "directory",
434
- type: () => options.directory == null ? "text" : void 0,
435
- message: "Project Directory",
436
- initial: options.directory
437
- },
438
- {
439
- name: "template",
440
- type: () => defaultTemplate == null ? "select" : void 0,
441
- message: "Choose a template",
442
- choices: templates.map((template) => ({
443
- title: TEMPLATE_COLORS[template.name]?.(template.name) ?? template.name,
444
- value: template
445
- }))
446
- },
447
- {
448
- name: "packageManager",
449
- type: () => options.packageManager == null ? "select" : void 0,
450
- message: "Package Manager",
451
- choices: [
452
- { title: pc3.red("npm"), value: "npm" },
453
- { title: pc3.yellow("pnpm"), value: "pnpm" },
454
- { title: pc3.cyan("yarn"), value: "yarn" },
455
- {
456
- title: `${pc3.magenta("bun")}${pc3.gray(" (experimental)")}`,
457
- value: "bun"
458
- }
459
- ]
460
- }
461
- ],
462
- {
463
- onCancel: () => process.exit(1)
464
- }
465
- );
466
- input.directory ??= options.directory;
467
- input.template ??= defaultTemplate;
468
- input.packageManager ??= options.packageManager;
469
- const isExists = await fs2.pathExists(input.directory);
470
- if (isExists) {
471
- const isEmpty = (await fs2.readdir(input.directory)).length === 0;
472
- if (!isEmpty) {
473
- consola.error(
474
- `The directory ${path2.resolve(input.directory)} is not empty. Aborted.`
475
- );
476
- process.exit(1);
477
- }
478
- }
479
- await cloneProject(input);
480
- const cdPath = path2.relative(process.cwd(), path2.resolve(input.directory));
481
- console.log();
482
- consola.log(
483
- `\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
484
- );
485
- console.log();
486
- consola.log("Next steps:");
487
- let step = 0;
488
- if (cdPath !== "") consola.log(` ${++step}.`, pc3.cyan(`cd ${cdPath}`));
489
- consola.log(` ${++step}.`, pc3.cyan(`${input.packageManager} install`));
490
- console.log();
491
- }
492
- async function listTemplates() {
493
- try {
494
- const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
495
- if (res.status >= 300)
496
- throw Error(`Request failed with status ${res.status} ${res.statusText}`);
497
- const data = await res.json();
498
- return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` })).sort((l, r) => {
499
- const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
500
- const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
501
- const diff = lWeight - rWeight;
502
- if (diff !== 0) return diff;
503
- return l.name.localeCompare(r.name);
504
- });
505
- } catch (err) {
506
- consola.error(err);
507
- throw Error(`Failed to load templates`);
508
- }
509
- }
510
- async function cloneProject({
511
- directory,
512
- template,
513
- packageManager
514
- }) {
515
- const { default: ora } = await import("ora");
516
- const spinner = ora("Downloading template").start();
517
- try {
518
- await downloadTemplate(`gh:wxt-dev/wxt/${template.path}`, {
519
- dir: directory,
520
- force: true
521
- });
522
- await fs2.move(
523
- path2.join(directory, "_gitignore"),
524
- path2.join(directory, ".gitignore")
525
- ).catch(
526
- (err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
527
- );
528
- spinner.succeed();
529
- } catch (err) {
530
- spinner.fail();
531
- throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
532
- }
533
- }
534
- var TEMPLATE_COLORS = {
535
- vanilla: pc3.blue,
536
- vue: pc3.green,
537
- react: pc3.cyan,
538
- svelte: pc3.red,
539
- solid: pc3.blue
540
- };
541
- var TEMPLATE_SORT_WEIGHT = {
542
- vanilla: 0,
543
- vue: 1,
544
- react: 2
545
- };
546
-
547
- // src/core/prepare.ts
548
- async function prepare(config) {
549
- await registerWxt("build", config);
550
- wxt.logger.info("Generating types...");
551
- const entrypoints = await findEntrypoints();
552
- await generateTypesDir(entrypoints);
553
- }
554
-
555
- // src/core/zip.ts
556
- import path3 from "node:path";
557
- import fs3 from "fs-extra";
558
- import { minimatch } from "minimatch";
559
- import JSZip from "jszip";
560
- import glob2 from "fast-glob";
561
- async function zip(config) {
562
- await registerWxt("build", config);
563
- const output = await internalBuild();
564
- const start = Date.now();
565
- wxt.logger.info("Zipping extension...");
566
- const zipFiles = [];
567
- const projectName = wxt.config.zip.name ?? kebabCaseAlphanumeric(
568
- (await getPackageJson())?.name || path3.dirname(process.cwd())
569
- );
570
- const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll(
571
- "{{version}}",
572
- output.manifest.version_name ?? output.manifest.version
573
- ).replaceAll("{{mode}}", wxt.config.mode).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
574
- await fs3.ensureDir(wxt.config.outBaseDir);
575
- const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
576
- const outZipPath = path3.resolve(wxt.config.outBaseDir, outZipFilename);
577
- await zipDir(wxt.config.outDir, outZipPath);
578
- zipFiles.push(outZipPath);
579
- if (wxt.config.browser === "firefox") {
580
- const { overrides, files: downloadedPackages } = await downloadPrivatePackages();
581
- const sourcesZipFilename = applyTemplate(wxt.config.zip.sourcesTemplate);
582
- const sourcesZipPath = path3.resolve(
583
- wxt.config.outBaseDir,
584
- sourcesZipFilename
585
- );
586
- await zipDir(wxt.config.zip.sourcesRoot, sourcesZipPath, {
587
- include: wxt.config.zip.includeSources,
588
- exclude: wxt.config.zip.excludeSources,
589
- transform(absolutePath, zipPath, content) {
590
- if (zipPath.endsWith("package.json")) {
591
- return addOverridesToPackageJson(absolutePath, content, overrides);
592
- }
593
- },
594
- additionalFiles: downloadedPackages
595
- });
596
- zipFiles.push(sourcesZipPath);
597
- }
598
- await printFileList(
599
- wxt.logger.success,
600
- `Zipped extension in ${formatDuration(Date.now() - start)}`,
601
- wxt.config.outBaseDir,
602
- zipFiles
603
- );
604
- return zipFiles;
605
- }
606
- async function zipDir(directory, outputPath, options) {
607
- const archive = new JSZip();
608
- const files = (await glob2("**/*", {
609
- cwd: directory,
610
- // Ignore node_modules, otherwise this glob step takes forever
611
- ignore: ["**/node_modules"],
612
- onlyFiles: true
613
- // TODO: Fix #738
614
- // dot: true,
615
- })).filter((relativePath) => {
616
- return options?.include?.some((pattern) => minimatch(relativePath, pattern)) || !options?.exclude?.some((pattern) => minimatch(relativePath, pattern));
617
- });
618
- const filesToZip = [
619
- ...files,
620
- ...(options?.additionalFiles ?? []).map(
621
- (file) => path3.relative(directory, file)
622
- )
623
- ];
624
- for (const file of filesToZip) {
625
- const absolutePath = path3.resolve(directory, file);
626
- if (file.endsWith(".json")) {
627
- const content = await fs3.readFile(absolutePath, "utf-8");
628
- archive.file(
629
- file,
630
- await options?.transform?.(absolutePath, file, content) || content
631
- );
632
- } else {
633
- const content = await fs3.readFile(absolutePath);
634
- archive.file(file, content);
635
- }
636
- }
637
- await options?.additionalWork?.(archive);
638
- await new Promise(
639
- (resolve, reject) => archive.generateNodeStream({
640
- type: "nodebuffer",
641
- ...wxt.config.zip.compressionLevel === 0 ? { compression: "STORE" } : {
642
- compression: "DEFLATE",
643
- compressionOptions: { level: wxt.config.zip.compressionLevel }
644
- }
645
- }).pipe(fs3.createWriteStream(outputPath)).on("error", reject).on("close", resolve)
646
- );
647
- }
648
- async function downloadPrivatePackages() {
649
- const overrides = {};
650
- const files = [];
651
- if (wxt.config.zip.downloadPackages.length > 0) {
652
- const _downloadPackages = new Set(wxt.config.zip.downloadPackages);
653
- const allPackages = await wxt.pm.listDependencies({
654
- all: true,
655
- cwd: wxt.config.root
656
- });
657
- const downloadPackages = allPackages.filter(
658
- (pkg) => _downloadPackages.has(pkg.name)
659
- );
660
- for (const pkg of downloadPackages) {
661
- wxt.logger.info(`Downloading package: ${pkg.name}@${pkg.version}`);
662
- const id = `${pkg.name}@${pkg.version}`;
663
- const tgzPath = await wxt.pm.downloadDependency(
664
- id,
665
- wxt.config.zip.downloadedPackagesDir
666
- );
667
- files.push(tgzPath);
668
- overrides[id] = tgzPath;
669
- }
670
- }
671
- return { overrides, files };
672
- }
673
- function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
674
- if (Object.keys(overrides).length === 0) return content;
675
- const packageJsonDir = path3.dirname(absolutePackageJsonPath);
676
- const oldPackage = JSON.parse(content);
677
- const newPackage = {
678
- ...oldPackage,
679
- [wxt.pm.overridesKey]: { ...oldPackage[wxt.pm.overridesKey] }
680
- };
681
- Object.entries(overrides).forEach(([key, absolutePath]) => {
682
- newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(path3.relative(packageJsonDir, absolutePath));
683
- });
684
- return JSON.stringify(newPackage, null, 2);
685
- }
686
- export {
687
- build,
688
- clean,
689
- createServer,
690
- defineConfig,
691
- defineRunnerConfig,
692
- initialize,
693
- prepare,
694
- version,
695
- zip
696
- };