@kubb/core 2.0.0-beta.6 → 2.0.0-beta.8

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.
package/dist/index.cjs CHANGED
@@ -521,9 +521,9 @@ function isInputPath(result) {
521
521
 
522
522
  // src/utils/timeout.ts
523
523
  async function timeout(ms) {
524
- return new Promise((resolve2) => {
524
+ return new Promise((resolve3) => {
525
525
  setTimeout(() => {
526
- resolve2(true);
526
+ resolve3(true);
527
527
  }, ms);
528
528
  });
529
529
  }
@@ -677,78 +677,67 @@ var TreeNode = class _TreeNode {
677
677
  var _options;
678
678
  var BarrelManager = class {
679
679
  constructor(options = {}) {
680
- __privateAdd(this, _options, {});
680
+ __privateAdd(this, _options, void 0);
681
681
  __privateSet(this, _options, options);
682
682
  return this;
683
683
  }
684
- getIndexes(root, extName) {
685
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
686
- const extMapper = {
687
- ".ts": {
688
- extensions: /\.ts/,
689
- exclude: [/schemas/, /json/]
690
- },
691
- ".json": {
692
- extensions: /\.json/,
693
- exclude: []
694
- }
695
- };
696
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
684
+ getIndexes(pathToBuild) {
685
+ const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
686
+ const tree = TreeNode.build(pathToBuild, treeNode);
697
687
  if (!tree) {
698
688
  return null;
699
689
  }
700
- const fileReducer = (files2, currentTree) => {
701
- if (!currentTree.children) {
690
+ const fileReducer = (files, treeNode2) => {
691
+ if (!treeNode2.children) {
702
692
  return [];
703
693
  }
704
- if (currentTree.children?.length > 1) {
705
- const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
706
- const exports = currentTree.children.filter(Boolean).map((file) => {
707
- const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
708
- if (importPath.includes("index") && file.data.type === "file") {
694
+ if (treeNode2.children.length > 1) {
695
+ const indexPath = path4__default.default.resolve(treeNode2.data.path, "index.ts");
696
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
697
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
698
+ if (importPath.endsWith("index") && file.data.type === "file") {
709
699
  return void 0;
710
700
  }
711
701
  return {
712
- path: includeExt ? `${importPath}${extName}` : importPath,
702
+ path: extName ? `${importPath}${extName}` : importPath,
713
703
  isTypeOnly
714
704
  };
715
705
  }).filter(Boolean);
716
- files2.push({
706
+ files.push({
717
707
  path: indexPath,
718
708
  baseName: "index.ts",
719
709
  source: "",
720
- exports: output ? exports?.filter((item) => {
721
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
722
- }) : exports
710
+ exports,
711
+ meta: {
712
+ treeNode: treeNode2
713
+ }
723
714
  });
724
- } else {
725
- currentTree.children?.forEach((child) => {
726
- const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
727
- const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
728
- const exports = [
729
- {
730
- path: includeExt ? `${importPath}${extName}` : importPath,
731
- isTypeOnly
732
- }
733
- ];
734
- files2.push({
735
- path: indexPath,
736
- baseName: "index.ts",
737
- source: "",
738
- exports: output ? exports?.filter((item) => {
739
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
740
- }) : exports
741
- });
715
+ } else if (treeNode2.children.length === 1) {
716
+ const [treeNodeChild] = treeNode2.children;
717
+ const indexPath = path4__default.default.resolve(treeNode2.data.path, "index.ts");
718
+ const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
719
+ const exports = [
720
+ {
721
+ path: extName ? `${importPath}${extName}` : importPath,
722
+ isTypeOnly
723
+ }
724
+ ];
725
+ files.push({
726
+ path: indexPath,
727
+ baseName: "index.ts",
728
+ source: "",
729
+ exports,
730
+ meta: {
731
+ treeNode: treeNode2
732
+ }
742
733
  });
743
734
  }
744
- currentTree.children.forEach((childItem) => {
745
- fileReducer(files2, childItem);
735
+ treeNode2.children.forEach((childItem) => {
736
+ fileReducer(files, childItem);
746
737
  });
747
- return files2;
738
+ return files;
748
739
  };
749
- const files = fileReducer([], tree).reverse();
750
- const filteredFiles = filter ? files.filter(filter) : files;
751
- return map ? filteredFiles.map(map) : filteredFiles;
740
+ return fileReducer([], tree).reverse();
752
741
  }
753
742
  };
754
743
  _options = new WeakMap();
@@ -801,12 +790,33 @@ var _FileManager = class _FileManager {
801
790
  }
802
791
  return resolvedFiles[0];
803
792
  }
804
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
805
- const barrelManager = new BarrelManager(options);
806
- const files = barrelManager.getIndexes(root, extName);
793
+ async addIndexes({ root, output, meta, options = {} }) {
794
+ const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
795
+ const barrelManager = new BarrelManager({ extName: output.extName, ...options });
796
+ const files = barrelManager.getIndexes(path4.resolve(root, output.path));
807
797
  if (!files) {
808
798
  return void 0;
809
799
  }
800
+ const rootFile = {
801
+ path: path4.resolve(root, "index.ts"),
802
+ baseName: "index.ts",
803
+ source: "",
804
+ exports: [
805
+ output.exportAs ? {
806
+ name: output.exportAs,
807
+ asAlias: true,
808
+ path: exportPath,
809
+ isTypeOnly: options.isTypeOnly
810
+ } : {
811
+ path: exportPath,
812
+ isTypeOnly: options.isTypeOnly
813
+ }
814
+ ]
815
+ };
816
+ await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
817
+ ...rootFile,
818
+ meta: meta ? meta : rootFile.meta
819
+ });
810
820
  return await Promise.all(
811
821
  files.map((file) => {
812
822
  return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
@@ -922,7 +932,7 @@ _validate = new WeakSet();
922
932
  _add = new WeakSet();
923
933
  add_fn = async function(file) {
924
934
  const controller = new AbortController();
925
- const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
935
+ const resolvedFile = { id: crypto2__default.default.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
926
936
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
927
937
  if (__privateGet(this, _queue)) {
928
938
  await __privateGet(this, _queue).run(
@@ -1081,8 +1091,8 @@ var Queue = class {
1081
1091
  __privateSet(this, _debug, debug);
1082
1092
  }
1083
1093
  run(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
1084
- return new Promise((resolve2, reject) => {
1085
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1094
+ return new Promise((resolve3, reject) => {
1095
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1086
1096
  options.controller?.signal.addEventListener("abort", () => {
1087
1097
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1088
1098
  reject("Aborted");
@@ -1092,8 +1102,8 @@ var Queue = class {
1092
1102
  });
1093
1103
  }
1094
1104
  runSync(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
1095
- new Promise((resolve2, reject) => {
1096
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1105
+ new Promise((resolve3, reject) => {
1106
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1097
1107
  options.controller?.signal.addEventListener("abort", () => {
1098
1108
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1099
1109
  });
@@ -1120,13 +1130,13 @@ work_fn = function() {
1120
1130
  __privateWrapper(this, _workerCount)._++;
1121
1131
  let entry;
1122
1132
  while (entry = __privateGet(this, _queue2).shift()) {
1123
- const { reject, resolve: resolve2, job, name, description } = entry;
1133
+ const { reject, resolve: resolve3, job, name, description } = entry;
1124
1134
  if (__privateGet(this, _debug)) {
1125
1135
  perf_hooks.performance.mark(name + "_start");
1126
1136
  }
1127
1137
  job().then((result) => {
1128
1138
  this.eventEmitter.emit("jobDone", result);
1129
- resolve2(result);
1139
+ resolve3(result);
1130
1140
  if (__privateGet(this, _debug)) {
1131
1141
  perf_hooks.performance.mark(name + "_stop");
1132
1142
  perf_hooks.performance.measure(description, name + "_start", name + "_stop");
@@ -1964,18 +1974,18 @@ function pLimit(concurrency) {
1964
1974
  queue.dequeue()();
1965
1975
  }
1966
1976
  };
1967
- const run = async (fn, resolve2, args) => {
1977
+ const run = async (fn, resolve3, args) => {
1968
1978
  activeCount++;
1969
1979
  const result = (async () => fn(...args))();
1970
- resolve2(result);
1980
+ resolve3(result);
1971
1981
  try {
1972
1982
  await result;
1973
1983
  } catch {
1974
1984
  }
1975
1985
  next();
1976
1986
  };
1977
- const enqueue = (fn, resolve2, args) => {
1978
- queue.enqueue(run.bind(void 0, fn, resolve2, args));
1987
+ const enqueue = (fn, resolve3, args) => {
1988
+ queue.enqueue(run.bind(void 0, fn, resolve3, args));
1979
1989
  (async () => {
1980
1990
  await Promise.resolve();
1981
1991
  if (activeCount < concurrency && queue.size > 0) {
@@ -1983,8 +1993,8 @@ function pLimit(concurrency) {
1983
1993
  }
1984
1994
  })();
1985
1995
  };
1986
- const generator = (fn, ...args) => new Promise((resolve2) => {
1987
- enqueue(fn, resolve2, args);
1996
+ const generator = (fn, ...args) => new Promise((resolve3) => {
1997
+ enqueue(fn, resolve3, args);
1988
1998
  });
1989
1999
  Object.defineProperties(generator, {
1990
2000
  activeCount: {