@kubb/core 5.0.0-beta.7 → 5.0.0-beta.8

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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_PluginDriver = require("./PluginDriver-Cadu4ORh.cjs");
2
+ const require_PluginDriver = require("./PluginDriver-Cu1Kj9S-.cjs");
3
3
  let node_events = require("node:events");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
  let node_path = require("node:path");
@@ -524,6 +524,9 @@ function createAdapter(build) {
524
524
  return (options) => build(options ?? {});
525
525
  }
526
526
  //#endregion
527
+ //#region package.json
528
+ var version = "5.0.0-beta.8";
529
+ //#endregion
527
530
  //#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
528
531
  var Node = class {
529
532
  value;
@@ -735,12 +738,6 @@ function createStorage(build) {
735
738
  //#endregion
736
739
  //#region src/storages/fsStorage.ts
737
740
  /**
738
- * Detects the filesystem error used to indicate that a path does not exist.
739
- */
740
- function isMissingPathError(error) {
741
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
742
- }
743
- /**
744
741
  * Built-in filesystem storage driver.
745
742
  *
746
743
  * This is the default storage when no `storage` option is configured in the root config.
@@ -771,17 +768,15 @@ const fsStorage = createStorage(() => ({
771
768
  try {
772
769
  await (0, node_fs_promises.access)((0, node_path.resolve)(key));
773
770
  return true;
774
- } catch (error) {
775
- if (isMissingPathError(error)) return false;
776
- throw new Error(`Failed to access storage item "${key}"`, { cause: error });
771
+ } catch (_error) {
772
+ return false;
777
773
  }
778
774
  },
779
775
  async getItem(key) {
780
776
  try {
781
777
  return await (0, node_fs_promises.readFile)((0, node_path.resolve)(key), "utf8");
782
- } catch (error) {
783
- if (isMissingPathError(error)) return null;
784
- throw new Error(`Failed to read storage item "${key}"`, { cause: error });
778
+ } catch (_error) {
779
+ return null;
785
780
  }
786
781
  },
787
782
  async setItem(key, value) {
@@ -797,9 +792,8 @@ const fsStorage = createStorage(() => ({
797
792
  let entries;
798
793
  try {
799
794
  entries = await (0, node_fs_promises.readdir)(dir, { withFileTypes: true });
800
- } catch (error) {
801
- if (isMissingPathError(error)) return;
802
- throw new Error(`Failed to list storage keys under "${resolvedBase}"`, { cause: error });
795
+ } catch (_error) {
796
+ return;
803
797
  }
804
798
  for (const entry of entries) {
805
799
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
@@ -816,37 +810,31 @@ const fsStorage = createStorage(() => ({
816
810
  }
817
811
  }));
818
812
  //#endregion
819
- //#region package.json
820
- var version = "5.0.0-beta.7";
821
- //#endregion
822
- //#region src/utils/diagnostics.ts
823
- /**
824
- * Returns a snapshot of the current runtime environment.
825
- *
826
- * Useful for attaching context to debug logs and error reports so that
827
- * issues can be reproduced without manual information gathering.
828
- */
829
- function getDiagnosticInfo() {
830
- return {
831
- nodeVersion: node_process.version,
832
- KubbVersion: version,
833
- platform: process.platform,
834
- arch: process.arch,
835
- cwd: process.cwd()
836
- };
837
- }
838
- //#endregion
839
- //#region src/utils/isInputPath.ts
840
- function isInputPath(config) {
841
- return typeof config?.input === "object" && config.input !== null && "path" in config.input;
842
- }
843
- //#endregion
844
813
  //#region src/createKubb.ts
845
814
  async function setup(userConfig, options = {}) {
846
815
  const hooks = options.hooks ?? new AsyncEventEmitter();
816
+ const config = {
817
+ ...userConfig,
818
+ root: userConfig.root || process.cwd(),
819
+ parsers: userConfig.parsers ?? [],
820
+ adapter: userConfig.adapter,
821
+ output: {
822
+ format: false,
823
+ lint: false,
824
+ extension: require_PluginDriver.DEFAULT_EXTENSION,
825
+ defaultBanner: require_PluginDriver.DEFAULT_BANNER,
826
+ ...userConfig.output
827
+ },
828
+ storage: userConfig.storage ?? fsStorage(),
829
+ devtools: userConfig.devtools ? {
830
+ studioUrl: require_PluginDriver.DEFAULT_STUDIO_URL,
831
+ ...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
832
+ } : void 0,
833
+ plugins: userConfig.plugins ?? []
834
+ };
835
+ const driver = new require_PluginDriver.PluginDriver(config, { hooks });
847
836
  const sources = /* @__PURE__ */ new Map();
848
837
  const diagnosticInfo = getDiagnosticInfo();
849
- if (Array.isArray(userConfig.input)) await hooks.emit("kubb:warn", { message: "This feature is still under development — use with caution" });
850
838
  await hooks.emit("kubb:debug", {
851
839
  date: /* @__PURE__ */ new Date(),
852
840
  logs: [
@@ -856,7 +844,7 @@ async function setup(userConfig, options = {}) {
856
844
  ` • Output: ${userConfig.output?.path || "not specified"}`,
857
845
  ` • Plugins: ${userConfig.plugins?.length || 0}`,
858
846
  "Output Settings:",
859
- ` • Storage: ${userConfig.storage ? `custom(${userConfig.storage.name})` : userConfig.output?.write === false ? "disabled" : "filesystem (default)"}`,
847
+ ` • Storage: ${config.storage.name}`,
860
848
  ` • Formatter: ${userConfig.output?.format || "none"}`,
861
849
  ` • Linter: ${userConfig.output?.lint || "none"}`,
862
850
  "Environment:",
@@ -877,34 +865,13 @@ async function setup(userConfig, options = {}) {
877
865
  throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: error });
878
866
  }
879
867
  }
880
- const config = {
881
- ...userConfig,
882
- root: userConfig.root || process.cwd(),
883
- parsers: userConfig.parsers ?? [],
884
- adapter: userConfig.adapter,
885
- output: {
886
- format: false,
887
- lint: false,
888
- write: true,
889
- extension: require_PluginDriver.DEFAULT_EXTENSION,
890
- defaultBanner: require_PluginDriver.DEFAULT_BANNER,
891
- ...userConfig.output
892
- },
893
- devtools: userConfig.devtools ? {
894
- studioUrl: require_PluginDriver.DEFAULT_STUDIO_URL,
895
- ...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
896
- } : void 0,
897
- plugins: userConfig.plugins ?? []
898
- };
899
- const storage = config.output.write === false ? null : config.storage ?? fsStorage();
900
868
  if (config.output.clean) {
901
869
  await hooks.emit("kubb:debug", {
902
870
  date: /* @__PURE__ */ new Date(),
903
871
  logs: ["Cleaning output directories", ` • Output: ${config.output.path}`]
904
872
  });
905
- await storage?.clear((0, node_path.resolve)(config.root, config.output.path));
873
+ await config.storage.clear((0, node_path.resolve)(config.root, config.output.path));
906
874
  }
907
- const driver = new require_PluginDriver.PluginDriver(config, { hooks });
908
875
  function registerMiddlewareHook(event, middlewareHooks) {
909
876
  const handler = middlewareHooks[event];
910
877
  if (handler) hooks.on(event, handler);
@@ -931,8 +898,7 @@ async function setup(userConfig, options = {}) {
931
898
  config,
932
899
  hooks,
933
900
  driver,
934
- sources,
935
- storage
901
+ sources
936
902
  };
937
903
  }
938
904
  /**
@@ -948,7 +914,7 @@ async function setup(userConfig, options = {}) {
948
914
  async function runPluginAstHooks(plugin, context) {
949
915
  const { adapter, inputNode, resolver, driver } = context;
950
916
  const { exclude, include, override } = plugin.options;
951
- if (!adapter || !inputNode) throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. pluginOas()) before this plugin in your Kubb config.`);
917
+ if (!adapter || !inputNode) throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. adapterOas()) before this plugin in your Kubb config.`);
952
918
  function resolveRenderer(gen) {
953
919
  return gen.renderer === null ? void 0 : gen.renderer ?? plugin.renderer ?? context.config.renderer;
954
920
  }
@@ -1031,7 +997,7 @@ async function runPluginAstHooks(plugin, context) {
1031
997
  }
1032
998
  }
1033
999
  async function safeBuild(setupResult) {
1034
- const { driver, hooks, sources, storage } = setupResult;
1000
+ const { driver, hooks, sources } = setupResult;
1035
1001
  const failedPlugins = /* @__PURE__ */ new Set();
1036
1002
  const pluginTimings = /* @__PURE__ */ new Map();
1037
1003
  const config = driver.config;
@@ -1122,6 +1088,7 @@ async function safeBuild(setupResult) {
1122
1088
  });
1123
1089
  await fileProcessor.run(files, {
1124
1090
  parsers: parsersMap,
1091
+ mode: "parallel",
1125
1092
  extension: config.output.extension,
1126
1093
  onStart: async (processingFiles) => {
1127
1094
  await hooks.emit("kubb:files:processing:start", { files: processingFiles });
@@ -1136,7 +1103,7 @@ async function safeBuild(setupResult) {
1136
1103
  config
1137
1104
  });
1138
1105
  if (source) {
1139
- await storage?.setItem(file.path, source);
1106
+ await config.storage.setItem(file.path, source);
1140
1107
  sources.set(file.path, source);
1141
1108
  }
1142
1109
  },
@@ -1189,13 +1156,27 @@ async function build(setupResult) {
1189
1156
  sources
1190
1157
  };
1191
1158
  }
1159
+ /**
1160
+ * Returns a snapshot of the current runtime environment.
1161
+ *
1162
+ * Useful for attaching context to debug logs and error reports so that
1163
+ * issues can be reproduced without manual information gathering.
1164
+ */
1165
+ function getDiagnosticInfo() {
1166
+ return {
1167
+ nodeVersion: node_process.version,
1168
+ KubbVersion: version,
1169
+ platform: process.platform,
1170
+ arch: process.arch,
1171
+ cwd: process.cwd()
1172
+ };
1173
+ }
1174
+ function isInputPath(config) {
1175
+ return typeof config?.input === "object" && config.input !== null && "path" in config.input;
1176
+ }
1192
1177
  function inputToAdapterSource(config) {
1193
1178
  const input = config.input;
1194
1179
  if (!input) throw new Error("[kubb] input is required when using an adapter. Provide input.path or input.data in your config.");
1195
- if (Array.isArray(input)) return {
1196
- type: "paths",
1197
- paths: input.map((i) => new URLPath(i.path).isURL ? i.path : (0, node_path.resolve)(config.root, i.path))
1198
- };
1199
1180
  if ("data" in input) return {
1200
1181
  type: "data",
1201
1182
  data: input.data
@@ -1401,34 +1382,6 @@ function defineParser(parser) {
1401
1382
  return parser;
1402
1383
  }
1403
1384
  //#endregion
1404
- //#region src/definePlugin.ts
1405
- /**
1406
- * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
1407
- *
1408
- * Handlers live in a single `hooks` object (inspired by Astro integrations).
1409
- * All lifecycle events from `KubbHooks` are available for subscription.
1410
- *
1411
- * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
1412
- * Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
1413
- *
1414
- * @example
1415
- * ```ts
1416
- * import { definePlugin } from '@kubb/core'
1417
- *
1418
- * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
1419
- * name: 'plugin-ts',
1420
- * hooks: {
1421
- * 'kubb:plugin:setup'(ctx) {
1422
- * ctx.setResolver(resolverTs)
1423
- * },
1424
- * },
1425
- * }))
1426
- * ```
1427
- */
1428
- function definePlugin(factory) {
1429
- return (options) => factory(options ?? {});
1430
- }
1431
- //#endregion
1432
1385
  //#region src/storages/memoryStorage.ts
1433
1386
  /**
1434
1387
  * In-memory storage driver. Useful for testing and dry-run scenarios where
@@ -1498,7 +1451,7 @@ exports.defineGenerator = defineGenerator;
1498
1451
  exports.defineLogger = defineLogger;
1499
1452
  exports.defineMiddleware = defineMiddleware;
1500
1453
  exports.defineParser = defineParser;
1501
- exports.definePlugin = definePlugin;
1454
+ exports.definePlugin = require_PluginDriver.definePlugin;
1502
1455
  exports.defineResolver = require_PluginDriver.defineResolver;
1503
1456
  exports.fsStorage = fsStorage;
1504
1457
  exports.isInputPath = isInputPath;