@kubb/core 1.1.12 → 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 +292 -114
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +83 -26
- package/dist/index.js +277 -114
- package/dist/index.js.map +1 -0
- 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,98 +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;
|
|
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 || [];
|
|
472
486
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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";
|
|
479
494
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (
|
|
484
|
-
|
|
485
|
-
await this.task?.(cacheItem.id, file);
|
|
486
|
-
});
|
|
495
|
+
};
|
|
496
|
+
function createLogger(spinner) {
|
|
497
|
+
const [log] = throttle((message) => {
|
|
498
|
+
if (message && spinner) {
|
|
499
|
+
spinner.text = message;
|
|
487
500
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const previousCache = this.getCacheByPath(file.path);
|
|
493
|
-
if (previousCache) {
|
|
494
|
-
const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source);
|
|
495
|
-
if (sourceAlreadyExists) {
|
|
496
|
-
return Promise.resolve(file);
|
|
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
|
-
});
|
|
501
|
+
}, 100);
|
|
502
|
+
const [error] = throttle((message) => {
|
|
503
|
+
if (message) {
|
|
504
|
+
throw new Error(message || "Something went wrong");
|
|
506
505
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (!cacheItem) {
|
|
512
|
-
return;
|
|
506
|
+
}, 100);
|
|
507
|
+
const [warn] = throttle((message) => {
|
|
508
|
+
if (message && spinner) {
|
|
509
|
+
spinner.warn(pc__default.default.yellow(message));
|
|
513
510
|
}
|
|
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;
|
|
511
|
+
}, 100);
|
|
512
|
+
const [info] = throttle((message) => {
|
|
513
|
+
if (message && spinner) {
|
|
514
|
+
spinner.text = message;
|
|
525
515
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
|
|
516
|
+
}, 100);
|
|
517
|
+
const logger = {
|
|
518
|
+
log,
|
|
519
|
+
error,
|
|
520
|
+
warn,
|
|
521
|
+
info,
|
|
522
|
+
spinner
|
|
523
|
+
};
|
|
524
|
+
return logger;
|
|
525
|
+
}
|
|
535
526
|
function writeIndexes(root, options = {}) {
|
|
536
527
|
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
537
528
|
if (!tree) {
|
|
@@ -589,7 +580,8 @@ function combineFiles(files) {
|
|
|
589
580
|
source: prev.source && curr.source ? `${prev.source}
|
|
590
581
|
${curr.source}` : "'",
|
|
591
582
|
imports: [...prev.imports || [], ...curr.imports || []],
|
|
592
|
-
exports: [...prev.exports || [], ...curr.exports || []]
|
|
583
|
+
exports: [...prev.exports || [], ...curr.exports || []],
|
|
584
|
+
env: { ...prev.env || {}, ...curr.env || {} }
|
|
593
585
|
};
|
|
594
586
|
} else {
|
|
595
587
|
acc.push(curr);
|
|
@@ -597,9 +589,10 @@ ${curr.source}` : "'",
|
|
|
597
589
|
return acc;
|
|
598
590
|
}, []);
|
|
599
591
|
}
|
|
592
|
+
var extensions = [".js", ".ts"];
|
|
600
593
|
function getFileSource(file) {
|
|
601
594
|
let { source } = file;
|
|
602
|
-
if (!file.fileName.endsWith(
|
|
595
|
+
if (!extensions.some((extension) => file.fileName.endsWith(extension))) {
|
|
603
596
|
return file.source;
|
|
604
597
|
}
|
|
605
598
|
const imports = [];
|
|
@@ -646,6 +639,7 @@ function getFileSource(file) {
|
|
|
646
639
|
return [...prev, tsCodegen.createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })];
|
|
647
640
|
}, []);
|
|
648
641
|
const exportSource = tsCodegen.print(exportNodes);
|
|
642
|
+
source = getEnvSource(source, file.env);
|
|
649
643
|
if (importSource) {
|
|
650
644
|
source = `${importSource}
|
|
651
645
|
${source}`;
|
|
@@ -656,6 +650,149 @@ ${source}`;
|
|
|
656
650
|
}
|
|
657
651
|
return source;
|
|
658
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
|
+
};
|
|
659
796
|
function createPlugin(factory) {
|
|
660
797
|
return (options) => {
|
|
661
798
|
const plugin = factory(options);
|
|
@@ -670,9 +807,9 @@ function createPlugin(factory) {
|
|
|
670
807
|
return plugin;
|
|
671
808
|
};
|
|
672
809
|
}
|
|
673
|
-
var
|
|
810
|
+
var pluginName = "core";
|
|
674
811
|
var definePlugin = createPlugin((options) => {
|
|
675
|
-
const { fileManager, resolvePath, resolveName, load } = options;
|
|
812
|
+
const { fileManager, resolvePath, resolveName, load, logger } = options;
|
|
676
813
|
const api = {
|
|
677
814
|
get config() {
|
|
678
815
|
return options.config;
|
|
@@ -689,14 +826,14 @@ var definePlugin = createPlugin((options) => {
|
|
|
689
826
|
}
|
|
690
827
|
return 0;
|
|
691
828
|
});
|
|
692
|
-
const
|
|
829
|
+
const pluginName2 = plugins?.[0]?.name;
|
|
693
830
|
return Promise.all(
|
|
694
831
|
files.map((file) => {
|
|
695
832
|
const fileWithMeta = {
|
|
696
833
|
...file,
|
|
697
834
|
meta: {
|
|
698
835
|
...file.meta || {},
|
|
699
|
-
pluginName
|
|
836
|
+
pluginName: pluginName2
|
|
700
837
|
}
|
|
701
838
|
};
|
|
702
839
|
if (file.override) {
|
|
@@ -708,42 +845,58 @@ var definePlugin = createPlugin((options) => {
|
|
|
708
845
|
},
|
|
709
846
|
resolvePath,
|
|
710
847
|
resolveName: (params) => {
|
|
711
|
-
const
|
|
712
|
-
return transformReservedWord(
|
|
848
|
+
const name = resolveName(params);
|
|
849
|
+
return transformReservedWord(name);
|
|
713
850
|
},
|
|
714
851
|
load,
|
|
852
|
+
logger,
|
|
715
853
|
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
716
854
|
};
|
|
717
855
|
return {
|
|
718
|
-
name,
|
|
856
|
+
name: pluginName,
|
|
719
857
|
options,
|
|
720
858
|
api,
|
|
721
859
|
resolvePath(fileName) {
|
|
722
860
|
const root = pathParser2__default.default.resolve(this.config.root, this.config.output.path);
|
|
723
861
|
return pathParser2__default.default.resolve(root, fileName);
|
|
724
862
|
},
|
|
725
|
-
resolveName(
|
|
726
|
-
return
|
|
863
|
+
resolveName(name) {
|
|
864
|
+
return name;
|
|
727
865
|
}
|
|
728
866
|
};
|
|
729
867
|
});
|
|
730
868
|
|
|
731
869
|
// src/managers/pluginManager/ParallelPluginError.ts
|
|
732
870
|
var ParallelPluginError = class extends Error {
|
|
733
|
-
errors;
|
|
871
|
+
errors = [];
|
|
734
872
|
pluginManager;
|
|
735
873
|
constructor(message, options) {
|
|
736
874
|
super(message, { cause: options.cause });
|
|
875
|
+
this.name = "ParallelPluginError";
|
|
737
876
|
this.errors = options.errors;
|
|
738
877
|
this.pluginManager = options.pluginManager;
|
|
739
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
|
+
}
|
|
740
890
|
};
|
|
741
891
|
|
|
742
892
|
// src/managers/pluginManager/PluginError.ts
|
|
743
893
|
var PluginError = class extends Error {
|
|
744
894
|
pluginManager;
|
|
895
|
+
cause;
|
|
745
896
|
constructor(message, options) {
|
|
746
897
|
super(message, { cause: options.cause });
|
|
898
|
+
this.name = "PluginError";
|
|
899
|
+
this.cause = options.cause;
|
|
747
900
|
this.pluginManager = options.pluginManager;
|
|
748
901
|
}
|
|
749
902
|
};
|
|
@@ -768,12 +921,15 @@ var PluginManager = class {
|
|
|
768
921
|
queue;
|
|
769
922
|
executer;
|
|
770
923
|
executed = [];
|
|
924
|
+
logger;
|
|
771
925
|
constructor(config, options) {
|
|
772
926
|
this.onExecute = options.onExecute?.bind(this);
|
|
927
|
+
this.logger = options.logger;
|
|
773
928
|
this.queue = new Queue(10);
|
|
774
929
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
775
930
|
this.core = definePlugin({
|
|
776
931
|
config,
|
|
932
|
+
logger: this.logger,
|
|
777
933
|
fileManager: this.fileManager,
|
|
778
934
|
load: this.load,
|
|
779
935
|
resolvePath: this.resolvePath,
|
|
@@ -822,11 +978,11 @@ var PluginManager = class {
|
|
|
822
978
|
* Run only hook for a specific plugin name
|
|
823
979
|
*/
|
|
824
980
|
hookForPlugin({
|
|
825
|
-
pluginName,
|
|
981
|
+
pluginName: pluginName2,
|
|
826
982
|
hookName,
|
|
827
983
|
parameters
|
|
828
984
|
}) {
|
|
829
|
-
const plugin = this.getPlugin(hookName,
|
|
985
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
830
986
|
return this.execute({
|
|
831
987
|
strategy: "hookFirst",
|
|
832
988
|
hookName,
|
|
@@ -835,11 +991,11 @@ var PluginManager = class {
|
|
|
835
991
|
});
|
|
836
992
|
}
|
|
837
993
|
hookForPluginSync({
|
|
838
|
-
pluginName,
|
|
994
|
+
pluginName: pluginName2,
|
|
839
995
|
hookName,
|
|
840
996
|
parameters
|
|
841
997
|
}) {
|
|
842
|
-
const plugin = this.getPlugin(hookName,
|
|
998
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
843
999
|
return this.executeSync({
|
|
844
1000
|
strategy: "hookFirst",
|
|
845
1001
|
hookName,
|
|
@@ -924,9 +1080,13 @@ var PluginManager = class {
|
|
|
924
1080
|
}
|
|
925
1081
|
}
|
|
926
1082
|
const results = await Promise.allSettled(parallelPromises);
|
|
927
|
-
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);
|
|
928
1089
|
if (errors.length) {
|
|
929
|
-
console.log(errors);
|
|
930
1090
|
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
931
1091
|
}
|
|
932
1092
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
@@ -976,9 +1136,9 @@ var PluginManager = class {
|
|
|
976
1136
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
977
1137
|
return plugins;
|
|
978
1138
|
}
|
|
979
|
-
getPlugin(hookName,
|
|
1139
|
+
getPlugin(hookName, pluginName2) {
|
|
980
1140
|
const plugins = [...this.plugins];
|
|
981
|
-
const pluginByPluginName = plugins.find((item) => item.name ===
|
|
1141
|
+
const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
|
|
982
1142
|
if (!pluginByPluginName) {
|
|
983
1143
|
return this.core;
|
|
984
1144
|
}
|
|
@@ -1035,6 +1195,7 @@ var PluginManager = class {
|
|
|
1035
1195
|
return hook;
|
|
1036
1196
|
}).catch((e) => {
|
|
1037
1197
|
this.catcher(e, plugin, hookName);
|
|
1198
|
+
return null;
|
|
1038
1199
|
});
|
|
1039
1200
|
}
|
|
1040
1201
|
/**
|
|
@@ -1099,10 +1260,10 @@ function validatePlugins(plugins, dependedPluginNames) {
|
|
|
1099
1260
|
} else {
|
|
1100
1261
|
pluginNames = dependedPluginNames;
|
|
1101
1262
|
}
|
|
1102
|
-
pluginNames.forEach((
|
|
1103
|
-
const exists = plugins.some((plugin) => plugin.name ===
|
|
1263
|
+
pluginNames.forEach((pluginName2) => {
|
|
1264
|
+
const exists = plugins.some((plugin) => plugin.name === pluginName2);
|
|
1104
1265
|
if (!exists) {
|
|
1105
|
-
throw new ValidationPluginError(`This plugin depends on the ${
|
|
1266
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1106
1267
|
}
|
|
1107
1268
|
});
|
|
1108
1269
|
return true;
|
|
@@ -1113,7 +1274,7 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1113
1274
|
return result;
|
|
1114
1275
|
}
|
|
1115
1276
|
async function build(options) {
|
|
1116
|
-
const { config, logger } = options;
|
|
1277
|
+
const { config, logger = createLogger() } = options;
|
|
1117
1278
|
try {
|
|
1118
1279
|
if (!isURL(config.input.path)) {
|
|
1119
1280
|
await read(config.input.path);
|
|
@@ -1156,11 +1317,12 @@ async function build(options) {
|
|
|
1156
1317
|
return;
|
|
1157
1318
|
}
|
|
1158
1319
|
const { hookName, plugin } = executer;
|
|
1159
|
-
if (config.logLevel === "info"
|
|
1160
|
-
|
|
1320
|
+
if (config.logLevel === "info") {
|
|
1321
|
+
const messsage = `\u{1FA82} Executing ${hookName || "unknown"}(${pc__default.default.yellow(plugin.name || "unknown")})`;
|
|
1322
|
+
logger.log(messsage);
|
|
1161
1323
|
}
|
|
1162
1324
|
};
|
|
1163
|
-
const pluginManager = new PluginManager(config, { task: queueTask, onExecute });
|
|
1325
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, onExecute });
|
|
1164
1326
|
const { plugins, fileManager } = pluginManager;
|
|
1165
1327
|
await pluginManager.hookParallel({
|
|
1166
1328
|
hookName: "validate",
|
|
@@ -1201,6 +1363,10 @@ var SchemaGenerator = class extends Generator {
|
|
|
1201
1363
|
// src/index.ts
|
|
1202
1364
|
var src_default = build;
|
|
1203
1365
|
|
|
1366
|
+
Object.defineProperty(exports, 'pc', {
|
|
1367
|
+
enumerable: true,
|
|
1368
|
+
get: function () { return pc__default.default; }
|
|
1369
|
+
});
|
|
1204
1370
|
exports.FileManager = FileManager;
|
|
1205
1371
|
exports.Generator = Generator;
|
|
1206
1372
|
exports.ParallelPluginError = ParallelPluginError;
|
|
@@ -1208,28 +1374,38 @@ exports.PluginError = PluginError;
|
|
|
1208
1374
|
exports.PluginManager = PluginManager;
|
|
1209
1375
|
exports.Queue = Queue;
|
|
1210
1376
|
exports.SchemaGenerator = SchemaGenerator;
|
|
1377
|
+
exports.SummaryError = SummaryError;
|
|
1211
1378
|
exports.TreeNode = TreeNode;
|
|
1212
1379
|
exports.ValidationPluginError = ValidationPluginError;
|
|
1380
|
+
exports.Warning = Warning;
|
|
1213
1381
|
exports.build = build;
|
|
1214
1382
|
exports.clean = clean;
|
|
1215
1383
|
exports.combineFiles = combineFiles;
|
|
1216
1384
|
exports.createJSDocBlockText = createJSDocBlockText;
|
|
1385
|
+
exports.createLogger = createLogger;
|
|
1217
1386
|
exports.createPlugin = createPlugin;
|
|
1218
1387
|
exports.createPluginCache = createPluginCache;
|
|
1219
1388
|
exports.default = src_default;
|
|
1220
1389
|
exports.defineConfig = defineConfig;
|
|
1390
|
+
exports.extensions = extensions;
|
|
1221
1391
|
exports.getEncodedText = getEncodedText;
|
|
1222
1392
|
exports.getFileSource = getFileSource;
|
|
1393
|
+
exports.getLocation = getLocation;
|
|
1223
1394
|
exports.getPathMode = getPathMode;
|
|
1224
1395
|
exports.getRelativePath = getRelativePath;
|
|
1225
1396
|
exports.getStackTrace = getStackTrace;
|
|
1226
1397
|
exports.getUniqueName = getUniqueName;
|
|
1227
1398
|
exports.hooks = hooks;
|
|
1399
|
+
exports.importModule = importModule;
|
|
1228
1400
|
exports.isPromise = isPromise;
|
|
1401
|
+
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
1402
|
+
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
1229
1403
|
exports.isURL = isURL;
|
|
1230
|
-
exports.name =
|
|
1404
|
+
exports.name = pluginName;
|
|
1231
1405
|
exports.nameSorter = nameSorter;
|
|
1406
|
+
exports.normalizeDirectory = normalizeDirectory;
|
|
1232
1407
|
exports.objectToParameters = objectToParameters;
|
|
1408
|
+
exports.pluginName = pluginName;
|
|
1233
1409
|
exports.read = read;
|
|
1234
1410
|
exports.renderTemplate = renderTemplate;
|
|
1235
1411
|
exports.throttle = throttle;
|
|
@@ -1239,3 +1415,5 @@ exports.uniqueId = uniqueId;
|
|
|
1239
1415
|
exports.validatePlugins = validatePlugins;
|
|
1240
1416
|
exports.write = write;
|
|
1241
1417
|
exports.writeIndexes = writeIndexes;
|
|
1418
|
+
//# sourceMappingURL=out.js.map
|
|
1419
|
+
//# sourceMappingURL=index.cjs.map
|