wxt 0.20.0-beta2 → 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.
@@ -88,6 +88,7 @@ export default {
88
88
  name: "wxt/auto-imports",
89
89
  languageOptions: {
90
90
  globals,
91
+ /** @type {import('eslint').Linter.SourceType} */
91
92
  sourceType: "module",
92
93
  },
93
94
  };
@@ -7,7 +7,7 @@ import {
7
7
  } from "./cli-utils.mjs";
8
8
  const cli = cac("wxt");
9
9
  cli.option("--debug", "enable debug mode");
10
- cli.command("[root]", "start dev server").option("-c, --config <file>", "use specified config file").option("-m, --mode <mode>", "set env mode").option("-b, --browser <browser>", "specify a browser").option("-p, --port <port>", "specify a port for the dev server").option(
10
+ cli.command("[root]", "start dev server").option("-c, --config <file>", "use specified config file").option("-m, --mode <mode>", "set env mode").option("-b, --browser <browser>", "specify a browser").option("--host <host>", "specify a host for the dev server to bind to").option("-p, --port <port>", "specify a port for the dev server to bind to").option(
11
11
  "-e, --filter-entrypoint <entrypoint>",
12
12
  "only build specific entrypoints",
13
13
  {
@@ -15,6 +15,9 @@ cli.command("[root]", "start dev server").option("-c, --config <file>", "use spe
15
15
  }
16
16
  ).option("--mv3", "target manifest v3").option("--mv2", "target manifest v2").action(
17
17
  wrapAction(async (root, flags) => {
18
+ const serverOptions = {};
19
+ if (flags.host) serverOptions.host = flags.host;
20
+ if (flags.port) serverOptions.port = parseInt(flags.port);
18
21
  const server = await createServer({
19
22
  root,
20
23
  mode: flags.mode,
@@ -23,11 +26,7 @@ cli.command("[root]", "start dev server").option("-c, --config <file>", "use spe
23
26
  configFile: flags.config,
24
27
  debug: flags.debug,
25
28
  filterEntrypoints: getArrayFromFlags(flags, "filterEntrypoint"),
26
- dev: flags.port == null ? void 0 : {
27
- server: {
28
- port: parseInt(flags.port)
29
- }
30
- }
29
+ dev: Object.keys(serverOptions).length === 0 ? void 0 : { server: serverOptions }
31
30
  });
32
31
  await server.start();
33
32
  return { isOngoing: true };
@@ -256,9 +256,9 @@ export async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
256
256
  async createServer(info) {
257
257
  const serverConfig = {
258
258
  server: {
259
+ host: info.host,
259
260
  port: info.port,
260
261
  strictPort: true,
261
- host: info.hostname,
262
262
  origin: info.origin
263
263
  }
264
264
  };
@@ -2,7 +2,7 @@ import { getEntrypointName } from "../../../utils/entrypoints.mjs";
2
2
  import { parseHTML } from "linkedom";
3
3
  import { dirname, relative, resolve } from "node:path";
4
4
  import { normalizePath } from "../../../utils/paths.mjs";
5
- import { murmurHash } from "ohash";
5
+ import { hash } from "ohash";
6
6
  const inlineScriptContents = {};
7
7
  export function devHtmlPrerender(config, server) {
8
8
  const htmlReloadId = "@wxt/reload-html";
@@ -55,11 +55,11 @@ export function devHtmlPrerender(config, server) {
55
55
  const inlineScripts = document.querySelectorAll("script:not([src])");
56
56
  inlineScripts.forEach((script) => {
57
57
  const textContent = script.textContent ?? "";
58
- const hash = murmurHash(textContent);
59
- inlineScriptContents[hash] = textContent;
58
+ const textHash = hash(textContent);
59
+ inlineScriptContents[textHash] = textContent;
60
60
  const virtualScript = document.createElement("script");
61
61
  virtualScript.type = "module";
62
- virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${hash}`;
62
+ virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${textHash}`;
63
63
  script.replaceWith(virtualScript);
64
64
  });
65
65
  const viteClientScript = document.querySelector(
@@ -88,8 +88,8 @@ export function devHtmlPrerender(config, server) {
88
88
  },
89
89
  load(id) {
90
90
  if (id.startsWith(resolvedVirtualInlineScript)) {
91
- const hash = Number(id.substring(id.indexOf("?") + 1));
92
- return inlineScriptContents[hash];
91
+ const hash2 = Number(id.substring(id.indexOf("?") + 1));
92
+ return inlineScriptContents[hash2];
93
93
  }
94
94
  if (id === "\0noop") {
95
95
  return "";
@@ -5,9 +5,9 @@ export function devServerGlobals(config, server) {
5
5
  if (server == null || config.command == "build") return;
6
6
  return {
7
7
  define: {
8
- __DEV_SERVER_PROTOCOL__: JSON.stringify("ws:"),
9
- __DEV_SERVER_HOSTNAME__: JSON.stringify(server.hostname),
10
- __DEV_SERVER_PORT__: JSON.stringify(server.port)
8
+ __DEV_SERVER_ORIGIN__: JSON.stringify(
9
+ server.origin.replace(/^http(s):/, "ws$1:")
10
+ )
11
11
  }
12
12
  };
13
13
  }
@@ -37,7 +37,7 @@ try {
37
37
  // Use "pre" so the new script is added before vite bundles all the scripts
38
38
  order: "pre",
39
39
  handler(html, _ctx) {
40
- const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
40
+ const src = config.command === "serve" ? `${config.dev.server?.origin}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
41
41
  const { document } = parseHTML(html);
42
42
  const existing = document.querySelector(`script[src='${src}']`);
43
43
  if (existing) return;
@@ -31,12 +31,8 @@ export async function createServer(inlineConfig) {
31
31
  }
32
32
  async function createServerInternal() {
33
33
  const getServerInfo = () => {
34
- const { port, hostname } = wxt.config.dev.server;
35
- return {
36
- port,
37
- hostname,
38
- origin: `http://${hostname}:${port}`
39
- };
34
+ const { host, port, origin } = wxt.config.dev.server;
35
+ return { host, port, origin };
40
36
  };
41
37
  let [runner, builderServer] = await Promise.all([
42
38
  createExtensionRunner(),
@@ -44,8 +40,8 @@ async function createServerInternal() {
44
40
  ]);
45
41
  let wasStopped = false;
46
42
  const server = {
47
- get hostname() {
48
- return getServerInfo().hostname;
43
+ get host() {
44
+ return getServerInfo().host;
49
45
  },
50
46
  get port() {
51
47
  return getServerInfo().port;
@@ -68,7 +64,8 @@ async function createServerInternal() {
68
64
  await initWxtModules();
69
65
  }
70
66
  await builderServer.listen();
71
- wxt.logger.success(`Started dev server @ ${server.origin}`);
67
+ const hostInfo = server.host === "localhost" ? "" : ` (listening on ${server.host})`;
68
+ wxt.logger.success(`Started dev server @ ${server.origin}${hostInfo}`);
72
69
  await wxt.hooks.callHook("server:started", wxt, server);
73
70
  server.ws.on("wxt:background-initialized", () => {
74
71
  if (server.currentOutput == null) return;
@@ -0,0 +1,2 @@
1
+ import { WxtPackageManagerImpl } from './types';
2
+ export declare const deno: WxtPackageManagerImpl;
@@ -0,0 +1,9 @@
1
+ export const deno = {
2
+ overridesKey: "na",
3
+ downloadDependency() {
4
+ throw Error("Deno not supported");
5
+ },
6
+ listDependencies() {
7
+ throw Error("Deno not supported");
8
+ }
9
+ };
@@ -10,6 +10,7 @@ import { bun } from "./bun.mjs";
10
10
  import { yarn } from "./yarn.mjs";
11
11
  import { pnpm } from "./pnpm.mjs";
12
12
  import { npm } from "./npm.mjs";
13
+ import { deno } from "./deno.mjs";
13
14
  export async function createWxtPackageManager(root) {
14
15
  const pm = await detectPackageManager(root, {
15
16
  includeParentDirs: true
@@ -61,5 +62,6 @@ const packageManagers = {
61
62
  npm,
62
63
  pnpm,
63
64
  bun,
64
- yarn
65
+ yarn,
66
+ deno
65
67
  };
@@ -34,6 +34,12 @@ export async function resolveConfig(inlineConfig, command) {
34
34
  const logger = mergedConfig.logger ?? consola;
35
35
  if (debug) logger.level = LogLevels.debug;
36
36
  const browser = mergedConfig.browser ?? "chrome";
37
+ const targetBrowsers = mergedConfig.targetBrowsers ?? [];
38
+ if (targetBrowsers.length > 0 && !targetBrowsers.includes(browser)) {
39
+ throw new Error(
40
+ `Current target browser \`${browser}\` is not in your \`targetBrowsers\` list!`
41
+ );
42
+ }
37
43
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
38
44
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
39
45
  const env = { browser, command, manifestVersion, mode };
@@ -88,19 +94,30 @@ export async function resolveConfig(inlineConfig, command) {
88
94
  );
89
95
  let devServerConfig;
90
96
  if (command === "serve") {
91
- const hostname = mergedConfig.dev?.server?.hostname ?? "localhost";
97
+ if (mergedConfig.dev?.server?.hostname)
98
+ logger.warn(
99
+ `The 'hostname' option is deprecated, please use 'host' or 'origin' depending on your circumstances.`
100
+ );
101
+ const host = mergedConfig.dev?.server?.host ?? mergedConfig.dev?.server?.hostname ?? "localhost";
92
102
  let port = mergedConfig.dev?.server?.port;
103
+ const origin = mergedConfig.dev?.server?.origin ?? mergedConfig.dev?.server?.hostname ?? "localhost";
93
104
  if (port == null || !isFinite(port)) {
94
105
  port = await getPort({
95
- port: 3e3,
96
- portRange: [3001, 3010],
97
106
  // Passing host required for Mac, unsure of Windows/Linux
98
- host: hostname
107
+ host,
108
+ port: 3e3,
109
+ portRange: [3001, 3010]
99
110
  });
100
111
  }
112
+ const originWithProtocolAndPort = [
113
+ origin.match(/^https?:\/\//) ? "" : "http://",
114
+ origin,
115
+ origin.match(/:[0-9]+$/) ? "" : `:${port}`
116
+ ].join("");
101
117
  devServerConfig = {
118
+ host,
102
119
  port,
103
- hostname,
120
+ origin: originWithProtocolAndPort,
104
121
  watchDebounce: safeStringToNumber(process.env.WXT_WATCH_DEBOUNCE) ?? 800
105
122
  };
106
123
  }
@@ -121,6 +138,7 @@ export async function resolveConfig(inlineConfig, command) {
121
138
  );
122
139
  return {
123
140
  browser,
141
+ targetBrowsers,
124
142
  command,
125
143
  debug,
126
144
  entrypointsDir,
@@ -8,7 +8,7 @@ export function getGlobals(config) {
8
8
  {
9
9
  name: "BROWSER",
10
10
  value: config.browser,
11
- type: `string`
11
+ type: config.targetBrowsers.length === 0 ? "string" : config.targetBrowsers.map((browser) => `"${browser}"`).join(" | ")
12
12
  },
13
13
  {
14
14
  name: "CHROME",
@@ -349,7 +349,7 @@ function discoverIcons(buildOutput) {
349
349
  return icons.length > 0 ? Object.fromEntries(icons) : void 0;
350
350
  }
351
351
  function addDevModeCsp(manifest) {
352
- const permission = `http://${wxt.server?.hostname ?? ""}/*`;
352
+ const permission = `${wxt.server?.origin ?? ""}/*`;
353
353
  const allowedCsp = wxt.server?.origin ?? "http://localhost:*";
354
354
  if (manifest.manifest_version === 3) {
355
355
  addHostPermission(manifest, permission);