@vitejs/devtools-kit 0.0.0-alpha.20 → 0.0.0-alpha.21

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.
@@ -1,9 +1,10 @@
1
- import { t as EventEmitter } from "./events-S6nCJ_5X.mjs";
1
+ import { t as EventEmitter } from "./events-BrHMyEqJ.mjs";
2
2
  import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
3
3
  import { Raw } from "vue";
4
+ import { BirpcOptions, BirpcReturn } from "birpc";
5
+ import { WebSocket } from "ws";
4
6
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
5
7
  import { ChildProcess } from "node:child_process";
6
- import { BirpcOptions, BirpcReturn } from "birpc";
7
8
 
8
9
  //#region src/types/docks.d.ts
9
10
  interface DevToolsDockHost {
@@ -93,7 +94,7 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
93
94
  }
94
95
  interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
95
96
  type: '~builtin';
96
- id: '~terminals' | '~logs';
97
+ id: '~terminals' | '~logs' | '~client-auth-notice';
97
98
  }
98
99
  type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
99
100
  type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
@@ -180,14 +181,47 @@ interface DevToolsPluginOptions {
180
181
  setup: (context: DevToolsNodeContext) => void | Promise<void>;
181
182
  }
182
183
  interface DevToolsNodeContext {
184
+ /**
185
+ * Workspace root directory of Vite DevTools
186
+ */
187
+ readonly workspaceRoot: string;
188
+ /**
189
+ * Current working directory of Vite DevTools
190
+ */
183
191
  readonly cwd: string;
192
+ /**
193
+ * Current mode of Vite DevTools
194
+ * - 'dev' - when Vite DevTools is running in dev mode
195
+ * - 'build' - when Vite DevTools is running in build mode (no server)
196
+ */
184
197
  readonly mode: 'dev' | 'build';
198
+ /**
199
+ * Resolved Vite configuration
200
+ */
185
201
  readonly viteConfig: ResolvedConfig;
202
+ /**
203
+ * Vite dev server instance (only available in dev mode)
204
+ */
186
205
  readonly viteServer?: ViteDevServer;
206
+ /**
207
+ * RPC functions host, for registering server-side RPC functions and calling client-side RPC functions
208
+ */
187
209
  rpc: RpcFunctionsHost;
210
+ /**
211
+ * Docks host, for registering dock entries
212
+ */
188
213
  docks: DevToolsDockHost;
214
+ /**
215
+ * Views host, for registering static views
216
+ */
189
217
  views: DevToolsViewHost;
218
+ /**
219
+ * Utils for the node context
220
+ */
190
221
  utils: DevToolsNodeUtils;
222
+ /**
223
+ * Terminals host, for registering terminal sessions and streaming terminal output
224
+ */
191
225
  terminals: DevToolsTerminalHost;
192
226
  }
193
227
  interface DevToolsNodeUtils {
@@ -205,8 +239,27 @@ interface ConnectionMeta {
205
239
  }
206
240
  //#endregion
207
241
  //#region src/types/rpc.d.ts
242
+ interface DevToolsNodeRpcSessionMeta {
243
+ id: number;
244
+ ws?: WebSocket;
245
+ clientAuthId?: string;
246
+ isTrusted?: boolean;
247
+ }
248
+ interface DevToolsNodeRpcSession {
249
+ meta: DevToolsNodeRpcSessionMeta;
250
+ rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
251
+ }
208
252
  type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
209
- boardcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
253
+ /**
254
+ * Broadcast a message to all connected clients
255
+ */
256
+ broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
257
+ /**
258
+ * Get the current RPC client
259
+ *
260
+ * Available in RPC functions to get the current RPC client
261
+ */
262
+ getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
210
263
  };
211
264
  //#endregion
212
265
  //#region src/types/utils.d.ts
@@ -223,6 +276,21 @@ declare module 'vite' {
223
276
  interface Plugin {
224
277
  devtools?: DevToolsPluginOptions;
225
278
  }
279
+ interface UserConfig {
280
+ devtools?: ViteConfigDevtoolsOptions;
281
+ }
282
+ }
283
+ interface ViteConfigDevtoolsOptions {
284
+ /**
285
+ * Disable client authentication.
286
+ *
287
+ * Beware that if you disable client authentication,
288
+ * any browsers can connect to the devtools and access to your server and filesystem.
289
+ * (including other devices, if you open server `host` option to LAN or WAN)
290
+ *
291
+ * @default true
292
+ */
293
+ clientAuth?: boolean;
226
294
  }
227
295
  interface PluginWithDevTools extends Plugin {
228
296
  devtools?: DevToolsPluginOptions;
@@ -240,6 +308,10 @@ interface WebSocketRpcClientOptions {
240
308
  interface DevToolsRpcClientOptions {
241
309
  connectionMeta?: ConnectionMeta;
242
310
  baseURL?: string[];
311
+ /**
312
+ * The auth id to use for the client
313
+ */
314
+ authId?: string;
243
315
  wsOptions?: Partial<WebSocketRpcClientOptions>;
244
316
  rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions, boolean>>;
245
317
  }
@@ -248,10 +320,26 @@ interface DevToolsRpcClient {
248
320
  * The events of the client
249
321
  */
250
322
  events: EventEmitter<RpcClientEvents>;
323
+ /**
324
+ * Whether the client is trusted
325
+ */
326
+ readonly isTrusted: boolean | null;
251
327
  /**
252
328
  * The connection meta
253
329
  */
254
330
  readonly connectionMeta: ConnectionMeta;
331
+ /**
332
+ * Return a promise that resolves when the client is trusted
333
+ *
334
+ * Rejects with an error if the timeout is reached
335
+ *
336
+ * @param timeout - The timeout in milliseconds, default to 60 seconds
337
+ */
338
+ ensureTrusted: (timeout?: number) => Promise<boolean>;
339
+ /**
340
+ * Request trust from the server
341
+ */
342
+ requestTrust: () => Promise<boolean>;
255
343
  /**
256
344
  * Call a RPC function on the server
257
345
  */
@@ -327,6 +415,12 @@ interface DocksEntriesContext {
327
415
  * @returns Whether the selection was changed successfully
328
416
  */
329
417
  switchEntry: (id?: string | null) => Promise<boolean>;
418
+ /**
419
+ * Toggle the selected dock entry
420
+ *
421
+ * @returns Whether the selection was changed successfully
422
+ */
423
+ toggleEntry: (id: string) => Promise<boolean>;
330
424
  }
331
425
  interface DockEntryState {
332
426
  entryMeta: DevToolsDockEntry;
@@ -344,7 +438,9 @@ interface DockEntryStateEvents {
344
438
  'dom:panel:mounted': (panel: HTMLDivElement) => void;
345
439
  'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
346
440
  }
347
- interface RpcClientEvents {}
441
+ interface RpcClientEvents {
442
+ 'rpc:is-trusted:updated': (isTrusted: boolean) => void;
443
+ }
348
444
  //#endregion
349
445
  //#region src/client/client-script.d.ts
350
446
  /**
@@ -357,4 +453,4 @@ interface DockClientScriptContext extends DocksContext {
357
453
  current: DockEntryState;
358
454
  }
359
455
  //#endregion
360
- export { DevToolsTerminalHost as A, DevToolsDockEntryCategory as B, DevToolsCapabilities as C, DevToolsViewHost as D, DevToolsPluginOptions as E, DevToolsRpcClientFunctions as F, DevToolsViewBuiltin as G, DevToolsDockHost as H, DevToolsRpcServerFunctions as I, DevToolsViewLauncher as J, DevToolsViewCustomRender as K, ClientScriptEntry as L, DevToolsTerminalSessionBase as M, DevToolsTerminalSessionStreamChunkEvent as N, DevToolsChildProcessExecuteOptions as O, DevToolsTerminalStatus as P, DevToolsDockEntry as R, ConnectionMeta as S, DevToolsNodeUtils as T, DevToolsDockUserEntry as U, DevToolsDockEntryIcon as V, DevToolsViewAction as W, DevToolsViewLauncherStatus as Y, PluginWithDevTools as _, DockEntryState as a, Thenable as b, DocksContext as c, RpcClientEvents as d, DevToolsRpcClient as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, DockClientType as i, DevToolsTerminalSession as j, DevToolsChildProcessTerminalSession as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsViewIframe as q, DevToolsClientRpcHost as r, DockPanelStorage as s, DockClientScriptContext as t, DocksPanelContext as u, EntriesToObject as v, DevToolsNodeContext as w, RpcFunctionsHost as x, PartialWithoutId as y, DevToolsDockEntryBase as z };
456
+ export { DevToolsViewHost as A, ClientScriptEntry as B, DevToolsNodeRpcSessionMeta as C, DevToolsNodeContext as D, DevToolsCapabilities as E, DevToolsTerminalSessionBase as F, DevToolsDockHost as G, DevToolsDockEntryBase as H, DevToolsTerminalSessionStreamChunkEvent as I, DevToolsViewBuiltin as J, DevToolsDockUserEntry as K, DevToolsTerminalStatus as L, DevToolsChildProcessTerminalSession as M, DevToolsTerminalHost as N, DevToolsNodeUtils as O, DevToolsTerminalSession as P, DevToolsViewLauncherStatus as Q, DevToolsRpcClientFunctions as R, DevToolsNodeRpcSession as S, ConnectionMeta as T, DevToolsDockEntryCategory as U, DevToolsDockEntry as V, DevToolsDockEntryIcon as W, DevToolsViewIframe as X, DevToolsViewCustomRender as Y, DevToolsViewLauncher as Z, PluginWithDevTools as _, DockEntryState as a, PartialWithoutId as b, DocksContext as c, RpcClientEvents as d, DevToolsRpcClient as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, DockClientType as i, DevToolsChildProcessExecuteOptions as j, DevToolsPluginOptions as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsViewAction as q, DevToolsClientRpcHost as r, DockPanelStorage as s, DockClientScriptContext as t, DocksPanelContext as u, ViteConfigDevtoolsOptions as v, RpcFunctionsHost as w, Thenable as x, EntriesToObject as y, DevToolsRpcServerFunctions as z };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { n as EventUnsubscribe, r as EventsMap, t as EventEmitter } from "./events-S6nCJ_5X.mjs";
2
- import { A as DevToolsTerminalHost, B as DevToolsDockEntryCategory, C as DevToolsCapabilities, D as DevToolsViewHost, E as DevToolsPluginOptions, F as DevToolsRpcClientFunctions, G as DevToolsViewBuiltin, H as DevToolsDockHost, I as DevToolsRpcServerFunctions, J as DevToolsViewLauncher, K as DevToolsViewCustomRender, L as ClientScriptEntry, M as DevToolsTerminalSessionBase, N as DevToolsTerminalSessionStreamChunkEvent, O as DevToolsChildProcessExecuteOptions, P as DevToolsTerminalStatus, R as DevToolsDockEntry, S as ConnectionMeta, T as DevToolsNodeUtils, U as DevToolsDockUserEntry, V as DevToolsDockEntryIcon, W as DevToolsViewAction, Y as DevToolsViewLauncherStatus, _ as PluginWithDevTools, b as Thenable, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, j as DevToolsTerminalSession, k as DevToolsChildProcessTerminalSession, q as DevToolsViewIframe, v as EntriesToObject, w as DevToolsNodeContext, x as RpcFunctionsHost, y as PartialWithoutId, z as DevToolsDockEntryBase } from "./index-DLPbKO1M.mjs";
1
+ import { n as EventUnsubscribe, r as EventsMap, t as EventEmitter } from "./events-BrHMyEqJ.mjs";
2
+ import { A as DevToolsViewHost, B as ClientScriptEntry, C as DevToolsNodeRpcSessionMeta, D as DevToolsNodeContext, E as DevToolsCapabilities, F as DevToolsTerminalSessionBase, G as DevToolsDockHost, H as DevToolsDockEntryBase, I as DevToolsTerminalSessionStreamChunkEvent, J as DevToolsViewBuiltin, K as DevToolsDockUserEntry, L as DevToolsTerminalStatus, M as DevToolsChildProcessTerminalSession, N as DevToolsTerminalHost, O as DevToolsNodeUtils, P as DevToolsTerminalSession, Q as DevToolsViewLauncherStatus, R as DevToolsRpcClientFunctions, S as DevToolsNodeRpcSession, T as ConnectionMeta, U as DevToolsDockEntryCategory, V as DevToolsDockEntry, W as DevToolsDockEntryIcon, X as DevToolsViewIframe, Y as DevToolsViewCustomRender, Z as DevToolsViewLauncher, _ as PluginWithDevTools, b as PartialWithoutId, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, j as DevToolsChildProcessExecuteOptions, k as DevToolsPluginOptions, q as DevToolsViewAction, v as ViteConfigDevtoolsOptions, w as RpcFunctionsHost, x as Thenable, y as EntriesToObject, z as DevToolsRpcServerFunctions } from "./index-FzXSK6np.mjs";
3
3
  import * as birpc_x0 from "birpc-x";
4
4
 
5
5
  //#region src/utils/define.d.ts
6
6
  declare const defineRpcFunction: <NAME extends string, TYPE extends birpc_x0.RpcFunctionType, ARGS$1 extends any[], RETURN$1 = void>(definition: birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS$1, RETURN$1, DevToolsNodeContext>) => birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS$1, RETURN$1, DevToolsNodeContext>;
7
7
  //#endregion
8
- export { ClientScriptEntry, ConnectionMeta, DevToolsCapabilities, DevToolsChildProcessExecuteOptions, DevToolsChildProcessTerminalSession, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockEntryCategory, DevToolsDockEntryIcon, DevToolsDockHost, DevToolsDockUserEntry, DevToolsNodeContext, DevToolsNodeUtils, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsTerminalHost, DevToolsTerminalSession, DevToolsTerminalSessionBase, DevToolsTerminalSessionStreamChunkEvent, DevToolsTerminalStatus, DevToolsViewAction, DevToolsViewBuiltin, DevToolsViewCustomRender, DevToolsViewHost, DevToolsViewIframe, DevToolsViewLauncher, DevToolsViewLauncherStatus, EntriesToObject, EventEmitter, EventUnsubscribe, EventsMap, PartialWithoutId, PluginWithDevTools, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsHost, Thenable, defineRpcFunction };
8
+ export { ClientScriptEntry, ConnectionMeta, DevToolsCapabilities, DevToolsChildProcessExecuteOptions, DevToolsChildProcessTerminalSession, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockEntryCategory, DevToolsDockEntryIcon, DevToolsDockHost, DevToolsDockUserEntry, DevToolsNodeContext, DevToolsNodeRpcSession, DevToolsNodeRpcSessionMeta, DevToolsNodeUtils, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsTerminalHost, DevToolsTerminalSession, DevToolsTerminalSessionBase, DevToolsTerminalSessionStreamChunkEvent, DevToolsTerminalStatus, DevToolsViewAction, DevToolsViewBuiltin, DevToolsViewCustomRender, DevToolsViewHost, DevToolsViewIframe, DevToolsViewLauncher, DevToolsViewLauncherStatus, EntriesToObject, EventEmitter, EventUnsubscribe, EventsMap, PartialWithoutId, PluginWithDevTools, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsHost, Thenable, ViteConfigDevtoolsOptions, defineRpcFunction };
@@ -0,0 +1,11 @@
1
+ //#region src/utils/nanoid.ts
2
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3
+ function nanoid(size = 21) {
4
+ let id = "";
5
+ let i = size;
6
+ while (i--) id += urlAlphabet[Math.random() * 64 | 0];
7
+ return id;
8
+ }
9
+
10
+ //#endregion
11
+ export { nanoid as t };
@@ -1,4 +1,4 @@
1
- import { r as EventsMap, t as EventEmitter } from "../events-S6nCJ_5X.mjs";
1
+ import { r as EventsMap, t as EventEmitter } from "../events-BrHMyEqJ.mjs";
2
2
 
3
3
  //#region src/utils/events.d.ts
4
4
 
@@ -1,3 +1,3 @@
1
- import { t as createEventEmitter } from "../events-AmnAXhnR.mjs";
1
+ import { t as createEventEmitter } from "../events-CWYZG96x.mjs";
2
2
 
3
3
  export { createEventEmitter };
@@ -1,11 +1,3 @@
1
- //#region src/utils/nanoid.ts
2
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3
- function nanoid(size = 21) {
4
- let id = "";
5
- let i = size;
6
- while (i--) id += urlAlphabet[Math.random() * 64 | 0];
7
- return id;
8
- }
1
+ import { t as nanoid } from "../nanoid-B0pJU5uW.mjs";
9
2
 
10
- //#endregion
11
3
  export { nanoid };
@@ -0,0 +1,50 @@
1
+ import { t as EventEmitter } from "../events-BrHMyEqJ.mjs";
2
+ import { Objectish, Patch } from "immer";
3
+
4
+ //#region src/utils/shared-state.d.ts
5
+ type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
6
+ type Immutable<T> = T extends ImmutablePrimitive ? T : T extends Array<infer U> ? ImmutableArray<U> : T extends Map<infer K, infer V> ? ImmutableMap<K, V> : T extends Set<infer M> ? ImmutableSet<M> : ImmutableObject<T>;
7
+ type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
8
+ type ImmutableMap<K$1, V$1> = ReadonlyMap<Immutable<K$1>, Immutable<V$1>>;
9
+ type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
10
+ type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
11
+ /**
12
+ * State host that is immutable by default with explicit mutate.
13
+ */
14
+ interface SharedState<T> {
15
+ /**
16
+ * Get the current state. Immutable.
17
+ */
18
+ get: () => Immutable<T>;
19
+ /**
20
+ * Subscribe to state changes.
21
+ */
22
+ on: EventEmitter<SharedStateEvents<T>>['on'];
23
+ /**
24
+ * Mutate the state.
25
+ */
26
+ mutate: (fn: (state: T) => void) => void;
27
+ /**
28
+ * Apply patches to the state.
29
+ */
30
+ patch: (patches: Patch[]) => void;
31
+ }
32
+ interface SharedStateEvents<T> {
33
+ updated: (state: T) => void;
34
+ patches: (patches: Patch[]) => void;
35
+ }
36
+ interface SharedStateOptions<T> {
37
+ /**
38
+ * Initial state.
39
+ */
40
+ initialState: T;
41
+ /**
42
+ * Enable patches.
43
+ *
44
+ * @default false
45
+ */
46
+ enablePatches?: boolean;
47
+ }
48
+ declare function createSharedState<T extends Objectish>(options: SharedStateOptions<T>): SharedState<T>;
49
+ //#endregion
50
+ export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, createSharedState };
@@ -0,0 +1,28 @@
1
+ import { t as createEventEmitter } from "../events-CWYZG96x.mjs";
2
+ import { applyPatches, produce, produceWithPatches } from "immer";
3
+
4
+ //#region src/utils/shared-state.ts
5
+ function createSharedState(options) {
6
+ const { enablePatches = false } = options;
7
+ const events = createEventEmitter();
8
+ let state = options.initialState;
9
+ return {
10
+ on: events.on,
11
+ get: () => state,
12
+ patch: (patches) => {
13
+ state = applyPatches(state, patches);
14
+ events.emit("updated", state);
15
+ },
16
+ mutate: (fn) => {
17
+ if (enablePatches) {
18
+ const [newState, patches] = produceWithPatches(state, fn);
19
+ state = newState;
20
+ events.emit("patches", patches);
21
+ } else state = produce(state, fn);
22
+ events.emit("updated", state);
23
+ }
24
+ };
25
+ }
26
+
27
+ //#endregion
28
+ export { createSharedState };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/devtools-kit",
3
3
  "type": "module",
4
- "version": "0.0.0-alpha.20",
4
+ "version": "0.0.0-alpha.21",
5
5
  "description": "Vite DevTools Kit",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
@@ -23,6 +23,7 @@
23
23
  "./client": "./dist/client.mjs",
24
24
  "./utils/events": "./dist/utils/events.mjs",
25
25
  "./utils/nanoid": "./dist/utils/nanoid.mjs",
26
+ "./utils/shared-state": "./dist/utils/shared-state.mjs",
26
27
  "./package.json": "./package.json"
27
28
  },
28
29
  "main": "./dist/index.mjs",
@@ -37,12 +38,13 @@
37
38
  "dependencies": {
38
39
  "birpc": "^4.0.0",
39
40
  "birpc-x": "0.0.6",
40
- "@vitejs/devtools-rpc": "0.0.0-alpha.20"
41
+ "immer": "^11.1.0",
42
+ "@vitejs/devtools-rpc": "0.0.0-alpha.21"
41
43
  },
42
44
  "devDependencies": {
43
45
  "my-ua-parser": "^2.0.4",
44
- "tsdown": "^0.17.4",
45
- "vite": "^8.0.0-beta.2"
46
+ "tsdown": "^0.18.2",
47
+ "vite": "^8.0.0-beta.3"
46
48
  },
47
49
  "scripts": {
48
50
  "build": "tsdown",