@vitejs/devtools 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.
@@ -1,54 +1,26 @@
1
- import { RpcFunctionsCollectorBase } from "birpc-x";
1
+ import { RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
2
2
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
3
  import { Emitter } from "nanoevents";
4
4
  import { Raw } from "vue";
5
- import { BirpcReturn } from "birpc";
5
+ import { BirpcGroup, BirpcReturn } from "birpc";
6
6
  import "@vitejs/devtools-rpc/presets/ws/client";
7
7
 
8
- //#region ../kit/src/types/rpc-augments.d.ts
9
- /**
10
- * To be extended
11
- */
12
- interface DevToolsRpcClientFunctions {}
13
- /**
14
- * To be extended
15
- */
16
- interface DevToolsRpcServerFunctions {}
17
- //#endregion
18
- //#region ../kit/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 ../kit/src/types/views.d.ts
8
+ //#region ../kit/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: string | {
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 ../kit/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 ../kit/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 ../kit/src/types/vite-plugin.d.ts
101
114
  interface DevToolsCapabilities {
@@ -128,28 +141,15 @@ interface DevToolsNodeUtils {
128
141
  */
129
142
  createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
130
143
  }
144
+ interface ConnectionMeta {
145
+ backend: 'websocket' | 'static';
146
+ websocket?: number | string;
147
+ }
131
148
  //#endregion
132
149
  //#region ../kit/src/types/rpc.d.ts
133
- /**
134
- * Type of the RPC function,
135
- * - static: A function that returns a static data (can be cached and dumped)
136
- * - action: A function that performs an action (no data returned)
137
- * - query: A function that queries a resource
138
- */
139
- type RpcFunctionType = 'static' | 'action' | 'query';
140
- type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext>;
141
- interface RpcFunctionSetupResult<ARGS extends any[], RETURN = void> {
142
- handler: (...args: ARGS) => RETURN;
143
- }
144
- interface RpcFunctionDefinition<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[] = [], RETURN = void> {
145
- name: NAME;
146
- type: TYPE;
147
- setup: (context: DevToolsNodeContext) => Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
148
- handler?: (...args: ARGS) => RETURN;
149
- __resolved?: RpcFunctionSetupResult<ARGS, RETURN>;
150
- __promise?: Thenable<RpcFunctionSetupResult<ARGS, RETURN>>;
151
- }
152
- type RpcDefinitionsToFunctions<T extends readonly RpcFunctionDefinition<any, any, any>[]> = EntriesToObject<{ [K in keyof T]: [T[K]['name'], Awaited<ReturnType<T[K]['setup']>>['handler']] }>;
150
+ type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
151
+ boardcast: BirpcGroup<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions>['broadcast'];
152
+ };
153
153
  //#endregion
154
154
  //#region ../kit/src/types/vite-augment.d.ts
155
155
  declare module 'vite' {
@@ -160,6 +160,11 @@ declare module 'vite' {
160
160
  //#endregion
161
161
  //#region ../kit/src/client/rpc.d.ts
162
162
  type DevToolsRpcClient = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>;
163
+ interface ClientRpcReturn {
164
+ connectionMeta: ConnectionMeta;
165
+ rpc: DevToolsRpcClient;
166
+ clientRpc: DevToolsClientRpcHost;
167
+ }
163
168
  //#endregion
164
169
  //#region ../kit/src/client/docks.d.ts
165
170
  interface DockPanelStorage {
@@ -171,27 +176,34 @@ interface DockPanelStorage {
171
176
  open: boolean;
172
177
  inactiveTimeout: number;
173
178
  }
174
- interface DocksContext {
179
+ interface DevToolsClientContext {
180
+ /**
181
+ * The RPC client to interact with the server
182
+ */
183
+ readonly rpc: DevToolsRpcClient;
184
+ }
185
+ interface DocksContext extends DevToolsClientContext {
175
186
  /**
176
187
  * Type of the client environment
177
188
  *
178
189
  * 'embedded' - running inside an embedded floating panel
179
- * 'standalone' - running inside a standlone window (no user app)
190
+ * 'standalone' - running inside a standalone window (no user app)
180
191
  */
181
192
  readonly clientType: 'embedded' | 'standalone';
182
- /**
183
- * The RPC client to interact with the server
184
- */
185
- readonly rpc: DevToolsRpcClient;
186
193
  /**
187
194
  * The panel context
188
195
  */
189
- panel: DocksPanelContext;
196
+ readonly panel: DocksPanelContext;
190
197
  /**
191
198
  * The docks entries context
192
199
  */
193
- docks: DocksEntriesContext;
200
+ readonly docks: DocksEntriesContext;
201
+ /**
202
+ * The client-side RPC functions to be called from the server
203
+ */
204
+ readonly clientRpc: DevToolsClientRpcHost;
194
205
  }
206
+ type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
195
207
  interface DocksPanelContext {
196
208
  store: DockPanelStorage;
197
209
  isDragging: boolean;
@@ -199,7 +211,8 @@ interface DocksPanelContext {
199
211
  readonly isVertical: boolean;
200
212
  }
201
213
  interface DocksEntriesContext {
202
- selected: DevToolsDockEntry | null;
214
+ selectedId: string | null;
215
+ readonly selected: DevToolsDockEntry | null;
203
216
  entries: DevToolsDockEntry[];
204
217
  entryToStateMap: Map<string, DockEntryState>;
205
218
  /**
@@ -241,4 +254,4 @@ interface DockClientScriptContext extends DocksContext {
241
254
  current: DockEntryState;
242
255
  }
243
256
  //#endregion
244
- export { DevToolsNodeContext as a, RpcDefinitionsToFunctions as i, DocksContext as n, DevToolsDockEntry as o, DevToolsRpcClient as r, DockPanelStorage as t };
257
+ export { ConnectionMeta as a, DevToolsRpcServerFunctions as c, RpcDefinitionsToFunctions as i, DevToolsDockEntry as l, DocksContext as n, DevToolsNodeContext as o, ClientRpcReturn as r, DevToolsRpcClientFunctions as s, DockPanelStorage as t };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as DevToolsNodeContext, i as RpcDefinitionsToFunctions, o as DevToolsDockEntry } from "./index-CG5vL1Rm.js";
1
+ import { a as ConnectionMeta, c as DevToolsRpcServerFunctions, i as RpcDefinitionsToFunctions, l as DevToolsDockEntry, o as DevToolsNodeContext, s as DevToolsRpcClientFunctions } from "./index-Dt5HYF60.js";
2
2
  import * as birpc_x0 from "birpc-x";
3
3
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
4
4
  import * as birpc0 from "birpc";
@@ -12,10 +12,13 @@ declare const builtinRpcFunctions: readonly [birpc_x0.RpcFunctionDefinition<"vit
12
12
  [k: string]: {
13
13
  type: any;
14
14
  };
15
- }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:list-dock-entries", "query", [], DevToolsDockEntry[], DevToolsNodeContext>, 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>];
15
+ }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:list-dock-entries", "query", [], DevToolsDockEntry[], DevToolsNodeContext>, 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:core:on-dock-launch", "action", [entryId: string], Promise<void>, DevToolsNodeContext>];
16
16
  type ServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcFunctions>;
17
17
  declare module '@vitejs/devtools-kit' {
18
18
  interface DevToolsRpcServerFunctions extends ServerFunctions {}
19
+ interface DevToolsRpcClientFunctions {
20
+ 'vite:core:list-dock-entries:updated': () => Promise<void>;
21
+ }
19
22
  }
20
23
  //#endregion
21
24
  //#region src/node/plugins/index.d.ts
@@ -40,8 +43,9 @@ interface CreateWsServerOptions {
40
43
  //#region src/node/server.d.ts
41
44
  declare function createDevToolsMiddleware(options: CreateWsServerOptions): Promise<{
42
45
  h3: h30.App;
46
+ rpc: birpc0.BirpcGroup<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions>;
43
47
  middleware: h30.NodeListener;
44
- rpc: birpc0.BirpcGroup<any, any>;
48
+ getConnectionMeta: () => Promise<ConnectionMeta>;
45
49
  }>;
46
50
  //#endregion
47
51
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-CMhTYtP5.js";
1
+ import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-LceePuMU.js";
2
2
  import "./dirs-DcSK9l9L.js";
3
3
 
4
4
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };
@@ -1,6 +1,7 @@
1
1
  import { n as dirDist, t as dirClientStandalone } from "./dirs-DcSK9l9L.js";
2
2
  import Debug from "debug";
3
3
  import { toDataURL } from "mlly";
4
+ import { debounce } from "perfect-debounce";
4
5
  import { RpcFunctionsCollectorBase } from "birpc-x";
5
6
  import { existsSync } from "node:fs";
6
7
  import sirv from "sirv";
@@ -52,25 +53,32 @@ const ContextUtils = { createSimpleClientScript(fn) {
52
53
  //#region src/node/host-docks.ts
53
54
  var DevToolsDockHost = class {
54
55
  views = /* @__PURE__ */ new Map();
56
+ _sendOnChange;
55
57
  constructor(context) {
56
58
  this.context = context;
59
+ this._sendOnChange = debounce(() => {
60
+ context.rpc?.boardcast?.$callOptional("vite:core:list-dock-entries:updated");
61
+ }, 10);
57
62
  }
58
63
  values() {
59
64
  return Array.from(this.views.values());
60
65
  }
61
- register(view) {
62
- if (this.views.has(view.id)) throw new Error(`Dock with id "${view.id}" is already registered`);
66
+ register(view, force) {
67
+ if (this.views.has(view.id) && !force) throw new Error(`Dock with id "${view.id}" is already registered`);
63
68
  this.views.set(view.id, view);
69
+ this._sendOnChange();
64
70
  }
65
71
  update(view) {
66
72
  if (!this.views.has(view.id)) throw new Error(`Dock with id "${view.id}" is not registered. Use register() to add new docks.`);
67
73
  this.views.set(view.id, view);
74
+ this._sendOnChange();
68
75
  }
69
76
  };
70
77
 
71
78
  //#endregion
72
79
  //#region src/node/host-functions.ts
73
80
  var RpcFunctionsHost = class extends RpcFunctionsCollectorBase {
81
+ boardcast = void 0;
74
82
  constructor(context) {
75
83
  super(context);
76
84
  }
@@ -124,6 +132,53 @@ const listRpcFunctions = defineRpcFunction({
124
132
  }
125
133
  });
126
134
 
135
+ //#endregion
136
+ //#region src/node/rpc/on-dock-launch.ts
137
+ const onDockLaunch = defineRpcFunction({
138
+ name: "vite:core:on-dock-launch",
139
+ type: "action",
140
+ setup: (context) => {
141
+ const launchMap = /* @__PURE__ */ new Map();
142
+ return { handler: async (entryId) => {
143
+ if (launchMap.has(entryId)) return launchMap.get(entryId);
144
+ const entry = context.docks.values().find((entry$1) => entry$1.id === entryId);
145
+ if (!entry) throw new Error(`Dock entry with id "${entryId}" not found`);
146
+ if (entry.type !== "launcher") throw new Error(`Dock entry with id "${entryId}" is not a launcher`);
147
+ try {
148
+ context.docks.update({
149
+ ...entry,
150
+ launcher: {
151
+ ...entry.launcher,
152
+ status: "loading"
153
+ }
154
+ });
155
+ const promise = entry.launcher.onLaunch();
156
+ launchMap.set(entryId, promise);
157
+ const result = await promise;
158
+ const newEntry = context.docks.values().find((entry$1) => entry$1.id === entryId) || entry;
159
+ if (newEntry.type === "launcher") context.docks.update({
160
+ ...newEntry,
161
+ launcher: {
162
+ ...newEntry.launcher,
163
+ status: "success"
164
+ }
165
+ });
166
+ return result;
167
+ } catch (error) {
168
+ console.error(`[VITE DEVTOOLS] Error launching dock entry "${entryId}"`, error);
169
+ context.docks.update({
170
+ ...entry,
171
+ launcher: {
172
+ ...entry.launcher,
173
+ status: "error",
174
+ error: error instanceof Error ? error.message : String(error)
175
+ }
176
+ });
177
+ }
178
+ } };
179
+ }
180
+ });
181
+
127
182
  //#endregion
128
183
  //#region src/node/rpc/open-in-editor.ts
129
184
  const openInEditor = defineRpcFunction({
@@ -154,7 +209,8 @@ const builtinRpcFunctions = [
154
209
  listRpcFunctions,
155
210
  listDockEntries,
156
211
  openInEditor,
157
- openInFinder
212
+ openInFinder,
213
+ onDockLaunch
158
214
  ];
159
215
 
160
216
  //#endregion
@@ -1249,7 +1305,8 @@ async function createWsServer(options) {
1249
1305
  throw error;
1250
1306
  } }
1251
1307
  });
1252
- const getMetadata = async () => {
1308
+ rpcHost.boardcast = rpc.broadcast;
1309
+ const getConnectionMeta = async () => {
1253
1310
  return {
1254
1311
  backend: "websocket",
1255
1312
  websocket: port
@@ -1258,28 +1315,29 @@ async function createWsServer(options) {
1258
1315
  return {
1259
1316
  port,
1260
1317
  rpc,
1261
- functions: rpcHost,
1262
- getMetadata
1318
+ rpcHost,
1319
+ getConnectionMeta
1263
1320
  };
1264
1321
  }
1265
1322
 
1266
1323
  //#endregion
1267
1324
  //#region src/node/server.ts
1268
1325
  async function createDevToolsMiddleware(options) {
1269
- const app = createApp();
1270
- const { rpc, getMetadata } = await createWsServer(options);
1271
- app.use("/.vdt-connection.json", eventHandler(async (event) => {
1326
+ const h3 = createApp();
1327
+ const { rpc, getConnectionMeta } = await createWsServer(options);
1328
+ h3.use("/.vdt-connection.json", eventHandler(async (event) => {
1272
1329
  event.node.res.setHeader("Content-Type", "application/json");
1273
- return event.node.res.end(JSON.stringify(await getMetadata()));
1330
+ return event.node.res.end(JSON.stringify(await getConnectionMeta()));
1274
1331
  }));
1275
- app.use(fromNodeMiddleware(sirv(dirClientStandalone, {
1332
+ h3.use(fromNodeMiddleware(sirv(dirClientStandalone, {
1276
1333
  dev: true,
1277
1334
  single: true
1278
1335
  })));
1279
1336
  return {
1280
- h3: app,
1281
- middleware: toNodeListener(app),
1282
- rpc
1337
+ h3,
1338
+ rpc,
1339
+ middleware: toNodeListener(h3),
1340
+ getConnectionMeta
1283
1341
  };
1284
1342
  }
1285
1343