@kubb/core 3.0.0-alpha.9 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +14 -5
  2. package/dist/{FileManager-B0GJlthB.d.cts → FileManager-C9aZTwst.d.ts} +94 -77
  3. package/dist/{FileManager-BFycBDqG.d.ts → FileManager-ibNoWwHN.d.cts} +94 -77
  4. package/dist/chunk-2EU7DMPM.js +2 -3
  5. package/dist/chunk-2EU7DMPM.js.map +1 -1
  6. package/dist/{chunk-DID47EQD.cjs → chunk-2TOEDZ2U.cjs} +6 -7
  7. package/dist/chunk-2TOEDZ2U.cjs.map +1 -0
  8. package/dist/{chunk-A6PCLWEY.cjs → chunk-4GJEWGQN.cjs} +30 -31
  9. package/dist/chunk-4GJEWGQN.cjs.map +1 -0
  10. package/dist/{chunk-SEH6NUCX.cjs → chunk-72BWXKV4.cjs} +10 -10
  11. package/dist/chunk-72BWXKV4.cjs.map +1 -0
  12. package/dist/{chunk-4X5FFJPJ.js → chunk-BQXM32UO.js} +11 -16
  13. package/dist/chunk-BQXM32UO.js.map +1 -0
  14. package/dist/{chunk-27CPVXAT.js → chunk-DXGMSPTW.js} +174 -231
  15. package/dist/chunk-DXGMSPTW.js.map +1 -0
  16. package/dist/{chunk-SCR3LUXT.js → chunk-E6CN2CZC.js} +38 -27
  17. package/dist/chunk-E6CN2CZC.js.map +1 -0
  18. package/dist/chunk-HBQM723K.js +12 -26
  19. package/dist/chunk-HBQM723K.js.map +1 -1
  20. package/dist/{chunk-5E2I6KH4.cjs → chunk-KXT7F2WS.cjs} +54 -37
  21. package/dist/chunk-KXT7F2WS.cjs.map +1 -0
  22. package/dist/{chunk-IPZQXBA2.cjs → chunk-MVWRVN66.cjs} +57 -34
  23. package/dist/chunk-MVWRVN66.cjs.map +1 -0
  24. package/dist/{chunk-5IGANEGE.cjs → chunk-SQBOUPF4.cjs} +268 -301
  25. package/dist/chunk-SQBOUPF4.cjs.map +1 -0
  26. package/dist/index.cjs +223 -241
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +4 -6
  29. package/dist/index.d.ts +4 -6
  30. package/dist/index.js +106 -148
  31. package/dist/index.js.map +1 -1
  32. package/dist/{logger-BWFeedRk.d.cts → logger-DvbHXjIO.d.cts} +10 -8
  33. package/dist/{logger-BWFeedRk.d.ts → logger-DvbHXjIO.d.ts} +10 -8
  34. package/dist/logger.cjs +25 -14
  35. package/dist/logger.cjs.map +1 -1
  36. package/dist/logger.d.cts +1 -1
  37. package/dist/logger.d.ts +1 -1
  38. package/dist/logger.js +3 -13
  39. package/dist/logger.js.map +1 -1
  40. package/dist/mocks.cjs +29 -24
  41. package/dist/mocks.cjs.map +1 -1
  42. package/dist/mocks.d.cts +4 -3
  43. package/dist/mocks.d.ts +4 -3
  44. package/dist/mocks.js +22 -25
  45. package/dist/mocks.js.map +1 -1
  46. package/dist/{prompt-DVQN7JTN.cjs → prompt-FODZPXQF.cjs} +89 -89
  47. package/dist/prompt-FODZPXQF.cjs.map +1 -0
  48. package/dist/prompt-WQQUN22Z.js +8 -13
  49. package/dist/prompt-WQQUN22Z.js.map +1 -1
  50. package/dist/transformers.cjs +63 -52
  51. package/dist/transformers.cjs.map +1 -1
  52. package/dist/transformers.d.cts +1 -1
  53. package/dist/transformers.d.ts +1 -1
  54. package/dist/transformers.js +10 -37
  55. package/dist/transformers.js.map +1 -1
  56. package/dist/utils.cjs +65 -34
  57. package/dist/utils.cjs.map +1 -1
  58. package/dist/utils.d.cts +6 -8
  59. package/dist/utils.d.ts +6 -8
  60. package/dist/utils.js +3 -33
  61. package/dist/utils.js.map +1 -1
  62. package/package.json +10 -13
  63. package/src/BarrelManager.ts +76 -74
  64. package/src/FileManager.ts +55 -60
  65. package/src/PluginManager.ts +61 -61
  66. package/src/PromiseManager.ts +1 -1
  67. package/src/__snapshots__/barrel.json +11 -29
  68. package/src/__snapshots__/grouped.json +18 -12
  69. package/src/__snapshots__/ordered.json +18 -12
  70. package/src/build.ts +24 -11
  71. package/src/config.ts +2 -4
  72. package/src/index.ts +1 -1
  73. package/src/logger.ts +41 -7
  74. package/src/plugin.ts +0 -3
  75. package/src/transformers/escape.ts +0 -10
  76. package/src/transformers/stringify.ts +1 -1
  77. package/src/types.ts +70 -38
  78. package/src/utils/TreeNode.ts +31 -56
  79. package/src/utils/executeStrategies.ts +2 -2
  80. package/src/utils/parser.ts +38 -39
  81. package/dist/chunk-27CPVXAT.js.map +0 -1
  82. package/dist/chunk-4X5FFJPJ.js.map +0 -1
  83. package/dist/chunk-5E2I6KH4.cjs.map +0 -1
  84. package/dist/chunk-5IGANEGE.cjs.map +0 -1
  85. package/dist/chunk-A6PCLWEY.cjs.map +0 -1
  86. package/dist/chunk-DID47EQD.cjs.map +0 -1
  87. package/dist/chunk-IPZQXBA2.cjs.map +0 -1
  88. package/dist/chunk-SCR3LUXT.js.map +0 -1
  89. package/dist/chunk-SEH6NUCX.cjs.map +0 -1
  90. package/dist/prompt-DVQN7JTN.cjs.map +0 -1
  91. package/src/utils/cache.ts +0 -35
@@ -1,7 +1,9 @@
1
- import {
2
- camelCase,
3
- orderBy
4
- } from "./chunk-4X5FFJPJ.js";
1
+ import { orderBy, camelCase } from './chunk-BQXM32UO.js';
2
+ import path, { join, extname, relative } from 'node:path';
3
+ import { trimExtName, write, read, getRelativePath } from '@kubb/fs';
4
+ import hash from 'object-hash';
5
+ import { isDeepEqual } from 'remeda';
6
+ import PQueue from 'p-queue';
5
7
 
6
8
  // src/utils/FunctionParams.ts
7
9
  var FunctionParams = class _FunctionParams {
@@ -173,8 +175,8 @@ function setUniqueName(originalName, data) {
173
175
  // src/utils/URLPath.ts
174
176
  var URLPath = class {
175
177
  path;
176
- constructor(path) {
177
- this.path = path;
178
+ constructor(path2) {
179
+ this.path = path2;
178
180
  return this;
179
181
  }
180
182
  /**
@@ -268,24 +270,12 @@ var URLPath = class {
268
270
  }
269
271
  };
270
272
 
271
- // src/utils/parser.ts
272
- import { extname as extname2 } from "node:path";
273
- import { getRelativePath as getRelativePath2 } from "@kubb/fs";
274
- import hash from "object-hash";
275
-
276
- // src/FileManager.ts
277
- import { extname, join as join2, relative } from "node:path";
278
- import { isDeepEqual } from "remeda";
279
- import { read, write } from "@kubb/fs";
280
-
281
- // src/BarrelManager.ts
282
- import { join } from "node:path";
283
-
284
273
  // src/utils/TreeNode.ts
285
274
  var TreeNode = class _TreeNode {
286
275
  data;
287
276
  parent;
288
277
  children = [];
278
+ #cachedLeaves = void 0;
289
279
  constructor(data, parent) {
290
280
  this.data = data;
291
281
  this.parent = parent;
@@ -299,41 +289,28 @@ var TreeNode = class _TreeNode {
299
289
  this.children.push(child);
300
290
  return child;
301
291
  }
302
- find(data) {
303
- if (!data) {
304
- return null;
305
- }
306
- if (data === this.data) {
292
+ get root() {
293
+ if (!this.parent) {
307
294
  return this;
308
295
  }
309
- if (this.children?.length) {
310
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
311
- target = this.children[i].find(data);
312
- if (target) {
313
- return target;
314
- }
315
- }
316
- }
317
- return null;
296
+ return this.parent.root;
318
297
  }
319
298
  get leaves() {
320
299
  if (!this.children || this.children.length === 0) {
321
300
  return [this];
322
301
  }
302
+ if (this.#cachedLeaves) {
303
+ return this.#cachedLeaves;
304
+ }
323
305
  const leaves = [];
324
306
  if (this.children) {
325
307
  for (let i = 0, { length } = this.children; i < length; i++) {
326
308
  leaves.push.apply(leaves, this.children[i].leaves);
327
309
  }
328
310
  }
311
+ this.#cachedLeaves = leaves;
329
312
  return leaves;
330
313
  }
331
- get root() {
332
- if (!this.parent) {
333
- return this;
334
- }
335
- return this.parent.root;
336
- }
337
314
  forEach(callback) {
338
315
  if (typeof callback !== "function") {
339
316
  throw new TypeError("forEach() callback must be a function");
@@ -346,35 +323,29 @@ var TreeNode = class _TreeNode {
346
323
  }
347
324
  return this;
348
325
  }
349
- filter(callback) {
350
- let data = [];
326
+ findDeep(predicate) {
327
+ if (typeof predicate !== "function") {
328
+ throw new TypeError("find() predicate must be a function");
329
+ }
330
+ return this.leaves.find(predicate);
331
+ }
332
+ forEachDeep(callback) {
351
333
  if (typeof callback !== "function") {
352
334
  throw new TypeError("forEach() callback must be a function");
353
335
  }
354
- if (callback(this)) {
355
- data.push(this);
356
- }
357
- if (this.children) {
358
- for (let i = 0, { length } = this.children; i < length; i++) {
359
- const childData = this.children[i]?.filter(callback).filter(Boolean) || [];
360
- data = [.../* @__PURE__ */ new Set([...data, ...childData])];
361
- }
362
- }
363
- return data;
336
+ this.leaves.forEach(callback);
364
337
  }
365
- map(callback) {
366
- let data = [];
338
+ filterDeep(callback) {
367
339
  if (typeof callback !== "function") {
368
- throw new TypeError("forEach() callback must be a function");
340
+ throw new TypeError("filter() callback must be a function");
369
341
  }
370
- data.push(callback(this));
371
- if (this.children) {
372
- for (let i = 0, { length } = this.children; i < length; i++) {
373
- const childData = this.children[i]?.map(callback).filter(Boolean) || [];
374
- data = [.../* @__PURE__ */ new Set([...data, ...childData])];
375
- }
342
+ return this.leaves.filter(callback);
343
+ }
344
+ mapDeep(callback) {
345
+ if (typeof callback !== "function") {
346
+ throw new TypeError("map() callback must be a function");
376
347
  }
377
- return data;
348
+ return this.leaves.map(callback);
378
349
  }
379
350
  static build(files, root) {
380
351
  try {
@@ -420,8 +391,8 @@ function buildDirectoryTree(files, rootFolder = "") {
420
391
  children: []
421
392
  };
422
393
  filteredFiles.forEach((file) => {
423
- const path = file.path.slice(rootFolder.length);
424
- const parts = path.split("/");
394
+ const path2 = file.path.slice(rootFolder.length);
395
+ const parts = path2.split("/");
425
396
  let currentLevel = root.children;
426
397
  let currentPath = rootFolder;
427
398
  parts.forEach((part, index) => {
@@ -454,25 +425,29 @@ function buildDirectoryTree(files, rootFolder = "") {
454
425
  });
455
426
  return root;
456
427
  }
457
-
458
- // src/BarrelManager.ts
459
- import { getRelativePath } from "@kubb/fs";
460
428
  var BarrelManager = class {
461
429
  #options;
462
430
  constructor(options = {}) {
463
431
  this.#options = options;
464
432
  return this;
465
433
  }
466
- getFiles(generatedFiles, root) {
434
+ getFiles({ files: generatedFiles, root, meta }) {
467
435
  const { logger } = this.#options;
468
- const files = /* @__PURE__ */ new Map();
436
+ const cachedFiles = /* @__PURE__ */ new Map();
437
+ logger?.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join(".")} and root '${root}'`] });
469
438
  TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
470
439
  if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
471
440
  return void 0;
472
441
  }
473
- const barrelPath = join(treeNode.parent?.data.path, "index.ts");
442
+ const barrelFile = {
443
+ path: join(treeNode.parent?.data.path, "index.ts"),
444
+ baseName: "index.ts",
445
+ exports: [],
446
+ sources: []
447
+ };
448
+ const previousBarrelFile = cachedFiles.get(barrelFile.path);
474
449
  const leaves = treeNode.leaves;
475
- const exports = leaves.map((item) => {
450
+ leaves.forEach((item) => {
476
451
  if (!item.data.name) {
477
452
  return void 0;
478
453
  }
@@ -484,96 +459,88 @@ var BarrelManager = class {
484
459
  File: ${JSON.stringify(item.data.file, void 0, 2)}`
485
460
  );
486
461
  }
487
- return sources.map((source) => {
488
- if (!item.data.file?.path || !source.isIndexable) {
462
+ sources.forEach((source) => {
463
+ if (!item.data.file?.path || !source.isIndexable || !source.name) {
464
+ return void 0;
465
+ }
466
+ const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item2) => item2.name === source.name);
467
+ if (alreadyContainInPreviousBarrelFile) {
489
468
  return void 0;
490
469
  }
470
+ if (!barrelFile.exports) {
471
+ barrelFile.exports = [];
472
+ }
491
473
  const isSubExport = !!treeNode.parent?.data.path?.split?.("/")?.length;
492
474
  if (isSubExport) {
493
- return {
475
+ barrelFile.exports.push({
494
476
  name: [source.name],
495
477
  path: getRelativePath(treeNode.parent?.data.path, item.data.path),
496
478
  isTypeOnly: source.isTypeOnly
497
- };
498
- }
499
- return {
500
- name: [source.name],
501
- path: `./${item.data.file.baseName}`,
502
- isTypeOnly: source.isTypeOnly
503
- };
504
- });
505
- }).flat().filter(Boolean);
506
- const barrelFile = {
507
- path: barrelPath,
508
- baseName: "index.ts",
509
- exports,
510
- sources: exports.flatMap((item) => {
511
- if (Array.isArray(item.name)) {
512
- return item.name.map((name) => {
513
- return {
514
- name,
515
- isTypeOnly: item.isTypeOnly,
516
- //TODO use parser to generate import
517
- value: "",
518
- isExportable: false,
519
- isIndexable: false
520
- };
479
+ });
480
+ } else {
481
+ barrelFile.exports.push({
482
+ name: [source.name],
483
+ path: `./${item.data.file.baseName}`,
484
+ isTypeOnly: source.isTypeOnly
521
485
  });
522
486
  }
523
- return [
524
- {
525
- name: item.name,
526
- isTypeOnly: item.isTypeOnly,
527
- //TODO use parser to generate import
528
- value: "",
529
- isExportable: false,
530
- isIndexable: false
531
- }
532
- ];
533
- })
534
- };
535
- const previousBarrelFile = files.get(barrelFile.path);
536
- if (previousBarrelFile) {
537
- files.set(barrelFile.path, {
538
- ...previousBarrelFile,
539
- ...barrelFile,
540
- exports: combineExports([...previousBarrelFile.exports || [], ...barrelFile.exports || []]),
541
- sources: combineSources([...previousBarrelFile.sources || [], ...barrelFile.sources || []])
487
+ barrelFile.sources.push({
488
+ name: source.name,
489
+ isTypeOnly: source.isTypeOnly,
490
+ //TODO use parser to generate import
491
+ value: "",
492
+ isExportable: false,
493
+ isIndexable: false
494
+ });
542
495
  });
496
+ });
497
+ logger?.emit("debug", {
498
+ date: /* @__PURE__ */ new Date(),
499
+ logs: [
500
+ `Generating barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with ${barrelFile.sources.length} indexable exports: '${barrelFile.sources?.map((source) => source.name).join(", ")}'`
501
+ ]
502
+ });
503
+ logger?.emit("debug", {
504
+ date: /* @__PURE__ */ new Date(),
505
+ logs: [
506
+ `Generated barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with exports: '${cachedFiles.get(barrelFile.path)?.sources?.map((source) => source.name).join(", ")}'`
507
+ ]
508
+ });
509
+ if (previousBarrelFile) {
510
+ previousBarrelFile.sources.push(...barrelFile.sources);
511
+ previousBarrelFile.exports?.push(...barrelFile.exports || []);
543
512
  } else {
544
- files.set(barrelFile.path, barrelFile);
513
+ cachedFiles.set(barrelFile.path, barrelFile);
545
514
  }
546
515
  });
547
- return [...files.values()];
516
+ return [...cachedFiles.values()];
548
517
  }
549
518
  };
550
-
551
- // src/FileManager.ts
552
- import { trimExtName } from "@kubb/fs";
553
- import PQueue from "p-queue";
554
519
  var FileManager = class {
555
520
  #filesByPath = /* @__PURE__ */ new Map();
556
- #files = /* @__PURE__ */ new Set();
557
521
  constructor() {
558
522
  return this;
559
523
  }
560
524
  get files() {
561
- return Array.from(this.#files);
525
+ return [...this.#filesByPath.values()];
562
526
  }
563
527
  get orderedFiles() {
564
- return orderBy(Array.from(this.#files), [
565
- (v) => v?.meta && "pluginKey" in v.meta && !v.meta.pluginKey,
566
- (v) => v.path.length,
567
- (v) => trimExtName(v.path).endsWith("index"),
568
- (v) => trimExtName(v.baseName),
569
- (v) => v.path.split(".").pop()
570
- ]);
528
+ return orderBy(
529
+ [...this.#filesByPath.values()],
530
+ [
531
+ (v) => v?.meta && "pluginKey" in v.meta && !v.meta.pluginKey,
532
+ (v) => v.path.length,
533
+ (v) => trimExtName(v.path).endsWith("index"),
534
+ (v) => trimExtName(v.baseName),
535
+ (v) => v.path.split(".").pop()
536
+ ]
537
+ );
571
538
  }
572
539
  get groupedFiles() {
573
- return buildDirectoryTree(Array.from(this.#files));
540
+ return buildDirectoryTree([...this.#filesByPath.values()]);
574
541
  }
575
542
  get treeNode() {
576
- return TreeNode.build(Array.from(this.#files));
543
+ return TreeNode.build([...this.#filesByPath.values()]);
577
544
  }
578
545
  async add(...files) {
579
546
  const promises = files.map((file) => {
@@ -591,55 +558,44 @@ var FileManager = class {
591
558
  async #add(file) {
592
559
  const resolvedFile = createFile(file);
593
560
  this.#filesByPath.set(resolvedFile.path, resolvedFile);
594
- this.#files.add(resolvedFile);
595
561
  return resolvedFile;
596
562
  }
597
563
  clear() {
598
564
  this.#filesByPath.clear();
599
- this.#files.clear();
600
565
  }
601
566
  async #addOrAppend(file) {
602
567
  const previousFile = this.#filesByPath.get(file.path);
603
568
  if (previousFile) {
604
569
  this.#filesByPath.delete(previousFile.path);
605
- this.#files.delete(previousFile);
606
570
  return this.#add(mergeFile(previousFile, file));
607
571
  }
608
572
  return this.#add(file);
609
573
  }
610
574
  getCacheById(id) {
611
- let cache;
612
- this.#files.forEach((file) => {
613
- if (file.id === id) {
614
- cache = file;
615
- }
616
- });
617
- return cache;
575
+ return [...this.#filesByPath.values()].find((file) => file.id === id);
618
576
  }
619
- getByPath(path) {
620
- return this.#filesByPath.get(path);
577
+ getByPath(path2) {
578
+ return this.#filesByPath.get(path2);
621
579
  }
622
- deleteByPath(path) {
623
- const cacheItem = this.getByPath(path);
580
+ deleteByPath(path2) {
581
+ const cacheItem = this.getByPath(path2);
624
582
  if (!cacheItem) {
625
583
  return;
626
584
  }
627
- this.#filesByPath.delete(path);
628
- this.#files.delete(cacheItem);
585
+ this.#filesByPath.delete(path2);
629
586
  }
630
- async getBarrelFiles({ files, meta, root, output, logger }) {
631
- const { exportType = "barrelNamed" } = output;
632
- const barrelManager = new BarrelManager({ logger });
633
- if (exportType === false) {
587
+ async getBarrelFiles({ type, files, meta = {}, root, output, logger }) {
588
+ if (!type) {
634
589
  return [];
635
590
  }
636
- const pathToBuildFrom = join2(root, output.path);
591
+ const barrelManager = new BarrelManager({ logger });
592
+ const pathToBuildFrom = join(root, output.path);
637
593
  if (trimExtName(pathToBuildFrom).endsWith("index")) {
638
594
  logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
639
595
  return [];
640
596
  }
641
- const barrelFiles = barrelManager.getFiles(files, pathToBuildFrom);
642
- if (exportType === "barrel") {
597
+ const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta });
598
+ if (type === "all") {
643
599
  return barrelFiles.map((file) => {
644
600
  return {
645
601
  ...file,
@@ -666,16 +622,17 @@ var FileManager = class {
666
622
  return read(...params);
667
623
  }
668
624
  // statics
669
- static getMode(path) {
670
- if (!path) {
625
+ static getMode(path2) {
626
+ if (!path2) {
671
627
  return "split";
672
628
  }
673
- return extname(path) ? "single" : "split";
629
+ return extname(path2) ? "single" : "split";
674
630
  }
675
631
  };
676
- async function getSource(file, { logger } = {}) {
677
- const parser = await getFileParser(file.extName);
678
- return parser.print(file, { logger });
632
+ async function getSource(file, { logger, extname: extname2 } = {}) {
633
+ const parser = await getFileParser(file.extname);
634
+ const source = await parser.print(file, { logger, extname: extname2 });
635
+ return parser.format(source);
679
636
  }
680
637
  function mergeFile(a, b) {
681
638
  return {
@@ -688,7 +645,7 @@ function mergeFile(a, b) {
688
645
  function combineSources(sources) {
689
646
  return sources.reduce(
690
647
  (prev, curr) => {
691
- const prevByName = prev.findLast((imp) => imp.name === curr.name);
648
+ const prevByName = prev.findLast((imp) => imp.name && imp.name === curr.name);
692
649
  const prevByPathAndIsExportable = prev.findLast((imp) => imp.name === curr.name && imp.isExportable);
693
650
  if (prevByPathAndIsExportable) {
694
651
  return [...prev, curr];
@@ -706,7 +663,13 @@ function combineSources(sources) {
706
663
  );
707
664
  }
708
665
  function combineExports(exports) {
709
- const combinedExports = exports.reduce(
666
+ return orderBy(exports, [
667
+ (v) => !!Array.isArray(v.name),
668
+ (v) => !v.isTypeOnly,
669
+ (v) => v.path,
670
+ (v) => !!v.name,
671
+ (v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
672
+ ]).reduce(
710
673
  (prev, curr) => {
711
674
  const name = curr.name;
712
675
  const prevByPath = prev.findLast((imp) => imp.path === curr.path);
@@ -737,23 +700,24 @@ function combineExports(exports) {
737
700
  },
738
701
  []
739
702
  );
740
- return orderBy(combinedExports, [
703
+ }
704
+ function combineImports(imports, exports, source) {
705
+ return orderBy(imports, [
741
706
  (v) => !!Array.isArray(v.name),
742
707
  (v) => !v.isTypeOnly,
743
708
  (v) => v.path,
744
709
  (v) => !!v.name,
745
710
  (v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
746
- ]);
747
- }
748
- function combineImports(imports, exports, source) {
749
- const combinedImports = imports.reduce(
711
+ ]).reduce(
750
712
  (prev, curr) => {
751
713
  let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
752
714
  const hasImportInSource = (importName) => {
753
715
  if (!source) {
754
716
  return true;
755
717
  }
756
- const checker = (name2) => name2 && !!source.includes(name2);
718
+ const checker = (name2) => {
719
+ return name2 && !!source.includes(name2);
720
+ };
757
721
  return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
758
722
  };
759
723
  if (curr.path === curr.root) {
@@ -791,13 +755,6 @@ function combineImports(imports, exports, source) {
791
755
  },
792
756
  []
793
757
  );
794
- return orderBy(combinedImports, [
795
- (v) => !!Array.isArray(v.name),
796
- (v) => !v.isTypeOnly,
797
- (v) => v.path,
798
- (v) => !!v.name,
799
- (v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
800
- ]);
801
758
  }
802
759
  var queue = new PQueue({ concurrency: 100 });
803
760
  async function processFiles({ dryRun, config, logger, files }) {
@@ -807,18 +764,20 @@ async function processFiles({ dryRun, config, logger, files }) {
807
764
  (v) => trimExtName(v.path).endsWith("index")
808
765
  ]);
809
766
  logger.emit("debug", {
767
+ date: /* @__PURE__ */ new Date(),
810
768
  logs: [JSON.stringify({ files: orderedFiles }, null, 2)],
811
- fileName: "kubb-files.json",
812
- override: true
769
+ fileName: "kubb-files.log"
813
770
  });
814
771
  if (!dryRun) {
815
772
  const size = orderedFiles.length;
816
- logger.emit("progress_start", { id: "files", size });
773
+ logger.emit("progress_start", { id: "files", size, message: "Writing files ..." });
817
774
  const promises = orderedFiles.map(async (file) => {
818
775
  await queue.add(async () => {
819
- const source = await getSource(file, { logger });
776
+ const message = file ? `Writing ${relative(config.root, file.path)}` : "";
777
+ const extname2 = config.output.extension?.[file.extname];
778
+ const source = await getSource(file, { logger, extname: extname2 });
820
779
  await write(file.path, source, { sanity: false });
821
- logger.emit("progress", { id: "files", data: file ? relative(config.root, file.path) : "" });
780
+ logger.emit("progressed", { id: "files", message });
822
781
  });
823
782
  });
824
783
  await Promise.all(promises);
@@ -829,9 +788,9 @@ async function processFiles({ dryRun, config, logger, files }) {
829
788
 
830
789
  // src/utils/parser.ts
831
790
  function createFile(file) {
832
- const extName = extname2(file.baseName);
833
- if (!extName) {
834
- throw new Error(`No extName found for ${file.baseName}`);
791
+ const extname2 = path.extname(file.baseName);
792
+ if (!extname2) {
793
+ throw new Error(`No extname found for ${file.baseName}`);
835
794
  }
836
795
  const source = file.sources.map((item) => item.value).join("\n\n");
837
796
  const exports = file.exports ? combineExports(file.exports) : [];
@@ -841,63 +800,64 @@ function createFile(file) {
841
800
  ...file,
842
801
  id: hash({ path: file.path }),
843
802
  name: trimExtName2(file.baseName),
844
- extName,
803
+ extname: extname2,
845
804
  imports: imports.map((item) => createFileImport(item)),
846
805
  exports: exports.map((item) => createFileExport(item)),
847
- sources: sources.map((item) => createFileSource(item))
806
+ sources: sources.map((item) => createFileSource(item)),
807
+ meta: file.meta || {}
848
808
  };
849
809
  }
850
810
  function createFileSource(source) {
851
811
  return source;
852
812
  }
853
813
  function createFileImport(imp) {
854
- const extName = extname2(imp.path);
855
814
  return {
856
- ...imp,
857
- extName: imp.extName ? imp.extName : extName
815
+ ...imp
858
816
  };
859
817
  }
860
818
  function createFileExport(exp) {
861
- const extName = extname2(exp.path);
862
819
  return {
863
- ...exp,
864
- extName: exp.extName ? exp.extName : extName
820
+ ...exp
865
821
  };
866
822
  }
867
823
  function createFileParser(parser) {
868
824
  return parser;
869
825
  }
870
826
  var typeScriptParser = createFileParser({
871
- render() {
872
- return void 0;
827
+ async format(source) {
828
+ const module = await import('@kubb/parser-ts');
829
+ return module.format(source);
873
830
  },
874
- async print(file) {
875
- const module = await import("@kubb/parser-ts");
831
+ async print(file, options = { extname: ".ts" }) {
832
+ const module = await import('@kubb/parser-ts');
833
+ const source = file.sources.map((item) => item.value).join("\n\n");
876
834
  const importNodes = file.imports.map((item) => {
877
- const path = item.root ? getRelativePath2(item.root, item.path) : item.path;
835
+ const importPath = item.root ? getRelativePath(item.root, item.path) : item.path;
836
+ const hasExtname = !!path.extname(importPath);
878
837
  return module.factory.createImportDeclaration({
879
838
  name: item.name,
880
- path,
839
+ path: options.extname && hasExtname ? `${trimExtName2(importPath)}${options.extname}` : trimExtName2(importPath),
881
840
  isTypeOnly: item.isTypeOnly
882
841
  });
883
842
  }).filter(Boolean);
884
843
  const exportNodes = file.exports.map((item) => {
844
+ const exportPath = item.path;
845
+ const hasExtname = !!path.extname(exportPath);
885
846
  return module.factory.createExportDeclaration({
886
847
  name: item.name,
887
- path: item.path,
848
+ path: options.extname && hasExtname ? `${trimExtName2(item.path)}${options.extname}` : trimExtName2(item.path),
888
849
  isTypeOnly: item.isTypeOnly,
889
850
  asAlias: item.asAlias
890
851
  });
891
852
  }).filter(Boolean);
892
- const source = [module.print([...importNodes, ...exportNodes]), file.sources.map((item) => item.value).join("\n\n")].join("\n");
893
- return module.print([], { source, noEmitHelpers: false });
853
+ return [file.banner, module.print([...importNodes, ...exportNodes]), source, file.footer].join("\n");
894
854
  }
895
855
  });
896
856
  var defaultParser = createFileParser({
897
- render() {
898
- return void 0;
857
+ async format(source) {
858
+ return source;
899
859
  },
900
- async print(file, { logger }) {
860
+ async print(file) {
901
861
  return file.sources.map((item) => item.value).join("\n\n");
902
862
  }
903
863
  });
@@ -908,38 +868,21 @@ var parsers = {
908
868
  ".tsx": typeScriptParser,
909
869
  ".json": defaultParser
910
870
  };
911
- async function getFileParser(extName) {
912
- if (!extName) {
871
+ async function getFileParser(extname2) {
872
+ if (!extname2) {
913
873
  return defaultParser;
914
874
  }
915
- const parser = parsers[extName];
875
+ const parser = parsers[extname2];
916
876
  if (!parser) {
917
- console.warn(`[parser] No parser found for ${extName}, default parser will be used`);
877
+ console.warn(`[parser] No parser found for ${extname2}, default parser will be used`);
918
878
  }
919
879
  return parser || defaultParser;
920
880
  }
921
881
  function trimExtName2(text) {
922
- const extName = text.split(".").pop();
923
- return text.replace(`.${extName}`, "");
882
+ const extname2 = text.split(".").pop();
883
+ return text.replace(`.${extname2}`, "");
924
884
  }
925
885
 
926
- export {
927
- FunctionParams,
928
- isPromise,
929
- isPromiseFulfilledResult,
930
- isPromiseRejectedResult,
931
- renderTemplate,
932
- timeout,
933
- getUniqueName,
934
- setUniqueName,
935
- URLPath,
936
- createFile,
937
- createFileImport,
938
- createFileExport,
939
- createFileParser,
940
- getFileParser,
941
- FileManager,
942
- getSource,
943
- processFiles
944
- };
945
- //# sourceMappingURL=chunk-27CPVXAT.js.map
886
+ export { FileManager, FunctionParams, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getSource, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, processFiles, renderTemplate, setUniqueName, timeout };
887
+ //# sourceMappingURL=chunk-DXGMSPTW.js.map
888
+ //# sourceMappingURL=chunk-DXGMSPTW.js.map