wxt 0.18.15 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/bin/wxt.mjs +1 -1
  2. package/dist/browser/chrome.d.ts +17 -0
  3. package/dist/browser/chrome.mjs +7 -0
  4. package/dist/browser/index.d.ts +18 -0
  5. package/dist/browser/index.mjs +2 -0
  6. package/dist/builtin-modules/index.d.ts +2 -0
  7. package/dist/builtin-modules/index.mjs +2 -0
  8. package/dist/builtin-modules/unimport.d.ts +8 -0
  9. package/dist/builtin-modules/unimport.mjs +99 -0
  10. package/dist/cli/cli-utils.d.ts +25 -0
  11. package/dist/cli/cli-utils.mjs +58 -0
  12. package/dist/cli/commands.d.ts +2 -0
  13. package/dist/cli/commands.mjs +104 -0
  14. package/dist/cli/index.d.ts +1 -0
  15. package/dist/cli/index.mjs +11 -0
  16. package/dist/client/app-config.d.ts +2 -0
  17. package/dist/client/app-config.mjs +4 -0
  18. package/dist/client/content-scripts/content-script-context.d.ts +114 -0
  19. package/dist/client/content-scripts/content-script-context.mjs +169 -0
  20. package/dist/client/content-scripts/custom-events.d.ts +10 -0
  21. package/dist/client/content-scripts/custom-events.mjs +13 -0
  22. package/dist/client/content-scripts/index.d.ts +2 -0
  23. package/dist/client/content-scripts/index.mjs +2 -0
  24. package/dist/client/content-scripts/location-watcher.d.ts +12 -0
  25. package/dist/client/content-scripts/location-watcher.mjs +22 -0
  26. package/dist/client/content-scripts/ui/index.d.ts +23 -0
  27. package/dist/client/content-scripts/ui/index.mjs +188 -0
  28. package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
  29. package/dist/client/content-scripts/ui/types.mjs +0 -0
  30. package/dist/client/index.d.ts +7 -0
  31. package/dist/client/index.mjs +2 -0
  32. package/dist/core/build.d.ts +15 -0
  33. package/dist/core/build.mjs +6 -0
  34. package/dist/core/builders/vite/index.d.ts +3 -0
  35. package/dist/core/builders/vite/index.mjs +285 -0
  36. package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
  37. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
  38. package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
  39. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
  40. package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
  41. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
  42. package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
  43. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
  44. package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
  45. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
  46. package/dist/core/builders/vite/plugins/download.d.ts +10 -0
  47. package/dist/core/builders/vite/plugins/download.mjs +14 -0
  48. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
  49. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
  50. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
  51. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
  52. package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
  53. package/dist/core/builders/vite/plugins/globals.mjs +15 -0
  54. package/dist/core/builders/vite/plugins/index.d.ts +17 -0
  55. package/dist/core/builders/vite/plugins/index.mjs +17 -0
  56. package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
  57. package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
  58. package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
  59. package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
  60. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
  61. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
  62. package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
  63. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
  64. package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
  65. package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
  66. package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
  67. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
  68. package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
  69. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
  70. package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
  71. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
  72. package/dist/core/clean.d.ts +21 -0
  73. package/dist/core/clean.mjs +38 -0
  74. package/dist/core/create-server.d.ts +11 -0
  75. package/dist/core/create-server.mjs +206 -0
  76. package/dist/core/define-config.d.ts +2 -0
  77. package/dist/core/define-config.mjs +3 -0
  78. package/dist/core/define-runner-config.d.ts +2 -0
  79. package/dist/core/define-runner-config.mjs +3 -0
  80. package/dist/core/index.d.ts +8 -0
  81. package/dist/core/index.mjs +8 -0
  82. package/dist/core/initialize.d.ts +5 -0
  83. package/dist/core/initialize.mjs +128 -0
  84. package/dist/core/package-managers/bun.d.ts +2 -0
  85. package/dist/core/package-managers/bun.mjs +19 -0
  86. package/dist/core/package-managers/index.d.ts +2 -0
  87. package/dist/core/package-managers/index.mjs +65 -0
  88. package/dist/core/package-managers/npm.d.ts +17 -0
  89. package/dist/core/package-managers/npm.mjs +58 -0
  90. package/dist/core/package-managers/pnpm.d.ts +2 -0
  91. package/dist/core/package-managers/pnpm.mjs +21 -0
  92. package/dist/core/package-managers/types.d.ts +2 -0
  93. package/dist/core/package-managers/types.mjs +0 -0
  94. package/dist/core/package-managers/yarn.d.ts +2 -0
  95. package/dist/core/package-managers/yarn.mjs +31 -0
  96. package/dist/core/prepare.d.ts +2 -0
  97. package/dist/core/prepare.mjs +8 -0
  98. package/dist/core/runners/index.d.ts +2 -0
  99. package/dist/core/runners/index.mjs +12 -0
  100. package/dist/core/runners/manual.d.ts +5 -0
  101. package/dist/core/runners/manual.mjs +16 -0
  102. package/dist/core/runners/safari.d.ts +5 -0
  103. package/dist/core/runners/safari.mjs +16 -0
  104. package/dist/core/runners/web-ext.d.ts +5 -0
  105. package/dist/core/runners/web-ext.mjs +78 -0
  106. package/dist/core/runners/wsl.d.ts +5 -0
  107. package/dist/core/runners/wsl.mjs +16 -0
  108. package/dist/core/utils/arrays.d.ts +13 -0
  109. package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
  110. package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
  111. package/dist/core/utils/building/build-entrypoints.mjs +47 -0
  112. package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
  113. package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
  114. package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
  115. package/dist/core/utils/building/find-entrypoints.mjs +385 -0
  116. package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
  117. package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
  118. package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
  119. package/dist/core/utils/building/group-entrypoints.mjs +37 -0
  120. package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
  121. package/dist/core/utils/building/import-entrypoint.mjs +97 -0
  122. package/dist/core/utils/building/index.d.ts +9 -0
  123. package/dist/core/utils/building/index.mjs +9 -0
  124. package/dist/core/utils/building/internal-build.d.ts +12 -0
  125. package/dist/core/utils/building/internal-build.mjs +112 -0
  126. package/dist/core/utils/building/rebuild.d.ts +23 -0
  127. package/dist/core/utils/building/rebuild.mjs +39 -0
  128. package/dist/core/utils/building/resolve-config.d.ts +11 -0
  129. package/dist/core/utils/building/resolve-config.mjs +364 -0
  130. package/dist/core/utils/cache.d.ts +8 -0
  131. package/dist/core/utils/cache.mjs +21 -0
  132. package/dist/core/utils/cli.d.ts +3 -0
  133. package/dist/core/utils/cli.mjs +26 -0
  134. package/dist/core/utils/constants.d.ts +5 -0
  135. package/dist/core/utils/constants.mjs +1 -0
  136. package/dist/core/utils/content-scripts.d.ts +11 -0
  137. package/dist/core/utils/content-scripts.mjs +60 -0
  138. package/dist/core/utils/content-security-policy.d.ts +14 -0
  139. package/dist/core/utils/content-security-policy.mjs +39 -0
  140. package/dist/core/utils/entrypoints.d.ts +25 -0
  141. package/dist/core/utils/entrypoints.mjs +31 -0
  142. package/dist/core/utils/eslint.d.ts +1 -0
  143. package/dist/core/utils/eslint.mjs +11 -0
  144. package/dist/core/utils/fs.d.ts +13 -0
  145. package/dist/core/utils/fs.mjs +15 -0
  146. package/dist/core/utils/globals.d.ts +11 -0
  147. package/dist/core/utils/globals.mjs +53 -0
  148. package/dist/core/utils/i18n.d.ts +11 -0
  149. package/dist/core/utils/i18n.mjs +35 -0
  150. package/dist/core/utils/log/index.d.ts +4 -0
  151. package/dist/core/utils/log/index.mjs +4 -0
  152. package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
  153. package/dist/core/utils/log/printBuildSummary.mjs +32 -0
  154. package/dist/core/utils/log/printFileList.d.ts +1 -0
  155. package/dist/core/utils/log/printFileList.mjs +42 -0
  156. package/dist/core/utils/log/printHeader.d.ts +1 -0
  157. package/dist/core/utils/log/printHeader.mjs +7 -0
  158. package/dist/core/utils/log/printTable.d.ts +1 -0
  159. package/dist/core/utils/log/printTable.mjs +22 -0
  160. package/dist/core/utils/manifest.d.ts +44 -0
  161. package/dist/core/utils/manifest.mjs +512 -0
  162. package/dist/core/utils/network.d.ts +7 -0
  163. package/dist/core/utils/network.mjs +38 -0
  164. package/dist/core/utils/package.d.ts +6 -0
  165. package/dist/core/utils/package.mjs +14 -0
  166. package/dist/core/utils/paths.d.ts +11 -0
  167. package/dist/core/utils/paths.mjs +10 -0
  168. package/dist/core/utils/strings.d.ts +14 -0
  169. package/dist/core/utils/strings.mjs +18 -0
  170. package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
  171. package/dist/core/utils/testing/fake-objects.mjs +322 -0
  172. package/dist/core/utils/time.d.ts +9 -0
  173. package/dist/core/utils/time.mjs +17 -0
  174. package/dist/core/utils/transform.d.ts +9 -0
  175. package/dist/core/utils/transform.mjs +17 -0
  176. package/dist/core/utils/types.d.ts +10 -0
  177. package/dist/core/utils/types.mjs +0 -0
  178. package/dist/core/utils/validation.d.ts +15 -0
  179. package/dist/core/utils/validation.mjs +55 -0
  180. package/dist/core/utils/virtual-modules.d.ts +22 -0
  181. package/dist/core/utils/virtual-modules.mjs +14 -0
  182. package/dist/core/utils/wsl.d.ts +4 -0
  183. package/dist/core/utils/wsl.mjs +4 -0
  184. package/dist/core/wxt.d.ts +19 -0
  185. package/dist/core/wxt.mjs +41 -0
  186. package/dist/core/zip.d.ts +7 -0
  187. package/dist/core/zip.mjs +137 -0
  188. package/dist/index.d.ts +4 -79
  189. package/dist/index.mjs +3 -0
  190. package/dist/modules.d.ts +10 -20
  191. package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
  192. package/dist/sandbox/define-app-config.d.ts +19 -0
  193. package/dist/sandbox/define-app-config.mjs +3 -0
  194. package/dist/sandbox/define-background.d.ts +3 -0
  195. package/dist/sandbox/define-background.mjs +4 -0
  196. package/dist/sandbox/define-content-script.d.ts +2 -0
  197. package/dist/sandbox/define-content-script.mjs +3 -0
  198. package/dist/sandbox/define-unlisted-script.d.ts +3 -0
  199. package/dist/sandbox/define-unlisted-script.mjs +4 -0
  200. package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
  201. package/dist/sandbox/define-wxt-plugin.mjs +3 -0
  202. package/dist/sandbox/dev-server-websocket.d.ts +21 -0
  203. package/dist/sandbox/dev-server-websocket.mjs +37 -0
  204. package/dist/sandbox/index.d.ts +11 -0
  205. package/dist/sandbox/index.mjs +6 -0
  206. package/dist/sandbox/utils/logger.d.ts +9 -0
  207. package/dist/sandbox/utils/logger.mjs +15 -0
  208. package/dist/storage.d.ts +39 -16
  209. package/dist/{storage.js → storage.mjs} +30 -41
  210. package/dist/testing/fake-browser.d.ts +1 -0
  211. package/dist/testing/fake-browser.mjs +1 -0
  212. package/dist/testing/index.d.ts +5 -0
  213. package/dist/testing/index.mjs +2 -0
  214. package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
  215. package/dist/testing/wxt-vitest-plugin.mjs +26 -0
  216. package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
  217. package/dist/types.mjs +0 -0
  218. package/dist/version.d.ts +1 -0
  219. package/dist/version.mjs +1 -0
  220. package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
  221. package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
  222. package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
  223. package/dist/virtual/mock-browser.mjs +6 -0
  224. package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
  225. package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
  226. package/package.json +47 -57
  227. package/dist/browser.d.ts +0 -18
  228. package/dist/browser.js +0 -6
  229. package/dist/chunk-BM6QYGAW.js +0 -1063
  230. package/dist/chunk-FNTE2L27.js +0 -7
  231. package/dist/chunk-FP7RYLVL.js +0 -3617
  232. package/dist/chunk-KPD5J7PZ.js +0 -1065
  233. package/dist/chunk-QGM4M3NI.js +0 -37
  234. package/dist/chunk-SGKCDMVR.js +0 -38
  235. package/dist/cli.d.ts +0 -2
  236. package/dist/cli.js +0 -4438
  237. package/dist/client.js +0 -424
  238. package/dist/define-app-config-bg54F_lV.d.ts +0 -294
  239. package/dist/execa-4UBDUBJZ.js +0 -7244
  240. package/dist/execa-QLUM2B3W.js +0 -7245
  241. package/dist/index-nWRfwAJi.d.ts +0 -1401
  242. package/dist/index.cjs +0 -14473
  243. package/dist/index.d.cts +0 -81
  244. package/dist/index.js +0 -696
  245. package/dist/modules.cjs +0 -96
  246. package/dist/modules.d.cts +0 -119
  247. package/dist/modules.js +0 -17
  248. package/dist/prompt-25QIVJDC.js +0 -755
  249. package/dist/prompt-7BMKNSWS.js +0 -754
  250. package/dist/sandbox.d.ts +0 -16
  251. package/dist/sandbox.js +0 -36
  252. package/dist/storage.cjs +0 -439
  253. package/dist/storage.d.cts +0 -200
  254. package/dist/testing.cjs +0 -2815
  255. package/dist/testing.d.cts +0 -30
  256. package/dist/testing.js +0 -40
  257. package/dist/virtual/mock-browser.js +0 -6
package/dist/sandbox.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { U as UnlistedScriptDefinition, B as BackgroundDefinition, C as ContentScriptDefinition, W as WxtPlugin } from './define-app-config-bg54F_lV.js';
2
- export { a as WxtAppConfig, d as defineAppConfig } from './define-app-config-bg54F_lV.js';
3
- export * from '@webext-core/match-patterns';
4
- import 'webextension-polyfill';
5
-
6
- declare function defineUnlistedScript(main: () => void): UnlistedScriptDefinition;
7
- declare function defineUnlistedScript(definition: UnlistedScriptDefinition): UnlistedScriptDefinition;
8
-
9
- declare function defineBackground(main: () => void): BackgroundDefinition;
10
- declare function defineBackground(definition: BackgroundDefinition): BackgroundDefinition;
11
-
12
- declare function defineContentScript(definition: ContentScriptDefinition): ContentScriptDefinition;
13
-
14
- declare function defineWxtPlugin(plugin: WxtPlugin): WxtPlugin;
15
-
16
- export { defineBackground, defineContentScript, defineUnlistedScript, defineWxtPlugin };
package/dist/sandbox.js DELETED
@@ -1,36 +0,0 @@
1
- // src/sandbox/define-unlisted-script.ts
2
- function defineUnlistedScript(arg) {
3
- if (typeof arg === "function") return { main: arg };
4
- return arg;
5
- }
6
-
7
- // src/sandbox/define-background.ts
8
- function defineBackground(arg) {
9
- if (typeof arg === "function") return { main: arg };
10
- return arg;
11
- }
12
-
13
- // src/sandbox/define-content-script.ts
14
- function defineContentScript(definition) {
15
- return definition;
16
- }
17
-
18
- // src/sandbox/define-wxt-plugin.ts
19
- function defineWxtPlugin(plugin) {
20
- return plugin;
21
- }
22
-
23
- // src/sandbox/define-app-config.ts
24
- function defineAppConfig(config) {
25
- return config;
26
- }
27
-
28
- // src/sandbox/index.ts
29
- export * from "@webext-core/match-patterns";
30
- export {
31
- defineAppConfig,
32
- defineBackground,
33
- defineContentScript,
34
- defineUnlistedScript,
35
- defineWxtPlugin
36
- };
package/dist/storage.cjs DELETED
@@ -1,439 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/storage.ts
31
- var storage_exports = {};
32
- __export(storage_exports, {
33
- storage: () => storage
34
- });
35
- module.exports = __toCommonJS(storage_exports);
36
-
37
- // src/browser.ts
38
- var import_webextension_polyfill = __toESM(require("webextension-polyfill"), 1);
39
- var browser = import_webextension_polyfill.default;
40
-
41
- // src/storage.ts
42
- var import_lite = require("dequal/lite");
43
-
44
- // src/sandbox/utils/logger.ts
45
- var import_meta = {};
46
- function print(method, ...args) {
47
- if (import_meta.env.MODE === "production") return;
48
- if (typeof args[0] === "string") {
49
- const message = args.shift();
50
- method(`[wxt] ${message}`, ...args);
51
- } else {
52
- method("[wxt]", ...args);
53
- }
54
- }
55
- var logger = {
56
- debug: (...args) => print(console.debug, ...args),
57
- log: (...args) => print(console.log, ...args),
58
- warn: (...args) => print(console.warn, ...args),
59
- error: (...args) => print(console.error, ...args)
60
- };
61
-
62
- // src/core/utils/arrays.ts
63
- function toArray(a) {
64
- return Array.isArray(a) ? a : [a];
65
- }
66
-
67
- // src/storage.ts
68
- var storage = createStorage();
69
- function createStorage() {
70
- const drivers = {
71
- local: createDriver("local"),
72
- session: createDriver("session"),
73
- sync: createDriver("sync"),
74
- managed: createDriver("managed")
75
- };
76
- const getDriver = (area) => {
77
- const driver = drivers[area];
78
- if (driver == null) {
79
- const areaNames = Object.keys(drivers).join(", ");
80
- throw Error(`Invalid area "${area}". Options: ${areaNames}`);
81
- }
82
- return driver;
83
- };
84
- const resolveKey = (key) => {
85
- const deliminatorIndex = key.indexOf(":");
86
- const driverArea = key.substring(0, deliminatorIndex);
87
- const driverKey = key.substring(deliminatorIndex + 1);
88
- if (driverKey == null)
89
- throw Error(
90
- `Storage key should be in the form of "area:key", but received "${key}"`
91
- );
92
- return {
93
- driverArea,
94
- driverKey,
95
- driver: getDriver(driverArea)
96
- };
97
- };
98
- const getMetaKey = (key) => key + "$";
99
- const getValueOrDefault = (value, defaultValue) => value ?? defaultValue ?? null;
100
- const getMetaValue = (properties) => typeof properties === "object" && !Array.isArray(properties) ? properties : {};
101
- const getItem = async (driver, driverKey, opts) => {
102
- const res = await driver.getItem(driverKey);
103
- return getValueOrDefault(res, opts?.defaultValue);
104
- };
105
- const getMeta = async (driver, driverKey) => {
106
- const metaKey = getMetaKey(driverKey);
107
- const res = await driver.getItem(metaKey);
108
- return getMetaValue(res);
109
- };
110
- const setItem = async (driver, driverKey, value) => {
111
- await driver.setItem(driverKey, value ?? null);
112
- };
113
- const setMeta = async (driver, driverKey, properties) => {
114
- const metaKey = getMetaKey(driverKey);
115
- const existingFields = getMetaValue(await driver.getItem(metaKey));
116
- const newFields = { ...existingFields };
117
- Object.entries(properties).forEach(([key, value]) => {
118
- if (value == null) {
119
- delete newFields[key];
120
- } else {
121
- newFields[key] = value;
122
- }
123
- });
124
- await driver.setItem(metaKey, newFields);
125
- };
126
- const removeItem = async (driver, driverKey, opts) => {
127
- await driver.removeItem(driverKey);
128
- if (opts?.removeMeta) {
129
- const metaKey = getMetaKey(driverKey);
130
- await driver.removeItem(metaKey);
131
- }
132
- };
133
- const removeMeta = async (driver, driverKey, properties) => {
134
- const metaKey = getMetaKey(driverKey);
135
- if (properties == null) {
136
- await driver.removeItem(metaKey);
137
- } else {
138
- const newFields = getMetaValue(await driver.getItem(metaKey));
139
- toArray(properties).forEach((field) => delete newFields[field]);
140
- await driver.setItem(metaKey, newFields);
141
- }
142
- };
143
- const watch = (driver, driverKey, cb) => {
144
- return driver.watch(driverKey, cb);
145
- };
146
- const storage2 = {
147
- getItem: async (key, opts) => {
148
- const { driver, driverKey } = resolveKey(key);
149
- return await getItem(driver, driverKey, opts);
150
- },
151
- getItems: async (keys) => {
152
- const areaToKeyMap = /* @__PURE__ */ new Map();
153
- const keyToOptsMap = /* @__PURE__ */ new Map();
154
- keys.forEach((key) => {
155
- let keyStr;
156
- let opts;
157
- if (typeof key === "string") {
158
- keyStr = key;
159
- } else {
160
- keyStr = key.key;
161
- opts = key.options;
162
- }
163
- const { driverArea, driverKey } = resolveKey(keyStr);
164
- const keys2 = areaToKeyMap.get(driverArea) ?? [];
165
- areaToKeyMap.set(driverArea, keys2.concat(driverKey));
166
- keyToOptsMap.set(keyStr, opts);
167
- });
168
- const results = await Promise.all(
169
- Array.from(areaToKeyMap.entries()).map(async ([driverArea, keys2]) => {
170
- const driverResults = await drivers[driverArea].getItems(keys2);
171
- return driverResults.map((driverResult) => {
172
- const key = `${driverArea}:${driverResult.key}`;
173
- const value = getValueOrDefault(
174
- driverResult.value,
175
- keyToOptsMap.get(key)?.defaultValue
176
- );
177
- return { key, value };
178
- });
179
- })
180
- );
181
- return results.flat();
182
- },
183
- getMeta: async (key) => {
184
- const { driver, driverKey } = resolveKey(key);
185
- return await getMeta(driver, driverKey);
186
- },
187
- setItem: async (key, value) => {
188
- const { driver, driverKey } = resolveKey(key);
189
- await setItem(driver, driverKey, value);
190
- },
191
- setItems: async (values) => {
192
- const areaToKeyValueMap = /* @__PURE__ */ new Map();
193
- values.forEach(({ key, value }) => {
194
- const { driverArea, driverKey } = resolveKey(key);
195
- const values2 = areaToKeyValueMap.get(driverArea) ?? [];
196
- areaToKeyValueMap.set(
197
- driverArea,
198
- values2.concat({ key: driverKey, value })
199
- );
200
- });
201
- await Promise.all(
202
- Array.from(areaToKeyValueMap.entries()).map(
203
- async ([driverArea, values2]) => {
204
- const driver = getDriver(driverArea);
205
- await driver.setItems(values2);
206
- }
207
- )
208
- );
209
- },
210
- setMeta: async (key, properties) => {
211
- const { driver, driverKey } = resolveKey(key);
212
- await setMeta(driver, driverKey, properties);
213
- },
214
- removeItem: async (key, opts) => {
215
- const { driver, driverKey } = resolveKey(key);
216
- await removeItem(driver, driverKey, opts);
217
- },
218
- removeItems: async (keys) => {
219
- const areaToKeysMap = /* @__PURE__ */ new Map();
220
- keys.forEach((key) => {
221
- let keyStr;
222
- let opts;
223
- if (typeof key === "string") {
224
- keyStr = key;
225
- } else {
226
- keyStr = key.key;
227
- opts = key.options;
228
- }
229
- const { driverArea, driverKey } = resolveKey(keyStr);
230
- const areaKeys = areaToKeysMap.get(driverArea) ?? [];
231
- areaKeys.push(driverKey);
232
- if (opts?.removeMeta) {
233
- areaKeys.push(getMetaKey(driverKey));
234
- }
235
- areaToKeysMap.set(driverArea, areaKeys);
236
- });
237
- await Promise.all(
238
- Array.from(areaToKeysMap.entries()).map(async ([driverArea, keys2]) => {
239
- const driver = getDriver(driverArea);
240
- await driver.removeItems(keys2);
241
- })
242
- );
243
- },
244
- removeMeta: async (key, properties) => {
245
- const { driver, driverKey } = resolveKey(key);
246
- await removeMeta(driver, driverKey, properties);
247
- },
248
- snapshot: async (base, opts) => {
249
- const driver = getDriver(base);
250
- const data = await driver.snapshot();
251
- opts?.excludeKeys?.forEach((key) => {
252
- delete data[key];
253
- delete data[getMetaKey(key)];
254
- });
255
- return data;
256
- },
257
- restoreSnapshot: async (base, data) => {
258
- const driver = getDriver(base);
259
- await driver.restoreSnapshot(data);
260
- },
261
- watch: (key, cb) => {
262
- const { driver, driverKey } = resolveKey(key);
263
- return watch(driver, driverKey, cb);
264
- },
265
- unwatch() {
266
- Object.values(drivers).forEach((driver) => {
267
- driver.unwatch();
268
- });
269
- },
270
- defineItem: (key, opts) => {
271
- const { driver, driverKey } = resolveKey(key);
272
- const { version: targetVersion = 1, migrations = {} } = opts ?? {};
273
- if (targetVersion < 1) {
274
- throw Error(
275
- "Storage item version cannot be less than 1. Initial versions should be set to 1, not 0."
276
- );
277
- }
278
- const migrate = async () => {
279
- const driverMetaKey = getMetaKey(driverKey);
280
- const [{ value }, { value: meta }] = await driver.getItems([
281
- driverKey,
282
- driverMetaKey
283
- ]);
284
- if (value == null) return;
285
- const currentVersion = meta?.v ?? 1;
286
- if (currentVersion > targetVersion) {
287
- throw Error(
288
- `Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`
289
- );
290
- }
291
- logger.debug(
292
- `Running storage migration for ${key}: v${currentVersion} -> v${targetVersion}`
293
- );
294
- const migrationsToRun = Array.from(
295
- { length: targetVersion - currentVersion },
296
- (_, i) => currentVersion + i + 1
297
- );
298
- let migratedValue = value;
299
- for (const migrateToVersion of migrationsToRun) {
300
- migratedValue = await migrations?.[migrateToVersion]?.(migratedValue) ?? migratedValue;
301
- }
302
- await driver.setItems([
303
- { key: driverKey, value: migratedValue },
304
- { key: driverMetaKey, value: { ...meta, v: targetVersion } }
305
- ]);
306
- logger.debug(
307
- `Storage migration completed for ${key} v${targetVersion}`,
308
- { migratedValue }
309
- );
310
- };
311
- const migrationsDone = opts?.migrations == null ? Promise.resolve() : migrate().catch((err) => {
312
- logger.error(`Migration failed for ${key}`, err);
313
- });
314
- const getDefaultValue = () => opts?.defaultValue ?? null;
315
- return {
316
- get defaultValue() {
317
- return getDefaultValue();
318
- },
319
- getValue: async () => {
320
- await migrationsDone;
321
- return await getItem(driver, driverKey, opts);
322
- },
323
- getMeta: async () => {
324
- await migrationsDone;
325
- return await getMeta(driver, driverKey);
326
- },
327
- setValue: async (value) => {
328
- await migrationsDone;
329
- return await setItem(driver, driverKey, value);
330
- },
331
- setMeta: async (properties) => {
332
- await migrationsDone;
333
- return await setMeta(driver, driverKey, properties);
334
- },
335
- removeValue: async (opts2) => {
336
- await migrationsDone;
337
- return await removeItem(driver, driverKey, opts2);
338
- },
339
- removeMeta: async (properties) => {
340
- await migrationsDone;
341
- return await removeMeta(driver, driverKey, properties);
342
- },
343
- watch: (cb) => watch(
344
- driver,
345
- driverKey,
346
- (newValue, oldValue) => cb(newValue ?? getDefaultValue(), oldValue ?? getDefaultValue())
347
- ),
348
- migrate
349
- };
350
- }
351
- };
352
- return storage2;
353
- }
354
- function createDriver(storageArea) {
355
- const getStorageArea = () => {
356
- if (browser.runtime == null) {
357
- throw Error(
358
- [
359
- "'wxt/storage' must be loaded in a web extension environment",
360
- "\n - If thrown during a build, see https://github.com/wxt-dev/wxt/issues/371",
361
- " - If thrown during tests, mock 'wxt/browser' correctly. See https://wxt.dev/guide/go-further/testing.html\n"
362
- ].join("\n")
363
- );
364
- }
365
- if (browser.storage == null) {
366
- throw Error(
367
- "You must add the 'storage' permission to your manifest to use 'wxt/storage'"
368
- );
369
- }
370
- const area = browser.storage[storageArea];
371
- if (area == null)
372
- throw Error(`"browser.storage.${storageArea}" is undefined`);
373
- return area;
374
- };
375
- const watchListeners = /* @__PURE__ */ new Set();
376
- return {
377
- getItem: async (key) => {
378
- const res = await getStorageArea().get(key);
379
- return res[key];
380
- },
381
- getItems: async (keys) => {
382
- const result = await getStorageArea().get(keys);
383
- return keys.map((key) => ({ key, value: result[key] ?? null }));
384
- },
385
- setItem: async (key, value) => {
386
- if (value == null) {
387
- await getStorageArea().remove(key);
388
- } else {
389
- await getStorageArea().set({ [key]: value });
390
- }
391
- },
392
- setItems: async (values) => {
393
- const map = values.reduce(
394
- (map2, { key, value }) => {
395
- map2[key] = value;
396
- return map2;
397
- },
398
- {}
399
- );
400
- await getStorageArea().set(map);
401
- },
402
- removeItem: async (key) => {
403
- await getStorageArea().remove(key);
404
- },
405
- removeItems: async (keys) => {
406
- await getStorageArea().remove(keys);
407
- },
408
- snapshot: async () => {
409
- return await getStorageArea().get();
410
- },
411
- restoreSnapshot: async (data) => {
412
- await getStorageArea().set(data);
413
- },
414
- watch(key, cb) {
415
- const listener = (changes) => {
416
- const change = changes[key];
417
- if (change == null) return;
418
- if ((0, import_lite.dequal)(change.newValue, change.oldValue)) return;
419
- cb(change.newValue ?? null, change.oldValue ?? null);
420
- };
421
- getStorageArea().onChanged.addListener(listener);
422
- watchListeners.add(listener);
423
- return () => {
424
- getStorageArea().onChanged.removeListener(listener);
425
- watchListeners.delete(listener);
426
- };
427
- },
428
- unwatch() {
429
- watchListeners.forEach((listener) => {
430
- getStorageArea().onChanged.removeListener(listener);
431
- });
432
- watchListeners.clear();
433
- }
434
- };
435
- }
436
- // Annotate the CommonJS export names for ESM import in node:
437
- 0 && (module.exports = {
438
- storage
439
- });
@@ -1,200 +0,0 @@
1
- declare const storage: WxtStorage;
2
- interface WxtStorage {
3
- /**
4
- * Get an item from storage, or return `null` if it doesn't exist.
5
- *
6
- * @example
7
- * await storage.getItem<number>("local:installDate");
8
- */
9
- getItem<T>(key: StorageItemKey, opts?: GetItemOptions<T>): Promise<T | null>;
10
- /**
11
- * Get multiple items from storage. The return order is guaranteed to be the same as the order
12
- * requested.
13
- *
14
- * @example
15
- * await storage.getItems(["local:installDate", "session:someCounter"]);
16
- */
17
- getItems(keys: Array<StorageItemKey | {
18
- key: StorageItemKey;
19
- options?: GetItemOptions<any>;
20
- }>): Promise<Array<{
21
- key: StorageItemKey;
22
- value: any;
23
- }>>;
24
- /**
25
- * Return an object containing metadata about the key. Object is stored at `key + "$"`. If value
26
- * is not an object, it returns an empty object.
27
- *
28
- * @example
29
- * await storage.getMeta("local:installDate");
30
- */
31
- getMeta<T extends Record<string, unknown>>(key: StorageItemKey): Promise<T>;
32
- /**
33
- * Set a value in storage. Setting a value to `null` or `undefined` is equivalent to calling
34
- * `removeItem`.
35
- *
36
- * @example
37
- * await storage.setItem<number>("local:installDate", Date.now());
38
- */
39
- setItem<T>(key: StorageItemKey, value: T | null): Promise<void>;
40
- /**
41
- * Set multiple values in storage. If a value is set to `null` or `undefined`, the key is removed.
42
- *
43
- * @example
44
- * await storage.setItem([
45
- * { key: "local:installDate", value: Date.now() },
46
- * { key: "session:someCounter, value: 5 },
47
- * ]);
48
- */
49
- setItems(values: Array<{
50
- key: StorageItemKey;
51
- value: any;
52
- }>): Promise<void>;
53
- /**
54
- * Sets metadata properties. If some properties are already set, but are not included in the
55
- * `properties` parameter, they will not be removed.
56
- *
57
- * @example
58
- * await storage.setMeta("local:installDate", { appVersion });
59
- */
60
- setMeta<T extends Record<string, unknown>>(key: StorageItemKey, properties: T | null): Promise<void>;
61
- /**
62
- * Removes an item from storage.
63
- *
64
- * @example
65
- * await storage.removeItem("local:installDate");
66
- */
67
- removeItem(key: StorageItemKey, opts?: RemoveItemOptions): Promise<void>;
68
- /**
69
- * Remove a list of keys from storage.
70
- */
71
- removeItems(keys: Array<StorageItemKey | {
72
- key: StorageItemKey;
73
- options?: RemoveItemOptions;
74
- }>): Promise<void>;
75
- /**
76
- * Remove the entire metadata for a key, or specific properties by name.
77
- *
78
- * @example
79
- * // Remove all metadata properties from the item
80
- * await storage.removeMeta("local:installDate");
81
- *
82
- * // Remove only specific the "v" field
83
- * await storage.removeMeta("local:installDate", "v")
84
- */
85
- removeMeta(key: StorageItemKey, properties?: string | string[]): Promise<void>;
86
- /**
87
- * Return all the items in storage.
88
- */
89
- snapshot(base: StorageArea, opts?: SnapshotOptions): Promise<Record<string, unknown>>;
90
- /**
91
- * Restores the results of `snapshot`. If new properties have been saved since the snapshot, they are
92
- * not overridden. Only values existing in the snapshot are overridden.
93
- */
94
- restoreSnapshot(base: StorageArea, data: any): Promise<void>;
95
- /**
96
- * Watch for changes to a specific key in storage.
97
- */
98
- watch<T>(key: StorageItemKey, cb: WatchCallback<T | null>): Unwatch;
99
- /**
100
- * Remove all watch listeners.
101
- */
102
- unwatch(): void;
103
- /**
104
- * Define a storage item with a default value, type, or versioning.
105
- *
106
- * Read full docs: https://wxt.dev/guide/extension-apis/storage.html#defining-storage-items
107
- */
108
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey): WxtStorageItem<TValue | null, TMetadata>;
109
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
110
- }
111
- interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
112
- defaultValue: TValue;
113
- /**
114
- * Get the latest value from storage.
115
- */
116
- getValue(): Promise<TValue>;
117
- /**
118
- * Get metadata.
119
- */
120
- getMeta(): Promise<NullablePartial<TMetadata>>;
121
- /**
122
- * Set the value in storage.
123
- */
124
- setValue(value: TValue): Promise<void>;
125
- /**
126
- * Set metadata properties.
127
- */
128
- setMeta(properties: NullablePartial<TMetadata>): Promise<void>;
129
- /**
130
- * Remove the value from storage.
131
- */
132
- removeValue(opts?: RemoveItemOptions): Promise<void>;
133
- /**
134
- * Remove all metadata or certain properties from metadata.
135
- */
136
- removeMeta(properties?: string[]): Promise<void>;
137
- /**
138
- * Listen for changes to the value in storage.
139
- */
140
- watch(cb: WatchCallback<TValue>): Unwatch;
141
- /**
142
- * If there are migrations defined on the storage item, migrate to the latest version.
143
- *
144
- * **This function is ran automatically whenever the extension updates**, so you don't have to call it
145
- * manually.
146
- */
147
- migrate(): Promise<void>;
148
- }
149
- type StorageArea = 'local' | 'session' | 'sync' | 'managed';
150
- type StorageItemKey = `${StorageArea}:${string}`;
151
- interface GetItemOptions<T> {
152
- /**
153
- * Value returned from `getValue` when it would otherwise return null.
154
- */
155
- defaultValue?: T;
156
- }
157
- interface RemoveItemOptions {
158
- /**
159
- * Optionally remove metadata when deleting a key.
160
- *
161
- * @default false
162
- */
163
- removeMeta?: boolean;
164
- }
165
- interface SnapshotOptions {
166
- /**
167
- * Exclude a list of keys. The storage area prefix should be removed since the snapshot is for a
168
- * specific storage area already.
169
- */
170
- excludeKeys?: string[];
171
- }
172
- interface WxtStorageItemOptions<T> {
173
- defaultValue: T;
174
- /**
175
- * Provide a version number for the storage item to enable migrations. When changing the version
176
- * in the future, migration functions will be ran on application startup.
177
- */
178
- version?: number;
179
- /**
180
- * A map of version numbers to the functions used to migrate the data to that version.
181
- */
182
- migrations?: Record<number, (oldValue: any) => any>;
183
- }
184
- /**
185
- * Same as `Partial`, but includes `| null`. It makes all the properties of an object optional and
186
- * nullable.
187
- */
188
- type NullablePartial<T> = {
189
- [key in keyof T]+?: T[key] | undefined | null;
190
- };
191
- /**
192
- * Callback called when a value in storage is changed.
193
- */
194
- type WatchCallback<T> = (newValue: T, oldValue: T) => void;
195
- /**
196
- * Call to remove a watch listener
197
- */
198
- type Unwatch = () => void;
199
-
200
- export { type GetItemOptions, type NullablePartial, type RemoveItemOptions, type SnapshotOptions, type StorageArea, type StorageItemKey, type Unwatch, type WatchCallback, type WxtStorage, type WxtStorageItem, type WxtStorageItemOptions, storage };