@vitejs/devtools-vite 0.0.0-alpha.20 → 0.0.0-alpha.22

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/index.d.mts CHANGED
@@ -1,7 +1,9 @@
1
+ import { BirpcReturn } from "birpc";
2
+ import { WebSocket } from "ws";
1
3
  import { RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
4
+ import { Patch } from "immer";
2
5
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
6
  import { Raw } from "vue";
4
- import { BirpcReturn } from "birpc";
5
7
  import { ChildProcess } from "node:child_process";
6
8
 
7
9
  //#region ../kit/src/types/events.d.ts
@@ -22,14 +24,14 @@ interface EventEmitter<Events extends EventsMap> {
22
24
  * @param event The event name.
23
25
  * @param args The arguments for listeners.
24
26
  */
25
- emit: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
27
+ emit: <K$1 extends keyof Events>(event: K$1, ...args: Parameters<Events[K$1]>) => void;
26
28
  /**
27
29
  * Calls the listeners for a given event once and then removes the listener.
28
30
  *
29
31
  * @param event The event name.
30
32
  * @param args The arguments for listeners.
31
33
  */
32
- emitOnce: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
34
+ emitOnce: <K$1 extends keyof Events>(event: K$1, ...args: Parameters<Events[K$1]>) => void;
33
35
  /**
34
36
  * Event names in keys and arrays with listeners in values.
35
37
  *
@@ -53,7 +55,7 @@ interface EventEmitter<Events extends EventsMap> {
53
55
  * @param cb The listener function.
54
56
  * @returns Unbind listener from event.
55
57
  */
56
- on: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
58
+ on: <K$1 extends keyof Events>(event: K$1, cb: Events[K$1]) => EventUnsubscribe;
57
59
  /**
58
60
  * Add a listener for a given event once.
59
61
  *
@@ -71,7 +73,7 @@ interface EventEmitter<Events extends EventsMap> {
71
73
  * @param cb The listener function.
72
74
  * @returns Unbind listener from event.
73
75
  */
74
- once: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
76
+ once: <K$1 extends keyof Events>(event: K$1, cb: Events[K$1]) => EventUnsubscribe;
75
77
  }
76
78
  //#endregion
77
79
  //#region ../kit/src/types/docks.d.ts
@@ -162,11 +164,55 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
162
164
  }
163
165
  interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
164
166
  type: '~builtin';
165
- id: '~terminals' | '~logs';
167
+ id: '~terminals' | '~logs' | '~client-auth-notice';
166
168
  }
167
169
  type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
168
170
  type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
169
171
  //#endregion
172
+ //#region ../rpc/src/presets/ws/server.d.ts
173
+ interface DevToolsNodeRpcSessionMeta {
174
+ id: number;
175
+ ws?: WebSocket;
176
+ clientAuthId?: string;
177
+ isTrusted?: boolean;
178
+ }
179
+ //#endregion
180
+ //#region ../kit/src/utils/shared-state.d.ts
181
+ type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
182
+ 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>;
183
+ type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
184
+ type ImmutableMap<K$1, V$1> = ReadonlyMap<Immutable<K$1>, Immutable<V$1>>;
185
+ type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
186
+ type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
187
+ /**
188
+ * State host that is immutable by default with explicit mutate.
189
+ */
190
+ interface SharedState<T> {
191
+ /**
192
+ * Get the current state. Immutable.
193
+ */
194
+ value: () => Immutable<T>;
195
+ /**
196
+ * Subscribe to state changes.
197
+ */
198
+ on: EventEmitter<SharedStateEvents<T>>['on'];
199
+ /**
200
+ * Mutate the state.
201
+ */
202
+ mutate: (fn: (state: T) => void, syncId?: string) => void;
203
+ /**
204
+ * Apply patches to the state.
205
+ */
206
+ patch: (patches: Patch[], syncId?: string) => void;
207
+ /**
208
+ * Sync IDs that have been applied to the state.
209
+ */
210
+ syncIds: Set<string>;
211
+ }
212
+ interface SharedStateEvents<T> {
213
+ updated: (fullState: T, patches: Patch[] | undefined, syncId: string) => void;
214
+ }
215
+ //#endregion
170
216
  //#region ../kit/src/types/rpc-augments.d.ts
171
217
  /**
172
218
  * To be extended
@@ -176,6 +222,10 @@ interface DevToolsRpcClientFunctions {}
176
222
  * To be extended
177
223
  */
178
224
  interface DevToolsRpcServerFunctions {}
225
+ /**
226
+ * To be extended
227
+ */
228
+ interface DevToolsRpcSharedStates {}
179
229
  //#endregion
180
230
  //#region ../kit/src/client/rpc.d.ts
181
231
  interface DevToolsRpcClient {
@@ -183,10 +233,26 @@ interface DevToolsRpcClient {
183
233
  * The events of the client
184
234
  */
185
235
  events: EventEmitter<RpcClientEvents>;
236
+ /**
237
+ * Whether the client is trusted
238
+ */
239
+ readonly isTrusted: boolean | null;
186
240
  /**
187
241
  * The connection meta
188
242
  */
189
243
  readonly connectionMeta: ConnectionMeta;
244
+ /**
245
+ * Return a promise that resolves when the client is trusted
246
+ *
247
+ * Rejects with an error if the timeout is reached
248
+ *
249
+ * @param timeout - The timeout in milliseconds, default to 60 seconds
250
+ */
251
+ ensureTrusted: (timeout?: number) => Promise<boolean>;
252
+ /**
253
+ * Request trust from the server
254
+ */
255
+ requestTrust: () => Promise<boolean>;
190
256
  /**
191
257
  * Call a RPC function on the server
192
258
  */
@@ -203,6 +269,10 @@ interface DevToolsRpcClient {
203
269
  * The client RPC host
204
270
  */
205
271
  client: DevToolsClientRpcHost;
272
+ /**
273
+ * The shared state host
274
+ */
275
+ sharedState: RpcSharedStateHost;
206
276
  }
207
277
  //#endregion
208
278
  //#region ../kit/src/client/docks.d.ts
@@ -260,6 +330,12 @@ interface DocksEntriesContext {
260
330
  * @returns Whether the selection was changed successfully
261
331
  */
262
332
  switchEntry: (id?: string | null) => Promise<boolean>;
333
+ /**
334
+ * Toggle the selected dock entry
335
+ *
336
+ * @returns Whether the selection was changed successfully
337
+ */
338
+ toggleEntry: (id: string) => Promise<boolean>;
263
339
  }
264
340
  interface DockEntryState {
265
341
  entryMeta: DevToolsDockEntry;
@@ -277,7 +353,9 @@ interface DockEntryStateEvents {
277
353
  'dom:panel:mounted': (panel: HTMLDivElement) => void;
278
354
  'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
279
355
  }
280
- interface RpcClientEvents {}
356
+ interface RpcClientEvents {
357
+ 'rpc:is-trusted:updated': (isTrusted: boolean) => void;
358
+ }
281
359
  //#endregion
282
360
  //#region ../kit/src/client/client-script.d.ts
283
361
  /**
@@ -362,14 +440,47 @@ interface DevToolsPluginOptions {
362
440
  setup: (context: DevToolsNodeContext) => void | Promise<void>;
363
441
  }
364
442
  interface DevToolsNodeContext {
443
+ /**
444
+ * Workspace root directory of Vite DevTools
445
+ */
446
+ readonly workspaceRoot: string;
447
+ /**
448
+ * Current working directory of Vite DevTools
449
+ */
365
450
  readonly cwd: string;
451
+ /**
452
+ * Current mode of Vite DevTools
453
+ * - 'dev' - when Vite DevTools is running in dev mode
454
+ * - 'build' - when Vite DevTools is running in build mode (no server)
455
+ */
366
456
  readonly mode: 'dev' | 'build';
457
+ /**
458
+ * Resolved Vite configuration
459
+ */
367
460
  readonly viteConfig: ResolvedConfig;
461
+ /**
462
+ * Vite dev server instance (only available in dev mode)
463
+ */
368
464
  readonly viteServer?: ViteDevServer;
465
+ /**
466
+ * RPC functions host, for registering server-side RPC functions and calling client-side RPC functions
467
+ */
369
468
  rpc: RpcFunctionsHost;
469
+ /**
470
+ * Docks host, for registering dock entries
471
+ */
370
472
  docks: DevToolsDockHost;
473
+ /**
474
+ * Views host, for registering static views
475
+ */
371
476
  views: DevToolsViewHost;
477
+ /**
478
+ * Utils for the node context
479
+ */
372
480
  utils: DevToolsNodeUtils;
481
+ /**
482
+ * Terminals host, for registering terminal sessions and streaming terminal output
483
+ */
373
484
  terminals: DevToolsTerminalHost;
374
485
  }
375
486
  interface DevToolsNodeUtils {
@@ -387,15 +498,60 @@ interface ConnectionMeta {
387
498
  }
388
499
  //#endregion
389
500
  //#region ../kit/src/types/rpc.d.ts
501
+ interface DevToolsNodeRpcSession {
502
+ meta: DevToolsNodeRpcSessionMeta;
503
+ rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
504
+ }
505
+ interface RpcBroadcastOptions<METHOD, Args extends any[]> {
506
+ method: METHOD;
507
+ args: Args;
508
+ optional?: boolean;
509
+ event?: boolean;
510
+ filter?: (client: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>) => boolean | void;
511
+ }
390
512
  type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
391
- boardcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
513
+ /**
514
+ * Broadcast a message to all connected clients
515
+ */
516
+ broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(options: RpcBroadcastOptions<T, Args>) => Promise<void>;
517
+ /**
518
+ * Get the current RPC client
519
+ *
520
+ * Available in RPC functions to get the current RPC client
521
+ */
522
+ getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
523
+ /**
524
+ * The shared state host
525
+ */
526
+ sharedState: RpcSharedStateHost;
392
527
  };
528
+ interface RpcSharedStateGetOptions<T> {
529
+ initialValue?: T;
530
+ }
531
+ interface RpcSharedStateHost {
532
+ get: <T extends keyof DevToolsRpcSharedStates>(key: T, options?: RpcSharedStateGetOptions<DevToolsRpcSharedStates[T]>) => Promise<SharedState<DevToolsRpcSharedStates[T]>>;
533
+ }
393
534
  //#endregion
394
535
  //#region ../kit/src/types/vite-augment.d.ts
395
536
  declare module 'vite' {
396
537
  interface Plugin {
397
538
  devtools?: DevToolsPluginOptions;
398
539
  }
540
+ interface UserConfig {
541
+ devtools?: ViteConfigDevtoolsOptions;
542
+ }
543
+ }
544
+ interface ViteConfigDevtoolsOptions {
545
+ /**
546
+ * Disable client authentication.
547
+ *
548
+ * Beware that if you disable client authentication,
549
+ * any browsers can connect to the devtools and access to your server and filesystem.
550
+ * (including other devices, if you open server `host` option to LAN or WAN)
551
+ *
552
+ * @default true
553
+ */
554
+ clientAuth?: boolean;
399
555
  }
400
556
  interface PluginWithDevTools extends Plugin {
401
557
  devtools?: DevToolsPluginOptions;