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