@kubb/core 2.0.0-beta.6 → 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 +78 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +72 -50
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +72 -50
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +513 -18
- package/dist/utils.d.ts +513 -18
- package/dist/utils.js +72 -50
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/BarrelManager.ts +53 -51
- package/src/FileManager.ts +56 -7
- package/src/utils/TreeNode.ts +6 -3
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
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Add .ts or .js
|
|
14
|
+
*/
|
|
14
15
|
includeExt?: boolean;
|
|
15
|
-
output?: string;
|
|
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
|
|
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,11 +578,26 @@ 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
|
-
|
|
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: string | {
|
|
598
|
+
path: string;
|
|
599
|
+
exportAs?: string;
|
|
600
|
+
};
|
|
582
601
|
extName?: KubbFile.Extname;
|
|
583
602
|
options?: BarrelManagerOptions;
|
|
584
603
|
meta?: KubbFile.File['meta'];
|
|
@@ -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, extName, 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
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Add .ts or .js
|
|
14
|
+
*/
|
|
14
15
|
includeExt?: boolean;
|
|
15
|
-
output?: string;
|
|
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
|
|
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,11 +578,26 @@ 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
|
-
|
|
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: string | {
|
|
598
|
+
path: string;
|
|
599
|
+
exportAs?: string;
|
|
600
|
+
};
|
|
582
601
|
extName?: KubbFile.Extname;
|
|
583
602
|
options?: BarrelManagerOptions;
|
|
584
603
|
meta?: KubbFile.File['meta'];
|
|
@@ -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, extName, 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((
|
|
482
|
+
return new Promise((resolve3) => {
|
|
483
483
|
setTimeout(() => {
|
|
484
|
-
|
|
484
|
+
resolve3(true);
|
|
485
485
|
}, ms);
|
|
486
486
|
});
|
|
487
487
|
}
|
|
@@ -635,12 +635,12 @@ 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(
|
|
643
|
-
const { treeNode = {}, isTypeOnly,
|
|
642
|
+
getIndexes(pathToBuild, extName) {
|
|
643
|
+
const { treeNode = {}, isTypeOnly, includeExt } = __privateGet(this, _options);
|
|
644
644
|
const extMapper = {
|
|
645
645
|
".ts": {
|
|
646
646
|
extensions: /\.ts/,
|
|
@@ -651,19 +651,19 @@ var BarrelManager = class {
|
|
|
651
651
|
exclude: []
|
|
652
652
|
}
|
|
653
653
|
};
|
|
654
|
-
const tree = TreeNode.build(
|
|
654
|
+
const tree = TreeNode.build(pathToBuild, { ...extMapper[extName] || {}, ...treeNode });
|
|
655
655
|
if (!tree) {
|
|
656
656
|
return null;
|
|
657
657
|
}
|
|
658
|
-
const fileReducer = (
|
|
659
|
-
if (!
|
|
658
|
+
const fileReducer = (files, treeNode2) => {
|
|
659
|
+
if (!treeNode2.children) {
|
|
660
660
|
return [];
|
|
661
661
|
}
|
|
662
|
-
if (
|
|
663
|
-
const indexPath = path.resolve(
|
|
664
|
-
const exports =
|
|
665
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name
|
|
666
|
-
if (importPath.
|
|
662
|
+
if (treeNode2.children.length > 1) {
|
|
663
|
+
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
664
|
+
const exports = treeNode2.children.filter(Boolean).map((file) => {
|
|
665
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
|
|
666
|
+
if (importPath.endsWith("index") && file.data.type === "file") {
|
|
667
667
|
return void 0;
|
|
668
668
|
}
|
|
669
669
|
return {
|
|
@@ -671,42 +671,41 @@ var BarrelManager = class {
|
|
|
671
671
|
isTypeOnly
|
|
672
672
|
};
|
|
673
673
|
}).filter(Boolean);
|
|
674
|
-
|
|
674
|
+
files.push({
|
|
675
675
|
path: indexPath,
|
|
676
676
|
baseName: "index.ts",
|
|
677
677
|
source: "",
|
|
678
|
-
exports
|
|
679
|
-
|
|
680
|
-
|
|
678
|
+
exports,
|
|
679
|
+
meta: {
|
|
680
|
+
treeNode: treeNode2
|
|
681
|
+
}
|
|
681
682
|
});
|
|
682
|
-
} else {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
}
|
|
683
|
+
} else if (treeNode2.children.length === 1) {
|
|
684
|
+
const [treeNodeChild] = treeNode2.children;
|
|
685
|
+
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
686
|
+
const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
|
|
687
|
+
const exports = [
|
|
688
|
+
{
|
|
689
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
690
|
+
isTypeOnly
|
|
691
|
+
}
|
|
692
|
+
];
|
|
693
|
+
files.push({
|
|
694
|
+
path: indexPath,
|
|
695
|
+
baseName: "index.ts",
|
|
696
|
+
source: "",
|
|
697
|
+
exports,
|
|
698
|
+
meta: {
|
|
699
|
+
treeNode: treeNode2
|
|
700
|
+
}
|
|
700
701
|
});
|
|
701
702
|
}
|
|
702
|
-
|
|
703
|
-
fileReducer(
|
|
703
|
+
treeNode2.children.forEach((childItem) => {
|
|
704
|
+
fileReducer(files, childItem);
|
|
704
705
|
});
|
|
705
|
-
return
|
|
706
|
+
return files;
|
|
706
707
|
};
|
|
707
|
-
|
|
708
|
-
const filteredFiles = filter ? files.filter(filter) : files;
|
|
709
|
-
return map ? filteredFiles.map(map) : filteredFiles;
|
|
708
|
+
return fileReducer([], tree).reverse();
|
|
710
709
|
}
|
|
711
710
|
};
|
|
712
711
|
_options = new WeakMap();
|
|
@@ -759,12 +758,35 @@ var _FileManager = class _FileManager {
|
|
|
759
758
|
}
|
|
760
759
|
return resolvedFiles[0];
|
|
761
760
|
}
|
|
762
|
-
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
761
|
+
async addIndexes({ root, output, extName = ".ts", meta, options = {} }) {
|
|
762
|
+
const outputPath = typeof output === "string" ? output : output.path;
|
|
763
|
+
const exportAs = typeof output === "string" ? void 0 : output.exportAs;
|
|
764
|
+
const exportPath = outputPath.startsWith("./") ? outputPath : `./${outputPath}`;
|
|
763
765
|
const barrelManager = new BarrelManager(options);
|
|
764
|
-
const files = barrelManager.getIndexes(root, extName);
|
|
766
|
+
const files = barrelManager.getIndexes(resolve(root, outputPath), extName);
|
|
765
767
|
if (!files) {
|
|
766
768
|
return void 0;
|
|
767
769
|
}
|
|
770
|
+
const rootFile = {
|
|
771
|
+
path: resolve(root, "index.ts"),
|
|
772
|
+
baseName: "index.ts",
|
|
773
|
+
source: "",
|
|
774
|
+
exports: [
|
|
775
|
+
exportAs ? {
|
|
776
|
+
name: exportAs,
|
|
777
|
+
asAlias: !!exportAs,
|
|
778
|
+
path: exportPath,
|
|
779
|
+
isTypeOnly: options.isTypeOnly
|
|
780
|
+
} : {
|
|
781
|
+
path: exportPath,
|
|
782
|
+
isTypeOnly: options.isTypeOnly
|
|
783
|
+
}
|
|
784
|
+
]
|
|
785
|
+
};
|
|
786
|
+
await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
787
|
+
...rootFile,
|
|
788
|
+
meta: meta ? meta : rootFile.meta
|
|
789
|
+
});
|
|
768
790
|
return await Promise.all(
|
|
769
791
|
files.map((file) => {
|
|
770
792
|
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
@@ -880,7 +902,7 @@ _validate = new WeakSet();
|
|
|
880
902
|
_add = new WeakSet();
|
|
881
903
|
add_fn = async function(file) {
|
|
882
904
|
const controller = new AbortController();
|
|
883
|
-
const resolvedFile = { id: crypto2.randomUUID(), ...file };
|
|
905
|
+
const resolvedFile = { id: crypto2.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
|
|
884
906
|
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
885
907
|
if (__privateGet(this, _queue)) {
|
|
886
908
|
await __privateGet(this, _queue).run(
|
|
@@ -1039,8 +1061,8 @@ var Queue = class {
|
|
|
1039
1061
|
__privateSet(this, _debug, debug);
|
|
1040
1062
|
}
|
|
1041
1063
|
run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
1042
|
-
return new Promise((
|
|
1043
|
-
const item = { reject, resolve:
|
|
1064
|
+
return new Promise((resolve3, reject) => {
|
|
1065
|
+
const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
|
|
1044
1066
|
options.controller?.signal.addEventListener("abort", () => {
|
|
1045
1067
|
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1046
1068
|
reject("Aborted");
|
|
@@ -1050,8 +1072,8 @@ var Queue = class {
|
|
|
1050
1072
|
});
|
|
1051
1073
|
}
|
|
1052
1074
|
runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
1053
|
-
new Promise((
|
|
1054
|
-
const item = { reject, resolve:
|
|
1075
|
+
new Promise((resolve3, reject) => {
|
|
1076
|
+
const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
|
|
1055
1077
|
options.controller?.signal.addEventListener("abort", () => {
|
|
1056
1078
|
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1057
1079
|
});
|
|
@@ -1078,13 +1100,13 @@ work_fn = function() {
|
|
|
1078
1100
|
__privateWrapper(this, _workerCount)._++;
|
|
1079
1101
|
let entry;
|
|
1080
1102
|
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1081
|
-
const { reject, resolve:
|
|
1103
|
+
const { reject, resolve: resolve3, job, name, description } = entry;
|
|
1082
1104
|
if (__privateGet(this, _debug)) {
|
|
1083
1105
|
performance.mark(name + "_start");
|
|
1084
1106
|
}
|
|
1085
1107
|
job().then((result) => {
|
|
1086
1108
|
this.eventEmitter.emit("jobDone", result);
|
|
1087
|
-
|
|
1109
|
+
resolve3(result);
|
|
1088
1110
|
if (__privateGet(this, _debug)) {
|
|
1089
1111
|
performance.mark(name + "_stop");
|
|
1090
1112
|
performance.measure(description, name + "_start", name + "_stop");
|