@vitejs/devtools 0.1.5 → 0.1.9
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/{DockIcon-DNt-Vqy4.js → DockIcon-7v-JouW5.js} +27 -27
- package/dist/DockStandalone-DZ0INpRC.js +3246 -0
- package/dist/{LogItem-CZM2G41b.js → LogItem-Ca0SsU39.js} +23 -20
- package/dist/{ViewBuiltinLogs-1ABRTwzd.js → ViewBuiltinLogs-B_CLlali.js} +39 -39
- package/dist/{ViewBuiltinTerminals-Co7G-321.js → ViewBuiltinTerminals-ZrMObMte.js} +10 -11
- package/dist/{ViewJsonRender-ByPfpKFM.js → ViewJsonRender-Cc5BPfnv.js} +4 -4
- package/dist/auth-state-DXCxEqSd.js +54 -0
- package/dist/build-static-zB8LrlMJ.js +49 -0
- package/dist/cli-commands.js +57 -2
- package/dist/cli.js +8 -4
- package/dist/client/inject.js +231 -27
- package/dist/client/standalone/assets/DockStandalone-BUOgWTCb.js +1 -0
- package/dist/client/standalone/assets/LogItem-BnVhub2j.js +1 -0
- package/dist/client/standalone/assets/ViewBuiltinLogs-rU-E-8qT.js +1 -0
- package/dist/client/standalone/assets/{ViewBuiltinTerminals-UrMq7UXM.js → ViewBuiltinTerminals-UWfUyC_P.js} +2 -2
- package/dist/client/standalone/assets/{ViewJsonRender-BURuu55Z.js → ViewJsonRender-De5eeIha.js} +3 -3
- package/dist/client/standalone/assets/dist-CAaP5Isp.js +1 -0
- package/dist/client/standalone/assets/iconify-C-CPDXMf.js +2 -0
- package/dist/client/standalone/assets/index-DtZFMvER.css +1 -0
- package/dist/client/standalone/assets/index-hQ4JAD5S.js +3 -0
- package/dist/client/standalone/assets/runtime-core.esm-bundler-Bvz2jy0O.js +1 -0
- package/dist/client/standalone/index.html +6 -5
- package/dist/client/webcomponents.d.ts +1 -21628
- package/dist/client/webcomponents.js +54 -51
- package/dist/config.js +1 -1
- package/dist/constants-DfEeYo9W.js +142 -0
- package/dist/{plugins-DiuKIPkS.js → context-DmXts6Ac.js} +116 -673
- package/dist/{dist-D2Z6bwqJ.js → dist-CCdqIez-.js} +128 -5
- package/dist/dist-DpLy3ojW.js +229 -0
- package/dist/index.d.ts +43 -3
- package/dist/index.js +3 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/plugins-vfc-N600.js +59 -0
- package/dist/{popup-BUPO6e0I.js → popup-DcuzpgO2.js} +114 -55
- package/dist/server-C54I1zbj.js +2 -0
- package/dist/server-DH39-LHL.js +50 -0
- package/dist/server-DSh-GQIq.js +188 -0
- package/dist/standalone-w_GYdx1T.js +33 -0
- package/dist/static-dump-BqRb_x-O.js +65 -0
- package/package.json +12 -15
- package/dist/DockStandalone-DxFEMDp2.js +0 -1256
- package/dist/cli-commands-CnJ4eqDp.js +0 -180
- package/dist/client/standalone/assets/DockStandalone-C8ChyZLh.js +0 -1
- package/dist/client/standalone/assets/LogItem-Mx4UyReX.js +0 -1
- package/dist/client/standalone/assets/ViewBuiltinLogs-C4j4vgSn.js +0 -1
- package/dist/client/standalone/assets/dist-DIlAYcjk.js +0 -1
- package/dist/client/standalone/assets/index-BEyoIK7m.css +0 -1
- package/dist/client/standalone/assets/index-Rpv7PwRD.js +0 -4
- package/dist/client/standalone/assets/runtime-core.esm-bundler-CJlaYmKv.js +0 -1
- package/dist/vue.runtime.esm-bundler-CS1wMbap.js +0 -6988
- /package/dist/{context-internal-CvIHbZq4.js → context-internal-DZpoJjMz.js} +0 -0
- /package/dist/{context-internal-Du6FuGIu.d.ts → context-internal-Ys7Zu3q3.d.ts} +0 -0
- /package/dist/{iconify-BW79QmbD.js → iconify-JodklND-.js} +0 -0
- /package/dist/{utils-DaaVwEUH.js → utils-HWI9S6d-.js} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import { i as __exportAll, n as ansis_default, r as __commonJSMin, t as MARK_INFO } from "./constants-DfEeYo9W.js";
|
|
2
|
+
import { n as createStorage, t as getInternalContext } from "./context-internal-DZpoJjMz.js";
|
|
3
|
+
import { a as setPendingAuth, i as refreshTempAuthToken, r as getTempAuthToken, t as abortPendingAuth } from "./auth-state-DXCxEqSd.js";
|
|
4
|
+
import { t as isObject } from "./utils-HWI9S6d-.js";
|
|
4
5
|
import { createDebug } from "obug";
|
|
5
6
|
import { debounce } from "perfect-debounce";
|
|
6
|
-
import { normalizePath, searchForWorkspaceRoot } from "vite";
|
|
7
7
|
import { toDataURL } from "mlly";
|
|
8
|
-
import { DEFAULT_STATE_USER_SETTINGS, DEVTOOLS_CONNECTION_META_FILENAME, DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID, DEVTOOLS_MOUNT_PATH } from "@vitejs/devtools-kit/constants";
|
|
9
8
|
import { createEventEmitter } from "@vitejs/devtools-kit/utils/events";
|
|
9
|
+
import { DEFAULT_STATE_USER_SETTINGS } from "@vitejs/devtools-kit/constants";
|
|
10
10
|
import { join } from "pathe";
|
|
11
11
|
import { existsSync } from "node:fs";
|
|
12
12
|
import { createSharedState } from "@vitejs/devtools-kit/utils/shared-state";
|
|
@@ -18,48 +18,8 @@ import { stripVTControlCharacters, styleText } from "node:util";
|
|
|
18
18
|
import "node:readline";
|
|
19
19
|
import ot from "node:readline";
|
|
20
20
|
import "node:tty";
|
|
21
|
-
import
|
|
21
|
+
import "node:path";
|
|
22
22
|
import { defineRpcFunction } from "@vitejs/devtools-kit";
|
|
23
|
-
import { humanId } from "@vitejs/devtools-kit/utils/human-id";
|
|
24
|
-
import { networkInterfaces } from "node:os";
|
|
25
|
-
import { createServer } from "node:net";
|
|
26
|
-
import { createApp, eventHandler, fromNodeMiddleware, getQuery, toNodeListener } from "h3";
|
|
27
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
28
|
-
import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/server";
|
|
29
|
-
import { createRpcServer } from "@vitejs/devtools-rpc/server";
|
|
30
|
-
import "node:fs/promises";
|
|
31
|
-
//#region \0rolldown/runtime.js
|
|
32
|
-
var __create = Object.create;
|
|
33
|
-
var __defProp = Object.defineProperty;
|
|
34
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
35
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
36
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
37
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
38
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
39
|
-
var __exportAll = (all, no_symbols) => {
|
|
40
|
-
let target = {};
|
|
41
|
-
for (var name in all) __defProp(target, name, {
|
|
42
|
-
get: all[name],
|
|
43
|
-
enumerable: true
|
|
44
|
-
});
|
|
45
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
46
|
-
return target;
|
|
47
|
-
};
|
|
48
|
-
var __copyProps = (to, from, except, desc) => {
|
|
49
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
50
|
-
key = keys[i];
|
|
51
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
52
|
-
get: ((k) => from[k]).bind(null, key),
|
|
53
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return to;
|
|
57
|
-
};
|
|
58
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
59
|
-
value: mod,
|
|
60
|
-
enumerable: true
|
|
61
|
-
}) : target, mod));
|
|
62
|
-
//#endregion
|
|
63
23
|
//#region src/node/context-utils.ts
|
|
64
24
|
const ContextUtils = { createSimpleClientScript(fn) {
|
|
65
25
|
return {
|
|
@@ -68,6 +28,61 @@ const ContextUtils = { createSimpleClientScript(fn) {
|
|
|
68
28
|
};
|
|
69
29
|
} };
|
|
70
30
|
//#endregion
|
|
31
|
+
//#region src/node/host-commands.ts
|
|
32
|
+
var DevToolsCommandsHost = class {
|
|
33
|
+
commands = /* @__PURE__ */ new Map();
|
|
34
|
+
events = createEventEmitter();
|
|
35
|
+
constructor(context) {
|
|
36
|
+
this.context = context;
|
|
37
|
+
}
|
|
38
|
+
register(command) {
|
|
39
|
+
if (this.commands.has(command.id)) throw new Error(`Command "${command.id}" is already registered`);
|
|
40
|
+
this.commands.set(command.id, command);
|
|
41
|
+
this.events.emit("command:registered", this.toSerializable(command));
|
|
42
|
+
return {
|
|
43
|
+
id: command.id,
|
|
44
|
+
update: (patch) => {
|
|
45
|
+
if ("id" in patch) throw new Error(`Cannot change the id of a command. Use register() to add new commands.`);
|
|
46
|
+
const existing = this.commands.get(command.id);
|
|
47
|
+
if (!existing) throw new Error(`Command "${command.id}" is not registered`);
|
|
48
|
+
Object.assign(existing, patch);
|
|
49
|
+
this.events.emit("command:registered", this.toSerializable(existing));
|
|
50
|
+
},
|
|
51
|
+
unregister: () => this.unregister(command.id)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
unregister(id) {
|
|
55
|
+
const deleted = this.commands.delete(id);
|
|
56
|
+
if (deleted) this.events.emit("command:unregistered", id);
|
|
57
|
+
return deleted;
|
|
58
|
+
}
|
|
59
|
+
async execute(id, ...args) {
|
|
60
|
+
const found = this.findCommand(id);
|
|
61
|
+
if (!found) throw new Error(`Command "${id}" is not registered`);
|
|
62
|
+
if (!found.handler) throw new Error(`Command "${id}" has no handler (group-only command)`);
|
|
63
|
+
return found.handler(...args);
|
|
64
|
+
}
|
|
65
|
+
list() {
|
|
66
|
+
return Array.from(this.commands.values()).map((cmd) => this.toSerializable(cmd));
|
|
67
|
+
}
|
|
68
|
+
findCommand(id) {
|
|
69
|
+
const topLevel = this.commands.get(id);
|
|
70
|
+
if (topLevel) return topLevel;
|
|
71
|
+
for (const cmd of this.commands.values()) if (cmd.children) {
|
|
72
|
+
const child = cmd.children.find((c) => c.id === id);
|
|
73
|
+
if (child) return child;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
toSerializable(cmd) {
|
|
77
|
+
const { handler: _, children, ...rest } = cmd;
|
|
78
|
+
return {
|
|
79
|
+
...rest,
|
|
80
|
+
source: "server",
|
|
81
|
+
...children ? { children: children.map((c) => this.toSerializable(c)) } : {}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
71
86
|
//#region src/node/host-docks.ts
|
|
72
87
|
var DevToolsDockHost = class {
|
|
73
88
|
views = /* @__PURE__ */ new Map();
|
|
@@ -91,8 +106,8 @@ var DevToolsDockHost = class {
|
|
|
91
106
|
title: "Terminals",
|
|
92
107
|
icon: "ph:terminal-duotone",
|
|
93
108
|
category: "~builtin",
|
|
94
|
-
get
|
|
95
|
-
return context.terminals.sessions.size === 0;
|
|
109
|
+
get when() {
|
|
110
|
+
return context.terminals.sessions.size === 0 ? "false" : void 0;
|
|
96
111
|
}
|
|
97
112
|
},
|
|
98
113
|
{
|
|
@@ -1188,167 +1203,6 @@ ${Qe}${i.trimStart()}`), s = 3 + stripVTControlCharacters(i.trimStart()).length)
|
|
|
1188
1203
|
error: (e) => K.message(e, { symbol: styleText("red", Ee) })
|
|
1189
1204
|
};
|
|
1190
1205
|
//#endregion
|
|
1191
|
-
//#region ../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.mjs
|
|
1192
|
-
var import_ansis = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1193
|
-
let e, t, r, { defineProperty: l, setPrototypeOf: n, create: o, keys: s } = Object, i = "", { round: c, max: a } = Math, p = (e) => {
|
|
1194
|
-
let t = /([a-f\d]{3,6})/i.exec(e)?.[1], r = t?.length, l = parseInt(6 ^ r ? 3 ^ r ? "0" : t[0] + t[0] + t[1] + t[1] + t[2] + t[2] : t, 16);
|
|
1195
|
-
return [
|
|
1196
|
-
l >> 16 & 255,
|
|
1197
|
-
l >> 8 & 255,
|
|
1198
|
-
255 & l
|
|
1199
|
-
];
|
|
1200
|
-
}, u = (e, t, r) => e ^ t || t ^ r ? 16 + 36 * c(e / 51) + 6 * c(t / 51) + c(r / 51) : 8 > e ? 16 : e > 248 ? 231 : c(24 * (e - 8) / 247) + 232, d = (e) => {
|
|
1201
|
-
let t, r, l, n, o;
|
|
1202
|
-
return 8 > e ? 30 + e : 16 > e ? e - 8 + 90 : (232 > e ? (o = (e -= 16) % 36, t = (e / 36 | 0) / 5, r = (o / 6 | 0) / 5, l = o % 6 / 5) : t = r = l = (10 * (e - 232) + 8) / 255, n = 2 * a(t, r, l), n ? 30 + (c(l) << 2 | c(r) << 1 | c(t)) + (2 ^ n ? 0 : 60) : 30);
|
|
1203
|
-
}, f = (() => {
|
|
1204
|
-
let r = (e) => o.some(((t) => e.test(t))), l = globalThis, n = l.process ?? {}, o = n.argv ?? [], i = n.env ?? {}, c = -1;
|
|
1205
|
-
try {
|
|
1206
|
-
e = "," + s(i).join(",");
|
|
1207
|
-
} catch (e) {
|
|
1208
|
-
i = {}, c = 0;
|
|
1209
|
-
}
|
|
1210
|
-
let a = "FORCE_COLOR", p = {
|
|
1211
|
-
false: 0,
|
|
1212
|
-
0: 0,
|
|
1213
|
-
1: 1,
|
|
1214
|
-
2: 2,
|
|
1215
|
-
3: 3
|
|
1216
|
-
}[i[a]] ?? -1, u = a in i && p || r(/^--color=?(true|always)?$/);
|
|
1217
|
-
return u && (c = p), ~c || (c = ((r, l, n) => (t = r.TERM, {
|
|
1218
|
-
"24bit": 3,
|
|
1219
|
-
truecolor: 3,
|
|
1220
|
-
ansi256: 2,
|
|
1221
|
-
ansi: 1
|
|
1222
|
-
}[r.COLORTERM] || (r.CI ? /,GITHUB/.test(e) ? 3 : 1 : l && "dumb" !== t ? n ? 3 : /-256/.test(t) ? 2 : 1 : 0)))(i, !!i.PM2_HOME || i.NEXT_RUNTIME?.includes("edge") || !!n.stdout?.isTTY, "win32" === n.platform)), !p || i.NO_COLOR || r(/^--(no-color|color=(false|never))$/) ? 0 : l.window?.chrome || u && !c ? 3 : c;
|
|
1223
|
-
})(), g = {
|
|
1224
|
-
open: i,
|
|
1225
|
-
close: i
|
|
1226
|
-
}, h = 39, b = 49, O = {}, m = ({ p: e }, { open: t, close: l }) => {
|
|
1227
|
-
let o = (e, ...r) => {
|
|
1228
|
-
if (!e) {
|
|
1229
|
-
if (t && t === l) return t;
|
|
1230
|
-
if ((e ?? i) === i) return i;
|
|
1231
|
-
}
|
|
1232
|
-
let n, s = e.raw ? String.raw({ raw: e }, ...r) : i + e, c = o.p, a = c.o, p = c.c;
|
|
1233
|
-
if (s.includes("\x1B")) for (; c; c = c.p) {
|
|
1234
|
-
let { open: e, close: t } = c, r = t.length, l = i, o = 0;
|
|
1235
|
-
if (r) for (; ~(n = s.indexOf(t, o)); o = n + r) l += s.slice(o, n) + e;
|
|
1236
|
-
s = l + s.slice(o);
|
|
1237
|
-
}
|
|
1238
|
-
return a + (s.includes("\n") ? s.replace(/(\r?\n)/g, p + "$1" + a) : s) + p;
|
|
1239
|
-
}, s = t, c = l;
|
|
1240
|
-
return e && (s = e.o + t, c = l + e.c), n(o, r), o.p = {
|
|
1241
|
-
open: t,
|
|
1242
|
-
close: l,
|
|
1243
|
-
o: s,
|
|
1244
|
-
c,
|
|
1245
|
-
p: e
|
|
1246
|
-
}, o.open = s, o.close = c, o;
|
|
1247
|
-
};
|
|
1248
|
-
const w = new function e(t = f) {
|
|
1249
|
-
let s = {
|
|
1250
|
-
Ansis: e,
|
|
1251
|
-
level: t,
|
|
1252
|
-
isSupported: () => a,
|
|
1253
|
-
strip: (e) => e.replace(/[][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, i),
|
|
1254
|
-
extend(e) {
|
|
1255
|
-
for (let t in e) {
|
|
1256
|
-
let r = e[t], l = (typeof r)[0];
|
|
1257
|
-
"s" === l ? (c(t, T(...p(r))), c(_(t), v(...p(r)))) : c(t, r, "f" === l);
|
|
1258
|
-
}
|
|
1259
|
-
return r = o({}, O), n(s, r), s;
|
|
1260
|
-
}
|
|
1261
|
-
}, c = (e, t, r) => {
|
|
1262
|
-
O[e] = { get() {
|
|
1263
|
-
let n = r ? (...e) => m(this, t(...e)) : m(this, t);
|
|
1264
|
-
return l(this, e, { value: n }), n;
|
|
1265
|
-
} };
|
|
1266
|
-
}, a = t > 0, w = (e, t) => a ? {
|
|
1267
|
-
open: `[${e}m`,
|
|
1268
|
-
close: `[${t}m`
|
|
1269
|
-
} : g, y = (e) => (t) => e(...p(t)), R = (e, t) => (r, l, n) => w(`${e}8;2;${r};${l};${n}`, t), $ = (e, t) => (r, l, n) => w(((e, t, r) => d(u(e, t, r)))(r, l, n) + e, t), x = (e) => (t, r, l) => e(u(t, r, l)), T = R(3, h), v = R(4, b), C = (e) => w("38;5;" + e, h), E = (e) => w("48;5;" + e, b);
|
|
1270
|
-
2 === t ? (T = x(C), v = x(E)) : 1 === t && (T = $(0, h), v = $(10, b), C = (e) => w(d(e), h), E = (e) => w(d(e) + 10, b));
|
|
1271
|
-
let M, I = {
|
|
1272
|
-
fg: C,
|
|
1273
|
-
bg: E,
|
|
1274
|
-
rgb: T,
|
|
1275
|
-
bgRgb: v,
|
|
1276
|
-
hex: y(T),
|
|
1277
|
-
bgHex: y(v),
|
|
1278
|
-
visible: g,
|
|
1279
|
-
reset: w(0, 0),
|
|
1280
|
-
bold: w(1, 22),
|
|
1281
|
-
dim: w(2, 22),
|
|
1282
|
-
italic: w(3, 23),
|
|
1283
|
-
underline: w(4, 24),
|
|
1284
|
-
inverse: w(7, 27),
|
|
1285
|
-
hidden: w(8, 28),
|
|
1286
|
-
strikethrough: w(9, 29)
|
|
1287
|
-
}, _ = (e) => "bg" + e[0].toUpperCase() + e.slice(1), k = "Bright";
|
|
1288
|
-
return "black,red,green,yellow,blue,magenta,cyan,white,gray".split(",").map(((e, t) => {
|
|
1289
|
-
M = _(e), 8 > t ? (I[e + k] = w(90 + t, h), I[M + k] = w(100 + t, b)) : t = 60, I[e] = w(30 + t, h), I[M] = w(40 + t, b);
|
|
1290
|
-
})), s.extend(I);
|
|
1291
|
-
}();
|
|
1292
|
-
module.exports = w, w.default = w;
|
|
1293
|
-
})))(), 1);
|
|
1294
|
-
var ansis_default = import_ansis.default;
|
|
1295
|
-
const { Ansis, fg, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
|
|
1296
|
-
//#endregion
|
|
1297
|
-
//#region src/node/auth-state.ts
|
|
1298
|
-
let pendingAuth = null;
|
|
1299
|
-
let tempAuthToken = generateTempId();
|
|
1300
|
-
function generateTempId() {
|
|
1301
|
-
return humanId({
|
|
1302
|
-
separator: "-",
|
|
1303
|
-
capitalize: false
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
function getTempAuthToken() {
|
|
1307
|
-
return tempAuthToken;
|
|
1308
|
-
}
|
|
1309
|
-
function refreshTempAuthToken() {
|
|
1310
|
-
tempAuthToken = generateTempId();
|
|
1311
|
-
return tempAuthToken;
|
|
1312
|
-
}
|
|
1313
|
-
function setPendingAuth(request) {
|
|
1314
|
-
pendingAuth = request;
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Abort and clean up any existing pending auth request.
|
|
1318
|
-
*/
|
|
1319
|
-
function abortPendingAuth() {
|
|
1320
|
-
if (pendingAuth) {
|
|
1321
|
-
pendingAuth.abortController.abort();
|
|
1322
|
-
clearTimeout(pendingAuth.timeout);
|
|
1323
|
-
pendingAuth = null;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* Consume the temp auth ID: verify it matches, trust the pending client, and clean up.
|
|
1328
|
-
* Returns the client's authToken if successful, null otherwise.
|
|
1329
|
-
*/
|
|
1330
|
-
function consumeTempAuthToken(id, storage) {
|
|
1331
|
-
if (id !== tempAuthToken || !pendingAuth) return null;
|
|
1332
|
-
const { clientAuthToken, session, ua, origin, resolve } = pendingAuth;
|
|
1333
|
-
storage.mutate((state) => {
|
|
1334
|
-
state.trusted[clientAuthToken] = {
|
|
1335
|
-
authToken: clientAuthToken,
|
|
1336
|
-
ua,
|
|
1337
|
-
origin,
|
|
1338
|
-
timestamp: Date.now()
|
|
1339
|
-
};
|
|
1340
|
-
});
|
|
1341
|
-
session.meta.clientAuthToken = clientAuthToken;
|
|
1342
|
-
session.meta.isTrusted = true;
|
|
1343
|
-
resolve({ isTrusted: true });
|
|
1344
|
-
abortPendingAuth();
|
|
1345
|
-
refreshTempAuthToken();
|
|
1346
|
-
return clientAuthToken;
|
|
1347
|
-
}
|
|
1348
|
-
ansis_default.green("✔");
|
|
1349
|
-
const MARK_INFO = ansis_default.blue("ℹ");
|
|
1350
|
-
ansis_default.red("✖");
|
|
1351
|
-
//#endregion
|
|
1352
1206
|
//#region src/node/rpc/anonymous/auth.ts
|
|
1353
1207
|
const AUTH_TIMEOUT_MS = 6e4;
|
|
1354
1208
|
const anonymousAuth = defineRpcFunction({
|
|
@@ -1452,6 +1306,28 @@ const anonymousAuth = defineRpcFunction({
|
|
|
1452
1306
|
}
|
|
1453
1307
|
});
|
|
1454
1308
|
//#endregion
|
|
1309
|
+
//#region src/node/rpc/internal/commands-execute.ts
|
|
1310
|
+
const commandsExecute = defineRpcFunction({
|
|
1311
|
+
name: "devtoolskit:internal:commands:execute",
|
|
1312
|
+
type: "action",
|
|
1313
|
+
setup: (context) => {
|
|
1314
|
+
return { async handler(id, ...args) {
|
|
1315
|
+
return context.commands.execute(id, ...args);
|
|
1316
|
+
} };
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
//#endregion
|
|
1320
|
+
//#region src/node/rpc/internal/commands-list.ts
|
|
1321
|
+
const commandsList = defineRpcFunction({
|
|
1322
|
+
name: "devtoolskit:internal:commands:list",
|
|
1323
|
+
type: "static",
|
|
1324
|
+
setup: (context) => {
|
|
1325
|
+
return { async handler() {
|
|
1326
|
+
return context.commands.list();
|
|
1327
|
+
} };
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
//#endregion
|
|
1455
1331
|
//#region src/node/rpc/internal/docks-on-launch.ts
|
|
1456
1332
|
const docksOnLaunch = defineRpcFunction({
|
|
1457
1333
|
name: "devtoolskit:internal:docks:on-launch",
|
|
@@ -1695,6 +1571,8 @@ const builtinPublicRpcDeclarations = [defineRpcFunction({
|
|
|
1695
1571
|
})];
|
|
1696
1572
|
const builtinAnonymousRpcDeclarations = [anonymousAuth];
|
|
1697
1573
|
const builtinInternalRpcDeclarations = [
|
|
1574
|
+
commandsExecute,
|
|
1575
|
+
commandsList,
|
|
1698
1576
|
docksOnLaunch,
|
|
1699
1577
|
logsAdd,
|
|
1700
1578
|
logsClear,
|
|
@@ -1716,6 +1594,7 @@ const builtinRpcDeclarations = [
|
|
|
1716
1594
|
];
|
|
1717
1595
|
//#endregion
|
|
1718
1596
|
//#region src/node/context.ts
|
|
1597
|
+
var context_exports = /* @__PURE__ */ __exportAll({ createDevToolsContext: () => createDevToolsContext });
|
|
1719
1598
|
const debugSetup = createDebug("vite:devtools:context:setup");
|
|
1720
1599
|
function shouldSkipSetupByCapabilities(plugin, mode) {
|
|
1721
1600
|
const modeCapabilities = plugin.devtools?.capabilities?.[mode];
|
|
@@ -1725,6 +1604,7 @@ function shouldSkipSetupByCapabilities(plugin, mode) {
|
|
|
1725
1604
|
}
|
|
1726
1605
|
async function createDevToolsContext(viteConfig, viteServer) {
|
|
1727
1606
|
const cwd = viteConfig.root;
|
|
1607
|
+
const { searchForWorkspaceRoot } = await import("vite");
|
|
1728
1608
|
const context = {
|
|
1729
1609
|
cwd,
|
|
1730
1610
|
workspaceRoot: searchForWorkspaceRoot(cwd) ?? cwd,
|
|
@@ -1737,6 +1617,7 @@ async function createDevToolsContext(viteConfig, viteServer) {
|
|
|
1737
1617
|
utils: ContextUtils,
|
|
1738
1618
|
terminals: void 0,
|
|
1739
1619
|
logs: void 0,
|
|
1620
|
+
commands: void 0,
|
|
1740
1621
|
createJsonRenderer: void 0
|
|
1741
1622
|
};
|
|
1742
1623
|
const rpcHost = new RpcFunctionsHost(context);
|
|
@@ -1744,14 +1625,16 @@ async function createDevToolsContext(viteConfig, viteServer) {
|
|
|
1744
1625
|
const viewsHost = new DevToolsViewHost(context);
|
|
1745
1626
|
const terminalsHost = new DevToolsTerminalHost(context);
|
|
1746
1627
|
const logsHost = new DevToolsLogsHost(context);
|
|
1628
|
+
const commandsHost = new DevToolsCommandsHost(context);
|
|
1747
1629
|
context.rpc = rpcHost;
|
|
1748
1630
|
context.docks = docksHost;
|
|
1749
1631
|
context.views = viewsHost;
|
|
1750
1632
|
context.terminals = terminalsHost;
|
|
1751
1633
|
context.logs = logsHost;
|
|
1634
|
+
context.commands = commandsHost;
|
|
1752
1635
|
let jrCounter = 0;
|
|
1753
1636
|
context.createJsonRenderer = (initialSpec) => {
|
|
1754
|
-
const stateKey = `
|
|
1637
|
+
const stateKey = `devtoolskit:internal:json-render:${jrCounter++}`;
|
|
1755
1638
|
const statePromise = rpcHost.sharedState.get(stateKey, { initialValue: initialSpec });
|
|
1756
1639
|
return {
|
|
1757
1640
|
_stateKey: stateKey,
|
|
@@ -1798,6 +1681,28 @@ async function createDevToolsContext(viteConfig, viteServer) {
|
|
|
1798
1681
|
logsHost.events.on("log:updated", () => debouncedLogsUpdate());
|
|
1799
1682
|
logsHost.events.on("log:removed", () => debouncedLogsUpdate());
|
|
1800
1683
|
logsHost.events.on("log:cleared", () => debouncedLogsUpdate());
|
|
1684
|
+
const commandsSharedState = await rpcHost.sharedState.get("devtoolskit:internal:commands", { initialValue: [] });
|
|
1685
|
+
const debouncedCommandsSync = debounce(() => {
|
|
1686
|
+
commandsSharedState.mutate(() => commandsHost.list());
|
|
1687
|
+
}, context.mode === "build" ? 0 : 10);
|
|
1688
|
+
commandsHost.events.on("command:registered", () => debouncedCommandsSync());
|
|
1689
|
+
commandsHost.events.on("command:unregistered", () => debouncedCommandsSync());
|
|
1690
|
+
commandsHost.register({
|
|
1691
|
+
id: "vite:open-in-editor",
|
|
1692
|
+
title: "Open in Editor",
|
|
1693
|
+
icon: "ph:pencil-duotone",
|
|
1694
|
+
category: "editor",
|
|
1695
|
+
showInPalette: false,
|
|
1696
|
+
handler: (path) => rpcHost.invokeLocal("vite:core:open-in-editor", path)
|
|
1697
|
+
});
|
|
1698
|
+
commandsHost.register({
|
|
1699
|
+
id: "vite:open-in-finder",
|
|
1700
|
+
title: "Open in Finder",
|
|
1701
|
+
icon: "ph:folder-open-duotone",
|
|
1702
|
+
category: "editor",
|
|
1703
|
+
showInPalette: false,
|
|
1704
|
+
handler: (path) => rpcHost.invokeLocal("vite:core:open-in-finder", path)
|
|
1705
|
+
});
|
|
1801
1706
|
const plugins = viteConfig.plugins.filter((plugin) => "devtools" in plugin);
|
|
1802
1707
|
for (const plugin of plugins) {
|
|
1803
1708
|
if (!plugin.devtools?.setup) continue;
|
|
@@ -1816,466 +1721,4 @@ async function createDevToolsContext(viteConfig, viteServer) {
|
|
|
1816
1721
|
return context;
|
|
1817
1722
|
}
|
|
1818
1723
|
//#endregion
|
|
1819
|
-
|
|
1820
|
-
function DevToolsInjection() {
|
|
1821
|
-
return {
|
|
1822
|
-
name: "vite:devtools:injection",
|
|
1823
|
-
enforce: "post",
|
|
1824
|
-
transformIndexHtml() {
|
|
1825
|
-
return [{
|
|
1826
|
-
tag: "script",
|
|
1827
|
-
attrs: {
|
|
1828
|
-
src: `/@fs/${process$1.env.VITE_DEVTOOLS_LOCAL_DEV ? normalizePath(join$1(dirDist, "..", "src/client/inject/index.ts")) : normalizePath(join$1(dirDist, "client/inject.js"))}`,
|
|
1829
|
-
type: "module"
|
|
1830
|
-
},
|
|
1831
|
-
injectTo: "body"
|
|
1832
|
-
}];
|
|
1833
|
-
}
|
|
1834
|
-
};
|
|
1835
|
-
}
|
|
1836
|
-
//#endregion
|
|
1837
|
-
//#region ../../node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
|
|
1838
|
-
const unsafePorts = /* @__PURE__ */ new Set([
|
|
1839
|
-
1,
|
|
1840
|
-
7,
|
|
1841
|
-
9,
|
|
1842
|
-
11,
|
|
1843
|
-
13,
|
|
1844
|
-
15,
|
|
1845
|
-
17,
|
|
1846
|
-
19,
|
|
1847
|
-
20,
|
|
1848
|
-
21,
|
|
1849
|
-
22,
|
|
1850
|
-
23,
|
|
1851
|
-
25,
|
|
1852
|
-
37,
|
|
1853
|
-
42,
|
|
1854
|
-
43,
|
|
1855
|
-
53,
|
|
1856
|
-
69,
|
|
1857
|
-
77,
|
|
1858
|
-
79,
|
|
1859
|
-
87,
|
|
1860
|
-
95,
|
|
1861
|
-
101,
|
|
1862
|
-
102,
|
|
1863
|
-
103,
|
|
1864
|
-
104,
|
|
1865
|
-
109,
|
|
1866
|
-
110,
|
|
1867
|
-
111,
|
|
1868
|
-
113,
|
|
1869
|
-
115,
|
|
1870
|
-
117,
|
|
1871
|
-
119,
|
|
1872
|
-
123,
|
|
1873
|
-
135,
|
|
1874
|
-
137,
|
|
1875
|
-
139,
|
|
1876
|
-
143,
|
|
1877
|
-
161,
|
|
1878
|
-
179,
|
|
1879
|
-
389,
|
|
1880
|
-
427,
|
|
1881
|
-
465,
|
|
1882
|
-
512,
|
|
1883
|
-
513,
|
|
1884
|
-
514,
|
|
1885
|
-
515,
|
|
1886
|
-
526,
|
|
1887
|
-
530,
|
|
1888
|
-
531,
|
|
1889
|
-
532,
|
|
1890
|
-
540,
|
|
1891
|
-
548,
|
|
1892
|
-
554,
|
|
1893
|
-
556,
|
|
1894
|
-
563,
|
|
1895
|
-
587,
|
|
1896
|
-
601,
|
|
1897
|
-
636,
|
|
1898
|
-
989,
|
|
1899
|
-
990,
|
|
1900
|
-
993,
|
|
1901
|
-
995,
|
|
1902
|
-
1719,
|
|
1903
|
-
1720,
|
|
1904
|
-
1723,
|
|
1905
|
-
2049,
|
|
1906
|
-
3659,
|
|
1907
|
-
4045,
|
|
1908
|
-
5060,
|
|
1909
|
-
5061,
|
|
1910
|
-
6e3,
|
|
1911
|
-
6566,
|
|
1912
|
-
6665,
|
|
1913
|
-
6666,
|
|
1914
|
-
6667,
|
|
1915
|
-
6668,
|
|
1916
|
-
6669,
|
|
1917
|
-
6697,
|
|
1918
|
-
10080
|
|
1919
|
-
]);
|
|
1920
|
-
function isUnsafePort(port) {
|
|
1921
|
-
return unsafePorts.has(port);
|
|
1922
|
-
}
|
|
1923
|
-
function isSafePort(port) {
|
|
1924
|
-
return !isUnsafePort(port);
|
|
1925
|
-
}
|
|
1926
|
-
var GetPortError = class extends Error {
|
|
1927
|
-
constructor(message, opts) {
|
|
1928
|
-
super(message, opts);
|
|
1929
|
-
this.message = message;
|
|
1930
|
-
}
|
|
1931
|
-
name = "GetPortError";
|
|
1932
|
-
};
|
|
1933
|
-
function _log(verbose, message) {
|
|
1934
|
-
if (verbose) console.log(`[get-port] ${message}`);
|
|
1935
|
-
}
|
|
1936
|
-
function _generateRange(from, to) {
|
|
1937
|
-
if (to < from) return [];
|
|
1938
|
-
const r = [];
|
|
1939
|
-
for (let index = from; index <= to; index++) r.push(index);
|
|
1940
|
-
return r;
|
|
1941
|
-
}
|
|
1942
|
-
function _tryPort(port, host) {
|
|
1943
|
-
return new Promise((resolve) => {
|
|
1944
|
-
const server = createServer();
|
|
1945
|
-
server.unref();
|
|
1946
|
-
server.on("error", () => {
|
|
1947
|
-
resolve(false);
|
|
1948
|
-
});
|
|
1949
|
-
server.listen({
|
|
1950
|
-
port,
|
|
1951
|
-
host
|
|
1952
|
-
}, () => {
|
|
1953
|
-
const { port: port2 } = server.address();
|
|
1954
|
-
server.close(() => {
|
|
1955
|
-
resolve(isSafePort(port2) && port2);
|
|
1956
|
-
});
|
|
1957
|
-
});
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
function _getLocalHosts(additional) {
|
|
1961
|
-
const hosts = new Set(additional);
|
|
1962
|
-
for (const _interface of Object.values(networkInterfaces())) for (const config of _interface || []) if (config.address && !config.internal && !config.address.startsWith("fe80::") && !config.address.startsWith("169.254")) hosts.add(config.address);
|
|
1963
|
-
return [...hosts];
|
|
1964
|
-
}
|
|
1965
|
-
async function _findPort(ports, host) {
|
|
1966
|
-
for (const port of ports) {
|
|
1967
|
-
const r = await _tryPort(port, host);
|
|
1968
|
-
if (r) return r;
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
function _fmtOnHost(hostname) {
|
|
1972
|
-
return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
|
|
1973
|
-
}
|
|
1974
|
-
const HOSTNAME_RE = /^(?!-)[\d.:A-Za-z-]{1,63}(?<!-)$/;
|
|
1975
|
-
function _validateHostname(hostname, _public, verbose) {
|
|
1976
|
-
if (hostname && !HOSTNAME_RE.test(hostname)) {
|
|
1977
|
-
const fallbackHost = _public ? "0.0.0.0" : "127.0.0.1";
|
|
1978
|
-
_log(verbose, `Invalid hostname: ${JSON.stringify(hostname)}. Using ${JSON.stringify(fallbackHost)} as fallback.`);
|
|
1979
|
-
return fallbackHost;
|
|
1980
|
-
}
|
|
1981
|
-
return hostname;
|
|
1982
|
-
}
|
|
1983
|
-
async function getPort(_userOptions = {}) {
|
|
1984
|
-
if (typeof _userOptions === "number" || typeof _userOptions === "string") _userOptions = { port: Number.parseInt(_userOptions + "") || 0 };
|
|
1985
|
-
const _port = Number(_userOptions.port ?? process.env.PORT);
|
|
1986
|
-
const _userSpecifiedAnyPort = Boolean(_userOptions.port || _userOptions.ports?.length || _userOptions.portRange?.length);
|
|
1987
|
-
const options = {
|
|
1988
|
-
random: _port === 0,
|
|
1989
|
-
ports: [],
|
|
1990
|
-
portRange: [],
|
|
1991
|
-
alternativePortRange: _userSpecifiedAnyPort ? [] : [3e3, 3100],
|
|
1992
|
-
verbose: false,
|
|
1993
|
-
..._userOptions,
|
|
1994
|
-
port: _port,
|
|
1995
|
-
host: _validateHostname(_userOptions.host ?? process.env.HOST, _userOptions.public, _userOptions.verbose)
|
|
1996
|
-
};
|
|
1997
|
-
if (options.random && !_userSpecifiedAnyPort) return getRandomPort(options.host);
|
|
1998
|
-
const portsToCheck = [
|
|
1999
|
-
options.port,
|
|
2000
|
-
...options.ports,
|
|
2001
|
-
..._generateRange(...options.portRange)
|
|
2002
|
-
].filter((port) => {
|
|
2003
|
-
if (!port) return false;
|
|
2004
|
-
if (!isSafePort(port)) {
|
|
2005
|
-
_log(options.verbose, `Ignoring unsafe port: ${port}`);
|
|
2006
|
-
return false;
|
|
2007
|
-
}
|
|
2008
|
-
return true;
|
|
2009
|
-
});
|
|
2010
|
-
if (portsToCheck.length === 0) portsToCheck.push(3e3);
|
|
2011
|
-
let availablePort = await _findPort(portsToCheck, options.host);
|
|
2012
|
-
if (!availablePort && options.alternativePortRange.length > 0) {
|
|
2013
|
-
availablePort = await _findPort(_generateRange(...options.alternativePortRange), options.host);
|
|
2014
|
-
if (portsToCheck.length > 0) {
|
|
2015
|
-
let message = `Unable to find an available port (tried ${portsToCheck.join("-")} ${_fmtOnHost(options.host)}).`;
|
|
2016
|
-
if (availablePort) message += ` Using alternative port ${availablePort}.`;
|
|
2017
|
-
_log(options.verbose, message);
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
if (!availablePort && _userOptions.random !== false) {
|
|
2021
|
-
availablePort = await getRandomPort(options.host);
|
|
2022
|
-
if (availablePort) _log(options.verbose, `Using random port ${availablePort}`);
|
|
2023
|
-
}
|
|
2024
|
-
if (!availablePort) {
|
|
2025
|
-
const triedRanges = [
|
|
2026
|
-
options.port,
|
|
2027
|
-
options.portRange.join("-"),
|
|
2028
|
-
options.alternativePortRange.join("-")
|
|
2029
|
-
].filter(Boolean).join(", ");
|
|
2030
|
-
throw new GetPortError(`Unable to find an available port ${_fmtOnHost(options.host)} (tried ${triedRanges})`);
|
|
2031
|
-
}
|
|
2032
|
-
return availablePort;
|
|
2033
|
-
}
|
|
2034
|
-
async function getRandomPort(host) {
|
|
2035
|
-
const port = await checkPort(0, host);
|
|
2036
|
-
if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
|
|
2037
|
-
return port;
|
|
2038
|
-
}
|
|
2039
|
-
async function checkPort(port, host = process.env.HOST, verbose) {
|
|
2040
|
-
if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
|
|
2041
|
-
if (!Array.isArray(host)) return _tryPort(port, host);
|
|
2042
|
-
for (const _host of host) {
|
|
2043
|
-
const _port = await _tryPort(port, _host);
|
|
2044
|
-
if (_port === false) {
|
|
2045
|
-
if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
|
|
2046
|
-
return false;
|
|
2047
|
-
}
|
|
2048
|
-
if (port === 0 && _port !== 0) port = _port;
|
|
2049
|
-
}
|
|
2050
|
-
return port;
|
|
2051
|
-
}
|
|
2052
|
-
//#endregion
|
|
2053
|
-
//#region src/node/ws.ts
|
|
2054
|
-
const debugInvoked = createDebug("vite:devtools:rpc:invoked");
|
|
2055
|
-
const ANONYMOUS_SCOPE = "vite:anonymous:";
|
|
2056
|
-
async function createWsServer(options) {
|
|
2057
|
-
const rpcHost = options.context.rpc;
|
|
2058
|
-
const host = options.hostWebSocket ?? "localhost";
|
|
2059
|
-
const https = options.context.viteConfig.server.https;
|
|
2060
|
-
const port = options.portWebSocket ?? await getPort({
|
|
2061
|
-
port: 7812,
|
|
2062
|
-
host,
|
|
2063
|
-
random: true
|
|
2064
|
-
});
|
|
2065
|
-
const wsClients = /* @__PURE__ */ new Set();
|
|
2066
|
-
const context = options.context;
|
|
2067
|
-
const contextInternal = getInternalContext(context);
|
|
2068
|
-
const isClientAuthDisabled = context.mode === "build" || context.viteConfig.devtools?.config?.clientAuth === false || process$1.env.VITE_DEVTOOLS_DISABLE_CLIENT_AUTH === "true";
|
|
2069
|
-
if (isClientAuthDisabled) console.warn("[Vite DevTools] Client authentication is disabled. Any browser can connect to the devtools and access to your server and filesystem.");
|
|
2070
|
-
const preset = createWsRpcPreset({
|
|
2071
|
-
port,
|
|
2072
|
-
host,
|
|
2073
|
-
https,
|
|
2074
|
-
onConnected: (ws, req, meta) => {
|
|
2075
|
-
const authToken = new URL(req.url ?? "", "http://localhost").searchParams.get("vite_devtools_auth_token") ?? void 0;
|
|
2076
|
-
if (isClientAuthDisabled) meta.isTrusted = true;
|
|
2077
|
-
else if (authToken && contextInternal.storage.auth.value().trusted[authToken]) {
|
|
2078
|
-
meta.isTrusted = true;
|
|
2079
|
-
meta.clientAuthToken = authToken;
|
|
2080
|
-
} else if (authToken && ((context.viteConfig.devtools?.config)?.clientAuthTokens ?? []).includes(authToken)) {
|
|
2081
|
-
meta.isTrusted = true;
|
|
2082
|
-
meta.clientAuthToken = authToken;
|
|
2083
|
-
}
|
|
2084
|
-
wsClients.add(ws);
|
|
2085
|
-
const color = meta.isTrusted ? ansis_default.green : ansis_default.yellow;
|
|
2086
|
-
const trustedKeys = Object.keys(contextInternal.storage.auth.value().trusted);
|
|
2087
|
-
console.log(color`${MARK_INFO} Websocket client connected. [${meta.id}] [${meta.clientAuthToken}] (${meta.isTrusted ? "trusted" : "untrusted"}) authToken=${authToken} trustedKeys=${JSON.stringify(trustedKeys)} isClientAuthDisabled=${isClientAuthDisabled}`);
|
|
2088
|
-
},
|
|
2089
|
-
onDisconnected: (ws, meta) => {
|
|
2090
|
-
wsClients.delete(ws);
|
|
2091
|
-
console.log(ansis_default.red`${MARK_INFO} Websocket client disconnected. [${meta.id}]`);
|
|
2092
|
-
}
|
|
2093
|
-
});
|
|
2094
|
-
const asyncStorage = new AsyncLocalStorage();
|
|
2095
|
-
const rpcGroup = createRpcServer(rpcHost.functions, {
|
|
2096
|
-
preset,
|
|
2097
|
-
rpcOptions: {
|
|
2098
|
-
onFunctionError(error, name) {
|
|
2099
|
-
console.error(ansis_default.red`⬢ RPC error on executing "${ansis_default.bold(name)}":`);
|
|
2100
|
-
console.error(error);
|
|
2101
|
-
},
|
|
2102
|
-
onGeneralError(error) {
|
|
2103
|
-
console.error(ansis_default.red`⬢ RPC error on executing rpc`);
|
|
2104
|
-
console.error(error);
|
|
2105
|
-
},
|
|
2106
|
-
resolver(name, fn) {
|
|
2107
|
-
const rpc = this;
|
|
2108
|
-
if (!name.startsWith(ANONYMOUS_SCOPE) && !rpc.$meta.isTrusted) return () => {
|
|
2109
|
-
throw new Error(`Unauthorized access to method ${JSON.stringify(name)} from client [${rpc.$meta.id}]`);
|
|
2110
|
-
};
|
|
2111
|
-
if (!fn) return void 0;
|
|
2112
|
-
return async function(...args) {
|
|
2113
|
-
debugInvoked(`${JSON.stringify(name)} from #${rpc.$meta.id}`);
|
|
2114
|
-
return await asyncStorage.run({
|
|
2115
|
-
rpc,
|
|
2116
|
-
meta: rpc.$meta
|
|
2117
|
-
}, async () => {
|
|
2118
|
-
return (await fn).apply(this, args);
|
|
2119
|
-
});
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
});
|
|
2124
|
-
rpcHost._rpcGroup = rpcGroup;
|
|
2125
|
-
rpcHost._asyncStorage = asyncStorage;
|
|
2126
|
-
const getConnectionMeta = async () => {
|
|
2127
|
-
return {
|
|
2128
|
-
backend: "websocket",
|
|
2129
|
-
websocket: port
|
|
2130
|
-
};
|
|
2131
|
-
};
|
|
2132
|
-
return {
|
|
2133
|
-
port,
|
|
2134
|
-
rpc: rpcGroup,
|
|
2135
|
-
rpcHost,
|
|
2136
|
-
getConnectionMeta
|
|
2137
|
-
};
|
|
2138
|
-
}
|
|
2139
|
-
//#endregion
|
|
2140
|
-
//#region src/node/server.ts
|
|
2141
|
-
function generateAuthPageHtml() {
|
|
2142
|
-
return `<!DOCTYPE html>
|
|
2143
|
-
<html>
|
|
2144
|
-
<head>
|
|
2145
|
-
<title>Vite DevTools Authorization</title>
|
|
2146
|
-
<style>
|
|
2147
|
-
html { font-family: system-ui, sans-serif; padding: 2rem; }
|
|
2148
|
-
body { height: 80vh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; }
|
|
2149
|
-
#message { font-size: 1.2rem; }
|
|
2150
|
-
@media (prefers-color-scheme: dark) { html { background: #1a1a1a; color: #e0e0e0; } }
|
|
2151
|
-
</style>
|
|
2152
|
-
</head>
|
|
2153
|
-
<body>
|
|
2154
|
-
<div id="message">Verifying...</div>
|
|
2155
|
-
<script>
|
|
2156
|
-
const query = new URLSearchParams(location.search)
|
|
2157
|
-
const id = query.get('id')
|
|
2158
|
-
const el = document.getElementById('message')
|
|
2159
|
-
|
|
2160
|
-
if (!id) {
|
|
2161
|
-
el.textContent = '\\u26a0\\ufe0f No auth token found. Please check your URL.'
|
|
2162
|
-
el.style.color = '#df513f'
|
|
2163
|
-
} else {
|
|
2164
|
-
fetch(location.pathname.replace(/\\/$/, '') + '-verify?id=' + encodeURIComponent(id))
|
|
2165
|
-
.then(async (r) => {
|
|
2166
|
-
if (r.status !== 200) throw new Error(await r.text())
|
|
2167
|
-
const data = await r.json()
|
|
2168
|
-
const authToken = data.authToken
|
|
2169
|
-
|
|
2170
|
-
localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__', authToken)
|
|
2171
|
-
|
|
2172
|
-
try {
|
|
2173
|
-
const bc = new BroadcastChannel('vite-devtools-auth')
|
|
2174
|
-
bc.postMessage({ type: 'auth-update', authToken: authToken })
|
|
2175
|
-
} catch {}
|
|
2176
|
-
|
|
2177
|
-
el.textContent = '\\u2705 Authorized! You can close this window now.'
|
|
2178
|
-
window.close()
|
|
2179
|
-
})
|
|
2180
|
-
.catch((err) => {
|
|
2181
|
-
el.textContent = '\\u26a0\\ufe0f Failed to authorize: ' + err.message
|
|
2182
|
-
el.style.color = '#df513f'
|
|
2183
|
-
})
|
|
2184
|
-
}
|
|
2185
|
-
<\/script>
|
|
2186
|
-
</body>
|
|
2187
|
-
</html>`;
|
|
2188
|
-
}
|
|
2189
|
-
async function createDevToolsMiddleware(options) {
|
|
2190
|
-
const h3 = createApp();
|
|
2191
|
-
const contextInternal = getInternalContext(options.context);
|
|
2192
|
-
const { rpc, getConnectionMeta } = await createWsServer(options);
|
|
2193
|
-
h3.use(`/${DEVTOOLS_CONNECTION_META_FILENAME}`, eventHandler(async (event) => {
|
|
2194
|
-
event.node.res.setHeader("Content-Type", "application/json");
|
|
2195
|
-
return event.node.res.end(JSON.stringify(await getConnectionMeta()));
|
|
2196
|
-
}));
|
|
2197
|
-
h3.use("/auth-verify", eventHandler((event) => {
|
|
2198
|
-
const { id } = getQuery(event);
|
|
2199
|
-
if (!id) {
|
|
2200
|
-
event.node.res.statusCode = 400;
|
|
2201
|
-
return event.node.res.end("Missing id parameter");
|
|
2202
|
-
}
|
|
2203
|
-
const clientAuthToken = consumeTempAuthToken(id, contextInternal.storage.auth);
|
|
2204
|
-
if (!clientAuthToken) {
|
|
2205
|
-
event.node.res.statusCode = 403;
|
|
2206
|
-
return event.node.res.end("Invalid or expired auth token");
|
|
2207
|
-
}
|
|
2208
|
-
event.node.res.setHeader("Content-Type", "application/json");
|
|
2209
|
-
return event.node.res.end(JSON.stringify({ authToken: clientAuthToken }));
|
|
2210
|
-
}));
|
|
2211
|
-
h3.use("/auth", eventHandler((event) => {
|
|
2212
|
-
event.node.res.setHeader("Content-Type", "text/html");
|
|
2213
|
-
return event.node.res.end(generateAuthPageHtml());
|
|
2214
|
-
}));
|
|
2215
|
-
h3.use(fromNodeMiddleware(sirv(dirClientStandalone, {
|
|
2216
|
-
dev: true,
|
|
2217
|
-
single: true
|
|
2218
|
-
})));
|
|
2219
|
-
return {
|
|
2220
|
-
h3,
|
|
2221
|
-
rpc,
|
|
2222
|
-
middleware: toNodeListener(h3),
|
|
2223
|
-
getConnectionMeta
|
|
2224
|
-
};
|
|
2225
|
-
}
|
|
2226
|
-
//#endregion
|
|
2227
|
-
//#region src/node/plugins/server.ts
|
|
2228
|
-
/**
|
|
2229
|
-
* Core plugin for enabling Vite DevTools
|
|
2230
|
-
*/
|
|
2231
|
-
function renderDockImportsMap(docks) {
|
|
2232
|
-
const map = /* @__PURE__ */ new Map();
|
|
2233
|
-
for (const dock of docks) {
|
|
2234
|
-
const id = `${dock.type}:${dock.id}`;
|
|
2235
|
-
if (dock.type === "action") map.set(id, dock.action);
|
|
2236
|
-
else if (dock.type === "custom-render") map.set(id, dock.renderer);
|
|
2237
|
-
else if (dock.type === "iframe" && dock.clientScript) map.set(id, dock.clientScript);
|
|
2238
|
-
}
|
|
2239
|
-
return [
|
|
2240
|
-
`export const importsMap = {`,
|
|
2241
|
-
...[...map.entries()].filter(([, entry]) => entry != null).map(([id, { importFrom, importName }]) => ` [${JSON.stringify(id)}]: () => import(${JSON.stringify(importFrom)}).then(r => r[${JSON.stringify(importName ?? "default")}]),`),
|
|
2242
|
-
"}"
|
|
2243
|
-
].join("\n");
|
|
2244
|
-
}
|
|
2245
|
-
function DevToolsServer() {
|
|
2246
|
-
let context;
|
|
2247
|
-
return {
|
|
2248
|
-
name: "vite:devtools:server",
|
|
2249
|
-
enforce: "post",
|
|
2250
|
-
apply: "serve",
|
|
2251
|
-
async configureServer(viteDevServer) {
|
|
2252
|
-
context = await createDevToolsContext(viteDevServer.config, viteDevServer);
|
|
2253
|
-
const host = viteDevServer.config.server.host === true ? "0.0.0.0" : viteDevServer.config.server.host || "localhost";
|
|
2254
|
-
const { middleware } = await createDevToolsMiddleware({
|
|
2255
|
-
cwd: viteDevServer.config.root,
|
|
2256
|
-
hostWebSocket: host,
|
|
2257
|
-
context
|
|
2258
|
-
});
|
|
2259
|
-
viteDevServer.middlewares.use(DEVTOOLS_MOUNT_PATH, middleware);
|
|
2260
|
-
},
|
|
2261
|
-
resolveId(id) {
|
|
2262
|
-
if (id === DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID) return id;
|
|
2263
|
-
},
|
|
2264
|
-
load(id) {
|
|
2265
|
-
if (id === DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID) {
|
|
2266
|
-
if (!context) throw new Error("DevTools context is not initialized");
|
|
2267
|
-
return renderDockImportsMap(context.docks.values());
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
};
|
|
2271
|
-
}
|
|
2272
|
-
//#endregion
|
|
2273
|
-
//#region src/node/plugins/index.ts
|
|
2274
|
-
async function DevTools(options = {}) {
|
|
2275
|
-
const { builtinDevTools = true } = options;
|
|
2276
|
-
const plugins = [DevToolsInjection(), DevToolsServer()];
|
|
2277
|
-
if (builtinDevTools) plugins.push(await import("@vitejs/devtools-rolldown").then((m) => m.DevToolsRolldownUI()));
|
|
2278
|
-
return plugins;
|
|
2279
|
-
}
|
|
2280
|
-
//#endregion
|
|
2281
|
-
export { createDevToolsContext as a, getPort as i, renderDockImportsMap as n, ansis_default as o, createDevToolsMiddleware as r, __exportAll as s, DevTools as t };
|
|
1724
|
+
export { createDevToolsContext as n, context_exports as t };
|