@kubb/core 1.0.0 → 1.0.1
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 +298 -205
- package/dist/index.d.ts +292 -247
- package/dist/index.js +298 -207
- package/package.json +7 -10
- package/src/build.ts +30 -44
- package/src/config.ts +2 -2
- package/src/generators/SchemaGenerator.ts +1 -1
- package/src/generators/index.ts +2 -2
- package/src/index.ts +9 -8
- package/src/managers/fileManager/FileManager.ts +5 -5
- package/src/managers/fileManager/index.ts +3 -3
- package/src/managers/fileManager/types.ts +3 -0
- package/src/managers/fileManager/utils.ts +9 -11
- package/src/managers/index.ts +2 -2
- package/src/managers/pluginManager/ParallelPluginError.ts +15 -0
- package/src/managers/pluginManager/PluginError.ts +11 -0
- package/src/managers/pluginManager/PluginManager.ts +129 -64
- package/src/managers/pluginManager/index.ts +5 -3
- package/src/managers/pluginManager/types.ts +10 -1
- package/src/managers/pluginManager/validate.ts +1 -1
- package/src/plugin.ts +34 -5
- package/src/types.ts +31 -4
- package/src/utils/clean.ts +2 -10
- package/src/utils/getStackTrace.ts +19 -0
- package/src/utils/index.ts +17 -16
- package/src/utils/isPromise.ts +1 -1
- package/src/utils/read.ts +2 -2
- package/src/utils/transformReservedWord.ts +2 -2
- package/src/utils/write.ts +2 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -7,19 +7,37 @@ var pathParser2 = require('path');
|
|
|
7
7
|
var fs = require('fs');
|
|
8
8
|
var rimraf = require('rimraf');
|
|
9
9
|
var dirTree = require('directory-tree');
|
|
10
|
-
var
|
|
11
|
-
var uniq = require('lodash.uniq');
|
|
10
|
+
var crypto = require('crypto');
|
|
12
11
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
13
12
|
|
|
14
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
|
|
16
15
|
var pathParser2__default = /*#__PURE__*/_interopDefault(pathParser2);
|
|
17
|
-
var rimraf__default = /*#__PURE__*/_interopDefault(rimraf);
|
|
18
16
|
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
19
|
-
var
|
|
17
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
20
18
|
|
|
21
19
|
module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
|
|
22
20
|
|
|
21
|
+
// src/managers/pluginManager/PluginError.ts
|
|
22
|
+
var PluginError = class extends Error {
|
|
23
|
+
pluginManager;
|
|
24
|
+
constructor(message, options) {
|
|
25
|
+
super(message, { cause: options.cause });
|
|
26
|
+
this.pluginManager = options.pluginManager;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/managers/pluginManager/ParallelPluginError.ts
|
|
31
|
+
var ParallelPluginError = class extends Error {
|
|
32
|
+
errors;
|
|
33
|
+
pluginManager;
|
|
34
|
+
constructor(message, options) {
|
|
35
|
+
super(message, { cause: options.cause });
|
|
36
|
+
this.errors = options.errors;
|
|
37
|
+
this.pluginManager = options.pluginManager;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
23
41
|
// src/utils/isPromise.ts
|
|
24
42
|
function isPromise(result) {
|
|
25
43
|
return typeof result?.then === "function";
|
|
@@ -215,15 +233,7 @@ function renderTemplate(template, data = void 0) {
|
|
|
215
233
|
});
|
|
216
234
|
}
|
|
217
235
|
async function clean(path) {
|
|
218
|
-
return
|
|
219
|
-
rimraf__default.default(path, (err) => {
|
|
220
|
-
if (err) {
|
|
221
|
-
reject(err);
|
|
222
|
-
} else {
|
|
223
|
-
resolve(true);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
});
|
|
236
|
+
return rimraf.rimraf(path);
|
|
227
237
|
}
|
|
228
238
|
var TreeNode = class {
|
|
229
239
|
data;
|
|
@@ -392,12 +402,28 @@ var reservedWords = [
|
|
|
392
402
|
"valueOf"
|
|
393
403
|
];
|
|
394
404
|
function transformReservedWord(word) {
|
|
395
|
-
if (reservedWords.includes(word)) {
|
|
405
|
+
if (word && reservedWords.includes(word)) {
|
|
396
406
|
return `_${word}`;
|
|
397
407
|
}
|
|
398
408
|
return word;
|
|
399
409
|
}
|
|
400
410
|
|
|
411
|
+
// src/utils/getStackTrace.ts
|
|
412
|
+
function getStackTrace(belowFn) {
|
|
413
|
+
const oldLimit = Error.stackTraceLimit;
|
|
414
|
+
Error.stackTraceLimit = Infinity;
|
|
415
|
+
const dummyObject = {};
|
|
416
|
+
const v8Handler = Error.prepareStackTrace;
|
|
417
|
+
Error.prepareStackTrace = function prepareStackTrace(dummyObject2, v8StackTrace2) {
|
|
418
|
+
return v8StackTrace2;
|
|
419
|
+
};
|
|
420
|
+
Error.captureStackTrace(dummyObject, belowFn || getStackTrace);
|
|
421
|
+
const v8StackTrace = dummyObject.stack;
|
|
422
|
+
Error.prepareStackTrace = v8Handler;
|
|
423
|
+
Error.stackTraceLimit = oldLimit;
|
|
424
|
+
return v8StackTrace;
|
|
425
|
+
}
|
|
426
|
+
|
|
401
427
|
// src/plugin.ts
|
|
402
428
|
function createPlugin(factory) {
|
|
403
429
|
return (options) => {
|
|
@@ -422,7 +448,30 @@ var definePlugin = createPlugin((options) => {
|
|
|
422
448
|
},
|
|
423
449
|
fileManager,
|
|
424
450
|
async addFile(...files) {
|
|
425
|
-
|
|
451
|
+
const trace = getStackTrace();
|
|
452
|
+
const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
|
|
453
|
+
if (a.name.length < b.name.length)
|
|
454
|
+
return 1;
|
|
455
|
+
if (a.name.length > b.name.length)
|
|
456
|
+
return -1;
|
|
457
|
+
return 0;
|
|
458
|
+
});
|
|
459
|
+
const pluginName = plugins?.[0].name;
|
|
460
|
+
return Promise.all(
|
|
461
|
+
files.map((file) => {
|
|
462
|
+
const fileWithMeta = {
|
|
463
|
+
...file,
|
|
464
|
+
meta: {
|
|
465
|
+
...file.meta || {},
|
|
466
|
+
pluginName
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
if (file.override) {
|
|
470
|
+
return fileManager.add(fileWithMeta);
|
|
471
|
+
}
|
|
472
|
+
return fileManager.addOrAppend(fileWithMeta);
|
|
473
|
+
})
|
|
474
|
+
);
|
|
426
475
|
},
|
|
427
476
|
resolvePath,
|
|
428
477
|
resolveName: (params) => {
|
|
@@ -475,7 +524,7 @@ var FileManager = class {
|
|
|
475
524
|
return files;
|
|
476
525
|
}
|
|
477
526
|
async add(file) {
|
|
478
|
-
const cacheItem = { id:
|
|
527
|
+
const cacheItem = { id: crypto__default.default.randomUUID(), file, status: "new" };
|
|
479
528
|
this.cache.set(cacheItem.id, cacheItem);
|
|
480
529
|
if (this.queue) {
|
|
481
530
|
await this.queue.run(async () => {
|
|
@@ -529,133 +578,6 @@ ${file.source}`,
|
|
|
529
578
|
return read(...params);
|
|
530
579
|
}
|
|
531
580
|
};
|
|
532
|
-
function writeIndexes(root, options) {
|
|
533
|
-
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
534
|
-
if (!tree) {
|
|
535
|
-
return void 0;
|
|
536
|
-
}
|
|
537
|
-
const fileReducer = (files2, item) => {
|
|
538
|
-
if (!item.children) {
|
|
539
|
-
return [];
|
|
540
|
-
}
|
|
541
|
-
if (item.children?.length > 1) {
|
|
542
|
-
const path = pathParser2__default.default.resolve(item.data.path, "index.ts");
|
|
543
|
-
const exports = item.children.map((file) => {
|
|
544
|
-
if (!file) {
|
|
545
|
-
return void 0;
|
|
546
|
-
}
|
|
547
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
548
|
-
if (importPath.includes("index") && path.includes("index")) {
|
|
549
|
-
return void 0;
|
|
550
|
-
}
|
|
551
|
-
return { path: importPath };
|
|
552
|
-
}).filter(Boolean);
|
|
553
|
-
files2.push({
|
|
554
|
-
path,
|
|
555
|
-
fileName: "index.ts",
|
|
556
|
-
source: "",
|
|
557
|
-
exports
|
|
558
|
-
});
|
|
559
|
-
} else {
|
|
560
|
-
item.children?.forEach((child) => {
|
|
561
|
-
const path = pathParser2__default.default.resolve(item.data.path, "index.ts");
|
|
562
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
563
|
-
files2.push({
|
|
564
|
-
path,
|
|
565
|
-
fileName: "index.ts",
|
|
566
|
-
source: "",
|
|
567
|
-
exports: [{ path: importPath }]
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
item.children.forEach((childItem) => {
|
|
572
|
-
fileReducer(files2, childItem);
|
|
573
|
-
});
|
|
574
|
-
return files2;
|
|
575
|
-
};
|
|
576
|
-
const files = fileReducer([], tree);
|
|
577
|
-
return files;
|
|
578
|
-
}
|
|
579
|
-
function combineFiles(files) {
|
|
580
|
-
return files.filter(Boolean).reduce((acc, curr) => {
|
|
581
|
-
if (!curr) {
|
|
582
|
-
return acc;
|
|
583
|
-
}
|
|
584
|
-
const prevIndex = acc.findIndex((item) => item.path === curr.path);
|
|
585
|
-
if (prevIndex !== -1) {
|
|
586
|
-
const prev = acc[prevIndex];
|
|
587
|
-
acc[prevIndex] = {
|
|
588
|
-
...curr,
|
|
589
|
-
source: `${prev.source}
|
|
590
|
-
${curr.source}`,
|
|
591
|
-
imports: [...prev.imports || [], ...curr.imports || []],
|
|
592
|
-
exports: [...prev.exports || [], ...curr.exports || []]
|
|
593
|
-
};
|
|
594
|
-
} else {
|
|
595
|
-
acc.push(curr);
|
|
596
|
-
}
|
|
597
|
-
return acc;
|
|
598
|
-
}, []);
|
|
599
|
-
}
|
|
600
|
-
function getFileSource(file) {
|
|
601
|
-
let { source } = file;
|
|
602
|
-
if (!file.fileName.endsWith(".ts")) {
|
|
603
|
-
return file.source;
|
|
604
|
-
}
|
|
605
|
-
const imports = [];
|
|
606
|
-
const exports = [];
|
|
607
|
-
file.imports?.forEach((curr) => {
|
|
608
|
-
const exists = imports.find((imp) => imp.path === curr.path);
|
|
609
|
-
if (!exists) {
|
|
610
|
-
imports.push({
|
|
611
|
-
...curr,
|
|
612
|
-
name: Array.isArray(curr.name) ? uniq__default.default(curr.name) : curr.name
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
|
|
616
|
-
imports.push(curr);
|
|
617
|
-
}
|
|
618
|
-
if (exists && Array.isArray(exists.name)) {
|
|
619
|
-
if (Array.isArray(curr.name)) {
|
|
620
|
-
exists.name = uniq__default.default([...exists.name, ...curr.name]);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
file.exports?.forEach((curr) => {
|
|
625
|
-
const exists = exports.find((imp) => imp.path === curr.path);
|
|
626
|
-
if (!exists) {
|
|
627
|
-
exports.push({
|
|
628
|
-
...curr,
|
|
629
|
-
name: Array.isArray(curr.name) ? uniq__default.default(curr.name) : curr.name
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {
|
|
633
|
-
exports.push(curr);
|
|
634
|
-
}
|
|
635
|
-
if (exists && Array.isArray(exists.name)) {
|
|
636
|
-
if (Array.isArray(curr.name)) {
|
|
637
|
-
exists.name = uniq__default.default([...exists.name, ...curr.name]);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
const importNodes = imports.reduce((prev, curr) => {
|
|
642
|
-
return [...prev, tsCodegen.createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
|
|
643
|
-
}, []);
|
|
644
|
-
const importSource = tsCodegen.print(importNodes);
|
|
645
|
-
const exportNodes = exports.reduce((prev, curr) => {
|
|
646
|
-
return [...prev, tsCodegen.createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })];
|
|
647
|
-
}, []);
|
|
648
|
-
const exportSource = tsCodegen.print(exportNodes);
|
|
649
|
-
if (importSource) {
|
|
650
|
-
source = `${importSource}
|
|
651
|
-
${source}`;
|
|
652
|
-
}
|
|
653
|
-
if (exportSource) {
|
|
654
|
-
source = `${exportSource}
|
|
655
|
-
${source}`;
|
|
656
|
-
}
|
|
657
|
-
return source;
|
|
658
|
-
}
|
|
659
581
|
|
|
660
582
|
// src/managers/pluginManager/PluginManager.ts
|
|
661
583
|
var hookNames = {
|
|
@@ -672,13 +594,13 @@ var hooks = Object.keys(hookNames);
|
|
|
672
594
|
var PluginManager = class {
|
|
673
595
|
plugins;
|
|
674
596
|
fileManager;
|
|
675
|
-
|
|
676
|
-
config;
|
|
597
|
+
onExecute;
|
|
677
598
|
core;
|
|
678
599
|
queue;
|
|
600
|
+
executer;
|
|
601
|
+
executed = [];
|
|
679
602
|
constructor(config, options) {
|
|
680
|
-
this.
|
|
681
|
-
this.config = config;
|
|
603
|
+
this.onExecute = options.onExecute;
|
|
682
604
|
this.queue = new Queue(10);
|
|
683
605
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
684
606
|
this.core = definePlugin({
|
|
@@ -686,10 +608,14 @@ var PluginManager = class {
|
|
|
686
608
|
fileManager: this.fileManager,
|
|
687
609
|
load: this.load,
|
|
688
610
|
resolvePath: this.resolvePath,
|
|
689
|
-
resolveName: this.resolveName
|
|
611
|
+
resolveName: this.resolveName,
|
|
612
|
+
getExecuter: this.getExecuter.bind(this)
|
|
690
613
|
});
|
|
691
614
|
this.plugins = [this.core, ...config.plugins || []];
|
|
692
615
|
}
|
|
616
|
+
getExecuter() {
|
|
617
|
+
return this.executer;
|
|
618
|
+
}
|
|
693
619
|
resolvePath = (params) => {
|
|
694
620
|
if (params.pluginName) {
|
|
695
621
|
return this.hookForPluginSync({
|
|
@@ -732,7 +658,7 @@ var PluginManager = class {
|
|
|
732
658
|
parameters
|
|
733
659
|
}) {
|
|
734
660
|
const plugin = this.getPlugin(hookName, pluginName);
|
|
735
|
-
return this.
|
|
661
|
+
return this.execute({
|
|
736
662
|
strategy: "hookFirst",
|
|
737
663
|
hookName,
|
|
738
664
|
parameters,
|
|
@@ -745,7 +671,7 @@ var PluginManager = class {
|
|
|
745
671
|
parameters
|
|
746
672
|
}) {
|
|
747
673
|
const plugin = this.getPlugin(hookName, pluginName);
|
|
748
|
-
return this.
|
|
674
|
+
return this.executeSync({
|
|
749
675
|
strategy: "hookFirst",
|
|
750
676
|
hookName,
|
|
751
677
|
parameters,
|
|
@@ -768,7 +694,7 @@ var PluginManager = class {
|
|
|
768
694
|
promise = promise.then((result) => {
|
|
769
695
|
if (result != null)
|
|
770
696
|
return result;
|
|
771
|
-
return this.
|
|
697
|
+
return this.execute({
|
|
772
698
|
strategy: "hookFirst",
|
|
773
699
|
hookName,
|
|
774
700
|
parameters,
|
|
@@ -791,7 +717,7 @@ var PluginManager = class {
|
|
|
791
717
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
792
718
|
if (skipped && skipped.has(plugin))
|
|
793
719
|
continue;
|
|
794
|
-
result = this.
|
|
720
|
+
result = this.executeSync({
|
|
795
721
|
strategy: "hookFirst",
|
|
796
722
|
hookName,
|
|
797
723
|
parameters,
|
|
@@ -813,18 +739,25 @@ var PluginManager = class {
|
|
|
813
739
|
if (plugin[hookName]?.sequential) {
|
|
814
740
|
await Promise.all(parallelPromises);
|
|
815
741
|
parallelPromises.length = 0;
|
|
816
|
-
await this.
|
|
742
|
+
await this.execute({
|
|
817
743
|
strategy: "hookParallel",
|
|
818
744
|
hookName,
|
|
819
745
|
parameters,
|
|
820
746
|
plugin
|
|
821
747
|
});
|
|
822
748
|
} else {
|
|
823
|
-
const promise = this.
|
|
824
|
-
|
|
749
|
+
const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin });
|
|
750
|
+
if (promise) {
|
|
751
|
+
parallelPromises.push(promise);
|
|
752
|
+
}
|
|
825
753
|
}
|
|
826
754
|
}
|
|
827
|
-
|
|
755
|
+
const results = await Promise.allSettled(parallelPromises);
|
|
756
|
+
const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
757
|
+
if (errors.length) {
|
|
758
|
+
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
759
|
+
}
|
|
760
|
+
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
828
761
|
}
|
|
829
762
|
// chains, reduces returned value, handling the reduced value as the first hook argument
|
|
830
763
|
hookReduceArg0({
|
|
@@ -835,14 +768,15 @@ var PluginManager = class {
|
|
|
835
768
|
const [argument0, ...rest] = parameters;
|
|
836
769
|
let promise = Promise.resolve(argument0);
|
|
837
770
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
838
|
-
promise = promise.then(
|
|
839
|
-
|
|
771
|
+
promise = promise.then((argument02) => {
|
|
772
|
+
const value = this.execute({
|
|
840
773
|
strategy: "hookReduceArg0",
|
|
841
774
|
hookName,
|
|
842
775
|
parameters: [argument02, ...rest],
|
|
843
776
|
plugin
|
|
844
|
-
})
|
|
845
|
-
|
|
777
|
+
});
|
|
778
|
+
return value;
|
|
779
|
+
}).then((result) => reduce.call(this.core.api, argument0, result, plugin));
|
|
846
780
|
}
|
|
847
781
|
return promise;
|
|
848
782
|
}
|
|
@@ -851,7 +785,7 @@ var PluginManager = class {
|
|
|
851
785
|
let promise = Promise.resolve();
|
|
852
786
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
853
787
|
promise = promise.then(
|
|
854
|
-
() => this.
|
|
788
|
+
() => this.execute({
|
|
855
789
|
strategy: "hookSeq",
|
|
856
790
|
hookName,
|
|
857
791
|
parameters,
|
|
@@ -869,13 +803,16 @@ var PluginManager = class {
|
|
|
869
803
|
const plugins = [...this.plugins];
|
|
870
804
|
const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName]);
|
|
871
805
|
if (!pluginByPluginName) {
|
|
872
|
-
if (this.config.logLevel === "warn" && this.logger?.spinner) {
|
|
873
|
-
this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`);
|
|
874
|
-
}
|
|
875
806
|
return this.core;
|
|
876
807
|
}
|
|
877
808
|
return pluginByPluginName;
|
|
878
809
|
}
|
|
810
|
+
addExecuter(executer) {
|
|
811
|
+
this.onExecute?.call(this, executer);
|
|
812
|
+
if (executer) {
|
|
813
|
+
this.executed.push(executer);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
879
816
|
/**
|
|
880
817
|
* Run an async plugin hook and return the result.
|
|
881
818
|
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
@@ -883,36 +820,42 @@ var PluginManager = class {
|
|
|
883
820
|
* @param plugin The actual pluginObject to run.
|
|
884
821
|
*/
|
|
885
822
|
// Implementation signature
|
|
886
|
-
|
|
823
|
+
execute({
|
|
887
824
|
strategy,
|
|
888
825
|
hookName,
|
|
889
826
|
parameters,
|
|
890
827
|
plugin
|
|
891
828
|
}) {
|
|
892
829
|
const hook = plugin[hookName];
|
|
830
|
+
if (!hook) {
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
893
833
|
return Promise.resolve().then(() => {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
834
|
+
this.executer = {
|
|
835
|
+
strategy,
|
|
836
|
+
hookName,
|
|
837
|
+
plugin
|
|
838
|
+
};
|
|
839
|
+
if (typeof hook === "function") {
|
|
840
|
+
const hookResult = hook.apply(this.core.api, parameters);
|
|
841
|
+
if (isPromise(hookResult)) {
|
|
842
|
+
return Promise.resolve(hookResult).then((result) => {
|
|
843
|
+
this.addExecuter({
|
|
844
|
+
strategy,
|
|
845
|
+
hookName,
|
|
846
|
+
plugin
|
|
847
|
+
});
|
|
848
|
+
return result;
|
|
849
|
+
});
|
|
906
850
|
}
|
|
907
851
|
return hookResult;
|
|
908
852
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
}
|
|
914
|
-
return result;
|
|
853
|
+
this.addExecuter({
|
|
854
|
+
strategy,
|
|
855
|
+
hookName,
|
|
856
|
+
plugin
|
|
915
857
|
});
|
|
858
|
+
return hook;
|
|
916
859
|
}).catch((e) => {
|
|
917
860
|
this.catcher(e, plugin, hookName);
|
|
918
861
|
});
|
|
@@ -924,18 +867,37 @@ var PluginManager = class {
|
|
|
924
867
|
* @param plugin The acutal plugin
|
|
925
868
|
* @param replaceContext When passed, the plugin context can be overridden.
|
|
926
869
|
*/
|
|
927
|
-
|
|
870
|
+
executeSync({
|
|
928
871
|
strategy,
|
|
929
872
|
hookName,
|
|
930
873
|
parameters,
|
|
931
874
|
plugin
|
|
932
875
|
}) {
|
|
933
876
|
const hook = plugin[hookName];
|
|
877
|
+
if (!hook) {
|
|
878
|
+
return null;
|
|
879
|
+
}
|
|
934
880
|
try {
|
|
935
|
-
|
|
936
|
-
|
|
881
|
+
this.executer = {
|
|
882
|
+
strategy,
|
|
883
|
+
hookName,
|
|
884
|
+
plugin
|
|
885
|
+
};
|
|
886
|
+
if (typeof hook === "function") {
|
|
887
|
+
const fn = hook.apply(this.core.api, parameters);
|
|
888
|
+
this.addExecuter({
|
|
889
|
+
strategy,
|
|
890
|
+
hookName,
|
|
891
|
+
plugin
|
|
892
|
+
});
|
|
893
|
+
return fn;
|
|
937
894
|
}
|
|
938
|
-
|
|
895
|
+
this.addExecuter({
|
|
896
|
+
strategy,
|
|
897
|
+
hookName,
|
|
898
|
+
plugin
|
|
899
|
+
});
|
|
900
|
+
return hook;
|
|
939
901
|
} catch (e) {
|
|
940
902
|
this.catcher(e, plugin, hookName);
|
|
941
903
|
return null;
|
|
@@ -944,7 +906,7 @@ var PluginManager = class {
|
|
|
944
906
|
catcher(e, plugin, hookName) {
|
|
945
907
|
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
946
908
|
`;
|
|
947
|
-
throw new
|
|
909
|
+
throw new PluginError(text, { cause: e, pluginManager: this });
|
|
948
910
|
}
|
|
949
911
|
};
|
|
950
912
|
function noReturn() {
|
|
@@ -968,6 +930,133 @@ function validatePlugins(plugins, dependedPluginNames) {
|
|
|
968
930
|
});
|
|
969
931
|
return true;
|
|
970
932
|
}
|
|
933
|
+
function writeIndexes(root, options) {
|
|
934
|
+
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
935
|
+
if (!tree) {
|
|
936
|
+
return void 0;
|
|
937
|
+
}
|
|
938
|
+
const fileReducer = (files2, item) => {
|
|
939
|
+
if (!item.children) {
|
|
940
|
+
return [];
|
|
941
|
+
}
|
|
942
|
+
if (item.children?.length > 1) {
|
|
943
|
+
const path = pathParser2__default.default.resolve(item.data.path, "index.ts");
|
|
944
|
+
const exports = item.children.map((file) => {
|
|
945
|
+
if (!file) {
|
|
946
|
+
return void 0;
|
|
947
|
+
}
|
|
948
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
949
|
+
if (importPath.includes("index") && path.includes("index")) {
|
|
950
|
+
return void 0;
|
|
951
|
+
}
|
|
952
|
+
return { path: importPath };
|
|
953
|
+
}).filter(Boolean);
|
|
954
|
+
files2.push({
|
|
955
|
+
path,
|
|
956
|
+
fileName: "index.ts",
|
|
957
|
+
source: "",
|
|
958
|
+
exports
|
|
959
|
+
});
|
|
960
|
+
} else {
|
|
961
|
+
item.children?.forEach((child) => {
|
|
962
|
+
const path = pathParser2__default.default.resolve(item.data.path, "index.ts");
|
|
963
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
964
|
+
files2.push({
|
|
965
|
+
path,
|
|
966
|
+
fileName: "index.ts",
|
|
967
|
+
source: "",
|
|
968
|
+
exports: [{ path: importPath }]
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
item.children.forEach((childItem) => {
|
|
973
|
+
fileReducer(files2, childItem);
|
|
974
|
+
});
|
|
975
|
+
return files2;
|
|
976
|
+
};
|
|
977
|
+
const files = fileReducer([], tree);
|
|
978
|
+
return files;
|
|
979
|
+
}
|
|
980
|
+
function combineFiles(files) {
|
|
981
|
+
return files.filter(Boolean).reduce((acc, curr) => {
|
|
982
|
+
if (!curr) {
|
|
983
|
+
return acc;
|
|
984
|
+
}
|
|
985
|
+
const prevIndex = acc.findIndex((item) => item.path === curr.path);
|
|
986
|
+
if (prevIndex !== -1) {
|
|
987
|
+
const prev = acc[prevIndex];
|
|
988
|
+
acc[prevIndex] = {
|
|
989
|
+
...curr,
|
|
990
|
+
source: `${prev.source}
|
|
991
|
+
${curr.source}`,
|
|
992
|
+
imports: [...prev.imports || [], ...curr.imports || []],
|
|
993
|
+
exports: [...prev.exports || [], ...curr.exports || []]
|
|
994
|
+
};
|
|
995
|
+
} else {
|
|
996
|
+
acc.push(curr);
|
|
997
|
+
}
|
|
998
|
+
return acc;
|
|
999
|
+
}, []);
|
|
1000
|
+
}
|
|
1001
|
+
function getFileSource(file) {
|
|
1002
|
+
let { source } = file;
|
|
1003
|
+
if (!file.fileName.endsWith(".ts")) {
|
|
1004
|
+
return file.source;
|
|
1005
|
+
}
|
|
1006
|
+
const imports = [];
|
|
1007
|
+
const exports = [];
|
|
1008
|
+
file.imports?.forEach((curr) => {
|
|
1009
|
+
const exists = imports.find((imp) => imp.path === curr.path);
|
|
1010
|
+
if (!exists) {
|
|
1011
|
+
imports.push({
|
|
1012
|
+
...curr,
|
|
1013
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
|
|
1017
|
+
imports.push(curr);
|
|
1018
|
+
}
|
|
1019
|
+
if (exists && Array.isArray(exists.name)) {
|
|
1020
|
+
if (Array.isArray(curr.name)) {
|
|
1021
|
+
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
file.exports?.forEach((curr) => {
|
|
1026
|
+
const exists = exports.find((imp) => imp.path === curr.path);
|
|
1027
|
+
if (!exists) {
|
|
1028
|
+
exports.push({
|
|
1029
|
+
...curr,
|
|
1030
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {
|
|
1034
|
+
exports.push(curr);
|
|
1035
|
+
}
|
|
1036
|
+
if (exists && Array.isArray(exists.name)) {
|
|
1037
|
+
if (Array.isArray(curr.name)) {
|
|
1038
|
+
exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
const importNodes = imports.reduce((prev, curr) => {
|
|
1043
|
+
return [...prev, tsCodegen.createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
|
|
1044
|
+
}, []);
|
|
1045
|
+
const importSource = tsCodegen.print(importNodes);
|
|
1046
|
+
const exportNodes = exports.reduce((prev, curr) => {
|
|
1047
|
+
return [...prev, tsCodegen.createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })];
|
|
1048
|
+
}, []);
|
|
1049
|
+
const exportSource = tsCodegen.print(exportNodes);
|
|
1050
|
+
if (importSource) {
|
|
1051
|
+
source = `${importSource}
|
|
1052
|
+
${source}`;
|
|
1053
|
+
}
|
|
1054
|
+
if (exportSource) {
|
|
1055
|
+
source = `${exportSource}
|
|
1056
|
+
${source}`;
|
|
1057
|
+
}
|
|
1058
|
+
return source;
|
|
1059
|
+
}
|
|
971
1060
|
|
|
972
1061
|
// src/build.ts
|
|
973
1062
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
@@ -976,8 +1065,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
976
1065
|
}
|
|
977
1066
|
return result;
|
|
978
1067
|
}
|
|
979
|
-
async function
|
|
1068
|
+
async function build(options) {
|
|
980
1069
|
const { config, logger } = options;
|
|
1070
|
+
try {
|
|
1071
|
+
await read(config.input.path);
|
|
1072
|
+
} catch (e) {
|
|
1073
|
+
throw new Error("Cannot read file defined in `input.path` or set with --input in the CLI of your Kubb config", { cause: e });
|
|
1074
|
+
}
|
|
981
1075
|
if (config.output.clean) {
|
|
982
1076
|
await clean(config.output.path);
|
|
983
1077
|
}
|
|
@@ -1005,7 +1099,17 @@ async function buildImplementation(options) {
|
|
|
1005
1099
|
}
|
|
1006
1100
|
}
|
|
1007
1101
|
};
|
|
1008
|
-
const
|
|
1102
|
+
const onExecute = (executer) => {
|
|
1103
|
+
if (!executer) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const { strategy, hookName, plugin } = executer;
|
|
1107
|
+
if (config.logLevel === "info" && logger?.spinner) {
|
|
1108
|
+
logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
1109
|
+
`;
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
const pluginManager = new PluginManager(config, { task: queueTask, onExecute });
|
|
1009
1113
|
const { plugins, fileManager } = pluginManager;
|
|
1010
1114
|
await pluginManager.hookParallel({
|
|
1011
1115
|
hookName: "validate",
|
|
@@ -1016,19 +1120,7 @@ async function buildImplementation(options) {
|
|
|
1016
1120
|
parameters: [config]
|
|
1017
1121
|
});
|
|
1018
1122
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1019
|
-
return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) };
|
|
1020
|
-
}
|
|
1021
|
-
function build(options) {
|
|
1022
|
-
return new Promise(async (resolve, reject) => {
|
|
1023
|
-
try {
|
|
1024
|
-
const output = await buildImplementation(options);
|
|
1025
|
-
setTimeout(() => {
|
|
1026
|
-
resolve(output);
|
|
1027
|
-
}, 500);
|
|
1028
|
-
} catch (e) {
|
|
1029
|
-
reject(e);
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1123
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })), pluginManager };
|
|
1032
1124
|
}
|
|
1033
1125
|
|
|
1034
1126
|
// src/config.ts
|
|
@@ -1060,6 +1152,8 @@ var src_default = build;
|
|
|
1060
1152
|
|
|
1061
1153
|
exports.FileManager = FileManager;
|
|
1062
1154
|
exports.Generator = Generator;
|
|
1155
|
+
exports.ParallelPluginError = ParallelPluginError;
|
|
1156
|
+
exports.PluginError = PluginError;
|
|
1063
1157
|
exports.PluginManager = PluginManager;
|
|
1064
1158
|
exports.Queue = Queue;
|
|
1065
1159
|
exports.SchemaGenerator = SchemaGenerator;
|
|
@@ -1077,6 +1171,7 @@ exports.getEncodedText = getEncodedText;
|
|
|
1077
1171
|
exports.getFileSource = getFileSource;
|
|
1078
1172
|
exports.getPathMode = getPathMode;
|
|
1079
1173
|
exports.getRelativePath = getRelativePath;
|
|
1174
|
+
exports.getStackTrace = getStackTrace;
|
|
1080
1175
|
exports.getUniqueName = getUniqueName;
|
|
1081
1176
|
exports.hooks = hooks;
|
|
1082
1177
|
exports.isPromise = isPromise;
|
|
@@ -1091,5 +1186,3 @@ exports.transformReservedWord = transformReservedWord;
|
|
|
1091
1186
|
exports.validatePlugins = validatePlugins;
|
|
1092
1187
|
exports.write = write;
|
|
1093
1188
|
exports.writeIndexes = writeIndexes;
|
|
1094
|
-
//# sourceMappingURL=out.js.map
|
|
1095
|
-
//# sourceMappingURL=index.cjs.map
|