@vitejs/devtools 0.0.0-alpha.0 → 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.
Files changed (62) hide show
  1. package/dist/{functions-CKJw6Oxo.mjs → cli-B_fm1Ing.mjs} +209 -236
  2. package/dist/cli.mjs +2 -2
  3. package/dist/functions-BdbZxtmk.mjs +3 -0
  4. package/dist/functions-d6vvbndK.mjs +234 -0
  5. package/dist/index.d.mts +1 -1
  6. package/dist/nitro.json +3 -3
  7. package/dist/node/cli.mjs +2 -2
  8. package/dist/public/200.html +9 -18
  9. package/dist/public/404.html +9 -18
  10. package/dist/public/_nuxt/B4lqwDon.js +1 -0
  11. package/dist/public/_nuxt/{CcGHFnjf.js → BMB3EEfo.js} +1 -1
  12. package/dist/public/_nuxt/BYYDnj5Q.js +1 -0
  13. package/dist/public/_nuxt/BeSFnMzD.js +1 -0
  14. package/dist/public/_nuxt/BfzgVO01.js +1 -0
  15. package/dist/public/_nuxt/BpyJ-U40.js +1 -0
  16. package/dist/public/_nuxt/BxkFQq1F.js +1 -0
  17. package/dist/public/_nuxt/C1DPtPHu.js +1 -0
  18. package/dist/public/_nuxt/C8oXVTvZ.js +1 -0
  19. package/dist/public/_nuxt/CWPvh8od.js +1 -0
  20. package/dist/public/_nuxt/CiwsH4Q6.js +33 -0
  21. package/dist/public/_nuxt/CsnZqsGp.js +16 -0
  22. package/dist/public/_nuxt/CzEHI6hC.js +1 -0
  23. package/dist/public/_nuxt/D-iXojuv.js +1 -0
  24. package/dist/public/_nuxt/DHpfOFMA.js +1 -0
  25. package/dist/public/_nuxt/DsbJux3u.js +1 -0
  26. package/dist/public/_nuxt/builds/latest.json +1 -1
  27. package/dist/public/_nuxt/builds/meta/3597016d-955b-44d8-83dd-f083d7311779.json +1 -0
  28. package/dist/public/_nuxt/diff.worker-9IK9E-UB.js +10 -0
  29. package/dist/public/_nuxt/entry.BHghYYEP.css +1 -0
  30. package/dist/public/_nuxt/error-404.7Y6KY23b.css +1 -0
  31. package/dist/public/_nuxt/error-500.CaUb23JJ.css +1 -0
  32. package/dist/public/_nuxt/{flow.CT0fChr5.css → graph.BGBTj9Q7.css} +1 -1
  33. package/dist/public/favicon.svg +15 -0
  34. package/dist/public/index.html +9 -18
  35. package/dist/public/vite-devtools.svg +17 -0
  36. package/package.json +15 -13
  37. package/dist/cli-CkEkRmBL.mjs +0 -176
  38. package/dist/functions-peYM_6iz.mjs +0 -3
  39. package/dist/public/_nuxt/B0gvptKi.js +0 -1
  40. package/dist/public/_nuxt/B1XPhBbs.js +0 -4
  41. package/dist/public/_nuxt/B4YzJ31L.js +0 -1
  42. package/dist/public/_nuxt/BHxVjsIi.js +0 -1
  43. package/dist/public/_nuxt/BKXf1uMu.js +0 -1
  44. package/dist/public/_nuxt/BKZ3jkBI.js +0 -1
  45. package/dist/public/_nuxt/Bnn-hxaI.js +0 -1
  46. package/dist/public/_nuxt/BrR0v-Bn.js +0 -1
  47. package/dist/public/_nuxt/BuzEimhA.js +0 -33
  48. package/dist/public/_nuxt/C4K5k6WM.js +0 -1
  49. package/dist/public/_nuxt/COxwzm_n.js +0 -12
  50. package/dist/public/_nuxt/CaCHQCx7.js +0 -1
  51. package/dist/public/_nuxt/CmTKMvEX.js +0 -1
  52. package/dist/public/_nuxt/CwDtpcut.js +0 -1
  53. package/dist/public/_nuxt/DKLzMrv9.js +0 -1
  54. package/dist/public/_nuxt/I6F6kbCC.js +0 -1
  55. package/dist/public/_nuxt/WiKH-0vv.js +0 -1
  56. package/dist/public/_nuxt/YnXJxoTD.js +0 -1
  57. package/dist/public/_nuxt/builds/meta/4e2f12bf-362f-48e3-9beb-2b83e6e986dc.json +0 -1
  58. package/dist/public/_nuxt/diff.worker-394KunD7.js +0 -4
  59. package/dist/public/_nuxt/entry.DadeTU15.css +0 -1
  60. package/dist/public/_nuxt/error-404.RpxUbdEP.css +0 -1
  61. package/dist/public/_nuxt/error-500.tfCn4Lmz.css +0 -1
  62. package/dist/public/_nuxt/kgs9XIg8.js +0 -1
@@ -1,8 +1,22 @@
1
+ import { distDir } from "./dirs-6LDFDMFM.mjs";
2
+ import { createServerFunctions } from "./functions-d6vvbndK.mjs";
1
3
  import { createRequire } from "node:module";
2
- import fs from "node:fs";
3
- import fs$1 from "node:fs/promises";
4
- import { join } from "pathe";
5
- import { diffLines } from "diff";
4
+ import fs, { existsSync } from "node:fs";
5
+ import fs$1, { readFile, stat } from "node:fs/promises";
6
+ import { join } from "node:path";
7
+ import process from "node:process";
8
+ import c from "ansis";
9
+ import cac from "cac";
10
+ import { getPort } from "get-port-please";
11
+ import open from "open";
12
+ import { join as join$1, relative, resolve } from "pathe";
13
+ import { stringify } from "structured-clone-es";
14
+ import { glob } from "tinyglobby";
15
+ import { createServer } from "node:http";
16
+ import { createApp, eventHandler, serveStatic, toNodeListener } from "h3";
17
+ import { lookup } from "mrmime";
18
+ import { createRpcServer } from "@vitejs/devtools-rpc";
19
+ import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/server";
6
20
 
7
21
  //#region rolldown:runtime
8
22
  var __create = Object.create;
@@ -31,40 +45,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
45
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
32
46
 
33
47
  //#endregion
34
- //#region src/node/rpc/utils.ts
35
- function defineRpcFunction(definition) {
36
- return definition;
37
- }
38
-
39
- //#endregion
40
- //#region src/node/rpc/functions/get-payload.ts
41
- const getPayload = defineRpcFunction({
42
- name: "vite:get-payload",
43
- type: "static",
44
- setup: () => {
45
- return { handler: async () => ({ timestamp: Date.now() }) };
46
- }
47
- });
48
-
49
- //#endregion
50
- //#region src/node/rpc/functions/open-in-editor.ts
51
- const openInEditor = defineRpcFunction({
52
- name: "vite:open-in-editor",
53
- type: "action",
54
- setup: () => ({ handler: async (path) => {
55
- await import("launch-editor").then((r) => r.default(path));
56
- } })
57
- });
58
-
59
- //#endregion
60
- //#region src/node/rpc/functions/open-in-finder.ts
61
- const openInFinder = defineRpcFunction({
62
- name: "vite:open-in-finder",
63
- type: "action",
64
- setup: () => ({ handler: async (path) => {
65
- await import("open").then((r) => r.default(path));
66
- } })
67
- });
48
+ //#region src/node/constants.ts
49
+ const MARK_CHECK = c.green("✔");
50
+ const MARK_INFO = c.blue("ℹ");
51
+ const MARK_ERROR = c.red("✖");
52
+ const MARK_NODE = "⬢";
68
53
 
69
54
  //#endregion
70
55
  //#region ../../node_modules/.pnpm/stream-json@1.9.1/node_modules/stream-json/utils/Utf8Stream.js
@@ -215,8 +200,8 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
215
200
  match = patterns.value1.exec(this._buffer);
216
201
  if (!match) {
217
202
  if (this._done || index + MAX_PATTERN_SIZE < this._buffer.length) {
218
- if (index < this._buffer.length) return callback(new Error("Parser cannot parse input: expected a value"));
219
- return callback(new Error("Parser has expected a value"));
203
+ if (index < this._buffer.length) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected a value"));
204
+ return callback(/* @__PURE__ */ new Error("Parser has expected a value"));
220
205
  }
221
206
  break main;
222
207
  }
@@ -239,7 +224,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
239
224
  this._expect = "value1";
240
225
  break;
241
226
  case "]":
242
- if (this._expect !== "value1") return callback(new Error("Parser cannot parse input: unexpected token ']'"));
227
+ if (this._expect !== "value1") return callback(/* @__PURE__ */ new Error("Parser cannot parse input: unexpected token ']'"));
243
228
  if (this._open_number) {
244
229
  this._streamNumbers && this.push({ name: "endNumber" });
245
230
  this._open_number = false;
@@ -318,8 +303,8 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
318
303
  patterns.string.lastIndex = index;
319
304
  match = patterns.string.exec(this._buffer);
320
305
  if (!match) {
321
- if (index < this._buffer.length && (this._done || this._buffer.length - index >= 6)) return callback(new Error("Parser cannot parse input: escaped characters"));
322
- if (this._done) return callback(new Error("Parser has expected a string value"));
306
+ if (index < this._buffer.length && (this._done || this._buffer.length - index >= 6)) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: escaped characters"));
307
+ if (this._done) return callback(/* @__PURE__ */ new Error("Parser has expected a string value"));
323
308
  break main;
324
309
  }
325
310
  value = match[0];
@@ -366,7 +351,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
366
351
  patterns.key1.lastIndex = index;
367
352
  match = patterns.key1.exec(this._buffer);
368
353
  if (!match) {
369
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected an object key"));
354
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected an object key"));
370
355
  break main;
371
356
  }
372
357
  value = match[0];
@@ -374,7 +359,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
374
359
  this._streamKeys && this.push({ name: "startKey" });
375
360
  this._expect = "keyVal";
376
361
  } else if (value === "}") {
377
- if (this._expect !== "key1") return callback(new Error("Parser cannot parse input: unexpected token '}'"));
362
+ if (this._expect !== "key1") return callback(/* @__PURE__ */ new Error("Parser cannot parse input: unexpected token '}'"));
378
363
  this.push({ name: "endObject" });
379
364
  this._parent = this._stack.pop();
380
365
  this._expect = expected[this._parent];
@@ -386,7 +371,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
386
371
  patterns.colon.lastIndex = index;
387
372
  match = patterns.colon.exec(this._buffer);
388
373
  if (!match) {
389
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ':'"));
374
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected ':'"));
390
375
  break main;
391
376
  }
392
377
  value = match[0];
@@ -399,7 +384,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
399
384
  patterns.comma.lastIndex = index;
400
385
  match = patterns.comma.exec(this._buffer);
401
386
  if (!match) {
402
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ','"));
387
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected ','"));
403
388
  break main;
404
389
  }
405
390
  if (this._open_number) {
@@ -416,7 +401,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
416
401
  value = match[0];
417
402
  if (value === ",") this._expect = this._expect === "arrayStop" ? "value" : "key";
418
403
  else if (value === "}" || value === "]") {
419
- if (value === "}" ? this._expect === "arrayStop" : this._expect !== "arrayStop") return callback(new Error("Parser cannot parse input: expected '" + (this._expect === "arrayStop" ? "]" : "}") + "'"));
404
+ if (value === "}" ? this._expect === "arrayStop" : this._expect !== "arrayStop") return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected '" + (this._expect === "arrayStop" ? "]" : "}") + "'"));
420
405
  this.push({ name: value === "}" ? "endObject" : "endArray" });
421
406
  this._parent = this._stack.pop();
422
407
  this._expect = expected[this._parent];
@@ -428,7 +413,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
428
413
  patterns.numberStart.lastIndex = index;
429
414
  match = patterns.numberStart.exec(this._buffer);
430
415
  if (!match) {
431
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected a starting digit"));
416
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected a starting digit"));
432
417
  break main;
433
418
  }
434
419
  value = match[0];
@@ -445,7 +430,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
445
430
  patterns.numberDigit.lastIndex = index;
446
431
  match = patterns.numberDigit.exec(this._buffer);
447
432
  if (!match) {
448
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected a digit"));
433
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected a digit"));
449
434
  break main;
450
435
  }
451
436
  value = match[0];
@@ -493,7 +478,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
493
478
  patterns.numberFracStart.lastIndex = index;
494
479
  match = patterns.numberFracStart.exec(this._buffer);
495
480
  if (!match) {
496
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected a fractional part of a number"));
481
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected a fractional part of a number"));
497
482
  break main;
498
483
  }
499
484
  value = match[0];
@@ -562,7 +547,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
562
547
  this._expect = "numberExpStart";
563
548
  break;
564
549
  }
565
- if (this._done) return callback(new Error("Parser has expected an exponent value of a number"));
550
+ if (this._done) return callback(/* @__PURE__ */ new Error("Parser has expected an exponent value of a number"));
566
551
  break main;
567
552
  }
568
553
  value = match[0];
@@ -579,7 +564,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
579
564
  patterns.numberExpStart.lastIndex = index;
580
565
  match = patterns.numberExpStart.exec(this._buffer);
581
566
  if (!match) {
582
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected an exponent part of a number"));
567
+ if (index < this._buffer.length || this._done) return callback(/* @__PURE__ */ new Error("Parser cannot parse input: expected an exponent part of a number"));
583
568
  break main;
584
569
  }
585
570
  value = match[0];
@@ -621,7 +606,7 @@ var require_Parser = __commonJS({ "../../node_modules/.pnpm/stream-json@1.9.1/no
621
606
  this._expect = "value";
622
607
  break;
623
608
  }
624
- return callback(new Error("Parser cannot parse input: unexpected characters"));
609
+ return callback(/* @__PURE__ */ new Error("Parser cannot parse input: unexpected characters"));
625
610
  }
626
611
  break main;
627
612
  }
@@ -805,13 +790,28 @@ function parseJsonStreamWithConcatArrays(stream, processor) {
805
790
  //#region src/node/rolldown/events-manager.ts
806
791
  var RolldownEventsManager = class {
807
792
  events = [];
808
- modules = new Map();
793
+ modules = /* @__PURE__ */ new Map();
794
+ source_refs = /* @__PURE__ */ new Map();
795
+ interpretSourceRefs(event, key) {
796
+ if (key in event && typeof event[key] === "string") {
797
+ if (event[key].startsWith("$ref:")) {
798
+ const refKey = event[key].slice(5);
799
+ if (this.source_refs.has(refKey)) event[key] = this.source_refs.get(refKey);
800
+ }
801
+ }
802
+ }
809
803
  handleEvent(raw) {
810
804
  const event = {
811
805
  ...raw,
812
- event_id: `${raw.timestamp}#${this.events.length}`
806
+ event_id: `${"timestamp" in raw ? raw.timestamp : "x"}#${this.events.length}`
813
807
  };
814
808
  this.events.push(event);
809
+ if (event.action === "StringRef") {
810
+ this.source_refs.set(event.id, event.content);
811
+ return;
812
+ }
813
+ this.interpretSourceRefs(event, "source");
814
+ this.interpretSourceRefs(event, "transformed_source");
815
815
  if ("module_id" in event) {
816
816
  if (this.modules.has(event.module_id)) return;
817
817
  this.modules.set(event.module_id, {
@@ -838,11 +838,12 @@ var RolldownEventsManager = class {
838
838
 
839
839
  //#endregion
840
840
  //#region src/node/rolldown/events-reader.ts
841
- const readers = new Map();
841
+ const readers = /* @__PURE__ */ new Map();
842
842
  var RolldownEventsReader = class RolldownEventsReader {
843
843
  lastBytes = 0;
844
844
  lastTimestamp = 0;
845
845
  manager = new RolldownEventsManager();
846
+ meta;
846
847
  constructor(filepath) {
847
848
  this.filepath = filepath;
848
849
  }
@@ -873,194 +874,166 @@ var RolldownEventsReader = class RolldownEventsReader {
873
874
  };
874
875
 
875
876
  //#endregion
876
- //#region src/node/rpc/functions/rolldown-get-module-info.ts
877
- const DURATION_THRESHOLD = 10;
878
- const rolldownGetModuleInfo = defineRpcFunction({
879
- name: "vite:rolldown:get-module-info",
880
- type: "query",
881
- setup: ({ cwd }) => {
882
- return { handler: async ({ session, module: module$1 }) => {
883
- const reader = RolldownEventsReader.get(join(cwd, ".rolldown", session, "logs.json"));
884
- await reader.read();
885
- const events = reader.manager.events;
886
- if (!events.length) return null;
887
- const info = {
888
- id: module$1,
889
- loads: [],
890
- transforms: [],
891
- imports: [],
892
- importers: [],
893
- resolve_ids: [],
894
- ...reader.manager.modules.get(module$1) || {}
895
- };
896
- events.forEach((start, index) => {
897
- if (start.action !== "HookLoadCallStart" || start.module_id !== module$1) return;
898
- const end = events.find((e) => e.action === "HookLoadCallEnd" && e.call_id === start.call_id, index);
899
- if (!end || end.action !== "HookLoadCallEnd") {
900
- console.error(`[rolldown] Load call end not found for ${start.call_id}`);
901
- return;
902
- }
903
- const duration = +end.timestamp - +start.timestamp;
904
- if (!end.source && duration < DURATION_THRESHOLD) return;
905
- info.loads.push({
906
- type: "load",
907
- id: start.event_id,
908
- plugin_name: start.plugin_name,
909
- plugin_index: start.plugin_index,
910
- source: end.source,
911
- timestamp_start: +start.timestamp,
912
- timestamp_end: +end.timestamp,
913
- duration
914
- });
915
- });
916
- events.forEach((start, index) => {
917
- if (start.action !== "HookTransformCallStart" || start.module_id !== module$1) return;
918
- const end = events.find((e) => e.action === "HookTransformCallEnd" && e.call_id === start.call_id, index);
919
- if (!end || end.action !== "HookTransformCallEnd") {
920
- console.error(`[rolldown] Transform call end not found for ${start.event_id}`);
921
- return;
922
- }
923
- const duration = +end.timestamp - +start.timestamp;
924
- if (end.transformed_source === start.source && duration < DURATION_THRESHOLD) return;
925
- let diff_added = 0;
926
- let diff_removed = 0;
927
- if (start.source !== end.transformed_source && start.source != null && end.transformed_source != null) {
928
- const delta = diffLines(end.transformed_source, start.source);
929
- diff_added = delta.filter((d) => d.added).map((d) => d.value).join("").split(/\n/g).length;
930
- diff_removed = delta.filter((d) => d.removed).map((d) => d.value).join("").split(/\n/g).length;
931
- }
932
- info.transforms.push({
933
- type: "transform",
934
- id: start.event_id,
935
- plugin_name: start.plugin_name,
936
- plugin_index: start.plugin_index,
937
- source_from: start.source,
938
- source_to: end.transformed_source,
939
- diff_added,
940
- diff_removed,
941
- timestamp_start: +start.timestamp,
942
- timestamp_end: +end.timestamp,
943
- duration
944
- });
945
- });
946
- events.forEach((end) => {
947
- if (end.action !== "HookResolveIdCallEnd" || end.resolved_id !== module$1) return;
948
- const start = events.find((e) => e.action === "HookResolveIdCallStart" && e.call_id === end.call_id);
949
- if (!start || start.action !== "HookResolveIdCallStart") {
950
- console.error(`[rolldown] resolveId call start not found for ${end.event_id}`);
951
- return;
952
- }
953
- const duration = +end.timestamp - +start.timestamp;
954
- const data = {
955
- type: "resolve",
956
- id: end.event_id,
957
- importer: start.importer,
958
- module_request: start.module_request,
959
- import_kind: start.import_kind,
960
- plugin_name: end.plugin_name,
961
- plugin_index: end.plugin_index,
962
- resolved_id: end.resolved_id,
963
- timestamp_start: +start.timestamp,
964
- timestamp_end: +end.timestamp,
965
- duration
966
- };
967
- const existingIndex = info.resolve_ids.findIndex((r) => r.importer === start.importer && r.module_request === start.module_request && r.import_kind === start.import_kind && r.plugin_index === end.plugin_index);
968
- if (existingIndex >= 0) info.resolve_ids.splice(existingIndex, 1);
969
- info.resolve_ids.push(data);
970
- });
971
- info.loads.sort((a, b) => a.plugin_index - b.plugin_index);
972
- info.transforms.sort((a, b) => a.plugin_index - b.plugin_index);
973
- info.resolve_ids.sort((a, b) => a.plugin_index - b.plugin_index);
974
- return info;
975
- } };
976
- }
977
- });
978
-
979
- //#endregion
980
- //#region src/node/rpc/functions/rolldown-get-module-raw-events.ts
981
- const rolldownGetModuleRawEvents = defineRpcFunction({
982
- name: "vite:rolldown:get-module-raw-events",
983
- type: "query",
984
- setup: ({ cwd }) => {
985
- return { handler: async ({ session, module: module$1 }) => {
986
- const reader = RolldownEventsReader.get(join(cwd, ".rolldown", session, "logs.json"));
987
- await reader.read();
988
- const events = reader.manager.events.filter((event) => "module_id" in event && event.module_id === module$1);
989
- return { events };
990
- } };
991
- }
992
- });
993
-
994
- //#endregion
995
- //#region src/node/rpc/functions/rolldown-get-raw-events.ts
996
- const rolldownGetRawEvents = defineRpcFunction({
997
- name: "vite:rolldown:get-raw-events",
998
- type: "query",
999
- setup: ({ cwd }) => {
1000
- return { handler: async ({ session }) => {
1001
- const reader = RolldownEventsReader.get(join(cwd, ".rolldown", session, "logs.json"));
1002
- await reader.read();
1003
- return reader.manager.events;
1004
- } };
877
+ //#region src/node/rolldown/logs-manager.ts
878
+ var RolldownLogsManager = class {
879
+ constructor(dir) {
880
+ this.dir = dir;
1005
881
  }
1006
- });
1007
-
1008
- //#endregion
1009
- //#region src/node/rpc/functions/rolldown-get-session-summary.ts
1010
- const rolldownGetSessionSummary = defineRpcFunction({
1011
- name: "vite:rolldown:get-session-summary",
1012
- type: "query",
1013
- setup: async ({ cwd }) => {
1014
- return { handler: async ({ session }) => {
1015
- const reader = RolldownEventsReader.get(join(cwd, ".rolldown", session, "logs.json"));
1016
- await reader.read();
882
+ async list() {
883
+ const sessions = await fs$1.readdir(this.dir, { withFileTypes: true });
884
+ return await Promise.all(sessions.filter((d) => d.isDirectory()).map(async (d) => {
885
+ const meta = JSON.parse(await fs$1.readFile(join$1(this.dir, d.name, "meta.json"), "utf-8"));
1017
886
  return {
1018
- id: session,
1019
- rootDir: cwd,
1020
- modules: Array.from(reader.manager.modules.values()).sort((a, b) => a.id.localeCompare(b.id))
887
+ id: d.name,
888
+ timestamp: meta.timestamp,
889
+ meta
1021
890
  };
1022
- } };
891
+ }));
1023
892
  }
1024
- });
1025
-
1026
- //#endregion
1027
- //#region src/node/rpc/functions/rolldown-list-sessions.ts
1028
- const rolldownListSessions = defineRpcFunction({
1029
- name: "vite:rolldown:list-sessions",
1030
- type: "query",
1031
- setup: ({ cwd }) => {
1032
- return { handler: async () => {
1033
- const sessions = await fs$1.readdir(join(cwd, ".rolldown"), { withFileTypes: true });
1034
- return await Promise.all(sessions.filter((d) => d.isDirectory()).map(async (d) => {
1035
- const stats = await fs$1.stat(join(cwd, ".rolldown", d.name));
1036
- return {
1037
- id: d.name,
1038
- createdAt: stats.birthtime.getTime()
1039
- };
1040
- }));
1041
- } };
893
+ async loadSession(session) {
894
+ const reader = RolldownEventsReader.get(join$1(this.dir, session, "logs.json"));
895
+ reader.meta ||= JSON.parse(await fs$1.readFile(join$1(this.dir, session, "meta.json"), "utf-8"));
896
+ await reader.read();
897
+ return reader;
1042
898
  }
1043
- });
899
+ };
1044
900
 
1045
901
  //#endregion
1046
- //#region src/node/rpc/index.ts
1047
- const rpcFunctions = [
1048
- openInEditor,
1049
- openInFinder,
1050
- getPayload,
1051
- rolldownListSessions,
1052
- rolldownGetRawEvents,
1053
- rolldownGetSessionSummary,
1054
- rolldownGetModuleInfo,
1055
- rolldownGetModuleRawEvents
1056
- ];
902
+ //#region src/node/ws.ts
903
+ async function createWsServer(options) {
904
+ const port = options.port ?? await getPort({
905
+ port: 7812,
906
+ random: true
907
+ });
908
+ const wsClients = /* @__PURE__ */ new Set();
909
+ const serverFunctions = await createServerFunctions(options);
910
+ const preset = createWsRpcPreset({
911
+ port,
912
+ onConnected: (ws) => {
913
+ wsClients.add(ws);
914
+ console.log(c.green`${MARK_CHECK} Websocket client connected`);
915
+ },
916
+ onDisconnected: (ws) => {
917
+ wsClients.delete(ws);
918
+ console.log(c.red`${MARK_CHECK} Websocket client disconnected`);
919
+ }
920
+ });
921
+ const rpc = createRpcServer(serverFunctions, {
922
+ preset,
923
+ rpcOptions: { onError(error, name) {
924
+ console.error(c.red`⬢ RPC error on executing "${c.bold(name)}":`);
925
+ console.error(error);
926
+ throw error;
927
+ } }
928
+ });
929
+ const getMetadata = async () => {
930
+ return {
931
+ backend: "websocket",
932
+ websocket: port
933
+ };
934
+ };
935
+ return {
936
+ port,
937
+ rpc,
938
+ serverFunctions,
939
+ getMetadata
940
+ };
941
+ }
1057
942
 
1058
943
  //#endregion
1059
- //#region src/node/functions.ts
1060
- async function createServerFunctions(options) {
1061
- const functions = await Promise.all(rpcFunctions.map(async (fn) => [fn.name, (await fn.setup(options)).handler]));
1062
- return Object.fromEntries(functions);
944
+ //#region src/node/server.ts
945
+ async function createHostServer(options) {
946
+ const app = createApp();
947
+ const { rpc, getMetadata } = await createWsServer(options);
948
+ const fileMap = /* @__PURE__ */ new Map();
949
+ const readCachedFile = (id) => {
950
+ if (!fileMap.has(id)) fileMap.set(id, readFile(id).catch(() => void 0));
951
+ return fileMap.get(id);
952
+ };
953
+ app.use("/api/metadata.json", eventHandler(async (event) => {
954
+ event.node.res.setHeader("Content-Type", "application/json");
955
+ return event.node.res.end(JSON.stringify(await getMetadata()));
956
+ }));
957
+ app.use("/", eventHandler(async (event) => {
958
+ const result = await serveStatic(event, {
959
+ fallthrough: true,
960
+ getContents: (id) => readCachedFile(join$1(distDir, id)),
961
+ getMeta: async (id) => {
962
+ const stats = await stat(join$1(distDir, id)).catch(() => {});
963
+ if (!stats || !stats.isFile()) return;
964
+ return {
965
+ type: lookup(id),
966
+ size: stats.size,
967
+ mtime: stats.mtimeMs
968
+ };
969
+ }
970
+ });
971
+ if (result === false) return readCachedFile(join$1(distDir, "index.html"));
972
+ }));
973
+ return {
974
+ server: createServer(toNodeListener(app)),
975
+ rpc
976
+ };
1063
977
  }
1064
978
 
1065
979
  //#endregion
1066
- export { createServerFunctions };
980
+ //#region src/node/cli.ts
981
+ const cli = cac("vite-devtools");
982
+ cli.command("build", "Build devtools with current config file for static hosting").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Config file").option("--depth <depth>", "Max depth to list dependencies", { default: 8 }).option("--base <baseURL>", "Base URL for deployment", { default: "/" }).option("--outDir <dir>", "Output directory", { default: ".vite-devtools" }).action(async (options) => {
983
+ console.log(c.cyan`${MARK_NODE} Building static Vite DevTools...`);
984
+ const cwd = process.cwd();
985
+ const outDir = resolve(cwd, options.outDir);
986
+ const rpc = await import("./functions-BdbZxtmk.mjs").then(async (r) => await r.createServerFunctions({
987
+ cwd,
988
+ mode: "build",
989
+ manager: new RolldownLogsManager(join(cwd, ".rolldown"))
990
+ }));
991
+ const rpcDump = { "vite:get-payload": await rpc["vite:get-payload"]() };
992
+ let baseURL = options.base;
993
+ if (!baseURL.endsWith("/")) baseURL += "/";
994
+ if (!baseURL.startsWith("/")) baseURL = `/${baseURL}`;
995
+ baseURL = baseURL.replace(/\/+/g, "/");
996
+ if (existsSync(outDir)) await fs$1.rm(outDir, { recursive: true });
997
+ await fs$1.mkdir(outDir, { recursive: true });
998
+ await fs$1.cp(distDir, outDir, { recursive: true });
999
+ const htmlFiles = await glob("**/*.html", {
1000
+ cwd: distDir,
1001
+ onlyFiles: true,
1002
+ dot: true,
1003
+ expandDirectories: false
1004
+ });
1005
+ if (baseURL !== "/") for (const file of htmlFiles) {
1006
+ const content = await fs$1.readFile(resolve(distDir, file), "utf-8");
1007
+ const newContent = content.replaceAll(/\s(href|src)="\//g, ` $1="${baseURL}`).replaceAll("baseURL:\"/\"", `baseURL:"${baseURL}"`);
1008
+ await fs$1.writeFile(resolve(outDir, file), newContent, "utf-8");
1009
+ }
1010
+ await fs$1.mkdir(resolve(outDir, "api"), { recursive: true });
1011
+ await fs$1.writeFile(resolve(outDir, "api/metadata.json"), JSON.stringify({ backend: "static" }, null, 2), "utf-8");
1012
+ await fs$1.writeFile(resolve(outDir, "api/rpc-dump.json"), stringify(rpcDump), "utf-8");
1013
+ console.log(c.green`${MARK_CHECK} Built to ${relative(cwd, outDir)}`);
1014
+ console.log(c.blue`${MARK_NODE} You can use static server like \`npx serve ${relative(cwd, outDir)}\` to serve the devtools`);
1015
+ });
1016
+ cli.command("", "Start devtools").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Config file").option("--depth <depth>", "Max depth to list dependencies", { default: 8 }).option("--host <host>", "Host", { default: process.env.HOST || "127.0.0.1" }).option("--port <port>", "Port", { default: process.env.PORT || 9999 }).option("--open", "Open browser", { default: true }).action(async (options) => {
1017
+ const host = options.host;
1018
+ const port = await getPort({
1019
+ port: options.port,
1020
+ portRange: [9999, 15e3],
1021
+ host
1022
+ });
1023
+ console.log(c.green`${MARK_NODE} Starting Vite DevTools at`, c.green(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`), "\n");
1024
+ const { server, rpc } = await createHostServer({
1025
+ cwd: options.root,
1026
+ mode: "dev",
1027
+ manager: new RolldownLogsManager(join(options.root, ".rolldown"))
1028
+ });
1029
+ setTimeout(() => {
1030
+ rpc.functions["vite:get-payload"]();
1031
+ }, 1);
1032
+ server.listen(port, host, async () => {
1033
+ if (options.open) await open(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`);
1034
+ });
1035
+ });
1036
+ cli.help();
1037
+ cli.parse();
1038
+
1039
+ //#endregion
package/dist/cli.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import "./functions-CKJw6Oxo.mjs";
1
+ import "./cli-B_fm1Ing.mjs";
2
2
  import "./dirs-6LDFDMFM.mjs";
3
- import "./cli-CkEkRmBL.mjs";
3
+ import "./functions-d6vvbndK.mjs";
@@ -0,0 +1,3 @@
1
+ import { createServerFunctions } from "./functions-d6vvbndK.mjs";
2
+
3
+ export { createServerFunctions };