@kubb/core 5.0.0-alpha.40 → 5.0.0-alpha.42
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/index.cjs +12 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +12 -16
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/{types-PLXOrxov.d.ts → types-C6NCtNqM.d.ts} +7 -7
- package/package.json +4 -4
- package/src/createKubb.ts +10 -12
- package/src/storages/fsStorage.ts +2 -1
- package/src/storages/memoryStorage.ts +2 -1
- package/src/utils/isInputPath.ts +4 -2
package/src/createKubb.ts
CHANGED
|
@@ -11,14 +11,13 @@ import type { Kubb } from './Kubb.ts'
|
|
|
11
11
|
import { PluginDriver } from './PluginDriver.ts'
|
|
12
12
|
import { applyHookResult } from './renderNode.ts'
|
|
13
13
|
import { fsStorage } from './storages/fsStorage.ts'
|
|
14
|
-
import type { AdapterSource, Config, GeneratorContext, KubbHooks, Plugin, PluginContext, Storage } from './types.ts'
|
|
14
|
+
import type { AdapterSource, Config, GeneratorContext, KubbHooks, Plugin, PluginContext, Storage, UserConfig } from './types.ts'
|
|
15
15
|
import { getDiagnosticInfo } from './utils/diagnostics.ts'
|
|
16
16
|
import type { FileMetaBase } from './utils/getBarrelFiles.ts'
|
|
17
17
|
import { getBarrelFiles } from './utils/getBarrelFiles.ts'
|
|
18
18
|
import { isInputPath } from './utils/isInputPath.ts'
|
|
19
19
|
|
|
20
|
-
type
|
|
21
|
-
config: Config
|
|
20
|
+
type SetupOptions = {
|
|
22
21
|
hooks?: AsyncEventEmitter<KubbHooks>
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -51,8 +50,7 @@ type SetupResult = {
|
|
|
51
50
|
storage: Storage | null
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
async function setup(options:
|
|
55
|
-
const { config: userConfig } = options
|
|
53
|
+
async function setup(userConfig: UserConfig, options: SetupOptions = {}): Promise<SetupResult> {
|
|
56
54
|
const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()
|
|
57
55
|
|
|
58
56
|
const sources: Map<string, string> = new Map<string, string>()
|
|
@@ -546,21 +544,21 @@ function inputToAdapterSource(config: Config): AdapterSource {
|
|
|
546
544
|
return { type: 'path', path: resolved }
|
|
547
545
|
}
|
|
548
546
|
|
|
549
|
-
type
|
|
550
|
-
config: Config
|
|
547
|
+
type CreateKubbOptions = {
|
|
551
548
|
hooks?: AsyncEventEmitter<KubbHooks>
|
|
552
549
|
}
|
|
553
550
|
|
|
554
551
|
/**
|
|
555
552
|
* Creates a Kubb instance bound to a single config entry.
|
|
556
553
|
*
|
|
557
|
-
*
|
|
558
|
-
* `setup
|
|
554
|
+
* Accepts a user-facing config shape and resolves it to a full {@link Config} during
|
|
555
|
+
* `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
|
|
556
|
+
* across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
|
|
559
557
|
* calling `setup()` or `build()`.
|
|
560
558
|
*
|
|
561
559
|
* @example
|
|
562
560
|
* ```ts
|
|
563
|
-
* const kubb = createKubb(
|
|
561
|
+
* const kubb = createKubb(userConfig)
|
|
564
562
|
*
|
|
565
563
|
* kubb.hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
566
564
|
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
@@ -569,7 +567,7 @@ type KubbOptions = {
|
|
|
569
567
|
* const { files, failedPlugins } = await kubb.safeBuild()
|
|
570
568
|
* ```
|
|
571
569
|
*/
|
|
572
|
-
export function createKubb(options:
|
|
570
|
+
export function createKubb(userConfig: UserConfig, options: CreateKubbOptions = {}): Kubb {
|
|
573
571
|
const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()
|
|
574
572
|
let setupResult: SetupResult | undefined
|
|
575
573
|
|
|
@@ -587,7 +585,7 @@ export function createKubb(options: KubbOptions): Kubb {
|
|
|
587
585
|
return setupResult?.config
|
|
588
586
|
},
|
|
589
587
|
async setup() {
|
|
590
|
-
setupResult = await setup({
|
|
588
|
+
setupResult = await setup(userConfig, { hooks })
|
|
591
589
|
},
|
|
592
590
|
async build() {
|
|
593
591
|
if (!setupResult) {
|
|
@@ -26,7 +26,8 @@ function isMissingPathError(error: unknown): error is NodeJS.ErrnoException {
|
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
|
-
* import {
|
|
29
|
+
* import { fsStorage } from '@kubb/core'
|
|
30
|
+
* import { defineConfig } from 'kubb'
|
|
30
31
|
*
|
|
31
32
|
* export default defineConfig({
|
|
32
33
|
* input: { path: './petStore.yaml' },
|
|
@@ -9,7 +9,8 @@ import { createStorage } from '../createStorage.ts'
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* import {
|
|
12
|
+
* import { memoryStorage } from '@kubb/core'
|
|
13
|
+
* import { defineConfig } from 'kubb'
|
|
13
14
|
*
|
|
14
15
|
* export default defineConfig({
|
|
15
16
|
* input: { path: './petStore.yaml' },
|
package/src/utils/isInputPath.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { Config, InputPath } from '../types'
|
|
1
|
+
import type { Config, InputPath, UserConfig } 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: UserConfig | undefined): config is UserConfig<InputPath>
|
|
7
|
+
export function isInputPath(config: Config | undefined): config is Config<InputPath>
|
|
8
|
+
export function isInputPath(config: Config | UserConfig | undefined): config is Config<InputPath> | UserConfig<InputPath> {
|
|
7
9
|
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
8
10
|
}
|