wxt 0.20.13 → 0.20.15

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 (280) 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 +54 -50
  6. package/dist/cli/commands.mjs +78 -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 +293 -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 +105 -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 +26 -23
  25. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -24
  26. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +28 -26
  27. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
  28. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +42 -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 +110 -148
  38. package/dist/core/index.d.mts +9 -0
  39. package/dist/core/index.mjs +12 -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 +15 -10
  53. package/dist/core/runners/manual.mjs +13 -14
  54. package/dist/core/runners/safari.mjs +13 -14
  55. package/dist/core/runners/web-ext.mjs +62 -83
  56. package/dist/core/runners/wsl.mjs +13 -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 +278 -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 +86 -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/index.mjs +3 -0
  80. package/dist/core/utils/log/index.mjs +6 -4
  81. package/dist/core/utils/log/printBuildSummary.mjs +20 -25
  82. package/dist/core/utils/log/printFileList.mjs +30 -33
  83. package/dist/core/utils/log/printHeader.mjs +9 -5
  84. package/dist/core/utils/log/printTable.mjs +19 -21
  85. package/dist/core/utils/manifest.mjs +366 -479
  86. package/dist/core/utils/minimatch-multiple.mjs +26 -15
  87. package/dist/core/utils/network.mjs +27 -33
  88. package/dist/core/utils/number.mjs +7 -3
  89. package/dist/core/utils/package.mjs +20 -13
  90. package/dist/core/utils/paths.d.mts +8 -0
  91. package/dist/core/utils/paths.mjs +26 -7
  92. package/dist/core/utils/strings.mjs +19 -14
  93. package/dist/core/utils/syntax-errors.mjs +14 -16
  94. package/dist/core/utils/time.mjs +19 -15
  95. package/dist/core/utils/transform.mjs +129 -160
  96. package/dist/core/utils/types.d.mts +6 -0
  97. package/dist/core/utils/validation.mjs +43 -50
  98. package/dist/core/utils/virtual-modules.mjs +20 -12
  99. package/dist/core/utils/wsl.mjs +11 -3
  100. package/dist/core/wxt.mjs +65 -60
  101. package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
  102. package/dist/core/zip.mjs +118 -140
  103. package/dist/index.d.mts +13 -0
  104. package/dist/index.mjs +13 -3
  105. package/dist/{modules.d.ts → modules.d.mts} +14 -16
  106. package/dist/modules.mjs +179 -51
  107. package/dist/testing/fake-browser.d.mts +2 -0
  108. package/dist/testing/fake-browser.mjs +3 -1
  109. package/dist/testing/index.d.mts +3 -0
  110. package/dist/testing/index.mjs +4 -2
  111. package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
  112. package/dist/testing/wxt-vitest-plugin.mjs +38 -19
  113. package/dist/types.d.mts +1475 -0
  114. package/dist/utils/app-config.d.mts +6 -0
  115. package/dist/utils/app-config.mjs +8 -2
  116. package/dist/utils/content-script-context.d.mts +134 -0
  117. package/dist/utils/content-script-context.mjs +187 -175
  118. package/dist/utils/content-script-ui/iframe.d.mts +42 -0
  119. package/dist/utils/content-script-ui/iframe.mjs +42 -27
  120. package/dist/utils/content-script-ui/integrated.d.mts +37 -0
  121. package/dist/utils/content-script-ui/integrated.mjs +36 -29
  122. package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
  123. package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
  124. package/dist/utils/content-script-ui/shared.mjs +115 -150
  125. package/dist/utils/content-script-ui/types.d.mts +107 -0
  126. package/dist/utils/content-script-ui/types.mjs +1 -0
  127. package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
  128. package/dist/utils/define-app-config.mjs +22 -2
  129. package/dist/utils/define-background.d.mts +7 -0
  130. package/dist/utils/define-background.mjs +7 -3
  131. package/dist/utils/define-content-script.d.mts +6 -0
  132. package/dist/utils/define-content-script.mjs +6 -2
  133. package/dist/utils/define-unlisted-script.d.mts +7 -0
  134. package/dist/utils/define-unlisted-script.mjs +7 -3
  135. package/dist/utils/define-wxt-plugin.d.mts +6 -0
  136. package/dist/utils/define-wxt-plugin.mjs +6 -2
  137. package/dist/utils/inject-script.d.mts +41 -0
  138. package/dist/utils/inject-script.mjs +44 -34
  139. package/dist/utils/internal/custom-events.d.mts +9 -0
  140. package/dist/utils/internal/custom-events.mjs +18 -10
  141. package/dist/utils/internal/location-watcher.mjs +23 -20
  142. package/dist/utils/internal/logger.mjs +15 -12
  143. package/dist/utils/match-patterns.d.mts +1 -0
  144. package/dist/utils/match-patterns.mjs +3 -1
  145. package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
  146. package/dist/utils/split-shadow-root-css.mjs +16 -7
  147. package/dist/utils/storage.d.mts +1 -0
  148. package/dist/utils/storage.mjs +3 -1
  149. package/dist/version.d.mts +4 -0
  150. package/dist/version.mjs +5 -1
  151. package/dist/virtual/background-entrypoint.d.mts +4 -0
  152. package/dist/virtual/background-entrypoint.mjs +143 -161
  153. package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
  154. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
  155. package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
  156. package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
  157. package/dist/virtual/mock-browser.d.mts +6 -0
  158. package/dist/virtual/mock-browser.mjs +5 -3
  159. package/dist/virtual/reload-html.d.mts +1 -0
  160. package/dist/virtual/reload-html.mjs +57 -53
  161. package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
  162. package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
  163. package/package.json +56 -50
  164. package/dist/browser.d.ts +0 -30
  165. package/dist/builtin-modules/index.d.ts +0 -2
  166. package/dist/builtin-modules/unimport.d.ts +0 -5
  167. package/dist/cli/cli-utils.d.ts +0 -25
  168. package/dist/cli/commands.d.ts +0 -2
  169. package/dist/cli/index.d.ts +0 -1
  170. package/dist/core/builders/vite/index.d.ts +0 -7
  171. package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
  172. package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
  173. package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
  174. package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
  175. package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
  176. package/dist/core/builders/vite/plugins/download.d.ts +0 -10
  177. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
  178. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
  179. package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
  180. package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
  181. package/dist/core/builders/vite/plugins/index.d.ts +0 -16
  182. package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
  183. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
  184. package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
  185. package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
  186. package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
  187. package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
  188. package/dist/core/define-config.d.ts +0 -2
  189. package/dist/core/define-web-ext-config.d.ts +0 -9
  190. package/dist/core/generate-wxt-dir.d.ts +0 -5
  191. package/dist/core/index.d.ts +0 -8
  192. package/dist/core/initialize.d.ts +0 -5
  193. package/dist/core/keyboard-shortcuts.d.ts +0 -12
  194. package/dist/core/package-managers/bun.d.ts +0 -2
  195. package/dist/core/package-managers/deno.d.ts +0 -2
  196. package/dist/core/package-managers/index.d.ts +0 -2
  197. package/dist/core/package-managers/npm.d.ts +0 -17
  198. package/dist/core/package-managers/pnpm.d.ts +0 -2
  199. package/dist/core/package-managers/types.d.ts +0 -2
  200. package/dist/core/package-managers/types.mjs +0 -0
  201. package/dist/core/package-managers/yarn.d.ts +0 -2
  202. package/dist/core/prepare.d.ts +0 -2
  203. package/dist/core/resolve-config.d.ts +0 -11
  204. package/dist/core/runners/index.d.ts +0 -2
  205. package/dist/core/runners/manual.d.ts +0 -5
  206. package/dist/core/runners/safari.d.ts +0 -5
  207. package/dist/core/runners/web-ext.d.ts +0 -5
  208. package/dist/core/runners/wsl.d.ts +0 -5
  209. package/dist/core/utils/arrays.d.ts +0 -13
  210. package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
  211. package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
  212. package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
  213. package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
  214. package/dist/core/utils/building/index.d.ts +0 -6
  215. package/dist/core/utils/building/internal-build.d.ts +0 -12
  216. package/dist/core/utils/building/rebuild.d.ts +0 -23
  217. package/dist/core/utils/cache.d.ts +0 -8
  218. package/dist/core/utils/cli.d.ts +0 -3
  219. package/dist/core/utils/cli.mjs +0 -26
  220. package/dist/core/utils/constants.d.ts +0 -5
  221. package/dist/core/utils/content-scripts.d.ts +0 -12
  222. package/dist/core/utils/content-security-policy.d.ts +0 -14
  223. package/dist/core/utils/entrypoints.d.ts +0 -31
  224. package/dist/core/utils/env.d.ts +0 -5
  225. package/dist/core/utils/environments/browser-environment.d.ts +0 -3
  226. package/dist/core/utils/environments/environment.d.ts +0 -8
  227. package/dist/core/utils/environments/extension-environment.d.ts +0 -6
  228. package/dist/core/utils/environments/index.d.ts +0 -2
  229. package/dist/core/utils/eslint.d.ts +0 -1
  230. package/dist/core/utils/fs.d.ts +0 -13
  231. package/dist/core/utils/globals.d.ts +0 -11
  232. package/dist/core/utils/i18n.d.ts +0 -11
  233. package/dist/core/utils/log/index.d.ts +0 -4
  234. package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
  235. package/dist/core/utils/log/printFileList.d.ts +0 -1
  236. package/dist/core/utils/log/printHeader.d.ts +0 -1
  237. package/dist/core/utils/log/printTable.d.ts +0 -1
  238. package/dist/core/utils/manifest.d.ts +0 -40
  239. package/dist/core/utils/minimatch-multiple.d.ts +0 -15
  240. package/dist/core/utils/network.d.ts +0 -7
  241. package/dist/core/utils/number.d.ts +0 -1
  242. package/dist/core/utils/package.d.ts +0 -6
  243. package/dist/core/utils/paths.d.ts +0 -11
  244. package/dist/core/utils/strings.d.ts +0 -14
  245. package/dist/core/utils/syntax-errors.d.ts +0 -11
  246. package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
  247. package/dist/core/utils/testing/fake-objects.mjs +0 -326
  248. package/dist/core/utils/time.d.ts +0 -9
  249. package/dist/core/utils/transform.d.ts +0 -11
  250. package/dist/core/utils/types.d.ts +0 -13
  251. package/dist/core/utils/types.mjs +0 -0
  252. package/dist/core/utils/validation.d.ts +0 -15
  253. package/dist/core/utils/virtual-modules.d.ts +0 -22
  254. package/dist/core/utils/wsl.d.ts +0 -4
  255. package/dist/core/wxt.d.ts +0 -24
  256. package/dist/index.d.ts +0 -11
  257. package/dist/testing/fake-browser.d.ts +0 -10
  258. package/dist/testing/index.d.ts +0 -10
  259. package/dist/types.d.ts +0 -1459
  260. package/dist/types.mjs +0 -0
  261. package/dist/utils/app-config.d.ts +0 -2
  262. package/dist/utils/content-script-context.d.ts +0 -134
  263. package/dist/utils/content-script-ui/iframe.d.ts +0 -32
  264. package/dist/utils/content-script-ui/integrated.d.ts +0 -34
  265. package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
  266. package/dist/utils/content-script-ui/shared.d.ts +0 -5
  267. package/dist/utils/content-script-ui/types.d.ts +0 -104
  268. package/dist/utils/define-background.d.ts +0 -4
  269. package/dist/utils/define-content-script.d.ts +0 -3
  270. package/dist/utils/define-unlisted-script.d.ts +0 -4
  271. package/dist/utils/define-wxt-plugin.d.ts +0 -3
  272. package/dist/utils/inject-script.d.ts +0 -36
  273. package/dist/utils/internal/custom-events.d.ts +0 -10
  274. package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
  275. package/dist/utils/internal/dev-server-websocket.mjs +0 -37
  276. package/dist/utils/internal/location-watcher.d.ts +0 -12
  277. package/dist/utils/internal/logger.d.ts +0 -9
  278. package/dist/utils/match-patterns.d.ts +0 -5
  279. package/dist/utils/storage.d.ts +0 -5
  280. package/dist/version.d.ts +0 -1
@@ -1,53 +1,49 @@
1
- import fs from "fs-extra";
2
- import { dirname, relative, resolve } from "node:path";
1
+ import { normalizePath } from "./utils/paths.mjs";
2
+ import "./utils/index.mjs";
3
3
  import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
4
4
  import { getEntrypointGlobals, getGlobals } from "./utils/globals.mjs";
5
- import { normalizePath } from "./utils/paths.mjs";
6
- import path from "node:path";
7
- import { parseI18nMessages } from "./utils/i18n.mjs";
8
- import { writeFileIfDifferent, getPublicFiles } from "./utils/fs.mjs";
9
5
  import { wxt } from "./wxt.mjs";
10
- export async function generateWxtDir(entrypoints) {
11
- await fs.ensureDir(wxt.config.typesDir);
12
- const entries = [
13
- // Hard-coded entries
14
- { module: "wxt/vite-builder-env" }
15
- ];
16
- wxt.config.userModules.forEach((module) => {
17
- if (module.type === "node_module") entries.push({ module: module.id });
18
- });
19
- entries.push(await getPathsDeclarationEntry(entrypoints));
20
- entries.push(await getI18nDeclarationEntry());
21
- entries.push(await getGlobalsDeclarationEntry());
22
- entries.push(await getTsConfigEntry());
23
- await wxt.hooks.callHook("prepare:types", wxt, entries);
24
- entries.push(getMainDeclarationEntry(entries));
25
- const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
26
- ...entry,
27
- path: resolve(wxt.config.wxtDir, entry.path)
28
- }));
29
- await Promise.all(
30
- absoluteFileEntries.map(async (file) => {
31
- await fs.ensureDir(dirname(file.path));
32
- await writeFileIfDifferent(file.path, file.text);
33
- })
34
- );
6
+ import { getPublicFiles, writeFileIfDifferent } from "./utils/fs.mjs";
7
+ import { parseI18nMessages } from "./utils/i18n.mjs";
8
+ import fs from "fs-extra";
9
+ import path, { dirname, relative, resolve } from "node:path";
10
+
11
+ //#region src/core/generate-wxt-dir.ts
12
+ /**
13
+ * Generate and write all the files inside the `InternalConfig.typesDir` directory.
14
+ */
15
+ async function generateWxtDir(entrypoints) {
16
+ await fs.ensureDir(wxt.config.typesDir);
17
+ const entries = [{ module: "wxt/vite-builder-env" }];
18
+ wxt.config.userModules.forEach((module) => {
19
+ if (module.type === "node_module") entries.push({ module: module.id });
20
+ });
21
+ entries.push(await getPathsDeclarationEntry(entrypoints));
22
+ entries.push(await getI18nDeclarationEntry());
23
+ entries.push(await getGlobalsDeclarationEntry());
24
+ entries.push(await getTsConfigEntry());
25
+ await wxt.hooks.callHook("prepare:types", wxt, entries);
26
+ entries.push(getMainDeclarationEntry(entries));
27
+ const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
28
+ ...entry,
29
+ path: resolve(wxt.config.wxtDir, entry.path)
30
+ }));
31
+ await Promise.all(absoluteFileEntries.map(async (file) => {
32
+ await fs.ensureDir(dirname(file.path));
33
+ await writeFileIfDifferent(file.path, file.text);
34
+ }));
35
35
  }
36
36
  async function getPathsDeclarationEntry(entrypoints) {
37
- const paths = entrypoints.map(
38
- (entry) => getEntrypointBundlePath(
39
- entry,
40
- wxt.config.outDir,
41
- isHtmlEntrypoint(entry) ? ".html" : ".js"
42
- )
43
- ).concat(await getPublicFiles());
44
- await wxt.hooks.callHook("prepare:publicPaths", wxt, paths);
45
- const unions = [
46
- ` | ""`,
47
- ` | "/"`,
48
- ...paths.map(normalizePath).sort().map((path2) => ` | "/${path2}"`)
49
- ].join("\n");
50
- const template = `// Generated by wxt
37
+ const paths = entrypoints.map((entry) => getEntrypointBundlePath(entry, wxt.config.outDir, isHtmlEntrypoint(entry) ? ".html" : ".js")).concat(await getPublicFiles());
38
+ await wxt.hooks.callHook("prepare:publicPaths", wxt, paths);
39
+ const unions = [
40
+ ` | ""`,
41
+ ` | "/"`,
42
+ ...paths.map(normalizePath).sort().map((path) => ` | "/${path}"`)
43
+ ].join("\n");
44
+ return {
45
+ path: "types/paths.d.ts",
46
+ text: `// Generated by wxt
51
47
  import "wxt/browser";
52
48
 
53
49
  declare module "wxt/browser" {
@@ -59,16 +55,13 @@ declare module "wxt/browser" {
59
55
  getURL(path: \`\${HtmlPublicPath}\${string}\`): string;
60
56
  }
61
57
  }
62
- `;
63
- return {
64
- path: "types/paths.d.ts",
65
- text: template.replace("{{ union }}", unions || " | never"),
66
- tsReference: true
67
- };
58
+ `.replace("{{ union }}", unions || " | never"),
59
+ tsReference: true
60
+ };
68
61
  }
69
62
  async function getI18nDeclarationEntry() {
70
- const defaultLocale = wxt.config.manifest.default_locale;
71
- const template = `// Generated by wxt
63
+ const defaultLocale = wxt.config.manifest.default_locale;
64
+ const template = `// Generated by wxt
72
65
  import "wxt/browser";
73
66
 
74
67
  declare module "wxt/browser" {
@@ -87,105 +80,71 @@ declare module "wxt/browser" {
87
80
  }
88
81
  }
89
82
  `;
90
- const defaultLocalePath = path.resolve(
91
- wxt.config.publicDir,
92
- "_locales",
93
- defaultLocale ?? "",
94
- "messages.json"
95
- );
96
- let messages;
97
- if (await fs.exists(defaultLocalePath)) {
98
- const content = JSON.parse(await fs.readFile(defaultLocalePath, "utf-8"));
99
- messages = parseI18nMessages(content);
100
- } else {
101
- messages = parseI18nMessages({});
102
- }
103
- const renderGetMessageOverload = (keyType, description, translation) => {
104
- const commentLines = [];
105
- if (description) commentLines.push(...description.split("\n"));
106
- if (translation) {
107
- if (commentLines.length > 0) commentLines.push("");
108
- commentLines.push(`"${translation}"`);
109
- }
110
- const comment = commentLines.length > 0 ? `/**
111
- ${commentLines.map((line) => ` * ${line}`.trimEnd()).join("\n")}
112
- */
113
- ` : "";
114
- return ` ${comment}getMessage(
83
+ const defaultLocalePath = path.resolve(wxt.config.publicDir, "_locales", defaultLocale ?? "", "messages.json");
84
+ let messages;
85
+ if (await fs.pathExists(defaultLocalePath)) messages = parseI18nMessages(JSON.parse(await fs.readFile(defaultLocalePath, "utf-8")));
86
+ else messages = parseI18nMessages({});
87
+ const renderGetMessageOverload = (keyType, description, translation) => {
88
+ const commentLines = [];
89
+ if (description) commentLines.push(...description.split("\n"));
90
+ if (translation) {
91
+ if (commentLines.length > 0) commentLines.push("");
92
+ commentLines.push(`"${translation}"`);
93
+ }
94
+ return ` ${commentLines.length > 0 ? `/**\n${commentLines.map((line) => ` * ${line}`.trimEnd()).join("\n")}\n */\n ` : ""}getMessage(
115
95
  messageName: ${keyType},
116
96
  substitutions?: string | string[],
117
97
  options?: GetMessageOptions,
118
98
  ): string;`;
119
- };
120
- const overrides = [
121
- // Generate individual overloads for each message so JSDoc contains description and base translation.
122
- ...messages.map(
123
- (message) => renderGetMessageOverload(
124
- `"${message.name}"`,
125
- message.description,
126
- message.message
127
- )
128
- ),
129
- // Include a final union-based override so TS accepts valid string templates or concatenations
130
- // ie: browser.i18n.getMessage(`some_enum_${enumValue}`)
131
- renderGetMessageOverload(
132
- messages.map((message) => `"${message.name}"`).join(" | ")
133
- )
134
- ];
135
- return {
136
- path: "types/i18n.d.ts",
137
- text: template.replace("{{ overrides }}", overrides.join("\n")),
138
- tsReference: true
139
- };
99
+ };
100
+ const overrides = [...messages.map((message) => renderGetMessageOverload(`"${message.name}"`, message.description, message.message)), renderGetMessageOverload(messages.map((message) => `"${message.name}"`).join(" | "))];
101
+ return {
102
+ path: "types/i18n.d.ts",
103
+ text: template.replace("{{ overrides }}", overrides.join("\n")),
104
+ tsReference: true
105
+ };
140
106
  }
141
107
  async function getGlobalsDeclarationEntry() {
142
- const globals = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
143
- return {
144
- path: "types/globals.d.ts",
145
- text: [
146
- "// Generated by wxt",
147
- "interface ImportMetaEnv {",
148
- ...globals.map((global) => ` readonly ${global.name}: ${global.type};`),
149
- "}",
150
- "interface ImportMeta {",
151
- " readonly env: ImportMetaEnv",
152
- "}",
153
- ""
154
- ].join("\n"),
155
- tsReference: true
156
- };
108
+ return {
109
+ path: "types/globals.d.ts",
110
+ text: [
111
+ "// Generated by wxt",
112
+ "interface ImportMetaEnv {",
113
+ ...[...getGlobals(wxt.config), ...getEntrypointGlobals("")].map((global) => ` readonly ${global.name}: ${global.type};`),
114
+ "}",
115
+ "interface ImportMeta {",
116
+ " readonly env: ImportMetaEnv",
117
+ "}",
118
+ ""
119
+ ].join("\n"),
120
+ tsReference: true
121
+ };
157
122
  }
158
123
  function getMainDeclarationEntry(references) {
159
- const lines = ["// Generated by wxt"];
160
- references.forEach((ref) => {
161
- if ("module" in ref) {
162
- return lines.push(`/// <reference types="${ref.module}" />`);
163
- } else if (ref.tsReference) {
164
- const absolutePath = resolve(wxt.config.wxtDir, ref.path);
165
- const relativePath = relative(wxt.config.wxtDir, absolutePath);
166
- lines.push(`/// <reference path="./${normalizePath(relativePath)}" />`);
167
- }
168
- });
169
- return {
170
- path: "wxt.d.ts",
171
- text: lines.join("\n") + "\n"
172
- };
124
+ const lines = ["// Generated by wxt"];
125
+ references.forEach((ref) => {
126
+ if ("module" in ref) return lines.push(`/// <reference types="${ref.module}" />`);
127
+ else if (ref.tsReference) {
128
+ const absolutePath = resolve(wxt.config.wxtDir, ref.path);
129
+ const relativePath = relative(wxt.config.wxtDir, absolutePath);
130
+ lines.push(`/// <reference path="./${normalizePath(relativePath)}" />`);
131
+ }
132
+ });
133
+ return {
134
+ path: "wxt.d.ts",
135
+ text: lines.join("\n") + "\n"
136
+ };
173
137
  }
174
138
  async function getTsConfigEntry() {
175
- const dir = wxt.config.wxtDir;
176
- const getTsconfigPath = (path2) => {
177
- const res = normalizePath(relative(dir, path2));
178
- if (res.startsWith(".") || res.startsWith("/")) return res;
179
- return "./" + res;
180
- };
181
- const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
182
- const aliasPath = getTsconfigPath(absolutePath);
183
- return [
184
- `"${alias}": ["${aliasPath}"]`,
185
- `"${alias}/*": ["${aliasPath}/*"]`
186
- ];
187
- }).map((line) => ` ${line}`).join(",\n");
188
- const text = `{
139
+ const dir = wxt.config.wxtDir;
140
+ const getTsconfigPath = (path) => {
141
+ const res = normalizePath(relative(dir, path));
142
+ if (res.startsWith(".") || res.startsWith("/")) return res;
143
+ return "./" + res;
144
+ };
145
+ return {
146
+ path: "tsconfig.json",
147
+ text: `{
189
148
  "compilerOptions": {
190
149
  "target": "ESNext",
191
150
  "module": "ESNext",
@@ -197,7 +156,10 @@ async function getTsConfigEntry() {
197
156
  "strict": true,
198
157
  "skipLibCheck": true,
199
158
  "paths": {
200
- ${paths}
159
+ ${Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
160
+ const aliasPath = getTsconfigPath(absolutePath);
161
+ return [`"${alias}": ["${aliasPath}"]`, `"${alias}/*": ["${aliasPath}/*"]`];
162
+ }).map((line) => ` ${line}`).join(",\n")}
201
163
  }
202
164
  },
203
165
  "include": [
@@ -205,9 +167,9 @@ ${paths}
205
167
  "./wxt.d.ts"
206
168
  ],
207
169
  "exclude": ["${getTsconfigPath(wxt.config.outBaseDir)}"]
208
- }`;
209
- return {
210
- path: "tsconfig.json",
211
- text
212
- };
170
+ }`
171
+ };
213
172
  }
173
+
174
+ //#endregion
175
+ export { generateWxtDir };
@@ -0,0 +1,9 @@
1
+ import { build } from "./build.mjs";
2
+ import { clean } from "./clean.mjs";
3
+ import { defineConfig } from "./define-config.mjs";
4
+ import { defineRunnerConfig, defineWebExtConfig } from "./define-web-ext-config.mjs";
5
+ import { createServer } from "./create-server.mjs";
6
+ import { initialize } from "./initialize.mjs";
7
+ import { prepare } from "./prepare.mjs";
8
+ import { zip } from "./zip.mjs";
9
+ import { normalizePath } from "./utils/paths.mjs";
@@ -1,8 +1,12 @@
1
- export * from "./build.mjs";
2
- export * from "./clean.mjs";
3
- export * from "./define-config.mjs";
4
- export * from "./define-web-ext-config.mjs";
5
- export * from "./create-server.mjs";
6
- export * from "./initialize.mjs";
7
- export * from "./prepare.mjs";
8
- export * from "./zip.mjs";
1
+ import { normalizePath } from "./utils/paths.mjs";
2
+ import "./utils/index.mjs";
3
+ import { build } from "./build.mjs";
4
+ import { clean } from "./clean.mjs";
5
+ import { defineConfig } from "./define-config.mjs";
6
+ import { defineRunnerConfig, defineWebExtConfig } from "./define-web-ext-config.mjs";
7
+ import { createServer } from "./create-server.mjs";
8
+ import { initialize } from "./initialize.mjs";
9
+ import { prepare } from "./prepare.mjs";
10
+ import { zip } from "./zip.mjs";
11
+
12
+ export { };
@@ -0,0 +1,8 @@
1
+ //#region src/core/initialize.d.ts
2
+ declare function initialize(options: {
3
+ directory: string;
4
+ template: string;
5
+ packageManager: string;
6
+ }): Promise<void>;
7
+ //#endregion
8
+ export { initialize };
@@ -1,140 +1,126 @@
1
- import prompts from "prompts";
2
- import { consola } from "consola";
3
- import { downloadTemplate } from "giget";
4
1
  import fs from "fs-extra";
5
2
  import path from "node:path";
3
+ import { consola as consola$1 } from "consola";
6
4
  import pc from "picocolors";
7
- export async function initialize(options) {
8
- consola.info("Initializing new project");
9
- const templates = await listTemplates();
10
- const defaultTemplate = templates.find(
11
- (template) => template.name === options.template?.toLowerCase().trim()
12
- );
13
- const input = await prompts(
14
- [
15
- {
16
- name: "directory",
17
- type: () => options.directory == null ? "text" : void 0,
18
- message: "Project Directory",
19
- initial: options.directory
20
- },
21
- {
22
- name: "template",
23
- type: () => defaultTemplate == null ? "select" : void 0,
24
- message: "Choose a template",
25
- choices: templates.map((template) => ({
26
- title: TEMPLATE_COLORS[template.name]?.(template.name) ?? template.name,
27
- value: template
28
- }))
29
- },
30
- {
31
- name: "packageManager",
32
- type: () => options.packageManager == null ? "select" : void 0,
33
- message: "Package Manager",
34
- choices: [
35
- { title: pc.red("npm"), value: "npm" },
36
- { title: pc.yellow("pnpm"), value: "pnpm" },
37
- { title: pc.cyan("yarn"), value: "yarn" },
38
- { title: pc.magenta("bun"), value: "bun" }
39
- ]
40
- }
41
- ],
42
- {
43
- onCancel: () => process.exit(1)
44
- }
45
- );
46
- input.directory ??= options.directory;
47
- input.template ??= defaultTemplate;
48
- input.packageManager ??= options.packageManager;
49
- const isExists = await fs.pathExists(input.directory);
50
- if (isExists) {
51
- const isEmpty = (await fs.readdir(input.directory)).filter((dir) => dir !== ".git").length === 0;
52
- if (!isEmpty) {
53
- consola.error(
54
- `The directory ${path.resolve(input.directory)} is not empty. Aborted.`
55
- );
56
- process.exit(1);
57
- }
58
- }
59
- await cloneProject(input);
60
- const cdPath = path.relative(process.cwd(), path.resolve(input.directory));
61
- console.log();
62
- consola.log(
63
- `\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
64
- );
65
- console.log();
66
- consola.log("Next steps:");
67
- let step = 0;
68
- if (cdPath !== "") consola.log(` ${++step}.`, pc.cyan(`cd ${cdPath}`));
69
- consola.log(` ${++step}.`, pc.cyan(`${input.packageManager} install`));
70
- console.log();
5
+ import prompts from "prompts";
6
+ import { downloadTemplate } from "giget";
7
+
8
+ //#region src/core/initialize.ts
9
+ async function initialize(options) {
10
+ consola$1.info("Initializing new project");
11
+ const templates = await listTemplates();
12
+ const defaultTemplate = templates.find((template) => template.name === options.template?.toLowerCase().trim());
13
+ const input = await prompts([
14
+ {
15
+ name: "directory",
16
+ type: () => options.directory == null ? "text" : void 0,
17
+ message: "Project Directory",
18
+ initial: options.directory
19
+ },
20
+ {
21
+ name: "template",
22
+ type: () => defaultTemplate == null ? "select" : void 0,
23
+ message: "Choose a template",
24
+ choices: templates.map((template) => ({
25
+ title: TEMPLATE_COLORS[template.name]?.(template.name) ?? template.name,
26
+ value: template
27
+ }))
28
+ },
29
+ {
30
+ name: "packageManager",
31
+ type: () => options.packageManager == null ? "select" : void 0,
32
+ message: "Package Manager",
33
+ choices: [
34
+ {
35
+ title: pc.red("npm"),
36
+ value: "npm"
37
+ },
38
+ {
39
+ title: pc.yellow("pnpm"),
40
+ value: "pnpm"
41
+ },
42
+ {
43
+ title: pc.cyan("yarn"),
44
+ value: "yarn"
45
+ },
46
+ {
47
+ title: pc.magenta("bun"),
48
+ value: "bun"
49
+ }
50
+ ]
51
+ }
52
+ ], { onCancel: () => process.exit(1) });
53
+ input.directory ??= options.directory;
54
+ input.template ??= defaultTemplate;
55
+ input.packageManager ??= options.packageManager;
56
+ if (await fs.pathExists(input.directory)) {
57
+ if (!((await fs.readdir(input.directory)).filter((dir) => dir !== ".git").length === 0)) {
58
+ consola$1.error(`The directory ${path.resolve(input.directory)} is not empty. Aborted.`);
59
+ process.exit(1);
60
+ }
61
+ }
62
+ await cloneProject(input);
63
+ const cdPath = path.relative(process.cwd(), path.resolve(input.directory));
64
+ console.log();
65
+ consola$1.log(`✨ WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`);
66
+ console.log();
67
+ consola$1.log("Next steps:");
68
+ let step = 0;
69
+ if (cdPath !== "") consola$1.log(` ${++step}.`, pc.cyan(`cd ${cdPath}`));
70
+ consola$1.log(` ${++step}.`, pc.cyan(`${input.packageManager} install`));
71
+ console.log();
71
72
  }
72
73
  async function listTemplates() {
73
- const templates = await listTemplatesUngh().catch((err) => {
74
- consola.debug("Failed to load templates via ungh:", err);
75
- return listTemplatesGithub();
76
- });
77
- return templates.sort((l, r) => {
78
- const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
79
- const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
80
- const diff = lWeight - rWeight;
81
- if (diff !== 0) return diff;
82
- return l.name.localeCompare(r.name);
83
- });
74
+ return (await listTemplatesUngh().catch((err) => {
75
+ consola$1.debug("Failed to load templates via ungh:", err);
76
+ return listTemplatesGithub();
77
+ })).sort((l, r) => {
78
+ const diff = (TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER) - (TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER);
79
+ if (diff !== 0) return diff;
80
+ return l.name.localeCompare(r.name);
81
+ });
84
82
  }
85
83
  async function listTemplatesUngh() {
86
- const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
87
- if (res.status !== 200)
88
- throw Error(
89
- `Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`
90
- );
91
- const data = await res.json();
92
- return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` }));
84
+ const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
85
+ if (res.status !== 200) throw Error(`Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`);
86
+ return (await res.json()).files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({
87
+ name,
88
+ path: `templates/${name}`
89
+ }));
93
90
  }
94
91
  async function listTemplatesGithub() {
95
- const res = await fetch(
96
- `https://api.github.com/repos/${REPO}/contents/templates`,
97
- { headers: { Accept: "application/vnd.github+json" } }
98
- );
99
- if (res.status !== 200)
100
- throw Error(
101
- `Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`
102
- );
103
- return await res.json();
92
+ const res = await fetch(`https://api.github.com/repos/${REPO}/contents/templates`, { headers: { Accept: "application/vnd.github+json" } });
93
+ if (res.status !== 200) throw Error(`Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`);
94
+ return await res.json();
104
95
  }
105
- async function cloneProject({
106
- directory,
107
- template
108
- }) {
109
- const { default: ora } = await import("ora");
110
- const spinner = ora("Downloading template").start();
111
- try {
112
- await downloadTemplate(`gh:${REPO}/${template.path}`, {
113
- dir: directory,
114
- force: true
115
- });
116
- await fs.move(
117
- path.join(directory, "_gitignore"),
118
- path.join(directory, ".gitignore")
119
- ).catch(
120
- (err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
121
- );
122
- spinner.succeed();
123
- } catch (err) {
124
- spinner.fail();
125
- throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
126
- }
96
+ async function cloneProject({ directory, template }) {
97
+ const { default: ora } = await import("ora");
98
+ const spinner = ora("Downloading template").start();
99
+ try {
100
+ await downloadTemplate(`gh:${REPO}/${template.path}`, {
101
+ dir: directory,
102
+ force: true
103
+ });
104
+ await fs.move(path.join(directory, "_gitignore"), path.join(directory, ".gitignore")).catch((err) => consola$1.warn("Failed to move _gitignore to .gitignore:", err));
105
+ spinner.succeed();
106
+ } catch (err) {
107
+ spinner.fail();
108
+ throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
109
+ }
127
110
  }
128
111
  const TEMPLATE_COLORS = {
129
- vanilla: pc.blue,
130
- vue: pc.green,
131
- react: pc.cyan,
132
- svelte: pc.red,
133
- solid: pc.blue
112
+ vanilla: pc.blue,
113
+ vue: pc.green,
114
+ react: pc.cyan,
115
+ svelte: pc.red,
116
+ solid: pc.blue
134
117
  };
135
118
  const TEMPLATE_SORT_WEIGHT = {
136
- vanilla: 0,
137
- vue: 1,
138
- react: 2
119
+ vanilla: 0,
120
+ vue: 1,
121
+ react: 2
139
122
  };
140
123
  const REPO = "wxt-dev/wxt";
124
+
125
+ //#endregion
126
+ export { initialize };