@kubb/core 5.0.0-alpha.43 → 5.0.0-alpha.45
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-CgXFtmNP.js → PluginDriver-Bt_UCn7-.js} +88 -739
- package/dist/PluginDriver-Bt_UCn7-.js.map +1 -0
- package/dist/{PluginDriver-BQwm8hDd.cjs → PluginDriver-rVSfG8tW.cjs} +91 -751
- package/dist/PluginDriver-rVSfG8tW.cjs.map +1 -0
- package/dist/index.cjs +185 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +186 -14
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +5 -33
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +5 -5
- package/dist/mocks.js +5 -33
- package/dist/mocks.js.map +1 -1
- package/dist/{types-BJX_uR-y.d.ts → types-BUgxQiWY.d.ts} +72 -500
- package/package.json +5 -5
- package/src/FileManager.ts +20 -21
- package/src/FileProcessor.ts +2 -0
- package/src/Kubb.ts +3 -47
- package/src/PluginDriver.ts +53 -578
- package/src/constants.ts +9 -1
- package/src/createKubb.ts +6 -16
- package/src/definePlugin.ts +12 -34
- package/src/defineResolver.ts +23 -8
- package/src/mocks.ts +10 -84
- package/src/types.ts +40 -342
- package/src/utils/getBarrelFiles.ts +9 -3
- package/dist/PluginDriver-BQwm8hDd.cjs.map +0 -1
- package/dist/PluginDriver-CgXFtmNP.js.map +0 -1
- package/src/createPlugin.ts +0 -31
- package/src/utils/executeStrategies.ts +0 -84
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.45",
|
|
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",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"fflate": "^0.8.2",
|
|
68
68
|
"tinyexec": "^1.1.1",
|
|
69
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
70
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.43"
|
|
69
|
+
"@kubb/ast": "5.0.0-alpha.45"
|
|
71
70
|
},
|
|
72
71
|
"devDependencies": {
|
|
73
72
|
"p-limit": "^7.3.0",
|
|
74
|
-
"@internals/utils": "0.0.0"
|
|
73
|
+
"@internals/utils": "0.0.0",
|
|
74
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.45"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
77
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.45"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
80
|
"node": ">=22"
|
package/src/FileManager.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { trimExtName } from '@internals/utils'
|
|
2
2
|
import type { FileNode } from '@kubb/ast'
|
|
3
3
|
import { createFile } from '@kubb/ast'
|
|
4
|
+
import { BARREL_BASENAME } from './constants.ts'
|
|
4
5
|
|
|
5
6
|
function mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {
|
|
6
7
|
return {
|
|
@@ -38,21 +39,17 @@ export class FileManager {
|
|
|
38
39
|
const resolvedFiles: Array<FileNode> = []
|
|
39
40
|
const mergedFiles = new Map<string, FileNode>()
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
for (const file of files) {
|
|
42
43
|
const existing = mergedFiles.get(file.path)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else {
|
|
46
|
-
mergedFiles.set(file.path, file)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
44
|
+
mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)
|
|
45
|
+
}
|
|
49
46
|
|
|
50
47
|
for (const file of mergedFiles.values()) {
|
|
51
48
|
const resolvedFile = createFile(file)
|
|
52
49
|
this.#cache.set(resolvedFile.path, resolvedFile)
|
|
53
|
-
this.#filesCache = null
|
|
54
50
|
resolvedFiles.push(resolvedFile)
|
|
55
51
|
}
|
|
52
|
+
this.#filesCache = null
|
|
56
53
|
|
|
57
54
|
return resolvedFiles
|
|
58
55
|
}
|
|
@@ -65,23 +62,19 @@ export class FileManager {
|
|
|
65
62
|
const resolvedFiles: Array<FileNode> = []
|
|
66
63
|
const mergedFiles = new Map<string, FileNode>()
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
for (const file of files) {
|
|
69
66
|
const existing = mergedFiles.get(file.path)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} else {
|
|
73
|
-
mergedFiles.set(file.path, file)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
67
|
+
mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)
|
|
68
|
+
}
|
|
76
69
|
|
|
77
70
|
for (const file of mergedFiles.values()) {
|
|
78
71
|
const existing = this.#cache.get(file.path)
|
|
79
72
|
const merged = existing ? mergeFile(existing, file) : file
|
|
80
73
|
const resolvedFile = createFile(merged)
|
|
81
74
|
this.#cache.set(resolvedFile.path, resolvedFile)
|
|
82
|
-
this.#filesCache = null
|
|
83
75
|
resolvedFiles.push(resolvedFile)
|
|
84
76
|
}
|
|
77
|
+
this.#filesCache = null
|
|
85
78
|
|
|
86
79
|
return resolvedFiles
|
|
87
80
|
}
|
|
@@ -109,11 +102,17 @@ export class FileManager {
|
|
|
109
102
|
return this.#filesCache
|
|
110
103
|
}
|
|
111
104
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
// Precompute the barrel-file flag per key so the comparator avoids repeated string work.
|
|
106
|
+
const keys = [...this.#cache.keys()]
|
|
107
|
+
const meta = new Map<string, { length: number; isIndex: boolean }>()
|
|
108
|
+
for (const key of keys) {
|
|
109
|
+
meta.set(key, { length: key.length, isIndex: trimExtName(key).endsWith(BARREL_BASENAME) })
|
|
110
|
+
}
|
|
111
|
+
keys.sort((a, b) => {
|
|
112
|
+
const ma = meta.get(a)!
|
|
113
|
+
const mb = meta.get(b)!
|
|
114
|
+
if (ma.length !== mb.length) return ma.length - mb.length
|
|
115
|
+
if (ma.isIndex !== mb.isIndex) return ma.isIndex ? 1 : -1
|
|
117
116
|
return 0
|
|
118
117
|
})
|
|
119
118
|
|
package/src/FileProcessor.ts
CHANGED
|
@@ -29,6 +29,8 @@ function joinSources(file: FileNode): string {
|
|
|
29
29
|
/**
|
|
30
30
|
* Converts a single file to a string using the registered parsers.
|
|
31
31
|
* Falls back to joining source values when no matching parser is found.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
32
34
|
*/
|
|
33
35
|
export class FileProcessor {
|
|
34
36
|
readonly #limit = pLimit(PARALLEL_CONCURRENCY_LIMIT)
|
package/src/Kubb.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AsyncEventEmitter } from '@internals/utils'
|
|
2
2
|
import type { FileNode, OperationNode, SchemaNode } from '@kubb/ast'
|
|
3
3
|
import type { BuildOutput } from './createKubb.ts'
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { Plugin } from './definePlugin.ts'
|
|
5
|
+
import type { PluginDriver } from './PluginDriver.ts'
|
|
6
|
+
import type { Config, GeneratorContext, KubbBuildEndContext, KubbBuildStartContext, KubbPluginSetupContext } from './types'
|
|
6
7
|
|
|
7
8
|
type DebugInfo = {
|
|
8
9
|
date: Date
|
|
@@ -10,28 +11,6 @@ type DebugInfo = {
|
|
|
10
11
|
fileName?: string
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
14
|
-
hookName: H
|
|
15
|
-
plugins: Array<Plugin>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
19
|
-
strategy: Strategy
|
|
20
|
-
hookName: H
|
|
21
|
-
plugin: Plugin
|
|
22
|
-
parameters?: Array<unknown>
|
|
23
|
-
output?: unknown
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
27
|
-
duration: number
|
|
28
|
-
strategy: Strategy
|
|
29
|
-
hookName: H
|
|
30
|
-
plugin: Plugin
|
|
31
|
-
parameters?: Array<unknown>
|
|
32
|
-
output?: unknown
|
|
33
|
-
}
|
|
34
|
-
|
|
35
14
|
/**
|
|
36
15
|
* The instance returned by {@link createKubb}.
|
|
37
16
|
*/
|
|
@@ -253,28 +232,6 @@ export interface KubbHooks {
|
|
|
253
232
|
*/
|
|
254
233
|
'kubb:plugin:end': [plugin: Plugin, result: { duration: number; success: boolean; error?: Error }]
|
|
255
234
|
|
|
256
|
-
/**
|
|
257
|
-
* Emitted when plugin hook progress tracking starts.
|
|
258
|
-
* Contains the hook name and list of plugins to execute.
|
|
259
|
-
*/
|
|
260
|
-
'kubb:plugins:hook:progress:start': [progress: HookProgress]
|
|
261
|
-
/**
|
|
262
|
-
* Emitted when plugin hook progress tracking ends.
|
|
263
|
-
* Contains the hook name that completed.
|
|
264
|
-
*/
|
|
265
|
-
'kubb:plugins:hook:progress:end': [{ hookName: PluginLifecycleHooks }]
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Emitted when a plugin hook starts processing.
|
|
269
|
-
* Contains strategy, hook name, plugin, parameters, and output.
|
|
270
|
-
*/
|
|
271
|
-
'kubb:plugins:hook:processing:start': [execution: HookExecution]
|
|
272
|
-
/**
|
|
273
|
-
* Emitted when a plugin hook completes processing.
|
|
274
|
-
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
275
|
-
*/
|
|
276
|
-
'kubb:plugins:hook:processing:end': [result: HookResult]
|
|
277
|
-
|
|
278
235
|
/**
|
|
279
236
|
* Fired once — before any plugin's `buildStart` runs — so that hook-style plugins
|
|
280
237
|
* can register generators, configure resolvers/transformers/renderers, or inject
|
|
@@ -318,7 +275,6 @@ export interface KubbHooks {
|
|
|
318
275
|
|
|
319
276
|
declare global {
|
|
320
277
|
namespace Kubb {
|
|
321
|
-
interface PluginContext {}
|
|
322
278
|
/**
|
|
323
279
|
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
324
280
|
* Augment this interface in each plugin's `types.ts` to enable automatic
|