kubb 5.0.0-beta.6 → 5.0.0-beta.60

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,17 +1,14 @@
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]
11
-
12
- ### The meta framework for code generation
13
-
14
- **Stop writing glue code. Define your API once and Kubb generates types, clients, hooks, validators, mocks and more.**
10
+ [![Coverage][coverage-src]][coverage-href]
11
+ [![Node][node-src]][node-href]
15
12
 
16
13
  <h4>
17
14
  <a href="https://kubb.dev" target="_blank">Documentation</a>
@@ -24,30 +21,31 @@
24
21
 
25
22
  <br />
26
23
 
24
+ # Kubb
25
+
26
+ ### The meta framework for code generation
27
+
28
+ Point Kubb at an OpenAPI spec and it generates types, clients, hooks, validators, mocks, and more.
29
+
27
30
  ## Installation
28
31
 
29
32
  ```bash
30
- npm install kubb
33
+ bun add kubb
31
34
  # or
32
35
  pnpm add kubb
36
+ # or
37
+ npm install kubb
33
38
  ```
34
39
 
35
- ## Quick Start
40
+ ## Quick start
36
41
 
37
- Get started with Kubb in seconds:
42
+ Run the setup wizard to create a `kubb.config.ts`:
38
43
 
39
44
  ```bash
40
45
  npx kubb init
41
46
  ```
42
47
 
43
- The interactive setup will:
44
-
45
- - Create a `package.json` (if needed)
46
- - Guide you through plugin selection
47
- - Install packages automatically
48
- - Generate `kubb.config.ts`
49
-
50
- Then generate your code:
48
+ The wizard creates a `package.json` if needed, guides you through plugin selection, installs packages, and writes `kubb.config.ts`. Then generate your code:
51
49
 
52
50
  ```bash
53
51
  npx kubb generate
@@ -57,19 +55,22 @@ See the [documentation](https://kubb.dev) for detailed usage and advanced featur
57
55
 
58
56
  ## Features
59
57
 
60
- - Works with Node.js 22+ and TypeScript 6.
61
- - 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).
62
- - Extensible plugin and middleware system for customizing and composing code generation.
63
- - CLI support with interactive setup, progress bar, and detailed logs.
64
- - Model Context Protocol (MCP) server for AI assistants like [Claude](https://claude.ai), [Cursor](https://cursor.sh), and other MCP-compatible tools.
65
- - JSX-based renderer (`@kubb/renderer-jsx`) for building custom plugin output.
66
- - Barrel file generation via the `@kubb/middleware-barrel` middleware.
58
+ - Generate from a spec: point Kubb at an OpenAPI document and it 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
+ - Read Swagger 2.0, OpenAPI 3.0, and 3.1, 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/kubb-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.
67
67
 
68
68
  ## Supporting Kubb
69
69
 
70
- Kubb is an 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:
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:
71
71
 
72
72
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
73
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
73
74
 
74
75
  <p align="center">
75
76
  <a href="https://github.com/sponsors/stijnvanhulle">
@@ -77,6 +78,16 @@ Kubb is an open source project with its ongoing development made possible entire
77
78
  </a>
78
79
  </p>
79
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
+
80
91
  ## Contributors [![Contributors][contributors-src]][contributors-href]
81
92
 
82
93
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
@@ -164,15 +175,11 @@ Kubb is an open source project with its ongoing development made possible entire
164
175
 
165
176
  ## License
166
177
 
167
- Most of this repository is licensed under the [MIT License](./licenses/LICENSE-MIT), Copyright © 2025 [Stijn Van Hulle](https://stijnvanhulle.be). Some components are licensed
168
- under AGPL-3.0-or-later.
169
-
170
- - **Most packages** — [MIT](./licenses/LICENSE-MIT)
171
- - **`@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).
172
179
 
173
180
  See [LICENSE](./LICENSE) for details.
174
181
 
175
- ## Star History
182
+ ## Star history
176
183
 
177
184
  <a href="https://star-history.com/#kubb-labs/kubb&Date">
178
185
  <picture>
@@ -184,19 +191,17 @@ See [LICENSE](./LICENSE) for details.
184
191
 
185
192
  <!-- Badges -->
186
193
 
187
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/core?flat&colorA=18181B&colorB=f58517
188
- [npm-version-href]: https://npmx.dev/package/@kubb/core
189
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/core?flat&colorA=18181B&colorB=f58517
190
- [npm-downloads-href]: https://npmjs.com/package/@kubb/core
191
- [license-src]: https://img.shields.io/npm/l/%40kubb%2Fcore?flat&colorA=18181B&colorB=f58517
192
- [license-href]: https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT
193
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
194
- [build-href]: https://www.npmjs.com/package/@kubb/core
195
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/core?style=flat&colorA=18181B&colorB=f58517
196
- [minified-href]: https://www.npmjs.com/package/@kubb/core
197
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
198
- [coverage-href]: https://www.npmjs.com/package/@kubb/core
199
- [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
200
205
  [contributors-href]: #contributors-
201
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
202
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
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/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.barrel`, `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.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
27
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` 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.barrel === void 0) output.barrel = { type: "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,42 @@ 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 so a minimal config
66
+ * stays small.
52
67
  *
53
- * When no `adapter` is provided, `adapterOas()` is used automatically.
54
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
68
+ * Defaults applied when omitted:
69
+ * - `adapter` `adapterOas()` (OpenAPI 2.0/3.0/3.1).
70
+ * - `parsers` → `[parserTs, parserTsx, parserMd]`.
71
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
72
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
73
+ * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
74
+ * in the plugins list.
75
+ * - `output.format` and `output.lint` → `false`.
55
76
  *
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
77
+ * Accepts a config object, an array of configs, a Promise resolving to one,
78
+ * or a function that receives the parsed CLI options and returns any of the
79
+ * above. The return type is preserved so async/array variants stay typed.
60
80
  *
61
81
  * @example
62
82
  * ```ts
63
- * export default defineConfig(({ logLevel }) => ({
64
- * root: 'src',
65
- * plugins: [myPlugin()],
83
+ * import { defineConfig } from 'kubb'
84
+ * import { pluginTs } from '@kubb/plugin-ts'
85
+ *
86
+ * export default defineConfig({
87
+ * input: { path: './petStore.yaml' },
88
+ * output: { path: './src/gen' },
89
+ * plugins: [pluginTs()],
90
+ * })
91
+ * ```
92
+ *
93
+ * @example Function form with CLI options
94
+ * ```ts
95
+ * import { defineConfig } from 'kubb'
96
+ *
97
+ * export default defineConfig(({ input }) => ({
98
+ * input: { path: input ?? './petStore.yaml' },
99
+ * output: { path: './src/gen' },
100
+ * plugins: [],
66
101
  * }))
67
102
  * ```
68
103
  */
@@ -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.barrel`, `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.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` 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.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 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;CAC7E,OAAO,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;CACnC,IAAI,uBAAuB,OAAO,WAAW,KAAA,GAC3C,OAAO,SAAS,EAAE,MAAM,SAAS;CAEnC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;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;CACvI,IAAI,MAAM,QAAQ,OAAO,EACvB,OAAO,OAAO,IAAI,cAAc;CAGlC,OAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;CAI7C,IAAI,UAAU,OAAO,EACnB,OAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;CAG7D,OAAO,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":["function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** 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 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\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 so a minimal config\n * stays small.\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":";;;;;;;;;;;;;;;;AAyFA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;AC7DA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,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 "./chunk-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,42 @@ 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 so a minimal config
24
+ * stays small.
24
25
  *
25
- * When no `adapter` is provided, `adapterOas()` is used automatically.
26
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
26
+ * Defaults applied when omitted:
27
+ * - `adapter` `adapterOas()` (OpenAPI 2.0/3.0/3.1).
28
+ * - `parsers` → `[parserTs, parserTsx, parserMd]`.
29
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
30
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
31
+ * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
32
+ * in the plugins list.
33
+ * - `output.format` and `output.lint` → `false`.
27
34
  *
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
35
+ * Accepts a config object, an array of configs, a Promise resolving to one,
36
+ * or a function that receives the parsed CLI options and returns any of the
37
+ * above. The return type is preserved so async/array variants stay typed.
32
38
  *
33
39
  * @example
34
40
  * ```ts
35
- * export default defineConfig(({ logLevel }) => ({
36
- * root: 'src',
37
- * plugins: [myPlugin()],
41
+ * import { defineConfig } from 'kubb'
42
+ * import { pluginTs } from '@kubb/plugin-ts'
43
+ *
44
+ * export default defineConfig({
45
+ * input: { path: './petStore.yaml' },
46
+ * output: { path: './src/gen' },
47
+ * plugins: [pluginTs()],
48
+ * })
49
+ * ```
50
+ *
51
+ * @example Function form with CLI options
52
+ * ```ts
53
+ * import { defineConfig } from 'kubb'
54
+ *
55
+ * export default defineConfig(({ input }) => ({
56
+ * input: { path: input ?? './petStore.yaml' },
57
+ * output: { path: './src/gen' },
58
+ * plugins: [],
38
59
  * }))
39
60
  * ```
40
61
  */
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
- import "./chunk--u3MIqq1.js";
1
+ import "./chunk-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.barrel`, `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.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
26
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` 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.barrel === void 0) output.barrel = { type: "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,42 @@ 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 so a minimal config
65
+ * stays small.
51
66
  *
52
- * When no `adapter` is provided, `adapterOas()` is used automatically.
53
- * 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`.
54
75
  *
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
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.
59
79
  *
60
80
  * @example
61
81
  * ```ts
62
- * export default defineConfig(({ logLevel }) => ({
63
- * root: 'src',
64
- * 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: [],
65
100
  * }))
66
101
  * ```
67
102
  */
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.barrel`, `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.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` 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.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 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;CAC7E,OAAO,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;CACnC,IAAI,uBAAuB,OAAO,WAAW,KAAA,GAC3C,OAAO,SAAS,EAAE,MAAM,SAAS;CAEnC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACxE;EACA;EACD;;AAGH,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,OAAO,EACvB,OAAO,OAAO,IAAI,cAAc;CAGlC,OAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;CAI7C,IAAI,UAAU,OAAO,EACnB,OAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;CAG7D,OAAO,gBAAgB,OAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** 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 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\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 so a minimal config\n * stays small.\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":";;;;;;;;;;;;;;;AAyFA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;AC7DA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,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,21 @@
1
1
  {
2
2
  "name": "kubb",
3
- "version": "5.0.0-beta.6",
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.60",
4
+ "description": "Meta-package and entry point for Kubb — a plugin-based code generation framework for OpenAPI. Includes defineConfig, all public APIs, and serves as the gateway to the entire Kubb ecosystem.",
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
13
  "openapi",
15
14
  "plugin-system",
16
- "plugins",
17
15
  "react-query",
18
16
  "sdk-generator",
19
17
  "swagger",
20
18
  "tanstack-query",
21
- "type-safe",
22
19
  "typescript",
23
20
  "zod"
24
21
  ],
@@ -57,47 +54,31 @@
57
54
  "registry": "https://registry.npmjs.org/"
58
55
  },
59
56
  "dependencies": {
60
- "@kubb/adapter-oas": "5.0.0-beta.6",
61
- "@kubb/cli": "5.0.0-beta.6",
62
- "@kubb/core": "5.0.0-beta.6",
63
- "@kubb/middleware-barrel": "5.0.0-beta.6",
64
- "@kubb/parser-ts": "5.0.0-beta.6",
65
- "@kubb/renderer-jsx": "5.0.0-beta.6"
57
+ "@kubb/adapter-oas": "5.0.0-beta.60",
58
+ "@kubb/cli": "5.0.0-beta.60",
59
+ "@kubb/core": "5.0.0-beta.60",
60
+ "@kubb/mcp": "5.0.0-beta.60",
61
+ "@kubb/parser-md": "5.0.0-beta.60",
62
+ "@kubb/parser-ts": "5.0.0-beta.60",
63
+ "@kubb/plugin-barrel": "5.0.0-beta.60",
64
+ "@kubb/renderer-jsx": "5.0.0-beta.60"
66
65
  },
67
66
  "devDependencies": {
68
67
  "typescript": "^6.0.3",
69
68
  "@internals/utils": "0.0.0"
70
69
  },
71
- "peerDependencies": {
72
- "@kubb/agent": "5.0.0-beta.6",
73
- "@kubb/mcp": "5.0.0-beta.6"
74
- },
75
- "peerDependenciesMeta": {
76
- "@kubb/agent": {
77
- "optional": true
78
- },
79
- "@kubb/mcp": {
80
- "optional": true
81
- }
82
- },
83
- "size-limit": [
84
- {
85
- "path": "./dist/*.js",
86
- "limit": "510 KiB",
87
- "gzip": true
88
- }
89
- ],
90
70
  "preferGlobal": true,
91
71
  "engines": {
92
72
  "node": ">=22"
93
73
  },
94
74
  "scripts": {
95
75
  "build": "tsdown",
96
- "clean": "npx rimraf ./dist",
76
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
97
77
  "lint": "oxlint .",
98
78
  "lint:fix": "oxlint --fix .",
99
79
  "release": "pnpm publish --no-git-check",
100
80
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
81
+ "release:stage": "pnpm stage publish --no-git-check",
101
82
  "start": "tsdown --watch",
102
83
  "test": "vitest --passWithNoTests",
103
84
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
@@ -1,8 +1,9 @@
1
1
  import { isPromise, type PossiblePromise } from '@internals/utils'
2
2
  import { adapterOas } from '@kubb/adapter-oas'
3
- import type { CLIOptions, UserConfig } from '@kubb/core'
4
- import { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'
3
+ import { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'
4
+ import { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'
5
5
  import { parserTs, parserTsx } from '@kubb/parser-ts'
6
+ import { parserMd } from '@kubb/parser-md'
6
7
 
7
8
  type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>
8
9
  type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)
@@ -15,22 +16,25 @@ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptio
15
16
  : NormalizeConfig<TConfig>
16
17
 
17
18
  /**
18
- * Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
19
+ * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
19
20
  *
21
+ * - `root` defaults to `process.cwd()`
20
22
  * - `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'`
23
+ * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
24
+ * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
25
+ * - `plugins` gets `pluginBarrel()` appended when none is already present
26
+ * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
27
+ * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
28
+ * - `output.format` defaults to `false`
29
+ * - `output.lint` defaults to `false`
27
30
  */
28
31
  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)
32
+ const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)
33
+ const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]
34
+ const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)
31
35
 
32
36
  const output = { ...config.output }
33
- if (hasBarrelMiddleware && output.barrel === undefined) {
37
+ if (hasBarrelPlugin && output.barrel === undefined) {
34
38
  output.barrel = { type: 'named' }
35
39
  }
36
40
  if (output.format === undefined) {
@@ -42,9 +46,11 @@ function applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {
42
46
 
43
47
  return {
44
48
  ...config,
49
+ root: config.root || process.cwd(),
45
50
  adapter: config.adapter ?? adapterOas(),
46
- parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],
47
- middleware,
51
+ parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],
52
+ reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],
53
+ plugins,
48
54
  output,
49
55
  }
50
56
  }
@@ -58,21 +64,42 @@ function normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<T
58
64
  }
59
65
 
60
66
  /**
61
- * Helper for defining a Kubb configuration with built-in defaults.
67
+ * Defines a Kubb build configuration and fills in defaults so a minimal config
68
+ * stays small.
62
69
  *
63
- * When no `adapter` is provided, `adapterOas()` is used automatically.
64
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
70
+ * Defaults applied when omitted:
71
+ * - `adapter` `adapterOas()` (OpenAPI 2.0/3.0/3.1).
72
+ * - `parsers` → `[parserTs, parserTsx, parserMd]`.
73
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
74
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
75
+ * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
76
+ * in the plugins list.
77
+ * - `output.format` and `output.lint` → `false`.
65
78
  *
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
79
+ * Accepts a config object, an array of configs, a Promise resolving to one,
80
+ * or a function that receives the parsed CLI options and returns any of the
81
+ * above. The return type is preserved so async/array variants stay typed.
70
82
  *
71
83
  * @example
72
84
  * ```ts
73
- * export default defineConfig(({ logLevel }) => ({
74
- * root: 'src',
75
- * plugins: [myPlugin()],
85
+ * import { defineConfig } from 'kubb'
86
+ * import { pluginTs } from '@kubb/plugin-ts'
87
+ *
88
+ * export default defineConfig({
89
+ * input: { path: './petStore.yaml' },
90
+ * output: { path: './src/gen' },
91
+ * plugins: [pluginTs()],
92
+ * })
93
+ * ```
94
+ *
95
+ * @example Function form with CLI options
96
+ * ```ts
97
+ * import { defineConfig } from 'kubb'
98
+ *
99
+ * export default defineConfig(({ input }) => ({
100
+ * input: { path: input ?? './petStore.yaml' },
101
+ * output: { path: './src/gen' },
102
+ * plugins: [],
76
103
  * }))
77
104
  * ```
78
105
  */
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { BarrelType } from '@kubb/middleware-barrel'
1
+ export type { BarrelType } from '@kubb/plugin-barrel'
2
2
  export { defineConfig } from './defineConfig.ts'
File without changes