kubb 5.0.0-beta.75 → 5.0.0-beta.77

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 CHANGED
@@ -1,14 +1,21 @@
1
- Copyright (c) 2026 Stijn Van Hulle
2
-
3
- This repository contains software under two licenses:
1
+ MIT License
4
2
 
5
- 1. Most of the code in this repository is licensed under the
6
- MIT License — see licenses/LICENSE-MIT for the full license text.
3
+ Copyright (c) 2026 Stijn Van Hulle
7
4
 
8
- 2. The following components are licensed under the
9
- GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
10
- see licenses/LICENSE-AGPL-3.0 for the full license text:
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
- - packages/agent (published as @kubb/agent)
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
- Each package's own LICENSE file or package.json specifies its applicable license.
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,18 @@
1
1
  <div align="center">
2
2
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
3
- <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
4
4
  </a>
5
5
 
6
6
  [![npm version][npm-version-src]][npm-version-href]
7
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
8
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
9
9
  [![License][license-src]][license-href]
10
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Coverage][coverage-src]][coverage-href]
11
+ [![Node][node-src]][node-href]
12
+ [![OC Backers][oc-backers-src]][oc-backers-href]
11
13
 
12
14
  <h4>
13
- <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main/examples/typescript" target="_blank">View Demo</a>
14
- <span> · </span>
15
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
15
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
16
16
  <span> · </span>
17
17
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
18
18
  <span> · </span>
@@ -22,28 +22,74 @@
22
22
 
23
23
  <br />
24
24
 
25
+ # Kubb
26
+
27
+ ### The meta framework for code generation
28
+
29
+ Point Kubb at a schema and it generates types, clients, hooks, validators, mocks, and more.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ bun add kubb
35
+ # or
36
+ pnpm add kubb
37
+ # or
38
+ npm install kubb
39
+ ```
40
+
41
+ ## Quick start
42
+
43
+ Run the setup wizard to create a `kubb.config.ts`:
44
+
45
+ ```bash
46
+ npx kubb init
47
+ ```
48
+
49
+ The wizard creates a `package.json` if needed, guides you through plugin selection, installs packages, and writes `kubb.config.ts`. Then generate your code:
50
+
51
+ ```bash
52
+ npx kubb generate
53
+ ```
54
+
55
+ See the [documentation](https://kubb.dev) for detailed usage and advanced features.
56
+
25
57
  ## Features
26
58
 
27
- - Works with Node.js 22+ and TypeScript 6.
28
- - Convert Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1 to TypeScript types, API clients, and more via the [plugin ecosystem](https://github.com/kubb-labs/kubb-plugins).
29
- - Extensible plugin and middleware system for customizing and composing code generation.
30
- - CLI support with interactive setup, progress bar, and detailed logs.
31
- - Model Context Protocol (MCP) server for AI assistants like [Claude](https://claude.ai), [Cursor](https://cursor.sh), and other MCP-compatible tools.
32
- - JSX-based renderer (`@kubb/renderer-jsx`) for building custom plugin output.
33
- - Barrel file generation via the `@kubb/middleware-barrel` middleware.
59
+ - 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.
60
+ - 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.
61
+ - Pick what you generate from the [plugin ecosystem](https://github.com/kubb-labs/plugins): `plugin-ts`, `plugin-axios`, `plugin-fetch`, `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.
62
+ - 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.
63
+ - Control the generated tree: group files by tag, emit barrel exports, and include or exclude operations to keep the output focused.
64
+ - Build your own output with custom plugins, adapters, and the JSX-based renderer (`@kubb/renderer-jsx`) for full control over what lands on disk.
65
+ - 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.
66
+ - 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.
67
+ - 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.
34
68
 
35
69
  ## Supporting Kubb
36
70
 
37
- Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
71
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
38
72
 
39
73
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
74
+ - [Back Kubb on Open Collective](https://opencollective.com/kubb)
75
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
40
76
 
41
77
  <p align="center">
42
78
  <a href="https://github.com/sponsors/stijnvanhulle">
43
- <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
79
+ <img src="https://shieldcn.dev/sponsors/stijnvanhulle.svg?titleAlign=center&mode=dark" alt="stijnvanhulle sponsors" width="100%" />
44
80
  </a>
45
81
  </p>
46
82
 
83
+ ## Contributing
84
+
85
+ We welcome contributions that help improve Kubb. A few ways to get involved:
86
+
87
+ - Found a bug? File it in the [issue tracker](https://github.com/kubb-labs/kubb/issues).
88
+ - Have an idea to improve Kubb? [Open an issue](https://github.com/kubb-labs/kubb/issues/new) to share it.
89
+ - Need help? Ask the community on [Discord](https://discord.gg/4dQjA6vrWX).
90
+
91
+ See [CONTRIBUTING.md](https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md) for the project structure, local setup, and commands.
92
+
47
93
  ## Contributors [![Contributors][contributors-src]][contributors-href]
48
94
 
49
95
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
@@ -53,55 +99,73 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
53
99
  <tbody>
54
100
  <tr>
55
101
  <td align="center" valign="top" width="14.28%"><a href="http://www.stijnvanhulle.be"><img src="https://avatars.githubusercontent.com/u/5904681?v=4?s=100" width="100px;" alt="Stijn Van Hulle"/><br /><sub><b>Stijn Van Hulle</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=stijnvanhulle" title="Code">💻</a></td>
56
- <td align="center" valign="top" width="14.28%"><a href="https://fosstodon.org/@xphentom"><img src="https://avatars.githubusercontent.com/u/5096867?v=4?s=100" width="100px;" alt="Wouter Roozeleer"/><br /><sub><b>Wouter Roozeleer</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=xPhentom" title="Code">💻</a></td>
57
102
  <td align="center" valign="top" width="14.28%"><a href="https://aluc.io/"><img src="https://avatars.githubusercontent.com/u/15520015?v=4?s=100" width="100px;" alt="Alfred"/><br /><sub><b>Alfred</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=b6pzeusbc54tvhw5jgpyw8pwz2x6gs" title="Code">💻</a></td>
58
103
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/raveclassic"><img src="https://avatars.githubusercontent.com/u/1743568?v=4?s=100" width="100px;" alt="Kirill Agalakov"/><br /><sub><b>Kirill Agalakov</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=raveclassic" title="Code">💻</a></td>
59
104
  <td align="center" valign="top" width="14.28%"><a href="http://wicky.nillia.ms"><img src="https://avatars.githubusercontent.com/u/1091390?v=4?s=100" width="100px;" alt="Nick Williams"/><br /><sub><b>Nick Williams</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=WickyNilliams" title="Documentation">📖</a></td>
60
105
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/helt"><img src="https://avatars.githubusercontent.com/u/1732112?v=4?s=100" width="100px;" alt="helt"/><br /><sub><b>helt</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=helt" title="Code">💻</a></td>
61
106
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/Ti-webdev"><img src="https://avatars.githubusercontent.com/u/478565?v=4?s=100" width="100px;" alt="Vasily Mikhaylovsky"/><br /><sub><b>Vasily Mikhaylovsky</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=Ti-webdev" title="Code">💻</a></td>
107
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/chiptus"><img src="https://avatars.githubusercontent.com/u/1381655?v=4?s=100" width="100px;" alt="Chaim Lev-Ari"/><br /><sub><b>Chaim Lev-Ari</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=chiptus" title="Code">💻</a></td>
62
108
  </tr>
63
109
  <tr>
64
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/chiptus"><img src="https://avatars.githubusercontent.com/u/1381655?v=4?s=100" width="100px;" alt="Chaim Lev-Ari"/><br /><sub><b>Chaim Lev-Ari</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=chiptus" title="Code">💻</a></td>
65
110
  <td align="center" valign="top" width="14.28%"><a href="http://projects.pafnuty.name"><img src="https://avatars.githubusercontent.com/u/1635679?v=4?s=100" width="100px;" alt="Pavel Belousov"/><br /><sub><b>Pavel Belousov</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=pafnuty" title="Code">💻</a></td>
66
111
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/dmitry-blackwave"><img src="https://avatars.githubusercontent.com/u/5526543?v=4?s=100" width="100px;" alt="Dmitry Belov"/><br /><sub><b>Dmitry Belov</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=dmitry-blackwave" title="Code">💻</a></td>
67
112
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/aburgel"><img src="https://avatars.githubusercontent.com/u/341478?v=4?s=100" width="100px;" alt="Alex Burgel"/><br /><sub><b>Alex Burgel</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=aburgel" title="Code">💻</a></td>
68
113
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/dgarciamuria"><img src="https://avatars.githubusercontent.com/u/8144333?v=4?s=100" width="100px;" alt="Daniel Garcia"/><br /><sub><b>Daniel Garcia</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=dgarciamuria" title="Code">💻</a></td>
69
114
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/wuyuanyi135"><img src="https://avatars.githubusercontent.com/u/11760870?v=4?s=100" width="100px;" alt="wuyuanyi135"/><br /><sub><b>wuyuanyi135</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=wuyuanyi135" title="Code">💻</a></td>
70
115
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/cjthompson"><img src="https://avatars.githubusercontent.com/u/1958266?v=4?s=100" width="100px;" alt="Chris Thompson"/><br /><sub><b>Chris Thompson</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=cjthompson" title="Code">💻</a></td>
116
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/hkang1"><img src="https://avatars.githubusercontent.com/u/220971?v=4?s=100" width="100px;" alt="Caleb Hoyoul Kang"/><br /><sub><b>Caleb Hoyoul Kang</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=hkang1" title="Code">💻</a></td>
71
117
  </tr>
72
118
  <tr>
73
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/hkang1"><img src="https://avatars.githubusercontent.com/u/220971?v=4?s=100" width="100px;" alt="Caleb Hoyoul Kang"/><br /><sub><b>Caleb Hoyoul Kang</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=hkang1" title="Code">💻</a></td>
74
119
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/grreeenn"><img src="https://avatars.githubusercontent.com/u/13204857?v=4?s=100" width="100px;" alt="Gregory Zhukovsky"/><br /><sub><b>Gregory Zhukovsky</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=grreeenn" title="Code">💻</a></td>
75
120
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/ChilloManiac"><img src="https://avatars.githubusercontent.com/u/3761964?v=4?s=100" width="100px;" alt="Christoffer Nørbjerg"/><br /><sub><b>Christoffer Nørbjerg</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=ChilloManiac" title="Code">💻</a></td>
76
121
  <td align="center" valign="top" width="14.28%"><a href="https://codefy.de/de/karriere"><img src="https://avatars.githubusercontent.com/u/122524301?v=4?s=100" width="100px;" alt="CHE1RON"/><br /><sub><b>CHE1RON</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=CHE1RON" title="Code">💻</a></td>
77
122
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/ekaradon"><img src="https://avatars.githubusercontent.com/u/9439390?v=4?s=100" width="100px;" alt="ekaradon"/><br /><sub><b>ekaradon</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=ekaradon" title="Code">💻</a></td>
78
123
  <td align="center" valign="top" width="14.28%"><a href="https://thijmen.dev"><img src="https://avatars.githubusercontent.com/u/383903?v=4?s=100" width="100px;" alt="Thijmen Stavenuiter"/><br /><sub><b>Thijmen Stavenuiter</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=Thijmen" title="Code">💻</a></td>
79
124
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/bohdanhusak"><img src="https://avatars.githubusercontent.com/u/13829370?v=4?s=100" width="100px;" alt="Bohdan Husak"/><br /><sub><b>Bohdan Husak</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=bohdanhusak" title="Documentation">📖</a></td>
125
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Ericlm"><img src="https://avatars.githubusercontent.com/u/19361503?v=4?s=100" width="100px;" alt="Éric Le Maître"/><br /><sub><b>Éric Le Maître</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=Ericlm" title="Code">💻</a></td>
80
126
  </tr>
81
127
  <tr>
82
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Ericlm"><img src="https://avatars.githubusercontent.com/u/19361503?v=4?s=100" width="100px;" alt="Éric Le Maître"/><br /><sub><b>Éric Le Maître</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=Ericlm" title="Code">💻</a></td>
83
128
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/chambber"><img src="https://avatars.githubusercontent.com/u/11406841?v=4?s=100" width="100px;" alt="Rubens Pereira do Nascimento"/><br /><sub><b>Rubens Pereira do Nascimento</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=chambber" title="Code">💻</a></td>
84
129
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/msutkowski"><img src="https://avatars.githubusercontent.com/u/784953?v=4?s=100" width="100px;" alt="Matt Sutkowski"/><br /><sub><b>Matt Sutkowski</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=msutkowski" title="Code">💻</a></td>
85
130
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/vitorcamachoo"><img src="https://avatars.githubusercontent.com/u/20595956?v=4?s=100" width="100px;" alt="Vítor Camacho"/><br /><sub><b>Vítor Camacho</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=vitorcamachoo" title="Code">💻</a></td>
86
131
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/VasekProchazka"><img src="https://avatars.githubusercontent.com/u/13906845?v=4?s=100" width="100px;" alt="Václav Procházka"/><br /><sub><b>Václav Procházka</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=VasekProchazka" title="Code">💻</a></td>
87
132
  <td align="center" valign="top" width="14.28%"><a href="https://codx.dev"><img src="https://avatars.githubusercontent.com/u/59735735?v=4?s=100" width="100px;" alt="Luiz Bett"/><br /><sub><b>Luiz Bett</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=heyBett" title="Code">💻</a></td>
88
133
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/lambdank"><img src="https://avatars.githubusercontent.com/u/5475129?v=4?s=100" width="100px;" alt="Sebastian Andersen"/><br /><sub><b>Sebastian Andersen</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=lambdank" title="Code">💻</a></td>
134
+ <td align="center" valign="top" width="14.28%"><a href="https://akino.icu"><img src="https://avatars.githubusercontent.com/u/64176534?v=4?s=100" width="100px;" alt="Akino"/><br /><sub><b>Akino</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=akinoccc" title="Code">💻</a></td>
89
135
  </tr>
90
136
  <tr>
91
- <td align="center" valign="top" width="14.28%"><a href="https://akino.icu"><img src="https://avatars.githubusercontent.com/u/64176534?v=4?s=100" width="100px;" alt="Akino"/><br /><sub><b>Akino</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=akinoccc" title="Code">💻</a></td>
92
137
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/rmachado-studocu"><img src="https://avatars.githubusercontent.com/u/89906313?v=4?s=100" width="100px;" alt="Ricardo Machado"/><br /><sub><b>Ricardo Machado</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=rmachado-studocu" title="Code">💻</a></td>
93
138
  <td align="center" valign="top" width="14.28%"><a href="http://simonelnahas.com"><img src="https://avatars.githubusercontent.com/u/29279201?v=4?s=100" width="100px;" alt="Simon El Nahas"/><br /><sub><b>Simon El Nahas</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=simonelnahas" title="Documentation">📖</a></td>
94
139
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/maartenvansambeek"><img src="https://avatars.githubusercontent.com/u/91739524?v=4?s=100" width="100px;" alt="maartenvansambeek"/><br /><sub><b>maartenvansambeek</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=maartenvansambeek" title="Code">💻</a></td>
95
140
  <td align="center" valign="top" width="14.28%"><a href="https://sdufresne.info"><img src="https://avatars.githubusercontent.com/u/583851?v=4?s=100" width="100px;" alt="Stefan du Fresne"/><br /><sub><b>Stefan du Fresne</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=SCdF" title="Code">💻</a></td>
96
141
  <td align="center" valign="top" width="14.28%"><a href="https://hugofelippe.github.io/"><img src="https://avatars.githubusercontent.com/u/19368365?v=4?s=100" width="100px;" alt="Hugo Felippe de Souza Cruz"/><br /><sub><b>Hugo Felippe de Souza Cruz</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=hugoFelippe" title="Code">💻</a></td>
97
142
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/belgattitude"><img src="https://avatars.githubusercontent.com/u/259798?v=4?s=100" width="100px;" alt="Sébastien Vanvelthem"/><br /><sub><b>Sébastien Vanvelthem</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=belgattitude" title="Code">💻</a></td>
143
+ <td align="center" valign="top" width="14.28%"><a href="http://bento.me/vitalygashkov"><img src="https://avatars.githubusercontent.com/u/30000398?v=4?s=100" width="100px;" alt="Vitaly Gashkov"/><br /><sub><b>Vitaly Gashkov</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=vitalygashkov" title="Documentation">📖</a></td>
98
144
  </tr>
99
145
  <tr>
100
- <td align="center" valign="top" width="14.28%"><a href="http://bento.me/vitalygashkov"><img src="https://avatars.githubusercontent.com/u/30000398?v=4?s=100" width="100px;" alt="Vitaly Gashkov"/><br /><sub><b>Vitaly Gashkov</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=vitalygashkov" title="Documentation">📖</a></td>
101
146
  <td align="center" valign="top" width="14.28%"><a href="https://ducduc.nl"><img src="https://avatars.githubusercontent.com/u/9675738?v=4?s=100" width="100px;" alt="Duco Drupsteen"/><br /><sub><b>Duco Drupsteen</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=ducodrupsteen" title="Code">💻</a></td>
102
147
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/th3l0g4n"><img src="https://avatars.githubusercontent.com/u/326306?v=4?s=100" width="100px;" alt="th3l0g4n"/><br /><sub><b>th3l0g4n</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=th3l0g4n" title="Code">💻</a></td>
103
148
  <td align="center" valign="top" width="14.28%"><a href="https://rxliuli.com"><img src="https://avatars.githubusercontent.com/u/24560368?v=4?s=100" width="100px;" alt="rxliuli"/><br /><sub><b>rxliuli</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=rxliuli" title="Code">💻</a></td>
104
149
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/humarkx"><img src="https://avatars.githubusercontent.com/u/13049940?v=4?s=100" width="100px;" alt="humarkx"/><br /><sub><b>humarkx</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=humarkx" title="Code">💻</a></td>
150
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Jakub-Cerovsky"><img src="https://avatars.githubusercontent.com/u/141134227?v=4?s=100" width="100px;" alt="Jakub Cerovsky"/><br /><sub><b>Jakub Cerovsky</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=Jakub-Cerovsky" title="Code">💻</a></td>
151
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/yukikwi"><img src="https://avatars.githubusercontent.com/u/66879660?v=4?s=100" width="100px;" alt="Pachara Chantawong"/><br /><sub><b>Pachara Chantawong</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=yukikwi" title="Code">💻</a></td>
152
+ <td align="center" valign="top" width="14.28%"><a href="https://volodymyrkushnir.dev/"><img src="https://avatars.githubusercontent.com/u/10290626?v=4?s=100" width="100px;" alt="Volodymyr Kushnir"/><br /><sub><b>Volodymyr Kushnir</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=volodymyr-kushnir" title="Code">💻</a></td>
153
+ </tr>
154
+ <tr>
155
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/GKNewsrooms"><img src="https://avatars.githubusercontent.com/u/201248633?v=4?s=100" width="100px;" alt="GKNewsrooms"/><br /><sub><b>GKNewsrooms</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=GKNewsrooms" title="Code">💻</a></td>
156
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/stepek"><img src="https://avatars.githubusercontent.com/u/5058678?v=4?s=100" width="100px;" alt="Kamil Stepczuk"/><br /><sub><b>Kamil Stepczuk</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=stepek" title="Code">💻</a></td>
157
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/JoaoBrlt"><img src="https://avatars.githubusercontent.com/u/11065509?v=4?s=100" width="100px;" alt="João Brilhante"/><br /><sub><b>João Brilhante</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=JoaoBrlt" title="Code">💻</a></td>
158
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/kamilzki"><img src="https://avatars.githubusercontent.com/u/27976736?v=4?s=100" width="100px;" alt="Kamil Sieradzki"/><br /><sub><b>Kamil Sieradzki</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=kamilzki" title="Code">💻</a></td>
159
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/EricPierlotIdmog"><img src="https://avatars.githubusercontent.com/u/124898024?v=4?s=100" width="100px;" alt="Eric Pierlot"/><br /><sub><b>Eric Pierlot</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=EricPierlotIdmog" title="Code">💻</a></td>
160
+ <td align="center" valign="top" width="14.28%"><a href="http://atholin.se"><img src="https://avatars.githubusercontent.com/u/33940473?v=4?s=100" width="100px;" alt="Alexander Sjöcrona Tholin"/><br /><sub><b>Alexander Sjöcrona Tholin</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=ATholin" title="Code">💻</a></td>
161
+ <td align="center" valign="top" width="14.28%"><a href="http://hyoban.cc"><img src="https://avatars.githubusercontent.com/u/38493346?v=4?s=100" width="100px;" alt="Stephen Zhou"/><br /><sub><b>Stephen Zhou</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=hyoban" title="Code">💻</a></td>
162
+ </tr>
163
+ <tr>
164
+ <td align="center" valign="top" width="14.28%"><a href="https://choly.ca"><img src="https://avatars.githubusercontent.com/u/943597?v=4?s=100" width="100px;" alt="Ilia Choly"/><br /><sub><b>Ilia Choly</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=icholy" title="Code">💻</a></td>
165
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/skoropadas"><img src="https://avatars.githubusercontent.com/u/20700969?v=4?s=100" width="100px;" alt="Alex Skoropad"/><br /><sub><b>Alex Skoropad</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=skoropadas" title="Code">💻</a></td>
166
+ <td align="center" valign="top" width="14.28%"><a href="https://pateljay.io"><img src="https://avatars.githubusercontent.com/u/36803168?v=4?s=100" width="100px;" alt="Jay Patel"/><br /><sub><b>Jay Patel</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=jay-babu" title="Code">💻</a></td>
167
+ <td align="center" valign="top" width="14.28%"><a href="https://hamzamihaidaniel.com"><img src="https://avatars.githubusercontent.com/u/12731515?v=4?s=100" width="100px;" alt="Hamza Mihai Daniel"/><br /><sub><b>Hamza Mihai Daniel</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=hamzamihaidanielx" title="Code">💻</a></td>
168
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/DesselBane"><img src="https://avatars.githubusercontent.com/u/12199480?v=4?s=100" width="100px;" alt="DesselBane"/><br /><sub><b>DesselBane</b></sub></a><br /><a href="https://github.com/kubb-labs/kubb/commits?author=DesselBane" title="Code">💻</a></td>
105
169
  </tr>
106
170
  </tbody>
107
171
  </table>
@@ -110,39 +174,32 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
110
174
  <!-- prettier-ignore-end -->
111
175
 
112
176
  <!-- ALL-CONTRIBUTORS-LIST:END -->
113
- <!-- prettier-ignore-start -->
114
- <!-- markdownlint-disable -->
115
177
 
116
- <!-- markdownlint-restore -->
117
- <!-- prettier-ignore-end -->
178
+ ## License
118
179
 
119
- <!-- ALL-CONTRIBUTORS-LIST:END -->
180
+ This repository is licensed under the [MIT License](./licenses/LICENSE-MIT), Copyright © 2025 [Stijn Van Hulle](https://stijnvanhulle.be).
181
+
182
+ See [LICENSE](./LICENSE) for details.
120
183
 
121
- ## Star History
184
+ ## Star history
122
185
 
123
- <a href="https://star-history.com/#kubb-labs/kubb&Date">
124
- <picture>
125
- <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=kubb-labs/kubb&type=Date&theme=dark" />
126
- <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=kubb-labs/kubb&type=Date" />
127
- <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=kubb-labs/kubb&type=Date" />
128
- </picture>
129
- </a>
186
+ <img alt="Star history chart" src="https://shieldcn.dev/chart/github/stars/kubb-labs/kubb.svg?theme=orange" width="100%" />
130
187
 
131
188
  <!-- Badges -->
132
189
 
133
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/core?flat&colorA=18181B&colorB=f58517
134
- [npm-version-href]: https://npmjs.com/package/@kubb/core
135
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/core?flat&colorA=18181B&colorB=f58517
136
- [npm-downloads-href]: https://npmjs.com/package/@kubb/core
137
- [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
190
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
191
+ [npm-version-href]: https://npmx.dev/package/kubb
192
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
193
+ [npm-downloads-href]: https://npmx.dev/package/kubb
194
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
195
+ [stars-href]: https://github.com/kubb-labs/kubb
196
+ [license-src]: https://shieldcn.dev/npm/license/kubb.svg?variant=secondary&size=xs&theme=zinc
138
197
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
139
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
140
- [build-href]: https://www.npmjs.com/package/@kubb/core
141
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/core?style=flat&colorA=18181B&colorB=f58517
142
- [minified-href]: https://www.npmjs.com/package/@kubb/core
143
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
144
- [coverage-href]: https://www.npmjs.com/package/@kubb/core
145
- [contributors-src]: https://img.shields.io/github/contributors/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517&label=%20
198
+ [node-src]: https://shieldcn.dev/npm/node/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
199
+ [node-href]: https://npmx.dev/package/kubb
200
+ [contributors-src]: https://shieldcn.dev/github/contributors/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
146
201
  [contributors-href]: #contributors-
147
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
148
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
202
+ [coverage-src]: https://shieldcn.dev/codecov/github/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
203
+ [coverage-href]: https://app.codecov.io/gh/kubb-labs/kubb
204
+ [oc-backers-src]: https://shieldcn.dev/opencollective/backers/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
205
+ [oc-backers-href]: https://opencollective.com/kubb
package/bin/kubb.js CHANGED
@@ -1,4 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import('@kubb/cli').then(({ run }) => {
3
- run(process.argv)
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 _kubb_middleware_barrel = require("@kubb/middleware-barrel");
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, middleware, `output.barrelType`, `output.format`, and `output.lint` to a single user config when not set.
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
- * - `middleware` defaults to `[middlewareBarrel()]`
26
- * - `output.barrelType` defaults to `'named'` **only when `middlewareBarrel` is part of `middleware`**.
27
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrelType` is left untouched.
28
- * - `output.format` defaults to `'auto'`
29
- * - `output.lint` defaults to `'auto'`
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 middleware = config.middleware?.length ? config.middleware : [(0, _kubb_middleware_barrel.middlewareBarrel)()];
33
- const hasBarrelMiddleware = middleware.some((m) => m.name === _kubb_middleware_barrel.middlewareBarrelName);
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 (hasBarrelMiddleware && output.barrelType === void 0) output.barrelType = "named";
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 : [_kubb_parser_ts.parserTs, _kubb_parser_ts.parserTsx],
42
- middleware,
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
- * Helper for defining a Kubb configuration with built-in defaults.
65
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
52
66
  *
53
- * When no `adapter` is provided, `adapterOas()` is used automatically.
54
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
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 either:
57
- * - A config object or array of configs
58
- * - A function returning the config(s), optionally async,
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
- * export default defineConfig(({ logLevel }) => ({
64
- * root: 'src',
65
- * plugins: [myPlugin()],
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
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["middlewareBarrelName","parserTs","parserTsx"],"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/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\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 adapter, parsers, middleware, `output.barrelType`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrelType` defaults to `'named'` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrelType` is left untouched.\n * - `output.format` defaults to `'auto'`\n * - `output.lint` defaults to `'auto'`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && output.barrelType === undefined) {\n output.barrelType = '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 adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n middleware,\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 * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * ```ts\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\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;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;;;;;;ACO3G,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,EAAA,GAAA,wBAAA,mBAAmB,CAAC;CACvF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAASA,wBAAAA,qBAAqB;CAEnF,MAAM,SAAS,EAAE,GAAG,OAAO,QAAQ;AACnC,KAAI,uBAAuB,OAAO,eAAe,KAAA,EAC/C,QAAO,aAAa;AAEtB,KAAI,OAAO,WAAW,KAAA,EACpB,QAAO,SAAS;AAElB,KAAI,OAAO,SAAS,KAAA,EAClB,QAAO,OAAO;AAGhB,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACC,gBAAAA,UAAUC,gBAAAA,UAAU;EACxE;EACA;EACD;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
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,6 +1,6 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { BarrelType } from "@kubb/middleware-barrel";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
3
2
  import { CLIOptions, UserConfig } from "@kubb/core";
3
+ import { BarrelType } from "@kubb/plugin-barrel";
4
4
 
5
5
  //#region ../../internals/utils/src/promise.d.ts
6
6
  /** A value that may already be resolved or still pending.
@@ -20,21 +20,41 @@ type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOption
20
20
  type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
21
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>;
22
22
  /**
23
- * Helper for defining a Kubb configuration with built-in defaults.
23
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
24
24
  *
25
- * When no `adapter` is provided, `adapterOas()` is used automatically.
26
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
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`.
27
33
  *
28
- * Accepts either:
29
- * - A config object or array of configs
30
- * - A function returning the config(s), optionally async,
31
- * 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.
32
37
  *
33
38
  * @example
34
39
  * ```ts
35
- * export default defineConfig(({ logLevel }) => ({
36
- * root: 'src',
37
- * plugins: [myPlugin()],
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: [],
38
58
  * }))
39
59
  * ```
40
60
  */
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
- import "./chunk--u3MIqq1.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  import { adapterOas } from "@kubb/adapter-oas";
3
- import { middlewareBarrel, middlewareBarrelName } from "@kubb/middleware-barrel";
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, middleware, `output.barrelType`, `output.format`, and `output.lint` to a single user config when not set.
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
- * - `middleware` defaults to `[middlewareBarrel()]`
25
- * - `output.barrelType` defaults to `'named'` **only when `middlewareBarrel` is part of `middleware`**.
26
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrelType` is left untouched.
27
- * - `output.format` defaults to `'auto'`
28
- * - `output.lint` defaults to `'auto'`
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 middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()];
32
- const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName);
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 (hasBarrelMiddleware && output.barrelType === void 0) output.barrelType = "named";
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 : [parserTs, parserTsx],
41
- middleware,
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
- * Helper for defining a Kubb configuration with built-in defaults.
64
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
51
65
  *
52
- * When no `adapter` is provided, `adapterOas()` is used automatically.
53
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
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 either:
56
- * - A config object or array of configs
57
- * - A function returning the config(s), optionally async,
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
- * export default defineConfig(({ logLevel }) => ({
63
- * root: 'src',
64
- * plugins: [myPlugin()],
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/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\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 adapter, parsers, middleware, `output.barrelType`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrelType` defaults to `'named'` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrelType` is left untouched.\n * - `output.format` defaults to `'auto'`\n * - `output.lint` defaults to `'auto'`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && output.barrelType === undefined) {\n output.barrelType = '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 adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n middleware,\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 * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * ```ts\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\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;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;;;;;;ACO3G,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,CAAC,kBAAkB,CAAC;CACvF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAAS,qBAAqB;CAEnF,MAAM,SAAS,EAAE,GAAG,OAAO,QAAQ;AACnC,KAAI,uBAAuB,OAAO,eAAe,KAAA,EAC/C,QAAO,aAAa;AAEtB,KAAI,OAAO,WAAW,KAAA,EACpB,QAAO,SAAS;AAElB,KAAI,OAAO,SAAS,KAAA,EAClB,QAAO,OAAO;AAGhB,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACxE;EACA;EACD;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
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,24 +1,17 @@
1
1
  {
2
2
  "name": "kubb",
3
- "version": "5.0.0-beta.75",
4
- "description": "Transform OpenAPI specifications into TypeScript, React-Query, Zod, Faker.js, MSW and more with a plugin-based code generation tool.",
3
+ "version": "5.0.0-beta.77",
4
+ "description": "The meta framework for code generation. Point Kubb at a schema and it generates types, clients, hooks, validators, mocks, and more.",
5
5
  "keywords": [
6
6
  "api-client",
7
- "cli",
8
7
  "code-generator",
9
8
  "codegen",
10
9
  "faker",
11
10
  "kubb",
11
+ "meta-framework",
12
12
  "msw",
13
- "oas",
14
- "openapi",
15
13
  "plugin-system",
16
- "plugins",
17
- "react-query",
18
14
  "sdk-generator",
19
- "swagger",
20
- "tanstack-query",
21
- "type-safe",
22
15
  "typescript",
23
16
  "zod"
24
17
  ],
@@ -33,7 +26,6 @@
33
26
  "kubb": "bin/kubb.js"
34
27
  },
35
28
  "files": [
36
- "src",
37
29
  "dist",
38
30
  "bin",
39
31
  "!/**/**.test.**",
@@ -57,36 +49,31 @@
57
49
  "registry": "https://registry.npmjs.org/"
58
50
  },
59
51
  "dependencies": {
60
- "@kubb/adapter-oas": "5.0.0-beta.75",
61
- "@kubb/agent": "5.0.0-beta.75",
62
- "@kubb/cli": "5.0.0-beta.75",
63
- "@kubb/core": "5.0.0-beta.75",
64
- "@kubb/mcp": "5.0.0-beta.75",
65
- "@kubb/middleware-barrel": "5.0.0-beta.75",
66
- "@kubb/parser-ts": "5.0.0-beta.75"
52
+ "@kubb/adapter-oas": "5.0.0-beta.77",
53
+ "@kubb/cli": "5.0.0-beta.77",
54
+ "@kubb/core": "5.0.0-beta.77",
55
+ "@kubb/mcp": "5.0.0-beta.77",
56
+ "@kubb/parser-md": "5.0.0-beta.77",
57
+ "@kubb/parser-ts": "5.0.0-beta.77",
58
+ "@kubb/plugin-barrel": "5.0.0-beta.77",
59
+ "@kubb/renderer-jsx": "5.0.0-beta.77"
67
60
  },
68
61
  "devDependencies": {
69
62
  "typescript": "^6.0.3",
70
63
  "@internals/utils": "0.0.0"
71
64
  },
72
- "size-limit": [
73
- {
74
- "path": "./dist/*.js",
75
- "limit": "510 KiB",
76
- "gzip": true
77
- }
78
- ],
79
65
  "preferGlobal": true,
80
66
  "engines": {
81
67
  "node": ">=22"
82
68
  },
83
69
  "scripts": {
84
70
  "build": "tsdown",
85
- "clean": "npx rimraf ./dist",
71
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
86
72
  "lint": "oxlint .",
87
73
  "lint:fix": "oxlint --fix .",
88
74
  "release": "pnpm publish --no-git-check",
89
75
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
76
+ "release:stage": "pnpm stage publish --no-git-check",
90
77
  "start": "tsdown --watch",
91
78
  "test": "vitest --passWithNoTests",
92
79
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
@@ -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.barrelType`, `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.barrelType` defaults to `'named'` **only when `middlewareBarrel` is part of `middleware`**.
24
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrelType` 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.barrelType === undefined) {
34
- output.barrelType = '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,2 +0,0 @@
1
- export type { BarrelType } from '@kubb/middleware-barrel'
2
- export { defineConfig } from './defineConfig.ts'