@vitejs/devtools 0.1.5 → 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-DxFEMDp2.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-BUPO6e0I.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-DiuKIPkS.js → server-DhChc9gv.js} +8 -624
  30. package/dist/standalone-CAJbdnf4.js +34 -0
  31. package/dist/static-dump-Q0iG9hz3.js +65 -0
  32. package/package.json +9 -14
  33. package/dist/cli-commands-CnJ4eqDp.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({
@@ -1725,6 +1524,7 @@ function shouldSkipSetupByCapabilities(plugin, mode) {
1725
1524
  }
1726
1525
  async function createDevToolsContext(viteConfig, viteServer) {
1727
1526
  const cwd = viteConfig.root;
1527
+ const { searchForWorkspaceRoot } = await import("vite");
1728
1528
  const context = {
1729
1529
  cwd,
1730
1530
  workspaceRoot: searchForWorkspaceRoot(cwd) ?? cwd,
@@ -1816,414 +1616,6 @@ async function createDevToolsContext(viteConfig, viteServer) {
1816
1616
  return context;
1817
1617
  }
1818
1618
  //#endregion
1819
- //#region src/node/plugins/injection.ts
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
1619
  //#region src/node/plugins/server.ts
2228
1620
  /**
2229
1621
  * Core plugin for enabling Vite DevTools
@@ -2270,12 +1662,4 @@ function DevToolsServer() {
2270
1662
  };
2271
1663
  }
2272
1664
  //#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 };
1665
+ export { renderDockImportsMap as n, createDevToolsContext as r, DevToolsServer as t };
@@ -0,0 +1,34 @@
1
+ import { r as createDevToolsContext } from "./server-DhChc9gv.js";
2
+ import { t as DevTools } from "./plugins-DfC1vp4w.js";
3
+ import "./dist-DpLy3ojW.js";
4
+ import process from "node:process";
5
+ //#region src/node/standalone.ts
6
+ async function startStandaloneDevTools(options = {}) {
7
+ const { cwd = process.cwd(), command = "build", mode = "production" } = options;
8
+ const { resolveConfig } = await import("vite");
9
+ const resolved = await resolveConfig({
10
+ configFile: options.config,
11
+ root: cwd,
12
+ plugins: [DevTools()]
13
+ }, command, mode);
14
+ dedupeVitePlugins(resolved.plugins, (plugin) => plugin.name?.startsWith("vite:devtools"));
15
+ return {
16
+ config: resolved,
17
+ context: await createDevToolsContext(resolved)
18
+ };
19
+ }
20
+ function dedupeVitePlugins(plugins, include) {
21
+ const toDelete = [];
22
+ const map = /* @__PURE__ */ new Map();
23
+ for (let i = 0; i < plugins.length; i++) {
24
+ const plugin = plugins[i];
25
+ if (!plugin || !include(plugin)) continue;
26
+ if (map.has(plugin.name)) toDelete.push(i);
27
+ else map.set(plugin.name, plugin);
28
+ }
29
+ toDelete.sort((a, b) => b - a);
30
+ for (const i of toDelete) plugins.splice(i, 1);
31
+ return plugins;
32
+ }
33
+ //#endregion
34
+ export { startStandaloneDevTools };