@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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { A as UserPlugin, B as AsyncEventEmitter, C as Printer, D as UnknownUserPlugin, E as ResolvePathParams, F as DefineStorage, I as defineStorage, L as formatters, M as KubbEvents, N as PluginManager, O as UserConfig, P as getMode, R as linters, S as PluginWithLifeCycle, T as ResolveNameParams, V as URLPath, _ as PluginFactoryOptions, a as Config, b as PluginLifecycleHooks, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as UserPluginWithLifeCycle, k as UserLogger, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginKey, w as PrinterFactoryOptions, x as PluginParameter, y as PluginLifecycle, z as logLevel } from "./types-BwL2CHjl.js";
2
+ import { A as UserLogger, B as logLevel, C as PluginWithLifeCycle, D as ResolvePathParams, E as ResolveNameParams, F as getMode, H as URLPath, I as DefineStorage, L as defineStorage, M as UserPluginWithLifeCycle, N as KubbEvents, O as UnknownUserPlugin, P as PluginManager, R as formatters, S as PluginParameter, T as PrinterFactoryOptions, V as AsyncEventEmitter, _ as PluginContext, a as BarrelType, b as PluginLifecycle, c as GetPluginFactoryOptions, d as InputPath, f as Logger, g as Plugin, h as Output, i as Barrel, j as UserPlugin, k as UserConfig, l as Group, m as LoggerOptions, n as AdapterFactoryOptions, o as Config, p as LoggerContext, r as AdapterSource, s as DevtoolsOptions, t as Adapter, u as InputData, v as PluginFactoryOptions, w as Printer, x as PluginLifecycleHooks, y as PluginKey, z as linters } from "./types-DsJhzsHG.js";
3
3
  import { definePrinter } from "@kubb/ast";
4
4
  import { KubbFile } from "@kubb/fabric-core/types";
5
5
  import { Fabric } from "@kubb/react-fabric/types";
@@ -59,6 +59,14 @@ type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOption
59
59
  * - A function returning the config(s), optionally async,
60
60
  * receiving the CLI options as argument
61
61
  *
62
+ * @deprecated Import `defineConfig` from `kubb` instead of `@kubb/core`. The `kubb`
63
+ * package wires up the OpenAPI adapter, the TypeScript parsers, and the barrel plugin
64
+ * for you. See the v5 migration guide: https://kubb.dev/docs/5.x/migration-guide
65
+ *
66
+ * ```ts
67
+ * import { defineConfig } from '@kubb/core' // [!code --]
68
+ * import { defineConfig } from 'kubb' // [!code ++]
69
+ * ```
62
70
  * @example
63
71
  * export default defineConfig(({ logLevel }) => ({
64
72
  * root: 'src',
@@ -277,7 +285,10 @@ type FileMetaBase = {
277
285
  pluginKey?: Plugin['key'];
278
286
  };
279
287
  type AddIndexesProps = {
280
- type: BarrelType | false | undefined;
288
+ /**
289
+ * Explicit barrel strategy. When omitted it is resolved from `output.barrel` (preferred) or the legacy `output.barrelType`.
290
+ */
291
+ type?: BarrelType | false;
281
292
  /**
282
293
  * Root based on root and output.path specified in the config
283
294
  */
@@ -287,6 +298,8 @@ type AddIndexesProps = {
287
298
  */
288
299
  output: {
289
300
  path: string;
301
+ barrel?: Barrel | false;
302
+ barrelType?: BarrelType | false;
290
303
  };
291
304
  group?: {
292
305
  output: string;
@@ -311,5 +324,19 @@ declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions):
311
324
  type Linter = keyof typeof linters;
312
325
  declare function detectLinter(): Promise<Linter | undefined>;
313
326
  //#endregion
314
- export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, Config, type ConfigInput, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginKey, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, setup };
327
+ //#region src/utils/resolveBarrelType.d.ts
328
+ type BarrelOutput = {
329
+ barrel?: Barrel | false;
330
+ barrelType?: BarrelType | false;
331
+ };
332
+ /**
333
+ * Resolve the effective barrel strategy from an output config.
334
+ *
335
+ * Prefers the object `barrel` option and falls back to the legacy `barrelType`.
336
+ * `barrel: { nested: true }` maps to the legacy `'propagate'` value, and
337
+ * `barrel: false` disables the barrel file.
338
+ */
339
+ declare function resolveBarrelType(output: BarrelOutput | undefined): BarrelType | false | undefined;
340
+ //#endregion
341
+ export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, Barrel, BarrelType, type CLIOptions, Config, type ConfigInput, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginKey, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveBarrelType, safeBuild, setup };
315
342
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1475,7 +1475,7 @@ const fsStorage = defineStorage(() => ({
1475
1475
  }));
1476
1476
  //#endregion
1477
1477
  //#region package.json
1478
- var version$1 = "4.38.1";
1478
+ var version$1 = "4.39.1";
1479
1479
  //#endregion
1480
1480
  //#region src/utils/diagnostics.ts
1481
1481
  /**
@@ -1491,6 +1491,25 @@ function getDiagnosticInfo() {
1491
1491
  };
1492
1492
  }
1493
1493
  //#endregion
1494
+ //#region src/utils/resolveBarrelType.ts
1495
+ /**
1496
+ * Resolve the effective barrel strategy from an output config.
1497
+ *
1498
+ * Prefers the object `barrel` option and falls back to the legacy `barrelType`.
1499
+ * `barrel: { nested: true }` maps to the legacy `'propagate'` value, and
1500
+ * `barrel: false` disables the barrel file.
1501
+ */
1502
+ function resolveBarrelType(output) {
1503
+ if (!output) return;
1504
+ const { barrel } = output;
1505
+ if (barrel !== void 0) {
1506
+ if (barrel === false) return false;
1507
+ if (barrel.nested) return "propagate";
1508
+ return barrel.type ?? "named";
1509
+ }
1510
+ return output.barrelType;
1511
+ }
1512
+ //#endregion
1494
1513
  //#region src/build.ts
1495
1514
  async function setup(options) {
1496
1515
  const { config: userConfig, events = new AsyncEventEmitter() } = options;
@@ -1586,7 +1605,7 @@ async function setup(options) {
1586
1605
  logs: [
1587
1606
  "✓ Fabric initialized",
1588
1607
  ` • Storage: ${storage ? storage.name : "disabled (dry-run)"}`,
1589
- ` • Barrel type: ${definedConfig.output.barrelType || "none"}`
1608
+ ` • Barrel type: ${resolveBarrelType(definedConfig.output) || "none"}`
1590
1609
  ]
1591
1610
  });
1592
1611
  const pluginManager = new PluginManager(definedConfig, {
@@ -1687,14 +1706,15 @@ async function safeBuild(options, overrides) {
1687
1706
  });
1688
1707
  }
1689
1708
  }
1690
- if (config.output.barrelType) {
1709
+ const rootBarrelType = resolveBarrelType(config.output);
1710
+ if (rootBarrelType) {
1691
1711
  const rootPath = resolve(resolve(config.root), config.output.path, BARREL_FILENAME);
1692
1712
  const rootDir = dirname(rootPath);
1693
1713
  await events.emit("debug", {
1694
1714
  date: /* @__PURE__ */ new Date(),
1695
1715
  logs: [
1696
1716
  "Generating barrel file",
1697
- ` • Type: ${config.output.barrelType}`,
1717
+ ` • Type: ${rootBarrelType}`,
1698
1718
  ` • Path: ${rootPath}`
1699
1719
  ]
1700
1720
  });
@@ -1749,6 +1769,7 @@ async function safeBuild(options, overrides) {
1749
1769
  }
1750
1770
  }
1751
1771
  function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }) {
1772
+ const rootBarrelType = resolveBarrelType(config.output);
1752
1773
  const pluginKeyMap = /* @__PURE__ */ new Map();
1753
1774
  for (const plugin of pluginManager.plugins) pluginKeyMap.set(JSON.stringify(plugin.key), plugin);
1754
1775
  return barrelFiles.flatMap((file) => {
@@ -1757,13 +1778,13 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
1757
1778
  if (!file.path || !source.isIndexable) return [];
1758
1779
  const meta = file.meta;
1759
1780
  const pluginOptions = (meta?.pluginKey ? pluginKeyMap.get(JSON.stringify(meta.pluginKey)) : void 0)?.options;
1760
- if (!pluginOptions || pluginOptions.output?.barrelType === false) return [];
1761
- const exportName = config.output.barrelType === "all" ? void 0 : source.name ? [source.name] : void 0;
1781
+ if (!pluginOptions || resolveBarrelType(pluginOptions.output) === false) return [];
1782
+ const exportName = rootBarrelType === "all" ? void 0 : source.name ? [source.name] : void 0;
1762
1783
  if (exportName?.some((n) => existingExports.has(n))) return [];
1763
1784
  return [{
1764
1785
  name: exportName,
1765
1786
  path: getRelativePath(rootDir, file.path),
1766
- isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
1787
+ isTypeOnly: rootBarrelType === "all" ? containsOnlyTypes : source.isTypeOnly
1767
1788
  }];
1768
1789
  });
1769
1790
  });
@@ -2244,7 +2265,8 @@ function trimExtName(text) {
2244
2265
  return text;
2245
2266
  }
2246
2267
  async function getBarrelFiles(files, { type, meta = {}, root, output }) {
2247
- if (!type || type === "propagate") return [];
2268
+ const resolvedType = type ?? resolveBarrelType(output) ?? "named";
2269
+ if (!resolvedType || resolvedType === "propagate") return [];
2248
2270
  const barrelManager = new BarrelManager();
2249
2271
  const pathToBuildFrom = join(root, output.path);
2250
2272
  if (trimExtName(pathToBuildFrom).endsWith("index")) return [];
@@ -2253,7 +2275,7 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
2253
2275
  root: pathToBuildFrom,
2254
2276
  meta
2255
2277
  });
2256
- if (type === "all") return barrelFiles.map((file) => {
2278
+ if (resolvedType === "all") return barrelFiles.map((file) => {
2257
2279
  return {
2258
2280
  ...file,
2259
2281
  exports: file.exports?.map((exportItem) => {
@@ -2320,6 +2342,6 @@ async function detectLinter() {
2320
2342
  ]) if (await isLinterAvailable(linter)) return linter;
2321
2343
  }
2322
2344
  //#endregion
2323
- export { AsyncEventEmitter, FunctionParams, PackageManager, PluginManager, PromiseManager, URLPath, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, setup };
2345
+ export { AsyncEventEmitter, FunctionParams, PackageManager, PluginManager, PromiseManager, URLPath, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveBarrelType, safeBuild, setup };
2324
2346
 
2325
2347
  //# sourceMappingURL=index.js.map