@kubb/core 1.1.13 → 1.2.0
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 +287 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +83 -34
- package/dist/index.js +273 -133
- package/dist/index.js.map +1 -1
- package/globals.d.ts +39 -0
- package/package.json +12 -6
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,9 @@ var pathParser2 = require('path');
|
|
|
8
8
|
var changeCase = require('change-case');
|
|
9
9
|
var rimraf = require('rimraf');
|
|
10
10
|
var dirTree = require('directory-tree');
|
|
11
|
+
var mod = require('module');
|
|
12
|
+
var url = require('url');
|
|
13
|
+
var pc = require('picocolors');
|
|
11
14
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
12
15
|
|
|
13
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -16,6 +19,8 @@ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
|
16
19
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
17
20
|
var pathParser2__default = /*#__PURE__*/_interopDefault(pathParser2);
|
|
18
21
|
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
22
|
+
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
23
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
19
24
|
|
|
20
25
|
// src/managers/fileManager/FileManager.ts
|
|
21
26
|
|
|
@@ -23,6 +28,12 @@ var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
|
23
28
|
function isPromise(result) {
|
|
24
29
|
return typeof result?.then === "function";
|
|
25
30
|
}
|
|
31
|
+
function isPromiseFulfilledResult(result) {
|
|
32
|
+
return result.status === "fulfilled";
|
|
33
|
+
}
|
|
34
|
+
function isPromiseRejectedResult(result) {
|
|
35
|
+
return result.status === "rejected";
|
|
36
|
+
}
|
|
26
37
|
async function safeWriteFileToPath(path, data) {
|
|
27
38
|
const passedPath = pathParser2__default.default.dirname(pathParser2__default.default.resolve(path));
|
|
28
39
|
await fs__default.default.mkdir(passedPath, { recursive: true });
|
|
@@ -412,6 +423,31 @@ function getStackTrace(belowFn) {
|
|
|
412
423
|
|
|
413
424
|
// src/utils/uniqueId.ts
|
|
414
425
|
var uniqueId = ((counter) => (str = "") => `${str}${++counter}`)(0);
|
|
426
|
+
var SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
427
|
+
function normalizeDirectory(directory) {
|
|
428
|
+
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
429
|
+
return `${directory}/`;
|
|
430
|
+
}
|
|
431
|
+
return directory;
|
|
432
|
+
}
|
|
433
|
+
function getLocation(path, cwd) {
|
|
434
|
+
let location = path;
|
|
435
|
+
if (cwd) {
|
|
436
|
+
const require2 = mod__default.default.createRequire(normalizeDirectory(cwd));
|
|
437
|
+
location = require2.resolve(path);
|
|
438
|
+
}
|
|
439
|
+
return location;
|
|
440
|
+
}
|
|
441
|
+
async function importModule(path, cwd) {
|
|
442
|
+
try {
|
|
443
|
+
const location = getLocation(path, cwd);
|
|
444
|
+
const module = await import(url.pathToFileURL(location).href);
|
|
445
|
+
return module?.default ?? module;
|
|
446
|
+
} catch (e) {
|
|
447
|
+
console.log(e);
|
|
448
|
+
return void 0;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
415
451
|
|
|
416
452
|
// src/utils/throttle.ts
|
|
417
453
|
var throttle = (fn, delay) => {
|
|
@@ -440,108 +476,53 @@ var throttle = (fn, delay) => {
|
|
|
440
476
|
];
|
|
441
477
|
};
|
|
442
478
|
|
|
443
|
-
// src/
|
|
444
|
-
var
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
this.task = options.task;
|
|
451
|
-
this.queue = options.queue;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
getCache(id) {
|
|
455
|
-
return this.cache.get(id);
|
|
456
|
-
}
|
|
457
|
-
getCacheByPath(path) {
|
|
458
|
-
let cache;
|
|
459
|
-
this.cache.forEach((item) => {
|
|
460
|
-
if (item.file.path === path) {
|
|
461
|
-
cache = item;
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
return cache;
|
|
465
|
-
}
|
|
466
|
-
get files() {
|
|
467
|
-
const files = [];
|
|
468
|
-
this.cache.forEach((item) => {
|
|
469
|
-
files.push(item.file);
|
|
470
|
-
});
|
|
471
|
-
return files;
|
|
472
|
-
}
|
|
473
|
-
get cachedFiles() {
|
|
474
|
-
const files = [];
|
|
475
|
-
this.cache.forEach((item) => {
|
|
476
|
-
files.push(item);
|
|
477
|
-
});
|
|
478
|
-
return files;
|
|
479
|
-
}
|
|
480
|
-
async add(file) {
|
|
481
|
-
const cacheItem = { id: crypto__default.default.randomUUID(), file, status: "new" };
|
|
482
|
-
this.cache.set(cacheItem.id, cacheItem);
|
|
483
|
-
if (this.queue) {
|
|
484
|
-
await this.queue.run(async () => {
|
|
485
|
-
await this.task?.(cacheItem.id, file);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
return file;
|
|
479
|
+
// src/utils/SummaryError.ts
|
|
480
|
+
var SummaryError = class extends Error {
|
|
481
|
+
summary;
|
|
482
|
+
constructor(message, options) {
|
|
483
|
+
super(message, { cause: options.cause });
|
|
484
|
+
this.name = "SummaryError";
|
|
485
|
+
this.summary = options.summary || [];
|
|
489
486
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
this.cache.delete(previousCache.id);
|
|
499
|
-
return this.add({
|
|
500
|
-
...file,
|
|
501
|
-
source: `${previousCache.file.source}
|
|
502
|
-
${file.source}`,
|
|
503
|
-
imports: [...previousCache.file.imports || [], ...file.imports || []],
|
|
504
|
-
exports: [...previousCache.file.exports || [], ...file.exports || []]
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
return this.add(file);
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/utils/Warning.ts
|
|
490
|
+
var Warning = class extends Error {
|
|
491
|
+
constructor(message, options) {
|
|
492
|
+
super(message, { cause: options?.cause });
|
|
493
|
+
this.name = "Warning";
|
|
508
494
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
495
|
+
};
|
|
496
|
+
function createLogger(spinner) {
|
|
497
|
+
const [log] = throttle((message) => {
|
|
498
|
+
if (message && spinner) {
|
|
499
|
+
spinner.text = message;
|
|
513
500
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const cacheItem = this.getCache(id);
|
|
519
|
-
return cacheItem?.file;
|
|
520
|
-
}
|
|
521
|
-
remove(id) {
|
|
522
|
-
const cacheItem = this.getCache(id);
|
|
523
|
-
if (!cacheItem) {
|
|
524
|
-
return;
|
|
501
|
+
}, 100);
|
|
502
|
+
const [error] = throttle((message) => {
|
|
503
|
+
if (message) {
|
|
504
|
+
throw new Error(message || "Something went wrong");
|
|
525
505
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return this.queue.run(async () => {
|
|
531
|
-
return write(...params);
|
|
532
|
-
});
|
|
506
|
+
}, 100);
|
|
507
|
+
const [warn] = throttle((message) => {
|
|
508
|
+
if (message && spinner) {
|
|
509
|
+
spinner.warn(pc__default.default.yellow(message));
|
|
533
510
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return this.queue.run(async () => {
|
|
539
|
-
return read(...params);
|
|
540
|
-
});
|
|
511
|
+
}, 100);
|
|
512
|
+
const [info] = throttle((message) => {
|
|
513
|
+
if (message && spinner) {
|
|
514
|
+
spinner.text = message;
|
|
541
515
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
516
|
+
}, 100);
|
|
517
|
+
const logger = {
|
|
518
|
+
log,
|
|
519
|
+
error,
|
|
520
|
+
warn,
|
|
521
|
+
info,
|
|
522
|
+
spinner
|
|
523
|
+
};
|
|
524
|
+
return logger;
|
|
525
|
+
}
|
|
545
526
|
function writeIndexes(root, options = {}) {
|
|
546
527
|
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
547
528
|
if (!tree) {
|
|
@@ -599,7 +580,8 @@ function combineFiles(files) {
|
|
|
599
580
|
source: prev.source && curr.source ? `${prev.source}
|
|
600
581
|
${curr.source}` : "'",
|
|
601
582
|
imports: [...prev.imports || [], ...curr.imports || []],
|
|
602
|
-
exports: [...prev.exports || [], ...curr.exports || []]
|
|
583
|
+
exports: [...prev.exports || [], ...curr.exports || []],
|
|
584
|
+
env: { ...prev.env || {}, ...curr.env || {} }
|
|
603
585
|
};
|
|
604
586
|
} else {
|
|
605
587
|
acc.push(curr);
|
|
@@ -607,9 +589,10 @@ ${curr.source}` : "'",
|
|
|
607
589
|
return acc;
|
|
608
590
|
}, []);
|
|
609
591
|
}
|
|
592
|
+
var extensions = [".js", ".ts"];
|
|
610
593
|
function getFileSource(file) {
|
|
611
594
|
let { source } = file;
|
|
612
|
-
if (!file.fileName.endsWith(
|
|
595
|
+
if (!extensions.some((extension) => file.fileName.endsWith(extension))) {
|
|
613
596
|
return file.source;
|
|
614
597
|
}
|
|
615
598
|
const imports = [];
|
|
@@ -656,6 +639,7 @@ function getFileSource(file) {
|
|
|
656
639
|
return [...prev, tsCodegen.createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })];
|
|
657
640
|
}, []);
|
|
658
641
|
const exportSource = tsCodegen.print(exportNodes);
|
|
642
|
+
source = getEnvSource(source, file.env);
|
|
659
643
|
if (importSource) {
|
|
660
644
|
source = `${importSource}
|
|
661
645
|
${source}`;
|
|
@@ -666,6 +650,149 @@ ${source}`;
|
|
|
666
650
|
}
|
|
667
651
|
return source;
|
|
668
652
|
}
|
|
653
|
+
function searchAndReplace(options) {
|
|
654
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
655
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
656
|
+
`${prefix}["${key}"]`,
|
|
657
|
+
`${prefix}['${key}']`,
|
|
658
|
+
`${prefix}[\`${key}\`]`,
|
|
659
|
+
`${prefix}"${key}"`,
|
|
660
|
+
`${prefix}'${key}'`,
|
|
661
|
+
`${prefix}\`${key}\``,
|
|
662
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
663
|
+
];
|
|
664
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
665
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
666
|
+
}, text);
|
|
667
|
+
}
|
|
668
|
+
function getEnvSource(source, env) {
|
|
669
|
+
if (!env) {
|
|
670
|
+
return source;
|
|
671
|
+
}
|
|
672
|
+
const keys = Object.keys(env);
|
|
673
|
+
if (!keys.length) {
|
|
674
|
+
return source;
|
|
675
|
+
}
|
|
676
|
+
return keys.reduce((prev, key) => {
|
|
677
|
+
const environmentValue = env[key];
|
|
678
|
+
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
679
|
+
if (key.toUpperCase() !== key) {
|
|
680
|
+
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
681
|
+
}
|
|
682
|
+
if (typeof replaceBy === "string") {
|
|
683
|
+
prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
684
|
+
prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
685
|
+
`, "ig"), ""), replaceBy, key });
|
|
686
|
+
}
|
|
687
|
+
return prev;
|
|
688
|
+
}, source);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// src/managers/fileManager/FileManager.ts
|
|
692
|
+
var FileManager = class {
|
|
693
|
+
cache = /* @__PURE__ */ new Map();
|
|
694
|
+
task;
|
|
695
|
+
queue;
|
|
696
|
+
constructor(options) {
|
|
697
|
+
if (options) {
|
|
698
|
+
this.task = options.task;
|
|
699
|
+
this.queue = options.queue;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
getCache(id) {
|
|
703
|
+
return this.cache.get(id);
|
|
704
|
+
}
|
|
705
|
+
get extensions() {
|
|
706
|
+
return extensions;
|
|
707
|
+
}
|
|
708
|
+
getCacheByPath(path) {
|
|
709
|
+
let cache;
|
|
710
|
+
this.cache.forEach((item) => {
|
|
711
|
+
if (item.file.path === path) {
|
|
712
|
+
cache = item;
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
return cache;
|
|
716
|
+
}
|
|
717
|
+
get files() {
|
|
718
|
+
const files = [];
|
|
719
|
+
this.cache.forEach((item) => {
|
|
720
|
+
files.push(item.file);
|
|
721
|
+
});
|
|
722
|
+
return files;
|
|
723
|
+
}
|
|
724
|
+
get cachedFiles() {
|
|
725
|
+
const files = [];
|
|
726
|
+
this.cache.forEach((item) => {
|
|
727
|
+
files.push(item);
|
|
728
|
+
});
|
|
729
|
+
return files;
|
|
730
|
+
}
|
|
731
|
+
async add(file) {
|
|
732
|
+
const cacheItem = { id: crypto__default.default.randomUUID(), file, status: "new" };
|
|
733
|
+
this.cache.set(cacheItem.id, cacheItem);
|
|
734
|
+
if (this.queue) {
|
|
735
|
+
await this.queue.run(async () => {
|
|
736
|
+
await this.task?.(cacheItem.id, file);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
return file;
|
|
740
|
+
}
|
|
741
|
+
addOrAppend(file) {
|
|
742
|
+
if (!file.path.endsWith(file.fileName)) ;
|
|
743
|
+
const previousCache = this.getCacheByPath(file.path);
|
|
744
|
+
if (previousCache) {
|
|
745
|
+
const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source);
|
|
746
|
+
if (sourceAlreadyExists) {
|
|
747
|
+
return Promise.resolve(file);
|
|
748
|
+
}
|
|
749
|
+
this.cache.delete(previousCache.id);
|
|
750
|
+
return this.add({
|
|
751
|
+
...file,
|
|
752
|
+
source: `${previousCache.file.source}
|
|
753
|
+
${file.source}`,
|
|
754
|
+
imports: [...previousCache.file.imports || [], ...file.imports || []],
|
|
755
|
+
exports: [...previousCache.file.exports || [], ...file.exports || []]
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
return this.add(file);
|
|
759
|
+
}
|
|
760
|
+
setStatus(id, status) {
|
|
761
|
+
const cacheItem = this.getCache(id);
|
|
762
|
+
if (!cacheItem) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
cacheItem.status = status;
|
|
766
|
+
this.cache.set(id, cacheItem);
|
|
767
|
+
}
|
|
768
|
+
get(id) {
|
|
769
|
+
const cacheItem = this.getCache(id);
|
|
770
|
+
return cacheItem?.file;
|
|
771
|
+
}
|
|
772
|
+
remove(id) {
|
|
773
|
+
const cacheItem = this.getCache(id);
|
|
774
|
+
if (!cacheItem) {
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
this.setStatus(id, "removed");
|
|
778
|
+
}
|
|
779
|
+
async write(...params) {
|
|
780
|
+
if (this.queue) {
|
|
781
|
+
return this.queue.run(async () => {
|
|
782
|
+
return write(...params);
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return write(...params);
|
|
786
|
+
}
|
|
787
|
+
async read(...params) {
|
|
788
|
+
if (this.queue) {
|
|
789
|
+
return this.queue.run(async () => {
|
|
790
|
+
return read(...params);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
return read(...params);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
669
796
|
function createPlugin(factory) {
|
|
670
797
|
return (options) => {
|
|
671
798
|
const plugin = factory(options);
|
|
@@ -680,9 +807,9 @@ function createPlugin(factory) {
|
|
|
680
807
|
return plugin;
|
|
681
808
|
};
|
|
682
809
|
}
|
|
683
|
-
var
|
|
810
|
+
var pluginName = "core";
|
|
684
811
|
var definePlugin = createPlugin((options) => {
|
|
685
|
-
const { fileManager, resolvePath, resolveName, load } = options;
|
|
812
|
+
const { fileManager, resolvePath, resolveName, load, logger } = options;
|
|
686
813
|
const api = {
|
|
687
814
|
get config() {
|
|
688
815
|
return options.config;
|
|
@@ -699,14 +826,14 @@ var definePlugin = createPlugin((options) => {
|
|
|
699
826
|
}
|
|
700
827
|
return 0;
|
|
701
828
|
});
|
|
702
|
-
const
|
|
829
|
+
const pluginName2 = plugins?.[0]?.name;
|
|
703
830
|
return Promise.all(
|
|
704
831
|
files.map((file) => {
|
|
705
832
|
const fileWithMeta = {
|
|
706
833
|
...file,
|
|
707
834
|
meta: {
|
|
708
835
|
...file.meta || {},
|
|
709
|
-
pluginName
|
|
836
|
+
pluginName: pluginName2
|
|
710
837
|
}
|
|
711
838
|
};
|
|
712
839
|
if (file.override) {
|
|
@@ -718,29 +845,30 @@ var definePlugin = createPlugin((options) => {
|
|
|
718
845
|
},
|
|
719
846
|
resolvePath,
|
|
720
847
|
resolveName: (params) => {
|
|
721
|
-
const
|
|
722
|
-
return transformReservedWord(
|
|
848
|
+
const name = resolveName(params);
|
|
849
|
+
return transformReservedWord(name);
|
|
723
850
|
},
|
|
724
851
|
load,
|
|
852
|
+
logger,
|
|
725
853
|
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
726
854
|
};
|
|
727
855
|
return {
|
|
728
|
-
name,
|
|
856
|
+
name: pluginName,
|
|
729
857
|
options,
|
|
730
858
|
api,
|
|
731
859
|
resolvePath(fileName) {
|
|
732
860
|
const root = pathParser2__default.default.resolve(this.config.root, this.config.output.path);
|
|
733
861
|
return pathParser2__default.default.resolve(root, fileName);
|
|
734
862
|
},
|
|
735
|
-
resolveName(
|
|
736
|
-
return
|
|
863
|
+
resolveName(name) {
|
|
864
|
+
return name;
|
|
737
865
|
}
|
|
738
866
|
};
|
|
739
867
|
});
|
|
740
868
|
|
|
741
869
|
// src/managers/pluginManager/ParallelPluginError.ts
|
|
742
870
|
var ParallelPluginError = class extends Error {
|
|
743
|
-
errors;
|
|
871
|
+
errors = [];
|
|
744
872
|
pluginManager;
|
|
745
873
|
constructor(message, options) {
|
|
746
874
|
super(message, { cause: options.cause });
|
|
@@ -748,14 +876,27 @@ var ParallelPluginError = class extends Error {
|
|
|
748
876
|
this.errors = options.errors;
|
|
749
877
|
this.pluginManager = options.pluginManager;
|
|
750
878
|
}
|
|
879
|
+
findError(searchError) {
|
|
880
|
+
return this.errors.find((error) => {
|
|
881
|
+
if (error.cause) {
|
|
882
|
+
if (error.cause.name == searchError.name) {
|
|
883
|
+
return true;
|
|
884
|
+
}
|
|
885
|
+
return !!this.findError(error.cause);
|
|
886
|
+
}
|
|
887
|
+
return error.name === searchError.name;
|
|
888
|
+
})?.cause;
|
|
889
|
+
}
|
|
751
890
|
};
|
|
752
891
|
|
|
753
892
|
// src/managers/pluginManager/PluginError.ts
|
|
754
893
|
var PluginError = class extends Error {
|
|
755
894
|
pluginManager;
|
|
895
|
+
cause;
|
|
756
896
|
constructor(message, options) {
|
|
757
897
|
super(message, { cause: options.cause });
|
|
758
898
|
this.name = "PluginError";
|
|
899
|
+
this.cause = options.cause;
|
|
759
900
|
this.pluginManager = options.pluginManager;
|
|
760
901
|
}
|
|
761
902
|
};
|
|
@@ -780,12 +921,15 @@ var PluginManager = class {
|
|
|
780
921
|
queue;
|
|
781
922
|
executer;
|
|
782
923
|
executed = [];
|
|
924
|
+
logger;
|
|
783
925
|
constructor(config, options) {
|
|
784
926
|
this.onExecute = options.onExecute?.bind(this);
|
|
927
|
+
this.logger = options.logger;
|
|
785
928
|
this.queue = new Queue(10);
|
|
786
929
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
787
930
|
this.core = definePlugin({
|
|
788
931
|
config,
|
|
932
|
+
logger: this.logger,
|
|
789
933
|
fileManager: this.fileManager,
|
|
790
934
|
load: this.load,
|
|
791
935
|
resolvePath: this.resolvePath,
|
|
@@ -834,11 +978,11 @@ var PluginManager = class {
|
|
|
834
978
|
* Run only hook for a specific plugin name
|
|
835
979
|
*/
|
|
836
980
|
hookForPlugin({
|
|
837
|
-
pluginName,
|
|
981
|
+
pluginName: pluginName2,
|
|
838
982
|
hookName,
|
|
839
983
|
parameters
|
|
840
984
|
}) {
|
|
841
|
-
const plugin = this.getPlugin(hookName,
|
|
985
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
842
986
|
return this.execute({
|
|
843
987
|
strategy: "hookFirst",
|
|
844
988
|
hookName,
|
|
@@ -847,11 +991,11 @@ var PluginManager = class {
|
|
|
847
991
|
});
|
|
848
992
|
}
|
|
849
993
|
hookForPluginSync({
|
|
850
|
-
pluginName,
|
|
994
|
+
pluginName: pluginName2,
|
|
851
995
|
hookName,
|
|
852
996
|
parameters
|
|
853
997
|
}) {
|
|
854
|
-
const plugin = this.getPlugin(hookName,
|
|
998
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
855
999
|
return this.executeSync({
|
|
856
1000
|
strategy: "hookFirst",
|
|
857
1001
|
hookName,
|
|
@@ -936,7 +1080,12 @@ var PluginManager = class {
|
|
|
936
1080
|
}
|
|
937
1081
|
}
|
|
938
1082
|
const results = await Promise.allSettled(parallelPromises);
|
|
939
|
-
const errors = results.
|
|
1083
|
+
const errors = results.map((result) => {
|
|
1084
|
+
if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
|
|
1085
|
+
return result.reason;
|
|
1086
|
+
}
|
|
1087
|
+
return void 0;
|
|
1088
|
+
}).filter(Boolean);
|
|
940
1089
|
if (errors.length) {
|
|
941
1090
|
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
942
1091
|
}
|
|
@@ -987,9 +1136,9 @@ var PluginManager = class {
|
|
|
987
1136
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
988
1137
|
return plugins;
|
|
989
1138
|
}
|
|
990
|
-
getPlugin(hookName,
|
|
1139
|
+
getPlugin(hookName, pluginName2) {
|
|
991
1140
|
const plugins = [...this.plugins];
|
|
992
|
-
const pluginByPluginName = plugins.find((item) => item.name ===
|
|
1141
|
+
const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
|
|
993
1142
|
if (!pluginByPluginName) {
|
|
994
1143
|
return this.core;
|
|
995
1144
|
}
|
|
@@ -1046,6 +1195,7 @@ var PluginManager = class {
|
|
|
1046
1195
|
return hook;
|
|
1047
1196
|
}).catch((e) => {
|
|
1048
1197
|
this.catcher(e, plugin, hookName);
|
|
1198
|
+
return null;
|
|
1049
1199
|
});
|
|
1050
1200
|
}
|
|
1051
1201
|
/**
|
|
@@ -1110,31 +1260,21 @@ function validatePlugins(plugins, dependedPluginNames) {
|
|
|
1110
1260
|
} else {
|
|
1111
1261
|
pluginNames = dependedPluginNames;
|
|
1112
1262
|
}
|
|
1113
|
-
pluginNames.forEach((
|
|
1114
|
-
const exists = plugins.some((plugin) => plugin.name ===
|
|
1263
|
+
pluginNames.forEach((pluginName2) => {
|
|
1264
|
+
const exists = plugins.some((plugin) => plugin.name === pluginName2);
|
|
1115
1265
|
if (!exists) {
|
|
1116
|
-
throw new ValidationPluginError(`This plugin depends on the ${
|
|
1266
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1117
1267
|
}
|
|
1118
1268
|
});
|
|
1119
1269
|
return true;
|
|
1120
1270
|
}
|
|
1121
1271
|
|
|
1122
|
-
// src/managers/pluginManager/SummaryError.ts
|
|
1123
|
-
var SummaryError = class extends Error {
|
|
1124
|
-
summary;
|
|
1125
|
-
constructor(message, options) {
|
|
1126
|
-
super(message, { cause: options.cause });
|
|
1127
|
-
this.name = "SummaryError";
|
|
1128
|
-
this.summary = options.summary || [];
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
1272
|
// src/build.ts
|
|
1133
1273
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1134
1274
|
return result;
|
|
1135
1275
|
}
|
|
1136
1276
|
async function build(options) {
|
|
1137
|
-
const { config, logger } = options;
|
|
1277
|
+
const { config, logger = createLogger() } = options;
|
|
1138
1278
|
try {
|
|
1139
1279
|
if (!isURL(config.input.path)) {
|
|
1140
1280
|
await read(config.input.path);
|
|
@@ -1177,11 +1317,12 @@ async function build(options) {
|
|
|
1177
1317
|
return;
|
|
1178
1318
|
}
|
|
1179
1319
|
const { hookName, plugin } = executer;
|
|
1180
|
-
if (config.logLevel === "info"
|
|
1181
|
-
|
|
1320
|
+
if (config.logLevel === "info") {
|
|
1321
|
+
const messsage = `\u{1FA82} Executing ${hookName || "unknown"}(${pc__default.default.yellow(plugin.name || "unknown")})`;
|
|
1322
|
+
logger.log(messsage);
|
|
1182
1323
|
}
|
|
1183
1324
|
};
|
|
1184
|
-
const pluginManager = new PluginManager(config, { task: queueTask, onExecute });
|
|
1325
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, onExecute });
|
|
1185
1326
|
const { plugins, fileManager } = pluginManager;
|
|
1186
1327
|
await pluginManager.hookParallel({
|
|
1187
1328
|
hookName: "validate",
|
|
@@ -1222,6 +1363,10 @@ var SchemaGenerator = class extends Generator {
|
|
|
1222
1363
|
// src/index.ts
|
|
1223
1364
|
var src_default = build;
|
|
1224
1365
|
|
|
1366
|
+
Object.defineProperty(exports, 'pc', {
|
|
1367
|
+
enumerable: true,
|
|
1368
|
+
get: function () { return pc__default.default; }
|
|
1369
|
+
});
|
|
1225
1370
|
exports.FileManager = FileManager;
|
|
1226
1371
|
exports.Generator = Generator;
|
|
1227
1372
|
exports.ParallelPluginError = ParallelPluginError;
|
|
@@ -1232,26 +1377,35 @@ exports.SchemaGenerator = SchemaGenerator;
|
|
|
1232
1377
|
exports.SummaryError = SummaryError;
|
|
1233
1378
|
exports.TreeNode = TreeNode;
|
|
1234
1379
|
exports.ValidationPluginError = ValidationPluginError;
|
|
1380
|
+
exports.Warning = Warning;
|
|
1235
1381
|
exports.build = build;
|
|
1236
1382
|
exports.clean = clean;
|
|
1237
1383
|
exports.combineFiles = combineFiles;
|
|
1238
1384
|
exports.createJSDocBlockText = createJSDocBlockText;
|
|
1385
|
+
exports.createLogger = createLogger;
|
|
1239
1386
|
exports.createPlugin = createPlugin;
|
|
1240
1387
|
exports.createPluginCache = createPluginCache;
|
|
1241
1388
|
exports.default = src_default;
|
|
1242
1389
|
exports.defineConfig = defineConfig;
|
|
1390
|
+
exports.extensions = extensions;
|
|
1243
1391
|
exports.getEncodedText = getEncodedText;
|
|
1244
1392
|
exports.getFileSource = getFileSource;
|
|
1393
|
+
exports.getLocation = getLocation;
|
|
1245
1394
|
exports.getPathMode = getPathMode;
|
|
1246
1395
|
exports.getRelativePath = getRelativePath;
|
|
1247
1396
|
exports.getStackTrace = getStackTrace;
|
|
1248
1397
|
exports.getUniqueName = getUniqueName;
|
|
1249
1398
|
exports.hooks = hooks;
|
|
1399
|
+
exports.importModule = importModule;
|
|
1250
1400
|
exports.isPromise = isPromise;
|
|
1401
|
+
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
1402
|
+
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
1251
1403
|
exports.isURL = isURL;
|
|
1252
|
-
exports.name =
|
|
1404
|
+
exports.name = pluginName;
|
|
1253
1405
|
exports.nameSorter = nameSorter;
|
|
1406
|
+
exports.normalizeDirectory = normalizeDirectory;
|
|
1254
1407
|
exports.objectToParameters = objectToParameters;
|
|
1408
|
+
exports.pluginName = pluginName;
|
|
1255
1409
|
exports.read = read;
|
|
1256
1410
|
exports.renderTemplate = renderTemplate;
|
|
1257
1411
|
exports.throttle = throttle;
|