@kubb/core 3.0.0-alpha.3 → 3.0.0-alpha.5

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 (41) hide show
  1. package/dist/{FileManager-BW--rO8q.d.ts → FileManager-jZpqETKU.d.cts} +15 -20
  2. package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-tzl0YsYE.d.ts} +15 -20
  3. package/dist/{chunk-SA2GZKXS.js → chunk-CEWT73XF.js} +110 -69
  4. package/dist/chunk-CEWT73XF.js.map +1 -0
  5. package/dist/{chunk-ADC5UNZ5.cjs → chunk-FWU62YO5.cjs} +319 -281
  6. package/dist/chunk-FWU62YO5.cjs.map +1 -0
  7. package/dist/{chunk-LM2YQC3T.cjs → chunk-RBP2ASUX.cjs} +38 -23
  8. package/dist/chunk-RBP2ASUX.cjs.map +1 -0
  9. package/dist/{chunk-3OXCZ5DJ.js → chunk-Z5CHJQJB.js} +29 -21
  10. package/dist/chunk-Z5CHJQJB.js.map +1 -0
  11. package/dist/index.cjs +43 -130
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +4 -15
  14. package/dist/index.d.ts +4 -15
  15. package/dist/index.js +25 -105
  16. package/dist/index.js.map +1 -1
  17. package/dist/{logger-DChjnJMn.d.cts → logger-BnWJh6Yq.d.cts} +17 -19
  18. package/dist/{logger-DChjnJMn.d.ts → logger-BnWJh6Yq.d.ts} +17 -19
  19. package/dist/logger.cjs +3 -4
  20. package/dist/logger.cjs.map +1 -1
  21. package/dist/logger.d.cts +2 -2
  22. package/dist/logger.d.ts +2 -2
  23. package/dist/logger.js +2 -3
  24. package/dist/mocks.cjs +3 -3
  25. package/dist/mocks.cjs.map +1 -1
  26. package/dist/mocks.d.cts +2 -4
  27. package/dist/mocks.d.ts +2 -4
  28. package/dist/mocks.js +4 -4
  29. package/dist/mocks.js.map +1 -1
  30. package/package.json +7 -8
  31. package/src/BarrelManager.ts +10 -1
  32. package/src/FileManager.ts +107 -63
  33. package/src/PluginManager.ts +6 -22
  34. package/src/build.ts +19 -101
  35. package/src/errors.ts +0 -11
  36. package/src/index.ts +0 -1
  37. package/src/logger.ts +43 -33
  38. package/dist/chunk-3OXCZ5DJ.js.map +0 -1
  39. package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
  40. package/dist/chunk-LM2YQC3T.cjs.map +0 -1
  41. package/dist/chunk-SA2GZKXS.js.map +0 -1
@@ -188,6 +188,219 @@ var require_eventemitter3 = _chunkXCPFG6DOcjs.__commonJS.call(void 0, {
188
188
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
189
189
  var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
190
190
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
191
+ var _remeda = require('remeda');
192
+ var _fs = require('@kubb/fs');
193
+
194
+ // src/BarrelManager.ts
195
+ _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
196
+ var _parserts = require('@kubb/parser-ts');
197
+
198
+
199
+ // src/utils/TreeNode.ts
200
+ _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
201
+ var _directorytree = require('directory-tree'); var _directorytree2 = _interopRequireDefault(_directorytree);
202
+ var TreeNode = class _TreeNode {
203
+ constructor(data, parent) {
204
+ this.children = [];
205
+ this.data = data;
206
+ this.parent = parent;
207
+ return this;
208
+ }
209
+ addChild(data) {
210
+ const child = new _TreeNode(data, this);
211
+ if (!this.children) {
212
+ this.children = [];
213
+ }
214
+ this.children.push(child);
215
+ return child;
216
+ }
217
+ find(data) {
218
+ if (!data) {
219
+ return null;
220
+ }
221
+ if (data === this.data) {
222
+ return this;
223
+ }
224
+ if (_optionalChain([this, 'access', _2 => _2.children, 'optionalAccess', _3 => _3.length])) {
225
+ for (let i = 0, { length } = this.children, target = null; i < length; i++) {
226
+ target = this.children[i].find(data);
227
+ if (target) {
228
+ return target;
229
+ }
230
+ }
231
+ }
232
+ return null;
233
+ }
234
+ get leaves() {
235
+ if (!this.children || this.children.length === 0) {
236
+ return [this];
237
+ }
238
+ const leaves = [];
239
+ if (this.children) {
240
+ for (let i = 0, { length } = this.children; i < length; i++) {
241
+ leaves.push.apply(leaves, this.children[i].leaves);
242
+ }
243
+ }
244
+ return leaves;
245
+ }
246
+ get root() {
247
+ if (!this.parent) {
248
+ return this;
249
+ }
250
+ return this.parent.root;
251
+ }
252
+ forEach(callback) {
253
+ if (typeof callback !== "function") {
254
+ throw new TypeError("forEach() callback must be a function");
255
+ }
256
+ callback(this);
257
+ if (this.children) {
258
+ for (let i = 0, { length } = this.children; i < length; i++) {
259
+ _optionalChain([this, 'access', _4 => _4.children, 'access', _5 => _5[i], 'optionalAccess', _6 => _6.forEach, 'call', _7 => _7(callback)]);
260
+ }
261
+ }
262
+ return this;
263
+ }
264
+ static build(path3, options = {}) {
265
+ try {
266
+ const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
267
+ const filteredTree = _directorytree2.default.call(void 0, path3, {
268
+ extensions: options.extensions,
269
+ exclude: [/node_modules/, ...exclude]
270
+ });
271
+ if (!filteredTree) {
272
+ return null;
273
+ }
274
+ const treeNode = new _TreeNode({
275
+ name: filteredTree.name,
276
+ path: filteredTree.path,
277
+ type: FileManager.getMode(filteredTree.path)
278
+ });
279
+ const recurse = (node, item) => {
280
+ const subNode = node.addChild({
281
+ name: item.name,
282
+ path: item.path,
283
+ type: FileManager.getMode(item.path)
284
+ });
285
+ if (_optionalChain([item, 'access', _8 => _8.children, 'optionalAccess', _9 => _9.length])) {
286
+ _optionalChain([item, 'access', _10 => _10.children, 'optionalAccess', _11 => _11.forEach, 'call', _12 => _12((child) => {
287
+ recurse(subNode, child);
288
+ })]);
289
+ }
290
+ };
291
+ _optionalChain([filteredTree, 'access', _13 => _13.children, 'optionalAccess', _14 => _14.forEach, 'call', _15 => _15((child) => recurse(treeNode, child))]);
292
+ return treeNode;
293
+ } catch (e) {
294
+ throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
295
+ }
296
+ }
297
+ };
298
+
299
+ // src/BarrelManager.ts
300
+ var _options;
301
+ var BarrelManager = class {
302
+ constructor(options = {}) {
303
+ _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _options);
304
+ _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _options, options);
305
+ return this;
306
+ }
307
+ /**
308
+ * Loop through the file and find all exports(with the help of the ts printer)
309
+ * Important: a real file is needed(cannot work from memory/FileManager)
310
+ */
311
+ getNamedExport(root, item) {
312
+ const exportedNames = _parserts.getExports.call(void 0, _path2.default.resolve(root, item.path));
313
+ if (!exportedNames) {
314
+ return [item];
315
+ }
316
+ const exports = exportedNames.reduce(
317
+ (prev, curr) => {
318
+ if (!_optionalChain([prev, 'access', _16 => _16[0], 'optionalAccess', _17 => _17.name]) || !_optionalChain([prev, 'access', _18 => _18[1], 'optionalAccess', _19 => _19.name])) {
319
+ return prev;
320
+ }
321
+ if (curr.isTypeOnly) {
322
+ prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
323
+ } else {
324
+ prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
325
+ }
326
+ return prev;
327
+ },
328
+ [
329
+ {
330
+ ...item,
331
+ name: [],
332
+ isTypeOnly: false
333
+ },
334
+ {
335
+ ...item,
336
+ name: [],
337
+ isTypeOnly: true
338
+ }
339
+ ]
340
+ );
341
+ return exports;
342
+ }
343
+ getNamedExports(root, exports) {
344
+ return _optionalChain([exports, 'optionalAccess', _20 => _20.flatMap, 'call', _21 => _21((item) => {
345
+ return this.getNamedExport(root, item);
346
+ })]);
347
+ }
348
+ getIndexes(root) {
349
+ const { treeNode = {}, isTypeOnly, extName } = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _options);
350
+ const tree = TreeNode.build(root, treeNode);
351
+ if (!tree) {
352
+ return null;
353
+ }
354
+ const fileReducer = (files, treeNode2) => {
355
+ if (!treeNode2.children) {
356
+ return [];
357
+ }
358
+ if (treeNode2.children.length > 1) {
359
+ const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
360
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
361
+ const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, file.data.name)}`;
362
+ if (importPath.endsWith("index") && file.data.type === "single") {
363
+ return void 0;
364
+ }
365
+ return {
366
+ path: extName ? `${importPath}${extName}` : importPath,
367
+ isTypeOnly
368
+ };
369
+ }).filter(Boolean);
370
+ files.push({
371
+ path: indexPath,
372
+ baseName: "index.ts",
373
+ source: "",
374
+ exports,
375
+ exportable: true
376
+ });
377
+ } else if (treeNode2.children.length === 1) {
378
+ const [treeNodeChild] = treeNode2.children;
379
+ const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
380
+ const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, treeNodeChild.data.name)}`;
381
+ const exports = [
382
+ {
383
+ path: extName ? `${importPath}${extName}` : importPath,
384
+ isTypeOnly
385
+ }
386
+ ];
387
+ files.push({
388
+ path: indexPath,
389
+ baseName: "index.ts",
390
+ source: "",
391
+ exports,
392
+ exportable: true
393
+ });
394
+ }
395
+ treeNode2.children.forEach((childItem) => {
396
+ fileReducer(files, childItem);
397
+ });
398
+ return files;
399
+ };
400
+ return fileReducer([], tree).reverse();
401
+ }
402
+ };
403
+ _options = new WeakMap();
191
404
 
192
405
  // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
193
406
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
@@ -326,7 +539,7 @@ var PriorityQueue = class {
326
539
  }
327
540
  dequeue() {
328
541
  const item = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).shift();
329
- return _optionalChain([item, 'optionalAccess', _2 => _2.run]);
542
+ return _optionalChain([item, 'optionalAccess', _22 => _22.run]);
330
543
  }
331
544
  filter(options) {
332
545
  return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run);
@@ -375,10 +588,10 @@ var PQueue = class extends import_index.default {
375
588
  ...options
376
589
  };
377
590
  if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
378
- throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${_nullishCoalesce(_optionalChain([options, 'access', _3 => _3.intervalCap, 'optionalAccess', _4 => _4.toString, 'call', _5 => _5()]), () => ( ""))}\` (${typeof options.intervalCap})`);
591
+ throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${_nullishCoalesce(_optionalChain([options, 'access', _23 => _23.intervalCap, 'optionalAccess', _24 => _24.toString, 'call', _25 => _25()]), () => ( ""))}\` (${typeof options.intervalCap})`);
379
592
  }
380
593
  if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
381
- throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${_nullishCoalesce(_optionalChain([options, 'access', _6 => _6.interval, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()]), () => ( ""))}\` (${typeof options.interval})`);
594
+ throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${_nullishCoalesce(_optionalChain([options, 'access', _26 => _26.interval, 'optionalAccess', _27 => _27.toString, 'call', _28 => _28()]), () => ( ""))}\` (${typeof options.interval})`);
382
595
  }
383
596
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _carryoverConcurrencyCount, options.carryoverConcurrencyCount);
384
597
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0);
@@ -412,7 +625,7 @@ var PQueue = class extends import_index.default {
412
625
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _pending)._++;
413
626
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _intervalCount)._++;
414
627
  try {
415
- _optionalChain([options, 'access', _9 => _9.signal, 'optionalAccess', _10 => _10.throwIfAborted, 'call', _11 => _11()]);
628
+ _optionalChain([options, 'access', _29 => _29.signal, 'optionalAccess', _30 => _30.throwIfAborted, 'call', _31 => _31()]);
416
629
  let operation = function_({ signal: options.signal });
417
630
  if (options.timeout) {
418
631
  operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
@@ -648,225 +861,11 @@ onEvent_fn = async function(event, filter) {
648
861
  };
649
862
 
650
863
  // src/FileManager.ts
651
- var _remeda = require('remeda');
652
- var _fs = require('@kubb/fs');
653
-
654
- // src/BarrelManager.ts
655
- _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
656
- var _parserts = require('@kubb/parser-ts');
657
-
658
-
659
- // src/utils/TreeNode.ts
660
- _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
661
- var _directorytree = require('directory-tree'); var _directorytree2 = _interopRequireDefault(_directorytree);
662
- var TreeNode = class _TreeNode {
663
- constructor(data, parent) {
664
- this.children = [];
665
- this.data = data;
666
- this.parent = parent;
667
- return this;
668
- }
669
- addChild(data) {
670
- const child = new _TreeNode(data, this);
671
- if (!this.children) {
672
- this.children = [];
673
- }
674
- this.children.push(child);
675
- return child;
676
- }
677
- find(data) {
678
- if (!data) {
679
- return null;
680
- }
681
- if (data === this.data) {
682
- return this;
683
- }
684
- if (_optionalChain([this, 'access', _12 => _12.children, 'optionalAccess', _13 => _13.length])) {
685
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
686
- target = this.children[i].find(data);
687
- if (target) {
688
- return target;
689
- }
690
- }
691
- }
692
- return null;
693
- }
694
- get leaves() {
695
- if (!this.children || this.children.length === 0) {
696
- return [this];
697
- }
698
- const leaves = [];
699
- if (this.children) {
700
- for (let i = 0, { length } = this.children; i < length; i++) {
701
- leaves.push.apply(leaves, this.children[i].leaves);
702
- }
703
- }
704
- return leaves;
705
- }
706
- get root() {
707
- if (!this.parent) {
708
- return this;
709
- }
710
- return this.parent.root;
711
- }
712
- forEach(callback) {
713
- if (typeof callback !== "function") {
714
- throw new TypeError("forEach() callback must be a function");
715
- }
716
- callback(this);
717
- if (this.children) {
718
- for (let i = 0, { length } = this.children; i < length; i++) {
719
- _optionalChain([this, 'access', _14 => _14.children, 'access', _15 => _15[i], 'optionalAccess', _16 => _16.forEach, 'call', _17 => _17(callback)]);
720
- }
721
- }
722
- return this;
723
- }
724
- static build(path2, options = {}) {
725
- try {
726
- const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
727
- const filteredTree = _directorytree2.default.call(void 0, path2, {
728
- extensions: options.extensions,
729
- exclude: [/node_modules/, ...exclude]
730
- });
731
- if (!filteredTree) {
732
- return null;
733
- }
734
- const treeNode = new _TreeNode({
735
- name: filteredTree.name,
736
- path: filteredTree.path,
737
- type: FileManager.getMode(filteredTree.path)
738
- });
739
- const recurse = (node, item) => {
740
- const subNode = node.addChild({
741
- name: item.name,
742
- path: item.path,
743
- type: FileManager.getMode(item.path)
744
- });
745
- if (_optionalChain([item, 'access', _18 => _18.children, 'optionalAccess', _19 => _19.length])) {
746
- _optionalChain([item, 'access', _20 => _20.children, 'optionalAccess', _21 => _21.forEach, 'call', _22 => _22((child) => {
747
- recurse(subNode, child);
748
- })]);
749
- }
750
- };
751
- _optionalChain([filteredTree, 'access', _23 => _23.children, 'optionalAccess', _24 => _24.forEach, 'call', _25 => _25((child) => recurse(treeNode, child))]);
752
- return treeNode;
753
- } catch (e) {
754
- throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
755
- }
756
- }
757
- };
758
-
759
- // src/BarrelManager.ts
760
- var _options;
761
- var BarrelManager = class {
762
- constructor(options = {}) {
763
- _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _options);
764
- _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _options, options);
765
- return this;
766
- }
767
- getNamedExport(root, item) {
768
- const exportedNames = _parserts.getExports.call(void 0, _path2.default.resolve(root, item.path));
769
- if (!exportedNames) {
770
- return [item];
771
- }
772
- return exportedNames.reduce(
773
- (prev, curr) => {
774
- if (!_optionalChain([prev, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.name]) || !_optionalChain([prev, 'access', _28 => _28[1], 'optionalAccess', _29 => _29.name])) {
775
- return prev;
776
- }
777
- if (curr.isTypeOnly) {
778
- prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
779
- } else {
780
- prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
781
- }
782
- return prev;
783
- },
784
- [
785
- {
786
- ...item,
787
- name: [],
788
- isTypeOnly: false
789
- },
790
- {
791
- ...item,
792
- name: [],
793
- isTypeOnly: true
794
- }
795
- ]
796
- );
797
- }
798
- getNamedExports(root, exports) {
799
- return _optionalChain([exports, 'optionalAccess', _30 => _30.flatMap, 'call', _31 => _31((item) => {
800
- return this.getNamedExport(root, item);
801
- })]);
802
- }
803
- getIndexes(root) {
804
- const { treeNode = {}, isTypeOnly, extName } = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _options);
805
- const tree = TreeNode.build(root, treeNode);
806
- if (!tree) {
807
- return null;
808
- }
809
- const fileReducer = (files, treeNode2) => {
810
- if (!treeNode2.children) {
811
- return [];
812
- }
813
- if (treeNode2.children.length > 1) {
814
- const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
815
- const exports = treeNode2.children.filter(Boolean).map((file) => {
816
- const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, file.data.name)}`;
817
- if (importPath.endsWith("index") && file.data.type === "single") {
818
- return void 0;
819
- }
820
- return {
821
- path: extName ? `${importPath}${extName}` : importPath,
822
- isTypeOnly
823
- };
824
- }).filter(Boolean);
825
- files.push({
826
- path: indexPath,
827
- baseName: "index.ts",
828
- source: "",
829
- exports,
830
- exportable: true
831
- });
832
- } else if (treeNode2.children.length === 1) {
833
- const [treeNodeChild] = treeNode2.children;
834
- const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
835
- const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, treeNodeChild.data.name)}`;
836
- const exports = [
837
- {
838
- path: extName ? `${importPath}${extName}` : importPath,
839
- isTypeOnly
840
- }
841
- ];
842
- files.push({
843
- path: indexPath,
844
- baseName: "index.ts",
845
- source: "",
846
- exports,
847
- exportable: true
848
- });
849
- }
850
- treeNode2.children.forEach((childItem) => {
851
- fileReducer(files, childItem);
852
- });
853
- return files;
854
- };
855
- return fileReducer([], tree).reverse();
856
- }
857
- };
858
- _options = new WeakMap();
859
-
860
- // src/FileManager.ts
861
- var _cache, _task, _queue3, _FileManager_instances, add_fn, addOrAppend_fn;
864
+ var _cache, _FileManager_instances, add_fn, addOrAppend_fn;
862
865
  var _FileManager = class _FileManager {
863
- constructor({ task = async (file) => file, queue = new PQueue() } = {}) {
866
+ constructor() {
864
867
  _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _FileManager_instances);
865
868
  _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _cache, /* @__PURE__ */ new Map());
866
- _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _task);
867
- _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _queue3);
868
- _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _task, task);
869
- _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _queue3, queue);
870
869
  return this;
871
870
  }
872
871
  get files() {
@@ -876,9 +875,6 @@ var _FileManager = class _FileManager {
876
875
  });
877
876
  return files;
878
877
  }
879
- get isExecuting() {
880
- return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue3).size !== 0 && _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue3).pending !== 0;
881
- }
882
878
  async add(...files) {
883
879
  const promises = combineFiles(files).map((file) => {
884
880
  if (file.override) {
@@ -892,15 +888,15 @@ var _FileManager = class _FileManager {
892
888
  }
893
889
  return resolvedFiles[0];
894
890
  }
895
- async addIndexes({ root, output, meta, logger, options = {} }) {
891
+ async getIndexFiles({ plugin, root, output, logger, options = {} }) {
896
892
  const { exportType = "barrel" } = output;
897
893
  if (exportType === false) {
898
- return void 0;
894
+ return [];
899
895
  }
900
896
  const pathToBuildFrom = _path.resolve.call(void 0, root, output.path);
901
897
  if (_chunkPZT4CTBVcjs.transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
902
898
  logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
903
- return;
899
+ return [];
904
900
  }
905
901
  const exportPath = output.path.startsWith("./") ? _chunkPZT4CTBVcjs.trimExtName.call(void 0, output.path) : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, output.path)}`;
906
902
  const mode = _FileManager.getMode(output.path);
@@ -910,27 +906,8 @@ var _FileManager = class _FileManager {
910
906
  });
911
907
  let files = barrelManager.getIndexes(pathToBuildFrom);
912
908
  if (!files) {
913
- return void 0;
914
- }
915
- if (exportType === "barrelNamed") {
916
- files = files.map((file) => {
917
- if (file.exports) {
918
- return {
919
- ...file,
920
- exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
921
- };
922
- }
923
- return file;
924
- });
909
+ return [];
925
910
  }
926
- await Promise.all(
927
- files.map((file) => {
928
- return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
929
- ...file,
930
- meta: meta ? meta : file.meta
931
- });
932
- })
933
- );
934
911
  const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
935
912
  const rootFile = {
936
913
  path: _path.resolve.call(void 0, root, "index.ts"),
@@ -949,13 +926,49 @@ var _FileManager = class _FileManager {
949
926
  ],
950
927
  exportable: true
951
928
  };
952
- if (exportType === "barrelNamed" && !output.exportAs && _optionalChain([rootFile, 'access', _32 => _32.exports, 'optionalAccess', _33 => _33[0]])) {
953
- rootFile.exports = barrelManager.getNamedExport(root, rootFile.exports[0]);
929
+ if (exportType === "barrelNamed") {
930
+ files = files.map((file) => {
931
+ if (file.exports) {
932
+ return {
933
+ ...file,
934
+ exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
935
+ };
936
+ }
937
+ return file;
938
+ });
939
+ const barrelExportRoot = _optionalChain([rootFile, 'access', _32 => _32.exports, 'optionalAccess', _33 => _33[0]]);
940
+ if (!output.exportAs && barrelExportRoot) {
941
+ const exportFile = files.find((file) => {
942
+ return _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.path) === _path2.default.resolve(root, barrelExportRoot.path);
943
+ });
944
+ if (_optionalChain([exportFile, 'optionalAccess', _34 => _34.exports])) {
945
+ rootFile.exports = exportFile.exports.map((exportItem) => {
946
+ return {
947
+ ...exportItem,
948
+ path: _fs.getRelativePath.call(void 0, rootFile.path, exportFile.path)
949
+ };
950
+ });
951
+ }
952
+ }
954
953
  }
955
- await _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
956
- ...rootFile,
957
- meta: meta ? meta : rootFile.meta
958
- });
954
+ return [
955
+ ...await Promise.all(
956
+ files.map((file) => {
957
+ return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
958
+ ...file,
959
+ meta: {
960
+ pluginKey: plugin.key
961
+ }
962
+ });
963
+ })
964
+ ),
965
+ await _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
966
+ ...rootFile,
967
+ meta: {
968
+ pluginKey: plugin.key
969
+ }
970
+ })
971
+ ];
959
972
  }
960
973
  getCacheByUUID(UUID) {
961
974
  let cache;
@@ -964,15 +977,15 @@ var _FileManager = class _FileManager {
964
977
  });
965
978
  return cache;
966
979
  }
967
- get(path2) {
968
- return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(path2);
980
+ get(path3) {
981
+ return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(path3);
969
982
  }
970
- remove(path2) {
971
- const cacheItem = this.get(path2);
983
+ remove(path3) {
984
+ const cacheItem = this.get(path3);
972
985
  if (!cacheItem) {
973
986
  return;
974
987
  }
975
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).delete(path2);
988
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).delete(path3);
976
989
  }
977
990
  async write(...params) {
978
991
  return _fs.write.call(void 0, ...params);
@@ -980,18 +993,18 @@ var _FileManager = class _FileManager {
980
993
  async read(...params) {
981
994
  return _fs.read.call(void 0, ...params);
982
995
  }
983
- // statics
984
- static async getSource(file) {
985
- return getSource(file);
996
+ async processFiles(...params) {
997
+ return processFiles(...params);
986
998
  }
999
+ // statics
987
1000
  static combineFiles(files) {
988
1001
  return combineFiles(files);
989
1002
  }
990
- static getMode(path2) {
991
- if (!path2) {
1003
+ static getMode(path3) {
1004
+ if (!path3) {
992
1005
  return "split";
993
1006
  }
994
- return _path.extname.call(void 0, path2) ? "single" : "split";
1007
+ return _path.extname.call(void 0, path3) ? "single" : "split";
995
1008
  }
996
1009
  static get extensions() {
997
1010
  return [".js", ".ts", ".tsx"];
@@ -1001,8 +1014,6 @@ var _FileManager = class _FileManager {
1001
1014
  }
1002
1015
  };
1003
1016
  _cache = new WeakMap();
1004
- _task = new WeakMap();
1005
- _queue3 = new WeakMap();
1006
1017
  _FileManager_instances = new WeakSet();
1007
1018
  add_fn = async function(file) {
1008
1019
  const controller = new AbortController();
@@ -1011,7 +1022,7 @@ add_fn = async function(file) {
1011
1022
  name: _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.baseName),
1012
1023
  ...file
1013
1024
  };
1014
- if (_optionalChain([resolvedFile, 'access', _34 => _34.exports, 'optionalAccess', _35 => _35.length])) {
1025
+ if (_optionalChain([resolvedFile, 'access', _35 => _35.exports, 'optionalAccess', _36 => _36.length])) {
1015
1026
  const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
1016
1027
  resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
1017
1028
  const exportedFile = this.files.find((file2) => file2.path.includes(_path.resolve.call(void 0, folder, exportItem.path)));
@@ -1022,13 +1033,7 @@ add_fn = async function(file) {
1022
1033
  });
1023
1034
  }
1024
1035
  _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
1025
- return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue3).add(
1026
- async () => {
1027
- var _a;
1028
- return (_a = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
1029
- },
1030
- { signal: controller.signal }
1031
- );
1036
+ return resolvedFile;
1032
1037
  };
1033
1038
  addOrAppend_fn = async function(file) {
1034
1039
  const previousCaches = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(file.path);
@@ -1086,13 +1091,13 @@ async function getSource(file) {
1086
1091
  const exports = file.exports ? combineExports(file.exports) : [];
1087
1092
  const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
1088
1093
  const importNodes = imports.filter((item) => {
1089
- const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1090
- return path2 !== _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.path);
1094
+ const path3 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1095
+ return path3 !== _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.path);
1091
1096
  }).map((item) => {
1092
- const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1097
+ const path3 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1093
1098
  return parser.factory.createImportDeclaration({
1094
1099
  name: item.name,
1095
- path: item.extName ? `${path2}${item.extName}` : path2,
1100
+ path: item.extName ? `${path3}${item.extName}` : path3,
1096
1101
  isTypeOnly: item.isTypeOnly
1097
1102
  });
1098
1103
  });
@@ -1119,7 +1124,7 @@ function combineExports(exports) {
1119
1124
  const uniquePrev = prev.findLast(
1120
1125
  (imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
1121
1126
  );
1122
- if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _36 => _36.asAlias]) && !curr.asAlias) {
1127
+ if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _37 => _37.asAlias]) && !curr.asAlias) {
1123
1128
  return prev;
1124
1129
  }
1125
1130
  if (!prevByPath) {
@@ -1199,7 +1204,7 @@ function getEnvSource(source, env) {
1199
1204
  }
1200
1205
  return keys.reduce((prev, key) => {
1201
1206
  const environmentValue = env[key];
1202
- const replaceBy = environmentValue ? `'${_optionalChain([environmentValue, 'access', _37 => _37.replaceAll, 'call', _38 => _38('"', ""), 'optionalAccess', _39 => _39.replaceAll, 'call', _40 => _40("'", "")])}'` : "undefined";
1207
+ const replaceBy = environmentValue ? `'${_optionalChain([environmentValue, 'access', _38 => _38.replaceAll, 'call', _39 => _39('"', ""), 'optionalAccess', _40 => _40.replaceAll, 'call', _41 => _41("'", "")])}'` : "undefined";
1203
1208
  if (key.toUpperCase() !== key) {
1204
1209
  throw new TypeError(`Environment should be in upperCase for ${key}`);
1205
1210
  }
@@ -1219,9 +1224,42 @@ function getEnvSource(source, env) {
1219
1224
  return prev;
1220
1225
  }, source);
1221
1226
  }
1227
+ var queue = new PQueue({ concurrency: 10 });
1228
+ async function processFiles({ dryRun, logger, files }) {
1229
+ const mergedFiles = await Promise.all(
1230
+ files.map(async (file) => ({
1231
+ ...file,
1232
+ source: await getSource(file)
1233
+ }))
1234
+ );
1235
+ const orderedFiles = _chunk67C6RBGQcjs.orderBy.call(void 0, mergedFiles, [(v) => !_optionalChain([v, 'access', _42 => _42.meta, 'optionalAccess', _43 => _43.pluginKey]), (v) => v.path.length, (v) => _chunkPZT4CTBVcjs.trimExtName.call(void 0, v.path).endsWith("index")], ["desc", "desc"]);
1236
+ logger.emit(
1237
+ "debug",
1238
+ orderedFiles.map((item) => `[${_optionalChain([item, 'access', _44 => _44.meta, 'optionalAccess', _45 => _45.pluginKey]) || "unknown"}]${item.path}:
1239
+ ${item.source}`)
1240
+ );
1241
+ if (!dryRun) {
1242
+ _optionalChain([logger, 'access', _46 => _46.consola, 'optionalAccess', _47 => _47.pauseLogs, 'call', _48 => _48()]);
1243
+ const size = orderedFiles.length;
1244
+ const promises = orderedFiles.map(async (file, index) => {
1245
+ await queue.add(async () => {
1246
+ logger.emit("progress", { count: index, size, file });
1247
+ await _fs.write.call(void 0, file.path, file.source, { sanity: false });
1248
+ await new Promise((resolve2) => {
1249
+ setTimeout(resolve2, 0);
1250
+ });
1251
+ logger.emit("progress", { count: index + 1, size, file });
1252
+ });
1253
+ });
1254
+ await Promise.all(promises);
1255
+ _optionalChain([logger, 'access', _49 => _49.consola, 'optionalAccess', _50 => _50.resumeLogs, 'call', _51 => _51()]);
1256
+ }
1257
+ return mergedFiles;
1258
+ }
1259
+
1222
1260
 
1223
1261
 
1224
1262
 
1225
1263
 
1226
- exports.PQueue = PQueue; exports.FileManager = FileManager;
1227
- //# sourceMappingURL=chunk-ADC5UNZ5.cjs.map
1264
+ exports.FileManager = FileManager; exports.getSource = getSource; exports.processFiles = processFiles;
1265
+ //# sourceMappingURL=chunk-FWU62YO5.cjs.map