wxt 0.20.0 → 0.20.2
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/builtin-modules/unimport.mjs +1 -0
- package/dist/cli/commands.mjs +5 -6
- package/dist/core/builders/vite/index.mjs +1 -1
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +6 -6
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +1 -1
- package/dist/core/create-server.mjs +6 -9
- package/dist/core/package-managers/deno.d.ts +2 -0
- package/dist/core/package-managers/deno.mjs +9 -0
- package/dist/core/package-managers/index.mjs +3 -1
- package/dist/core/resolve-config.mjs +23 -5
- package/dist/core/utils/globals.mjs +1 -1
- package/dist/core/utils/manifest.mjs +1 -1
- package/dist/core/utils/testing/fake-objects.d.ts +2068 -2051
- package/dist/core/utils/testing/fake-objects.mjs +5 -4
- package/dist/core/utils/transform.mjs +59 -7
- package/dist/types.d.ts +26 -6
- package/dist/utils/internal/dev-server-websocket.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/dist/virtual/background-entrypoint.mjs +1 -1
- package/dist/virtual/reload-html.mjs +1 -1
- package/package.json +22 -22
package/dist/cli/commands.mjs
CHANGED
|
@@ -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:
|
|
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 {
|
|
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
|
|
59
|
-
inlineScriptContents[
|
|
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}?${
|
|
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
|
|
92
|
-
return inlineScriptContents[
|
|
91
|
+
const newHash = hash(id.substring(id.indexOf("?")));
|
|
92
|
+
return inlineScriptContents[newHash];
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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" ?
|
|
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,
|
|
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
|
|
48
|
-
return getServerInfo().
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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,
|
|
@@ -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 =
|
|
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);
|