@kubb/core 5.0.0-beta.66 → 5.0.0-beta.68

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/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # @kubb/core
24
24
 
25
- ### Core engine for plugin-based code generation
25
+ ### Core engine for Kubb
26
26
 
27
27
  Core engine for Kubb's plugin-based code generation system. Provides the plugin driver, file manager, `defineConfig`, `definePlugin`, `defineMiddleware`, and the build orchestration layer used by every Kubb plugin.
28
28
 
@@ -926,13 +926,6 @@ type Output<_TOptions = unknown> = {
926
926
  * Pass a function to compute the footer from the file's `BannerMeta`.
927
927
  */
928
928
  footer?: string | ((meta: BannerMeta) => string);
929
- /**
930
- * Allows the plugin to overwrite hand-written files at the same path.
931
- * Defaults to `false` to protect manual edits.
932
- *
933
- * @default false
934
- */
935
- override?: boolean;
936
929
  } & ExtractRegistryKey$1<Kubb.PluginOptionsRegistry, 'output'>;
937
930
  /**
938
931
  * Groups generated files into subdirectories based on an OpenAPI tag or path
@@ -1127,7 +1120,7 @@ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactor
1127
1120
  * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
1128
1121
  * just like generators declared statically on `createPlugin`.
1129
1122
  */
1130
- addGenerator<TElement = unknown>(generator: Generator$1<TFactory, TElement>): void;
1123
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
1131
1124
  /**
1132
1125
  * Set or override the resolver for this plugin.
1133
1126
  * The resolver controls file naming and path resolution.
@@ -1149,6 +1142,9 @@ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactor
1149
1142
  setOptions(options: TFactory['resolvedOptions']): void;
1150
1143
  /**
1151
1144
  * Inject a raw file into the build output, bypassing the generation pipeline.
1145
+ *
1146
+ * Pass `copy` with an absolute path to emit a real source file (a shipped template) into the
1147
+ * generated folder verbatim, instead of building its content from `sources`.
1152
1148
  */
1153
1149
  injectFile(userFileNode: UserFileNode): void;
1154
1150
  /**
@@ -1215,7 +1211,7 @@ type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptio
1215
1211
  };
1216
1212
  resolver: TOptions['resolver'];
1217
1213
  macros?: Array<Macro>;
1218
- generators?: Array<Generator$1>;
1214
+ generators?: Array<Generator>;
1219
1215
  apply?: (config: Config) => boolean;
1220
1216
  version?: string;
1221
1217
  };
@@ -1365,7 +1361,7 @@ declare class KubbDriver {
1365
1361
  *
1366
1362
  * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
1367
1363
  */
1368
- registerGenerator(pluginName: string, generator: Generator$1): void;
1364
+ registerGenerator(pluginName: string, generator: Generator): void;
1369
1365
  /**
1370
1366
  * Returns `true` when at least one generator was registered for the given plugin
1371
1367
  * via `addGenerator()` in `kubb:plugin:setup` (event-based path).
@@ -1561,7 +1557,7 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
1561
1557
  * })
1562
1558
  * ```
1563
1559
  */
1564
- type Generator$1<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
1560
+ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
1565
1561
  /**
1566
1562
  * Used in diagnostic messages and debug output.
1567
1563
  */
@@ -1633,7 +1629,7 @@ type Generator$1<TOptions extends PluginFactoryOptions = PluginFactoryOptions, T
1633
1629
  * })
1634
1630
  * ```
1635
1631
  */
1636
- declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator$1<TOptions, TElement>): Generator$1<TOptions, TElement>;
1632
+ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
1637
1633
  //#endregion
1638
1634
  //#region src/defineParser.d.ts
1639
1635
  type PrintOptions = {
@@ -1976,17 +1972,6 @@ type Config<TInput = Input> = {
1976
1972
  * ```
1977
1973
  */
1978
1974
  defaultBanner?: 'simple' | 'full' | false;
1979
- /**
1980
- * Overwrite existing files when `true`, skip files that already exist when `false`. Individual
1981
- * plugins can override it. Keep `false` to avoid clobbering local edits in the output folder.
1982
- *
1983
- * @example
1984
- * ```ts
1985
- * override: true // regenerate everything, even existing files
1986
- * override: false // skip files that already exist
1987
- * ```
1988
- */
1989
- override?: boolean;
1990
1975
  } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>;
1991
1976
  /**
1992
1977
  * Where generated files are persisted. Defaults to `fsStorage()` (disk). Pass `memoryStorage()`
@@ -2903,5 +2888,5 @@ declare class Diagnostics {
2903
2888
  static formatLines(diagnostic: Diagnostic): Array<string>;
2904
2889
  }
2905
2890
  //#endregion
2906
- export { KubbPluginSetupContext as $, KubbHookStartContext as A, Adapter as At, ParsedFile as B, KubbFilesProcessingEndContext as C, GenerationResult as Ct, KubbGenerationStartContext as D, UserReporter as Dt, KubbGenerationEndContext as E, ReporterName as Et, KubbSuccessContext as F, Generator$1 as G, createKubb as H, KubbWarnContext as I, KubbDriver as J, GeneratorContext as K, PossibleConfig as L, KubbInfoContext as M, AdapterSource as Mt, KubbLifecycleStartContext as N, createAdapter as Nt, KubbHookEndContext as O, createReporter as Ot, KubbPluginsEndContext as P, AsyncEventEmitter as Pt, KubbPluginEndContext as Q, UserConfig as R, KubbFileProcessingUpdate as S, createStorage as St, KubbFilesProcessingUpdateContext as T, ReporterContext as Tt, Parser as U, Kubb$1 as V, defineParser as W, Group as X, Exclude$1 as Y, Include as Z, InputPath as _, defineResolver as _t, DiagnosticLocation as a, Override as at, KubbDiagnosticContext as b, createRenderer as bt, PerformanceDiagnostic as c, definePlugin as ct, SerializedDiagnostic as d, ResolveBannerFile as dt, KubbPluginStartContext as et, UpdateDiagnostic as f, ResolveOptionsContext as ft, InputData as g, ResolverPathParams as gt, Config as h, ResolverFileParams as ht, DiagnosticKind as i, OutputOptions as it, KubbHooks as j, AdapterFactoryOptions as jt, KubbHookLineContext as k, logLevel as kt, ProblemCode as l, BannerMeta as lt, CLIOptions as m, ResolverContext as mt, DiagnosticByCode as n, Output as nt, DiagnosticSeverity as o, Plugin as ot, BuildOutput as p, Resolver as pt, defineGenerator as q, DiagnosticDoc as r, OutputMode as rt, Diagnostics as s, PluginFactoryOptions as st, Diagnostic as t, NormalizedPlugin as tt, ProblemDiagnostic as u, ResolveBannerContext as ut, KubbBuildEndContext as v, Renderer as vt, KubbFilesProcessingStartContext as w, Reporter as wt, KubbErrorContext as x, Storage as xt, KubbBuildStartContext as y, RendererFactory as yt, FileProcessorHooks as z };
2907
- //# sourceMappingURL=diagnostics-M8ckppMO.d.ts.map
2891
+ export { KubbPluginSetupContext as $, KubbHookStartContext as A, Adapter as At, ParsedFile as B, KubbFilesProcessingEndContext as C, GenerationResult as Ct, KubbGenerationStartContext as D, UserReporter as Dt, KubbGenerationEndContext as E, ReporterName as Et, KubbSuccessContext as F, Generator as G, createKubb as H, KubbWarnContext as I, KubbDriver as J, GeneratorContext as K, PossibleConfig as L, KubbInfoContext as M, AdapterSource as Mt, KubbLifecycleStartContext as N, createAdapter as Nt, KubbHookEndContext as O, createReporter as Ot, KubbPluginsEndContext as P, AsyncEventEmitter as Pt, KubbPluginEndContext as Q, UserConfig as R, KubbFileProcessingUpdate as S, createStorage as St, KubbFilesProcessingUpdateContext as T, ReporterContext as Tt, Parser as U, Kubb$1 as V, defineParser as W, Group as X, Exclude$1 as Y, Include as Z, InputPath as _, defineResolver as _t, DiagnosticLocation as a, Override as at, KubbDiagnosticContext as b, createRenderer as bt, PerformanceDiagnostic as c, definePlugin as ct, SerializedDiagnostic as d, ResolveBannerFile as dt, KubbPluginStartContext as et, UpdateDiagnostic as f, ResolveOptionsContext as ft, InputData as g, ResolverPathParams as gt, Config as h, ResolverFileParams as ht, DiagnosticKind as i, OutputOptions as it, KubbHooks as j, AdapterFactoryOptions as jt, KubbHookLineContext as k, logLevel as kt, ProblemCode as l, BannerMeta as lt, CLIOptions as m, ResolverContext as mt, DiagnosticByCode as n, Output as nt, DiagnosticSeverity as o, Plugin as ot, BuildOutput as p, Resolver as pt, defineGenerator as q, DiagnosticDoc as r, OutputMode as rt, Diagnostics as s, PluginFactoryOptions as st, Diagnostic as t, NormalizedPlugin as tt, ProblemDiagnostic as u, ResolveBannerContext as ut, KubbBuildEndContext as v, Renderer as vt, KubbFilesProcessingStartContext as w, Reporter as wt, KubbErrorContext as x, Storage as xt, KubbBuildStartContext as y, RendererFactory as yt, FileProcessorHooks as z };
2892
+ //# sourceMappingURL=diagnostics-CJtO1uSM.d.ts.map
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_memoryStorage = require("./memoryStorage-67VG6jZn.cjs");
2
+ const require_memoryStorage = require("./memoryStorage-CfycFGzX.cjs");
3
3
  let node_crypto = require("node:crypto");
4
4
  let node_util = require("node:util");
5
5
  let node_fs_promises = require("node:fs/promises");
@@ -96,167 +96,6 @@ function randomCliColor(text) {
96
96
  return (0, node_util.styleText)(randomColors[(0, node_crypto.hash)("sha256", text, "buffer").readUInt32BE(0) % randomColors.length] ?? "white", text);
97
97
  }
98
98
  //#endregion
99
- //#region ../../internals/utils/src/runtime.ts
100
- /**
101
- * Detects the JavaScript runtime executing the current process and exposes its name and version.
102
- *
103
- * Prefer the shared {@link runtime} instance over constructing your own.
104
- */
105
- var Runtime = class {
106
- /**
107
- * `true` when the current process is running under Bun.
108
- *
109
- * Detection keys off the global `Bun` object rather than `process.versions`,
110
- * because Bun polyfills `process.versions.node` for Node compatibility and would
111
- * otherwise look like Node.
112
- *
113
- * @example
114
- * ```ts
115
- * if (runtime.isBun) {
116
- * await Bun.write(path, data)
117
- * }
118
- * ```
119
- */
120
- get isBun() {
121
- return typeof Bun !== "undefined";
122
- }
123
- /**
124
- * `true` when the current process is running under Deno.
125
- */
126
- get isDeno() {
127
- return typeof globalThis.Deno !== "undefined";
128
- }
129
- /**
130
- * `true` when the current process is running under Node.
131
- *
132
- * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.
133
- */
134
- get isNode() {
135
- return !this.isBun && !this.isDeno && typeof process !== "undefined" && process.versions?.node != null;
136
- }
137
- /**
138
- * Name of the runtime executing the current process.
139
- *
140
- * @example
141
- * ```ts
142
- * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
143
- * ```
144
- */
145
- get name() {
146
- if (this.isBun) return "bun";
147
- if (this.isDeno) return "deno";
148
- return "node";
149
- }
150
- /**
151
- * Version of the active runtime, or an empty string when it cannot be read.
152
- *
153
- * @example
154
- * ```ts
155
- * runtime.version // '1.3.11' under Bun, '22.22.2' under Node
156
- * ```
157
- */
158
- get version() {
159
- if (this.isBun) return process.versions.bun ?? "";
160
- if (this.isDeno) return globalThis.Deno?.version?.deno ?? "";
161
- return process.versions?.node ?? "";
162
- }
163
- };
164
- /**
165
- * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.
166
- */
167
- const runtime = new Runtime();
168
- //#endregion
169
- //#region ../../internals/utils/src/fs.ts
170
- /**
171
- * Writes `data` to `path`, trimming leading/trailing whitespace before saving.
172
- * Skips the write when the trimmed content is empty or identical to what is already on disk.
173
- * Creates any missing parent directories automatically.
174
- * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.
175
- *
176
- * @example
177
- * ```ts
178
- * await write('./src/Pet.ts', source) // writes and returns trimmed content
179
- * await write('./src/Pet.ts', source) // null — file unchanged
180
- * await write('./src/Pet.ts', ' ') // null — empty content skipped
181
- * ```
182
- */
183
- async function write(path, data, options = {}) {
184
- const trimmed = data.trim();
185
- if (trimmed === "") return null;
186
- const resolved = (0, node_path.resolve)(path);
187
- if (runtime.isBun) {
188
- const file = Bun.file(resolved);
189
- if ((await file.exists() ? await file.text() : null) === trimmed) return null;
190
- await Bun.write(resolved, trimmed);
191
- return trimmed;
192
- }
193
- try {
194
- if (await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" }) === trimmed) return null;
195
- } catch {}
196
- await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
197
- await (0, node_fs_promises.writeFile)(resolved, trimmed, { encoding: "utf-8" });
198
- if (options.sanity) {
199
- const savedData = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
200
- if (savedData !== trimmed) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
201
- return savedData;
202
- }
203
- return trimmed;
204
- }
205
- /**
206
- * Recursively removes `path`. Silently succeeds when `path` does not exist.
207
- *
208
- * @example
209
- * ```ts
210
- * await clean('./dist')
211
- * ```
212
- */
213
- async function clean(path) {
214
- return (0, node_fs_promises.rm)(path, {
215
- recursive: true,
216
- force: true
217
- });
218
- }
219
- /**
220
- * Converts a filesystem path to use POSIX (`/`) separators.
221
- *
222
- * Most of the codebase compares and composes paths as strings (prefix matching, joining for
223
- * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated
224
- * paths, but on Windows it returns `\`-separated paths, which breaks every such comparison.
225
- *
226
- * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the
227
- * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is
228
- * exercisable from POSIX CI.
229
- *
230
- * @example
231
- * toPosixPath('C:\\repo\\src\\pet.ts') // 'C:/repo/src/pet.ts'
232
- */
233
- function toPosixPath(filePath) {
234
- return filePath.replaceAll("\\", "/");
235
- }
236
- /**
237
- * Builds a nested file path from a dotted name. Splits on dots that precede a letter
238
- * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
239
- * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
240
- *
241
- * Empty segments are dropped before joining. They arise when the name starts with a dot
242
- * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
243
- * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
244
- * absolute path, letting generated files escape the configured output directory.
245
- *
246
- * @example Nested path from a dotted name
247
- * `toFilePath('pet.petId') // 'pet/petId'`
248
- *
249
- * @example PascalCase the final segment
250
- * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
251
- *
252
- * @example Suffix applied to the final segment only
253
- * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
254
- */
255
- function toFilePath(name, caseLast = require_memoryStorage.camelCase) {
256
- const parts = name.split(/\.(?=[a-zA-Z])/);
257
- return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : require_memoryStorage.camelCase(part)).filter(Boolean).join("/");
258
- }
259
- //#endregion
260
99
  //#region ../../internals/utils/src/promise.ts
261
100
  function* chunks(arr, size) {
262
101
  for (let i = 0; i < arr.length; i += size) yield arr.slice(i, i + size);
@@ -608,7 +447,7 @@ function createAdapter(build) {
608
447
  /**
609
448
  * Docs major version, derived from the package version so the link tracks the published major.
610
449
  */
611
- const docsMajor = "5.0.0-beta.66".split(".")[0] ?? "5";
450
+ const docsMajor = "5.0.0-beta.68".split(".")[0] ?? "5";
612
451
  /**
613
452
  * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
614
453
  *
@@ -1130,7 +969,7 @@ function matchesSchemaPattern(node, type, pattern) {
1130
969
  * - `camelCase` for `function` and everything else.
1131
970
  */
1132
971
  function defaultResolver(name, type) {
1133
- if (type === "file") return toFilePath(name);
972
+ if (type === "file") return require_memoryStorage.toFilePath(name);
1134
973
  if (type === "type") return require_memoryStorage.pascalCase(name);
1135
974
  return require_memoryStorage.camelCase(name);
1136
975
  }
@@ -2351,14 +2190,14 @@ const fsStorage = require_memoryStorage.createStorage(() => ({
2351
2190
  }
2352
2191
  },
2353
2192
  async setItem(key, value) {
2354
- await write((0, node_path.resolve)(key), value, { sanity: false });
2193
+ await require_memoryStorage.write((0, node_path.resolve)(key), value, { sanity: false });
2355
2194
  },
2356
2195
  async removeItem(key) {
2357
2196
  await (0, node_fs_promises.rm)((0, node_path.resolve)(key), { force: true });
2358
2197
  },
2359
2198
  async getKeys(base) {
2360
2199
  const resolvedBase = (0, node_path.resolve)(base ?? process.cwd());
2361
- if (runtime.isBun) {
2200
+ if (require_memoryStorage.runtime.isBun) {
2362
2201
  const bunGlob = new Bun.Glob("**/*");
2363
2202
  return Array.fromAsync(bunGlob.scan({
2364
2203
  cwd: resolvedBase,
@@ -2371,13 +2210,13 @@ const fsStorage = require_memoryStorage.createStorage(() => ({
2371
2210
  for await (const entry of (0, node_fs_promises.glob)("**/*", {
2372
2211
  cwd: resolvedBase,
2373
2212
  withFileTypes: true
2374
- })) if (entry.isFile()) keys.push(toPosixPath((0, node_path.relative)(resolvedBase, (0, node_path.join)(entry.parentPath, entry.name))));
2213
+ })) if (entry.isFile()) keys.push(require_memoryStorage.toPosixPath((0, node_path.relative)(resolvedBase, (0, node_path.join)(entry.parentPath, entry.name))));
2375
2214
  } catch (_error) {}
2376
2215
  return keys;
2377
2216
  },
2378
2217
  async clear(base) {
2379
2218
  if (!base) return;
2380
- await clean((0, node_path.resolve)(base));
2219
+ await require_memoryStorage.clean((0, node_path.resolve)(base));
2381
2220
  }
2382
2221
  }));
2383
2222
  //#endregion
@@ -2773,7 +2612,7 @@ const fileReporter = createReporter({
2773
2612
  Date.now()
2774
2613
  ].filter(Boolean).join("-")}.log`;
2775
2614
  const pathName = (0, node_path.resolve)(node_process.default.cwd(), ".kubb", baseName);
2776
- await write(pathName, `${content}\n`);
2615
+ await require_memoryStorage.write(pathName, `${content}\n`);
2777
2616
  console.error(`Debug log written to ${(0, node_path.relative)(node_process.default.cwd(), pathName)}`);
2778
2617
  }
2779
2618
  });