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

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 (73) hide show
  1. package/dist/{FileManager-tzl0YsYE.d.ts → FileManager-Ceski1W9.d.ts} +46 -33
  2. package/dist/{FileManager-jZpqETKU.d.cts → FileManager-wyXRkgIk.d.cts} +46 -33
  3. package/dist/chunk-2EU7DMPM.js +97 -0
  4. package/dist/chunk-2EU7DMPM.js.map +1 -0
  5. package/dist/chunk-5HN4LW3R.cjs +102 -0
  6. package/dist/chunk-5HN4LW3R.cjs.map +1 -0
  7. package/dist/{chunk-Z5CHJQJB.js → chunk-76UEJFFE.js} +1 -4
  8. package/dist/chunk-76UEJFFE.js.map +1 -0
  9. package/dist/{chunk-5JZNFPUP.js → chunk-AWAZR3D5.js} +61 -10
  10. package/dist/chunk-AWAZR3D5.js.map +1 -0
  11. package/dist/{chunk-FWU62YO5.cjs → chunk-DCZQYCCO.cjs} +216 -326
  12. package/dist/chunk-DCZQYCCO.cjs.map +1 -0
  13. package/dist/{chunk-YTSNYMHW.cjs → chunk-L3JJLZ5Q.cjs} +62 -11
  14. package/dist/chunk-L3JJLZ5Q.cjs.map +1 -0
  15. package/dist/{chunk-RBP2ASUX.cjs → chunk-LOLEBOMW.cjs} +1 -4
  16. package/dist/chunk-LOLEBOMW.cjs.map +1 -0
  17. package/dist/chunk-RIEGCND2.js +525 -0
  18. package/dist/chunk-RIEGCND2.js.map +1 -0
  19. package/dist/index.cjs +80 -69
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +4 -6
  22. package/dist/index.d.ts +4 -6
  23. package/dist/index.js +67 -58
  24. package/dist/index.js.map +1 -1
  25. package/dist/{logger-BnWJh6Yq.d.cts → logger-BWFeedRk.d.cts} +15 -5
  26. package/dist/{logger-BnWJh6Yq.d.ts → logger-BWFeedRk.d.ts} +15 -5
  27. package/dist/logger.cjs +2 -2
  28. package/dist/logger.d.cts +1 -2
  29. package/dist/logger.d.ts +1 -2
  30. package/dist/logger.js +1 -1
  31. package/dist/mocks.cjs +4 -6
  32. package/dist/mocks.cjs.map +1 -1
  33. package/dist/mocks.d.cts +3 -5
  34. package/dist/mocks.d.ts +3 -5
  35. package/dist/mocks.js +3 -5
  36. package/dist/mocks.js.map +1 -1
  37. package/dist/transformers.cjs +189 -33
  38. package/dist/transformers.cjs.map +1 -1
  39. package/dist/transformers.d.cts +1 -3
  40. package/dist/transformers.d.ts +1 -3
  41. package/dist/transformers.js +156 -14
  42. package/dist/transformers.js.map +1 -1
  43. package/dist/utils.cjs +6 -2
  44. package/dist/utils.cjs.map +1 -1
  45. package/dist/utils.d.cts +30 -3
  46. package/dist/utils.d.ts +30 -3
  47. package/dist/utils.js +7 -3
  48. package/package.json +9 -8
  49. package/src/BarrelManager.ts +24 -99
  50. package/src/FileManager.ts +156 -281
  51. package/src/PackageManager.ts +1 -1
  52. package/src/PluginManager.ts +89 -57
  53. package/src/build.ts +6 -19
  54. package/src/logger.ts +6 -8
  55. package/src/transformers/index.ts +2 -3
  56. package/src/transformers/trim.ts +0 -4
  57. package/src/types.ts +1 -1
  58. package/src/utils/TreeNode.ts +91 -26
  59. package/src/utils/executeStrategies.ts +1 -1
  60. package/src/utils/index.ts +2 -1
  61. package/src/utils/parser.ts +96 -0
  62. package/dist/chunk-5JZNFPUP.js.map +0 -1
  63. package/dist/chunk-CEWT73XF.js +0 -637
  64. package/dist/chunk-CEWT73XF.js.map +0 -1
  65. package/dist/chunk-FWU62YO5.cjs.map +0 -1
  66. package/dist/chunk-JKZG2IJR.js +0 -283
  67. package/dist/chunk-JKZG2IJR.js.map +0 -1
  68. package/dist/chunk-PZT4CTBV.cjs +0 -299
  69. package/dist/chunk-PZT4CTBV.cjs.map +0 -1
  70. package/dist/chunk-RBP2ASUX.cjs.map +0 -1
  71. package/dist/chunk-YTSNYMHW.cjs.map +0 -1
  72. package/dist/chunk-Z5CHJQJB.js.map +0 -1
  73. package/src/utils/getParser.ts +0 -17
@@ -1,11 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
-
5
- var _chunkPZT4CTBVcjs = require('./chunk-PZT4CTBV.cjs');
6
-
7
-
8
- var _chunkYTSNYMHWcjs = require('./chunk-YTSNYMHW.cjs');
4
+ var _chunkL3JJLZ5Qcjs = require('./chunk-L3JJLZ5Q.cjs');
9
5
 
10
6
 
11
7
  var _chunk67C6RBGQcjs = require('./chunk-67C6RBGQ.cjs');
@@ -186,19 +182,16 @@ var require_eventemitter3 = _chunkXCPFG6DOcjs.__commonJS.call(void 0, {
186
182
 
187
183
  // src/FileManager.ts
188
184
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
189
- var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
190
185
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
191
186
  var _remeda = require('remeda');
192
187
  var _fs = require('@kubb/fs');
193
188
 
194
189
  // src/BarrelManager.ts
195
190
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
196
- var _parserts = require('@kubb/parser-ts');
197
191
 
198
192
 
199
193
  // src/utils/TreeNode.ts
200
194
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
201
- var _directorytree = require('directory-tree'); var _directorytree2 = _interopRequireDefault(_directorytree);
202
195
  var TreeNode = class _TreeNode {
203
196
  constructor(data, parent) {
204
197
  this.children = [];
@@ -261,25 +254,23 @@ var TreeNode = class _TreeNode {
261
254
  }
262
255
  return this;
263
256
  }
264
- static build(path3, options = {}) {
257
+ static build(files, root) {
265
258
  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
- });
259
+ const filteredTree = buildDirectoryTree(files, root);
271
260
  if (!filteredTree) {
272
261
  return null;
273
262
  }
274
263
  const treeNode = new _TreeNode({
275
264
  name: filteredTree.name,
276
265
  path: filteredTree.path,
266
+ file: filteredTree.file,
277
267
  type: FileManager.getMode(filteredTree.path)
278
268
  });
279
269
  const recurse = (node, item) => {
280
270
  const subNode = node.addChild({
281
271
  name: item.name,
282
272
  path: item.path,
273
+ file: item.file,
283
274
  type: FileManager.getMode(item.path)
284
275
  });
285
276
  if (_optionalChain([item, 'access', _8 => _8.children, 'optionalAccess', _9 => _9.length])) {
@@ -295,8 +286,55 @@ var TreeNode = class _TreeNode {
295
286
  }
296
287
  }
297
288
  };
289
+ function buildDirectoryTree(files, rootFolder = "") {
290
+ const rootPrefix = rootFolder.endsWith("/") ? rootFolder : `${rootFolder}/`;
291
+ const filteredFiles = files.filter((file) => rootFolder ? file.path.startsWith(rootPrefix) && !file.path.endsWith(".json") : !file.path.endsWith(".json"));
292
+ if (filteredFiles.length === 0) {
293
+ return null;
294
+ }
295
+ const root = {
296
+ name: rootFolder || "",
297
+ path: rootFolder || "",
298
+ children: []
299
+ };
300
+ filteredFiles.forEach((file) => {
301
+ const path2 = file.path.slice(rootFolder.length);
302
+ const parts = path2.split("/");
303
+ let currentLevel = root.children;
304
+ let currentPath = rootFolder;
305
+ parts.forEach((part, index) => {
306
+ if (index !== 0) {
307
+ currentPath += `/${part}`;
308
+ } else {
309
+ currentPath += `${part}`;
310
+ }
311
+ let existingNode = currentLevel.find((node) => node.name === part);
312
+ if (!existingNode) {
313
+ if (index === parts.length - 1) {
314
+ existingNode = {
315
+ name: part,
316
+ file,
317
+ path: currentPath
318
+ };
319
+ } else {
320
+ existingNode = {
321
+ name: part,
322
+ path: currentPath,
323
+ children: []
324
+ };
325
+ }
326
+ currentLevel.push(existingNode);
327
+ }
328
+ if (!existingNode.file) {
329
+ currentLevel = existingNode.children;
330
+ }
331
+ });
332
+ });
333
+ return root;
334
+ }
298
335
 
299
336
  // src/BarrelManager.ts
337
+
300
338
  var _options;
301
339
  var BarrelManager = class {
302
340
  constructor(options = {}) {
@@ -304,95 +342,34 @@ var BarrelManager = class {
304
342
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _options, options);
305
343
  return this;
306
344
  }
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);
345
+ getIndexes(generatedFiles, root) {
346
+ const { isTypeOnly, extName } = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _options);
347
+ const tree = TreeNode.build(generatedFiles, root);
351
348
  if (!tree) {
352
349
  return null;
353
350
  }
354
- const fileReducer = (files, treeNode2) => {
355
- if (!treeNode2.children) {
351
+ const fileReducer = (files, treeNode) => {
352
+ if (!treeNode.children) {
356
353
  return [];
357
354
  }
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) => {
355
+ const indexPath = _path2.default.resolve(treeNode.data.path, "index.ts");
356
+ const exports = treeNode.children.filter((item) => !!item.data.name).map((treeNode2) => {
357
+ const importPath = treeNode2.data.file ? `./${_fs.trimExtName.call(void 0, treeNode2.data.name)}` : `./${treeNode2.data.name}/index`;
358
+ if (importPath.endsWith("index") && treeNode2.data.file) {
359
+ return void 0;
360
+ }
361
+ return {
362
+ path: extName ? `${importPath}${extName}` : importPath,
363
+ isTypeOnly
364
+ };
365
+ }).filter(Boolean);
366
+ files.push({
367
+ path: indexPath,
368
+ baseName: "index.ts",
369
+ exports,
370
+ sources: []
371
+ });
372
+ treeNode.children.forEach((childItem) => {
396
373
  fileReducer(files, childItem);
397
374
  });
398
375
  return files;
@@ -402,6 +379,9 @@ var BarrelManager = class {
402
379
  };
403
380
  _options = new WeakMap();
404
381
 
382
+ // src/FileManager.ts
383
+
384
+
405
385
  // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
406
386
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
407
387
 
@@ -539,7 +519,7 @@ var PriorityQueue = class {
539
519
  }
540
520
  dequeue() {
541
521
  const item = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).shift();
542
- return _optionalChain([item, 'optionalAccess', _22 => _22.run]);
522
+ return _optionalChain([item, 'optionalAccess', _16 => _16.run]);
543
523
  }
544
524
  filter(options) {
545
525
  return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run);
@@ -588,10 +568,10 @@ var PQueue = class extends import_index.default {
588
568
  ...options
589
569
  };
590
570
  if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
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})`);
571
+ throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${_nullishCoalesce(_optionalChain([options, 'access', _17 => _17.intervalCap, 'optionalAccess', _18 => _18.toString, 'call', _19 => _19()]), () => ( ""))}\` (${typeof options.intervalCap})`);
592
572
  }
593
573
  if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
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})`);
574
+ throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${_nullishCoalesce(_optionalChain([options, 'access', _20 => _20.interval, 'optionalAccess', _21 => _21.toString, 'call', _22 => _22()]), () => ( ""))}\` (${typeof options.interval})`);
595
575
  }
596
576
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _carryoverConcurrencyCount, options.carryoverConcurrencyCount);
597
577
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0);
@@ -625,7 +605,7 @@ var PQueue = class extends import_index.default {
625
605
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _pending)._++;
626
606
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _intervalCount)._++;
627
607
  try {
628
- _optionalChain([options, 'access', _29 => _29.signal, 'optionalAccess', _30 => _30.throwIfAborted, 'call', _31 => _31()]);
608
+ _optionalChain([options, 'access', _23 => _23.signal, 'optionalAccess', _24 => _24.throwIfAborted, 'call', _25 => _25()]);
629
609
  let operation = function_({ signal: options.signal });
630
610
  if (options.timeout) {
631
611
  operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
@@ -861,22 +841,33 @@ onEvent_fn = async function(event, filter) {
861
841
  };
862
842
 
863
843
  // src/FileManager.ts
864
- var _cache, _FileManager_instances, add_fn, addOrAppend_fn;
844
+ var _filesByPath, _files, _FileManager_instances, add_fn, addOrAppend_fn;
865
845
  var _FileManager = class _FileManager {
866
846
  constructor() {
867
847
  _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _FileManager_instances);
868
- _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _cache, /* @__PURE__ */ new Map());
848
+ _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _filesByPath, /* @__PURE__ */ new Map());
849
+ _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _files, /* @__PURE__ */ new Set());
869
850
  return this;
870
851
  }
871
852
  get files() {
872
- const files = [];
873
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).forEach((item) => {
874
- files.push(...item.flat(1));
875
- });
876
- return files;
853
+ return Array.from(_chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files));
854
+ }
855
+ get orderedFiles() {
856
+ return _chunk67C6RBGQcjs.orderBy.call(void 0, Array.from(_chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files)), [
857
+ (v) => v.path.length,
858
+ (v) => _fs.trimExtName.call(void 0, v.path).endsWith("index"),
859
+ (v) => _fs.trimExtName.call(void 0, v.baseName),
860
+ (v) => v.path.split(".").pop()
861
+ ]);
862
+ }
863
+ get groupedFiles() {
864
+ return buildDirectoryTree(Array.from(_chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files)));
865
+ }
866
+ get treeNode() {
867
+ return TreeNode.build(Array.from(_chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files)));
877
868
  }
878
869
  async add(...files) {
879
- const promises = combineFiles(files).map((file) => {
870
+ const promises = files.map((file) => {
880
871
  if (file.override) {
881
872
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, file);
882
873
  }
@@ -888,31 +879,47 @@ var _FileManager = class _FileManager {
888
879
  }
889
880
  return resolvedFiles[0];
890
881
  }
891
- async getIndexFiles({ plugin, root, output, logger, options = {} }) {
882
+ getCacheById(id) {
883
+ let cache;
884
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files).forEach((file) => {
885
+ if (file.id === id) {
886
+ cache = file;
887
+ }
888
+ });
889
+ return cache;
890
+ }
891
+ getByPath(path2) {
892
+ return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _filesByPath).get(path2);
893
+ }
894
+ deleteByPath(path2) {
895
+ const cacheItem = this.getByPath(path2);
896
+ if (!cacheItem) {
897
+ return;
898
+ }
899
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _filesByPath).delete(path2);
900
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files).delete(cacheItem);
901
+ }
902
+ async getIndexFiles({ files, plugin, root, output, logger, options = {} }) {
892
903
  const { exportType = "barrel" } = output;
893
904
  if (exportType === false) {
894
905
  return [];
895
906
  }
896
907
  const pathToBuildFrom = _path.resolve.call(void 0, root, output.path);
897
- if (_chunkPZT4CTBVcjs.transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
908
+ if (_fs.trimExtName.call(void 0, pathToBuildFrom).endsWith("index")) {
898
909
  logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
899
910
  return [];
900
911
  }
901
- const exportPath = output.path.startsWith("./") ? _chunkPZT4CTBVcjs.trimExtName.call(void 0, output.path) : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, output.path)}`;
912
+ const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
902
913
  const mode = _FileManager.getMode(output.path);
903
- const barrelManager = new BarrelManager({
904
- extName: output.extName,
905
- ...options
906
- });
907
- let files = barrelManager.getIndexes(pathToBuildFrom);
908
- if (!files) {
914
+ const barrelManager = new BarrelManager({ ...options, extName: output.extName });
915
+ let indexFiles = barrelManager.getIndexes(files, pathToBuildFrom);
916
+ if (!indexFiles) {
909
917
  return [];
910
918
  }
911
919
  const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
912
920
  const rootFile = {
913
921
  path: _path.resolve.call(void 0, root, "index.ts"),
914
922
  baseName: "index.ts",
915
- source: "",
916
923
  exports: [
917
924
  output.exportAs ? {
918
925
  name: output.exportAs,
@@ -924,193 +931,111 @@ var _FileManager = class _FileManager {
924
931
  isTypeOnly: options.isTypeOnly
925
932
  }
926
933
  ],
927
- exportable: true
934
+ sources: [],
935
+ meta: {
936
+ pluginKey: plugin.key
937
+ }
928
938
  };
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) => {
939
+ if (exportType === "barrel") {
940
+ indexFiles = indexFiles.map((file) => {
941
+ return {
942
+ ...file,
943
+ exports: _optionalChain([file, 'access', _26 => _26.exports, 'optionalAccess', _27 => _27.map, 'call', _28 => _28((exportItem) => {
946
944
  return {
947
945
  ...exportItem,
948
- path: _fs.getRelativePath.call(void 0, rootFile.path, exportFile.path)
946
+ name: void 0
949
947
  };
950
- });
951
- }
952
- }
948
+ })])
949
+ };
950
+ });
951
+ rootFile.exports = _optionalChain([rootFile, 'access', _29 => _29.exports, 'optionalAccess', _30 => _30.map, 'call', _31 => _31((item) => {
952
+ return {
953
+ ...item,
954
+ name: void 0
955
+ };
956
+ })]);
953
957
  }
954
958
  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
- })
959
+ ...indexFiles.map((indexFile) => {
960
+ return {
961
+ ...indexFile,
962
+ meta: {
963
+ pluginKey: plugin.key
964
+ }
965
+ };
966
+ }),
967
+ rootFile
971
968
  ];
972
969
  }
973
- getCacheByUUID(UUID) {
974
- let cache;
975
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).forEach((files) => {
976
- cache = files.find((item) => item.id === UUID);
977
- });
978
- return cache;
979
- }
980
- get(path3) {
981
- return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(path3);
982
- }
983
- remove(path3) {
984
- const cacheItem = this.get(path3);
985
- if (!cacheItem) {
986
- return;
987
- }
988
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).delete(path3);
989
- }
990
970
  async write(...params) {
991
971
  return _fs.write.call(void 0, ...params);
992
972
  }
993
973
  async read(...params) {
994
974
  return _fs.read.call(void 0, ...params);
995
975
  }
996
- async processFiles(...params) {
997
- return processFiles(...params);
998
- }
999
976
  // statics
1000
- static combineFiles(files) {
1001
- return combineFiles(files);
1002
- }
1003
- static getMode(path3) {
1004
- if (!path3) {
977
+ static getMode(path2) {
978
+ if (!path2) {
1005
979
  return "split";
1006
980
  }
1007
- return _path.extname.call(void 0, path3) ? "single" : "split";
1008
- }
1009
- static get extensions() {
1010
- return [".js", ".ts", ".tsx"];
1011
- }
1012
- static isJavascript(baseName) {
1013
- return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
981
+ return _path.extname.call(void 0, path2) ? "single" : "split";
1014
982
  }
1015
983
  };
1016
- _cache = new WeakMap();
984
+ _filesByPath = new WeakMap();
985
+ _files = new WeakMap();
1017
986
  _FileManager_instances = new WeakSet();
1018
987
  add_fn = async function(file) {
1019
- const controller = new AbortController();
1020
- const resolvedFile = {
1021
- id: _crypto2.default.randomUUID(),
1022
- name: _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.baseName),
1023
- ...file
1024
- };
1025
- if (_optionalChain([resolvedFile, 'access', _35 => _35.exports, 'optionalAccess', _36 => _36.length])) {
1026
- const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
1027
- resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
1028
- const exportedFile = this.files.find((file2) => file2.path.includes(_path.resolve.call(void 0, folder, exportItem.path)));
1029
- if (exportedFile) {
1030
- return exportedFile.exportable;
1031
- }
1032
- return true;
1033
- });
1034
- }
1035
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
988
+ const resolvedFile = _chunkL3JJLZ5Qcjs.createFile.call(void 0, file);
989
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _filesByPath).set(resolvedFile.path, resolvedFile);
990
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files).add(resolvedFile);
1036
991
  return resolvedFile;
1037
992
  };
1038
993
  addOrAppend_fn = async function(file) {
1039
- const previousCaches = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(file.path);
1040
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
1041
- if (previousCache) {
1042
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).delete(previousCache.path);
994
+ const previousFile = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _filesByPath).get(file.path);
995
+ if (previousFile) {
996
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _filesByPath).delete(previousFile.path);
997
+ _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _files).delete(previousFile);
1043
998
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, {
1044
999
  ...file,
1045
- source: previousCache.source && file.source ? `${previousCache.source}
1046
- ${file.source}` : "",
1047
- imports: [...previousCache.imports || [], ...file.imports || []],
1048
- exports: [...previousCache.exports || [], ...file.exports || []],
1049
- env: { ...previousCache.env || {}, ...file.env || {} }
1000
+ sources: [...previousFile.sources || [], ...file.sources || []],
1001
+ imports: [...previousFile.imports || [], ...file.imports || []],
1002
+ exports: [...previousFile.exports || [], ...file.exports || []]
1050
1003
  });
1051
1004
  }
1052
1005
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, file);
1053
1006
  };
1054
1007
  var FileManager = _FileManager;
1055
- function combineFiles(files) {
1056
- return files.filter(Boolean).reduce(
1057
- (acc, file) => {
1058
- const prevIndex = acc.findIndex((item) => item.path === file.path);
1059
- if (prevIndex === -1) {
1060
- return [...acc, file];
1061
- }
1062
- const prev = acc[prevIndex];
1063
- if (prev && file.override) {
1064
- acc[prevIndex] = {
1065
- imports: [],
1066
- exports: [],
1067
- ...file
1068
- };
1069
- return acc;
1070
- }
1071
- if (prev) {
1072
- acc[prevIndex] = {
1073
- ...file,
1074
- source: prev.source && file.source ? `${prev.source}
1075
- ${file.source}` : "",
1076
- imports: [...prev.imports || [], ...file.imports || []],
1077
- exports: [...prev.exports || [], ...file.exports || []],
1078
- env: { ...prev.env || {}, ...file.env || {} }
1079
- };
1080
- }
1081
- return acc;
1082
- },
1083
- []
1084
- );
1085
- }
1086
1008
  async function getSource(file) {
1087
- if (file.language ? !["typescript", "javascript"].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
1088
- return file.source;
1089
- }
1090
- const parser = await _chunkYTSNYMHWcjs.getParser.call(void 0, file.language);
1009
+ const parser = await _chunkL3JJLZ5Qcjs.getFileParser.call(void 0, file.extName);
1010
+ const source = file.sources.map((item) => item.value).join("\n\n");
1091
1011
  const exports = file.exports ? combineExports(file.exports) : [];
1092
- const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
1012
+ const imports = file.imports && source ? combineImports(file.imports, exports, source) : [];
1093
1013
  const importNodes = imports.filter((item) => {
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);
1014
+ const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1015
+ return path2 !== _fs.trimExtName.call(void 0, file.path);
1096
1016
  }).map((item) => {
1097
- const path3 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1098
- return parser.factory.createImportDeclaration({
1017
+ const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1018
+ return parser.createImport({
1099
1019
  name: item.name,
1100
- path: item.extName ? `${path3}${item.extName}` : path3,
1020
+ path: item.extName ? `${path2}${item.extName}` : path2,
1101
1021
  isTypeOnly: item.isTypeOnly
1102
1022
  });
1103
1023
  });
1104
- const exportNodes = exports.map(
1105
- (item) => parser.factory.createExportDeclaration({
1106
- name: item.name,
1107
- path: item.extName ? `${item.path}${item.extName}` : item.path,
1108
- isTypeOnly: item.isTypeOnly,
1109
- asAlias: item.asAlias
1110
- })
1111
- );
1112
- const source = [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
1113
- return parser.print([], { source, noEmitHelpers: false });
1024
+ const exportNodes = exports.map((item) => {
1025
+ if (item.path) {
1026
+ return parser.createExport({
1027
+ name: item.name,
1028
+ path: item.extName ? `${item.path}${item.extName}` : item.path,
1029
+ isTypeOnly: item.isTypeOnly,
1030
+ asAlias: item.asAlias
1031
+ });
1032
+ }
1033
+ }).filter(Boolean);
1034
+ return parser.print({
1035
+ imports: importNodes,
1036
+ exports: exportNodes,
1037
+ source
1038
+ });
1114
1039
  }
1115
1040
  function combineExports(exports) {
1116
1041
  const combinedExports = _chunk67C6RBGQcjs.orderBy.call(void 0, exports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
@@ -1124,7 +1049,7 @@ function combineExports(exports) {
1124
1049
  const uniquePrev = prev.findLast(
1125
1050
  (imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
1126
1051
  );
1127
- if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _37 => _37.asAlias]) && !curr.asAlias) {
1052
+ if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _32 => _32.asAlias]) && !curr.asAlias) {
1128
1053
  return prev;
1129
1054
  }
1130
1055
  if (!prevByPath) {
@@ -1144,7 +1069,7 @@ function combineExports(exports) {
1144
1069
  },
1145
1070
  []
1146
1071
  );
1147
- return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
1072
+ return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias]);
1148
1073
  }
1149
1074
  function combineImports(imports, exports, source) {
1150
1075
  const combinedImports = _chunk67C6RBGQcjs.orderBy.call(void 0, imports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
@@ -1192,69 +1117,34 @@ function combineImports(imports, exports, source) {
1192
1117
  },
1193
1118
  []
1194
1119
  );
1195
- return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
1120
+ return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedImports, [(v) => !v.isTypeOnly]);
1196
1121
  }
1197
- function getEnvSource(source, env) {
1198
- if (!env) {
1199
- return source;
1200
- }
1201
- const keys = Object.keys(env);
1202
- if (!keys.length) {
1203
- return source;
1204
- }
1205
- return keys.reduce((prev, key) => {
1206
- const environmentValue = env[key];
1207
- const replaceBy = environmentValue ? `'${_optionalChain([environmentValue, 'access', _38 => _38.replaceAll, 'call', _39 => _39('"', ""), 'optionalAccess', _40 => _40.replaceAll, 'call', _41 => _41("'", "")])}'` : "undefined";
1208
- if (key.toUpperCase() !== key) {
1209
- throw new TypeError(`Environment should be in upperCase for ${key}`);
1210
- }
1211
- if (typeof replaceBy === "string") {
1212
- prev = _chunkPZT4CTBVcjs.searchAndReplace.call(void 0, {
1213
- text: prev.replaceAll(`process.env.${key}`, replaceBy),
1214
- replaceBy,
1215
- prefix: "process.env",
1216
- key
1217
- });
1218
- prev = _chunkPZT4CTBVcjs.searchAndReplace.call(void 0, {
1219
- text: prev.replaceAll(/(declare const).*\n/gi, ""),
1220
- replaceBy,
1221
- key
1222
- });
1223
- }
1224
- return prev;
1225
- }, source);
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
- );
1122
+ var queue = new PQueue({ concurrency: 100 });
1123
+ async function processFiles({ dryRun, config, logger, files }) {
1124
+ const orderedFiles = _chunk67C6RBGQcjs.orderBy.call(void 0, files, [
1125
+ (v) => _optionalChain([v, 'optionalAccess', _33 => _33.meta]) && "pluginKey" in v.meta && !v.meta.pluginKey,
1126
+ (v) => v.path.length,
1127
+ (v) => _fs.trimExtName.call(void 0, v.path).endsWith("index")
1128
+ ]);
1129
+ logger.emit("debug", {
1130
+ logs: [JSON.stringify({ files: orderedFiles }, null, 2)],
1131
+ fileName: "kubb-files.json",
1132
+ override: true
1133
+ });
1241
1134
  if (!dryRun) {
1242
- _optionalChain([logger, 'access', _46 => _46.consola, 'optionalAccess', _47 => _47.pauseLogs, 'call', _48 => _48()]);
1243
1135
  const size = orderedFiles.length;
1244
- const promises = orderedFiles.map(async (file, index) => {
1136
+ logger.emit("progress_start", { id: "files", size });
1137
+ const promises = orderedFiles.map(async (file) => {
1245
1138
  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 });
1139
+ const source = await getSource(file);
1140
+ await _fs.write.call(void 0, file.path, source, { sanity: false });
1141
+ logger.emit("progress", { id: "files", data: file ? _path.relative.call(void 0, config.root, file.path) : "" });
1252
1142
  });
1253
1143
  });
1254
1144
  await Promise.all(promises);
1255
- _optionalChain([logger, 'access', _49 => _49.consola, 'optionalAccess', _50 => _50.resumeLogs, 'call', _51 => _51()]);
1145
+ logger.emit("progress_stop", { id: "files" });
1256
1146
  }
1257
- return mergedFiles;
1147
+ return files;
1258
1148
  }
1259
1149
 
1260
1150
 
@@ -1262,4 +1152,4 @@ ${item.source}`)
1262
1152
 
1263
1153
 
1264
1154
  exports.FileManager = FileManager; exports.getSource = getSource; exports.processFiles = processFiles;
1265
- //# sourceMappingURL=chunk-FWU62YO5.cjs.map
1155
+ //# sourceMappingURL=chunk-DCZQYCCO.cjs.map