@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.d.cts CHANGED
@@ -9,10 +9,10 @@ declare function write(data: string, path: string): Promise<string | undefined>;
9
9
  type BarrelManagerOptions = {
10
10
  treeNode?: DirectoryTreeOptions;
11
11
  isTypeOnly?: boolean;
12
- filter?: (file: KubbFile.File) => boolean;
13
- map?: (file: KubbFile.File) => KubbFile.File;
14
- includeExt?: boolean;
15
- output?: string;
12
+ /**
13
+ * Add .ts or .js
14
+ */
15
+ extName?: KubbFile.Extname;
16
16
  };
17
17
 
18
18
  declare class EventEmitter<TEvents extends Record<string, any>> {
@@ -486,6 +486,10 @@ declare namespace KubbFile {
486
486
  * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
487
487
  */
488
488
  isTypeOnly?: boolean;
489
+ /**
490
+ * Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
491
+ */
492
+ isNameSpace?: boolean;
489
493
  /**
490
494
  * When root is set it will get the path with relative getRelativePath(root, path).
491
495
  */
@@ -542,8 +546,8 @@ declare namespace KubbFile {
542
546
  */
543
547
  id?: string;
544
548
  /**
545
- * Name to be used to dynamicly create the baseName(based on input.path)
546
- * Based on UNIX basename
549
+ * Name to be used to create the path
550
+ * Based on UNIX basename, `${name}.extName`
547
551
  * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
548
552
  */
549
553
  baseName: TBaseName;
@@ -574,12 +578,27 @@ declare namespace KubbFile {
574
578
  * @default crypto.randomUUID()
575
579
  */
576
580
  id: UUID;
581
+ /**
582
+ * Contains the first part of the baseName, generated based on baseName
583
+ * @link https://nodejs.org/api/path.html#pathformatpathobject
584
+ */
585
+ name: string;
577
586
  };
578
587
  }
579
588
  type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
580
589
  type AddIndexesProps = {
581
- root: KubbFile.Path;
582
- extName?: KubbFile.Extname;
590
+ /**
591
+ * Root based on root and output.path specified in the config
592
+ */
593
+ root: string;
594
+ /**
595
+ * Output for plugin
596
+ */
597
+ output: {
598
+ path: string;
599
+ exportAs?: string;
600
+ extName?: KubbFile.Extname;
601
+ };
583
602
  options?: BarrelManagerOptions;
584
603
  meta?: KubbFile.File['meta'];
585
604
  };
@@ -597,7 +616,7 @@ declare class FileManager {
597
616
  get files(): Array<KubbFile.File>;
598
617
  get isExecuting(): boolean;
599
618
  add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
600
- addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
619
+ addIndexes({ root, output, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
601
620
  getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
602
621
  get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
603
622
  remove(path: KubbFile.Path): void;
package/dist/index.d.ts CHANGED
@@ -9,10 +9,10 @@ declare function write(data: string, path: string): Promise<string | undefined>;
9
9
  type BarrelManagerOptions = {
10
10
  treeNode?: DirectoryTreeOptions;
11
11
  isTypeOnly?: boolean;
12
- filter?: (file: KubbFile.File) => boolean;
13
- map?: (file: KubbFile.File) => KubbFile.File;
14
- includeExt?: boolean;
15
- output?: string;
12
+ /**
13
+ * Add .ts or .js
14
+ */
15
+ extName?: KubbFile.Extname;
16
16
  };
17
17
 
18
18
  declare class EventEmitter<TEvents extends Record<string, any>> {
@@ -486,6 +486,10 @@ declare namespace KubbFile {
486
486
  * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
487
487
  */
488
488
  isTypeOnly?: boolean;
489
+ /**
490
+ * Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
491
+ */
492
+ isNameSpace?: boolean;
489
493
  /**
490
494
  * When root is set it will get the path with relative getRelativePath(root, path).
491
495
  */
@@ -542,8 +546,8 @@ declare namespace KubbFile {
542
546
  */
543
547
  id?: string;
544
548
  /**
545
- * Name to be used to dynamicly create the baseName(based on input.path)
546
- * Based on UNIX basename
549
+ * Name to be used to create the path
550
+ * Based on UNIX basename, `${name}.extName`
547
551
  * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
548
552
  */
549
553
  baseName: TBaseName;
@@ -574,12 +578,27 @@ declare namespace KubbFile {
574
578
  * @default crypto.randomUUID()
575
579
  */
576
580
  id: UUID;
581
+ /**
582
+ * Contains the first part of the baseName, generated based on baseName
583
+ * @link https://nodejs.org/api/path.html#pathformatpathobject
584
+ */
585
+ name: string;
577
586
  };
578
587
  }
579
588
  type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
580
589
  type AddIndexesProps = {
581
- root: KubbFile.Path;
582
- extName?: KubbFile.Extname;
590
+ /**
591
+ * Root based on root and output.path specified in the config
592
+ */
593
+ root: string;
594
+ /**
595
+ * Output for plugin
596
+ */
597
+ output: {
598
+ path: string;
599
+ exportAs?: string;
600
+ extName?: KubbFile.Extname;
601
+ };
583
602
  options?: BarrelManagerOptions;
584
603
  meta?: KubbFile.File['meta'];
585
604
  };
@@ -597,7 +616,7 @@ declare class FileManager {
597
616
  get files(): Array<KubbFile.File>;
598
617
  get isExecuting(): boolean;
599
618
  add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
600
- addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
619
+ addIndexes({ root, output, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
601
620
  getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
602
621
  get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
603
622
  remove(path: KubbFile.Path): void;
package/dist/index.js CHANGED
@@ -479,9 +479,9 @@ function isInputPath(result) {
479
479
 
480
480
  // src/utils/timeout.ts
481
481
  async function timeout(ms) {
482
- return new Promise((resolve2) => {
482
+ return new Promise((resolve3) => {
483
483
  setTimeout(() => {
484
- resolve2(true);
484
+ resolve3(true);
485
485
  }, ms);
486
486
  });
487
487
  }
@@ -635,78 +635,67 @@ var TreeNode = class _TreeNode {
635
635
  var _options;
636
636
  var BarrelManager = class {
637
637
  constructor(options = {}) {
638
- __privateAdd(this, _options, {});
638
+ __privateAdd(this, _options, void 0);
639
639
  __privateSet(this, _options, options);
640
640
  return this;
641
641
  }
642
- getIndexes(root, extName) {
643
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
644
- const extMapper = {
645
- ".ts": {
646
- extensions: /\.ts/,
647
- exclude: [/schemas/, /json/]
648
- },
649
- ".json": {
650
- extensions: /\.json/,
651
- exclude: []
652
- }
653
- };
654
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
642
+ getIndexes(pathToBuild) {
643
+ const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
644
+ const tree = TreeNode.build(pathToBuild, treeNode);
655
645
  if (!tree) {
656
646
  return null;
657
647
  }
658
- const fileReducer = (files2, currentTree) => {
659
- if (!currentTree.children) {
648
+ const fileReducer = (files, treeNode2) => {
649
+ if (!treeNode2.children) {
660
650
  return [];
661
651
  }
662
- if (currentTree.children?.length > 1) {
663
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
664
- const exports = currentTree.children.filter(Boolean).map((file) => {
665
- const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
666
- if (importPath.includes("index") && file.data.type === "file") {
652
+ if (treeNode2.children.length > 1) {
653
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
654
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
655
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
656
+ if (importPath.endsWith("index") && file.data.type === "file") {
667
657
  return void 0;
668
658
  }
669
659
  return {
670
- path: includeExt ? `${importPath}${extName}` : importPath,
660
+ path: extName ? `${importPath}${extName}` : importPath,
671
661
  isTypeOnly
672
662
  };
673
663
  }).filter(Boolean);
674
- files2.push({
664
+ files.push({
675
665
  path: indexPath,
676
666
  baseName: "index.ts",
677
667
  source: "",
678
- exports: output ? exports?.filter((item) => {
679
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
680
- }) : exports
668
+ exports,
669
+ meta: {
670
+ treeNode: treeNode2
671
+ }
681
672
  });
682
- } else {
683
- currentTree.children?.forEach((child) => {
684
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
685
- const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
686
- const exports = [
687
- {
688
- path: includeExt ? `${importPath}${extName}` : importPath,
689
- isTypeOnly
690
- }
691
- ];
692
- files2.push({
693
- path: indexPath,
694
- baseName: "index.ts",
695
- source: "",
696
- exports: output ? exports?.filter((item) => {
697
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
698
- }) : exports
699
- });
673
+ } else if (treeNode2.children.length === 1) {
674
+ const [treeNodeChild] = treeNode2.children;
675
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
676
+ const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
677
+ const exports = [
678
+ {
679
+ path: extName ? `${importPath}${extName}` : importPath,
680
+ isTypeOnly
681
+ }
682
+ ];
683
+ files.push({
684
+ path: indexPath,
685
+ baseName: "index.ts",
686
+ source: "",
687
+ exports,
688
+ meta: {
689
+ treeNode: treeNode2
690
+ }
700
691
  });
701
692
  }
702
- currentTree.children.forEach((childItem) => {
703
- fileReducer(files2, childItem);
693
+ treeNode2.children.forEach((childItem) => {
694
+ fileReducer(files, childItem);
704
695
  });
705
- return files2;
696
+ return files;
706
697
  };
707
- const files = fileReducer([], tree).reverse();
708
- const filteredFiles = filter ? files.filter(filter) : files;
709
- return map ? filteredFiles.map(map) : filteredFiles;
698
+ return fileReducer([], tree).reverse();
710
699
  }
711
700
  };
712
701
  _options = new WeakMap();
@@ -759,12 +748,33 @@ var _FileManager = class _FileManager {
759
748
  }
760
749
  return resolvedFiles[0];
761
750
  }
762
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
763
- const barrelManager = new BarrelManager(options);
764
- const files = barrelManager.getIndexes(root, extName);
751
+ async addIndexes({ root, output, meta, options = {} }) {
752
+ const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
753
+ const barrelManager = new BarrelManager({ extName: output.extName, ...options });
754
+ const files = barrelManager.getIndexes(resolve(root, output.path));
765
755
  if (!files) {
766
756
  return void 0;
767
757
  }
758
+ const rootFile = {
759
+ path: resolve(root, "index.ts"),
760
+ baseName: "index.ts",
761
+ source: "",
762
+ exports: [
763
+ output.exportAs ? {
764
+ name: output.exportAs,
765
+ asAlias: true,
766
+ path: exportPath,
767
+ isTypeOnly: options.isTypeOnly
768
+ } : {
769
+ path: exportPath,
770
+ isTypeOnly: options.isTypeOnly
771
+ }
772
+ ]
773
+ };
774
+ await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
775
+ ...rootFile,
776
+ meta: meta ? meta : rootFile.meta
777
+ });
768
778
  return await Promise.all(
769
779
  files.map((file) => {
770
780
  return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
@@ -880,7 +890,7 @@ _validate = new WeakSet();
880
890
  _add = new WeakSet();
881
891
  add_fn = async function(file) {
882
892
  const controller = new AbortController();
883
- const resolvedFile = { id: crypto2.randomUUID(), ...file };
893
+ const resolvedFile = { id: crypto2.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
884
894
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
885
895
  if (__privateGet(this, _queue)) {
886
896
  await __privateGet(this, _queue).run(
@@ -1039,8 +1049,8 @@ var Queue = class {
1039
1049
  __privateSet(this, _debug, debug);
1040
1050
  }
1041
1051
  run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
1042
- return new Promise((resolve2, reject) => {
1043
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1052
+ return new Promise((resolve3, reject) => {
1053
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1044
1054
  options.controller?.signal.addEventListener("abort", () => {
1045
1055
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1046
1056
  reject("Aborted");
@@ -1050,8 +1060,8 @@ var Queue = class {
1050
1060
  });
1051
1061
  }
1052
1062
  runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
1053
- new Promise((resolve2, reject) => {
1054
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1063
+ new Promise((resolve3, reject) => {
1064
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1055
1065
  options.controller?.signal.addEventListener("abort", () => {
1056
1066
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1057
1067
  });
@@ -1078,13 +1088,13 @@ work_fn = function() {
1078
1088
  __privateWrapper(this, _workerCount)._++;
1079
1089
  let entry;
1080
1090
  while (entry = __privateGet(this, _queue2).shift()) {
1081
- const { reject, resolve: resolve2, job, name, description } = entry;
1091
+ const { reject, resolve: resolve3, job, name, description } = entry;
1082
1092
  if (__privateGet(this, _debug)) {
1083
1093
  performance.mark(name + "_start");
1084
1094
  }
1085
1095
  job().then((result) => {
1086
1096
  this.eventEmitter.emit("jobDone", result);
1087
- resolve2(result);
1097
+ resolve3(result);
1088
1098
  if (__privateGet(this, _debug)) {
1089
1099
  performance.mark(name + "_stop");
1090
1100
  performance.measure(description, name + "_start", name + "_stop");