@vitejs/devtools-kit 0.0.0-alpha.16 → 0.0.0-alpha.18
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/client.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { DevToolsRpcClient, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, getDevToolsRpcClient };
|
|
1
|
+
import { a as DockEntryState, c as DocksContext, d as ClientRpcReturn, 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-C7lGA5jg.mjs";
|
|
2
|
+
export { ClientRpcReturn, DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, getDevToolsRpcClient };
|
package/dist/client.mjs
CHANGED
|
@@ -1,35 +1,54 @@
|
|
|
1
|
+
import { RpcFunctionsCollectorBase } from "birpc-x";
|
|
1
2
|
import { createRpcClient } from "@vitejs/devtools-rpc";
|
|
2
3
|
import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/client";
|
|
3
4
|
|
|
4
5
|
//#region src/client/rpc.ts
|
|
6
|
+
const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
|
|
5
7
|
function isNumeric(str) {
|
|
6
8
|
if (str == null) return false;
|
|
7
9
|
return `${+str}` === `${str}`;
|
|
8
10
|
}
|
|
11
|
+
function findConnectionMetaFromWindows() {
|
|
12
|
+
const getters = [
|
|
13
|
+
() => window[CONNECTION_META_KEY],
|
|
14
|
+
() => globalThis[CONNECTION_META_KEY],
|
|
15
|
+
() => parent.window[CONNECTION_META_KEY]
|
|
16
|
+
];
|
|
17
|
+
for (const getter of getters) try {
|
|
18
|
+
const value = getter();
|
|
19
|
+
if (value) return value;
|
|
20
|
+
} catch {}
|
|
21
|
+
}
|
|
9
22
|
async function getDevToolsRpcClient(options = {}) {
|
|
10
23
|
const { baseURL = "/.devtools/", rpcOptions = {} } = options;
|
|
11
|
-
const
|
|
12
|
-
let connectionMeta = options.connectionMeta;
|
|
24
|
+
const bases = Array.isArray(baseURL) ? baseURL : [baseURL];
|
|
25
|
+
let connectionMeta = options.connectionMeta || findConnectionMetaFromWindows();
|
|
13
26
|
if (!connectionMeta) {
|
|
14
27
|
const errors = [];
|
|
15
|
-
for (const
|
|
16
|
-
connectionMeta = await fetch(`${
|
|
28
|
+
for (const base of bases) try {
|
|
29
|
+
connectionMeta = await fetch(`${base}.vdt-connection.json`).then((r) => r.json());
|
|
30
|
+
globalThis[CONNECTION_META_KEY] = connectionMeta;
|
|
17
31
|
break;
|
|
18
32
|
} catch (e) {
|
|
19
33
|
errors.push(e);
|
|
20
34
|
}
|
|
21
|
-
if (!connectionMeta) throw new Error(`Failed to get connection meta from ${
|
|
35
|
+
if (!connectionMeta) throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
|
|
22
36
|
}
|
|
23
|
-
const
|
|
37
|
+
const url = isNumeric(connectionMeta.websocket) ? `${location.protocol.replace("http", "ws")}//${location.hostname}:${connectionMeta.websocket}` : connectionMeta.websocket;
|
|
38
|
+
const context = { rpc: void 0 };
|
|
39
|
+
const clientRpc = new RpcFunctionsCollectorBase(context);
|
|
40
|
+
const rpc = createRpcClient(clientRpc.functions, {
|
|
24
41
|
preset: createWsRpcPreset({
|
|
25
|
-
url
|
|
42
|
+
url,
|
|
26
43
|
...options.wsOptions
|
|
27
44
|
}),
|
|
28
45
|
rpcOptions
|
|
29
46
|
});
|
|
47
|
+
context.rpc = rpc;
|
|
30
48
|
return {
|
|
31
49
|
connectionMeta,
|
|
32
|
-
rpc
|
|
50
|
+
rpc,
|
|
51
|
+
clientRpc
|
|
33
52
|
};
|
|
34
53
|
}
|
|
35
54
|
|
|
@@ -1,54 +1,26 @@
|
|
|
1
|
-
import { RpcFunctionsCollectorBase } from "birpc-x";
|
|
1
|
+
import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
|
|
2
2
|
import { WebSocketRpcClientOptions } from "@vitejs/devtools-rpc/presets/ws/client";
|
|
3
3
|
import { Emitter } from "nanoevents";
|
|
4
4
|
import { Raw } from "vue";
|
|
5
|
+
import { BirpcGroup, BirpcOptions, BirpcReturn } from "birpc";
|
|
5
6
|
import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
|
|
6
|
-
import { BirpcFn, BirpcOptions, BirpcReturn, BirpcReturn as BirpcReturn$1 } from "birpc";
|
|
7
7
|
|
|
8
|
-
//#region src/types/
|
|
9
|
-
/**
|
|
10
|
-
* To be extended
|
|
11
|
-
*/
|
|
12
|
-
interface DevToolsRpcClientFunctions {}
|
|
13
|
-
/**
|
|
14
|
-
* To be extended
|
|
15
|
-
*/
|
|
16
|
-
interface DevToolsRpcServerFunctions {}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/types/utils.d.ts
|
|
19
|
-
type Thenable<T> = T | Promise<T>;
|
|
20
|
-
type EntriesToObject<T extends readonly [string, any][]> = { [K in T[number] as K[0]]: K[1] };
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/types/views.d.ts
|
|
8
|
+
//#region src/types/docks.d.ts
|
|
23
9
|
interface DevToolsDockHost {
|
|
24
10
|
views: Map<string, DevToolsDockEntry>;
|
|
25
11
|
register: (entry: DevToolsDockEntry) => void;
|
|
26
12
|
update: (entry: DevToolsDockEntry) => void;
|
|
27
13
|
values: () => DevToolsDockEntry[];
|
|
28
14
|
}
|
|
29
|
-
interface DevToolsViewHost {
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
buildStaticDirs: {
|
|
34
|
-
baseUrl: string;
|
|
35
|
-
distDir: string;
|
|
36
|
-
}[];
|
|
37
|
-
/**
|
|
38
|
-
* Helper to host static files
|
|
39
|
-
* - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
|
|
40
|
-
* - In `build` mode, it will copy the static files to the dist directory
|
|
41
|
-
*/
|
|
42
|
-
hostStatic: (baseUrl: string, distDir: string) => void;
|
|
43
|
-
}
|
|
44
15
|
type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
|
|
16
|
+
type DevToolsDockEntryIcon = string | {
|
|
17
|
+
light: string;
|
|
18
|
+
dark: string;
|
|
19
|
+
};
|
|
45
20
|
interface DevToolsDockEntryBase {
|
|
46
21
|
id: string;
|
|
47
22
|
title: string;
|
|
48
|
-
icon:
|
|
49
|
-
light: string;
|
|
50
|
-
dark: string;
|
|
51
|
-
};
|
|
23
|
+
icon: DevToolsDockEntryIcon;
|
|
52
24
|
/**
|
|
53
25
|
* The default order of the entry in the dock.
|
|
54
26
|
* The higher the number the earlier it appears.
|
|
@@ -87,6 +59,20 @@ interface DevToolsViewIframe extends DevToolsDockEntryBase {
|
|
|
87
59
|
*/
|
|
88
60
|
clientScript?: ClientScriptEntry;
|
|
89
61
|
}
|
|
62
|
+
type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
63
|
+
interface DevToolsViewLauncher extends DevToolsDockEntryBase {
|
|
64
|
+
type: 'launcher';
|
|
65
|
+
launcher: {
|
|
66
|
+
icon?: DevToolsDockEntryIcon;
|
|
67
|
+
title: string;
|
|
68
|
+
status?: DevToolsViewLauncherStatus;
|
|
69
|
+
error?: string;
|
|
70
|
+
description?: string;
|
|
71
|
+
buttonStart?: string;
|
|
72
|
+
buttonLoading?: string;
|
|
73
|
+
onLaunch: () => Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
90
76
|
interface DevToolsViewAction extends DevToolsDockEntryBase {
|
|
91
77
|
type: 'action';
|
|
92
78
|
action: ClientScriptEntry;
|
|
@@ -95,7 +81,34 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
|
|
|
95
81
|
type: 'custom-render';
|
|
96
82
|
renderer: ClientScriptEntry;
|
|
97
83
|
}
|
|
98
|
-
type DevToolsDockEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender;
|
|
84
|
+
type DevToolsDockEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/types/rpc-augments.d.ts
|
|
87
|
+
/**
|
|
88
|
+
* To be extended
|
|
89
|
+
*/
|
|
90
|
+
interface DevToolsRpcClientFunctions {}
|
|
91
|
+
/**
|
|
92
|
+
* To be extended
|
|
93
|
+
*/
|
|
94
|
+
interface DevToolsRpcServerFunctions {}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/types/views.d.ts
|
|
97
|
+
interface DevToolsViewHost {
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
buildStaticDirs: {
|
|
102
|
+
baseUrl: string;
|
|
103
|
+
distDir: string;
|
|
104
|
+
}[];
|
|
105
|
+
/**
|
|
106
|
+
* Helper to host static files
|
|
107
|
+
* - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
|
|
108
|
+
* - In `build` mode, it will copy the static files to the dist directory
|
|
109
|
+
*/
|
|
110
|
+
hostStatic: (baseUrl: string, distDir: string) => void;
|
|
111
|
+
}
|
|
99
112
|
//#endregion
|
|
100
113
|
//#region src/types/vite-plugin.d.ts
|
|
101
114
|
interface DevToolsCapabilities {
|
|
@@ -134,29 +147,13 @@ interface ConnectionMeta {
|
|
|
134
147
|
}
|
|
135
148
|
//#endregion
|
|
136
149
|
//#region src/types/rpc.d.ts
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
type
|
|
144
|
-
type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext>;
|
|
145
|
-
interface RpcFunctionSetupResult<ARGS extends any[], RETURN = void> {
|
|
146
|
-
handler: (...args: ARGS) => RETURN;
|
|
147
|
-
}
|
|
148
|
-
interface RpcFunctionDefinition<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[] = [], RETURN = void> {
|
|
149
|
-
name: NAME;
|
|
150
|
-
type: TYPE;
|
|
151
|
-
setup: (context: DevToolsNodeContext) => Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
|
|
152
|
-
handler?: (...args: ARGS) => RETURN;
|
|
153
|
-
__resolved?: RpcFunctionSetupResult<ARGS, RETURN>;
|
|
154
|
-
__promise?: Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
|
|
155
|
-
}
|
|
156
|
-
type RpcDefinitionsToFunctions<T extends readonly RpcFunctionDefinition<any, any, any>[]> = EntriesToObject<{ [K in keyof T]: [T[K]['name'], Awaited<ReturnType<T[K]['setup']>>['handler']] }>;
|
|
157
|
-
type RpcDefinitionsFilter<T extends readonly RpcFunctionDefinition<any, any, any>[], Type extends RpcFunctionType> = { [K in keyof T]: T[K] extends {
|
|
158
|
-
type: Type;
|
|
159
|
-
} ? T[K] : never };
|
|
150
|
+
type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
|
|
151
|
+
boardcast: BirpcGroup<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions>['broadcast'];
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/types/utils.d.ts
|
|
155
|
+
type Thenable<T> = T | Promise<T>;
|
|
156
|
+
type EntriesToObject<T extends readonly [string, any][]> = { [K in T[number] as K[0]]: K[1] };
|
|
160
157
|
//#endregion
|
|
161
158
|
//#region src/types/vite-augment.d.ts
|
|
162
159
|
declare module 'vite' {
|
|
@@ -176,10 +173,12 @@ interface DevToolsRpcClientOptions {
|
|
|
176
173
|
rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions>>;
|
|
177
174
|
}
|
|
178
175
|
type DevToolsRpcClient = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>;
|
|
179
|
-
|
|
176
|
+
interface ClientRpcReturn {
|
|
180
177
|
connectionMeta: ConnectionMeta;
|
|
181
178
|
rpc: DevToolsRpcClient;
|
|
182
|
-
|
|
179
|
+
clientRpc: DevToolsClientRpcHost;
|
|
180
|
+
}
|
|
181
|
+
declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<ClientRpcReturn>;
|
|
183
182
|
//#endregion
|
|
184
183
|
//#region src/client/docks.d.ts
|
|
185
184
|
interface DockPanelStorage {
|
|
@@ -192,27 +191,34 @@ interface DockPanelStorage {
|
|
|
192
191
|
inactiveTimeout: number;
|
|
193
192
|
}
|
|
194
193
|
type DockClientType = 'embedded' | 'standalone';
|
|
195
|
-
interface
|
|
194
|
+
interface DevToolsClientContext {
|
|
195
|
+
/**
|
|
196
|
+
* The RPC client to interact with the server
|
|
197
|
+
*/
|
|
198
|
+
readonly rpc: DevToolsRpcClient;
|
|
199
|
+
}
|
|
200
|
+
interface DocksContext extends DevToolsClientContext {
|
|
196
201
|
/**
|
|
197
202
|
* Type of the client environment
|
|
198
203
|
*
|
|
199
204
|
* 'embedded' - running inside an embedded floating panel
|
|
200
|
-
* 'standalone' - running inside a
|
|
205
|
+
* 'standalone' - running inside a standalone window (no user app)
|
|
201
206
|
*/
|
|
202
207
|
readonly clientType: 'embedded' | 'standalone';
|
|
203
|
-
/**
|
|
204
|
-
* The RPC client to interact with the server
|
|
205
|
-
*/
|
|
206
|
-
readonly rpc: DevToolsRpcClient;
|
|
207
208
|
/**
|
|
208
209
|
* The panel context
|
|
209
210
|
*/
|
|
210
|
-
panel: DocksPanelContext;
|
|
211
|
+
readonly panel: DocksPanelContext;
|
|
211
212
|
/**
|
|
212
213
|
* The docks entries context
|
|
213
214
|
*/
|
|
214
|
-
docks: DocksEntriesContext;
|
|
215
|
+
readonly docks: DocksEntriesContext;
|
|
216
|
+
/**
|
|
217
|
+
* The client-side RPC functions to be called from the server
|
|
218
|
+
*/
|
|
219
|
+
readonly clientRpc: DevToolsClientRpcHost;
|
|
215
220
|
}
|
|
221
|
+
type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
|
|
216
222
|
interface DocksPanelContext {
|
|
217
223
|
store: DockPanelStorage;
|
|
218
224
|
isDragging: boolean;
|
|
@@ -220,7 +226,8 @@ interface DocksPanelContext {
|
|
|
220
226
|
readonly isVertical: boolean;
|
|
221
227
|
}
|
|
222
228
|
interface DocksEntriesContext {
|
|
223
|
-
|
|
229
|
+
selectedId: string | null;
|
|
230
|
+
readonly selected: DevToolsDockEntry | null;
|
|
224
231
|
entries: DevToolsDockEntry[];
|
|
225
232
|
entryToStateMap: Map<string, DockEntryState>;
|
|
226
233
|
/**
|
|
@@ -262,4 +269,4 @@ interface DockClientScriptContext extends DocksContext {
|
|
|
262
269
|
current: DockEntryState;
|
|
263
270
|
}
|
|
264
271
|
//#endregion
|
|
265
|
-
export {
|
|
272
|
+
export { DevToolsDockEntry as A, DevToolsNodeContext as C, DevToolsRpcClientFunctions as D, DevToolsViewHost as E, DevToolsViewAction as F, DevToolsViewCustomRender as I, DevToolsViewIframe as L, DevToolsDockEntryCategory as M, DevToolsDockEntryIcon as N, DevToolsRpcServerFunctions as O, DevToolsDockHost as P, DevToolsViewLauncher as R, DevToolsCapabilities as S, DevToolsPluginOptions as T, PluginWithDevTools as _, DockEntryState as a, RpcFunctionsHost as b, DocksContext as c, ClientRpcReturn as d, DevToolsRpcClient as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, DockClientType as i, DevToolsDockEntryBase as j, ClientScriptEntry as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsClientRpcHost as r, DockPanelStorage as s, DockClientScriptContext as t, DocksPanelContext as u, EntriesToObject as v, DevToolsNodeUtils as w, ConnectionMeta as x, Thenable as y, DevToolsViewLauncherStatus as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as DevToolsDockEntry, C as DevToolsNodeContext, D as DevToolsRpcClientFunctions, E as DevToolsViewHost, F as DevToolsViewAction, I as DevToolsViewCustomRender, L as DevToolsViewIframe, M as DevToolsDockEntryCategory, N as DevToolsDockEntryIcon, O as DevToolsRpcServerFunctions, P as DevToolsDockHost, R as DevToolsViewLauncher, S as DevToolsCapabilities, T as DevToolsPluginOptions, _ as PluginWithDevTools, b as RpcFunctionsHost, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, j as DevToolsDockEntryBase, k as ClientScriptEntry, v as EntriesToObject, w as DevToolsNodeUtils, x as ConnectionMeta, y as Thenable, z as DevToolsViewLauncherStatus } from "./index-C7lGA5jg.mjs";
|
|
2
2
|
import * as birpc_x0 from "birpc-x";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/rpc.d.ts
|
|
5
|
-
declare const defineRpcFunction: <NAME extends string, TYPE extends birpc_x0.RpcFunctionType, ARGS extends any[], RETURN = void>(definition: birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, DevToolsNodeContext>) => birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, DevToolsNodeContext>;
|
|
5
|
+
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>;
|
|
6
6
|
//#endregion
|
|
7
|
-
export {
|
|
7
|
+
export { ClientScriptEntry, ConnectionMeta, DevToolsCapabilities, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockEntryCategory, DevToolsDockEntryIcon, DevToolsDockHost, DevToolsNodeContext, DevToolsNodeUtils, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsViewAction, DevToolsViewCustomRender, DevToolsViewHost, DevToolsViewIframe, DevToolsViewLauncher, DevToolsViewLauncherStatus, EntriesToObject, PluginWithDevTools, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsHost, Thenable, defineRpcFunction };
|
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.
|
|
4
|
+
"version": "0.0.0-alpha.18",
|
|
5
5
|
"description": "Vite DevTools Kit",
|
|
6
6
|
"author": "VoidZero Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"vite": "*"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"birpc": "^2.
|
|
37
|
-
"birpc-x": "0.0.
|
|
36
|
+
"birpc": "^2.8.0",
|
|
37
|
+
"birpc-x": "0.0.5",
|
|
38
38
|
"nanoevents": "^9.1.0",
|
|
39
|
-
"@vitejs/devtools-rpc": "0.0.0-alpha.
|
|
39
|
+
"@vitejs/devtools-rpc": "0.0.0-alpha.18"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"tsdown": "^0.16.1",
|