@vitejs/devtools-kit 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,2 @@
1
+ import { a as DockEntryState, c as DocksContext, d as RpcClientEvents, f as DevToolsRpcClient, i as DockClientType, l as DocksEntriesContext, m as getDevToolsRpcClient, n as DevToolsClientContext, o as DockEntryStateEvents, p as DevToolsRpcClientOptions, r as DevToolsClientRpcHost, s as DockPanelStorage, t as DockClientScriptContext, u as DocksPanelContext } from "./index-DLPbKO1M.mjs";
2
+ export { DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, RpcClientEvents, getDevToolsRpcClient };
@@ -0,0 +1,68 @@
1
+ import { t as createEventEmitter } from "./events-AmnAXhnR.mjs";
2
+ import { RpcFunctionsCollectorBase } from "birpc-x";
3
+ import { createRpcClient } from "@vitejs/devtools-rpc";
4
+ import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/client";
5
+
6
+ //#region src/client/rpc.ts
7
+ const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
8
+ function isNumeric(str) {
9
+ if (str == null) return false;
10
+ return `${+str}` === `${str}`;
11
+ }
12
+ function findConnectionMetaFromWindows() {
13
+ const getters = [
14
+ () => window?.[CONNECTION_META_KEY],
15
+ () => globalThis?.[CONNECTION_META_KEY],
16
+ () => parent.window?.[CONNECTION_META_KEY]
17
+ ];
18
+ for (const getter of getters) try {
19
+ const value = getter();
20
+ if (value) return value;
21
+ } catch {}
22
+ }
23
+ async function getDevToolsRpcClient(options = {}) {
24
+ const { baseURL = "/.devtools/", rpcOptions = {} } = options;
25
+ const events = createEventEmitter();
26
+ const bases = Array.isArray(baseURL) ? baseURL : [baseURL];
27
+ let connectionMeta = options.connectionMeta || findConnectionMetaFromWindows();
28
+ if (!connectionMeta) {
29
+ const errors = [];
30
+ for (const base of bases) try {
31
+ connectionMeta = await fetch(`${base}.vdt-connection.json`).then((r) => r.json());
32
+ globalThis[CONNECTION_META_KEY] = connectionMeta;
33
+ break;
34
+ } catch (e) {
35
+ errors.push(e);
36
+ }
37
+ if (!connectionMeta) throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
38
+ }
39
+ const url = isNumeric(connectionMeta.websocket) ? `${location.protocol.replace("http", "ws")}//${location.hostname}:${connectionMeta.websocket}` : connectionMeta.websocket;
40
+ const context = { rpc: void 0 };
41
+ const clientRpc = new RpcFunctionsCollectorBase(context);
42
+ const serverRpc = createRpcClient(clientRpc.functions, {
43
+ preset: createWsRpcPreset({
44
+ url,
45
+ ...options.wsOptions
46
+ }),
47
+ rpcOptions
48
+ });
49
+ const rpc = {
50
+ events,
51
+ connectionMeta,
52
+ call: (...args) => {
53
+ return serverRpc.$call(...args);
54
+ },
55
+ callEvent: (...args) => {
56
+ return serverRpc.$callEvent(...args);
57
+ },
58
+ callOptional: (...args) => {
59
+ return serverRpc.$callOptional(...args);
60
+ },
61
+ client: clientRpc
62
+ };
63
+ context.rpc = rpc;
64
+ return rpc;
65
+ }
66
+
67
+ //#endregion
68
+ export { getDevToolsRpcClient };
@@ -0,0 +1,41 @@
1
+ //#region src/utils/events.ts
2
+ /**
3
+ * Create event emitter.
4
+ */
5
+ function createEventEmitter() {
6
+ const _listeners = {};
7
+ function emit(event, ...args) {
8
+ const callbacks = _listeners[event] || [];
9
+ for (let i = 0, length = callbacks.length; i < length; i++) {
10
+ const callback = callbacks[i];
11
+ if (callback) callback(...args);
12
+ }
13
+ }
14
+ function emitOnce(event, ...args) {
15
+ emit(event, ...args);
16
+ delete _listeners[event];
17
+ }
18
+ function on(event, cb) {
19
+ (_listeners[event] ||= []).push(cb);
20
+ return () => {
21
+ _listeners[event] = _listeners[event]?.filter((i) => cb !== i);
22
+ };
23
+ }
24
+ function once(event, cb) {
25
+ const unsubscribe = on(event, ((...args) => {
26
+ unsubscribe();
27
+ return cb(...args);
28
+ }));
29
+ return unsubscribe;
30
+ }
31
+ return {
32
+ _listeners,
33
+ emit,
34
+ emitOnce,
35
+ on,
36
+ once
37
+ };
38
+ }
39
+
40
+ //#endregion
41
+ export { createEventEmitter as t };
@@ -0,0 +1,71 @@
1
+ //#region src/types/events.d.ts
2
+ interface EventsMap {
3
+ [event: string]: any;
4
+ }
5
+ interface EventUnsubscribe {
6
+ (): void;
7
+ }
8
+ interface EventEmitter<Events extends EventsMap> {
9
+ /**
10
+ * Calls each of the listeners registered for a given event.
11
+ *
12
+ * ```js
13
+ * ee.emit('tick', tickType, tickDuration)
14
+ * ```
15
+ *
16
+ * @param event The event name.
17
+ * @param args The arguments for listeners.
18
+ */
19
+ emit: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
20
+ /**
21
+ * Calls the listeners for a given event once and then removes the listener.
22
+ *
23
+ * @param event The event name.
24
+ * @param args The arguments for listeners.
25
+ */
26
+ emitOnce: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
27
+ /**
28
+ * Event names in keys and arrays with listeners in values.
29
+ *
30
+ * @internal
31
+ */
32
+ _listeners: Partial<{ [E in keyof Events]: Events[E][] }>;
33
+ /**
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.
49
+ */
50
+ on: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
51
+ /**
52
+ * Add a listener for a given event once.
53
+ *
54
+ * ```js
55
+ * const unbind = ee.once('tick', (tickType, tickDuration) => {
56
+ * count += 1
57
+ * })
58
+ *
59
+ * disable () {
60
+ * unbind()
61
+ * }
62
+ * ```
63
+ *
64
+ * @param event The event name.
65
+ * @param cb The listener function.
66
+ * @returns Unbind listener from event.
67
+ */
68
+ once: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
69
+ }
70
+ //#endregion
71
+ export { EventUnsubscribe as n, EventsMap as r, EventEmitter as t };
@@ -0,0 +1,360 @@
1
+ import { t as EventEmitter } from "./events-S6nCJ_5X.mjs";
2
+ import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
3
+ import { Raw } from "vue";
4
+ import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
5
+ import { ChildProcess } from "node:child_process";
6
+ import { BirpcOptions, BirpcReturn } from "birpc";
7
+
8
+ //#region src/types/docks.d.ts
9
+ interface DevToolsDockHost {
10
+ readonly views: Map<string, DevToolsDockUserEntry>;
11
+ readonly events: EventEmitter<{
12
+ 'dock:entry:updated': (entry: DevToolsDockUserEntry) => void;
13
+ }>;
14
+ register: <T extends DevToolsDockUserEntry>(entry: T, force?: boolean) => {
15
+ update: (patch: Partial<T>) => void;
16
+ };
17
+ update: (entry: DevToolsDockUserEntry) => void;
18
+ values: () => DevToolsDockUserEntry[];
19
+ }
20
+ type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
21
+ type DevToolsDockEntryIcon = string | {
22
+ light: string;
23
+ dark: string;
24
+ };
25
+ interface DevToolsDockEntryBase {
26
+ id: string;
27
+ title: string;
28
+ icon: DevToolsDockEntryIcon;
29
+ /**
30
+ * The default order of the entry in the dock.
31
+ * The higher the number the earlier it appears.
32
+ * @default 0
33
+ */
34
+ defaultOrder?: number;
35
+ /**
36
+ * The category of the entry
37
+ * @default 'default'
38
+ */
39
+ category?: DevToolsDockEntryCategory;
40
+ /**
41
+ * Whether the entry should be hidden from the user.
42
+ * @default false
43
+ */
44
+ isHidden?: boolean;
45
+ }
46
+ interface ClientScriptEntry {
47
+ /**
48
+ * The filepath or module name to import from
49
+ */
50
+ importFrom: string;
51
+ /**
52
+ * The name to import the module as
53
+ *
54
+ * @default 'default'
55
+ */
56
+ importName?: string;
57
+ }
58
+ interface DevToolsViewIframe extends DevToolsDockEntryBase {
59
+ type: 'iframe';
60
+ url: string;
61
+ /**
62
+ * The id of the iframe, if multiple tabs is assigned with the same id, the iframe will be shared.
63
+ *
64
+ * When not provided, it would be treated as a unique frame.
65
+ */
66
+ frameId?: string;
67
+ /**
68
+ * Optional client script to import into the iframe
69
+ */
70
+ clientScript?: ClientScriptEntry;
71
+ }
72
+ type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
73
+ interface DevToolsViewLauncher extends DevToolsDockEntryBase {
74
+ type: 'launcher';
75
+ launcher: {
76
+ icon?: DevToolsDockEntryIcon;
77
+ title: string;
78
+ status?: DevToolsViewLauncherStatus;
79
+ error?: string;
80
+ description?: string;
81
+ buttonStart?: string;
82
+ buttonLoading?: string;
83
+ onLaunch: () => Promise<void>;
84
+ };
85
+ }
86
+ interface DevToolsViewAction extends DevToolsDockEntryBase {
87
+ type: 'action';
88
+ action: ClientScriptEntry;
89
+ }
90
+ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
91
+ type: 'custom-render';
92
+ renderer: ClientScriptEntry;
93
+ }
94
+ interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
95
+ type: '~builtin';
96
+ id: '~terminals' | '~logs';
97
+ }
98
+ type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
99
+ type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
100
+ //#endregion
101
+ //#region src/types/rpc-augments.d.ts
102
+ /**
103
+ * To be extended
104
+ */
105
+ interface DevToolsRpcClientFunctions {}
106
+ /**
107
+ * To be extended
108
+ */
109
+ interface DevToolsRpcServerFunctions {}
110
+ //#endregion
111
+ //#region src/types/terminals.d.ts
112
+ interface DevToolsTerminalSessionStreamChunkEvent {
113
+ id: string;
114
+ chunks: string[];
115
+ ts: number;
116
+ }
117
+ interface DevToolsTerminalHost {
118
+ readonly sessions: Map<string, DevToolsTerminalSession>;
119
+ readonly events: EventEmitter<{
120
+ 'terminal:session:updated': (session: DevToolsTerminalSession) => void;
121
+ 'terminal:session:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => void;
122
+ }>;
123
+ register: (session: DevToolsTerminalSession) => DevToolsTerminalSession;
124
+ update: (session: DevToolsTerminalSession) => void;
125
+ startChildProcess: (executeOptions: DevToolsChildProcessExecuteOptions, terminal: Omit<DevToolsTerminalSessionBase, 'status'>) => Promise<DevToolsChildProcessTerminalSession>;
126
+ }
127
+ type DevToolsTerminalStatus = 'running' | 'stopped' | 'error';
128
+ interface DevToolsTerminalSessionBase {
129
+ id: string;
130
+ title: string;
131
+ description?: string;
132
+ status: DevToolsTerminalStatus;
133
+ icon?: DevToolsDockEntryIcon;
134
+ }
135
+ interface DevToolsTerminalSession extends DevToolsTerminalSessionBase {
136
+ buffer?: string[];
137
+ stream?: ReadableStream<string>;
138
+ }
139
+ interface DevToolsChildProcessExecuteOptions {
140
+ command: string;
141
+ args: string[];
142
+ cwd?: string;
143
+ env?: Record<string, string>;
144
+ }
145
+ interface DevToolsChildProcessTerminalSession extends DevToolsTerminalSession {
146
+ type: 'child-process';
147
+ executeOptions: DevToolsChildProcessExecuteOptions;
148
+ getChildProcess: () => ChildProcess | undefined;
149
+ terminate: () => Promise<void>;
150
+ restart: () => Promise<void>;
151
+ }
152
+ //#endregion
153
+ //#region src/types/views.d.ts
154
+ interface DevToolsViewHost {
155
+ /**
156
+ * @internal
157
+ */
158
+ buildStaticDirs: {
159
+ baseUrl: string;
160
+ distDir: string;
161
+ }[];
162
+ /**
163
+ * Helper to host static files
164
+ * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
165
+ * - In `build` mode, it will copy the static files to the dist directory
166
+ */
167
+ hostStatic: (baseUrl: string, distDir: string) => void;
168
+ }
169
+ //#endregion
170
+ //#region src/types/vite-plugin.d.ts
171
+ interface DevToolsCapabilities {
172
+ rpc?: boolean;
173
+ views?: boolean;
174
+ }
175
+ interface DevToolsPluginOptions {
176
+ capabilities?: {
177
+ dev?: DevToolsCapabilities | boolean;
178
+ build?: DevToolsCapabilities | boolean;
179
+ };
180
+ setup: (context: DevToolsNodeContext) => void | Promise<void>;
181
+ }
182
+ interface DevToolsNodeContext {
183
+ readonly cwd: string;
184
+ readonly mode: 'dev' | 'build';
185
+ readonly viteConfig: ResolvedConfig;
186
+ readonly viteServer?: ViteDevServer;
187
+ rpc: RpcFunctionsHost;
188
+ docks: DevToolsDockHost;
189
+ views: DevToolsViewHost;
190
+ utils: DevToolsNodeUtils;
191
+ terminals: DevToolsTerminalHost;
192
+ }
193
+ interface DevToolsNodeUtils {
194
+ /**
195
+ * Create a simple client script from a function or stringified code
196
+ *
197
+ * @deprecated DO NOT USE. This is mostly for testing only. Please use a proper importable module instead.
198
+ * @experimental
199
+ */
200
+ createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
201
+ }
202
+ interface ConnectionMeta {
203
+ backend: 'websocket' | 'static';
204
+ websocket?: number | string;
205
+ }
206
+ //#endregion
207
+ //#region src/types/rpc.d.ts
208
+ 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)[]>;
210
+ };
211
+ //#endregion
212
+ //#region src/types/utils.d.ts
213
+ type Thenable<T> = T | Promise<T>;
214
+ type EntriesToObject<T extends readonly [string, any][]> = { [K in T[number] as K[0]]: K[1] };
215
+ type PartialWithoutId<T extends {
216
+ id: string;
217
+ }> = Partial<Omit<T, 'id'>> & {
218
+ id: string;
219
+ };
220
+ //#endregion
221
+ //#region src/types/vite-augment.d.ts
222
+ declare module 'vite' {
223
+ interface Plugin {
224
+ devtools?: DevToolsPluginOptions;
225
+ }
226
+ }
227
+ interface PluginWithDevTools extends Plugin {
228
+ devtools?: DevToolsPluginOptions;
229
+ }
230
+ //#endregion
231
+ //#region ../rpc/src/presets/ws/client.d.ts
232
+ interface WebSocketRpcClientOptions {
233
+ url: string;
234
+ onConnected?: (e: Event) => void;
235
+ onError?: (e: Error) => void;
236
+ onDisconnected?: (e: CloseEvent) => void;
237
+ }
238
+ //#endregion
239
+ //#region src/client/rpc.d.ts
240
+ interface DevToolsRpcClientOptions {
241
+ connectionMeta?: ConnectionMeta;
242
+ baseURL?: string[];
243
+ wsOptions?: Partial<WebSocketRpcClientOptions>;
244
+ rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions, boolean>>;
245
+ }
246
+ interface DevToolsRpcClient {
247
+ /**
248
+ * The events of the client
249
+ */
250
+ events: EventEmitter<RpcClientEvents>;
251
+ /**
252
+ * The connection meta
253
+ */
254
+ readonly connectionMeta: ConnectionMeta;
255
+ /**
256
+ * Call a RPC function on the server
257
+ */
258
+ call: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$call'];
259
+ /**
260
+ * Call a RPC event on the server, and does not expect a response
261
+ */
262
+ callEvent: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callEvent'];
263
+ /**
264
+ * Call a RPC optional function on the server
265
+ */
266
+ callOptional: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callOptional'];
267
+ /**
268
+ * The client RPC host
269
+ */
270
+ client: DevToolsClientRpcHost;
271
+ }
272
+ declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<DevToolsRpcClient>;
273
+ //#endregion
274
+ //#region src/client/docks.d.ts
275
+ interface DockPanelStorage {
276
+ width: number;
277
+ height: number;
278
+ top: number;
279
+ left: number;
280
+ position: 'left' | 'right' | 'bottom' | 'top';
281
+ open: boolean;
282
+ inactiveTimeout: number;
283
+ }
284
+ type DockClientType = 'embedded' | 'standalone';
285
+ interface DevToolsClientContext {
286
+ /**
287
+ * The RPC client to interact with the server
288
+ */
289
+ readonly rpc: DevToolsRpcClient;
290
+ }
291
+ interface DocksContext extends DevToolsClientContext {
292
+ /**
293
+ * Type of the client environment
294
+ *
295
+ * 'embedded' - running inside an embedded floating panel
296
+ * 'standalone' - running inside a standalone window (no user app)
297
+ */
298
+ readonly clientType: 'embedded' | 'standalone';
299
+ /**
300
+ * The panel context
301
+ */
302
+ readonly panel: DocksPanelContext;
303
+ /**
304
+ * The docks entries context
305
+ */
306
+ readonly docks: DocksEntriesContext;
307
+ }
308
+ type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
309
+ interface DocksPanelContext {
310
+ store: DockPanelStorage;
311
+ isDragging: boolean;
312
+ isResizing: boolean;
313
+ readonly isVertical: boolean;
314
+ }
315
+ interface DocksEntriesContext {
316
+ selectedId: string | null;
317
+ readonly selected: DevToolsDockEntry | null;
318
+ entries: DevToolsDockEntry[];
319
+ entryToStateMap: Map<string, DockEntryState>;
320
+ /**
321
+ * Get the state of a dock entry by its ID
322
+ */
323
+ getStateById: (id: string) => DockEntryState | undefined;
324
+ /**
325
+ * Switch to the selected dock entry, pass `null` to clear the selection
326
+ *
327
+ * @returns Whether the selection was changed successfully
328
+ */
329
+ switchEntry: (id?: string | null) => Promise<boolean>;
330
+ }
331
+ interface DockEntryState {
332
+ entryMeta: DevToolsDockEntry;
333
+ readonly isActive: boolean;
334
+ domElements: {
335
+ iframe?: HTMLIFrameElement | null;
336
+ panel?: HTMLDivElement | null;
337
+ };
338
+ events: Raw<EventEmitter<DockEntryStateEvents>>;
339
+ }
340
+ interface DockEntryStateEvents {
341
+ 'entry:activated': () => void;
342
+ 'entry:deactivated': () => void;
343
+ 'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
344
+ 'dom:panel:mounted': (panel: HTMLDivElement) => void;
345
+ 'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
346
+ }
347
+ interface RpcClientEvents {}
348
+ //#endregion
349
+ //#region src/client/client-script.d.ts
350
+ /**
351
+ * Context for client scripts running in dock entries
352
+ */
353
+ interface DockClientScriptContext extends DocksContext {
354
+ /**
355
+ * The state of the current dock entry
356
+ */
357
+ current: DockEntryState;
358
+ }
359
+ //#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 };
@@ -0,0 +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";
3
+ import * as birpc_x0 from "birpc-x";
4
+
5
+ //#region src/utils/define.d.ts
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
+ //#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 };
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { createDefineWrapperWithContext } from "birpc-x";
2
+
3
+ //#region src/utils/define.ts
4
+ const defineRpcFunction = createDefineWrapperWithContext();
5
+
6
+ //#endregion
7
+ export { defineRpcFunction };
@@ -0,0 +1,10 @@
1
+ import { r as EventsMap, t as EventEmitter } from "../events-S6nCJ_5X.mjs";
2
+
3
+ //#region src/utils/events.d.ts
4
+
5
+ /**
6
+ * Create event emitter.
7
+ */
8
+ declare function createEventEmitter<Events extends EventsMap>(): EventEmitter<Events>;
9
+ //#endregion
10
+ export { createEventEmitter };
@@ -0,0 +1,3 @@
1
+ import { t as createEventEmitter } from "../events-AmnAXhnR.mjs";
2
+
3
+ export { createEventEmitter };
@@ -0,0 +1,4 @@
1
+ //#region src/utils/nanoid.d.ts
2
+ declare function nanoid(size?: number): string;
3
+ //#endregion
4
+ export { nanoid };
@@ -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 };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@vitejs/devtools-kit",
3
3
  "type": "module",
4
- "version": "0.0.0-alpha.2",
4
+ "version": "0.0.0-alpha.20",
5
5
  "description": "Vite DevTools Kit",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/vitejs/devtools#readme",
9
9
  "repository": {
10
- "directory": "packages/devtools-kit",
10
+ "directory": "packages/kit",
11
11
  "type": "git",
12
12
  "url": "git+https://github.com/vitejs/devtools.git"
13
13
  },
@@ -19,26 +19,30 @@
19
19
  ],
20
20
  "sideEffects": false,
21
21
  "exports": {
22
- ".": "./dist/index.js",
23
- "./client": "./dist/client.js",
22
+ ".": "./dist/index.mjs",
23
+ "./client": "./dist/client.mjs",
24
+ "./utils/events": "./dist/utils/events.mjs",
25
+ "./utils/nanoid": "./dist/utils/nanoid.mjs",
24
26
  "./package.json": "./package.json"
25
27
  },
26
- "main": "./dist/index.js",
27
- "module": "./dist/index.js",
28
- "types": "./dist/index.d.ts",
28
+ "main": "./dist/index.mjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.mts",
29
31
  "files": [
30
32
  "dist"
31
33
  ],
32
34
  "peerDependencies": {
33
- "vite": "npm:rolldown-vite@^7.1.14"
35
+ "vite": "*"
34
36
  },
35
37
  "dependencies": {
36
- "birpc": "^2.6.1",
37
- "@vitejs/devtools-rpc": "0.0.0-alpha.2"
38
+ "birpc": "^4.0.0",
39
+ "birpc-x": "0.0.6",
40
+ "@vitejs/devtools-rpc": "0.0.0-alpha.20"
38
41
  },
39
42
  "devDependencies": {
40
- "tsdown": "^0.15.6",
41
- "vite": "npm:rolldown-vite@^7.1.14"
43
+ "my-ua-parser": "^2.0.4",
44
+ "tsdown": "^0.17.4",
45
+ "vite": "^8.0.0-beta.2"
42
46
  },
43
47
  "scripts": {
44
48
  "build": "tsdown",
package/dist/client.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { ConnectionMeta, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions } from "./rpc-ls6mUIa2.js";
2
- import { WebSocketRpcClientOptions } from "@vitejs/devtools-rpc/presets/ws/client";
3
- import { BirpcOptions, BirpcReturn } from "birpc";
4
-
5
- //#region src/client/index.d.ts
6
- interface DevToolsRpcClientOptions {
7
- connectionMeta?: ConnectionMeta;
8
- baseURL?: string[];
9
- wsOptions?: Partial<WebSocketRpcClientOptions>;
10
- rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions>>;
11
- }
12
- declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<{
13
- connectionMeta: ConnectionMeta;
14
- rpc: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>;
15
- }>;
16
- //#endregion
17
- export { DevToolsRpcClientOptions, getDevToolsRpcClient };
package/dist/client.js DELETED
@@ -1,38 +0,0 @@
1
- import { createRpcClient } from "@vitejs/devtools-rpc";
2
- import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/client";
3
-
4
- //#region src/client/index.ts
5
- function isNumeric(str) {
6
- if (str == null) return false;
7
- return `${+str}` === `${str}`;
8
- }
9
- async function getDevToolsRpcClient(options = {}) {
10
- const { baseURL = "/__vite_devtools__/api/" } = options;
11
- const urls = Array.isArray(baseURL) ? baseURL : [baseURL];
12
- let connectionMeta = options.connectionMeta;
13
- if (!connectionMeta) {
14
- const errors = [];
15
- for (const url$1 of urls) try {
16
- connectionMeta = await fetch(`${url$1}connection.json`).then((r) => r.json());
17
- break;
18
- } catch (e) {
19
- errors.push(e);
20
- }
21
- if (!connectionMeta) throw new Error(`Failed to get connection meta from ${urls.join(", ")}`, { cause: errors });
22
- }
23
- const url = isNumeric(connectionMeta.websocket) ? `${location.protocol.replace("http", "ws")}//${location.hostname}:${connectionMeta.websocket}` : connectionMeta.websocket;
24
- const rpc = createRpcClient({}, {
25
- preset: createWsRpcPreset({
26
- url,
27
- ...options.wsOptions
28
- }),
29
- ...options.rpcOptions
30
- });
31
- return {
32
- connectionMeta,
33
- rpc
34
- };
35
- }
36
-
37
- //#endregion
38
- export { getDevToolsRpcClient };
package/dist/index.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { BirpcFn, BirpcReturn, ConnectionMeta, DevToolsCapabilities, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockHost, DevToolsNodeContext, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsViewAction, DevToolsViewIframe, DevToolsViewWebComponent, EntriesToObject, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionDefinition, RpcFunctionSetupResult, RpcFunctionType, RpcFunctionsHost, Thenable } from "./rpc-ls6mUIa2.js";
2
- import { Plugin } from "vite";
3
-
4
- //#region src/types/vite-augment.d.ts
5
- declare module 'vite' {
6
- interface Plugin {
7
- devtools?: DevToolsPluginOptions;
8
- }
9
- }
10
- interface PluginWithDevTools extends Plugin {
11
- devtools?: DevToolsPluginOptions;
12
- }
13
- //#endregion
14
- //#region src/utils/rpc.d.ts
15
- declare function defineRpcFunction<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN>): RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN>;
16
- declare function getRpcHandler<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN>, context: DevToolsNodeContext): Promise<(...args: ARGS) => RETURN>;
17
- //#endregion
18
- export { BirpcFn, BirpcReturn, ConnectionMeta, DevToolsCapabilities, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockHost, DevToolsNodeContext, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsViewAction, DevToolsViewIframe, DevToolsViewWebComponent, EntriesToObject, PluginWithDevTools, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionDefinition, RpcFunctionSetupResult, RpcFunctionType, RpcFunctionsHost, Thenable, defineRpcFunction, getRpcHandler };
package/dist/index.js DELETED
@@ -1,17 +0,0 @@
1
- //#region src/utils/rpc.ts
2
- function defineRpcFunction(definition) {
3
- return definition;
4
- }
5
- async function getRpcHandler(definition, context) {
6
- if (definition.handler) return definition.handler;
7
- if (definition.__resolved?.handler) return definition.__resolved.handler;
8
- definition.__promise ??= Promise.resolve(definition.setup(context)).then((r) => {
9
- definition.__resolved = r;
10
- definition.__promise = void 0;
11
- return r;
12
- });
13
- return (definition.__resolved ??= await definition.__promise).handler;
14
- }
15
-
16
- //#endregion
17
- export { defineRpcFunction, getRpcHandler };
@@ -1,118 +0,0 @@
1
- import { BirpcFn, BirpcReturn as BirpcReturn$1 } from "birpc";
2
- import { ResolvedConfig, ViteDevServer } from "vite";
3
-
4
- //#region src/types/rpc-augments.d.ts
5
- /**
6
- * To be extended
7
- */
8
- interface DevToolsRpcClientFunctions {}
9
- /**
10
- * To be extended
11
- */
12
- interface DevToolsRpcServerFunctions {}
13
- //#endregion
14
- //#region src/types/utils.d.ts
15
- type Thenable<T> = T | Promise<T>;
16
- type EntriesToObject<T extends readonly [string, any][]> = { [K in T[number] as K[0]]: K[1] };
17
- //#endregion
18
- //#region src/types/views.d.ts
19
- interface DevToolsDockHost {
20
- register: (entry: DevToolsDockEntry) => void;
21
- values: () => DevToolsDockEntry[];
22
- }
23
- interface DevToolsDockEntryBase {
24
- id: string;
25
- title: string;
26
- icon: string;
27
- }
28
- interface DevToolsViewIframe extends DevToolsDockEntryBase {
29
- type: 'iframe';
30
- url: string;
31
- /**
32
- * The id of the iframe, if multiple tabs is assigned with the same id, the iframe will be shared.
33
- *
34
- * When not provided, it would be treated as a unique frame.
35
- */
36
- frameId?: string;
37
- }
38
- interface DevToolsViewWebComponent extends DevToolsDockEntryBase {
39
- type: 'webcomponent';
40
- from: string;
41
- import: string;
42
- }
43
- interface DevToolsViewAction extends DevToolsDockEntryBase {
44
- type: 'action';
45
- importFrom: string;
46
- /**
47
- * @default 'default'
48
- */
49
- importName?: string;
50
- }
51
- type DevToolsDockEntry = DevToolsViewIframe | DevToolsViewWebComponent | DevToolsViewAction;
52
- //#endregion
53
- //#region src/types/vite-plugin.d.ts
54
- interface DevToolsCapabilities {
55
- rpc?: boolean;
56
- views?: boolean;
57
- }
58
- interface DevToolsPluginOptions {
59
- capabilities?: {
60
- dev?: DevToolsCapabilities | boolean;
61
- build?: DevToolsCapabilities | boolean;
62
- };
63
- setup: (context: DevToolsNodeContext) => void | Promise<void>;
64
- }
65
- interface DevToolsNodeContext {
66
- readonly cwd: string;
67
- readonly mode: 'dev' | 'build';
68
- readonly viteConfig: ResolvedConfig;
69
- readonly viteServer?: ViteDevServer;
70
- rpc: RpcFunctionsHost;
71
- docks: DevToolsDockHost;
72
- /**
73
- * Helper to host static files
74
- * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
75
- * - In `build` mode, it will copy the static files to the dist directory
76
- */
77
- hostStatic: (baseUrl: string, distDir: string) => void;
78
- staticDirs: {
79
- baseUrl: string;
80
- distDir: string;
81
- }[];
82
- }
83
- interface ConnectionMeta {
84
- backend: 'websocket' | 'static';
85
- websocket?: number | string;
86
- }
87
- //#endregion
88
- //#region src/types/rpc.d.ts
89
- /**
90
- * Type of the RPC function,
91
- * - static: A function that returns a static data (can be cached and dumped)
92
- * - action: A function that performs an action (no data returned)
93
- * - query: A function that queries a resource
94
- */
95
- type RpcFunctionType = 'static' | 'action' | 'query';
96
- interface RpcFunctionsHost {
97
- context: DevToolsNodeContext;
98
- readonly functions: DevToolsRpcServerFunctions;
99
- readonly definitions: Map<string, RpcFunctionDefinition<string, any, any, any>>;
100
- register: (fn: RpcFunctionDefinition<string, any, any, any>) => void;
101
- }
102
- interface RpcFunctionSetupResult<ARGS extends any[], RETURN = void> {
103
- handler: (...args: ARGS) => RETURN;
104
- }
105
- interface RpcFunctionDefinition<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[] = [], RETURN = void> {
106
- name: NAME;
107
- type: TYPE;
108
- setup: (context: DevToolsNodeContext) => Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
109
- handler?: (...args: ARGS) => RETURN;
110
- __resolved?: RpcFunctionSetupResult<ARGS, RETURN>;
111
- __promise?: Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
112
- }
113
- type RpcDefinitionsToFunctions<T extends readonly RpcFunctionDefinition<any, any, any>[]> = EntriesToObject<{ [K in keyof T]: [T[K]['name'], Awaited<ReturnType<T[K]['setup']>>['handler']] }>;
114
- type RpcDefinitionsFilter<T extends readonly RpcFunctionDefinition<any, any, any>[], Type extends RpcFunctionType> = { [K in keyof T]: T[K] extends {
115
- type: Type;
116
- } ? T[K] : never };
117
- //#endregion
118
- export { type BirpcFn, type BirpcReturn$1 as BirpcReturn, ConnectionMeta, DevToolsCapabilities, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockHost, DevToolsNodeContext, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsViewAction, DevToolsViewIframe, DevToolsViewWebComponent, EntriesToObject, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionDefinition, RpcFunctionSetupResult, RpcFunctionType, RpcFunctionsHost, Thenable };