wxt 0.18.7 → 0.18.8
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/{chunk-A3R6ZPUA.js → chunk-Z3C7S5VV.js} +21 -15
- package/dist/cli.js +22 -15
- package/dist/index.cjs +22 -15
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/modules.cjs +5 -6
- package/dist/modules.js +5 -6
- package/dist/testing.js +1 -1
- package/dist/virtual/background-entrypoint.js +44 -31
- package/dist/virtual/reload-html.js +37 -29
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "./chunk-QGM4M3NI.js";
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
|
-
var version = "0.18.
|
|
15
|
+
var version = "0.18.7";
|
|
16
16
|
|
|
17
17
|
// src/core/utils/paths.ts
|
|
18
18
|
import systemPath from "node:path";
|
|
@@ -713,10 +713,13 @@ try {
|
|
|
713
713
|
// Use "pre" so the new script is added before vite bundles all the scripts
|
|
714
714
|
order: "pre",
|
|
715
715
|
handler(html, _ctx) {
|
|
716
|
+
const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
|
|
716
717
|
const { document } = parseHTML2(html);
|
|
718
|
+
const existing = document.querySelector(`script[src='${src}']`);
|
|
719
|
+
if (existing) return;
|
|
717
720
|
const script = document.createElement("script");
|
|
718
721
|
script.type = "module";
|
|
719
|
-
script.src =
|
|
722
|
+
script.src = src;
|
|
720
723
|
if (document.head == null) {
|
|
721
724
|
const newHead = document.createElement("head");
|
|
722
725
|
document.documentElement.prepend(newHead);
|
|
@@ -822,11 +825,25 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
822
825
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
823
826
|
)
|
|
824
827
|
);
|
|
825
|
-
if (changedSteps.size === 0)
|
|
828
|
+
if (changedSteps.size === 0) {
|
|
829
|
+
const hasPublicChange = some(
|
|
830
|
+
changedFiles,
|
|
831
|
+
(file) => file.startsWith(wxt.config.publicDir)
|
|
832
|
+
);
|
|
833
|
+
if (hasPublicChange) {
|
|
834
|
+
return {
|
|
835
|
+
type: "extension-reload",
|
|
836
|
+
rebuildGroups: [],
|
|
837
|
+
cachedOutput: currentOutput
|
|
838
|
+
};
|
|
839
|
+
} else {
|
|
840
|
+
return { type: "no-change" };
|
|
841
|
+
}
|
|
842
|
+
}
|
|
826
843
|
const unchangedOutput = {
|
|
827
844
|
manifest: currentOutput.manifest,
|
|
828
845
|
steps: [],
|
|
829
|
-
publicAssets: []
|
|
846
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
830
847
|
};
|
|
831
848
|
const changedOutput = {
|
|
832
849
|
manifest: currentOutput.manifest,
|
|
@@ -840,13 +857,6 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
840
857
|
unchangedOutput.steps.push(step);
|
|
841
858
|
}
|
|
842
859
|
}
|
|
843
|
-
for (const asset of currentOutput.publicAssets) {
|
|
844
|
-
if (changedSteps.has(asset)) {
|
|
845
|
-
changedOutput.publicAssets.push(asset);
|
|
846
|
-
} else {
|
|
847
|
-
unchangedOutput.publicAssets.push(asset);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
860
|
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
851
861
|
if (isOnlyHtmlChanges) {
|
|
852
862
|
return {
|
|
@@ -887,10 +897,6 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
887
897
|
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
888
898
|
if (effectedChunk) changes.push(step);
|
|
889
899
|
}
|
|
890
|
-
const effectedAsset = currentOutput.publicAssets.find(
|
|
891
|
-
(chunk) => isChunkEffected(chunk)
|
|
892
|
-
);
|
|
893
|
-
if (effectedAsset) changes.push(effectedAsset);
|
|
894
900
|
return changes;
|
|
895
901
|
}
|
|
896
902
|
|
package/dist/cli.js
CHANGED
|
@@ -917,10 +917,13 @@ try {
|
|
|
917
917
|
// Use "pre" so the new script is added before vite bundles all the scripts
|
|
918
918
|
order: "pre",
|
|
919
919
|
handler(html, _ctx) {
|
|
920
|
+
const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
|
|
920
921
|
const { document } = parseHTML2(html);
|
|
922
|
+
const existing = document.querySelector(`script[src='${src}']`);
|
|
923
|
+
if (existing) return;
|
|
921
924
|
const script = document.createElement("script");
|
|
922
925
|
script.type = "module";
|
|
923
|
-
script.src =
|
|
926
|
+
script.src = src;
|
|
924
927
|
if (document.head == null) {
|
|
925
928
|
const newHead = document.createElement("head");
|
|
926
929
|
document.documentElement.prepend(newHead);
|
|
@@ -1321,11 +1324,25 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
1321
1324
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
1322
1325
|
)
|
|
1323
1326
|
);
|
|
1324
|
-
if (changedSteps.size === 0)
|
|
1327
|
+
if (changedSteps.size === 0) {
|
|
1328
|
+
const hasPublicChange = some(
|
|
1329
|
+
changedFiles,
|
|
1330
|
+
(file) => file.startsWith(wxt.config.publicDir)
|
|
1331
|
+
);
|
|
1332
|
+
if (hasPublicChange) {
|
|
1333
|
+
return {
|
|
1334
|
+
type: "extension-reload",
|
|
1335
|
+
rebuildGroups: [],
|
|
1336
|
+
cachedOutput: currentOutput
|
|
1337
|
+
};
|
|
1338
|
+
} else {
|
|
1339
|
+
return { type: "no-change" };
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1325
1342
|
const unchangedOutput = {
|
|
1326
1343
|
manifest: currentOutput.manifest,
|
|
1327
1344
|
steps: [],
|
|
1328
|
-
publicAssets: []
|
|
1345
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
1329
1346
|
};
|
|
1330
1347
|
const changedOutput = {
|
|
1331
1348
|
manifest: currentOutput.manifest,
|
|
@@ -1339,13 +1356,6 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
1339
1356
|
unchangedOutput.steps.push(step);
|
|
1340
1357
|
}
|
|
1341
1358
|
}
|
|
1342
|
-
for (const asset of currentOutput.publicAssets) {
|
|
1343
|
-
if (changedSteps.has(asset)) {
|
|
1344
|
-
changedOutput.publicAssets.push(asset);
|
|
1345
|
-
} else {
|
|
1346
|
-
unchangedOutput.publicAssets.push(asset);
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
1359
|
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
1350
1360
|
if (isOnlyHtmlChanges) {
|
|
1351
1361
|
return {
|
|
@@ -1386,10 +1396,6 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
1386
1396
|
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
1387
1397
|
if (effectedChunk) changes.push(step);
|
|
1388
1398
|
}
|
|
1389
|
-
const effectedAsset = currentOutput.publicAssets.find(
|
|
1390
|
-
(chunk) => isChunkEffected(chunk)
|
|
1391
|
-
);
|
|
1392
|
-
if (effectedAsset) changes.push(effectedAsset);
|
|
1393
1399
|
return changes;
|
|
1394
1400
|
}
|
|
1395
1401
|
|
|
@@ -2609,7 +2615,7 @@ function getChunkSortWeight(filename) {
|
|
|
2609
2615
|
import pc4 from "picocolors";
|
|
2610
2616
|
|
|
2611
2617
|
// package.json
|
|
2612
|
-
var version = "0.18.
|
|
2618
|
+
var version = "0.18.7";
|
|
2613
2619
|
|
|
2614
2620
|
// src/core/utils/log/printHeader.ts
|
|
2615
2621
|
function printHeader() {
|
|
@@ -3690,6 +3696,7 @@ function createFileReloader(server) {
|
|
|
3690
3696
|
return async (event, path11) => {
|
|
3691
3697
|
await wxt.reloadConfig();
|
|
3692
3698
|
if (path11.startsWith(wxt.config.outBaseDir)) return;
|
|
3699
|
+
if (path11.startsWith(wxt.config.wxtDir)) return;
|
|
3693
3700
|
changeQueue.push([event, path11]);
|
|
3694
3701
|
await fileChangedMutex.runExclusive(async () => {
|
|
3695
3702
|
if (server.currentOutput == null) return;
|
package/dist/index.cjs
CHANGED
|
@@ -10981,10 +10981,13 @@ try {
|
|
|
10981
10981
|
// Use "pre" so the new script is added before vite bundles all the scripts
|
|
10982
10982
|
order: "pre",
|
|
10983
10983
|
handler(html, _ctx) {
|
|
10984
|
+
const src2 = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
|
|
10984
10985
|
const { document } = (0, import_linkedom2.parseHTML)(html);
|
|
10986
|
+
const existing = document.querySelector(`script[src='${src2}']`);
|
|
10987
|
+
if (existing) return;
|
|
10985
10988
|
const script = document.createElement("script");
|
|
10986
10989
|
script.type = "module";
|
|
10987
|
-
script.src =
|
|
10990
|
+
script.src = src2;
|
|
10988
10991
|
if (document.head == null) {
|
|
10989
10992
|
const newHead = document.createElement("head");
|
|
10990
10993
|
document.documentElement.prepend(newHead);
|
|
@@ -11382,11 +11385,25 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
11382
11385
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
11383
11386
|
)
|
|
11384
11387
|
);
|
|
11385
|
-
if (changedSteps.size === 0)
|
|
11388
|
+
if (changedSteps.size === 0) {
|
|
11389
|
+
const hasPublicChange = some(
|
|
11390
|
+
changedFiles,
|
|
11391
|
+
(file) => file.startsWith(wxt.config.publicDir)
|
|
11392
|
+
);
|
|
11393
|
+
if (hasPublicChange) {
|
|
11394
|
+
return {
|
|
11395
|
+
type: "extension-reload",
|
|
11396
|
+
rebuildGroups: [],
|
|
11397
|
+
cachedOutput: currentOutput
|
|
11398
|
+
};
|
|
11399
|
+
} else {
|
|
11400
|
+
return { type: "no-change" };
|
|
11401
|
+
}
|
|
11402
|
+
}
|
|
11386
11403
|
const unchangedOutput = {
|
|
11387
11404
|
manifest: currentOutput.manifest,
|
|
11388
11405
|
steps: [],
|
|
11389
|
-
publicAssets: []
|
|
11406
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
11390
11407
|
};
|
|
11391
11408
|
const changedOutput = {
|
|
11392
11409
|
manifest: currentOutput.manifest,
|
|
@@ -11400,13 +11417,6 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
11400
11417
|
unchangedOutput.steps.push(step);
|
|
11401
11418
|
}
|
|
11402
11419
|
}
|
|
11403
|
-
for (const asset of currentOutput.publicAssets) {
|
|
11404
|
-
if (changedSteps.has(asset)) {
|
|
11405
|
-
changedOutput.publicAssets.push(asset);
|
|
11406
|
-
} else {
|
|
11407
|
-
unchangedOutput.publicAssets.push(asset);
|
|
11408
|
-
}
|
|
11409
|
-
}
|
|
11410
11420
|
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
11411
11421
|
if (isOnlyHtmlChanges) {
|
|
11412
11422
|
return {
|
|
@@ -11447,10 +11457,6 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
11447
11457
|
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
11448
11458
|
if (effectedChunk) changes.push(step);
|
|
11449
11459
|
}
|
|
11450
|
-
const effectedAsset = currentOutput.publicAssets.find(
|
|
11451
|
-
(chunk) => isChunkEffected(chunk)
|
|
11452
|
-
);
|
|
11453
|
-
if (effectedAsset) changes.push(effectedAsset);
|
|
11454
11460
|
return changes;
|
|
11455
11461
|
}
|
|
11456
11462
|
|
|
@@ -12682,7 +12688,7 @@ function getChunkSortWeight(filename) {
|
|
|
12682
12688
|
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
12683
12689
|
|
|
12684
12690
|
// package.json
|
|
12685
|
-
var version = "0.18.
|
|
12691
|
+
var version = "0.18.7";
|
|
12686
12692
|
|
|
12687
12693
|
// src/core/utils/building/internal-build.ts
|
|
12688
12694
|
var import_fast_glob4 = __toESM(require("fast-glob"), 1);
|
|
@@ -13767,6 +13773,7 @@ function createFileReloader(server) {
|
|
|
13767
13773
|
return async (event, path12) => {
|
|
13768
13774
|
await wxt.reloadConfig();
|
|
13769
13775
|
if (path12.startsWith(wxt.config.outBaseDir)) return;
|
|
13776
|
+
if (path12.startsWith(wxt.config.wxtDir)) return;
|
|
13770
13777
|
changeQueue.push([event, path12]);
|
|
13771
13778
|
await fileChangedMutex.runExclusive(async () => {
|
|
13772
13779
|
if (server.currentOutput == null) return;
|
package/dist/index.d.cts
CHANGED
|
@@ -65,6 +65,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
65
65
|
*/
|
|
66
66
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
67
67
|
|
|
68
|
-
var version = "0.18.
|
|
68
|
+
var version = "0.18.7";
|
|
69
69
|
|
|
70
70
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
65
65
|
*/
|
|
66
66
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
67
67
|
|
|
68
|
-
var version = "0.18.
|
|
68
|
+
var version = "0.18.7";
|
|
69
69
|
|
|
70
70
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
unnormalizePath,
|
|
20
20
|
version,
|
|
21
21
|
wxt
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-Z3C7S5VV.js";
|
|
23
23
|
import "./chunk-BERPNPEZ.js";
|
|
24
24
|
import {
|
|
25
25
|
consola
|
|
@@ -302,6 +302,7 @@ function createFileReloader(server) {
|
|
|
302
302
|
return async (event, path4) => {
|
|
303
303
|
await wxt.reloadConfig();
|
|
304
304
|
if (path4.startsWith(wxt.config.outBaseDir)) return;
|
|
305
|
+
if (path4.startsWith(wxt.config.wxtDir)) return;
|
|
305
306
|
changeQueue.push([event, path4]);
|
|
306
307
|
await fileChangedMutex.runExclusive(async () => {
|
|
307
308
|
if (server.currentOutput == null) return;
|
package/dist/modules.cjs
CHANGED
|
@@ -65,12 +65,11 @@ function addPublicAssets(wxt, dir) {
|
|
|
65
65
|
function addViteConfig(wxt, viteConfig) {
|
|
66
66
|
wxt.hooks.hook("ready", (wxt2) => {
|
|
67
67
|
const userVite = wxt2.config.vite;
|
|
68
|
-
wxt2.config.vite = (env) =>
|
|
69
|
-
|
|
70
|
-
viteConfig(env) ?? {}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
);
|
|
68
|
+
wxt2.config.vite = async (env) => {
|
|
69
|
+
const fromUser = await userVite(env);
|
|
70
|
+
const fromModule = viteConfig(env) ?? {};
|
|
71
|
+
return vite.mergeConfig(fromModule, fromUser);
|
|
72
|
+
};
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
function addWxtPlugin(wxt, plugin) {
|
package/dist/modules.js
CHANGED
|
@@ -28,12 +28,11 @@ function addPublicAssets(wxt, dir) {
|
|
|
28
28
|
function addViteConfig(wxt, viteConfig) {
|
|
29
29
|
wxt.hooks.hook("ready", (wxt2) => {
|
|
30
30
|
const userVite = wxt2.config.vite;
|
|
31
|
-
wxt2.config.vite = (env) =>
|
|
32
|
-
|
|
33
|
-
viteConfig(env) ?? {}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
31
|
+
wxt2.config.vite = async (env) => {
|
|
32
|
+
const fromUser = await userVite(env);
|
|
33
|
+
const fromModule = viteConfig(env) ?? {};
|
|
34
|
+
return vite.mergeConfig(fromModule, fromUser);
|
|
35
|
+
};
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
function addWxtPlugin(wxt, plugin) {
|
package/dist/testing.js
CHANGED
|
@@ -19,30 +19,41 @@ var logger = {
|
|
|
19
19
|
error: (...args) => print(console.error, ...args)
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// src/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
logger.debug("
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
// src/sandbox/dev-server-websocket.ts
|
|
23
|
+
var ws;
|
|
24
|
+
function getDevServerWebSocket() {
|
|
25
|
+
if (import.meta.env.COMMAND !== "serve")
|
|
26
|
+
throw Error(
|
|
27
|
+
"Must be running WXT dev command to connect to call getDevServerWebSocket()"
|
|
28
|
+
);
|
|
29
|
+
if (ws == null) {
|
|
30
|
+
const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
|
|
31
|
+
logger.debug("Connecting to dev server @", serverUrl);
|
|
32
|
+
ws = new WebSocket(serverUrl, "vite-hmr");
|
|
33
|
+
ws.addWxtEventListener = ws.addEventListener.bind(ws);
|
|
34
|
+
ws.sendCustom = (event, payload) => ws?.send(JSON.stringify({ type: "custom", event, payload }));
|
|
35
|
+
ws.addEventListener("open", () => {
|
|
36
|
+
logger.debug("Connected to dev server");
|
|
37
|
+
});
|
|
38
|
+
ws.addEventListener("close", () => {
|
|
39
|
+
logger.debug("Disconnected from dev server");
|
|
40
|
+
});
|
|
41
|
+
ws.addEventListener("error", (event) => {
|
|
42
|
+
logger.error("Failed to connect to dev server", event);
|
|
43
|
+
});
|
|
44
|
+
ws.addEventListener("message", (e) => {
|
|
45
|
+
try {
|
|
46
|
+
const message = JSON.parse(e.data);
|
|
47
|
+
if (message.type === "custom") {
|
|
48
|
+
ws?.dispatchEvent(
|
|
49
|
+
new CustomEvent(message.event, { detail: message.data })
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
logger.error("Failed to handle message", err);
|
|
41
54
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
46
57
|
return ws;
|
|
47
58
|
}
|
|
48
59
|
|
|
@@ -131,16 +142,18 @@ async function reloadContentScriptMv2(_payload) {
|
|
|
131
142
|
// src/virtual/background-entrypoint.ts
|
|
132
143
|
if (import.meta.env.COMMAND === "serve") {
|
|
133
144
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
const ws2 = getDevServerWebSocket();
|
|
146
|
+
ws2.addWxtEventListener("wxt:reload-extension", () => {
|
|
147
|
+
browser3.runtime.reload();
|
|
148
|
+
});
|
|
149
|
+
ws2.addWxtEventListener("wxt:reload-content-script", (event) => {
|
|
150
|
+
reloadContentScript(event.detail);
|
|
138
151
|
});
|
|
139
152
|
if (import.meta.env.MANIFEST_VERSION === 3) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
ws2.addEventListener(
|
|
154
|
+
"open",
|
|
155
|
+
() => ws2.sendCustom("wxt:background-initialized")
|
|
156
|
+
);
|
|
144
157
|
keepServiceWorkerAlive();
|
|
145
158
|
}
|
|
146
159
|
} catch (err) {
|
|
@@ -15,42 +15,50 @@ var logger = {
|
|
|
15
15
|
error: (...args) => print(console.error, ...args)
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
// src/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
logger.debug("
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
// src/sandbox/dev-server-websocket.ts
|
|
19
|
+
var ws;
|
|
20
|
+
function getDevServerWebSocket() {
|
|
21
|
+
if (import.meta.env.COMMAND !== "serve")
|
|
22
|
+
throw Error(
|
|
23
|
+
"Must be running WXT dev command to connect to call getDevServerWebSocket()"
|
|
24
|
+
);
|
|
25
|
+
if (ws == null) {
|
|
26
|
+
const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
|
|
27
|
+
logger.debug("Connecting to dev server @", serverUrl);
|
|
28
|
+
ws = new WebSocket(serverUrl, "vite-hmr");
|
|
29
|
+
ws.addWxtEventListener = ws.addEventListener.bind(ws);
|
|
30
|
+
ws.sendCustom = (event, payload) => ws?.send(JSON.stringify({ type: "custom", event, payload }));
|
|
31
|
+
ws.addEventListener("open", () => {
|
|
32
|
+
logger.debug("Connected to dev server");
|
|
33
|
+
});
|
|
34
|
+
ws.addEventListener("close", () => {
|
|
35
|
+
logger.debug("Disconnected from dev server");
|
|
36
|
+
});
|
|
37
|
+
ws.addEventListener("error", (event) => {
|
|
38
|
+
logger.error("Failed to connect to dev server", event);
|
|
39
|
+
});
|
|
40
|
+
ws.addEventListener("message", (e) => {
|
|
41
|
+
try {
|
|
42
|
+
const message = JSON.parse(e.data);
|
|
43
|
+
if (message.type === "custom") {
|
|
44
|
+
ws?.dispatchEvent(
|
|
45
|
+
new CustomEvent(message.event, { detail: message.data })
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
logger.error("Failed to handle message", err);
|
|
37
50
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
42
53
|
return ws;
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
// src/virtual/reload-html.ts
|
|
46
57
|
if (import.meta.env.COMMAND === "serve") {
|
|
47
58
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
location.reload();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
59
|
+
const ws2 = getDevServerWebSocket();
|
|
60
|
+
ws2.addWxtEventListener("wxt:reload-page", (event) => {
|
|
61
|
+
if (event.detail === location.pathname.substring(1)) location.reload();
|
|
54
62
|
});
|
|
55
63
|
} catch (err) {
|
|
56
64
|
logger.error("Failed to setup web socket connection with dev server", err);
|