@kubb/core 4.2.0 → 4.2.2

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
@@ -141,5 +141,5 @@ type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
141
141
  //#region src/fs/index.d.ts
142
142
  declare function trimExtName(text: string): string;
143
143
  //#endregion
144
- export { read as _, File as a, clean as b, OptionalPath as c, ResolvedFile as d, ResolvedImport as f, unlink as g, getRelativePath as h, Extname as i, Path as l, write as m, BaseName as n, Import as o, types_d_exports as p, Export as r, Mode as s, trimExtName as t, ResolvedExport as u, readSync as v, exists as y };
145
- //# sourceMappingURL=index-BY_kka8d.d.ts.map
144
+ export { Mode as a, types_d_exports as c, unlink as d, read as f, clean as h, File as i, write as l, exists as m, BaseName as n, OptionalPath as o, readSync as p, Extname as r, ResolvedFile as s, trimExtName as t, getRelativePath as u };
145
+ //# sourceMappingURL=index-BTe91LHd.d.ts.map
@@ -140,5 +140,5 @@ type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
140
140
  //#region src/fs/index.d.ts
141
141
  declare function trimExtName(text: string): string;
142
142
  //#endregion
143
- export { read as _, File as a, clean as b, OptionalPath as c, ResolvedFile as d, ResolvedImport as f, unlink as g, getRelativePath as h, Extname as i, Path as l, write as m, BaseName as n, Import as o, types_d_exports as p, Export as r, Mode as s, trimExtName as t, ResolvedExport as u, readSync as v, exists as y };
144
- //# sourceMappingURL=index-Iq8NJRgc.d.cts.map
143
+ export { Mode as a, types_d_exports as c, unlink as d, read as f, clean as h, File as i, write as l, exists as m, BaseName as n, OptionalPath as o, readSync as p, Extname as r, ResolvedFile as s, trimExtName as t, getRelativePath as u };
144
+ //# sourceMappingURL=index-BmQIxvw0.d.cts.map
package/dist/index.cjs CHANGED
@@ -2,9 +2,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_chunk = require('./chunk-CZg_9w7l.cjs');
3
3
  const require_fs = require('./fs-RSVoUw3S.cjs');
4
4
  require('./write-BJfM7G1_.cjs');
5
- const require_logger = require('./logger-S_t55o9n.cjs');
6
- const require_transformers = require('./transformers-BIx7CVmw.cjs');
7
- const require_FileManager = require('./FileManager-DlkY9W5A.cjs');
5
+ const require_logger = require('./logger-BXL0YCrv.cjs');
6
+ const require_transformers = require('./transformers-BH0KLJJP.cjs');
7
+ const require_URLPath = require('./URLPath-8WVzHBnA.cjs');
8
+ require('./casing-CP-9GGdK.cjs');
8
9
  let node_path = require("node:path");
9
10
  node_path = require_chunk.__toESM(node_path);
10
11
  let picocolors = require("picocolors");
@@ -13,6 +14,8 @@ let remeda = require("remeda");
13
14
  remeda = require_chunk.__toESM(remeda);
14
15
  let node_process = require("node:process");
15
16
  node_process = require_chunk.__toESM(node_process);
17
+ let __kubb_fabric_core = require("@kubb/fabric-core");
18
+ __kubb_fabric_core = require_chunk.__toESM(__kubb_fabric_core);
16
19
  let node_module = require("node:module");
17
20
  node_module = require_chunk.__toESM(node_module);
18
21
  let node_os = require("node:os");
@@ -63,6 +66,128 @@ function isInputPath(result) {
63
66
  return !!result && "path" in result?.input;
64
67
  }
65
68
 
69
+ //#endregion
70
+ //#region src/errors.ts
71
+ var ValidationPluginError = class extends Error {};
72
+
73
+ //#endregion
74
+ //#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
75
+ var Node = class {
76
+ value;
77
+ next;
78
+ constructor(value) {
79
+ this.value = value;
80
+ }
81
+ };
82
+ var Queue = class {
83
+ #head;
84
+ #tail;
85
+ #size;
86
+ constructor() {
87
+ this.clear();
88
+ }
89
+ enqueue(value) {
90
+ const node = new Node(value);
91
+ if (this.#head) {
92
+ this.#tail.next = node;
93
+ this.#tail = node;
94
+ } else {
95
+ this.#head = node;
96
+ this.#tail = node;
97
+ }
98
+ this.#size++;
99
+ }
100
+ dequeue() {
101
+ const current = this.#head;
102
+ if (!current) return;
103
+ this.#head = this.#head.next;
104
+ this.#size--;
105
+ return current.value;
106
+ }
107
+ peek() {
108
+ if (!this.#head) return;
109
+ return this.#head.value;
110
+ }
111
+ clear() {
112
+ this.#head = void 0;
113
+ this.#tail = void 0;
114
+ this.#size = 0;
115
+ }
116
+ get size() {
117
+ return this.#size;
118
+ }
119
+ *[Symbol.iterator]() {
120
+ let current = this.#head;
121
+ while (current) {
122
+ yield current.value;
123
+ current = current.next;
124
+ }
125
+ }
126
+ *drain() {
127
+ while (this.#head) yield this.dequeue();
128
+ }
129
+ };
130
+
131
+ //#endregion
132
+ //#region ../../node_modules/.pnpm/p-limit@7.2.0/node_modules/p-limit/index.js
133
+ function pLimit$1(concurrency) {
134
+ validateConcurrency(concurrency);
135
+ const queue = new Queue();
136
+ let activeCount = 0;
137
+ const resumeNext = () => {
138
+ if (activeCount < concurrency && queue.size > 0) {
139
+ activeCount++;
140
+ queue.dequeue()();
141
+ }
142
+ };
143
+ const next = () => {
144
+ activeCount--;
145
+ resumeNext();
146
+ };
147
+ const run = async (function_, resolve$1, arguments_) => {
148
+ const result = (async () => function_(...arguments_))();
149
+ resolve$1(result);
150
+ try {
151
+ await result;
152
+ } catch {}
153
+ next();
154
+ };
155
+ const enqueue = (function_, resolve$1, arguments_) => {
156
+ new Promise((internalResolve) => {
157
+ queue.enqueue(internalResolve);
158
+ }).then(run.bind(void 0, function_, resolve$1, arguments_));
159
+ if (activeCount < concurrency) resumeNext();
160
+ };
161
+ const generator = (function_, ...arguments_) => new Promise((resolve$1) => {
162
+ enqueue(function_, resolve$1, arguments_);
163
+ });
164
+ Object.defineProperties(generator, {
165
+ activeCount: { get: () => activeCount },
166
+ pendingCount: { get: () => queue.size },
167
+ clearQueue: { value() {
168
+ queue.clear();
169
+ } },
170
+ concurrency: {
171
+ get: () => concurrency,
172
+ set(newConcurrency) {
173
+ validateConcurrency(newConcurrency);
174
+ concurrency = newConcurrency;
175
+ queueMicrotask(() => {
176
+ while (activeCount < concurrency && queue.size > 0) resumeNext();
177
+ });
178
+ }
179
+ },
180
+ map: { async value(iterable, function_) {
181
+ const promises = Array.from(iterable, (value, index) => this(function_, value, index));
182
+ return Promise.all(promises);
183
+ } }
184
+ });
185
+ return generator;
186
+ }
187
+ function validateConcurrency(concurrency) {
188
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
189
+ }
190
+
66
191
  //#endregion
67
192
  //#region src/utils/executeStrategies.ts
68
193
  /**
@@ -92,7 +217,7 @@ function hookFirst(promises, nullCheck = (state) => state !== null) {
92
217
  * Runs an array of promise functions with optional concurrency limit.
93
218
  */
94
219
  function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
95
- const limit = require_FileManager.pLimit(concurrency);
220
+ const limit = pLimit$1(concurrency);
96
221
  const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
97
222
  return Promise.allSettled(tasks);
98
223
  }
@@ -116,10 +241,6 @@ function isPromiseRejectedResult(result) {
116
241
  return result.status === "rejected";
117
242
  }
118
243
 
119
- //#endregion
120
- //#region src/errors.ts
121
- var ValidationPluginError = class extends Error {};
122
-
123
244
  //#endregion
124
245
  //#region src/plugin.ts
125
246
  function createPlugin(factory) {
@@ -170,6 +291,9 @@ const pluginCore = createPlugin((options) => {
170
291
  //#region src/PluginManager.ts
171
292
  var PluginManager = class {
172
293
  plugins = /* @__PURE__ */ new Set();
294
+ /**
295
+ * @deprecated do not use from pluginManager
296
+ */
173
297
  fileManager;
174
298
  events = new require_logger.EventEmitter();
175
299
  config;
@@ -183,7 +307,7 @@ var PluginManager = class {
183
307
  this.config = config;
184
308
  this.options = options;
185
309
  this.logger = options.logger;
186
- this.fileManager = new require_FileManager.FileManager();
310
+ this.fileManager = new __kubb_fabric_core.FileManager();
187
311
  this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
188
312
  const core = pluginCore({
189
313
  config,
@@ -201,8 +325,8 @@ var PluginManager = class {
201
325
  });
202
326
  return this;
203
327
  }
204
- getFile({ name, mode, extname, pluginKey, options }) {
205
- const baseName = `${name}${extname}`;
328
+ getFile({ name, mode, extname: extname$1, pluginKey, options }) {
329
+ const baseName = `${name}${extname$1}`;
206
330
  const path$3 = this.resolvePath({
207
331
  baseName,
208
332
  mode,
@@ -576,7 +700,7 @@ var PluginManager = class {
576
700
  }
577
701
  #parse(plugin, pluginManager, context) {
578
702
  const usedPluginNames = pluginManager.#usedPluginNames;
579
- require_FileManager.setUniqueName(plugin.name, usedPluginNames);
703
+ require_URLPath.setUniqueName(plugin.name, usedPluginNames);
580
704
  const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
581
705
  if (plugin.context && typeof plugin.context === "function") return {
582
706
  ...plugin,
@@ -615,7 +739,7 @@ async function setup(options) {
615
739
  const { config: userConfig, logger = require_logger.createLogger() } = options;
616
740
  if (Array.isArray(userConfig.input)) console.warn(picocolors.default.yellow("This feature is still under development — use with caution"));
617
741
  try {
618
- if (isInputPath(userConfig) && !new require_FileManager.URLPath(userConfig.input.path).isURL) await require_fs.exists(userConfig.input.path);
742
+ if (isInputPath(userConfig) && !new require_URLPath.URLPath(userConfig.input.path).isURL) await require_fs.exists(userConfig.input.path);
619
743
  } catch (e) {
620
744
  if (isInputPath(userConfig)) throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: e });
621
745
  }
@@ -675,7 +799,7 @@ async function safeBuild(options) {
675
799
  const rootFile = {
676
800
  path: rootPath,
677
801
  baseName: "index.ts",
678
- exports: (await pluginManager.fileManager.getFiles()).filter((file) => {
802
+ exports: (await pluginManager.fileManager.files).filter((file) => {
679
803
  return file.sources.some((source) => source.isIndexable);
680
804
  }).flatMap((file) => {
681
805
  const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
@@ -698,11 +822,27 @@ async function safeBuild(options) {
698
822
  };
699
823
  await pluginManager.fileManager.add(rootFile);
700
824
  }
701
- const files = await pluginManager.fileManager.processFiles({
702
- root: config.root,
825
+ pluginManager.fileManager.processor.on("start", ({ files: files$1 }) => {
826
+ pluginManager.logger.emit("progress_start", {
827
+ id: "files",
828
+ size: files$1.length,
829
+ message: "Writing files ..."
830
+ });
831
+ });
832
+ pluginManager.fileManager.processor.on("file:start", ({ file }) => {
833
+ const message = file ? `Writing ${(0, node_path.relative)(config.root, file.path)}` : "";
834
+ pluginManager.logger.emit("progressed", {
835
+ id: "files",
836
+ message
837
+ });
838
+ });
839
+ pluginManager.fileManager.processor.on("file:finish", () => {});
840
+ pluginManager.fileManager.processor.on("finish", () => {
841
+ pluginManager.logger.emit("progress_stop", { id: "files" });
842
+ });
843
+ const files = await pluginManager.fileManager.write({
703
844
  extension: config.output.extension,
704
- dryRun: !config.output.write,
705
- logger: pluginManager.logger
845
+ dryRun: !config.output.write
706
846
  });
707
847
  await pluginManager.hookParallel({
708
848
  hookName: "buildEnd",
@@ -722,11 +862,228 @@ async function safeBuild(options) {
722
862
  }
723
863
  }
724
864
 
865
+ //#endregion
866
+ //#region src/utils/TreeNode.ts
867
+ var TreeNode = class TreeNode {
868
+ data;
869
+ parent;
870
+ children = [];
871
+ #cachedLeaves = void 0;
872
+ constructor(data, parent) {
873
+ this.data = data;
874
+ this.parent = parent;
875
+ return this;
876
+ }
877
+ addChild(data) {
878
+ const child = new TreeNode(data, this);
879
+ if (!this.children) this.children = [];
880
+ this.children.push(child);
881
+ return child;
882
+ }
883
+ get root() {
884
+ if (!this.parent) return this;
885
+ return this.parent.root;
886
+ }
887
+ get leaves() {
888
+ if (!this.children || this.children.length === 0) return [this];
889
+ if (this.#cachedLeaves) return this.#cachedLeaves;
890
+ const leaves = [];
891
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
892
+ this.#cachedLeaves = leaves;
893
+ return leaves;
894
+ }
895
+ forEach(callback) {
896
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
897
+ callback(this);
898
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
899
+ return this;
900
+ }
901
+ findDeep(predicate) {
902
+ if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
903
+ return this.leaves.find(predicate);
904
+ }
905
+ forEachDeep(callback) {
906
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
907
+ this.leaves.forEach(callback);
908
+ }
909
+ filterDeep(callback) {
910
+ if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
911
+ return this.leaves.filter(callback);
912
+ }
913
+ mapDeep(callback) {
914
+ if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
915
+ return this.leaves.map(callback);
916
+ }
917
+ static build(files, root) {
918
+ try {
919
+ const filteredTree = buildDirectoryTree(files, root);
920
+ if (!filteredTree) return null;
921
+ const treeNode = new TreeNode({
922
+ name: filteredTree.name,
923
+ path: filteredTree.path,
924
+ file: filteredTree.file,
925
+ type: getMode(filteredTree.path)
926
+ });
927
+ const recurse = (node, item) => {
928
+ const subNode = node.addChild({
929
+ name: item.name,
930
+ path: item.path,
931
+ file: item.file,
932
+ type: getMode(item.path)
933
+ });
934
+ if (item.children?.length) item.children?.forEach((child) => {
935
+ recurse(subNode, child);
936
+ });
937
+ };
938
+ filteredTree.children?.forEach((child) => {
939
+ recurse(treeNode, child);
940
+ });
941
+ return treeNode;
942
+ } catch (e) {
943
+ throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
944
+ }
945
+ }
946
+ };
947
+ const normalizePath = (p) => p.replace(/\\/g, "/");
948
+ function buildDirectoryTree(files, rootFolder = "") {
949
+ const normalizedRootFolder = normalizePath(rootFolder);
950
+ const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
951
+ const filteredFiles = files.filter((file) => {
952
+ const normalizedFilePath = normalizePath(file.path);
953
+ return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
954
+ });
955
+ if (filteredFiles.length === 0) return null;
956
+ const root = {
957
+ name: rootFolder || "",
958
+ path: rootFolder || "",
959
+ children: []
960
+ };
961
+ filteredFiles.forEach((file) => {
962
+ const parts = file.path.slice(rootFolder.length).split("/");
963
+ let currentLevel = root.children;
964
+ let currentPath = rootFolder;
965
+ parts.forEach((part, index) => {
966
+ if (index !== 0) currentPath += `/${part}`;
967
+ else currentPath += `${part}`;
968
+ let existingNode = currentLevel.find((node) => node.name === part);
969
+ if (!existingNode) {
970
+ if (index === parts.length - 1) existingNode = {
971
+ name: part,
972
+ file,
973
+ path: currentPath
974
+ };
975
+ else existingNode = {
976
+ name: part,
977
+ path: currentPath,
978
+ children: []
979
+ };
980
+ currentLevel.push(existingNode);
981
+ }
982
+ if (!existingNode.file) currentLevel = existingNode.children;
983
+ });
984
+ });
985
+ return root;
986
+ }
987
+
988
+ //#endregion
989
+ //#region src/BarrelManager.ts
990
+ var BarrelManager = class {
991
+ #options;
992
+ constructor(options = {}) {
993
+ this.#options = options;
994
+ return this;
995
+ }
996
+ getFiles({ files: generatedFiles, root }) {
997
+ const { logger } = this.#options;
998
+ const cachedFiles = /* @__PURE__ */ new Map();
999
+ TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
1000
+ if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
1001
+ const barrelFile = {
1002
+ path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
1003
+ baseName: "index.ts",
1004
+ exports: [],
1005
+ sources: []
1006
+ };
1007
+ const previousBarrelFile = cachedFiles.get(barrelFile.path);
1008
+ treeNode.leaves.forEach((item) => {
1009
+ if (!item.data.name) return;
1010
+ const sources = item.data.file?.sources || [];
1011
+ 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)}`);
1012
+ sources.forEach((source) => {
1013
+ if (!item.data.file?.path || !source.isIndexable || !source.name) return;
1014
+ if (previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly)) return;
1015
+ if (!barrelFile.exports) barrelFile.exports = [];
1016
+ if (!!treeNode.parent?.data.path?.split?.("/")?.length) barrelFile.exports.push({
1017
+ name: [source.name],
1018
+ path: require_fs.getRelativePath(treeNode.parent?.data.path, item.data.path),
1019
+ isTypeOnly: source.isTypeOnly
1020
+ });
1021
+ else barrelFile.exports.push({
1022
+ name: [source.name],
1023
+ path: `./${item.data.file.baseName}`,
1024
+ isTypeOnly: source.isTypeOnly
1025
+ });
1026
+ barrelFile.sources.push({
1027
+ name: source.name,
1028
+ isTypeOnly: source.isTypeOnly,
1029
+ value: "",
1030
+ isExportable: false,
1031
+ isIndexable: false
1032
+ });
1033
+ });
1034
+ });
1035
+ if (previousBarrelFile) {
1036
+ previousBarrelFile.sources.push(...barrelFile.sources);
1037
+ previousBarrelFile.exports?.push(...barrelFile.exports || []);
1038
+ } else cachedFiles.set(barrelFile.path, barrelFile);
1039
+ });
1040
+ return [...cachedFiles.values()];
1041
+ }
1042
+ };
1043
+
1044
+ //#endregion
1045
+ //#region src/FileManager.ts
1046
+ function getMode(path$3) {
1047
+ if (!path$3) return "split";
1048
+ return (0, node_path.extname)(path$3) ? "single" : "split";
1049
+ }
1050
+ async function getBarrelFiles(files, { type, meta = {}, root, output, logger }) {
1051
+ if (!type || type === "propagate") return [];
1052
+ const barrelManager = new BarrelManager({ logger });
1053
+ const pathToBuildFrom = (0, node_path.join)(root, output.path);
1054
+ if (require_fs.trimExtName(pathToBuildFrom).endsWith("index")) {
1055
+ logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
1056
+ return [];
1057
+ }
1058
+ const barrelFiles = barrelManager.getFiles({
1059
+ files,
1060
+ root: pathToBuildFrom,
1061
+ meta
1062
+ });
1063
+ if (type === "all") return barrelFiles.map((file) => {
1064
+ return {
1065
+ ...file,
1066
+ exports: file.exports?.map((exportItem) => {
1067
+ return {
1068
+ ...exportItem,
1069
+ name: void 0
1070
+ };
1071
+ })
1072
+ };
1073
+ });
1074
+ return barrelFiles.map((indexFile) => {
1075
+ return {
1076
+ ...indexFile,
1077
+ meta
1078
+ };
1079
+ });
1080
+ }
1081
+
725
1082
  //#endregion
726
1083
  //#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
727
1084
  function pLimit(concurrency) {
728
1085
  if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
729
- const queue = new require_FileManager.Queue();
1086
+ const queue = new Queue();
730
1087
  let activeCount = 0;
731
1088
  const next = () => {
732
1089
  activeCount--;
@@ -989,7 +1346,6 @@ var PackageManager = class PackageManager {
989
1346
 
990
1347
  //#endregion
991
1348
  exports.BaseGenerator = BaseGenerator;
992
- exports.FileManager = require_FileManager.FileManager;
993
1349
  exports.PackageManager = PackageManager;
994
1350
  exports.PluginManager = PluginManager;
995
1351
  exports.PromiseManager = PromiseManager;
@@ -997,8 +1353,8 @@ exports.build = build;
997
1353
  exports.createPlugin = createPlugin;
998
1354
  exports.default = build;
999
1355
  exports.defineConfig = defineConfig;
1000
- exports.getDefaultBanner = require_FileManager.getDefaultBanner;
1001
- exports.getSource = require_FileManager.getSource;
1356
+ exports.getBarrelFiles = getBarrelFiles;
1357
+ exports.getMode = getMode;
1002
1358
  exports.isInputPath = isInputPath;
1003
1359
  exports.safeBuild = safeBuild;
1004
1360
  exports.setup = setup;