@kubb/core 1.1.5 → 1.1.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 +252 -250
- package/dist/index.d.ts +14 -2
- package/dist/index.js +251 -249
- package/package.json +9 -6
- package/src/build.ts +4 -7
- package/src/config.ts +1 -1
- package/src/generators/SchemaGenerator.ts +1 -0
- package/src/managers/fileManager/FileManager.ts +13 -4
- package/src/managers/fileManager/utils.ts +3 -3
- package/src/managers/pluginManager/PluginManager.ts +45 -38
- package/src/managers/pluginManager/types.ts +2 -1
- package/src/plugin.ts +2 -2
- package/src/types.ts +1 -1
- package/src/utils/getStackTrace.ts +1 -1
- package/src/utils/read.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
3
|
import { promises } from 'node:fs';
|
|
4
|
+
import pathParser2 from 'node:path';
|
|
4
5
|
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
5
6
|
import { rimraf } from 'rimraf';
|
|
6
7
|
import dirTree from 'directory-tree';
|
|
7
|
-
import crypto from 'node:crypto';
|
|
8
8
|
import { createImportDeclaration, print, createExportDeclaration } from '@kubb/ts-codegen';
|
|
9
9
|
|
|
10
10
|
createRequire(import.meta.url);
|
|
11
11
|
|
|
12
|
-
// src/managers/pluginManager/PluginError.ts
|
|
13
|
-
var PluginError = class extends Error {
|
|
14
|
-
pluginManager;
|
|
15
|
-
constructor(message, options) {
|
|
16
|
-
super(message, { cause: options.cause });
|
|
17
|
-
this.pluginManager = options.pluginManager;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// src/managers/pluginManager/ParallelPluginError.ts
|
|
22
|
-
var ParallelPluginError = class extends Error {
|
|
23
|
-
errors;
|
|
24
|
-
pluginManager;
|
|
25
|
-
constructor(message, options) {
|
|
26
|
-
super(message, { cause: options.cause });
|
|
27
|
-
this.errors = options.errors;
|
|
28
|
-
this.pluginManager = options.pluginManager;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
12
|
// src/utils/isPromise.ts
|
|
33
13
|
function isPromise(result) {
|
|
34
14
|
return typeof result?.then === "function";
|
|
@@ -414,76 +394,7 @@ function getStackTrace(belowFn) {
|
|
|
414
394
|
return v8StackTrace;
|
|
415
395
|
}
|
|
416
396
|
|
|
417
|
-
// src/
|
|
418
|
-
function createPlugin(factory) {
|
|
419
|
-
return (options) => {
|
|
420
|
-
const plugin = factory(options);
|
|
421
|
-
if (Array.isArray(plugin)) {
|
|
422
|
-
throw new Error("Not implemented");
|
|
423
|
-
}
|
|
424
|
-
if (!plugin.transform) {
|
|
425
|
-
plugin.transform = function transform(code) {
|
|
426
|
-
return code;
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
return plugin;
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
var name = "core";
|
|
433
|
-
var definePlugin = createPlugin((options) => {
|
|
434
|
-
const { fileManager, resolvePath, resolveName, load } = options;
|
|
435
|
-
const api = {
|
|
436
|
-
get config() {
|
|
437
|
-
return options.config;
|
|
438
|
-
},
|
|
439
|
-
fileManager,
|
|
440
|
-
async addFile(...files) {
|
|
441
|
-
const trace = getStackTrace();
|
|
442
|
-
const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
|
|
443
|
-
if (a.name.length < b.name.length)
|
|
444
|
-
return 1;
|
|
445
|
-
if (a.name.length > b.name.length)
|
|
446
|
-
return -1;
|
|
447
|
-
return 0;
|
|
448
|
-
});
|
|
449
|
-
const pluginName = plugins?.[0].name;
|
|
450
|
-
return Promise.all(
|
|
451
|
-
files.map((file) => {
|
|
452
|
-
const fileWithMeta = {
|
|
453
|
-
...file,
|
|
454
|
-
meta: {
|
|
455
|
-
...file.meta || {},
|
|
456
|
-
pluginName
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
if (file.override) {
|
|
460
|
-
return fileManager.add(fileWithMeta);
|
|
461
|
-
}
|
|
462
|
-
return fileManager.addOrAppend(fileWithMeta);
|
|
463
|
-
})
|
|
464
|
-
);
|
|
465
|
-
},
|
|
466
|
-
resolvePath,
|
|
467
|
-
resolveName: (params) => {
|
|
468
|
-
const name2 = resolveName(params);
|
|
469
|
-
return transformReservedWord(name2);
|
|
470
|
-
},
|
|
471
|
-
load,
|
|
472
|
-
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
473
|
-
};
|
|
474
|
-
return {
|
|
475
|
-
name,
|
|
476
|
-
options,
|
|
477
|
-
api,
|
|
478
|
-
resolvePath(fileName) {
|
|
479
|
-
const root = pathParser2.resolve(this.config.root, this.config.output.path);
|
|
480
|
-
return pathParser2.resolve(root, fileName);
|
|
481
|
-
},
|
|
482
|
-
resolveName(name2) {
|
|
483
|
-
return name2;
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
});
|
|
397
|
+
// src/managers/fileManager/FileManager.ts
|
|
487
398
|
var FileManager = class {
|
|
488
399
|
cache = /* @__PURE__ */ new Map();
|
|
489
400
|
task;
|
|
@@ -513,6 +424,13 @@ var FileManager = class {
|
|
|
513
424
|
});
|
|
514
425
|
return files;
|
|
515
426
|
}
|
|
427
|
+
get cachedFiles() {
|
|
428
|
+
const files = [];
|
|
429
|
+
this.cache.forEach((item) => {
|
|
430
|
+
files.push(item);
|
|
431
|
+
});
|
|
432
|
+
return files;
|
|
433
|
+
}
|
|
516
434
|
async add(file) {
|
|
517
435
|
const cacheItem = { id: crypto.randomUUID(), file, status: "new" };
|
|
518
436
|
this.cache.set(cacheItem.id, cacheItem);
|
|
@@ -568,6 +486,222 @@ ${file.source}`,
|
|
|
568
486
|
return read(...params);
|
|
569
487
|
}
|
|
570
488
|
};
|
|
489
|
+
function writeIndexes(root, options) {
|
|
490
|
+
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
491
|
+
if (!tree) {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
const fileReducer = (files2, item) => {
|
|
495
|
+
if (!item.children) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
if (item.children?.length > 1) {
|
|
499
|
+
const path = pathParser2.resolve(item.data.path, "index.ts");
|
|
500
|
+
const exports = item.children.map((file) => {
|
|
501
|
+
if (!file) {
|
|
502
|
+
return void 0;
|
|
503
|
+
}
|
|
504
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
505
|
+
if (importPath.includes("index") && path.includes("index")) {
|
|
506
|
+
return void 0;
|
|
507
|
+
}
|
|
508
|
+
return { path: importPath };
|
|
509
|
+
}).filter(Boolean);
|
|
510
|
+
files2.push({
|
|
511
|
+
path,
|
|
512
|
+
fileName: "index.ts",
|
|
513
|
+
source: "",
|
|
514
|
+
exports
|
|
515
|
+
});
|
|
516
|
+
} else {
|
|
517
|
+
item.children?.forEach((child) => {
|
|
518
|
+
const path = pathParser2.resolve(item.data.path, "index.ts");
|
|
519
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
520
|
+
files2.push({
|
|
521
|
+
path,
|
|
522
|
+
fileName: "index.ts",
|
|
523
|
+
source: "",
|
|
524
|
+
exports: [{ path: importPath }]
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
item.children.forEach((childItem) => {
|
|
529
|
+
fileReducer(files2, childItem);
|
|
530
|
+
});
|
|
531
|
+
return files2;
|
|
532
|
+
};
|
|
533
|
+
const files = fileReducer([], tree);
|
|
534
|
+
return files;
|
|
535
|
+
}
|
|
536
|
+
function combineFiles(files) {
|
|
537
|
+
return files.filter(Boolean).reduce((acc, curr) => {
|
|
538
|
+
if (!curr) {
|
|
539
|
+
return acc;
|
|
540
|
+
}
|
|
541
|
+
const prevIndex = acc.findIndex((item) => item.path === curr.path);
|
|
542
|
+
if (prevIndex !== -1) {
|
|
543
|
+
const prev = acc[prevIndex];
|
|
544
|
+
acc[prevIndex] = {
|
|
545
|
+
...curr,
|
|
546
|
+
source: `${prev.source}
|
|
547
|
+
${curr.source}`,
|
|
548
|
+
imports: [...prev.imports || [], ...curr.imports || []],
|
|
549
|
+
exports: [...prev.exports || [], ...curr.exports || []]
|
|
550
|
+
};
|
|
551
|
+
} else {
|
|
552
|
+
acc.push(curr);
|
|
553
|
+
}
|
|
554
|
+
return acc;
|
|
555
|
+
}, []);
|
|
556
|
+
}
|
|
557
|
+
function getFileSource(file) {
|
|
558
|
+
let { source } = file;
|
|
559
|
+
if (!file.fileName.endsWith(".ts")) {
|
|
560
|
+
return file.source;
|
|
561
|
+
}
|
|
562
|
+
const imports = [];
|
|
563
|
+
const exports = [];
|
|
564
|
+
file.imports?.forEach((curr) => {
|
|
565
|
+
const exists = imports.find((imp) => imp.path === curr.path);
|
|
566
|
+
if (!exists) {
|
|
567
|
+
imports.push({
|
|
568
|
+
...curr,
|
|
569
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
|
|
573
|
+
imports.push(curr);
|
|
574
|
+
}
|
|
575
|
+
if (exists && Array.isArray(exists.name)) {
|
|
576
|
+
if (Array.isArray(curr.name)) {
|
|
577
|
+
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
file.exports?.forEach((curr) => {
|
|
582
|
+
const exists = exports.find((imp) => imp.path === curr.path);
|
|
583
|
+
if (!exists) {
|
|
584
|
+
exports.push({
|
|
585
|
+
...curr,
|
|
586
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {
|
|
590
|
+
exports.push(curr);
|
|
591
|
+
}
|
|
592
|
+
if (exists && Array.isArray(exists.name)) {
|
|
593
|
+
if (Array.isArray(curr.name)) {
|
|
594
|
+
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
const importNodes = imports.reduce((prev, curr) => {
|
|
599
|
+
return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
|
|
600
|
+
}, []);
|
|
601
|
+
const importSource = print(importNodes);
|
|
602
|
+
const exportNodes = exports.reduce((prev, curr) => {
|
|
603
|
+
return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })];
|
|
604
|
+
}, []);
|
|
605
|
+
const exportSource = print(exportNodes);
|
|
606
|
+
if (importSource) {
|
|
607
|
+
source = `${importSource}
|
|
608
|
+
${source}`;
|
|
609
|
+
}
|
|
610
|
+
if (exportSource) {
|
|
611
|
+
source = `${exportSource}
|
|
612
|
+
${source}`;
|
|
613
|
+
}
|
|
614
|
+
return source;
|
|
615
|
+
}
|
|
616
|
+
function createPlugin(factory) {
|
|
617
|
+
return (options) => {
|
|
618
|
+
const plugin = factory(options);
|
|
619
|
+
if (Array.isArray(plugin)) {
|
|
620
|
+
throw new Error("Not implemented");
|
|
621
|
+
}
|
|
622
|
+
if (!plugin.transform) {
|
|
623
|
+
plugin.transform = function transform(code) {
|
|
624
|
+
return code;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return plugin;
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
var name = "core";
|
|
631
|
+
var definePlugin = createPlugin((options) => {
|
|
632
|
+
const { fileManager, resolvePath, resolveName, load } = options;
|
|
633
|
+
const api = {
|
|
634
|
+
get config() {
|
|
635
|
+
return options.config;
|
|
636
|
+
},
|
|
637
|
+
fileManager,
|
|
638
|
+
async addFile(...files) {
|
|
639
|
+
const trace = getStackTrace();
|
|
640
|
+
const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
|
|
641
|
+
if (a.name.length < b.name.length)
|
|
642
|
+
return 1;
|
|
643
|
+
if (a.name.length > b.name.length)
|
|
644
|
+
return -1;
|
|
645
|
+
return 0;
|
|
646
|
+
});
|
|
647
|
+
const pluginName = plugins?.[0].name;
|
|
648
|
+
return Promise.all(
|
|
649
|
+
files.map((file) => {
|
|
650
|
+
const fileWithMeta = {
|
|
651
|
+
...file,
|
|
652
|
+
meta: {
|
|
653
|
+
...file.meta || {},
|
|
654
|
+
pluginName
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
if (file.override) {
|
|
658
|
+
return fileManager.add(fileWithMeta);
|
|
659
|
+
}
|
|
660
|
+
return fileManager.addOrAppend(fileWithMeta);
|
|
661
|
+
})
|
|
662
|
+
);
|
|
663
|
+
},
|
|
664
|
+
resolvePath,
|
|
665
|
+
resolveName: (params) => {
|
|
666
|
+
const name2 = resolveName(params);
|
|
667
|
+
return transformReservedWord(name2);
|
|
668
|
+
},
|
|
669
|
+
load,
|
|
670
|
+
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
671
|
+
};
|
|
672
|
+
return {
|
|
673
|
+
name,
|
|
674
|
+
options,
|
|
675
|
+
api,
|
|
676
|
+
resolvePath(fileName) {
|
|
677
|
+
const root = pathParser2.resolve(this.config.root, this.config.output.path);
|
|
678
|
+
return pathParser2.resolve(root, fileName);
|
|
679
|
+
},
|
|
680
|
+
resolveName(name2) {
|
|
681
|
+
return name2;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
// src/managers/pluginManager/ParallelPluginError.ts
|
|
687
|
+
var ParallelPluginError = class extends Error {
|
|
688
|
+
errors;
|
|
689
|
+
pluginManager;
|
|
690
|
+
constructor(message, options) {
|
|
691
|
+
super(message, { cause: options.cause });
|
|
692
|
+
this.errors = options.errors;
|
|
693
|
+
this.pluginManager = options.pluginManager;
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
// src/managers/pluginManager/PluginError.ts
|
|
698
|
+
var PluginError = class extends Error {
|
|
699
|
+
pluginManager;
|
|
700
|
+
constructor(message, options) {
|
|
701
|
+
super(message, { cause: options.cause });
|
|
702
|
+
this.pluginManager = options.pluginManager;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
571
705
|
|
|
572
706
|
// src/managers/pluginManager/PluginManager.ts
|
|
573
707
|
var hookNames = {
|
|
@@ -681,9 +815,9 @@ var PluginManager = class {
|
|
|
681
815
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
682
816
|
if (skipped && skipped.has(plugin))
|
|
683
817
|
continue;
|
|
684
|
-
promise = promise.then(async (
|
|
685
|
-
if (result != null) {
|
|
686
|
-
return
|
|
818
|
+
promise = promise.then(async (parseResult) => {
|
|
819
|
+
if (parseResult?.result != null) {
|
|
820
|
+
return parseResult;
|
|
687
821
|
}
|
|
688
822
|
const value = await this.execute({
|
|
689
823
|
strategy: "hookFirst",
|
|
@@ -708,45 +842,38 @@ var PluginManager = class {
|
|
|
708
842
|
parameters,
|
|
709
843
|
skipped
|
|
710
844
|
}) {
|
|
711
|
-
let
|
|
845
|
+
let parseResult = null;
|
|
712
846
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
713
847
|
if (skipped && skipped.has(plugin))
|
|
714
848
|
continue;
|
|
715
|
-
|
|
849
|
+
parseResult = {
|
|
716
850
|
result: this.executeSync({
|
|
717
851
|
strategy: "hookFirst",
|
|
718
852
|
hookName,
|
|
719
853
|
parameters,
|
|
720
854
|
plugin
|
|
721
|
-
})
|
|
855
|
+
}),
|
|
856
|
+
plugin
|
|
722
857
|
};
|
|
723
|
-
if (result != null) {
|
|
858
|
+
if (parseResult?.result != null) {
|
|
724
859
|
break;
|
|
725
860
|
}
|
|
726
861
|
}
|
|
727
|
-
return
|
|
862
|
+
return parseResult;
|
|
728
863
|
}
|
|
729
|
-
|
|
864
|
+
/**
|
|
865
|
+
*
|
|
866
|
+
* Parallel, runs all plugins
|
|
867
|
+
*/
|
|
730
868
|
async hookParallel({
|
|
731
869
|
hookName,
|
|
732
870
|
parameters
|
|
733
871
|
}) {
|
|
734
872
|
const parallelPromises = [];
|
|
735
873
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
parallelPromises.
|
|
739
|
-
await this.execute({
|
|
740
|
-
strategy: "hookParallel",
|
|
741
|
-
hookName,
|
|
742
|
-
parameters,
|
|
743
|
-
plugin
|
|
744
|
-
});
|
|
745
|
-
} else {
|
|
746
|
-
const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin });
|
|
747
|
-
if (promise) {
|
|
748
|
-
parallelPromises.push(promise);
|
|
749
|
-
}
|
|
874
|
+
const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin });
|
|
875
|
+
if (promise) {
|
|
876
|
+
parallelPromises.push(promise);
|
|
750
877
|
}
|
|
751
878
|
}
|
|
752
879
|
const results = await Promise.allSettled(parallelPromises);
|
|
@@ -756,7 +883,10 @@ var PluginManager = class {
|
|
|
756
883
|
}
|
|
757
884
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
758
885
|
}
|
|
759
|
-
|
|
886
|
+
/**
|
|
887
|
+
*
|
|
888
|
+
* Chains, reduces returned value, handling the reduced value as the first hook argument
|
|
889
|
+
*/
|
|
760
890
|
hookReduceArg0({
|
|
761
891
|
hookName,
|
|
762
892
|
parameters,
|
|
@@ -765,11 +895,11 @@ var PluginManager = class {
|
|
|
765
895
|
const [argument0, ...rest] = parameters;
|
|
766
896
|
let promise = Promise.resolve(argument0);
|
|
767
897
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
768
|
-
promise = promise.then((
|
|
898
|
+
promise = promise.then((arg0) => {
|
|
769
899
|
const value = this.execute({
|
|
770
900
|
strategy: "hookReduceArg0",
|
|
771
901
|
hookName,
|
|
772
|
-
parameters: [
|
|
902
|
+
parameters: [arg0, ...rest],
|
|
773
903
|
plugin
|
|
774
904
|
});
|
|
775
905
|
return value;
|
|
@@ -777,7 +907,9 @@ var PluginManager = class {
|
|
|
777
907
|
}
|
|
778
908
|
return promise;
|
|
779
909
|
}
|
|
780
|
-
|
|
910
|
+
/**
|
|
911
|
+
* Chains plugins
|
|
912
|
+
*/
|
|
781
913
|
hookSeq({ hookName, parameters }) {
|
|
782
914
|
let promise = Promise.resolve();
|
|
783
915
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
@@ -927,139 +1059,9 @@ function validatePlugins(plugins, dependedPluginNames) {
|
|
|
927
1059
|
});
|
|
928
1060
|
return true;
|
|
929
1061
|
}
|
|
930
|
-
function writeIndexes(root, options) {
|
|
931
|
-
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
932
|
-
if (!tree) {
|
|
933
|
-
return void 0;
|
|
934
|
-
}
|
|
935
|
-
const fileReducer = (files2, item) => {
|
|
936
|
-
if (!item.children) {
|
|
937
|
-
return [];
|
|
938
|
-
}
|
|
939
|
-
if (item.children?.length > 1) {
|
|
940
|
-
const path = pathParser2.resolve(item.data.path, "index.ts");
|
|
941
|
-
const exports = item.children.map((file) => {
|
|
942
|
-
if (!file) {
|
|
943
|
-
return void 0;
|
|
944
|
-
}
|
|
945
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
946
|
-
if (importPath.includes("index") && path.includes("index")) {
|
|
947
|
-
return void 0;
|
|
948
|
-
}
|
|
949
|
-
return { path: importPath };
|
|
950
|
-
}).filter(Boolean);
|
|
951
|
-
files2.push({
|
|
952
|
-
path,
|
|
953
|
-
fileName: "index.ts",
|
|
954
|
-
source: "",
|
|
955
|
-
exports
|
|
956
|
-
});
|
|
957
|
-
} else {
|
|
958
|
-
item.children?.forEach((child) => {
|
|
959
|
-
const path = pathParser2.resolve(item.data.path, "index.ts");
|
|
960
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
961
|
-
files2.push({
|
|
962
|
-
path,
|
|
963
|
-
fileName: "index.ts",
|
|
964
|
-
source: "",
|
|
965
|
-
exports: [{ path: importPath }]
|
|
966
|
-
});
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
item.children.forEach((childItem) => {
|
|
970
|
-
fileReducer(files2, childItem);
|
|
971
|
-
});
|
|
972
|
-
return files2;
|
|
973
|
-
};
|
|
974
|
-
const files = fileReducer([], tree);
|
|
975
|
-
return files;
|
|
976
|
-
}
|
|
977
|
-
function combineFiles(files) {
|
|
978
|
-
return files.filter(Boolean).reduce((acc, curr) => {
|
|
979
|
-
if (!curr) {
|
|
980
|
-
return acc;
|
|
981
|
-
}
|
|
982
|
-
const prevIndex = acc.findIndex((item) => item.path === curr.path);
|
|
983
|
-
if (prevIndex !== -1) {
|
|
984
|
-
const prev = acc[prevIndex];
|
|
985
|
-
acc[prevIndex] = {
|
|
986
|
-
...curr,
|
|
987
|
-
source: `${prev.source}
|
|
988
|
-
${curr.source}`,
|
|
989
|
-
imports: [...prev.imports || [], ...curr.imports || []],
|
|
990
|
-
exports: [...prev.exports || [], ...curr.exports || []]
|
|
991
|
-
};
|
|
992
|
-
} else {
|
|
993
|
-
acc.push(curr);
|
|
994
|
-
}
|
|
995
|
-
return acc;
|
|
996
|
-
}, []);
|
|
997
|
-
}
|
|
998
|
-
function getFileSource(file) {
|
|
999
|
-
let { source } = file;
|
|
1000
|
-
if (!file.fileName.endsWith(".ts")) {
|
|
1001
|
-
return file.source;
|
|
1002
|
-
}
|
|
1003
|
-
const imports = [];
|
|
1004
|
-
const exports = [];
|
|
1005
|
-
file.imports?.forEach((curr) => {
|
|
1006
|
-
const exists = imports.find((imp) => imp.path === curr.path);
|
|
1007
|
-
if (!exists) {
|
|
1008
|
-
imports.push({
|
|
1009
|
-
...curr,
|
|
1010
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
|
|
1014
|
-
imports.push(curr);
|
|
1015
|
-
}
|
|
1016
|
-
if (exists && Array.isArray(exists.name)) {
|
|
1017
|
-
if (Array.isArray(curr.name)) {
|
|
1018
|
-
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
file.exports?.forEach((curr) => {
|
|
1023
|
-
const exists = exports.find((imp) => imp.path === curr.path);
|
|
1024
|
-
if (!exists) {
|
|
1025
|
-
exports.push({
|
|
1026
|
-
...curr,
|
|
1027
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {
|
|
1031
|
-
exports.push(curr);
|
|
1032
|
-
}
|
|
1033
|
-
if (exists && Array.isArray(exists.name)) {
|
|
1034
|
-
if (Array.isArray(curr.name)) {
|
|
1035
|
-
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
});
|
|
1039
|
-
const importNodes = imports.reduce((prev, curr) => {
|
|
1040
|
-
return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
|
|
1041
|
-
}, []);
|
|
1042
|
-
const importSource = print(importNodes);
|
|
1043
|
-
const exportNodes = exports.reduce((prev, curr) => {
|
|
1044
|
-
return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })];
|
|
1045
|
-
}, []);
|
|
1046
|
-
const exportSource = print(exportNodes);
|
|
1047
|
-
if (importSource) {
|
|
1048
|
-
source = `${importSource}
|
|
1049
|
-
${source}`;
|
|
1050
|
-
}
|
|
1051
|
-
if (exportSource) {
|
|
1052
|
-
source = `${exportSource}
|
|
1053
|
-
${source}`;
|
|
1054
|
-
}
|
|
1055
|
-
return source;
|
|
1056
|
-
}
|
|
1057
1062
|
|
|
1058
1063
|
// src/build.ts
|
|
1059
1064
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1060
|
-
if (result === null) {
|
|
1061
|
-
return null;
|
|
1062
|
-
}
|
|
1063
1065
|
return result;
|
|
1064
1066
|
}
|
|
1065
1067
|
async function build(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,27 +43,30 @@
|
|
|
43
43
|
"change-case": "^4.1.2",
|
|
44
44
|
"directory-tree": "^3.5.1",
|
|
45
45
|
"rimraf": "^5.0.1",
|
|
46
|
-
"@kubb/ts-codegen": "1.1.
|
|
46
|
+
"@kubb/ts-codegen": "1.1.7"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"eslint": "^8.42.0",
|
|
49
50
|
"tsup": "^6.7.0",
|
|
50
51
|
"ora": "^6.3.1",
|
|
51
|
-
"typescript": "^5.1.3"
|
|
52
|
+
"typescript": "^5.1.3",
|
|
53
|
+
"@kubb/tsup-config": "0.1.0",
|
|
54
|
+
"@kubb/eslint-config": "0.1.0"
|
|
52
55
|
},
|
|
53
56
|
"publishConfig": {
|
|
54
57
|
"access": "public",
|
|
55
58
|
"registry": "https://registry.npmjs.org/"
|
|
56
59
|
},
|
|
57
60
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
61
|
+
"node": ">=18",
|
|
59
62
|
"pnpm": ">=8"
|
|
60
63
|
},
|
|
61
64
|
"scripts": {
|
|
62
65
|
"build": "tsup",
|
|
63
66
|
"start": "tsup --watch",
|
|
64
67
|
"release": "pnpm publish --no-git-check",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
68
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
69
|
+
"lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
|
|
67
70
|
"test": "vitest --passWithNoTests",
|
|
68
71
|
"upgrade": "pnpm update",
|
|
69
72
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/src/build.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-async-promise-executor */
|
|
2
|
+
import { getFileSource } from './managers/fileManager/index.ts'
|
|
2
3
|
import { PluginManager } from './managers/pluginManager/index.ts'
|
|
3
4
|
import { clean, isURL, read } from './utils/index.ts'
|
|
4
|
-
import { getFileSource } from './managers/fileManager/index.ts'
|
|
5
5
|
import { isPromise } from './utils/isPromise.ts'
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { Ora } from 'ora'
|
|
8
8
|
import type { File } from './managers/fileManager/index.ts'
|
|
9
|
+
import type { OnExecute } from './managers/pluginManager/index.ts'
|
|
10
|
+
import type { BuildOutput, KubbPlugin, LogLevel, PluginContext, TransformResult } from './types.ts'
|
|
9
11
|
import type { QueueTask } from './utils/index.ts'
|
|
10
|
-
import type { PluginContext, TransformResult, LogLevel, KubbPlugin, BuildOutput } from './types.ts'
|
|
11
|
-
import type { Ora } from 'ora'
|
|
12
12
|
|
|
13
13
|
export type Logger = {
|
|
14
14
|
log: (message: string, logLevel: LogLevel) => void
|
|
@@ -25,9 +25,6 @@ async function transformReducer(
|
|
|
25
25
|
result: TransformResult | Promise<TransformResult>,
|
|
26
26
|
_plugin: KubbPlugin
|
|
27
27
|
): Promise<string | null> {
|
|
28
|
-
if (result === null) {
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
28
|
return result
|
|
32
29
|
}
|
|
33
30
|
|
package/src/config.ts
CHANGED