@kubb/core 3.0.0-alpha.4 → 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-CaejIVBd.d.ts → FileManager-Ceski1W9.d.ts} +47 -47
  2. package/dist/{FileManager--scIq4y4.d.cts → FileManager-wyXRkgIk.d.cts} +47 -47
  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-EFQPHF4E.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-V5THHXXQ.cjs → chunk-DCZQYCCO.cjs} +218 -299
  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-QRIDQ4RG.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 +81 -75
  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 +68 -64
  24. package/dist/index.js.map +1 -1
  25. package/dist/{logger-dzAcLeAA.d.cts → logger-BWFeedRk.d.cts} +17 -2
  26. package/dist/{logger-dzAcLeAA.d.ts → logger-BWFeedRk.d.ts} +17 -2
  27. package/dist/logger.cjs +2 -2
  28. package/dist/logger.d.cts +1 -1
  29. package/dist/logger.d.ts +1 -1
  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 +5 -7
  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 +27 -93
  50. package/src/FileManager.ts +165 -266
  51. package/src/PackageManager.ts +1 -1
  52. package/src/PluginManager.ts +89 -57
  53. package/src/build.ts +7 -26
  54. package/src/logger.ts +6 -7
  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-EFQPHF4E.js.map +0 -1
  64. package/dist/chunk-JKZG2IJR.js +0 -283
  65. package/dist/chunk-JKZG2IJR.js.map +0 -1
  66. package/dist/chunk-PZT4CTBV.cjs +0 -299
  67. package/dist/chunk-PZT4CTBV.cjs.map +0 -1
  68. package/dist/chunk-QRIDQ4RG.cjs.map +0 -1
  69. package/dist/chunk-UUBPTMRW.js +0 -608
  70. package/dist/chunk-UUBPTMRW.js.map +0 -1
  71. package/dist/chunk-V5THHXXQ.cjs.map +0 -1
  72. package/dist/chunk-YTSNYMHW.cjs.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(path2, 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, path2, {
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,90 +342,34 @@ var BarrelManager = class {
304
342
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _options, options);
305
343
  return this;
306
344
  }
307
- getNamedExport(root, item) {
308
- const exportedNames = _parserts.getExports.call(void 0, _path2.default.resolve(root, item.path));
309
- if (!exportedNames) {
310
- return [item];
311
- }
312
- return exportedNames.reduce(
313
- (prev, curr) => {
314
- if (!_optionalChain([prev, 'access', _16 => _16[0], 'optionalAccess', _17 => _17.name]) || !_optionalChain([prev, 'access', _18 => _18[1], 'optionalAccess', _19 => _19.name])) {
315
- return prev;
316
- }
317
- if (curr.isTypeOnly) {
318
- prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
319
- } else {
320
- prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
321
- }
322
- return prev;
323
- },
324
- [
325
- {
326
- ...item,
327
- name: [],
328
- isTypeOnly: false
329
- },
330
- {
331
- ...item,
332
- name: [],
333
- isTypeOnly: true
334
- }
335
- ]
336
- );
337
- }
338
- getNamedExports(root, exports) {
339
- return _optionalChain([exports, 'optionalAccess', _20 => _20.flatMap, 'call', _21 => _21((item) => {
340
- return this.getNamedExport(root, item);
341
- })]);
342
- }
343
- getIndexes(root) {
344
- const { treeNode = {}, isTypeOnly, extName } = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _options);
345
- 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);
346
348
  if (!tree) {
347
349
  return null;
348
350
  }
349
- const fileReducer = (files, treeNode2) => {
350
- if (!treeNode2.children) {
351
+ const fileReducer = (files, treeNode) => {
352
+ if (!treeNode.children) {
351
353
  return [];
352
354
  }
353
- if (treeNode2.children.length > 1) {
354
- const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
355
- const exports = treeNode2.children.filter(Boolean).map((file) => {
356
- const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, file.data.name)}`;
357
- if (importPath.endsWith("index") && file.data.type === "single") {
358
- return void 0;
359
- }
360
- return {
361
- path: extName ? `${importPath}${extName}` : importPath,
362
- isTypeOnly
363
- };
364
- }).filter(Boolean);
365
- files.push({
366
- path: indexPath,
367
- baseName: "index.ts",
368
- source: "",
369
- exports,
370
- exportable: true
371
- });
372
- } else if (treeNode2.children.length === 1) {
373
- const [treeNodeChild] = treeNode2.children;
374
- const indexPath = _path2.default.resolve(treeNode2.data.path, "index.ts");
375
- const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${_chunkPZT4CTBVcjs.trimExtName.call(void 0, treeNodeChild.data.name)}`;
376
- const exports = [
377
- {
378
- path: extName ? `${importPath}${extName}` : importPath,
379
- isTypeOnly
380
- }
381
- ];
382
- files.push({
383
- path: indexPath,
384
- baseName: "index.ts",
385
- source: "",
386
- exports,
387
- exportable: true
388
- });
389
- }
390
- 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) => {
391
373
  fileReducer(files, childItem);
392
374
  });
393
375
  return files;
@@ -397,6 +379,9 @@ var BarrelManager = class {
397
379
  };
398
380
  _options = new WeakMap();
399
381
 
382
+ // src/FileManager.ts
383
+
384
+
400
385
  // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
401
386
  _chunkXCPFG6DOcjs.init_cjs_shims.call(void 0, );
402
387
 
@@ -534,7 +519,7 @@ var PriorityQueue = class {
534
519
  }
535
520
  dequeue() {
536
521
  const item = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).shift();
537
- return _optionalChain([item, 'optionalAccess', _22 => _22.run]);
522
+ return _optionalChain([item, 'optionalAccess', _16 => _16.run]);
538
523
  }
539
524
  filter(options) {
540
525
  return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run);
@@ -583,10 +568,10 @@ var PQueue = class extends import_index.default {
583
568
  ...options
584
569
  };
585
570
  if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
586
- 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})`);
587
572
  }
588
573
  if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
589
- 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})`);
590
575
  }
591
576
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _carryoverConcurrencyCount, options.carryoverConcurrencyCount);
592
577
  _chunkXCPFG6DOcjs.__privateSet.call(void 0, this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0);
@@ -620,7 +605,7 @@ var PQueue = class extends import_index.default {
620
605
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _pending)._++;
621
606
  _chunkXCPFG6DOcjs.__privateWrapper.call(void 0, this, _intervalCount)._++;
622
607
  try {
623
- _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()]);
624
609
  let operation = function_({ signal: options.signal });
625
610
  if (options.timeout) {
626
611
  operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
@@ -856,22 +841,33 @@ onEvent_fn = async function(event, filter) {
856
841
  };
857
842
 
858
843
  // src/FileManager.ts
859
- var _cache, _FileManager_instances, add_fn, addOrAppend_fn;
844
+ var _filesByPath, _files, _FileManager_instances, add_fn, addOrAppend_fn;
860
845
  var _FileManager = class _FileManager {
861
846
  constructor() {
862
847
  _chunkXCPFG6DOcjs.__privateAdd.call(void 0, this, _FileManager_instances);
863
- _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());
864
850
  return this;
865
851
  }
866
852
  get files() {
867
- const files = [];
868
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).forEach((item) => {
869
- files.push(...item.flat(1));
870
- });
871
- 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)));
872
868
  }
873
869
  async add(...files) {
874
- const promises = combineFiles(files).map((file) => {
870
+ const promises = files.map((file) => {
875
871
  if (file.override) {
876
872
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, file);
877
873
  }
@@ -883,42 +879,47 @@ var _FileManager = class _FileManager {
883
879
  }
884
880
  return resolvedFiles[0];
885
881
  }
886
- async getIndexFiles({ root, output, meta, 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 = {} }) {
887
903
  const { exportType = "barrel" } = output;
888
904
  if (exportType === false) {
889
905
  return [];
890
906
  }
891
907
  const pathToBuildFrom = _path.resolve.call(void 0, root, output.path);
892
- if (_chunkPZT4CTBVcjs.transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
908
+ if (_fs.trimExtName.call(void 0, pathToBuildFrom).endsWith("index")) {
893
909
  logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
894
910
  return [];
895
911
  }
896
- 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}`;
897
913
  const mode = _FileManager.getMode(output.path);
898
- const barrelManager = new BarrelManager({
899
- extName: output.extName,
900
- ...options
901
- });
902
- let files = barrelManager.getIndexes(pathToBuildFrom);
903
- if (!files) {
914
+ const barrelManager = new BarrelManager({ ...options, extName: output.extName });
915
+ let indexFiles = barrelManager.getIndexes(files, pathToBuildFrom);
916
+ if (!indexFiles) {
904
917
  return [];
905
918
  }
906
- if (exportType === "barrelNamed") {
907
- files = files.map((file) => {
908
- if (file.exports) {
909
- return {
910
- ...file,
911
- exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
912
- };
913
- }
914
- return file;
915
- });
916
- }
917
919
  const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
918
920
  const rootFile = {
919
921
  path: _path.resolve.call(void 0, root, "index.ts"),
920
922
  baseName: "index.ts",
921
- source: "",
922
923
  exports: [
923
924
  output.exportAs ? {
924
925
  name: output.exportAs,
@@ -930,170 +931,111 @@ var _FileManager = class _FileManager {
930
931
  isTypeOnly: options.isTypeOnly
931
932
  }
932
933
  ],
933
- exportable: true
934
+ sources: [],
935
+ meta: {
936
+ pluginKey: plugin.key
937
+ }
934
938
  };
935
- if (exportType === "barrelNamed" && !output.exportAs && _optionalChain([rootFile, 'access', _32 => _32.exports, 'optionalAccess', _33 => _33[0]])) {
936
- rootFile.exports = barrelManager.getNamedExport(root, rootFile.exports[0]);
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) => {
944
+ return {
945
+ ...exportItem,
946
+ name: void 0
947
+ };
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
+ })]);
937
957
  }
938
958
  return [
939
- ...await Promise.all(
940
- files.map((file) => {
941
- return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
942
- ...file,
943
- meta: meta ? meta : file.meta
944
- });
945
- })
946
- ),
947
- await _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, addOrAppend_fn).call(this, {
948
- ...rootFile,
949
- meta: meta ? meta : rootFile.meta
950
- })
959
+ ...indexFiles.map((indexFile) => {
960
+ return {
961
+ ...indexFile,
962
+ meta: {
963
+ pluginKey: plugin.key
964
+ }
965
+ };
966
+ }),
967
+ rootFile
951
968
  ];
952
969
  }
953
- getCacheByUUID(UUID) {
954
- let cache;
955
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).forEach((files) => {
956
- cache = files.find((item) => item.id === UUID);
957
- });
958
- return cache;
959
- }
960
- get(path2) {
961
- return _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(path2);
962
- }
963
- remove(path2) {
964
- const cacheItem = this.get(path2);
965
- if (!cacheItem) {
966
- return;
967
- }
968
- _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).delete(path2);
969
- }
970
970
  async write(...params) {
971
971
  return _fs.write.call(void 0, ...params);
972
972
  }
973
973
  async read(...params) {
974
974
  return _fs.read.call(void 0, ...params);
975
975
  }
976
- async processFiles(...params) {
977
- return processFiles(...params);
978
- }
979
976
  // statics
980
- static async getSource(file) {
981
- return getSource(file);
982
- }
983
- static combineFiles(files) {
984
- return combineFiles(files);
985
- }
986
977
  static getMode(path2) {
987
978
  if (!path2) {
988
979
  return "split";
989
980
  }
990
981
  return _path.extname.call(void 0, path2) ? "single" : "split";
991
982
  }
992
- static get extensions() {
993
- return [".js", ".ts", ".tsx"];
994
- }
995
- static isJavascript(baseName) {
996
- return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
997
- }
998
983
  };
999
- _cache = new WeakMap();
984
+ _filesByPath = new WeakMap();
985
+ _files = new WeakMap();
1000
986
  _FileManager_instances = new WeakSet();
1001
987
  add_fn = async function(file) {
1002
- const controller = new AbortController();
1003
- const resolvedFile = {
1004
- id: _crypto2.default.randomUUID(),
1005
- name: _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.baseName),
1006
- ...file
1007
- };
1008
- if (_optionalChain([resolvedFile, 'access', _34 => _34.exports, 'optionalAccess', _35 => _35.length])) {
1009
- const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
1010
- resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
1011
- const exportedFile = this.files.find((file2) => file2.path.includes(_path.resolve.call(void 0, folder, exportItem.path)));
1012
- if (exportedFile) {
1013
- return exportedFile.exportable;
1014
- }
1015
- return true;
1016
- });
1017
- }
1018
- _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);
1019
991
  return resolvedFile;
1020
992
  };
1021
993
  addOrAppend_fn = async function(file) {
1022
- const previousCaches = _chunkXCPFG6DOcjs.__privateGet.call(void 0, this, _cache).get(file.path);
1023
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
1024
- if (previousCache) {
1025
- _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);
1026
998
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, {
1027
999
  ...file,
1028
- source: previousCache.source && file.source ? `${previousCache.source}
1029
- ${file.source}` : "",
1030
- imports: [...previousCache.imports || [], ...file.imports || []],
1031
- exports: [...previousCache.exports || [], ...file.exports || []],
1032
- env: { ...previousCache.env || {}, ...file.env || {} }
1000
+ sources: [...previousFile.sources || [], ...file.sources || []],
1001
+ imports: [...previousFile.imports || [], ...file.imports || []],
1002
+ exports: [...previousFile.exports || [], ...file.exports || []]
1033
1003
  });
1034
1004
  }
1035
1005
  return _chunkXCPFG6DOcjs.__privateMethod.call(void 0, this, _FileManager_instances, add_fn).call(this, file);
1036
1006
  };
1037
1007
  var FileManager = _FileManager;
1038
- function combineFiles(files) {
1039
- return files.filter(Boolean).reduce(
1040
- (acc, file) => {
1041
- const prevIndex = acc.findIndex((item) => item.path === file.path);
1042
- if (prevIndex === -1) {
1043
- return [...acc, file];
1044
- }
1045
- const prev = acc[prevIndex];
1046
- if (prev && file.override) {
1047
- acc[prevIndex] = {
1048
- imports: [],
1049
- exports: [],
1050
- ...file
1051
- };
1052
- return acc;
1053
- }
1054
- if (prev) {
1055
- acc[prevIndex] = {
1056
- ...file,
1057
- source: prev.source && file.source ? `${prev.source}
1058
- ${file.source}` : "",
1059
- imports: [...prev.imports || [], ...file.imports || []],
1060
- exports: [...prev.exports || [], ...file.exports || []],
1061
- env: { ...prev.env || {}, ...file.env || {} }
1062
- };
1063
- }
1064
- return acc;
1065
- },
1066
- []
1067
- );
1068
- }
1069
1008
  async function getSource(file) {
1070
- if (file.language ? !["typescript", "javascript"].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
1071
- return file.source;
1072
- }
1073
- 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");
1074
1011
  const exports = file.exports ? combineExports(file.exports) : [];
1075
- const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
1012
+ const imports = file.imports && source ? combineImports(file.imports, exports, source) : [];
1076
1013
  const importNodes = imports.filter((item) => {
1077
1014
  const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1078
- return path2 !== _chunkPZT4CTBVcjs.trimExtName.call(void 0, file.path);
1015
+ return path2 !== _fs.trimExtName.call(void 0, file.path);
1079
1016
  }).map((item) => {
1080
1017
  const path2 = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1081
- return parser.factory.createImportDeclaration({
1018
+ return parser.createImport({
1082
1019
  name: item.name,
1083
1020
  path: item.extName ? `${path2}${item.extName}` : path2,
1084
1021
  isTypeOnly: item.isTypeOnly
1085
1022
  });
1086
1023
  });
1087
- const exportNodes = exports.map(
1088
- (item) => parser.factory.createExportDeclaration({
1089
- name: item.name,
1090
- path: item.extName ? `${item.path}${item.extName}` : item.path,
1091
- isTypeOnly: item.isTypeOnly,
1092
- asAlias: item.asAlias
1093
- })
1094
- );
1095
- const source = [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
1096
- 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
+ });
1097
1039
  }
1098
1040
  function combineExports(exports) {
1099
1041
  const combinedExports = _chunk67C6RBGQcjs.orderBy.call(void 0, exports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
@@ -1107,7 +1049,7 @@ function combineExports(exports) {
1107
1049
  const uniquePrev = prev.findLast(
1108
1050
  (imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
1109
1051
  );
1110
- if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _36 => _36.asAlias]) && !curr.asAlias) {
1052
+ if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _32 => _32.asAlias]) && !curr.asAlias) {
1111
1053
  return prev;
1112
1054
  }
1113
1055
  if (!prevByPath) {
@@ -1127,7 +1069,7 @@ function combineExports(exports) {
1127
1069
  },
1128
1070
  []
1129
1071
  );
1130
- 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]);
1131
1073
  }
1132
1074
  function combineImports(imports, exports, source) {
1133
1075
  const combinedImports = _chunk67C6RBGQcjs.orderBy.call(void 0, imports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
@@ -1175,62 +1117,39 @@ function combineImports(imports, exports, source) {
1175
1117
  },
1176
1118
  []
1177
1119
  );
1178
- return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
1179
- }
1180
- function getEnvSource(source, env) {
1181
- if (!env) {
1182
- return source;
1183
- }
1184
- const keys = Object.keys(env);
1185
- if (!keys.length) {
1186
- return source;
1187
- }
1188
- return keys.reduce((prev, key) => {
1189
- const environmentValue = env[key];
1190
- const replaceBy = environmentValue ? `'${_optionalChain([environmentValue, 'access', _37 => _37.replaceAll, 'call', _38 => _38('"', ""), 'optionalAccess', _39 => _39.replaceAll, 'call', _40 => _40("'", "")])}'` : "undefined";
1191
- if (key.toUpperCase() !== key) {
1192
- throw new TypeError(`Environment should be in upperCase for ${key}`);
1193
- }
1194
- if (typeof replaceBy === "string") {
1195
- prev = _chunkPZT4CTBVcjs.searchAndReplace.call(void 0, {
1196
- text: prev.replaceAll(`process.env.${key}`, replaceBy),
1197
- replaceBy,
1198
- prefix: "process.env",
1199
- key
1200
- });
1201
- prev = _chunkPZT4CTBVcjs.searchAndReplace.call(void 0, {
1202
- text: prev.replaceAll(/(declare const).*\n/gi, ""),
1203
- replaceBy,
1204
- key
1205
- });
1206
- }
1207
- return prev;
1208
- }, source);
1120
+ return _chunk67C6RBGQcjs.orderBy.call(void 0, combinedImports, [(v) => !v.isTypeOnly]);
1209
1121
  }
1210
- var queue = new PQueue({ concurrency: 1 });
1211
- async function processFiles({ dryRun, logger, files }) {
1212
- const mergedFiles = await Promise.all(
1213
- files.map(async (file) => ({
1214
- ...file,
1215
- source: await FileManager.getSource(file)
1216
- }))
1217
- );
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
+ });
1218
1134
  if (!dryRun) {
1219
- _optionalChain([logger, 'access', _41 => _41.consola, 'optionalAccess', _42 => _42.pauseLogs, 'call', _43 => _43()]);
1220
- const filePromises = mergedFiles.map(async (file, index) => {
1221
- await queue.add(() => {
1222
- logger.emit("progress", index, mergedFiles.length);
1223
- return _fs.write.call(void 0, file.path, file.source, { sanity: false });
1135
+ const size = orderedFiles.length;
1136
+ logger.emit("progress_start", { id: "files", size });
1137
+ const promises = orderedFiles.map(async (file) => {
1138
+ await queue.add(async () => {
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) : "" });
1224
1142
  });
1225
1143
  });
1226
- await Promise.all(filePromises);
1227
- _optionalChain([logger, 'access', _44 => _44.consola, 'optionalAccess', _45 => _45.resumeLogs, 'call', _46 => _46()]);
1144
+ await Promise.all(promises);
1145
+ logger.emit("progress_stop", { id: "files" });
1228
1146
  }
1229
- return mergedFiles;
1147
+ return files;
1230
1148
  }
1231
1149
 
1232
1150
 
1233
1151
 
1234
1152
 
1235
- exports.FileManager = FileManager; exports.processFiles = processFiles;
1236
- //# sourceMappingURL=chunk-V5THHXXQ.cjs.map
1153
+
1154
+ exports.FileManager = FileManager; exports.getSource = getSource; exports.processFiles = processFiles;
1155
+ //# sourceMappingURL=chunk-DCZQYCCO.cjs.map