@kubb/cli 5.18.7 → 5.18.8

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 (116) hide show
  1. package/dist/{Telemetry-Cbt_dJE6.cjs → Telemetry-CBzCK4kO.cjs} +2 -2
  2. package/dist/{Telemetry-Cbt_dJE6.cjs.map → Telemetry-CBzCK4kO.cjs.map} +1 -1
  3. package/dist/{Telemetry-Bf16psPO.js → Telemetry-DUl_hxVn.js} +2 -2
  4. package/dist/{Telemetry-Bf16psPO.js.map → Telemetry-DUl_hxVn.js.map} +1 -1
  5. package/dist/{background-Cvoxk_DQ.js → background-CA9lRKAK.js} +2 -2
  6. package/dist/{background-Cvoxk_DQ.js.map → background-CA9lRKAK.js.map} +1 -1
  7. package/dist/{background-JyYJdws1.js → background-DK3HLyNk.js} +1 -1
  8. package/dist/{background-3TB5Cgkv.cjs → background-fhpYDuSs.cjs} +2 -2
  9. package/dist/{background-3TB5Cgkv.cjs.map → background-fhpYDuSs.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-BQ-Pp7i_.cjs} +3 -3
  20. package/dist/{configFile-C_7uzuGV.cjs.map → configFile-BQ-Pp7i_.cjs.map} +1 -1
  21. package/dist/{configFile-B2EIouxg.js → configFile-CPXDgTC2.js} +3 -3
  22. package/dist/{configFile-B2EIouxg.js.map → configFile-CPXDgTC2.js.map} +1 -1
  23. package/dist/{fs-j84Tqpbx.js → fs-CmODfKN-.js} +25 -6
  24. package/dist/fs-CmODfKN-.js.map +1 -0
  25. package/dist/index.cjs +12 -12
  26. package/dist/index.js +12 -12
  27. package/dist/{installWithSpinner-YEtb8cNf.cjs → installWithSpinner-DZDlVp1J.cjs} +3 -3
  28. package/dist/{installWithSpinner-YEtb8cNf.cjs.map → installWithSpinner-DZDlVp1J.cjs.map} +1 -1
  29. package/dist/{installWithSpinner-C4gKZ7r5.js → installWithSpinner-gv_OWgww.js} +2 -2
  30. package/dist/{installWithSpinner-C4gKZ7r5.js.map → installWithSpinner-gv_OWgww.js.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-CIMQ8g_J.cjs → mcp-BBD4kdKF.cjs} +2 -2
  36. package/dist/{mcp-CIMQ8g_J.cjs.map → mcp-BBD4kdKF.cjs.map} +1 -1
  37. package/dist/{mcp-DFPXRd6M.js → mcp-CQXp9pcW.js} +2 -2
  38. package/dist/{mcp-DFPXRd6M.js.map → mcp-CQXp9pcW.js.map} +1 -1
  39. package/dist/package-CdMFA8OG.js +5 -0
  40. package/dist/package-CdMFA8OG.js.map +1 -0
  41. package/dist/{package-C482iN7Y.cjs → package-DXNoJQYa.cjs} +2 -2
  42. package/dist/package-DXNoJQYa.cjs.map +1 -0
  43. package/dist/{reporters-yVmLpEoU.cjs → reporters-CaJ8brYA.cjs} +253 -101
  44. package/dist/reporters-CaJ8brYA.cjs.map +1 -0
  45. package/dist/{reporters-DJPMb1-j.js → reporters-CzxaQ_bD.js} +1 -1
  46. package/dist/{reporters-De3ynr5a.js → reporters-DeruUk9K.js} +255 -103
  47. package/dist/reporters-DeruUk9K.js.map +1 -0
  48. package/dist/{run-jGpJxxmr.js → run-96_svbr3.js} +5 -5
  49. package/dist/{run-jGpJxxmr.js.map → run-96_svbr3.js.map} +1 -1
  50. package/dist/{run-BGkdpZwR.cjs → run-BIgV2zvB.cjs} +2 -2
  51. package/dist/{run-BGkdpZwR.cjs.map → run-BIgV2zvB.cjs.map} +1 -1
  52. package/dist/{run-hqWFyi0N.cjs → run-BSA2x4iE.cjs} +8 -8
  53. package/dist/{run-hqWFyi0N.cjs.map → run-BSA2x4iE.cjs.map} +1 -1
  54. package/dist/{run-DYr--XFw.js → run-Bi8hhAzv.js} +1 -1
  55. package/dist/{run-D-3F2mhJ.cjs → run-Bxqg0GuI.cjs} +4 -4
  56. package/dist/{run-D-3F2mhJ.cjs.map → run-Bxqg0GuI.cjs.map} +1 -1
  57. package/dist/{run-DD1VdcpX.cjs → run-CIEKCdM-.cjs} +8 -8
  58. package/dist/{run-DD1VdcpX.cjs.map → run-CIEKCdM-.cjs.map} +1 -1
  59. package/dist/{run-BVz9vmbt.js → run-CYdKWpyH.js} +6 -6
  60. package/dist/{run-BVz9vmbt.js.map → run-CYdKWpyH.js.map} +1 -1
  61. package/dist/{run-B-PAQSVx.js → run-CmHjIMpd.js} +7 -7
  62. package/dist/{run-B-PAQSVx.js.map → run-CmHjIMpd.js.map} +1 -1
  63. package/dist/{run-nSTiS72Z.js → run-CpyFU0RM.js} +8 -8
  64. package/dist/{run-nSTiS72Z.js.map → run-CpyFU0RM.js.map} +1 -1
  65. package/dist/{run-DwPkySke.cjs → run-DLRu4z5Z.cjs} +5 -5
  66. package/dist/{run-DwPkySke.cjs.map → run-DLRu4z5Z.cjs.map} +1 -1
  67. package/dist/{run-DVbHd7qm.js → run-Df4PGOFX.js} +74 -23
  68. package/dist/run-Df4PGOFX.js.map +1 -0
  69. package/dist/{run-D7AQwBWZ.cjs → run-GdctJlXN.cjs} +6 -6
  70. package/dist/{run-D7AQwBWZ.cjs.map → run-GdctJlXN.cjs.map} +1 -1
  71. package/dist/{run-BjWqOCAj.js → run-ORjkOWFp.js} +2 -2
  72. package/dist/{run-BjWqOCAj.js.map → run-ORjkOWFp.js.map} +1 -1
  73. package/dist/{run-w0kr76jl.cjs → run-OqiJknWr.cjs} +9 -9
  74. package/dist/{run-w0kr76jl.cjs.map → run-OqiJknWr.cjs.map} +1 -1
  75. package/dist/{run-Bc34cwzh.js → run-U2Ze_QP4.js} +8 -8
  76. package/dist/{run-Bc34cwzh.js.map → run-U2Ze_QP4.js.map} +1 -1
  77. package/dist/{run-D1hHaTDJ.js → run-ixh050Ip.js} +4 -4
  78. package/dist/{run-D1hHaTDJ.js.map → run-ixh050Ip.js.map} +1 -1
  79. package/dist/{run-puNdxNuf.cjs → run-k-LqKkgU.cjs} +74 -23
  80. package/dist/run-k-LqKkgU.cjs.map +1 -0
  81. package/dist/{snapshot-DRyGykFq.cjs → snapshot-C-ge8g3_.cjs} +5 -5
  82. package/dist/{snapshot-DRyGykFq.cjs.map → snapshot-C-ge8g3_.cjs.map} +1 -1
  83. package/dist/{snapshot-eO0_VdUy.js → snapshot-CSacL1qI.js} +5 -5
  84. package/dist/{snapshot-eO0_VdUy.js.map → snapshot-CSacL1qI.js.map} +1 -1
  85. package/dist/{spinner-CdX9Noe9.cjs → spinner-D584jFAz.cjs} +24 -6
  86. package/dist/spinner-D584jFAz.cjs.map +1 -0
  87. package/dist/{status-NqYVjTY8.js → status-Bq-Bjo2n.js} +3 -3
  88. package/dist/{status-NqYVjTY8.js.map → status-Bq-Bjo2n.js.map} +1 -1
  89. package/dist/{status-DICY3TJQ.cjs → status-D-Osmkhr.cjs} +3 -3
  90. package/dist/{status-DICY3TJQ.cjs.map → status-D-Osmkhr.cjs.map} +1 -1
  91. package/dist/{studio-gu56JqH0.js → studio-BBXKjMN-.js} +12 -12
  92. package/dist/{studio-gu56JqH0.js.map → studio-BBXKjMN-.js.map} +1 -1
  93. package/dist/{studio-BfR2KY0b.cjs → studio-BZ53idqa.cjs} +12 -12
  94. package/dist/{studio-BfR2KY0b.cjs.map → studio-BZ53idqa.cjs.map} +1 -1
  95. package/dist/studioWorker.js +2 -2
  96. package/dist/{utils-DGopc0Bo.js → utils-BVccq6W0.js} +3 -3
  97. package/dist/{utils-DGopc0Bo.js.map → utils-BVccq6W0.js.map} +1 -1
  98. package/dist/{utils-D19HX-lE.cjs → utils-C9fYoqP2.cjs} +4 -4
  99. package/dist/{utils-D19HX-lE.cjs.map → utils-C9fYoqP2.cjs.map} +1 -1
  100. package/dist/{validate-DoSQad-i.js → validate-BuStuH_z.js} +2 -2
  101. package/dist/{validate-DoSQad-i.js.map → validate-BuStuH_z.js.map} +1 -1
  102. package/dist/{validate-BXSS6BSO.cjs → validate-rr0LpFhN.cjs} +2 -2
  103. package/dist/{validate-BXSS6BSO.cjs.map → validate-rr0LpFhN.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/fs-j84Tqpbx.js.map +0 -1
  108. package/dist/mascot-kx6WDntR.js.map +0 -1
  109. package/dist/package-C482iN7Y.cjs.map +0 -1
  110. package/dist/package-DqSfSjr4.js +0 -5
  111. package/dist/package-DqSfSjr4.js.map +0 -1
  112. package/dist/reporters-De3ynr5a.js.map +0 -1
  113. package/dist/reporters-yVmLpEoU.cjs.map +0 -1
  114. package/dist/run-DVbHd7qm.js.map +0 -1
  115. package/dist/run-puNdxNuf.cjs.map +0 -1
  116. package/dist/spinner-CdX9Noe9.cjs.map +0 -1
@@ -1,17 +1,54 @@
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-D584jFAz.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
15
  // ../../internals/utils/src/promise.ts
14
16
  /**
17
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
18
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
19
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
20
+ *
21
+ * @example
22
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
23
+ */
24
+ function memo(store, key, compute) {
25
+ const cached = store.get(key);
26
+ if (cached !== void 0 || store.has(key)) return cached;
27
+ const value = compute();
28
+ store.set(key, value);
29
+ return value;
30
+ }
31
+ function createStore({ type }) {
32
+ if (type === "weak") return /* @__PURE__ */ new WeakMap();
33
+ const entry = /* @__PURE__ */ new Map();
34
+ if (type === "map") return entry;
35
+ const set = (key, value) => {
36
+ entry.clear();
37
+ entry.set(key, value);
38
+ };
39
+ const touch = (key) => {
40
+ if (!entry.has(key)) return false;
41
+ set(key, entry.get(key));
42
+ return true;
43
+ };
44
+ return {
45
+ has: touch,
46
+ get: (key) => touch(key) ? entry.get(key) : void 0,
47
+ set
48
+ };
49
+ }
50
+ memo.create = createStore;
51
+ /**
15
52
  * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
16
53
  * takes the next item the moment it frees up instead of waiting for a batch to drain.
17
54
  *
@@ -813,24 +850,35 @@ function diffBuilds(previous, next) {
813
850
  operations: diffNames(previous.operations, next.operations)
814
851
  };
815
852
  }
816
- function countLineChanges(before, after) {
853
+ function splitLines(text) {
854
+ return text ? text.split("\n") : [];
855
+ }
856
+ function hashLine(line) {
857
+ let hash = 2166136261;
858
+ for (const char of line) hash = Math.imul(hash ^ char.codePointAt(0), 16777619);
859
+ return hash;
860
+ }
861
+ function hashLines(text) {
862
+ return Int32Array.from(splitLines(text), hashLine);
863
+ }
864
+ function countLineChanges({ before, after }) {
817
865
  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);
866
+ for (const line of before) remaining.set(line, (remaining.get(line) ?? 0) + 1);
826
867
  return {
827
- added,
828
- removed
868
+ added: [...after].filter((line) => {
869
+ const count = remaining.get(line) ?? 0;
870
+ if (count === 0) return true;
871
+ remaining.set(line, count - 1);
872
+ return false;
873
+ }).length,
874
+ removed: [...remaining.values()].reduce((sum, count) => sum + count, 0)
829
875
  };
830
876
  }
831
877
  /**
832
878
  * Reads the output before generation, so cleaning the directory cannot erase the diff baseline.
833
- * A missing directory or an unreadable file is skipped.
879
+ * A missing directory or an unreadable file is skipped. This keeps every file's text for the whole
880
+ * run, so only a dry run and a run with output passes use it: they compare against the output read
881
+ * back at the end.
834
882
  */
835
883
  async function readOutputFiles(outputPath) {
836
884
  const entries = await (0, node_fs_promises.readdir)(outputPath, {
@@ -848,61 +896,134 @@ async function readOutputFiles(outputPath) {
848
896
  });
849
897
  return files;
850
898
  }
899
+ function fingerprintFile(text) {
900
+ const body = text.trimEnd();
901
+ const trimmed = body.trimStart();
902
+ const leading = body.slice(0, body.length - trimmed.length).split("\n").length - 1;
903
+ const lines = hashLines(trimmed);
904
+ return {
905
+ length: trimmed.length,
906
+ digest: (0, node_crypto.hash)("sha1", trimmed),
907
+ lines,
908
+ deletedLines: body ? lines.length + leading : 0
909
+ };
910
+ }
911
+ /**
912
+ * Fingerprints every file under the output folder right before `output.clean` empties it, one file at a time, so the
913
+ * old tree is never held in memory. A missing directory or an unreadable file is skipped.
914
+ */
915
+ async function readOutputFingerprints(outputPath) {
916
+ const entries = await (0, node_fs_promises.readdir)(outputPath, {
917
+ recursive: true,
918
+ withFileTypes: true
919
+ }).catch(() => []);
920
+ const fingerprints = /* @__PURE__ */ new Map();
921
+ for (const entry of entries) {
922
+ if (!entry.isFile()) continue;
923
+ const filePath = (0, node_path.join)(entry.parentPath, entry.name);
924
+ try {
925
+ fingerprints.set(filePath, fingerprintFile((0, node_fs.readFileSync)(filePath, "utf8")));
926
+ } catch {}
927
+ }
928
+ return fingerprints;
929
+ }
851
930
  /**
852
931
  * 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.
932
+ * same output, otherwise the change with its line counts. `previous` is the stored text, the
933
+ * {@link FileFingerprint} of a file `output.clean` deleted, or `null` for a new file. The manifest
934
+ * recognizes output a formatter rewrote.
855
935
  */
856
936
  function diffFile({ path, next, previous, manifest }) {
857
- if (previous !== null && (require_spinner.matchesStored({
937
+ if (previous === null) return {
938
+ status: "A",
939
+ path,
940
+ added: splitLines(next.trimEnd()).length,
941
+ removed: 0
942
+ };
943
+ if (typeof previous !== "string") {
944
+ const trimmed = next.trim();
945
+ if (trimmed.length === previous.length && (0, node_crypto.hash)("sha1", trimmed) === previous.digest) return void 0;
946
+ return {
947
+ status: "M",
948
+ path,
949
+ ...countLineChanges({
950
+ before: previous.lines,
951
+ after: hashLines(trimmed)
952
+ })
953
+ };
954
+ }
955
+ if (require_spinner.matchesStored({
858
956
  stored: previous,
859
957
  source: next
860
958
  }) || manifest?.isUpToDate({
861
959
  key: path,
862
960
  source: next,
863
961
  disk: previous
864
- }))) return;
962
+ })) return void 0;
865
963
  return {
866
- status: previous === null ? "A" : "M",
964
+ status: "M",
867
965
  path,
868
- ...countLineChanges(previous?.trim() ?? "", previous === null ? next.trimEnd() : next.trim())
966
+ ...countLineChanges({
967
+ before: splitLines(previous.trim()),
968
+ after: splitLines(next.trim())
969
+ })
970
+ };
971
+ }
972
+ const statusKeys = {
973
+ A: "added",
974
+ M: "modified",
975
+ D: "deleted"
976
+ };
977
+ /**
978
+ * Adds one file's outcome to the totals: a {@link FileChange}, or `undefined` for an unchanged file.
979
+ */
980
+ function tallyChange({ tally, change }) {
981
+ if (!change) {
982
+ tally.unchanged++;
983
+ return;
984
+ }
985
+ tally[statusKeys[change.status]]++;
986
+ tally.linesAdded += change.added ?? 0;
987
+ tally.linesRemoved += change.removed ?? 0;
988
+ }
989
+ function createChangeTally() {
990
+ return {
991
+ added: 0,
992
+ modified: 0,
993
+ deleted: 0,
994
+ linesAdded: 0,
995
+ linesRemoved: 0,
996
+ unchanged: 0
869
997
  };
870
998
  }
871
999
  /**
872
1000
  * 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.
1001
+ * output rewritten by a formatter, and `clean` includes files the run would delete.
875
1002
  */
876
- async function diffOutput({ storage, paths, clean, manifest, previousFiles, counted }) {
877
- const generated = new Set(paths);
878
- const changes = [];
879
- let unchanged = 0;
1003
+ async function diffOutput({ storage, paths, clean, manifest, previousFiles }) {
1004
+ const results = [];
880
1005
  await inParallel({
881
- items: paths,
1006
+ items: [...paths],
882
1007
  limit: 50,
883
1008
  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++;
1009
+ const next = await storage.readItem(filePath);
1010
+ if (next === null) return;
1011
+ results[index] = diffFile({
1012
+ path: filePath,
1013
+ next,
1014
+ previous: previousFiles.get(filePath) ?? null,
1015
+ manifest
1016
+ }) ?? null;
898
1017
  }
899
1018
  });
900
- const files = changes.filter((file) => file !== void 0);
1019
+ const files = results.filter((result) => result !== null);
1020
+ const unchanged = results.filter((result) => result === null).length;
901
1021
  if (clean) {
902
- for (const [filePath, source] of previousFiles) if (!generated.has(filePath)) files.push({
1022
+ for (const [filePath, source] of previousFiles) if (!paths.has(filePath)) files.push({
903
1023
  status: "D",
904
1024
  path: filePath,
905
- ...countLineChanges(source.trimEnd(), "")
1025
+ added: 0,
1026
+ removed: splitLines(source.trimEnd()).length
906
1027
  });
907
1028
  }
908
1029
  return {
@@ -968,90 +1089,121 @@ function setupReporters(context, { logLevel, reporters, writer: writer$1 = requi
968
1089
  pluginFiles.set(plugin.name, paths);
969
1090
  }
970
1091
  });
971
- let filesUnchanged = 0;
972
- let previous;
973
- let reading;
974
- let counted;
975
- let paths = [];
976
- let outputPath = "";
1092
+ let run;
977
1093
  const trackChanges = (fileChanges || selected.some((reporter) => reporter.name === "cli")) && logLevel > _kubb_core.logLevel.silent;
978
1094
  context.hook("kubb:generation:start", ({ config }) => {
979
1095
  pluginFiles?.clear();
980
1096
  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;
1097
+ const outputPath = (0, node_path.resolve)(config.root, config.output.path);
1098
+ const tracked = trackChanges && (dryRun || config.storage?.name === "fs");
1099
+ const live = (() => {
1100
+ if (!tracked || dryRun || (0, _kubb_core.hasOutputPasses)(config)) return void 0;
1101
+ return {
1102
+ tally: createChangeTally(),
1103
+ fingerprints: /* @__PURE__ */ new Map(),
1104
+ processed: /* @__PURE__ */ new Set()
1105
+ };
1106
+ })();
1107
+ run = {
1108
+ outputPath,
1109
+ filesUnchanged: 0,
1110
+ paths: /* @__PURE__ */ new Set(),
1111
+ live,
1112
+ reading: tracked && !live ? readOutputFiles(outputPath) : void 0
1113
+ };
987
1114
  });
988
- context.hook("kubb:plugins:end", async () => {
989
- if (reading) previous = await reading;
1115
+ context.hook("kubb:plugins:end", async ({ config }) => {
1116
+ if (!run) return;
1117
+ if (run.reading) run.previous = await run.reading;
1118
+ if (run.live && config.output.clean) run.live.fingerprints = await readOutputFingerprints(run.outputPath);
990
1119
  });
991
1120
  context.hook("kubb:files:processing:start", async ({ files }) => {
992
- if (!previous) return;
1121
+ if (!run?.previous) return;
1122
+ const { previous, outputPath } = run;
993
1123
  for (const file of files) {
994
1124
  if (previous.has(file.path) || require_spinner.isPathInside(outputPath, file.path)) continue;
995
1125
  const source = await (0, node_fs_promises.readFile)(file.path, "utf8").catch(() => null);
996
1126
  if (source !== null) previous.set(file.path, source);
997
1127
  }
998
1128
  });
999
- context.hook("kubb:file:processed", ({ file, source }) => {
1000
- if (!counted || !previous) return;
1129
+ context.hook("kubb:file:processed", ({ file, source, stored = null }) => {
1130
+ const live = run?.live;
1131
+ if (!live) return;
1001
1132
  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
- }));
1133
+ if (!next) return;
1134
+ live.processed.add(file.path);
1135
+ tallyChange({
1136
+ tally: live.tally,
1137
+ change: diffFile({
1138
+ path: file.path,
1139
+ next,
1140
+ previous: stored ?? live.fingerprints.get(file.path) ?? null
1141
+ })
1142
+ });
1007
1143
  });
1008
1144
  context.hook("kubb:files:processing:end", ({ files, unchanged }) => {
1009
- filesUnchanged = unchanged.length;
1010
- paths = files.map((file) => file.path);
1145
+ if (!run) return;
1146
+ run.filesUnchanged = unchanged.length;
1147
+ run.paths = new Set(files.map((file) => file.path));
1011
1148
  });
1149
+ /** The run's totals: counted while writing, or worked out by reading the output back. */
1150
+ async function countChanges({ config, storage, current }) {
1151
+ const { live, paths, previous } = current;
1152
+ if (live) {
1153
+ const { tally, fingerprints, processed } = live;
1154
+ for (const [filePath, fingerprint] of fingerprints) if (!paths.has(filePath)) tallyChange({
1155
+ tally,
1156
+ change: {
1157
+ status: "D",
1158
+ path: filePath,
1159
+ removed: fingerprint.deletedLines
1160
+ }
1161
+ });
1162
+ for (const filePath of paths.difference(processed)) if (await storage.readItem(filePath) !== null) tally.unchanged++;
1163
+ return tally;
1164
+ }
1165
+ if (!previous) return void 0;
1166
+ const manifest = dryRun ? await (0, _kubb_core.createOutputManifest)({
1167
+ storage,
1168
+ cache: (0, _kubb_core.cacheStorage)({ root: config.root })
1169
+ }) : void 0;
1170
+ const diff = await diffOutput({
1171
+ storage,
1172
+ paths,
1173
+ clean: Boolean(config.output.clean),
1174
+ manifest,
1175
+ previousFiles: previous
1176
+ });
1177
+ const changes = createChangeTally();
1178
+ changes.unchanged = diff.unchanged;
1179
+ for (const file of diff.files) tallyChange({
1180
+ tally: changes,
1181
+ change: file
1182
+ });
1183
+ return changes;
1184
+ }
1012
1185
  context.hook("kubb:generation:end", async ({ config, storage, diagnostics = [], filesCreated = 0, status = "success", hrStart = node_process.default.hrtime() }) => {
1186
+ const current = run;
1187
+ run = void 0;
1013
1188
  const result = {
1014
1189
  config,
1015
1190
  diagnostics,
1016
1191
  filesCreated,
1017
- filesUnchanged,
1192
+ filesUnchanged: current?.filesUnchanged ?? 0,
1018
1193
  dryRun,
1019
1194
  status,
1020
1195
  hrStart
1021
1196
  };
1022
1197
  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;
1198
+ const counted = current && status !== "failed" ? await countChanges({
1199
+ config,
1200
+ storage,
1201
+ current
1202
+ }) : void 0;
1203
+ if (counted) {
1204
+ const { unchanged, ...changes } = counted;
1205
+ cliResult.filesCreated = changes.added + changes.modified + unchanged;
1206
+ cliResult.filesUnchanged = unchanged;
1055
1207
  cliResult.fileChanges = changes;
1056
1208
  }
1057
1209
  for (const reporter of selected) {
@@ -1116,4 +1268,4 @@ Object.defineProperty(exports, "trackBuild", {
1116
1268
  }
1117
1269
  });
1118
1270
 
1119
- //# sourceMappingURL=reporters-yVmLpEoU.cjs.map
1271
+ //# sourceMappingURL=reporters-CaJ8brYA.cjs.map