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,5 @@
1
+ export declare function initialize(options: {
2
+ directory: string;
3
+ template: string;
4
+ packageManager: string;
5
+ }): Promise<void>;
@@ -0,0 +1,128 @@
1
+ import prompts from "prompts";
2
+ import { consola } from "consola";
3
+ import { downloadTemplate } from "giget";
4
+ import fs from "fs-extra";
5
+ import path from "node:path";
6
+ import pc from "picocolors";
7
+ export async function initialize(options) {
8
+ consola.info("Initalizing 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
+ {
39
+ title: `${pc.magenta("bun")}${pc.gray(" (experimental)")}`,
40
+ value: "bun"
41
+ }
42
+ ]
43
+ }
44
+ ],
45
+ {
46
+ onCancel: () => process.exit(1)
47
+ }
48
+ );
49
+ input.directory ??= options.directory;
50
+ input.template ??= defaultTemplate;
51
+ input.packageManager ??= options.packageManager;
52
+ const isExists = await fs.pathExists(input.directory);
53
+ if (isExists) {
54
+ const isEmpty = (await fs.readdir(input.directory)).length === 0;
55
+ if (!isEmpty) {
56
+ consola.error(
57
+ `The directory ${path.resolve(input.directory)} is not empty. Aborted.`
58
+ );
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.log(
66
+ `\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
67
+ );
68
+ console.log();
69
+ consola.log("Next steps:");
70
+ let step = 0;
71
+ if (cdPath !== "") consola.log(` ${++step}.`, pc.cyan(`cd ${cdPath}`));
72
+ consola.log(` ${++step}.`, pc.cyan(`${input.packageManager} install`));
73
+ console.log();
74
+ }
75
+ async function listTemplates() {
76
+ try {
77
+ const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
78
+ if (res.status >= 300)
79
+ throw Error(`Request failed with status ${res.status} ${res.statusText}`);
80
+ const data = await res.json();
81
+ return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` })).sort((l, r) => {
82
+ const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
83
+ const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
84
+ const diff = lWeight - rWeight;
85
+ if (diff !== 0) return diff;
86
+ return l.name.localeCompare(r.name);
87
+ });
88
+ } catch (err) {
89
+ consola.error(err);
90
+ throw Error(`Failed to load templates`);
91
+ }
92
+ }
93
+ async function cloneProject({
94
+ directory,
95
+ template,
96
+ packageManager
97
+ }) {
98
+ const { default: ora } = await import("ora");
99
+ const spinner = ora("Downloading template").start();
100
+ try {
101
+ await downloadTemplate(`gh:wxt-dev/wxt/${template.path}`, {
102
+ dir: directory,
103
+ force: true
104
+ });
105
+ await fs.move(
106
+ path.join(directory, "_gitignore"),
107
+ path.join(directory, ".gitignore")
108
+ ).catch(
109
+ (err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
110
+ );
111
+ spinner.succeed();
112
+ } catch (err) {
113
+ spinner.fail();
114
+ throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
115
+ }
116
+ }
117
+ const TEMPLATE_COLORS = {
118
+ vanilla: pc.blue,
119
+ vue: pc.green,
120
+ react: pc.cyan,
121
+ svelte: pc.red,
122
+ solid: pc.blue
123
+ };
124
+ const TEMPLATE_SORT_WEIGHT = {
125
+ vanilla: 0,
126
+ vue: 1,
127
+ react: 2
128
+ };
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManagerImpl } from './types';
2
+ export declare const bun: WxtPackageManagerImpl;
@@ -0,0 +1,19 @@
1
+ import { dedupeDependencies, npm } from "./npm.mjs";
2
+ export const bun = {
3
+ overridesKey: "overrides",
4
+ // But also supports "resolutions"
5
+ downloadDependency(...args) {
6
+ return npm.downloadDependency(...args);
7
+ },
8
+ async listDependencies(options) {
9
+ const args = ["pm", "ls"];
10
+ if (options?.all) {
11
+ args.push("--all");
12
+ }
13
+ const { execa } = await import("execa");
14
+ const res = await execa("bun", args, { cwd: options?.cwd });
15
+ return dedupeDependencies(
16
+ res.stdout.split("\n").slice(1).map((line) => line.trim()).map((line) => /.* (@?\S+)@(\S+)$/.exec(line)).filter((match) => !!match).map(([_, name, version]) => ({ name, version }))
17
+ );
18
+ }
19
+ };
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManager } from '../../types';
2
+ export declare function createWxtPackageManager(root: string): Promise<WxtPackageManager>;
@@ -0,0 +1,65 @@
1
+ import {
2
+ detectPackageManager,
3
+ addDependency,
4
+ addDevDependency,
5
+ ensureDependencyInstalled,
6
+ installDependencies,
7
+ removeDependency
8
+ } from "nypm";
9
+ import { bun } from "./bun.mjs";
10
+ import { yarn } from "./yarn.mjs";
11
+ import { pnpm } from "./pnpm.mjs";
12
+ import { npm } from "./npm.mjs";
13
+ export async function createWxtPackageManager(root) {
14
+ const pm = await detectPackageManager(root, {
15
+ includeParentDirs: true
16
+ });
17
+ const requirePm = (cb) => {
18
+ if (pm == null) throw Error("Could not detect package manager");
19
+ return cb(pm);
20
+ };
21
+ return {
22
+ get name() {
23
+ return requirePm((pm2) => pm2.name);
24
+ },
25
+ get command() {
26
+ return requirePm((pm2) => pm2.command);
27
+ },
28
+ get version() {
29
+ return requirePm((pm2) => pm2.version);
30
+ },
31
+ get majorVersion() {
32
+ return requirePm((pm2) => pm2.majorVersion);
33
+ },
34
+ get lockFile() {
35
+ return requirePm((pm2) => pm2.lockFile);
36
+ },
37
+ get files() {
38
+ return requirePm((pm2) => pm2.files);
39
+ },
40
+ addDependency,
41
+ addDevDependency,
42
+ ensureDependencyInstalled,
43
+ installDependencies,
44
+ removeDependency,
45
+ get overridesKey() {
46
+ return requirePm((pm2) => packageManagers[pm2.name].overridesKey);
47
+ },
48
+ downloadDependency(...args) {
49
+ return requirePm(
50
+ (pm2) => packageManagers[pm2.name].downloadDependency(...args)
51
+ );
52
+ },
53
+ listDependencies(...args) {
54
+ return requirePm(
55
+ (pm2) => packageManagers[pm2.name].listDependencies(...args)
56
+ );
57
+ }
58
+ };
59
+ }
60
+ const packageManagers = {
61
+ npm,
62
+ pnpm,
63
+ bun,
64
+ yarn
65
+ };
@@ -0,0 +1,17 @@
1
+ import { Dependency } from '../../types';
2
+ import { WxtPackageManagerImpl } from './types';
3
+ export declare const npm: WxtPackageManagerImpl;
4
+ export declare function flattenNpmListOutput(projects: NpmListProject[]): Dependency[];
5
+ export declare function dedupeDependencies(dependencies: Dependency[]): Dependency[];
6
+ export interface NpmListProject {
7
+ name: string;
8
+ dependencies?: Record<string, NpmListDependency>;
9
+ devDependencies?: Record<string, NpmListDependency>;
10
+ }
11
+ export interface NpmListDependency {
12
+ version: string;
13
+ resolved?: string;
14
+ overridden?: boolean;
15
+ dependencies?: Record<string, NpmListDependency>;
16
+ devDependencies?: Record<string, NpmListDependency>;
17
+ }
@@ -0,0 +1,58 @@
1
+ import path from "node:path";
2
+ import { ensureDir } from "fs-extra";
3
+ export const npm = {
4
+ overridesKey: "overrides",
5
+ async downloadDependency(id, downloadDir) {
6
+ await ensureDir(downloadDir);
7
+ const { execa } = await import("execa");
8
+ const res = await execa("npm", ["pack", id, "--json"], {
9
+ cwd: downloadDir
10
+ });
11
+ const packed = JSON.parse(res.stdout);
12
+ return path.resolve(downloadDir, packed[0].filename);
13
+ },
14
+ async listDependencies(options) {
15
+ const args = ["ls", "--json"];
16
+ if (options?.all) {
17
+ args.push("--depth", "Infinity");
18
+ }
19
+ const { execa } = await import("execa");
20
+ const res = await execa("npm", args, { cwd: options?.cwd });
21
+ const project = JSON.parse(res.stdout);
22
+ return flattenNpmListOutput([project]);
23
+ }
24
+ };
25
+ export function flattenNpmListOutput(projects) {
26
+ const queue = projects.flatMap(
27
+ (project) => {
28
+ const acc = [];
29
+ if (project.dependencies) acc.push(project.dependencies);
30
+ if (project.devDependencies) acc.push(project.devDependencies);
31
+ return acc;
32
+ }
33
+ );
34
+ const dependencies = [];
35
+ while (queue.length > 0) {
36
+ Object.entries(queue.pop()).forEach(([name, meta]) => {
37
+ dependencies.push({
38
+ name,
39
+ version: meta.version
40
+ });
41
+ if (meta.dependencies) queue.push(meta.dependencies);
42
+ if (meta.devDependencies) queue.push(meta.devDependencies);
43
+ });
44
+ }
45
+ return dedupeDependencies(dependencies);
46
+ }
47
+ export function dedupeDependencies(dependencies) {
48
+ const hashes = /* @__PURE__ */ new Set();
49
+ return dependencies.filter((dep) => {
50
+ const hash = `${dep.name}@${dep.version}`;
51
+ if (hashes.has(hash)) {
52
+ return false;
53
+ } else {
54
+ hashes.add(hash);
55
+ return true;
56
+ }
57
+ });
58
+ }
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManagerImpl } from './types';
2
+ export declare const pnpm: WxtPackageManagerImpl;
@@ -0,0 +1,21 @@
1
+ import { flattenNpmListOutput, npm } from "./npm.mjs";
2
+ export const pnpm = {
3
+ overridesKey: "resolutions",
4
+ // "pnpm.overrides" has a higher priority, but I don't want to deal with nesting
5
+ downloadDependency(...args) {
6
+ return npm.downloadDependency(...args);
7
+ },
8
+ async listDependencies(options) {
9
+ const args = ["ls", "-r", "--json"];
10
+ if (options?.all) {
11
+ args.push("--depth", "Infinity");
12
+ }
13
+ if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
14
+ args.push("--ignore-workspace");
15
+ }
16
+ const { execa } = await import("execa");
17
+ const res = await execa("pnpm", args, { cwd: options?.cwd });
18
+ const projects = JSON.parse(res.stdout);
19
+ return flattenNpmListOutput(projects);
20
+ }
21
+ };
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManager } from '../../types';
2
+ export type WxtPackageManagerImpl = Pick<WxtPackageManager, 'downloadDependency' | 'listDependencies' | 'overridesKey'>;
File without changes
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManagerImpl } from './types';
2
+ export declare const yarn: WxtPackageManagerImpl;
@@ -0,0 +1,31 @@
1
+ import { dedupeDependencies, npm } from "./npm.mjs";
2
+ export const yarn = {
3
+ overridesKey: "resolutions",
4
+ downloadDependency(...args) {
5
+ return npm.downloadDependency(...args);
6
+ },
7
+ async listDependencies(options) {
8
+ const args = ["list", "--json"];
9
+ if (options?.all) {
10
+ args.push("--depth", "Infinity");
11
+ }
12
+ const { execa } = await import("execa");
13
+ const res = await execa("yarn", args, { cwd: options?.cwd });
14
+ const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
15
+ if (tree == null) throw Error("'yarn list --json' did not output a tree");
16
+ const queue = [...tree.trees];
17
+ const dependencies = [];
18
+ while (queue.length > 0) {
19
+ const { name: treeName, children } = queue.pop();
20
+ const match = /(@?\S+)@(\S+)$/.exec(treeName);
21
+ if (match) {
22
+ const [_, name, version] = match;
23
+ dependencies.push({ name, version });
24
+ }
25
+ if (children != null) {
26
+ queue.push(...children);
27
+ }
28
+ }
29
+ return dedupeDependencies(dependencies);
30
+ }
31
+ };
@@ -0,0 +1,2 @@
1
+ import { InlineConfig } from '../types';
2
+ export declare function prepare(config: InlineConfig): Promise<void>;
@@ -0,0 +1,8 @@
1
+ import { findEntrypoints, generateTypesDir } from "./utils/building/index.mjs";
2
+ import { registerWxt, wxt } from "./wxt.mjs";
3
+ export async function prepare(config) {
4
+ await registerWxt("build", config);
5
+ wxt.logger.info("Generating types...");
6
+ const entrypoints = await findEntrypoints();
7
+ await generateTypesDir(entrypoints);
8
+ }
@@ -0,0 +1,2 @@
1
+ import { ExtensionRunner } from '../../types';
2
+ export declare function createExtensionRunner(): Promise<ExtensionRunner>;
@@ -0,0 +1,12 @@
1
+ import { createWslRunner } from "./wsl.mjs";
2
+ import { createWebExtRunner } from "./web-ext.mjs";
3
+ import { createSafariRunner } from "./safari.mjs";
4
+ import { createManualRunner } from "./manual.mjs";
5
+ import { isWsl } from "../utils/wsl.mjs";
6
+ import { wxt } from "../wxt.mjs";
7
+ export async function createExtensionRunner() {
8
+ if (wxt.config.browser === "safari") return createSafariRunner();
9
+ if (await isWsl()) return createWslRunner();
10
+ if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
11
+ return createWebExtRunner();
12
+ }
@@ -0,0 +1,5 @@
1
+ import { ExtensionRunner } from '../../types';
2
+ /**
3
+ * The manual runner tells the user to load the unpacked extension manually.
4
+ */
5
+ export declare function createManualRunner(): ExtensionRunner;
@@ -0,0 +1,16 @@
1
+ import { relative } from "node:path";
2
+ import { wxt } from "../wxt.mjs";
3
+ export function createManualRunner() {
4
+ return {
5
+ async openBrowser() {
6
+ wxt.logger.info(
7
+ `Load "${relative(
8
+ process.cwd(),
9
+ wxt.config.outDir
10
+ )}" as an unpacked extension manually`
11
+ );
12
+ },
13
+ async closeBrowser() {
14
+ }
15
+ };
16
+ }
@@ -0,0 +1,5 @@
1
+ import { ExtensionRunner } from '../../types';
2
+ /**
3
+ * The Safari runner just logs a warning message because `web-ext` doesn't work with Safari.
4
+ */
5
+ export declare function createSafariRunner(): ExtensionRunner;
@@ -0,0 +1,16 @@
1
+ import { relative } from "node:path";
2
+ import { wxt } from "../wxt.mjs";
3
+ export function createSafariRunner() {
4
+ return {
5
+ async openBrowser() {
6
+ wxt.logger.warn(
7
+ `Cannot Safari using web-ext. Load "${relative(
8
+ process.cwd(),
9
+ wxt.config.outDir
10
+ )}" as an unpacked extension manually`
11
+ );
12
+ },
13
+ async closeBrowser() {
14
+ }
15
+ };
16
+ }
@@ -0,0 +1,5 @@
1
+ import { ExtensionRunner } from '../../types';
2
+ /**
3
+ * Create an `ExtensionRunner` backed by `web-ext`.
4
+ */
5
+ export declare function createWebExtRunner(): ExtensionRunner;
@@ -0,0 +1,78 @@
1
+ import { formatDuration } from "../utils/time.mjs";
2
+ import defu from "defu";
3
+ import { wxt } from "../wxt.mjs";
4
+ export function createWebExtRunner() {
5
+ let runner;
6
+ return {
7
+ async openBrowser() {
8
+ const startTime = Date.now();
9
+ if (wxt.config.browser === "firefox" && wxt.config.manifestVersion === 3) {
10
+ throw Error(
11
+ "Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653"
12
+ );
13
+ }
14
+ const webExtLogger = await import("web-ext-run/util/logger");
15
+ webExtLogger.consoleStream.write = ({ level, msg, name }) => {
16
+ if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
17
+ if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
18
+ };
19
+ const wxtUserConfig = wxt.config.runnerConfig.config;
20
+ const userConfig = {
21
+ console: wxtUserConfig?.openConsole,
22
+ devtools: wxtUserConfig?.openDevtools,
23
+ startUrl: wxtUserConfig?.startUrls,
24
+ keepProfileChanges: wxtUserConfig?.keepProfileChanges,
25
+ ...wxt.config.browser === "firefox" ? {
26
+ firefox: wxtUserConfig?.binaries?.firefox,
27
+ firefoxProfile: wxtUserConfig?.firefoxProfile,
28
+ prefs: wxtUserConfig?.firefoxPrefs,
29
+ args: wxtUserConfig?.firefoxArgs
30
+ } : {
31
+ chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
32
+ chromiumProfile: wxtUserConfig?.chromiumProfile,
33
+ chromiumPref: defu(
34
+ wxtUserConfig?.chromiumPref,
35
+ DEFAULT_CHROMIUM_PREFS
36
+ ),
37
+ args: wxtUserConfig?.chromiumArgs
38
+ }
39
+ };
40
+ const finalConfig = {
41
+ ...userConfig,
42
+ target: wxt.config.browser === "firefox" ? "firefox-desktop" : "chromium",
43
+ sourceDir: wxt.config.outDir,
44
+ // Don't add a "Reload Manager" extension alongside dev extension, WXT
45
+ // already handles reloads intenrally.
46
+ noReloadManagerExtension: true,
47
+ // WXT handles reloads, so disable auto-reload behaviors in web-ext
48
+ noReload: true,
49
+ noInput: true
50
+ };
51
+ const options = {
52
+ // Don't call `process.exit(0)` after starting web-ext
53
+ shouldExitProgram: false
54
+ };
55
+ wxt.logger.debug("web-ext config:", finalConfig);
56
+ wxt.logger.debug("web-ext options:", options);
57
+ const webExt = await import("web-ext-run");
58
+ runner = await webExt.default.cmd.run(finalConfig, options);
59
+ const duration = Date.now() - startTime;
60
+ wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
61
+ },
62
+ async closeBrowser() {
63
+ return await runner?.exit();
64
+ }
65
+ };
66
+ }
67
+ const WARN_LOG_LEVEL = 40;
68
+ const ERROR_LOG_LEVEL = 50;
69
+ const DEFAULT_CHROMIUM_PREFS = {
70
+ devtools: {
71
+ synced_preferences_sync_disabled: {
72
+ // Remove content scripts from sourcemap debugger ignore list so stack traces
73
+ // and log locations show up properly, see:
74
+ // https://github.com/wxt-dev/wxt/issues/236#issuecomment-1915364520
75
+ skipContentScripts: false
76
+ }
77
+ }
78
+ };
@@ -0,0 +1,5 @@
1
+ import { ExtensionRunner } from '../../types';
2
+ /**
3
+ * The WSL runner just logs a warning message because `web-ext` doesn't work in WSL.
4
+ */
5
+ export declare function createWslRunner(): ExtensionRunner;
@@ -0,0 +1,16 @@
1
+ import { relative } from "node:path";
2
+ import { wxt } from "../wxt.mjs";
3
+ export function createWslRunner() {
4
+ return {
5
+ async openBrowser() {
6
+ wxt.logger.warn(
7
+ `Cannot open browser when using WSL. Load "${relative(
8
+ process.cwd(),
9
+ wxt.config.outDir
10
+ )}" as an unpacked extension manually`
11
+ );
12
+ },
13
+ async closeBrowser() {
14
+ }
15
+ };
16
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if `predicate` returns truthy for all elements of the array.
3
+ */
4
+ export declare function every<T>(array: T[], predicate: (item: T, index: number) => boolean): boolean;
5
+ /**
6
+ * Returns true when any of the predicates return true;
7
+ */
8
+ export declare function some<T>(array: T[], predicate: (item: T, index: number) => boolean): boolean;
9
+ /**
10
+ * Convert an item or array to an array.
11
+ */
12
+ export declare function toArray<T>(a: T | T[]): T[];
13
+ export declare function filterTruthy<T>(array: Array<T | undefined>): T[];
@@ -1,20 +1,16 @@
1
- // src/core/utils/arrays.ts
2
- function every(array, predicate) {
1
+ export function every(array, predicate) {
3
2
  for (let i = 0; i < array.length; i++)
4
3
  if (!predicate(array[i], i)) return false;
5
4
  return true;
6
5
  }
7
- function some(array, predicate) {
6
+ export function some(array, predicate) {
8
7
  for (let i = 0; i < array.length; i++)
9
8
  if (predicate(array[i], i)) return true;
10
9
  return false;
11
10
  }
12
- function toArray(a) {
11
+ export function toArray(a) {
13
12
  return Array.isArray(a) ? a : [a];
14
13
  }
15
-
16
- export {
17
- every,
18
- some,
19
- toArray
20
- };
14
+ export function filterTruthy(array) {
15
+ return array.filter((item) => !!item);
16
+ }
@@ -0,0 +1,3 @@
1
+ import { BuildOutput, EntrypointGroup } from '../../../types';
2
+ import type { Ora } from 'ora';
3
+ export declare function buildEntrypoints(groups: EntrypointGroup[], spinner: Ora): Promise<Omit<BuildOutput, 'manifest'>>;
@@ -0,0 +1,47 @@
1
+ import { getPublicFiles } from "../../utils/fs.mjs";
2
+ import fs from "fs-extra";
3
+ import { dirname, resolve } from "path";
4
+ import pc from "picocolors";
5
+ import { wxt } from "../../wxt.mjs";
6
+ import { toArray } from "../arrays.mjs";
7
+ export async function buildEntrypoints(groups, spinner) {
8
+ const steps = [];
9
+ for (let i = 0; i < groups.length; i++) {
10
+ const group = groups[i];
11
+ const groupNames = toArray(group).map((e) => e.name);
12
+ const groupNameColored = groupNames.join(pc.dim(", "));
13
+ spinner.text = pc.dim(`[${i + 1}/${groups.length}]`) + ` ${groupNameColored}`;
14
+ try {
15
+ steps.push(await wxt.builder.build(group));
16
+ } catch (err) {
17
+ spinner.stop().clear();
18
+ wxt.logger.error(err);
19
+ throw Error(`Failed to build ${groupNames.join(", ")}`, { cause: err });
20
+ }
21
+ }
22
+ const publicAssets = await copyPublicDirectory();
23
+ return { publicAssets, steps };
24
+ }
25
+ async function copyPublicDirectory() {
26
+ const files = (await getPublicFiles()).map((file) => ({
27
+ absoluteSrc: resolve(wxt.config.publicDir, file),
28
+ relativeDest: file
29
+ }));
30
+ await wxt.hooks.callHook("build:publicAssets", wxt, files);
31
+ if (files.length === 0) return [];
32
+ const publicAssets = [];
33
+ for (const file of files) {
34
+ const absoluteDest = resolve(wxt.config.outDir, file.relativeDest);
35
+ await fs.ensureDir(dirname(absoluteDest));
36
+ if ("absoluteSrc" in file) {
37
+ await fs.copyFile(file.absoluteSrc, absoluteDest);
38
+ } else {
39
+ await fs.writeFile(absoluteDest, file.contents, "utf8");
40
+ }
41
+ publicAssets.push({
42
+ type: "asset",
43
+ fileName: file.relativeDest
44
+ });
45
+ }
46
+ return publicAssets;
47
+ }