@kubb/core 5.0.0-alpha.9 → 5.0.0-beta.2
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 +24 -21
- package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
- package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
- package/dist/PluginDriver-DV3p2Hky.js +945 -0
- package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
- package/dist/index.cjs +752 -1641
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +271 -225
- package/dist/index.js +736 -1609
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +145 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +80 -0
- package/dist/mocks.js +140 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-CC09VtBt.d.ts +2148 -0
- package/package.json +51 -57
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +207 -131
- package/src/PluginDriver.ts +325 -564
- package/src/constants.ts +20 -47
- package/src/createAdapter.ts +13 -6
- package/src/createKubb.ts +574 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +13 -1
- package/src/defineGenerator.ts +77 -124
- package/src/defineLogger.ts +4 -2
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +83 -0
- package/src/defineResolver.ts +418 -28
- package/src/devtools.ts +14 -14
- package/src/index.ts +13 -15
- package/src/mocks.ts +178 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +41 -11
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +1031 -283
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +50 -12
- package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -103
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -77
- package/dist/hooks.js +0 -98
- package/dist/hooks.js.map +0 -1
- package/src/build.ts +0 -418
- package/src/config.ts +0 -56
- package/src/createPlugin.ts +0 -28
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -143
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginDriver.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/TreeNode.ts +0 -215
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getBarrelFiles.ts +0 -141
- package/src/utils/getConfigs.ts +0 -12
- package/src/utils/linters.ts +0 -25
package/src/Kubb.ts
CHANGED
|
@@ -1,224 +1,300 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import type { AsyncEventEmitter } from '@internals/utils'
|
|
2
|
+
import type { OperationNode, SchemaNode } from '@kubb/ast'
|
|
3
|
+
import type { BuildOutput } from './createKubb.ts'
|
|
4
|
+
import type { PluginDriver } from './PluginDriver.ts'
|
|
5
|
+
import type {
|
|
6
|
+
Config,
|
|
7
|
+
GeneratorContext,
|
|
8
|
+
KubbBuildEndContext,
|
|
9
|
+
KubbBuildStartContext,
|
|
10
|
+
KubbConfigEndContext,
|
|
11
|
+
KubbDebugContext,
|
|
12
|
+
KubbErrorContext,
|
|
13
|
+
KubbFileProcessingUpdateContext,
|
|
14
|
+
KubbFilesProcessingEndContext,
|
|
15
|
+
KubbFilesProcessingStartContext,
|
|
16
|
+
KubbGenerationEndContext,
|
|
17
|
+
KubbGenerationStartContext,
|
|
18
|
+
KubbGenerationSummaryContext,
|
|
19
|
+
KubbHookEndContext,
|
|
20
|
+
KubbHookStartContext,
|
|
21
|
+
KubbInfoContext,
|
|
22
|
+
KubbLifecycleStartContext,
|
|
23
|
+
KubbPluginEndContext,
|
|
24
|
+
KubbPluginSetupContext,
|
|
25
|
+
KubbPluginStartContext,
|
|
26
|
+
KubbPluginsEndContext,
|
|
27
|
+
KubbSuccessContext,
|
|
28
|
+
KubbVersionNewContext,
|
|
29
|
+
KubbWarnContext,
|
|
30
|
+
} from './types'
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Kubb code generation instance returned by {@link createKubb}.
|
|
34
|
+
*
|
|
35
|
+
* Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.
|
|
36
|
+
* For a single one-off build, chain directly: `await createKubb(config).build()`.
|
|
37
|
+
*/
|
|
38
|
+
export type Kubb = {
|
|
39
|
+
/**
|
|
40
|
+
* Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.
|
|
41
|
+
*/
|
|
42
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>
|
|
43
|
+
/**
|
|
44
|
+
* Generated source code keyed by absolute file path. Available after `build()` or `safeBuild()` completes.
|
|
45
|
+
*/
|
|
46
|
+
readonly sources: Map<string, string>
|
|
47
|
+
/**
|
|
48
|
+
* Plugin driver managing all plugins. Available after `setup()` completes.
|
|
49
|
+
*/
|
|
50
|
+
readonly driver: PluginDriver | undefined
|
|
51
|
+
/**
|
|
52
|
+
* Resolved configuration with defaults applied. Available after `setup()` completes.
|
|
53
|
+
*/
|
|
54
|
+
readonly config: Config | undefined
|
|
55
|
+
/**
|
|
56
|
+
* Resolves config and initializes the driver. `build()` calls this automatically.
|
|
57
|
+
*/
|
|
58
|
+
setup(): Promise<void>
|
|
59
|
+
/**
|
|
60
|
+
* Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.
|
|
61
|
+
*/
|
|
62
|
+
build(): Promise<BuildOutput>
|
|
63
|
+
/**
|
|
64
|
+
* Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.
|
|
65
|
+
*/
|
|
66
|
+
safeBuild(): Promise<BuildOutput>
|
|
31
67
|
}
|
|
32
68
|
|
|
33
69
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
70
|
+
* Lifecycle events emitted during Kubb code generation.
|
|
71
|
+
* Use these for logging, progress tracking, and custom integrations.
|
|
36
72
|
*
|
|
37
73
|
* @example
|
|
38
74
|
* ```typescript
|
|
39
75
|
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
40
|
-
* import type {
|
|
76
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
41
77
|
*
|
|
42
|
-
* const
|
|
78
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
43
79
|
*
|
|
44
|
-
*
|
|
80
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
45
81
|
* console.log('Starting Kubb generation')
|
|
46
82
|
* })
|
|
47
83
|
*
|
|
48
|
-
*
|
|
84
|
+
* hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
|
|
49
85
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
50
86
|
* })
|
|
51
87
|
* ```
|
|
52
88
|
*/
|
|
53
|
-
export interface
|
|
89
|
+
export interface KubbHooks {
|
|
54
90
|
/**
|
|
55
|
-
*
|
|
91
|
+
* Fires at the start of the Kubb lifecycle, before code generation begins.
|
|
56
92
|
*/
|
|
57
|
-
'lifecycle:start': [
|
|
93
|
+
'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext]
|
|
58
94
|
/**
|
|
59
|
-
*
|
|
95
|
+
* Fires at the end of the Kubb lifecycle, after all code generation completes.
|
|
60
96
|
*/
|
|
61
|
-
'lifecycle:end': []
|
|
97
|
+
'kubb:lifecycle:end': []
|
|
62
98
|
|
|
63
99
|
/**
|
|
64
|
-
*
|
|
100
|
+
* Fires when configuration loading starts.
|
|
65
101
|
*/
|
|
66
|
-
'config:start': []
|
|
102
|
+
'kubb:config:start': []
|
|
67
103
|
/**
|
|
68
|
-
*
|
|
104
|
+
* Fires when configuration loading completes.
|
|
69
105
|
*/
|
|
70
|
-
'config:end': [
|
|
106
|
+
'kubb:config:end': [ctx: KubbConfigEndContext]
|
|
71
107
|
|
|
72
108
|
/**
|
|
73
|
-
*
|
|
109
|
+
* Fires when code generation starts.
|
|
74
110
|
*/
|
|
75
|
-
'generation:start': [
|
|
111
|
+
'kubb:generation:start': [ctx: KubbGenerationStartContext]
|
|
76
112
|
/**
|
|
77
|
-
*
|
|
113
|
+
* Fires when code generation completes.
|
|
78
114
|
*/
|
|
79
|
-
'generation:end': [
|
|
115
|
+
'kubb:generation:end': [ctx: KubbGenerationEndContext]
|
|
80
116
|
/**
|
|
81
|
-
*
|
|
82
|
-
* Contains summary lines, title, and success status.
|
|
117
|
+
* Fires with a generation summary including summary lines, title, and success status.
|
|
83
118
|
*/
|
|
84
|
-
'generation:summary': [
|
|
85
|
-
config: Config,
|
|
86
|
-
{
|
|
87
|
-
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
88
|
-
status: 'success' | 'failed'
|
|
89
|
-
hrStart: [number, number]
|
|
90
|
-
filesCreated: number
|
|
91
|
-
pluginTimings?: Map<Plugin['name'], number>
|
|
92
|
-
},
|
|
93
|
-
]
|
|
119
|
+
'kubb:generation:summary': [ctx: KubbGenerationSummaryContext]
|
|
94
120
|
|
|
95
121
|
/**
|
|
96
|
-
*
|
|
122
|
+
* Fires when code formatting starts (e.g., Biome or Prettier).
|
|
97
123
|
*/
|
|
98
|
-
'format:start': []
|
|
124
|
+
'kubb:format:start': []
|
|
99
125
|
/**
|
|
100
|
-
*
|
|
126
|
+
* Fires when code formatting completes.
|
|
101
127
|
*/
|
|
102
|
-
'format:end': []
|
|
128
|
+
'kubb:format:end': []
|
|
103
129
|
|
|
104
130
|
/**
|
|
105
|
-
*
|
|
131
|
+
* Fires when linting starts.
|
|
106
132
|
*/
|
|
107
|
-
'lint:start': []
|
|
133
|
+
'kubb:lint:start': []
|
|
108
134
|
/**
|
|
109
|
-
*
|
|
135
|
+
* Fires when linting completes.
|
|
110
136
|
*/
|
|
111
|
-
'lint:end': []
|
|
137
|
+
'kubb:lint:end': []
|
|
112
138
|
|
|
113
139
|
/**
|
|
114
|
-
*
|
|
140
|
+
* Fires when plugin hooks execution starts.
|
|
115
141
|
*/
|
|
116
|
-
'hooks:start': []
|
|
142
|
+
'kubb:hooks:start': []
|
|
117
143
|
/**
|
|
118
|
-
*
|
|
144
|
+
* Fires when plugin hooks execution completes.
|
|
119
145
|
*/
|
|
120
|
-
'hooks:end': []
|
|
146
|
+
'kubb:hooks:end': []
|
|
121
147
|
|
|
122
148
|
/**
|
|
123
|
-
*
|
|
124
|
-
* The callback should be invoked when the command completes.
|
|
149
|
+
* Fires when a single hook executes (e.g., format or lint). The callback is invoked when the command finishes.
|
|
125
150
|
*/
|
|
126
|
-
'hook:start': [
|
|
151
|
+
'kubb:hook:start': [ctx: KubbHookStartContext]
|
|
127
152
|
/**
|
|
128
|
-
*
|
|
153
|
+
* Fires when a single hook execution completes.
|
|
129
154
|
*/
|
|
130
|
-
'hook:end': [
|
|
155
|
+
'kubb:hook:end': [ctx: KubbHookEndContext]
|
|
131
156
|
|
|
132
157
|
/**
|
|
133
|
-
*
|
|
158
|
+
* Fires when a new Kubb version is available.
|
|
134
159
|
*/
|
|
135
|
-
'version:new': [
|
|
160
|
+
'kubb:version:new': [ctx: KubbVersionNewContext]
|
|
136
161
|
|
|
137
162
|
/**
|
|
138
163
|
* Informational message event.
|
|
139
164
|
*/
|
|
140
|
-
info: [
|
|
165
|
+
'kubb:info': [ctx: KubbInfoContext]
|
|
141
166
|
/**
|
|
142
|
-
* Error event
|
|
167
|
+
* Error event, fired when an error occurs during generation.
|
|
143
168
|
*/
|
|
144
|
-
error: [
|
|
169
|
+
'kubb:error': [ctx: KubbErrorContext]
|
|
145
170
|
/**
|
|
146
171
|
* Success message event.
|
|
147
172
|
*/
|
|
148
|
-
success: [
|
|
173
|
+
'kubb:success': [ctx: KubbSuccessContext]
|
|
149
174
|
/**
|
|
150
175
|
* Warning message event.
|
|
151
176
|
*/
|
|
152
|
-
warn: [
|
|
177
|
+
'kubb:warn': [ctx: KubbWarnContext]
|
|
153
178
|
/**
|
|
154
|
-
* Debug event for detailed logging.
|
|
155
|
-
* Contains timestamp, log messages, and optional filename.
|
|
179
|
+
* Debug event for detailed logging with timestamp and optional filename.
|
|
156
180
|
*/
|
|
157
|
-
debug: [
|
|
181
|
+
'kubb:debug': [ctx: KubbDebugContext]
|
|
158
182
|
|
|
159
183
|
/**
|
|
160
|
-
*
|
|
161
|
-
* Contains the list of files to be processed.
|
|
184
|
+
* Fires when file processing starts with the list of files to process.
|
|
162
185
|
*/
|
|
163
|
-
'files:processing:start': [
|
|
186
|
+
'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext]
|
|
164
187
|
/**
|
|
165
|
-
*
|
|
166
|
-
* Contains processed count, total count, percentage, and file details.
|
|
188
|
+
* Fires for each file with progress updates: processed count, total, percentage, and file details.
|
|
167
189
|
*/
|
|
168
|
-
'file:processing:update': [
|
|
169
|
-
{
|
|
170
|
-
/** Number of files processed so far. */
|
|
171
|
-
processed: number
|
|
172
|
-
/** Total number of files to process. */
|
|
173
|
-
total: number
|
|
174
|
-
/** Processing percentage (0–100). */
|
|
175
|
-
percentage: number
|
|
176
|
-
/** Optional source identifier. */
|
|
177
|
-
source?: string
|
|
178
|
-
/** The file being processed. */
|
|
179
|
-
file: KubbFile.ResolvedFile
|
|
180
|
-
/**
|
|
181
|
-
* Kubb configuration (not present in Fabric).
|
|
182
|
-
* Provides access to the current config during file processing.
|
|
183
|
-
*/
|
|
184
|
-
config: Config
|
|
185
|
-
},
|
|
186
|
-
]
|
|
190
|
+
'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext]
|
|
187
191
|
/**
|
|
188
|
-
*
|
|
189
|
-
* Contains the list of processed files.
|
|
192
|
+
* Fires when file processing completes with the list of processed files.
|
|
190
193
|
*/
|
|
191
|
-
'files:processing:end': [
|
|
194
|
+
'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext]
|
|
192
195
|
|
|
193
196
|
/**
|
|
194
|
-
*
|
|
197
|
+
* Fires when a plugin starts execution.
|
|
195
198
|
*/
|
|
196
|
-
'plugin:start': [
|
|
199
|
+
'kubb:plugin:start': [ctx: KubbPluginStartContext]
|
|
197
200
|
/**
|
|
198
|
-
*
|
|
199
|
-
* Duration in ms.
|
|
201
|
+
* Fires when a plugin completes execution. Duration measured in milliseconds.
|
|
200
202
|
*/
|
|
201
|
-
'plugin:end': [
|
|
203
|
+
'kubb:plugin:end': [ctx: KubbPluginEndContext]
|
|
202
204
|
|
|
203
205
|
/**
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
+
* Fires once before plugins execute — allowing plugins to register generators, configure resolvers/transformers/renderers, or inject files.
|
|
207
|
+
*/
|
|
208
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext]
|
|
209
|
+
/**
|
|
210
|
+
* Fires before the plugin execution loop begins. The adapter has already parsed the source and `inputNode` is available.
|
|
206
211
|
*/
|
|
207
|
-
'
|
|
212
|
+
'kubb:build:start': [ctx: KubbBuildStartContext]
|
|
208
213
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
214
|
+
* Fires after all plugins run and per-plugin barrels generate, but before files write to disk.
|
|
215
|
+
* Use this to inject final files that must persist in the same write pass as plugin output.
|
|
211
216
|
*/
|
|
212
|
-
'plugins:
|
|
217
|
+
'kubb:plugins:end': [ctx: KubbPluginsEndContext]
|
|
218
|
+
/**
|
|
219
|
+
* Fires after all files write to disk.
|
|
220
|
+
*/
|
|
221
|
+
'kubb:build:end': [ctx: KubbBuildEndContext]
|
|
213
222
|
|
|
214
223
|
/**
|
|
215
|
-
*
|
|
216
|
-
|
|
224
|
+
* Fires for each schema node during AST traversal. Generator listeners respond to this.
|
|
225
|
+
*/
|
|
226
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext]
|
|
227
|
+
/**
|
|
228
|
+
* Fires for each operation node during AST traversal. Generator listeners respond to this.
|
|
217
229
|
*/
|
|
218
|
-
'
|
|
230
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext]
|
|
219
231
|
/**
|
|
220
|
-
*
|
|
221
|
-
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
232
|
+
* Fires once after all operations traverse with the full collected array. Batch generator listeners respond to this.
|
|
222
233
|
*/
|
|
223
|
-
'
|
|
234
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext]
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare global {
|
|
238
|
+
namespace Kubb {
|
|
239
|
+
/**
|
|
240
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
241
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
242
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* // packages/plugin-ts/src/types.ts
|
|
247
|
+
* declare global {
|
|
248
|
+
* namespace Kubb {
|
|
249
|
+
* interface PluginRegistry {
|
|
250
|
+
* 'plugin-ts': PluginTs
|
|
251
|
+
* }
|
|
252
|
+
* }
|
|
253
|
+
* }
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
interface PluginRegistry {}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Extension point for root `Config['output']` options.
|
|
260
|
+
* Augment the `output` key in middleware or plugin packages to add extra fields
|
|
261
|
+
* to the global output configuration without touching core types.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* // packages/middleware-barrel/src/types.ts
|
|
266
|
+
* declare global {
|
|
267
|
+
* namespace Kubb {
|
|
268
|
+
* interface ConfigOptionsRegistry {
|
|
269
|
+
* output: {
|
|
270
|
+
* barrel?: import('./types.ts').BarrelConfig | false
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* }
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
interface ConfigOptionsRegistry {}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Extension point for per-plugin `Output` options.
|
|
281
|
+
* Augment the `output` key in middleware or plugin packages to add extra fields
|
|
282
|
+
* to the per-plugin output configuration without touching core types.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* // packages/middleware-barrel/src/types.ts
|
|
287
|
+
* declare global {
|
|
288
|
+
* namespace Kubb {
|
|
289
|
+
* interface PluginOptionsRegistry {
|
|
290
|
+
* output: {
|
|
291
|
+
* barrel?: import('./types.ts').PluginBarrelConfig | false
|
|
292
|
+
* }
|
|
293
|
+
* }
|
|
294
|
+
* }
|
|
295
|
+
* }
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
interface PluginOptionsRegistry {}
|
|
299
|
+
}
|
|
224
300
|
}
|