kubb 5.0.0-beta.7 → 5.0.0-beta.70
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/LICENSE +17 -10
- package/README.md +46 -37
- package/bin/kubb.js +11 -3
- package/dist/index.cjs +57 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -12
- package/dist/index.js +58 -24
- package/dist/index.js.map +1 -1
- package/package.json +12 -31
- package/src/defineConfig.ts +0 -91
- package/src/index.ts +0 -1
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This repository contains software under two licenses:
|
|
1
|
+
MIT License
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
MIT License — see licenses/LICENSE-MIT for the full license text.
|
|
3
|
+
Copyright (c) 2026 Stijn Van Hulle
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>kubb</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
8
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
9
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
10
9
|
[![License][license-src]][license-href]
|
|
11
|
-
[![
|
|
12
|
-
|
|
13
|
-
### The meta framework for code generation
|
|
14
|
-
|
|
15
|
-
Point Kubb at an OpenAPI spec and it generates types, clients, hooks, validators, mocks, and more.
|
|
10
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
11
|
+
[![Node][node-src]][node-href]
|
|
16
12
|
|
|
17
13
|
<h4>
|
|
18
14
|
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
@@ -25,6 +21,12 @@ Point Kubb at an OpenAPI spec and it generates types, clients, hooks, validators
|
|
|
25
21
|
|
|
26
22
|
<br />
|
|
27
23
|
|
|
24
|
+
# Kubb
|
|
25
|
+
|
|
26
|
+
### The meta framework for code generation
|
|
27
|
+
|
|
28
|
+
Point Kubb at a schema and it generates types, clients, hooks, validators, mocks, and more.
|
|
29
|
+
|
|
28
30
|
## Installation
|
|
29
31
|
|
|
30
32
|
```bash
|
|
@@ -53,19 +55,22 @@ See the [documentation](https://kubb.dev) for detailed usage and advanced featur
|
|
|
53
55
|
|
|
54
56
|
## Features
|
|
55
57
|
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
- JSX-based renderer (`@kubb/renderer-jsx`) for
|
|
62
|
-
-
|
|
58
|
+
- Generate from a schema: Kubb produces TypeScript types, type-safe API clients, [TanStack Query](https://github.com/TanStack/query) hooks for React and Vue, [SWR](https://github.com/vercel/swr) hooks, [Zod](https://github.com/colinhacks/zod) validators, [Faker](https://github.com/faker-js/faker) mocks, and [MSW](https://github.com/mswjs/msw) handlers.
|
|
59
|
+
- Plug in input formats through adapters like [`@kubb/adapter-oas`](https://npmx.dev/package/@kubb/adapter-oas), with TypeScript-first output that runs on Node.js and Bun.
|
|
60
|
+
- Pick what you generate from the [plugin ecosystem](https://github.com/kubb-labs/plugins): `plugin-ts`, `plugin-client`, `plugin-react-query`, `plugin-vue-query`, `plugin-swr`, `plugin-zod`, `plugin-faker`, `plugin-msw`, `plugin-cypress`, `plugin-redoc`, and `plugin-mcp`. Enable only the ones a project needs.
|
|
61
|
+
- Choose your HTTP client: use the axios or fetch presets, or point at a custom client module so generated requests run through your own wrapper.
|
|
62
|
+
- Control the generated tree: group files by tag, emit barrel exports, and include or exclude operations to keep the output focused.
|
|
63
|
+
- Build your own output with custom plugins, adapters, and the JSX-based renderer (`@kubb/renderer-jsx`) for full control over what lands on disk.
|
|
64
|
+
- Hook into your bundler with `unplugin-kubb`, which runs generation inside [Vite](https://github.com/vitejs/vite), [Nuxt](https://github.com/nuxt/nuxt), [Astro](https://github.com/withastro/astro), [webpack](https://github.com/webpack/webpack), and other build tools.
|
|
65
|
+
- Drive generation from AI tools through the built-in Model Context Protocol (MCP) server, which works with [Claude](https://claude.ai), [Cursor](https://cursor.sh), and other MCP-compatible assistants.
|
|
66
|
+
- Generate from inside [Claude Code](https://kubb.dev/docs/5.x/ai/claude) with the Kubb plugin, which adds slash commands, a config skill, and an agent that run the Kubb CLI.
|
|
63
67
|
|
|
64
68
|
## Supporting Kubb
|
|
65
69
|
|
|
66
|
-
Kubb is an open source project
|
|
70
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
67
71
|
|
|
68
72
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
73
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
69
74
|
|
|
70
75
|
<p align="center">
|
|
71
76
|
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
@@ -73,6 +78,16 @@ Kubb is an open source project with its ongoing development made possible entire
|
|
|
73
78
|
</a>
|
|
74
79
|
</p>
|
|
75
80
|
|
|
81
|
+
## Contributing
|
|
82
|
+
|
|
83
|
+
We welcome contributions that help improve Kubb. A few ways to get involved:
|
|
84
|
+
|
|
85
|
+
- Found a bug? File it in the [issue tracker](https://github.com/kubb-labs/kubb/issues).
|
|
86
|
+
- Have an idea to improve Kubb? [Open an issue](https://github.com/kubb-labs/kubb/issues/new) to share it.
|
|
87
|
+
- Need help? Ask the community on [Discord](https://discord.gg/4dQjA6vrWX).
|
|
88
|
+
|
|
89
|
+
See [CONTRIBUTING.md](https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md) for the project structure, local setup, and commands.
|
|
90
|
+
|
|
76
91
|
## Contributors [![Contributors][contributors-src]][contributors-href]
|
|
77
92
|
|
|
78
93
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
@@ -160,15 +175,11 @@ Kubb is an open source project with its ongoing development made possible entire
|
|
|
160
175
|
|
|
161
176
|
## License
|
|
162
177
|
|
|
163
|
-
|
|
164
|
-
under AGPL-3.0-or-later.
|
|
165
|
-
|
|
166
|
-
- **Most packages** — [MIT](./licenses/LICENSE-MIT)
|
|
167
|
-
- **`@kubb/agent`** — [AGPL-3.0-or-later](./licenses/LICENSE-AGPL-3.0)
|
|
178
|
+
This repository is licensed under the [MIT License](./licenses/LICENSE-MIT), Copyright © 2025 [Stijn Van Hulle](https://stijnvanhulle.be).
|
|
168
179
|
|
|
169
180
|
See [LICENSE](./LICENSE) for details.
|
|
170
181
|
|
|
171
|
-
## Star
|
|
182
|
+
## Star history
|
|
172
183
|
|
|
173
184
|
<a href="https://star-history.com/#kubb-labs/kubb&Date">
|
|
174
185
|
<picture>
|
|
@@ -180,19 +191,17 @@ See [LICENSE](./LICENSE) for details.
|
|
|
180
191
|
|
|
181
192
|
<!-- Badges -->
|
|
182
193
|
|
|
183
|
-
[npm-version-src]: https://
|
|
184
|
-
[npm-version-href]: https://npmx.dev/package
|
|
185
|
-
[npm-downloads-src]: https://
|
|
186
|
-
[npm-downloads-href]: https://
|
|
187
|
-
[
|
|
188
|
-
[
|
|
189
|
-
[
|
|
190
|
-
[
|
|
191
|
-
[
|
|
192
|
-
[
|
|
193
|
-
[
|
|
194
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/core
|
|
195
|
-
[contributors-src]: https://img.shields.io/github/contributors/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517&label=%20
|
|
194
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
195
|
+
[npm-version-href]: https://npmx.dev/package/kubb
|
|
196
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
197
|
+
[npm-downloads-href]: https://npmx.dev/package/kubb
|
|
198
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
199
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
200
|
+
[license-src]: https://shieldcn.dev/npm/license/kubb.svg?variant=secondary&size=xs&theme=zinc
|
|
201
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
202
|
+
[node-src]: https://shieldcn.dev/npm/node/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
203
|
+
[node-href]: https://npmx.dev/package/kubb
|
|
204
|
+
[contributors-src]: https://shieldcn.dev/github/contributors/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
196
205
|
[contributors-href]: #contributors-
|
|
197
|
-
[
|
|
198
|
-
[
|
|
206
|
+
[coverage-src]: https://shieldcn.dev/codecov/github/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
207
|
+
[coverage-href]: https://app.codecov.io/gh/kubb-labs/kubb
|
package/bin/kubb.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
process.setSourceMapsEnabled?.(true)
|
|
4
|
+
process.title = 'Kubb'
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const { run } = await import('@kubb/cli')
|
|
8
|
+
await run(process.argv)
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
3
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
4
|
-
let
|
|
4
|
+
let _kubb_core = require("@kubb/core");
|
|
5
|
+
let _kubb_plugin_barrel = require("@kubb/plugin-barrel");
|
|
5
6
|
let _kubb_parser_ts = require("@kubb/parser-ts");
|
|
7
|
+
let _kubb_parser_md = require("@kubb/parser-md");
|
|
6
8
|
//#region ../../internals/utils/src/promise.ts
|
|
7
9
|
/** Returns `true` when `result` is a thenable `Promise`.
|
|
8
10
|
*
|
|
@@ -18,28 +20,40 @@ function isPromise(result) {
|
|
|
18
20
|
//#endregion
|
|
19
21
|
//#region src/defineConfig.ts
|
|
20
22
|
/**
|
|
21
|
-
* Applies default adapter, parsers,
|
|
23
|
+
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
22
24
|
*
|
|
25
|
+
* - `root` defaults to `process.cwd()`
|
|
23
26
|
* - `adapter` defaults to `adapterOas()`
|
|
24
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
25
|
-
* - `
|
|
26
|
-
* - `
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - `output.
|
|
27
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
28
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
29
|
+
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
30
|
+
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
31
|
+
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
32
|
+
* - `output.format` defaults to `false`
|
|
33
|
+
* - `output.lint` defaults to `false`
|
|
30
34
|
*/
|
|
31
35
|
function applyDefaults(config) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
36
|
+
const plugins = config.plugins?.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], (0, _kubb_plugin_barrel.pluginBarrel)()];
|
|
37
|
+
const hasBarrelPlugin = plugins.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName);
|
|
34
38
|
const output = { ...config.output };
|
|
35
|
-
if (
|
|
39
|
+
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
36
40
|
if (output.format === void 0) output.format = false;
|
|
37
41
|
if (output.lint === void 0) output.lint = false;
|
|
38
42
|
return {
|
|
39
43
|
...config,
|
|
44
|
+
root: config.root || process.cwd(),
|
|
40
45
|
adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
|
|
41
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
42
|
-
|
|
46
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
47
|
+
_kubb_parser_ts.parserTs,
|
|
48
|
+
_kubb_parser_ts.parserTsx,
|
|
49
|
+
_kubb_parser_md.parserMd
|
|
50
|
+
],
|
|
51
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
52
|
+
_kubb_core.cliReporter,
|
|
53
|
+
_kubb_core.jsonReporter,
|
|
54
|
+
_kubb_core.fileReporter
|
|
55
|
+
],
|
|
56
|
+
plugins,
|
|
43
57
|
output
|
|
44
58
|
};
|
|
45
59
|
}
|
|
@@ -48,21 +62,41 @@ function normalizeConfig(config) {
|
|
|
48
62
|
return applyDefaults(config);
|
|
49
63
|
}
|
|
50
64
|
/**
|
|
51
|
-
*
|
|
65
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
52
66
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
67
|
+
* Defaults applied when omitted:
|
|
68
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
69
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
70
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
71
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
72
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
73
|
+
* in the plugins list.
|
|
74
|
+
* - `output.format` and `output.lint` → `false`.
|
|
55
75
|
*
|
|
56
|
-
* Accepts
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* receiving the CLI options as argument
|
|
76
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
77
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
78
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
60
79
|
*
|
|
61
80
|
* @example
|
|
62
81
|
* ```ts
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
82
|
+
* import { defineConfig } from 'kubb'
|
|
83
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
84
|
+
*
|
|
85
|
+
* export default defineConfig({
|
|
86
|
+
* input: { path: './petStore.yaml' },
|
|
87
|
+
* output: { path: './src/gen' },
|
|
88
|
+
* plugins: [pluginTs()],
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example Function form with CLI options
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { defineConfig } from 'kubb'
|
|
95
|
+
*
|
|
96
|
+
* export default defineConfig(({ input }) => ({
|
|
97
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
98
|
+
* output: { path: './src/gen' },
|
|
99
|
+
* plugins: [],
|
|
66
100
|
* }))
|
|
67
101
|
* ```
|
|
68
102
|
*/
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,IAAA,GAAA,oBAAA,aAAA,CAAiB,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,YAAA,GAAA,kBAAA,WAAA,CAAsB;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAACC,gBAAAA;GAAUC,gBAAAA;GAAWC,gBAAAA;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as __name } from "./
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { CLIOptions, UserConfig } from "@kubb/core";
|
|
3
|
+
import { BarrelType } from "@kubb/plugin-barrel";
|
|
3
4
|
|
|
4
5
|
//#region ../../internals/utils/src/promise.d.ts
|
|
5
6
|
/** A value that may already be resolved or still pending.
|
|
@@ -19,25 +20,45 @@ type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOption
|
|
|
19
20
|
type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
|
|
20
21
|
type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOptions) => PossiblePromise<infer TResult>) ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>> : TConfig extends Promise<infer TResult> ? Promise<NormalizeConfig<TResult>> : NormalizeConfig<TConfig>;
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* Defaults applied when omitted:
|
|
26
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
27
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
28
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
29
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
30
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
31
|
+
* in the plugins list.
|
|
32
|
+
* - `output.format` and `output.lint` → `false`.
|
|
26
33
|
*
|
|
27
|
-
* Accepts
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* receiving the CLI options as argument
|
|
34
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
35
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
36
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
31
37
|
*
|
|
32
38
|
* @example
|
|
33
39
|
* ```ts
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
40
|
+
* import { defineConfig } from 'kubb'
|
|
41
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
42
|
+
*
|
|
43
|
+
* export default defineConfig({
|
|
44
|
+
* input: { path: './petStore.yaml' },
|
|
45
|
+
* output: { path: './src/gen' },
|
|
46
|
+
* plugins: [pluginTs()],
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Function form with CLI options
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { defineConfig } from 'kubb'
|
|
53
|
+
*
|
|
54
|
+
* export default defineConfig(({ input }) => ({
|
|
55
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
56
|
+
* output: { path: './src/gen' },
|
|
57
|
+
* plugins: [],
|
|
37
58
|
* }))
|
|
38
59
|
* ```
|
|
39
60
|
*/
|
|
40
61
|
declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
|
|
41
62
|
//#endregion
|
|
42
|
-
export { defineConfig };
|
|
63
|
+
export { type BarrelType, defineConfig };
|
|
43
64
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import "./
|
|
1
|
+
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { adapterOas } from "@kubb/adapter-oas";
|
|
3
|
-
import {
|
|
3
|
+
import { cliReporter, fileReporter, jsonReporter } from "@kubb/core";
|
|
4
|
+
import { pluginBarrel, pluginBarrelName } from "@kubb/plugin-barrel";
|
|
4
5
|
import { parserTs, parserTsx } from "@kubb/parser-ts";
|
|
6
|
+
import { parserMd } from "@kubb/parser-md";
|
|
5
7
|
//#region ../../internals/utils/src/promise.ts
|
|
6
8
|
/** Returns `true` when `result` is a thenable `Promise`.
|
|
7
9
|
*
|
|
@@ -17,28 +19,40 @@ function isPromise(result) {
|
|
|
17
19
|
//#endregion
|
|
18
20
|
//#region src/defineConfig.ts
|
|
19
21
|
/**
|
|
20
|
-
* Applies default adapter, parsers,
|
|
22
|
+
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
21
23
|
*
|
|
24
|
+
* - `root` defaults to `process.cwd()`
|
|
22
25
|
* - `adapter` defaults to `adapterOas()`
|
|
23
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
24
|
-
* - `
|
|
25
|
-
* - `
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* - `output.
|
|
26
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
|
+
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
+
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
30
|
+
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
31
|
+
* - `output.format` defaults to `false`
|
|
32
|
+
* - `output.lint` defaults to `false`
|
|
29
33
|
*/
|
|
30
34
|
function applyDefaults(config) {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
35
|
+
const plugins = config.plugins?.some((p) => p.name === pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], pluginBarrel()];
|
|
36
|
+
const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName);
|
|
33
37
|
const output = { ...config.output };
|
|
34
|
-
if (
|
|
38
|
+
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
35
39
|
if (output.format === void 0) output.format = false;
|
|
36
40
|
if (output.lint === void 0) output.lint = false;
|
|
37
41
|
return {
|
|
38
42
|
...config,
|
|
43
|
+
root: config.root || process.cwd(),
|
|
39
44
|
adapter: config.adapter ?? adapterOas(),
|
|
40
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
41
|
-
|
|
45
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
46
|
+
parserTs,
|
|
47
|
+
parserTsx,
|
|
48
|
+
parserMd
|
|
49
|
+
],
|
|
50
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
51
|
+
cliReporter,
|
|
52
|
+
jsonReporter,
|
|
53
|
+
fileReporter
|
|
54
|
+
],
|
|
55
|
+
plugins,
|
|
42
56
|
output
|
|
43
57
|
};
|
|
44
58
|
}
|
|
@@ -47,21 +61,41 @@ function normalizeConfig(config) {
|
|
|
47
61
|
return applyDefaults(config);
|
|
48
62
|
}
|
|
49
63
|
/**
|
|
50
|
-
*
|
|
64
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
51
65
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
66
|
+
* Defaults applied when omitted:
|
|
67
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
68
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
72
|
+
* in the plugins list.
|
|
73
|
+
* - `output.format` and `output.lint` → `false`.
|
|
54
74
|
*
|
|
55
|
-
* Accepts
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* receiving the CLI options as argument
|
|
75
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
76
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
77
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
59
78
|
*
|
|
60
79
|
* @example
|
|
61
80
|
* ```ts
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
81
|
+
* import { defineConfig } from 'kubb'
|
|
82
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
83
|
+
*
|
|
84
|
+
* export default defineConfig({
|
|
85
|
+
* input: { path: './petStore.yaml' },
|
|
86
|
+
* output: { path: './src/gen' },
|
|
87
|
+
* plugins: [pluginTs()],
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Function form with CLI options
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { defineConfig } from 'kubb'
|
|
94
|
+
*
|
|
95
|
+
* export default defineConfig(({ input }) => ({
|
|
96
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
97
|
+
* output: { path: './src/gen' },
|
|
98
|
+
* plugins: [],
|
|
65
99
|
* }))
|
|
66
100
|
* ```
|
|
67
101
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAAS,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,aAAa,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAAS,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,WAAW,WAAW;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC;GAAU;GAAW;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubb",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "Meta-package and entry point for Kubb
|
|
3
|
+
"version": "5.0.0-beta.70",
|
|
4
|
+
"description": "Meta-package and entry point for Kubb, the meta framework for code generation. Bundles defineConfig and all public APIs into a single install.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
7
7
|
"code-generator",
|
|
@@ -10,11 +10,9 @@
|
|
|
10
10
|
"kubb",
|
|
11
11
|
"meta-framework",
|
|
12
12
|
"msw",
|
|
13
|
-
"openapi",
|
|
14
13
|
"plugin-system",
|
|
15
14
|
"react-query",
|
|
16
15
|
"sdk-generator",
|
|
17
|
-
"swagger",
|
|
18
16
|
"tanstack-query",
|
|
19
17
|
"typescript",
|
|
20
18
|
"zod"
|
|
@@ -30,7 +28,6 @@
|
|
|
30
28
|
"kubb": "bin/kubb.js"
|
|
31
29
|
},
|
|
32
30
|
"files": [
|
|
33
|
-
"src",
|
|
34
31
|
"dist",
|
|
35
32
|
"bin",
|
|
36
33
|
"!/**/**.test.**",
|
|
@@ -54,47 +51,31 @@
|
|
|
54
51
|
"registry": "https://registry.npmjs.org/"
|
|
55
52
|
},
|
|
56
53
|
"dependencies": {
|
|
57
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
58
|
-
"@kubb/cli": "5.0.0-beta.
|
|
59
|
-
"@kubb/core": "5.0.0-beta.
|
|
60
|
-
"@kubb/
|
|
61
|
-
"@kubb/parser-
|
|
62
|
-
"@kubb/
|
|
54
|
+
"@kubb/adapter-oas": "5.0.0-beta.70",
|
|
55
|
+
"@kubb/cli": "5.0.0-beta.70",
|
|
56
|
+
"@kubb/core": "5.0.0-beta.70",
|
|
57
|
+
"@kubb/mcp": "5.0.0-beta.70",
|
|
58
|
+
"@kubb/parser-md": "5.0.0-beta.70",
|
|
59
|
+
"@kubb/parser-ts": "5.0.0-beta.70",
|
|
60
|
+
"@kubb/plugin-barrel": "5.0.0-beta.70",
|
|
61
|
+
"@kubb/renderer-jsx": "5.0.0-beta.70"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
64
|
"typescript": "^6.0.3",
|
|
66
65
|
"@internals/utils": "0.0.0"
|
|
67
66
|
},
|
|
68
|
-
"peerDependencies": {
|
|
69
|
-
"@kubb/agent": "5.0.0-beta.7",
|
|
70
|
-
"@kubb/mcp": "5.0.0-beta.7"
|
|
71
|
-
},
|
|
72
|
-
"peerDependenciesMeta": {
|
|
73
|
-
"@kubb/agent": {
|
|
74
|
-
"optional": true
|
|
75
|
-
},
|
|
76
|
-
"@kubb/mcp": {
|
|
77
|
-
"optional": true
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"size-limit": [
|
|
81
|
-
{
|
|
82
|
-
"path": "./dist/*.js",
|
|
83
|
-
"limit": "510 KiB",
|
|
84
|
-
"gzip": true
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
67
|
"preferGlobal": true,
|
|
88
68
|
"engines": {
|
|
89
69
|
"node": ">=22"
|
|
90
70
|
},
|
|
91
71
|
"scripts": {
|
|
92
72
|
"build": "tsdown",
|
|
93
|
-
"clean": "
|
|
73
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
94
74
|
"lint": "oxlint .",
|
|
95
75
|
"lint:fix": "oxlint --fix .",
|
|
96
76
|
"release": "pnpm publish --no-git-check",
|
|
97
77
|
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
78
|
+
"release:stage": "pnpm stage publish --no-git-check",
|
|
98
79
|
"start": "tsdown --watch",
|
|
99
80
|
"test": "vitest --passWithNoTests",
|
|
100
81
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/src/defineConfig.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { isPromise, type PossiblePromise } from '@internals/utils'
|
|
2
|
-
import { adapterOas } from '@kubb/adapter-oas'
|
|
3
|
-
import type { CLIOptions, UserConfig } from '@kubb/core'
|
|
4
|
-
import { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'
|
|
5
|
-
import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
6
|
-
|
|
7
|
-
type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>
|
|
8
|
-
type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)
|
|
9
|
-
type NormalizeConfig<TConfig> =
|
|
10
|
-
TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never
|
|
11
|
-
type DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>
|
|
12
|
-
? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>
|
|
13
|
-
: TConfig extends Promise<infer TResult>
|
|
14
|
-
? Promise<NormalizeConfig<TResult>>
|
|
15
|
-
: NormalizeConfig<TConfig>
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
19
|
-
*
|
|
20
|
-
* - `adapter` defaults to `adapterOas()`
|
|
21
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
22
|
-
* - `middleware` defaults to `[middlewareBarrel()]`
|
|
23
|
-
* - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
|
|
24
|
-
* When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
|
|
25
|
-
* - `output.format` defaults to `'auto'`
|
|
26
|
-
* - `output.lint` defaults to `'auto'`
|
|
27
|
-
*/
|
|
28
|
-
function applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {
|
|
29
|
-
const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]
|
|
30
|
-
const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)
|
|
31
|
-
|
|
32
|
-
const output = { ...config.output }
|
|
33
|
-
if (hasBarrelMiddleware && output.barrel === undefined) {
|
|
34
|
-
output.barrel = { type: 'named' }
|
|
35
|
-
}
|
|
36
|
-
if (output.format === undefined) {
|
|
37
|
-
output.format = false
|
|
38
|
-
}
|
|
39
|
-
if (output.lint === undefined) {
|
|
40
|
-
output.lint = false
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
...config,
|
|
45
|
-
adapter: config.adapter ?? adapterOas(),
|
|
46
|
-
parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],
|
|
47
|
-
middleware,
|
|
48
|
-
output,
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {
|
|
53
|
-
if (Array.isArray(config)) {
|
|
54
|
-
return config.map(applyDefaults)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return applyDefaults(config)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Helper for defining a Kubb configuration with built-in defaults.
|
|
62
|
-
*
|
|
63
|
-
* When no `adapter` is provided, `adapterOas()` is used automatically.
|
|
64
|
-
* When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
|
|
65
|
-
*
|
|
66
|
-
* Accepts either:
|
|
67
|
-
* - A config object or array of configs
|
|
68
|
-
* - A function returning the config(s), optionally async,
|
|
69
|
-
* receiving the CLI options as argument
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* export default defineConfig(({ logLevel }) => ({
|
|
74
|
-
* root: 'src',
|
|
75
|
-
* plugins: [myPlugin()],
|
|
76
|
-
* }))
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {
|
|
80
|
-
if (typeof config === 'function') {
|
|
81
|
-
return (async (cli: CLIOptions) => {
|
|
82
|
-
return normalizeConfig(await config(cli))
|
|
83
|
-
}) as DefinedConfig<TConfig>
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (isPromise(config)) {
|
|
87
|
-
return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return normalizeConfig(config) as DefinedConfig<TConfig>
|
|
91
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { defineConfig } from './defineConfig.ts'
|
|
File without changes
|