@kubb/core 2.0.0-beta.5 → 2.0.0-beta.7

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,12 +677,12 @@ 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);
684
+ getIndexes(pathToBuild, extName) {
685
+ const { treeNode = {}, isTypeOnly, includeExt } = __privateGet(this, _options);
686
686
  const extMapper = {
687
687
  ".ts": {
688
688
  extensions: /\.ts/,
@@ -693,19 +693,19 @@ var BarrelManager = class {
693
693
  exclude: []
694
694
  }
695
695
  };
696
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
696
+ const tree = TreeNode.build(pathToBuild, { ...extMapper[extName] || {}, ...treeNode });
697
697
  if (!tree) {
698
698
  return null;
699
699
  }
700
- const fileReducer = (files2, currentTree) => {
701
- if (!currentTree.children) {
700
+ const fileReducer = (files, treeNode2) => {
701
+ if (!treeNode2.children) {
702
702
  return [];
703
703
  }
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") {
704
+ if (treeNode2.children.length > 1) {
705
+ const indexPath = path4__default.default.resolve(treeNode2.data.path, "index.ts");
706
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
707
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
708
+ if (importPath.endsWith("index") && file.data.type === "file") {
709
709
  return void 0;
710
710
  }
711
711
  return {
@@ -713,42 +713,41 @@ var BarrelManager = class {
713
713
  isTypeOnly
714
714
  };
715
715
  }).filter(Boolean);
716
- files2.push({
716
+ files.push({
717
717
  path: indexPath,
718
718
  baseName: "index.ts",
719
719
  source: "",
720
- exports: output ? exports?.filter((item) => {
721
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
722
- }) : exports
720
+ exports,
721
+ meta: {
722
+ treeNode: treeNode2
723
+ }
723
724
  });
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
- });
725
+ } else if (treeNode2.children.length === 1) {
726
+ const [treeNodeChild] = treeNode2.children;
727
+ const indexPath = path4__default.default.resolve(treeNode2.data.path, "index.ts");
728
+ const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
729
+ const exports = [
730
+ {
731
+ path: includeExt ? `${importPath}${extName}` : importPath,
732
+ isTypeOnly
733
+ }
734
+ ];
735
+ files.push({
736
+ path: indexPath,
737
+ baseName: "index.ts",
738
+ source: "",
739
+ exports,
740
+ meta: {
741
+ treeNode: treeNode2
742
+ }
742
743
  });
743
744
  }
744
- currentTree.children.forEach((childItem) => {
745
- fileReducer(files2, childItem);
745
+ treeNode2.children.forEach((childItem) => {
746
+ fileReducer(files, childItem);
746
747
  });
747
- return files2;
748
+ return files;
748
749
  };
749
- const files = fileReducer([], tree).reverse();
750
- const filteredFiles = filter ? files.filter(filter) : files;
751
- return map ? filteredFiles.map(map) : filteredFiles;
750
+ return fileReducer([], tree).reverse();
752
751
  }
753
752
  };
754
753
  _options = new WeakMap();
@@ -801,12 +800,35 @@ var _FileManager = class _FileManager {
801
800
  }
802
801
  return resolvedFiles[0];
803
802
  }
804
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
803
+ async addIndexes({ root, output, extName = ".ts", meta, options = {} }) {
804
+ const outputPath = typeof output === "string" ? output : output.path;
805
+ const exportAs = typeof output === "string" ? void 0 : output.exportAs;
806
+ const exportPath = outputPath.startsWith("./") ? outputPath : `./${outputPath}`;
805
807
  const barrelManager = new BarrelManager(options);
806
- const files = barrelManager.getIndexes(root, extName);
808
+ const files = barrelManager.getIndexes(path4.resolve(root, outputPath), extName);
807
809
  if (!files) {
808
810
  return void 0;
809
811
  }
812
+ const rootFile = {
813
+ path: path4.resolve(root, "index.ts"),
814
+ baseName: "index.ts",
815
+ source: "",
816
+ exports: [
817
+ exportAs ? {
818
+ name: exportAs,
819
+ asAlias: !!exportAs,
820
+ path: exportPath,
821
+ isTypeOnly: options.isTypeOnly
822
+ } : {
823
+ path: exportPath,
824
+ isTypeOnly: options.isTypeOnly
825
+ }
826
+ ]
827
+ };
828
+ await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
829
+ ...rootFile,
830
+ meta: meta ? meta : rootFile.meta
831
+ });
810
832
  return await Promise.all(
811
833
  files.map((file) => {
812
834
  return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
@@ -922,7 +944,7 @@ _validate = new WeakSet();
922
944
  _add = new WeakSet();
923
945
  add_fn = async function(file) {
924
946
  const controller = new AbortController();
925
- const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
947
+ const resolvedFile = { id: crypto2__default.default.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
926
948
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
927
949
  if (__privateGet(this, _queue)) {
928
950
  await __privateGet(this, _queue).run(
@@ -1081,8 +1103,8 @@ var Queue = class {
1081
1103
  __privateSet(this, _debug, debug);
1082
1104
  }
1083
1105
  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 };
1106
+ return new Promise((resolve3, reject) => {
1107
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1086
1108
  options.controller?.signal.addEventListener("abort", () => {
1087
1109
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1088
1110
  reject("Aborted");
@@ -1092,8 +1114,8 @@ var Queue = class {
1092
1114
  });
1093
1115
  }
1094
1116
  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 };
1117
+ new Promise((resolve3, reject) => {
1118
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1097
1119
  options.controller?.signal.addEventListener("abort", () => {
1098
1120
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1099
1121
  });
@@ -1120,13 +1142,13 @@ work_fn = function() {
1120
1142
  __privateWrapper(this, _workerCount)._++;
1121
1143
  let entry;
1122
1144
  while (entry = __privateGet(this, _queue2).shift()) {
1123
- const { reject, resolve: resolve2, job, name, description } = entry;
1145
+ const { reject, resolve: resolve3, job, name, description } = entry;
1124
1146
  if (__privateGet(this, _debug)) {
1125
1147
  perf_hooks.performance.mark(name + "_start");
1126
1148
  }
1127
1149
  job().then((result) => {
1128
1150
  this.eventEmitter.emit("jobDone", result);
1129
- resolve2(result);
1151
+ resolve3(result);
1130
1152
  if (__privateGet(this, _debug)) {
1131
1153
  perf_hooks.performance.mark(name + "_stop");
1132
1154
  perf_hooks.performance.measure(description, name + "_start", name + "_stop");
@@ -1964,18 +1986,18 @@ function pLimit(concurrency) {
1964
1986
  queue.dequeue()();
1965
1987
  }
1966
1988
  };
1967
- const run = async (fn, resolve2, args) => {
1989
+ const run = async (fn, resolve3, args) => {
1968
1990
  activeCount++;
1969
1991
  const result = (async () => fn(...args))();
1970
- resolve2(result);
1992
+ resolve3(result);
1971
1993
  try {
1972
1994
  await result;
1973
1995
  } catch {
1974
1996
  }
1975
1997
  next();
1976
1998
  };
1977
- const enqueue = (fn, resolve2, args) => {
1978
- queue.enqueue(run.bind(void 0, fn, resolve2, args));
1999
+ const enqueue = (fn, resolve3, args) => {
2000
+ queue.enqueue(run.bind(void 0, fn, resolve3, args));
1979
2001
  (async () => {
1980
2002
  await Promise.resolve();
1981
2003
  if (activeCount < concurrency && queue.size > 0) {
@@ -1983,8 +2005,8 @@ function pLimit(concurrency) {
1983
2005
  }
1984
2006
  })();
1985
2007
  };
1986
- const generator = (fn, ...args) => new Promise((resolve2) => {
1987
- enqueue(fn, resolve2, args);
2008
+ const generator = (fn, ...args) => new Promise((resolve3) => {
2009
+ enqueue(fn, resolve3, args);
1988
2010
  });
1989
2011
  Object.defineProperties(generator, {
1990
2012
  activeCount: {