@vitejs/devtools-kit 0.1.3 → 0.1.4

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/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as DevToolsRpcClientCallOptional, a as DevToolsClientRpcHost, b as getDevToolsRpcClient, c as DockEntryStateEvents, d as DocksEntriesContext, f as DocksPanelContext, g as DevToolsRpcClientCallEvent, h as DevToolsRpcClientCall, i as DevToolsClientContext, l as DockPanelStorage, m as DevToolsRpcClient, n as getDevToolsClientContext, o as DockClientType, p as RpcClientEvents, r as DockClientScriptContext, s as DockEntryState, t as CLIENT_CONTEXT_KEY, u as DocksContext, v as DevToolsRpcClientMode, y as DevToolsRpcClientOptions } from "./index-DryCMVBy.js";
1
+ import { _ as DevToolsRpcClientCallOptional, a as DevToolsClientRpcHost, b as getDevToolsRpcClient, c as DockEntryStateEvents, d as DocksEntriesContext, f as DocksPanelContext, g as DevToolsRpcClientCallEvent, h as DevToolsRpcClientCall, i as DevToolsClientContext, l as DockPanelStorage, m as DevToolsRpcClient, n as getDevToolsClientContext, o as DockClientType, p as RpcClientEvents, r as DockClientScriptContext, s as DockEntryState, t as CLIENT_CONTEXT_KEY, u as DocksContext, v as DevToolsRpcClientMode, y as DevToolsRpcClientOptions } from "./index-BSLgRVfr.js";
2
2
  export { CLIENT_CONTEXT_KEY, DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientCall, DevToolsRpcClientCallEvent, DevToolsRpcClientCallOptional, DevToolsRpcClientMode, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, RpcClientEvents, getDevToolsClientContext, getDevToolsRpcClient };
package/dist/client.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { DEVTOOLS_CONNECTION_META_FILENAME, DEVTOOLS_MOUNT_PATH, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME } from "./constants.js";
2
2
  import { createEventEmitter } from "./utils/events.js";
3
- import { nanoid } from "./utils/nanoid.js";
4
- import { createSharedState } from "./utils/shared-state.js";
3
+ import { t as humanId } from "./human-id-BSiGlZOw.js";
4
+ import { t as createSharedState } from "./shared-state-CCNEYlbv.js";
5
5
  import { RpcFunctionsCollectorBase } from "@vitejs/devtools-rpc";
6
+ import { hash } from "ohash";
6
7
  import { createRpcClient } from "@vitejs/devtools-rpc/client";
7
8
  import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/client";
8
9
  //#region src/client/context.ts
@@ -86,260 +87,6 @@ function createRpcSharedStateClientHost(rpc) {
86
87
  };
87
88
  }
88
89
  //#endregion
89
- //#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
90
- function serialize(o) {
91
- return typeof o == "string" ? `'${o}'` : new c().serialize(o);
92
- }
93
- const c = /* @__PURE__ */ function() {
94
- class o {
95
- #t = /* @__PURE__ */ new Map();
96
- compare(t, r) {
97
- const e = typeof t, n = typeof r;
98
- return e === "string" && n === "string" ? t.localeCompare(r) : e === "number" && n === "number" ? t - r : String.prototype.localeCompare.call(this.serialize(t, true), this.serialize(r, true));
99
- }
100
- serialize(t, r) {
101
- if (t === null) return "null";
102
- switch (typeof t) {
103
- case "string": return r ? t : `'${t}'`;
104
- case "bigint": return `${t}n`;
105
- case "object": return this.$object(t);
106
- case "function": return this.$function(t);
107
- }
108
- return String(t);
109
- }
110
- serializeObject(t) {
111
- const r = Object.prototype.toString.call(t);
112
- if (r !== "[object Object]") return this.serializeBuiltInType(r.length < 10 ? `unknown:${r}` : r.slice(8, -1), t);
113
- const e = t.constructor, n = e === Object || e === void 0 ? "" : e.name;
114
- if (n !== "" && globalThis[n] === e) return this.serializeBuiltInType(n, t);
115
- if (typeof t.toJSON == "function") {
116
- const i = t.toJSON();
117
- return n + (i !== null && typeof i == "object" ? this.$object(i) : `(${this.serialize(i)})`);
118
- }
119
- return this.serializeObjectEntries(n, Object.entries(t));
120
- }
121
- serializeBuiltInType(t, r) {
122
- const e = this["$" + t];
123
- if (e) return e.call(this, r);
124
- if (typeof r?.entries == "function") return this.serializeObjectEntries(t, r.entries());
125
- throw new Error(`Cannot serialize ${t}`);
126
- }
127
- serializeObjectEntries(t, r) {
128
- const e = Array.from(r).sort((i, a) => this.compare(i[0], a[0]));
129
- let n = `${t}{`;
130
- for (let i = 0; i < e.length; i++) {
131
- const [a, l] = e[i];
132
- n += `${this.serialize(a, true)}:${this.serialize(l)}`, i < e.length - 1 && (n += ",");
133
- }
134
- return n + "}";
135
- }
136
- $object(t) {
137
- let r = this.#t.get(t);
138
- return r === void 0 && (this.#t.set(t, `#${this.#t.size}`), r = this.serializeObject(t), this.#t.set(t, r)), r;
139
- }
140
- $function(t) {
141
- const r = Function.prototype.toString.call(t);
142
- return r.slice(-15) === "[native code] }" ? `${t.name || ""}()[native]` : `${t.name}(${t.length})${r.replace(/\s*\n\s*/g, "")}`;
143
- }
144
- $Array(t) {
145
- let r = "[";
146
- for (let e = 0; e < t.length; e++) r += this.serialize(t[e]), e < t.length - 1 && (r += ",");
147
- return r + "]";
148
- }
149
- $Date(t) {
150
- try {
151
- return `Date(${t.toISOString()})`;
152
- } catch {
153
- return "Date(null)";
154
- }
155
- }
156
- $ArrayBuffer(t) {
157
- return `ArrayBuffer[${new Uint8Array(t).join(",")}]`;
158
- }
159
- $Set(t) {
160
- return `Set${this.$Array(Array.from(t).sort((r, e) => this.compare(r, e)))}`;
161
- }
162
- $Map(t) {
163
- return this.serializeObjectEntries("Map", t.entries());
164
- }
165
- }
166
- for (const s of [
167
- "Error",
168
- "RegExp",
169
- "URL"
170
- ]) o.prototype["$" + s] = function(t) {
171
- return `${s}(${t})`;
172
- };
173
- for (const s of [
174
- "Int8Array",
175
- "Uint8Array",
176
- "Uint8ClampedArray",
177
- "Int16Array",
178
- "Uint16Array",
179
- "Int32Array",
180
- "Uint32Array",
181
- "Float32Array",
182
- "Float64Array"
183
- ]) o.prototype["$" + s] = function(t) {
184
- return `${s}[${t.join(",")}]`;
185
- };
186
- for (const s of ["BigInt64Array", "BigUint64Array"]) o.prototype["$" + s] = function(t) {
187
- return `${s}[${t.join("n,")}${t.length > 0 ? "n" : ""}]`;
188
- };
189
- return o;
190
- }();
191
- //#endregion
192
- //#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/js/index.mjs
193
- const z = [
194
- 1779033703,
195
- -1150833019,
196
- 1013904242,
197
- -1521486534,
198
- 1359893119,
199
- -1694144372,
200
- 528734635,
201
- 1541459225
202
- ], R = [
203
- 1116352408,
204
- 1899447441,
205
- -1245643825,
206
- -373957723,
207
- 961987163,
208
- 1508970993,
209
- -1841331548,
210
- -1424204075,
211
- -670586216,
212
- 310598401,
213
- 607225278,
214
- 1426881987,
215
- 1925078388,
216
- -2132889090,
217
- -1680079193,
218
- -1046744716,
219
- -459576895,
220
- -272742522,
221
- 264347078,
222
- 604807628,
223
- 770255983,
224
- 1249150122,
225
- 1555081692,
226
- 1996064986,
227
- -1740746414,
228
- -1473132947,
229
- -1341970488,
230
- -1084653625,
231
- -958395405,
232
- -710438585,
233
- 113926993,
234
- 338241895,
235
- 666307205,
236
- 773529912,
237
- 1294757372,
238
- 1396182291,
239
- 1695183700,
240
- 1986661051,
241
- -2117940946,
242
- -1838011259,
243
- -1564481375,
244
- -1474664885,
245
- -1035236496,
246
- -949202525,
247
- -778901479,
248
- -694614492,
249
- -200395387,
250
- 275423344,
251
- 430227734,
252
- 506948616,
253
- 659060556,
254
- 883997877,
255
- 958139571,
256
- 1322822218,
257
- 1537002063,
258
- 1747873779,
259
- 1955562222,
260
- 2024104815,
261
- -2067236844,
262
- -1933114872,
263
- -1866530822,
264
- -1538233109,
265
- -1090935817,
266
- -965641998
267
- ], S = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", r = [];
268
- var k = class {
269
- _data = new l();
270
- _hash = new l([...z]);
271
- _nDataBytes = 0;
272
- _minBufferSize = 0;
273
- finalize(e) {
274
- e && this._append(e);
275
- const s = this._nDataBytes * 8, t = this._data.sigBytes * 8;
276
- return this._data.words[t >>> 5] |= 128 << 24 - t % 32, this._data.words[(t + 64 >>> 9 << 4) + 14] = Math.floor(s / 4294967296), this._data.words[(t + 64 >>> 9 << 4) + 15] = s, this._data.sigBytes = this._data.words.length * 4, this._process(), this._hash;
277
- }
278
- _doProcessBlock(e, s) {
279
- const t = this._hash.words;
280
- let i = t[0], o = t[1], a = t[2], c = t[3], h = t[4], g = t[5], f = t[6], y = t[7];
281
- for (let n = 0; n < 64; n++) {
282
- if (n < 16) r[n] = e[s + n] | 0;
283
- else {
284
- const d = r[n - 15], j = (d << 25 | d >>> 7) ^ (d << 14 | d >>> 18) ^ d >>> 3, B = r[n - 2], x = (B << 15 | B >>> 17) ^ (B << 13 | B >>> 19) ^ B >>> 10;
285
- r[n] = j + r[n - 7] + x + r[n - 16];
286
- }
287
- const m = h & g ^ ~h & f, p = i & o ^ i & a ^ o & a, u = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), b = (h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25), w = y + b + m + R[n] + r[n], M = u + p;
288
- y = f, f = g, g = h, h = c + w | 0, c = a, a = o, o = i, i = w + M | 0;
289
- }
290
- t[0] = t[0] + i | 0, t[1] = t[1] + o | 0, t[2] = t[2] + a | 0, t[3] = t[3] + c | 0, t[4] = t[4] + h | 0, t[5] = t[5] + g | 0, t[6] = t[6] + f | 0, t[7] = t[7] + y | 0;
291
- }
292
- _append(e) {
293
- typeof e == "string" && (e = l.fromUtf8(e)), this._data.concat(e), this._nDataBytes += e.sigBytes;
294
- }
295
- _process(e) {
296
- let s, t = this._data.sigBytes / 64;
297
- e ? t = Math.ceil(t) : t = Math.max((t | 0) - this._minBufferSize, 0);
298
- const i = t * 16, o = Math.min(i * 4, this._data.sigBytes);
299
- if (i) {
300
- for (let a = 0; a < i; a += 16) this._doProcessBlock(this._data.words, a);
301
- s = this._data.words.splice(0, i), this._data.sigBytes -= o;
302
- }
303
- return new l(s, o);
304
- }
305
- };
306
- var l = class l {
307
- words;
308
- sigBytes;
309
- constructor(e, s) {
310
- e = this.words = e || [], this.sigBytes = s === void 0 ? e.length * 4 : s;
311
- }
312
- static fromUtf8(e) {
313
- const s = unescape(encodeURIComponent(e)), t = s.length, i = [];
314
- for (let o = 0; o < t; o++) i[o >>> 2] |= (s.charCodeAt(o) & 255) << 24 - o % 4 * 8;
315
- return new l(i, t);
316
- }
317
- toBase64() {
318
- const e = [];
319
- for (let s = 0; s < this.sigBytes; s += 3) {
320
- const t = this.words[s >>> 2] >>> 24 - s % 4 * 8 & 255, i = this.words[s + 1 >>> 2] >>> 24 - (s + 1) % 4 * 8 & 255, o = this.words[s + 2 >>> 2] >>> 24 - (s + 2) % 4 * 8 & 255, a = t << 16 | i << 8 | o;
321
- for (let c = 0; c < 4 && s * 8 + c * 6 < this.sigBytes * 8; c++) e.push(S.charAt(a >>> 6 * (3 - c) & 63));
322
- }
323
- return e.join("");
324
- }
325
- concat(e) {
326
- if (this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8, this.words.length = Math.ceil(this.sigBytes / 4), this.sigBytes % 4) for (let s = 0; s < e.sigBytes; s++) {
327
- const t = e.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
328
- this.words[this.sigBytes + s >>> 2] |= t << 24 - (this.sigBytes + s) % 4 * 8;
329
- }
330
- else for (let s = 0; s < e.sigBytes; s += 4) this.words[this.sigBytes + s >>> 2] = e.words[s >>> 2];
331
- this.sigBytes += e.sigBytes;
332
- }
333
- };
334
- function digest(_) {
335
- return new k().finalize(_).toBase64();
336
- }
337
- //#endregion
338
- //#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs
339
- function hash(input) {
340
- return digest(serialize(input));
341
- }
342
- //#endregion
343
90
  //#region src/client/static-rpc.ts
344
91
  function isStaticEntry(value) {
345
92
  return typeof value === "object" && value !== null && value.type === "static" && typeof value.path === "string";
@@ -404,6 +151,7 @@ async function createStaticRpcClientMode(options) {
404
151
  return {
405
152
  isTrusted: true,
406
153
  requestTrust: async () => true,
154
+ requestTrustWithToken: async () => true,
407
155
  ensureTrusted: async () => true,
408
156
  call: (...args) => staticCaller.call(args[0], args.slice(1)),
409
157
  callEvent: (...args) => staticCaller.callEvent(args[0], args.slice(1)),
@@ -1593,20 +1341,29 @@ function isNumeric(str) {
1593
1341
  return `${+str}` === `${str}`;
1594
1342
  }
1595
1343
  function createWsRpcClientMode(options) {
1596
- const { authId, connectionMeta, events, clientRpc, rpcOptions = {}, wsOptions = {} } = options;
1344
+ const { authToken, connectionMeta, events, clientRpc, rpcOptions = {}, wsOptions = {} } = options;
1597
1345
  let isTrusted = false;
1598
1346
  const trustedPromise = promiseWithResolver();
1599
1347
  const url = isNumeric(connectionMeta.websocket) ? `${location.protocol.replace("http", "ws")}//${location.hostname}:${connectionMeta.websocket}` : connectionMeta.websocket;
1600
1348
  const serverRpc = createRpcClient(clientRpc.functions, {
1601
1349
  preset: createWsRpcPreset({
1602
1350
  url,
1603
- authId,
1351
+ authToken,
1604
1352
  ...wsOptions
1605
1353
  }),
1606
1354
  rpcOptions
1607
1355
  });
1608
- async function requestTrust() {
1609
- if (isTrusted) return true;
1356
+ clientRpc.register({
1357
+ name: "devtoolskit:internal:auth:revoked",
1358
+ type: "event",
1359
+ handler: () => {
1360
+ isTrusted = false;
1361
+ events.emit("rpc:is-trusted:updated", false);
1362
+ }
1363
+ });
1364
+ let currentAuthToken = authToken;
1365
+ async function requestTrustWithToken(token) {
1366
+ currentAuthToken = token;
1610
1367
  const info = parseUA(navigator.userAgent);
1611
1368
  const ua = [
1612
1369
  info.browser.name,
@@ -1617,7 +1374,7 @@ function createWsRpcClientMode(options) {
1617
1374
  info.device.type
1618
1375
  ].filter((i) => i).join(" ");
1619
1376
  const result = await serverRpc.$call("vite:anonymous:auth", {
1620
- authId,
1377
+ authToken: token,
1621
1378
  ua,
1622
1379
  origin: location.origin
1623
1380
  });
@@ -1626,6 +1383,10 @@ function createWsRpcClientMode(options) {
1626
1383
  events.emit("rpc:is-trusted:updated", isTrusted);
1627
1384
  return result.isTrusted;
1628
1385
  }
1386
+ async function requestTrust() {
1387
+ if (isTrusted) return true;
1388
+ return requestTrustWithToken(currentAuthToken);
1389
+ }
1629
1390
  async function ensureTrusted(timeout = 6e4) {
1630
1391
  if (isTrusted) trustedPromise.resolve(true);
1631
1392
  if (timeout <= 0) return trustedPromise.promise;
@@ -1643,6 +1404,7 @@ function createWsRpcClientMode(options) {
1643
1404
  return isTrusted;
1644
1405
  },
1645
1406
  requestTrust,
1407
+ requestTrustWithToken,
1646
1408
  ensureTrusted,
1647
1409
  call: (...args) => {
1648
1410
  return serverRpc.$call(...args);
@@ -1658,23 +1420,26 @@ function createWsRpcClientMode(options) {
1658
1420
  //#endregion
1659
1421
  //#region src/client/rpc.ts
1660
1422
  const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
1661
- const CONNECTION_AUTH_ID_KEY = "__VITE_DEVTOOLS_CONNECTION_AUTH_ID__";
1662
- function getConnectionAuthIdFromWindows(userAuthId) {
1423
+ const CONNECTION_AUTH_TOKEN_KEY = "__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__";
1424
+ function getConnectionAuthTokenFromWindows(userAuthToken) {
1663
1425
  const getters = [
1664
- () => userAuthId,
1665
- () => localStorage.getItem(CONNECTION_AUTH_ID_KEY),
1666
- () => window?.[CONNECTION_AUTH_ID_KEY],
1667
- () => globalThis?.[CONNECTION_AUTH_ID_KEY],
1668
- () => parent.window?.[CONNECTION_AUTH_ID_KEY]
1426
+ () => userAuthToken,
1427
+ () => localStorage.getItem(CONNECTION_AUTH_TOKEN_KEY),
1428
+ () => window?.[CONNECTION_AUTH_TOKEN_KEY],
1429
+ () => globalThis?.[CONNECTION_AUTH_TOKEN_KEY],
1430
+ () => parent.window?.[CONNECTION_AUTH_TOKEN_KEY]
1669
1431
  ];
1670
1432
  let value;
1671
1433
  for (const getter of getters) try {
1672
1434
  value = getter();
1673
1435
  if (value) break;
1674
1436
  } catch {}
1675
- if (!value) value = nanoid();
1676
- localStorage.setItem(CONNECTION_AUTH_ID_KEY, value);
1677
- globalThis[CONNECTION_AUTH_ID_KEY] = value;
1437
+ if (!value) value = humanId({
1438
+ separator: "-",
1439
+ capitalize: false
1440
+ });
1441
+ localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, value);
1442
+ globalThis[CONNECTION_AUTH_TOKEN_KEY] = value;
1678
1443
  return value;
1679
1444
  }
1680
1445
  function findConnectionMetaFromWindows() {
@@ -1715,7 +1480,7 @@ async function getDevToolsRpcClient(options = {}) {
1715
1480
  if (!connectionMeta) throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
1716
1481
  }
1717
1482
  const context = { rpc: void 0 };
1718
- const authId = getConnectionAuthIdFromWindows(options.authId);
1483
+ const authToken = getConnectionAuthTokenFromWindows(options.authToken);
1719
1484
  const clientRpc = new RpcFunctionsCollectorBase(context);
1720
1485
  async function fetchJsonFromBases(path) {
1721
1486
  const candidates = [resolvedBaseURL, ...bases.filter((base) => base !== resolvedBaseURL)].filter((x) => x != null);
@@ -1731,7 +1496,7 @@ async function getDevToolsRpcClient(options = {}) {
1731
1496
  throw new Error(`Failed to load ${path} from ${candidates.join(", ")}`, { cause: errors });
1732
1497
  }
1733
1498
  const mode = connectionMeta.backend === "static" ? await createStaticRpcClientMode({ fetchJsonFromBases }) : createWsRpcClientMode({
1734
- authId,
1499
+ authToken,
1735
1500
  connectionMeta,
1736
1501
  events,
1737
1502
  clientRpc,
@@ -1746,6 +1511,11 @@ async function getDevToolsRpcClient(options = {}) {
1746
1511
  connectionMeta,
1747
1512
  ensureTrusted: mode.ensureTrusted,
1748
1513
  requestTrust: mode.requestTrust,
1514
+ requestTrustWithToken: async (token) => {
1515
+ localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token);
1516
+ globalThis[CONNECTION_AUTH_TOKEN_KEY] = token;
1517
+ return mode.requestTrustWithToken(token);
1518
+ },
1749
1519
  call: mode.call,
1750
1520
  callEvent: mode.callEvent,
1751
1521
  callOptional: mode.callOptional,
@@ -1755,6 +1525,12 @@ async function getDevToolsRpcClient(options = {}) {
1755
1525
  rpc.sharedState = createRpcSharedStateClientHost(rpc);
1756
1526
  context.rpc = rpc;
1757
1527
  mode.requestTrust();
1528
+ try {
1529
+ const bc = new BroadcastChannel("vite-devtools-auth");
1530
+ bc.onmessage = (event) => {
1531
+ if (event.data?.type === "auth-update" && event.data.authToken) rpc.requestTrustWithToken(event.data.authToken);
1532
+ };
1533
+ } catch {}
1758
1534
  return rpc;
1759
1535
  }
1760
1536
  //#endregion
@@ -1,4 +1,5 @@
1
- import { D as DevToolsDocksUserSettings } from "./index-DryCMVBy.js";
1
+ import { D as DevToolsDocksUserSettings } from "./index-BSLgRVfr.js";
2
+
2
3
  //#region src/constants.d.ts
3
4
  declare const DEVTOOLS_MOUNT_PATH = "/.devtools/";
4
5
  declare const DEVTOOLS_MOUNT_PATH_NO_TRAILING_SLASH = "/.devtools";