@kubb/core 5.0.0-alpha.34 → 5.0.0-alpha.36
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-B_65W4fv.js +1677 -0
- package/dist/PluginDriver-B_65W4fv.js.map +1 -0
- package/dist/{PluginDriver-BBi_41VF.d.ts → PluginDriver-C9iBgYbk.d.ts} +743 -376
- package/dist/PluginDriver-CCdkwR14.cjs +1806 -0
- package/dist/PluginDriver-CCdkwR14.cjs.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +272 -1666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -141
- package/dist/index.js +231 -1623
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +165 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +11 -5
- package/src/FileManager.ts +1 -1
- package/src/FileProcessor.ts +1 -1
- package/src/Kubb.ts +145 -38
- package/src/PluginDriver.ts +318 -40
- package/src/constants.ts +1 -1
- package/src/{build.ts → createKubb.ts} +180 -122
- package/src/createPlugin.ts +1 -0
- package/src/createRenderer.ts +57 -0
- package/src/defineGenerator.ts +57 -84
- package/src/defineLogger.ts +2 -2
- package/src/defineParser.ts +3 -2
- package/src/definePlugin.ts +95 -0
- package/src/defineResolver.ts +1 -1
- package/src/devtools.ts +1 -1
- package/src/index.ts +7 -6
- package/src/mocks.ts +234 -0
- package/src/renderNode.ts +35 -0
- package/src/types.ts +275 -210
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/getBarrelFiles.ts +3 -3
- package/src/utils/getFunctionParams.ts +14 -7
- package/src/utils/isInputPath.ts +2 -2
- package/src/utils/packageJSON.ts +2 -3
- package/src/defineConfig.ts +0 -51
- package/src/definePresets.ts +0 -16
- package/src/renderNode.tsx +0 -28
- package/src/utils/getConfigs.ts +0 -16
- package/src/utils/getPreset.ts +0 -78
package/src/utils/TreeNode.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import { getRelativePath } from '@internals/utils'
|
|
4
|
+
import type { FileNode } from '@kubb/ast'
|
|
4
5
|
import { createExport, createFile, createSource } from '@kubb/ast'
|
|
5
|
-
import type { FileNode } from '@kubb/ast/types'
|
|
6
6
|
import type { BarrelType } from '../types.ts'
|
|
7
7
|
import { TreeNode } from './TreeNode.ts'
|
|
8
8
|
|
|
@@ -13,11 +13,11 @@ export type FileMetaBase = {
|
|
|
13
13
|
type AddIndexesProps = {
|
|
14
14
|
type: BarrelType | false | undefined
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Absolute output root derived from config `root` and `output.path`.
|
|
17
17
|
*/
|
|
18
18
|
root: string
|
|
19
19
|
/**
|
|
20
|
-
* Output for plugin
|
|
20
|
+
* Output settings for the plugin.
|
|
21
21
|
*/
|
|
22
22
|
output: {
|
|
23
23
|
path: string
|
|
@@ -2,22 +2,29 @@ import { sortBy } from 'remeda'
|
|
|
2
2
|
|
|
3
3
|
export type Param = {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Controls how path parameters are emitted in the function signature.
|
|
6
|
+
* - `'object'` groups them as a single destructured parameter.
|
|
7
|
+
* - `'inline'` spreads them as individual comma-separated parameters.
|
|
8
|
+
* - `'inlineSpread'` emits a single rest parameter.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @private
|
|
10
|
+
* @default 'inline'
|
|
11
|
+
* @internal
|
|
10
12
|
*/
|
|
11
13
|
mode?: 'object' | 'inline' | 'inlineSpread'
|
|
12
14
|
type?: 'string' | 'number' | (string & {})
|
|
13
15
|
optional?: boolean
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
17
|
+
* Default value expression for the parameter.
|
|
18
|
+
*
|
|
19
|
+
* @example Assignment syntax
|
|
20
|
+
* `test = "default"`
|
|
16
21
|
*/
|
|
17
22
|
default?: string
|
|
18
23
|
/**
|
|
19
|
-
* Used for no TypeScript(with mode object)
|
|
20
|
-
*
|
|
24
|
+
* Used for no TypeScript (with mode object).
|
|
25
|
+
*
|
|
26
|
+
* @example Value syntax
|
|
27
|
+
* `test: "default"`
|
|
21
28
|
*/
|
|
22
29
|
value?: string
|
|
23
30
|
children?: Params
|
package/src/utils/isInputPath.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config, InputPath } from '../types'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Type guard to check if a given config has an `input.path`.
|
|
5
5
|
*/
|
|
6
|
-
export function isInputPath(config:
|
|
6
|
+
export function isInputPath(config: Config | undefined): config is Config<InputPath> {
|
|
7
7
|
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
8
8
|
}
|
package/src/utils/packageJSON.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { readSync } from '@internals/utils'
|
|
2
|
-
import * as pkg from 'empathic/package'
|
|
1
|
+
import { findPackageJSON, readSync } from '@internals/utils'
|
|
3
2
|
import { coerce, satisfies } from 'semver'
|
|
4
3
|
|
|
5
4
|
type PackageJSON = {
|
|
@@ -11,7 +10,7 @@ type DependencyName = string
|
|
|
11
10
|
type DependencyVersion = string
|
|
12
11
|
|
|
13
12
|
function getPackageJSONSync(cwd?: string): PackageJSON | null {
|
|
14
|
-
const pkgPath =
|
|
13
|
+
const pkgPath = findPackageJSON(cwd)
|
|
15
14
|
if (!pkgPath) {
|
|
16
15
|
return null
|
|
17
16
|
}
|
package/src/defineConfig.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { PossiblePromise } from '@internals/utils'
|
|
2
|
-
import type { UserConfig } from './types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CLI options derived from command-line flags.
|
|
6
|
-
*/
|
|
7
|
-
export type CLIOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* Path to `kubb.config.js`.
|
|
10
|
-
*/
|
|
11
|
-
config?: string
|
|
12
|
-
/**
|
|
13
|
-
* Enable watch mode for input files.
|
|
14
|
-
*/
|
|
15
|
-
watch?: boolean
|
|
16
|
-
/**
|
|
17
|
-
* Logging verbosity for CLI usage.
|
|
18
|
-
*
|
|
19
|
-
* - `silent`: hide non-essential logs
|
|
20
|
-
* - `info`: show general logs (non-plugin-related)
|
|
21
|
-
* - `debug`: include detailed plugin lifecycle logs
|
|
22
|
-
* @default 'silent'
|
|
23
|
-
*/
|
|
24
|
-
logLevel?: 'silent' | 'info' | 'debug'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* All accepted forms of a Kubb configuration.
|
|
29
|
-
*/
|
|
30
|
-
export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Helper for defining a Kubb configuration.
|
|
34
|
-
*
|
|
35
|
-
* Accepts either:
|
|
36
|
-
* - A config object or array of configs
|
|
37
|
-
* - A function returning the config(s), optionally async,
|
|
38
|
-
* receiving the CLI options as argument
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* export default defineConfig(({ logLevel }) => ({
|
|
42
|
-
* root: 'src',
|
|
43
|
-
* plugins: [myPlugin()],
|
|
44
|
-
* }))
|
|
45
|
-
* @deprecated as of Kubb v5, @kubb/core will not expose `defineConfig` anymore. use the `kubb` package instead
|
|
46
|
-
*/
|
|
47
|
-
export function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
48
|
-
export function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
49
|
-
export function defineConfig(config: ConfigInput): ConfigInput {
|
|
50
|
-
return config
|
|
51
|
-
}
|
package/src/definePresets.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Preset, Presets, Resolver } from './types.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a typed presets registry object — a named collection of {@link Preset} entries.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { definePreset, definePresets } from '@kubb/core'
|
|
8
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
9
|
-
*
|
|
10
|
-
* export const myPresets = definePresets({
|
|
11
|
-
* kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy] }),
|
|
12
|
-
* })
|
|
13
|
-
*/
|
|
14
|
-
export function definePresets<TResolver extends Resolver = Resolver>(presets: Presets<TResolver>): Presets<TResolver> {
|
|
15
|
-
return presets
|
|
16
|
-
}
|
package/src/renderNode.tsx
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { FileNode } from '@kubb/ast/types'
|
|
2
|
-
import { createRenderer } from '@kubb/renderer-jsx'
|
|
3
|
-
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
4
|
-
import type { PluginDriver } from './PluginDriver.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handles the return value of a plugin AST hook or generator method.
|
|
8
|
-
*
|
|
9
|
-
* - React element → rendered via renderer-jsx, files stored in `driver.fileManager`
|
|
10
|
-
* - `Array<FileNode>` → upserted directly into `driver.fileManager`
|
|
11
|
-
* - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)
|
|
12
|
-
*/
|
|
13
|
-
export async function applyHookResult(result: KubbReactNode | Array<FileNode> | void, driver: PluginDriver): Promise<void> {
|
|
14
|
-
if (!result) return
|
|
15
|
-
|
|
16
|
-
if (Array.isArray(result)) {
|
|
17
|
-
driver.fileManager.upsert(...(result as Array<FileNode>))
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const renderer = createRenderer()
|
|
22
|
-
|
|
23
|
-
// biome-ignore lint/complexity/noUselessFragments: not needed
|
|
24
|
-
await renderer.render(<>{result as KubbReactNode}</>)
|
|
25
|
-
|
|
26
|
-
driver.fileManager.upsert(...renderer.files)
|
|
27
|
-
renderer.unmount()
|
|
28
|
-
}
|
package/src/utils/getConfigs.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CLIOptions, ConfigInput } from '../defineConfig.ts'
|
|
2
|
-
import type { Config, UserConfig } from '../types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolves a {@link ConfigInput} into a normalized array of {@link Config} objects.
|
|
6
|
-
*
|
|
7
|
-
* - Awaits the config when it is a `Promise`.
|
|
8
|
-
* - Calls the factory function with `args` when the config is a function.
|
|
9
|
-
* - Wraps a single config object in an array for uniform downstream handling.
|
|
10
|
-
*/
|
|
11
|
-
export async function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>> {
|
|
12
|
-
const resolved = await (typeof config === 'function' ? config(args as CLIOptions) : config)
|
|
13
|
-
const userConfigs = Array.isArray(resolved) ? resolved : [resolved]
|
|
14
|
-
|
|
15
|
-
return userConfigs.map((item) => ({ plugins: [], ...item }) as Config)
|
|
16
|
-
}
|
package/src/utils/getPreset.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { composeTransformers } from '@kubb/ast'
|
|
2
|
-
import type { Visitor } from '@kubb/ast/types'
|
|
3
|
-
import type { CompatibilityPreset, Generator, Preset, Presets, Resolver } from '../types.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a copy of `defaults` where each function in `userOverrides` is wrapped
|
|
7
|
-
* so a `null`/`undefined` return falls back to the original. Non-function values
|
|
8
|
-
* are assigned directly. All calls use the merged object as `this`.
|
|
9
|
-
*/
|
|
10
|
-
function withFallback<T extends object>(defaults: T, userOverrides: Partial<T>): T {
|
|
11
|
-
const merged = { ...defaults } as T
|
|
12
|
-
|
|
13
|
-
for (const key of Object.keys(userOverrides) as Array<keyof T>) {
|
|
14
|
-
const userVal = userOverrides[key]
|
|
15
|
-
const defaultVal = defaults[key]
|
|
16
|
-
|
|
17
|
-
if (typeof userVal === 'function' && typeof defaultVal === 'function') {
|
|
18
|
-
;(merged as any)[key] = (...args: any[]) => (userVal as Function).apply(merged, args) ?? (defaultVal as Function).apply(merged, args)
|
|
19
|
-
} else if (userVal !== undefined) {
|
|
20
|
-
merged[key] = userVal as T[typeof key]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return merged
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type GetPresetParams<TResolver extends Resolver> = {
|
|
28
|
-
preset: CompatibilityPreset
|
|
29
|
-
presets: Presets<TResolver>
|
|
30
|
-
/**
|
|
31
|
-
* Optional single resolver whose methods override the preset resolver.
|
|
32
|
-
* When a method returns `null` or `undefined` the preset resolver's method is used instead.
|
|
33
|
-
*/
|
|
34
|
-
resolver?: Partial<TResolver> & ThisType<TResolver>
|
|
35
|
-
/**
|
|
36
|
-
* User-supplied generators to append after the preset's generators.
|
|
37
|
-
*/
|
|
38
|
-
generators?: Array<Generator<any>>
|
|
39
|
-
/**
|
|
40
|
-
* Optional single transformer visitor whose methods override the preset transformer.
|
|
41
|
-
* When a method returns `null` or `undefined` the preset transformer's method is used instead.
|
|
42
|
-
*/
|
|
43
|
-
transformer?: Visitor
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
type GetPresetResult<TResolver extends Resolver> = {
|
|
47
|
-
resolver: TResolver
|
|
48
|
-
transformer: Visitor | undefined
|
|
49
|
-
generators: Array<Generator<any>>
|
|
50
|
-
preset: Preset<TResolver> | undefined
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Resolves a named preset into a resolver, transformer, and generators.
|
|
55
|
-
*
|
|
56
|
-
* - Selects the preset resolver; wraps it with user overrides using null/undefined fallback.
|
|
57
|
-
* - Composes the preset's transformers into a single visitor; wraps it with the user transformer using null/undefined fallback.
|
|
58
|
-
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
59
|
-
*/
|
|
60
|
-
export function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver> {
|
|
61
|
-
const { preset: presetName, presets, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = params
|
|
62
|
-
const preset = presets[presetName]
|
|
63
|
-
|
|
64
|
-
const presetResolver = preset?.resolver ?? presets['default']!.resolver
|
|
65
|
-
const resolver = userResolver ? withFallback(presetResolver, userResolver) : presetResolver
|
|
66
|
-
|
|
67
|
-
const presetTransformers = preset?.transformers ?? []
|
|
68
|
-
const presetTransformer = presetTransformers.length > 0 ? composeTransformers(...presetTransformers) : undefined
|
|
69
|
-
const transformer = presetTransformer && userTransformer ? withFallback(presetTransformer, userTransformer) : (userTransformer ?? presetTransformer)
|
|
70
|
-
|
|
71
|
-
const presetGenerators = preset?.generators ?? []
|
|
72
|
-
const defaultGenerators = presets['default']?.generators ?? []
|
|
73
|
-
const generators = (presetGenerators.length > 0 || userGenerators.length > 0 ? [...presetGenerators, ...userGenerators] : defaultGenerators) as Array<
|
|
74
|
-
Generator<any>
|
|
75
|
-
>
|
|
76
|
-
|
|
77
|
-
return { resolver, transformer, generators, preset }
|
|
78
|
-
}
|