@vitejs/devtools-kit 0.0.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, VoidZero Inc. and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
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 ADDED
@@ -0,0 +1,38 @@
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 };
@@ -0,0 +1,18 @@
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 ADDED
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,118 @@
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 };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@vitejs/devtools-kit",
3
+ "type": "module",
4
+ "version": "0.0.0-alpha.1",
5
+ "description": "Vite DevTools Kit",
6
+ "author": "VoidZero Inc.",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/vitejs/devtools#readme",
9
+ "repository": {
10
+ "directory": "packages/devtools-kit",
11
+ "type": "git",
12
+ "url": "git+https://github.com/vitejs/devtools.git"
13
+ },
14
+ "bugs": "https://github.com/vitejs/devtools/issues",
15
+ "keywords": [
16
+ "vite",
17
+ "devtools",
18
+ "kit"
19
+ ],
20
+ "sideEffects": false,
21
+ "exports": {
22
+ ".": "./dist/index.js",
23
+ "./client": "./dist/client.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "peerDependencies": {
33
+ "vite": "npm:rolldown-vite@^7.1.14"
34
+ },
35
+ "dependencies": {
36
+ "birpc": "^2.6.1",
37
+ "@vitejs/devtools-rpc": "0.0.0-alpha.1"
38
+ },
39
+ "devDependencies": {
40
+ "tsdown": "^0.15.6",
41
+ "vite": "npm:rolldown-vite@^7.1.14"
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "watch": "tsdown --watch"
46
+ }
47
+ }