@vitejs/devtools 0.0.0-alpha.2 → 0.0.0-alpha.20

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.
@@ -0,0 +1,401 @@
1
+ import { RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
2
+ import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
+ import { Raw } from "vue";
4
+ import { ChildProcess } from "node:child_process";
5
+ import { BirpcReturn } from "birpc";
6
+
7
+ //#region ../kit/src/types/events.d.ts
8
+ interface EventsMap {
9
+ [event: string]: any;
10
+ }
11
+ interface EventUnsubscribe {
12
+ (): void;
13
+ }
14
+ interface EventEmitter<Events extends EventsMap> {
15
+ /**
16
+ * Calls each of the listeners registered for a given event.
17
+ *
18
+ * ```js
19
+ * ee.emit('tick', tickType, tickDuration)
20
+ * ```
21
+ *
22
+ * @param event The event name.
23
+ * @param args The arguments for listeners.
24
+ */
25
+ emit: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
26
+ /**
27
+ * Calls the listeners for a given event once and then removes the listener.
28
+ *
29
+ * @param event The event name.
30
+ * @param args The arguments for listeners.
31
+ */
32
+ emitOnce: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
33
+ /**
34
+ * Event names in keys and arrays with listeners in values.
35
+ *
36
+ * @internal
37
+ */
38
+ _listeners: Partial<{ [E in keyof Events]: Events[E][] }>;
39
+ /**
40
+ * Add a listener for a given event.
41
+ *
42
+ * ```js
43
+ * const unbind = ee.on('tick', (tickType, tickDuration) => {
44
+ * count += 1
45
+ * })
46
+ *
47
+ * disable () {
48
+ * unbind()
49
+ * }
50
+ * ```
51
+ *
52
+ * @param event The event name.
53
+ * @param cb The listener function.
54
+ * @returns Unbind listener from event.
55
+ */
56
+ on: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
57
+ /**
58
+ * Add a listener for a given event once.
59
+ *
60
+ * ```js
61
+ * const unbind = ee.once('tick', (tickType, tickDuration) => {
62
+ * count += 1
63
+ * })
64
+ *
65
+ * disable () {
66
+ * unbind()
67
+ * }
68
+ * ```
69
+ *
70
+ * @param event The event name.
71
+ * @param cb The listener function.
72
+ * @returns Unbind listener from event.
73
+ */
74
+ once: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
75
+ }
76
+ //#endregion
77
+ //#region ../kit/src/types/docks.d.ts
78
+ interface DevToolsDockHost {
79
+ readonly views: Map<string, DevToolsDockUserEntry>;
80
+ readonly events: EventEmitter<{
81
+ 'dock:entry:updated': (entry: DevToolsDockUserEntry) => void;
82
+ }>;
83
+ register: <T extends DevToolsDockUserEntry>(entry: T, force?: boolean) => {
84
+ update: (patch: Partial<T>) => void;
85
+ };
86
+ update: (entry: DevToolsDockUserEntry) => void;
87
+ values: () => DevToolsDockUserEntry[];
88
+ }
89
+ type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
90
+ type DevToolsDockEntryIcon = string | {
91
+ light: string;
92
+ dark: string;
93
+ };
94
+ interface DevToolsDockEntryBase {
95
+ id: string;
96
+ title: string;
97
+ icon: DevToolsDockEntryIcon;
98
+ /**
99
+ * The default order of the entry in the dock.
100
+ * The higher the number the earlier it appears.
101
+ * @default 0
102
+ */
103
+ defaultOrder?: number;
104
+ /**
105
+ * The category of the entry
106
+ * @default 'default'
107
+ */
108
+ category?: DevToolsDockEntryCategory;
109
+ /**
110
+ * Whether the entry should be hidden from the user.
111
+ * @default false
112
+ */
113
+ isHidden?: boolean;
114
+ }
115
+ interface ClientScriptEntry {
116
+ /**
117
+ * The filepath or module name to import from
118
+ */
119
+ importFrom: string;
120
+ /**
121
+ * The name to import the module as
122
+ *
123
+ * @default 'default'
124
+ */
125
+ importName?: string;
126
+ }
127
+ interface DevToolsViewIframe extends DevToolsDockEntryBase {
128
+ type: 'iframe';
129
+ url: string;
130
+ /**
131
+ * The id of the iframe, if multiple tabs is assigned with the same id, the iframe will be shared.
132
+ *
133
+ * When not provided, it would be treated as a unique frame.
134
+ */
135
+ frameId?: string;
136
+ /**
137
+ * Optional client script to import into the iframe
138
+ */
139
+ clientScript?: ClientScriptEntry;
140
+ }
141
+ type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
142
+ interface DevToolsViewLauncher extends DevToolsDockEntryBase {
143
+ type: 'launcher';
144
+ launcher: {
145
+ icon?: DevToolsDockEntryIcon;
146
+ title: string;
147
+ status?: DevToolsViewLauncherStatus;
148
+ error?: string;
149
+ description?: string;
150
+ buttonStart?: string;
151
+ buttonLoading?: string;
152
+ onLaunch: () => Promise<void>;
153
+ };
154
+ }
155
+ interface DevToolsViewAction extends DevToolsDockEntryBase {
156
+ type: 'action';
157
+ action: ClientScriptEntry;
158
+ }
159
+ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
160
+ type: 'custom-render';
161
+ renderer: ClientScriptEntry;
162
+ }
163
+ interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
164
+ type: '~builtin';
165
+ id: '~terminals' | '~logs';
166
+ }
167
+ type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
168
+ type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
169
+ //#endregion
170
+ //#region ../kit/src/types/rpc-augments.d.ts
171
+ /**
172
+ * To be extended
173
+ */
174
+ interface DevToolsRpcClientFunctions {}
175
+ /**
176
+ * To be extended
177
+ */
178
+ interface DevToolsRpcServerFunctions {}
179
+ //#endregion
180
+ //#region ../kit/src/types/terminals.d.ts
181
+ interface DevToolsTerminalSessionStreamChunkEvent {
182
+ id: string;
183
+ chunks: string[];
184
+ ts: number;
185
+ }
186
+ interface DevToolsTerminalHost {
187
+ readonly sessions: Map<string, DevToolsTerminalSession>;
188
+ readonly events: EventEmitter<{
189
+ 'terminal:session:updated': (session: DevToolsTerminalSession) => void;
190
+ 'terminal:session:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => void;
191
+ }>;
192
+ register: (session: DevToolsTerminalSession) => DevToolsTerminalSession;
193
+ update: (session: DevToolsTerminalSession) => void;
194
+ startChildProcess: (executeOptions: DevToolsChildProcessExecuteOptions, terminal: Omit<DevToolsTerminalSessionBase, 'status'>) => Promise<DevToolsChildProcessTerminalSession>;
195
+ }
196
+ type DevToolsTerminalStatus = 'running' | 'stopped' | 'error';
197
+ interface DevToolsTerminalSessionBase {
198
+ id: string;
199
+ title: string;
200
+ description?: string;
201
+ status: DevToolsTerminalStatus;
202
+ icon?: DevToolsDockEntryIcon;
203
+ }
204
+ interface DevToolsTerminalSession extends DevToolsTerminalSessionBase {
205
+ buffer?: string[];
206
+ stream?: ReadableStream<string>;
207
+ }
208
+ interface DevToolsChildProcessExecuteOptions {
209
+ command: string;
210
+ args: string[];
211
+ cwd?: string;
212
+ env?: Record<string, string>;
213
+ }
214
+ interface DevToolsChildProcessTerminalSession extends DevToolsTerminalSession {
215
+ type: 'child-process';
216
+ executeOptions: DevToolsChildProcessExecuteOptions;
217
+ getChildProcess: () => ChildProcess | undefined;
218
+ terminate: () => Promise<void>;
219
+ restart: () => Promise<void>;
220
+ }
221
+ //#endregion
222
+ //#region ../kit/src/types/views.d.ts
223
+ interface DevToolsViewHost {
224
+ /**
225
+ * @internal
226
+ */
227
+ buildStaticDirs: {
228
+ baseUrl: string;
229
+ distDir: string;
230
+ }[];
231
+ /**
232
+ * Helper to host static files
233
+ * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
234
+ * - In `build` mode, it will copy the static files to the dist directory
235
+ */
236
+ hostStatic: (baseUrl: string, distDir: string) => void;
237
+ }
238
+ //#endregion
239
+ //#region ../kit/src/types/vite-plugin.d.ts
240
+ interface DevToolsCapabilities {
241
+ rpc?: boolean;
242
+ views?: boolean;
243
+ }
244
+ interface DevToolsPluginOptions {
245
+ capabilities?: {
246
+ dev?: DevToolsCapabilities | boolean;
247
+ build?: DevToolsCapabilities | boolean;
248
+ };
249
+ setup: (context: DevToolsNodeContext) => void | Promise<void>;
250
+ }
251
+ interface DevToolsNodeContext {
252
+ readonly cwd: string;
253
+ readonly mode: 'dev' | 'build';
254
+ readonly viteConfig: ResolvedConfig;
255
+ readonly viteServer?: ViteDevServer;
256
+ rpc: RpcFunctionsHost;
257
+ docks: DevToolsDockHost;
258
+ views: DevToolsViewHost;
259
+ utils: DevToolsNodeUtils;
260
+ terminals: DevToolsTerminalHost;
261
+ }
262
+ interface DevToolsNodeUtils {
263
+ /**
264
+ * Create a simple client script from a function or stringified code
265
+ *
266
+ * @deprecated DO NOT USE. This is mostly for testing only. Please use a proper importable module instead.
267
+ * @experimental
268
+ */
269
+ createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
270
+ }
271
+ interface ConnectionMeta {
272
+ backend: 'websocket' | 'static';
273
+ websocket?: number | string;
274
+ }
275
+ //#endregion
276
+ //#region ../kit/src/types/rpc.d.ts
277
+ type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
278
+ boardcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
279
+ };
280
+ //#endregion
281
+ //#region ../kit/src/types/vite-augment.d.ts
282
+ declare module 'vite' {
283
+ interface Plugin {
284
+ devtools?: DevToolsPluginOptions;
285
+ }
286
+ }
287
+ //#endregion
288
+ //#region ../kit/src/client/rpc.d.ts
289
+ interface DevToolsRpcClient {
290
+ /**
291
+ * The events of the client
292
+ */
293
+ events: EventEmitter<RpcClientEvents>;
294
+ /**
295
+ * The connection meta
296
+ */
297
+ readonly connectionMeta: ConnectionMeta;
298
+ /**
299
+ * Call a RPC function on the server
300
+ */
301
+ call: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$call'];
302
+ /**
303
+ * Call a RPC event on the server, and does not expect a response
304
+ */
305
+ callEvent: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callEvent'];
306
+ /**
307
+ * Call a RPC optional function on the server
308
+ */
309
+ callOptional: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callOptional'];
310
+ /**
311
+ * The client RPC host
312
+ */
313
+ client: DevToolsClientRpcHost;
314
+ }
315
+ //#endregion
316
+ //#region ../kit/src/client/docks.d.ts
317
+ interface DockPanelStorage {
318
+ width: number;
319
+ height: number;
320
+ top: number;
321
+ left: number;
322
+ position: 'left' | 'right' | 'bottom' | 'top';
323
+ open: boolean;
324
+ inactiveTimeout: number;
325
+ }
326
+ interface DevToolsClientContext {
327
+ /**
328
+ * The RPC client to interact with the server
329
+ */
330
+ readonly rpc: DevToolsRpcClient;
331
+ }
332
+ interface DocksContext extends DevToolsClientContext {
333
+ /**
334
+ * Type of the client environment
335
+ *
336
+ * 'embedded' - running inside an embedded floating panel
337
+ * 'standalone' - running inside a standalone window (no user app)
338
+ */
339
+ readonly clientType: 'embedded' | 'standalone';
340
+ /**
341
+ * The panel context
342
+ */
343
+ readonly panel: DocksPanelContext;
344
+ /**
345
+ * The docks entries context
346
+ */
347
+ readonly docks: DocksEntriesContext;
348
+ }
349
+ type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
350
+ interface DocksPanelContext {
351
+ store: DockPanelStorage;
352
+ isDragging: boolean;
353
+ isResizing: boolean;
354
+ readonly isVertical: boolean;
355
+ }
356
+ interface DocksEntriesContext {
357
+ selectedId: string | null;
358
+ readonly selected: DevToolsDockEntry | null;
359
+ entries: DevToolsDockEntry[];
360
+ entryToStateMap: Map<string, DockEntryState>;
361
+ /**
362
+ * Get the state of a dock entry by its ID
363
+ */
364
+ getStateById: (id: string) => DockEntryState | undefined;
365
+ /**
366
+ * Switch to the selected dock entry, pass `null` to clear the selection
367
+ *
368
+ * @returns Whether the selection was changed successfully
369
+ */
370
+ switchEntry: (id?: string | null) => Promise<boolean>;
371
+ }
372
+ interface DockEntryState {
373
+ entryMeta: DevToolsDockEntry;
374
+ readonly isActive: boolean;
375
+ domElements: {
376
+ iframe?: HTMLIFrameElement | null;
377
+ panel?: HTMLDivElement | null;
378
+ };
379
+ events: Raw<EventEmitter<DockEntryStateEvents>>;
380
+ }
381
+ interface DockEntryStateEvents {
382
+ 'entry:activated': () => void;
383
+ 'entry:deactivated': () => void;
384
+ 'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
385
+ 'dom:panel:mounted': (panel: HTMLDivElement) => void;
386
+ 'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
387
+ }
388
+ interface RpcClientEvents {}
389
+ //#endregion
390
+ //#region ../kit/src/client/client-script.d.ts
391
+ /**
392
+ * Context for client scripts running in dock entries
393
+ */
394
+ interface DockClientScriptContext extends DocksContext {
395
+ /**
396
+ * The state of the current dock entry
397
+ */
398
+ current: DockEntryState;
399
+ }
400
+ //#endregion
401
+ export { RpcDefinitionsToFunctions as a, DevToolsTerminalSessionBase as c, DevToolsRpcServerFunctions as d, DevToolsDockEntry as f, DevToolsRpcClient 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,12 +1,32 @@
1
- import { DevToolsNodeContext } from "@vitejs/devtools-kit";
2
- import "@vitejs/devtools-vite";
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-C5iw-7QZ.js";
2
+ import * as birpc_x0 from "birpc-x";
3
+ import { RpcFunctionsCollectorBase } from "birpc-x";
3
4
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
4
- import * as h30 from "h3";
5
5
  import * as birpc0 from "birpc";
6
+ import * as h30 from "h3";
6
7
 
7
8
  //#region src/node/context.d.ts
8
9
  declare function createDevToolsContext(viteConfig: ResolvedConfig, viteServer?: ViteDevServer): Promise<DevToolsNodeContext>;
9
10
  //#endregion
11
+ //#region src/node/rpc/index.d.ts
12
+ 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<{
13
+ [k: string]: {
14
+ type: any;
15
+ };
16
+ }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:list", "static", [], Promise<DevToolsTerminalSessionBase[]>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:read", "query", [id: string], Promise<{
17
+ buffer: string[];
18
+ ts: number;
19
+ }>, DevToolsNodeContext>];
20
+ type BuiltinServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcDecalrations>;
21
+ declare module '@vitejs/devtools-kit' {
22
+ interface DevToolsRpcServerFunctions extends BuiltinServerFunctions {}
23
+ interface DevToolsRpcClientFunctions {
24
+ 'vite:internal:docks:updated': () => Promise<void>;
25
+ 'vite:internal:terminals:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => Promise<void>;
26
+ 'vite:internal:terminals:updated': () => Promise<void>;
27
+ }
28
+ }
29
+ //#endregion
10
30
  //#region src/node/plugins/index.d.ts
11
31
  interface DevToolsOptions {
12
32
  /**
@@ -16,7 +36,7 @@ interface DevToolsOptions {
16
36
  */
17
37
  builtinDevTools?: boolean;
18
38
  }
19
- declare function DevTools(options?: DevToolsOptions): Plugin[];
39
+ declare function DevTools(options?: DevToolsOptions): Promise<Plugin[]>;
20
40
  //#endregion
21
41
  //#region src/node/ws.d.ts
22
42
  interface CreateWsServerOptions {
@@ -29,8 +49,9 @@ interface CreateWsServerOptions {
29
49
  //#region src/node/server.d.ts
30
50
  declare function createDevToolsMiddleware(options: CreateWsServerOptions): Promise<{
31
51
  h3: h30.App;
52
+ rpc: birpc0.BirpcGroup<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
32
53
  middleware: h30.NodeListener;
33
- rpc: birpc0.BirpcGroup<any, any>;
54
+ getConnectionMeta: () => Promise<ConnectionMeta>;
34
55
  }>;
35
56
  //#endregion
36
57
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };
package/dist/index.js CHANGED
@@ -1,57 +1,3 @@
1
- import { createDevToolsContext, createDevToolsMiddleware } from "./server-B_q0HJ88.js";
2
- import { dirDist } from "./dirs-B7dOX6eI.js";
3
- import { DevToolsViteUI } from "@vitejs/devtools-vite";
4
- import { join } from "node:path";
5
- import process from "node:process";
6
- import { normalizePath } from "vite";
1
+ import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-DfJlAQ2j.js";
7
2
 
8
- //#region src/node/plugins/injection.ts
9
- function DevToolsInjection() {
10
- return {
11
- name: "vite:devtools:injection",
12
- enforce: "post",
13
- transformIndexHtml() {
14
- return [{
15
- tag: "script",
16
- attrs: {
17
- src: `/@fs/${process.env.VITE_DEVTOOLS_LOCAL_DEV ? normalizePath(join(dirDist, "..", "src/client/inject/index.ts")) : normalizePath(join(dirDist, "client/inject.js"))}`,
18
- type: "module"
19
- },
20
- injectTo: "body"
21
- }];
22
- }
23
- };
24
- }
25
-
26
- //#endregion
27
- //#region src/node/plugins/server.ts
28
- /**
29
- * Core plugin for enabling Vite DevTools
30
- */
31
- function DevToolsServer() {
32
- return {
33
- name: "vite:devtools:server",
34
- enforce: "post",
35
- apply: "serve",
36
- async configureServer(viteDevServer) {
37
- const context = await createDevToolsContext(viteDevServer.config, viteDevServer);
38
- const { middleware } = await createDevToolsMiddleware({
39
- cwd: viteDevServer.config.root,
40
- context
41
- });
42
- viteDevServer.middlewares.use("/__vite_devtools__/", middleware);
43
- }
44
- };
45
- }
46
-
47
- //#endregion
48
- //#region src/node/plugins/index.ts
49
- function DevTools(options = {}) {
50
- const { builtinDevTools = true } = options;
51
- const plugins = [DevToolsInjection(), DevToolsServer()];
52
- if (builtinDevTools) plugins.push(DevToolsViteUI());
53
- return plugins;
54
- }
55
-
56
- //#endregion
57
3
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };