@kubb/core 5.0.0-alpha.29 → 5.0.0-alpha.30
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-C6VX0skO.d.ts → PluginDriver-D110FoJ-.d.ts} +265 -108
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +495 -529
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -80
- package/dist/index.js +496 -525
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PluginDriver.ts +44 -10
- package/src/build.ts +87 -8
- package/src/createPlugin.ts +3 -1
- package/src/defineGenerator.ts +101 -134
- package/src/index.ts +1 -2
- package/src/renderNode.tsx +14 -186
- package/src/types.ts +213 -11
- package/src/utils/executeStrategies.ts +7 -1
|
@@ -213,112 +213,77 @@ declare function createStorage<TOptions = Record<string, never>>(build: (options
|
|
|
213
213
|
//#endregion
|
|
214
214
|
//#region src/defineGenerator.d.ts
|
|
215
215
|
/**
|
|
216
|
-
*
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
};
|
|
239
|
-
/**
|
|
240
|
-
* Props for the `schema` lifecycle — receives a single schema node.
|
|
241
|
-
*/
|
|
242
|
-
type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
243
|
-
config: Config;
|
|
244
|
-
adapter: Adapter;
|
|
245
|
-
driver: PluginDriver;
|
|
246
|
-
plugin: Plugin<TPlugin>;
|
|
247
|
-
options: Plugin<TPlugin>['options'];
|
|
248
|
-
resolver: TPlugin['resolver'];
|
|
249
|
-
node: SchemaNode;
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Input shape for a core v2 async generator — lifecycle methods are optional.
|
|
253
|
-
*/
|
|
254
|
-
type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
255
|
-
name: string;
|
|
256
|
-
type: 'core';
|
|
257
|
-
version?: '2';
|
|
258
|
-
operations?(props: OperationsV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
259
|
-
operation?(props: OperationV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
260
|
-
schema?(props: SchemaV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
261
|
-
};
|
|
262
|
-
/**
|
|
263
|
-
* Input shape for a React v2 generator — component methods are optional.
|
|
264
|
-
*/
|
|
265
|
-
type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
266
|
-
name: string;
|
|
267
|
-
type: 'react';
|
|
268
|
-
version?: '2';
|
|
269
|
-
Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode;
|
|
270
|
-
Operation?(props: OperationV2Props<TPlugin>): FabricReactNode;
|
|
271
|
-
Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode;
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* A fully resolved core v2 generator with `version: '2'` and guaranteed async lifecycle methods.
|
|
275
|
-
*/
|
|
276
|
-
type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
277
|
-
name: string;
|
|
278
|
-
type: 'core';
|
|
279
|
-
version: '2';
|
|
280
|
-
operations(props: OperationsV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
281
|
-
operation(props: OperationV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
282
|
-
schema(props: SchemaV2Props<TPlugin>): Promise<Array<FabricFile.File>>;
|
|
283
|
-
};
|
|
284
|
-
/**
|
|
285
|
-
* A fully resolved React v2 generator with `version: '2'` and guaranteed component methods.
|
|
216
|
+
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
217
|
+
* methods. Each method is called with `this = PluginContext` of the parent plugin,
|
|
218
|
+
* giving full access to `this.config`, `this.resolver`, `this.adapter`, `this.fabric`,
|
|
219
|
+
* `this.driver`, etc.
|
|
220
|
+
*
|
|
221
|
+
* Return a React element, an array of `FabricFile.File`, or `void` to handle file
|
|
222
|
+
* writing manually via `this.upsertFile`. Both React and core (non-React) generators
|
|
223
|
+
* use the same method signatures — the return type determines how output is handled.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
228
|
+
* name: 'typescript',
|
|
229
|
+
* schema(node, options) {
|
|
230
|
+
* const { adapter, resolver, root } = this
|
|
231
|
+
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
232
|
+
* },
|
|
233
|
+
* operation(node, options) {
|
|
234
|
+
* return <File ...><OperationType node={node} /></File>
|
|
235
|
+
* },
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
286
238
|
*/
|
|
287
|
-
type
|
|
288
|
-
name: string;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
239
|
+
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
240
|
+
/** Used in diagnostic messages and debug output. */name: string;
|
|
241
|
+
/**
|
|
242
|
+
* Called for each schema node in the AST walk.
|
|
243
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
244
|
+
* `options` contains the per-node resolved options (after exclude/include/override).
|
|
245
|
+
*/
|
|
246
|
+
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
247
|
+
/**
|
|
248
|
+
* Called for each operation node in the AST walk.
|
|
249
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
250
|
+
*/
|
|
251
|
+
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
252
|
+
/**
|
|
253
|
+
* Called once after all operations have been walked.
|
|
254
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
255
|
+
*/
|
|
256
|
+
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
294
257
|
};
|
|
295
258
|
/**
|
|
296
|
-
*
|
|
259
|
+
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
260
|
+
* No type discrimination (`type: 'react' | 'core'`) needed — `applyHookResult`
|
|
261
|
+
* handles React elements and `File[]` uniformly.
|
|
297
262
|
*/
|
|
298
|
-
|
|
263
|
+
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generator: Generator<TOptions>): Generator<TOptions>;
|
|
299
264
|
/**
|
|
300
|
-
*
|
|
301
|
-
* Works for both `core` (async file output) and `react` (JSX component) generators.
|
|
265
|
+
* Merges an array of generators into a single generator.
|
|
302
266
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* Schema({ node, options }) { return <File>...</File> },
|
|
310
|
-
* })
|
|
267
|
+
* The merged generator's `schema`, `operation`, and `operations` methods run
|
|
268
|
+
* the corresponding method from each input generator in sequence, applying each
|
|
269
|
+
* result via `applyHookResult`. This eliminates the need to write the loop
|
|
270
|
+
* manually in each plugin.
|
|
271
|
+
*
|
|
272
|
+
* @param generators - Array of generators to merge into a single generator.
|
|
311
273
|
*
|
|
312
274
|
* @example
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
275
|
+
* ```ts
|
|
276
|
+
* const merged = mergeGenerators(generators)
|
|
277
|
+
*
|
|
278
|
+
* return {
|
|
279
|
+
* name: pluginName,
|
|
280
|
+
* schema: merged.schema,
|
|
281
|
+
* operation: merged.operation,
|
|
282
|
+
* operations: merged.operations,
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
319
285
|
*/
|
|
320
|
-
declare function
|
|
321
|
-
declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>;
|
|
286
|
+
declare function mergeGenerators<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generators: Array<Generator<TOptions>>): Generator<TOptions>;
|
|
322
287
|
//#endregion
|
|
323
288
|
//#region src/Kubb.d.ts
|
|
324
289
|
type DebugInfo = {
|
|
@@ -554,6 +519,24 @@ interface KubbEvents {
|
|
|
554
519
|
declare global {
|
|
555
520
|
namespace Kubb {
|
|
556
521
|
interface PluginContext {}
|
|
522
|
+
/**
|
|
523
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
524
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
525
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* // packages/plugin-ts/src/types.ts
|
|
530
|
+
* declare global {
|
|
531
|
+
* namespace Kubb {
|
|
532
|
+
* interface PluginRegistry {
|
|
533
|
+
* 'plugin-ts': PluginTs
|
|
534
|
+
* }
|
|
535
|
+
* }
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
interface PluginRegistry {}
|
|
557
540
|
}
|
|
558
541
|
}
|
|
559
542
|
/**
|
|
@@ -919,7 +902,12 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
919
902
|
/**
|
|
920
903
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
921
904
|
*/
|
|
922
|
-
options: TOptions['resolvedOptions']
|
|
905
|
+
options: TOptions['resolvedOptions'] & {
|
|
906
|
+
output: Output;
|
|
907
|
+
include?: Array<Include>;
|
|
908
|
+
exclude: Array<Exclude>;
|
|
909
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
910
|
+
};
|
|
923
911
|
/**
|
|
924
912
|
* The resolver for this plugin.
|
|
925
913
|
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
@@ -940,10 +928,46 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
940
928
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
941
929
|
*/
|
|
942
930
|
post?: Array<string>;
|
|
943
|
-
|
|
931
|
+
/**
|
|
932
|
+
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
933
|
+
* Inspired by Vite's `apply` option.
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```ts
|
|
937
|
+
* apply: (config) => config.output.path !== 'disabled'
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
apply?: (config: Config) => boolean;
|
|
941
|
+
/**
|
|
942
|
+
* Expose shared helpers or data to all other plugins via `PluginContext`.
|
|
943
|
+
* The object returned is merged into the context that every plugin receives.
|
|
944
|
+
* Use the `declare global { namespace Kubb { interface PluginContext { … } } }` pattern
|
|
945
|
+
* to make the injected properties type-safe.
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* inject() {
|
|
950
|
+
* return { getOas: () => parseSpec(this.config) }
|
|
951
|
+
* }
|
|
952
|
+
* // Other plugins can then call `this.getOas()` inside buildStart()
|
|
953
|
+
* ```
|
|
954
|
+
*/
|
|
955
|
+
inject?: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
944
956
|
};
|
|
945
957
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
946
958
|
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
|
|
959
|
+
/**
|
|
960
|
+
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
961
|
+
*/
|
|
962
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
963
|
+
/**
|
|
964
|
+
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
965
|
+
*/
|
|
966
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
967
|
+
/**
|
|
968
|
+
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
969
|
+
*/
|
|
970
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FabricFile.File> | void>;
|
|
947
971
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
948
972
|
/**
|
|
949
973
|
* Unique name used for the plugin
|
|
@@ -962,7 +986,12 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
962
986
|
/**
|
|
963
987
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
964
988
|
*/
|
|
965
|
-
options: TOptions['resolvedOptions']
|
|
989
|
+
options: TOptions['resolvedOptions'] & {
|
|
990
|
+
output: Output;
|
|
991
|
+
include?: Array<Include>;
|
|
992
|
+
exclude: Array<Exclude>;
|
|
993
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
994
|
+
};
|
|
966
995
|
/**
|
|
967
996
|
* The resolver for this plugin.
|
|
968
997
|
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
@@ -974,19 +1003,87 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
974
1003
|
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
975
1004
|
*/
|
|
976
1005
|
transformer?: Visitor;
|
|
977
|
-
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
978
1006
|
/**
|
|
979
|
-
*
|
|
1007
|
+
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
1008
|
+
* Inspired by Vite's `apply` option.
|
|
1009
|
+
*/
|
|
1010
|
+
apply?: (config: Config) => boolean;
|
|
1011
|
+
/**
|
|
1012
|
+
* Optional semver version string for this plugin, e.g. `"1.2.3"`.
|
|
1013
|
+
* Used in diagnostic messages and version-conflict detection.
|
|
1014
|
+
*/
|
|
1015
|
+
version?: string;
|
|
1016
|
+
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Called once per plugin after all files have been written to disk.
|
|
1019
|
+
* Use this for post-processing, copying assets, or generating summary reports.
|
|
980
1020
|
*/
|
|
981
|
-
|
|
1021
|
+
buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Called for each schema node during the AST walk.
|
|
1024
|
+
* Return a React element, an array of `FabricFile.File`, or `void` for manual handling.
|
|
1025
|
+
* Nodes matching `exclude`/`include` filters are skipped automatically.
|
|
1026
|
+
*
|
|
1027
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1028
|
+
*/
|
|
1029
|
+
schema?: SchemaHook<TOptions>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Called for each operation node during the AST walk.
|
|
1032
|
+
* Return a React element, an array of `FabricFile.File`, or `void` for manual handling.
|
|
1033
|
+
*
|
|
1034
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1035
|
+
*/
|
|
1036
|
+
operation?: OperationHook<TOptions>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Called once after all operations have been walked, with the full collected set.
|
|
1039
|
+
*
|
|
1040
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1041
|
+
*/
|
|
1042
|
+
operations?: OperationsHook<TOptions>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Expose shared helpers or data to all other plugins via `PluginContext`.
|
|
1045
|
+
* The returned object is merged into the context received by every plugin.
|
|
1046
|
+
*/
|
|
1047
|
+
inject: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
982
1048
|
};
|
|
983
1049
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
984
1050
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
985
1051
|
/**
|
|
986
|
-
*
|
|
1052
|
+
* Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
|
|
1053
|
+
* Use this to set up shared state, fetch remote data, or perform any async initialization.
|
|
1054
|
+
* @type hookParallel
|
|
1055
|
+
*/
|
|
1056
|
+
buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Called once per plugin after all files have been written to disk.
|
|
1059
|
+
* Use this for post-processing, copying assets, or generating summary reports.
|
|
987
1060
|
* @type hookParallel
|
|
988
1061
|
*/
|
|
989
|
-
|
|
1062
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Called for each schema node during the AST walk.
|
|
1065
|
+
* Return a React element (`<File>...</File>`), an array of `FabricFile.File` objects,
|
|
1066
|
+
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1067
|
+
* Nodes matching `exclude` / `include` filters are skipped automatically.
|
|
1068
|
+
*
|
|
1069
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1070
|
+
*/
|
|
1071
|
+
schema?: SchemaHook<TOptions>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Called for each operation node during the AST walk.
|
|
1074
|
+
* Return a React element (`<File>...</File>`), an array of `FabricFile.File` objects,
|
|
1075
|
+
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1076
|
+
*
|
|
1077
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1078
|
+
*/
|
|
1079
|
+
operation?: OperationHook<TOptions>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Called once after all operation nodes have been walked, with the full collection.
|
|
1082
|
+
* Useful for generating index/barrel files per group or aggregate operation handlers.
|
|
1083
|
+
*
|
|
1084
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1085
|
+
*/
|
|
1086
|
+
operations?: OperationsHook<TOptions>;
|
|
990
1087
|
/**
|
|
991
1088
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
992
1089
|
* Options can als be included.
|
|
@@ -1031,8 +1128,32 @@ type ResolveNameParams = {
|
|
|
1031
1128
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1032
1129
|
fabric: Fabric;
|
|
1033
1130
|
config: Config;
|
|
1131
|
+
/**
|
|
1132
|
+
* Absolute path to the output directory for the current plugin.
|
|
1133
|
+
* Shorthand for `path.resolve(config.root, config.output.path)`.
|
|
1134
|
+
*/
|
|
1135
|
+
root: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* Returns the output mode for the given output config.
|
|
1138
|
+
* Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
|
|
1139
|
+
* Shorthand for `getMode(path.resolve(this.root, output.path))`.
|
|
1140
|
+
*/
|
|
1141
|
+
getMode: (output: {
|
|
1142
|
+
path: string;
|
|
1143
|
+
}) => FabricFile.Mode;
|
|
1034
1144
|
driver: PluginDriver;
|
|
1035
|
-
|
|
1145
|
+
/**
|
|
1146
|
+
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
1147
|
+
* the name is a registered key, otherwise returns the generic `Plugin`.
|
|
1148
|
+
*/
|
|
1149
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1150
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1151
|
+
/**
|
|
1152
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
1153
|
+
* Useful for enforcing dependencies inside `buildStart()`.
|
|
1154
|
+
*/
|
|
1155
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1156
|
+
requirePlugin(name: string): Plugin;
|
|
1036
1157
|
/**
|
|
1037
1158
|
* Only add when the file does not exist yet
|
|
1038
1159
|
*/
|
|
@@ -1041,6 +1162,9 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1041
1162
|
* merging multiple sources into the same output file
|
|
1042
1163
|
*/
|
|
1043
1164
|
upsertFile: (...file: Array<FabricFile.File>) => Promise<void>;
|
|
1165
|
+
/**
|
|
1166
|
+
* @deprecated use this.warn, this.error, this.info instead
|
|
1167
|
+
*/
|
|
1044
1168
|
events: AsyncEventEmitter<KubbEvents>;
|
|
1045
1169
|
/**
|
|
1046
1170
|
* Current plugin
|
|
@@ -1055,6 +1179,21 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1055
1179
|
* Apply with `transform(node, context.transformer)` to pre-process AST nodes before printing.
|
|
1056
1180
|
*/
|
|
1057
1181
|
transformer: Visitor | undefined;
|
|
1182
|
+
/**
|
|
1183
|
+
* Emit a warning via the build event system.
|
|
1184
|
+
* Shorthand for `this.events.emit('warn', message)`.
|
|
1185
|
+
*/
|
|
1186
|
+
warn: (message: string) => void;
|
|
1187
|
+
/**
|
|
1188
|
+
* Emit an error via the build event system.
|
|
1189
|
+
* Shorthand for `this.events.emit('error', error)`.
|
|
1190
|
+
*/
|
|
1191
|
+
error: (error: string | Error) => void;
|
|
1192
|
+
/**
|
|
1193
|
+
* Emit an info message via the build event system.
|
|
1194
|
+
* Shorthand for `this.events.emit('info', message)`.
|
|
1195
|
+
*/
|
|
1196
|
+
info: (message: string) => void;
|
|
1058
1197
|
/**
|
|
1059
1198
|
* Opens the Kubb Studio URL for the current `rootNode` in the default browser.
|
|
1060
1199
|
* Falls back to printing the URL if the browser cannot be launched.
|
|
@@ -1075,6 +1214,18 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1075
1214
|
rootNode?: never;
|
|
1076
1215
|
adapter?: never;
|
|
1077
1216
|
}) & Kubb.PluginContext;
|
|
1217
|
+
/**
|
|
1218
|
+
* Narrowed `PluginContext` used as the `this` type inside generator and plugin AST hook methods.
|
|
1219
|
+
*
|
|
1220
|
+
* Generators and the `schema`/`operation`/`operations` plugin hooks are only invoked from
|
|
1221
|
+
* `runPluginAstHooks`, which already guards against a missing adapter. This type reflects
|
|
1222
|
+
* that guarantee — `this.adapter` and `this.rootNode` are always defined, so no runtime
|
|
1223
|
+
* checks or casts are needed inside the method bodies.
|
|
1224
|
+
*/
|
|
1225
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'rootNode'> & {
|
|
1226
|
+
adapter: Adapter;
|
|
1227
|
+
rootNode: RootNode;
|
|
1228
|
+
};
|
|
1078
1229
|
/**
|
|
1079
1230
|
* Specify the export location for the files and define the behavior of the output
|
|
1080
1231
|
*/
|
|
@@ -1468,8 +1619,14 @@ declare class PluginDriver {
|
|
|
1468
1619
|
hookName: H;
|
|
1469
1620
|
parameters?: PluginParameter<H>;
|
|
1470
1621
|
}): Promise<void>;
|
|
1622
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1471
1623
|
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
1624
|
+
/**
|
|
1625
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
1626
|
+
*/
|
|
1627
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1628
|
+
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1472
1629
|
}
|
|
1473
1630
|
//#endregion
|
|
1474
|
-
export {
|
|
1475
|
-
//# sourceMappingURL=PluginDriver-
|
|
1631
|
+
export { defineGenerator as $, Preset as A, Resolver as B, Plugin as C, PluginLifecycleHooks as D, PluginLifecycle as E, ResolveBannerContext as F, UserConfig as G, ResolverFileParams as H, ResolveNameParams as I, UserPlugin as J, UserGroup as K, ResolveOptionsContext as L, Printer$1 as M, PrinterFactoryOptions as N, PluginParameter as O, PrinterPartial as P, Generator as Q, ResolvePathOptions as R, Override as S, PluginFactoryOptions as T, ResolverPathParams as U, ResolverContext as V, SchemaHook as W, UserResolver as X, UserPluginWithLifeCycle as Y, KubbEvents as Z, LoggerContext as _, AdapterSource as a, logLevel as at, OperationsHook as b, Config as c, GeneratorContext as d, mergeGenerators as et, Group as f, Logger as g, InputPath as h, AdapterFactoryOptions as i, linters as it, Presets as j, PluginWithLifeCycle as k, DevtoolsOptions as l, InputData as m, getMode as n, createStorage as nt, BarrelType as o, PossiblePromise as ot, Include as p, UserLogger as q, Adapter as r, formatters as rt, CompatibilityPreset as s, AsyncEventEmitter as st, PluginDriver as t, Storage as tt, Exclude as u, LoggerOptions as v, PluginContext as w, Output as x, OperationHook as y, ResolvePathParams as z };
|
|
1632
|
+
//# sourceMappingURL=PluginDriver-D110FoJ-.d.ts.map
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
2
|
+
import { C as Plugin, T as PluginFactoryOptions, t as PluginDriver } from "./PluginDriver-D110FoJ-.js";
|
|
3
3
|
import { FabricFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useDriver.d.ts
|