@kubb/core 5.0.0-alpha.50 → 5.0.0-alpha.51
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/{PluginDriver-DtwggkXg.cjs → PluginDriver-6E8zd8MW.cjs} +25 -21
- package/dist/PluginDriver-6E8zd8MW.cjs.map +1 -0
- package/dist/{PluginDriver-mXeqWp-U.js → PluginDriver-D6wQFD4r.js} +25 -21
- package/dist/PluginDriver-D6wQFD4r.js.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +16 -11
- package/dist/index.js +2 -2
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.js +1 -1
- package/package.json +4 -4
- package/src/PluginDriver.ts +1 -1
- package/src/defineResolver.ts +41 -21
- package/dist/PluginDriver-DtwggkXg.cjs.map +0 -1
- package/dist/PluginDriver-mXeqWp-U.js.map +0 -1
|
@@ -317,26 +317,28 @@ function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root
|
|
|
317
317
|
*
|
|
318
318
|
* @example Resolve a schema file
|
|
319
319
|
* ```ts
|
|
320
|
-
* const file = defaultResolveFile
|
|
320
|
+
* const file = defaultResolveFile(
|
|
321
321
|
* { name: 'pet', extname: '.ts' },
|
|
322
322
|
* { root: '/src', output: { path: 'types' } },
|
|
323
|
+
* resolver,
|
|
323
324
|
* )
|
|
324
325
|
* // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
|
|
325
326
|
* ```
|
|
326
327
|
*
|
|
327
328
|
* @example Resolve an operation file with tag grouping
|
|
328
329
|
* ```ts
|
|
329
|
-
* const file = defaultResolveFile
|
|
330
|
+
* const file = defaultResolveFile(
|
|
330
331
|
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
331
332
|
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
333
|
+
* resolver,
|
|
332
334
|
* )
|
|
333
335
|
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
334
336
|
* ```
|
|
335
337
|
*/
|
|
336
|
-
function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
338
|
+
function defaultResolveFile({ name, extname, tag, path: groupPath }, context, ctx) {
|
|
337
339
|
const pathMode = PluginDriver.getMode(node_path.default.resolve(context.root, context.output.path));
|
|
338
|
-
const baseName = `${pathMode === "single" ? "" :
|
|
339
|
-
const filePath =
|
|
340
|
+
const baseName = `${pathMode === "single" ? "" : ctx.default(name, "file")}${extname}`;
|
|
341
|
+
const filePath = ctx.resolvePath({
|
|
340
342
|
baseName,
|
|
341
343
|
pathMode,
|
|
342
344
|
tag,
|
|
@@ -345,7 +347,7 @@ function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
|
345
347
|
return (0, _kubb_ast.createFile)({
|
|
346
348
|
path: filePath,
|
|
347
349
|
baseName: node_path.default.basename(filePath),
|
|
348
|
-
meta: { pluginName:
|
|
350
|
+
meta: { pluginName: ctx.pluginName },
|
|
349
351
|
sources: [],
|
|
350
352
|
imports: [],
|
|
351
353
|
exports: []
|
|
@@ -461,25 +463,25 @@ function defaultResolveFooter(node, { output }) {
|
|
|
461
463
|
* - `resolvePath` — output path computation
|
|
462
464
|
* - `resolveFile` — full `FileNode` construction
|
|
463
465
|
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
+
* The builder receives `ctx` — a reference to the assembled resolver — so methods can
|
|
467
|
+
* call sibling resolver methods using `ctx` instead of `this`.
|
|
466
468
|
*
|
|
467
469
|
* @example Basic resolver with naming helpers
|
|
468
470
|
* ```ts
|
|
469
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
471
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
470
472
|
* name: 'default',
|
|
471
473
|
* resolveName(node) {
|
|
472
|
-
* return
|
|
474
|
+
* return ctx.default(node.name, 'function')
|
|
473
475
|
* },
|
|
474
476
|
* resolveTypedName(node) {
|
|
475
|
-
* return
|
|
477
|
+
* return ctx.default(node.name, 'type')
|
|
476
478
|
* },
|
|
477
479
|
* }))
|
|
478
480
|
* ```
|
|
479
481
|
*
|
|
480
482
|
* @example Override resolvePath for a custom output structure
|
|
481
483
|
* ```ts
|
|
482
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
484
|
+
* export const resolver = defineResolver<PluginTs>((_ctx) => ({
|
|
483
485
|
* name: 'custom',
|
|
484
486
|
* resolvePath({ baseName }, { root, output }) {
|
|
485
487
|
* return path.resolve(root, output.path, 'generated', baseName)
|
|
@@ -487,26 +489,28 @@ function defaultResolveFooter(node, { output }) {
|
|
|
487
489
|
* }))
|
|
488
490
|
* ```
|
|
489
491
|
*
|
|
490
|
-
* @example Use
|
|
492
|
+
* @example Use ctx.default inside a helper
|
|
491
493
|
* ```ts
|
|
492
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
494
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
493
495
|
* name: 'default',
|
|
494
496
|
* resolveParamName(node, param) {
|
|
495
|
-
* return
|
|
497
|
+
* return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
496
498
|
* },
|
|
497
499
|
* }))
|
|
498
500
|
* ```
|
|
499
501
|
*/
|
|
500
502
|
function defineResolver(build) {
|
|
501
|
-
|
|
503
|
+
const resolver = {};
|
|
504
|
+
Object.assign(resolver, {
|
|
502
505
|
default: defaultResolver,
|
|
503
506
|
resolveOptions: defaultResolveOptions,
|
|
504
507
|
resolvePath: defaultResolvePath,
|
|
505
|
-
resolveFile: defaultResolveFile,
|
|
508
|
+
resolveFile: (params, context) => defaultResolveFile(params, context, resolver),
|
|
506
509
|
resolveBanner: defaultResolveBanner,
|
|
507
510
|
resolveFooter: defaultResolveFooter,
|
|
508
|
-
...build()
|
|
509
|
-
};
|
|
511
|
+
...build(resolver)
|
|
512
|
+
});
|
|
513
|
+
return resolver;
|
|
510
514
|
}
|
|
511
515
|
//#endregion
|
|
512
516
|
//#region src/devtools.ts
|
|
@@ -913,7 +917,7 @@ var PluginDriver = class PluginDriver {
|
|
|
913
917
|
#createDefaultResolver(pluginName) {
|
|
914
918
|
const existingResolver = this.#defaultResolvers.get(pluginName);
|
|
915
919
|
if (existingResolver) return existingResolver;
|
|
916
|
-
const resolver = defineResolver(() => ({
|
|
920
|
+
const resolver = defineResolver((_ctx) => ({
|
|
917
921
|
name: "default",
|
|
918
922
|
pluginName
|
|
919
923
|
}));
|
|
@@ -1079,4 +1083,4 @@ Object.defineProperty(exports, "logLevel", {
|
|
|
1079
1083
|
}
|
|
1080
1084
|
});
|
|
1081
1085
|
|
|
1082
|
-
//# sourceMappingURL=PluginDriver-
|
|
1086
|
+
//# sourceMappingURL=PluginDriver-6E8zd8MW.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginDriver-6E8zd8MW.cjs","names":["path","#cache","#filesCache","#pluginsWithEventGenerators","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#trackHookListener","#createDefaultResolver","#studioIsOpen","openInStudioFn"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/string.ts","../src/constants.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/renderNode.ts","../src/PluginDriver.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\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 const normalized = 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\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const\n\n/**\n * Default number of plugins that may run concurrently during a build.\n */\nexport const DEFAULT_CONCURRENCY = 15\n\n/**\n * Maximum number of files processed in parallel by FileProcessor.\n */\nexport const PARALLEL_CONCURRENCY_LIMIT = 100\n\n/**\n * Basename (without extension) of generated barrel files.\n *\n * Used to detect whether a path already points at a barrel so the generator\n * avoids re-creating one on top of it.\n */\nexport const BARREL_BASENAME = 'index' as const\n\n/**\n * File name used for generated barrel (index) files.\n */\nexport const BARREL_FILENAME = `${BARREL_BASENAME}.ts` as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Characters recognized as path separators on both POSIX and Windows.\n */\nexport const PATH_SEPARATORS = new Set(['/', '\\\\'] as const)\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport { PluginDriver } from './PluginDriver.ts'\nimport type {\n Config,\n PluginFactoryOptions,\n ResolveBannerContext,\n ResolveOptionsContext,\n Resolver,\n ResolverContext,\n ResolverFileParams,\n ResolverPathParams,\n} from './types.ts'\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n *\n * The builder receives `ctx` — a reference to the fully assembled resolver — so methods can\n * call sibling resolver methods without using `this`. Because `ctx` is captured by the closure\n * and the resolver is populated after the builder runs, `ctx` correctly reflects any overrides\n * that were applied by the builder itself.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = (ctx: T['resolver']) => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n }\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n switch (type) {\n case 'tag':\n return node.tags.some((tag) => testPattern(tag, pattern))\n case 'operationId':\n return testPattern(node.operationId, pattern)\n case 'path':\n return testPattern(node.path, pattern)\n case 'method':\n return testPattern(node.method.toLowerCase(), pattern)\n case 'contentType':\n return node.requestBody?.contentType ? testPattern(node.requestBody.contentType, pattern) : false\n default:\n return false\n }\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n switch (type) {\n case 'schemaName':\n return node.name ? testPattern(node.name, pattern) : false\n default:\n return null\n }\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n return resolvedName\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n if (isOperationNode(node)) {\n const isExcluded = exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))\n if (isExcluded) {\n return null\n }\n\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) {\n return null\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) {\n return null\n }\n\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n if (applicable.length > 0 && !applicable.includes(true)) {\n return null\n }\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? PluginDriver.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n let result: string\n\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n result = path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n } else {\n result = path.resolve(root, output.path, baseName)\n }\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile(\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * resolver,\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile(\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * resolver,\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile({ name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext, ctx: Resolver): FileNode {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : ctx.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = ctx.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: ctx.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the OAS spec when a `node` is provided).\n *\n * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.\n * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with node\n * ```ts\n * defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(inputNode, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → undefined\n * ```\n */\nexport function defaultResolveBanner(node: InputNode | undefined, { output, config }: ResolveBannerContext): string | undefined {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return undefined\n }\n\n return buildDefaultBanner({\n title: node?.meta?.title,\n version: node?.meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function and `node` is provided, calls it with the node.\n * - When `output.footer` is a function and `node` is absent, returns `undefined`.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with node\n * ```ts\n * defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(node: InputNode | undefined, { output }: ResolveBannerContext): string | undefined {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n}\n\n/**\n * Defines a resolver for a plugin, injecting built-in defaults for name casing,\n * include/exclude/override filtering, path resolution, and file construction.\n *\n * All four defaults can be overridden by providing them in the builder function:\n * - `default` — name casing strategy (camelCase / PascalCase)\n * - `resolveOptions` — include/exclude/override filtering\n * - `resolvePath` — output path computation\n * - `resolveFile` — full `FileNode` construction\n *\n * The builder receives `ctx` — a reference to the assembled resolver — so methods can\n * call sibling resolver methods using `ctx` instead of `this`.\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolver = defineResolver<PluginTs>((ctx) => ({\n * name: 'default',\n * resolveName(node) {\n * return ctx.default(node.name, 'function')\n * },\n * resolveTypedName(node) {\n * return ctx.default(node.name, 'type')\n * },\n * }))\n * ```\n *\n * @example Override resolvePath for a custom output structure\n * ```ts\n * export const resolver = defineResolver<PluginTs>((_ctx) => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n *\n * @example Use ctx.default inside a helper\n * ```ts\n * export const resolver = defineResolver<PluginTs>((ctx) => ({\n * name: 'default',\n * resolveParamName(node, param) {\n * return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n // Create the resolver shell first. When `build(resolver)` executes below, `resolver` is\n // still empty, but methods returned by the builder capture it by reference. By the time\n // those methods are actually called, `Object.assign` will have already populated all\n // properties (including any overrides from the builder itself).\n const resolver = {} as T['resolver']\n\n Object.assign(resolver, {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n // Wire the default resolveFile implementation with a wrapper that passes resolver as ctx.\n // Unlike other defaults which can be assigned directly, defaultResolveFile requires the\n // resolver as its third parameter.\n resolveFile: (params: ResolverFileParams, context: ResolverContext) => defaultResolveFile(params, context, resolver as Resolver),\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n // Builder overrides are applied last. Any method in the builder can call\n // ctx.xxx() and will see the fully merged resolver (including its own overrides).\n ...build(resolver),\n })\n\n return resolver\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\nimport type { DevtoolsOptions } from './types.ts'\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import { trimExtName } from '@internals/utils'\nimport type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { BARREL_BASENAME } from './constants.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\n/**\n * In-memory file store for generated files.\n *\n * Files with the same `path` are merged — sources, imports, and exports are concatenated.\n * The `files` getter returns all stored files sorted by path length (shortest first).\n *\n * @example\n * ```ts\n * import { FileManager } from '@kubb/core'\n *\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * console.log(manager.files) // all stored files\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n #filesCache: Array<FileNode> | null = null\n\n /**\n * Adds one or more files. Files with the same path are merged — sources, imports,\n * and exports from all calls with the same path are concatenated together.\n */\n add(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const resolvedFile = createFile(file)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n /**\n * Adds or merges one or more files.\n * If a file with the same path already exists, its sources/imports/exports are merged together.\n */\n upsert(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n /**\n * All stored files, sorted by path length (shorter paths first).\n * Barrel/index files (e.g. index.ts) are sorted last within each length bucket.\n */\n get files(): Array<FileNode> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n // Precompute the barrel-file flag per key so the comparator avoids repeated string work.\n const keys = [...this.#cache.keys()]\n const meta = new Map<string, { length: number; isIndex: boolean }>()\n for (const key of keys) {\n meta.set(key, {\n length: key.length,\n isIndex: trimExtName(key).endsWith(BARREL_BASENAME),\n })\n }\n keys.sort((a, b) => {\n const ma = meta.get(a)!\n const mb = meta.get(b)!\n if (ma.length !== mb.length) return ma.length - mb.length\n if (ma.isIndex !== mb.isIndex) return ma.isIndex ? 1 : -1\n return 0\n })\n\n const files: Array<FileNode> = []\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n return files\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport async function applyHookResult<TElement = unknown>(\n result: TElement | Array<FileNode> | void,\n driver: PluginDriver,\n rendererFactory?: RendererFactory<TElement>,\n): Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n await renderer.render(result)\n driver.fileManager.upsert(...renderer.files)\n renderer.unmount()\n}\n","import { extname, resolve } from 'node:path'\nimport type { AsyncEventEmitter } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport { applyHookResult } from './renderNode.ts'\n\nimport type {\n Adapter,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nexport class PluginDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * PluginDriver.getMode('src/gen/types.ts') // 'single'\n * PluginDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) {\n return 'split'\n }\n return extname(fileOrFolder) ? 'single' : 'split'\n }\n\n /**\n * The universal `@kubb/ast` `InputNode` produced by the adapter, set by\n * the build pipeline after the adapter's `parse()` resolves.\n */\n inputNode: InputNode | undefined = undefined\n adapter: Adapter | undefined = undefined\n #studioIsOpen = false\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #pluginsWithEventGenerators = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: never[]) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n config.plugins\n .map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n .filter((plugin) => {\n if (typeof plugin.apply === 'function') {\n return plugin.apply(config)\n }\n return true\n })\n .sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n return 0\n })\n .forEach((plugin) => {\n this.plugins.set(plugin.name, plugin)\n })\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(hookPlugin: Plugin): NormalizedPlugin {\n const normalizedPlugin = {\n name: hookPlugin.name,\n dependencies: hookPlugin.dependencies,\n options: { output: { path: '.' }, exclude: [], override: [] },\n } as unknown as NormalizedPlugin\n\n this.registerPluginHooks(hookPlugin, normalizedPlugin)\n return normalizedPlugin\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {\n const { hooks } = hookPlugin\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: hookPlugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(normalizedPlugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(normalizedPlugin.name, resolver)\n },\n setTransformer: (visitor) => {\n normalizedPlugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n normalizedPlugin.renderer = renderer\n },\n setOptions: (opts) => {\n normalizedPlugin.options = { ...normalizedPlugin.options, ...opts }\n },\n injectFile: ({ sources = [], ...rest }) => {\n this.fileManager.add(createFile({ imports: [], exports: [], sources, ...rest }))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: never[]) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: never[]) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: never[]) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: never[]) => void | Promise<void>)\n }\n\n this.#pluginsWithEventGenerators.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasRegisteredGenerators(pluginName: string): boolean {\n return this.#pluginsWithEventGenerators.has(pluginName)\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n this.#hookListeners.clear()\n this.#pluginsWithEventGenerators.clear()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: never[]) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #createDefaultResolver(pluginName: string): Resolver {\n const existingResolver = this.#defaultResolvers.get(pluginName)\n if (existingResolver) {\n return existingResolver\n }\n\n const resolver = defineResolver<PluginFactoryOptions>((_ctx) => ({\n name: 'default',\n pluginName,\n }))\n this.#defaultResolvers.set(pluginName, resolver)\n return resolver\n }\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#createDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#createDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n const baseContext = {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get inputNode(): InputNode | undefined {\n return driver.inputNode\n },\n get adapter(): Adapter | undefined {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', message)\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', typeof error === 'string' ? new Error(error) : error)\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', message)\n },\n openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studioIsOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.inputNode || !driver.adapter) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studioIsOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n\n return openInStudioFn(driver.inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n\n return baseContext\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,Q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AG,MAAM;;GAErC,IAAI,YAAmC;AACrC,WAAO,OAAO;;GAEhB,IAAI,UAA+B;AACjC,WAAO,OAAO;;GAEhB,IAAI,WAAW;AACb,WAAO,OAAO,YAAY,OAAO,KAAK;;GAExC,IAAI,cAAc;AAChB,WAAO,OAAO;;GAEhB,KAAK,SAAiB;AACpB,WAAO,MAAM,KAAK,aAAa,QAAQ;;GAEzC,MAAM,OAAuB;AAC3B,WAAO,MAAM,KAAK,cAAc,OAAO,UAAU,WAAW,IAAI,MAAM,MAAM,GAAG,MAAM;;GAEvF,KAAK,SAAiB;AACpB,WAAO,MAAM,KAAK,aAAa,QAAQ;;GAEzC,aAAa,SAA2B;AACtC,QAAI,CAAC,OAAO,OAAO,YAAY,QAAA,aAC7B;AAGF,QAAI,OAAO,OAAO,OAAO,aAAa,SACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,QAAI,CAAC,OAAO,aAAa,CAAC,OAAO,QAC/B,OAAM,IAAI,MAAM,8EAA8E;AAGhG,YAAA,eAAuB;IAEvB,MAAM,YAAY,OAAO,OAAO,UAAU,aAAA;AAE1C,WAAOW,aAAe,OAAO,WAAW,WAAW,QAAQ;;GAE9D;;CAOH,UAAU,YAAwC;AAChD,SAAO,KAAK,QAAQ,IAAI,WAAW;;CAQrC,cAAc,YAA4B;EACxC,MAAM,SAAS,KAAK,QAAQ,IAAI,WAAW;AAC3C,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,kBAAkB,WAAW,4EAA4E;AAE3H,SAAO"}
|
|
@@ -291,26 +291,28 @@ function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root
|
|
|
291
291
|
*
|
|
292
292
|
* @example Resolve a schema file
|
|
293
293
|
* ```ts
|
|
294
|
-
* const file = defaultResolveFile
|
|
294
|
+
* const file = defaultResolveFile(
|
|
295
295
|
* { name: 'pet', extname: '.ts' },
|
|
296
296
|
* { root: '/src', output: { path: 'types' } },
|
|
297
|
+
* resolver,
|
|
297
298
|
* )
|
|
298
299
|
* // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
|
|
299
300
|
* ```
|
|
300
301
|
*
|
|
301
302
|
* @example Resolve an operation file with tag grouping
|
|
302
303
|
* ```ts
|
|
303
|
-
* const file = defaultResolveFile
|
|
304
|
+
* const file = defaultResolveFile(
|
|
304
305
|
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
305
306
|
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
307
|
+
* resolver,
|
|
306
308
|
* )
|
|
307
309
|
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
308
310
|
* ```
|
|
309
311
|
*/
|
|
310
|
-
function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
312
|
+
function defaultResolveFile({ name, extname, tag, path: groupPath }, context, ctx) {
|
|
311
313
|
const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path));
|
|
312
|
-
const baseName = `${pathMode === "single" ? "" :
|
|
313
|
-
const filePath =
|
|
314
|
+
const baseName = `${pathMode === "single" ? "" : ctx.default(name, "file")}${extname}`;
|
|
315
|
+
const filePath = ctx.resolvePath({
|
|
314
316
|
baseName,
|
|
315
317
|
pathMode,
|
|
316
318
|
tag,
|
|
@@ -319,7 +321,7 @@ function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
|
319
321
|
return createFile({
|
|
320
322
|
path: filePath,
|
|
321
323
|
baseName: path.basename(filePath),
|
|
322
|
-
meta: { pluginName:
|
|
324
|
+
meta: { pluginName: ctx.pluginName },
|
|
323
325
|
sources: [],
|
|
324
326
|
imports: [],
|
|
325
327
|
exports: []
|
|
@@ -435,25 +437,25 @@ function defaultResolveFooter(node, { output }) {
|
|
|
435
437
|
* - `resolvePath` — output path computation
|
|
436
438
|
* - `resolveFile` — full `FileNode` construction
|
|
437
439
|
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
+
* The builder receives `ctx` — a reference to the assembled resolver — so methods can
|
|
441
|
+
* call sibling resolver methods using `ctx` instead of `this`.
|
|
440
442
|
*
|
|
441
443
|
* @example Basic resolver with naming helpers
|
|
442
444
|
* ```ts
|
|
443
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
445
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
444
446
|
* name: 'default',
|
|
445
447
|
* resolveName(node) {
|
|
446
|
-
* return
|
|
448
|
+
* return ctx.default(node.name, 'function')
|
|
447
449
|
* },
|
|
448
450
|
* resolveTypedName(node) {
|
|
449
|
-
* return
|
|
451
|
+
* return ctx.default(node.name, 'type')
|
|
450
452
|
* },
|
|
451
453
|
* }))
|
|
452
454
|
* ```
|
|
453
455
|
*
|
|
454
456
|
* @example Override resolvePath for a custom output structure
|
|
455
457
|
* ```ts
|
|
456
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
458
|
+
* export const resolver = defineResolver<PluginTs>((_ctx) => ({
|
|
457
459
|
* name: 'custom',
|
|
458
460
|
* resolvePath({ baseName }, { root, output }) {
|
|
459
461
|
* return path.resolve(root, output.path, 'generated', baseName)
|
|
@@ -461,26 +463,28 @@ function defaultResolveFooter(node, { output }) {
|
|
|
461
463
|
* }))
|
|
462
464
|
* ```
|
|
463
465
|
*
|
|
464
|
-
* @example Use
|
|
466
|
+
* @example Use ctx.default inside a helper
|
|
465
467
|
* ```ts
|
|
466
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
468
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
467
469
|
* name: 'default',
|
|
468
470
|
* resolveParamName(node, param) {
|
|
469
|
-
* return
|
|
471
|
+
* return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
470
472
|
* },
|
|
471
473
|
* }))
|
|
472
474
|
* ```
|
|
473
475
|
*/
|
|
474
476
|
function defineResolver(build) {
|
|
475
|
-
|
|
477
|
+
const resolver = {};
|
|
478
|
+
Object.assign(resolver, {
|
|
476
479
|
default: defaultResolver,
|
|
477
480
|
resolveOptions: defaultResolveOptions,
|
|
478
481
|
resolvePath: defaultResolvePath,
|
|
479
|
-
resolveFile: defaultResolveFile,
|
|
482
|
+
resolveFile: (params, context) => defaultResolveFile(params, context, resolver),
|
|
480
483
|
resolveBanner: defaultResolveBanner,
|
|
481
484
|
resolveFooter: defaultResolveFooter,
|
|
482
|
-
...build()
|
|
483
|
-
};
|
|
485
|
+
...build(resolver)
|
|
486
|
+
});
|
|
487
|
+
return resolver;
|
|
484
488
|
}
|
|
485
489
|
//#endregion
|
|
486
490
|
//#region src/devtools.ts
|
|
@@ -887,7 +891,7 @@ var PluginDriver = class PluginDriver {
|
|
|
887
891
|
#createDefaultResolver(pluginName) {
|
|
888
892
|
const existingResolver = this.#defaultResolvers.get(pluginName);
|
|
889
893
|
if (existingResolver) return existingResolver;
|
|
890
|
-
const resolver = defineResolver(() => ({
|
|
894
|
+
const resolver = defineResolver((_ctx) => ({
|
|
891
895
|
name: "default",
|
|
892
896
|
pluginName
|
|
893
897
|
}));
|
|
@@ -976,4 +980,4 @@ var PluginDriver = class PluginDriver {
|
|
|
976
980
|
//#endregion
|
|
977
981
|
export { BARREL_BASENAME as a, DEFAULT_EXTENSION as c, camelCase as d, defineResolver as i, DEFAULT_STUDIO_URL as l, applyHookResult as n, BARREL_FILENAME as o, FileManager as r, DEFAULT_BANNER as s, PluginDriver as t, logLevel as u };
|
|
978
982
|
|
|
979
|
-
//# sourceMappingURL=PluginDriver-
|
|
983
|
+
//# sourceMappingURL=PluginDriver-D6wQFD4r.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginDriver-D6wQFD4r.js","names":["#cache","#filesCache","#pluginsWithEventGenerators","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#trackHookListener","#createDefaultResolver","#studioIsOpen","openInStudioFn"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/string.ts","../src/constants.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/renderNode.ts","../src/PluginDriver.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\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 const normalized = 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\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const\n\n/**\n * Default number of plugins that may run concurrently during a build.\n */\nexport const DEFAULT_CONCURRENCY = 15\n\n/**\n * Maximum number of files processed in parallel by FileProcessor.\n */\nexport const PARALLEL_CONCURRENCY_LIMIT = 100\n\n/**\n * Basename (without extension) of generated barrel files.\n *\n * Used to detect whether a path already points at a barrel so the generator\n * avoids re-creating one on top of it.\n */\nexport const BARREL_BASENAME = 'index' as const\n\n/**\n * File name used for generated barrel (index) files.\n */\nexport const BARREL_FILENAME = `${BARREL_BASENAME}.ts` as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Characters recognized as path separators on both POSIX and Windows.\n */\nexport const PATH_SEPARATORS = new Set(['/', '\\\\'] as const)\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport { PluginDriver } from './PluginDriver.ts'\nimport type {\n Config,\n PluginFactoryOptions,\n ResolveBannerContext,\n ResolveOptionsContext,\n Resolver,\n ResolverContext,\n ResolverFileParams,\n ResolverPathParams,\n} from './types.ts'\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n *\n * The builder receives `ctx` — a reference to the fully assembled resolver — so methods can\n * call sibling resolver methods without using `this`. Because `ctx` is captured by the closure\n * and the resolver is populated after the builder runs, `ctx` correctly reflects any overrides\n * that were applied by the builder itself.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = (ctx: T['resolver']) => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n }\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n switch (type) {\n case 'tag':\n return node.tags.some((tag) => testPattern(tag, pattern))\n case 'operationId':\n return testPattern(node.operationId, pattern)\n case 'path':\n return testPattern(node.path, pattern)\n case 'method':\n return testPattern(node.method.toLowerCase(), pattern)\n case 'contentType':\n return node.requestBody?.contentType ? testPattern(node.requestBody.contentType, pattern) : false\n default:\n return false\n }\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n switch (type) {\n case 'schemaName':\n return node.name ? testPattern(node.name, pattern) : false\n default:\n return null\n }\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n return resolvedName\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n if (isOperationNode(node)) {\n const isExcluded = exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))\n if (isExcluded) {\n return null\n }\n\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) {\n return null\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) {\n return null\n }\n\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n if (applicable.length > 0 && !applicable.includes(true)) {\n return null\n }\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? PluginDriver.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n let result: string\n\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n result = path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n } else {\n result = path.resolve(root, output.path, baseName)\n }\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile(\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * resolver,\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile(\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * resolver,\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile({ name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext, ctx: Resolver): FileNode {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : ctx.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = ctx.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: ctx.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the OAS spec when a `node` is provided).\n *\n * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.\n * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with node\n * ```ts\n * defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(inputNode, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → undefined\n * ```\n */\nexport function defaultResolveBanner(node: InputNode | undefined, { output, config }: ResolveBannerContext): string | undefined {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return undefined\n }\n\n return buildDefaultBanner({\n title: node?.meta?.title,\n version: node?.meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function and `node` is provided, calls it with the node.\n * - When `output.footer` is a function and `node` is absent, returns `undefined`.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with node\n * ```ts\n * defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(node: InputNode | undefined, { output }: ResolveBannerContext): string | undefined {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n}\n\n/**\n * Defines a resolver for a plugin, injecting built-in defaults for name casing,\n * include/exclude/override filtering, path resolution, and file construction.\n *\n * All four defaults can be overridden by providing them in the builder function:\n * - `default` — name casing strategy (camelCase / PascalCase)\n * - `resolveOptions` — include/exclude/override filtering\n * - `resolvePath` — output path computation\n * - `resolveFile` — full `FileNode` construction\n *\n * The builder receives `ctx` — a reference to the assembled resolver — so methods can\n * call sibling resolver methods using `ctx` instead of `this`.\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolver = defineResolver<PluginTs>((ctx) => ({\n * name: 'default',\n * resolveName(node) {\n * return ctx.default(node.name, 'function')\n * },\n * resolveTypedName(node) {\n * return ctx.default(node.name, 'type')\n * },\n * }))\n * ```\n *\n * @example Override resolvePath for a custom output structure\n * ```ts\n * export const resolver = defineResolver<PluginTs>((_ctx) => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n *\n * @example Use ctx.default inside a helper\n * ```ts\n * export const resolver = defineResolver<PluginTs>((ctx) => ({\n * name: 'default',\n * resolveParamName(node, param) {\n * return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n // Create the resolver shell first. When `build(resolver)` executes below, `resolver` is\n // still empty, but methods returned by the builder capture it by reference. By the time\n // those methods are actually called, `Object.assign` will have already populated all\n // properties (including any overrides from the builder itself).\n const resolver = {} as T['resolver']\n\n Object.assign(resolver, {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n // Wire the default resolveFile implementation with a wrapper that passes resolver as ctx.\n // Unlike other defaults which can be assigned directly, defaultResolveFile requires the\n // resolver as its third parameter.\n resolveFile: (params: ResolverFileParams, context: ResolverContext) => defaultResolveFile(params, context, resolver as Resolver),\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n // Builder overrides are applied last. Any method in the builder can call\n // ctx.xxx() and will see the fully merged resolver (including its own overrides).\n ...build(resolver),\n })\n\n return resolver\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\nimport type { DevtoolsOptions } from './types.ts'\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import { trimExtName } from '@internals/utils'\nimport type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { BARREL_BASENAME } from './constants.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\n/**\n * In-memory file store for generated files.\n *\n * Files with the same `path` are merged — sources, imports, and exports are concatenated.\n * The `files` getter returns all stored files sorted by path length (shortest first).\n *\n * @example\n * ```ts\n * import { FileManager } from '@kubb/core'\n *\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * console.log(manager.files) // all stored files\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n #filesCache: Array<FileNode> | null = null\n\n /**\n * Adds one or more files. Files with the same path are merged — sources, imports,\n * and exports from all calls with the same path are concatenated together.\n */\n add(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const resolvedFile = createFile(file)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n /**\n * Adds or merges one or more files.\n * If a file with the same path already exists, its sources/imports/exports are merged together.\n */\n upsert(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n /**\n * All stored files, sorted by path length (shorter paths first).\n * Barrel/index files (e.g. index.ts) are sorted last within each length bucket.\n */\n get files(): Array<FileNode> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n // Precompute the barrel-file flag per key so the comparator avoids repeated string work.\n const keys = [...this.#cache.keys()]\n const meta = new Map<string, { length: number; isIndex: boolean }>()\n for (const key of keys) {\n meta.set(key, {\n length: key.length,\n isIndex: trimExtName(key).endsWith(BARREL_BASENAME),\n })\n }\n keys.sort((a, b) => {\n const ma = meta.get(a)!\n const mb = meta.get(b)!\n if (ma.length !== mb.length) return ma.length - mb.length\n if (ma.isIndex !== mb.isIndex) return ma.isIndex ? 1 : -1\n return 0\n })\n\n const files: Array<FileNode> = []\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n return files\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport async function applyHookResult<TElement = unknown>(\n result: TElement | Array<FileNode> | void,\n driver: PluginDriver,\n rendererFactory?: RendererFactory<TElement>,\n): Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n await renderer.render(result)\n driver.fileManager.upsert(...renderer.files)\n renderer.unmount()\n}\n","import { extname, resolve } from 'node:path'\nimport type { AsyncEventEmitter } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport { applyHookResult } from './renderNode.ts'\n\nimport type {\n Adapter,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nexport class PluginDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * PluginDriver.getMode('src/gen/types.ts') // 'single'\n * PluginDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) {\n return 'split'\n }\n return extname(fileOrFolder) ? 'single' : 'split'\n }\n\n /**\n * The universal `@kubb/ast` `InputNode` produced by the adapter, set by\n * the build pipeline after the adapter's `parse()` resolves.\n */\n inputNode: InputNode | undefined = undefined\n adapter: Adapter | undefined = undefined\n #studioIsOpen = false\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #pluginsWithEventGenerators = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: never[]) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n config.plugins\n .map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n .filter((plugin) => {\n if (typeof plugin.apply === 'function') {\n return plugin.apply(config)\n }\n return true\n })\n .sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n return 0\n })\n .forEach((plugin) => {\n this.plugins.set(plugin.name, plugin)\n })\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(hookPlugin: Plugin): NormalizedPlugin {\n const normalizedPlugin = {\n name: hookPlugin.name,\n dependencies: hookPlugin.dependencies,\n options: { output: { path: '.' }, exclude: [], override: [] },\n } as unknown as NormalizedPlugin\n\n this.registerPluginHooks(hookPlugin, normalizedPlugin)\n return normalizedPlugin\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {\n const { hooks } = hookPlugin\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: hookPlugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(normalizedPlugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(normalizedPlugin.name, resolver)\n },\n setTransformer: (visitor) => {\n normalizedPlugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n normalizedPlugin.renderer = renderer\n },\n setOptions: (opts) => {\n normalizedPlugin.options = { ...normalizedPlugin.options, ...opts }\n },\n injectFile: ({ sources = [], ...rest }) => {\n this.fileManager.add(createFile({ imports: [], exports: [], sources, ...rest }))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: never[]) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: never[]) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: never[]) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: never[]) => void | Promise<void>)\n }\n\n this.#pluginsWithEventGenerators.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasRegisteredGenerators(pluginName: string): boolean {\n return this.#pluginsWithEventGenerators.has(pluginName)\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n this.#hookListeners.clear()\n this.#pluginsWithEventGenerators.clear()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: never[]) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #createDefaultResolver(pluginName: string): Resolver {\n const existingResolver = this.#defaultResolvers.get(pluginName)\n if (existingResolver) {\n return existingResolver\n }\n\n const resolver = defineResolver<PluginFactoryOptions>((_ctx) => ({\n name: 'default',\n pluginName,\n }))\n this.#defaultResolvers.set(pluginName, resolver)\n return resolver\n }\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#createDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#createDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n const baseContext = {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get inputNode(): InputNode | undefined {\n return driver.inputNode\n },\n get adapter(): Adapter | undefined {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', message)\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', typeof error === 'string' ? new Error(error) : error)\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', message)\n },\n openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studioIsOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.inputNode || !driver.adapter) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studioIsOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n\n return openInStudioFn(driver.inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n\n return baseContext\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;;;;;;;AAiBjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;AAC1C,QAAO,MACJ,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAC7D,OAAO,QAAQ,CACf,KAAK,IAAI;;;;;;;;;;AAWd,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAA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Property(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_PluginDriver = require("./PluginDriver-
|
|
2
|
+
const require_PluginDriver = require("./PluginDriver-6E8zd8MW.cjs");
|
|
3
3
|
let node_events = require("node:events");
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
5
|
let node_path = require("node:path");
|
|
@@ -735,7 +735,7 @@ const fsStorage = createStorage(() => ({
|
|
|
735
735
|
}));
|
|
736
736
|
//#endregion
|
|
737
737
|
//#region package.json
|
|
738
|
-
var version = "5.0.0-alpha.
|
|
738
|
+
var version = "5.0.0-alpha.51";
|
|
739
739
|
//#endregion
|
|
740
740
|
//#region src/utils/diagnostics.ts
|
|
741
741
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -182,11 +182,16 @@ declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(log
|
|
|
182
182
|
*
|
|
183
183
|
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
184
184
|
* are optional — built-in fallbacks are injected when omitted.
|
|
185
|
+
*
|
|
186
|
+
* The builder receives `ctx` — a reference to the fully assembled resolver — so methods can
|
|
187
|
+
* call sibling resolver methods without using `this`. Because `ctx` is captured by the closure
|
|
188
|
+
* and the resolver is populated after the builder runs, `ctx` correctly reflects any overrides
|
|
189
|
+
* that were applied by the builder itself.
|
|
185
190
|
*/
|
|
186
|
-
type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
|
|
191
|
+
type ResolverBuilder<T extends PluginFactoryOptions> = (ctx: T['resolver']) => Omit<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
|
|
187
192
|
name: string;
|
|
188
193
|
pluginName: T['name'];
|
|
189
|
-
}
|
|
194
|
+
};
|
|
190
195
|
/**
|
|
191
196
|
* Default option resolver — applies include/exclude filters and merges matching override options.
|
|
192
197
|
*
|
|
@@ -220,25 +225,25 @@ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'],
|
|
|
220
225
|
* - `resolvePath` — output path computation
|
|
221
226
|
* - `resolveFile` — full `FileNode` construction
|
|
222
227
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
228
|
+
* The builder receives `ctx` — a reference to the assembled resolver — so methods can
|
|
229
|
+
* call sibling resolver methods using `ctx` instead of `this`.
|
|
225
230
|
*
|
|
226
231
|
* @example Basic resolver with naming helpers
|
|
227
232
|
* ```ts
|
|
228
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
233
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
229
234
|
* name: 'default',
|
|
230
235
|
* resolveName(node) {
|
|
231
|
-
* return
|
|
236
|
+
* return ctx.default(node.name, 'function')
|
|
232
237
|
* },
|
|
233
238
|
* resolveTypedName(node) {
|
|
234
|
-
* return
|
|
239
|
+
* return ctx.default(node.name, 'type')
|
|
235
240
|
* },
|
|
236
241
|
* }))
|
|
237
242
|
* ```
|
|
238
243
|
*
|
|
239
244
|
* @example Override resolvePath for a custom output structure
|
|
240
245
|
* ```ts
|
|
241
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
246
|
+
* export const resolver = defineResolver<PluginTs>((_ctx) => ({
|
|
242
247
|
* name: 'custom',
|
|
243
248
|
* resolvePath({ baseName }, { root, output }) {
|
|
244
249
|
* return path.resolve(root, output.path, 'generated', baseName)
|
|
@@ -246,12 +251,12 @@ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'],
|
|
|
246
251
|
* }))
|
|
247
252
|
* ```
|
|
248
253
|
*
|
|
249
|
-
* @example Use
|
|
254
|
+
* @example Use ctx.default inside a helper
|
|
250
255
|
* ```ts
|
|
251
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
256
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
252
257
|
* name: 'default',
|
|
253
258
|
* resolveParamName(node, param) {
|
|
254
|
-
* return
|
|
259
|
+
* return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
255
260
|
* },
|
|
256
261
|
* }))
|
|
257
262
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { c as DEFAULT_EXTENSION, d as camelCase, i as defineResolver, l as DEFAULT_STUDIO_URL, n as applyHookResult, o as BARREL_FILENAME, r as FileManager, s as DEFAULT_BANNER, t as PluginDriver, u as logLevel } from "./PluginDriver-
|
|
2
|
+
import { c as DEFAULT_EXTENSION, d as camelCase, i as defineResolver, l as DEFAULT_STUDIO_URL, n as applyHookResult, o as BARREL_FILENAME, r as FileManager, s as DEFAULT_BANNER, t as PluginDriver, u as logLevel } from "./PluginDriver-D6wQFD4r.js";
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import path, { dirname, join, posix, resolve } from "node:path";
|
|
@@ -737,7 +737,7 @@ const fsStorage = createStorage(() => ({
|
|
|
737
737
|
}));
|
|
738
738
|
//#endregion
|
|
739
739
|
//#region package.json
|
|
740
|
-
var version$1 = "5.0.0-alpha.
|
|
740
|
+
var version$1 = "5.0.0-alpha.51";
|
|
741
741
|
//#endregion
|
|
742
742
|
//#region src/utils/diagnostics.ts
|
|
743
743
|
/**
|
package/dist/mocks.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_PluginDriver = require("./PluginDriver-
|
|
2
|
+
const require_PluginDriver = require("./PluginDriver-6E8zd8MW.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
let _kubb_ast = require("@kubb/ast");
|
|
5
5
|
//#region src/mocks.ts
|
package/dist/mocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as applyHookResult, r as FileManager, t as PluginDriver } from "./PluginDriver-
|
|
2
|
+
import { n as applyHookResult, r as FileManager, t as PluginDriver } from "./PluginDriver-D6wQFD4r.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { transform } from "@kubb/ast";
|
|
5
5
|
//#region src/mocks.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.51",
|
|
4
4
|
"description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -65,15 +65,15 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"fflate": "^0.8.2",
|
|
67
67
|
"tinyexec": "^1.1.1",
|
|
68
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
68
|
+
"@kubb/ast": "5.0.0-alpha.51"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"p-limit": "^7.3.0",
|
|
72
72
|
"@internals/utils": "0.0.0",
|
|
73
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
73
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.51"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
76
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.51"
|
|
77
77
|
},
|
|
78
78
|
"size-limit": [
|
|
79
79
|
{
|
package/src/PluginDriver.ts
CHANGED
package/src/defineResolver.ts
CHANGED
|
@@ -19,15 +19,20 @@ import type {
|
|
|
19
19
|
*
|
|
20
20
|
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
21
21
|
* are optional — built-in fallbacks are injected when omitted.
|
|
22
|
+
*
|
|
23
|
+
* The builder receives `ctx` — a reference to the fully assembled resolver — so methods can
|
|
24
|
+
* call sibling resolver methods without using `this`. Because `ctx` is captured by the closure
|
|
25
|
+
* and the resolver is populated after the builder runs, `ctx` correctly reflects any overrides
|
|
26
|
+
* that were applied by the builder itself.
|
|
22
27
|
*/
|
|
23
|
-
type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<
|
|
28
|
+
type ResolverBuilder<T extends PluginFactoryOptions> = (ctx: T['resolver']) => Omit<
|
|
24
29
|
T['resolver'],
|
|
25
30
|
'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'
|
|
26
31
|
> &
|
|
27
32
|
Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
|
|
28
33
|
name: string
|
|
29
34
|
pluginName: T['name']
|
|
30
|
-
}
|
|
35
|
+
}
|
|
31
36
|
|
|
32
37
|
// String patterns are compiled lazily and cached — the same filter is reused for every node.
|
|
33
38
|
const stringPatternCache = new Map<string, RegExp>()
|
|
@@ -263,33 +268,35 @@ export function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }:
|
|
|
263
268
|
*
|
|
264
269
|
* @example Resolve a schema file
|
|
265
270
|
* ```ts
|
|
266
|
-
* const file = defaultResolveFile
|
|
271
|
+
* const file = defaultResolveFile(
|
|
267
272
|
* { name: 'pet', extname: '.ts' },
|
|
268
273
|
* { root: '/src', output: { path: 'types' } },
|
|
274
|
+
* resolver,
|
|
269
275
|
* )
|
|
270
276
|
* // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
|
|
271
277
|
* ```
|
|
272
278
|
*
|
|
273
279
|
* @example Resolve an operation file with tag grouping
|
|
274
280
|
* ```ts
|
|
275
|
-
* const file = defaultResolveFile
|
|
281
|
+
* const file = defaultResolveFile(
|
|
276
282
|
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
277
283
|
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
284
|
+
* resolver,
|
|
278
285
|
* )
|
|
279
286
|
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
280
287
|
* ```
|
|
281
288
|
*/
|
|
282
|
-
export function defaultResolveFile(
|
|
289
|
+
export function defaultResolveFile({ name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext, ctx: Resolver): FileNode {
|
|
283
290
|
const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))
|
|
284
|
-
const resolvedName = pathMode === 'single' ? '' :
|
|
291
|
+
const resolvedName = pathMode === 'single' ? '' : ctx.default(name, 'file')
|
|
285
292
|
const baseName = `${resolvedName}${extname}` as FileNode['baseName']
|
|
286
|
-
const filePath =
|
|
293
|
+
const filePath = ctx.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)
|
|
287
294
|
|
|
288
295
|
return createFile({
|
|
289
296
|
path: filePath,
|
|
290
297
|
baseName: path.basename(filePath) as `${string}.${string}`,
|
|
291
298
|
meta: {
|
|
292
|
-
pluginName:
|
|
299
|
+
pluginName: ctx.pluginName,
|
|
293
300
|
},
|
|
294
301
|
sources: [],
|
|
295
302
|
imports: [],
|
|
@@ -452,25 +459,25 @@ export function defaultResolveFooter(node: InputNode | undefined, { output }: Re
|
|
|
452
459
|
* - `resolvePath` — output path computation
|
|
453
460
|
* - `resolveFile` — full `FileNode` construction
|
|
454
461
|
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
462
|
+
* The builder receives `ctx` — a reference to the assembled resolver — so methods can
|
|
463
|
+
* call sibling resolver methods using `ctx` instead of `this`.
|
|
457
464
|
*
|
|
458
465
|
* @example Basic resolver with naming helpers
|
|
459
466
|
* ```ts
|
|
460
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
467
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
461
468
|
* name: 'default',
|
|
462
469
|
* resolveName(node) {
|
|
463
|
-
* return
|
|
470
|
+
* return ctx.default(node.name, 'function')
|
|
464
471
|
* },
|
|
465
472
|
* resolveTypedName(node) {
|
|
466
|
-
* return
|
|
473
|
+
* return ctx.default(node.name, 'type')
|
|
467
474
|
* },
|
|
468
475
|
* }))
|
|
469
476
|
* ```
|
|
470
477
|
*
|
|
471
478
|
* @example Override resolvePath for a custom output structure
|
|
472
479
|
* ```ts
|
|
473
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
480
|
+
* export const resolver = defineResolver<PluginTs>((_ctx) => ({
|
|
474
481
|
* name: 'custom',
|
|
475
482
|
* resolvePath({ baseName }, { root, output }) {
|
|
476
483
|
* return path.resolve(root, output.path, 'generated', baseName)
|
|
@@ -478,24 +485,37 @@ export function defaultResolveFooter(node: InputNode | undefined, { output }: Re
|
|
|
478
485
|
* }))
|
|
479
486
|
* ```
|
|
480
487
|
*
|
|
481
|
-
* @example Use
|
|
488
|
+
* @example Use ctx.default inside a helper
|
|
482
489
|
* ```ts
|
|
483
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
490
|
+
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
484
491
|
* name: 'default',
|
|
485
492
|
* resolveParamName(node, param) {
|
|
486
|
-
* return
|
|
493
|
+
* return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
487
494
|
* },
|
|
488
495
|
* }))
|
|
489
496
|
* ```
|
|
490
497
|
*/
|
|
491
498
|
export function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {
|
|
492
|
-
|
|
499
|
+
// Create the resolver shell first. When `build(resolver)` executes below, `resolver` is
|
|
500
|
+
// still empty, but methods returned by the builder capture it by reference. By the time
|
|
501
|
+
// those methods are actually called, `Object.assign` will have already populated all
|
|
502
|
+
// properties (including any overrides from the builder itself).
|
|
503
|
+
const resolver = {} as T['resolver']
|
|
504
|
+
|
|
505
|
+
Object.assign(resolver, {
|
|
493
506
|
default: defaultResolver,
|
|
494
507
|
resolveOptions: defaultResolveOptions,
|
|
495
508
|
resolvePath: defaultResolvePath,
|
|
496
|
-
resolveFile
|
|
509
|
+
// Wire the default resolveFile implementation with a wrapper that passes resolver as ctx.
|
|
510
|
+
// Unlike other defaults which can be assigned directly, defaultResolveFile requires the
|
|
511
|
+
// resolver as its third parameter.
|
|
512
|
+
resolveFile: (params: ResolverFileParams, context: ResolverContext) => defaultResolveFile(params, context, resolver as Resolver),
|
|
497
513
|
resolveBanner: defaultResolveBanner,
|
|
498
514
|
resolveFooter: defaultResolveFooter,
|
|
499
|
-
|
|
500
|
-
|
|
515
|
+
// Builder overrides are applied last. Any method in the builder can call
|
|
516
|
+
// ctx.xxx() and will see the fully merged resolver (including its own overrides).
|
|
517
|
+
...build(resolver),
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
return resolver
|
|
501
521
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginDriver-DtwggkXg.cjs","names":["path","#cache","#filesCache","#pluginsWithEventGenerators","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#trackHookListener","#createDefaultResolver","#studioIsOpen","openInStudioFn"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/string.ts","../src/constants.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/renderNode.ts","../src/PluginDriver.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\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 const normalized = 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\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const\n\n/**\n * Default number of plugins that may run concurrently during a build.\n */\nexport const DEFAULT_CONCURRENCY = 15\n\n/**\n * Maximum number of files processed in parallel by FileProcessor.\n */\nexport const PARALLEL_CONCURRENCY_LIMIT = 100\n\n/**\n * Basename (without extension) of generated barrel files.\n *\n * Used to detect whether a path already points at a barrel so the generator\n * avoids re-creating one on top of it.\n */\nexport const BARREL_BASENAME = 'index' as const\n\n/**\n * File name used for generated barrel (index) files.\n */\nexport const BARREL_FILENAME = `${BARREL_BASENAME}.ts` as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Characters recognized as path separators on both POSIX and Windows.\n */\nexport const PATH_SEPARATORS = new Set(['/', '\\\\'] as const)\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport { PluginDriver } from './PluginDriver.ts'\nimport type {\n Config,\n PluginFactoryOptions,\n ResolveBannerContext,\n ResolveOptionsContext,\n Resolver,\n ResolverContext,\n ResolverFileParams,\n ResolverPathParams,\n} from './types.ts'\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n } & ThisType<T['resolver']>\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n switch (type) {\n case 'tag':\n return node.tags.some((tag) => testPattern(tag, pattern))\n case 'operationId':\n return testPattern(node.operationId, pattern)\n case 'path':\n return testPattern(node.path, pattern)\n case 'method':\n return testPattern(node.method.toLowerCase(), pattern)\n case 'contentType':\n return node.requestBody?.contentType ? testPattern(node.requestBody.contentType, pattern) : false\n default:\n return false\n }\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n switch (type) {\n case 'schemaName':\n return node.name ? testPattern(node.name, pattern) : false\n default:\n return null\n }\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n return resolvedName\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n if (isOperationNode(node)) {\n const isExcluded = exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))\n if (isExcluded) {\n return null\n }\n\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) {\n return null\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) {\n return null\n }\n\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n if (applicable.length > 0 && !applicable.includes(true)) {\n return null\n }\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? PluginDriver.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n let result: string\n\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n result = path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n } else {\n result = path.resolve(root, output.path, baseName)\n }\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile.call(resolver,\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile.call(resolver,\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile(this: Resolver, { name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext): FileNode {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : this.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = this.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: this.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the OAS spec when a `node` is provided).\n *\n * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.\n * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with node\n * ```ts\n * defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(inputNode, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → undefined\n * ```\n */\nexport function defaultResolveBanner(node: InputNode | undefined, { output, config }: ResolveBannerContext): string | undefined {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return undefined\n }\n\n return buildDefaultBanner({\n title: node?.meta?.title,\n version: node?.meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function and `node` is provided, calls it with the node.\n * - When `output.footer` is a function and `node` is absent, returns `undefined`.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with node\n * ```ts\n * defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(node: InputNode | undefined, { output }: ResolveBannerContext): string | undefined {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n}\n\n/**\n * Defines a resolver for a plugin, injecting built-in defaults for name casing,\n * include/exclude/override filtering, path resolution, and file construction.\n *\n * All four defaults can be overridden by providing them in the builder function:\n * - `default` — name casing strategy (camelCase / PascalCase)\n * - `resolveOptions` — include/exclude/override filtering\n * - `resolvePath` — output path computation\n * - `resolveFile` — full `FileNode` construction\n *\n * Methods in the builder have access to `this` (the full resolver object), so they\n * can call other resolver methods without circular imports.\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveName(node) {\n * return this.default(node.name, 'function')\n * },\n * resolveTypedName(node) {\n * return this.default(node.name, 'type')\n * },\n * }))\n * ```\n *\n * @example Override resolvePath for a custom output structure\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n *\n * @example Use this.default inside a helper\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveParamName(node, param) {\n * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n return {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n resolveFile: defaultResolveFile,\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n ...build(),\n } as T['resolver']\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\nimport type { DevtoolsOptions } from './types.ts'\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import { trimExtName } from '@internals/utils'\nimport type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { BARREL_BASENAME } from './constants.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\n/**\n * In-memory file store for generated files.\n *\n * Files with the same `path` are merged — sources, imports, and exports are concatenated.\n * The `files` getter returns all stored files sorted by path length (shortest first).\n *\n * @example\n * ```ts\n * import { FileManager } from '@kubb/core'\n *\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * console.log(manager.files) // all stored files\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n #filesCache: Array<FileNode> | null = null\n\n /**\n * Adds one or more files. Files with the same path are merged — sources, imports,\n * and exports from all calls with the same path are concatenated together.\n */\n add(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const resolvedFile = createFile(file)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n /**\n * Adds or merges one or more files.\n * If a file with the same path already exists, its sources/imports/exports are merged together.\n */\n upsert(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n /**\n * All stored files, sorted by path length (shorter paths first).\n * Barrel/index files (e.g. index.ts) are sorted last within each length bucket.\n */\n get files(): Array<FileNode> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n // Precompute the barrel-file flag per key so the comparator avoids repeated string work.\n const keys = [...this.#cache.keys()]\n const meta = new Map<string, { length: number; isIndex: boolean }>()\n for (const key of keys) {\n meta.set(key, {\n length: key.length,\n isIndex: trimExtName(key).endsWith(BARREL_BASENAME),\n })\n }\n keys.sort((a, b) => {\n const ma = meta.get(a)!\n const mb = meta.get(b)!\n if (ma.length !== mb.length) return ma.length - mb.length\n if (ma.isIndex !== mb.isIndex) return ma.isIndex ? 1 : -1\n return 0\n })\n\n const files: Array<FileNode> = []\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n return files\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport async function applyHookResult<TElement = unknown>(\n result: TElement | Array<FileNode> | void,\n driver: PluginDriver,\n rendererFactory?: RendererFactory<TElement>,\n): Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n await renderer.render(result)\n driver.fileManager.upsert(...renderer.files)\n renderer.unmount()\n}\n","import { extname, resolve } from 'node:path'\nimport type { AsyncEventEmitter } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport { applyHookResult } from './renderNode.ts'\n\nimport type {\n Adapter,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nexport class PluginDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * PluginDriver.getMode('src/gen/types.ts') // 'single'\n * PluginDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) {\n return 'split'\n }\n return extname(fileOrFolder) ? 'single' : 'split'\n }\n\n /**\n * The universal `@kubb/ast` `InputNode` produced by the adapter, set by\n * the build pipeline after the adapter's `parse()` resolves.\n */\n inputNode: InputNode | undefined = undefined\n adapter: Adapter | undefined = undefined\n #studioIsOpen = false\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #pluginsWithEventGenerators = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: never[]) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n config.plugins\n .map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n .filter((plugin) => {\n if (typeof plugin.apply === 'function') {\n return plugin.apply(config)\n }\n return true\n })\n .sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n return 0\n })\n .forEach((plugin) => {\n this.plugins.set(plugin.name, plugin)\n })\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(hookPlugin: Plugin): NormalizedPlugin {\n const normalizedPlugin = {\n name: hookPlugin.name,\n dependencies: hookPlugin.dependencies,\n options: { output: { path: '.' }, exclude: [], override: [] },\n } as unknown as NormalizedPlugin\n\n this.registerPluginHooks(hookPlugin, normalizedPlugin)\n return normalizedPlugin\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {\n const { hooks } = hookPlugin\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: hookPlugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(normalizedPlugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(normalizedPlugin.name, resolver)\n },\n setTransformer: (visitor) => {\n normalizedPlugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n normalizedPlugin.renderer = renderer\n },\n setOptions: (opts) => {\n normalizedPlugin.options = { ...normalizedPlugin.options, ...opts }\n },\n injectFile: ({ sources = [], ...rest }) => {\n this.fileManager.add(createFile({ imports: [], exports: [], sources, ...rest }))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: never[]) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: never[]) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: never[]) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: never[]) => void | Promise<void>)\n }\n\n this.#pluginsWithEventGenerators.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasRegisteredGenerators(pluginName: string): boolean {\n return this.#pluginsWithEventGenerators.has(pluginName)\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n this.#hookListeners.clear()\n this.#pluginsWithEventGenerators.clear()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: never[]) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #createDefaultResolver(pluginName: string): Resolver {\n const existingResolver = this.#defaultResolvers.get(pluginName)\n if (existingResolver) {\n return existingResolver\n }\n\n const resolver = defineResolver<PluginFactoryOptions>(() => ({\n name: 'default',\n pluginName,\n }))\n this.#defaultResolvers.set(pluginName, resolver)\n return resolver\n }\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#createDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#createDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n const baseContext = {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get inputNode(): InputNode | undefined {\n return driver.inputNode\n },\n get adapter(): Adapter | undefined {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', message)\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', typeof error === 'string' ? new Error(error) : error)\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', message)\n },\n openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studioIsOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.inputNode || !driver.adapter) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studioIsOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n\n return openInStudioFn(driver.inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n\n return baseContext\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SA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AM,MAAM,GAAG,MAAM;;GAEvF,KAAK,SAAiB;AACpB,WAAO,MAAM,KAAK,aAAa,QAAQ;;GAEzC,aAAa,SAA2B;AACtC,QAAI,CAAC,OAAO,OAAO,YAAY,QAAA,aAC7B;AAGF,QAAI,OAAO,OAAO,OAAO,aAAa,SACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,QAAI,CAAC,OAAO,aAAa,CAAC,OAAO,QAC/B,OAAM,IAAI,MAAM,8EAA8E;AAGhG,YAAA,eAAuB;IAEvB,MAAM,YAAY,OAAO,OAAO,UAAU,aAAA;AAE1C,WAAOW,aAAe,OAAO,WAAW,WAAW,QAAQ;;GAE9D;;CAOH,UAAU,YAAwC;AAChD,SAAO,KAAK,QAAQ,IAAI,WAAW;;CAQrC,cAAc,YAA4B;EACxC,MAAM,SAAS,KAAK,QAAQ,IAAI,WAAW;AAC3C,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,kBAAkB,WAAW,4EAA4E;AAE3H,SAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginDriver-mXeqWp-U.js","names":["#cache","#filesCache","#pluginsWithEventGenerators","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#trackHookListener","#createDefaultResolver","#studioIsOpen","openInStudioFn"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/string.ts","../src/constants.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/renderNode.ts","../src/PluginDriver.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\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 const normalized = 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\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const\n\n/**\n * Default number of plugins that may run concurrently during a build.\n */\nexport const DEFAULT_CONCURRENCY = 15\n\n/**\n * Maximum number of files processed in parallel by FileProcessor.\n */\nexport const PARALLEL_CONCURRENCY_LIMIT = 100\n\n/**\n * Basename (without extension) of generated barrel files.\n *\n * Used to detect whether a path already points at a barrel so the generator\n * avoids re-creating one on top of it.\n */\nexport const BARREL_BASENAME = 'index' as const\n\n/**\n * File name used for generated barrel (index) files.\n */\nexport const BARREL_FILENAME = `${BARREL_BASENAME}.ts` as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Characters recognized as path separators on both POSIX and Windows.\n */\nexport const PATH_SEPARATORS = new Set(['/', '\\\\'] as const)\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport { PluginDriver } from './PluginDriver.ts'\nimport type {\n Config,\n PluginFactoryOptions,\n ResolveBannerContext,\n ResolveOptionsContext,\n Resolver,\n ResolverContext,\n ResolverFileParams,\n ResolverPathParams,\n} from './types.ts'\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n } & ThisType<T['resolver']>\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n switch (type) {\n case 'tag':\n return node.tags.some((tag) => testPattern(tag, pattern))\n case 'operationId':\n return testPattern(node.operationId, pattern)\n case 'path':\n return testPattern(node.path, pattern)\n case 'method':\n return testPattern(node.method.toLowerCase(), pattern)\n case 'contentType':\n return node.requestBody?.contentType ? testPattern(node.requestBody.contentType, pattern) : false\n default:\n return false\n }\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n switch (type) {\n case 'schemaName':\n return node.name ? testPattern(node.name, pattern) : false\n default:\n return null\n }\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n return resolvedName\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n if (isOperationNode(node)) {\n const isExcluded = exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))\n if (isExcluded) {\n return null\n }\n\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) {\n return null\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) {\n return null\n }\n\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n if (applicable.length > 0 && !applicable.includes(true)) {\n return null\n }\n }\n\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? PluginDriver.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n let result: string\n\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n result = path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n } else {\n result = path.resolve(root, output.path, baseName)\n }\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile.call(resolver,\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile.call(resolver,\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile(this: Resolver, { name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext): FileNode {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : this.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = this.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: this.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the OAS spec when a `node` is provided).\n *\n * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.\n * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with node\n * ```ts\n * defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(inputNode, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → undefined\n * ```\n */\nexport function defaultResolveBanner(node: InputNode | undefined, { output, config }: ResolveBannerContext): string | undefined {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return undefined\n }\n\n return buildDefaultBanner({\n title: node?.meta?.title,\n version: node?.meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function and `node` is provided, calls it with the node.\n * - When `output.footer` is a function and `node` is absent, returns `undefined`.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with node\n * ```ts\n * defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(node: InputNode | undefined, { output }: ResolveBannerContext): string | undefined {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n}\n\n/**\n * Defines a resolver for a plugin, injecting built-in defaults for name casing,\n * include/exclude/override filtering, path resolution, and file construction.\n *\n * All four defaults can be overridden by providing them in the builder function:\n * - `default` — name casing strategy (camelCase / PascalCase)\n * - `resolveOptions` — include/exclude/override filtering\n * - `resolvePath` — output path computation\n * - `resolveFile` — full `FileNode` construction\n *\n * Methods in the builder have access to `this` (the full resolver object), so they\n * can call other resolver methods without circular imports.\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveName(node) {\n * return this.default(node.name, 'function')\n * },\n * resolveTypedName(node) {\n * return this.default(node.name, 'type')\n * },\n * }))\n * ```\n *\n * @example Override resolvePath for a custom output structure\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n *\n * @example Use this.default inside a helper\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveParamName(node, param) {\n * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n return {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n resolveFile: defaultResolveFile,\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n ...build(),\n } as T['resolver']\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\nimport type { DevtoolsOptions } from './types.ts'\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import { trimExtName } from '@internals/utils'\nimport type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { BARREL_BASENAME } from './constants.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\n/**\n * In-memory file store for generated files.\n *\n * Files with the same `path` are merged — sources, imports, and exports are concatenated.\n * The `files` getter returns all stored files sorted by path length (shortest first).\n *\n * @example\n * ```ts\n * import { FileManager } from '@kubb/core'\n *\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * console.log(manager.files) // all stored files\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n #filesCache: Array<FileNode> | null = null\n\n /**\n * Adds one or more files. Files with the same path are merged — sources, imports,\n * and exports from all calls with the same path are concatenated together.\n */\n add(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const resolvedFile = createFile(file)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n /**\n * Adds or merges one or more files.\n * If a file with the same path already exists, its sources/imports/exports are merged together.\n */\n upsert(...files: Array<FileNode>): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n const mergedFiles = new Map<string, FileNode>()\n\n for (const file of files) {\n const existing = mergedFiles.get(file.path)\n mergedFiles.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n\n return resolvedFiles\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n /**\n * All stored files, sorted by path length (shorter paths first).\n * Barrel/index files (e.g. index.ts) are sorted last within each length bucket.\n */\n get files(): Array<FileNode> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n // Precompute the barrel-file flag per key so the comparator avoids repeated string work.\n const keys = [...this.#cache.keys()]\n const meta = new Map<string, { length: number; isIndex: boolean }>()\n for (const key of keys) {\n meta.set(key, {\n length: key.length,\n isIndex: trimExtName(key).endsWith(BARREL_BASENAME),\n })\n }\n keys.sort((a, b) => {\n const ma = meta.get(a)!\n const mb = meta.get(b)!\n if (ma.length !== mb.length) return ma.length - mb.length\n if (ma.isIndex !== mb.isIndex) return ma.isIndex ? 1 : -1\n return 0\n })\n\n const files: Array<FileNode> = []\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n return files\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport async function applyHookResult<TElement = unknown>(\n result: TElement | Array<FileNode> | void,\n driver: PluginDriver,\n rendererFactory?: RendererFactory<TElement>,\n): Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n await renderer.render(result)\n driver.fileManager.upsert(...renderer.files)\n renderer.unmount()\n}\n","import { extname, resolve } from 'node:path'\nimport type { AsyncEventEmitter } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport { applyHookResult } from './renderNode.ts'\n\nimport type {\n Adapter,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nexport class PluginDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * PluginDriver.getMode('src/gen/types.ts') // 'single'\n * PluginDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) {\n return 'split'\n }\n return extname(fileOrFolder) ? 'single' : 'split'\n }\n\n /**\n * The universal `@kubb/ast` `InputNode` produced by the adapter, set by\n * the build pipeline after the adapter's `parse()` resolves.\n */\n inputNode: InputNode | undefined = undefined\n adapter: Adapter | undefined = undefined\n #studioIsOpen = false\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #pluginsWithEventGenerators = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: never[]) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n config.plugins\n .map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n .filter((plugin) => {\n if (typeof plugin.apply === 'function') {\n return plugin.apply(config)\n }\n return true\n })\n .sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n return 0\n })\n .forEach((plugin) => {\n this.plugins.set(plugin.name, plugin)\n })\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(hookPlugin: Plugin): NormalizedPlugin {\n const normalizedPlugin = {\n name: hookPlugin.name,\n dependencies: hookPlugin.dependencies,\n options: { output: { path: '.' }, exclude: [], override: [] },\n } as unknown as NormalizedPlugin\n\n this.registerPluginHooks(hookPlugin, normalizedPlugin)\n return normalizedPlugin\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {\n const { hooks } = hookPlugin\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: hookPlugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(normalizedPlugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(normalizedPlugin.name, resolver)\n },\n setTransformer: (visitor) => {\n normalizedPlugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n normalizedPlugin.renderer = renderer\n },\n setOptions: (opts) => {\n normalizedPlugin.options = { ...normalizedPlugin.options, ...opts }\n },\n injectFile: ({ sources = [], ...rest }) => {\n this.fileManager.add(createFile({ imports: [], exports: [], sources, ...rest }))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: never[]) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: never[]) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: never[]) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult(result, this, resolveRenderer())\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: never[]) => void | Promise<void>)\n }\n\n this.#pluginsWithEventGenerators.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasRegisteredGenerators(pluginName: string): boolean {\n return this.#pluginsWithEventGenerators.has(pluginName)\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n this.#hookListeners.clear()\n this.#pluginsWithEventGenerators.clear()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: never[]) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #createDefaultResolver(pluginName: string): Resolver {\n const existingResolver = this.#defaultResolvers.get(pluginName)\n if (existingResolver) {\n return existingResolver\n }\n\n const resolver = defineResolver<PluginFactoryOptions>(() => ({\n name: 'default',\n pluginName,\n }))\n this.#defaultResolvers.set(pluginName, resolver)\n return resolver\n }\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#createDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#createDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n const baseContext = {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get inputNode(): InputNode | undefined {\n return driver.inputNode\n },\n get adapter(): Adapter | undefined {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', message)\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', typeof error === 'string' ? new Error(error) : error)\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', message)\n },\n openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studioIsOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.inputNode || !driver.adapter) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studioIsOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n\n return openInStudioFn(driver.inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n\n return baseContext\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBA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