wxt 0.18.3 → 0.18.5

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.
package/dist/storage.d.ts CHANGED
@@ -6,7 +6,7 @@ interface WxtStorage {
6
6
  * @example
7
7
  * await storage.getItem<number>("local:installDate");
8
8
  */
9
- getItem<T>(key: string, opts?: GetItemOptions<T>): Promise<T | null>;
9
+ getItem<T>(key: StorageItemKey, opts?: GetItemOptions<T>): Promise<T | null>;
10
10
  /**
11
11
  * Get multiple items from storage. The return order is guaranteed to be the same as the order
12
12
  * requested.
@@ -14,11 +14,11 @@ interface WxtStorage {
14
14
  * @example
15
15
  * await storage.getItems(["local:installDate", "session:someCounter"]);
16
16
  */
17
- getItems(keys: Array<string | {
18
- key: string;
17
+ getItems(keys: Array<StorageItemKey | {
18
+ key: StorageItemKey;
19
19
  options?: GetItemOptions<any>;
20
20
  }>): Promise<Array<{
21
- key: string;
21
+ key: StorageItemKey;
22
22
  value: any;
23
23
  }>>;
24
24
  /**
@@ -28,7 +28,7 @@ interface WxtStorage {
28
28
  * @example
29
29
  * await storage.getMeta("local:installDate");
30
30
  */
31
- getMeta<T extends Record<string, unknown>>(key: string): Promise<T>;
31
+ getMeta<T extends Record<string, unknown>>(key: StorageItemKey): Promise<T>;
32
32
  /**
33
33
  * Set a value in storage. Setting a value to `null` or `undefined` is equivalent to calling
34
34
  * `removeItem`.
@@ -36,7 +36,7 @@ interface WxtStorage {
36
36
  * @example
37
37
  * await storage.setItem<number>("local:installDate", Date.now());
38
38
  */
39
- setItem<T>(key: string, value: T | null): Promise<void>;
39
+ setItem<T>(key: StorageItemKey, value: T | null): Promise<void>;
40
40
  /**
41
41
  * Set multiple values in storage. If a value is set to `null` or `undefined`, the key is removed.
42
42
  *
@@ -47,7 +47,7 @@ interface WxtStorage {
47
47
  * ]);
48
48
  */
49
49
  setItems(values: Array<{
50
- key: string;
50
+ key: StorageItemKey;
51
51
  value: any;
52
52
  }>): Promise<void>;
53
53
  /**
@@ -57,19 +57,19 @@ interface WxtStorage {
57
57
  * @example
58
58
  * await storage.setMeta("local:installDate", { appVersion });
59
59
  */
60
- setMeta<T extends Record<string, unknown>>(key: string, properties: T | null): Promise<void>;
60
+ setMeta<T extends Record<string, unknown>>(key: StorageItemKey, properties: T | null): Promise<void>;
61
61
  /**
62
62
  * Removes an item from storage.
63
63
  *
64
64
  * @example
65
65
  * await storage.removeItem("local:installDate");
66
66
  */
67
- removeItem(key: string, opts?: RemoveItemOptions): Promise<void>;
67
+ removeItem(key: StorageItemKey, opts?: RemoveItemOptions): Promise<void>;
68
68
  /**
69
69
  * Remove a list of keys from storage.
70
70
  */
71
- removeItems(keys: Array<string | {
72
- key: string;
71
+ removeItems(keys: Array<StorageItemKey | {
72
+ key: StorageItemKey;
73
73
  options?: RemoveItemOptions;
74
74
  }>): Promise<void>;
75
75
  /**
@@ -82,20 +82,20 @@ interface WxtStorage {
82
82
  * // Remove only specific the "v" field
83
83
  * await storage.removeMeta("local:installDate", "v")
84
84
  */
85
- removeMeta(key: string, properties?: string | string[]): Promise<void>;
85
+ removeMeta(key: StorageItemKey, properties?: string | string[]): Promise<void>;
86
86
  /**
87
87
  * Return all the items in storage.
88
88
  */
89
- snapshot(base: string, opts?: SnapshotOptions): Promise<Record<string, unknown>>;
89
+ snapshot(base: StorageArea, opts?: SnapshotOptions): Promise<Record<string, unknown>>;
90
90
  /**
91
91
  * Restores the results of `snapshot`. If new properties have been saved since the snapshot, they are
92
92
  * not overridden. Only values existing in the snapshot are overridden.
93
93
  */
94
- restoreSnapshot(base: string, data: any): Promise<void>;
94
+ restoreSnapshot(base: StorageArea, data: any): Promise<void>;
95
95
  /**
96
96
  * Watch for changes to a specific key in storage.
97
97
  */
98
- watch<T>(key: string, cb: WatchCallback<T | null>): Unwatch;
98
+ watch<T>(key: StorageItemKey, cb: WatchCallback<T | null>): Unwatch;
99
99
  /**
100
100
  * Remove all watch listeners.
101
101
  */
@@ -105,8 +105,8 @@ interface WxtStorage {
105
105
  *
106
106
  * Read full docs: https://wxt.dev/guide/storage.html#defining-storage-items
107
107
  */
108
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string): WxtStorageItem<TValue | null, TMetadata>;
109
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
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
110
  }
111
111
  interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
112
112
  defaultValue: TValue;
@@ -146,6 +146,8 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
146
146
  */
147
147
  migrate(): Promise<void>;
148
148
  }
149
+ type StorageArea = 'local' | 'session' | 'sync' | 'managed';
150
+ type StorageItemKey = `${StorageArea}:${string}`;
149
151
  interface GetItemOptions<T> {
150
152
  /**
151
153
  * Value returned from `getValue` when it would otherwise return null.
@@ -195,4 +197,4 @@ type WatchCallback<T> = (newValue: T, oldValue: T) => void;
195
197
  */
196
198
  type Unwatch = () => void;
197
199
 
198
- export { type GetItemOptions, type NullablePartial, type RemoveItemOptions, type SnapshotOptions, type Unwatch, type WatchCallback, type WxtStorage, type WxtStorageItem, type WxtStorageItemOptions, storage };
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 };
package/dist/testing.cjs CHANGED
@@ -2169,6 +2169,9 @@ var import_magicast = require("magicast");
2169
2169
  // src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
2170
2170
  var import_node_path7 = require("path");
2171
2171
 
2172
+ // src/core/builders/vite/plugins/wxtPluginLoader.ts
2173
+ var import_linkedom2 = require("linkedom");
2174
+
2172
2175
  // src/core/utils/fs.ts
2173
2176
  var import_fs_extra4 = __toESM(require("fs-extra"), 1);
2174
2177
  var import_fast_glob = __toESM(require("fast-glob"), 1);
@@ -2198,7 +2201,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
2198
2201
  // src/core/utils/building/find-entrypoints.ts
2199
2202
  var import_fs_extra7 = __toESM(require("fs-extra"), 1);
2200
2203
  var import_minimatch = require("minimatch");
2201
- var import_linkedom2 = require("linkedom");
2204
+ var import_linkedom3 = require("linkedom");
2202
2205
  var import_json5 = __toESM(require("json5"), 1);
2203
2206
  var import_fast_glob2 = __toESM(require("fast-glob"), 1);
2204
2207
  var import_picocolors2 = __toESM(require("picocolors"), 1);
@@ -2308,6 +2311,7 @@ function isModuleInstalled(name) {
2308
2311
 
2309
2312
  // src/core/utils/building/resolve-config.ts
2310
2313
  var import_fs_extra11 = __toESM(require("fs-extra"), 1);
2314
+ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
2311
2315
  var import_meta = {};
2312
2316
  async function resolveConfig(inlineConfig, command) {
2313
2317
  let userConfig = {};
@@ -2344,6 +2348,7 @@ async function resolveConfig(inlineConfig, command) {
2344
2348
  srcDir,
2345
2349
  mergedConfig.entrypointsDir ?? "entrypoints"
2346
2350
  );
2351
+ const modulesDir = import_node_path15.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
2347
2352
  if (await isDirMissing(entrypointsDir)) {
2348
2353
  logMissingDir(logger, "Entrypoints", entrypointsDir);
2349
2354
  }
@@ -2385,11 +2390,20 @@ async function resolveConfig(inlineConfig, command) {
2385
2390
  hostname: "localhost"
2386
2391
  };
2387
2392
  }
2393
+ const modules = await resolveWxtModules(modulesDir, mergedConfig.modules);
2394
+ const moduleOptions = modules.reduce((map, module2) => {
2395
+ if (module2.configKey) {
2396
+ map[module2.configKey] = // @ts-expect-error
2397
+ mergedConfig[module2.configKey];
2398
+ }
2399
+ return map;
2400
+ }, {});
2388
2401
  return {
2389
2402
  browser,
2390
2403
  command,
2391
2404
  debug,
2392
2405
  entrypointsDir,
2406
+ modulesDir,
2393
2407
  filterEntrypoints,
2394
2408
  env: env2,
2395
2409
  fsCache: createFsCache(wxtDir),
@@ -2421,7 +2435,10 @@ async function resolveConfig(inlineConfig, command) {
2421
2435
  reloadCommand
2422
2436
  },
2423
2437
  hooks: mergedConfig.hooks ?? {},
2424
- vite: mergedConfig.vite ?? (() => ({}))
2438
+ vite: mergedConfig.vite ?? (() => ({})),
2439
+ modules,
2440
+ plugins: [],
2441
+ ...moduleOptions
2425
2442
  };
2426
2443
  }
2427
2444
  async function resolveManifestConfig(env2, manifest) {
@@ -2560,6 +2577,43 @@ async function mergeBuilderConfig(inlineConfig, userConfig) {
2560
2577
  }
2561
2578
  throw Error("Builder not found. Make sure vite is installed.");
2562
2579
  }
2580
+ async function resolveWxtModules(modulesDir, modules = []) {
2581
+ const npmModules = await Promise.all(
2582
+ modules.map(async (moduleId) => {
2583
+ const mod = await import(
2584
+ /* @vite-ignore */
2585
+ moduleId
2586
+ );
2587
+ if (mod.default == null) {
2588
+ throw Error("Module missing default export: " + moduleId);
2589
+ }
2590
+ return mod.default;
2591
+ })
2592
+ );
2593
+ const localModulePaths = await (0, import_fast_glob3.default)(["*.[tj]s", "*/index.[tj]s"], {
2594
+ cwd: modulesDir,
2595
+ onlyFiles: true
2596
+ }).catch(() => []);
2597
+ const localModules = await Promise.all(
2598
+ localModulePaths.map(async (file) => {
2599
+ const { config } = await (0, import_c12.loadConfig)({
2600
+ configFile: import_node_path15.default.resolve(modulesDir, file),
2601
+ globalRc: false,
2602
+ rcFile: false,
2603
+ packageJson: false,
2604
+ envName: false,
2605
+ dotenv: false
2606
+ });
2607
+ if (config == null)
2608
+ throw Error(
2609
+ `No config found for ${file}. Did you forget to add a default export?`
2610
+ );
2611
+ config.name ??= file;
2612
+ return config;
2613
+ })
2614
+ );
2615
+ return [...npmModules, ...localModules];
2616
+ }
2563
2617
 
2564
2618
  // src/core/utils/building/internal-build.ts
2565
2619
  var import_picocolors5 = __toESM(require("picocolors"), 1);
@@ -2587,7 +2641,7 @@ var CHUNK_COLORS = {
2587
2641
  var import_picocolors4 = __toESM(require("picocolors"), 1);
2588
2642
 
2589
2643
  // src/core/utils/building/internal-build.ts
2590
- var import_fast_glob3 = __toESM(require("fast-glob"), 1);
2644
+ var import_fast_glob4 = __toESM(require("fast-glob"), 1);
2591
2645
 
2592
2646
  // src/core/utils/manifest.ts
2593
2647
  var import_fs_extra13 = __toESM(require("fs-extra"), 1);
@@ -1,6 +1,6 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './index-xOGXP3vY.cjs';
3
+ import { I as InlineConfig } from './index-q2ZwJBs6.cjs';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
package/dist/testing.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './index-xOGXP3vY.js';
3
+ import { I as InlineConfig } from './index-q2ZwJBs6.js';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
package/dist/testing.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  tsconfigPaths,
6
6
  unimport,
7
7
  webextensionPolyfillMock
8
- } from "./chunk-XAYX5BXI.js";
8
+ } from "./chunk-7AOGIMIM.js";
9
9
  import "./chunk-5X3S6AWF.js";
10
10
  import "./chunk-ZZCTFNQ5.js";
11
11
  import "./chunk-VBXJIVYU.js";
@@ -1,5 +1,6 @@
1
1
  // src/virtual/background-entrypoint.ts
2
2
  import definition from "virtual:user-background-entrypoint";
3
+ import { initPlugins } from "virtual:wxt-plugins";
3
4
 
4
5
  // src/sandbox/utils/logger.ts
5
6
  function print(method, ...args) {
@@ -156,6 +157,7 @@ if (import.meta.env.COMMAND === "serve") {
156
157
  }
157
158
  var result;
158
159
  try {
160
+ initPlugins();
159
161
  result = definition.main();
160
162
  if (result instanceof Promise) {
161
163
  console.warn(
@@ -21,8 +21,10 @@ var logger = {
21
21
 
22
22
  // src/virtual/content-script-isolated-world-entrypoint.ts
23
23
  import { ContentScriptContext } from "wxt/client";
24
+ import { initPlugins } from "virtual:wxt-plugins";
24
25
  var result = (async () => {
25
26
  try {
27
+ initPlugins();
26
28
  const { main, ...options } = definition;
27
29
  const ctx = new ContentScriptContext(import.meta.env.ENTRYPOINT, options);
28
30
  return await main(ctx);
@@ -20,8 +20,10 @@ var logger = {
20
20
  };
21
21
 
22
22
  // src/virtual/content-script-main-world-entrypoint.ts
23
+ import { initPlugins } from "virtual:wxt-plugins";
23
24
  var result = (async () => {
24
25
  try {
26
+ initPlugins();
25
27
  const { main } = definition;
26
28
  return await main();
27
29
  } catch (err) {
@@ -20,8 +20,10 @@ var logger = {
20
20
  };
21
21
 
22
22
  // src/virtual/unlisted-script-entrypoint.ts
23
+ import { initPlugins } from "virtual:wxt-plugins";
23
24
  var result = (async () => {
24
25
  try {
26
+ initPlugins();
25
27
  return await definition.main();
26
28
  } catch (err) {
27
29
  logger.error(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.18.3",
4
+ "version": "0.18.5",
5
5
  "description": "Next gen framework for developing web extensions",
6
6
  "repository": {
7
7
  "type": "git",
@@ -78,6 +78,16 @@
78
78
  },
79
79
  "./vite-builder-env": {
80
80
  "types": "./dist/vite-builder-env.d.ts"
81
+ },
82
+ "./modules": {
83
+ "import": {
84
+ "types": "./dist/modules.d.ts",
85
+ "default": "./dist/modules.js"
86
+ },
87
+ "require": {
88
+ "types": "./dist/modules.d.cts",
89
+ "default": "./dist/modules.cjs"
90
+ }
81
91
  }
82
92
  },
83
93
  "dependencies": {
@@ -104,12 +114,12 @@
104
114
  "jiti": "^1.21.0",
105
115
  "json5": "^2.2.3",
106
116
  "jszip": "^3.10.1",
107
- "linkedom": "^0.16.1",
117
+ "linkedom": "^0.18.2",
108
118
  "magicast": "^0.3.4",
109
119
  "minimatch": "^9.0.3",
110
120
  "natural-compare": "^1.4.0",
111
121
  "normalize-path": "^3.0.0",
112
- "nypm": "^0.3.6",
122
+ "nypm": "^0.3.8",
113
123
  "open": "^10.1.0",
114
124
  "ora": "^7.0.1",
115
125
  "picocolors": "^1.0.0",
@@ -129,21 +139,16 @@
129
139
  "@types/node": "^20.10.3",
130
140
  "@types/normalize-path": "^3.0.2",
131
141
  "@types/prompts": "^2.4.9",
132
- "execa": "^8.0.1",
142
+ "execa": "^9.1.0",
133
143
  "extract-zip": "^2.0.1",
134
144
  "happy-dom": "^13.3.8",
135
145
  "lodash.merge": "^4.6.2",
136
146
  "p-map": "^7.0.0",
137
147
  "publint": "^0.2.6",
138
148
  "tsup": "^8.0.1",
139
- "tsx": "^4.6.2",
149
+ "tsx": "^4.11.2",
140
150
  "typescript": "^5.3.2"
141
151
  },
142
- "changelog": {
143
- "excludeAuthors": [
144
- "aaronklinker1@gmail.com"
145
- ]
146
- },
147
152
  "scripts": {
148
153
  "wxt": "tsx src/cli/index.ts",
149
154
  "build": "tsx scripts/build.ts",