@vitejs/devtools 0.0.0-alpha.9 → 0.1.0

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.
Files changed (36) hide show
  1. package/dist/DockIcon-Jbdv1CYn.js +1720 -0
  2. package/dist/DockStandalone-Dd6Dcd5B.js +81 -0
  3. package/dist/LogItem-CfTxUV6A.js +204 -0
  4. package/dist/ToastOverlay-BVErqkif.js +1048 -0
  5. package/dist/ViewBuiltinLogs-DQLxnQ1c.js +427 -0
  6. package/dist/ViewBuiltinTerminals-B83FB-cT.js +10407 -0
  7. package/dist/cli-commands-DRp01A04.js +178 -0
  8. package/dist/cli-commands.js +3 -5
  9. package/dist/cli.js +3 -6
  10. package/dist/client/inject.js +170 -18
  11. package/dist/client/standalone/assets/DockStandalone-B8W-HO8N.js +1 -0
  12. package/dist/client/standalone/assets/LogItem-B-ayIBi6.js +1 -0
  13. package/dist/client/standalone/assets/ViewBuiltinLogs-B8M7lPbt.js +1 -0
  14. package/dist/client/standalone/assets/ViewBuiltinTerminals-Dkd5qdlN.js +36 -0
  15. package/dist/client/standalone/assets/dist-ZC9UAo6H.js +1 -0
  16. package/dist/client/standalone/assets/index-6F2y1lxr.css +1 -0
  17. package/dist/client/standalone/assets/index-odNIfapG.js +4 -0
  18. package/dist/client/standalone/index.html +5 -3
  19. package/dist/client/webcomponents.d.ts +21657 -31
  20. package/dist/client/webcomponents.js +305 -455
  21. package/dist/config.d.ts +25 -0
  22. package/dist/config.js +14 -0
  23. package/dist/dirs.js +7 -3
  24. package/dist/{dist-2aLfy0Lc.js → dist-3NIYLDlS.js} +2261 -936
  25. package/dist/index.d.ts +256 -13
  26. package/dist/index.js +2 -4
  27. package/dist/plugins-6tW2SoNv.js +2115 -0
  28. package/dist/popup-EDv_a9nQ.js +358 -0
  29. package/dist/utils--qjmgani.js +6 -0
  30. package/package.json +50 -21
  31. package/dist/cli-commands-CWESTkWI.js +0 -97
  32. package/dist/client/standalone/assets/index-CXKamp9k.js +0 -7
  33. package/dist/client/standalone/assets/index-DULlvzQC.css +0 -1
  34. package/dist/dirs-DcSK9l9L.js +0 -9
  35. package/dist/index-C-9eMTqf.d.ts +0 -142
  36. package/dist/plugins-5VE4Mfdt.js +0 -1365
@@ -0,0 +1,358 @@
1
+ import { H as reactive, L as watch, V as markRaw, W as shallowRef } from "./dist-3NIYLDlS.js";
2
+ import { createEventEmitter } from "@vitejs/devtools-kit/utils/events";
3
+ //#region src/client/webcomponents/constants.ts
4
+ const BUILTIN_ENTRY_CLIENT_AUTH_NOTICE = Object.freeze({
5
+ type: "~builtin",
6
+ id: "~client-auth-notice",
7
+ title: "Unauthorized",
8
+ icon: "i-fluent-emoji-flat-warning"
9
+ });
10
+ const BUILTIN_ENTRIES = Object.freeze([BUILTIN_ENTRY_CLIENT_AUTH_NOTICE]);
11
+ const DEFAULT_CATEGORIES_ORDER = {
12
+ "~viteplus": -1e3,
13
+ "default": 0,
14
+ "app": 100,
15
+ "framework": 200,
16
+ "web": 300,
17
+ "advanced": 400,
18
+ "~builtin": 1e3
19
+ };
20
+ //#endregion
21
+ //#region src/client/webcomponents/state/dock-settings.ts
22
+ /**
23
+ * Group and sort dock entries based on user settings.
24
+ * Filters out hidden entries and categories, sorts by pinned status, custom order, and default order.
25
+ */
26
+ function docksGroupByCategories(entries, settings, options) {
27
+ const { docksHidden, docksCategoriesHidden, docksCustomOrder, docksPinned } = settings;
28
+ const { includeHidden = false } = options ?? {};
29
+ const map = /* @__PURE__ */ new Map();
30
+ for (const entry of entries) {
31
+ if (entry.isHidden && !includeHidden) continue;
32
+ if (!includeHidden && docksHidden.includes(entry.id)) continue;
33
+ const category = entry.category ?? "default";
34
+ if (!includeHidden && docksCategoriesHidden.includes(category)) continue;
35
+ if (!map.has(category)) map.set(category, []);
36
+ map.get(category).push(entry);
37
+ }
38
+ const grouped = Array.from(map.entries()).sort(([a], [b]) => {
39
+ const ia = DEFAULT_CATEGORIES_ORDER[a] || 0;
40
+ const ib = DEFAULT_CATEGORIES_ORDER[b] || 0;
41
+ return ib === ia ? b.localeCompare(a) : ia - ib;
42
+ });
43
+ grouped.forEach(([_, items]) => {
44
+ items.sort((a, b) => {
45
+ const aPinned = docksPinned.includes(a.id);
46
+ if (aPinned !== docksPinned.includes(b.id)) return aPinned ? -1 : 1;
47
+ const customOrderA = docksCustomOrder[a.id] ?? 0;
48
+ const customOrderB = docksCustomOrder[b.id] ?? 0;
49
+ if (customOrderA !== customOrderB) return customOrderA - customOrderB;
50
+ const ia = a.defaultOrder ?? 0;
51
+ const ib = b.defaultOrder ?? 0;
52
+ return ib === ia ? b.title.localeCompare(a.title) : ia - ib;
53
+ });
54
+ });
55
+ return grouped;
56
+ }
57
+ /**
58
+ * Split grouped entries into visible and overflow based on capacity.
59
+ */
60
+ function docksSplitGroupsWithCapacity(groups, capacity) {
61
+ const visible = [];
62
+ const overflow = [];
63
+ let left = capacity;
64
+ for (const [category, items] of groups) if (left <= 0) overflow.push([category, items]);
65
+ else if (items.length > left) {
66
+ visible.push([category, items.slice(0, left)]);
67
+ overflow.push([category, items.slice(left)]);
68
+ left = 0;
69
+ } else {
70
+ left -= items.length;
71
+ visible.push([category, items]);
72
+ }
73
+ return {
74
+ visible,
75
+ overflow
76
+ };
77
+ }
78
+ //#endregion
79
+ //#region src/client/webcomponents/state/docks.ts
80
+ function DEFAULT_DOCK_PANEL_STORE() {
81
+ return {
82
+ width: 80,
83
+ height: 80,
84
+ top: 0,
85
+ left: 10,
86
+ position: "bottom",
87
+ open: false,
88
+ inactiveTimeout: 3e3
89
+ };
90
+ }
91
+ function createDockEntryState(entry, selected) {
92
+ const events = createEventEmitter();
93
+ const state = reactive({
94
+ entryMeta: entry,
95
+ get isActive() {
96
+ return selected.value?.id === entry.id;
97
+ },
98
+ domElements: {},
99
+ events: markRaw(events)
100
+ });
101
+ watch(() => selected.value?.id, (newSelectedId) => {
102
+ if (newSelectedId === entry.id) events.emit("entry:activated");
103
+ else events.emit("entry:deactivated");
104
+ }, { immediate: true });
105
+ watch(() => state.domElements.iframe, (newIframe) => {
106
+ if (newIframe) events.emit("dom:iframe:mounted", newIframe);
107
+ }, { immediate: true });
108
+ watch(() => state.domElements.panel, (newPanel) => {
109
+ if (newPanel) events.emit("dom:panel:mounted", newPanel);
110
+ }, { immediate: true });
111
+ return state;
112
+ }
113
+ function sharedStateToRef(sharedState) {
114
+ const ref = shallowRef(sharedState.value());
115
+ sharedState.on("updated", (newState) => {
116
+ ref.value = newState;
117
+ });
118
+ return ref;
119
+ }
120
+ const docksEntriesRefByRpc = /* @__PURE__ */ new WeakMap();
121
+ async function useDocksEntries(rpc) {
122
+ if (docksEntriesRefByRpc.has(rpc)) return docksEntriesRefByRpc.get(rpc);
123
+ const docksEntriesRef = sharedStateToRef(await rpc.sharedState.get("devtoolskit:internal:docks", { initialValue: [] }));
124
+ docksEntriesRefByRpc.set(rpc, docksEntriesRef);
125
+ return docksEntriesRef;
126
+ }
127
+ //#endregion
128
+ //#region src/client/webcomponents/state/floating-tooltip.ts
129
+ const tooltip = shallowRef(null);
130
+ const docksOverflowPanel = shallowRef(null);
131
+ const dockContextMenu = shallowRef(null);
132
+ function setFloatingTooltip(info) {
133
+ tooltip.value = info;
134
+ }
135
+ function useFloatingTooltip() {
136
+ return tooltip;
137
+ }
138
+ function setDocksOverflowPanel(info) {
139
+ docksOverflowPanel.value = info;
140
+ }
141
+ function useDocksOverflowPanel() {
142
+ return docksOverflowPanel;
143
+ }
144
+ function setDockContextMenu(info) {
145
+ dockContextMenu.value = info;
146
+ }
147
+ function useDockContextMenu() {
148
+ return dockContextMenu;
149
+ }
150
+ //#endregion
151
+ //#region src/client/webcomponents/state/popup.ts
152
+ const PANEL_MIN_SIZE = 20;
153
+ const PANEL_MAX_SIZE = 100;
154
+ const POPUP_MIN_WIDTH = 320;
155
+ const POPUP_MIN_HEIGHT = 240;
156
+ const POPUP_DOCK_ID = "~popup";
157
+ const MAIN_FRAME_ACTION_HANDLER_KEY = "__VITE_DEVTOOLS_TRIGGER_DOCK_ACTION__";
158
+ const popupWindow = shallowRef(null);
159
+ const isPopupOpen = shallowRef(false);
160
+ const popupEvents = createEventEmitter();
161
+ let detachPopupListeners;
162
+ let detachColorModeSync;
163
+ let popupDockElement;
164
+ let loadDockStandalone = async () => {
165
+ return await import("./DockStandalone-Dd6Dcd5B.js").then((m) => m.DockStandalone);
166
+ };
167
+ popupEvents.on("popup:open-requested", (context) => {
168
+ openDockPopup(context);
169
+ });
170
+ function getDocumentPictureInPicture() {
171
+ if (typeof window === "undefined") return;
172
+ return window.documentPictureInPicture;
173
+ }
174
+ function clearListeners() {
175
+ detachPopupListeners?.();
176
+ detachPopupListeners = void 0;
177
+ detachColorModeSync?.();
178
+ detachColorModeSync = void 0;
179
+ }
180
+ function resolveColorMode() {
181
+ const sourceWindow = window;
182
+ const elements = [sourceWindow.document?.documentElement, sourceWindow.document?.body].filter(Boolean);
183
+ for (const element of elements) {
184
+ if (element?.classList?.contains("dark")) return "dark";
185
+ if (element?.classList?.contains("light")) return "light";
186
+ const dataTheme = element?.getAttribute?.("data-theme");
187
+ if (dataTheme === "dark" || dataTheme === "light") return dataTheme;
188
+ }
189
+ if (sourceWindow.matchMedia?.("(prefers-color-scheme: dark)").matches) return "dark";
190
+ return "light";
191
+ }
192
+ function applyPopupColorMode(popup, mode) {
193
+ popup.document.documentElement?.style.setProperty("color-scheme", mode);
194
+ }
195
+ function setupPopupColorModeSync(popup) {
196
+ const cleanups = [];
197
+ const update = () => applyPopupColorMode(popup, resolveColorMode());
198
+ update();
199
+ const sourceWindow = window;
200
+ const sourceDocument = sourceWindow.document;
201
+ if (typeof MutationObserver !== "undefined" && sourceDocument) {
202
+ const observer = new MutationObserver(update);
203
+ for (const element of [sourceDocument.documentElement, sourceDocument.body]) {
204
+ if (!element) continue;
205
+ observer.observe(element, {
206
+ attributes: true,
207
+ attributeFilter: [
208
+ "class",
209
+ "data-theme",
210
+ "style"
211
+ ]
212
+ });
213
+ }
214
+ cleanups.push(() => observer.disconnect());
215
+ }
216
+ if (sourceWindow.matchMedia) {
217
+ const darkQuery = sourceWindow.matchMedia("(prefers-color-scheme: dark)");
218
+ const lightQuery = sourceWindow.matchMedia("(prefers-color-scheme: light)");
219
+ darkQuery.addEventListener("change", update);
220
+ lightQuery.addEventListener("change", update);
221
+ cleanups.push(() => {
222
+ darkQuery.removeEventListener("change", update);
223
+ lightQuery.removeEventListener("change", update);
224
+ });
225
+ }
226
+ return () => {
227
+ cleanups.forEach((fn) => fn());
228
+ };
229
+ }
230
+ function unmountPopupElement() {
231
+ popupDockElement?.remove();
232
+ popupDockElement = void 0;
233
+ }
234
+ function clearPopupState() {
235
+ clearListeners();
236
+ unmountPopupElement();
237
+ popupWindow.value = null;
238
+ isPopupOpen.value = false;
239
+ }
240
+ function clamp(value, min, max) {
241
+ return Math.min(Math.max(value, min), max);
242
+ }
243
+ function syncPanelSizeFromPopup(context, popup) {
244
+ if (window.innerWidth <= 0 || window.innerHeight <= 0) return;
245
+ context.panel.store.width = clamp(Math.round(popup.innerWidth / window.innerWidth * 100), PANEL_MIN_SIZE, PANEL_MAX_SIZE);
246
+ context.panel.store.height = clamp(Math.round(popup.innerHeight / window.innerHeight * 100), PANEL_MIN_SIZE, PANEL_MAX_SIZE);
247
+ }
248
+ async function mountStandaloneApp(context, popup) {
249
+ const DockStandaloneElement = await loadDockStandalone();
250
+ const baseStyle = popup.document.createElement("style");
251
+ baseStyle.textContent = [
252
+ "html, body {",
253
+ " margin: 0;",
254
+ " padding: 0;",
255
+ " width: 100%;",
256
+ " height: 100%;",
257
+ " overflow: hidden;",
258
+ " background: transparent;",
259
+ "}",
260
+ "#vite-devtools-popup-root {",
261
+ " width: 100vw;",
262
+ " height: 100vh;",
263
+ "}",
264
+ "#vite-devtools-popup-root > vite-devtools-dock-standalone {",
265
+ " display: block;",
266
+ " width: 100%;",
267
+ " height: 100%;",
268
+ "}"
269
+ ].join("\n");
270
+ popup.document.title = "Vite DevTools";
271
+ popup.document.head?.appendChild(baseStyle);
272
+ popup.document.body.textContent = "";
273
+ const appRoot = popup.document.createElement("div");
274
+ appRoot.id = "vite-devtools-popup-root";
275
+ popup.document.body.appendChild(appRoot);
276
+ const dockElement = new DockStandaloneElement({ context });
277
+ popupDockElement = dockElement;
278
+ appRoot.appendChild(dockElement);
279
+ }
280
+ function isDockPopupSupported() {
281
+ return !!getDocumentPictureInPicture()?.requestWindow;
282
+ }
283
+ function registerMainFrameDockActionHandler(clientType, handler) {
284
+ if (typeof window === "undefined") return;
285
+ if (clientType === "standalone") return;
286
+ window[MAIN_FRAME_ACTION_HANDLER_KEY] = handler;
287
+ }
288
+ async function triggerMainFrameDockAction(clientType, entryId) {
289
+ if (typeof window === "undefined") return void 0;
290
+ if (clientType !== "standalone") return void 0;
291
+ try {
292
+ const opener = window.opener;
293
+ if (!opener || opener.closed) return void 0;
294
+ const handler = opener[MAIN_FRAME_ACTION_HANDLER_KEY];
295
+ if (typeof handler !== "function") return void 0;
296
+ return await handler(entryId);
297
+ } catch {
298
+ return;
299
+ }
300
+ }
301
+ function isDockPopupEntryVisible(clientType) {
302
+ return isDockPopupSupported() && !isPopupOpen.value && clientType !== "standalone";
303
+ }
304
+ function filterPopupDockEntry(groups) {
305
+ return groups.map(([category, entries]) => [category, entries.filter((entry) => entry.id !== POPUP_DOCK_ID)]).filter(([, entries]) => entries.length > 0);
306
+ }
307
+ function useIsDockPopupOpen() {
308
+ return isPopupOpen;
309
+ }
310
+ function requestDockPopupOpen(context) {
311
+ popupEvents.emit("popup:open-requested", context);
312
+ }
313
+ function closeDockPopup() {
314
+ const popup = popupWindow.value;
315
+ clearPopupState();
316
+ if (!popup || popup.closed) return;
317
+ popup.close();
318
+ }
319
+ async function openDockPopup(context) {
320
+ setDocksOverflowPanel(null);
321
+ const currentPopup = popupWindow.value;
322
+ if (currentPopup?.closed) clearPopupState();
323
+ else if (currentPopup) {
324
+ currentPopup.focus();
325
+ return currentPopup;
326
+ }
327
+ const documentPictureInPicture = getDocumentPictureInPicture();
328
+ if (!documentPictureInPicture?.requestWindow) return null;
329
+ let openedPopup;
330
+ try {
331
+ const popup = openedPopup = await documentPictureInPicture.requestWindow({
332
+ width: Math.max(POPUP_MIN_WIDTH, Math.round(window.innerWidth * context.panel.store.width / 100)),
333
+ height: Math.max(POPUP_MIN_HEIGHT, Math.round(window.innerHeight * context.panel.store.height / 100))
334
+ });
335
+ await mountStandaloneApp(context, popup);
336
+ detachColorModeSync = setupPopupColorModeSync(popup);
337
+ const onResize = () => syncPanelSizeFromPopup(context, popup);
338
+ const onPageHide = () => {
339
+ if (popupWindow.value !== popup) return;
340
+ clearPopupState();
341
+ };
342
+ popup.addEventListener("resize", onResize);
343
+ popup.addEventListener("pagehide", onPageHide);
344
+ detachPopupListeners = () => {
345
+ popup.removeEventListener("resize", onResize);
346
+ popup.removeEventListener("pagehide", onPageHide);
347
+ };
348
+ popupWindow.value = popup;
349
+ isPopupOpen.value = true;
350
+ return popup;
351
+ } catch {
352
+ if (openedPopup && !openedPopup.closed) openedPopup.close();
353
+ clearPopupState();
354
+ return null;
355
+ }
356
+ }
357
+ //#endregion
358
+ export { useDocksEntries as _, requestDockPopupOpen as a, BUILTIN_ENTRIES as b, setDockContextMenu as c, useDockContextMenu as d, useDocksOverflowPanel as f, sharedStateToRef as g, createDockEntryState as h, registerMainFrameDockActionHandler as i, setDocksOverflowPanel as l, DEFAULT_DOCK_PANEL_STORE as m, filterPopupDockEntry as n, triggerMainFrameDockAction as o, useFloatingTooltip as p, isDockPopupEntryVisible as r, useIsDockPopupOpen as s, closeDockPopup as t, setFloatingTooltip as u, docksGroupByCategories as v, BUILTIN_ENTRY_CLIENT_AUTH_NOTICE as x, docksSplitGroupsWithCapacity as y };
@@ -0,0 +1,6 @@
1
+ //#region src/node/utils.ts
2
+ function isObject(value) {
3
+ return Object.prototype.toString.call(value) === "[object Object]";
4
+ }
5
+ //#endregion
6
+ export { isObject as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/devtools",
3
3
  "type": "module",
4
- "version": "0.0.0-alpha.9",
4
+ "version": "0.1.0",
5
5
  "description": "Vite DevTools",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
@@ -14,6 +14,7 @@
14
14
  "bugs": "https://github.com/vitejs/devtools/issues",
15
15
  "keywords": [
16
16
  "vite",
17
+ "vite-plugin",
17
18
  "devtools",
18
19
  "rpc"
19
20
  ],
@@ -24,11 +25,10 @@
24
25
  "./cli-commands": "./dist/cli-commands.js",
25
26
  "./client/inject": "./dist/client/inject.js",
26
27
  "./client/webcomponents": "./dist/client/webcomponents.js",
28
+ "./config": "./dist/config.js",
27
29
  "./dirs": "./dist/dirs.js",
28
30
  "./package.json": "./package.json"
29
31
  },
30
- "main": "./dist/index.js",
31
- "module": "./dist/index.js",
32
32
  "types": "./dist/index.d.ts",
33
33
  "bin": {
34
34
  "vite-devtools": "./bin.js"
@@ -38,31 +38,59 @@
38
38
  "dist"
39
39
  ],
40
40
  "peerDependencies": {
41
- "vite": "npm:rolldown-vite@^7.1.20"
41
+ "vite": "*"
42
42
  },
43
43
  "dependencies": {
44
- "cac": "^6.7.14",
45
- "debug": "^4.4.3",
46
- "launch-editor": "^2.12.0",
47
- "mlly": "^1.8.0",
48
- "open": "^10.2.0",
44
+ "birpc": "^4.0.0",
45
+ "cac": "^7.0.0",
46
+ "h3": "^1.15.6",
47
+ "immer": "^11.1.4",
48
+ "launch-editor": "^2.13.1",
49
+ "mlly": "^1.8.1",
50
+ "obug": "^2.1.1",
51
+ "open": "^11.0.0",
49
52
  "pathe": "^2.0.3",
53
+ "perfect-debounce": "^2.1.0",
50
54
  "sirv": "^3.0.2",
51
- "ws": "^8.18.3",
52
- "@vitejs/devtools-kit": "0.0.0-alpha.9",
53
- "@vitejs/devtools-vite": "0.0.0-alpha.9",
54
- "@vitejs/devtools-rpc": "0.0.0-alpha.9"
55
+ "tinyexec": "^1.0.2",
56
+ "ws": "^8.19.0",
57
+ "@vitejs/devtools-kit": "0.1.0",
58
+ "@vitejs/devtools-rpc": "0.1.0",
59
+ "@vitejs/devtools-rolldown": "0.1.0"
55
60
  },
56
61
  "devDependencies": {
57
- "@vitejs/plugin-vue": "^6.0.1",
58
- "tsdown": "^0.15.12",
62
+ "@clack/prompts": "^1.1.0",
63
+ "@vitejs/plugin-vue": "^6.0.5",
64
+ "@xterm/addon-fit": "^0.11.0",
65
+ "@xterm/xterm": "^6.0.0",
66
+ "dompurify": "^3.3.3",
67
+ "tsdown": "^0.21.2",
59
68
  "typescript": "^5.9.3",
60
- "unplugin-vue": "^7.0.4",
61
- "vite": "npm:rolldown-vite@^7.1.20",
62
- "vue": "^3.5.22",
63
- "vue-tsc": "^3.1.2",
64
- "@vitejs/devtools": "0.0.0-alpha.9",
65
- "@vitejs/devtools-vite": "0.0.0-alpha.9"
69
+ "unplugin-vue": "^7.1.1",
70
+ "unplugin-vue-router": "^0.19.2",
71
+ "vite": "^8.0.0",
72
+ "vue": "^3.5.30",
73
+ "vue-router": "^5.0.3",
74
+ "vue-tsc": "^3.2.5",
75
+ "@vitejs/devtools-rolldown": "0.1.0"
76
+ },
77
+ "inlinedDependencies": {
78
+ "@vue/shared": "3.5.30",
79
+ "@vue/reactivity": "3.5.30",
80
+ "@vue/runtime-core": "3.5.30",
81
+ "csstype": "3.2.3",
82
+ "@vue/runtime-dom": "3.5.30",
83
+ "vue": "3.5.30",
84
+ "dompurify": "3.3.3",
85
+ "@xterm/addon-fit": "0.11.0",
86
+ "@xterm/xterm": "6.0.0",
87
+ "@vueuse/shared": "14.2.1",
88
+ "@vueuse/core": "14.2.1",
89
+ "sisteransi": "1.0.5",
90
+ "@clack/core": "1.1.0",
91
+ "@clack/prompts": "1.1.0",
92
+ "ansis": "4.2.0",
93
+ "get-port-please": "3.2.0"
66
94
  },
67
95
  "scripts": {
68
96
  "build": "pnpm build:js && pnpm build:standalone",
@@ -71,6 +99,7 @@
71
99
  "watch": "tsdown --watch --config-loader=tsx",
72
100
  "dev:standalone": "cd src/client/standalone && vite dev",
73
101
  "play": "DEBUG='vite:devtools:*' pnpm -C playground run dev",
102
+ "play:standalone": "DEBUG='vite:devtools:*' pnpm -C playground run dev:standalone",
74
103
  "cli": "DEBUG='vite:devtools:*' tsx src/node/cli.ts",
75
104
  "play:build": "pnpm -C playground run build"
76
105
  }
@@ -1,97 +0,0 @@
1
- import { a as ansis_default, c as fromNodeMiddleware, d as createDevToolsContext, i as getPort, l as sendRedirect, n as createDevToolsMiddleware, o as createApp, r as MARK_NODE, s as eventHandler, t as DevTools, u as toNodeListener } from "./plugins-5VE4Mfdt.js";
2
- import { t as dirClientStandalone } from "./dirs-DcSK9l9L.js";
3
- import { existsSync } from "node:fs";
4
- import sirv from "sirv";
5
- import process from "node:process";
6
- import { loadConfigFromFile, resolveConfig } from "vite";
7
- import fs from "node:fs/promises";
8
- import { createServer } from "node:http";
9
- import open from "open";
10
- import { join, relative, resolve } from "pathe";
11
-
12
- //#region src/node/standalone.ts
13
- async function startStandaloneDevTools(options = {}) {
14
- const { cwd = process.cwd(), command = "build", mode = "production" } = options;
15
- const config = (await loadConfigFromFile({
16
- command,
17
- mode
18
- }, options.config, cwd))?.config || {};
19
- config.plugins ||= [];
20
- config.plugins.push(DevTools());
21
- dedupeVitePlugins(config.plugins, (plugin) => plugin.name?.startsWith("vite:devtools"));
22
- const resolved = await resolveConfig(config, command, mode);
23
- return {
24
- config: resolved,
25
- context: await createDevToolsContext(resolved)
26
- };
27
- }
28
- function dedupeVitePlugins(plugins, include) {
29
- const toDelete = [];
30
- const map = /* @__PURE__ */ new Map();
31
- for (let i = 0; i < plugins.length; i++) {
32
- const plugin = plugins[i];
33
- if (!plugin || !include(plugin)) continue;
34
- if (map.has(plugin.name)) toDelete.push(i);
35
- else map.set(plugin.name, plugin);
36
- }
37
- toDelete.sort((a, b) => b - a);
38
- for (const i of toDelete) plugins.splice(i, 1);
39
- return plugins;
40
- }
41
-
42
- //#endregion
43
- //#region src/node/cli-commands.ts
44
- async function start(options) {
45
- const { host } = options;
46
- const port = await getPort({
47
- host,
48
- port: options.port == null ? void 0 : +options.port,
49
- portRange: [9999, 15e3]
50
- });
51
- const devtools = await startStandaloneDevTools({ cwd: options.root });
52
- const { h3 } = await createDevToolsMiddleware({
53
- cwd: devtools.config.root,
54
- context: devtools.context
55
- });
56
- const app = createApp();
57
- for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) app.use(baseUrl, fromNodeMiddleware(sirv(distDir, {
58
- dev: true,
59
- single: true
60
- })));
61
- app.use("/.devtools/", h3.handler);
62
- app.use("/", eventHandler(async (event) => {
63
- if (event.node.req.url === "/") return sendRedirect(event, "/.devtools/");
64
- }));
65
- createServer(toNodeListener(app)).listen(port, host, async () => {
66
- console.log(ansis_default.green`${MARK_NODE} Vite DevTools started at`, ansis_default.green(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`), "\n");
67
- if (options.open) await open(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`);
68
- });
69
- }
70
- async function build(options) {
71
- console.log(ansis_default.cyan`${MARK_NODE} Building static Vite DevTools...`);
72
- const devtools = await startStandaloneDevTools({
73
- cwd: options.root,
74
- config: options.config
75
- });
76
- const outDir = resolve(devtools.config.root, options.outDir);
77
- if (existsSync(outDir)) await fs.rm(outDir, { recursive: true });
78
- const devToolsRoot = join(outDir, ".devtools");
79
- await fs.mkdir(devToolsRoot, { recursive: true });
80
- await fs.cp(dirClientStandalone, devToolsRoot, { recursive: true });
81
- for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) {
82
- console.log(ansis_default.cyan`${MARK_NODE} Copying static files from ${distDir} to ${join(outDir, baseUrl)}`);
83
- await fs.mkdir(join(outDir, baseUrl), { recursive: true });
84
- await fs.cp(distDir, join(outDir, baseUrl), { recursive: true });
85
- }
86
- await fs.mkdir(resolve(devToolsRoot, "api"), { recursive: true });
87
- await fs.writeFile(resolve(devToolsRoot, ".vdt-connection.json"), JSON.stringify({ backend: "static" }, null, 2), "utf-8");
88
- console.log(ansis_default.cyan`${MARK_NODE} Writing RPC dump to ${resolve(devToolsRoot, ".vdt-rpc-dump.json")}`);
89
- const dump = {};
90
- for (const [key, value] of Object.entries(devtools.context.rpc.functions)) if (value.type === "static") dump[key] = await value.handler?.();
91
- await fs.writeFile(resolve(devToolsRoot, ".vdt-rpc-dump.json"), JSON.stringify(dump, null, 2), "utf-8");
92
- console.log(ansis_default.green`${MARK_NODE} Built to ${relative(devtools.config.root, outDir)}`);
93
- throw new Error("[Vite DevTools] Build mode of Vite DevTools is not yet complete");
94
- }
95
-
96
- //#endregion
97
- export { start as n, build as t };