wxt 0.10.4 → 0.11.1

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.
@@ -1,10 +1,11 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './external-32209cff.js';
3
+ import { I as InlineConfig } from './external-irU6kFSB.cjs';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
+ import 'chokidar';
8
9
 
9
10
  /**
10
11
  * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
package/dist/testing.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './external-32209cff.js';
3
+ import { I as InlineConfig } from './external-irU6kFSB.js';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
+ import 'chokidar';
8
9
 
9
10
  /**
10
11
  * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
package/dist/testing.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  unimport,
7
7
  webextensionPolyfillAlias,
8
8
  webextensionPolyfillInlineDeps
9
- } from "./chunk-RSHXTUF4.js";
10
- import "./chunk-YUG22S6W.js";
9
+ } from "./chunk-65FJ5ESC.js";
10
+ import "./chunk-VBXJIVYU.js";
11
11
 
12
12
  // src/testing/fake-browser.ts
13
13
  import { fakeBrowser } from "@webext-core/fake-browser";
@@ -23,6 +23,44 @@ var logger = {
23
23
  import originalBrowser from "webextension-polyfill";
24
24
  var browser = originalBrowser;
25
25
 
26
+ // src/client/content-scripts/custom-events.ts
27
+ var WxtLocationChangeEvent = class _WxtLocationChangeEvent extends Event {
28
+ constructor(newUrl, oldUrl) {
29
+ super(_WxtLocationChangeEvent.EVENT_NAME, {});
30
+ this.newUrl = newUrl;
31
+ this.oldUrl = oldUrl;
32
+ }
33
+ static EVENT_NAME = getUniqueEventName("wxt:locationchange");
34
+ };
35
+ function getUniqueEventName(eventName) {
36
+ const entrypointName = typeof __ENTRYPOINT__ === "undefined" ? "build" : __ENTRYPOINT__;
37
+ return `${browser.runtime.id}:${entrypointName}:${eventName}`;
38
+ }
39
+
40
+ // src/client/content-scripts/location-watcher.ts
41
+ function createLocationWatcher(ctx) {
42
+ let interval;
43
+ let oldUrl;
44
+ return {
45
+ /**
46
+ * Ensure the location watcher is actively looking for URL changes. If it's already watching,
47
+ * this is a noop.
48
+ */
49
+ run() {
50
+ if (interval != null)
51
+ return;
52
+ oldUrl = new URL(location.href);
53
+ interval = ctx.setInterval(() => {
54
+ let newUrl = new URL(location.href);
55
+ if (newUrl.href !== oldUrl.href) {
56
+ window.dispatchEvent(new WxtLocationChangeEvent(newUrl, oldUrl));
57
+ oldUrl = newUrl;
58
+ }
59
+ }, 1e3);
60
+ }
61
+ };
62
+ }
63
+
26
64
  // src/client/content-scripts/content-script-context.ts
27
65
  var ContentScriptContext = class _ContentScriptContext {
28
66
  constructor(contentScriptName, options) {
@@ -39,6 +77,7 @@ var ContentScriptContext = class _ContentScriptContext {
39
77
  static SCRIPT_STARTED_MESSAGE_TYPE = "wxt:content-script-started";
40
78
  #isTopFrame = window.self === window.top;
41
79
  #abortController;
80
+ #locationWatcher = createLocationWatcher(this);
42
81
  get signal() {
43
82
  return this.#abortController.signal;
44
83
  }
@@ -135,18 +174,33 @@ var ContentScriptContext = class _ContentScriptContext {
135
174
  /**
136
175
  * Call `target.addEventListener` and remove the event listener when the context is invalidated.
137
176
  *
177
+ * Includes additional events useful for content scripts:
178
+ *
179
+ * - `"wxt:locationchange"` - Triggered when HTML5 history mode is used to change URL. Content
180
+ * scripts are not reloaded when navigating this way, so this can be used to reset the content
181
+ * script state on URL change, or run custom code.
182
+ *
138
183
  * @example
139
- * ctx.addEventListener(window, "mousemove", () => {
184
+ * ctx.addEventListener(document, "visibilitychange", () => {
140
185
  * // ...
141
186
  * });
142
- * ctx.addEventListener(document, "visibilitychange", () => {
187
+ * ctx.addEventListener(document, "wxt:locationchange", () => {
143
188
  * // ...
144
189
  * });
145
190
  */
146
191
  addEventListener(target, type, handler, options) {
147
- target.addEventListener?.(type, handler, options);
148
- this.onInvalidated(
149
- () => target.removeEventListener?.(type, handler, options)
192
+ if (type === "wxt:locationchange") {
193
+ if (this.isValid)
194
+ this.#locationWatcher.run();
195
+ }
196
+ target.addEventListener?.(
197
+ type.startsWith("wxt:") ? getUniqueEventName(type) : type,
198
+ // @ts-expect-error: Event don't match, but that's OK, EventTarget doesn't allow custom types in the callback
199
+ handler,
200
+ {
201
+ ...options,
202
+ signal: this.signal
203
+ }
150
204
  );
151
205
  }
152
206
  /**
@@ -6,30 +6,27 @@ import normalize from "normalize-path";
6
6
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
7
7
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
8
8
 
9
- // src/core/vite-plugins/devHtmlPrerender.ts
9
+ // src/core/builders/vite/plugins/devHtmlPrerender.ts
10
10
  import { parseHTML } from "linkedom";
11
11
 
12
- // src/core/vite-plugins/multipageMove.ts
12
+ // src/core/builders/vite/plugins/multipageMove.ts
13
13
  import fs, { ensureDir } from "fs-extra";
14
14
 
15
- // src/core/vite-plugins/unimport.ts
15
+ // src/core/builders/vite/plugins/unimport.ts
16
16
  import { createUnimport } from "unimport";
17
17
 
18
18
  // src/core/utils/unimport.ts
19
- import { mergeConfig } from "vite";
19
+ import { defu } from "defu";
20
20
 
21
- // src/core/vite-plugins/virtualEntrypoint.ts
21
+ // src/core/builders/vite/plugins/virtualEntrypoint.ts
22
22
  import fs2 from "fs-extra";
23
23
 
24
- // src/core/vite-plugins/noopBackground.ts
24
+ // src/core/utils/constants.ts
25
25
  var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
26
26
 
27
- // src/core/vite-plugins/bundleAnalysis.ts
27
+ // src/core/builders/vite/plugins/bundleAnalysis.ts
28
28
  import { visualizer } from "rollup-plugin-visualizer";
29
29
 
30
- // src/core/utils/building/build-entrypoints.ts
31
- import * as vite from "vite";
32
-
33
30
  // src/core/utils/fs.ts
34
31
  import fs3 from "fs-extra";
35
32
  import glob from "fast-glob";
@@ -92,14 +89,13 @@ import fs6 from "fs-extra";
92
89
 
93
90
  // src/core/utils/building/get-internal-config.ts
94
91
  import { loadConfig } from "c12";
95
- import * as vite2 from "vite";
96
92
 
97
93
  // src/core/utils/cache.ts
98
94
  import fs7, { ensureDir as ensureDir2 } from "fs-extra";
99
95
 
100
96
  // src/core/utils/building/get-internal-config.ts
101
97
  import consola, { LogLevels } from "consola";
102
- import defu from "defu";
98
+ import defu2 from "defu";
103
99
 
104
100
  // src/core/utils/building/import-entrypoint.ts
105
101
  import createJITI from "jiti";
@@ -109,7 +105,6 @@ import { transformSync } from "esbuild";
109
105
 
110
106
  // src/core/utils/building/internal-build.ts
111
107
  import pc4 from "picocolors";
112
- import * as vite3 from "vite";
113
108
  import fs12 from "fs-extra";
114
109
 
115
110
  // src/core/utils/log/printFileList.ts
@@ -144,7 +139,7 @@ import fs10 from "fs-extra";
144
139
 
145
140
  // src/core/utils/manifest.ts
146
141
  import { produce } from "immer";
147
- import defu2 from "defu";
142
+ import defu3 from "defu";
148
143
 
149
144
  // src/virtual/mock-browser.ts
150
145
  var mock_browser_default = fakeBrowser;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.10.4",
4
+ "version": "0.11.1",
5
5
  "description": "Next gen framework for developing web extensions",
6
6
  "engines": {
7
7
  "node": ">=18",
@@ -71,6 +71,7 @@
71
71
  "async-mutex": "^0.4.0",
72
72
  "c12": "^1.5.1",
73
73
  "cac": "^6.7.14",
74
+ "chokidar": "^3.5.3",
74
75
  "consola": "^3.2.3",
75
76
  "defu": "^6.1.3",
76
77
  "esbuild": "^0.19.5",
@@ -92,37 +93,37 @@
92
93
  "rollup-plugin-visualizer": "^5.9.2",
93
94
  "unimport": "^3.4.0",
94
95
  "unstorage": "^1.9.0",
95
- "vite": "^4.0.0 || ^5.0.0-0",
96
+ "vite": "^5.0.0",
96
97
  "web-ext-run": "^0.1.0",
97
98
  "webextension-polyfill": "^0.10.0",
98
99
  "zip-dir": "^2.0.0"
99
100
  },
100
101
  "devDependencies": {
101
- "@faker-js/faker": "^8.2.0",
102
- "@types/fs-extra": "^11.0.3",
103
- "@types/lodash.merge": "^4.6.8",
104
- "@types/node": "^20.8.10",
102
+ "@faker-js/faker": "^8.3.1",
103
+ "@types/fs-extra": "^11.0.4",
104
+ "@types/lodash.merge": "^4.6.9",
105
+ "@types/node": "^20.10.3",
105
106
  "@types/normalize-path": "^3.0.2",
106
- "@types/prompts": "^2.4.7",
107
- "@vitest/coverage-v8": "^0.34.6",
107
+ "@types/prompts": "^2.4.9",
108
+ "@vitest/coverage-v8": "^1.0.1",
108
109
  "execa": "^8.0.1",
109
- "happy-dom": "^12.4.0",
110
- "lint-staged": "^15.0.2",
110
+ "happy-dom": "^12.10.3",
111
+ "lint-staged": "^15.2.0",
111
112
  "lodash.merge": "^4.6.2",
112
113
  "npm-run-all": "^4.1.5",
113
- "p-map": "^6.0.0",
114
- "prettier": "^3.0.1",
114
+ "p-map": "^7.0.0",
115
+ "prettier": "^3.1.0",
115
116
  "simple-git-hooks": "^2.9.0",
116
- "tsup": "^7.2.0",
117
- "tsx": "^4.6.1",
117
+ "tsup": "^8.0.1",
118
+ "tsx": "^4.6.2",
118
119
  "typedoc": "^0.25.4",
119
120
  "typedoc-plugin-markdown": "4.0.0-next.23",
120
121
  "typedoc-vitepress-theme": "1.0.0-next.3",
121
122
  "typescript": "^5.3.2",
122
- "vitepress": "1.0.0-rc.24",
123
- "vitest": "^0.34.6",
123
+ "vitepress": "1.0.0-rc.31",
124
+ "vitest": "^1.0.0",
124
125
  "vitest-mock-extended": "^1.3.1",
125
- "vue": "^3.3.7"
126
+ "vue": "^3.3.10"
126
127
  },
127
128
  "packageManager": "pnpm@8.6.3",
128
129
  "simple-git-hooks": {
File without changes