@kubb/core 1.1.3 → 1.1.5
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 +24 -14
- package/dist/index.d.ts +29 -23
- package/dist/index.js +24 -14
- package/package.json +3 -4
- package/src/build.ts +7 -3
- package/src/managers/pluginManager/PluginManager.ts +37 -26
- package/src/managers/pluginManager/types.ts +7 -0
- package/src/types.ts +3 -2
package/dist/index.cjs
CHANGED
|
@@ -627,7 +627,7 @@ var PluginManager = class {
|
|
|
627
627
|
return this.hookFirstSync({
|
|
628
628
|
hookName: "resolvePath",
|
|
629
629
|
parameters: [params.fileName, params.directory, params.options]
|
|
630
|
-
});
|
|
630
|
+
}).result;
|
|
631
631
|
};
|
|
632
632
|
resolveName = (params) => {
|
|
633
633
|
if (params.pluginName) {
|
|
@@ -640,7 +640,7 @@ var PluginManager = class {
|
|
|
640
640
|
return this.hookFirstSync({
|
|
641
641
|
hookName: "resolveName",
|
|
642
642
|
parameters: [params.name]
|
|
643
|
-
});
|
|
643
|
+
}).result;
|
|
644
644
|
};
|
|
645
645
|
load = async (id) => {
|
|
646
646
|
return this.hookFirst({
|
|
@@ -691,15 +691,20 @@ var PluginManager = class {
|
|
|
691
691
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
692
692
|
if (skipped && skipped.has(plugin))
|
|
693
693
|
continue;
|
|
694
|
-
promise = promise.then((result) => {
|
|
695
|
-
if (result != null)
|
|
694
|
+
promise = promise.then(async (result) => {
|
|
695
|
+
if (result != null) {
|
|
696
696
|
return result;
|
|
697
|
-
|
|
697
|
+
}
|
|
698
|
+
const value = await this.execute({
|
|
698
699
|
strategy: "hookFirst",
|
|
699
700
|
hookName,
|
|
700
701
|
parameters,
|
|
701
702
|
plugin
|
|
702
703
|
});
|
|
704
|
+
return Promise.resolve({
|
|
705
|
+
plugin,
|
|
706
|
+
result: value
|
|
707
|
+
});
|
|
703
708
|
});
|
|
704
709
|
}
|
|
705
710
|
return promise;
|
|
@@ -717,12 +722,14 @@ var PluginManager = class {
|
|
|
717
722
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
718
723
|
if (skipped && skipped.has(plugin))
|
|
719
724
|
continue;
|
|
720
|
-
result =
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
725
|
+
result = {
|
|
726
|
+
result: this.executeSync({
|
|
727
|
+
strategy: "hookFirst",
|
|
728
|
+
hookName,
|
|
729
|
+
parameters,
|
|
730
|
+
plugin
|
|
731
|
+
})
|
|
732
|
+
};
|
|
726
733
|
if (result != null) {
|
|
727
734
|
break;
|
|
728
735
|
}
|
|
@@ -796,7 +803,7 @@ var PluginManager = class {
|
|
|
796
803
|
return promise.then(noReturn);
|
|
797
804
|
}
|
|
798
805
|
getSortedPlugins(_hookName) {
|
|
799
|
-
const plugins = [...this.plugins];
|
|
806
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
800
807
|
return plugins;
|
|
801
808
|
}
|
|
802
809
|
getPlugin(hookName, pluginName) {
|
|
@@ -1080,11 +1087,14 @@ async function build(options) {
|
|
|
1080
1087
|
const queueTask = async (id, file) => {
|
|
1081
1088
|
const { path } = file;
|
|
1082
1089
|
let code = getFileSource(file);
|
|
1083
|
-
const loadedResult = await pluginManager.hookFirst({
|
|
1090
|
+
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1084
1091
|
hookName: "load",
|
|
1085
1092
|
parameters: [path]
|
|
1086
1093
|
});
|
|
1087
|
-
if (loadedResult) {
|
|
1094
|
+
if (loadedResult && isPromise(loadedResult)) {
|
|
1095
|
+
code = await loadedResult;
|
|
1096
|
+
}
|
|
1097
|
+
if (loadedResult && !isPromise(loadedResult)) {
|
|
1088
1098
|
code = loadedResult;
|
|
1089
1099
|
}
|
|
1090
1100
|
if (code) {
|
package/dist/index.d.ts
CHANGED
|
@@ -154,22 +154,14 @@ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
154
154
|
plugin: KubbPlugin;
|
|
155
155
|
};
|
|
156
156
|
type OnExecute<H extends PluginLifecycleHooks = PluginLifecycleHooks> = (this: PluginManager, executer: Executer<H> | undefined) => void;
|
|
157
|
-
|
|
158
|
-
type
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
config: PluginContext['config'];
|
|
162
|
-
fileManager: FileManager;
|
|
163
|
-
resolvePath: PluginContext['resolvePath'];
|
|
164
|
-
resolveName: PluginContext['resolveName'];
|
|
165
|
-
load: PluginContext['load'];
|
|
166
|
-
getExecuter: () => Executer<PluginLifecycleHooks> | undefined;
|
|
157
|
+
type ParseResult<H extends PluginLifecycleHooks> = PluginLifecycle[H];
|
|
158
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
159
|
+
result: Result;
|
|
160
|
+
plugin: KubbPlugin;
|
|
167
161
|
};
|
|
168
|
-
type CorePluginOptions = PluginFactoryOptions<Options$1, false, PluginContext>;
|
|
169
|
-
declare const name: "core";
|
|
170
162
|
|
|
171
163
|
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<unknown, false, any, Record<string, any>>>];
|
|
172
|
-
type Options = {
|
|
164
|
+
type Options$1 = {
|
|
173
165
|
task: QueueTask;
|
|
174
166
|
onExecute?: OnExecute<PluginLifecycleHooks>;
|
|
175
167
|
};
|
|
@@ -177,15 +169,15 @@ declare class PluginManager {
|
|
|
177
169
|
plugins: KubbPlugin[];
|
|
178
170
|
readonly fileManager: FileManager;
|
|
179
171
|
private readonly onExecute?;
|
|
180
|
-
readonly core
|
|
172
|
+
private readonly core;
|
|
181
173
|
queue: Queue;
|
|
182
174
|
executer: Executer | undefined;
|
|
183
175
|
executed: Executer[];
|
|
184
|
-
constructor(config: KubbConfig, options: Options);
|
|
176
|
+
constructor(config: KubbConfig, options: Options$1);
|
|
185
177
|
getExecuter(): Executer | undefined;
|
|
186
178
|
resolvePath: (params: ResolvePathParams) => OptionalPath;
|
|
187
179
|
resolveName: (params: ResolveNameParams) => string | null;
|
|
188
|
-
load: (id: string) => Promise<
|
|
180
|
+
load: (id: string) => Promise<SafeParseResult<"load">>;
|
|
189
181
|
/**
|
|
190
182
|
*
|
|
191
183
|
* Run only hook for a specific plugin name
|
|
@@ -194,12 +186,12 @@ declare class PluginManager {
|
|
|
194
186
|
pluginName: string;
|
|
195
187
|
hookName: H;
|
|
196
188
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
197
|
-
}): Promise<ReturnType<
|
|
189
|
+
}): Promise<ReturnType<ParseResult<H>> | null> | null;
|
|
198
190
|
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
|
|
199
191
|
pluginName: string;
|
|
200
192
|
hookName: H;
|
|
201
193
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
202
|
-
}): ReturnType<
|
|
194
|
+
}): ReturnType<ParseResult<H>> | null;
|
|
203
195
|
/**
|
|
204
196
|
*
|
|
205
197
|
* Chains, first non-null result stops and returns
|
|
@@ -208,7 +200,7 @@ declare class PluginManager {
|
|
|
208
200
|
hookName: H;
|
|
209
201
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
210
202
|
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
211
|
-
}): Promise<
|
|
203
|
+
}): Promise<SafeParseResult<H>>;
|
|
212
204
|
/**
|
|
213
205
|
*
|
|
214
206
|
* Chains, first non-null result stops and returns
|
|
@@ -217,7 +209,7 @@ declare class PluginManager {
|
|
|
217
209
|
hookName: H;
|
|
218
210
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
219
211
|
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
220
|
-
}):
|
|
212
|
+
}): SafeParseResult<H>;
|
|
221
213
|
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
222
214
|
hookName: H;
|
|
223
215
|
parameters?: Parameters<PluginLifecycle[H]> | undefined;
|
|
@@ -225,7 +217,7 @@ declare class PluginManager {
|
|
|
225
217
|
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
226
218
|
hookName: H;
|
|
227
219
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
228
|
-
reduce: (reduction: Argument0<H>, result: ReturnType<
|
|
220
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>;
|
|
229
221
|
}): Promise<Argument0<H>>;
|
|
230
222
|
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
231
223
|
hookName: H;
|
|
@@ -376,6 +368,7 @@ type CLIOptions = {
|
|
|
376
368
|
* @default `'silent'`
|
|
377
369
|
*/
|
|
378
370
|
logLevel?: LogLevel;
|
|
371
|
+
init?: unknown;
|
|
379
372
|
};
|
|
380
373
|
type BuildOutput = {
|
|
381
374
|
files: FileManager['files'];
|
|
@@ -489,7 +482,7 @@ type PluginContext<TOptions = Record<string, any>> = {
|
|
|
489
482
|
addFile: (...file: File[]) => Promise<File[]>;
|
|
490
483
|
resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
491
484
|
resolveName: (params: ResolveNameParams) => string | null | undefined;
|
|
492
|
-
load: (id: string) =>
|
|
485
|
+
load: (id: string) => Promise<SafeParseResult<'load'>>;
|
|
493
486
|
};
|
|
494
487
|
type TransformResult = string | null;
|
|
495
488
|
/**
|
|
@@ -517,6 +510,19 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
|
517
510
|
*/
|
|
518
511
|
declare const defineConfig: (options: MaybePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>)) => MaybePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>);
|
|
519
512
|
|
|
513
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>;
|
|
514
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => T["nested"] extends true ? KubbPlugin<T>[] : KubbPlugin<T>;
|
|
515
|
+
type Options = {
|
|
516
|
+
config: PluginContext['config'];
|
|
517
|
+
fileManager: FileManager;
|
|
518
|
+
resolvePath: PluginContext['resolvePath'];
|
|
519
|
+
resolveName: PluginContext['resolveName'];
|
|
520
|
+
load: PluginContext['load'];
|
|
521
|
+
getExecuter: () => Executer<PluginLifecycleHooks> | undefined;
|
|
522
|
+
};
|
|
523
|
+
type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>;
|
|
524
|
+
declare const name: "core";
|
|
525
|
+
|
|
520
526
|
/**
|
|
521
527
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
522
528
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
@@ -535,4 +541,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
535
541
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
536
542
|
}
|
|
537
543
|
|
|
538
|
-
export { Argument0, BuildOutput, CLIOptions, Cache, CacheStore, CorePluginOptions, Executer, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugin, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, Logger, MaybePromise, OnExecute, OptionalPath, ParallelPluginError, Path, PathMode, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, build as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, validatePlugins, write, writeIndexes };
|
|
544
|
+
export { Argument0, BuildOutput, CLIOptions, Cache, CacheStore, CorePluginOptions, Executer, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugin, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, Logger, MaybePromise, OnExecute, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, build as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, validatePlugins, write, writeIndexes };
|
package/dist/index.js
CHANGED
|
@@ -617,7 +617,7 @@ var PluginManager = class {
|
|
|
617
617
|
return this.hookFirstSync({
|
|
618
618
|
hookName: "resolvePath",
|
|
619
619
|
parameters: [params.fileName, params.directory, params.options]
|
|
620
|
-
});
|
|
620
|
+
}).result;
|
|
621
621
|
};
|
|
622
622
|
resolveName = (params) => {
|
|
623
623
|
if (params.pluginName) {
|
|
@@ -630,7 +630,7 @@ var PluginManager = class {
|
|
|
630
630
|
return this.hookFirstSync({
|
|
631
631
|
hookName: "resolveName",
|
|
632
632
|
parameters: [params.name]
|
|
633
|
-
});
|
|
633
|
+
}).result;
|
|
634
634
|
};
|
|
635
635
|
load = async (id) => {
|
|
636
636
|
return this.hookFirst({
|
|
@@ -681,15 +681,20 @@ var PluginManager = class {
|
|
|
681
681
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
682
682
|
if (skipped && skipped.has(plugin))
|
|
683
683
|
continue;
|
|
684
|
-
promise = promise.then((result) => {
|
|
685
|
-
if (result != null)
|
|
684
|
+
promise = promise.then(async (result) => {
|
|
685
|
+
if (result != null) {
|
|
686
686
|
return result;
|
|
687
|
-
|
|
687
|
+
}
|
|
688
|
+
const value = await this.execute({
|
|
688
689
|
strategy: "hookFirst",
|
|
689
690
|
hookName,
|
|
690
691
|
parameters,
|
|
691
692
|
plugin
|
|
692
693
|
});
|
|
694
|
+
return Promise.resolve({
|
|
695
|
+
plugin,
|
|
696
|
+
result: value
|
|
697
|
+
});
|
|
693
698
|
});
|
|
694
699
|
}
|
|
695
700
|
return promise;
|
|
@@ -707,12 +712,14 @@ var PluginManager = class {
|
|
|
707
712
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
708
713
|
if (skipped && skipped.has(plugin))
|
|
709
714
|
continue;
|
|
710
|
-
result =
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
715
|
+
result = {
|
|
716
|
+
result: this.executeSync({
|
|
717
|
+
strategy: "hookFirst",
|
|
718
|
+
hookName,
|
|
719
|
+
parameters,
|
|
720
|
+
plugin
|
|
721
|
+
})
|
|
722
|
+
};
|
|
716
723
|
if (result != null) {
|
|
717
724
|
break;
|
|
718
725
|
}
|
|
@@ -786,7 +793,7 @@ var PluginManager = class {
|
|
|
786
793
|
return promise.then(noReturn);
|
|
787
794
|
}
|
|
788
795
|
getSortedPlugins(_hookName) {
|
|
789
|
-
const plugins = [...this.plugins];
|
|
796
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
790
797
|
return plugins;
|
|
791
798
|
}
|
|
792
799
|
getPlugin(hookName, pluginName) {
|
|
@@ -1070,11 +1077,14 @@ async function build(options) {
|
|
|
1070
1077
|
const queueTask = async (id, file) => {
|
|
1071
1078
|
const { path } = file;
|
|
1072
1079
|
let code = getFileSource(file);
|
|
1073
|
-
const loadedResult = await pluginManager.hookFirst({
|
|
1080
|
+
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1074
1081
|
hookName: "load",
|
|
1075
1082
|
parameters: [path]
|
|
1076
1083
|
});
|
|
1077
|
-
if (loadedResult) {
|
|
1084
|
+
if (loadedResult && isPromise(loadedResult)) {
|
|
1085
|
+
code = await loadedResult;
|
|
1086
|
+
}
|
|
1087
|
+
if (loadedResult && !isPromise(loadedResult)) {
|
|
1078
1088
|
code = loadedResult;
|
|
1079
1089
|
}
|
|
1080
1090
|
if (code) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
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.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^6.7.0",
|
|
@@ -65,8 +65,7 @@
|
|
|
65
65
|
"pre-commit": "echo 'pre-commit not configured'",
|
|
66
66
|
"pre-push": "pnpm typecheck",
|
|
67
67
|
"test": "vitest --passWithNoTests",
|
|
68
|
-
"upgrade": "
|
|
69
|
-
"upgrade:local": "ncu --interactive --doctor",
|
|
68
|
+
"upgrade": "pnpm update",
|
|
70
69
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
71
70
|
}
|
|
72
71
|
}
|
package/src/build.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { PluginManager } from './managers/pluginManager/index.ts'
|
|
3
3
|
import { clean, isURL, read } from './utils/index.ts'
|
|
4
4
|
import { getFileSource } from './managers/fileManager/index.ts'
|
|
5
|
+
import { isPromise } from './utils/isPromise.ts'
|
|
5
6
|
|
|
6
7
|
import type { OnExecute } from './managers/pluginManager/index.ts'
|
|
7
8
|
import type { File } from './managers/fileManager/index.ts'
|
|
@@ -48,13 +49,16 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
|
48
49
|
const queueTask = async (id: string, file: File) => {
|
|
49
50
|
const { path } = file
|
|
50
51
|
|
|
51
|
-
let code = getFileSource(file)
|
|
52
|
+
let code: string | null = getFileSource(file)
|
|
52
53
|
|
|
53
|
-
const loadedResult = await pluginManager.hookFirst({
|
|
54
|
+
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
54
55
|
hookName: 'load',
|
|
55
56
|
parameters: [path],
|
|
56
57
|
})
|
|
57
|
-
if (loadedResult) {
|
|
58
|
+
if (loadedResult && isPromise(loadedResult)) {
|
|
59
|
+
code = await loadedResult
|
|
60
|
+
}
|
|
61
|
+
if (loadedResult && !isPromise(loadedResult)) {
|
|
58
62
|
code = loadedResult
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -11,7 +11,7 @@ import { Queue } from '../../utils/Queue.ts'
|
|
|
11
11
|
import { isPromise } from '../../utils/isPromise.ts'
|
|
12
12
|
|
|
13
13
|
import type { QueueTask } from '../../utils/Queue.ts'
|
|
14
|
-
import type { Argument0, Strategy, Executer, OnExecute } from './types.ts'
|
|
14
|
+
import type { Argument0, Strategy, Executer, OnExecute, ParseResult, SafeParseResult } from './types.ts'
|
|
15
15
|
import type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolvePathParams, ResolveNameParams } from '../../types.ts'
|
|
16
16
|
import type { CorePluginOptions } from '../../plugin.ts'
|
|
17
17
|
|
|
@@ -41,7 +41,7 @@ export class PluginManager {
|
|
|
41
41
|
|
|
42
42
|
private readonly onExecute?: OnExecute
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
private readonly core: KubbPlugin<CorePluginOptions>
|
|
45
45
|
|
|
46
46
|
public queue: Queue
|
|
47
47
|
|
|
@@ -82,7 +82,7 @@ export class PluginManager {
|
|
|
82
82
|
return this.hookFirstSync({
|
|
83
83
|
hookName: 'resolvePath',
|
|
84
84
|
parameters: [params.fileName, params.directory, params.options],
|
|
85
|
-
})
|
|
85
|
+
}).result
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
resolveName = (params: ResolveNameParams) => {
|
|
@@ -96,7 +96,7 @@ export class PluginManager {
|
|
|
96
96
|
return this.hookFirstSync({
|
|
97
97
|
hookName: 'resolveName',
|
|
98
98
|
parameters: [params.name],
|
|
99
|
-
})
|
|
99
|
+
}).result
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
load = async (id: string) => {
|
|
@@ -118,7 +118,7 @@ export class PluginManager {
|
|
|
118
118
|
pluginName: string
|
|
119
119
|
hookName: H
|
|
120
120
|
parameters: Parameters<PluginLifecycle[H]>
|
|
121
|
-
}): Promise<ReturnType<
|
|
121
|
+
}): Promise<ReturnType<ParseResult<H>> | null> | null {
|
|
122
122
|
const plugin = this.getPlugin(hookName, pluginName)
|
|
123
123
|
|
|
124
124
|
return this.execute({
|
|
@@ -137,7 +137,7 @@ export class PluginManager {
|
|
|
137
137
|
pluginName: string
|
|
138
138
|
hookName: H
|
|
139
139
|
parameters: Parameters<PluginLifecycle[H]>
|
|
140
|
-
}): ReturnType<
|
|
140
|
+
}): ReturnType<ParseResult<H>> | null {
|
|
141
141
|
const plugin = this.getPlugin(hookName, pluginName)
|
|
142
142
|
|
|
143
143
|
return this.executeSync({
|
|
@@ -160,20 +160,29 @@ export class PluginManager {
|
|
|
160
160
|
hookName: H
|
|
161
161
|
parameters: Parameters<PluginLifecycle[H]>
|
|
162
162
|
skipped?: ReadonlySet<KubbPlugin> | null
|
|
163
|
-
}): Promise<
|
|
164
|
-
let promise: Promise<
|
|
163
|
+
}): Promise<SafeParseResult<H>> {
|
|
164
|
+
let promise: Promise<SafeParseResult<H>> = Promise.resolve(null as any)
|
|
165
|
+
|
|
165
166
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
166
167
|
if (skipped && skipped.has(plugin)) continue
|
|
167
|
-
promise = promise.then((result) => {
|
|
168
|
-
if (result != null)
|
|
169
|
-
|
|
168
|
+
promise = promise.then(async (result) => {
|
|
169
|
+
if (result != null) {
|
|
170
|
+
return result
|
|
171
|
+
}
|
|
172
|
+
const value = await this.execute<H>({
|
|
170
173
|
strategy: 'hookFirst',
|
|
171
174
|
hookName,
|
|
172
175
|
parameters,
|
|
173
176
|
plugin,
|
|
174
|
-
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return Promise.resolve({
|
|
180
|
+
plugin,
|
|
181
|
+
result: value,
|
|
182
|
+
} as typeof result)
|
|
175
183
|
})
|
|
176
184
|
}
|
|
185
|
+
|
|
177
186
|
return promise
|
|
178
187
|
}
|
|
179
188
|
|
|
@@ -189,24 +198,26 @@ export class PluginManager {
|
|
|
189
198
|
hookName: H
|
|
190
199
|
parameters: Parameters<PluginLifecycle[H]>
|
|
191
200
|
skipped?: ReadonlySet<KubbPlugin> | null
|
|
192
|
-
}):
|
|
193
|
-
let result = null
|
|
201
|
+
}): SafeParseResult<H> {
|
|
202
|
+
let result: SafeParseResult<H> = null as unknown as SafeParseResult<H>
|
|
194
203
|
|
|
195
204
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
196
205
|
if (skipped && skipped.has(plugin)) continue
|
|
197
206
|
|
|
198
|
-
result =
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
result = {
|
|
208
|
+
result: this.executeSync<H>({
|
|
209
|
+
strategy: 'hookFirst',
|
|
210
|
+
hookName,
|
|
211
|
+
parameters,
|
|
212
|
+
plugin,
|
|
213
|
+
}),
|
|
214
|
+
} as SafeParseResult<H>
|
|
204
215
|
|
|
205
216
|
if (result != null) {
|
|
206
217
|
break
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
|
-
return result as
|
|
220
|
+
return result as SafeParseResult<H>
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
// parallel
|
|
@@ -255,7 +266,7 @@ export class PluginManager {
|
|
|
255
266
|
}: {
|
|
256
267
|
hookName: H
|
|
257
268
|
parameters: Parameters<PluginLifecycle[H]>
|
|
258
|
-
reduce: (reduction: Argument0<H>, result: ReturnType<
|
|
269
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>
|
|
259
270
|
}): Promise<Argument0<H>> {
|
|
260
271
|
const [argument0, ...rest] = parameters
|
|
261
272
|
|
|
@@ -271,7 +282,7 @@ export class PluginManager {
|
|
|
271
282
|
})
|
|
272
283
|
return value
|
|
273
284
|
})
|
|
274
|
-
.then((result) => reduce.call(this.core.api, argument0, result as ReturnType<
|
|
285
|
+
.then((result) => reduce.call(this.core.api, argument0, result as ReturnType<ParseResult<H>>, plugin)) as Promise<Argument0<H>>
|
|
275
286
|
}
|
|
276
287
|
return promise
|
|
277
288
|
}
|
|
@@ -294,7 +305,7 @@ export class PluginManager {
|
|
|
294
305
|
}
|
|
295
306
|
|
|
296
307
|
private getSortedPlugins(_hookName: keyof PluginLifecycle): KubbPlugin[] {
|
|
297
|
-
const plugins = [...this.plugins]
|
|
308
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== 'core')
|
|
298
309
|
|
|
299
310
|
return plugins
|
|
300
311
|
}
|
|
@@ -400,7 +411,7 @@ export class PluginManager {
|
|
|
400
411
|
hookName: H
|
|
401
412
|
parameters: Parameters<PluginLifecycle[H]>
|
|
402
413
|
plugin: KubbPlugin
|
|
403
|
-
}): ReturnType<
|
|
414
|
+
}): ReturnType<ParseResult<H>> | null {
|
|
404
415
|
const hook = plugin[hookName]
|
|
405
416
|
|
|
406
417
|
if (!hook) {
|
|
@@ -438,7 +449,7 @@ export class PluginManager {
|
|
|
438
449
|
} catch (e) {
|
|
439
450
|
this.catcher<H>(e as Error, plugin, hookName)
|
|
440
451
|
|
|
441
|
-
return null as ReturnType<
|
|
452
|
+
return null as ReturnType<ParseResult<H>>
|
|
442
453
|
}
|
|
443
454
|
}
|
|
444
455
|
|
|
@@ -15,3 +15,10 @@ export type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export type OnExecute<H extends PluginLifecycleHooks = PluginLifecycleHooks> = (this: PluginManager, executer: Executer<H> | undefined) => void
|
|
18
|
+
|
|
19
|
+
export type ParseResult<H extends PluginLifecycleHooks> = PluginLifecycle[H]
|
|
20
|
+
|
|
21
|
+
export type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
22
|
+
result: Result
|
|
23
|
+
plugin: KubbPlugin
|
|
24
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
2
|
-
import type { PluginManager } from './managers/index.ts'
|
|
2
|
+
import type { PluginManager, SafeParseResult } from './managers/index.ts'
|
|
3
3
|
import type { FileManager, File } from './managers/fileManager/index.ts'
|
|
4
4
|
import type { Cache } from './utils/cache.ts'
|
|
5
5
|
|
|
@@ -109,6 +109,7 @@ export type CLIOptions = {
|
|
|
109
109
|
* @default `'silent'`
|
|
110
110
|
*/
|
|
111
111
|
logLevel?: LogLevel
|
|
112
|
+
init?: unknown
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
export type BuildOutput = {
|
|
@@ -236,7 +237,7 @@ export type PluginContext<TOptions = Record<string, any>> = {
|
|
|
236
237
|
addFile: (...file: File[]) => Promise<File[]>
|
|
237
238
|
resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath
|
|
238
239
|
resolveName: (params: ResolveNameParams) => string | null | undefined
|
|
239
|
-
load: (id: string) =>
|
|
240
|
+
load: (id: string) => Promise<SafeParseResult<'load'>>
|
|
240
241
|
}
|
|
241
242
|
|
|
242
243
|
// null will mean clear the watcher for this key
|