@vitejs/devtools-kit 0.1.2 → 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 +2 -2
- package/dist/client.js +59 -274
- package/dist/constants.d.ts +2 -1
- package/dist/human-id-BSiGlZOw.js +803 -0
- package/dist/{index-WxzZW3L-.d.ts → index-BSLgRVfr.d.ts} +19 -5
- package/dist/index.d.ts +2 -2
- package/dist/shared-state-CCNEYlbv.js +928 -0
- package/dist/{shared-state-BFKKxNt1.d.ts → shared-state-NxkOZ3u0.d.ts} +17 -3
- package/dist/utils/events.d.ts +1 -1
- package/dist/utils/human-id.d.ts +10 -0
- package/dist/utils/human-id.js +2 -0
- package/dist/utils/shared-state.d.ts +2 -2
- package/dist/utils/shared-state.js +1 -35
- package/package.json +10 -6
- package/skills/vite-devtools-kit/SKILL.md +13 -0
- package/skills/vite-devtools-kit/references/project-structure.md +9 -0
- package/skills/vite-devtools-kit/references/rpc-patterns.md +15 -0
- package/skills/vite-devtools-kit/references/shared-state-patterns.md +12 -1
- /package/dist/{events-B41U-zeg.d.ts → events-BTCXlxeC.d.ts} +0 -0
package/dist/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientCall, DevToolsRpcClientCallEvent, DevToolsRpcClientCallOptional, DevToolsRpcClientMode, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, RpcClientEvents, getDevToolsRpcClient };
|
|
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
|
+
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,10 +1,20 @@
|
|
|
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 {
|
|
4
|
-
import { createSharedState } from "./
|
|
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";
|
|
9
|
+
//#region src/client/context.ts
|
|
10
|
+
const CLIENT_CONTEXT_KEY = "__VITE_DEVTOOLS_CLIENT_CONTEXT__";
|
|
11
|
+
/**
|
|
12
|
+
* Get the global DevTools client context, or `undefined` if not yet initialized.
|
|
13
|
+
*/
|
|
14
|
+
function getDevToolsClientContext() {
|
|
15
|
+
return globalThis[CLIENT_CONTEXT_KEY];
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
8
18
|
//#region src/client/rpc-shared-state.ts
|
|
9
19
|
function createRpcSharedStateClientHost(rpc) {
|
|
10
20
|
const sharedState = /* @__PURE__ */ new Map();
|
|
@@ -77,260 +87,6 @@ function createRpcSharedStateClientHost(rpc) {
|
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
//#endregion
|
|
80
|
-
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
|
|
81
|
-
function serialize(o) {
|
|
82
|
-
return typeof o == "string" ? `'${o}'` : new c().serialize(o);
|
|
83
|
-
}
|
|
84
|
-
const c = /* @__PURE__ */ function() {
|
|
85
|
-
class o {
|
|
86
|
-
#t = /* @__PURE__ */ new Map();
|
|
87
|
-
compare(t, r) {
|
|
88
|
-
const e = typeof t, n = typeof r;
|
|
89
|
-
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));
|
|
90
|
-
}
|
|
91
|
-
serialize(t, r) {
|
|
92
|
-
if (t === null) return "null";
|
|
93
|
-
switch (typeof t) {
|
|
94
|
-
case "string": return r ? t : `'${t}'`;
|
|
95
|
-
case "bigint": return `${t}n`;
|
|
96
|
-
case "object": return this.$object(t);
|
|
97
|
-
case "function": return this.$function(t);
|
|
98
|
-
}
|
|
99
|
-
return String(t);
|
|
100
|
-
}
|
|
101
|
-
serializeObject(t) {
|
|
102
|
-
const r = Object.prototype.toString.call(t);
|
|
103
|
-
if (r !== "[object Object]") return this.serializeBuiltInType(r.length < 10 ? `unknown:${r}` : r.slice(8, -1), t);
|
|
104
|
-
const e = t.constructor, n = e === Object || e === void 0 ? "" : e.name;
|
|
105
|
-
if (n !== "" && globalThis[n] === e) return this.serializeBuiltInType(n, t);
|
|
106
|
-
if (typeof t.toJSON == "function") {
|
|
107
|
-
const i = t.toJSON();
|
|
108
|
-
return n + (i !== null && typeof i == "object" ? this.$object(i) : `(${this.serialize(i)})`);
|
|
109
|
-
}
|
|
110
|
-
return this.serializeObjectEntries(n, Object.entries(t));
|
|
111
|
-
}
|
|
112
|
-
serializeBuiltInType(t, r) {
|
|
113
|
-
const e = this["$" + t];
|
|
114
|
-
if (e) return e.call(this, r);
|
|
115
|
-
if (typeof r?.entries == "function") return this.serializeObjectEntries(t, r.entries());
|
|
116
|
-
throw new Error(`Cannot serialize ${t}`);
|
|
117
|
-
}
|
|
118
|
-
serializeObjectEntries(t, r) {
|
|
119
|
-
const e = Array.from(r).sort((i, a) => this.compare(i[0], a[0]));
|
|
120
|
-
let n = `${t}{`;
|
|
121
|
-
for (let i = 0; i < e.length; i++) {
|
|
122
|
-
const [a, l] = e[i];
|
|
123
|
-
n += `${this.serialize(a, true)}:${this.serialize(l)}`, i < e.length - 1 && (n += ",");
|
|
124
|
-
}
|
|
125
|
-
return n + "}";
|
|
126
|
-
}
|
|
127
|
-
$object(t) {
|
|
128
|
-
let r = this.#t.get(t);
|
|
129
|
-
return r === void 0 && (this.#t.set(t, `#${this.#t.size}`), r = this.serializeObject(t), this.#t.set(t, r)), r;
|
|
130
|
-
}
|
|
131
|
-
$function(t) {
|
|
132
|
-
const r = Function.prototype.toString.call(t);
|
|
133
|
-
return r.slice(-15) === "[native code] }" ? `${t.name || ""}()[native]` : `${t.name}(${t.length})${r.replace(/\s*\n\s*/g, "")}`;
|
|
134
|
-
}
|
|
135
|
-
$Array(t) {
|
|
136
|
-
let r = "[";
|
|
137
|
-
for (let e = 0; e < t.length; e++) r += this.serialize(t[e]), e < t.length - 1 && (r += ",");
|
|
138
|
-
return r + "]";
|
|
139
|
-
}
|
|
140
|
-
$Date(t) {
|
|
141
|
-
try {
|
|
142
|
-
return `Date(${t.toISOString()})`;
|
|
143
|
-
} catch {
|
|
144
|
-
return "Date(null)";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
$ArrayBuffer(t) {
|
|
148
|
-
return `ArrayBuffer[${new Uint8Array(t).join(",")}]`;
|
|
149
|
-
}
|
|
150
|
-
$Set(t) {
|
|
151
|
-
return `Set${this.$Array(Array.from(t).sort((r, e) => this.compare(r, e)))}`;
|
|
152
|
-
}
|
|
153
|
-
$Map(t) {
|
|
154
|
-
return this.serializeObjectEntries("Map", t.entries());
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const s of [
|
|
158
|
-
"Error",
|
|
159
|
-
"RegExp",
|
|
160
|
-
"URL"
|
|
161
|
-
]) o.prototype["$" + s] = function(t) {
|
|
162
|
-
return `${s}(${t})`;
|
|
163
|
-
};
|
|
164
|
-
for (const s of [
|
|
165
|
-
"Int8Array",
|
|
166
|
-
"Uint8Array",
|
|
167
|
-
"Uint8ClampedArray",
|
|
168
|
-
"Int16Array",
|
|
169
|
-
"Uint16Array",
|
|
170
|
-
"Int32Array",
|
|
171
|
-
"Uint32Array",
|
|
172
|
-
"Float32Array",
|
|
173
|
-
"Float64Array"
|
|
174
|
-
]) o.prototype["$" + s] = function(t) {
|
|
175
|
-
return `${s}[${t.join(",")}]`;
|
|
176
|
-
};
|
|
177
|
-
for (const s of ["BigInt64Array", "BigUint64Array"]) o.prototype["$" + s] = function(t) {
|
|
178
|
-
return `${s}[${t.join("n,")}${t.length > 0 ? "n" : ""}]`;
|
|
179
|
-
};
|
|
180
|
-
return o;
|
|
181
|
-
}();
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/js/index.mjs
|
|
184
|
-
const z = [
|
|
185
|
-
1779033703,
|
|
186
|
-
-1150833019,
|
|
187
|
-
1013904242,
|
|
188
|
-
-1521486534,
|
|
189
|
-
1359893119,
|
|
190
|
-
-1694144372,
|
|
191
|
-
528734635,
|
|
192
|
-
1541459225
|
|
193
|
-
], R = [
|
|
194
|
-
1116352408,
|
|
195
|
-
1899447441,
|
|
196
|
-
-1245643825,
|
|
197
|
-
-373957723,
|
|
198
|
-
961987163,
|
|
199
|
-
1508970993,
|
|
200
|
-
-1841331548,
|
|
201
|
-
-1424204075,
|
|
202
|
-
-670586216,
|
|
203
|
-
310598401,
|
|
204
|
-
607225278,
|
|
205
|
-
1426881987,
|
|
206
|
-
1925078388,
|
|
207
|
-
-2132889090,
|
|
208
|
-
-1680079193,
|
|
209
|
-
-1046744716,
|
|
210
|
-
-459576895,
|
|
211
|
-
-272742522,
|
|
212
|
-
264347078,
|
|
213
|
-
604807628,
|
|
214
|
-
770255983,
|
|
215
|
-
1249150122,
|
|
216
|
-
1555081692,
|
|
217
|
-
1996064986,
|
|
218
|
-
-1740746414,
|
|
219
|
-
-1473132947,
|
|
220
|
-
-1341970488,
|
|
221
|
-
-1084653625,
|
|
222
|
-
-958395405,
|
|
223
|
-
-710438585,
|
|
224
|
-
113926993,
|
|
225
|
-
338241895,
|
|
226
|
-
666307205,
|
|
227
|
-
773529912,
|
|
228
|
-
1294757372,
|
|
229
|
-
1396182291,
|
|
230
|
-
1695183700,
|
|
231
|
-
1986661051,
|
|
232
|
-
-2117940946,
|
|
233
|
-
-1838011259,
|
|
234
|
-
-1564481375,
|
|
235
|
-
-1474664885,
|
|
236
|
-
-1035236496,
|
|
237
|
-
-949202525,
|
|
238
|
-
-778901479,
|
|
239
|
-
-694614492,
|
|
240
|
-
-200395387,
|
|
241
|
-
275423344,
|
|
242
|
-
430227734,
|
|
243
|
-
506948616,
|
|
244
|
-
659060556,
|
|
245
|
-
883997877,
|
|
246
|
-
958139571,
|
|
247
|
-
1322822218,
|
|
248
|
-
1537002063,
|
|
249
|
-
1747873779,
|
|
250
|
-
1955562222,
|
|
251
|
-
2024104815,
|
|
252
|
-
-2067236844,
|
|
253
|
-
-1933114872,
|
|
254
|
-
-1866530822,
|
|
255
|
-
-1538233109,
|
|
256
|
-
-1090935817,
|
|
257
|
-
-965641998
|
|
258
|
-
], S = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", r = [];
|
|
259
|
-
var k = class {
|
|
260
|
-
_data = new l();
|
|
261
|
-
_hash = new l([...z]);
|
|
262
|
-
_nDataBytes = 0;
|
|
263
|
-
_minBufferSize = 0;
|
|
264
|
-
finalize(e) {
|
|
265
|
-
e && this._append(e);
|
|
266
|
-
const s = this._nDataBytes * 8, t = this._data.sigBytes * 8;
|
|
267
|
-
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;
|
|
268
|
-
}
|
|
269
|
-
_doProcessBlock(e, s) {
|
|
270
|
-
const t = this._hash.words;
|
|
271
|
-
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];
|
|
272
|
-
for (let n = 0; n < 64; n++) {
|
|
273
|
-
if (n < 16) r[n] = e[s + n] | 0;
|
|
274
|
-
else {
|
|
275
|
-
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;
|
|
276
|
-
r[n] = j + r[n - 7] + x + r[n - 16];
|
|
277
|
-
}
|
|
278
|
-
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;
|
|
279
|
-
y = f, f = g, g = h, h = c + w | 0, c = a, a = o, o = i, i = w + M | 0;
|
|
280
|
-
}
|
|
281
|
-
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;
|
|
282
|
-
}
|
|
283
|
-
_append(e) {
|
|
284
|
-
typeof e == "string" && (e = l.fromUtf8(e)), this._data.concat(e), this._nDataBytes += e.sigBytes;
|
|
285
|
-
}
|
|
286
|
-
_process(e) {
|
|
287
|
-
let s, t = this._data.sigBytes / 64;
|
|
288
|
-
e ? t = Math.ceil(t) : t = Math.max((t | 0) - this._minBufferSize, 0);
|
|
289
|
-
const i = t * 16, o = Math.min(i * 4, this._data.sigBytes);
|
|
290
|
-
if (i) {
|
|
291
|
-
for (let a = 0; a < i; a += 16) this._doProcessBlock(this._data.words, a);
|
|
292
|
-
s = this._data.words.splice(0, i), this._data.sigBytes -= o;
|
|
293
|
-
}
|
|
294
|
-
return new l(s, o);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
var l = class l {
|
|
298
|
-
words;
|
|
299
|
-
sigBytes;
|
|
300
|
-
constructor(e, s) {
|
|
301
|
-
e = this.words = e || [], this.sigBytes = s === void 0 ? e.length * 4 : s;
|
|
302
|
-
}
|
|
303
|
-
static fromUtf8(e) {
|
|
304
|
-
const s = unescape(encodeURIComponent(e)), t = s.length, i = [];
|
|
305
|
-
for (let o = 0; o < t; o++) i[o >>> 2] |= (s.charCodeAt(o) & 255) << 24 - o % 4 * 8;
|
|
306
|
-
return new l(i, t);
|
|
307
|
-
}
|
|
308
|
-
toBase64() {
|
|
309
|
-
const e = [];
|
|
310
|
-
for (let s = 0; s < this.sigBytes; s += 3) {
|
|
311
|
-
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;
|
|
312
|
-
for (let c = 0; c < 4 && s * 8 + c * 6 < this.sigBytes * 8; c++) e.push(S.charAt(a >>> 6 * (3 - c) & 63));
|
|
313
|
-
}
|
|
314
|
-
return e.join("");
|
|
315
|
-
}
|
|
316
|
-
concat(e) {
|
|
317
|
-
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++) {
|
|
318
|
-
const t = e.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
|
|
319
|
-
this.words[this.sigBytes + s >>> 2] |= t << 24 - (this.sigBytes + s) % 4 * 8;
|
|
320
|
-
}
|
|
321
|
-
else for (let s = 0; s < e.sigBytes; s += 4) this.words[this.sigBytes + s >>> 2] = e.words[s >>> 2];
|
|
322
|
-
this.sigBytes += e.sigBytes;
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
function digest(_) {
|
|
326
|
-
return new k().finalize(_).toBase64();
|
|
327
|
-
}
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs
|
|
330
|
-
function hash(input) {
|
|
331
|
-
return digest(serialize(input));
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
334
90
|
//#region src/client/static-rpc.ts
|
|
335
91
|
function isStaticEntry(value) {
|
|
336
92
|
return typeof value === "object" && value !== null && value.type === "static" && typeof value.path === "string";
|
|
@@ -395,6 +151,7 @@ async function createStaticRpcClientMode(options) {
|
|
|
395
151
|
return {
|
|
396
152
|
isTrusted: true,
|
|
397
153
|
requestTrust: async () => true,
|
|
154
|
+
requestTrustWithToken: async () => true,
|
|
398
155
|
ensureTrusted: async () => true,
|
|
399
156
|
call: (...args) => staticCaller.call(args[0], args.slice(1)),
|
|
400
157
|
callEvent: (...args) => staticCaller.callEvent(args[0], args.slice(1)),
|
|
@@ -1584,20 +1341,29 @@ function isNumeric(str) {
|
|
|
1584
1341
|
return `${+str}` === `${str}`;
|
|
1585
1342
|
}
|
|
1586
1343
|
function createWsRpcClientMode(options) {
|
|
1587
|
-
const {
|
|
1344
|
+
const { authToken, connectionMeta, events, clientRpc, rpcOptions = {}, wsOptions = {} } = options;
|
|
1588
1345
|
let isTrusted = false;
|
|
1589
1346
|
const trustedPromise = promiseWithResolver();
|
|
1590
1347
|
const url = isNumeric(connectionMeta.websocket) ? `${location.protocol.replace("http", "ws")}//${location.hostname}:${connectionMeta.websocket}` : connectionMeta.websocket;
|
|
1591
1348
|
const serverRpc = createRpcClient(clientRpc.functions, {
|
|
1592
1349
|
preset: createWsRpcPreset({
|
|
1593
1350
|
url,
|
|
1594
|
-
|
|
1351
|
+
authToken,
|
|
1595
1352
|
...wsOptions
|
|
1596
1353
|
}),
|
|
1597
1354
|
rpcOptions
|
|
1598
1355
|
});
|
|
1599
|
-
|
|
1600
|
-
|
|
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;
|
|
1601
1367
|
const info = parseUA(navigator.userAgent);
|
|
1602
1368
|
const ua = [
|
|
1603
1369
|
info.browser.name,
|
|
@@ -1608,7 +1374,7 @@ function createWsRpcClientMode(options) {
|
|
|
1608
1374
|
info.device.type
|
|
1609
1375
|
].filter((i) => i).join(" ");
|
|
1610
1376
|
const result = await serverRpc.$call("vite:anonymous:auth", {
|
|
1611
|
-
|
|
1377
|
+
authToken: token,
|
|
1612
1378
|
ua,
|
|
1613
1379
|
origin: location.origin
|
|
1614
1380
|
});
|
|
@@ -1617,6 +1383,10 @@ function createWsRpcClientMode(options) {
|
|
|
1617
1383
|
events.emit("rpc:is-trusted:updated", isTrusted);
|
|
1618
1384
|
return result.isTrusted;
|
|
1619
1385
|
}
|
|
1386
|
+
async function requestTrust() {
|
|
1387
|
+
if (isTrusted) return true;
|
|
1388
|
+
return requestTrustWithToken(currentAuthToken);
|
|
1389
|
+
}
|
|
1620
1390
|
async function ensureTrusted(timeout = 6e4) {
|
|
1621
1391
|
if (isTrusted) trustedPromise.resolve(true);
|
|
1622
1392
|
if (timeout <= 0) return trustedPromise.promise;
|
|
@@ -1634,6 +1404,7 @@ function createWsRpcClientMode(options) {
|
|
|
1634
1404
|
return isTrusted;
|
|
1635
1405
|
},
|
|
1636
1406
|
requestTrust,
|
|
1407
|
+
requestTrustWithToken,
|
|
1637
1408
|
ensureTrusted,
|
|
1638
1409
|
call: (...args) => {
|
|
1639
1410
|
return serverRpc.$call(...args);
|
|
@@ -1649,23 +1420,26 @@ function createWsRpcClientMode(options) {
|
|
|
1649
1420
|
//#endregion
|
|
1650
1421
|
//#region src/client/rpc.ts
|
|
1651
1422
|
const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
|
|
1652
|
-
const
|
|
1653
|
-
function
|
|
1423
|
+
const CONNECTION_AUTH_TOKEN_KEY = "__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__";
|
|
1424
|
+
function getConnectionAuthTokenFromWindows(userAuthToken) {
|
|
1654
1425
|
const getters = [
|
|
1655
|
-
() =>
|
|
1656
|
-
() => localStorage.getItem(
|
|
1657
|
-
() => window?.[
|
|
1658
|
-
() => globalThis?.[
|
|
1659
|
-
() => parent.window?.[
|
|
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]
|
|
1660
1431
|
];
|
|
1661
1432
|
let value;
|
|
1662
1433
|
for (const getter of getters) try {
|
|
1663
1434
|
value = getter();
|
|
1664
1435
|
if (value) break;
|
|
1665
1436
|
} catch {}
|
|
1666
|
-
if (!value) value =
|
|
1667
|
-
|
|
1668
|
-
|
|
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;
|
|
1669
1443
|
return value;
|
|
1670
1444
|
}
|
|
1671
1445
|
function findConnectionMetaFromWindows() {
|
|
@@ -1706,7 +1480,7 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1706
1480
|
if (!connectionMeta) throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
|
|
1707
1481
|
}
|
|
1708
1482
|
const context = { rpc: void 0 };
|
|
1709
|
-
const
|
|
1483
|
+
const authToken = getConnectionAuthTokenFromWindows(options.authToken);
|
|
1710
1484
|
const clientRpc = new RpcFunctionsCollectorBase(context);
|
|
1711
1485
|
async function fetchJsonFromBases(path) {
|
|
1712
1486
|
const candidates = [resolvedBaseURL, ...bases.filter((base) => base !== resolvedBaseURL)].filter((x) => x != null);
|
|
@@ -1722,7 +1496,7 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1722
1496
|
throw new Error(`Failed to load ${path} from ${candidates.join(", ")}`, { cause: errors });
|
|
1723
1497
|
}
|
|
1724
1498
|
const mode = connectionMeta.backend === "static" ? await createStaticRpcClientMode({ fetchJsonFromBases }) : createWsRpcClientMode({
|
|
1725
|
-
|
|
1499
|
+
authToken,
|
|
1726
1500
|
connectionMeta,
|
|
1727
1501
|
events,
|
|
1728
1502
|
clientRpc,
|
|
@@ -1737,6 +1511,11 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1737
1511
|
connectionMeta,
|
|
1738
1512
|
ensureTrusted: mode.ensureTrusted,
|
|
1739
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
|
+
},
|
|
1740
1519
|
call: mode.call,
|
|
1741
1520
|
callEvent: mode.callEvent,
|
|
1742
1521
|
callOptional: mode.callOptional,
|
|
@@ -1746,7 +1525,13 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1746
1525
|
rpc.sharedState = createRpcSharedStateClientHost(rpc);
|
|
1747
1526
|
context.rpc = rpc;
|
|
1748
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 {}
|
|
1749
1534
|
return rpc;
|
|
1750
1535
|
}
|
|
1751
1536
|
//#endregion
|
|
1752
|
-
export { getDevToolsRpcClient };
|
|
1537
|
+
export { CLIENT_CONTEXT_KEY, getDevToolsClientContext, getDevToolsRpcClient };
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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";
|