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,322 @@
1
+ import { resolve } from "path";
2
+ import { faker } from "@faker-js/faker";
3
+ import merge from "lodash.merge";
4
+ import { mock } from "vitest-mock-extended";
5
+ import { vi } from "vitest";
6
+ import { setWxtForTesting } from "../../../core/wxt.mjs";
7
+ faker.seed(import.meta.test.SEED);
8
+ function fakeObjectCreator(base) {
9
+ return (overrides) => merge(base(), overrides);
10
+ }
11
+ export function fakeFileName() {
12
+ return faker.string.alphanumeric() + "." + faker.string.alpha({ length: 3 });
13
+ }
14
+ export function fakeFile(root = process.cwd()) {
15
+ return resolve(root, fakeFileName());
16
+ }
17
+ export function fakeDir(root = process.cwd()) {
18
+ return resolve(root, faker.string.alphanumeric());
19
+ }
20
+ export const fakeEntrypoint = () => faker.helpers.arrayElement([
21
+ fakePopupEntrypoint,
22
+ fakeGenericEntrypoint,
23
+ fakeOptionsEntrypoint,
24
+ fakeBackgroundEntrypoint,
25
+ fakeContentScriptEntrypoint,
26
+ fakeUnlistedScriptEntrypoint
27
+ ])();
28
+ export const fakeContentScriptEntrypoint = fakeObjectCreator(() => ({
29
+ type: "content-script",
30
+ inputPath: fakeFile("src"),
31
+ name: faker.string.alpha(),
32
+ options: {
33
+ matches: [],
34
+ matchAboutBlank: faker.datatype.boolean(),
35
+ matchOriginAsFallback: faker.helpers.arrayElement([
36
+ true,
37
+ false,
38
+ void 0
39
+ ]),
40
+ runAt: faker.helpers.arrayElement([
41
+ "document_start",
42
+ "document_end",
43
+ "document_idle",
44
+ void 0
45
+ ])
46
+ },
47
+ outputDir: fakeDir(".output"),
48
+ skipped: faker.datatype.boolean()
49
+ }));
50
+ export const fakeBackgroundEntrypoint = fakeObjectCreator(
51
+ () => ({
52
+ type: "background",
53
+ inputPath: "entrypoints/background.ts",
54
+ name: "background",
55
+ options: {
56
+ persistent: faker.datatype.boolean(),
57
+ type: faker.helpers.maybe(() => "module")
58
+ },
59
+ outputDir: fakeDir(".output"),
60
+ skipped: faker.datatype.boolean()
61
+ })
62
+ );
63
+ export const fakeUnlistedScriptEntrypoint = fakeObjectCreator(() => ({
64
+ type: "unlisted-script",
65
+ inputPath: fakeFile("src"),
66
+ name: faker.string.alpha(),
67
+ outputDir: fakeDir(".output"),
68
+ options: {},
69
+ skipped: faker.datatype.boolean()
70
+ }));
71
+ export const fakeOptionsEntrypoint = fakeObjectCreator(
72
+ () => ({
73
+ type: "options",
74
+ inputPath: "entrypoints/options.html",
75
+ name: "options",
76
+ outputDir: fakeDir(".output"),
77
+ options: {
78
+ browserStyle: faker.datatype.boolean(),
79
+ chromeStyle: faker.datatype.boolean(),
80
+ openInTab: faker.datatype.boolean()
81
+ },
82
+ skipped: faker.datatype.boolean()
83
+ })
84
+ );
85
+ export const fakePopupEntrypoint = fakeObjectCreator(() => ({
86
+ type: "popup",
87
+ inputPath: "entrypoints/popup.html",
88
+ name: "popup",
89
+ outputDir: fakeDir(".output"),
90
+ options: {
91
+ defaultTitle: faker.helpers.arrayElement([
92
+ faker.person.fullName(),
93
+ void 0
94
+ ]),
95
+ defaultIcon: faker.helpers.arrayElement([
96
+ {
97
+ "16": "icon/16.png",
98
+ "24": "icon/24.png",
99
+ "64": "icon/64.png"
100
+ }
101
+ ]),
102
+ mv2Key: faker.helpers.arrayElement([
103
+ "browser_action",
104
+ "page_action",
105
+ void 0
106
+ ])
107
+ },
108
+ skipped: faker.datatype.boolean()
109
+ }));
110
+ export const fakeSidepanelEntrypoint = fakeObjectCreator(
111
+ () => ({
112
+ type: "sidepanel",
113
+ inputPath: "entrypoints/sidepanel.html",
114
+ name: "sidepanel",
115
+ outputDir: fakeDir(".output"),
116
+ options: {
117
+ defaultTitle: faker.helpers.arrayElement([
118
+ faker.person.fullName(),
119
+ void 0
120
+ ]),
121
+ defaultIcon: faker.helpers.arrayElement([
122
+ {
123
+ "16": "icon/16.png",
124
+ "24": "icon/24.png",
125
+ "64": "icon/64.png"
126
+ }
127
+ ]),
128
+ openAtInstall: faker.helpers.arrayElement([true, false, void 0])
129
+ },
130
+ skipped: faker.datatype.boolean()
131
+ })
132
+ );
133
+ export const fakeGenericEntrypoint = fakeObjectCreator(
134
+ () => ({
135
+ type: faker.helpers.arrayElement([
136
+ "sandbox",
137
+ "bookmarks",
138
+ "history",
139
+ "newtab",
140
+ "devtools",
141
+ "unlisted-page",
142
+ "unlisted-script"
143
+ ]),
144
+ inputPath: fakeFile("src"),
145
+ name: faker.string.alpha(),
146
+ outputDir: fakeDir(".output"),
147
+ options: {},
148
+ skipped: faker.datatype.boolean()
149
+ })
150
+ );
151
+ export const fakeOutputChunk = fakeObjectCreator(() => ({
152
+ type: "chunk",
153
+ fileName: faker.string.alphanumeric(),
154
+ moduleIds: []
155
+ }));
156
+ export const fakeOutputAsset = fakeObjectCreator(() => ({
157
+ type: "asset",
158
+ fileName: fakeFileName()
159
+ }));
160
+ export function fakeOutputFile() {
161
+ return faker.helpers.arrayElement([fakeOutputAsset(), fakeOutputChunk()]);
162
+ }
163
+ export const fakeManifest = fakeObjectCreator(
164
+ () => ({
165
+ manifest_version: faker.helpers.arrayElement([2, 3]),
166
+ name: faker.string.alphanumeric(),
167
+ version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
168
+ })
169
+ );
170
+ export const fakeUserManifest = fakeObjectCreator(() => ({
171
+ name: faker.string.alphanumeric(),
172
+ version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
173
+ }));
174
+ export function fakeArray(createItem, count = 3) {
175
+ const array = [];
176
+ for (let i = 0; i < count; i++) {
177
+ array.push(createItem());
178
+ }
179
+ return array;
180
+ }
181
+ export const fakeResolvedConfig = fakeObjectCreator(() => {
182
+ const browser = faker.helpers.arrayElement(["chrome", "firefox"]);
183
+ const command = faker.helpers.arrayElement(["build", "serve"]);
184
+ const manifestVersion = faker.helpers.arrayElement([2, 3]);
185
+ const mode = faker.helpers.arrayElement(["development", "production"]);
186
+ return {
187
+ browser,
188
+ command,
189
+ entrypointsDir: fakeDir(),
190
+ modulesDir: fakeDir(),
191
+ builtinModules: [],
192
+ userModules: [],
193
+ env: { browser, command, manifestVersion, mode },
194
+ fsCache: mock(),
195
+ imports: {
196
+ eslintrc: {
197
+ enabled: faker.helpers.arrayElement([false, 8, 9]),
198
+ filePath: fakeFile(),
199
+ globalsPropValue: faker.helpers.arrayElement([
200
+ true,
201
+ false,
202
+ "readable",
203
+ "readonly",
204
+ "writable",
205
+ "writeable"
206
+ ])
207
+ }
208
+ },
209
+ logger: mock(),
210
+ manifest: fakeUserManifest(),
211
+ manifestVersion,
212
+ mode,
213
+ outBaseDir: fakeDir(),
214
+ outDir: fakeDir(),
215
+ publicDir: fakeDir(),
216
+ root: fakeDir(),
217
+ wxtModuleDir: fakeDir(),
218
+ runnerConfig: {
219
+ config: {}
220
+ },
221
+ debug: faker.datatype.boolean(),
222
+ srcDir: fakeDir(),
223
+ typesDir: fakeDir(),
224
+ wxtDir: fakeDir(),
225
+ analysis: {
226
+ enabled: false,
227
+ open: false,
228
+ template: "treemap",
229
+ outputFile: fakeFile(),
230
+ outputDir: fakeDir(),
231
+ outputName: "stats",
232
+ keepArtifacts: false
233
+ },
234
+ zip: {
235
+ artifactTemplate: "{{name}}-{{version}}.zip",
236
+ includeSources: [],
237
+ excludeSources: [],
238
+ sourcesRoot: fakeDir(),
239
+ sourcesTemplate: "{{name}}-sources.zip",
240
+ name: faker.person.firstName().toLowerCase(),
241
+ downloadedPackagesDir: fakeDir(),
242
+ downloadPackages: [],
243
+ compressionLevel: 9
244
+ },
245
+ transformManifest: () => {
246
+ },
247
+ userConfigMetadata: {},
248
+ alias: {},
249
+ extensionApi: "webextension-polyfill",
250
+ browserModule: "wxt/browser",
251
+ entrypointLoader: "vite-node",
252
+ experimental: {},
253
+ dev: {
254
+ reloadCommand: "Alt+R"
255
+ },
256
+ hooks: {},
257
+ vite: () => ({}),
258
+ plugins: []
259
+ };
260
+ });
261
+ export const fakeWxt = fakeObjectCreator(() => ({
262
+ config: fakeResolvedConfig(),
263
+ hooks: mock(),
264
+ logger: mock(),
265
+ reloadConfig: vi.fn(),
266
+ pm: mock(),
267
+ server: faker.helpers.arrayElement([void 0, fakeWxtDevServer()]),
268
+ builder: mock()
269
+ }));
270
+ export const fakeWxtDevServer = fakeObjectCreator(() => ({
271
+ currentOutput: fakeBuildOutput(),
272
+ hostname: "localhost",
273
+ origin: "http://localhost:3000",
274
+ port: 3e3,
275
+ reloadContentScript: vi.fn(),
276
+ reloadExtension: vi.fn(),
277
+ reloadPage: vi.fn(),
278
+ restart: vi.fn(),
279
+ restartBrowser: vi.fn(),
280
+ start: vi.fn(),
281
+ stop: vi.fn(),
282
+ transformHtml: vi.fn(),
283
+ watcher: mock(),
284
+ ws: mock()
285
+ }));
286
+ export function setFakeWxt(overrides) {
287
+ const wxt = fakeWxt(overrides);
288
+ setWxtForTesting(wxt);
289
+ return wxt;
290
+ }
291
+ export const fakeBuildOutput = fakeObjectCreator(() => ({
292
+ manifest: fakeManifest(),
293
+ publicAssets: fakeArray(fakeOutputAsset),
294
+ steps: fakeArray(fakeBuildStepOutput)
295
+ }));
296
+ export const fakeBuildStepOutput = fakeObjectCreator(() => ({
297
+ chunks: fakeArray(fakeOutputChunk),
298
+ entrypoints: fakeArray(fakeEntrypoint)
299
+ }));
300
+ export const fakeManifestCommand = fakeObjectCreator(() => ({
301
+ description: faker.string.sample(),
302
+ shortcut: `${faker.helpers.arrayElement(["ctrl", "alt"])}+${faker.number.int({
303
+ min: 0,
304
+ max: 9
305
+ })}`
306
+ }));
307
+ export const fakeDevServer = fakeObjectCreator(() => ({
308
+ hostname: "localhost",
309
+ origin: "http://localhost",
310
+ port: 5173,
311
+ reloadContentScript: vi.fn(),
312
+ reloadExtension: vi.fn(),
313
+ reloadPage: vi.fn(),
314
+ restart: vi.fn(),
315
+ restartBrowser: vi.fn(),
316
+ stop: vi.fn(),
317
+ start: vi.fn(),
318
+ watcher: mock(),
319
+ transformHtml: vi.fn(),
320
+ ws: mock(),
321
+ currentOutput: void 0
322
+ }));
@@ -0,0 +1,9 @@
1
+ export declare function formatDuration(duration: number): string;
2
+ /**
3
+ * Add a timeout to a promise.
4
+ */
5
+ export declare function withTimeout<T>(promise: Promise<T>, duration: number): Promise<T>;
6
+ /**
7
+ * @deprecated Don't use in production, just for testing and slowing things down.
8
+ */
9
+ export declare function sleep(ms: number): Promise<void>;
@@ -0,0 +1,17 @@
1
+ export function formatDuration(duration) {
2
+ if (duration < 1e3) return `${duration} ms`;
3
+ if (duration < 1e4) return `${(duration / 1e3).toFixed(3)} s`;
4
+ if (duration < 6e4) return `${(duration / 1e3).toFixed(1)} s`;
5
+ return `${(duration / 1e3).toFixed(0)} s`;
6
+ }
7
+ export function withTimeout(promise, duration) {
8
+ return new Promise((res, rej) => {
9
+ const timeout = setTimeout(() => {
10
+ rej(`Promise timed out after ${duration}ms`);
11
+ }, duration);
12
+ promise.then(res).catch(rej).finally(() => clearTimeout(timeout));
13
+ });
14
+ }
15
+ export function sleep(ms) {
16
+ return new Promise((res) => setTimeout(res, ms));
17
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Removes any code used at runtime related to an entrypoint's main function.
3
+ * - Removes or clears out `main` function from returned object
4
+ * - TODO: Removes unused imports after main function has been removed to prevent importing runtime modules
5
+ */
6
+ export declare function removeMainFunctionCode(code: string): {
7
+ code: string;
8
+ map?: string;
9
+ };
@@ -0,0 +1,17 @@
1
+ import { parseModule } from "magicast";
2
+ export function removeMainFunctionCode(code) {
3
+ const mod = parseModule(code);
4
+ emptyMainFunction(mod);
5
+ return mod.generate();
6
+ }
7
+ function emptyMainFunction(mod) {
8
+ if (mod.exports?.default?.$type === "function-call") {
9
+ if (mod.exports.default.$ast?.arguments?.[0]?.body) {
10
+ mod.exports.default.$ast.arguments[0].body.body = [];
11
+ } else if (mod.exports.default.$ast?.arguments?.[0]?.properties) {
12
+ mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter(
13
+ (prop) => prop.key.name !== "main"
14
+ );
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Remove optional from key, but keep undefined if present
3
+ *
4
+ * @example
5
+ * type Test = NullablyRequired<{a?: string, b: number}>
6
+ * // type Test = {a: string | undefined, b: number}
7
+ */
8
+ export type NullablyRequired<T> = {
9
+ [K in keyof Required<T>]: T[K];
10
+ };
File without changes
@@ -0,0 +1,15 @@
1
+ import { Entrypoint } from '../../types';
2
+ export declare function validateEntrypoints(entrypoints: Entrypoint[]): ValidationResults;
3
+ export interface ValidationResult {
4
+ type: 'warning' | 'error';
5
+ message: string;
6
+ entrypoint: Entrypoint;
7
+ value: any;
8
+ }
9
+ export interface ValidationResults {
10
+ errors: ValidationResult[];
11
+ errorCount: number;
12
+ warningCount: number;
13
+ }
14
+ export declare class ValidationError extends Error {
15
+ }
@@ -0,0 +1,55 @@
1
+ export function validateEntrypoints(entrypoints) {
2
+ const errors = entrypoints.flatMap((entrypoint) => {
3
+ switch (entrypoint.type) {
4
+ case "content-script":
5
+ return validateContentScriptEntrypoint(entrypoint);
6
+ default:
7
+ return validateBaseEntrypoint(entrypoint);
8
+ }
9
+ });
10
+ let errorCount = 0;
11
+ let warningCount = 0;
12
+ for (const err of errors) {
13
+ if (err.type === "warning") warningCount++;
14
+ else errorCount++;
15
+ }
16
+ return {
17
+ errors,
18
+ errorCount,
19
+ warningCount
20
+ };
21
+ }
22
+ function validateContentScriptEntrypoint(definition) {
23
+ const errors = validateBaseEntrypoint(definition);
24
+ if (definition.options.matches == null) {
25
+ errors.push({
26
+ type: "error",
27
+ message: "`matches` is required",
28
+ value: definition.options.matches,
29
+ entrypoint: definition
30
+ });
31
+ }
32
+ return errors;
33
+ }
34
+ function validateBaseEntrypoint(definition) {
35
+ const errors = [];
36
+ if (definition.options.exclude != null && !Array.isArray(definition.options.exclude)) {
37
+ errors.push({
38
+ type: "error",
39
+ message: "`exclude` must be an array of browser names",
40
+ value: definition.options.exclude,
41
+ entrypoint: definition
42
+ });
43
+ }
44
+ if (definition.options.include != null && !Array.isArray(definition.options.include)) {
45
+ errors.push({
46
+ type: "error",
47
+ message: "`include` must be an array of browser names",
48
+ value: definition.options.include,
49
+ entrypoint: definition
50
+ });
51
+ }
52
+ return errors;
53
+ }
54
+ export class ValidationError extends Error {
55
+ }
@@ -0,0 +1,22 @@
1
+ export declare const virtualEntrypointTypes: ("background" | "unlisted-script" | "content-script-main-world" | "content-script-isolated-world")[];
2
+ export type VirtualEntrypointType = (typeof virtualEntrypointTypes)[0];
3
+ /**
4
+ * All the names of entrypoint files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
5
+ */
6
+ export declare const virtualEntrypointModuleNames: ("background-entrypoint" | "unlisted-script-entrypoint" | "content-script-main-world-entrypoint" | "content-script-isolated-world-entrypoint")[];
7
+ /**
8
+ * Name of entrypoint files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
9
+ */
10
+ export type VirtualEntrypointModuleName = (typeof virtualEntrypointModuleNames)[0];
11
+ /**
12
+ * All the names of files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
13
+ */
14
+ export declare const virtualModuleNames: ("background-entrypoint" | "unlisted-script-entrypoint" | "content-script-main-world-entrypoint" | "content-script-isolated-world-entrypoint" | "mock-browser" | "reload-html")[];
15
+ /**
16
+ * Name of files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
17
+ */
18
+ export type VirtualModuleName = (typeof virtualModuleNames)[0];
19
+ /**
20
+ * Import alias used for importing a virtual module
21
+ */
22
+ export type VirtualModuleId = `virtual:wxt-${VirtualModuleName}`;
@@ -0,0 +1,14 @@
1
+ export const virtualEntrypointTypes = [
2
+ "content-script-main-world",
3
+ "content-script-isolated-world",
4
+ "background",
5
+ "unlisted-script"
6
+ ];
7
+ export const virtualEntrypointModuleNames = virtualEntrypointTypes.map(
8
+ (name) => `${name}-entrypoint`
9
+ );
10
+ export const virtualModuleNames = [
11
+ ...virtualEntrypointModuleNames,
12
+ "mock-browser",
13
+ "reload-html"
14
+ ];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns true when running on WSL or WSL2.
3
+ */
4
+ export declare function isWsl(): Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ export async function isWsl() {
2
+ const { default: isWsl2 } = await import("is-wsl");
3
+ return isWsl2;
4
+ }
@@ -0,0 +1,19 @@
1
+ import { InlineConfig, ResolvedConfig, Wxt, WxtCommand, WxtDevServer } from '../types';
2
+ /**
3
+ * Global variable set once `createWxt` is called once. Since this variable is used everywhere, this
4
+ * global can be used instead of passing the variable as a function parameter everywhere.
5
+ */
6
+ export declare let wxt: Wxt;
7
+ /**
8
+ * Create and register a global instance of the Wxt interface for use throughout the project.
9
+ */
10
+ export declare function registerWxt(command: WxtCommand, inlineConfig?: InlineConfig, getServer?: (config: ResolvedConfig) => Promise<WxtDevServer>): Promise<void>;
11
+ /**
12
+ * @internal ONLY USE FOR TESTING.
13
+ *
14
+ * @example
15
+ * setWxtForTesting(fakeWxt({ ... }));
16
+ * // Or use the shorthand
17
+ * setFakeWxt({ ... })
18
+ */
19
+ export declare function setWxtForTesting(testInstance: Wxt): void;
@@ -0,0 +1,41 @@
1
+ import { resolveConfig } from "./utils/building/index.mjs";
2
+ import { createHooks } from "hookable";
3
+ import { createWxtPackageManager } from "./package-managers/index.mjs";
4
+ import { createViteBuilder } from "./builders/vite/index.mjs";
5
+ import { builtinModules } from "../builtin-modules/index.mjs";
6
+ export let wxt;
7
+ export async function registerWxt(command, inlineConfig = {}, getServer) {
8
+ const hooks = createHooks();
9
+ const config = await resolveConfig(inlineConfig, command);
10
+ const server = await getServer?.(config);
11
+ const builder = await createViteBuilder(config, hooks, server);
12
+ const pm = await createWxtPackageManager(config.root);
13
+ wxt = {
14
+ config,
15
+ hooks,
16
+ get logger() {
17
+ return config.logger;
18
+ },
19
+ async reloadConfig() {
20
+ wxt.config = await resolveConfig(inlineConfig, command);
21
+ },
22
+ pm,
23
+ builder,
24
+ server
25
+ };
26
+ const initModule = async (module) => {
27
+ if (module.hooks) wxt.hooks.addHooks(module.hooks);
28
+ await module.setup?.(
29
+ wxt,
30
+ // @ts-expect-error: Untyped configKey field
31
+ module.configKey ? config[module.configKey] : void 0
32
+ );
33
+ };
34
+ for (const builtinModule of builtinModules) await initModule(builtinModule);
35
+ for (const userModule of config.userModules) await initModule(userModule);
36
+ wxt.hooks.addHooks(config.hooks);
37
+ await wxt.hooks.callHook("ready", wxt);
38
+ }
39
+ export function setWxtForTesting(testInstance) {
40
+ wxt = testInstance;
41
+ }
@@ -0,0 +1,7 @@
1
+ import { InlineConfig } from '../types';
2
+ /**
3
+ * Build and zip the extension for distribution.
4
+ * @param config Optional config that will override your `<root>/wxt.config.ts`.
5
+ * @returns A list of all files included in the ZIP.
6
+ */
7
+ export declare function zip(config?: InlineConfig): Promise<string[]>;