wxt 0.20.0 → 0.20.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.
@@ -183,6 +183,7 @@ export const fakeResolvedConfig = fakeObjectCreator(() => {
183
183
  const mode = faker.helpers.arrayElement(["development", "production"]);
184
184
  return {
185
185
  browser,
186
+ targetBrowsers: [],
186
187
  command,
187
188
  entrypointsDir: fakeDir(),
188
189
  modulesDir: fakeDir(),
@@ -266,9 +267,9 @@ export const fakeWxt = fakeObjectCreator(() => ({
266
267
  }));
267
268
  export const fakeWxtDevServer = fakeObjectCreator(() => ({
268
269
  currentOutput: fakeBuildOutput(),
269
- hostname: "localhost",
270
- origin: "http://localhost:3000",
270
+ host: "localhost",
271
271
  port: 3e3,
272
+ origin: "http://localhost:3000",
272
273
  reloadContentScript: vi.fn(),
273
274
  reloadExtension: vi.fn(),
274
275
  reloadPage: vi.fn(),
@@ -308,9 +309,9 @@ export const fakeManifestCommand = fakeObjectCreator(
308
309
  })
309
310
  );
310
311
  export const fakeDevServer = fakeObjectCreator(() => ({
311
- hostname: "localhost",
312
- origin: "http://localhost",
312
+ host: "localhost",
313
313
  port: 5173,
314
+ origin: "http://localhost:3000",
314
315
  reloadContentScript: vi.fn(),
315
316
  reloadExtension: vi.fn(),
316
317
  reloadPage: vi.fn(),
@@ -30,18 +30,70 @@ function removeUnusedTopLevelVariables(mod) {
30
30
  const usedMap = findUsedIdentifiers(simpleAst);
31
31
  let deletedCount = 0;
32
32
  const ast = mod.$ast;
33
- for (let i = ast.body.length - 1; i >= 0; i--) {
34
- if (ast.body[i].type === "VariableDeclaration") {
35
- for (let j = ast.body[i].declarations.length - 1; j >= 0; j--) {
36
- if (!usedMap.get(ast.body[i].declarations[j].id.name)) {
37
- ast.body[i].declarations.splice(j, 1);
33
+ const isUsed = (id) => {
34
+ return id?.type === "Identifier" && usedMap.get(id.name);
35
+ };
36
+ const cleanArrayPattern = (pattern) => {
37
+ const elements = pattern.elements;
38
+ for (let i = elements.length - 1; i >= 0; i--) {
39
+ const el = elements[i];
40
+ if (el?.type === "Identifier" && !isUsed(el)) {
41
+ elements.splice(i, 1);
42
+ deletedCount++;
43
+ }
44
+ }
45
+ return elements.length === 0;
46
+ };
47
+ const cleanObjectPattern = (pattern) => {
48
+ const properties = pattern.properties;
49
+ for (let i = properties.length - 1; i >= 0; i--) {
50
+ const prop = properties[i];
51
+ if (prop.type === "Property") {
52
+ const value = prop.value;
53
+ if (value.type === "ObjectPattern") {
54
+ const isEmpty = cleanObjectPattern(value);
55
+ if (isEmpty) {
56
+ properties.splice(i, 1);
57
+ }
58
+ } else if (value.type === "ArrayPattern") {
59
+ const isEmpty = cleanArrayPattern(value);
60
+ if (isEmpty) {
61
+ properties.splice(i, 1);
62
+ }
63
+ } else if (value.type === "Identifier" && !isUsed(value)) {
64
+ properties.splice(i, 1);
65
+ deletedCount++;
66
+ }
67
+ } else if (prop.type === "RestElement") {
68
+ const arg = prop.argument;
69
+ if (arg.type === "Identifier" && !isUsed(arg)) {
70
+ properties.splice(i, 1);
38
71
  deletedCount++;
39
72
  }
40
73
  }
41
- if (ast.body[i].declarations.length === 0) {
42
- ast.body.splice(i, 1);
74
+ }
75
+ return properties.length === 0;
76
+ };
77
+ for (let i = ast.body.length - 1; i >= 0; i--) {
78
+ if (ast.body[i].type !== "VariableDeclaration") continue;
79
+ for (let j = ast.body[i].declarations.length - 1; j >= 0; j--) {
80
+ const id = ast.body[i].declarations[j].id;
81
+ let shouldRemove = false;
82
+ if (id.type === "Identifier") {
83
+ shouldRemove = !isUsed(id);
84
+ if (shouldRemove) deletedCount++;
85
+ } else if (id.type === "ArrayPattern") {
86
+ shouldRemove = cleanArrayPattern(id);
87
+ } else if (id.type === "ObjectPattern") {
88
+ shouldRemove = cleanObjectPattern(id);
89
+ }
90
+ if (shouldRemove) {
91
+ ast.body[i].declarations.splice(j, 1);
43
92
  }
44
93
  }
94
+ if (ast.body[i].declarations.length === 0) {
95
+ ast.body.splice(i, 1);
96
+ }
45
97
  }
46
98
  return deletedCount;
47
99
  }
package/dist/types.d.ts CHANGED
@@ -107,6 +107,12 @@ export interface InlineConfig {
107
107
  * "chrome"
108
108
  */
109
109
  browser?: TargetBrowser;
110
+ /**
111
+ * Target browsers to support. When set, `import.meta.env.BROWSER` will be narrowed to a string literal type containing only the specified browser names.
112
+ *
113
+ * @default []
114
+ */
115
+ targetBrowsers?: TargetBrowser[];
110
116
  /**
111
117
  * Explicitly set a manifest version to target. This will override the default manifest version
112
118
  * for each command, and can be overridden by the command line `--mv2` or `--mv3` option.
@@ -318,14 +324,26 @@ export interface InlineConfig {
318
324
  */
319
325
  dev?: {
320
326
  server?: {
327
+ /**
328
+ * Host to bind the dev server to.
329
+ *
330
+ * @default "localhost"
331
+ */
332
+ host?: string;
321
333
  /**
322
334
  * Port to run the dev server on. Defaults to the first open port from 3000 to 3010.
323
335
  */
324
336
  port?: number;
337
+ /**
338
+ * Origin to use to connect from the extension ui runtime to the dev server.
339
+ *
340
+ * @default "http://localhost:3000"
341
+ */
342
+ origin?: string;
325
343
  /**
326
344
  * Hostname to run the dev server on.
327
345
  *
328
- * @default "localhost"
346
+ * @deprecated use `host` to specify the interface to bind to, or use `origin` to specify the dev server hostname.
329
347
  */
330
348
  hostname?: string;
331
349
  };
@@ -953,13 +971,13 @@ export interface WxtBuilderServer {
953
971
  }
954
972
  export interface ServerInfo {
955
973
  /**
956
- * Ex: `3000`
974
+ * Ex: `"localhost"`
957
975
  */
958
- port: number;
976
+ host: string;
959
977
  /**
960
- * Ex: `"localhost"`
978
+ * Ex: `3000`
961
979
  */
962
- hostname: string;
980
+ port: number;
963
981
  /**
964
982
  * Ex: `"http://localhost:3000"`
965
983
  */
@@ -1177,6 +1195,7 @@ export interface ResolvedConfig {
1177
1195
  mode: string;
1178
1196
  command: WxtCommand;
1179
1197
  browser: TargetBrowser;
1198
+ targetBrowsers: TargetBrowser[];
1180
1199
  manifestVersion: TargetManifestVersion;
1181
1200
  env: ConfigEnv;
1182
1201
  logger: Logger;
@@ -1221,8 +1240,9 @@ export interface ResolvedConfig {
1221
1240
  dev: {
1222
1241
  /** Only defined during dev command */
1223
1242
  server?: {
1243
+ host: string;
1224
1244
  port: number;
1225
- hostname: string;
1245
+ origin: string;
1226
1246
  /**
1227
1247
  * The milliseconds to debounce when a file is saved before reloading.
1228
1248
  * The only way to set this option is to set the `WXT_WATCH_DEBOUNCE`
@@ -6,7 +6,7 @@ export function getDevServerWebSocket() {
6
6
  "Must be running WXT dev command to connect to call getDevServerWebSocket()"
7
7
  );
8
8
  if (ws == null) {
9
- const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
9
+ const serverUrl = __DEV_SERVER_ORIGIN__;
10
10
  logger.debug("Connecting to dev server @", serverUrl);
11
11
  ws = new WebSocket(serverUrl, "vite-hmr");
12
12
  ws.addWxtEventListener = ws.addEventListener.bind(ws);
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "0.20.0";
1
+ export const version = "0.20.1";
@@ -26,7 +26,7 @@ function getDevServerWebSocket() {
26
26
  "Must be running WXT dev command to connect to call getDevServerWebSocket()"
27
27
  );
28
28
  if (ws == null) {
29
- const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
29
+ const serverUrl = __DEV_SERVER_ORIGIN__;
30
30
  logger.debug("Connecting to dev server @", serverUrl);
31
31
  ws = new WebSocket(serverUrl, "vite-hmr");
32
32
  ws.addWxtEventListener = ws.addEventListener.bind(ws);
@@ -21,7 +21,7 @@ function getDevServerWebSocket() {
21
21
  "Must be running WXT dev command to connect to call getDevServerWebSocket()"
22
22
  );
23
23
  if (ws == null) {
24
- const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
24
+ const serverUrl = __DEV_SERVER_ORIGIN__;
25
25
  logger.debug("Connecting to dev server @", serverUrl);
26
26
  ws = new WebSocket(serverUrl, "vite-hmr");
27
27
  ws.addWxtEventListener = ws.addEventListener.bind(ws);
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.20.0",
4
+ "version": "0.20.1",
5
5
  "description": "⚡ Next-gen Web Extension Framework",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@1natsu/wait-element": "^4.1.2",
9
9
  "@aklinker1/rollup-plugin-visualizer": "5.12.0",
10
- "@webext-core/fake-browser": "^1.3.1",
10
+ "@webext-core/fake-browser": "^1.3.2",
11
11
  "@webext-core/isolated-element": "^1.1.2",
12
12
  "@webext-core/match-patterns": "^1.0.3",
13
13
  "@wxt-dev/storage": "^1.0.0",
14
14
  "async-mutex": "^0.5.0",
15
- "c12": "^3.0.2",
15
+ "c12": "^3.0.3",
16
16
  "cac": "^6.7.14",
17
17
  "chokidar": "^4.0.3",
18
- "ci-info": "^4.1.0",
19
- "consola": "^3.2.3",
18
+ "ci-info": "^4.2.0",
19
+ "consola": "^3.4.2",
20
20
  "defu": "^6.1.4",
21
- "dotenv": "^16.4.5",
21
+ "dotenv": "^16.4.7",
22
22
  "dotenv-expand": "^12.0.1",
23
23
  "esbuild": "^0.25.0",
24
- "fast-glob": "^3.3.2",
24
+ "fast-glob": "^3.3.3",
25
25
  "filesize": "^10.1.6",
26
- "fs-extra": "^11.2.0",
26
+ "fs-extra": "^11.3.0",
27
27
  "get-port-please": "^3.1.2",
28
28
  "giget": "^1.2.3 || ^2.0.0",
29
29
  "hookable": "^5.5.3",
@@ -31,42 +31,42 @@
31
31
  "is-wsl": "^3.1.0",
32
32
  "json5": "^2.2.3",
33
33
  "jszip": "^3.10.1",
34
- "linkedom": "^0.18.5",
34
+ "linkedom": "^0.18.9",
35
35
  "magicast": "^0.3.5",
36
36
  "minimatch": "^10.0.1",
37
37
  "nano-spawn": "^0.2.0",
38
38
  "normalize-path": "^3.0.0",
39
- "nypm": "^0.3.12",
40
- "ohash": "^1.1.4",
39
+ "nypm": "^0.6.0",
40
+ "ohash": "^2.0.11",
41
41
  "open": "^10.1.0",
42
- "ora": "^8.1.1",
42
+ "ora": "^8.2.0",
43
43
  "perfect-debounce": "^1.0.0",
44
44
  "picocolors": "^1.1.1",
45
45
  "prompts": "^2.4.2",
46
46
  "publish-browser-extension": "^2.3.0 || ^3.0.0",
47
47
  "scule": "^1.3.0",
48
- "unimport": "^3.13.1 || ^4.0.0",
49
- "vite": "^5.0.0 || ^6.0.0",
48
+ "unimport": "^3.13.1 || ^4.0.0 || ^5.0.0",
49
+ "vite": "^5.4.17 || ^6.2.5",
50
50
  "vite-node": "^2.1.4 || ^3.0.0",
51
- "web-ext-run": "^0.2.1",
52
- "@wxt-dev/browser": "0.0.310"
51
+ "web-ext-run": "^0.2.2",
52
+ "@wxt-dev/browser": "0.0.315"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@aklinker1/check": "^1.4.5",
56
- "@faker-js/faker": "^9.2.0",
56
+ "@faker-js/faker": "^9.6.0",
57
57
  "@types/fs-extra": "^11.0.4",
58
58
  "@types/lodash.merge": "^4.6.9",
59
59
  "@types/node": "^20.17.6",
60
60
  "@types/normalize-path": "^3.0.2",
61
61
  "@types/prompts": "^2.4.9",
62
62
  "extract-zip": "^2.0.1",
63
- "happy-dom": "^17.1.8",
63
+ "happy-dom": "^17.4.4",
64
64
  "lodash.merge": "^4.6.2",
65
- "oxlint": "^0.11.1",
66
- "publint": "^0.2.12",
67
- "typescript": "^5.6.3",
65
+ "oxlint": "^0.16.5",
66
+ "publint": "^0.3.10",
67
+ "typescript": "^5.8.3",
68
68
  "unbuild": "^3.5.0",
69
- "vitest": "^3.0.7",
69
+ "vitest": "^3.1.1",
70
70
  "vitest-plugin-random-seed": "^1.1.1"
71
71
  },
72
72
  "peerDependenciesMeta": {},