@kubb/core 5.0.0-beta.95 → 5.0.0-beta.97

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 "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as definePlugin, A as Generator, At as DiagnosticSeverity, B as Include, Bt as AdapterSource, C as KubbWarnContext, Ct as UserReporter, D as CreateKubbOptions, Dt as DiagnosticDoc, E as UserConfig, Et as Diagnostic, F as Parser, Ft as SerializedDiagnostic, G as Output, H as KubbPluginSetupContext, I as defineParser, It as UpdateDiagnostic, J as Override, K as OutputMode, L as Exclude, Lt as Hookable, M as defineGenerator, Mt as PerformanceDiagnostic, N as KubbDriver, Nt as ProblemCode, O as Kubb, Ot as DiagnosticKind, P as FileManagerHooks, Pt as ProblemDiagnostic, Q as ResolvePluginOptions, R as Filter, Rt as Adapter, S as KubbSuccessContext, St as ReporterName, T as PostGenerateCommand, Tt as logLevel, U as KubbPluginStartContext, V as KubbPluginEndContext, Vt as createAdapter, W as NormalizedPlugin, X as PluginFactoryOptions, Y as Plugin, Z as PluginName, _ as KubbHookStartContext, _t as Storage, a as KubbBuildEndContext, at as ResolveOptionsContext, b as KubbLifecycleStartContext, bt as Reporter, c as KubbErrorContext, ct as ResolverDefault, d as KubbFilesProcessingStartContext, dt as ResolverFilePathParams, et as BannerMeta, f as KubbFilesProcessingUpdateContext, ft as ResolverPatch, g as KubbHookLineContext, gt as createRenderer, h as KubbHookEndContext, ht as RendererFactory, i as Input, it as ResolveImportsOptions, j as GeneratorContext, jt as Diagnostics, k as createKubb, kt as DiagnosticLocation, l as KubbFileProcessingUpdate, lt as ResolverFile, m as KubbGenerationStartContext, mt as Renderer, n as CLIOptions, nt as ResolveBannerFile, o as KubbBuildStartContext, ot as ResolvePathOptions, p as KubbGenerationEndContext, pt as ResolverPathParams, q as OutputOptions, r as Config, rt as ResolveFileOptions, s as KubbDiagnosticContext, st as Resolver, t as BuildOutput, tt as ResolveBannerContext, u as KubbFilesProcessingEndContext, ut as ResolverFileParams, v as KubbHooks, vt as createStorage, w as PossibleConfig, wt as createReporter, x as KubbPluginsEndContext, xt as ReporterContext, y as KubbInfoContext, yt as GenerationResult, z as Group, zt as AdapterFactoryOptions } from "./types-Bl0feoGY.js";
2
+ import { $ as definePlugin, A as Generator, At as DiagnosticSeverity, B as Include, Bt as AdapterSource, C as KubbWarnContext, Ct as UserReporter, D as CreateKubbOptions, Dt as DiagnosticDoc, E as UserConfig, Et as Diagnostic, F as Parser, Ft as SerializedDiagnostic, G as Output, H as KubbPluginSetupContext, I as defineParser, It as UpdateDiagnostic, J as Override, K as OutputMode, L as Exclude, Lt as Hookable, M as defineGenerator, Mt as PerformanceDiagnostic, N as KubbDriver, Nt as ProblemCode, O as Kubb, Ot as DiagnosticKind, P as FileManagerHooks, Pt as ProblemDiagnostic, Q as ResolvePluginOptions, R as Filter, Rt as Adapter, S as KubbSuccessContext, St as ReporterName, T as PostGenerateCommand, Tt as logLevel, U as KubbPluginStartContext, V as KubbPluginEndContext, Vt as createAdapter, W as NormalizedPlugin, X as PluginFactoryOptions, Y as Plugin, Z as PluginName, _ as KubbHookStartContext, _t as Storage, a as KubbBuildEndContext, at as ResolveOptionsContext, b as KubbLifecycleStartContext, bt as Reporter, c as KubbErrorContext, ct as ResolverDefault, d as KubbFilesProcessingStartContext, dt as ResolverFilePathParams, et as BannerMeta, f as KubbFilesProcessingUpdateContext, ft as ResolverPatch, g as KubbHookLineContext, gt as createRenderer, h as KubbHookEndContext, ht as RendererFactory, i as Input, it as ResolveImportsOptions, j as GeneratorContext, jt as Diagnostics, k as createKubb, kt as DiagnosticLocation, l as KubbFileProcessingUpdate, lt as ResolverFile, m as KubbGenerationStartContext, mt as Renderer, n as CLIOptions, nt as ResolveBannerFile, o as KubbBuildStartContext, ot as ResolvePathOptions, p as KubbGenerationEndContext, pt as ResolverPathParams, q as OutputOptions, r as Config, rt as ResolveFileOptions, s as KubbDiagnosticContext, st as Resolver, t as BuildOutput, tt as ResolveBannerContext, u as KubbFilesProcessingEndContext, ut as ResolverFileParams, v as KubbHooks, vt as createStorage, w as PossibleConfig, wt as createReporter, x as KubbPluginsEndContext, xt as ReporterContext, y as KubbInfoContext, yt as GenerationResult, z as Group, zt as AdapterFactoryOptions } from "./types-CK6CfipY.js";
3
3
  //#region src/applyConfigDefaults.d.ts
4
4
  type ApplyConfigDefaultsOptions<TOutput> = {
5
5
  defaultAdapter: Adapter;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { a as toFilePath, c as BuildError, d as camelCase, i as clean, l as getErrorMessage, n as FileManager, o as toPosixPath, r as Hookable, s as write, t as _usingCtx, u as toError } from "./usingCtx-BriKju-v.js";
2
+ import { a as isPathInside, c as write, d as toError, f as camelCase, i as clean, l as BuildError, n as FileManager, o as toFilePath, r as Hookable, s as toPosixPath, t as _usingCtx, u as getErrorMessage } from "./usingCtx-DOXZGtQx.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { hash } from "node:crypto";
@@ -189,7 +189,7 @@ function memoize(store, factory) {
189
189
  }
190
190
  //#endregion
191
191
  //#region package.json
192
- var version = "5.0.0-beta.95";
192
+ var version = "5.0.0-beta.97";
193
193
  //#endregion
194
194
  //#region src/constants.ts
195
195
  /**
@@ -267,6 +267,11 @@ const diagnosticCode = {
267
267
  */
268
268
  pathTraversal: "KUBB_PATH_TRAVERSAL",
269
269
  /**
270
+ * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,
271
+ * so cleaning would delete kubb.config and every source file.
272
+ */
273
+ cleanRoot: "KUBB_CLEAN_ROOT",
274
+ /**
270
275
  * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.
271
276
  */
272
277
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
@@ -414,6 +419,11 @@ const diagnosticCatalog = {
414
419
  cause: "A resolved output path escaped the output directory, which can stem from a path traversal in the spec or a misconfigured `group.name`.",
415
420
  fix: "Keep generated paths within the output directory. Review the `group.name` function and the names coming from the spec."
416
421
  },
422
+ [diagnosticCode.cleanRoot]: {
423
+ title: "Clean targets the project root",
424
+ cause: "`output.clean` is enabled and `output.path` resolves to the project root or a parent of it, so cleaning would delete `kubb.config` and every source file.",
425
+ fix: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code, or disable `output.clean`."
426
+ },
417
427
  [diagnosticCode.invalidPluginOptions]: {
418
428
  title: "Invalid plugin options",
419
429
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
@@ -899,23 +909,32 @@ var Resolver = class Resolver {
899
909
  } });
900
910
  }
901
911
  /**
902
- * Merges `override` over `base` and returns a new resolver with helpers re-bound. Top-level
903
- * keys replace, and a namespace (or `file`) merges per method, so overriding `query.name`
904
- * keeps the base `query.keyName`. Used when applying `setResolver` partial overrides. Reads a
905
- * resolver's options through the shared brand rather than `instanceof`, so a `file` override
906
- * survives even when `base` and `override` come from different `@kubb/core` copies.
907
- */
908
- static merge(base, override) {
909
- const patch = resolverOptions in override ? override[resolverOptions] : override;
910
- const merged = { ...base[resolverOptions] };
911
- for (const [key, value] of Object.entries(patch)) {
912
- if (value === void 0) continue;
913
- const current = merged[key];
914
- merged[key] = isNamespace(value) && isNamespace(current) ? {
915
- ...current,
916
- ...value
917
- } : value;
918
- }
912
+ * Folds each `override` over `base`, left to right, and returns a new resolver with helpers
913
+ * re-bound. Top-level keys replace, and a namespace (or `file`) merges per method, so overriding
914
+ * `query.name` keeps the base `query.keyName`. The last override wins per key. Used when applying
915
+ * `setResolver` partial overrides, and to compose shared resolver fragments without spreading each
916
+ * namespace by hand. Reads a resolver's options through the shared brand rather than `instanceof`,
917
+ * so a `file` override survives even when `base` and `override` come from different `@kubb/core`
918
+ * copies.
919
+ *
920
+ * @example Fold several partial overrides onto a resolver
921
+ * ```ts
922
+ * const resolver = Resolver.merge(defaultResolver, sharedNamingPatch, { name: (name) => name.toUpperCase() })
923
+ * ```
924
+ */
925
+ static merge(base, ...overrides) {
926
+ const merged = overrides.reduce((acc, override) => {
927
+ const patch = resolverOptions in override ? override[resolverOptions] : override;
928
+ for (const [key, value] of Object.entries(patch)) {
929
+ if (value === void 0) continue;
930
+ const current = acc[key];
931
+ acc[key] = isNamespace(value) && isNamespace(current) ? {
932
+ ...current,
933
+ ...value
934
+ } : value;
935
+ }
936
+ return acc;
937
+ }, { ...base[resolverOptions] });
919
938
  return new Resolver(merged);
920
939
  }
921
940
  /**
@@ -2083,7 +2102,17 @@ var Kubb = class {
2083
2102
  const config = this.config;
2084
2103
  const driver = new KubbDriver(config, { hooks: this.hooks });
2085
2104
  this.hooks.setMaxListeners(Math.max(10, config.plugins.length * 4));
2086
- if (config.output.clean) await config.storage.clear(resolve(config.root, config.output.path));
2105
+ if (config.output.clean) {
2106
+ const cleanPath = resolve(config.root, config.output.path);
2107
+ if (isPathInside(config.root, cleanPath)) throw new Diagnostics.Error({
2108
+ code: Diagnostics.code.cleanRoot,
2109
+ severity: "error",
2110
+ message: `output.clean cannot delete "${cleanPath}" because it is the project root or a parent of it.`,
2111
+ help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2112
+ location: { kind: "config" }
2113
+ });
2114
+ await config.storage.clear(cleanPath);
2115
+ }
2087
2116
  await driver.setup();
2088
2117
  this.#driver = driver;
2089
2118
  this.#storage = config.storage;