@kubb/core 5.8.0 → 5.8.1

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
- import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as OutputOptions, $t as ProblemCode, A as HookResult, At as ExtensionMeta, B as ParserDefinition, Bt as ReporterContext, C as KubbMessageContext, Ct as ResolverPatch, D as PossibleConfig, Dt as ExtensionDependencyRecord, E as KubbWarnContext, Et as ExtensionDependency, F as defineGenerator, Ft as createRenderer, G as Group, Gt as logLevel, H as defineParser, Ht as ReporterPluginFiles, I as NodeCache, It as Storage, J as KubbPluginSetupContext, Jt as DiagnosticKind, K as Include, Kt as Diagnostic, L as KubbDriver, Lt as createStorage, M as runHook, Mt as StandardSchemaV1, N as Generator, Nt as Renderer, O as PostGenerateCommand, Ot as ExtensionFactory, P as GeneratorContext, Pt as RendererFactory, Q as OutputMode, Qt as PerformanceDiagnostic, R as FileManagerHooks, Rt as GenerationResult, S as KubbLifecycleStartContext, St as ResolverFilePathParams, T as KubbSuccessContext, Tt as ExtensionDependencies, U as Exclude, Ut as UserReporter, V as ParserFactory, Vt as ReporterName, W as Filter, Wt as createReporter, X as NormalizedPlugin, Xt as DiagnosticSeverity, Y as KubbPluginStartContext, Yt as DiagnosticLocation, Z as Output, Zt as Diagnostics, _ as KubbHookEndContext, _t as ResolvePathOptions, a as Input, an as AdapterFactoryOptions, at as PluginName, b as KubbHooks, bt as ResolverFile, c as KubbDiagnosticContext, ct as ResolvePluginOptions, d as KubbFilesProcessingEndContext, dt as BannerMeta, en as ProblemDiagnostic, et as Override, f as KubbFilesProcessingStartContext, ft as ResolveBannerContext, g as KubbGenerationSummaryContext, gt as ResolveOptionsContext, h as KubbGenerationStartContext, ht as ResolveImportsOptions, i as FilesContext, in as Adapter, it as PluginFactoryOptions, j as RunHookOptions, jt as resolveMeta, k as UserConfig, kt as ExtensionKind, l as KubbErrorContext, lt as assertPluginOption, m as KubbGenerationEndContext, mt as ResolveFileOptions, n as CLIOptions, nn as UpdateDiagnostic, nt as PluginDefinition, o as KubbBuildEndContext, on as AdapterSource, ot as PluginOptions, p as KubbFilesProcessingUpdateContext, pt as ResolveBannerFile, q as KubbPluginEndContext, qt as DiagnosticDoc, r as Config, rn as Hookable, rt as PluginFactory, s as KubbBuildStartContext, sn as createAdapter, st as PluginType, t as BuildOutput, tn as SerializedDiagnostic, tt as Plugin, u as KubbFileProcessingUpdate, ut as definePlugin, v as KubbHookLineContext, vt as Resolver, w as KubbPluginsEndContext, wt as ResolverPathParams, x as KubbInfoContext, xt as ResolverFileParams, y as KubbHookStartContext, yt as ResolverDefault, z as Parser, zt as Reporter } from "./types-anBcq2U0.js";
1
+ import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
2
+ import { $ as NodeCache, $t as Diagnostics, A as PluginFactoryOptions, At as RunHookOptions, B as ResolveImportsOptions, Bt as GenerationResult, C as Output, Ct as KubbPluginsEndContext, D as Plugin, Dt as PostGenerateCommand, E as Override, Et as PossibleConfig, F as definePlugin, Ft as ParserDefinition, G as ResolverFile, Gt as UserReporter, H as ResolvePathOptions, Ht as ReporterContext, I as BannerMeta, It as ParserFactory, J as ResolverPatch, Jt as Diagnostic, K as ResolverFileParams, Kt as createReporter, L as ResolveBannerContext, Lt as defineParser, M as PluginType, Mt as KubbDriver, N as ResolvePluginOptions, Nt as FileManagerHooks, O as PluginDefinition, Ot as UserConfig, P as assertPluginOption, Pt as Parser, Q as defineGenerator, Qt as DiagnosticSeverity, R as ResolveBannerFile, Rt as Storage, S as NormalizedPlugin, St as KubbMessageContext, T as OutputOptions, Tt as KubbWarnContext, U as Resolver, Ut as ReporterName, V as ResolveOptionsContext, Vt as Reporter, W as ResolverDefault, Wt as ReporterPluginFiles, X as Generator, Xt as DiagnosticKind, Y as ResolverPathParams, Yt as DiagnosticDoc, Z as GeneratorContext, Zt as DiagnosticLocation, _ as Group, _t as KubbHookLineContext, a as AdapterSource, an as Hookable, at as KubbBuildEndContext, b as KubbPluginSetupContext, bt as KubbInfoContext, c as ExtensionDependency, cn as createRenderer, ct as KubbErrorContext, d as ExtensionKind, dt as KubbFilesProcessingStartContext, en as PerformanceDiagnostic, et as BuildOutput, f as ExtensionMeta, ft as KubbFilesProcessingUpdateContext, g as Filter, gt as KubbHookEndContext, h as Exclude, ht as KubbGenerationSummaryContext, i as AdapterFactoryOptions, in as UpdateDiagnostic, it as Input, j as PluginName, jt as runHook, k as PluginFactory, kt as HookResult, l as ExtensionDependencyRecord, lt as KubbFileProcessingUpdate, m as resolveMeta, mt as KubbGenerationStartContext, n as AdapterDefinition, nn as ProblemDiagnostic, nt as Config, o as createAdapter, on as Renderer, ot as KubbBuildStartContext, p as checkCompatibility, pt as KubbGenerationEndContext, q as ResolverFilePathParams, qt as logLevel, r as AdapterFactory, rn as SerializedDiagnostic, rt as FilesContext, s as ExtensionDependencies, sn as RendererFactory, st as KubbDiagnosticContext, t as Adapter, tn as ProblemCode, tt as CLIOptions, u as ExtensionFactory, ut as KubbFilesProcessingEndContext, v as Include, vt as KubbHookStartContext, w as OutputMode, wt as KubbSuccessContext, x as KubbPluginStartContext, xt as KubbLifecycleStartContext, y as KubbPluginEndContext, yt as KubbHooks, z as ResolveFileOptions, zt as createStorage } from "./createAdapter-BO_AxI05.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { FileNode, Macro, UserFileNode } from "@kubb/ast";
5
5
  //#region src/applyConfigDefaults.d.ts
@@ -68,9 +68,9 @@ export declare function setMacros(macros: ReadonlyArray<Macro>): void;
68
68
  */
69
69
  export declare function injectFile(file: UserFileNode): void;
70
70
  /**
71
- * Returns the options of the plugin being set up, parsed by its options `schema` when it has one, like `ctx.options`.
71
+ * Returns the options the user passed to the plugin being set up, like `ctx.options`.
72
72
  */
73
- export declare function useOptions<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(): TFactory['parsedOptions'];
73
+ export declare function useOptions<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(): TFactory['options'];
74
74
  /**
75
75
  * Sets the resolved options of the plugin being set up, like `ctx.setOptions`.
76
76
  */
@@ -474,5 +474,144 @@ export declare function kubbStorage({ base }?: KubbStorageOptions): import("unst
474
474
  */
475
475
  export declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
476
476
  //#endregion
477
- export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type ExtensionDependencies, type ExtensionDependency, type ExtensionDependencyRecord, type ExtensionFactory, type ExtensionKind, type ExtensionMeta, type FileManagerHooks, FilesContext, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, type HookResult, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbMessageContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type ParserDefinition, type ParserFactory, type PerformanceDiagnostic, type Plugin, type PluginDefinition, type PluginFactory, type PluginFactoryOptions, type PluginName, type PluginOptions, type PluginType, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ReporterPluginFiles, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type RunHookOptions, type RunOutputPassesOptions, type SerializedDiagnostic, type StandardSchemaV1, type Storage, type SummaryRenderer, type UpdateDiagnostic, UserConfig, type UserReporter, assertPluginOption, createAdapter, createRenderer, createReporter, createStorage, defineGenerator, defineParser, definePlugin, logLevel, resolveMeta, runHook };
477
+ //#region src/manifest.d.ts
478
+ /** A value that survives `JSON.stringify` and `JSON.parse` unchanged. */
479
+ type JSONValue = string | number | boolean | null | Array<JSONValue> | {
480
+ [key: string]: JSONValue;
481
+ };
482
+ /**
483
+ * One form field Studio renders for an extension. It edits the value at `path` in the options
484
+ * object the user passes to the factory.
485
+ */
486
+ type ExtensionManifestOption = {
487
+ /** Stable UI key, unique within the manifest. */
488
+ key: string;
489
+ /** Where the value lives, such as `['output', 'path']`. */
490
+ path: Array<string>;
491
+ label: string;
492
+ description?: string;
493
+ type: 'select' | 'boolean' | 'text' | 'number' | 'list';
494
+ /** The extension's runtime default, shown when the option is unset. */
495
+ default?: JSONValue;
496
+ /** For `select`. A choice with value `null` leaves the option unset. */
497
+ choices?: Array<{
498
+ label?: string;
499
+ value: JSONValue;
500
+ }>;
501
+ /** For `boolean`: the value written for `true`, `true` when unset. */
502
+ trueValue?: JSONValue;
503
+ /** For `boolean`: the value written for `false`, `false` when unset. */
504
+ falseValue?: JSONValue;
505
+ /** For `list`: template for each entry, where every `"$item"` string is replaced by the entry. */
506
+ item?: JSONValue;
507
+ /** For `list`: upper-case each entry before writing it. */
508
+ itemCase?: 'upper';
509
+ };
510
+ /**
511
+ * The `kubb-extension.json` file an extension package ships at its root. Studio, the kubb.dev
512
+ * registry, and `kubb add` read it.
513
+ */
514
+ type ExtensionManifest = {
515
+ $schema?: string;
516
+ kind: ExtensionKind;
517
+ /** Equals the extension's `meta.name`. */
518
+ name: string;
519
+ /** The factory export users call in `kubb.config.ts`, such as `pluginZod`. */
520
+ export: string;
521
+ displayName: string;
522
+ description: string;
523
+ category?: string;
524
+ icon?: {
525
+ light: string;
526
+ dark?: string;
527
+ };
528
+ /** HTTPS image or video URLs. */
529
+ media?: Array<string>;
530
+ tags?: Array<string>;
531
+ docs?: string;
532
+ compatibility?: {
533
+ kubb?: string;
534
+ node?: string;
535
+ };
536
+ /** Plugins only: `client` ships the HTTP client runtime, `consumer` calls one but ships none. */
537
+ role?: 'client' | 'consumer';
538
+ options?: Array<ExtensionManifestOption>;
539
+ };
540
+ /** One extension in a registry's `index.json`. */
541
+ type RegistryEntry = {
542
+ /** `<owner>/<slug>`, such as `kubb-labs/plugin-zod`. */
543
+ id: string;
544
+ kind: ExtensionKind;
545
+ type: 'official' | 'community';
546
+ /** The reviewed npm version to install. */
547
+ artifact: {
548
+ kind: 'npm';
549
+ package: string;
550
+ version: string;
551
+ };
552
+ repository?: {
553
+ url: string;
554
+ };
555
+ manifest: ExtensionManifest;
556
+ stats?: {
557
+ downloads?: number;
558
+ weekly?: number;
559
+ stars?: number;
560
+ };
561
+ submittedAt: string;
562
+ publishedAt: string;
563
+ reviewedAt: string;
564
+ };
565
+ /** The registry's `index.json`. */
566
+ type RegistryIndex = {
567
+ version: 1;
568
+ generatedAt: string;
569
+ extensions: Array<RegistryEntry>;
570
+ };
571
+ /** The registry's `<owner>/<slug>.json`: an entry plus its `OVERVIEW.md`. */
572
+ type RegistryDetail = RegistryEntry & {
573
+ overview: string | null;
574
+ };
575
+ /**
576
+ * Whether `name` is a valid npm package name, such as `@kubb/plugin-ts`. Rejects paths, URLs,
577
+ * `node:` specifiers, and names that start with `-`, so the result is safe to pass to `import()` or
578
+ * a package manager.
579
+ */
580
+ export declare function isPackageName(name: unknown): name is string;
581
+ /**
582
+ * What is wrong with the options of a well-formed manifest, beyond their shape: keys are unique, a
583
+ * select has choices, and a select's default is one of its choice values. Empty when they pass.
584
+ */
585
+ export declare function manifestProblems({ options }: ExtensionManifest): Array<string>;
586
+ /**
587
+ * Checks a parsed `kubb-extension.json` or a registry response before Kubb or Studio uses it: the
588
+ * fields Kubb reads, every option's shape (including option paths that cannot reach a prototype),
589
+ * and `manifestProblems`. A malformed manifest is skipped instead of trusted.
590
+ */
591
+ export declare function isExtensionManifest(value: unknown): value is ExtensionManifest;
592
+ /**
593
+ * Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
594
+ * an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
595
+ */
596
+ export declare function isRegistryEntry(value: unknown): value is RegistryEntry;
597
+ //#endregion
598
+ //#region src/installedPackages.d.ts
599
+ type InstalledPackage = {
600
+ package: string;
601
+ version?: string;
602
+ manifest?: ExtensionManifest;
603
+ };
604
+ /**
605
+ * The `dependencies` and `devDependencies` of the project at `root`, plus `packages`, with the
606
+ * installed version and the valid `kubb-extension.json` each one ships, when it does. A package
607
+ * also counts as installed when it resolves from one of the `resolveFrom` packages, such as `kubb`
608
+ * for the extensions it ships with.
609
+ */
610
+ export declare function readInstalledPackages({ root, packages, resolveFrom }: {
611
+ root: string;
612
+ packages?: Iterable<string>;
613
+ resolveFrom?: Array<string>;
614
+ }): Promise<Array<InstalledPackage>>;
615
+ //#endregion
616
+ export { type Adapter, type AdapterDefinition, type AdapterFactory, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type ExtensionDependencies, type ExtensionDependency, type ExtensionDependencyRecord, type ExtensionFactory, type ExtensionKind, type ExtensionManifest, type ExtensionManifestOption, type ExtensionMeta, type FileManagerHooks, FilesContext, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, type HookResult, Hookable, type Include, Input, type InputKind, type InstalledPackage, type JSONValue, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbMessageContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type ParserDefinition, type ParserFactory, type PerformanceDiagnostic, type Plugin, type PluginDefinition, type PluginFactory, type PluginFactoryOptions, type PluginName, type PluginType, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type RegistryDetail, type RegistryEntry, type RegistryIndex, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ReporterPluginFiles, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type RunHookOptions, type RunOutputPassesOptions, type SerializedDiagnostic, type Storage, type SummaryRenderer, type UpdateDiagnostic, UserConfig, type UserReporter, assertPluginOption, checkCompatibility, createAdapter, createRenderer, createReporter, createStorage, defineGenerator, defineParser, definePlugin, logLevel, resolveMeta, runHook };
478
617
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
- import "./rolldown-runtime-C0LytTxp.js";
2
- import { A as clean, C as useConfig, D as formatMs, E as Diagnostics, F as write, I as toError, M as isPathInside, N as read, O as getElapsedMs, P as toPosixPath, S as tryUseKubb, T as useOptions, _ as kubbContext, a as _usingCtx, b as setOptions, c as Resolver, d as definePlugin, f as defineExtension, g as injectFile, h as addMacro, j as exists, k as inParallel, l as getInputKind, m as addGenerator, o as Hookable, p as resolveMeta, s as createResolver, t as KubbDriver, u as assertPluginOption, v as requirePlugin, w as useKubb, x as setResolver, y as setMacros } from "./KubbDriver-BrltQ0nL.js";
1
+ import "./rolldown-runtime-CRm0XQPb.js";
2
+ import { A as inParallel, C as useOptions, D as Diagnostics, E as resolveMeta, F as toPosixPath, I as write, L as toError, M as exists, N as isPathInside, O as formatMs, P as read, S as useKubb, T as defineExtension, _ as setMacros, a as _usingCtx, b as tryUseKubb, c as Resolver, d as definePlugin, f as addGenerator, g as requirePlugin, h as kubbContext, j as clean, k as getElapsedMs, l as getInputKind, m as injectFile, o as Hookable, p as addMacro, s as createResolver, t as KubbDriver, u as assertPluginOption, v as setOptions, w as checkCompatibility, x as useConfig, y as setResolver } from "./KubbDriver-Dz36Klt9.js";
3
+ import { createRequire } from "node:module";
4
+ import { isValid } from "verkit";
3
5
  import { stripVTControlCharacters, styleText } from "node:util";
4
6
  import process$1 from "node:process";
5
7
  import { x } from "tinyexec";
6
8
  import { glob, readFile, rm } from "node:fs/promises";
7
- import { join, relative, resolve } from "node:path";
9
+ import path, { join, relative, resolve } from "node:path";
8
10
  import { hash, randomUUID } from "node:crypto";
9
11
  import { chmodSync, existsSync, mkdirSync } from "node:fs";
10
12
  import { homedir, tmpdir } from "node:os";
@@ -12,60 +14,6 @@ import { createInterface } from "node:readline";
12
14
  import { createStorage as createStorage$1 } from "unstorage";
13
15
  import fsDriver from "unstorage/drivers/fs";
14
16
  import { fileURLToPath } from "node:url";
15
- //#region src/createAdapter.ts
16
- /**
17
- * Defines a custom adapter that translates a spec format into Kubb's universal
18
- * AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
19
- * handles OpenAPI/Swagger documents.
20
- *
21
- * Adapters must return an `InputNode` from `parse`. That node is what every
22
- * plugin in the build consumes.
23
- *
24
- * @example
25
- * ```ts
26
- * import { createAdapter, type AdapterFactoryOptions } from '@kubb/core'
27
- * import { ast } from '@kubb/ast'
28
- *
29
- * type MyAdapter = AdapterFactoryOptions<'my-adapter', { validate?: boolean }>
30
- *
31
- * export const myAdapter = createAdapter<MyAdapter>((options) => ({
32
- * name: 'my-adapter',
33
- * options,
34
- * document: null,
35
- * async parse(_source) {
36
- * // Convert the source (path or inline data) into an InputNode.
37
- * return ast.factory.createInput()
38
- * },
39
- * async validate() {
40
- * // Throw here when the spec is invalid.
41
- * },
42
- * }))
43
- * ```
44
- */
45
- function createAdapter(build) {
46
- return (options) => build(options ?? {});
47
- }
48
- //#endregion
49
- //#region src/applyConfigDefaults.ts
50
- /**
51
- * Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
52
- * adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
53
- * registered. Both entry points construct their own adapter, barrel plugin, and output defaults
54
- * (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
55
- * so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
56
- */
57
- function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
58
- const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
59
- return {
60
- adapter: config.adapter ?? defaultAdapter,
61
- plugins,
62
- output: {
63
- ...defaultOutput,
64
- ...config.output
65
- }
66
- };
67
- }
68
- //#endregion
69
17
  //#region ../../internals/utils/src/isCIEnvironment.ts
70
18
  /**
71
19
  * Returns `true` when a known CI provider has set its environment variable.
@@ -204,6 +152,47 @@ function tokenize(command) {
204
152
  return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
205
153
  }
206
154
  //#endregion
155
+ //#region src/createAdapter.ts
156
+ function createAdapter(input) {
157
+ if (typeof input === "function") return defineExtension({
158
+ kind: "adapter",
159
+ build: (options) => input(options)
160
+ });
161
+ const { meta, setup, build } = input;
162
+ return defineExtension({
163
+ kind: "adapter",
164
+ meta,
165
+ build: (raw) => {
166
+ const options = setup ? setup(raw) : raw;
167
+ return Object.assign(build(options), {
168
+ name: meta.name,
169
+ meta,
170
+ options
171
+ });
172
+ }
173
+ });
174
+ }
175
+ //#endregion
176
+ //#region src/applyConfigDefaults.ts
177
+ /**
178
+ * Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
179
+ * adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
180
+ * registered. Both entry points construct their own adapter, barrel plugin, and output defaults
181
+ * (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
182
+ * so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
183
+ */
184
+ function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
185
+ const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
186
+ return {
187
+ adapter: config.adapter ?? defaultAdapter,
188
+ plugins,
189
+ output: {
190
+ ...defaultOutput,
191
+ ...config.output
192
+ }
193
+ };
194
+ }
195
+ //#endregion
207
196
  //#region src/outputManifest.ts
208
197
  /**
209
198
  * Bumped when the stored shape changes, so an older cache is discarded instead of misread.
@@ -1298,7 +1287,7 @@ function defineGenerator(generator) {
1298
1287
  function defineParser(input) {
1299
1288
  if (typeof input === "function") return defineExtension({
1300
1289
  kind: "parser",
1301
- build: ({ options }) => {
1290
+ build: (options) => {
1302
1291
  const parser = input(options);
1303
1292
  return {
1304
1293
  ...parser,
@@ -1306,14 +1295,16 @@ function defineParser(input) {
1306
1295
  };
1307
1296
  }
1308
1297
  });
1309
- const { meta, setup } = input;
1298
+ const { meta } = input;
1299
+ const build = "build" in input ? input.build : input.setup;
1310
1300
  return defineExtension({
1311
1301
  kind: "parser",
1312
1302
  meta,
1313
- build: ({ options }) => ({
1314
- ...setup(options),
1303
+ build: (options) => ({
1304
+ ...build(options),
1315
1305
  name: meta.name,
1316
- meta
1306
+ meta,
1307
+ options
1317
1308
  })
1318
1309
  });
1319
1310
  }
@@ -1368,6 +1359,118 @@ const memoryStorage = createStorage(() => {
1368
1359
  };
1369
1360
  });
1370
1361
  //#endregion
1371
- export { Diagnostics, Hookable, KubbDriver, Resolver, addGenerator, addMacro, applyConfigDefaults, assertPluginOption, cacheStorage, cliReporter, createAdapter, createCliReporter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, htmlReporter, injectFile, jsonReporter, kubbContext, kubbStorage, logLevel, memoryStorage, requirePlugin, resolveCacheDir, resolveKubbDir, resolveMeta, runHook, runOutputPasses, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
1362
+ //#region src/manifest.ts
1363
+ const EXTENSION_KINDS = /* @__PURE__ */ new Set([
1364
+ "plugin",
1365
+ "adapter",
1366
+ "parser"
1367
+ ]);
1368
+ const OPTION_TYPES = /* @__PURE__ */ new Set([
1369
+ "select",
1370
+ "boolean",
1371
+ "text",
1372
+ "number",
1373
+ "list"
1374
+ ]);
1375
+ const PACKAGE_NAME = /^(?:@[a-z0-9~][a-z0-9._~-]*\/)?[a-z0-9~][a-z0-9._~-]*$/;
1376
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
1377
+ const REGISTRY_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
1378
+ /** Option path segments that would reach an object's prototype when Studio writes the value by path. */
1379
+ const UNSAFE_KEYS = /* @__PURE__ */ new Set([
1380
+ "__proto__",
1381
+ "constructor",
1382
+ "prototype"
1383
+ ]);
1384
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1385
+ const isOptionalString = (value) => value === void 0 || typeof value === "string";
1386
+ const isFilledString = (value) => typeof value === "string" && value !== "";
1387
+ /** Serializes with sorted object keys, so equal JSON values give equal strings whatever their key order. */
1388
+ const canonicalJSON = (value) => JSON.stringify(value, (_key, item) => isObject(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
1389
+ /**
1390
+ * Whether `name` is a valid npm package name, such as `@kubb/plugin-ts`. Rejects paths, URLs,
1391
+ * `node:` specifiers, and names that start with `-`, so the result is safe to pass to `import()` or
1392
+ * a package manager.
1393
+ */
1394
+ function isPackageName(name) {
1395
+ return typeof name === "string" && name.length <= 214 && PACKAGE_NAME.test(name);
1396
+ }
1397
+ /** Checks the shape of one manifest option, including that its path cannot reach a prototype. */
1398
+ function isOption(value) {
1399
+ if (!isObject(value)) return false;
1400
+ const { key, path, label, description, type, choices, itemCase } = value;
1401
+ return isFilledString(key) && Array.isArray(path) && path.length > 0 && path.every((segment) => isFilledString(segment) && !UNSAFE_KEYS.has(segment)) && isFilledString(label) && isOptionalString(description) && OPTION_TYPES.has(type) && (choices === void 0 || Array.isArray(choices) && choices.every((choice) => isObject(choice) && "value" in choice && isOptionalString(choice.label))) && (itemCase === void 0 || itemCase === "upper");
1402
+ }
1403
+ /**
1404
+ * What is wrong with the options of a well-formed manifest, beyond their shape: keys are unique, a
1405
+ * select has choices, and a select's default is one of its choice values. Empty when they pass.
1406
+ */
1407
+ function manifestProblems({ options = [] }) {
1408
+ const seen = /* @__PURE__ */ new Set();
1409
+ return options.flatMap((option) => {
1410
+ const problems = seen.has(option.key) ? [`option "${option.key}" is declared more than once`] : [];
1411
+ seen.add(option.key);
1412
+ if (option.type !== "select") return problems;
1413
+ if (!option.choices?.length) return [...problems, `option "${option.key}" is a select without choices`];
1414
+ return !("default" in option) || option.choices.some((choice) => canonicalJSON(choice.value) === canonicalJSON(option.default)) ? problems : [...problems, `option "${option.key}" has a default that is not one of its choices`];
1415
+ });
1416
+ }
1417
+ /**
1418
+ * Checks a parsed `kubb-extension.json` or a registry response before Kubb or Studio uses it: the
1419
+ * fields Kubb reads, every option's shape (including option paths that cannot reach a prototype),
1420
+ * and `manifestProblems`. A malformed manifest is skipped instead of trusted.
1421
+ */
1422
+ function isExtensionManifest(value) {
1423
+ if (!isObject(value)) return false;
1424
+ const { kind, name, export: exportName, displayName, description, compatibility, options } = value;
1425
+ return EXTENSION_KINDS.has(kind) && isPackageName(name) && typeof exportName === "string" && IDENTIFIER.test(exportName) && typeof displayName === "string" && typeof description === "string" && (compatibility === void 0 || isObject(compatibility) && Object.entries(compatibility).every(([key, range]) => (key === "kubb" || key === "node") && typeof range === "string")) && (options === void 0 || Array.isArray(options) && options.every(isOption)) && manifestProblems(value).length === 0;
1426
+ }
1427
+ /**
1428
+ * Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
1429
+ * an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
1430
+ */
1431
+ function isRegistryEntry(value) {
1432
+ if (!isObject(value)) return false;
1433
+ const { id, kind, type, artifact, manifest } = value;
1434
+ return typeof id === "string" && REGISTRY_ID.test(id) && EXTENSION_KINDS.has(kind) && (type === "official" || type === "community") && isObject(artifact) && artifact.kind === "npm" && isPackageName(artifact.package) && typeof artifact.version === "string" && isValid(artifact.version) && isExtensionManifest(manifest) && manifest.kind === kind;
1435
+ }
1436
+ //#endregion
1437
+ //#region src/installedPackages.ts
1438
+ /** Reads and parses a JSON file. Throws when it is missing or not JSON. */
1439
+ const readJSON = async (file) => JSON.parse(await readFile(file, "utf8"));
1440
+ /**
1441
+ * The `dependencies` and `devDependencies` of the project at `root`, plus `packages`, with the
1442
+ * installed version and the valid `kubb-extension.json` each one ships, when it does. A package
1443
+ * also counts as installed when it resolves from one of the `resolveFrom` packages, such as `kubb`
1444
+ * for the extensions it ships with.
1445
+ */
1446
+ async function readInstalledPackages({ root, packages = [], resolveFrom = [] }) {
1447
+ const project = createRequire(path.join(root, "package.json"));
1448
+ const requires = [project, ...resolveFrom.flatMap((name) => {
1449
+ try {
1450
+ return [createRequire(project.resolve(`${name}/package.json`))];
1451
+ } catch {
1452
+ return [];
1453
+ }
1454
+ })];
1455
+ const packageJSON = await readJSON(path.join(root, "package.json")).catch(() => null);
1456
+ const dependencies = [packageJSON?.dependencies, packageJSON?.devDependencies].flatMap((record) => typeof record === "object" && record !== null ? Object.keys(record) : []);
1457
+ return Promise.all([.../* @__PURE__ */ new Set([...dependencies, ...packages])].filter(isPackageName).map(async (name) => {
1458
+ const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync(path.join(dir, "package.json")));
1459
+ if (!dir) return { package: name };
1460
+ try {
1461
+ const { version } = await readJSON(path.join(dir, "package.json"));
1462
+ const manifest = await readJSON(path.join(dir, "kubb-extension.json")).catch(() => void 0);
1463
+ return {
1464
+ package: name,
1465
+ version: typeof version === "string" ? version : void 0,
1466
+ manifest: isExtensionManifest(manifest) ? manifest : void 0
1467
+ };
1468
+ } catch {
1469
+ return { package: name };
1470
+ }
1471
+ }));
1472
+ }
1473
+ //#endregion
1474
+ export { Diagnostics, Hookable, KubbDriver, Resolver, addGenerator, addMacro, applyConfigDefaults, assertPluginOption, cacheStorage, checkCompatibility, cliReporter, createAdapter, createCliReporter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, htmlReporter, injectFile, isExtensionManifest, isPackageName, isRegistryEntry, jsonReporter, kubbContext, kubbStorage, logLevel, manifestProblems, memoryStorage, readInstalledPackages, requirePlugin, resolveCacheDir, resolveKubbDir, resolveMeta, runHook, runOutputPasses, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
1372
1475
 
1373
1476
  //# sourceMappingURL=index.js.map