@kubb/cli 5.18.7 → 5.19.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 (120) hide show
  1. package/dist/{Telemetry-Cbt_dJE6.cjs → Telemetry-B2TeLVo4.cjs} +2 -2
  2. package/dist/{Telemetry-Cbt_dJE6.cjs.map → Telemetry-B2TeLVo4.cjs.map} +1 -1
  3. package/dist/{Telemetry-Bf16psPO.js → Telemetry-Ctyp_EFO.js} +2 -2
  4. package/dist/{Telemetry-Bf16psPO.js.map → Telemetry-Ctyp_EFO.js.map} +1 -1
  5. package/dist/{background-Cvoxk_DQ.js → background-CByahHYn.js} +2 -2
  6. package/dist/{background-Cvoxk_DQ.js.map → background-CByahHYn.js.map} +1 -1
  7. package/dist/{background-JyYJdws1.js → background-D60rO2Lz.js} +1 -1
  8. package/dist/{background-3TB5Cgkv.cjs → background-D6dQxXt6.cjs} +2 -2
  9. package/dist/{background-3TB5Cgkv.cjs.map → background-D6dQxXt6.cjs.map} +1 -1
  10. package/dist/config-BKi_vTvh.js +1 -0
  11. package/dist/{config-DJtqFNG2.cjs → config-BU9xeaGq.cjs} +2 -2
  12. package/dist/{config-DJtqFNG2.cjs.map → config-BU9xeaGq.cjs.map} +1 -1
  13. package/dist/{config-BL4UlCHs.js → config-CGcQTdZV.js} +2 -2
  14. package/dist/{config-BL4UlCHs.js.map → config-CGcQTdZV.js.map} +1 -1
  15. package/dist/{config-BIv45u1Z.cjs → config-CkTrJD0E.cjs} +2 -2
  16. package/dist/{config-BIv45u1Z.cjs.map → config-CkTrJD0E.cjs.map} +1 -1
  17. package/dist/{config-BqDpLCPu.js → config-re864UnO.js} +4 -4
  18. package/dist/config-re864UnO.js.map +1 -0
  19. package/dist/{configFile-C_7uzuGV.cjs → configFile-B_xrd2yx.cjs} +5 -5
  20. package/dist/configFile-B_xrd2yx.cjs.map +1 -0
  21. package/dist/{configFile-B2EIouxg.js → configFile-Bh_5k4pf.js} +5 -5
  22. package/dist/configFile-Bh_5k4pf.js.map +1 -0
  23. package/dist/{fs-j84Tqpbx.js → fs-CWRKTIst.js} +83 -7
  24. package/dist/fs-CWRKTIst.js.map +1 -0
  25. package/dist/index.cjs +12 -12
  26. package/dist/index.js +12 -12
  27. package/dist/{installWithSpinner-C4gKZ7r5.js → installWithSpinner-RJhWCsgh.js} +2 -2
  28. package/dist/{installWithSpinner-C4gKZ7r5.js.map → installWithSpinner-RJhWCsgh.js.map} +1 -1
  29. package/dist/{installWithSpinner-YEtb8cNf.cjs → installWithSpinner-qjIqjyiW.cjs} +3 -3
  30. package/dist/{installWithSpinner-YEtb8cNf.cjs.map → installWithSpinner-qjIqjyiW.cjs.map} +1 -1
  31. package/dist/{mascot-ZEiXQ_LT.cjs → mascot-CLw0Qmln.cjs} +10 -6
  32. package/dist/{mascot-ZEiXQ_LT.cjs.map → mascot-CLw0Qmln.cjs.map} +1 -1
  33. package/dist/{mascot-kx6WDntR.js → mascot-b4yXsKwl.js} +10 -6
  34. package/dist/mascot-b4yXsKwl.js.map +1 -0
  35. package/dist/{mcp-DFPXRd6M.js → mcp-BrB7TJZU.js} +2 -2
  36. package/dist/{mcp-DFPXRd6M.js.map → mcp-BrB7TJZU.js.map} +1 -1
  37. package/dist/{mcp-CIMQ8g_J.cjs → mcp-D2gcpCcx.cjs} +2 -2
  38. package/dist/{mcp-CIMQ8g_J.cjs.map → mcp-D2gcpCcx.cjs.map} +1 -1
  39. package/dist/package-CcsdQpSf.js +5 -0
  40. package/dist/package-CcsdQpSf.js.map +1 -0
  41. package/dist/{package-C482iN7Y.cjs → package-DM5mr0Yc.cjs} +2 -2
  42. package/dist/package-DM5mr0Yc.cjs.map +1 -0
  43. package/dist/{reporters-De3ynr5a.js → reporters-B6p0n7s3.js} +226 -132
  44. package/dist/reporters-B6p0n7s3.js.map +1 -0
  45. package/dist/{reporters-DJPMb1-j.js → reporters-BDzKLpyo.js} +1 -1
  46. package/dist/{reporters-yVmLpEoU.cjs → reporters-DLK4D0js.cjs} +226 -132
  47. package/dist/reporters-DLK4D0js.cjs.map +1 -0
  48. package/dist/{run-D7AQwBWZ.cjs → run-3OxB7Zxn.cjs} +6 -6
  49. package/dist/{run-D7AQwBWZ.cjs.map → run-3OxB7Zxn.cjs.map} +1 -1
  50. package/dist/{run-D-3F2mhJ.cjs → run-4MUhIiPj.cjs} +4 -4
  51. package/dist/{run-D-3F2mhJ.cjs.map → run-4MUhIiPj.cjs.map} +1 -1
  52. package/dist/{run-w0kr76jl.cjs → run-6qjg9Twy.cjs} +9 -9
  53. package/dist/{run-w0kr76jl.cjs.map → run-6qjg9Twy.cjs.map} +1 -1
  54. package/dist/{run-BVz9vmbt.js → run-B3TuKUr4.js} +6 -6
  55. package/dist/{run-BVz9vmbt.js.map → run-B3TuKUr4.js.map} +1 -1
  56. package/dist/{run-DYr--XFw.js → run-BJiP4ib3.js} +1 -1
  57. package/dist/{run-B-PAQSVx.js → run-BSsTBfse.js} +7 -7
  58. package/dist/{run-B-PAQSVx.js.map → run-BSsTBfse.js.map} +1 -1
  59. package/dist/{run-puNdxNuf.cjs → run-C2lQXYrF.cjs} +74 -23
  60. package/dist/run-C2lQXYrF.cjs.map +1 -0
  61. package/dist/{run-DD1VdcpX.cjs → run-C6tE9zTS.cjs} +8 -8
  62. package/dist/{run-DD1VdcpX.cjs.map → run-C6tE9zTS.cjs.map} +1 -1
  63. package/dist/{run-jGpJxxmr.js → run-CC9TBCph.js} +5 -5
  64. package/dist/{run-jGpJxxmr.js.map → run-CC9TBCph.js.map} +1 -1
  65. package/dist/{run-D1hHaTDJ.js → run-CcWmws1R.js} +4 -4
  66. package/dist/{run-D1hHaTDJ.js.map → run-CcWmws1R.js.map} +1 -1
  67. package/dist/{run-DVbHd7qm.js → run-Cxfs1SLQ.js} +74 -23
  68. package/dist/run-Cxfs1SLQ.js.map +1 -0
  69. package/dist/{run-DwPkySke.cjs → run-D0HO6_Yr.cjs} +5 -5
  70. package/dist/{run-DwPkySke.cjs.map → run-D0HO6_Yr.cjs.map} +1 -1
  71. package/dist/{run-BjWqOCAj.js → run-D2tJP_b8.js} +2 -2
  72. package/dist/{run-BjWqOCAj.js.map → run-D2tJP_b8.js.map} +1 -1
  73. package/dist/{run-Bc34cwzh.js → run-DFOjQVMO.js} +8 -8
  74. package/dist/{run-Bc34cwzh.js.map → run-DFOjQVMO.js.map} +1 -1
  75. package/dist/{run-nSTiS72Z.js → run-Dyzva1xB.js} +8 -8
  76. package/dist/{run-nSTiS72Z.js.map → run-Dyzva1xB.js.map} +1 -1
  77. package/dist/{run-BGkdpZwR.cjs → run-ejmyJI37.cjs} +2 -2
  78. package/dist/{run-BGkdpZwR.cjs.map → run-ejmyJI37.cjs.map} +1 -1
  79. package/dist/{run-hqWFyi0N.cjs → run-lH8k2FY7.cjs} +8 -8
  80. package/dist/{run-hqWFyi0N.cjs.map → run-lH8k2FY7.cjs.map} +1 -1
  81. package/dist/{snapshot-DRyGykFq.cjs → snapshot-DdRni_x5.cjs} +5 -5
  82. package/dist/{snapshot-DRyGykFq.cjs.map → snapshot-DdRni_x5.cjs.map} +1 -1
  83. package/dist/{snapshot-eO0_VdUy.js → snapshot-DnqAAzKE.js} +5 -5
  84. package/dist/{snapshot-eO0_VdUy.js.map → snapshot-DnqAAzKE.js.map} +1 -1
  85. package/dist/{spinner-CdX9Noe9.cjs → spinner-BQgUoe7F.cjs} +93 -6
  86. package/dist/spinner-BQgUoe7F.cjs.map +1 -0
  87. package/dist/{status-NqYVjTY8.js → status-X9BNNp9F.js} +3 -3
  88. package/dist/{status-NqYVjTY8.js.map → status-X9BNNp9F.js.map} +1 -1
  89. package/dist/{status-DICY3TJQ.cjs → status-wHJjD3Fs.cjs} +3 -3
  90. package/dist/{status-DICY3TJQ.cjs.map → status-wHJjD3Fs.cjs.map} +1 -1
  91. package/dist/{studio-BfR2KY0b.cjs → studio-j4As00N6.cjs} +12 -12
  92. package/dist/{studio-BfR2KY0b.cjs.map → studio-j4As00N6.cjs.map} +1 -1
  93. package/dist/{studio-gu56JqH0.js → studio-rRSg33RE.js} +12 -12
  94. package/dist/{studio-gu56JqH0.js.map → studio-rRSg33RE.js.map} +1 -1
  95. package/dist/studioWorker.js +2 -2
  96. package/dist/{utils-DGopc0Bo.js → utils-DnmjcKb0.js} +5 -11
  97. package/dist/utils-DnmjcKb0.js.map +1 -0
  98. package/dist/{utils-D19HX-lE.cjs → utils-_hY0r-7x.cjs} +6 -12
  99. package/dist/utils-_hY0r-7x.cjs.map +1 -0
  100. package/dist/{validate-DoSQad-i.js → validate-CSbYneXo.js} +2 -2
  101. package/dist/{validate-DoSQad-i.js.map → validate-CSbYneXo.js.map} +1 -1
  102. package/dist/{validate-BXSS6BSO.cjs → validate-CyxoAzEK.cjs} +2 -2
  103. package/dist/{validate-BXSS6BSO.cjs.map → validate-CyxoAzEK.cjs.map} +1 -1
  104. package/package.json +7 -7
  105. package/dist/config-BqDpLCPu.js.map +0 -1
  106. package/dist/config-CGpzjjPV.js +0 -1
  107. package/dist/configFile-B2EIouxg.js.map +0 -1
  108. package/dist/configFile-C_7uzuGV.cjs.map +0 -1
  109. package/dist/fs-j84Tqpbx.js.map +0 -1
  110. package/dist/mascot-kx6WDntR.js.map +0 -1
  111. package/dist/package-C482iN7Y.cjs.map +0 -1
  112. package/dist/package-DqSfSjr4.js +0 -5
  113. package/dist/package-DqSfSjr4.js.map +0 -1
  114. package/dist/reporters-De3ynr5a.js.map +0 -1
  115. package/dist/reporters-yVmLpEoU.cjs.map +0 -1
  116. package/dist/run-DVbHd7qm.js.map +0 -1
  117. package/dist/run-puNdxNuf.cjs.map +0 -1
  118. package/dist/spinner-CdX9Noe9.cjs.map +0 -1
  119. package/dist/utils-D19HX-lE.cjs.map +0 -1
  120. package/dist/utils-DGopc0Bo.js.map +0 -1
@@ -1,32 +1,17 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
- const require_spinner = require("./spinner-CdX9Noe9.cjs");
2
+ const require_spinner = require("./spinner-BQgUoe7F.cjs");
3
3
  const require_log = require("./log-BzmBldY6.cjs");
4
4
  const require_time = require("./time-D4xUq6tx.cjs");
5
5
  const require_banner = require("./banner-GwQ2NFNI.cjs");
6
6
  const require_text = require("./text-CkCtm5VP.cjs");
7
7
  let node_util = require("node:util");
8
+ let node_crypto = require("node:crypto");
8
9
  let node_process = require("node:process");
9
10
  node_process = require_rolldown_runtime.__toESM(node_process, 1);
11
+ let node_fs = require("node:fs");
10
12
  let node_fs_promises = require("node:fs/promises");
11
13
  let node_path = require("node:path");
12
14
  let _kubb_core = require("@kubb/core");
13
- // ../../internals/utils/src/promise.ts
14
- /**
15
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
16
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
17
- *
18
- * @example
19
- * ```ts
20
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
21
- * ```
22
- */
23
- async function inParallel({ items, limit, run }) {
24
- const queue = items.entries();
25
- const worker = async () => {
26
- for (const [index, item] of queue) await run(item, index);
27
- };
28
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
29
- }
30
15
  // src/loggers/features/context.ts
31
16
  function createLoggerContext({ hooks, writer, logLevel }) {
32
17
  const text = (message) => logLevel >= _kubb_core.logLevel.verbose ? `${(0, node_util.styleText)("dim", `[${clock()}]`)} ${message}` : message;
@@ -272,17 +257,13 @@ function createPhases({ writer, silent, logLevel, text, line, onRun }, spinner)
272
257
  };
273
258
  }
274
259
  // src/loggers/specFrame.ts
275
- let cached;
260
+ const startsBySource = require_spinner.memo.create({ max: 1 });
276
261
  function lineStarts(source) {
277
- if (cached?.source !== source) {
262
+ return require_spinner.memo(startsBySource, source, () => {
278
263
  const starts = [0];
279
264
  for (const match of source.matchAll(/\n/g)) starts.push(match.index + 1);
280
- cached = {
281
- source,
282
- starts
283
- };
284
- }
285
- return cached.starts;
265
+ return starts;
266
+ });
286
267
  }
287
268
  /** The index of the last line start at or before `offset`, found by binary search. */
288
269
  function lineIndex(starts, offset, low = 0, high = starts.length - 1) {
@@ -813,24 +794,35 @@ function diffBuilds(previous, next) {
813
794
  operations: diffNames(previous.operations, next.operations)
814
795
  };
815
796
  }
816
- function countLineChanges(before, after) {
797
+ function splitLines(text) {
798
+ return text ? text.split("\n") : [];
799
+ }
800
+ function hashLine(line) {
801
+ let hash = 2166136261;
802
+ for (const char of line) hash = Math.imul(hash ^ char.codePointAt(0), 16777619);
803
+ return hash;
804
+ }
805
+ function hashLines(text) {
806
+ return Int32Array.from(splitLines(text), hashLine);
807
+ }
808
+ function countLineChanges({ before, after }) {
817
809
  const remaining = /* @__PURE__ */ new Map();
818
- for (const line of before ? before.split("\n") : []) remaining.set(line, (remaining.get(line) ?? 0) + 1);
819
- let added = 0;
820
- for (const line of after ? after.split("\n") : []) {
821
- const count = remaining.get(line) ?? 0;
822
- if (count > 0) remaining.set(line, count - 1);
823
- else added++;
824
- }
825
- const removed = [...remaining.values()].reduce((sum, count) => sum + count, 0);
810
+ for (const line of before) remaining.set(line, (remaining.get(line) ?? 0) + 1);
826
811
  return {
827
- added,
828
- removed
812
+ added: [...after].filter((line) => {
813
+ const count = remaining.get(line) ?? 0;
814
+ if (count === 0) return true;
815
+ remaining.set(line, count - 1);
816
+ return false;
817
+ }).length,
818
+ removed: [...remaining.values()].reduce((sum, count) => sum + count, 0)
829
819
  };
830
820
  }
831
821
  /**
832
822
  * Reads the output before generation, so cleaning the directory cannot erase the diff baseline.
833
- * A missing directory or an unreadable file is skipped.
823
+ * A missing directory or an unreadable file is skipped. This keeps every file's text for the whole
824
+ * run, so only a dry run and a run with output passes use it: they compare against the output read
825
+ * back at the end.
834
826
  */
835
827
  async function readOutputFiles(outputPath) {
836
828
  const entries = await (0, node_fs_promises.readdir)(outputPath, {
@@ -838,7 +830,7 @@ async function readOutputFiles(outputPath) {
838
830
  withFileTypes: true
839
831
  }).catch(() => []);
840
832
  const files = /* @__PURE__ */ new Map();
841
- await inParallel({
833
+ await require_spinner.inParallel({
842
834
  items: entries.filter((entry) => entry.isFile()).map((entry) => (0, node_path.join)(entry.parentPath, entry.name)),
843
835
  limit: 50,
844
836
  run: async (filePath) => {
@@ -848,61 +840,134 @@ async function readOutputFiles(outputPath) {
848
840
  });
849
841
  return files;
850
842
  }
843
+ function fingerprintFile(text) {
844
+ const body = text.trimEnd();
845
+ const trimmed = body.trimStart();
846
+ const leading = body.slice(0, body.length - trimmed.length).split("\n").length - 1;
847
+ const lines = hashLines(trimmed);
848
+ return {
849
+ length: trimmed.length,
850
+ digest: (0, node_crypto.hash)("sha1", trimmed),
851
+ lines,
852
+ deletedLines: body ? lines.length + leading : 0
853
+ };
854
+ }
855
+ /**
856
+ * Fingerprints every file under the output folder right before `output.clean` empties it, one file at a time, so the
857
+ * old tree is never held in memory. A missing directory or an unreadable file is skipped.
858
+ */
859
+ async function readOutputFingerprints(outputPath) {
860
+ const entries = await (0, node_fs_promises.readdir)(outputPath, {
861
+ recursive: true,
862
+ withFileTypes: true
863
+ }).catch(() => []);
864
+ const fingerprints = /* @__PURE__ */ new Map();
865
+ for (const entry of entries) {
866
+ if (!entry.isFile()) continue;
867
+ const filePath = (0, node_path.join)(entry.parentPath, entry.name);
868
+ try {
869
+ fingerprints.set(filePath, fingerprintFile((0, node_fs.readFileSync)(filePath, "utf8")));
870
+ } catch {}
871
+ }
872
+ return fingerprints;
873
+ }
851
874
  /**
852
875
  * How one generated file differs from its copy before generation: `undefined` when both hold the
853
- * same output, otherwise the change with its line counts. The manifest recognizes output a
854
- * formatter rewrote.
876
+ * same output, otherwise the change with its line counts. `previous` is the stored text, the
877
+ * {@link FileFingerprint} of a file `output.clean` deleted, or `null` for a new file. The manifest
878
+ * recognizes output a formatter rewrote.
855
879
  */
856
880
  function diffFile({ path, next, previous, manifest }) {
857
- if (previous !== null && (require_spinner.matchesStored({
881
+ if (previous === null) return {
882
+ status: "A",
883
+ path,
884
+ added: splitLines(next.trimEnd()).length,
885
+ removed: 0
886
+ };
887
+ if (typeof previous !== "string") {
888
+ const trimmed = next.trim();
889
+ if (trimmed.length === previous.length && (0, node_crypto.hash)("sha1", trimmed) === previous.digest) return void 0;
890
+ return {
891
+ status: "M",
892
+ path,
893
+ ...countLineChanges({
894
+ before: previous.lines,
895
+ after: hashLines(trimmed)
896
+ })
897
+ };
898
+ }
899
+ if (require_spinner.matchesStored({
858
900
  stored: previous,
859
901
  source: next
860
902
  }) || manifest?.isUpToDate({
861
903
  key: path,
862
904
  source: next,
863
905
  disk: previous
864
- }))) return;
906
+ })) return void 0;
865
907
  return {
866
- status: previous === null ? "A" : "M",
908
+ status: "M",
867
909
  path,
868
- ...countLineChanges(previous?.trim() ?? "", previous === null ? next.trimEnd() : next.trim())
910
+ ...countLineChanges({
911
+ before: splitLines(previous.trim()),
912
+ after: splitLines(next.trim())
913
+ })
914
+ };
915
+ }
916
+ const statusKeys = {
917
+ A: "added",
918
+ M: "modified",
919
+ D: "deleted"
920
+ };
921
+ /**
922
+ * Adds one file's outcome to the totals: a {@link FileChange}, or `undefined` for an unchanged file.
923
+ */
924
+ function tallyChange({ tally, change }) {
925
+ if (!change) {
926
+ tally.unchanged++;
927
+ return;
928
+ }
929
+ tally[statusKeys[change.status]]++;
930
+ tally.linesAdded += change.added ?? 0;
931
+ tally.linesRemoved += change.removed ?? 0;
932
+ }
933
+ function createChangeTally() {
934
+ return {
935
+ added: 0,
936
+ modified: 0,
937
+ deleted: 0,
938
+ linesAdded: 0,
939
+ linesRemoved: 0,
940
+ unchanged: 0
869
941
  };
870
942
  }
871
943
  /**
872
944
  * Compares generated output with the files captured before generation. The manifest recognizes
873
- * output rewritten by a formatter, and `clean` includes files the run would delete. `counted` holds
874
- * changes already worked out while the files were written; any other path is read back.
945
+ * output rewritten by a formatter, and `clean` includes files the run would delete.
875
946
  */
876
- async function diffOutput({ storage, paths, clean, manifest, previousFiles, counted }) {
877
- const generated = new Set(paths);
878
- const changes = [];
879
- let unchanged = 0;
880
- await inParallel({
881
- items: paths,
947
+ async function diffOutput({ storage, paths, clean, manifest, previousFiles }) {
948
+ const results = [];
949
+ await require_spinner.inParallel({
950
+ items: [...paths],
882
951
  limit: 50,
883
952
  run: async (filePath, index) => {
884
- let change;
885
- if (counted?.has(filePath)) change = counted.get(filePath);
886
- else {
887
- const next = await storage.readItem(filePath);
888
- if (next === null) return;
889
- change = diffFile({
890
- path: filePath,
891
- next,
892
- previous: previousFiles.get(filePath) ?? null,
893
- manifest
894
- });
895
- }
896
- if (change) changes[index] = change;
897
- else unchanged++;
953
+ const next = await storage.readItem(filePath);
954
+ if (next === null) return;
955
+ results[index] = diffFile({
956
+ path: filePath,
957
+ next,
958
+ previous: previousFiles.get(filePath) ?? null,
959
+ manifest
960
+ }) ?? null;
898
961
  }
899
962
  });
900
- const files = changes.filter((file) => file !== void 0);
963
+ const files = results.filter((result) => result !== null);
964
+ const unchanged = results.filter((result) => result === null).length;
901
965
  if (clean) {
902
- for (const [filePath, source] of previousFiles) if (!generated.has(filePath)) files.push({
966
+ for (const [filePath, source] of previousFiles) if (!paths.has(filePath)) files.push({
903
967
  status: "D",
904
968
  path: filePath,
905
- ...countLineChanges(source.trimEnd(), "")
969
+ added: 0,
970
+ removed: splitLines(source.trimEnd()).length
906
971
  });
907
972
  }
908
973
  return {
@@ -957,101 +1022,130 @@ function setupReporters(context, { logLevel, reporters, writer: writer$1 = requi
957
1022
  }).renderSummary })];
958
1023
  });
959
1024
  const ctx = { logLevel };
960
- const pluginFiles = selected.some((reporter) => reporter.needsPluginFiles) ? /* @__PURE__ */ new Map() : void 0;
1025
+ const pluginFiles = selected.some((reporter) => reporter.needsPluginFiles) ? require_spinner.memo.create() : void 0;
961
1026
  const seen = /* @__PURE__ */ new Set();
962
1027
  if (pluginFiles) context.hook("kubb:plugin:end", ({ plugin, files }) => {
963
1028
  for (const file of files) {
964
1029
  if (seen.has(file.path)) continue;
965
1030
  seen.add(file.path);
966
- const paths = pluginFiles.get(plugin.name) ?? [];
967
- paths.push(file.path);
968
- pluginFiles.set(plugin.name, paths);
1031
+ require_spinner.memo(pluginFiles, plugin.name, () => []).push(file.path);
969
1032
  }
970
1033
  });
971
- let filesUnchanged = 0;
972
- let previous;
973
- let reading;
974
- let counted;
975
- let paths = [];
976
- let outputPath = "";
1034
+ let run;
977
1035
  const trackChanges = (fileChanges || selected.some((reporter) => reporter.name === "cli")) && logLevel > _kubb_core.logLevel.silent;
978
1036
  context.hook("kubb:generation:start", ({ config }) => {
979
1037
  pluginFiles?.clear();
980
1038
  seen.clear();
981
- filesUnchanged = 0;
982
- paths = [];
983
- outputPath = (0, node_path.resolve)(config.root, config.output.path);
984
- previous = void 0;
985
- reading = trackChanges && (dryRun || config.storage?.name === "fs") ? readOutputFiles(outputPath) : void 0;
986
- counted = reading && !dryRun && !(0, _kubb_core.hasOutputPasses)(config) ? /* @__PURE__ */ new Map() : void 0;
1039
+ const outputPath = (0, node_path.resolve)(config.root, config.output.path);
1040
+ const tracked = trackChanges && (dryRun || config.storage?.name === "fs");
1041
+ const live = (() => {
1042
+ if (!tracked || dryRun || (0, _kubb_core.hasOutputPasses)(config)) return void 0;
1043
+ return {
1044
+ tally: createChangeTally(),
1045
+ fingerprints: /* @__PURE__ */ new Map(),
1046
+ processed: /* @__PURE__ */ new Set()
1047
+ };
1048
+ })();
1049
+ run = {
1050
+ outputPath,
1051
+ filesUnchanged: 0,
1052
+ paths: /* @__PURE__ */ new Set(),
1053
+ live,
1054
+ reading: tracked && !live ? readOutputFiles(outputPath) : void 0
1055
+ };
987
1056
  });
988
- context.hook("kubb:plugins:end", async () => {
989
- if (reading) previous = await reading;
1057
+ context.hook("kubb:plugins:end", async ({ config }) => {
1058
+ if (!run) return;
1059
+ if (run.reading) run.previous = await run.reading;
1060
+ if (run.live && config.output.clean) run.live.fingerprints = await readOutputFingerprints(run.outputPath);
990
1061
  });
991
1062
  context.hook("kubb:files:processing:start", async ({ files }) => {
992
- if (!previous) return;
1063
+ if (!run?.previous) return;
1064
+ const { previous, outputPath } = run;
993
1065
  for (const file of files) {
994
1066
  if (previous.has(file.path) || require_spinner.isPathInside(outputPath, file.path)) continue;
995
1067
  const source = await (0, node_fs_promises.readFile)(file.path, "utf8").catch(() => null);
996
1068
  if (source !== null) previous.set(file.path, source);
997
1069
  }
998
1070
  });
999
- context.hook("kubb:file:processed", ({ file, source }) => {
1000
- if (!counted || !previous) return;
1071
+ context.hook("kubb:file:processed", ({ file, source, stored = null }) => {
1072
+ const live = run?.live;
1073
+ if (!live) return;
1001
1074
  const next = source.trim();
1002
- if (next) counted.set(file.path, diffFile({
1003
- path: file.path,
1004
- next,
1005
- previous: previous.get(file.path) ?? null
1006
- }));
1075
+ if (!next) return;
1076
+ live.processed.add(file.path);
1077
+ tallyChange({
1078
+ tally: live.tally,
1079
+ change: diffFile({
1080
+ path: file.path,
1081
+ next,
1082
+ previous: stored ?? live.fingerprints.get(file.path) ?? null
1083
+ })
1084
+ });
1007
1085
  });
1008
1086
  context.hook("kubb:files:processing:end", ({ files, unchanged }) => {
1009
- filesUnchanged = unchanged.length;
1010
- paths = files.map((file) => file.path);
1087
+ if (!run) return;
1088
+ run.filesUnchanged = unchanged.length;
1089
+ run.paths = new Set(files.map((file) => file.path));
1011
1090
  });
1091
+ /** The run's totals: counted while writing, or worked out by reading the output back. */
1092
+ async function countChanges({ config, storage, current }) {
1093
+ const { live, paths, previous } = current;
1094
+ if (live) {
1095
+ const { tally, fingerprints, processed } = live;
1096
+ for (const [filePath, fingerprint] of fingerprints) if (!paths.has(filePath)) tallyChange({
1097
+ tally,
1098
+ change: {
1099
+ status: "D",
1100
+ path: filePath,
1101
+ removed: fingerprint.deletedLines
1102
+ }
1103
+ });
1104
+ for (const filePath of paths.difference(processed)) if (await storage.readItem(filePath) !== null) tally.unchanged++;
1105
+ return tally;
1106
+ }
1107
+ if (!previous) return void 0;
1108
+ const manifest = dryRun ? await (0, _kubb_core.createOutputManifest)({
1109
+ storage,
1110
+ cache: (0, _kubb_core.cacheStorage)({ root: config.root })
1111
+ }) : void 0;
1112
+ const diff = await diffOutput({
1113
+ storage,
1114
+ paths,
1115
+ clean: Boolean(config.output.clean),
1116
+ manifest,
1117
+ previousFiles: previous
1118
+ });
1119
+ const changes = createChangeTally();
1120
+ changes.unchanged = diff.unchanged;
1121
+ for (const file of diff.files) tallyChange({
1122
+ tally: changes,
1123
+ change: file
1124
+ });
1125
+ return changes;
1126
+ }
1012
1127
  context.hook("kubb:generation:end", async ({ config, storage, diagnostics = [], filesCreated = 0, status = "success", hrStart = node_process.default.hrtime() }) => {
1128
+ const current = run;
1129
+ run = void 0;
1013
1130
  const result = {
1014
1131
  config,
1015
1132
  diagnostics,
1016
1133
  filesCreated,
1017
- filesUnchanged,
1134
+ filesUnchanged: current?.filesUnchanged ?? 0,
1018
1135
  dryRun,
1019
1136
  status,
1020
1137
  hrStart
1021
1138
  };
1022
1139
  const cliResult = { ...result };
1023
- if (previous && status !== "failed") {
1024
- const manifest = dryRun ? await (0, _kubb_core.createOutputManifest)({
1025
- storage,
1026
- cache: (0, _kubb_core.cacheStorage)({ root: config.root })
1027
- }) : void 0;
1028
- const diff = await diffOutput({
1029
- storage,
1030
- paths,
1031
- clean: Boolean(config.output.clean),
1032
- manifest,
1033
- previousFiles: previous,
1034
- counted
1035
- });
1036
- const changes = {
1037
- added: 0,
1038
- modified: 0,
1039
- deleted: 0,
1040
- linesAdded: 0,
1041
- linesRemoved: 0
1042
- };
1043
- const counts = {
1044
- A: "added",
1045
- M: "modified",
1046
- D: "deleted"
1047
- };
1048
- for (const file of diff.files) {
1049
- changes[counts[file.status]]++;
1050
- changes.linesAdded += file.added ?? 0;
1051
- changes.linesRemoved += file.removed ?? 0;
1052
- }
1053
- cliResult.filesCreated = changes.added + changes.modified + diff.unchanged;
1054
- cliResult.filesUnchanged = diff.unchanged;
1140
+ const counted = current && status !== "failed" ? await countChanges({
1141
+ config,
1142
+ storage,
1143
+ current
1144
+ }) : void 0;
1145
+ if (counted) {
1146
+ const { unchanged, ...changes } = counted;
1147
+ cliResult.filesCreated = changes.added + changes.modified + unchanged;
1148
+ cliResult.filesUnchanged = unchanged;
1055
1149
  cliResult.fileChanges = changes;
1056
1150
  }
1057
1151
  for (const reporter of selected) {
@@ -1116,4 +1210,4 @@ Object.defineProperty(exports, "trackBuild", {
1116
1210
  }
1117
1211
  });
1118
1212
 
1119
- //# sourceMappingURL=reporters-yVmLpEoU.cjs.map
1213
+ //# sourceMappingURL=reporters-DLK4D0js.cjs.map