@kubb/core 4.38.1 → 4.39.1

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.
@@ -619,6 +619,26 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
619
619
  parse: (source: AdapterSource) => PossiblePromise<RootNode>;
620
620
  };
621
621
  type BarrelType = 'all' | 'named' | 'propagate';
622
+ /**
623
+ * Object form of the barrel option, the forward-compatible replacement for `barrelType`.
624
+ *
625
+ * Available in v4 so a config can be migrated ahead of v5, where it becomes the only barrel option.
626
+ * See https://kubb.dev/docs/5.x/migration-guide
627
+ */
628
+ type Barrel = {
629
+ /**
630
+ * How `index.ts` files re-export their files.
631
+ * - 'named' lists every export by name.
632
+ * - 'all' re-exports with a wildcard (`export *`).
633
+ * @default 'named'
634
+ */
635
+ type?: Exclude<BarrelType, 'propagate'>;
636
+ /**
637
+ * Re-export the nested barrel files instead of the individual files. Replaces the legacy `'propagate'` value of `barrelType`.
638
+ * @default false
639
+ */
640
+ nested?: boolean;
641
+ };
622
642
  type DevtoolsOptions = {
623
643
  /**
624
644
  * Open the AST inspector view (`/ast`) in Kubb Studio.
@@ -719,8 +739,17 @@ type Config<TInput = Input> = {
719
739
  /**
720
740
  * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
721
741
  * @default 'named'
742
+ * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide
722
743
  */
723
744
  barrelType?: Exclude<BarrelType, 'propagate'> | false;
745
+ /**
746
+ * Object form of {@link Config.output.barrelType} for the root barrel file (e.g., `src/gen/index.ts`). Prefer this over `barrelType`; it becomes the only barrel option in v5.
747
+ * - `{ type: 'named' }` lists every export by name.
748
+ * - `{ type: 'all' }` re-exports with a wildcard.
749
+ * - `false` disables the root barrel file.
750
+ * @default { type: 'named' }
751
+ */
752
+ barrel?: Omit<Barrel, 'nested'> | false;
724
753
  /**
725
754
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
726
755
  * - 'simple' adds banner with link to Kubb.
@@ -734,6 +763,7 @@ type Config<TInput = Input> = {
734
763
  * When setting the option in the global configuration, all plugins inherit the same behavior by default.
735
764
  * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
736
765
  * @default false
766
+ * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide
737
767
  */
738
768
  override?: boolean;
739
769
  };
@@ -938,8 +968,18 @@ type Output<TOptions> = {
938
968
  /**
939
969
  * Define what needs to be exported, here you can also disable the export of barrel files
940
970
  * @default 'named'
971
+ * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide
941
972
  */
942
973
  barrelType?: BarrelType | false;
974
+ /**
975
+ * Object form of {@link Output.barrelType}. Prefer this over `barrelType`; it becomes the only barrel option in v5.
976
+ * - `{ type: 'named' }` lists every export by name.
977
+ * - `{ type: 'all' }` re-exports with a wildcard.
978
+ * - `{ type: 'named', nested: true }` replaces the legacy `'propagate'` value.
979
+ * - `false` disables the barrel file for this plugin.
980
+ * @default { type: 'named' }
981
+ */
982
+ barrel?: Barrel | false;
943
983
  /**
944
984
  * Add a banner text in the beginning of every file
945
985
  */
@@ -951,6 +991,7 @@ type Output<TOptions> = {
951
991
  /**
952
992
  * Whether to override existing external files if they already exist.
953
993
  * @default false
994
+ * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide
954
995
  */
955
996
  override?: boolean;
956
997
  };
@@ -987,5 +1028,5 @@ type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
987
1028
  };
988
1029
  type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
989
1030
  //#endregion
990
- export { UserPlugin as A, AsyncEventEmitter as B, Printer as C, UnknownUserPlugin as D, ResolvePathParams as E, DefineStorage as F, defineStorage as I, formatters as L, KubbEvents as M, PluginManager as N, UserConfig as O, getMode as P, linters as R, PluginWithLifeCycle as S, ResolveNameParams as T, URLPath as V, PluginFactoryOptions as _, Config as a, PluginLifecycleHooks as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, UserPluginWithLifeCycle as j, UserLogger as k, InputData as l, Output as m, AdapterFactoryOptions as n, DevtoolsOptions as o, LoggerOptions as p, AdapterSource as r, GetPluginFactoryOptions as s, Adapter as t, InputPath as u, PluginKey as v, PrinterFactoryOptions as w, PluginParameter as x, PluginLifecycle as y, logLevel as z };
991
- //# sourceMappingURL=types-BwL2CHjl.d.ts.map
1031
+ export { UserLogger as A, logLevel as B, PluginWithLifeCycle as C, ResolvePathParams as D, ResolveNameParams as E, getMode as F, URLPath as H, DefineStorage as I, defineStorage as L, UserPluginWithLifeCycle as M, KubbEvents as N, UnknownUserPlugin as O, PluginManager as P, formatters as R, PluginParameter as S, PrinterFactoryOptions as T, AsyncEventEmitter as V, PluginContext as _, BarrelType as a, PluginLifecycle as b, GetPluginFactoryOptions as c, InputPath as d, Logger as f, Plugin as g, Output as h, Barrel as i, UserPlugin as j, UserConfig as k, Group as l, LoggerOptions as m, AdapterFactoryOptions as n, Config as o, LoggerContext as p, AdapterSource as r, DevtoolsOptions as s, Adapter as t, InputData as u, PluginFactoryOptions as v, Printer as w, PluginLifecycleHooks as x, PluginKey as y, linters as z };
1032
+ //# sourceMappingURL=types-DsJhzsHG.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "4.38.1",
3
+ "version": "4.39.1",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -71,7 +71,7 @@
71
71
  "remeda": "^2.37.0",
72
72
  "semver": "^7.8.2",
73
73
  "tinyexec": "^1.2.4",
74
- "@kubb/ast": "4.38.1"
74
+ "@kubb/ast": "4.39.1"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/semver": "^7.7.1",
package/src/build.ts CHANGED
@@ -13,6 +13,7 @@ import { fsStorage } from './storages/fsStorage.ts'
13
13
  import type { AdapterSource, Config, DefineStorage, KubbEvents, Output, Plugin, UserConfig } from './types.ts'
14
14
  import { getDiagnosticInfo } from './utils/diagnostics.ts'
15
15
  import type { FileMetaBase } from './utils/getBarrelFiles.ts'
16
+ import { resolveBarrelType } from './utils/resolveBarrelType.ts'
16
17
 
17
18
  type BuildOptions = {
18
19
  config: UserConfig
@@ -161,7 +162,7 @@ export async function setup(options: BuildOptions): Promise<SetupResult> {
161
162
  logs: [
162
163
  '✓ Fabric initialized',
163
164
  ` • Storage: ${storage ? storage.name : 'disabled (dry-run)'}`,
164
- ` • Barrel type: ${definedConfig.output.barrelType || 'none'}`,
165
+ ` • Barrel type: ${resolveBarrelType(definedConfig.output) || 'none'}`,
165
166
  ],
166
167
  })
167
168
 
@@ -286,14 +287,15 @@ export async function safeBuild(options: BuildOptions, overrides?: SetupResult):
286
287
  }
287
288
  }
288
289
 
289
- if (config.output.barrelType) {
290
+ const rootBarrelType = resolveBarrelType(config.output)
291
+ if (rootBarrelType) {
290
292
  const root = resolve(config.root)
291
293
  const rootPath = resolve(root, config.output.path, BARREL_FILENAME)
292
294
  const rootDir = dirname(rootPath)
293
295
 
294
296
  await events.emit('debug', {
295
297
  date: new Date(),
296
- logs: ['Generating barrel file', ` • Type: ${config.output.barrelType}`, ` • Path: ${rootPath}`],
298
+ logs: ['Generating barrel file', ` • Type: ${rootBarrelType}`, ` • Path: ${rootPath}`],
297
299
  })
298
300
 
299
301
  const barrelFiles = fabric.files.filter((file) => {
@@ -361,6 +363,7 @@ type BuildBarrelExportsParams = {
361
363
  }
362
364
 
363
365
  function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }: BuildBarrelExportsParams): KubbFile.Export[] {
366
+ const rootBarrelType = resolveBarrelType(config.output)
364
367
  const pluginKeyMap = new Map<string, Plugin>()
365
368
  for (const plugin of pluginManager.plugins) {
366
369
  pluginKeyMap.set(JSON.stringify(plugin.key), plugin)
@@ -378,11 +381,11 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
378
381
  const plugin = meta?.pluginKey ? pluginKeyMap.get(JSON.stringify(meta.pluginKey)) : undefined
379
382
  const pluginOptions = plugin?.options as { output?: Output<unknown> } | undefined
380
383
 
381
- if (!pluginOptions || pluginOptions.output?.barrelType === false) {
384
+ if (!pluginOptions || resolveBarrelType(pluginOptions.output) === false) {
382
385
  return []
383
386
  }
384
387
 
385
- const exportName = config.output.barrelType === 'all' ? undefined : source.name ? [source.name] : undefined
388
+ const exportName = rootBarrelType === 'all' ? undefined : source.name ? [source.name] : undefined
386
389
  if (exportName?.some((n) => existingExports.has(n))) {
387
390
  return []
388
391
  }
@@ -391,7 +394,7 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
391
394
  {
392
395
  name: exportName,
393
396
  path: getRelativePath(rootDir, file.path),
394
- isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
397
+ isTypeOnly: rootBarrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
395
398
  } satisfies KubbFile.Export,
396
399
  ]
397
400
  })
package/src/config.ts CHANGED
@@ -36,6 +36,14 @@ export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CL
36
36
  * - A function returning the config(s), optionally async,
37
37
  * receiving the CLI options as argument
38
38
  *
39
+ * @deprecated Import `defineConfig` from `kubb` instead of `@kubb/core`. The `kubb`
40
+ * package wires up the OpenAPI adapter, the TypeScript parsers, and the barrel plugin
41
+ * for you. See the v5 migration guide: https://kubb.dev/docs/5.x/migration-guide
42
+ *
43
+ * ```ts
44
+ * import { defineConfig } from '@kubb/core' // [!code --]
45
+ * import { defineConfig } from 'kubb' // [!code ++]
46
+ * ```
39
47
  * @example
40
48
  * export default defineConfig(({ logLevel }) => ({
41
49
  * root: 'src',
package/src/index.ts CHANGED
@@ -20,3 +20,4 @@ export type { FileMetaBase } from './utils/getBarrelFiles.ts'
20
20
  export { getBarrelFiles } from './utils/getBarrelFiles.ts'
21
21
  export { getConfigs } from './utils/getConfigs.ts'
22
22
  export { detectLinter } from './utils/linters.ts'
23
+ export { resolveBarrelType } from './utils/resolveBarrelType.ts'
package/src/types.ts CHANGED
@@ -102,6 +102,27 @@ export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptio
102
102
 
103
103
  export type BarrelType = 'all' | 'named' | 'propagate'
104
104
 
105
+ /**
106
+ * Object form of the barrel option, the forward-compatible replacement for `barrelType`.
107
+ *
108
+ * Available in v4 so a config can be migrated ahead of v5, where it becomes the only barrel option.
109
+ * See https://kubb.dev/docs/5.x/migration-guide
110
+ */
111
+ export type Barrel = {
112
+ /**
113
+ * How `index.ts` files re-export their files.
114
+ * - 'named' lists every export by name.
115
+ * - 'all' re-exports with a wildcard (`export *`).
116
+ * @default 'named'
117
+ */
118
+ type?: Exclude<BarrelType, 'propagate'>
119
+ /**
120
+ * Re-export the nested barrel files instead of the individual files. Replaces the legacy `'propagate'` value of `barrelType`.
121
+ * @default false
122
+ */
123
+ nested?: boolean
124
+ }
125
+
105
126
  export type DevtoolsOptions = {
106
127
  /**
107
128
  * Open the AST inspector view (`/ast`) in Kubb Studio.
@@ -203,8 +224,17 @@ export type Config<TInput = Input> = {
203
224
  /**
204
225
  * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
205
226
  * @default 'named'
227
+ * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide
206
228
  */
207
229
  barrelType?: Exclude<BarrelType, 'propagate'> | false
230
+ /**
231
+ * Object form of {@link Config.output.barrelType} for the root barrel file (e.g., `src/gen/index.ts`). Prefer this over `barrelType`; it becomes the only barrel option in v5.
232
+ * - `{ type: 'named' }` lists every export by name.
233
+ * - `{ type: 'all' }` re-exports with a wildcard.
234
+ * - `false` disables the root barrel file.
235
+ * @default { type: 'named' }
236
+ */
237
+ barrel?: Omit<Barrel, 'nested'> | false
208
238
  /**
209
239
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
210
240
  * - 'simple' adds banner with link to Kubb.
@@ -218,6 +248,7 @@ export type Config<TInput = Input> = {
218
248
  * When setting the option in the global configuration, all plugins inherit the same behavior by default.
219
249
  * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
220
250
  * @default false
251
+ * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide
221
252
  */
222
253
  override?: boolean
223
254
  }
@@ -442,8 +473,18 @@ export type Output<TOptions> = {
442
473
  /**
443
474
  * Define what needs to be exported, here you can also disable the export of barrel files
444
475
  * @default 'named'
476
+ * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide
445
477
  */
446
478
  barrelType?: BarrelType | false
479
+ /**
480
+ * Object form of {@link Output.barrelType}. Prefer this over `barrelType`; it becomes the only barrel option in v5.
481
+ * - `{ type: 'named' }` lists every export by name.
482
+ * - `{ type: 'all' }` re-exports with a wildcard.
483
+ * - `{ type: 'named', nested: true }` replaces the legacy `'propagate'` value.
484
+ * - `false` disables the barrel file for this plugin.
485
+ * @default { type: 'named' }
486
+ */
487
+ barrel?: Barrel | false
447
488
  /**
448
489
  * Add a banner text in the beginning of every file
449
490
  */
@@ -455,6 +496,7 @@ export type Output<TOptions> = {
455
496
  /**
456
497
  * Whether to override existing external files if they already exist.
457
498
  * @default false
499
+ * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide
458
500
  */
459
501
  override?: boolean
460
502
  }
@@ -1,14 +1,18 @@
1
1
  import { join } from 'node:path'
2
2
  import type { KubbFile } from '@kubb/fabric-core/types'
3
3
  import { BarrelManager } from '../BarrelManager.ts'
4
- import type { BarrelType, Plugin } from '../types.ts'
4
+ import type { Barrel, BarrelType, Plugin } from '../types.ts'
5
+ import { resolveBarrelType } from './resolveBarrelType.ts'
5
6
 
6
7
  export type FileMetaBase = {
7
8
  pluginKey?: Plugin['key']
8
9
  }
9
10
 
10
11
  type AddIndexesProps = {
11
- type: BarrelType | false | undefined
12
+ /**
13
+ * Explicit barrel strategy. When omitted it is resolved from `output.barrel` (preferred) or the legacy `output.barrelType`.
14
+ */
15
+ type?: BarrelType | false
12
16
  /**
13
17
  * Root based on root and output.path specified in the config
14
18
  */
@@ -18,6 +22,8 @@ type AddIndexesProps = {
18
22
  */
19
23
  output: {
20
24
  path: string
25
+ barrel?: Barrel | false
26
+ barrelType?: BarrelType | false
21
27
  }
22
28
  group?: {
23
29
  output: string
@@ -38,7 +44,9 @@ function trimExtName(text: string): string {
38
44
  }
39
45
 
40
46
  export async function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, { type, meta = {}, root, output }: AddIndexesProps): Promise<KubbFile.File[]> {
41
- if (!type || type === 'propagate') {
47
+ const resolvedType = type ?? resolveBarrelType(output) ?? 'named'
48
+
49
+ if (!resolvedType || resolvedType === 'propagate') {
42
50
  return []
43
51
  }
44
52
 
@@ -56,7 +64,7 @@ export async function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, { type
56
64
  meta,
57
65
  })
58
66
 
59
- if (type === 'all') {
67
+ if (resolvedType === 'all') {
60
68
  return barrelFiles.map((file) => {
61
69
  return {
62
70
  ...file,
@@ -0,0 +1,32 @@
1
+ import type { Barrel, BarrelType } from '../types.ts'
2
+
3
+ type BarrelOutput = {
4
+ barrel?: Barrel | false
5
+ barrelType?: BarrelType | false
6
+ }
7
+
8
+ /**
9
+ * Resolve the effective barrel strategy from an output config.
10
+ *
11
+ * Prefers the object `barrel` option and falls back to the legacy `barrelType`.
12
+ * `barrel: { nested: true }` maps to the legacy `'propagate'` value, and
13
+ * `barrel: false` disables the barrel file.
14
+ */
15
+ export function resolveBarrelType(output: BarrelOutput | undefined): BarrelType | false | undefined {
16
+ if (!output) {
17
+ return undefined
18
+ }
19
+
20
+ const { barrel } = output
21
+ if (barrel !== undefined) {
22
+ if (barrel === false) {
23
+ return false
24
+ }
25
+ if (barrel.nested) {
26
+ return 'propagate'
27
+ }
28
+ return barrel.type ?? 'named'
29
+ }
30
+
31
+ return output.barrelType
32
+ }