@vitejs/devtools 0.0.0-alpha.17 → 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.
@@ -57,7 +57,7 @@ var DevToolsDockHost = class {
57
57
  constructor(context) {
58
58
  this.context = context;
59
59
  this._sendOnChange = debounce(() => {
60
- context.rpc.boardcast?.$callOptional("vite:core:list-dock-entries:updated");
60
+ context.rpc?.boardcast?.$callOptional("vite:core:list-dock-entries:updated");
61
61
  }, 10);
62
62
  }
63
63
  values() {
@@ -132,6 +132,53 @@ const listRpcFunctions = defineRpcFunction({
132
132
  }
133
133
  });
134
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
+
135
182
  //#endregion
136
183
  //#region src/node/rpc/open-in-editor.ts
137
184
  const openInEditor = defineRpcFunction({
@@ -162,7 +209,8 @@ const builtinRpcFunctions = [
162
209
  listRpcFunctions,
163
210
  listDockEntries,
164
211
  openInEditor,
165
- openInFinder
212
+ openInFinder,
213
+ onDockLaunch
166
214
  ];
167
215
 
168
216
  //#endregion
@@ -1275,20 +1323,21 @@ async function createWsServer(options) {
1275
1323
  //#endregion
1276
1324
  //#region src/node/server.ts
1277
1325
  async function createDevToolsMiddleware(options) {
1278
- const app = createApp();
1279
- const { rpc, getConnectionMeta: getMetadata } = await createWsServer(options);
1280
- 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) => {
1281
1329
  event.node.res.setHeader("Content-Type", "application/json");
1282
- return event.node.res.end(JSON.stringify(await getMetadata()));
1330
+ return event.node.res.end(JSON.stringify(await getConnectionMeta()));
1283
1331
  }));
1284
- app.use(fromNodeMiddleware(sirv(dirClientStandalone, {
1332
+ h3.use(fromNodeMiddleware(sirv(dirClientStandalone, {
1285
1333
  dev: true,
1286
1334
  single: true
1287
1335
  })));
1288
1336
  return {
1289
- h3: app,
1290
- middleware: toNodeListener(app),
1291
- rpc
1337
+ h3,
1338
+ rpc,
1339
+ middleware: toNodeListener(h3),
1340
+ getConnectionMeta
1292
1341
  };
1293
1342
  }
1294
1343