@kubb/core 5.0.0-beta.20 → 5.0.0-beta.21

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.
@@ -250,6 +250,10 @@ type Renderer<TElement = unknown> = {
250
250
  * Pass an `Error` to signal a failure, a number for an exit code, or omit for a clean shutdown.
251
251
  */
252
252
  unmount(error?: Error | number | null): void;
253
+ /**
254
+ * Releases any held resources. `[Symbol.dispose]` delegates here.
255
+ */
256
+ dispose(): void;
253
257
  /**
254
258
  * Accumulated {@link FileNode} results produced by the last {@link render} call.
255
259
  * Not populated when {@link stream} is implemented.
@@ -260,6 +264,11 @@ type Renderer<TElement = unknown> = {
260
264
  * forwarding each file to `FileManager` as soon as it is ready.
261
265
  */
262
266
  stream?(element: TElement): Iterable<FileNode>;
267
+ /**
268
+ * Disposer hook so renderers participate in `using` blocks: `using r = rendererFactory()`
269
+ * guarantees {@link dispose} runs on every exit path, including thrown errors.
270
+ */
271
+ [Symbol.dispose](): void;
263
272
  };
264
273
  /**
265
274
  * A factory function that produces a fresh {@link Renderer} per render cycle.
@@ -277,6 +286,7 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
277
286
  * return {
278
287
  * async render(element) { await runtime.render(element) },
279
288
  * get files() { return runtime.nodes },
289
+ * dispose() { runtime.unmount() },
280
290
  * unmount(error) { runtime.unmount(error) },
281
291
  * }
282
292
  * })
@@ -439,6 +449,11 @@ declare class FileProcessor {
439
449
  }?: ParseOptions): string;
440
450
  stream(files: ReadonlyArray<FileNode>, options?: ParseOptions): Generator<ParsedFile>;
441
451
  run(files: Array<FileNode>, options?: ParseOptions): Promise<Array<FileNode>>;
452
+ /**
453
+ * Clears all registered event listeners.
454
+ */
455
+ dispose(): void;
456
+ [Symbol.dispose](): void;
442
457
  }
443
458
  //#endregion
444
459
  //#region src/defineLogger.d.ts
@@ -592,8 +607,8 @@ type Resolver = {
592
607
  resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
593
608
  resolvePath(params: ResolverPathParams, context: ResolverContext): string;
594
609
  resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
595
- resolveBanner(meta: InputMeta | undefined, context: ResolveBannerContext): string | undefined;
596
- resolveFooter(meta: InputMeta | undefined, context: ResolveBannerContext): string | undefined;
610
+ resolveBanner(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
611
+ resolveFooter(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
597
612
  };
598
613
  /**
599
614
  * File-specific parameters for `Resolver.resolvePath`.
@@ -1086,45 +1101,39 @@ declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFact
1086
1101
  //#endregion
1087
1102
  //#region src/FileManager.d.ts
1088
1103
  /**
1089
- * In-memory file store for generated files.
1090
- *
1091
- * Files with the same `path` are merged sources, imports, and exports are concatenated.
1092
- * The `files` getter returns all stored files sorted by path length (shortest first).
1104
+ * In-memory file store for generated files. Files sharing a `path` are merged
1105
+ * (sources/imports/exports concatenated). The `files` getter is sorted by
1106
+ * path length (barrel `index.ts` last within a bucket).
1093
1107
  *
1094
1108
  * @example
1095
1109
  * ```ts
1096
- * import { FileManager } from '@kubb/core'
1097
- *
1098
1110
  * const manager = new FileManager()
1099
1111
  * manager.upsert(myFile)
1100
- * console.log(manager.files) // all stored files
1112
+ * manager.files // sorted view
1101
1113
  * ```
1102
1114
  */
1103
1115
  declare class FileManager {
1104
1116
  #private;
1105
1117
  /**
1106
- * Adds one or more files. Incoming files with the same path are merged
1107
- * (sources/imports/exports concatenated), but existing cache entries are
1108
- * replaced use {@link upsert} when you want to merge into the cache too.
1118
+ * Registers a callback invoked with the resolved {@link FileNode} on every
1119
+ * `add` / `upsert`. Used by the build loop to track newly written files
1120
+ * without keeping its own scan-based diff. Single subscriber by design
1121
+ * setting again replaces the previous callback. Pass `null` to detach.
1109
1122
  */
1123
+ setOnUpsert(callback: ((file: FileNode) => void) | null): void;
1110
1124
  add(...files: Array<FileNode>): Array<FileNode>;
1111
- /**
1112
- * Adds or merges one or more files.
1113
- * If a file with the same path already exists in the cache, its
1114
- * sources/imports/exports are merged into the incoming file.
1115
- */
1116
1125
  upsert(...files: Array<FileNode>): Array<FileNode>;
1117
1126
  getByPath(path: string): FileNode | null;
1118
1127
  deleteByPath(path: string): void;
1119
1128
  clear(): void;
1120
1129
  /**
1121
- * Releases all stored files. Called by the core after `kubb:build:end` to
1122
- * free the per-plugin FileNode caches for the rest of the process lifetime.
1130
+ * Releases all stored files. Called by the core after `kubb:build:end`.
1123
1131
  */
1124
1132
  dispose(): void;
1125
1133
  [Symbol.dispose](): void;
1126
1134
  /**
1127
- * All stored files, sorted by path length (shorter paths first).
1135
+ * All stored files in stable sort order (shortest path first, barrel files
1136
+ * last within a length bucket). Returns a cached view — do not mutate.
1128
1137
  */
1129
1138
  get files(): Array<FileNode>;
1130
1139
  }
@@ -1151,8 +1160,8 @@ declare class KubbDriver {
1151
1160
  * The streaming `InputStreamNode` produced by the adapter.
1152
1161
  * Always set after adapter setup — parse-only adapters are wrapped automatically.
1153
1162
  */
1154
- inputNode: InputStreamNode | undefined;
1155
- adapter: Adapter | undefined;
1163
+ inputNode: InputStreamNode | null;
1164
+ adapter: Adapter | null;
1156
1165
  /**
1157
1166
  * Central file store for all generated files.
1158
1167
  * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
@@ -1193,6 +1202,23 @@ declare class KubbDriver {
1193
1202
  * for a plugin that has no static `plugin.generators`.
1194
1203
  */
1195
1204
  hasEventGenerators(pluginName: string): boolean;
1205
+ /**
1206
+ * Runs the full plugin pipeline. Returns timings/failures collected so far even
1207
+ * when an outer hook throws — the orchestrator preserves partial state by capturing
1208
+ * the error into `error` instead of propagating.
1209
+ */
1210
+ run({
1211
+ storage
1212
+ }: {
1213
+ storage: Storage;
1214
+ }): Promise<{
1215
+ failedPlugins: Set<{
1216
+ plugin: Plugin;
1217
+ error: Error;
1218
+ }>;
1219
+ pluginTimings: Map<string, number>;
1220
+ error?: Error;
1221
+ }>;
1196
1222
  /**
1197
1223
  * Unregisters all plugin lifecycle listeners from the shared event emitter.
1198
1224
  * Called at the end of a build to prevent listener leaks across repeated builds.
@@ -1878,7 +1904,7 @@ interface KubbHooks {
1878
1904
  'kubb:warn': [ctx: KubbWarnContext];
1879
1905
  'kubb:debug': [ctx: KubbDebugContext];
1880
1906
  'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
1881
- 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext];
1907
+ 'kubb:files:processing:update': [ctx: KubbFilesProcessingUpdateContext];
1882
1908
  'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
1883
1909
  'kubb:plugin:start': [ctx: KubbPluginStartContext];
1884
1910
  'kubb:plugin:end': [ctx: KubbPluginEndContext];
@@ -2084,7 +2110,7 @@ type KubbFilesProcessingStartContext = {
2084
2110
  */
2085
2111
  files: Array<FileNode>;
2086
2112
  };
2087
- type KubbFileProcessingUpdateContext = {
2113
+ type KubbFileProcessingUpdate = {
2088
2114
  /**
2089
2115
  * Number of files processed so far in this batch.
2090
2116
  */
@@ -2110,6 +2136,12 @@ type KubbFileProcessingUpdateContext = {
2110
2136
  */
2111
2137
  config: Config;
2112
2138
  };
2139
+ type KubbFilesProcessingUpdateContext = {
2140
+ /**
2141
+ * All files processed in this flush chunk.
2142
+ */
2143
+ files: Array<KubbFileProcessingUpdate>;
2144
+ };
2113
2145
  type KubbFilesProcessingEndContext = {
2114
2146
  /**
2115
2147
  * All files that were serialised in this batch.
@@ -2215,59 +2247,6 @@ type BuildOutput = {
2215
2247
  */
2216
2248
  storage: Storage;
2217
2249
  };
2218
- /**
2219
- * Kubb code generation instance returned by {@link createKubb}.
2220
- *
2221
- * Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.
2222
- * For a single one-off build, chain directly: `await createKubb(config).build()`.
2223
- */
2224
- type Kubb$1 = {
2225
- /**
2226
- * Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.
2227
- */
2228
- readonly hooks: AsyncEventEmitter<KubbHooks>;
2229
- /**
2230
- * Read-only view of the files from the most recent `build()` or `safeBuild()` call.
2231
- * Only populated after the build completes.
2232
- *
2233
- * Keys are scoped to the current run. Reads go straight to `config.storage`,
2234
- * so nothing extra is held in memory.
2235
- *
2236
- * @example Read a generated file
2237
- * ```ts
2238
- * const { storage } = await kubb.safeBuild()
2239
- * const code = await storage.getItem('/src/gen/pet.ts')
2240
- * ```
2241
- *
2242
- * @example Walk every generated file
2243
- * ```ts
2244
- * for (const path of await kubb.storage.getKeys()) {
2245
- * const code = await kubb.storage.getItem(path)
2246
- * }
2247
- * ```
2248
- */
2249
- readonly storage: Storage;
2250
- /**
2251
- * Plugin driver managing all plugins. Available after `setup()` completes.
2252
- */
2253
- readonly driver: KubbDriver;
2254
- /**
2255
- * Resolved configuration with defaults applied. Available after `setup()` completes.
2256
- */
2257
- readonly config: Config;
2258
- /**
2259
- * Resolves config and initializes the driver. `build()` calls this automatically.
2260
- */
2261
- setup(): Promise<void>;
2262
- /**
2263
- * Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.
2264
- */
2265
- build(): Promise<BuildOutput>;
2266
- /**
2267
- * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.
2268
- */
2269
- safeBuild(): Promise<BuildOutput>;
2270
- };
2271
2250
  /**
2272
2251
  * Type guard to check if a given config has an `input.path`.
2273
2252
  */
@@ -2281,25 +2260,48 @@ type CreateKubbOptions = {
2281
2260
  hooks?: AsyncEventEmitter<KubbHooks>;
2282
2261
  };
2283
2262
  /**
2284
- * Creates a Kubb instance bound to a single config entry.
2263
+ * Kubb code-generation instance bound to a single config entry. Resolves the user
2264
+ * config during `setup()` and shares `hooks`, `storage`, `driver`, and `config` across
2265
+ * the `setup → build` lifecycle.
2285
2266
  *
2286
- * Accepts a user-facing config shape and resolves it to a full {@link Config} during
2287
- * `setup()`. The instance then holds shared state (`hooks`, `storage`, `driver`, `config`)
2288
- * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
2289
- * calling `setup()` or `build()`.
2267
+ * Attach event listeners to `.hooks` before calling `setup()` or `build()`.
2290
2268
  *
2291
2269
  * @example
2292
2270
  * ```ts
2293
2271
  * const kubb = createKubb(userConfig)
2294
- *
2295
- * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
2296
- * console.log(`${plugin.name} completed in ${duration}ms`)
2297
- * })
2298
- *
2272
+ * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => console.log(plugin.name, duration))
2299
2273
  * const { files, failedPlugins } = await kubb.safeBuild()
2300
2274
  * ```
2301
2275
  */
2276
+ declare class Kubb$1 {
2277
+ #private;
2278
+ readonly hooks: AsyncEventEmitter<KubbHooks>;
2279
+ constructor(userConfig: UserConfig, options?: CreateKubbOptions);
2280
+ get storage(): Storage;
2281
+ get driver(): KubbDriver;
2282
+ get config(): Config;
2283
+ /**
2284
+ * Resolves config and initializes the driver. `build()` calls this automatically.
2285
+ */
2286
+ setup(): Promise<void>;
2287
+ /**
2288
+ * Runs the full pipeline and throws on any plugin error.
2289
+ * Automatically calls `setup()` if needed.
2290
+ */
2291
+ build(): Promise<BuildOutput>;
2292
+ /**
2293
+ * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing.
2294
+ * Automatically calls `setup()` if needed.
2295
+ */
2296
+ safeBuild(): Promise<BuildOutput>;
2297
+ dispose(): void;
2298
+ [Symbol.dispose](): void;
2299
+ }
2300
+ /**
2301
+ * Factory for {@link Kubb}. Equivalent to `new Kubb(userConfig, options)` and kept
2302
+ * as the canonical public entry point.
2303
+ */
2302
2304
  declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
2303
2305
  //#endregion
2304
- export { ResolverPathParams as $, isInputPath as A, KubbPluginSetupContext as B, KubbPluginsEndContext as C, logLevel as Ct, PossibleConfig as D, KubbWarnContext as E, FileManager as F, Plugin as G, NormalizedPlugin as H, Exclude as I, ResolveBannerContext as J, PluginFactoryOptions as K, Group as L, GeneratorContext as M, defineGenerator as N, UserConfig as O, KubbDriver as P, ResolverFileParams as Q, Include as R, KubbLifecycleStartContext as S, createAdapter as St, KubbVersionNewContext as T, Output as U, KubbPluginStartContext as V, Override as W, Resolver as X, ResolveOptionsContext as Y, ResolverContext as Z, KubbGenerationSummaryContext as _, RendererFactory as _t, InputPath as a, LoggerOptions as at, KubbHooks as b, AdapterFactoryOptions as bt, KubbBuildStartContext as c, FileProcessor as ct, KubbErrorContext as d, Parser as dt, defineResolver as et, KubbFileProcessingUpdateContext as f, defineParser as ft, KubbGenerationStartContext as g, Renderer as gt, KubbGenerationEndContext as h, createStorage as ht, InputData as i, LoggerContext as it, Generator$1 as j, createKubb as k, KubbConfigEndContext as l, FileProcessorEvents as lt, KubbFilesProcessingStartContext as m, Storage as mt, CLIOptions as n, defineMiddleware as nt, Kubb$1 as o, UserLogger as ot, KubbFilesProcessingEndContext as p, DevtoolsOptions as pt, definePlugin as q, Config as r, Logger as rt, KubbBuildEndContext as s, defineLogger as st, BuildOutput as t, Middleware as tt, KubbDebugContext as u, ParsedFile as ut, KubbHookEndContext as v, createRenderer as vt, KubbSuccessContext as w, AsyncEventEmitter as wt, KubbInfoContext as x, AdapterSource as xt, KubbHookStartContext as y, Adapter as yt, KubbPluginEndContext as z };
2305
- //# sourceMappingURL=createKubb-Dcmtjqds.d.ts.map
2306
+ export { ResolverFileParams as $, createKubb as A, KubbPluginEndContext as B, KubbLifecycleStartContext as C, createAdapter as Ct, KubbWarnContext as D, KubbVersionNewContext as E, KubbDriver as F, Override as G, KubbPluginStartContext as H, FileManager as I, definePlugin as J, Plugin as K, Exclude as L, Generator$1 as M, GeneratorContext as N, PossibleConfig as O, defineGenerator as P, ResolverContext as Q, Group as R, KubbInfoContext as S, AdapterSource as St, KubbSuccessContext as T, AsyncEventEmitter as Tt, NormalizedPlugin as U, KubbPluginSetupContext as V, Output as W, ResolveOptionsContext as X, ResolveBannerContext as Y, Resolver as Z, KubbGenerationStartContext as _, Renderer as _t, InputPath as a, LoggerContext as at, KubbHookStartContext as b, Adapter as bt, KubbBuildStartContext as c, defineLogger as ct, KubbErrorContext as d, ParsedFile as dt, ResolverPathParams as et, KubbFileProcessingUpdate as f, Parser as ft, KubbGenerationEndContext as g, createStorage as gt, KubbFilesProcessingUpdateContext as h, Storage as ht, InputData as i, Logger as it, isInputPath as j, UserConfig as k, KubbConfigEndContext as l, FileProcessor as lt, KubbFilesProcessingStartContext as m, DevtoolsOptions as mt, CLIOptions as n, Middleware as nt, Kubb$1 as o, LoggerOptions as ot, KubbFilesProcessingEndContext as p, defineParser as pt, PluginFactoryOptions as q, Config as r, defineMiddleware as rt, KubbBuildEndContext as s, UserLogger as st, BuildOutput as t, defineResolver as tt, KubbDebugContext as u, FileProcessorEvents as ut, KubbGenerationSummaryContext as v, RendererFactory as vt, KubbPluginsEndContext as w, logLevel as wt, KubbHooks as x, AdapterFactoryOptions as xt, KubbHookEndContext as y, createRenderer as yt, Include as z };
2307
+ //# sourceMappingURL=createKubb-CYrw_xaR.d.ts.map