@kubb/core 4.2.0 → 4.2.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 (130) hide show
  1. package/dist/URLPath-8WVzHBnA.cjs +134 -0
  2. package/dist/URLPath-8WVzHBnA.cjs.map +1 -0
  3. package/dist/URLPath-BYceu_vY.js +117 -0
  4. package/dist/URLPath-BYceu_vY.js.map +1 -0
  5. package/dist/{acorn-DExO7r0H.cjs → acorn-BAVXZMtK.cjs} +1 -1
  6. package/dist/{acorn-DExO7r0H.cjs.map → acorn-BAVXZMtK.cjs.map} +1 -1
  7. package/dist/{acorn-B0JdnMwY.js → acorn-D-VhIOLw.js} +1 -1
  8. package/dist/{acorn-B0JdnMwY.js.map → acorn-D-VhIOLw.js.map} +1 -1
  9. package/dist/{angular-C2M8l5eL.cjs → angular-Bp0XO9db.cjs} +1 -1
  10. package/dist/{angular-C2M8l5eL.cjs.map → angular-Bp0XO9db.cjs.map} +1 -1
  11. package/dist/{angular-CmU_K35W.js → angular-Czhp4eq5.js} +1 -1
  12. package/dist/{angular-CmU_K35W.js.map → angular-Czhp4eq5.js.map} +1 -1
  13. package/dist/{babel-CfF0c5A9.js → babel-DCR_B4Qn.js} +1 -1
  14. package/dist/{babel-CfF0c5A9.js.map → babel-DCR_B4Qn.js.map} +1 -1
  15. package/dist/{babel-BKn0s9Rj.cjs → babel-NI0v59ga.cjs} +1 -1
  16. package/dist/{babel-BKn0s9Rj.cjs.map → babel-NI0v59ga.cjs.map} +1 -1
  17. package/dist/casing-BSeq_teY.js +100 -0
  18. package/dist/casing-BSeq_teY.js.map +1 -0
  19. package/dist/casing-CP-9GGdK.cjs +112 -0
  20. package/dist/casing-CP-9GGdK.cjs.map +1 -0
  21. package/dist/{estree-Br3l79C5.cjs → estree-C3BZPlpU.cjs} +1 -1
  22. package/dist/{estree-Br3l79C5.cjs.map → estree-C3BZPlpU.cjs.map} +1 -1
  23. package/dist/{estree-B_YMDsR7.js → estree-DU2NummP.js} +1 -1
  24. package/dist/{estree-B_YMDsR7.js.map → estree-DU2NummP.js.map} +1 -1
  25. package/dist/{flow-B_3vaVXc.cjs → flow-CWUBUkoi.cjs} +1 -1
  26. package/dist/{flow-B_3vaVXc.cjs.map → flow-CWUBUkoi.cjs.map} +1 -1
  27. package/dist/{flow-Dc3wao4M.js → flow-JiEbweKj.js} +1 -1
  28. package/dist/{flow-Dc3wao4M.js.map → flow-JiEbweKj.js.map} +1 -1
  29. package/dist/fs.d.cts +1 -1
  30. package/dist/fs.d.ts +1 -1
  31. package/dist/{glimmer-BF35HI3l.cjs → glimmer-CX9OqG1j.cjs} +1 -1
  32. package/dist/{glimmer-BF35HI3l.cjs.map → glimmer-CX9OqG1j.cjs.map} +1 -1
  33. package/dist/{glimmer-CwM1XZA1.js → glimmer-t9nWn9aE.js} +1 -1
  34. package/dist/{glimmer-CwM1XZA1.js.map → glimmer-t9nWn9aE.js.map} +1 -1
  35. package/dist/{graphql-KQQTidk7.js → graphql-DjErlIi5.js} +1 -1
  36. package/dist/{graphql-KQQTidk7.js.map → graphql-DjErlIi5.js.map} +1 -1
  37. package/dist/{graphql-DhaHiYrP.cjs → graphql-GOxQAKxM.cjs} +1 -1
  38. package/dist/{graphql-DhaHiYrP.cjs.map → graphql-GOxQAKxM.cjs.map} +1 -1
  39. package/dist/hooks.d.cts +3 -2
  40. package/dist/hooks.d.ts +4 -3
  41. package/dist/{html-B2QWX43c.cjs → html-CWrdYAhQ.cjs} +1 -1
  42. package/dist/{html-B2QWX43c.cjs.map → html-CWrdYAhQ.cjs.map} +1 -1
  43. package/dist/{html-DQoJX7Yj.js → html-_apcbx34.js} +1 -1
  44. package/dist/{html-DQoJX7Yj.js.map → html-_apcbx34.js.map} +1 -1
  45. package/dist/{index-BY_kka8d.d.ts → index-BTe91LHd.d.ts} +2 -2
  46. package/dist/{index-Iq8NJRgc.d.cts → index-BmQIxvw0.d.cts} +2 -2
  47. package/dist/index.cjs +378 -22
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +37 -4
  50. package/dist/index.d.ts +38 -5
  51. package/dist/index.js +371 -15
  52. package/dist/index.js.map +1 -1
  53. package/dist/{logger-BkGPbocD.d.ts → logger-BA-za85-.d.ts} +1 -1
  54. package/dist/{logger-S_t55o9n.cjs → logger-BXL0YCrv.cjs} +2 -2
  55. package/dist/{logger-S_t55o9n.cjs.map → logger-BXL0YCrv.cjs.map} +1 -1
  56. package/dist/{logger-CsQ2EGpR.js → logger-CDxSrFkR.js} +2 -2
  57. package/dist/{logger-CsQ2EGpR.js.map → logger-CDxSrFkR.js.map} +1 -1
  58. package/dist/logger.cjs +1 -1
  59. package/dist/logger.d.ts +1 -1
  60. package/dist/logger.js +1 -1
  61. package/dist/{markdown-CDf4HsAQ.js → markdown-ckUc3Q6q.js} +1 -1
  62. package/dist/{markdown-CDf4HsAQ.js.map → markdown-ckUc3Q6q.js.map} +1 -1
  63. package/dist/{markdown-HXmAlxeH.cjs → markdown-pzqiRmft.cjs} +1 -1
  64. package/dist/{markdown-HXmAlxeH.cjs.map → markdown-pzqiRmft.cjs.map} +1 -1
  65. package/dist/{meriyah-D8fyVkyI.js → meriyah-BjnGqpUs.js} +1 -1
  66. package/dist/{meriyah-D8fyVkyI.js.map → meriyah-BjnGqpUs.js.map} +1 -1
  67. package/dist/{meriyah-CWoiYjq_.cjs → meriyah-D_x7itbT.cjs} +1 -1
  68. package/dist/{meriyah-CWoiYjq_.cjs.map → meriyah-D_x7itbT.cjs.map} +1 -1
  69. package/dist/mocks.cjs +24 -24
  70. package/dist/mocks.cjs.map +1 -1
  71. package/dist/mocks.d.cts +3 -2
  72. package/dist/mocks.d.ts +4 -3
  73. package/dist/mocks.js +19 -20
  74. package/dist/mocks.js.map +1 -1
  75. package/dist/{postcss-bESf1Yzf.cjs → postcss-B_c2wbFu.cjs} +1 -1
  76. package/dist/{postcss-bESf1Yzf.cjs.map → postcss-B_c2wbFu.cjs.map} +1 -1
  77. package/dist/{postcss-Dqh1XvaI.js → postcss-v7BP6SZ-.js} +1 -1
  78. package/dist/{postcss-Dqh1XvaI.js.map → postcss-v7BP6SZ-.js.map} +1 -1
  79. package/dist/{prompt-C5GR2LPU.js → prompt-DBVnG4Me.js} +1 -1
  80. package/dist/{prompt-C5GR2LPU.js.map → prompt-DBVnG4Me.js.map} +1 -1
  81. package/dist/{prompt-ZBXNC-aV.cjs → prompt-DgONOpPH.cjs} +1 -1
  82. package/dist/{prompt-ZBXNC-aV.cjs.map → prompt-DgONOpPH.cjs.map} +1 -1
  83. package/dist/{transformers-BIx7CVmw.cjs → transformers-BH0KLJJP.cjs} +119 -228
  84. package/dist/transformers-BH0KLJJP.cjs.map +1 -0
  85. package/dist/{transformers-5BubQvcu.js → transformers-DzHGqYO2.js} +118 -215
  86. package/dist/transformers-DzHGqYO2.js.map +1 -0
  87. package/dist/transformers.cjs +4 -3
  88. package/dist/transformers.js +2 -1
  89. package/dist/types-BzI9JlV8.d.ts +5 -0
  90. package/dist/types-C3ea5qNG.d.cts +5 -0
  91. package/dist/{types-IOE1JAFC.d.cts → types-DNxlynJr.d.cts} +11 -70
  92. package/dist/{types-DtokChaW.d.ts → types-DPeNK0FO.d.ts} +12 -71
  93. package/dist/{typescript-BYxryL2A.cjs → typescript-6kMN6Wqz.cjs} +1 -1
  94. package/dist/{typescript-BYxryL2A.cjs.map → typescript-6kMN6Wqz.cjs.map} +1 -1
  95. package/dist/{typescript-B7n7vRma.js → typescript-B_IBfKSe.js} +1 -1
  96. package/dist/{typescript-B7n7vRma.js.map → typescript-B_IBfKSe.js.map} +1 -1
  97. package/dist/typescript-C5hce4HG.cjs +4 -0
  98. package/dist/typescript-Cas1XcNz.js +3 -0
  99. package/dist/utils.cjs +165 -20
  100. package/dist/utils.cjs.map +1 -0
  101. package/dist/utils.d.cts +136 -5
  102. package/dist/utils.d.ts +136 -5
  103. package/dist/utils.js +156 -5
  104. package/dist/utils.js.map +1 -0
  105. package/dist/{yaml-BMiF8MYP.js → yaml-BfWM_B73.js} +1 -1
  106. package/dist/{yaml-BMiF8MYP.js.map → yaml-BfWM_B73.js.map} +1 -1
  107. package/dist/{yaml-DQCs4b_O.cjs → yaml-DZs6MhV1.cjs} +1 -1
  108. package/dist/{yaml-DQCs4b_O.cjs.map → yaml-DZs6MhV1.cjs.map} +1 -1
  109. package/package.json +3 -3
  110. package/src/FileManager.ts +34 -302
  111. package/src/PluginManager.ts +9 -8
  112. package/src/__snapshots__/barrel.json +5 -5
  113. package/src/build.ts +19 -5
  114. package/src/index.ts +1 -2
  115. package/src/mocks/index.ts +4 -3
  116. package/src/plugin.ts +1 -1
  117. package/src/types.ts +4 -1
  118. package/src/utils/TreeNode.ts +3 -3
  119. package/src/utils/index.ts +2 -4
  120. package/dist/FileManager-DlkY9W5A.cjs +0 -1001
  121. package/dist/FileManager-DlkY9W5A.cjs.map +0 -1
  122. package/dist/FileManager-zlhCXf6A.js +0 -879
  123. package/dist/FileManager-zlhCXf6A.js.map +0 -1
  124. package/dist/index-CYcjcRdj.d.ts +0 -179
  125. package/dist/index-DaYv9bst.d.cts +0 -179
  126. package/dist/transformers-5BubQvcu.js.map +0 -1
  127. package/dist/transformers-BIx7CVmw.cjs.map +0 -1
  128. package/dist/typescript-CIdP4XPm.js +0 -3
  129. package/dist/typescript-CbuCkdxv.cjs +0 -4
  130. package/src/utils/parser.ts +0 -199
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
1
- import { a as read, c as clean, o as readSync, r as getRelativePath, s as exists } from "./fs-BIPMUfpW.js";
1
+ import { a as read, c as clean, o as readSync, r as getRelativePath, s as exists, t as trimExtName } from "./fs-BIPMUfpW.js";
2
2
  import "./write-CxO1CDML.js";
3
- import { a as EventEmitter, n as createLogger } from "./logger-CsQ2EGpR.js";
4
- import { a as transformReservedWord, l as trim } from "./transformers-5BubQvcu.js";
5
- import { b as Queue, c as getDefaultBanner, f as setUniqueName, n as getSource, t as FileManager, u as URLPath, y as pLimit$1 } from "./FileManager-zlhCXf6A.js";
3
+ import { a as EventEmitter, n as createLogger } from "./logger-CDxSrFkR.js";
4
+ import { h as trim, v as transformReservedWord } from "./transformers-DzHGqYO2.js";
5
+ import { r as setUniqueName, t as URLPath } from "./URLPath-BYceu_vY.js";
6
+ import "./casing-BSeq_teY.js";
6
7
  import mod from "node:module";
7
- import path, { join, resolve } from "node:path";
8
+ import path, { extname, join, relative, resolve } from "node:path";
8
9
  import pc from "picocolors";
9
10
  import { isDeepEqual } from "remeda";
10
11
  import g$1 from "node:process";
12
+ import { FileManager } from "@kubb/fabric-core";
11
13
  import os from "node:os";
12
14
  import { fileURLToPath, pathToFileURL } from "node:url";
13
15
  import fs, { promises } from "node:fs";
@@ -52,6 +54,128 @@ function isInputPath(result) {
52
54
  return !!result && "path" in result?.input;
53
55
  }
54
56
 
57
+ //#endregion
58
+ //#region src/errors.ts
59
+ var ValidationPluginError = class extends Error {};
60
+
61
+ //#endregion
62
+ //#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
63
+ var Node = class {
64
+ value;
65
+ next;
66
+ constructor(value) {
67
+ this.value = value;
68
+ }
69
+ };
70
+ var Queue = class {
71
+ #head;
72
+ #tail;
73
+ #size;
74
+ constructor() {
75
+ this.clear();
76
+ }
77
+ enqueue(value) {
78
+ const node = new Node(value);
79
+ if (this.#head) {
80
+ this.#tail.next = node;
81
+ this.#tail = node;
82
+ } else {
83
+ this.#head = node;
84
+ this.#tail = node;
85
+ }
86
+ this.#size++;
87
+ }
88
+ dequeue() {
89
+ const current = this.#head;
90
+ if (!current) return;
91
+ this.#head = this.#head.next;
92
+ this.#size--;
93
+ return current.value;
94
+ }
95
+ peek() {
96
+ if (!this.#head) return;
97
+ return this.#head.value;
98
+ }
99
+ clear() {
100
+ this.#head = void 0;
101
+ this.#tail = void 0;
102
+ this.#size = 0;
103
+ }
104
+ get size() {
105
+ return this.#size;
106
+ }
107
+ *[Symbol.iterator]() {
108
+ let current = this.#head;
109
+ while (current) {
110
+ yield current.value;
111
+ current = current.next;
112
+ }
113
+ }
114
+ *drain() {
115
+ while (this.#head) yield this.dequeue();
116
+ }
117
+ };
118
+
119
+ //#endregion
120
+ //#region ../../node_modules/.pnpm/p-limit@7.2.0/node_modules/p-limit/index.js
121
+ function pLimit$1(concurrency) {
122
+ validateConcurrency(concurrency);
123
+ const queue = new Queue();
124
+ let activeCount = 0;
125
+ const resumeNext = () => {
126
+ if (activeCount < concurrency && queue.size > 0) {
127
+ activeCount++;
128
+ queue.dequeue()();
129
+ }
130
+ };
131
+ const next = () => {
132
+ activeCount--;
133
+ resumeNext();
134
+ };
135
+ const run = async (function_, resolve$1, arguments_) => {
136
+ const result = (async () => function_(...arguments_))();
137
+ resolve$1(result);
138
+ try {
139
+ await result;
140
+ } catch {}
141
+ next();
142
+ };
143
+ const enqueue = (function_, resolve$1, arguments_) => {
144
+ new Promise((internalResolve) => {
145
+ queue.enqueue(internalResolve);
146
+ }).then(run.bind(void 0, function_, resolve$1, arguments_));
147
+ if (activeCount < concurrency) resumeNext();
148
+ };
149
+ const generator = (function_, ...arguments_) => new Promise((resolve$1) => {
150
+ enqueue(function_, resolve$1, arguments_);
151
+ });
152
+ Object.defineProperties(generator, {
153
+ activeCount: { get: () => activeCount },
154
+ pendingCount: { get: () => queue.size },
155
+ clearQueue: { value() {
156
+ queue.clear();
157
+ } },
158
+ concurrency: {
159
+ get: () => concurrency,
160
+ set(newConcurrency) {
161
+ validateConcurrency(newConcurrency);
162
+ concurrency = newConcurrency;
163
+ queueMicrotask(() => {
164
+ while (activeCount < concurrency && queue.size > 0) resumeNext();
165
+ });
166
+ }
167
+ },
168
+ map: { async value(iterable, function_) {
169
+ const promises$1 = Array.from(iterable, (value, index) => this(function_, value, index));
170
+ return Promise.all(promises$1);
171
+ } }
172
+ });
173
+ return generator;
174
+ }
175
+ function validateConcurrency(concurrency) {
176
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
177
+ }
178
+
55
179
  //#endregion
56
180
  //#region src/utils/executeStrategies.ts
57
181
  /**
@@ -105,10 +229,6 @@ function isPromiseRejectedResult(result) {
105
229
  return result.status === "rejected";
106
230
  }
107
231
 
108
- //#endregion
109
- //#region src/errors.ts
110
- var ValidationPluginError = class extends Error {};
111
-
112
232
  //#endregion
113
233
  //#region src/plugin.ts
114
234
  function createPlugin(factory) {
@@ -159,6 +279,9 @@ const pluginCore = createPlugin((options) => {
159
279
  //#region src/PluginManager.ts
160
280
  var PluginManager = class {
161
281
  plugins = /* @__PURE__ */ new Set();
282
+ /**
283
+ * @deprecated do not use from pluginManager
284
+ */
162
285
  fileManager;
163
286
  events = new EventEmitter();
164
287
  config;
@@ -664,7 +787,7 @@ async function safeBuild(options) {
664
787
  const rootFile = {
665
788
  path: rootPath,
666
789
  baseName: "index.ts",
667
- exports: (await pluginManager.fileManager.getFiles()).filter((file) => {
790
+ exports: (await pluginManager.fileManager.files).filter((file) => {
668
791
  return file.sources.some((source) => source.isIndexable);
669
792
  }).flatMap((file) => {
670
793
  const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
@@ -687,11 +810,27 @@ async function safeBuild(options) {
687
810
  };
688
811
  await pluginManager.fileManager.add(rootFile);
689
812
  }
690
- const files = await pluginManager.fileManager.processFiles({
691
- root: config.root,
813
+ pluginManager.fileManager.processor.on("start", ({ files: files$1 }) => {
814
+ pluginManager.logger.emit("progress_start", {
815
+ id: "files",
816
+ size: files$1.length,
817
+ message: "Writing files ..."
818
+ });
819
+ });
820
+ pluginManager.fileManager.processor.on("file:start", ({ file }) => {
821
+ const message = file ? `Writing ${relative(config.root, file.path)}` : "";
822
+ pluginManager.logger.emit("progressed", {
823
+ id: "files",
824
+ message
825
+ });
826
+ });
827
+ pluginManager.fileManager.processor.on("file:finish", () => {});
828
+ pluginManager.fileManager.processor.on("finish", () => {
829
+ pluginManager.logger.emit("progress_stop", { id: "files" });
830
+ });
831
+ const files = await pluginManager.fileManager.write({
692
832
  extension: config.output.extension,
693
- dryRun: !config.output.write,
694
- logger: pluginManager.logger
833
+ dryRun: !config.output.write
695
834
  });
696
835
  await pluginManager.hookParallel({
697
836
  hookName: "buildEnd",
@@ -711,6 +850,223 @@ async function safeBuild(options) {
711
850
  }
712
851
  }
713
852
 
853
+ //#endregion
854
+ //#region src/utils/TreeNode.ts
855
+ var TreeNode = class TreeNode {
856
+ data;
857
+ parent;
858
+ children = [];
859
+ #cachedLeaves = void 0;
860
+ constructor(data, parent) {
861
+ this.data = data;
862
+ this.parent = parent;
863
+ return this;
864
+ }
865
+ addChild(data) {
866
+ const child = new TreeNode(data, this);
867
+ if (!this.children) this.children = [];
868
+ this.children.push(child);
869
+ return child;
870
+ }
871
+ get root() {
872
+ if (!this.parent) return this;
873
+ return this.parent.root;
874
+ }
875
+ get leaves() {
876
+ if (!this.children || this.children.length === 0) return [this];
877
+ if (this.#cachedLeaves) return this.#cachedLeaves;
878
+ const leaves = [];
879
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
880
+ this.#cachedLeaves = leaves;
881
+ return leaves;
882
+ }
883
+ forEach(callback) {
884
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
885
+ callback(this);
886
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
887
+ return this;
888
+ }
889
+ findDeep(predicate) {
890
+ if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
891
+ return this.leaves.find(predicate);
892
+ }
893
+ forEachDeep(callback) {
894
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
895
+ this.leaves.forEach(callback);
896
+ }
897
+ filterDeep(callback) {
898
+ if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
899
+ return this.leaves.filter(callback);
900
+ }
901
+ mapDeep(callback) {
902
+ if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
903
+ return this.leaves.map(callback);
904
+ }
905
+ static build(files, root) {
906
+ try {
907
+ const filteredTree = buildDirectoryTree(files, root);
908
+ if (!filteredTree) return null;
909
+ const treeNode = new TreeNode({
910
+ name: filteredTree.name,
911
+ path: filteredTree.path,
912
+ file: filteredTree.file,
913
+ type: getMode(filteredTree.path)
914
+ });
915
+ const recurse = (node, item) => {
916
+ const subNode = node.addChild({
917
+ name: item.name,
918
+ path: item.path,
919
+ file: item.file,
920
+ type: getMode(item.path)
921
+ });
922
+ if (item.children?.length) item.children?.forEach((child) => {
923
+ recurse(subNode, child);
924
+ });
925
+ };
926
+ filteredTree.children?.forEach((child) => {
927
+ recurse(treeNode, child);
928
+ });
929
+ return treeNode;
930
+ } catch (e) {
931
+ throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
932
+ }
933
+ }
934
+ };
935
+ const normalizePath = (p) => p.replace(/\\/g, "/");
936
+ function buildDirectoryTree(files, rootFolder = "") {
937
+ const normalizedRootFolder = normalizePath(rootFolder);
938
+ const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
939
+ const filteredFiles = files.filter((file) => {
940
+ const normalizedFilePath = normalizePath(file.path);
941
+ return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
942
+ });
943
+ if (filteredFiles.length === 0) return null;
944
+ const root = {
945
+ name: rootFolder || "",
946
+ path: rootFolder || "",
947
+ children: []
948
+ };
949
+ filteredFiles.forEach((file) => {
950
+ const parts = file.path.slice(rootFolder.length).split("/");
951
+ let currentLevel = root.children;
952
+ let currentPath = rootFolder;
953
+ parts.forEach((part, index) => {
954
+ if (index !== 0) currentPath += `/${part}`;
955
+ else currentPath += `${part}`;
956
+ let existingNode = currentLevel.find((node) => node.name === part);
957
+ if (!existingNode) {
958
+ if (index === parts.length - 1) existingNode = {
959
+ name: part,
960
+ file,
961
+ path: currentPath
962
+ };
963
+ else existingNode = {
964
+ name: part,
965
+ path: currentPath,
966
+ children: []
967
+ };
968
+ currentLevel.push(existingNode);
969
+ }
970
+ if (!existingNode.file) currentLevel = existingNode.children;
971
+ });
972
+ });
973
+ return root;
974
+ }
975
+
976
+ //#endregion
977
+ //#region src/BarrelManager.ts
978
+ var BarrelManager = class {
979
+ #options;
980
+ constructor(options = {}) {
981
+ this.#options = options;
982
+ return this;
983
+ }
984
+ getFiles({ files: generatedFiles, root }) {
985
+ const { logger } = this.#options;
986
+ const cachedFiles = /* @__PURE__ */ new Map();
987
+ TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
988
+ if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
989
+ const barrelFile = {
990
+ path: join(treeNode.parent?.data.path, "index.ts"),
991
+ baseName: "index.ts",
992
+ exports: [],
993
+ sources: []
994
+ };
995
+ const previousBarrelFile = cachedFiles.get(barrelFile.path);
996
+ treeNode.leaves.forEach((item) => {
997
+ if (!item.data.name) return;
998
+ const sources = item.data.file?.sources || [];
999
+ if (!sources.some((source) => source.isIndexable)) logger?.emit("warning", `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, void 0, 2)}`);
1000
+ sources.forEach((source) => {
1001
+ if (!item.data.file?.path || !source.isIndexable || !source.name) return;
1002
+ if (previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly)) return;
1003
+ if (!barrelFile.exports) barrelFile.exports = [];
1004
+ if (!!treeNode.parent?.data.path?.split?.("/")?.length) barrelFile.exports.push({
1005
+ name: [source.name],
1006
+ path: getRelativePath(treeNode.parent?.data.path, item.data.path),
1007
+ isTypeOnly: source.isTypeOnly
1008
+ });
1009
+ else barrelFile.exports.push({
1010
+ name: [source.name],
1011
+ path: `./${item.data.file.baseName}`,
1012
+ isTypeOnly: source.isTypeOnly
1013
+ });
1014
+ barrelFile.sources.push({
1015
+ name: source.name,
1016
+ isTypeOnly: source.isTypeOnly,
1017
+ value: "",
1018
+ isExportable: false,
1019
+ isIndexable: false
1020
+ });
1021
+ });
1022
+ });
1023
+ if (previousBarrelFile) {
1024
+ previousBarrelFile.sources.push(...barrelFile.sources);
1025
+ previousBarrelFile.exports?.push(...barrelFile.exports || []);
1026
+ } else cachedFiles.set(barrelFile.path, barrelFile);
1027
+ });
1028
+ return [...cachedFiles.values()];
1029
+ }
1030
+ };
1031
+
1032
+ //#endregion
1033
+ //#region src/FileManager.ts
1034
+ function getMode(path$1) {
1035
+ if (!path$1) return "split";
1036
+ return extname(path$1) ? "single" : "split";
1037
+ }
1038
+ async function getBarrelFiles(files, { type, meta = {}, root, output, logger }) {
1039
+ if (!type || type === "propagate") return [];
1040
+ const barrelManager = new BarrelManager({ logger });
1041
+ const pathToBuildFrom = join(root, output.path);
1042
+ if (trimExtName(pathToBuildFrom).endsWith("index")) {
1043
+ logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
1044
+ return [];
1045
+ }
1046
+ const barrelFiles = barrelManager.getFiles({
1047
+ files,
1048
+ root: pathToBuildFrom,
1049
+ meta
1050
+ });
1051
+ if (type === "all") return barrelFiles.map((file) => {
1052
+ return {
1053
+ ...file,
1054
+ exports: file.exports?.map((exportItem) => {
1055
+ return {
1056
+ ...exportItem,
1057
+ name: void 0
1058
+ };
1059
+ })
1060
+ };
1061
+ });
1062
+ return barrelFiles.map((indexFile) => {
1063
+ return {
1064
+ ...indexFile,
1065
+ meta
1066
+ };
1067
+ });
1068
+ }
1069
+
714
1070
  //#endregion
715
1071
  //#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
716
1072
  function pLimit(concurrency) {
@@ -977,5 +1333,5 @@ var PackageManager = class PackageManager {
977
1333
  };
978
1334
 
979
1335
  //#endregion
980
- export { BaseGenerator, FileManager, PackageManager, PluginManager, PromiseManager, build, build as default, createPlugin, defineConfig, getDefaultBanner, getSource, isInputPath, safeBuild, setup };
1336
+ export { BaseGenerator, PackageManager, PluginManager, PromiseManager, build, build as default, createPlugin, defineConfig, getBarrelFiles, getMode, isInputPath, safeBuild, setup };
981
1337
  //# sourceMappingURL=index.js.map