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,364 @@
1
+ import { loadConfig } from "c12";
2
+ import path from "node:path";
3
+ import { createFsCache } from "../../utils/cache.mjs";
4
+ import consola, { LogLevels } from "consola";
5
+ import defu from "defu";
6
+ import fs from "fs-extra";
7
+ import { normalizePath } from "../paths.mjs";
8
+ import glob from "fast-glob";
9
+ import { builtinModules } from "../../../builtin-modules/index.mjs";
10
+ import { getEslintVersion } from "../eslint.mjs";
11
+ export async function resolveConfig(inlineConfig, command) {
12
+ let userConfig = {};
13
+ let userConfigMetadata;
14
+ if (inlineConfig.configFile !== false) {
15
+ const { config: loadedConfig, ...metadata } = await loadConfig({
16
+ configFile: inlineConfig.configFile,
17
+ name: "wxt",
18
+ cwd: inlineConfig.root ?? process.cwd(),
19
+ rcFile: false,
20
+ jitiOptions: {
21
+ esmResolve: true
22
+ }
23
+ });
24
+ userConfig = loadedConfig ?? {};
25
+ userConfigMetadata = metadata;
26
+ }
27
+ const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
28
+ const debug = mergedConfig.debug ?? false;
29
+ const logger = mergedConfig.logger ?? consola;
30
+ if (debug) logger.level = LogLevels.debug;
31
+ const browser = mergedConfig.browser ?? "chrome";
32
+ const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
33
+ const mode = mergedConfig.mode ?? COMMAND_MODES[command];
34
+ const env = { browser, command, manifestVersion, mode };
35
+ const root = path.resolve(
36
+ inlineConfig.root ?? userConfig.root ?? process.cwd()
37
+ );
38
+ const wxtDir = path.resolve(root, ".wxt");
39
+ const wxtModuleDir = await resolveWxtModuleDir();
40
+ const srcDir = path.resolve(root, mergedConfig.srcDir ?? root);
41
+ const entrypointsDir = path.resolve(
42
+ srcDir,
43
+ mergedConfig.entrypointsDir ?? "entrypoints"
44
+ );
45
+ const modulesDir = path.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
46
+ if (await isDirMissing(entrypointsDir)) {
47
+ logMissingDir(logger, "Entrypoints", entrypointsDir);
48
+ }
49
+ const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
50
+ const publicDir = path.resolve(srcDir, mergedConfig.publicDir ?? "public");
51
+ if (await isDirMissing(publicDir)) {
52
+ logMissingDir(logger, "Public", publicDir);
53
+ }
54
+ const typesDir = path.resolve(wxtDir, "types");
55
+ const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
56
+ const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
57
+ const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
58
+ const runnerConfig = await loadConfig({
59
+ name: "web-ext",
60
+ cwd: root,
61
+ globalRc: true,
62
+ rcFile: ".webextrc",
63
+ overrides: inlineConfig.runner,
64
+ defaults: userConfig.runner
65
+ });
66
+ const alias = Object.fromEntries(
67
+ Object.entries({
68
+ ...mergedConfig.alias,
69
+ "@": srcDir,
70
+ "~": srcDir,
71
+ "@@": root,
72
+ "~~": root
73
+ }).map(([key, value]) => [key, path.resolve(root, value)])
74
+ );
75
+ let devServerConfig;
76
+ if (command === "serve") {
77
+ let port = mergedConfig.dev?.server?.port;
78
+ if (port == null || !isFinite(port)) {
79
+ const { default: getPort, portNumbers } = await import("get-port");
80
+ port = await getPort({ port: portNumbers(3e3, 3010) });
81
+ }
82
+ devServerConfig = {
83
+ port,
84
+ hostname: mergedConfig.dev?.server?.hostname ?? "localhost"
85
+ };
86
+ }
87
+ const userModules = await resolveWxtUserModules(
88
+ modulesDir,
89
+ mergedConfig.modules
90
+ );
91
+ const moduleOptions = userModules.reduce(
92
+ (map, module) => {
93
+ if (module.configKey) {
94
+ map[module.configKey] = // @ts-expect-error
95
+ mergedConfig[module.configKey];
96
+ }
97
+ return map;
98
+ },
99
+ {}
100
+ );
101
+ const extensionApi = mergedConfig.extensionApi ?? "webextension-polyfill";
102
+ return {
103
+ browser,
104
+ command,
105
+ debug,
106
+ entrypointsDir,
107
+ modulesDir,
108
+ filterEntrypoints,
109
+ env,
110
+ fsCache: createFsCache(wxtDir),
111
+ imports: await getUnimportOptions(
112
+ wxtDir,
113
+ srcDir,
114
+ logger,
115
+ extensionApi,
116
+ mergedConfig
117
+ ),
118
+ logger,
119
+ manifest: await resolveManifestConfig(env, mergedConfig.manifest),
120
+ manifestVersion,
121
+ mode,
122
+ outBaseDir,
123
+ outDir,
124
+ publicDir,
125
+ wxtModuleDir,
126
+ root,
127
+ runnerConfig,
128
+ srcDir,
129
+ typesDir,
130
+ wxtDir,
131
+ zip: resolveZipConfig(root, outBaseDir, mergedConfig),
132
+ transformManifest: mergedConfig.transformManifest,
133
+ analysis: resolveAnalysisConfig(root, mergedConfig),
134
+ userConfigMetadata: userConfigMetadata ?? {},
135
+ alias,
136
+ extensionApi,
137
+ browserModule: extensionApi === "chrome" ? "wxt/browser/chrome" : "wxt/browser",
138
+ entrypointLoader: mergedConfig.entrypointLoader ?? "vite-node",
139
+ experimental: defu(mergedConfig.experimental, {}),
140
+ dev: {
141
+ server: devServerConfig,
142
+ reloadCommand
143
+ },
144
+ hooks: mergedConfig.hooks ?? {},
145
+ vite: mergedConfig.vite ?? (() => ({})),
146
+ builtinModules,
147
+ userModules,
148
+ plugins: [],
149
+ ...moduleOptions
150
+ };
151
+ }
152
+ async function resolveManifestConfig(env, manifest) {
153
+ return typeof manifest === "function" ? await manifest(env) : await (manifest ?? {});
154
+ }
155
+ async function mergeInlineConfig(inlineConfig, userConfig) {
156
+ const imports = inlineConfig.imports === false || userConfig.imports === false ? false : userConfig.imports == null && inlineConfig.imports == null ? void 0 : defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
157
+ const manifest = async (env) => {
158
+ const user = await resolveManifestConfig(env, userConfig.manifest);
159
+ const inline = await resolveManifestConfig(env, inlineConfig.manifest);
160
+ return defu(inline, user);
161
+ };
162
+ const transformManifest = (manifest2) => {
163
+ userConfig.transformManifest?.(manifest2);
164
+ inlineConfig.transformManifest?.(manifest2);
165
+ };
166
+ const merged = defu(inlineConfig, userConfig);
167
+ const builderConfig = await mergeBuilderConfig(
168
+ merged.logger ?? consola,
169
+ inlineConfig,
170
+ userConfig
171
+ );
172
+ return {
173
+ ...merged,
174
+ // Custom merge values
175
+ transformManifest,
176
+ imports,
177
+ manifest,
178
+ ...builderConfig
179
+ };
180
+ }
181
+ function resolveZipConfig(root, outBaseDir, mergedConfig) {
182
+ const downloadedPackagesDir = path.resolve(root, ".wxt/local_modules");
183
+ return {
184
+ name: void 0,
185
+ sourcesTemplate: "{{name}}-{{version}}-sources.zip",
186
+ artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
187
+ sourcesRoot: root,
188
+ includeSources: [],
189
+ compressionLevel: 9,
190
+ ...mergedConfig.zip,
191
+ excludeSources: [
192
+ "**/node_modules",
193
+ // WXT files
194
+ "**/web-ext.config.ts",
195
+ // Hidden files
196
+ "**/.*",
197
+ // Tests
198
+ "**/__tests__/**",
199
+ "**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
200
+ // Output directory
201
+ `${path.relative(root, outBaseDir)}/**`,
202
+ // From user
203
+ ...mergedConfig.zip?.excludeSources ?? []
204
+ ],
205
+ downloadPackages: mergedConfig.zip?.downloadPackages ?? [],
206
+ downloadedPackagesDir
207
+ };
208
+ }
209
+ function resolveAnalysisConfig(root, mergedConfig) {
210
+ const analysisOutputFile = path.resolve(
211
+ root,
212
+ mergedConfig.analysis?.outputFile ?? "stats.html"
213
+ );
214
+ const analysisOutputDir = path.dirname(analysisOutputFile);
215
+ const analysisOutputName = path.parse(analysisOutputFile).name;
216
+ return {
217
+ enabled: mergedConfig.analysis?.enabled ?? false,
218
+ open: mergedConfig.analysis?.open ?? false,
219
+ template: mergedConfig.analysis?.template ?? "treemap",
220
+ outputFile: analysisOutputFile,
221
+ outputDir: analysisOutputDir,
222
+ outputName: analysisOutputName,
223
+ keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
224
+ };
225
+ }
226
+ async function getUnimportOptions(wxtDir, srcDir, logger, extensionApi, config) {
227
+ if (config.imports === false) return false;
228
+ const defaultOptions = {
229
+ debugLog: logger.debug,
230
+ imports: [
231
+ { name: "defineConfig", from: "wxt" },
232
+ { name: "fakeBrowser", from: "wxt/testing" }
233
+ ],
234
+ presets: [
235
+ {
236
+ package: "wxt/client",
237
+ // There seems to be a bug in unimport that thinks "options" is an
238
+ // export from wxt/client, but it doesn't actually exist... so it's
239
+ // ignored.
240
+ ignore: ["options"]
241
+ },
242
+ {
243
+ package: extensionApi === "chrome" ? "wxt/browser/chrome" : "wxt/browser"
244
+ },
245
+ { package: "wxt/sandbox" },
246
+ { package: "wxt/storage" }
247
+ ],
248
+ warn: logger.warn,
249
+ dirs: ["components", "composables", "hooks", "utils"],
250
+ dirsScanOptions: {
251
+ cwd: srcDir
252
+ },
253
+ eslintrc: await getUnimportEslintOptions(wxtDir, config.imports?.eslintrc)
254
+ };
255
+ return defu(
256
+ config.imports ?? {},
257
+ defaultOptions
258
+ );
259
+ }
260
+ async function getUnimportEslintOptions(wxtDir, options) {
261
+ const rawEslintEnabled = options?.enabled ?? "auto";
262
+ let eslintEnabled;
263
+ switch (rawEslintEnabled) {
264
+ case "auto":
265
+ const version = await getEslintVersion();
266
+ let major = parseInt(version[0]);
267
+ if (major <= 8) eslintEnabled = 8;
268
+ else if (major >= 9) eslintEnabled = 9;
269
+ else eslintEnabled = 8;
270
+ break;
271
+ case true:
272
+ eslintEnabled = 8;
273
+ break;
274
+ default:
275
+ eslintEnabled = rawEslintEnabled;
276
+ }
277
+ return {
278
+ enabled: eslintEnabled,
279
+ filePath: path.resolve(
280
+ wxtDir,
281
+ eslintEnabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
282
+ ),
283
+ globalsPropValue: true
284
+ };
285
+ }
286
+ async function resolveWxtModuleDir() {
287
+ const requireResolve = globalThis.require?.resolve ?? (await import("node:module")).default.createRequire(import.meta.url).resolve;
288
+ return path.resolve(requireResolve("wxt"), "../..");
289
+ }
290
+ async function isDirMissing(dir) {
291
+ return !await fs.exists(dir);
292
+ }
293
+ function logMissingDir(logger, name, expected) {
294
+ logger.warn(
295
+ `${name} directory not found: ./${normalizePath(
296
+ path.relative(process.cwd(), expected)
297
+ )}`
298
+ );
299
+ }
300
+ const COMMAND_MODES = {
301
+ build: "production",
302
+ serve: "development"
303
+ };
304
+ export async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
305
+ const vite = await import("vite").catch((err) => {
306
+ logger.debug("Failed to import vite:", err);
307
+ });
308
+ if (vite) {
309
+ return {
310
+ vite: async (env) => {
311
+ const resolvedInlineConfig = await inlineConfig.vite?.(env) ?? {};
312
+ const resolvedUserConfig = await userConfig.vite?.(env) ?? {};
313
+ return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
314
+ }
315
+ };
316
+ }
317
+ throw Error("Builder not found. Make sure vite is installed.");
318
+ }
319
+ export async function resolveWxtUserModules(modulesDir, modules = []) {
320
+ const npmModules = await Promise.all(
321
+ modules.map(async (moduleId) => {
322
+ const mod = await import(
323
+ /* @vite-ignore */
324
+ moduleId
325
+ );
326
+ if (mod.default == null) {
327
+ throw Error("Module missing default export: " + moduleId);
328
+ }
329
+ return {
330
+ ...mod.default,
331
+ type: "node_module",
332
+ id: moduleId
333
+ };
334
+ })
335
+ );
336
+ const localModulePaths = await glob(["*.[tj]s", "*/index.[tj]s"], {
337
+ cwd: modulesDir,
338
+ onlyFiles: true
339
+ }).catch(() => []);
340
+ const localModules = await Promise.all(
341
+ localModulePaths.map(async (file) => {
342
+ const absolutePath = normalizePath(path.resolve(modulesDir, file));
343
+ const { config } = await loadConfig({
344
+ configFile: absolutePath,
345
+ globalRc: false,
346
+ rcFile: false,
347
+ packageJson: false,
348
+ envName: false,
349
+ dotenv: false
350
+ });
351
+ if (config == null)
352
+ throw Error(
353
+ `No config found for ${file}. Did you forget to add a default export?`
354
+ );
355
+ config.name ??= file;
356
+ return {
357
+ ...config,
358
+ type: "local",
359
+ id: absolutePath
360
+ };
361
+ })
362
+ );
363
+ return [...npmModules, ...localModules];
364
+ }
@@ -0,0 +1,8 @@
1
+ import { FsCache } from '../../types';
2
+ /**
3
+ * A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches a string in a
4
+ * file for the given key.
5
+ *
6
+ * @param srcDir Absolute path to source directory. See `InternalConfig.srcDir`
7
+ */
8
+ export declare function createFsCache(wxtDir: string): FsCache;
@@ -0,0 +1,21 @@
1
+ import fs, { ensureDir } from "fs-extra";
2
+ import { dirname, resolve } from "path";
3
+ import { writeFileIfDifferent } from "./fs.mjs";
4
+ export function createFsCache(wxtDir) {
5
+ const getPath = (key) => resolve(wxtDir, "cache", encodeURIComponent(key));
6
+ return {
7
+ async set(key, value) {
8
+ const path = getPath(key);
9
+ await ensureDir(dirname(path));
10
+ await writeFileIfDifferent(path, value);
11
+ },
12
+ async get(key) {
13
+ const path = getPath(key);
14
+ try {
15
+ return await fs.readFile(path, "utf-8");
16
+ } catch {
17
+ return void 0;
18
+ }
19
+ }
20
+ };
21
+ }
@@ -0,0 +1,3 @@
1
+ export declare function defineCommand<TArgs extends any[]>(cb: (...args: TArgs) => void | boolean | Promise<void | boolean>, options?: {
2
+ disableFinishedLog?: boolean;
3
+ }): (...args: TArgs) => Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { LogLevels, consola } from "consola";
2
+ import { printHeader } from "./log/index.mjs";
3
+ import { formatDuration } from "./time.mjs";
4
+ export function defineCommand(cb, options) {
5
+ return async (...args) => {
6
+ const isDebug = !!args.find((arg) => arg?.debug);
7
+ if (isDebug) {
8
+ consola.level = LogLevels.debug;
9
+ }
10
+ const startTime = Date.now();
11
+ try {
12
+ printHeader();
13
+ const ongoing = await cb(...args);
14
+ if (!ongoing && !options?.disableFinishedLog)
15
+ consola.success(
16
+ `Finished in ${formatDuration(Date.now() - startTime)}`
17
+ );
18
+ } catch (err) {
19
+ consola.fail(
20
+ `Command failed after ${formatDuration(Date.now() - startTime)}`
21
+ );
22
+ consola.error(err);
23
+ process.exit(1);
24
+ }
25
+ };
26
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Module ID used to build the background in dev mode if the extension doesn't include a background
3
+ * script/service worker.
4
+ */
5
+ export declare const VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
@@ -0,0 +1 @@
1
+ export const VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
@@ -0,0 +1,11 @@
1
+ import type { Manifest, Scripting } from 'wxt/browser';
2
+ import { ContentScriptEntrypoint, ResolvedConfig } from '../../types';
3
+ /**
4
+ * Returns a unique and consistent string hash based on a content scripts options.
5
+ *
6
+ * It is able to recognize default values,
7
+ */
8
+ export declare function hashContentScriptOptions(options: ContentScriptEntrypoint['options']): string;
9
+ export declare function mapWxtOptionsToContentScript(options: ContentScriptEntrypoint['options'], js: string[] | undefined, css: string[] | undefined): Manifest.ContentScript;
10
+ export declare function mapWxtOptionsToRegisteredContentScript(options: ContentScriptEntrypoint['options'], js: string[] | undefined, css: string[] | undefined): Omit<Scripting.RegisteredContentScript, 'id'>;
11
+ export declare function getContentScriptJs(config: ResolvedConfig, entrypoint: ContentScriptEntrypoint): string[];
@@ -0,0 +1,60 @@
1
+ import { getEntrypointBundlePath } from "./entrypoints.mjs";
2
+ export function hashContentScriptOptions(options) {
3
+ const simplifiedOptions = mapWxtOptionsToContentScript(
4
+ options,
5
+ void 0,
6
+ void 0
7
+ );
8
+ Object.keys(simplifiedOptions).forEach((key) => {
9
+ if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
10
+ });
11
+ const withDefaults = {
12
+ exclude_globs: [],
13
+ exclude_matches: [],
14
+ include_globs: [],
15
+ match_about_blank: false,
16
+ run_at: "document_idle",
17
+ all_frames: false,
18
+ // @ts-expect-error - not in type
19
+ match_origin_as_fallback: false,
20
+ world: "ISOLATED",
21
+ ...simplifiedOptions
22
+ };
23
+ return JSON.stringify(
24
+ Object.entries(withDefaults).map(([key, value]) => {
25
+ if (Array.isArray(value)) return [key, value.sort()];
26
+ else return [key, value];
27
+ }).sort((l, r) => l[0].localeCompare(r[0]))
28
+ );
29
+ }
30
+ export function mapWxtOptionsToContentScript(options, js, css) {
31
+ return {
32
+ matches: options.matches,
33
+ all_frames: options.allFrames,
34
+ match_about_blank: options.matchAboutBlank,
35
+ exclude_globs: options.excludeGlobs,
36
+ exclude_matches: options.excludeMatches,
37
+ include_globs: options.includeGlobs,
38
+ run_at: options.runAt,
39
+ css,
40
+ js,
41
+ // @ts-expect-error: untyped chrome options
42
+ match_origin_as_fallback: options.matchOriginAsFallback,
43
+ world: options.world
44
+ };
45
+ }
46
+ export function mapWxtOptionsToRegisteredContentScript(options, js, css) {
47
+ return {
48
+ allFrames: options.allFrames,
49
+ excludeMatches: options.excludeMatches,
50
+ matches: options.matches,
51
+ runAt: options.runAt,
52
+ js,
53
+ css,
54
+ // @ts-expect-error: Chrome accepts this, not typed in webextension-polyfill (https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript)
55
+ world: options.world
56
+ };
57
+ }
58
+ export function getContentScriptJs(config, entrypoint) {
59
+ return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
60
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Directive names that make up CSPs. There are more, this is all I need for the plugin.
3
+ */
4
+ export type CspDirective = 'default-src' | 'script-src' | 'object-src';
5
+ export declare class ContentSecurityPolicy {
6
+ private static DIRECTIVE_ORDER;
7
+ data: Record<string, string[]>;
8
+ constructor(csp?: string);
9
+ /**
10
+ * Ensure a set of values are listed under a directive.
11
+ */
12
+ add(directive: CspDirective, ...newValues: string[]): ContentSecurityPolicy;
13
+ toString(): string;
14
+ }
@@ -0,0 +1,39 @@
1
+ export class ContentSecurityPolicy {
2
+ static DIRECTIVE_ORDER = {
3
+ "default-src": 0,
4
+ "script-src": 1,
5
+ "object-src": 2
6
+ };
7
+ data;
8
+ constructor(csp) {
9
+ if (csp) {
10
+ const sections = csp.split(";").map((section) => section.trim());
11
+ this.data = sections.reduce((data, section) => {
12
+ const [key, ...values] = section.split(" ").map((item) => item.trim());
13
+ if (key) data[key] = values;
14
+ return data;
15
+ }, {});
16
+ } else {
17
+ this.data = {};
18
+ }
19
+ }
20
+ /**
21
+ * Ensure a set of values are listed under a directive.
22
+ */
23
+ add(directive, ...newValues) {
24
+ const values = this.data[directive] ?? [];
25
+ newValues.forEach((newValue) => {
26
+ if (!values.includes(newValue)) values.push(newValue);
27
+ });
28
+ this.data[directive] = values;
29
+ return this;
30
+ }
31
+ toString() {
32
+ const directives = Object.entries(this.data).sort(([l], [r]) => {
33
+ const lo = ContentSecurityPolicy.DIRECTIVE_ORDER[l] ?? 2;
34
+ const ro = ContentSecurityPolicy.DIRECTIVE_ORDER[r] ?? 2;
35
+ return lo - ro;
36
+ });
37
+ return directives.map((entry) => entry.flat().join(" ")).join("; ") + ";";
38
+ }
39
+ }
@@ -0,0 +1,25 @@
1
+ import { Entrypoint, PerBrowserOption, ResolvedPerBrowserOptions, TargetBrowser } from '../../types';
2
+ export declare function getEntrypointName(entrypointsDir: string, inputPath: string): string;
3
+ export declare function getEntrypointOutputFile(entrypoint: Entrypoint, ext: string): string;
4
+ /**
5
+ * Return's the entrypoint's output path relative to the output directory. Used for paths in the
6
+ * manifest and rollup's bundle.
7
+ */
8
+ export declare function getEntrypointBundlePath(entrypoint: Entrypoint, outDir: string, ext: string): string;
9
+ /**
10
+ * Given an entrypoint option, resolve it's value based on a target browser.
11
+ */
12
+ export declare function resolvePerBrowserOption<T>(option: PerBrowserOption<T>, browser: TargetBrowser): T;
13
+ /**
14
+ * Given an entrypoint option, resolve it's value based on a target browser.
15
+ *
16
+ * defaultIcon is special, it's the only key that's a record, which can confuse this function. So
17
+ * it's been manually excluded from resolution.
18
+ */
19
+ export declare function resolvePerBrowserOptions<T extends Record<string, any>, TKeys extends keyof T>(options: T, browser: TargetBrowser): ResolvedPerBrowserOptions<T, TKeys>;
20
+ /**
21
+ * Returns true when the entrypoint is an HTML entrypoint.
22
+ *
23
+ * Naively just checking the file extension of the input path.
24
+ */
25
+ export declare function isHtmlEntrypoint(entrypoint: Entrypoint): boolean;
@@ -0,0 +1,31 @@
1
+ import path, { relative, resolve } from "node:path";
2
+ import { normalizePath } from "./paths.mjs";
3
+ export function getEntrypointName(entrypointsDir, inputPath) {
4
+ const relativePath = path.relative(entrypointsDir, inputPath);
5
+ const name = relativePath.split(/[\.\/\\]/, 2)[0];
6
+ return name;
7
+ }
8
+ export function getEntrypointOutputFile(entrypoint, ext) {
9
+ return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
10
+ }
11
+ export function getEntrypointBundlePath(entrypoint, outDir, ext) {
12
+ return normalizePath(
13
+ relative(outDir, getEntrypointOutputFile(entrypoint, ext))
14
+ );
15
+ }
16
+ export function resolvePerBrowserOption(option, browser) {
17
+ if (typeof option === "object" && !Array.isArray(option))
18
+ return option[browser];
19
+ return option;
20
+ }
21
+ export function resolvePerBrowserOptions(options, browser) {
22
+ return Object.fromEntries(
23
+ Object.entries(options).map(([key, value]) => [
24
+ key,
25
+ key === "defaultIcon" ? value : resolvePerBrowserOption(value, browser)
26
+ ])
27
+ );
28
+ }
29
+ export function isHtmlEntrypoint(entrypoint) {
30
+ return entrypoint.inputPath.endsWith(".html");
31
+ }
@@ -0,0 +1 @@
1
+ export declare function getEslintVersion(): Promise<string[]>;
@@ -0,0 +1,11 @@
1
+ export async function getEslintVersion() {
2
+ try {
3
+ const require = (await import("node:module")).default.createRequire(
4
+ import.meta.url
5
+ );
6
+ const { ESLint } = require("eslint");
7
+ return ESLint.version?.split(".") ?? [];
8
+ } catch (error) {
9
+ return [];
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Only write the contents to a file if it results in a change. This prevents unnecessary file
3
+ * watchers from being triggered, like WXT's dev server or the TS language server in editors.
4
+ *
5
+ * @param file The file to write to.
6
+ * @param newContents The new text content to write.
7
+ */
8
+ export declare function writeFileIfDifferent(file: string, newContents: string): Promise<void>;
9
+ /**
10
+ * Get all the files in the project's public directory. Returned paths are relative to the
11
+ * `config.publicDir`.
12
+ */
13
+ export declare function getPublicFiles(): Promise<string[]>;
@@ -0,0 +1,15 @@
1
+ import fs from "fs-extra";
2
+ import glob from "fast-glob";
3
+ import { unnormalizePath } from "./paths.mjs";
4
+ import { wxt } from "../wxt.mjs";
5
+ export async function writeFileIfDifferent(file, newContents) {
6
+ const existingContents = await fs.readFile(file, "utf-8").catch(() => void 0);
7
+ if (existingContents !== newContents) {
8
+ await fs.writeFile(file, newContents);
9
+ }
10
+ }
11
+ export async function getPublicFiles() {
12
+ if (!await fs.exists(wxt.config.publicDir)) return [];
13
+ const files = await glob("**/*", { cwd: wxt.config.publicDir });
14
+ return files.map(unnormalizePath);
15
+ }
@@ -0,0 +1,11 @@
1
+ import { ResolvedConfig } from '../../types';
2
+ export declare function getGlobals(config: ResolvedConfig): Array<{
3
+ name: string;
4
+ value: any;
5
+ type: string;
6
+ }>;
7
+ export declare function getEntrypointGlobals(entrypointName: string): {
8
+ name: string;
9
+ value: string;
10
+ type: string;
11
+ }[];