@kubb/core 5.0.0-alpha.3 → 5.0.0-alpha.31
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-D0dY_hpJ.d.ts +1986 -0
- package/dist/{chunk-ByKO4r7w.cjs → chunk-MlS0t1Af.cjs} +15 -0
- package/dist/chunk-O_arW02_.js +17 -0
- package/dist/hooks.cjs +13 -28
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +11 -37
- package/dist/hooks.js +14 -28
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +1469 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +572 -191
- package/dist/index.js +1443 -826
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Kubb.ts +38 -56
- package/src/KubbFile.ts +143 -0
- package/src/{PluginManager.ts → PluginDriver.ts} +159 -170
- package/src/build.ts +213 -65
- package/src/constants.ts +39 -6
- package/src/createAdapter.ts +25 -0
- package/src/createPlugin.ts +30 -0
- package/src/createStorage.ts +58 -0
- package/src/{config.ts → defineConfig.ts} +11 -16
- package/src/defineGenerator.ts +126 -0
- package/src/defineLogger.ts +13 -3
- package/src/defineParser.ts +57 -0
- package/src/definePresets.ts +16 -0
- package/src/defineResolver.ts +454 -0
- package/src/hooks/index.ts +1 -6
- package/src/hooks/useDriver.ts +11 -0
- package/src/hooks/useMode.ts +4 -4
- package/src/hooks/usePlugin.ts +3 -3
- package/src/index.ts +22 -10
- package/src/renderNode.tsx +25 -0
- package/src/storages/fsStorage.ts +2 -2
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +639 -52
- package/src/utils/FunctionParams.ts +2 -2
- package/src/utils/TreeNode.ts +40 -2
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/executeStrategies.ts +29 -10
- package/src/utils/formatters.ts +10 -21
- package/src/utils/getBarrelFiles.ts +80 -10
- package/src/utils/getConfigs.ts +9 -23
- package/src/utils/getPreset.ts +78 -0
- package/src/utils/isInputPath.ts +8 -0
- package/src/utils/linters.ts +23 -3
- package/src/utils/packageJSON.ts +76 -0
- package/dist/chunk--u3MIqq1.js +0 -8
- package/dist/types-CiPWLv-5.d.ts +0 -1001
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PromiseManager.ts +0 -40
- package/src/defineAdapter.ts +0 -22
- package/src/definePlugin.ts +0 -12
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/useKubb.ts +0 -22
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/getPlugins.ts +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.31",
|
|
4
4
|
"description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -64,14 +64,14 @@
|
|
|
64
64
|
}
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@kubb/fabric-core": "0.
|
|
68
|
-
"@kubb/react-fabric": "0.
|
|
67
|
+
"@kubb/fabric-core": "0.15.1",
|
|
68
|
+
"@kubb/react-fabric": "0.15.1",
|
|
69
69
|
"empathic": "^2.0.0",
|
|
70
70
|
"fflate": "^0.8.2",
|
|
71
|
-
"remeda": "^2.33.
|
|
71
|
+
"remeda": "^2.33.7",
|
|
72
72
|
"semver": "^7.7.4",
|
|
73
73
|
"tinyexec": "^1.0.4",
|
|
74
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
74
|
+
"@kubb/ast": "5.0.0-alpha.31"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@types/semver": "^7.7.1",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@internals/utils": "0.0.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/fabric-core": "0.
|
|
83
|
-
"@kubb/react-fabric": "0.
|
|
82
|
+
"@kubb/fabric-core": "0.14.0",
|
|
83
|
+
"@kubb/react-fabric": "0.14.0"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=22"
|
package/src/Kubb.ts
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { Strategy } from './
|
|
1
|
+
import type * as KubbFile from './KubbFile.ts'
|
|
2
|
+
import type { Strategy } from './PluginDriver.ts'
|
|
3
3
|
import type { Config, Plugin, PluginLifecycleHooks } from './types'
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type DebugInfo = {
|
|
6
6
|
date: Date
|
|
7
|
-
logs: string
|
|
7
|
+
logs: Array<string>
|
|
8
8
|
fileName?: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
type
|
|
11
|
+
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
12
12
|
hookName: H
|
|
13
13
|
plugins: Array<Plugin>
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type
|
|
17
|
-
hookName: H
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
16
|
+
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
21
17
|
strategy: Strategy
|
|
22
18
|
hookName: H
|
|
23
19
|
plugin: Plugin
|
|
24
|
-
parameters?: unknown
|
|
20
|
+
parameters?: Array<unknown>
|
|
25
21
|
output?: unknown
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
type
|
|
24
|
+
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
29
25
|
duration: number
|
|
30
26
|
strategy: Strategy
|
|
31
27
|
hookName: H
|
|
32
28
|
plugin: Plugin
|
|
33
|
-
parameters?: unknown
|
|
29
|
+
parameters?: Array<unknown>
|
|
34
30
|
output?: unknown
|
|
35
31
|
}
|
|
36
32
|
|
|
@@ -40,7 +36,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
40
36
|
*
|
|
41
37
|
* @example
|
|
42
38
|
* ```typescript
|
|
43
|
-
* import type { AsyncEventEmitter } from '@
|
|
39
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
44
40
|
* import type { KubbEvents } from '@kubb/core'
|
|
45
41
|
*
|
|
46
42
|
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
@@ -59,7 +55,6 @@ export interface KubbEvents {
|
|
|
59
55
|
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
60
56
|
*/
|
|
61
57
|
'lifecycle:start': [version: string]
|
|
62
|
-
|
|
63
58
|
/**
|
|
64
59
|
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
65
60
|
*/
|
|
@@ -69,7 +64,6 @@ export interface KubbEvents {
|
|
|
69
64
|
* Emitted when configuration loading starts.
|
|
70
65
|
*/
|
|
71
66
|
'config:start': []
|
|
72
|
-
|
|
73
67
|
/**
|
|
74
68
|
* Emitted when configuration loading is complete.
|
|
75
69
|
*/
|
|
@@ -79,24 +73,22 @@ export interface KubbEvents {
|
|
|
79
73
|
* Emitted when code generation phase starts.
|
|
80
74
|
*/
|
|
81
75
|
'generation:start': [config: Config]
|
|
82
|
-
|
|
83
76
|
/**
|
|
84
77
|
* Emitted when code generation phase completes.
|
|
85
78
|
*/
|
|
86
|
-
'generation:end': [
|
|
87
|
-
|
|
79
|
+
'generation:end': [config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>]
|
|
88
80
|
/**
|
|
89
81
|
* Emitted with a summary of the generation results.
|
|
90
82
|
* Contains summary lines, title, and success status.
|
|
91
83
|
*/
|
|
92
84
|
'generation:summary': [
|
|
93
|
-
|
|
85
|
+
config: Config,
|
|
94
86
|
{
|
|
95
87
|
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
96
88
|
status: 'success' | 'failed'
|
|
97
89
|
hrStart: [number, number]
|
|
98
90
|
filesCreated: number
|
|
99
|
-
pluginTimings?: Map<
|
|
91
|
+
pluginTimings?: Map<Plugin['name'], number>
|
|
100
92
|
},
|
|
101
93
|
]
|
|
102
94
|
|
|
@@ -104,7 +96,6 @@ export interface KubbEvents {
|
|
|
104
96
|
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
105
97
|
*/
|
|
106
98
|
'format:start': []
|
|
107
|
-
|
|
108
99
|
/**
|
|
109
100
|
* Emitted when code formatting completes.
|
|
110
101
|
*/
|
|
@@ -114,7 +105,6 @@ export interface KubbEvents {
|
|
|
114
105
|
* Emitted when linting starts.
|
|
115
106
|
*/
|
|
116
107
|
'lint:start': []
|
|
117
|
-
|
|
118
108
|
/**
|
|
119
109
|
* Emitted when linting completes.
|
|
120
110
|
*/
|
|
@@ -124,29 +114,20 @@ export interface KubbEvents {
|
|
|
124
114
|
* Emitted when plugin hooks execution starts.
|
|
125
115
|
*/
|
|
126
116
|
'hooks:start': []
|
|
127
|
-
|
|
128
117
|
/**
|
|
129
118
|
* Emitted when plugin hooks execution completes.
|
|
130
119
|
*/
|
|
131
120
|
'hooks:end': []
|
|
132
121
|
|
|
133
122
|
/**
|
|
134
|
-
* Emitted when a single hook execution starts
|
|
123
|
+
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
135
124
|
* The callback should be invoked when the command completes.
|
|
136
125
|
*/
|
|
137
126
|
'hook:start': [{ id?: string; command: string; args?: readonly string[] }]
|
|
138
127
|
/**
|
|
139
128
|
* Emitted when a single hook execution completes.
|
|
140
129
|
*/
|
|
141
|
-
'hook:end': [
|
|
142
|
-
{
|
|
143
|
-
id?: string
|
|
144
|
-
command: string
|
|
145
|
-
args?: readonly string[]
|
|
146
|
-
success: boolean
|
|
147
|
-
error: Error | null
|
|
148
|
-
},
|
|
149
|
-
]
|
|
130
|
+
'hook:end': [{ id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }]
|
|
150
131
|
|
|
151
132
|
/**
|
|
152
133
|
* Emitted when a new version of Kubb is available.
|
|
@@ -157,49 +138,54 @@ export interface KubbEvents {
|
|
|
157
138
|
* Informational message event.
|
|
158
139
|
*/
|
|
159
140
|
info: [message: string, info?: string]
|
|
160
|
-
|
|
161
141
|
/**
|
|
162
142
|
* Error event. Emitted when an error occurs during code generation.
|
|
163
143
|
*/
|
|
164
144
|
error: [error: Error, meta?: Record<string, unknown>]
|
|
165
|
-
|
|
166
145
|
/**
|
|
167
146
|
* Success message event.
|
|
168
147
|
*/
|
|
169
148
|
success: [message: string, info?: string]
|
|
170
|
-
|
|
171
149
|
/**
|
|
172
150
|
* Warning message event.
|
|
173
151
|
*/
|
|
174
152
|
warn: [message: string, info?: string]
|
|
175
|
-
|
|
176
153
|
/**
|
|
177
154
|
* Debug event for detailed logging.
|
|
178
155
|
* Contains timestamp, log messages, and optional filename.
|
|
179
156
|
*/
|
|
180
|
-
debug: [
|
|
157
|
+
debug: [info: DebugInfo]
|
|
181
158
|
|
|
182
159
|
/**
|
|
183
160
|
* Emitted when file processing starts.
|
|
184
161
|
* Contains the list of files to be processed.
|
|
185
162
|
*/
|
|
186
163
|
'files:processing:start': [files: Array<KubbFile.ResolvedFile>]
|
|
187
|
-
|
|
188
164
|
/**
|
|
189
165
|
* Emitted for each file being processed, providing progress updates.
|
|
190
166
|
* Contains processed count, total count, percentage, and file details.
|
|
191
167
|
*/
|
|
192
168
|
'file:processing:update': [
|
|
193
169
|
{
|
|
194
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Number of files processed so far.
|
|
172
|
+
*/
|
|
195
173
|
processed: number
|
|
196
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Total number of files to process.
|
|
176
|
+
*/
|
|
197
177
|
total: number
|
|
198
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Processing percentage (0–100).
|
|
180
|
+
*/
|
|
199
181
|
percentage: number
|
|
200
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Optional source identifier.
|
|
184
|
+
*/
|
|
201
185
|
source?: string
|
|
202
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* The file being processed.
|
|
188
|
+
*/
|
|
203
189
|
file: KubbFile.ResolvedFile
|
|
204
190
|
/**
|
|
205
191
|
* Kubb configuration (not present in Fabric).
|
|
@@ -208,45 +194,41 @@ export interface KubbEvents {
|
|
|
208
194
|
config: Config
|
|
209
195
|
},
|
|
210
196
|
]
|
|
211
|
-
|
|
212
197
|
/**
|
|
213
198
|
* Emitted when file processing completes.
|
|
214
199
|
* Contains the list of processed files.
|
|
215
200
|
*/
|
|
216
|
-
'files:processing:end': [files: KubbFile.ResolvedFile
|
|
201
|
+
'files:processing:end': [files: Array<KubbFile.ResolvedFile>]
|
|
217
202
|
|
|
218
203
|
/**
|
|
219
204
|
* Emitted when a plugin starts executing.
|
|
220
205
|
*/
|
|
221
206
|
'plugin:start': [plugin: Plugin]
|
|
222
|
-
|
|
223
207
|
/**
|
|
224
208
|
* Emitted when a plugin completes execution.
|
|
225
|
-
* Duration in ms
|
|
209
|
+
* Duration in ms.
|
|
226
210
|
*/
|
|
227
|
-
'plugin:end': [plugin: Plugin,
|
|
211
|
+
'plugin:end': [plugin: Plugin, result: { duration: number; success: boolean; error?: Error }]
|
|
228
212
|
|
|
229
213
|
/**
|
|
230
214
|
* Emitted when plugin hook progress tracking starts.
|
|
231
215
|
* Contains the hook name and list of plugins to execute.
|
|
232
216
|
*/
|
|
233
|
-
'plugins:hook:progress:start': [
|
|
234
|
-
|
|
217
|
+
'plugins:hook:progress:start': [progress: HookProgress]
|
|
235
218
|
/**
|
|
236
219
|
* Emitted when plugin hook progress tracking ends.
|
|
237
220
|
* Contains the hook name that completed.
|
|
238
221
|
*/
|
|
239
|
-
'plugins:hook:progress:end': [
|
|
222
|
+
'plugins:hook:progress:end': [{ hookName: PluginLifecycleHooks }]
|
|
240
223
|
|
|
241
224
|
/**
|
|
242
225
|
* Emitted when a plugin hook starts processing.
|
|
243
226
|
* Contains strategy, hook name, plugin, parameters, and output.
|
|
244
227
|
*/
|
|
245
|
-
'plugins:hook:processing:start': [
|
|
246
|
-
|
|
228
|
+
'plugins:hook:processing:start': [execution: HookExecution]
|
|
247
229
|
/**
|
|
248
230
|
* Emitted when a plugin hook completes processing.
|
|
249
231
|
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
250
232
|
*/
|
|
251
|
-
'plugins:hook:processing:end': [
|
|
233
|
+
'plugins:hook:processing:end': [result: HookResult]
|
|
252
234
|
}
|
package/src/KubbFile.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
type ImportName =
|
|
2
|
+
| string
|
|
3
|
+
| Array<
|
|
4
|
+
| string
|
|
5
|
+
| {
|
|
6
|
+
propertyName: string
|
|
7
|
+
name?: string
|
|
8
|
+
}
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type Import = {
|
|
12
|
+
/**
|
|
13
|
+
* Import name to be used.
|
|
14
|
+
* @example ["useState"]
|
|
15
|
+
* @example "React"
|
|
16
|
+
*/
|
|
17
|
+
name: ImportName
|
|
18
|
+
/**
|
|
19
|
+
* Path for the import.
|
|
20
|
+
* @example '@kubb/core'
|
|
21
|
+
*/
|
|
22
|
+
path: string
|
|
23
|
+
/**
|
|
24
|
+
* Add type-only import prefix.
|
|
25
|
+
* - `true` generates `import type { Type } from './path'`
|
|
26
|
+
* - `false` generates `import { Type } from './path'`
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
isTypeOnly?: boolean
|
|
30
|
+
/**
|
|
31
|
+
* Import entire module as namespace.
|
|
32
|
+
* - `true` generates `import * as Name from './path'`
|
|
33
|
+
* - `false` generates standard import
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
isNameSpace?: boolean
|
|
37
|
+
/**
|
|
38
|
+
* When root is set it will compute a relative path with `getRelativePath(root, path)`.
|
|
39
|
+
*/
|
|
40
|
+
root?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type Source = {
|
|
44
|
+
name?: string
|
|
45
|
+
value?: string
|
|
46
|
+
/**
|
|
47
|
+
* Make this source a type-only export.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
isTypeOnly?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Include export keyword in source.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
isExportable?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* Include in barrel file generation.
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
isIndexable?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type Export = {
|
|
64
|
+
/**
|
|
65
|
+
* Export name to be used.
|
|
66
|
+
* @example ["useState"]
|
|
67
|
+
* @example "React"
|
|
68
|
+
*/
|
|
69
|
+
name?: string | Array<string>
|
|
70
|
+
/**
|
|
71
|
+
* Path for the export.
|
|
72
|
+
* @example '@kubb/core'
|
|
73
|
+
*/
|
|
74
|
+
path: string
|
|
75
|
+
/**
|
|
76
|
+
* Add type-only export prefix.
|
|
77
|
+
* - `true` generates `export type { Type } from './path'`
|
|
78
|
+
* - `false` generates `export { Type } from './path'`
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
isTypeOnly?: boolean
|
|
82
|
+
/**
|
|
83
|
+
* Export as aliased namespace.
|
|
84
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
85
|
+
* - `false` generates standard export
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
88
|
+
asAlias?: boolean
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
|
|
92
|
+
|
|
93
|
+
export type Mode = 'single' | 'split'
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Name to be used to dynamically create the baseName (based on input.path).
|
|
97
|
+
* Based on UNIX basename.
|
|
98
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
99
|
+
*/
|
|
100
|
+
export type BaseName = `${string}.${string}`
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Fully qualified path to a specified file.
|
|
104
|
+
*/
|
|
105
|
+
export type Path = string
|
|
106
|
+
|
|
107
|
+
export type File<TMeta extends object = object> = {
|
|
108
|
+
/**
|
|
109
|
+
* Name used to create the path.
|
|
110
|
+
* Based on UNIX basename, `${name}${extname}`.
|
|
111
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
112
|
+
*/
|
|
113
|
+
baseName: BaseName
|
|
114
|
+
/**
|
|
115
|
+
* Fully qualified path to the file.
|
|
116
|
+
*/
|
|
117
|
+
path: Path
|
|
118
|
+
sources: Array<Source>
|
|
119
|
+
imports: Array<Import>
|
|
120
|
+
exports: Array<Export>
|
|
121
|
+
/**
|
|
122
|
+
* Extra metadata used for barrel/index file generation.
|
|
123
|
+
*/
|
|
124
|
+
meta?: TMeta
|
|
125
|
+
banner?: string
|
|
126
|
+
footer?: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
130
|
+
/**
|
|
131
|
+
* Unique identifier, generated from a hash.
|
|
132
|
+
* @default hash
|
|
133
|
+
*/
|
|
134
|
+
id: string
|
|
135
|
+
/**
|
|
136
|
+
* First part of the `baseName`, derived from the file name.
|
|
137
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
138
|
+
*/
|
|
139
|
+
name: string
|
|
140
|
+
extname: Extname
|
|
141
|
+
imports: Array<Import>
|
|
142
|
+
exports: Array<Export>
|
|
143
|
+
}
|