@vitejs/devtools 0.1.4 → 0.1.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.
Files changed (38) hide show
  1. package/dist/{DockIcon-DNt-Vqy4.js → DockIcon-zZkKuxFy.js} +2 -2
  2. package/dist/{DockStandalone-CL8hrIeb.js → DockStandalone-BuMVHLt_.js} +64 -64
  3. package/dist/{LogItem-CZM2G41b.js → LogItem-D-AbVX5q.js} +5 -5
  4. package/dist/{ViewBuiltinLogs-1ABRTwzd.js → ViewBuiltinLogs-D9GVXA00.js} +39 -39
  5. package/dist/{ViewBuiltinTerminals-Co7G-321.js → ViewBuiltinTerminals-afgLtRQP.js} +11 -11
  6. package/dist/{ViewJsonRender-ByPfpKFM.js → ViewJsonRender-DtluXw3F.js} +4 -4
  7. package/dist/cli-commands.js +92 -2
  8. package/dist/cli.js +8 -4
  9. package/dist/client/inject.js +49 -28
  10. package/dist/client/standalone/assets/{DockStandalone-C8ChyZLh.js → DockStandalone-DvxQ5kAU.js} +1 -1
  11. package/dist/client/standalone/assets/{ViewBuiltinTerminals-UrMq7UXM.js → ViewBuiltinTerminals-CpNVjAgX.js} +1 -1
  12. package/dist/client/standalone/assets/{ViewJsonRender-BURuu55Z.js → ViewJsonRender-CbWAIBeO.js} +1 -1
  13. package/dist/client/standalone/assets/{index-Rpv7PwRD.js → index-BGGAiDua.js} +3 -3
  14. package/dist/client/standalone/index.html +1 -1
  15. package/dist/client/webcomponents.d.ts +1 -21628
  16. package/dist/client/webcomponents.js +31 -31
  17. package/dist/config.js +1 -1
  18. package/dist/constants-DfEeYo9W.js +142 -0
  19. package/dist/{dist-D2Z6bwqJ.js → dist-CBtGbo90.js} +4 -4
  20. package/dist/dist-DpLy3ojW.js +229 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +4 -1
  23. package/dist/internal.d.ts +1 -1
  24. package/dist/internal.js +1 -1
  25. package/dist/plugins-DfC1vp4w.js +31 -0
  26. package/dist/{popup-DzgY0boj.js → popup-CAT8YohS.js} +2 -2
  27. package/dist/server-BuWZ1h8p.js +241 -0
  28. package/dist/server-Ca6LOTxO.js +3 -0
  29. package/dist/{plugins-BHefDofV.js → server-DhChc9gv.js} +8 -628
  30. package/dist/standalone-CAJbdnf4.js +34 -0
  31. package/dist/static-dump-Q0iG9hz3.js +65 -0
  32. package/package.json +10 -15
  33. package/dist/cli-commands-D6M9N3th.js +0 -180
  34. package/dist/vue.runtime.esm-bundler-CS1wMbap.js +0 -6988
  35. /package/dist/{context-internal-Du6FuGIu.d.ts → context-internal-BA4ba-FN.d.ts} +0 -0
  36. /package/dist/{context-internal-CvIHbZq4.js → context-internal-DZpoJjMz.js} +0 -0
  37. /package/dist/{iconify-BW79QmbD.js → iconify-JodklND-.js} +0 -0
  38. /package/dist/{utils-DaaVwEUH.js → utils-HWI9S6d-.js} +0 -0
@@ -1,11 +1,11 @@
1
- import { n as createStorage, t as getInternalContext } from "./context-internal-CvIHbZq4.js";
2
- import { t as isObject } from "./utils-DaaVwEUH.js";
3
- import { dirClientStandalone, dirDist } from "./dirs.js";
1
+ import { 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 refreshTempAuthToken, i as getTempAuthToken, o as setPendingAuth, r as abortPendingAuth, t as createDevToolsMiddleware } from "./server-BuWZ1h8p.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";
8
+ import { DEFAULT_STATE_USER_SETTINGS, DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID, DEVTOOLS_MOUNT_PATH } from "@vitejs/devtools-kit/constants";
9
9
  import { createEventEmitter } from "@vitejs/devtools-kit/utils/events";
10
10
  import { join } from "pathe";
11
11
  import { existsSync } from "node:fs";
@@ -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 { join as join$1 } from "node:path";
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 {
@@ -1188,167 +1148,6 @@ ${Qe}${i.trimStart()}`), s = 3 + stripVTControlCharacters(i.trimStart()).length)
1188
1148
  error: (e) => K.message(e, { symbol: styleText("red", Ee) })
1189
1149
  };
1190
1150
  //#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
1151
  //#region src/node/rpc/anonymous/auth.ts
1353
1152
  const AUTH_TIMEOUT_MS = 6e4;
1354
1153
  const anonymousAuth = defineRpcFunction({
@@ -1360,10 +1159,6 @@ const anonymousAuth = defineRpcFunction({
1360
1159
  const session = context.rpc.getCurrentRpcSession();
1361
1160
  if (!session) throw new Error("Failed to retrieve the current RPC session");
1362
1161
  if (session.meta.isTrusted || storage.value().trusted[query.authToken]) {
1363
- console.log("trusted", {
1364
- isTrusted: session.meta.isTrusted,
1365
- trusted: storage.value().trusted[query.authToken]
1366
- });
1367
1162
  session.meta.clientAuthToken = query.authToken;
1368
1163
  session.meta.isTrusted = true;
1369
1164
  return { isTrusted: true };
@@ -1729,6 +1524,7 @@ function shouldSkipSetupByCapabilities(plugin, mode) {
1729
1524
  }
1730
1525
  async function createDevToolsContext(viteConfig, viteServer) {
1731
1526
  const cwd = viteConfig.root;
1527
+ const { searchForWorkspaceRoot } = await import("vite");
1732
1528
  const context = {
1733
1529
  cwd,
1734
1530
  workspaceRoot: searchForWorkspaceRoot(cwd) ?? cwd,
@@ -1820,414 +1616,6 @@ async function createDevToolsContext(viteConfig, viteServer) {
1820
1616
  return context;
1821
1617
  }
1822
1618
  //#endregion
1823
- //#region src/node/plugins/injection.ts
1824
- function DevToolsInjection() {
1825
- return {
1826
- name: "vite:devtools:injection",
1827
- enforce: "post",
1828
- transformIndexHtml() {
1829
- return [{
1830
- tag: "script",
1831
- attrs: {
1832
- 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"))}`,
1833
- type: "module"
1834
- },
1835
- injectTo: "body"
1836
- }];
1837
- }
1838
- };
1839
- }
1840
- //#endregion
1841
- //#region ../../node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
1842
- const unsafePorts = /* @__PURE__ */ new Set([
1843
- 1,
1844
- 7,
1845
- 9,
1846
- 11,
1847
- 13,
1848
- 15,
1849
- 17,
1850
- 19,
1851
- 20,
1852
- 21,
1853
- 22,
1854
- 23,
1855
- 25,
1856
- 37,
1857
- 42,
1858
- 43,
1859
- 53,
1860
- 69,
1861
- 77,
1862
- 79,
1863
- 87,
1864
- 95,
1865
- 101,
1866
- 102,
1867
- 103,
1868
- 104,
1869
- 109,
1870
- 110,
1871
- 111,
1872
- 113,
1873
- 115,
1874
- 117,
1875
- 119,
1876
- 123,
1877
- 135,
1878
- 137,
1879
- 139,
1880
- 143,
1881
- 161,
1882
- 179,
1883
- 389,
1884
- 427,
1885
- 465,
1886
- 512,
1887
- 513,
1888
- 514,
1889
- 515,
1890
- 526,
1891
- 530,
1892
- 531,
1893
- 532,
1894
- 540,
1895
- 548,
1896
- 554,
1897
- 556,
1898
- 563,
1899
- 587,
1900
- 601,
1901
- 636,
1902
- 989,
1903
- 990,
1904
- 993,
1905
- 995,
1906
- 1719,
1907
- 1720,
1908
- 1723,
1909
- 2049,
1910
- 3659,
1911
- 4045,
1912
- 5060,
1913
- 5061,
1914
- 6e3,
1915
- 6566,
1916
- 6665,
1917
- 6666,
1918
- 6667,
1919
- 6668,
1920
- 6669,
1921
- 6697,
1922
- 10080
1923
- ]);
1924
- function isUnsafePort(port) {
1925
- return unsafePorts.has(port);
1926
- }
1927
- function isSafePort(port) {
1928
- return !isUnsafePort(port);
1929
- }
1930
- var GetPortError = class extends Error {
1931
- constructor(message, opts) {
1932
- super(message, opts);
1933
- this.message = message;
1934
- }
1935
- name = "GetPortError";
1936
- };
1937
- function _log(verbose, message) {
1938
- if (verbose) console.log(`[get-port] ${message}`);
1939
- }
1940
- function _generateRange(from, to) {
1941
- if (to < from) return [];
1942
- const r = [];
1943
- for (let index = from; index <= to; index++) r.push(index);
1944
- return r;
1945
- }
1946
- function _tryPort(port, host) {
1947
- return new Promise((resolve) => {
1948
- const server = createServer();
1949
- server.unref();
1950
- server.on("error", () => {
1951
- resolve(false);
1952
- });
1953
- server.listen({
1954
- port,
1955
- host
1956
- }, () => {
1957
- const { port: port2 } = server.address();
1958
- server.close(() => {
1959
- resolve(isSafePort(port2) && port2);
1960
- });
1961
- });
1962
- });
1963
- }
1964
- function _getLocalHosts(additional) {
1965
- const hosts = new Set(additional);
1966
- 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);
1967
- return [...hosts];
1968
- }
1969
- async function _findPort(ports, host) {
1970
- for (const port of ports) {
1971
- const r = await _tryPort(port, host);
1972
- if (r) return r;
1973
- }
1974
- }
1975
- function _fmtOnHost(hostname) {
1976
- return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
1977
- }
1978
- const HOSTNAME_RE = /^(?!-)[\d.:A-Za-z-]{1,63}(?<!-)$/;
1979
- function _validateHostname(hostname, _public, verbose) {
1980
- if (hostname && !HOSTNAME_RE.test(hostname)) {
1981
- const fallbackHost = _public ? "0.0.0.0" : "127.0.0.1";
1982
- _log(verbose, `Invalid hostname: ${JSON.stringify(hostname)}. Using ${JSON.stringify(fallbackHost)} as fallback.`);
1983
- return fallbackHost;
1984
- }
1985
- return hostname;
1986
- }
1987
- async function getPort(_userOptions = {}) {
1988
- if (typeof _userOptions === "number" || typeof _userOptions === "string") _userOptions = { port: Number.parseInt(_userOptions + "") || 0 };
1989
- const _port = Number(_userOptions.port ?? process.env.PORT);
1990
- const _userSpecifiedAnyPort = Boolean(_userOptions.port || _userOptions.ports?.length || _userOptions.portRange?.length);
1991
- const options = {
1992
- random: _port === 0,
1993
- ports: [],
1994
- portRange: [],
1995
- alternativePortRange: _userSpecifiedAnyPort ? [] : [3e3, 3100],
1996
- verbose: false,
1997
- ..._userOptions,
1998
- port: _port,
1999
- host: _validateHostname(_userOptions.host ?? process.env.HOST, _userOptions.public, _userOptions.verbose)
2000
- };
2001
- if (options.random && !_userSpecifiedAnyPort) return getRandomPort(options.host);
2002
- const portsToCheck = [
2003
- options.port,
2004
- ...options.ports,
2005
- ..._generateRange(...options.portRange)
2006
- ].filter((port) => {
2007
- if (!port) return false;
2008
- if (!isSafePort(port)) {
2009
- _log(options.verbose, `Ignoring unsafe port: ${port}`);
2010
- return false;
2011
- }
2012
- return true;
2013
- });
2014
- if (portsToCheck.length === 0) portsToCheck.push(3e3);
2015
- let availablePort = await _findPort(portsToCheck, options.host);
2016
- if (!availablePort && options.alternativePortRange.length > 0) {
2017
- availablePort = await _findPort(_generateRange(...options.alternativePortRange), options.host);
2018
- if (portsToCheck.length > 0) {
2019
- let message = `Unable to find an available port (tried ${portsToCheck.join("-")} ${_fmtOnHost(options.host)}).`;
2020
- if (availablePort) message += ` Using alternative port ${availablePort}.`;
2021
- _log(options.verbose, message);
2022
- }
2023
- }
2024
- if (!availablePort && _userOptions.random !== false) {
2025
- availablePort = await getRandomPort(options.host);
2026
- if (availablePort) _log(options.verbose, `Using random port ${availablePort}`);
2027
- }
2028
- if (!availablePort) {
2029
- const triedRanges = [
2030
- options.port,
2031
- options.portRange.join("-"),
2032
- options.alternativePortRange.join("-")
2033
- ].filter(Boolean).join(", ");
2034
- throw new GetPortError(`Unable to find an available port ${_fmtOnHost(options.host)} (tried ${triedRanges})`);
2035
- }
2036
- return availablePort;
2037
- }
2038
- async function getRandomPort(host) {
2039
- const port = await checkPort(0, host);
2040
- if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
2041
- return port;
2042
- }
2043
- async function checkPort(port, host = process.env.HOST, verbose) {
2044
- if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
2045
- if (!Array.isArray(host)) return _tryPort(port, host);
2046
- for (const _host of host) {
2047
- const _port = await _tryPort(port, _host);
2048
- if (_port === false) {
2049
- if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
2050
- return false;
2051
- }
2052
- if (port === 0 && _port !== 0) port = _port;
2053
- }
2054
- return port;
2055
- }
2056
- //#endregion
2057
- //#region src/node/ws.ts
2058
- const debugInvoked = createDebug("vite:devtools:rpc:invoked");
2059
- const ANONYMOUS_SCOPE = "vite:anonymous:";
2060
- async function createWsServer(options) {
2061
- const rpcHost = options.context.rpc;
2062
- const host = options.hostWebSocket ?? "localhost";
2063
- const https = options.context.viteConfig.server.https;
2064
- const port = options.portWebSocket ?? await getPort({
2065
- port: 7812,
2066
- host,
2067
- random: true
2068
- });
2069
- const wsClients = /* @__PURE__ */ new Set();
2070
- const context = options.context;
2071
- const contextInternal = getInternalContext(context);
2072
- const isClientAuthDisabled = context.mode === "build" || context.viteConfig.devtools?.config?.clientAuth === false || process$1.env.VITE_DEVTOOLS_DISABLE_CLIENT_AUTH === "true";
2073
- if (isClientAuthDisabled) console.warn("[Vite DevTools] Client authentication is disabled. Any browser can connect to the devtools and access to your server and filesystem.");
2074
- const preset = createWsRpcPreset({
2075
- port,
2076
- host,
2077
- https,
2078
- onConnected: (ws, req, meta) => {
2079
- const authToken = new URL(req.url ?? "", "http://localhost").searchParams.get("vite_devtools_auth_token") ?? void 0;
2080
- if (isClientAuthDisabled) meta.isTrusted = true;
2081
- else if (authToken && contextInternal.storage.auth.value().trusted[authToken]) {
2082
- meta.isTrusted = true;
2083
- meta.clientAuthToken = authToken;
2084
- } else if (authToken && ((context.viteConfig.devtools?.config)?.clientAuthTokens ?? []).includes(authToken)) {
2085
- meta.isTrusted = true;
2086
- meta.clientAuthToken = authToken;
2087
- }
2088
- wsClients.add(ws);
2089
- const color = meta.isTrusted ? ansis_default.green : ansis_default.yellow;
2090
- const trustedKeys = Object.keys(contextInternal.storage.auth.value().trusted);
2091
- console.log(color`${MARK_INFO} Websocket client connected. [${meta.id}] [${meta.clientAuthToken}] (${meta.isTrusted ? "trusted" : "untrusted"}) authToken=${authToken} trustedKeys=${JSON.stringify(trustedKeys)} isClientAuthDisabled=${isClientAuthDisabled}`);
2092
- },
2093
- onDisconnected: (ws, meta) => {
2094
- wsClients.delete(ws);
2095
- console.log(ansis_default.red`${MARK_INFO} Websocket client disconnected. [${meta.id}]`);
2096
- }
2097
- });
2098
- const asyncStorage = new AsyncLocalStorage();
2099
- const rpcGroup = createRpcServer(rpcHost.functions, {
2100
- preset,
2101
- rpcOptions: {
2102
- onFunctionError(error, name) {
2103
- console.error(ansis_default.red`⬢ RPC error on executing "${ansis_default.bold(name)}":`);
2104
- console.error(error);
2105
- },
2106
- onGeneralError(error) {
2107
- console.error(ansis_default.red`⬢ RPC error on executing rpc`);
2108
- console.error(error);
2109
- },
2110
- resolver(name, fn) {
2111
- const rpc = this;
2112
- if (!name.startsWith(ANONYMOUS_SCOPE) && !rpc.$meta.isTrusted) return () => {
2113
- throw new Error(`Unauthorized access to method ${JSON.stringify(name)} from client [${rpc.$meta.id}]`);
2114
- };
2115
- if (!fn) return void 0;
2116
- return async function(...args) {
2117
- debugInvoked(`${JSON.stringify(name)} from #${rpc.$meta.id}`);
2118
- return await asyncStorage.run({
2119
- rpc,
2120
- meta: rpc.$meta
2121
- }, async () => {
2122
- return (await fn).apply(this, args);
2123
- });
2124
- };
2125
- }
2126
- }
2127
- });
2128
- rpcHost._rpcGroup = rpcGroup;
2129
- rpcHost._asyncStorage = asyncStorage;
2130
- const getConnectionMeta = async () => {
2131
- return {
2132
- backend: "websocket",
2133
- websocket: port
2134
- };
2135
- };
2136
- return {
2137
- port,
2138
- rpc: rpcGroup,
2139
- rpcHost,
2140
- getConnectionMeta
2141
- };
2142
- }
2143
- //#endregion
2144
- //#region src/node/server.ts
2145
- function generateAuthPageHtml() {
2146
- return `<!DOCTYPE html>
2147
- <html>
2148
- <head>
2149
- <title>Vite DevTools Authorization</title>
2150
- <style>
2151
- html { font-family: system-ui, sans-serif; padding: 2rem; }
2152
- body { height: 80vh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; }
2153
- #message { font-size: 1.2rem; }
2154
- @media (prefers-color-scheme: dark) { html { background: #1a1a1a; color: #e0e0e0; } }
2155
- </style>
2156
- </head>
2157
- <body>
2158
- <div id="message">Verifying...</div>
2159
- <script>
2160
- const query = new URLSearchParams(location.search)
2161
- const id = query.get('id')
2162
- const el = document.getElementById('message')
2163
-
2164
- if (!id) {
2165
- el.textContent = '\\u26a0\\ufe0f No auth token found. Please check your URL.'
2166
- el.style.color = '#df513f'
2167
- } else {
2168
- fetch(location.pathname.replace(/\\/$/, '') + '-verify?id=' + encodeURIComponent(id))
2169
- .then(async (r) => {
2170
- if (r.status !== 200) throw new Error(await r.text())
2171
- const data = await r.json()
2172
- const authToken = data.authToken
2173
-
2174
- localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__', authToken)
2175
-
2176
- try {
2177
- const bc = new BroadcastChannel('vite-devtools-auth')
2178
- bc.postMessage({ type: 'auth-update', authToken: authToken })
2179
- } catch {}
2180
-
2181
- el.textContent = '\\u2705 Authorized! You can close this window now.'
2182
- window.close()
2183
- })
2184
- .catch((err) => {
2185
- el.textContent = '\\u26a0\\ufe0f Failed to authorize: ' + err.message
2186
- el.style.color = '#df513f'
2187
- })
2188
- }
2189
- <\/script>
2190
- </body>
2191
- </html>`;
2192
- }
2193
- async function createDevToolsMiddleware(options) {
2194
- const h3 = createApp();
2195
- const contextInternal = getInternalContext(options.context);
2196
- const { rpc, getConnectionMeta } = await createWsServer(options);
2197
- h3.use(`/${DEVTOOLS_CONNECTION_META_FILENAME}`, eventHandler(async (event) => {
2198
- event.node.res.setHeader("Content-Type", "application/json");
2199
- return event.node.res.end(JSON.stringify(await getConnectionMeta()));
2200
- }));
2201
- h3.use("/auth-verify", eventHandler((event) => {
2202
- const { id } = getQuery(event);
2203
- if (!id) {
2204
- event.node.res.statusCode = 400;
2205
- return event.node.res.end("Missing id parameter");
2206
- }
2207
- const clientAuthToken = consumeTempAuthToken(id, contextInternal.storage.auth);
2208
- if (!clientAuthToken) {
2209
- event.node.res.statusCode = 403;
2210
- return event.node.res.end("Invalid or expired auth token");
2211
- }
2212
- event.node.res.setHeader("Content-Type", "application/json");
2213
- return event.node.res.end(JSON.stringify({ authToken: clientAuthToken }));
2214
- }));
2215
- h3.use("/auth", eventHandler((event) => {
2216
- event.node.res.setHeader("Content-Type", "text/html");
2217
- return event.node.res.end(generateAuthPageHtml());
2218
- }));
2219
- h3.use(fromNodeMiddleware(sirv(dirClientStandalone, {
2220
- dev: true,
2221
- single: true
2222
- })));
2223
- return {
2224
- h3,
2225
- rpc,
2226
- middleware: toNodeListener(h3),
2227
- getConnectionMeta
2228
- };
2229
- }
2230
- //#endregion
2231
1619
  //#region src/node/plugins/server.ts
2232
1620
  /**
2233
1621
  * Core plugin for enabling Vite DevTools
@@ -2274,12 +1662,4 @@ function DevToolsServer() {
2274
1662
  };
2275
1663
  }
2276
1664
  //#endregion
2277
- //#region src/node/plugins/index.ts
2278
- async function DevTools(options = {}) {
2279
- const { builtinDevTools = true } = options;
2280
- const plugins = [DevToolsInjection(), DevToolsServer()];
2281
- if (builtinDevTools) plugins.push(await import("@vitejs/devtools-rolldown").then((m) => m.DevToolsRolldownUI()));
2282
- return plugins;
2283
- }
2284
- //#endregion
2285
- export { createDevToolsContext as a, getPort as i, renderDockImportsMap as n, ansis_default as o, createDevToolsMiddleware as r, __exportAll as s, DevTools as t };
1665
+ export { renderDockImportsMap as n, createDevToolsContext as r, DevToolsServer as t };