@kubb/core 5.0.0-beta.4 → 5.0.0-beta.41

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.
Files changed (57) hide show
  1. package/README.md +25 -158
  2. package/dist/diagnostics-Ba-FcsPo.d.ts +2970 -0
  3. package/dist/index.cjs +760 -1193
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +165 -171
  6. package/dist/index.js +745 -1188
  7. package/dist/index.js.map +1 -1
  8. package/dist/memoryStorage-DA1bnMte.js +2860 -0
  9. package/dist/memoryStorage-DA1bnMte.js.map +1 -0
  10. package/dist/memoryStorage-DZqlEW7H.cjs +2993 -0
  11. package/dist/memoryStorage-DZqlEW7H.cjs.map +1 -0
  12. package/dist/mocks.cjs +80 -18
  13. package/dist/mocks.cjs.map +1 -1
  14. package/dist/mocks.d.ts +35 -8
  15. package/dist/mocks.js +81 -21
  16. package/dist/mocks.js.map +1 -1
  17. package/package.json +8 -19
  18. package/src/FileManager.ts +85 -63
  19. package/src/FileProcessor.ts +171 -43
  20. package/src/HookRegistry.ts +45 -0
  21. package/src/KubbDriver.ts +906 -0
  22. package/src/Telemetry.ts +278 -0
  23. package/src/Transform.ts +58 -0
  24. package/src/constants.ts +111 -19
  25. package/src/createAdapter.ts +113 -17
  26. package/src/createKubb.ts +944 -492
  27. package/src/createRenderer.ts +58 -27
  28. package/src/createReporter.ts +147 -0
  29. package/src/createStorage.ts +36 -23
  30. package/src/defineGenerator.ts +129 -17
  31. package/src/defineLogger.ts +58 -5
  32. package/src/defineMiddleware.ts +19 -17
  33. package/src/defineParser.ts +30 -13
  34. package/src/definePlugin.ts +320 -17
  35. package/src/defineResolver.ts +381 -179
  36. package/src/diagnostics.ts +660 -0
  37. package/src/index.ts +8 -6
  38. package/src/mocks.ts +92 -19
  39. package/src/reporters/cliReporter.ts +90 -0
  40. package/src/reporters/fileReporter.ts +103 -0
  41. package/src/reporters/jsonReporter.ts +20 -0
  42. package/src/reporters/report.ts +85 -0
  43. package/src/storages/fsStorage.ts +13 -37
  44. package/src/types.ts +60 -1297
  45. package/dist/PluginDriver-Ds-Us-e4.cjs +0 -1036
  46. package/dist/PluginDriver-Ds-Us-e4.cjs.map +0 -1
  47. package/dist/PluginDriver-Wi34Pegx.js +0 -945
  48. package/dist/PluginDriver-Wi34Pegx.js.map +0 -1
  49. package/dist/types-Cd0jhNmx.d.ts +0 -2153
  50. package/src/Kubb.ts +0 -300
  51. package/src/PluginDriver.ts +0 -424
  52. package/src/devtools.ts +0 -59
  53. package/src/renderNode.ts +0 -35
  54. package/src/utils/diagnostics.ts +0 -18
  55. package/src/utils/isInputPath.ts +0 -10
  56. package/src/utils/packageJSON.ts +0 -99
  57. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/src/types.ts CHANGED
@@ -1,1301 +1,64 @@
1
- import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
2
- import type { FileNode, HttpMethod, ImportNode, InputNode, Node, SchemaNode, UserFileNode, Visitor } from '@kubb/ast'
3
- import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
4
- import type { RendererFactory } from './createRenderer.ts'
5
- import type { Storage } from './createStorage.ts'
6
- import type { Generator } from './defineGenerator.ts'
7
- import type { Middleware } from './defineMiddleware.ts'
8
- import type { Parser } from './defineParser.ts'
9
- import type { Plugin } from './definePlugin.ts'
10
- import type { KubbHooks } from './Kubb.ts'
11
- import type { PluginDriver } from './PluginDriver.ts'
12
-
1
+ export type { Adapter, AdapterFactoryOptions, AdapterSource } from './createAdapter.ts'
2
+ export type {
3
+ Diagnostic,
4
+ DiagnosticByCode,
5
+ DiagnosticDoc,
6
+ DiagnosticKind,
7
+ DiagnosticLocation,
8
+ DiagnosticSeverity,
9
+ PerformanceDiagnostic,
10
+ ProblemCode,
11
+ ProblemDiagnostic,
12
+ SerializedDiagnostic,
13
+ UpdateDiagnostic,
14
+ } from './diagnostics.ts'
15
+ export type {
16
+ BuildOutput,
17
+ CLIOptions,
18
+ Config,
19
+ InputData,
20
+ InputPath,
21
+ Kubb,
22
+ KubbBuildEndContext,
23
+ KubbBuildStartContext,
24
+ KubbConfigEndContext,
25
+ KubbDiagnosticContext,
26
+ KubbErrorContext,
27
+ KubbFileProcessingUpdate,
28
+ KubbFilesProcessingEndContext,
29
+ KubbFilesProcessingStartContext,
30
+ KubbFilesProcessingUpdateContext,
31
+ KubbGenerationEndContext,
32
+ KubbGenerationStartContext,
33
+ KubbHookEndContext,
34
+ KubbHookLineContext,
35
+ KubbHookStartContext,
36
+ KubbHooks,
37
+ KubbInfoContext,
38
+ KubbLifecycleStartContext,
39
+ KubbPluginsEndContext,
40
+ KubbSuccessContext,
41
+ KubbWarnContext,
42
+ PossibleConfig,
43
+ UserConfig,
44
+ } from './createKubb.ts'
45
+ export type { GenerationResult, Reporter, ReporterContext, ReporterName, UserReporter } from './createReporter.ts'
13
46
  export type { Renderer, RendererFactory } from './createRenderer.ts'
14
-
15
- /**
16
- * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
17
- * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
18
- * without requiring changes to core.
19
- *
20
- * @internal
21
- */
22
- type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}
23
-
24
- /**
25
- * Reference to an input file to generate code from.
26
- *
27
- * Specify an absolute path or a path relative to the config file location.
28
- * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
29
- */
30
- export type InputPath = {
31
- /**
32
- * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
33
- *
34
- * @example
35
- * ```ts
36
- * { path: './petstore.yaml' }
37
- * { path: '/absolute/path/to/openapi.json' }
38
- * ```
39
- */
40
- path: string
41
- }
42
-
43
- /**
44
- * Inline input data to generate code from.
45
- *
46
- * Useful when you want to pass the specification directly instead of from a file.
47
- * Can be a string (YAML/JSON) or a parsed object.
48
- */
49
- export type InputData = {
50
- /**
51
- * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
52
- *
53
- * @example
54
- * ```ts
55
- * { data: fs.readFileSync('./openapi.yaml', 'utf8') }
56
- * { data: { openapi: '3.1.0', info: { ... } } }
57
- * ```
58
- */
59
- data: string | unknown
60
- }
61
-
62
- type Input = InputPath | InputData
63
-
64
- /**
65
- * Source data passed to an adapter's `parse` function.
66
- * Mirrors the config input shape with paths resolved to absolute.
67
- */
68
- export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }
69
-
70
- /**
71
- * Generic type parameters for an adapter definition.
72
- *
73
- * - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
74
- * - `TOptions` — user-facing options passed to the adapter factory
75
- * - `TResolvedOptions` — options after defaults applied
76
- * - `TDocument` — type of the parsed source document
77
- */
78
- export type AdapterFactoryOptions<
79
- TName extends string = string,
80
- TOptions extends object = object,
81
- TResolvedOptions extends object = TOptions,
82
- TDocument = unknown,
83
- > = {
84
- name: TName
85
- options: TOptions
86
- resolvedOptions: TResolvedOptions
87
- document: TDocument
88
- }
89
-
90
- /**
91
- * Adapter that converts input files or data into an `InputNode`.
92
- *
93
- * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
94
- * universal intermediate representation that all plugins consume.
95
- *
96
- * @example
97
- * ```ts
98
- * import { adapterOas } from '@kubb/adapter-oas'
99
- *
100
- * export default defineConfig({
101
- * adapter: adapterOas(),
102
- * input: { path: './openapi.yaml' },
103
- * plugins: [pluginTs(), pluginZod()],
104
- * })
105
- * ```
106
- */
107
- export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
108
- /**
109
- * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
110
- */
111
- name: TOptions['name']
112
- /**
113
- * Resolved adapter options after defaults have been applied.
114
- */
115
- options: TOptions['resolvedOptions']
116
- /**
117
- * Parsed source document after the first `parse()` call. `null` before parsing.
118
- */
119
- document: TOptions['document'] | null
120
- inputNode: InputNode | null
121
- /**
122
- * Parse the source into a universal `InputNode`.
123
- */
124
- parse: (source: AdapterSource) => PossiblePromise<InputNode>
125
- /**
126
- * Extract `ImportNode` entries for a schema tree.
127
- * Returns an empty array before the first `parse()` call.
128
- *
129
- * The `resolve` callback receives the collision-corrected schema name and must
130
- * return `{ name, path }` for the import, or `undefined` to skip it.
131
- */
132
- getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
133
- }
134
-
135
- export type DevtoolsOptions = {
136
- /**
137
- * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
138
- * @default false
139
- */
140
- ast?: boolean
141
- }
142
-
143
- /**
144
- * Build configuration for Kubb code generation.
145
- *
146
- * The Config is the main entry point for customizing how Kubb generates code. It specifies:
147
- * - What to generate from (adapter + input)
148
- * - Where to output generated code (output)
149
- * - How to generate (plugins + middleware)
150
- * - Runtime details (parsers, storage, renderer)
151
- *
152
- * See `UserConfig` for a relaxed version with sensible defaults.
153
- *
154
- * @private
155
- */
156
- export type Config<TInput = Input> = {
157
- /**
158
- * Display name for this configuration in CLI output and logs.
159
- * Useful when running multiple builds with `defineConfig` arrays.
160
- *
161
- * @example
162
- * ```ts
163
- * name: 'api-client'
164
- * ```
165
- */
166
- name?: string
167
- /**
168
- * Project root directory, absolute or relative to the config file.
169
- * @default process.cwd()
170
- */
171
- root: string
172
- /**
173
- * Parsers that convert generated files to strings.
174
- * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
175
- * A fallback parser is appended for unhandled extensions.
176
- * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
177
- *
178
- * @default [parserTs] from `@kubb/parser-ts`
179
- * @example
180
- * ```ts
181
- * import { parserTs, tsxParser } from '@kubb/parser-ts'
182
- * export default defineConfig({
183
- * parsers: [parserTs, tsxParser],
184
- * })
185
- * ```
186
- */
187
- parsers: Array<Parser>
188
- /**
189
- * Adapter that parses input files into the universal `InputNode` representation.
190
- * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
191
- *
192
- * When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files
193
- * injected via `injectFile` are written, but no AST walk occurs and generator hooks
194
- * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.
195
- *
196
- * @example
197
- * ```ts
198
- * import { adapterOas } from '@kubb/adapter-oas'
199
- * export default defineConfig({
200
- * adapter: adapterOas(),
201
- * input: { path: './petstore.yaml' },
202
- * })
203
- * ```
204
- */
205
- adapter?: Adapter
206
- /**
207
- * Source file or data to generate code from.
208
- * Use `input.path` for a file path or `input.data` for inline data.
209
- * Required when an adapter is configured; omit when running in plugin-only mode.
210
- */
211
- input?: TInput
212
- output: {
213
- /**
214
- * Output directory for generated files, absolute or relative to `root`.
215
- *
216
- * All generated files will be written under this directory. Subdirectories can be created
217
- * by plugins based on grouping strategy (by tag, path, etc.).
218
- *
219
- * @example
220
- * ```ts
221
- * output: {
222
- * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
223
- * }
224
- * ```
225
- */
226
- path: string
227
- /**
228
- * Remove all files from the output directory before starting the build.
229
- *
230
- * Useful to ensure old generated files aren't mixed with new ones.
231
- * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
232
- *
233
- * @default false
234
- * @example
235
- * ```ts
236
- * clean: true // wipes ./src/gen/* before generating
237
- * ```
238
- */
239
- clean?: boolean
240
- /**
241
- * Persists generated files to the file system.
242
- *
243
- * @default true
244
- * @deprecated Use `storage` option to control where files are written instead.
245
- */
246
- write?: boolean
247
- /**
248
- * Auto-format generated files after code generation completes.
249
- *
250
- * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
251
- * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
252
- *
253
- * @default false
254
- * @example
255
- * ```ts
256
- * format: 'auto' // auto-detect prettier, biome, or oxfmt
257
- * format: 'prettier' // force prettier
258
- * format: false // skip formatting
259
- * ```
260
- */
261
- format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false
262
- /**
263
- * Auto-lint generated files after code generation completes.
264
- *
265
- * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
266
- * is available on your system. Pass `false` to skip linting.
267
- *
268
- * @default false
269
- * @example
270
- * ```ts
271
- * lint: 'auto' // auto-detect oxlint, biome, or eslint
272
- * lint: 'eslint' // force eslint
273
- * lint: false // skip linting
274
- * ```
275
- */
276
- lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false
277
- /**
278
- * Map file extensions to different output extensions.
279
- *
280
- * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
281
- * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
282
- *
283
- * @default { '.ts': '.ts' }
284
- * @example
285
- * ```ts
286
- * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
287
- * extension: { '.ts': '', '.tsx': '.jsx' }
288
- * ```
289
- */
290
- extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
291
- /**
292
- * Banner text prepended to every generated file.
293
- *
294
- * Useful for auto-generation notices or license headers. Choose a preset or write custom text.
295
- * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
296
- *
297
- * @default 'simple'
298
- * @example
299
- * ```ts
300
- * defaultBanner: 'simple' // "This file was autogenerated by Kubb"
301
- * defaultBanner: 'full' // adds source, title, description, API version
302
- * defaultBanner: false // no banner
303
- * ```
304
- */
305
- defaultBanner?: 'simple' | 'full' | false
306
- /**
307
- * When `true`, overwrites existing files. When `false`, skips generated files that already exist.
308
- *
309
- * Individual plugins can override this setting. This is useful for preventing accidental data loss
310
- * when re-generating while you have local edits in the output folder.
311
- *
312
- * @default false
313
- * @example
314
- * ```ts
315
- * override: true // regenerate everything, even existing files
316
- * override: false // skip files that already exist
317
- * ```
318
- */
319
- override?: boolean
320
- } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>
321
- /**
322
- * Storage backend that controls where and how generated files are persisted.
323
- *
324
- * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
325
- * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
326
- *
327
- * @default fsStorage()
328
- * @example
329
- * ```ts
330
- * import { memoryStorage } from '@kubb/core'
331
- *
332
- * // Keep generated files in memory (useful for testing, CI pipelines)
333
- * storage: memoryStorage()
334
- *
335
- * // Use custom S3 storage
336
- * storage: myS3Storage()
337
- * ```
338
- *
339
- * @see {@link Storage} interface for implementing custom backends.
340
- */
341
- storage?: Storage
342
- /**
343
- * Plugins that execute during the build to generate code and transform the AST.
344
- *
345
- * Each plugin processes the AST produced by the adapter and can emit files for different
346
- * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
347
- * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
348
- *
349
- * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
350
- *
351
- * @example
352
- * ```ts
353
- * import { pluginTs } from '@kubb/plugin-ts'
354
- * import { pluginZod } from '@kubb/plugin-zod'
355
- *
356
- * plugins: [
357
- * pluginTs({ output: { path: './src/gen' } }),
358
- * pluginZod({ output: { path: './src/gen' } }),
359
- * ]
360
- * ```
361
- */
362
- plugins: Array<Plugin>
363
- /**
364
- * Middleware instances that observe build events and post-process generated code.
365
- *
366
- * Middleware fires AFTER all plugins for each event. Perfect for tasks like:
367
- * - Auditing what was generated
368
- * - Adding barrel/index files
369
- * - Validating output
370
- * - Running custom transformations
371
- *
372
- * @example
373
- * ```ts
374
- * import { middlewareBarrel } from '@kubb/middleware-barrel'
375
- *
376
- * middleware: [middlewareBarrel()]
377
- * ```
378
- *
379
- * @see {@link defineMiddleware} to create custom middleware.
380
- */
381
- middleware?: Array<Middleware>
382
- /**
383
- * Default renderer factory used by all plugins and generators.
384
- * Resolution chain: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw FileNode[] mode).
385
- *
386
- * @example
387
- * ```ts
388
- * import { jsxRenderer } from '@kubb/renderer-jsx'
389
- * export default defineConfig({
390
- * renderer: jsxRenderer,
391
- * plugins: [pluginTs(), pluginZod()],
392
- * })
393
- * ```
394
- */
395
- /**
396
- * Renderer that converts generated AST nodes to code strings.
397
- *
398
- * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support
399
- * different output formats (template engines, code generation DSLs, etc.).
400
- *
401
- * @default rendererJsx() // from @kubb/renderer-jsx
402
- * @example
403
- * ```ts
404
- * import { rendererJsx } from '@kubb/renderer-jsx'
405
- * renderer: rendererJsx()
406
- * ```
407
- *
408
- * @see {@link Renderer} to implement a custom renderer.
409
- */
410
- renderer?: RendererFactory
411
- /**
412
- * Kubb Studio cloud integration settings.
413
- *
414
- * Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
415
- * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
416
- *
417
- * @default false // disabled by default
418
- * @example
419
- * ```ts
420
- * devtools: true // use default Kubb Studio
421
- * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
422
- * ```
423
- */
424
- devtools?:
425
- | true
426
- | {
427
- /**
428
- * Override the Kubb Studio base URL.
429
- * @default 'https://studio.kubb.dev'
430
- */
431
- studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})
432
- }
433
- /**
434
- * Lifecycle hooks that execute during or after the build process.
435
- *
436
- * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
437
- * Currently supports the `done` hook which fires after all plugins and middleware complete.
438
- *
439
- * @example
440
- * ```ts
441
- * hooks: {
442
- * done: 'prettier --write "./src/gen"', // auto-format generated files
443
- * // or multiple commands:
444
- * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
445
- * }
446
- * ```
447
- */
448
- hooks?: {
449
- /**
450
- * Command(s) to run after all plugins and middleware complete generation.
451
- *
452
- * Useful for post-processing: formatting, linting, copying files, or custom validation.
453
- * Pass a single command string or array of command strings to run sequentially.
454
- * Commands are executed relative to the `root` directory.
455
- *
456
- * @example
457
- * ```ts
458
- * done: 'prettier --write "./src/gen"'
459
- * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
460
- * ```
461
- */
462
- done?: string | Array<string>
463
- }
464
- }
465
-
466
- // plugin
467
-
468
- /**
469
- * Type/string pattern filter for include/exclude/override matching.
470
- */
471
- type PatternFilter = {
472
- type: string
473
- pattern: string | RegExp
474
- }
475
-
476
- /**
477
- * Pattern filter with partial option overrides applied when the pattern matches.
478
- */
479
- type PatternOverride<TOptions> = PatternFilter & {
480
- options: Omit<Partial<TOptions>, 'override'>
481
- }
482
-
483
- /**
484
- * Context for resolving filtered options for a given operation or schema node.
485
- *
486
- * @internal
487
- */
488
- export type ResolveOptionsContext<TOptions> = {
489
- options: TOptions
490
- exclude?: Array<PatternFilter>
491
- include?: Array<PatternFilter>
492
- override?: Array<PatternOverride<TOptions>>
493
- }
494
-
495
- /**
496
- * Base constraint for all plugin resolver objects.
497
- *
498
- * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
499
- * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
500
- *
501
- * @example
502
- * ```ts
503
- * type MyResolver = Resolver & {
504
- * resolveName(node: SchemaNode): string
505
- * resolveTypedName(node: SchemaNode): string
506
- * }
507
- * ```
508
- */
509
- export type Resolver = {
510
- name: string
511
- pluginName: Plugin['name']
512
- default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
513
- resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null
514
- resolvePath(params: ResolverPathParams, context: ResolverContext): string
515
- resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode
516
- resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined
517
- resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
518
- }
519
-
520
- export type PluginFactoryOptions<
521
- /**
522
- * Unique plugin name.
523
- */
524
- TName extends string = string,
525
- /**
526
- * User-facing plugin options.
527
- */
528
- TOptions extends object = object,
529
- /**
530
- * Plugin options after defaults are applied.
531
- */
532
- TResolvedOptions extends object = TOptions,
533
- /**
534
- * Resolver that encapsulates naming and path-resolution helpers.
535
- * Define with `defineResolver` and export alongside the plugin.
536
- */
537
- TResolver extends Resolver = Resolver,
538
- > = {
539
- name: TName
540
- options: TOptions
541
- resolvedOptions: TResolvedOptions
542
- resolver: TResolver
543
- }
544
-
545
- /**
546
- * Normalized plugin after setup, with runtime fields populated.
547
- * For internal use only — plugins use the public `Plugin` type externally.
548
- *
549
- * @internal
550
- */
551
- export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
552
- options: TOptions['resolvedOptions'] & {
553
- output: Output
554
- include?: Array<Include>
555
- exclude: Array<Exclude>
556
- override: Array<Override<TOptions['resolvedOptions']>>
557
- }
558
- resolver: TOptions['resolver']
559
- transformer?: Visitor
560
- renderer?: RendererFactory
561
- generators?: Array<Generator>
562
- apply?: (config: Config) => boolean
563
- version?: string
564
- }
565
-
566
- /**
567
- * Partial `Config` for user-facing entry points with sensible defaults.
568
- *
569
- * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
570
- * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
571
- * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.
572
- *
573
- * @example
574
- * ```ts
575
- * export default defineConfig({
576
- * input: { path: './petstore.yaml' },
577
- * output: { path: './src/gen' },
578
- * plugins: [pluginTs(), pluginZod()],
579
- * })
580
- * ```
581
- */
582
- export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
583
- /**
584
- * Project root directory, absolute or relative to the config file location.
585
- *
586
- * Used as the base path for `root`-relative paths (e.g., `output.path`, file paths in hooks).
587
- *
588
- * @default process.cwd()
589
- * @example
590
- * ```ts
591
- * root: '/home/user/my-project'
592
- * root: './my-project' // relative to config file
593
- * ```
594
- */
595
- root?: string
596
- /**
597
- * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
598
- *
599
- * Each parser handles a specific file type. By default, Kubb uses `parserTs` from `@kubb/parser-ts` for TypeScript files.
600
- * Pass custom parsers to support additional languages or custom formats.
601
- *
602
- * @default [parserTs] // from `@kubb/parser-ts`
603
- * @example
604
- * ```ts
605
- * import { parserTs } from '@kubb/parser-ts'
606
- * import { parserJsonSchema } from '@kubb/parser-json-schema'
607
- *
608
- * parsers: [parserTs(), parserJsonSchema()]
609
- * ```
610
- *
611
- * @see {@link Parser} to implement a custom parser.
612
- */
613
- parsers?: Array<Parser>
614
- /**
615
- * Adapter that parses your API specification (OpenAPI, GraphQL, AsyncAPI, etc.) into Kubb's universal AST.
616
- *
617
- * Pass an adapter to support different spec formats. When omitted, Kubb runs in plugin-only mode —
618
- * `kubb:plugin:setup` fires and `injectFile` works, but no AST walk occurs and generator hooks
619
- * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.
620
- *
621
- * @example
622
- * ```ts
623
- * import { adapterOas } from '@kubb/adapter-oas'
624
- *
625
- * adapter: adapterOas()
626
- * ```
627
- *
628
- * @see {@link Adapter} to implement a custom adapter for GraphQL or other formats.
629
- */
630
- adapter?: Adapter
631
- /**
632
- * Plugins that execute during the build to generate code and transform the AST.
633
- *
634
- * Each plugin processes the AST produced by the adapter and can emit files for different
635
- * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
636
- *
637
- * @default [] // no plugins (useful for setup/testing)
638
- * @example
639
- * ```ts
640
- * plugins: [
641
- * pluginTs({ output: { path: './src/gen' } }),
642
- * pluginZod({ output: { path: './src/gen' } }),
643
- * ]
644
- * ```
645
- *
646
- * @see {@link definePlugin} to create a custom plugin.
647
- */
648
- plugins?: Array<Plugin>
649
- }
650
-
651
- export type ResolveNameParams = {
652
- name: string
653
- pluginName?: string
654
- /**
655
- * Entity type being named.
656
- * - `'file'` — file name (camelCase)
657
- * - `'function'` — exported function name (camelCase)
658
- * - `'type'` — TypeScript type name (PascalCase)
659
- * - `'const'` — variable name (camelCase)
660
- */
661
- type?: 'file' | 'function' | 'type' | 'const'
662
- }
663
- /**
664
- * Context object passed to generator `schema`, `operation`, and `operations` methods.
665
- *
666
- * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
667
- * are needed. `ctx.options` carries resolved per-node options after exclude/include/override
668
- * filtering for individual schema/operation calls, or plugin-level options for operations.
669
- */
670
- export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
671
- config: Config
672
- /**
673
- * Absolute path to the current plugin's output directory.
674
- */
675
- root: string
676
- /**
677
- * Determine output mode based on the output config.
678
- * Returns `'single'` when `output.path` is a file, `'split'` for a directory.
679
- */
680
- getMode: (output: { path: string }) => 'single' | 'split'
681
- driver: PluginDriver
682
- /**
683
- * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
684
- */
685
- getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
686
- getPlugin(name: string): Plugin | undefined
687
- /**
688
- * Get a plugin by name, throws an error if not found.
689
- */
690
- requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
691
- requirePlugin(name: string): Plugin
692
- /**
693
- * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
694
- */
695
- getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']
696
- getResolver(name: string): Resolver
697
- /**
698
- * Add files only if they don't exist.
699
- */
700
- addFile: (...file: Array<FileNode>) => Promise<void>
701
- /**
702
- * Merge sources into the same output file.
703
- */
704
- upsertFile: (...file: Array<FileNode>) => Promise<void>
705
- hooks: AsyncEventEmitter<KubbHooks>
706
- /**
707
- * The current plugin instance.
708
- */
709
- plugin: Plugin<TOptions>
710
- /**
711
- * The current plugin's resolver.
712
- */
713
- resolver: TOptions['resolver']
714
- /**
715
- * The current plugin's transformer.
716
- */
717
- transformer: Visitor | undefined
718
- /**
719
- * Emit a warning.
720
- */
721
- warn: (message: string) => void
722
- /**
723
- * Emit an error.
724
- */
725
- error: (error: string | Error) => void
726
- /**
727
- * Emit an info message.
728
- */
729
- info: (message: string) => void
730
- /**
731
- * Open the current input node in Kubb Studio.
732
- */
733
- openInStudio: (options?: DevtoolsOptions) => Promise<void>
734
- /**
735
- * The configured adapter instance.
736
- */
737
- adapter: Adapter
738
- /**
739
- * The universal `InputNode` produced by the adapter.
740
- */
741
- inputNode: InputNode
742
- /**
743
- * Resolved options after exclude/include/override filtering.
744
- */
745
- options: TOptions['resolvedOptions']
746
- }
747
- /**
748
- * Output configuration for generated files.
749
- */
750
- export type Output<_TOptions = unknown> = {
751
- /**
752
- * Output folder or file path for generated code.
753
- */
754
- path: string
755
- /**
756
- * Text or function prepended to every generated file.
757
- * When a function, receives the current `InputNode` and returns a string.
758
- */
759
- banner?: string | ((node?: InputNode) => string)
760
- /**
761
- * Text or function appended to every generated file.
762
- * When a function, receives the current `InputNode` and returns a string.
763
- */
764
- footer?: string | ((node?: InputNode) => string)
765
- /**
766
- * Whether to override existing external files if they already exist.
767
- * @default false
768
- */
769
- override?: boolean
770
- } & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>
771
-
772
- export type Group = {
773
- /**
774
- * How to group files into subdirectories.
775
- * - `'tag'` — group by OpenAPI tags
776
- * - `'path'` — group by OpenAPI paths
777
- */
778
- type: 'tag' | 'path'
779
- /**
780
- * Function that returns the subdirectory name for a group value.
781
- * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
782
- */
783
- name?: (context: { group: string }) => string
784
- }
785
-
786
- export type LoggerOptions = {
787
- /**
788
- * Log level for output verbosity.
789
- * @default 3
790
- */
791
- logLevel: (typeof logLevel)[keyof typeof logLevel]
792
- }
793
-
794
- /**
795
- * Shared context passed to plugins, parsers, and other internals.
796
- */
797
- export type LoggerContext = AsyncEventEmitter<KubbHooks>
798
-
799
- export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
800
- name: string
801
- install: (context: LoggerContext, options?: TOptions) => void | Promise<void>
802
- }
803
-
804
- export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>
805
-
806
47
  export type { Storage } from './createStorage.ts'
807
- export type { Generator } from './defineGenerator.ts'
48
+ export type { FileProcessorHooks, ParsedFile } from './FileProcessor.ts'
49
+ export type { Generator, GeneratorContext } from './defineGenerator.ts'
50
+ export type { Logger, LoggerContext, LoggerOptions, UserLogger } from './defineLogger.ts'
808
51
  export type { Middleware } from './defineMiddleware.ts'
809
- export type { Plugin } from './definePlugin.ts'
810
- export type { Kubb, KubbHooks } from './Kubb.ts'
811
-
812
- /**
813
- * Context for hook-style plugin `kubb:plugin:setup` handler.
814
- * Provides methods to register generators, configure resolvers, transformers, and renderers.
815
- */
816
- export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
817
- /**
818
- * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
819
- * just like generators declared statically on `createPlugin`.
820
- */
821
- addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
822
- /**
823
- * Set or override the resolver for this plugin.
824
- * The resolver controls file naming and path resolution.
825
- */
826
- setResolver(resolver: Partial<TFactory['resolver']>): void
827
- /**
828
- * Set the AST transformer to pre-process nodes before they reach generators.
829
- */
830
- setTransformer(visitor: Visitor): void
831
- /**
832
- * Set the renderer factory to process JSX elements from generators.
833
- */
834
- setRenderer(renderer: RendererFactory): void
835
- /**
836
- * Set resolved options merged into the normalized plugin's `options`.
837
- * Call this in `kubb:plugin:setup` to provide options generators need.
838
- */
839
- setOptions(options: TFactory['resolvedOptions']): void
840
- /**
841
- * Inject a raw file into the build output, bypassing the generation pipeline.
842
- */
843
- injectFile(userFileNode: UserFileNode): void
844
- /**
845
- * Merge a partial config update into the current build configuration.
846
- */
847
- updateConfig(config: Partial<Config>): void
848
- /**
849
- * The resolved build configuration at setup time.
850
- */
851
- config: Config
852
- /**
853
- * The plugin's user-provided options.
854
- */
855
- options: TFactory['options']
856
- }
857
-
858
- /**
859
- * Context for hook-style plugin `kubb:build:start` handler.
860
- * Fires immediately before the plugin execution loop begins.
861
- */
862
- export type KubbBuildStartContext = {
863
- config: Config
864
- adapter: Adapter
865
- inputNode: InputNode
866
- /**
867
- * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
868
- */
869
- getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
870
- getPlugin(name: string): Plugin | undefined
871
- /**
872
- * Get all files currently in the file manager.
873
- * Call this lazily (e.g. in `kubb:plugin:end`) to see files added by prior plugins.
874
- */
875
- readonly files: ReadonlyArray<FileNode>
876
- /**
877
- * Upsert one or more files into the file manager.
878
- * Files with the same path are merged; new files are appended.
879
- * Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
880
- */
881
- upsertFile: (...files: Array<FileNode>) => void
882
- }
883
-
884
- /**
885
- * Context for `kubb:plugins:end` handlers.
886
- * Fires after plugins run and per-plugin barrels are written, before final write to disk.
887
- * Middleware that needs final files (e.g. root barrel) use this event.
888
- */
889
- export type KubbPluginsEndContext = {
890
- config: Config
891
- /**
892
- * All files currently in the file manager (lazy snapshot).
893
- */
894
- readonly files: ReadonlyArray<FileNode>
895
- /**
896
- * Upsert files into the file manager.
897
- * Files added here are included in the write pass.
898
- */
899
- upsertFile: (...files: Array<FileNode>) => void
900
- }
901
-
902
- /**
903
- * Context for hook-style plugin `kubb:build:end` handler.
904
- * Fires after all files have been written to disk.
905
- */
906
- export type KubbBuildEndContext = {
907
- files: Array<FileNode>
908
- config: Config
909
- outputDir: string
910
- }
911
-
912
- export type KubbLifecycleStartContext = {
913
- version: string
914
- }
915
-
916
- export type KubbConfigEndContext = {
917
- configs: Array<Config>
918
- }
919
-
920
- export type KubbGenerationStartContext = {
921
- config: Config
922
- }
923
-
924
- export type KubbGenerationEndContext = {
925
- config: Config
926
- files: Array<FileNode>
927
- sources: Map<string, string>
928
- }
929
-
930
- export type KubbGenerationSummaryContext = {
931
- config: Config
932
- failedPlugins: Set<{ plugin: Plugin; error: Error }>
933
- status: 'success' | 'failed'
934
- hrStart: [number, number]
935
- filesCreated: number
936
- pluginTimings?: Map<Plugin['name'], number>
937
- }
938
-
939
- export type KubbVersionNewContext = {
940
- currentVersion: string
941
- latestVersion: string
942
- }
943
-
944
- export type KubbInfoContext = {
945
- message: string
946
- info?: string
947
- }
948
-
949
- export type KubbErrorContext = {
950
- error: Error
951
- meta?: Record<string, unknown>
952
- }
953
-
954
- export type KubbSuccessContext = {
955
- message: string
956
- info?: string
957
- }
958
-
959
- export type KubbWarnContext = {
960
- message: string
961
- info?: string
962
- }
963
-
964
- export type KubbDebugContext = {
965
- date: Date
966
- logs: Array<string>
967
- fileName?: string
968
- }
969
-
970
- export type KubbFilesProcessingStartContext = {
971
- files: Array<FileNode>
972
- }
973
-
974
- export type KubbFileProcessingUpdateContext = {
975
- /**
976
- * Number of files processed.
977
- */
978
- processed: number
979
- /**
980
- * Total files to process.
981
- */
982
- total: number
983
- /**
984
- * Processing percentage (0–100).
985
- */
986
- percentage: number
987
- /**
988
- * Optional source identifier.
989
- */
990
- source?: string
991
- /**
992
- * The file being processed.
993
- */
994
- file: FileNode
995
- /**
996
- * The current build configuration.
997
- */
998
- config: Config
999
- }
1000
-
1001
- export type KubbFilesProcessingEndContext = {
1002
- files: Array<FileNode>
1003
- }
1004
-
1005
- export type KubbPluginStartContext = {
1006
- plugin: NormalizedPlugin
1007
- }
1008
-
1009
- export type KubbPluginEndContext = {
1010
- plugin: NormalizedPlugin
1011
- duration: number
1012
- success: boolean
1013
- error?: Error
1014
- config: Config
1015
- /**
1016
- * Returns all files currently in the file manager (lazy snapshot).
1017
- * Includes files added by plugins that have already run.
1018
- */
1019
- readonly files: ReadonlyArray<FileNode>
1020
- /**
1021
- * Upsert one or more files into the file manager.
1022
- */
1023
- upsertFile: (...files: Array<FileNode>) => void
1024
- }
1025
-
1026
- export type KubbHookStartContext = {
1027
- id?: string
1028
- command: string
1029
- args?: readonly string[]
1030
- }
1031
-
1032
- export type KubbHookEndContext = {
1033
- id?: string
1034
- command: string
1035
- args?: readonly string[]
1036
- success: boolean
1037
- error: Error | null
1038
- }
1039
-
1040
- type ByTag = {
1041
- /**
1042
- * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
1043
- */
1044
- type: 'tag'
1045
- /**
1046
- * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
1047
- */
1048
- pattern: string | RegExp
1049
- }
1050
-
1051
- type ByOperationId = {
1052
- /**
1053
- * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
1054
- */
1055
- type: 'operationId'
1056
- /**
1057
- * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
1058
- */
1059
- pattern: string | RegExp
1060
- }
1061
-
1062
- type ByPath = {
1063
- /**
1064
- * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
1065
- */
1066
- type: 'path'
1067
- /**
1068
- * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
1069
- */
1070
- pattern: string | RegExp
1071
- }
1072
-
1073
- type ByMethod = {
1074
- /**
1075
- * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
1076
- */
1077
- type: 'method'
1078
- /**
1079
- * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
1080
- */
1081
- pattern: HttpMethod | RegExp
1082
- }
1083
- // TODO implement as alternative for ByMethod
1084
- // type ByMethods = {
1085
- // type: 'methods'
1086
- // pattern: Array<HttpMethod>
1087
- // }
1088
-
1089
- type BySchemaName = {
1090
- /**
1091
- * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
1092
- */
1093
- type: 'schemaName'
1094
- /**
1095
- * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
1096
- */
1097
- pattern: string | RegExp
1098
- }
1099
-
1100
- type ByContentType = {
1101
- /**
1102
- * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
1103
- */
1104
- type: 'contentType'
1105
- /**
1106
- * Content type to match (case-sensitive). Can be a literal string or regex pattern.
1107
- */
1108
- pattern: string | RegExp
1109
- }
1110
-
1111
- /**
1112
- * A pattern filter that prevents matching nodes from being generated.
1113
- *
1114
- * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
1115
- * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1116
- *
1117
- * @example
1118
- * ```ts
1119
- * exclude: [
1120
- * { type: 'tag', pattern: 'internal' }, // skip "internal" tag
1121
- * { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
1122
- * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
1123
- * ]
1124
- * ```
1125
- */
1126
- export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
1127
-
1128
- /**
1129
- * A pattern filter that restricts generation to only matching nodes.
1130
- *
1131
- * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
1132
- * tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1133
- *
1134
- * @example
1135
- * ```ts
1136
- * include: [
1137
- * { type: 'tag', pattern: 'public' }, // generate only "public" tag
1138
- * { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
1139
- * ]
1140
- * ```
1141
- */
1142
- export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
1143
-
1144
- /**
1145
- * A pattern filter paired with partial option overrides applied when the pattern matches.
1146
- *
1147
- * Use to customize generation for specific operations or schemas. For example, apply different output paths
1148
- * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
1149
- * HTTP method, schema name, or content type.
1150
- *
1151
- * @example
1152
- * ```ts
1153
- * override: [
1154
- * {
1155
- * type: 'tag',
1156
- * pattern: 'admin',
1157
- * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
1158
- * },
1159
- * {
1160
- * type: 'operationId',
1161
- * pattern: 'listPets',
1162
- * options: { exclude: true } // skip this specific operation
1163
- * }
1164
- * ]
1165
- * ```
1166
- */
1167
- export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1168
- //TODO should be options: Omit<Partial<TOptions>, 'override'>
1169
- options: Partial<TOptions>
1170
- }
1171
-
1172
- /**
1173
- * File-specific parameters for `Resolver.resolvePath`.
1174
- *
1175
- * Pass alongside a `ResolverContext` to identify which file to resolve.
1176
- * Provide `tag` for tag-based grouping or `path` for path-based grouping.
1177
- *
1178
- * @example
1179
- * ```ts
1180
- * resolver.resolvePath(
1181
- * { baseName: 'petTypes.ts', tag: 'pets' },
1182
- * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1183
- * )
1184
- * // → '/src/types/petsController/petTypes.ts'
1185
- * ```
1186
- */
1187
- export type ResolverPathParams = {
1188
- baseName: FileNode['baseName']
1189
- pathMode?: 'single' | 'split'
1190
- /**
1191
- * Tag value used when `group.type === 'tag'`.
1192
- */
1193
- tag?: string
1194
- /**
1195
- * Path value used when `group.type === 'path'`.
1196
- */
1197
- path?: string
1198
- }
1199
-
1200
- /**
1201
- * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
1202
- *
1203
- * Describes where on disk output is rooted, which output config is active, and the optional
1204
- * grouping strategy that controls subdirectory layout.
1205
- *
1206
- * @example
1207
- * ```ts
1208
- * const context: ResolverContext = {
1209
- * root: config.root,
1210
- * output,
1211
- * group,
1212
- * }
1213
- * ```
1214
- */
1215
- export type ResolverContext = {
1216
- root: string
1217
- output: Output
1218
- group?: Group
1219
- /**
1220
- * Plugin name used to populate `meta.pluginName` on the resolved file.
1221
- */
1222
- pluginName?: string
1223
- }
1224
-
1225
- /**
1226
- * File-specific parameters for `Resolver.resolveFile`.
1227
- *
1228
- * Pass alongside a `ResolverContext` to fully describe the file to resolve.
1229
- * `tag` and `path` are used only when a matching `group` is present in the context.
1230
- *
1231
- * @example
1232
- * ```ts
1233
- * resolver.resolveFile(
1234
- * { name: 'listPets', extname: '.ts', tag: 'pets' },
1235
- * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1236
- * )
1237
- * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
1238
- * ```
1239
- */
1240
- export type ResolverFileParams = {
1241
- name: string
1242
- extname: FileNode['extname']
1243
- /**
1244
- * Tag value used when `group.type === 'tag'`.
1245
- */
1246
- tag?: string
1247
- /**
1248
- * Path value used when `group.type === 'path'`.
1249
- */
1250
- path?: string
1251
- }
1252
-
1253
- /**
1254
- * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
1255
- *
1256
- * `output` is optional — not every plugin configures a banner/footer.
1257
- * `config` carries the global Kubb config, used to derive the default Kubb banner.
1258
- *
1259
- * @example
1260
- * ```ts
1261
- * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
1262
- * // → '// generated'
1263
- * ```
1264
- */
1265
- export type ResolveBannerContext = {
1266
- output?: Pick<Output, 'banner' | 'footer'>
1267
- config: Config
1268
- }
1269
-
1270
- /**
1271
- * CLI options derived from command-line flags.
1272
- */
1273
- export type CLIOptions = {
1274
- /**
1275
- * Path to `kubb.config.js`.
1276
- */
1277
- config?: string
1278
- /**
1279
- * Enable watch mode for input files.
1280
- */
1281
- watch?: boolean
1282
- /**
1283
- * Logging verbosity for CLI usage.
1284
- * @default 'silent'
1285
- */
1286
- logLevel?: 'silent' | 'info' | 'debug'
1287
- }
1288
-
1289
- /**
1290
- * All accepted forms of a Kubb configuration.
1291
- *
1292
- * Config is always `@kubb/core` {@link Config}.
1293
- * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1294
- * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1295
- */
1296
- export type PossibleConfig<TCliOptions = undefined> =
1297
- | PossiblePromise<Config | Config[]>
1298
- | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
1299
-
1300
- export type { BuildOutput } from './createKubb.ts'
1301
52
  export type { Parser } from './defineParser.ts'
53
+ export type { Exclude, Group, Include, Output, Override } from './definePlugin.ts'
54
+ export type { KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NormalizedPlugin, Plugin, PluginFactoryOptions } from './definePlugin.ts'
55
+ export type {
56
+ BannerMeta,
57
+ ResolveBannerContext,
58
+ ResolveBannerFile,
59
+ ResolveOptionsContext,
60
+ Resolver,
61
+ ResolverContext,
62
+ ResolverFileParams,
63
+ ResolverPathParams,
64
+ } from './defineResolver.ts'