@vitejs/devtools-kit 0.0.0-alpha.2 → 0.0.0-alpha.21
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 +2 -0
- package/dist/client.mjs +1230 -0
- package/dist/events-BrHMyEqJ.d.mts +71 -0
- package/dist/events-CWYZG96x.mjs +41 -0
- package/dist/index-FzXSK6np.d.mts +456 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +7 -0
- package/dist/nanoid-B0pJU5uW.mjs +11 -0
- package/dist/utils/events.d.mts +10 -0
- package/dist/utils/events.mjs +3 -0
- package/dist/utils/nanoid.d.mts +4 -0
- package/dist/utils/nanoid.mjs +3 -0
- package/dist/utils/shared-state.d.mts +50 -0
- package/dist/utils/shared-state.mjs +28 -0
- package/package.json +18 -12
- package/dist/client.d.ts +0 -17
- package/dist/client.js +0 -38
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -17
- package/dist/rpc-ls6mUIa2.d.ts +0 -118
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { t as createEventEmitter } from "../events-CWYZG96x.mjs";
|
|
2
|
+
import { applyPatches, produce, produceWithPatches } from "immer";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/shared-state.ts
|
|
5
|
+
function createSharedState(options) {
|
|
6
|
+
const { enablePatches = false } = options;
|
|
7
|
+
const events = createEventEmitter();
|
|
8
|
+
let state = options.initialState;
|
|
9
|
+
return {
|
|
10
|
+
on: events.on,
|
|
11
|
+
get: () => state,
|
|
12
|
+
patch: (patches) => {
|
|
13
|
+
state = applyPatches(state, patches);
|
|
14
|
+
events.emit("updated", state);
|
|
15
|
+
},
|
|
16
|
+
mutate: (fn) => {
|
|
17
|
+
if (enablePatches) {
|
|
18
|
+
const [newState, patches] = produceWithPatches(state, fn);
|
|
19
|
+
state = newState;
|
|
20
|
+
events.emit("patches", patches);
|
|
21
|
+
} else state = produce(state, fn);
|
|
22
|
+
events.emit("updated", state);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createSharedState };
|
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.
|
|
4
|
+
"version": "0.0.0-alpha.21",
|
|
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/
|
|
10
|
+
"directory": "packages/kit",
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git+https://github.com/vitejs/devtools.git"
|
|
13
13
|
},
|
|
@@ -19,26 +19,32 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"exports": {
|
|
22
|
-
".": "./dist/index.
|
|
23
|
-
"./client": "./dist/client.
|
|
22
|
+
".": "./dist/index.mjs",
|
|
23
|
+
"./client": "./dist/client.mjs",
|
|
24
|
+
"./utils/events": "./dist/utils/events.mjs",
|
|
25
|
+
"./utils/nanoid": "./dist/utils/nanoid.mjs",
|
|
26
|
+
"./utils/shared-state": "./dist/utils/shared-state.mjs",
|
|
24
27
|
"./package.json": "./package.json"
|
|
25
28
|
},
|
|
26
|
-
"main": "./dist/index.
|
|
27
|
-
"module": "./dist/index.
|
|
28
|
-
"types": "./dist/index.d.
|
|
29
|
+
"main": "./dist/index.mjs",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
29
32
|
"files": [
|
|
30
33
|
"dist"
|
|
31
34
|
],
|
|
32
35
|
"peerDependencies": {
|
|
33
|
-
"vite": "
|
|
36
|
+
"vite": "*"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"birpc": "^
|
|
37
|
-
"
|
|
39
|
+
"birpc": "^4.0.0",
|
|
40
|
+
"birpc-x": "0.0.6",
|
|
41
|
+
"immer": "^11.1.0",
|
|
42
|
+
"@vitejs/devtools-rpc": "0.0.0-alpha.21"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
45
|
+
"my-ua-parser": "^2.0.4",
|
|
46
|
+
"tsdown": "^0.18.2",
|
|
47
|
+
"vite": "^8.0.0-beta.3"
|
|
42
48
|
},
|
|
43
49
|
"scripts": {
|
|
44
50
|
"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 };
|
package/dist/rpc-ls6mUIa2.d.ts
DELETED
|
@@ -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 };
|