@kubb/core 5.0.0-alpha.22 → 5.0.0-alpha.24
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/{PluginDriver-DZdEyCoa.d.ts → PluginDriver-P920mak9.d.ts} +50 -23
- package/dist/hooks.cjs +1 -3
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +2 -4
- package/dist/hooks.js +1 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +99 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -58
- package/dist/index.js +100 -223
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PluginDriver.ts +81 -145
- package/src/build.ts +2 -2
- package/src/constants.ts +0 -10
- package/src/defineGenerator.ts +7 -0
- package/src/defineResolver.ts +1 -10
- package/src/hooks/useDriver.ts +1 -3
- package/src/index.ts +0 -2
- package/src/renderNode.tsx +9 -6
- package/src/types.ts +29 -18
- package/src/utils/getConfigs.ts +1 -1
- package/src/utils/getPreset.ts +3 -3
- package/src/defineBuilder.ts +0 -26
- package/src/definePreset.ts +0 -27
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { $ as formatters, A as
|
|
2
|
+
import { $ as formatters, A as PrinterFactoryOptions, B as UserConfig, C as PluginLifecycle, D as Preset, E as PluginWithLifeCycle, F as ResolvePathParams, G as UserResolver, H as UserLogger, I as Resolver, J as Generator, K as KubbEvents, L as ResolverContext, M as ResolveNameParams, N as ResolveOptionsContext, O as Presets, P as ResolvePathOptions, Q as createStorage, R as ResolverFileParams, S as PluginFactoryOptions, T as PluginParameter, U as UserPlugin, V as UserGroup, W as UserPluginWithLifeCycle, X as defineGenerator, Y as ReactGeneratorV2, Z as Storage, _ as LoggerOptions, a as AdapterSource, b as Plugin, c as Config, d as Group, et as linters, f as Include, g as LoggerContext, h as Logger, i as AdapterFactoryOptions, j as ResolveBannerContext, k as Printer, l as DevtoolsOptions, m as InputPath, n as getMode, nt as PossiblePromise, o as BarrelType, p as InputData, q as CoreGeneratorV2, r as Adapter, rt as AsyncEventEmitter, s as CompatibilityPreset, t as PluginDriver, tt as logLevel, u as Exclude, v as Output, w as PluginLifecycleHooks, x as PluginContext, y as Override, z as ResolverPathParams } from "./PluginDriver-P920mak9.js";
|
|
3
3
|
import { definePrinter } from "@kubb/ast";
|
|
4
4
|
import { Node, OperationNode, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
5
5
|
import { Fabric, FabricFile } from "@kubb/fabric-core/types";
|
|
@@ -303,29 +303,6 @@ type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (opt
|
|
|
303
303
|
*/
|
|
304
304
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
|
|
305
305
|
//#endregion
|
|
306
|
-
//#region src/defineBuilder.d.ts
|
|
307
|
-
/**
|
|
308
|
-
* Builder type for the plugin-specific builder fields.
|
|
309
|
-
* `name` is required; all other methods are defined by the concrete plugin builder type.
|
|
310
|
-
*/
|
|
311
|
-
type BuilderBuilder<T extends PluginFactoryOptions> = () => T['builder'] & ThisType<T['builder']>;
|
|
312
|
-
/**
|
|
313
|
-
* Defines a builder for a plugin — a named collection of schema-building helpers that
|
|
314
|
-
* can be exported alongside the plugin and imported by other plugins or generators.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* export const builder = defineBuilder<PluginTs>(() => ({
|
|
318
|
-
* name: 'default',
|
|
319
|
-
* buildParamsSchema({ params, node, resolver }) {
|
|
320
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
321
|
-
* },
|
|
322
|
-
* buildDataSchemaNode({ node, resolver }) {
|
|
323
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
324
|
-
* },
|
|
325
|
-
* }))
|
|
326
|
-
*/
|
|
327
|
-
declare function defineBuilder<T extends PluginFactoryOptions>(build: BuilderBuilder<T>): T['builder'];
|
|
328
|
-
//#endregion
|
|
329
306
|
//#region src/defineLogger.d.ts
|
|
330
307
|
/**
|
|
331
308
|
* Wraps a logger definition into a typed {@link Logger}.
|
|
@@ -341,37 +318,6 @@ declare function defineBuilder<T extends PluginFactoryOptions>(build: BuilderBui
|
|
|
341
318
|
*/
|
|
342
319
|
declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options>;
|
|
343
320
|
//#endregion
|
|
344
|
-
//#region src/definePreset.d.ts
|
|
345
|
-
/**
|
|
346
|
-
* Creates a typed preset object that bundles a name, resolvers, optional
|
|
347
|
-
* transformers, and optional generators — the building block for composable plugin presets.
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* import { definePreset } from '@kubb/core'
|
|
351
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
352
|
-
*
|
|
353
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy] })
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* // With custom transformers
|
|
357
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* // With generators
|
|
361
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] })
|
|
362
|
-
*/
|
|
363
|
-
declare function definePreset<TResolver extends Resolver = Resolver, TName extends string = string>(name: TName, {
|
|
364
|
-
resolvers,
|
|
365
|
-
transformers,
|
|
366
|
-
generators
|
|
367
|
-
}: {
|
|
368
|
-
resolvers: Array<TResolver>;
|
|
369
|
-
transformers?: Array<Visitor>;
|
|
370
|
-
generators?: Array<Generator<any>>;
|
|
371
|
-
}): Preset<TResolver> & {
|
|
372
|
-
name: TName;
|
|
373
|
-
};
|
|
374
|
-
//#endregion
|
|
375
321
|
//#region src/definePresets.d.ts
|
|
376
322
|
/**
|
|
377
323
|
* Creates a typed presets registry object — a named collection of {@link Preset} entries.
|
|
@@ -638,6 +584,7 @@ type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = {
|
|
|
638
584
|
adapter: Adapter;
|
|
639
585
|
driver: PluginDriver;
|
|
640
586
|
options: TOptions['resolvedOptions'];
|
|
587
|
+
resolver: TOptions['resolver'];
|
|
641
588
|
};
|
|
642
589
|
/**
|
|
643
590
|
* Renders a React component for a list of operation nodes (V2 generators).
|
|
@@ -651,6 +598,7 @@ type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = {
|
|
|
651
598
|
adapter: Adapter;
|
|
652
599
|
driver: PluginDriver;
|
|
653
600
|
options: TOptions['resolvedOptions'];
|
|
601
|
+
resolver: TOptions['resolver'];
|
|
654
602
|
};
|
|
655
603
|
/**
|
|
656
604
|
* Renders a React component for a single operation node (V2 generators).
|
|
@@ -664,6 +612,7 @@ type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = {
|
|
|
664
612
|
adapter: Adapter;
|
|
665
613
|
driver: PluginDriver;
|
|
666
614
|
options: TOptions['resolvedOptions'];
|
|
615
|
+
resolver: TOptions['resolver'];
|
|
667
616
|
};
|
|
668
617
|
/**
|
|
669
618
|
* Renders a React component for a single schema node (V2 generators).
|
|
@@ -829,11 +778,11 @@ declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions):
|
|
|
829
778
|
type GetPresetParams<TResolver extends Resolver> = {
|
|
830
779
|
preset: CompatibilityPreset;
|
|
831
780
|
presets: Presets<TResolver>;
|
|
832
|
-
resolvers
|
|
781
|
+
resolvers?: Array<TResolver>;
|
|
833
782
|
/**
|
|
834
783
|
* User-supplied generators to append after the preset's generators.
|
|
835
784
|
*/
|
|
836
|
-
generators
|
|
785
|
+
generators?: Array<Generator<any>>;
|
|
837
786
|
transformers?: Array<Visitor>;
|
|
838
787
|
};
|
|
839
788
|
type GetPresetResult<TResolver extends Resolver> = {
|
|
@@ -904,5 +853,5 @@ type DependencyVersion = string;
|
|
|
904
853
|
*/
|
|
905
854
|
declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
|
|
906
855
|
//#endregion
|
|
907
|
-
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType,
|
|
856
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, CompatibilityPreset, Config, type ConfigInput, CoreGeneratorV2, DevtoolsOptions, Exclude, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, Group, Include, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, Override, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, ReactGeneratorV2, ResolveBannerContext, ResolveNameParams, ResolveOptionsContext, ResolvePathOptions, ResolvePathParams, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, Storage, URLPath, UserConfig, UserGroup, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, buildDefaultBanner, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeResolvers, renderOperation, renderOperations, renderSchema, safeBuild, satisfiesDependency, setup };
|
|
908
857
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -16,14 +16,6 @@ import { sortBy } from "remeda";
|
|
|
16
16
|
import * as pkg from "empathic/package";
|
|
17
17
|
import { coerce, satisfies } from "semver";
|
|
18
18
|
//#region ../../internals/utils/src/errors.ts
|
|
19
|
-
/** Thrown when a plugin's configuration or input fails validation.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* throw new ValidationPluginError('Invalid config: "output.path" is required')
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
var ValidationPluginError = class extends Error {};
|
|
27
19
|
/**
|
|
28
20
|
* Thrown when one or more errors occur during a Kubb build.
|
|
29
21
|
* Carries the full list of underlying errors on `errors`.
|
|
@@ -344,28 +336,6 @@ async function clean(path) {
|
|
|
344
336
|
});
|
|
345
337
|
}
|
|
346
338
|
//#endregion
|
|
347
|
-
//#region ../../internals/utils/src/names.ts
|
|
348
|
-
/**
|
|
349
|
-
* Registers `originalName` in `data` without altering the returned name.
|
|
350
|
-
* Use when you need to track usage frequency but always emit the original identifier.
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* ```ts
|
|
354
|
-
* const seen: Record<string, number> = {}
|
|
355
|
-
* setUniqueName('Foo', seen) // 'Foo' (seen = { Foo: 1 })
|
|
356
|
-
* setUniqueName('Foo', seen) // 'Foo' (seen = { Foo: 2 })
|
|
357
|
-
* ```
|
|
358
|
-
*/
|
|
359
|
-
function setUniqueName(originalName, data) {
|
|
360
|
-
let used = data[originalName] || 0;
|
|
361
|
-
if (used) {
|
|
362
|
-
data[originalName] = ++used;
|
|
363
|
-
return originalName;
|
|
364
|
-
}
|
|
365
|
-
data[originalName] = 1;
|
|
366
|
-
return originalName;
|
|
367
|
-
}
|
|
368
|
-
//#endregion
|
|
369
339
|
//#region ../../internals/utils/src/promise.ts
|
|
370
340
|
/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.
|
|
371
341
|
*
|
|
@@ -989,29 +959,30 @@ var PluginDriver = class {
|
|
|
989
959
|
rootNode = void 0;
|
|
990
960
|
adapter = void 0;
|
|
991
961
|
#studioIsOpen = false;
|
|
992
|
-
|
|
993
|
-
#usedPluginNames = {};
|
|
962
|
+
plugins = /* @__PURE__ */ new Map();
|
|
994
963
|
constructor(config, options) {
|
|
995
964
|
this.config = config;
|
|
996
965
|
this.options = options;
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
966
|
+
config.plugins.map((plugin) => Object.assign({ install() {} }, plugin)).sort((a, b) => {
|
|
967
|
+
if (b.pre?.includes(a.name)) return 1;
|
|
968
|
+
if (b.post?.includes(a.name)) return -1;
|
|
969
|
+
return 0;
|
|
970
|
+
}).forEach((plugin) => {
|
|
971
|
+
this.plugins.set(plugin.name, plugin);
|
|
1000
972
|
});
|
|
1001
973
|
}
|
|
1002
974
|
get events() {
|
|
1003
975
|
return this.options.events;
|
|
1004
976
|
}
|
|
1005
977
|
getContext(plugin) {
|
|
1006
|
-
const plugins = [...this.#plugins];
|
|
1007
978
|
const driver = this;
|
|
1008
979
|
const baseContext = {
|
|
1009
|
-
fabric:
|
|
1010
|
-
config:
|
|
980
|
+
fabric: driver.options.fabric,
|
|
981
|
+
config: driver.config,
|
|
1011
982
|
plugin,
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
983
|
+
getPlugin: driver.getPlugin.bind(driver),
|
|
984
|
+
events: driver.options.events,
|
|
985
|
+
driver,
|
|
1015
986
|
addFile: async (...files) => {
|
|
1016
987
|
await this.options.fabric.addFile(...files);
|
|
1017
988
|
},
|
|
@@ -1024,6 +995,9 @@ var PluginDriver = class {
|
|
|
1024
995
|
get adapter() {
|
|
1025
996
|
return driver.adapter;
|
|
1026
997
|
},
|
|
998
|
+
get resolver() {
|
|
999
|
+
return plugin.resolver;
|
|
1000
|
+
},
|
|
1027
1001
|
openInStudio(options) {
|
|
1028
1002
|
if (!driver.config.devtools || driver.#studioIsOpen) return;
|
|
1029
1003
|
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
@@ -1034,8 +1008,8 @@ var PluginDriver = class {
|
|
|
1034
1008
|
}
|
|
1035
1009
|
};
|
|
1036
1010
|
const mergedExtras = {};
|
|
1037
|
-
for (const
|
|
1038
|
-
const result =
|
|
1011
|
+
for (const plugin of this.plugins.values()) if (typeof plugin.inject === "function") {
|
|
1012
|
+
const result = plugin.inject.call(baseContext, baseContext);
|
|
1039
1013
|
if (result !== null && typeof result === "object") Object.assign(mergedExtras, result);
|
|
1040
1014
|
}
|
|
1041
1015
|
return {
|
|
@@ -1043,9 +1017,9 @@ var PluginDriver = class {
|
|
|
1043
1017
|
...mergedExtras
|
|
1044
1018
|
};
|
|
1045
1019
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1020
|
+
/**
|
|
1021
|
+
* @deprecated use resolvers context instead
|
|
1022
|
+
*/
|
|
1049
1023
|
getFile({ name, mode, extname, pluginName, options }) {
|
|
1050
1024
|
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1051
1025
|
name,
|
|
@@ -1068,6 +1042,9 @@ var PluginDriver = class {
|
|
|
1068
1042
|
exports: []
|
|
1069
1043
|
};
|
|
1070
1044
|
}
|
|
1045
|
+
/**
|
|
1046
|
+
* @deprecated use resolvers context instead
|
|
1047
|
+
*/
|
|
1071
1048
|
resolvePath = (params) => {
|
|
1072
1049
|
const defaultPath = resolve(resolve(this.config.root, this.config.output.path), params.baseName);
|
|
1073
1050
|
if (params.pluginName) return this.hookForPluginSync({
|
|
@@ -1088,15 +1065,15 @@ var PluginDriver = class {
|
|
|
1088
1065
|
]
|
|
1089
1066
|
})?.result || defaultPath;
|
|
1090
1067
|
};
|
|
1068
|
+
/**
|
|
1069
|
+
* @deprecated use resolvers context instead
|
|
1070
|
+
*/
|
|
1091
1071
|
resolveName = (params) => {
|
|
1092
|
-
if (params.pluginName) {
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
});
|
|
1098
|
-
return transformReservedWord([...new Set(names)].at(0) || params.name);
|
|
1099
|
-
}
|
|
1072
|
+
if (params.pluginName) return transformReservedWord(this.hookForPluginSync({
|
|
1073
|
+
pluginName: params.pluginName,
|
|
1074
|
+
hookName: "resolveName",
|
|
1075
|
+
parameters: [params.name.trim(), params.type]
|
|
1076
|
+
})?.at(0) ?? params.name);
|
|
1100
1077
|
const name = this.hookFirstSync({
|
|
1101
1078
|
hookName: "resolveName",
|
|
1102
1079
|
parameters: [params.name.trim(), params.type]
|
|
@@ -1107,44 +1084,41 @@ var PluginDriver = class {
|
|
|
1107
1084
|
* Run a specific hookName for plugin x.
|
|
1108
1085
|
*/
|
|
1109
1086
|
async hookForPlugin({ pluginName, hookName, parameters }) {
|
|
1110
|
-
const
|
|
1087
|
+
const plugin = this.plugins.get(pluginName);
|
|
1088
|
+
if (!plugin) return [null];
|
|
1111
1089
|
this.events.emit("plugins:hook:progress:start", {
|
|
1112
1090
|
hookName,
|
|
1113
|
-
plugins
|
|
1091
|
+
plugins: [plugin]
|
|
1092
|
+
});
|
|
1093
|
+
const result = await this.#execute({
|
|
1094
|
+
strategy: "hookFirst",
|
|
1095
|
+
hookName,
|
|
1096
|
+
parameters,
|
|
1097
|
+
plugin
|
|
1114
1098
|
});
|
|
1115
|
-
const items = [];
|
|
1116
|
-
for (const plugin of plugins) {
|
|
1117
|
-
const result = await this.#execute({
|
|
1118
|
-
strategy: "hookFirst",
|
|
1119
|
-
hookName,
|
|
1120
|
-
parameters,
|
|
1121
|
-
plugin
|
|
1122
|
-
});
|
|
1123
|
-
if (result !== void 0 && result !== null) items.push(result);
|
|
1124
|
-
}
|
|
1125
1099
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1126
|
-
return
|
|
1100
|
+
return [result];
|
|
1127
1101
|
}
|
|
1128
1102
|
/**
|
|
1129
1103
|
* Run a specific hookName for plugin x.
|
|
1130
1104
|
*/
|
|
1131
1105
|
hookForPluginSync({ pluginName, hookName, parameters }) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
})
|
|
1106
|
+
const plugin = this.plugins.get(pluginName);
|
|
1107
|
+
if (!plugin) return null;
|
|
1108
|
+
const result = this.#executeSync({
|
|
1109
|
+
strategy: "hookFirst",
|
|
1110
|
+
hookName,
|
|
1111
|
+
parameters,
|
|
1112
|
+
plugin
|
|
1113
|
+
});
|
|
1114
|
+
return result !== null ? [result] : [];
|
|
1140
1115
|
}
|
|
1141
1116
|
/**
|
|
1142
1117
|
* Returns the first non-null result.
|
|
1143
1118
|
*/
|
|
1144
1119
|
async hookFirst({ hookName, parameters, skipped }) {
|
|
1145
|
-
const plugins =
|
|
1146
|
-
|
|
1147
|
-
});
|
|
1120
|
+
const plugins = [];
|
|
1121
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin && (skipped ? !skipped.has(plugin) : true)) plugins.push(plugin);
|
|
1148
1122
|
this.events.emit("plugins:hook:progress:start", {
|
|
1149
1123
|
hookName,
|
|
1150
1124
|
plugins
|
|
@@ -1171,10 +1145,9 @@ var PluginDriver = class {
|
|
|
1171
1145
|
*/
|
|
1172
1146
|
hookFirstSync({ hookName, parameters, skipped }) {
|
|
1173
1147
|
let parseResult = null;
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
for (const plugin of plugins) {
|
|
1148
|
+
for (const plugin of this.plugins.values()) {
|
|
1149
|
+
if (!(hookName in plugin)) continue;
|
|
1150
|
+
if (skipped?.has(plugin)) continue;
|
|
1178
1151
|
parseResult = {
|
|
1179
1152
|
result: this.#executeSync({
|
|
1180
1153
|
strategy: "hookFirst",
|
|
@@ -1184,7 +1157,7 @@ var PluginDriver = class {
|
|
|
1184
1157
|
}),
|
|
1185
1158
|
plugin
|
|
1186
1159
|
};
|
|
1187
|
-
if (parseResult
|
|
1160
|
+
if (parseResult.result != null) break;
|
|
1188
1161
|
}
|
|
1189
1162
|
return parseResult;
|
|
1190
1163
|
}
|
|
@@ -1192,7 +1165,8 @@ var PluginDriver = class {
|
|
|
1192
1165
|
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
1193
1166
|
*/
|
|
1194
1167
|
async hookParallel({ hookName, parameters }) {
|
|
1195
|
-
const plugins =
|
|
1168
|
+
const plugins = [];
|
|
1169
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
1196
1170
|
this.events.emit("plugins:hook:progress:start", {
|
|
1197
1171
|
hookName,
|
|
1198
1172
|
plugins
|
|
@@ -1211,7 +1185,7 @@ var PluginDriver = class {
|
|
|
1211
1185
|
}), this.options.concurrency);
|
|
1212
1186
|
results.forEach((result, index) => {
|
|
1213
1187
|
if (isPromiseRejectedResult(result)) {
|
|
1214
|
-
const plugin =
|
|
1188
|
+
const plugin = plugins[index];
|
|
1215
1189
|
if (plugin) {
|
|
1216
1190
|
const startTime = pluginStartTimes.get(plugin) ?? performance.now();
|
|
1217
1191
|
this.events.emit("error", result.reason, {
|
|
@@ -1234,7 +1208,8 @@ var PluginDriver = class {
|
|
|
1234
1208
|
* Chains plugins
|
|
1235
1209
|
*/
|
|
1236
1210
|
async hookSeq({ hookName, parameters }) {
|
|
1237
|
-
const plugins =
|
|
1211
|
+
const plugins = [];
|
|
1212
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
1238
1213
|
this.events.emit("plugins:hook:progress:start", {
|
|
1239
1214
|
hookName,
|
|
1240
1215
|
plugins
|
|
@@ -1249,33 +1224,8 @@ var PluginDriver = class {
|
|
|
1249
1224
|
}));
|
|
1250
1225
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1251
1226
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1255
|
-
return plugins.map((plugin) => {
|
|
1256
|
-
if (plugin.pre) {
|
|
1257
|
-
let missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1258
|
-
if (missingPlugins.includes("plugin-oas") && this.adapter) missingPlugins = missingPlugins.filter((pluginName) => pluginName !== "plugin-oas");
|
|
1259
|
-
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1260
|
-
}
|
|
1261
|
-
return plugin;
|
|
1262
|
-
}).sort((a, b) => {
|
|
1263
|
-
if (b.pre?.includes(a.name)) return 1;
|
|
1264
|
-
if (b.post?.includes(a.name)) return -1;
|
|
1265
|
-
return 0;
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
getPluginByName(pluginName) {
|
|
1269
|
-
return [...this.#plugins].find((item) => item.name === pluginName);
|
|
1270
|
-
}
|
|
1271
|
-
getPluginsByName(hookName, pluginName) {
|
|
1272
|
-
const plugins = [...this.plugins];
|
|
1273
|
-
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => item.name === pluginName);
|
|
1274
|
-
if (!pluginByPluginName?.length) {
|
|
1275
|
-
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
1276
|
-
return corePlugin ? [corePlugin] : [];
|
|
1277
|
-
}
|
|
1278
|
-
return pluginByPluginName;
|
|
1227
|
+
getPlugin(pluginName) {
|
|
1228
|
+
return this.plugins.get(pluginName);
|
|
1279
1229
|
}
|
|
1280
1230
|
/**
|
|
1281
1231
|
* Run an async plugin hook and return the result.
|
|
@@ -1363,16 +1313,6 @@ var PluginDriver = class {
|
|
|
1363
1313
|
return null;
|
|
1364
1314
|
}
|
|
1365
1315
|
}
|
|
1366
|
-
#parse(plugin) {
|
|
1367
|
-
const usedPluginNames = this.#usedPluginNames;
|
|
1368
|
-
setUniqueName(plugin.name, usedPluginNames);
|
|
1369
|
-
const usageCount = usedPluginNames[plugin.name];
|
|
1370
|
-
if (usageCount && usageCount > 1) throw new ValidationPluginError(`Duplicate plugin "${plugin.name}" detected. Each plugin can only be used once. Use a different configuration instead of adding multiple instances of the same plugin.`);
|
|
1371
|
-
return {
|
|
1372
|
-
install() {},
|
|
1373
|
-
...plugin
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
1316
|
};
|
|
1377
1317
|
//#endregion
|
|
1378
1318
|
//#region src/createStorage.ts
|
|
@@ -1472,7 +1412,7 @@ const fsStorage = createStorage(() => ({
|
|
|
1472
1412
|
}));
|
|
1473
1413
|
//#endregion
|
|
1474
1414
|
//#region package.json
|
|
1475
|
-
var version$1 = "5.0.0-alpha.
|
|
1415
|
+
var version$1 = "5.0.0-alpha.24";
|
|
1476
1416
|
//#endregion
|
|
1477
1417
|
//#region src/utils/diagnostics.ts
|
|
1478
1418
|
/**
|
|
@@ -1668,7 +1608,7 @@ async function safeBuild(options, overrides) {
|
|
|
1668
1608
|
const pluginTimings = /* @__PURE__ */ new Map();
|
|
1669
1609
|
const config = driver.config;
|
|
1670
1610
|
try {
|
|
1671
|
-
for (const plugin of driver.plugins) {
|
|
1611
|
+
for (const plugin of driver.plugins.values()) {
|
|
1672
1612
|
const context = driver.getContext(plugin);
|
|
1673
1613
|
const hrStart = process.hrtime();
|
|
1674
1614
|
const installer = plugin.install.bind(context);
|
|
@@ -1778,7 +1718,7 @@ async function safeBuild(options, overrides) {
|
|
|
1778
1718
|
}
|
|
1779
1719
|
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, driver }) {
|
|
1780
1720
|
const pluginNameMap = /* @__PURE__ */ new Map();
|
|
1781
|
-
for (const plugin of driver.plugins) pluginNameMap.set(plugin.name, plugin);
|
|
1721
|
+
for (const plugin of driver.plugins.values()) pluginNameMap.set(plugin.name, plugin);
|
|
1782
1722
|
return barrelFiles.flatMap((file) => {
|
|
1783
1723
|
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
|
|
1784
1724
|
return (file.sources ?? []).flatMap((source) => {
|
|
@@ -1860,26 +1800,6 @@ function createPlugin(build) {
|
|
|
1860
1800
|
return (options) => build(options ?? {});
|
|
1861
1801
|
}
|
|
1862
1802
|
//#endregion
|
|
1863
|
-
//#region src/defineBuilder.ts
|
|
1864
|
-
/**
|
|
1865
|
-
* Defines a builder for a plugin — a named collection of schema-building helpers that
|
|
1866
|
-
* can be exported alongside the plugin and imported by other plugins or generators.
|
|
1867
|
-
*
|
|
1868
|
-
* @example
|
|
1869
|
-
* export const builder = defineBuilder<PluginTs>(() => ({
|
|
1870
|
-
* name: 'default',
|
|
1871
|
-
* buildParamsSchema({ params, node, resolver }) {
|
|
1872
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
1873
|
-
* },
|
|
1874
|
-
* buildDataSchemaNode({ node, resolver }) {
|
|
1875
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
1876
|
-
* },
|
|
1877
|
-
* }))
|
|
1878
|
-
*/
|
|
1879
|
-
function defineBuilder(build) {
|
|
1880
|
-
return build();
|
|
1881
|
-
}
|
|
1882
|
-
//#endregion
|
|
1883
1803
|
//#region src/defineGenerator.ts
|
|
1884
1804
|
function defineGenerator(generator) {
|
|
1885
1805
|
if (generator.type === "react") return {
|
|
@@ -1927,34 +1847,6 @@ function defineLogger(logger) {
|
|
|
1927
1847
|
return logger;
|
|
1928
1848
|
}
|
|
1929
1849
|
//#endregion
|
|
1930
|
-
//#region src/definePreset.ts
|
|
1931
|
-
/**
|
|
1932
|
-
* Creates a typed preset object that bundles a name, resolvers, optional
|
|
1933
|
-
* transformers, and optional generators — the building block for composable plugin presets.
|
|
1934
|
-
*
|
|
1935
|
-
* @example
|
|
1936
|
-
* import { definePreset } from '@kubb/core'
|
|
1937
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
1938
|
-
*
|
|
1939
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy] })
|
|
1940
|
-
*
|
|
1941
|
-
* @example
|
|
1942
|
-
* // With custom transformers
|
|
1943
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
1944
|
-
*
|
|
1945
|
-
* @example
|
|
1946
|
-
* // With generators
|
|
1947
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] })
|
|
1948
|
-
*/
|
|
1949
|
-
function definePreset(name, { resolvers, transformers, generators }) {
|
|
1950
|
-
return {
|
|
1951
|
-
name,
|
|
1952
|
-
resolvers,
|
|
1953
|
-
transformers,
|
|
1954
|
-
generators
|
|
1955
|
-
};
|
|
1956
|
-
}
|
|
1957
|
-
//#endregion
|
|
1958
1850
|
//#region src/definePresets.ts
|
|
1959
1851
|
/**
|
|
1960
1852
|
* Creates a typed presets registry object — a named collection of {@link Preset} entries.
|
|
@@ -2101,13 +1993,7 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
|
|
|
2101
1993
|
*/
|
|
2102
1994
|
function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
|
|
2103
1995
|
if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single") return path.resolve(root, output.path);
|
|
2104
|
-
if (group && (groupPath || tag)) {
|
|
2105
|
-
const groupName = group.name ? group.name : (ctx) => {
|
|
2106
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
2107
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
2108
|
-
};
|
|
2109
|
-
return path.resolve(root, output.path, groupName({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
2110
|
-
}
|
|
1996
|
+
if (group && (groupPath || tag)) return path.resolve(root, output.path, group.name({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
2111
1997
|
return path.resolve(root, output.path, baseName);
|
|
2112
1998
|
}
|
|
2113
1999
|
/**
|
|
@@ -2307,19 +2193,15 @@ async function renderOperations(nodes, options) {
|
|
|
2307
2193
|
const { config, fabric, plugin, Component, driver, adapter } = options;
|
|
2308
2194
|
if (!Component) return;
|
|
2309
2195
|
const fabricChild = createReactFabric();
|
|
2310
|
-
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
nodes,
|
|
2320
|
-
options: options.options
|
|
2321
|
-
})
|
|
2322
|
-
}));
|
|
2196
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, { children: /* @__PURE__ */ jsx(Component, {
|
|
2197
|
+
config,
|
|
2198
|
+
plugin,
|
|
2199
|
+
driver,
|
|
2200
|
+
adapter,
|
|
2201
|
+
nodes,
|
|
2202
|
+
options: options.options,
|
|
2203
|
+
resolver: options.resolver
|
|
2204
|
+
}) }));
|
|
2323
2205
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2324
2206
|
fabricChild.unmount();
|
|
2325
2207
|
}
|
|
@@ -2330,19 +2212,15 @@ async function renderOperation(node, options) {
|
|
|
2330
2212
|
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2331
2213
|
if (!Component) return;
|
|
2332
2214
|
const fabricChild = createReactFabric();
|
|
2333
|
-
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
node,
|
|
2343
|
-
options: options.options
|
|
2344
|
-
})
|
|
2345
|
-
}));
|
|
2215
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, { children: /* @__PURE__ */ jsx(Component, {
|
|
2216
|
+
config,
|
|
2217
|
+
plugin,
|
|
2218
|
+
driver,
|
|
2219
|
+
adapter,
|
|
2220
|
+
node,
|
|
2221
|
+
options: options.options,
|
|
2222
|
+
resolver: options.resolver
|
|
2223
|
+
}) }));
|
|
2346
2224
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2347
2225
|
fabricChild.unmount();
|
|
2348
2226
|
}
|
|
@@ -2353,19 +2231,15 @@ async function renderSchema(node, options) {
|
|
|
2353
2231
|
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2354
2232
|
if (!Component) return;
|
|
2355
2233
|
const fabricChild = createReactFabric();
|
|
2356
|
-
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
node,
|
|
2366
|
-
options: options.options
|
|
2367
|
-
})
|
|
2368
|
-
}));
|
|
2234
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, { children: /* @__PURE__ */ jsx(Component, {
|
|
2235
|
+
config,
|
|
2236
|
+
plugin,
|
|
2237
|
+
driver,
|
|
2238
|
+
adapter,
|
|
2239
|
+
node,
|
|
2240
|
+
options: options.options,
|
|
2241
|
+
resolver: options.resolver
|
|
2242
|
+
}) }));
|
|
2369
2243
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2370
2244
|
fabricChild.unmount();
|
|
2371
2245
|
}
|
|
@@ -2778,7 +2652,10 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
|
|
|
2778
2652
|
*/
|
|
2779
2653
|
async function getConfigs(config, args) {
|
|
2780
2654
|
const resolved = await (typeof config === "function" ? config(args) : config);
|
|
2781
|
-
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
2655
|
+
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
2656
|
+
plugins: [],
|
|
2657
|
+
...item
|
|
2658
|
+
}));
|
|
2782
2659
|
}
|
|
2783
2660
|
//#endregion
|
|
2784
2661
|
//#region src/utils/mergeResolvers.ts
|
|
@@ -2810,7 +2687,7 @@ function mergeResolvers(...resolvers) {
|
|
|
2810
2687
|
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
2811
2688
|
*/
|
|
2812
2689
|
function getPreset(params) {
|
|
2813
|
-
const { preset: presetName, presets, resolvers, transformers: userTransformers, generators: userGenerators } = params;
|
|
2690
|
+
const { preset: presetName, presets, resolvers = [], transformers: userTransformers = [], generators: userGenerators = [] } = params;
|
|
2814
2691
|
const [defaultResolver, ...userResolvers] = resolvers;
|
|
2815
2692
|
const preset = presets[presetName];
|
|
2816
2693
|
const resolver = mergeResolvers(mergeResolvers(defaultResolver, ...preset?.resolvers ?? []), ...userResolvers ?? []);
|
|
@@ -2907,6 +2784,6 @@ function satisfiesDependency(dependency, version, cwd) {
|
|
|
2907
2784
|
return satisfies(semVer, version);
|
|
2908
2785
|
}
|
|
2909
2786
|
//#endregion
|
|
2910
|
-
export { AsyncEventEmitter, FunctionParams, PluginDriver, URLPath, build, build as default, buildDefaultBanner, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath,
|
|
2787
|
+
export { AsyncEventEmitter, FunctionParams, PluginDriver, URLPath, build, build as default, buildDefaultBanner, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeResolvers, renderOperation, renderOperations, renderSchema, safeBuild, satisfiesDependency, setup };
|
|
2911
2788
|
|
|
2912
2789
|
//# sourceMappingURL=index.js.map
|