@kubb/core 5.0.0-alpha.34 → 5.0.0-alpha.36
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-B_65W4fv.js +1677 -0
- package/dist/PluginDriver-B_65W4fv.js.map +1 -0
- package/dist/{PluginDriver-BBi_41VF.d.ts → PluginDriver-C9iBgYbk.d.ts} +743 -376
- package/dist/PluginDriver-CCdkwR14.cjs +1806 -0
- package/dist/PluginDriver-CCdkwR14.cjs.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +272 -1666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -141
- package/dist/index.js +231 -1623
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +165 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +11 -5
- package/src/FileManager.ts +1 -1
- package/src/FileProcessor.ts +1 -1
- package/src/Kubb.ts +145 -38
- package/src/PluginDriver.ts +318 -40
- package/src/constants.ts +1 -1
- package/src/{build.ts → createKubb.ts} +180 -122
- package/src/createPlugin.ts +1 -0
- package/src/createRenderer.ts +57 -0
- package/src/defineGenerator.ts +57 -84
- package/src/defineLogger.ts +2 -2
- package/src/defineParser.ts +3 -2
- package/src/definePlugin.ts +95 -0
- package/src/defineResolver.ts +1 -1
- package/src/devtools.ts +1 -1
- package/src/index.ts +7 -6
- package/src/mocks.ts +234 -0
- package/src/renderNode.ts +35 -0
- package/src/types.ts +275 -210
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/getBarrelFiles.ts +3 -3
- package/src/utils/getFunctionParams.ts +14 -7
- package/src/utils/isInputPath.ts +2 -2
- package/src/utils/packageJSON.ts +2 -3
- package/src/defineConfig.ts +0 -51
- package/src/definePresets.ts +0 -16
- package/src/renderNode.tsx +0 -28
- package/src/utils/getConfigs.ts +0 -16
- package/src/utils/getPreset.ts +0 -78
package/src/Kubb.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AsyncEventEmitter } from '@internals/utils'
|
|
2
|
+
import type { FileNode, OperationNode, SchemaNode } from '@kubb/ast'
|
|
3
|
+
import type { BuildOutput } from './createKubb.ts'
|
|
4
|
+
import type { PluginDriver, Strategy } from './PluginDriver.ts'
|
|
5
|
+
import type { Config, GeneratorContext, KubbBuildEndContext, KubbBuildStartContext, KubbPluginSetupContext, Plugin, PluginLifecycleHooks } from './types'
|
|
4
6
|
|
|
5
7
|
type DebugInfo = {
|
|
6
8
|
date: Date
|
|
@@ -30,6 +32,47 @@ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
30
32
|
output?: unknown
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The instance returned by {@link createKubb}.
|
|
37
|
+
*/
|
|
38
|
+
export type Kubb = {
|
|
39
|
+
/**
|
|
40
|
+
* The shared event emitter. Attach listeners here before calling `setup()` or `build()`.
|
|
41
|
+
*/
|
|
42
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>
|
|
43
|
+
/**
|
|
44
|
+
* Raw generated source, keyed by absolute file path.
|
|
45
|
+
* Populated after a successful `build()` or `safeBuild()` call.
|
|
46
|
+
*/
|
|
47
|
+
readonly sources: Map<string, string>
|
|
48
|
+
/**
|
|
49
|
+
* The plugin driver. Available after `setup()` has been called.
|
|
50
|
+
*/
|
|
51
|
+
readonly driver: PluginDriver | undefined
|
|
52
|
+
/**
|
|
53
|
+
* The resolved config with applied defaults. Available after `setup()` has been called.
|
|
54
|
+
*/
|
|
55
|
+
readonly config: Config | undefined
|
|
56
|
+
/**
|
|
57
|
+
* Initializes all Kubb infrastructure: validates input, applies config defaults,
|
|
58
|
+
* runs the adapter, and creates the PluginDriver.
|
|
59
|
+
*
|
|
60
|
+
* Calling `build()` or `safeBuild()` without calling `setup()` first will
|
|
61
|
+
* automatically invoke `setup()` before proceeding.
|
|
62
|
+
*/
|
|
63
|
+
setup(): Promise<void>
|
|
64
|
+
/**
|
|
65
|
+
* Runs a full Kubb build and throws on any error or plugin failure.
|
|
66
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
67
|
+
*/
|
|
68
|
+
build(): Promise<BuildOutput>
|
|
69
|
+
/**
|
|
70
|
+
* Runs a full Kubb build and captures errors instead of throwing.
|
|
71
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
72
|
+
*/
|
|
73
|
+
safeBuild(): Promise<BuildOutput>
|
|
74
|
+
}
|
|
75
|
+
|
|
33
76
|
/**
|
|
34
77
|
* Events emitted during the Kubb code generation lifecycle.
|
|
35
78
|
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
@@ -37,51 +80,51 @@ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
37
80
|
* @example
|
|
38
81
|
* ```typescript
|
|
39
82
|
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
40
|
-
* import type {
|
|
83
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
41
84
|
*
|
|
42
|
-
* const
|
|
85
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
43
86
|
*
|
|
44
|
-
*
|
|
87
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
45
88
|
* console.log('Starting Kubb generation')
|
|
46
89
|
* })
|
|
47
90
|
*
|
|
48
|
-
*
|
|
91
|
+
* hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
49
92
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
50
93
|
* })
|
|
51
94
|
* ```
|
|
52
95
|
*/
|
|
53
|
-
export interface
|
|
96
|
+
export interface KubbHooks {
|
|
54
97
|
/**
|
|
55
98
|
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
56
99
|
*/
|
|
57
|
-
'lifecycle:start': [version: string]
|
|
100
|
+
'kubb:lifecycle:start': [version: string]
|
|
58
101
|
/**
|
|
59
102
|
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
60
103
|
*/
|
|
61
|
-
'lifecycle:end': []
|
|
104
|
+
'kubb:lifecycle:end': []
|
|
62
105
|
|
|
63
106
|
/**
|
|
64
107
|
* Emitted when configuration loading starts.
|
|
65
108
|
*/
|
|
66
|
-
'config:start': []
|
|
109
|
+
'kubb:config:start': []
|
|
67
110
|
/**
|
|
68
111
|
* Emitted when configuration loading is complete.
|
|
69
112
|
*/
|
|
70
|
-
'config:end': [configs: Array<Config>]
|
|
113
|
+
'kubb:config:end': [configs: Array<Config>]
|
|
71
114
|
|
|
72
115
|
/**
|
|
73
116
|
* Emitted when code generation phase starts.
|
|
74
117
|
*/
|
|
75
|
-
'generation:start': [config: Config]
|
|
118
|
+
'kubb:generation:start': [config: Config]
|
|
76
119
|
/**
|
|
77
120
|
* Emitted when code generation phase completes.
|
|
78
121
|
*/
|
|
79
|
-
'generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>]
|
|
122
|
+
'kubb:generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>]
|
|
80
123
|
/**
|
|
81
124
|
* Emitted with a summary of the generation results.
|
|
82
125
|
* Contains summary lines, title, and success status.
|
|
83
126
|
*/
|
|
84
|
-
'generation:summary': [
|
|
127
|
+
'kubb:generation:summary': [
|
|
85
128
|
config: Config,
|
|
86
129
|
{
|
|
87
130
|
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
@@ -95,77 +138,77 @@ export interface KubbEvents {
|
|
|
95
138
|
/**
|
|
96
139
|
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
97
140
|
*/
|
|
98
|
-
'format:start': []
|
|
141
|
+
'kubb:format:start': []
|
|
99
142
|
/**
|
|
100
143
|
* Emitted when code formatting completes.
|
|
101
144
|
*/
|
|
102
|
-
'format:end': []
|
|
145
|
+
'kubb:format:end': []
|
|
103
146
|
|
|
104
147
|
/**
|
|
105
148
|
* Emitted when linting starts.
|
|
106
149
|
*/
|
|
107
|
-
'lint:start': []
|
|
150
|
+
'kubb:lint:start': []
|
|
108
151
|
/**
|
|
109
152
|
* Emitted when linting completes.
|
|
110
153
|
*/
|
|
111
|
-
'lint:end': []
|
|
154
|
+
'kubb:lint:end': []
|
|
112
155
|
|
|
113
156
|
/**
|
|
114
157
|
* Emitted when plugin hooks execution starts.
|
|
115
158
|
*/
|
|
116
|
-
'hooks:start': []
|
|
159
|
+
'kubb:hooks:start': []
|
|
117
160
|
/**
|
|
118
161
|
* Emitted when plugin hooks execution completes.
|
|
119
162
|
*/
|
|
120
|
-
'hooks:end': []
|
|
163
|
+
'kubb:hooks:end': []
|
|
121
164
|
|
|
122
165
|
/**
|
|
123
166
|
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
124
167
|
* The callback should be invoked when the command completes.
|
|
125
168
|
*/
|
|
126
|
-
'hook:start': [{ id?: string; command: string; args?: readonly string[] }]
|
|
169
|
+
'kubb:hook:start': [{ id?: string; command: string; args?: readonly string[] }]
|
|
127
170
|
/**
|
|
128
171
|
* Emitted when a single hook execution completes.
|
|
129
172
|
*/
|
|
130
|
-
'hook:end': [{ id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }]
|
|
173
|
+
'kubb:hook:end': [{ id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }]
|
|
131
174
|
|
|
132
175
|
/**
|
|
133
176
|
* Emitted when a new version of Kubb is available.
|
|
134
177
|
*/
|
|
135
|
-
'version:new': [currentVersion: string, latestVersion: string]
|
|
178
|
+
'kubb:version:new': [currentVersion: string, latestVersion: string]
|
|
136
179
|
|
|
137
180
|
/**
|
|
138
181
|
* Informational message event.
|
|
139
182
|
*/
|
|
140
|
-
info: [message: string, info?: string]
|
|
183
|
+
'kubb:info': [message: string, info?: string]
|
|
141
184
|
/**
|
|
142
185
|
* Error event. Emitted when an error occurs during code generation.
|
|
143
186
|
*/
|
|
144
|
-
error: [error: Error, meta?: Record<string, unknown>]
|
|
187
|
+
'kubb:error': [error: Error, meta?: Record<string, unknown>]
|
|
145
188
|
/**
|
|
146
189
|
* Success message event.
|
|
147
190
|
*/
|
|
148
|
-
success: [message: string, info?: string]
|
|
191
|
+
'kubb:success': [message: string, info?: string]
|
|
149
192
|
/**
|
|
150
193
|
* Warning message event.
|
|
151
194
|
*/
|
|
152
|
-
warn: [message: string, info?: string]
|
|
195
|
+
'kubb:warn': [message: string, info?: string]
|
|
153
196
|
/**
|
|
154
197
|
* Debug event for detailed logging.
|
|
155
198
|
* Contains timestamp, log messages, and optional filename.
|
|
156
199
|
*/
|
|
157
|
-
debug: [info: DebugInfo]
|
|
200
|
+
'kubb:debug': [info: DebugInfo]
|
|
158
201
|
|
|
159
202
|
/**
|
|
160
203
|
* Emitted when file processing starts.
|
|
161
204
|
* Contains the list of files to be processed.
|
|
162
205
|
*/
|
|
163
|
-
'files:processing:start': [files: Array<FileNode>]
|
|
206
|
+
'kubb:files:processing:start': [files: Array<FileNode>]
|
|
164
207
|
/**
|
|
165
208
|
* Emitted for each file being processed, providing progress updates.
|
|
166
209
|
* Contains processed count, total count, percentage, and file details.
|
|
167
210
|
*/
|
|
168
|
-
'file:processing:update': [
|
|
211
|
+
'kubb:file:processing:update': [
|
|
169
212
|
{
|
|
170
213
|
/**
|
|
171
214
|
* Number of files processed so far.
|
|
@@ -198,37 +241,101 @@ export interface KubbEvents {
|
|
|
198
241
|
* Emitted when file processing completes.
|
|
199
242
|
* Contains the list of processed files.
|
|
200
243
|
*/
|
|
201
|
-
'files:processing:end': [files: Array<FileNode>]
|
|
244
|
+
'kubb:files:processing:end': [files: Array<FileNode>]
|
|
202
245
|
|
|
203
246
|
/**
|
|
204
247
|
* Emitted when a plugin starts executing.
|
|
205
248
|
*/
|
|
206
|
-
'plugin:start': [plugin: Plugin]
|
|
249
|
+
'kubb:plugin:start': [plugin: Plugin]
|
|
207
250
|
/**
|
|
208
251
|
* Emitted when a plugin completes execution.
|
|
209
252
|
* Duration in ms.
|
|
210
253
|
*/
|
|
211
|
-
'plugin:end': [plugin: Plugin, result: { duration: number; success: boolean; error?: Error }]
|
|
254
|
+
'kubb:plugin:end': [plugin: Plugin, result: { duration: number; success: boolean; error?: Error }]
|
|
212
255
|
|
|
213
256
|
/**
|
|
214
257
|
* Emitted when plugin hook progress tracking starts.
|
|
215
258
|
* Contains the hook name and list of plugins to execute.
|
|
216
259
|
*/
|
|
217
|
-
'plugins:hook:progress:start': [progress: HookProgress]
|
|
260
|
+
'kubb:plugins:hook:progress:start': [progress: HookProgress]
|
|
218
261
|
/**
|
|
219
262
|
* Emitted when plugin hook progress tracking ends.
|
|
220
263
|
* Contains the hook name that completed.
|
|
221
264
|
*/
|
|
222
|
-
'plugins:hook:progress:end': [{ hookName: PluginLifecycleHooks }]
|
|
265
|
+
'kubb:plugins:hook:progress:end': [{ hookName: PluginLifecycleHooks }]
|
|
223
266
|
|
|
224
267
|
/**
|
|
225
268
|
* Emitted when a plugin hook starts processing.
|
|
226
269
|
* Contains strategy, hook name, plugin, parameters, and output.
|
|
227
270
|
*/
|
|
228
|
-
'plugins:hook:processing:start': [execution: HookExecution]
|
|
271
|
+
'kubb:plugins:hook:processing:start': [execution: HookExecution]
|
|
229
272
|
/**
|
|
230
273
|
* Emitted when a plugin hook completes processing.
|
|
231
274
|
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
232
275
|
*/
|
|
233
|
-
'plugins:hook:processing:end': [result: HookResult]
|
|
276
|
+
'kubb:plugins:hook:processing:end': [result: HookResult]
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Fired once — before any plugin's `buildStart` runs — so that hook-style plugins
|
|
280
|
+
* can register generators, configure resolvers/transformers/renderers, or inject
|
|
281
|
+
* extra files. All `kubb:plugin:setup` handlers registered via `definePlugin` receive
|
|
282
|
+
* a plugin-specific context (with the correct `addGenerator` closure).
|
|
283
|
+
* External tooling can observe this event via `hooks.on('kubb:plugin:setup', …)`.
|
|
284
|
+
*/
|
|
285
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext]
|
|
286
|
+
/**
|
|
287
|
+
* Fired immediately before the plugin execution loop begins.
|
|
288
|
+
* The adapter has already parsed the source and `inputNode` is available.
|
|
289
|
+
*/
|
|
290
|
+
'kubb:build:start': [ctx: KubbBuildStartContext]
|
|
291
|
+
/**
|
|
292
|
+
* Fired after all files have been written to disk.
|
|
293
|
+
*/
|
|
294
|
+
'kubb:build:end': [ctx: KubbBuildEndContext]
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Emitted for each schema node during the AST walk.
|
|
298
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
299
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
300
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
301
|
+
*/
|
|
302
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext]
|
|
303
|
+
/**
|
|
304
|
+
* Emitted for each operation node during the AST walk.
|
|
305
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
306
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
307
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
308
|
+
*/
|
|
309
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext]
|
|
310
|
+
/**
|
|
311
|
+
* Emitted once after all operations have been walked, with the full collected array.
|
|
312
|
+
* Generator listeners with an `operations()` method respond to this event.
|
|
313
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
314
|
+
* `ctx.options` carries the plugin-level resolved options for the batch call.
|
|
315
|
+
*/
|
|
316
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext]
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
declare global {
|
|
320
|
+
namespace Kubb {
|
|
321
|
+
interface PluginContext {}
|
|
322
|
+
/**
|
|
323
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
324
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
325
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* // packages/plugin-ts/src/types.ts
|
|
330
|
+
* declare global {
|
|
331
|
+
* namespace Kubb {
|
|
332
|
+
* interface PluginRegistry {
|
|
333
|
+
* 'plugin-ts': PluginTs
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* }
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
interface PluginRegistry {}
|
|
340
|
+
}
|
|
234
341
|
}
|