@kubb/core 5.0.0-alpha.4 → 5.0.0-alpha.6
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/{types-Bbh1o0yW.d.ts → PluginManager-vZodFEMe.d.ts} +124 -125
- package/dist/hooks.cjs +19 -9
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +33 -18
- package/dist/hooks.js +20 -10
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/PluginManager.ts +4 -5
- package/src/build.ts +3 -4
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +42 -9
- package/src/hooks/useMode.ts +2 -2
- package/src/hooks/usePlugin.ts +3 -3
- package/src/hooks/usePluginManager.ts +2 -2
- package/src/types.ts +2 -3
- package/src/utils/resolveOptions.ts +1 -1
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.6",
|
|
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.14.0",
|
|
68
|
+
"@kubb/react-fabric": "0.14.0",
|
|
69
69
|
"empathic": "^2.0.0",
|
|
70
70
|
"fflate": "^0.8.2",
|
|
71
71
|
"remeda": "^2.33.6",
|
|
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.6"
|
|
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/PluginManager.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { performance } from 'node:perf_hooks'
|
|
|
3
3
|
import type { AsyncEventEmitter } from '@internals/utils'
|
|
4
4
|
import { setUniqueName, transformReservedWord } from '@internals/utils'
|
|
5
5
|
import type { RootNode } from '@kubb/ast/types'
|
|
6
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
7
|
-
import type { Fabric } from '@kubb/react-fabric'
|
|
6
|
+
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
8
7
|
import { CORE_PLUGIN_NAME, DEFAULT_STUDIO_URL } from './constants.ts'
|
|
9
8
|
import { openInStudio as openInStudioFn } from './devtools.ts'
|
|
10
9
|
import { ValidationPluginError } from './errors.ts'
|
|
@@ -40,7 +39,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
40
39
|
// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#
|
|
41
40
|
|
|
42
41
|
type Options = {
|
|
43
|
-
fabric:
|
|
42
|
+
fabric: FabricType
|
|
44
43
|
events: AsyncEventEmitter<KubbEvents>
|
|
45
44
|
/**
|
|
46
45
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -48,7 +47,7 @@ type Options = {
|
|
|
48
47
|
concurrency?: number
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
type
|
|
50
|
+
export type GetFileOptions<TOptions = object> = {
|
|
52
51
|
name: string
|
|
53
52
|
mode?: KubbFile.Mode
|
|
54
53
|
extname: KubbFile.Extname
|
|
@@ -163,7 +162,7 @@ export class PluginManager {
|
|
|
163
162
|
return this.#getSortedPlugins()
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
getFile<TOptions = object>({ name, mode, extname, pluginName, options }:
|
|
165
|
+
getFile<TOptions = object>({ name, mode, extname, pluginName, options }: GetFileOptions<TOptions>): KubbFile.File<{ pluginName: string }> {
|
|
167
166
|
const resolvedName = mode ? (mode === 'single' ? '' : this.resolveName({ name, pluginName, type: 'file' })) : name
|
|
168
167
|
|
|
169
168
|
const path = this.resolvePath({
|
package/src/build.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { dirname, relative, resolve } from 'node:path'
|
|
2
2
|
import { AsyncEventEmitter, exists, formatMs, getElapsedMs, getRelativePath, URLPath } from '@internals/utils'
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
-
import type { Fabric } from '@kubb/react-fabric'
|
|
3
|
+
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
5
4
|
import { createFabric } from '@kubb/react-fabric'
|
|
6
5
|
import { typescriptParser } from '@kubb/react-fabric/parsers'
|
|
7
6
|
import { fsPlugin } from '@kubb/react-fabric/plugins'
|
|
@@ -21,7 +20,7 @@ type BuildOptions = {
|
|
|
21
20
|
|
|
22
21
|
type BuildOutput = {
|
|
23
22
|
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
24
|
-
fabric:
|
|
23
|
+
fabric: FabricType
|
|
25
24
|
files: Array<KubbFile.ResolvedFile>
|
|
26
25
|
pluginManager: PluginManager
|
|
27
26
|
pluginTimings: Map<string, number>
|
|
@@ -31,7 +30,7 @@ type BuildOutput = {
|
|
|
31
30
|
|
|
32
31
|
type SetupResult = {
|
|
33
32
|
events: AsyncEventEmitter<KubbEvents>
|
|
34
|
-
fabric:
|
|
33
|
+
fabric: FabricType
|
|
35
34
|
pluginManager: PluginManager
|
|
36
35
|
sources: Map<KubbFile.Path, string>
|
|
37
36
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export { useKubb } from './useKubb.ts'
|
|
2
|
-
|
|
3
|
-
/** @deprecated Use `useKubb` from `@kubb/core/hooks` instead */
|
|
4
2
|
export { useMode } from './useMode.ts'
|
|
5
|
-
/** @deprecated Use `useKubb` from `@kubb/core/hooks` instead */
|
|
6
3
|
export { usePlugin } from './usePlugin.ts'
|
|
7
|
-
/** @deprecated Use `useKubb` from `@kubb/core/hooks` instead */
|
|
8
4
|
export { usePluginManager } from './usePluginManager.ts'
|
package/src/hooks/useKubb.ts
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
1
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import {
|
|
3
|
-
import type { PluginManager } from '../PluginManager.ts'
|
|
4
|
-
import type { Plugin, PluginFactoryOptions } from '../types.ts'
|
|
2
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
3
|
+
import type { GetFileOptions, PluginManager } from '../PluginManager.ts'
|
|
4
|
+
import type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type ResolvePathOptions = {
|
|
7
|
+
pluginName?: string
|
|
8
|
+
group?: {
|
|
9
|
+
tag?: string
|
|
10
|
+
path?: string
|
|
11
|
+
}
|
|
12
|
+
type?: ResolveNameParams['type']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
16
|
+
plugin: Plugin<TOptions>
|
|
17
|
+
mode: KubbFile.Mode
|
|
18
|
+
config: Config
|
|
19
|
+
/**
|
|
20
|
+
* Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.
|
|
21
|
+
*/
|
|
22
|
+
getPluginByName: (pluginName?: string) => Plugin | undefined
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a file reference, defaulting `pluginName` to the current plugin.
|
|
25
|
+
*/
|
|
26
|
+
getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>
|
|
27
|
+
/**
|
|
28
|
+
* Resolves a name, defaulting `pluginName` to the current plugin.
|
|
29
|
+
*/
|
|
30
|
+
resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a path, defaulting `pluginName` to the current plugin.
|
|
33
|
+
*/
|
|
34
|
+
resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {
|
|
38
|
+
const { meta } = useFabric<{
|
|
8
39
|
plugin: Plugin<TOptions>
|
|
9
40
|
mode: KubbFile.Mode
|
|
10
41
|
pluginManager: PluginManager
|
|
11
42
|
}>()
|
|
12
43
|
|
|
44
|
+
const defaultPluginName = meta.plugin.name
|
|
45
|
+
|
|
13
46
|
return {
|
|
14
47
|
plugin: meta.plugin as Plugin<TOptions>,
|
|
15
48
|
mode: meta.mode,
|
|
16
49
|
config: meta.pluginManager.config,
|
|
17
|
-
getPluginByName: meta.pluginManager.getPluginByName.
|
|
18
|
-
getFile: meta.pluginManager.getFile.
|
|
19
|
-
resolveName: meta.pluginManager.resolveName.
|
|
20
|
-
resolvePath: meta.pluginManager.resolvePath.
|
|
50
|
+
getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),
|
|
51
|
+
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, { pluginName, ...rest }),
|
|
52
|
+
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, { pluginName, ...rest }),
|
|
53
|
+
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, { pluginName, ...rest }),
|
|
21
54
|
}
|
|
22
55
|
}
|
package/src/hooks/useMode.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import {
|
|
2
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated use `useKubb` instead
|
|
6
6
|
*/
|
|
7
7
|
export function useMode(): KubbFile.Mode {
|
|
8
|
-
const { meta } =
|
|
8
|
+
const { meta } = useFabric<{ mode: KubbFile.Mode }>()
|
|
9
9
|
|
|
10
10
|
return meta.mode
|
|
11
11
|
}
|
package/src/hooks/usePlugin.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
2
2
|
import type { Plugin, PluginFactoryOptions } from '../types.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated use
|
|
5
|
+
* @deprecated use useKubb instead
|
|
6
6
|
*/
|
|
7
7
|
export function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {
|
|
8
|
-
const { meta } =
|
|
8
|
+
const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()
|
|
9
9
|
|
|
10
10
|
return meta.plugin
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
2
2
|
import type { PluginManager } from '../PluginManager.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated use `useKubb` instead
|
|
6
6
|
*/
|
|
7
7
|
export function usePluginManager(): PluginManager {
|
|
8
|
-
const { meta } =
|
|
8
|
+
const { meta } = useFabric<{ pluginManager: PluginManager }>()
|
|
9
9
|
|
|
10
10
|
return meta.pluginManager
|
|
11
11
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
|
|
2
2
|
import type { RootNode, SchemaNode } from '@kubb/ast/types'
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
-
import type { Fabric } from '@kubb/react-fabric'
|
|
3
|
+
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
5
4
|
import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
|
|
6
5
|
import type { DefineStorage } from './defineStorage.ts'
|
|
7
6
|
import type { KubbEvents } from './Kubb.ts'
|
|
@@ -399,7 +398,7 @@ export type ResolveNameParams = {
|
|
|
399
398
|
}
|
|
400
399
|
|
|
401
400
|
export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
402
|
-
fabric:
|
|
401
|
+
fabric: FabricType
|
|
403
402
|
config: Config
|
|
404
403
|
pluginManager: PluginManager
|
|
405
404
|
/**
|