@kubb/core 5.0.0-beta.10 → 5.0.0-beta.12

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,7 +1,6 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { $ as ResolverPathParams, A as isInputPath, B as KubbPluginSetupContext, C as KubbPluginsEndContext, D as PossibleConfig, E as KubbWarnContext, F as FileManager, G as Plugin, H as NormalizedPlugin, I as Exclude, J as ResolveBannerContext, K as PluginFactoryOptions, L as Group, M as GeneratorContext, N as defineGenerator, O as UserConfig, P as PluginDriver, Q as ResolverFileParams, R as Include, S as KubbLifecycleStartContext, T as KubbVersionNewContext, U as Output, V as KubbPluginStartContext, W as Override, X as Resolver, Y as ResolveOptionsContext, Z as ResolverContext, _ as KubbGenerationSummaryContext, _t as AdapterFactoryOptions, a as InputPath, at as Logger, b as KubbHooks, bt as logLevel, c as KubbBuildStartContext, ct as UserLogger, d as KubbErrorContext, dt as Storage, et as defineResolver, f as KubbFileProcessingUpdateContext, ft as createStorage, g as KubbGenerationStartContext, gt as Adapter, h as KubbGenerationEndContext, ht as createRenderer, i as InputData, it as defineMiddleware, j as Generator, k as createKubb, l as KubbConfigEndContext, lt as defineLogger, m as KubbFilesProcessingStartContext, mt as RendererFactory, n as CLIOptions, nt as defineParser, o as Kubb, ot as LoggerContext, p as KubbFilesProcessingEndContext, pt as Renderer, q as definePlugin, r as Config, rt as Middleware, s as KubbBuildEndContext, st as LoggerOptions, t as BuildOutput, tt as Parser, u as KubbDebugContext, ut as DevtoolsOptions, v as KubbHookEndContext, vt as AdapterSource, w as KubbSuccessContext, x as KubbInfoContext, xt as AsyncEventEmitter, y as KubbHookStartContext, yt as createAdapter, z as KubbPluginEndContext } from "./createKubb-ALdb8lmq.js";
2
+ import { $ as ResolverPathParams, A as isInputPath, B as KubbPluginSetupContext, C as KubbPluginsEndContext, Ct as AsyncEventEmitter, D as PossibleConfig, E as KubbWarnContext, F as FileManager, G as Plugin, H as NormalizedPlugin, I as Exclude, J as ResolveBannerContext, K as PluginFactoryOptions, L as Group, M as GeneratorContext, N as defineGenerator, O as UserConfig, P as PluginDriver, Q as ResolverFileParams, R as Include, S as KubbLifecycleStartContext, St as logLevel, T as KubbVersionNewContext, U as Output, V as KubbPluginStartContext, W as Override, X as Resolver, Y as ResolveOptionsContext, Z as ResolverContext, _ as KubbGenerationSummaryContext, _t as createRenderer, a as InputPath, at as LoggerOptions, b as KubbHooks, bt as AdapterSource, c as KubbBuildStartContext, ct as FileProcessor, d as KubbErrorContext, dt as defineParser, et as defineResolver, f as KubbFileProcessingUpdateContext, ft as DevtoolsOptions, g as KubbGenerationStartContext, gt as RendererFactory, h as KubbGenerationEndContext, ht as Renderer, i as InputData, it as LoggerContext, j as Generator, k as createKubb, l as KubbConfigEndContext, lt as FileProcessorEvents, m as KubbFilesProcessingStartContext, mt as createStorage, n as CLIOptions, nt as defineMiddleware, o as Kubb, ot as UserLogger, p as KubbFilesProcessingEndContext, pt as Storage, q as definePlugin, r as Config, rt as Logger, s as KubbBuildEndContext, st as defineLogger, t as BuildOutput, tt as Middleware, u as KubbDebugContext, ut as Parser, v as KubbHookEndContext, vt as Adapter, w as KubbSuccessContext, x as KubbInfoContext, xt as createAdapter, y as KubbHookStartContext, yt as AdapterFactoryOptions, z as KubbPluginEndContext } from "./createKubb-uVWTlN_w.js";
3
3
  import * as ast from "@kubb/ast";
4
- import { FileNode } from "@kubb/ast";
5
4
 
6
5
  //#region ../../internals/utils/src/urlPath.d.ts
7
6
  type URLObject = {
@@ -139,48 +138,6 @@ declare class URLPath {
139
138
  toURLPath(): string;
140
139
  }
141
140
  //#endregion
142
- //#region src/FileProcessor.d.ts
143
- type ParseOptions = {
144
- parsers?: Map<FileNode['extname'], Parser>;
145
- extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
146
- };
147
- type RunOptions = ParseOptions & {
148
- /**
149
- * @default 'sequential'
150
- */
151
- mode?: 'sequential' | 'parallel';
152
- onStart?: (files: Array<FileNode>) => Promise<void> | void;
153
- onEnd?: (files: Array<FileNode>) => Promise<void> | void;
154
- onUpdate?: (params: {
155
- file: FileNode;
156
- source?: string;
157
- processed: number;
158
- total: number;
159
- percentage: number;
160
- }) => Promise<void> | void;
161
- };
162
- /**
163
- * Converts a single file to a string using the registered parsers.
164
- * Falls back to joining source values when no matching parser is found.
165
- *
166
- * @internal
167
- */
168
- declare class FileProcessor {
169
- #private;
170
- parse(file: FileNode, {
171
- parsers,
172
- extension
173
- }?: ParseOptions): Promise<string>;
174
- run(files: Array<FileNode>, {
175
- parsers,
176
- mode,
177
- extension,
178
- onStart,
179
- onEnd,
180
- onUpdate
181
- }?: RunOptions): Promise<Array<FileNode>>;
182
- }
183
- //#endregion
184
141
  //#region src/storages/fsStorage.d.ts
185
142
  /**
186
143
  * Built-in filesystem storage driver.
@@ -231,5 +188,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
231
188
  */
232
189
  declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
233
190
  //#endregion
234
- export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BuildOutput, CLIOptions, Config, DevtoolsOptions, Exclude, FileManager, FileProcessor, Generator, GeneratorContext, Group, Include, InputData, InputPath, Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbConfigEndContext, KubbDebugContext, KubbErrorContext, KubbFileProcessingUpdateContext, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbVersionNewContext, KubbWarnContext, Logger, LoggerContext, LoggerOptions, Middleware, NormalizedPlugin, Output, Override, Parser, Plugin, PluginDriver, PluginFactoryOptions, PossibleConfig, Renderer, RendererFactory, ResolveBannerContext, ResolveOptionsContext, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, Storage, URLPath, UserConfig, UserLogger, ast, createAdapter, createKubb, createRenderer, createStorage, defineGenerator, defineLogger, defineMiddleware, defineParser, definePlugin, defineResolver, fsStorage, isInputPath, logLevel, memoryStorage };
191
+ export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BuildOutput, CLIOptions, Config, DevtoolsOptions, Exclude, FileManager, FileProcessor, FileProcessorEvents, Generator, GeneratorContext, Group, Include, InputData, InputPath, Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbConfigEndContext, KubbDebugContext, KubbErrorContext, KubbFileProcessingUpdateContext, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbVersionNewContext, KubbWarnContext, Logger, LoggerContext, LoggerOptions, Middleware, NormalizedPlugin, Output, Override, Parser, Plugin, PluginDriver, PluginFactoryOptions, PossibleConfig, Renderer, RendererFactory, ResolveBannerContext, ResolveOptionsContext, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, Storage, URLPath, UserConfig, UserLogger, ast, createAdapter, createKubb, createRenderer, createStorage, defineGenerator, defineLogger, defineMiddleware, defineParser, definePlugin, defineResolver, fsStorage, isInputPath, logLevel, memoryStorage };
235
192
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { a as definePlugin, c as DEFAULT_STUDIO_URL, i as defineResolver, l as logLevel, n as applyHookResult, o as DEFAULT_BANNER, r as FileManager, s as DEFAULT_EXTENSION, t as PluginDriver, u as camelCase } from "./PluginDriver-D8Z0Htid.js";
2
+ import { a as definePlugin, c as DEFAULT_STUDIO_URL, i as defineResolver, l as logLevel, n as applyHookResult, o as DEFAULT_BANNER, r as FileManager, s as DEFAULT_EXTENSION, t as PluginDriver, u as camelCase } from "./PluginDriver-CGypdXHg.js";
3
3
  import { EventEmitter } from "node:events";
4
4
  import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
5
5
  import { dirname, join, resolve } from "node:path";
@@ -525,7 +525,44 @@ function createAdapter(build) {
525
525
  }
526
526
  //#endregion
527
527
  //#region package.json
528
- var version$1 = "5.0.0-beta.10";
528
+ var version$1 = "5.0.0-beta.12";
529
+ //#endregion
530
+ //#region src/createStorage.ts
531
+ /**
532
+ * Factory for implementing custom storage backends that control where generated files are written.
533
+ *
534
+ * Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.
535
+ * Kubb provides filesystem and in-memory implementations out of the box.
536
+ *
537
+ * @note Call the returned factory with optional options to instantiate the storage adapter.
538
+ *
539
+ * @example
540
+ * ```ts
541
+ * import { createStorage } from '@kubb/core'
542
+ *
543
+ * export const memoryStorage = createStorage(() => {
544
+ * const store = new Map<string, string>()
545
+ * return {
546
+ * name: 'memory',
547
+ * async hasItem(key) { return store.has(key) },
548
+ * async getItem(key) { return store.get(key) ?? null },
549
+ * async setItem(key, value) { store.set(key, value) },
550
+ * async removeItem(key) { store.delete(key) },
551
+ * async getKeys(base) {
552
+ * const keys = [...store.keys()]
553
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
554
+ * },
555
+ * async clear(base) { if (!base) store.clear() },
556
+ * }
557
+ * })
558
+ *
559
+ * // Instantiate:
560
+ * const storage = memoryStorage()
561
+ * ```
562
+ */
563
+ function createStorage(build) {
564
+ return (options) => build(options ?? {});
565
+ }
529
566
  //#endregion
530
567
  //#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
531
568
  var Node$1 = class {
@@ -668,7 +705,8 @@ function joinSources(file) {
668
705
  * @internal
669
706
  */
670
707
  var FileProcessor = class {
671
- #limit = pLimit(100);
708
+ events = new AsyncEventEmitter();
709
+ #limit = pLimit(16);
672
710
  async parse(file, { parsers, extension } = {}) {
673
711
  const parseExtName = extension?.[file.extname] || void 0;
674
712
  if (!parsers || !file.extname) return joinSources(file);
@@ -676,8 +714,8 @@ var FileProcessor = class {
676
714
  if (!parser) return joinSources(file);
677
715
  return parser.parse(file, { extname: parseExtName });
678
716
  }
679
- async run(files, { parsers, mode = "sequential", extension, onStart, onEnd, onUpdate } = {}) {
680
- await onStart?.(files);
717
+ async run(files, { parsers, mode = "sequential", extension } = {}) {
718
+ await this.events.emit("start", files);
681
719
  const total = files.length;
682
720
  let processed = 0;
683
721
  const processOne = async (file) => {
@@ -687,7 +725,7 @@ var FileProcessor = class {
687
725
  });
688
726
  const currentProcessed = ++processed;
689
727
  const percentage = currentProcessed / total * 100;
690
- await onUpdate?.({
728
+ await this.events.emit("update", {
691
729
  file,
692
730
  source,
693
731
  processed: currentProcessed,
@@ -697,48 +735,11 @@ var FileProcessor = class {
697
735
  };
698
736
  if (mode === "sequential") for (const file of files) await processOne(file);
699
737
  else await Promise.all(files.map((file) => this.#limit(() => processOne(file))));
700
- await onEnd?.(files);
738
+ await this.events.emit("end", files);
701
739
  return files;
702
740
  }
703
741
  };
704
742
  //#endregion
705
- //#region src/createStorage.ts
706
- /**
707
- * Factory for implementing custom storage backends that control where generated files are written.
708
- *
709
- * Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.
710
- * Kubb provides filesystem and in-memory implementations out of the box.
711
- *
712
- * @note Call the returned factory with optional options to instantiate the storage adapter.
713
- *
714
- * @example
715
- * ```ts
716
- * import { createStorage } from '@kubb/core'
717
- *
718
- * export const memoryStorage = createStorage(() => {
719
- * const store = new Map<string, string>()
720
- * return {
721
- * name: 'memory',
722
- * async hasItem(key) { return store.has(key) },
723
- * async getItem(key) { return store.get(key) ?? null },
724
- * async setItem(key, value) { store.set(key, value) },
725
- * async removeItem(key) { store.delete(key) },
726
- * async getKeys(base) {
727
- * const keys = [...store.keys()]
728
- * return base ? keys.filter((k) => k.startsWith(base)) : keys
729
- * },
730
- * async clear(base) { if (!base) store.clear() },
731
- * }
732
- * })
733
- *
734
- * // Instantiate:
735
- * const storage = memoryStorage()
736
- * ```
737
- */
738
- function createStorage(build) {
739
- return (options) => build(options ?? {});
740
- }
741
- //#endregion
742
743
  //#region src/storages/fsStorage.ts
743
744
  /**
744
745
  * Built-in filesystem storage driver.
@@ -814,6 +815,44 @@ const fsStorage = createStorage(() => ({
814
815
  }));
815
816
  //#endregion
816
817
  //#region src/createKubb.ts
818
+ /**
819
+ * Builds a `Storage` view scoped to the file paths produced by the current build.
820
+ *
821
+ * Reads delegate to the underlying `storage` (typically `fsStorage()`) so source bytes
822
+ * stay where they were written instead of being held in an extra in-memory map.
823
+ * Writing via `setItem` stores the content in the underlying storage and registers the
824
+ * key so subsequent reads and `getKeys` are scoped to this build's output.
825
+ */
826
+ function createSourcesView(storage) {
827
+ const paths = /* @__PURE__ */ new Set();
828
+ return createStorage(() => ({
829
+ name: `${storage.name}:sources`,
830
+ async hasItem(key) {
831
+ return paths.has(key) && await storage.hasItem(key);
832
+ },
833
+ async getItem(key) {
834
+ return paths.has(key) ? storage.getItem(key) : null;
835
+ },
836
+ async setItem(key, value) {
837
+ paths.add(key);
838
+ await storage.setItem(key, value);
839
+ },
840
+ async removeItem(key) {
841
+ paths.delete(key);
842
+ await storage.removeItem(key);
843
+ },
844
+ async getKeys(base) {
845
+ if (!base) return [...paths];
846
+ const result = [];
847
+ for (const key of paths) if (key.startsWith(base)) result.push(key);
848
+ return result;
849
+ },
850
+ async clear() {
851
+ paths.clear();
852
+ await storage.clear();
853
+ }
854
+ }))();
855
+ }
817
856
  async function setup(userConfig, options = {}) {
818
857
  const hooks = options.hooks ?? new AsyncEventEmitter();
819
858
  const config = {
@@ -836,7 +875,7 @@ async function setup(userConfig, options = {}) {
836
875
  plugins: userConfig.plugins ?? []
837
876
  };
838
877
  const driver = new PluginDriver(config, { hooks });
839
- const sources = /* @__PURE__ */ new Map();
878
+ const storage = createSourcesView(config.storage);
840
879
  const diagnosticInfo = getDiagnosticInfo();
841
880
  await hooks.emit("kubb:debug", {
842
881
  date: /* @__PURE__ */ new Date(),
@@ -901,7 +940,7 @@ async function setup(userConfig, options = {}) {
901
940
  config,
902
941
  hooks,
903
942
  driver,
904
- sources
943
+ storage
905
944
  };
906
945
  }
907
946
  /**
@@ -1000,10 +1039,49 @@ async function runPluginAstHooks(plugin, context) {
1000
1039
  }
1001
1040
  }
1002
1041
  async function safeBuild(setupResult) {
1003
- const { driver, hooks, sources } = setupResult;
1042
+ const { driver, hooks, storage } = setupResult;
1004
1043
  const failedPlugins = /* @__PURE__ */ new Set();
1005
1044
  const pluginTimings = /* @__PURE__ */ new Map();
1006
1045
  const config = driver.config;
1046
+ const writtenPaths = /* @__PURE__ */ new Set();
1047
+ const parsersMap = /* @__PURE__ */ new Map();
1048
+ for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
1049
+ const fileProcessor = new FileProcessor();
1050
+ fileProcessor.events.on("start", async (processingFiles) => {
1051
+ await hooks.emit("kubb:files:processing:start", { files: processingFiles });
1052
+ });
1053
+ fileProcessor.events.on("update", async ({ file, source, processed, total, percentage }) => {
1054
+ await hooks.emit("kubb:file:processing:update", {
1055
+ file,
1056
+ source,
1057
+ processed,
1058
+ total,
1059
+ percentage,
1060
+ config
1061
+ });
1062
+ if (source) await storage.setItem(file.path, source);
1063
+ });
1064
+ fileProcessor.events.on("end", async (processed) => {
1065
+ await hooks.emit("kubb:files:processing:end", { files: processed });
1066
+ await hooks.emit("kubb:debug", {
1067
+ date: /* @__PURE__ */ new Date(),
1068
+ logs: [`✓ File write process completed for ${processed.length} files`]
1069
+ });
1070
+ });
1071
+ async function flushPendingFiles() {
1072
+ const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path));
1073
+ if (files.length === 0) return;
1074
+ await hooks.emit("kubb:debug", {
1075
+ date: /* @__PURE__ */ new Date(),
1076
+ logs: [`Writing ${files.length} files...`]
1077
+ });
1078
+ await fileProcessor.run(files, {
1079
+ parsers: parsersMap,
1080
+ mode: "parallel",
1081
+ extension: config.output.extension
1082
+ });
1083
+ for (const file of files) writtenPaths.add(file.path);
1084
+ }
1007
1085
  try {
1008
1086
  await driver.emitSetupHooks();
1009
1087
  if (driver.adapter && driver.inputNode) await hooks.emit("kubb:build:start", {
@@ -1039,6 +1117,7 @@ async function safeBuild(setupResult) {
1039
1117
  },
1040
1118
  upsertFile: (...files) => driver.fileManager.upsert(...files)
1041
1119
  });
1120
+ await flushPendingFiles();
1042
1121
  await hooks.emit("kubb:debug", {
1043
1122
  date: /* @__PURE__ */ new Date(),
1044
1123
  logs: [`✓ Plugin started successfully (${formatMs(duration)})`]
@@ -1058,6 +1137,7 @@ async function safeBuild(setupResult) {
1058
1137
  },
1059
1138
  upsertFile: (...files) => driver.fileManager.upsert(...files)
1060
1139
  });
1140
+ await flushPendingFiles();
1061
1141
  await hooks.emit("kubb:debug", {
1062
1142
  date: errorTimestamp,
1063
1143
  logs: [
@@ -1081,43 +1161,8 @@ async function safeBuild(setupResult) {
1081
1161
  },
1082
1162
  upsertFile: (...files) => driver.fileManager.upsert(...files)
1083
1163
  });
1164
+ await flushPendingFiles();
1084
1165
  const files = driver.fileManager.files;
1085
- const parsersMap = /* @__PURE__ */ new Map();
1086
- for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
1087
- const fileProcessor = new FileProcessor();
1088
- await hooks.emit("kubb:debug", {
1089
- date: /* @__PURE__ */ new Date(),
1090
- logs: [`Writing ${files.length} files...`]
1091
- });
1092
- await fileProcessor.run(files, {
1093
- parsers: parsersMap,
1094
- mode: "parallel",
1095
- extension: config.output.extension,
1096
- onStart: async (processingFiles) => {
1097
- await hooks.emit("kubb:files:processing:start", { files: processingFiles });
1098
- },
1099
- onUpdate: async ({ file, source, processed, total, percentage }) => {
1100
- await hooks.emit("kubb:file:processing:update", {
1101
- file,
1102
- source,
1103
- processed,
1104
- total,
1105
- percentage,
1106
- config
1107
- });
1108
- if (source) {
1109
- await config.storage.setItem(file.path, source);
1110
- sources.set(file.path, source);
1111
- }
1112
- },
1113
- onEnd: async (processedFiles) => {
1114
- await hooks.emit("kubb:files:processing:end", { files: processedFiles });
1115
- await hooks.emit("kubb:debug", {
1116
- date: /* @__PURE__ */ new Date(),
1117
- logs: [`✓ File write process completed for ${processedFiles.length} files`]
1118
- });
1119
- }
1120
- });
1121
1166
  await hooks.emit("kubb:build:end", {
1122
1167
  files,
1123
1168
  config,
@@ -1128,7 +1173,7 @@ async function safeBuild(setupResult) {
1128
1173
  files,
1129
1174
  driver,
1130
1175
  pluginTimings,
1131
- sources
1176
+ storage
1132
1177
  };
1133
1178
  } catch (error) {
1134
1179
  return {
@@ -1137,14 +1182,14 @@ async function safeBuild(setupResult) {
1137
1182
  driver,
1138
1183
  pluginTimings,
1139
1184
  error,
1140
- sources
1185
+ storage
1141
1186
  };
1142
1187
  } finally {
1143
1188
  driver.dispose();
1144
1189
  }
1145
1190
  }
1146
1191
  async function build(setupResult) {
1147
- const { files, driver, failedPlugins, pluginTimings, error, sources } = await safeBuild(setupResult);
1192
+ const { files, driver, failedPlugins, pluginTimings, error, storage } = await safeBuild(setupResult);
1148
1193
  if (error) throw error;
1149
1194
  if (failedPlugins.size > 0) {
1150
1195
  const errors = [...failedPlugins].map(({ error }) => error);
@@ -1156,7 +1201,7 @@ async function build(setupResult) {
1156
1201
  driver,
1157
1202
  pluginTimings,
1158
1203
  error: void 0,
1159
- sources
1204
+ storage
1160
1205
  };
1161
1206
  }
1162
1207
  /**
@@ -1197,7 +1242,7 @@ function inputToAdapterSource(config) {
1197
1242
  * Creates a Kubb instance bound to a single config entry.
1198
1243
  *
1199
1244
  * Accepts a user-facing config shape and resolves it to a full {@link Config} during
1200
- * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
1245
+ * `setup()`. The instance then holds shared state (`hooks`, `storage`, `driver`, `config`)
1201
1246
  * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
1202
1247
  * calling `setup()` or `build()`.
1203
1248
  *
@@ -1219,14 +1264,17 @@ function createKubb(userConfig, options = {}) {
1219
1264
  get hooks() {
1220
1265
  return hooks;
1221
1266
  },
1222
- get sources() {
1223
- return setupResult?.sources ?? /* @__PURE__ */ new Map();
1267
+ get storage() {
1268
+ if (!setupResult) throw new Error("[kubb] setup() must be called before accessing storage");
1269
+ return setupResult.storage;
1224
1270
  },
1225
1271
  get driver() {
1226
- return setupResult?.driver;
1272
+ if (!setupResult) throw new Error("[kubb] setup() must be called before accessing driver");
1273
+ return setupResult.driver;
1227
1274
  },
1228
1275
  get config() {
1229
- return setupResult?.config;
1276
+ if (!setupResult) throw new Error("[kubb] setup() must be called before accessing config");
1277
+ return setupResult.config;
1230
1278
  },
1231
1279
  async setup() {
1232
1280
  setupResult = await setup(userConfig, { hooks });