@kubb/core 5.3.5 → 5.3.7
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 +6 -0
- package/dist/index.cjs +33 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -12
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{types-DIHOpbmO.d.ts → types-Cw20YGzh.d.ts} +30 -8
- package/dist/{usingCtx-BfeNtY1B.js → usingCtx-BoFplz1D.js} +5 -2
- package/dist/{usingCtx-BfeNtY1B.js.map → usingCtx-BoFplz1D.js.map} +1 -1
- package/dist/{usingCtx-CBWq26N5.cjs → usingCtx-DOy3BJPz.cjs} +5 -2
- package/dist/{usingCtx-CBWq26N5.cjs.map → usingCtx-DOy3BJPz.cjs.map} +1 -1
- package/package.json +2 -2
package/dist/mocks.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_usingCtx = require("./usingCtx-
|
|
2
|
+
const require_usingCtx = require("./usingCtx-DOy3BJPz.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_usingCtx.__toESM(node_path, 1);
|
|
5
5
|
let _kubb_ast = require("@kubb/ast");
|
package/dist/mocks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import {
|
|
2
|
+
import { J as NormalizedPlugin, L as KubbDriver, N as Generator, Ut as Adapter, Wt as AdapterFactoryOptions, et as PluginFactoryOptions, r as Config, z as Parser } from "./types-Cw20YGzh.js";
|
|
3
3
|
import { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from "@kubb/ast";
|
|
4
4
|
//#region src/mocks.d.ts
|
|
5
5
|
/**
|
package/dist/mocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { h as camelCase, i as Hookable, n as createNodeCache, r as FileManager, t as _usingCtx } from "./usingCtx-
|
|
2
|
+
import { h as camelCase, i as Hookable, n as createNodeCache, r as FileManager, t as _usingCtx } from "./usingCtx-BoFplz1D.js";
|
|
3
3
|
import path, { resolve } from "node:path";
|
|
4
4
|
import { applyMacros, ast } from "@kubb/ast";
|
|
5
5
|
import { expect } from "vitest";
|
|
@@ -97,7 +97,9 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
97
97
|
* resolve a `$ref` to the file that is actually generated. Refs that keep their pointer's
|
|
98
98
|
* last segment need no stamp.
|
|
99
99
|
*/
|
|
100
|
-
parse: (source: AdapterSource
|
|
100
|
+
parse: (source: AdapterSource, options?: {
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
}) => PossiblePromise<InputNode>;
|
|
101
103
|
/**
|
|
102
104
|
* Validate the document at the given path or URL.
|
|
103
105
|
*/
|
|
@@ -1802,6 +1804,7 @@ type ParseOptions = {
|
|
|
1802
1804
|
};
|
|
1803
1805
|
type WriteOptions = ParseOptions & {
|
|
1804
1806
|
storage: Storage;
|
|
1807
|
+
signal?: AbortSignal;
|
|
1805
1808
|
/**
|
|
1806
1809
|
* Consulted before each write so a file the output passes already normalized is recognized as
|
|
1807
1810
|
* unchanged. Omitted when no formatter, linter, or `postGenerate` step is configured.
|
|
@@ -1852,12 +1855,13 @@ declare class FileManager {
|
|
|
1852
1855
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
1853
1856
|
* writes nothing and leaves every mtime where it was.
|
|
1854
1857
|
*/
|
|
1855
|
-
write(files: Array<FileNode>, { storage, parsers, manifest }: WriteOptions): Promise<void>;
|
|
1858
|
+
write(files: Array<FileNode>, { storage, parsers, manifest, signal }: WriteOptions): Promise<void>;
|
|
1856
1859
|
}
|
|
1857
1860
|
//#endregion
|
|
1858
1861
|
//#region src/KubbDriver.d.ts
|
|
1859
1862
|
type Options = {
|
|
1860
1863
|
hooks: Hookable<KubbHooks>;
|
|
1864
|
+
signal?: AbortSignal;
|
|
1861
1865
|
/**
|
|
1862
1866
|
* Passed to `fileManager.write` so files the output passes already normalized are left alone.
|
|
1863
1867
|
*/
|
|
@@ -2015,6 +2019,10 @@ type NodeCache = {
|
|
|
2015
2019
|
* filtering for `schema` and `operation`, or the plugin-level options for `operations`.
|
|
2016
2020
|
*/
|
|
2017
2021
|
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
2022
|
+
/**
|
|
2023
|
+
* Stops cooperative generation work at the next safe checkpoint.
|
|
2024
|
+
*/
|
|
2025
|
+
signal?: AbortSignal;
|
|
2018
2026
|
/**
|
|
2019
2027
|
* The resolved Kubb config for this build, including `root`, `input`, `output`, and the
|
|
2020
2028
|
* full plugin list.
|
|
@@ -2227,7 +2235,14 @@ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginF
|
|
|
2227
2235
|
//#endregion
|
|
2228
2236
|
//#region src/createKubb.d.ts
|
|
2229
2237
|
type CreateKubbOptions = {
|
|
2238
|
+
/**
|
|
2239
|
+
* Receives Kubb lifecycle hooks for the run.
|
|
2240
|
+
*/
|
|
2230
2241
|
hooks?: Hookable<KubbHooks>;
|
|
2242
|
+
/**
|
|
2243
|
+
* Stops the build at the next safe checkpoint.
|
|
2244
|
+
*/
|
|
2245
|
+
signal?: AbortSignal;
|
|
2231
2246
|
};
|
|
2232
2247
|
/**
|
|
2233
2248
|
* Host hooks for a single {@link Kubb.generate} call. All optional. Progress narration rides the
|
|
@@ -2680,11 +2695,11 @@ declare global {
|
|
|
2680
2695
|
*
|
|
2681
2696
|
* @example
|
|
2682
2697
|
* ```ts
|
|
2683
|
-
* // packages/
|
|
2698
|
+
* // packages/my-plugin/src/hooks.ts
|
|
2684
2699
|
* declare global {
|
|
2685
2700
|
* namespace Kubb {
|
|
2686
2701
|
* interface KubbHooksRegistry {
|
|
2687
|
-
* '
|
|
2702
|
+
* 'my-plugin:ready': [ctx: { count: number }]
|
|
2688
2703
|
* }
|
|
2689
2704
|
* }
|
|
2690
2705
|
* }
|
|
@@ -2695,6 +2710,7 @@ declare global {
|
|
|
2695
2710
|
'kubb:lifecycle:end': [];
|
|
2696
2711
|
'kubb:generation:start': [ctx: KubbGenerationStartContext];
|
|
2697
2712
|
'kubb:generation:end': [ctx: KubbGenerationEndContext];
|
|
2713
|
+
'kubb:generation:summary': [ctx: KubbGenerationSummaryContext];
|
|
2698
2714
|
'kubb:setup:start': [];
|
|
2699
2715
|
'kubb:setup:end': [];
|
|
2700
2716
|
'kubb:format:start': [];
|
|
@@ -2731,8 +2747,8 @@ declare global {
|
|
|
2731
2747
|
* Attach listeners before calling `setup()` or `build()` to observe and react to build progress.
|
|
2732
2748
|
*
|
|
2733
2749
|
* A package can add its own hook names to this type by augmenting
|
|
2734
|
-
* {@link Kubb.KubbHooksRegistry} instead of exporting a second, separate hook type
|
|
2735
|
-
*
|
|
2750
|
+
* {@link Kubb.KubbHooksRegistry} instead of exporting a second, separate hook type. Studio's
|
|
2751
|
+
* connection and RPC hooks intentionally use its separate `StudioHooks` registry.
|
|
2736
2752
|
*
|
|
2737
2753
|
* @example
|
|
2738
2754
|
* ```ts
|
|
@@ -2898,6 +2914,12 @@ type KubbDiagnosticContext = {
|
|
|
2898
2914
|
*/
|
|
2899
2915
|
diagnostic: ProblemDiagnostic | UpdateDiagnostic;
|
|
2900
2916
|
};
|
|
2917
|
+
type KubbGenerationSummaryContext = {
|
|
2918
|
+
duration: number;
|
|
2919
|
+
fileCount: number;
|
|
2920
|
+
failedPlugins: number;
|
|
2921
|
+
status: 'success' | 'failed';
|
|
2922
|
+
};
|
|
2901
2923
|
type KubbFilesProcessingStartContext = {
|
|
2902
2924
|
/**
|
|
2903
2925
|
* Files about to be serialized and written.
|
|
@@ -3066,5 +3088,5 @@ type BuildOutput = {
|
|
|
3066
3088
|
storage: Storage;
|
|
3067
3089
|
};
|
|
3068
3090
|
//#endregion
|
|
3069
|
-
export {
|
|
3070
|
-
//# sourceMappingURL=types-
|
|
3091
|
+
export { Plugin as $, GenerateResult as A, logLevel as At, defineParser as B, SerializedDiagnostic as Bt, KubbSuccessContext as C, GenerationResult as Ct, UserConfig as D, ReporterPluginFiles as Dt, PostGenerateCommand as E, ReporterName as Et, defineGenerator as F, DiagnosticSeverity as Ft, KubbPluginEndContext as G, AdapterSource as Gt, Filter as H, Hookable as Ht, NodeCache as I, Diagnostics as It, NormalizedPlugin as J, KubbPluginSetupContext as K, createAdapter as Kt, KubbDriver as L, PerformanceDiagnostic as Lt, createKubb as M, DiagnosticDoc as Mt, Generator as N, DiagnosticKind as Nt, CreateKubbOptions as O, UserReporter as Ot, GeneratorContext as P, DiagnosticLocation as Pt, Override as Q, FileManagerHooks as R, ProblemCode as Rt, KubbPluginsEndContext as S, createStorage as St, PossibleConfig as T, ReporterContext as Tt, Group as U, Adapter as Ut, Exclude$1 as V, UpdateDiagnostic as Vt, Include as W, AdapterFactoryOptions as Wt, OutputMode as X, Output as Y, OutputOptions as Z, KubbHookLineContext as _, ResolverPathParams as _t, KubbBuildEndContext as a, ResolveBannerContext as at, KubbInfoContext as b, createRenderer as bt, KubbErrorContext as c, ResolveImportsOptions as ct, KubbFilesProcessingStartContext as d, Resolver as dt, PluginFactoryOptions as et, KubbFilesProcessingUpdateContext as f, ResolverDefault as ft, KubbHookEndContext as g, ResolverPatch as gt, KubbGenerationSummaryContext as h, ResolverFilePathParams as ht, Input as i, BannerMeta as it, Kubb$1 as j, Diagnostic as jt, GenerateOptions as k, createReporter as kt, KubbFileProcessingUpdate as l, ResolveOptionsContext as lt, KubbGenerationStartContext as m, ResolverFileParams as mt, CLIOptions as n, ResolvePluginOptions as nt, KubbBuildStartContext as o, ResolveBannerFile as ot, KubbGenerationEndContext as p, ResolverFile as pt, KubbPluginStartContext as q, Config as r, definePlugin as rt, KubbDiagnosticContext as s, ResolveFileOptions as st, BuildOutput as t, PluginName as tt, KubbFilesProcessingEndContext as u, ResolvePathOptions as ut, KubbHookStartContext as v, Renderer as vt, KubbWarnContext as w, Reporter as wt, KubbLifecycleStartContext as x, Storage as xt, KubbHooks as y, RendererFactory as yt, Parser as z, ProblemDiagnostic as zt };
|
|
3092
|
+
//# sourceMappingURL=types-Cw20YGzh.d.ts.map
|
|
@@ -668,7 +668,7 @@ var FileManager = class {
|
|
|
668
668
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
669
669
|
* writes nothing and leaves every mtime where it was.
|
|
670
670
|
*/
|
|
671
|
-
async write(files, { storage, parsers, manifest }) {
|
|
671
|
+
async write(files, { storage, parsers, manifest, signal }) {
|
|
672
672
|
if (files.length === 0) return;
|
|
673
673
|
await this.hooks.callHook("start", files);
|
|
674
674
|
const total = files.length;
|
|
@@ -676,6 +676,7 @@ var FileManager = class {
|
|
|
676
676
|
items: files,
|
|
677
677
|
limit: 50,
|
|
678
678
|
run: async (file, index) => {
|
|
679
|
+
signal?.throwIfAborted();
|
|
679
680
|
const source = await this.parse(file, { parsers });
|
|
680
681
|
await this.hooks.callHook("update", {
|
|
681
682
|
file,
|
|
@@ -685,6 +686,7 @@ var FileManager = class {
|
|
|
685
686
|
percentage: (index + 1) / total * 100
|
|
686
687
|
});
|
|
687
688
|
if (!source) return;
|
|
689
|
+
signal?.throwIfAborted();
|
|
688
690
|
const stored = await storage.readItem(file.path);
|
|
689
691
|
if (isUnchanged({
|
|
690
692
|
stored,
|
|
@@ -692,6 +694,7 @@ var FileManager = class {
|
|
|
692
694
|
key: file.path,
|
|
693
695
|
manifest
|
|
694
696
|
})) return;
|
|
697
|
+
signal?.throwIfAborted();
|
|
695
698
|
await storage.writeItem(file.path, source, { stored });
|
|
696
699
|
manifest?.track({
|
|
697
700
|
key: file.path,
|
|
@@ -789,4 +792,4 @@ function _usingCtx() {
|
|
|
789
792
|
//#endregion
|
|
790
793
|
export { OPERATION_FILTER_TYPES as a, clean as c, toPosixPath as d, write as f, camelCase as h, Hookable as i, isPathInside as l, toError as m, createNodeCache as n, diagnosticCode as o, getErrorMessage as p, FileManager as r, inParallel as s, _usingCtx as t, read as u };
|
|
791
794
|
|
|
792
|
-
//# sourceMappingURL=usingCtx-
|
|
795
|
+
//# sourceMappingURL=usingCtx-BoFplz1D.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usingCtx-BfeNtY1B.js","names":["NodeEventEmitter"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/errors.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/promise.ts","../src/constants.ts","../src/Hookable.ts","../src/FileManager.ts","../src/nodeCache.ts"],"sourcesContent":["type Options = {\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n return text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n","/**\n * Name of the JavaScript runtime executing the current process.\n */\ntype RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Detects the JavaScript runtime executing the current process and exposes its name and version.\n *\n * Prefer the shared {@link runtime} instance over constructing your own.\n */\nclass Runtime {\n /**\n * `true` when the current process is running under Bun.\n *\n * Detection keys off the global `Bun` object rather than `process.versions`,\n * because Bun polyfills `process.versions.node` for Node compatibility and would\n * otherwise look like Node.\n *\n * @example\n * ```ts\n * if (runtime.isBun) {\n * await Bun.write(path, data)\n * }\n * ```\n */\n get isBun(): boolean {\n return typeof Bun !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Deno.\n */\n get isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Node.\n *\n * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.\n */\n get isNode(): boolean {\n return !this.isBun && !this.isDeno && typeof process !== 'undefined' && process.versions?.node != null\n }\n\n /**\n * Name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\n get name(): RuntimeName {\n if (this.isBun) return 'bun'\n if (this.isDeno) return 'deno'\n\n return 'node'\n }\n\n /**\n * Version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * runtime.version // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\n get version(): string {\n if (this.isBun) return process.versions.bun ?? ''\n if (this.isDeno) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n\n return process.versions?.node ?? ''\n }\n}\n\n/**\n * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.\n */\nexport const runtime = new Runtime()\n","import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve } from 'node:path'\nimport { runtime } from './runtime.ts'\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * Previously read content, or `null` when the file does not exist.\n * Omitting this value reads the file before writing.\n */\n stored?: string | null\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact\n * bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a\n * reason to rewrite the file.\n *\n * Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one\n * that normalizes what it stores. Trimming only `stored` would leave a source with leading\n * whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison\n * has already dropped.\n */\nexport function matchesStored({ stored, source }: { stored: string; source: string }): boolean {\n return stored.trim() === source.trim()\n}\n\n/**\n * Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline\n * the way prettier, biome, and oxfmt all do.\n * Skips the write when the trimmed content is empty, or when the file already holds that content.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const content = `${trimmed}\\n`\n const resolved = resolve(path)\n let stored = options.stored\n\n if (stored === undefined) {\n if (runtime.isBun) {\n const file = Bun.file(resolved)\n stored = (await file.exists()) ? await file.text() : null\n } else {\n try {\n stored = await readFile(resolved, { encoding: 'utf-8' })\n } catch {\n /* file doesn't exist yet */\n stored = null\n }\n }\n }\n if (matchesStored({ stored: stored ?? '', source: trimmed })) return null\n\n if (runtime.isBun) {\n await Bun.write(resolved, content)\n return content\n }\n\n // Creating the directory up front costs a syscall per file, and every file after the first in a\n // directory pays it for nothing. Write first and only fall back when the directory is missing,\n // which also stays correct when something removed it mid-run.\n try {\n await writeFile(resolved, content, { encoding: 'utf-8' })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, content, { encoding: 'utf-8' })\n }\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== content) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return content\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n\n/**\n * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved\n * to absolute paths first, so relative and `..`-containing inputs compare correctly.\n *\n * Guards a destructive or an out-of-tree operation: before wiping an output directory, check that\n * it does not contain the project root, and before loading a path a caller supplied, check that it\n * did not escape the directory it is allowed to read from.\n *\n * @example\n * isPathInside('./src/gen', '.') // true — nested inside the root\n * isPathInside('.', '.') // true — the same directory counts as inside\n * isPathInside('.', './src/gen') // false — the root is not inside its own output\n * isPathInside('../other', '.') // false — escapes the root\n */\nexport function isPathInside(path: string, parent: string): boolean {\n const resolvedPath = resolve(path)\n const resolvedParent = resolve(parent)\n if (resolvedPath === resolvedParent) {\n return true\n }\n\n const rel = relative(resolvedParent, resolvedPath)\n\n return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)\n}\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","/**\n * Maximum number of █ characters in a plugin timing bar.\n */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/**\n * Divides elapsed milliseconds into bar-length units (1 block per 100 ms).\n */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/**\n * Upper bound of hook listeners a single plugin can add to one hook (its schema, operation,\n * and operations generators, plus lifecycle hooks). Used to size the hooks emitter's\n * max-listener ceiling so a multi-generator plugin set does not trip Node's leak warning.\n */\nexport const HOOK_LISTENERS_PER_PLUGIN = 4\n\n/**\n * How many files Kubb keeps in flight at once, both writing the output and reading it back to\n * record what the output passes produced. Caps parsed sources held in memory and open file\n * descriptors alike.\n */\nexport const FILE_CONCURRENCY = 50\n\n/**\n * Plugin `include` filter types that select operations directly. When one of these is set\n * without a `schemaName` include, the generate phase pre-scans operations to compute the set\n * of schemas they reach, so unreachable schemas can be pruned for that plugin.\n */\nexport const OPERATION_FILTER_TYPES: ReadonlySet<string> = new Set(['tag', 'operationId', 'path', 'method', 'contentType'])\n\n/**\n * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode\n * and stays stable so it can be referenced in tooling and (later) docs. Reference\n * these instead of inlining the string at a throw site.\n */\nexport const diagnosticCode = {\n /**\n * Fallback for an unstructured error with no specific code.\n */\n unknown: 'KUBB_UNKNOWN',\n /**\n * The file or URL set as `input` could not be read.\n */\n inputNotFound: 'KUBB_INPUT_NOT_FOUND',\n /**\n * A URL set as `input` (or referenced by a `$ref`) answered with a 4xx or 5xx status\n * instead of the document.\n */\n inputRequestFailed: 'KUBB_INPUT_REQUEST_FAILED',\n /**\n * A URL set as `input` (or referenced by a `$ref`) never answered, so the request failed\n * before a status was returned.\n */\n inputUnreachable: 'KUBB_INPUT_UNREACHABLE',\n /**\n * An adapter was configured without an `input`.\n */\n inputRequired: 'KUBB_INPUT_REQUIRED',\n /**\n * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed\n * document instead of a pointer to one.\n */\n legacyInput: 'KUBB_LEGACY_INPUT',\n /**\n * The parsed `input` carries no `openapi` or `swagger` version, so it is not a\n * document the adapter can read.\n */\n invalidDocument: 'KUBB_INVALID_DOCUMENT',\n /**\n * A `$ref` (or equivalent reference) could not be resolved in the source document.\n */\n refNotFound: 'KUBB_REF_NOT_FOUND',\n /**\n * A server variable value is not allowed by its `enum`.\n */\n invalidServerVariable: 'KUBB_INVALID_SERVER_VARIABLE',\n /**\n * A required plugin is missing from the config.\n */\n pluginNotFound: 'KUBB_PLUGIN_NOT_FOUND',\n /**\n * A plugin threw while generating.\n */\n pluginFailed: 'KUBB_PLUGIN_FAILED',\n /**\n * A plugin reported a non-fatal warning through `ctx.warn`.\n */\n pluginWarning: 'KUBB_PLUGIN_WARNING',\n /**\n * A plugin reported an informational message through `ctx.info`.\n */\n pluginInfo: 'KUBB_PLUGIN_INFO',\n /**\n * A schema uses a `format` Kubb does not map to a specific type. Reserved for\n * adapters to emit as a `warning`.\n */\n unsupportedFormat: 'KUBB_UNSUPPORTED_FORMAT',\n /**\n * A referenced schema or operation is marked `deprecated`. Reserved for adapters\n * to emit as an `info`.\n */\n deprecated: 'KUBB_DEPRECATED',\n /**\n * An adapter is required but the config has none. The build cannot read the input\n * without one.\n */\n adapterRequired: 'KUBB_ADAPTER_REQUIRED',\n /**\n * A resolved output path escapes the output directory, which can stem from a path\n * traversal in the spec or a misconfigured `group.name`.\n */\n pathTraversal: 'KUBB_PATH_TRAVERSAL',\n /**\n * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,\n * so cleaning would delete kubb.config and every source file.\n */\n cleanRoot: 'KUBB_CLEAN_ROOT',\n /**\n * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.\n */\n invalidPluginOptions: 'KUBB_INVALID_PLUGIN_OPTIONS',\n /**\n * A post-generate command (`output.postGenerate`) exited with a failure.\n */\n postGenerateFailed: 'KUBB_POST_GENERATE_FAILED',\n /**\n * The formatter pass over the generated files failed.\n */\n formatFailed: 'KUBB_FORMAT_FAILED',\n /**\n * The linter pass over the generated files failed.\n */\n lintFailed: 'KUBB_LINT_FAILED',\n /**\n * A barrel tries to re-export the same name from more than one module.\n */\n barrelDuplicateExport: 'KUBB_BARREL_DUPLICATE_EXPORT',\n /**\n * Not a failure. Carries a plugin's elapsed time, summed into the run total.\n */\n performance: 'KUBB_PERFORMANCE',\n /**\n * Not a failure. A newer Kubb version is available on npm.\n */\n updateAvailable: 'KUBB_UPDATE_AVAILABLE',\n} as const\n\n/**\n * Union of the stable {@link diagnosticCode} values.\n */\nexport type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode]\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from '@internals/utils'\n\n/**\n * A function that can be registered as a hook listener, synchronous or async. Any return value is\n * allowed and ignored, so handlers that return a result for their own callers still register.\n */\ntype AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => unknown\n\n/**\n * Typed hook emitter that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript hook-map inference.\n *\n * @example\n * ```ts\n * const hooks = new Hookable<{ build: [name: string] }>()\n * hooks.hook('build', async (name) => { console.log(name) })\n * await hooks.callHook('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class Hookable<THooks extends { [K in keyof THooks]: Array<unknown> }> {\n /**\n * Maximum number of listeners per hook before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Calls `hookName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the hook name and serialized arguments.\n *\n * @example\n * ```ts\n * await hooks.callHook('build', 'petstore')\n * ```\n */\n callHook<THookName extends keyof THooks & string>(hookName: THookName, ...hookArgs: THooks[THookName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(hookName) as Array<AsyncListener<THooks[THookName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(hookName, listeners, hookArgs)\n }\n\n async #emitAll<THookName extends keyof THooks & string>(\n hookName: THookName,\n listeners: Array<AsyncListener<THooks[THookName]>>,\n hookArgs: THooks[THookName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...hookArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(hookArgs)\n } catch {\n serializedArgs = String(hookArgs)\n }\n throw new Error(`Error in async listener for \"${hookName}\" with hookArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `hookName` and returns a function that removes it.\n *\n * @example\n * ```ts\n * const unhook = hooks.hook('build', async (name) => { console.log(name) })\n * unhook() // removes it\n * ```\n */\n hook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): () => void {\n this.#emitter.on(hookName, handler as AsyncListener<Array<unknown>>)\n return () => this.removeHook(hookName, handler)\n }\n\n /**\n * Registers every handler in `configHooks` at once and returns a function that removes them\n * all. Undefined entries are skipped, so a partial hook object registers only its present keys.\n *\n * @example\n * ```ts\n * const unhook = hooks.addHooks({ build: onBuild, done: onDone })\n * unhook() // removes both\n * ```\n */\n addHooks(configHooks: Partial<{ [K in keyof THooks & string]: AsyncListener<THooks[K]> }>): () => void {\n const unhooks = (Object.keys(configHooks) as Array<keyof THooks & string>)\n .filter((name) => configHooks[name])\n .map((name) => this.hook(name, configHooks[name]!))\n\n return () => {\n for (const unhook of unhooks) unhook()\n }\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * hooks.removeHook('build', handler)\n * ```\n */\n removeHook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): void {\n this.#emitter.off(hookName, handler as AsyncListener<Array<unknown>>)\n }\n\n /**\n * Returns the number of listeners registered for `hookName`.\n *\n * @example\n * ```ts\n * hooks.hook('build', handler)\n * hooks.listenerCount('build') // 1\n * ```\n */\n listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number {\n return this.#emitter.listenerCount(hookName)\n }\n\n /**\n * Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.\n * Set this above the expected listener count when many listeners attach by design.\n *\n * @example\n * ```ts\n * hooks.setMaxListeners(40)\n * ```\n */\n setMaxListeners(max: number): void {\n this.#emitter.setMaxListeners(max)\n }\n\n /**\n * Removes all listeners from every hook channel.\n *\n * @example\n * ```ts\n * hooks.removeAllHooks()\n * ```\n */\n removeAllHooks(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import { inParallel, matchesStored, read } from '@internals/utils'\nimport { ast, extractStringsFromNodes, type CodeNode, type FileNode } from '@kubb/ast'\nimport { FILE_CONCURRENCY } from './constants.ts'\nimport type { Storage } from './createStorage.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { OutputManifest } from './outputManifest.ts'\nimport { Hookable } from './Hookable.ts'\n\n/**\n * Hooks fired around a `FileManager#write` batch: `start` before it, `update` per file, `end` after.\n */\nexport type FileManagerHooks = {\n start: [files: Array<FileNode>]\n update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]\n end: [files: Array<FileNode>]\n}\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n}\n\ntype WriteOptions = ParseOptions & {\n storage: Storage\n /**\n * Consulted before each write so a file the output passes already normalized is recognized as\n * unchanged. Omitted when no formatter, linter, or `postGenerate` step is configured.\n */\n manifest?: OutputManifest\n}\n\nfunction joinSources(file: FileNode): string {\n return file.sources\n .map((source) => extractStringsFromNodes(source.nodes as Array<CodeNode>))\n .filter(Boolean)\n .join('\\n\\n')\n}\n\nasync function parseCopy(file: FileNode): Promise<string> {\n let content: string\n try {\n content = await read(file.copy as string)\n } catch (err) {\n throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err })\n }\n\n return [file.banner, content, file.footer]\n .filter((segment): segment is string => Boolean(segment))\n .map((segment) => segment.trimEnd())\n .join('\\n')\n}\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n // Incoming file (b) takes precedence for banner/footer so a barrel file (whose\n // banner/footer the barrel plugin resolves last) wins over a plugin-generated\n // file at the same path.\n banner: b.banner,\n footer: b.footer,\n // A verbatim-copy file cannot be merged with rendered content; the incoming `copy` wins.\n copy: b.copy ?? a.copy,\n sources: a.sources.length ? (b.sources.length ? [...a.sources, ...b.sources] : a.sources) : b.sources,\n imports: a.imports.length ? (b.imports.length ? [...a.imports, ...b.imports] : a.imports) : b.imports,\n exports: a.exports.length ? (b.exports.length ? [...a.exports, ...b.exports] : a.exports) : b.exports,\n }\n}\n\nfunction isIndexPath(path: string): boolean {\n return path.endsWith('/index.ts') || path === 'index.ts'\n}\n\n// Sort order: shortest path first. Within a length bucket, index.ts barrels last.\nfunction compareFiles(a: FileNode, b: FileNode): number {\n const lenDiff = a.path.length - b.path.length\n if (lenDiff !== 0) return lenDiff\n const aIsIndex = isIndexPath(a.path)\n const bIsIndex = isIndexPath(b.path)\n if (aIsIndex && !bIsIndex) return 1\n if (!aIsIndex && bIsIndex) return -1\n\n return 0\n}\n\n// A file is unchanged either because the storage already holds this content, or because the\n// manifest knows the output passes turn this exact source into what the storage holds.\nfunction isUnchanged({ stored, source, key, manifest }: { stored: string | null; source: string; key: string; manifest?: OutputManifest }): boolean {\n if (stored === null) return false\n if (matchesStored({ stored, source })) return true\n\n return manifest?.isUpToDate({ key, source, disk: stored }) ?? false\n}\n\n/**\n * In-memory file store for generated files, and the writer that turns them into source\n * strings on `storage`. Files sharing a `path` are merged (sources/imports/exports\n * concatenated). The `files` getter is sorted by path length (barrel `index.ts` last\n * within a bucket).\n *\n * @example\n * ```ts\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * manager.files // sorted view\n * await manager.write(manager.files, { storage: fsStorage() })\n * ```\n */\nexport class FileManager {\n readonly hooks = new Hookable<FileManagerHooks>()\n readonly #cache = new Map<string, FileNode>()\n // Cached sorted view. Null means stale and rebuilt lazily on next `files` read.\n // Nulled (not mutated) on every write so callers holding a prior reference keep\n // their snapshot. `dispose()` must not silently empty an array the consumer\n // already holds.\n #sorted: Array<FileNode> | null = null\n\n add(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, false)\n }\n\n upsert(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, true)\n }\n\n #store(files: ReadonlyArray<FileNode>, mergeExisting: boolean): Array<FileNode> {\n const batch = files.length > 1 ? this.#dedupe(files) : files\n const resolved: Array<FileNode> = []\n\n for (const file of batch) {\n const existing = this.#cache.get(file.path)\n const merged = existing && mergeExisting ? ast.factory.createFile(mergeFile(existing, file)) : ast.factory.createFile(file)\n this.#cache.set(merged.path, merged)\n resolved.push(merged)\n }\n\n if (resolved.length > 0) this.#sorted = null\n return resolved\n }\n\n // Merges same-path entries within a batch so the cache update loop stays\n // uniform. Only called for multi-file batches.\n #dedupe(files: ReadonlyArray<FileNode>): Array<FileNode> {\n const seen = new Map<string, FileNode>()\n for (const file of files) {\n const prev = seen.get(file.path)\n seen.set(file.path, prev ? mergeFile(prev, file) : file)\n }\n return [...seen.values()]\n }\n\n clear(): void {\n this.#cache.clear()\n this.#sorted = null\n }\n\n /**\n * Releases all stored files and clears every `hooks` listener. Called by the core after\n * `kubb:build:end`.\n */\n dispose(): void {\n this.clear()\n this.hooks.removeAllHooks()\n }\n\n /**\n * All stored files in stable sort order (shortest path first, barrel files\n * last within a length bucket). Returns a cached view, do not mutate.\n */\n get files(): Array<FileNode> {\n return (this.#sorted ??= [...this.#cache.values()].sort(compareFiles))\n }\n\n /**\n * Converts a file's AST sources (or its `copy` source) into the final on-disk string.\n */\n async parse(file: FileNode, { parsers }: ParseOptions = {}): Promise<string> {\n if (file.copy) {\n return parseCopy(file)\n }\n\n if (!parsers || !file.extname) {\n return joinSources(file)\n }\n\n const parser = parsers.get(file.extname)\n\n if (!parser) {\n return joinSources(file)\n }\n\n return parser.parse(file)\n }\n\n /**\n * Parses and writes every file through a bounded pool of workers. A small spec runs all its files\n * at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in\n * memory rather than holding every source, while still overlapping each file's write with the\n * next file's parse. Each `update` carries the file's input position, so a consumer can present\n * the files in generation order even though they finish in whatever order they parse.\n *\n * A file the storage already holds is skipped, so a rebuild that generates identical output\n * writes nothing and leaves every mtime where it was.\n */\n async write(files: Array<FileNode>, { storage, parsers, manifest }: WriteOptions): Promise<void> {\n if (files.length === 0) return\n\n await this.hooks.callHook('start', files)\n\n const total = files.length\n\n await inParallel({\n items: files,\n limit: FILE_CONCURRENCY,\n run: async (file, index) => {\n const source = await this.parse(file, { parsers })\n await this.hooks.callHook('update', { file, source, processed: index + 1, total, percentage: ((index + 1) / total) * 100 })\n if (!source) return\n\n // Checking here rather than inside a driver gives a storage writing to S3 or a database\n // the same guarantee `fsStorage` has, that unchanged content is never rewritten.\n const stored = await storage.readItem(file.path)\n if (isUnchanged({ stored, source, key: file.path, manifest })) return\n\n await storage.writeItem(file.path, source, { stored })\n\n // Only a file that was written can have been changed by the output passes.\n manifest?.track({ key: file.path, source })\n },\n })\n\n await this.hooks.callHook('end', files)\n }\n}\n","/**\n * Per-node memo shared by every plugin that generates from the same schema or operation node in\n * one generate pass. The driver creates one `NodeCache` per node during the walk and hands the\n * same instance to each plugin's generator context, so work derived purely from the node (its\n * resolved name, imports, parameters) is computed by the first plugin that needs it and reused by\n * the rest instead of being recomputed per plugin.\n *\n * Keys are namespaced by convention (`'plugin-ts:imports'`) so two plugins caching different\n * derivations of the same node never collide.\n *\n * @example Fill on first read, reuse afterwards\n * ```ts\n * const imports = ctx.cache.ensureItem('plugin-ts:imports', () => ctx.resolver.imports({ node, root, output }))\n * ```\n */\nexport type NodeCache = {\n /**\n * Returns the value stored under `key`, or `undefined` when nothing is stored yet.\n */\n readItem<TValue>(key: string): TValue | undefined\n /**\n * Stores `value` under `key`, overwriting any previous value, and returns it.\n */\n writeItem<TValue>(key: string, value: TValue): TValue\n /**\n * Returns the value stored under `key`, computing and storing it with `factory` on the first\n * call. Later calls with the same key return the stored value without running `factory` again.\n */\n ensureItem<TValue>(key: string, factory: () => TValue): TValue\n}\n\n/**\n * Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate\n * walk.\n */\nexport function createNodeCache(): NodeCache {\n const store = new Map<string, unknown>()\n\n return {\n readItem<TValue>(key: string): TValue | undefined {\n return store.get(key) as TValue | undefined\n },\n writeItem<TValue>(key: string, value: TValue): TValue {\n store.set(key, value)\n return value\n },\n ensureItem<TValue>(key: string, factory: () => TValue): TValue {\n if (store.has(key)) return store.get(key) as TValue\n\n const value = factory()\n store.set(key, value)\n return value\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;CAC9D,OAAO,KACJ,KAAK,CAAC,CACN,QAAQ,qBAAq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AC1B,MAAM,SAAS,MAAM,KAAK,MAAM,MAAM,EAAE,QAAQ,CAAC;IACjD,MAAM,KAAK,MAAM,SAAS,UAAU;KAAE;KAAM;KAAQ,WAAW,QAAQ;KAAG;KAAO,aAAc,QAAQ,KAAK,QAAS;IAAI,CAAC;IAC1H,IAAI,CAAC,QAAQ;IAIb,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,IAAI;IAC/C,IAAI,YAAY;KAAE;KAAQ;KAAQ,KAAK,KAAK;KAAM;IAAS,CAAC,GAAG;IAE/D,MAAM,QAAQ,UAAU,KAAK,MAAM,QAAQ,EAAE,OAAO,CAAC;IAGrD,UAAU,MAAM;KAAE,KAAK,KAAK;KAAM;IAAO,CAAC;GAC5C;EACF,CAAC;EAED,MAAM,KAAK,MAAM,SAAS,OAAO,KAAK;CACxC;AACF;;;;;;;ACpMA,SAAgB,kBAA6B;CAC3C,MAAM,wBAAQ,IAAI,IAAqB;CAEvC,OAAO;EACL,SAAiB,KAAiC;GAChD,OAAO,MAAM,IAAI,GAAG;EACtB;EACA,UAAkB,KAAa,OAAuB;GACpD,MAAM,IAAI,KAAK,KAAK;GACpB,OAAO;EACT;EACA,WAAmB,KAAa,SAA+B;GAC7D,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;GAExC,MAAM,QAAQ,QAAQ;GACtB,MAAM,IAAI,KAAK,KAAK;GACpB,OAAO;EACT;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"usingCtx-BoFplz1D.js","names":["NodeEventEmitter"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/errors.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/promise.ts","../src/constants.ts","../src/Hookable.ts","../src/FileManager.ts","../src/nodeCache.ts"],"sourcesContent":["type Options = {\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n return text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n","/**\n * Name of the JavaScript runtime executing the current process.\n */\ntype RuntimeName = 'bun' | 'deno' | 'node'\n\n/**\n * Detects the JavaScript runtime executing the current process and exposes its name and version.\n *\n * Prefer the shared {@link runtime} instance over constructing your own.\n */\nclass Runtime {\n /**\n * `true` when the current process is running under Bun.\n *\n * Detection keys off the global `Bun` object rather than `process.versions`,\n * because Bun polyfills `process.versions.node` for Node compatibility and would\n * otherwise look like Node.\n *\n * @example\n * ```ts\n * if (runtime.isBun) {\n * await Bun.write(path, data)\n * }\n * ```\n */\n get isBun(): boolean {\n return typeof Bun !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Deno.\n */\n get isDeno(): boolean {\n return typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined'\n }\n\n /**\n * `true` when the current process is running under Node.\n *\n * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.\n */\n get isNode(): boolean {\n return !this.isBun && !this.isDeno && typeof process !== 'undefined' && process.versions?.node != null\n }\n\n /**\n * Name of the runtime executing the current process.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\n get name(): RuntimeName {\n if (this.isBun) return 'bun'\n if (this.isDeno) return 'deno'\n\n return 'node'\n }\n\n /**\n * Version of the active runtime, or an empty string when it cannot be read.\n *\n * @example\n * ```ts\n * runtime.version // '1.3.11' under Bun, '22.22.2' under Node\n * ```\n */\n get version(): string {\n if (this.isBun) return process.versions.bun ?? ''\n if (this.isDeno) return (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? ''\n\n return process.versions?.node ?? ''\n }\n}\n\n/**\n * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.\n */\nexport const runtime = new Runtime()\n","import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve } from 'node:path'\nimport { runtime } from './runtime.ts'\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * Previously read content, or `null` when the file does not exist.\n * Omitting this value reads the file before writing.\n */\n stored?: string | null\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact\n * bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a\n * reason to rewrite the file.\n *\n * Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one\n * that normalizes what it stores. Trimming only `stored` would leave a source with leading\n * whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison\n * has already dropped.\n */\nexport function matchesStored({ stored, source }: { stored: string; source: string }): boolean {\n return stored.trim() === source.trim()\n}\n\n/**\n * Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline\n * the way prettier, biome, and oxfmt all do.\n * Skips the write when the trimmed content is empty, or when the file already holds that content.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const content = `${trimmed}\\n`\n const resolved = resolve(path)\n let stored = options.stored\n\n if (stored === undefined) {\n if (runtime.isBun) {\n const file = Bun.file(resolved)\n stored = (await file.exists()) ? await file.text() : null\n } else {\n try {\n stored = await readFile(resolved, { encoding: 'utf-8' })\n } catch {\n /* file doesn't exist yet */\n stored = null\n }\n }\n }\n if (matchesStored({ stored: stored ?? '', source: trimmed })) return null\n\n if (runtime.isBun) {\n await Bun.write(resolved, content)\n return content\n }\n\n // Creating the directory up front costs a syscall per file, and every file after the first in a\n // directory pays it for nothing. Write first and only fall back when the directory is missing,\n // which also stays correct when something removed it mid-run.\n try {\n await writeFile(resolved, content, { encoding: 'utf-8' })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, content, { encoding: 'utf-8' })\n }\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== content) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return content\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n\n/**\n * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved\n * to absolute paths first, so relative and `..`-containing inputs compare correctly.\n *\n * Guards a destructive or an out-of-tree operation: before wiping an output directory, check that\n * it does not contain the project root, and before loading a path a caller supplied, check that it\n * did not escape the directory it is allowed to read from.\n *\n * @example\n * isPathInside('./src/gen', '.') // true — nested inside the root\n * isPathInside('.', '.') // true — the same directory counts as inside\n * isPathInside('.', './src/gen') // false — the root is not inside its own output\n * isPathInside('../other', '.') // false — escapes the root\n */\nexport function isPathInside(path: string, parent: string): boolean {\n const resolvedPath = resolve(path)\n const resolvedParent = resolve(parent)\n if (resolvedPath === resolvedParent) {\n return true\n }\n\n const rel = relative(resolvedParent, resolvedPath)\n\n return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)\n}\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","/**\n * Maximum number of █ characters in a plugin timing bar.\n */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/**\n * Divides elapsed milliseconds into bar-length units (1 block per 100 ms).\n */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/**\n * Upper bound of hook listeners a single plugin can add to one hook (its schema, operation,\n * and operations generators, plus lifecycle hooks). Used to size the hooks emitter's\n * max-listener ceiling so a multi-generator plugin set does not trip Node's leak warning.\n */\nexport const HOOK_LISTENERS_PER_PLUGIN = 4\n\n/**\n * How many files Kubb keeps in flight at once, both writing the output and reading it back to\n * record what the output passes produced. Caps parsed sources held in memory and open file\n * descriptors alike.\n */\nexport const FILE_CONCURRENCY = 50\n\n/**\n * Plugin `include` filter types that select operations directly. When one of these is set\n * without a `schemaName` include, the generate phase pre-scans operations to compute the set\n * of schemas they reach, so unreachable schemas can be pruned for that plugin.\n */\nexport const OPERATION_FILTER_TYPES: ReadonlySet<string> = new Set(['tag', 'operationId', 'path', 'method', 'contentType'])\n\n/**\n * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode\n * and stays stable so it can be referenced in tooling and (later) docs. Reference\n * these instead of inlining the string at a throw site.\n */\nexport const diagnosticCode = {\n /**\n * Fallback for an unstructured error with no specific code.\n */\n unknown: 'KUBB_UNKNOWN',\n /**\n * The file or URL set as `input` could not be read.\n */\n inputNotFound: 'KUBB_INPUT_NOT_FOUND',\n /**\n * A URL set as `input` (or referenced by a `$ref`) answered with a 4xx or 5xx status\n * instead of the document.\n */\n inputRequestFailed: 'KUBB_INPUT_REQUEST_FAILED',\n /**\n * A URL set as `input` (or referenced by a `$ref`) never answered, so the request failed\n * before a status was returned.\n */\n inputUnreachable: 'KUBB_INPUT_UNREACHABLE',\n /**\n * An adapter was configured without an `input`.\n */\n inputRequired: 'KUBB_INPUT_REQUIRED',\n /**\n * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed\n * document instead of a pointer to one.\n */\n legacyInput: 'KUBB_LEGACY_INPUT',\n /**\n * The parsed `input` carries no `openapi` or `swagger` version, so it is not a\n * document the adapter can read.\n */\n invalidDocument: 'KUBB_INVALID_DOCUMENT',\n /**\n * A `$ref` (or equivalent reference) could not be resolved in the source document.\n */\n refNotFound: 'KUBB_REF_NOT_FOUND',\n /**\n * A server variable value is not allowed by its `enum`.\n */\n invalidServerVariable: 'KUBB_INVALID_SERVER_VARIABLE',\n /**\n * A required plugin is missing from the config.\n */\n pluginNotFound: 'KUBB_PLUGIN_NOT_FOUND',\n /**\n * A plugin threw while generating.\n */\n pluginFailed: 'KUBB_PLUGIN_FAILED',\n /**\n * A plugin reported a non-fatal warning through `ctx.warn`.\n */\n pluginWarning: 'KUBB_PLUGIN_WARNING',\n /**\n * A plugin reported an informational message through `ctx.info`.\n */\n pluginInfo: 'KUBB_PLUGIN_INFO',\n /**\n * A schema uses a `format` Kubb does not map to a specific type. Reserved for\n * adapters to emit as a `warning`.\n */\n unsupportedFormat: 'KUBB_UNSUPPORTED_FORMAT',\n /**\n * A referenced schema or operation is marked `deprecated`. Reserved for adapters\n * to emit as an `info`.\n */\n deprecated: 'KUBB_DEPRECATED',\n /**\n * An adapter is required but the config has none. The build cannot read the input\n * without one.\n */\n adapterRequired: 'KUBB_ADAPTER_REQUIRED',\n /**\n * A resolved output path escapes the output directory, which can stem from a path\n * traversal in the spec or a misconfigured `group.name`.\n */\n pathTraversal: 'KUBB_PATH_TRAVERSAL',\n /**\n * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,\n * so cleaning would delete kubb.config and every source file.\n */\n cleanRoot: 'KUBB_CLEAN_ROOT',\n /**\n * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.\n */\n invalidPluginOptions: 'KUBB_INVALID_PLUGIN_OPTIONS',\n /**\n * A post-generate command (`output.postGenerate`) exited with a failure.\n */\n postGenerateFailed: 'KUBB_POST_GENERATE_FAILED',\n /**\n * The formatter pass over the generated files failed.\n */\n formatFailed: 'KUBB_FORMAT_FAILED',\n /**\n * The linter pass over the generated files failed.\n */\n lintFailed: 'KUBB_LINT_FAILED',\n /**\n * A barrel tries to re-export the same name from more than one module.\n */\n barrelDuplicateExport: 'KUBB_BARREL_DUPLICATE_EXPORT',\n /**\n * Not a failure. Carries a plugin's elapsed time, summed into the run total.\n */\n performance: 'KUBB_PERFORMANCE',\n /**\n * Not a failure. A newer Kubb version is available on npm.\n */\n updateAvailable: 'KUBB_UPDATE_AVAILABLE',\n} as const\n\n/**\n * Union of the stable {@link diagnosticCode} values.\n */\nexport type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode]\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from '@internals/utils'\n\n/**\n * A function that can be registered as a hook listener, synchronous or async. Any return value is\n * allowed and ignored, so handlers that return a result for their own callers still register.\n */\ntype AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => unknown\n\n/**\n * Typed hook emitter that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript hook-map inference.\n *\n * @example\n * ```ts\n * const hooks = new Hookable<{ build: [name: string] }>()\n * hooks.hook('build', async (name) => { console.log(name) })\n * await hooks.callHook('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class Hookable<THooks extends { [K in keyof THooks]: Array<unknown> }> {\n /**\n * Maximum number of listeners per hook before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Calls `hookName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the hook name and serialized arguments.\n *\n * @example\n * ```ts\n * await hooks.callHook('build', 'petstore')\n * ```\n */\n callHook<THookName extends keyof THooks & string>(hookName: THookName, ...hookArgs: THooks[THookName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(hookName) as Array<AsyncListener<THooks[THookName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(hookName, listeners, hookArgs)\n }\n\n async #emitAll<THookName extends keyof THooks & string>(\n hookName: THookName,\n listeners: Array<AsyncListener<THooks[THookName]>>,\n hookArgs: THooks[THookName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...hookArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(hookArgs)\n } catch {\n serializedArgs = String(hookArgs)\n }\n throw new Error(`Error in async listener for \"${hookName}\" with hookArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `hookName` and returns a function that removes it.\n *\n * @example\n * ```ts\n * const unhook = hooks.hook('build', async (name) => { console.log(name) })\n * unhook() // removes it\n * ```\n */\n hook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): () => void {\n this.#emitter.on(hookName, handler as AsyncListener<Array<unknown>>)\n return () => this.removeHook(hookName, handler)\n }\n\n /**\n * Registers every handler in `configHooks` at once and returns a function that removes them\n * all. Undefined entries are skipped, so a partial hook object registers only its present keys.\n *\n * @example\n * ```ts\n * const unhook = hooks.addHooks({ build: onBuild, done: onDone })\n * unhook() // removes both\n * ```\n */\n addHooks(configHooks: Partial<{ [K in keyof THooks & string]: AsyncListener<THooks[K]> }>): () => void {\n const unhooks = (Object.keys(configHooks) as Array<keyof THooks & string>)\n .filter((name) => configHooks[name])\n .map((name) => this.hook(name, configHooks[name]!))\n\n return () => {\n for (const unhook of unhooks) unhook()\n }\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * hooks.removeHook('build', handler)\n * ```\n */\n removeHook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): void {\n this.#emitter.off(hookName, handler as AsyncListener<Array<unknown>>)\n }\n\n /**\n * Returns the number of listeners registered for `hookName`.\n *\n * @example\n * ```ts\n * hooks.hook('build', handler)\n * hooks.listenerCount('build') // 1\n * ```\n */\n listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number {\n return this.#emitter.listenerCount(hookName)\n }\n\n /**\n * Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.\n * Set this above the expected listener count when many listeners attach by design.\n *\n * @example\n * ```ts\n * hooks.setMaxListeners(40)\n * ```\n */\n setMaxListeners(max: number): void {\n this.#emitter.setMaxListeners(max)\n }\n\n /**\n * Removes all listeners from every hook channel.\n *\n * @example\n * ```ts\n * hooks.removeAllHooks()\n * ```\n */\n removeAllHooks(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import { inParallel, matchesStored, read } from '@internals/utils'\nimport { ast, extractStringsFromNodes, type CodeNode, type FileNode } from '@kubb/ast'\nimport { FILE_CONCURRENCY } from './constants.ts'\nimport type { Storage } from './createStorage.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { OutputManifest } from './outputManifest.ts'\nimport { Hookable } from './Hookable.ts'\n\n/**\n * Hooks fired around a `FileManager#write` batch: `start` before it, `update` per file, `end` after.\n */\nexport type FileManagerHooks = {\n start: [files: Array<FileNode>]\n update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]\n end: [files: Array<FileNode>]\n}\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n}\n\ntype WriteOptions = ParseOptions & {\n storage: Storage\n signal?: AbortSignal\n /**\n * Consulted before each write so a file the output passes already normalized is recognized as\n * unchanged. Omitted when no formatter, linter, or `postGenerate` step is configured.\n */\n manifest?: OutputManifest\n}\n\nfunction joinSources(file: FileNode): string {\n return file.sources\n .map((source) => extractStringsFromNodes(source.nodes as Array<CodeNode>))\n .filter(Boolean)\n .join('\\n\\n')\n}\n\nasync function parseCopy(file: FileNode): Promise<string> {\n let content: string\n try {\n content = await read(file.copy as string)\n } catch (err) {\n throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err })\n }\n\n return [file.banner, content, file.footer]\n .filter((segment): segment is string => Boolean(segment))\n .map((segment) => segment.trimEnd())\n .join('\\n')\n}\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n // Incoming file (b) takes precedence for banner/footer so a barrel file (whose\n // banner/footer the barrel plugin resolves last) wins over a plugin-generated\n // file at the same path.\n banner: b.banner,\n footer: b.footer,\n // A verbatim-copy file cannot be merged with rendered content; the incoming `copy` wins.\n copy: b.copy ?? a.copy,\n sources: a.sources.length ? (b.sources.length ? [...a.sources, ...b.sources] : a.sources) : b.sources,\n imports: a.imports.length ? (b.imports.length ? [...a.imports, ...b.imports] : a.imports) : b.imports,\n exports: a.exports.length ? (b.exports.length ? [...a.exports, ...b.exports] : a.exports) : b.exports,\n }\n}\n\nfunction isIndexPath(path: string): boolean {\n return path.endsWith('/index.ts') || path === 'index.ts'\n}\n\n// Sort order: shortest path first. Within a length bucket, index.ts barrels last.\nfunction compareFiles(a: FileNode, b: FileNode): number {\n const lenDiff = a.path.length - b.path.length\n if (lenDiff !== 0) return lenDiff\n const aIsIndex = isIndexPath(a.path)\n const bIsIndex = isIndexPath(b.path)\n if (aIsIndex && !bIsIndex) return 1\n if (!aIsIndex && bIsIndex) return -1\n\n return 0\n}\n\n// A file is unchanged either because the storage already holds this content, or because the\n// manifest knows the output passes turn this exact source into what the storage holds.\nfunction isUnchanged({ stored, source, key, manifest }: { stored: string | null; source: string; key: string; manifest?: OutputManifest }): boolean {\n if (stored === null) return false\n if (matchesStored({ stored, source })) return true\n\n return manifest?.isUpToDate({ key, source, disk: stored }) ?? false\n}\n\n/**\n * In-memory file store for generated files, and the writer that turns them into source\n * strings on `storage`. Files sharing a `path` are merged (sources/imports/exports\n * concatenated). The `files` getter is sorted by path length (barrel `index.ts` last\n * within a bucket).\n *\n * @example\n * ```ts\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * manager.files // sorted view\n * await manager.write(manager.files, { storage: fsStorage() })\n * ```\n */\nexport class FileManager {\n readonly hooks = new Hookable<FileManagerHooks>()\n readonly #cache = new Map<string, FileNode>()\n // Cached sorted view. Null means stale and rebuilt lazily on next `files` read.\n // Nulled (not mutated) on every write so callers holding a prior reference keep\n // their snapshot. `dispose()` must not silently empty an array the consumer\n // already holds.\n #sorted: Array<FileNode> | null = null\n\n add(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, false)\n }\n\n upsert(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, true)\n }\n\n #store(files: ReadonlyArray<FileNode>, mergeExisting: boolean): Array<FileNode> {\n const batch = files.length > 1 ? this.#dedupe(files) : files\n const resolved: Array<FileNode> = []\n\n for (const file of batch) {\n const existing = this.#cache.get(file.path)\n const merged = existing && mergeExisting ? ast.factory.createFile(mergeFile(existing, file)) : ast.factory.createFile(file)\n this.#cache.set(merged.path, merged)\n resolved.push(merged)\n }\n\n if (resolved.length > 0) this.#sorted = null\n return resolved\n }\n\n // Merges same-path entries within a batch so the cache update loop stays\n // uniform. Only called for multi-file batches.\n #dedupe(files: ReadonlyArray<FileNode>): Array<FileNode> {\n const seen = new Map<string, FileNode>()\n for (const file of files) {\n const prev = seen.get(file.path)\n seen.set(file.path, prev ? mergeFile(prev, file) : file)\n }\n return [...seen.values()]\n }\n\n clear(): void {\n this.#cache.clear()\n this.#sorted = null\n }\n\n /**\n * Releases all stored files and clears every `hooks` listener. Called by the core after\n * `kubb:build:end`.\n */\n dispose(): void {\n this.clear()\n this.hooks.removeAllHooks()\n }\n\n /**\n * All stored files in stable sort order (shortest path first, barrel files\n * last within a length bucket). Returns a cached view, do not mutate.\n */\n get files(): Array<FileNode> {\n return (this.#sorted ??= [...this.#cache.values()].sort(compareFiles))\n }\n\n /**\n * Converts a file's AST sources (or its `copy` source) into the final on-disk string.\n */\n async parse(file: FileNode, { parsers }: ParseOptions = {}): Promise<string> {\n if (file.copy) {\n return parseCopy(file)\n }\n\n if (!parsers || !file.extname) {\n return joinSources(file)\n }\n\n const parser = parsers.get(file.extname)\n\n if (!parser) {\n return joinSources(file)\n }\n\n return parser.parse(file)\n }\n\n /**\n * Parses and writes every file through a bounded pool of workers. A small spec runs all its files\n * at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in\n * memory rather than holding every source, while still overlapping each file's write with the\n * next file's parse. Each `update` carries the file's input position, so a consumer can present\n * the files in generation order even though they finish in whatever order they parse.\n *\n * A file the storage already holds is skipped, so a rebuild that generates identical output\n * writes nothing and leaves every mtime where it was.\n */\n async write(files: Array<FileNode>, { storage, parsers, manifest, signal }: WriteOptions): Promise<void> {\n if (files.length === 0) return\n\n await this.hooks.callHook('start', files)\n\n const total = files.length\n\n await inParallel({\n items: files,\n limit: FILE_CONCURRENCY,\n run: async (file, index) => {\n signal?.throwIfAborted()\n const source = await this.parse(file, { parsers })\n await this.hooks.callHook('update', { file, source, processed: index + 1, total, percentage: ((index + 1) / total) * 100 })\n if (!source) return\n\n signal?.throwIfAborted()\n\n // Checking here rather than inside a driver gives a storage writing to S3 or a database\n // the same guarantee `fsStorage` has, that unchanged content is never rewritten.\n const stored = await storage.readItem(file.path)\n if (isUnchanged({ stored, source, key: file.path, manifest })) return\n\n signal?.throwIfAborted()\n await storage.writeItem(file.path, source, { stored })\n\n // Only a file that was written can have been changed by the output passes.\n manifest?.track({ key: file.path, source })\n },\n })\n\n await this.hooks.callHook('end', files)\n }\n}\n","/**\n * Per-node memo shared by every plugin that generates from the same schema or operation node in\n * one generate pass. The driver creates one `NodeCache` per node during the walk and hands the\n * same instance to each plugin's generator context, so work derived purely from the node (its\n * resolved name, imports, parameters) is computed by the first plugin that needs it and reused by\n * the rest instead of being recomputed per plugin.\n *\n * Keys are namespaced by convention (`'plugin-ts:imports'`) so two plugins caching different\n * derivations of the same node never collide.\n *\n * @example Fill on first read, reuse afterwards\n * ```ts\n * const imports = ctx.cache.ensureItem('plugin-ts:imports', () => ctx.resolver.imports({ node, root, output }))\n * ```\n */\nexport type NodeCache = {\n /**\n * Returns the value stored under `key`, or `undefined` when nothing is stored yet.\n */\n readItem<TValue>(key: string): TValue | undefined\n /**\n * Stores `value` under `key`, overwriting any previous value, and returns it.\n */\n writeItem<TValue>(key: string, value: TValue): TValue\n /**\n * Returns the value stored under `key`, computing and storing it with `factory` on the first\n * call. Later calls with the same key return the stored value without running `factory` again.\n */\n ensureItem<TValue>(key: string, factory: () => TValue): TValue\n}\n\n/**\n * Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate\n * walk.\n */\nexport function createNodeCache(): NodeCache {\n const store = new Map<string, unknown>()\n\n return {\n readItem<TValue>(key: string): TValue | undefined {\n return store.get(key) as TValue | undefined\n },\n writeItem<TValue>(key: string, value: TValue): TValue {\n store.set(key, value)\n return value\n },\n ensureItem<TValue>(key: string, factory: () => TValue): TValue {\n if (store.has(key)) return store.get(key) as TValue\n\n const value = factory()\n store.set(key, value)\n return value\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;CAC9D,OAAO,KACJ,KAAK,CAAC,CACN,QAAQ,qBAAqB,OAAO,CAAC,CACrC,QAAQ,yBAAyB,OAAO,CAAC,CACzC,QAAQ,gBAAgB,OAAO,CAAC,CAChC,MAAM,eAAe,CAAC,CACtB,OAAO,OAAO,CAAC,CACf,KAAK,MAAM,MAAM;EAChB,IAAI,KAAK,SAAS,KAAK,SAAS,KAAK,YAAY,GAAG,OAAO;EAE3D,QADa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,KAC9E,KAAK,MAAM,CAAC;CAC5B,CAAC,CAAC,CACD,KAAK,EAAE,CAAC,CACR,QAAQ,iBAAiB,EAAE;AAChC;;;;;;;;;;AAWA,SAAgB,UAAU,MAAc,EAAE,SAAS,IAAI,SAAS,OAAgB,CAAC,GAAW;CAC1F,OAAO,gBAAgB,GAAG,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ED,MAAM,KAAK,MAAM,SAAS,OAAO,KAAK;CACxC;AACF;;;;;;;ACzMA,SAAgB,kBAA6B;CAC3C,MAAM,wBAAQ,IAAI,IAAqB;CAEvC,OAAO;EACL,SAAiB,KAAiC;GAChD,OAAO,MAAM,IAAI,GAAG;EACtB;EACA,UAAkB,KAAa,OAAuB;GACpD,MAAM,IAAI,KAAK,KAAK;GACpB,OAAO;EACT;EACA,WAAmB,KAAa,SAA+B;GAC7D,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;GAExC,MAAM,QAAQ,QAAQ;GACtB,MAAM,IAAI,KAAK,KAAK;GACpB,OAAO;EACT;CACF;AACF"}
|
|
@@ -693,7 +693,7 @@ var FileManager = class {
|
|
|
693
693
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
694
694
|
* writes nothing and leaves every mtime where it was.
|
|
695
695
|
*/
|
|
696
|
-
async write(files, { storage, parsers, manifest }) {
|
|
696
|
+
async write(files, { storage, parsers, manifest, signal }) {
|
|
697
697
|
if (files.length === 0) return;
|
|
698
698
|
await this.hooks.callHook("start", files);
|
|
699
699
|
const total = files.length;
|
|
@@ -701,6 +701,7 @@ var FileManager = class {
|
|
|
701
701
|
items: files,
|
|
702
702
|
limit: 50,
|
|
703
703
|
run: async (file, index) => {
|
|
704
|
+
signal?.throwIfAborted();
|
|
704
705
|
const source = await this.parse(file, { parsers });
|
|
705
706
|
await this.hooks.callHook("update", {
|
|
706
707
|
file,
|
|
@@ -710,6 +711,7 @@ var FileManager = class {
|
|
|
710
711
|
percentage: (index + 1) / total * 100
|
|
711
712
|
});
|
|
712
713
|
if (!source) return;
|
|
714
|
+
signal?.throwIfAborted();
|
|
713
715
|
const stored = await storage.readItem(file.path);
|
|
714
716
|
if (isUnchanged({
|
|
715
717
|
stored,
|
|
@@ -717,6 +719,7 @@ var FileManager = class {
|
|
|
717
719
|
key: file.path,
|
|
718
720
|
manifest
|
|
719
721
|
})) return;
|
|
722
|
+
signal?.throwIfAborted();
|
|
720
723
|
await storage.writeItem(file.path, source, { stored });
|
|
721
724
|
manifest?.track({
|
|
722
725
|
key: file.path,
|
|
@@ -915,4 +918,4 @@ Object.defineProperty(exports, "write", {
|
|
|
915
918
|
}
|
|
916
919
|
});
|
|
917
920
|
|
|
918
|
-
//# sourceMappingURL=usingCtx-
|
|
921
|
+
//# sourceMappingURL=usingCtx-DOy3BJPz.cjs.map
|