@vitejs/devtools 0.0.0-alpha.17 → 0.0.0-alpha.19

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,50 +1,76 @@
1
1
  import { RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
2
2
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
- import { Emitter } from "nanoevents";
4
3
  import { Raw } from "vue";
5
4
  import { BirpcGroup, BirpcReturn } from "birpc";
5
+ import { ChildProcess } from "node:child_process";
6
6
  import "@vitejs/devtools-rpc/presets/ws/client";
7
7
 
8
- //#region ../kit/src/types/rpc-augments.d.ts
9
- /**
10
- * To be extended
11
- */
12
- interface DevToolsRpcClientFunctions {}
13
- /**
14
- * To be extended
15
- */
16
- interface DevToolsRpcServerFunctions {}
17
- //#endregion
18
- //#region ../kit/src/types/views.d.ts
19
- interface DevToolsDockHost {
20
- views: Map<string, DevToolsDockEntry>;
21
- register: (entry: DevToolsDockEntry) => void;
22
- update: (entry: DevToolsDockEntry) => void;
23
- values: () => DevToolsDockEntry[];
8
+ //#region ../kit/src/types/events.d.ts
9
+ interface EventsMap {
10
+ [event: string]: any;
24
11
  }
25
- interface DevToolsViewHost {
12
+ interface EventUnsubscribe {
13
+ (): void;
14
+ }
15
+ interface EventEmitter<Events extends EventsMap> {
16
+ /**
17
+ * Calls each of the listeners registered for a given event.
18
+ *
19
+ * ```js
20
+ * ee.emit('tick', tickType, tickDuration)
21
+ * ```
22
+ *
23
+ * @param event The event name.
24
+ * @param args The arguments for listeners.
25
+ */
26
+ emit: <K extends keyof Events>(this: this, event: K, ...args: Parameters<Events[K]>) => void;
26
27
  /**
28
+ * Event names in keys and arrays with listeners in values.
29
+ *
27
30
  * @internal
28
31
  */
29
- buildStaticDirs: {
30
- baseUrl: string;
31
- distDir: string;
32
- }[];
32
+ _listeners: Partial<{ [E in keyof Events]: Events[E][] }>;
33
33
  /**
34
- * Helper to host static files
35
- * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
36
- * - In `build` mode, it will copy the static files to the dist directory
34
+ * Add a listener for a given event.
35
+ *
36
+ * ```js
37
+ * const unbind = ee.on('tick', (tickType, tickDuration) => {
38
+ * count += 1
39
+ * })
40
+ *
41
+ * disable () {
42
+ * unbind()
43
+ * }
44
+ * ```
45
+ *
46
+ * @param event The event name.
47
+ * @param cb The listener function.
48
+ * @returns Unbind listener from event.
37
49
  */
38
- hostStatic: (baseUrl: string, distDir: string) => void;
50
+ on: <K extends keyof Events>(this: this, event: K, cb: Events[K]) => EventUnsubscribe;
51
+ }
52
+ //#endregion
53
+ //#region ../kit/src/types/docks.d.ts
54
+ interface DevToolsDockHost {
55
+ readonly views: Map<string, DevToolsDockUserEntry>;
56
+ readonly events: EventEmitter<{
57
+ 'dock:entry:updated': (entry: DevToolsDockUserEntry) => void;
58
+ }>;
59
+ register: <T extends DevToolsDockUserEntry>(entry: T, force?: boolean) => {
60
+ update: (patch: Partial<T>) => void;
61
+ };
62
+ update: (entry: DevToolsDockUserEntry) => void;
63
+ values: () => DevToolsDockUserEntry[];
39
64
  }
40
65
  type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
66
+ type DevToolsDockEntryIcon = string | {
67
+ light: string;
68
+ dark: string;
69
+ };
41
70
  interface DevToolsDockEntryBase {
42
71
  id: string;
43
72
  title: string;
44
- icon: string | {
45
- light: string;
46
- dark: string;
47
- };
73
+ icon: DevToolsDockEntryIcon;
48
74
  /**
49
75
  * The default order of the entry in the dock.
50
76
  * The higher the number the earlier it appears.
@@ -56,6 +82,11 @@ interface DevToolsDockEntryBase {
56
82
  * @default 'default'
57
83
  */
58
84
  category?: DevToolsDockEntryCategory;
85
+ /**
86
+ * Whether the entry should be hidden from the user.
87
+ * @default false
88
+ */
89
+ isHidden?: boolean;
59
90
  }
60
91
  interface ClientScriptEntry {
61
92
  /**
@@ -83,6 +114,20 @@ interface DevToolsViewIframe extends DevToolsDockEntryBase {
83
114
  */
84
115
  clientScript?: ClientScriptEntry;
85
116
  }
117
+ type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
118
+ interface DevToolsViewLauncher extends DevToolsDockEntryBase {
119
+ type: 'launcher';
120
+ launcher: {
121
+ icon?: DevToolsDockEntryIcon;
122
+ title: string;
123
+ status?: DevToolsViewLauncherStatus;
124
+ error?: string;
125
+ description?: string;
126
+ buttonStart?: string;
127
+ buttonLoading?: string;
128
+ onLaunch: () => Promise<void>;
129
+ };
130
+ }
86
131
  interface DevToolsViewAction extends DevToolsDockEntryBase {
87
132
  type: 'action';
88
133
  action: ClientScriptEntry;
@@ -91,7 +136,81 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
91
136
  type: 'custom-render';
92
137
  renderer: ClientScriptEntry;
93
138
  }
94
- type DevToolsDockEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender;
139
+ interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
140
+ type: '~builtin';
141
+ id: '~terminals' | '~logs';
142
+ }
143
+ type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
144
+ type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
145
+ //#endregion
146
+ //#region ../kit/src/types/rpc-augments.d.ts
147
+ /**
148
+ * To be extended
149
+ */
150
+ interface DevToolsRpcClientFunctions {}
151
+ /**
152
+ * To be extended
153
+ */
154
+ interface DevToolsRpcServerFunctions {}
155
+ //#endregion
156
+ //#region ../kit/src/types/terminals.d.ts
157
+ interface DevToolsTerminalSessionStreamChunkEvent {
158
+ id: string;
159
+ chunks: string[];
160
+ ts: number;
161
+ }
162
+ interface DevToolsTerminalHost {
163
+ readonly sessions: Map<string, DevToolsTerminalSession>;
164
+ readonly events: EventEmitter<{
165
+ 'terminal:session:updated': (session: DevToolsTerminalSession) => void;
166
+ 'terminal:session:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => void;
167
+ }>;
168
+ register: (session: DevToolsTerminalSession) => DevToolsTerminalSession;
169
+ update: (session: DevToolsTerminalSession) => void;
170
+ startChildProcess: (executeOptions: DevToolsChildProcessExecuteOptions, terminal: Omit<DevToolsTerminalSessionBase, 'status'>) => Promise<DevToolsChildProcessTerminalSession>;
171
+ }
172
+ type DevToolsTerminalStatus = 'running' | 'stopped' | 'error';
173
+ interface DevToolsTerminalSessionBase {
174
+ id: string;
175
+ title: string;
176
+ description?: string;
177
+ status: DevToolsTerminalStatus;
178
+ icon?: DevToolsDockEntryIcon;
179
+ }
180
+ interface DevToolsTerminalSession extends DevToolsTerminalSessionBase {
181
+ buffer?: string[];
182
+ stream?: ReadableStream<string>;
183
+ }
184
+ interface DevToolsChildProcessExecuteOptions {
185
+ command: string;
186
+ args: string[];
187
+ cwd?: string;
188
+ env?: Record<string, string>;
189
+ }
190
+ interface DevToolsChildProcessTerminalSession extends DevToolsTerminalSession {
191
+ type: 'child-process';
192
+ executeOptions: DevToolsChildProcessExecuteOptions;
193
+ getChildProcess: () => ChildProcess | undefined;
194
+ terminate: () => Promise<void>;
195
+ restart: () => Promise<void>;
196
+ }
197
+ //#endregion
198
+ //#region ../kit/src/types/views.d.ts
199
+ interface DevToolsViewHost {
200
+ /**
201
+ * @internal
202
+ */
203
+ buildStaticDirs: {
204
+ baseUrl: string;
205
+ distDir: string;
206
+ }[];
207
+ /**
208
+ * Helper to host static files
209
+ * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
210
+ * - In `build` mode, it will copy the static files to the dist directory
211
+ */
212
+ hostStatic: (baseUrl: string, distDir: string) => void;
213
+ }
95
214
  //#endregion
96
215
  //#region ../kit/src/types/vite-plugin.d.ts
97
216
  interface DevToolsCapabilities {
@@ -114,6 +233,7 @@ interface DevToolsNodeContext {
114
233
  docks: DevToolsDockHost;
115
234
  views: DevToolsViewHost;
116
235
  utils: DevToolsNodeUtils;
236
+ terminals: DevToolsTerminalHost;
117
237
  }
118
238
  interface DevToolsNodeUtils {
119
239
  /**
@@ -170,7 +290,7 @@ interface DocksContext extends DevToolsClientContext {
170
290
  * Type of the client environment
171
291
  *
172
292
  * 'embedded' - running inside an embedded floating panel
173
- * 'standalone' - running inside a standlone window (no user app)
293
+ * 'standalone' - running inside a standalone window (no user app)
174
294
  */
175
295
  readonly clientType: 'embedded' | 'standalone';
176
296
  /**
@@ -194,7 +314,8 @@ interface DocksPanelContext {
194
314
  readonly isVertical: boolean;
195
315
  }
196
316
  interface DocksEntriesContext {
197
- selected: DevToolsDockEntry | null;
317
+ selectedId: string | null;
318
+ readonly selected: DevToolsDockEntry | null;
198
319
  entries: DevToolsDockEntry[];
199
320
  entryToStateMap: Map<string, DockEntryState>;
200
321
  /**
@@ -206,7 +327,7 @@ interface DocksEntriesContext {
206
327
  *
207
328
  * @returns Whether the selection was changed successfully
208
329
  */
209
- switchEntry: (id: string | null) => Promise<boolean>;
330
+ switchEntry: (id?: string | null) => Promise<boolean>;
210
331
  }
211
332
  interface DockEntryState {
212
333
  entryMeta: DevToolsDockEntry;
@@ -215,12 +336,12 @@ interface DockEntryState {
215
336
  iframe?: HTMLIFrameElement | null;
216
337
  panel?: HTMLDivElement | null;
217
338
  };
218
- events: Raw<Emitter<DockEntryStateEvents>>;
339
+ events: Raw<EventEmitter<DockEntryStateEvents>>;
219
340
  }
220
341
  interface DockEntryStateEvents {
221
342
  'entry:activated': () => void;
222
343
  'entry:deactivated': () => void;
223
- 'entry:updated': (newMeta: DevToolsDockEntry) => void;
344
+ 'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
224
345
  'dom:panel:mounted': (panel: HTMLDivElement) => void;
225
346
  'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
226
347
  }
@@ -236,4 +357,4 @@ interface DockClientScriptContext extends DocksContext {
236
357
  current: DockEntryState;
237
358
  }
238
359
  //#endregion
239
- export { DevToolsNodeContext as a, DevToolsRpcServerFunctions as c, RpcDefinitionsToFunctions as i, DocksContext as n, DevToolsDockEntry as o, ClientRpcReturn as r, DevToolsRpcClientFunctions as s, DockPanelStorage as t };
360
+ export { RpcDefinitionsToFunctions as a, DevToolsTerminalSessionBase as c, DevToolsRpcServerFunctions as d, DevToolsDockEntry as f, ClientRpcReturn as i, DevToolsTerminalSessionStreamChunkEvent as l, DockPanelStorage as n, ConnectionMeta as o, DocksContext as r, DevToolsNodeContext as s, DockEntryState as t, DevToolsRpcClientFunctions as u };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as DevToolsNodeContext, c as DevToolsRpcServerFunctions, i as RpcDefinitionsToFunctions, o as DevToolsDockEntry, s as DevToolsRpcClientFunctions } from "./index-DFE-IX9X.js";
1
+ import { a as RpcDefinitionsToFunctions, c as DevToolsTerminalSessionBase, d as DevToolsRpcServerFunctions, f as DevToolsDockEntry, l as DevToolsTerminalSessionStreamChunkEvent, o as ConnectionMeta, s as DevToolsNodeContext, u as DevToolsRpcClientFunctions } from "./index-Wdefo_Ne.js";
2
2
  import * as birpc_x0 from "birpc-x";
3
3
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
4
4
  import * as birpc0 from "birpc";
@@ -8,16 +8,21 @@ import * as h30 from "h3";
8
8
  declare function createDevToolsContext(viteConfig: ResolvedConfig, viteServer?: ViteDevServer): Promise<DevToolsNodeContext>;
9
9
  //#endregion
10
10
  //#region src/node/rpc/index.d.ts
11
- declare const builtinRpcFunctions: readonly [birpc_x0.RpcFunctionDefinition<"vite:core:list-rpc-functions", "action", [], Promise<{
11
+ declare const builtinRpcDecalrations: readonly [birpc_x0.RpcFunctionDefinition<"vite:core:open-in-editor", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:open-in-finder", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:docks:list", "static", [], DevToolsDockEntry[], DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:docks:on-launch", "action", [entryId: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server:list", "static", [], Promise<{
12
12
  [k: string]: {
13
13
  type: any;
14
14
  };
15
- }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:list-dock-entries", "query", [], DevToolsDockEntry[], DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:open-in-editor", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:open-in-finder", "action", [path: string], Promise<void>, DevToolsNodeContext>];
16
- type ServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcFunctions>;
15
+ }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:list", "static", [], Promise<DevToolsTerminalSessionBase[]>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:read", "query", [id: string], Promise<{
16
+ buffer: string[];
17
+ ts: number;
18
+ }>, DevToolsNodeContext>];
19
+ type BuiltinServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcDecalrations>;
17
20
  declare module '@vitejs/devtools-kit' {
18
- interface DevToolsRpcServerFunctions extends ServerFunctions {}
21
+ interface DevToolsRpcServerFunctions extends BuiltinServerFunctions {}
19
22
  interface DevToolsRpcClientFunctions {
20
- 'vite:core:list-dock-entries:updated': () => Promise<void>;
23
+ 'vite:internal:docks:updated': () => Promise<void>;
24
+ 'vite:internal:terminals:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => Promise<void>;
25
+ 'vite:internal:terminals:updated': () => Promise<void>;
21
26
  }
22
27
  }
23
28
  //#endregion
@@ -43,8 +48,9 @@ interface CreateWsServerOptions {
43
48
  //#region src/node/server.d.ts
44
49
  declare function createDevToolsMiddleware(options: CreateWsServerOptions): Promise<{
45
50
  h3: h30.App;
46
- middleware: h30.NodeListener;
47
51
  rpc: birpc0.BirpcGroup<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions>;
52
+ middleware: h30.NodeListener;
53
+ getConnectionMeta: () => Promise<ConnectionMeta>;
48
54
  }>;
49
55
  //#endregion
50
56
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-B_YgEdT2.js";
1
+ import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-l6D28NJB.js";
2
2
  import "./dirs-DcSK9l9L.js";
3
3
 
4
4
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };