@kubb/cli 5.19.0 → 5.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/{Telemetry-Ctyp_EFO.js → Telemetry-B7SszijK.js} +2 -2
  2. package/dist/{Telemetry-Ctyp_EFO.js.map → Telemetry-B7SszijK.js.map} +1 -1
  3. package/dist/{Telemetry-B2TeLVo4.cjs → Telemetry-Cg4O7utx.cjs} +2 -2
  4. package/dist/{Telemetry-B2TeLVo4.cjs.map → Telemetry-Cg4O7utx.cjs.map} +1 -1
  5. package/dist/{background-CByahHYn.js → background-DY0Mr03A.js} +2 -2
  6. package/dist/{background-CByahHYn.js.map → background-DY0Mr03A.js.map} +1 -1
  7. package/dist/{background-D6dQxXt6.cjs → background-DqI5F8po.cjs} +2 -2
  8. package/dist/{background-D6dQxXt6.cjs.map → background-DqI5F8po.cjs.map} +1 -1
  9. package/dist/{background-D60rO2Lz.js → background-tkqjTpos.js} +1 -1
  10. package/dist/{configFile-B_xrd2yx.cjs → configFile-CFaV_To0.cjs} +29 -9
  11. package/dist/configFile-CFaV_To0.cjs.map +1 -0
  12. package/dist/{configFile-Bh_5k4pf.js → configFile-lKPtO_1r.js} +27 -8
  13. package/dist/configFile-lKPtO_1r.js.map +1 -0
  14. package/dist/credentials-Cl3eOa8G.cjs.map +1 -1
  15. package/dist/credentials-LPHovWZe.js.map +1 -1
  16. package/dist/index.cjs +12 -12
  17. package/dist/index.js +12 -12
  18. package/dist/{mcp-D2gcpCcx.cjs → mcp-BiGBnYH7.cjs} +2 -2
  19. package/dist/{mcp-D2gcpCcx.cjs.map → mcp-BiGBnYH7.cjs.map} +1 -1
  20. package/dist/{mcp-BrB7TJZU.js → mcp-VfW5A7Et.js} +2 -2
  21. package/dist/{mcp-BrB7TJZU.js.map → mcp-VfW5A7Et.js.map} +1 -1
  22. package/dist/package-CdkP7X7O.js +5 -0
  23. package/dist/package-CdkP7X7O.js.map +1 -0
  24. package/dist/{package-DM5mr0Yc.cjs → package-D5f3ZWB1.cjs} +2 -2
  25. package/dist/package-D5f3ZWB1.cjs.map +1 -0
  26. package/dist/{run-Dyzva1xB.js → run--8RWm6ny.js} +4 -4
  27. package/dist/{run-Dyzva1xB.js.map → run--8RWm6ny.js.map} +1 -1
  28. package/dist/{run-DFOjQVMO.js → run-Bj7R9x32.js} +12 -5
  29. package/dist/run-Bj7R9x32.js.map +1 -0
  30. package/dist/{run-B3TuKUr4.js → run-Bn5MQwU6.js} +3 -3
  31. package/dist/{run-B3TuKUr4.js.map → run-Bn5MQwU6.js.map} +1 -1
  32. package/dist/{run-ejmyJI37.cjs → run-CnbPIGBg.cjs} +2 -2
  33. package/dist/{run-ejmyJI37.cjs.map → run-CnbPIGBg.cjs.map} +1 -1
  34. package/dist/{run-6qjg9Twy.cjs → run-Cp-ddEnQ.cjs} +12 -5
  35. package/dist/run-Cp-ddEnQ.cjs.map +1 -0
  36. package/dist/{run-4MUhIiPj.cjs → run-CvJA7KRW.cjs} +2 -2
  37. package/dist/{run-4MUhIiPj.cjs.map → run-CvJA7KRW.cjs.map} +1 -1
  38. package/dist/{run-D0HO6_Yr.cjs → run-Cz4jqsVH.cjs} +3 -3
  39. package/dist/{run-D0HO6_Yr.cjs.map → run-Cz4jqsVH.cjs.map} +1 -1
  40. package/dist/{run-BSsTBfse.js → run-DBEs_CXd.js} +3 -3
  41. package/dist/{run-BSsTBfse.js.map → run-DBEs_CXd.js.map} +1 -1
  42. package/dist/{run-CcWmws1R.js → run-DKTqPtGT.js} +2 -2
  43. package/dist/{run-CcWmws1R.js.map → run-DKTqPtGT.js.map} +1 -1
  44. package/dist/{run-Cxfs1SLQ.js → run-DM7m4Viy.js} +3 -3
  45. package/dist/{run-Cxfs1SLQ.js.map → run-DM7m4Viy.js.map} +1 -1
  46. package/dist/{run-C6tE9zTS.cjs → run-DWWlKSqg.cjs} +3 -3
  47. package/dist/{run-C6tE9zTS.cjs.map → run-DWWlKSqg.cjs.map} +1 -1
  48. package/dist/{run-CC9TBCph.js → run-DZF-DqiM.js} +3 -3
  49. package/dist/{run-CC9TBCph.js.map → run-DZF-DqiM.js.map} +1 -1
  50. package/dist/{run-D2tJP_b8.js → run-DkMqxmXf.js} +2 -2
  51. package/dist/{run-D2tJP_b8.js.map → run-DkMqxmXf.js.map} +1 -1
  52. package/dist/{run-lH8k2FY7.cjs → run-DnsSsAj2.cjs} +3 -3
  53. package/dist/{run-lH8k2FY7.cjs.map → run-DnsSsAj2.cjs.map} +1 -1
  54. package/dist/{run-BJiP4ib3.js → run-W0EIq66g.js} +1 -1
  55. package/dist/{run-C2lQXYrF.cjs → run-gBNMCysT.cjs} +3 -3
  56. package/dist/{run-C2lQXYrF.cjs.map → run-gBNMCysT.cjs.map} +1 -1
  57. package/dist/{run-3OxB7Zxn.cjs → run-w8oRvtdl.cjs} +3 -3
  58. package/dist/{run-3OxB7Zxn.cjs.map → run-w8oRvtdl.cjs.map} +1 -1
  59. package/dist/{shared-SrKde4x4.js → shared-B5nei7B5.js} +2 -1
  60. package/dist/{shared-SrKde4x4.js.map → shared-B5nei7B5.js.map} +1 -1
  61. package/dist/{shared-DoD3p_X8.cjs → shared-CK7OtOSX.cjs} +2 -1
  62. package/dist/{shared-DoD3p_X8.cjs.map → shared-CK7OtOSX.cjs.map} +1 -1
  63. package/dist/{snapshot-DnqAAzKE.js → snapshot-BH9zjo7V.js} +2 -2
  64. package/dist/{snapshot-DnqAAzKE.js.map → snapshot-BH9zjo7V.js.map} +1 -1
  65. package/dist/{snapshot-DdRni_x5.cjs → snapshot-osKgMu9i.cjs} +2 -2
  66. package/dist/{snapshot-DdRni_x5.cjs.map → snapshot-osKgMu9i.cjs.map} +1 -1
  67. package/dist/{status-X9BNNp9F.js → status-DZceprwS.js} +2 -2
  68. package/dist/{status-X9BNNp9F.js.map → status-DZceprwS.js.map} +1 -1
  69. package/dist/{status-wHJjD3Fs.cjs → status-Dw2z9CEy.cjs} +2 -2
  70. package/dist/{status-wHJjD3Fs.cjs.map → status-Dw2z9CEy.cjs.map} +1 -1
  71. package/dist/{studio-rRSg33RE.js → studio-CKZ8oF7u.js} +12 -12
  72. package/dist/{studio-rRSg33RE.js.map → studio-CKZ8oF7u.js.map} +1 -1
  73. package/dist/{studio-j4As00N6.cjs → studio-igCkMtri.cjs} +12 -12
  74. package/dist/{studio-j4As00N6.cjs.map → studio-igCkMtri.cjs.map} +1 -1
  75. package/dist/studioWorker.js +2 -2
  76. package/dist/{validate-CyxoAzEK.cjs → validate-YMI4B_lF.cjs} +3 -3
  77. package/dist/{validate-CyxoAzEK.cjs.map → validate-YMI4B_lF.cjs.map} +1 -1
  78. package/dist/{validate-CSbYneXo.js → validate-_a3pddzL.js} +3 -3
  79. package/dist/{validate-CSbYneXo.js.map → validate-_a3pddzL.js.map} +1 -1
  80. package/package.json +7 -7
  81. package/dist/configFile-B_xrd2yx.cjs.map +0 -1
  82. package/dist/configFile-Bh_5k4pf.js.map +0 -1
  83. package/dist/package-CcsdQpSf.js +0 -5
  84. package/dist/package-CcsdQpSf.js.map +0 -1
  85. package/dist/package-DM5mr0Yc.cjs.map +0 -1
  86. package/dist/run-6qjg9Twy.cjs.map +0 -1
  87. package/dist/run-DFOjQVMO.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"configFile-B_xrd2yx.cjs","names":["parse","getErrorMessage","camelCase","isPackageName","memo","getErrorMessage","read","writeRaw"],"sources":["../../../internals/shared/src/configFile/ast.ts","../../../internals/shared/src/configFile/types.ts","../../../internals/shared/src/configFile/rules.ts","../../../internals/shared/src/configFile/text.ts","../../../internals/shared/src/configFile/configFile.ts"],"sourcesContent":["import { getErrorMessage } from '@internals/utils'\nimport { type Comment, type Expression, type Program, parse } from 'yuku-parser'\n\nexport type {\n ArrayExpression,\n AssignmentExpression,\n BindingProperty,\n CallExpression,\n Comment,\n Expression,\n ImportDeclaration,\n ObjectExpression,\n ObjectPropertyKind,\n Program,\n RestElement,\n SpreadElement,\n VariableDeclaration,\n} from 'yuku-parser'\n\n/** Node types the config editor reads from the yuku AST. */\nexport const nodeTypes = {\n arrayExpression: 'ArrayExpression',\n arrowFunctionExpression: 'ArrowFunctionExpression',\n assignmentExpression: 'AssignmentExpression',\n blockStatement: 'BlockStatement',\n callExpression: 'CallExpression',\n exportDefaultDeclaration: 'ExportDefaultDeclaration',\n expressionStatement: 'ExpressionStatement',\n functionExpression: 'FunctionExpression',\n identifier: 'Identifier',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n literal: 'Literal',\n memberExpression: 'MemberExpression',\n objectExpression: 'ObjectExpression',\n objectPattern: 'ObjectPattern',\n property: 'Property',\n returnStatement: 'ReturnStatement',\n spreadElement: 'SpreadElement',\n tSAsExpression: 'TSAsExpression',\n tSSatisfiesExpression: 'TSSatisfiesExpression',\n templateLiteral: 'TemplateLiteral',\n unaryExpression: 'UnaryExpression',\n variableDeclaration: 'VariableDeclaration',\n} as const\n\nexport const commentTypes = { line: 'Line' } as const\nexport const propertyKinds = { init: 'init' } as const\nexport const unaryOperators = { minus: '-', plus: '+' } as const\nconst diagnosticSeverities = { error: 'error' } as const\n\n/** A parsed file: its statements and every comment in it, or why it could not be parsed. */\ntype ParsedSource = { program: Program; comments: Array<Comment> } | { reason: string }\n\n/**\n * Parses `source` as a TypeScript module. Never throws: a syntax error, or a native parser that\n * cannot load on this platform, comes back as a `reason`.\n */\nexport function parseSource(source: string): ParsedSource {\n try {\n // Parentheses are dropped, so `export default (defineConfig({}))` reads as the call itself.\n const { program, comments, diagnostics } = parse(source, { lang: 'ts', sourceType: 'module', preserveParens: false })\n if (diagnostics.some((diagnostic) => diagnostic.severity === diagnosticSeverities.error)) return { reason: 'the config file could not be parsed' }\n return { program, comments }\n } catch (error) {\n return { reason: `the config parser could not load on this platform: ${getErrorMessage(error)}` }\n }\n}\n\n/** Parses `source` as one expression, such as a commented-out `pluginTs({ ... })` call. */\nexport function parseExpression(source: string): Expression | undefined {\n const parsed = parseSource(source)\n if ('reason' in parsed) return undefined\n const [statement] = parsed.program.body\n return parsed.program.body.length === 1 && statement?.type === nodeTypes.expressionStatement ? statement.expression : undefined\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { ExtensionKind, ExtensionManifest } from '@kubb/core'\n\n/** Which `defineConfig(...)` entry an edit targets: its index or `name`, the first entry when omitted. */\nexport type ConfigRef = string | number\n\n/** A literal option value that survives a JSON round trip. */\nexport type OptionValue = string | number | boolean | null | Array<OptionValue> | { [key: string]: OptionValue }\n\nexport const extensionKinds = { plugin: 'plugin', adapter: 'adapter', parser: 'parser' } as const satisfies Record<string, ExtensionKind>\n\nexport const ConfigEditOperation = {\n SET_OPTION: 'set-option',\n REMOVE_OPTION: 'remove-option',\n ADD_PLUGIN: 'add-plugin',\n REMOVE_EXTENSION: 'remove-extension',\n DISABLE_PLUGIN: 'disable-plugin',\n ENABLE_PLUGIN: 'enable-plugin',\n SET_INPUT: 'set-input',\n SET_OUTPUT: 'set-output',\n REMOVE_OUTPUT: 'remove-output',\n} as const\nexport type ConfigEditOperation = ValueOf<typeof ConfigEditOperation>\n\n/**\n * One change to `kubb.config.ts`. `plugin` is the package name, and `kind` picks the `plugins` entry\n * (default), the `adapter`, or a `parsers` entry. `path` walks nested option objects.\n */\nexport type ConfigEdit =\n | { operation: typeof ConfigEditOperation.SET_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string> }\n /** With `kind: 'parser'`, adds to `parsers`. A config without `parsers` gets the defaults written next to it, so they keep running. */\n | {\n operation: typeof ConfigEditOperation.ADD_PLUGIN\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n options?: Record<string, unknown>\n }\n /** Deletes every call of a plugin, or a parser with `kind: 'parser'`, a disabled block included, and the imports nothing else uses. */\n | {\n operation: typeof ConfigEditOperation.REMOVE_EXTENSION\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n }\n | { operation: typeof ConfigEditOperation.DISABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.ENABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.SET_INPUT; config?: ConfigRef; input: string }\n | { operation: typeof ConfigEditOperation.SET_OUTPUT; config?: ConfigRef; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OUTPUT; config?: ConfigRef; path: Array<string> }\n\n/** Option keys, each with whether Studio may write it. `locked` lists the code paths inside a partly literal object. */\nexport type OptionsView = Record<string, { literal: boolean; value?: OptionValue; locked?: Array<Array<string>> }>\n\n/** A factory call in `plugins`, `adapter`, or `parsers`. `importName` is the local name, alias included. */\nexport type PluginView = {\n importName: string\n packageName: string\n options: OptionsView\n /** The call is commented out by `disable-plugin`. */\n disabled?: true\n}\n\nexport type ConfigView = {\n name?: string\n plugins: Array<PluginView>\n adapter?: PluginView\n parsers?: Array<PluginView>\n /** The root `output` members Studio may set, absent when `output` is not an object literal. */\n output?: OptionsView\n}\n\n/** The config file as Studio may edit it, or why it cannot. */\nexport type ConfigFileView = { managed: true; configs: Array<ConfigView> } | { managed: false; reason: string }\n\nexport type ConfigEditOutcome = {\n edit: ConfigEdit\n applied: boolean\n reason?: string\n}\n\nexport type ExtensionEntry = {\n package: string\n version: string\n manifest: ExtensionManifest\n /** Ships with `kubb` at its version, so updating `kubb` updates it and `kubb update` cannot. */\n bundled?: true\n}\n\n/** Installed extensions by package name, the only ones Studio may import besides `@kubb/plugin-*`. */\nexport type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>\n","import { type ExtensionKind, isPackageName } from '@kubb/core'\nimport { camelCase } from '@internals/utils'\nimport { extensionKinds, type InstalledExtensions, type OptionValue } from './types.ts'\n\n/** `@kubb/plugin-ts` becomes `plugin-ts`, the `name` Kubb plugin factories use. */\nexport function toPluginName(packageName: string): string {\n return packageName.split('/').pop() ?? packageName\n}\n\n/** `@kubb/plugin-react-query` becomes `pluginReactQuery`, the export a plugin package uses by convention. */\nexport function toExportName(packageName: string): string {\n return camelCase(toPluginName(packageName))\n}\n\nconst KUBB_PLUGIN_SPECIFIER = /^@kubb\\/plugin-[\\w.-]+$/\n\n/** Only a `@kubb/plugin-*` package or an installed extension of `kind` may be imported, never a path or URL. */\nexport function isAllowedPlugin({\n packageName,\n extensions,\n kind = extensionKinds.plugin,\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): boolean {\n if (!isPackageName(packageName)) return false\n return (kind === extensionKinds.plugin && KUBB_PLUGIN_SPECIFIER.test(packageName)) || extensions.get(packageName)?.manifest.kind === kind\n}\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype'])\n\n/** Whether `key` can be an option key without reaching the object's prototype. */\nexport function isSafeKey(key: string): boolean {\n return !UNSAFE_KEYS.has(key)\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\n/** Whether `value` survives a JSON round trip, so an edit never writes a lossy copy into the file. */\nexport function isOptionValue(value: unknown): value is OptionValue {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n if (typeof value === 'number') return Number.isFinite(value)\n if (Array.isArray(value)) return value.every(isOptionValue)\n if (isPlainObject(value)) return Object.entries(value).every(([key, entry]) => isSafeKey(key) && isOptionValue(entry))\n\n return false\n}\n\n/** The root `output` members Studio may set, with the values each takes. */\nconst OUTPUT_VALUES: Record<string, (value: unknown) => boolean> = {\n barrel: (value) => value === false || (isPlainObject(value) && Object.keys(value).length === 1 && (value.type === 'named' || value.type === 'all')),\n format: (value) => value === false || ['auto', 'prettier', 'biome', 'oxfmt'].includes(value as string),\n lint: (value) => value === false || ['auto', 'eslint', 'biome', 'oxlint'].includes(value as string),\n clean: (value) => typeof value === 'boolean',\n defaultBanner: (value) => value === false || value === 'simple' || value === 'full',\n}\n\nexport function isOutputKey(key: string): boolean {\n return Object.hasOwn(OUTPUT_VALUES, key)\n}\n\nexport function isOutputValue({ key, value }: { key: string; value: unknown }): boolean {\n return isOutputKey(key) && OUTPUT_VALUES[key]!(value)\n}\n\nexport function pickOutput<T>(output: Record<string, T>): Record<string, T> {\n return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)))\n}\n","import type { ValueOf } from '@internals/utils'\nimport { type ArrayExpression, nodeTypes, type ObjectExpression } from './ast.ts'\nimport type { OptionValue } from './types.ts'\n\n/**\n * A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,\n * never as source that breaks out of the import statement.\n */\nexport const IDENTIFIER_PATTERN = /^[A-Za-z_$][\\w$]*$/\n\nexport const quotes = { single: `'`, double: `\"` } as const\nexport type Quote = ValueOf<typeof quotes>\n\n/** `source` with the text between `start` and `end` replaced by `text`. */\nexport function replaceText(source: string, start: number, end: number, text = ''): string {\n return `${source.slice(0, start)}${text}${source.slice(end)}`\n}\n\n/** The 1-based line and 0-based column of `offset` in `source`. */\nexport function getPosition(source: string, offset: number): { line: number; column: number } {\n return { line: source.slice(0, offset).split('\\n').length, column: offset - source.lastIndexOf('\\n', offset - 1) - 1 }\n}\n\n/** Writes `value` as a single-line literal with the file's quote style. */\nexport function printValue(value: OptionValue, quote: Quote): string {\n if (typeof value === 'string') {\n // JSON's escaping covers every character that could end the literal or the line.\n const escaped = JSON.stringify(value).slice(1, -1)\n return quote === quotes.double ? `\"${escaped}\"` : `'${escaped.replaceAll(`\\\\\"`, `\"`).replaceAll(`'`, `\\\\'`)}'`\n }\n if (value === null || typeof value !== 'object') return String(value)\n if (Array.isArray(value)) return `[${value.map((item) => printValue(item, quote)).join(', ')}]`\n\n const entries = Object.entries(value)\n return entries.length ? `{ ${entries.map(([key, item]) => `${printKey(key, quote)}: ${printValue(item, quote)}`).join(', ')} }` : '{}'\n}\n\n/** An object key as source text: bare when it is an identifier, quoted otherwise. */\nexport function printKey(key: string, quote: Quote): string {\n return IDENTIFIER_PATTERN.test(key) ? key : printValue(key, quote)\n}\n\n/** `value` wrapped in one object per key of `path`: `wrapPath(['enum', 'type'], 'enum')` is `{ enum: { type: 'enum' } }`. */\nexport function wrapPath(path: Array<string>, value: OptionValue): OptionValue {\n return path.reduceRight<OptionValue>((inner, key) => ({ [key]: inner }), value)\n}\n\n/**\n * Adds `text` as the last item of an object or array literal, following its layout: on a line of\n * its own with the last item's indentation when the literal spans lines, inline otherwise.\n */\nexport function appendItem(source: string, container: ObjectExpression | ArrayExpression, text: string): string {\n const { start, end } = container\n const items: Array<{ start: number; end: number } | null> = container.type === nodeTypes.objectExpression ? container.properties : container.elements\n const last = items.filter((item) => item !== null).at(-1)\n\n if (!last) {\n const inner = source.slice(start + 1, end - 1)\n // A comment inside the empty literal stays, after the new item.\n if (inner.trim()) return replaceText(source, start + 1, start + 1, /^\\s/.test(inner) ? `${text},` : `${text}, `)\n return replaceText(source, start, end, container.type === nodeTypes.objectExpression ? `{ ${text} }` : `[${text}]`)\n }\n\n const between = source.slice(last.end, end - 1)\n // The closing bracket shares the last item's line: add the item inline.\n if (!between.includes('\\n')) return replaceText(source, last.end, last.end, `, ${text}`)\n\n const lineStart = source.lastIndexOf('\\n', last.start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n // After the last item's comma and any comment on its line, so neither moves. `between` holds a\n // newline, so one always follows.\n const lineEnd = source.indexOf('\\n', last.end)\n const comma = /^\\s*,/.test(between)\n\n return `${source.slice(0, last.end)}${comma ? '' : ','}${source.slice(last.end, lineEnd)}\\n${indent}${text}${comma ? ',' : ''}${source.slice(lineEnd)}`\n}\n\n/** Drops the item at `index` from an object or array literal, with its own lines when it sits on them alone. */\nexport function removeItem(source: string, node: ObjectExpression | ArrayExpression, index: number): string {\n const items: Array<{ start: number; end: number }> =\n node.type === nodeTypes.objectExpression ? node.properties : node.elements.filter((element) => element !== null)\n if (items.length === 1) return replaceText(source, node.start, node.end, node.type === nodeTypes.objectExpression ? '{}' : '[]')\n\n const { start, end } = items[index]!\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const nextNewline = source.indexOf('\\n', end)\n const lineEnd = nextNewline === -1 ? source.length : nextNewline\n if (!source.slice(lineStart, start).trim() && /^\\s*,?\\s*(\\/\\/.*)?$/.test(source.slice(end, lineEnd))) {\n return replaceText(source, lineStart, Math.min(lineEnd + 1, source.length))\n }\n\n const next = items[index + 1]\n return next ? replaceText(source, start, next.start) : replaceText(source, items[index - 1]!.end, end)\n}\n","import type { ExtensionKind } from '@kubb/core'\nimport { getErrorMessage, memo, read, writeRaw } from '@internals/utils'\nimport type { ValueOf } from '@internals/utils'\nimport {\n type AssignmentExpression,\n type BindingProperty,\n type CallExpression,\n type Comment,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectPropertyKind,\n type Program,\n type RestElement,\n type SpreadElement,\n type VariableDeclaration,\n commentTypes,\n nodeTypes,\n parseExpression,\n parseSource,\n propertyKinds,\n unaryOperators,\n} from './ast.ts'\nimport { isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isSafeKey, pickOutput, toExportName } from './rules.ts'\nimport { appendItem, getPosition, IDENTIFIER_PATTERN, printKey, printValue, quotes, type Quote, removeItem, replaceText, wrapPath } from './text.ts'\nimport {\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEditOutcome,\n type ConfigFileView,\n type ConfigRef,\n type ConfigView,\n extensionKinds,\n type InstalledExtensions,\n type OptionsView,\n type OptionValue,\n type PluginView,\n} from './types.ts'\n\n/** The marker `disable-plugin` writes, with the block's line count so `enable-plugin` restores exactly those lines. */\nconst DISABLED_MARKER_PATTERN = /^kubb:disabled (.+)\\s+(\\d+)$/\n\nconst OPERATIONS = new Set<string>(Object.values(ConfigEditOperation))\nconst OPTION_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OPTION, ConfigEditOperation.REMOVE_OPTION])\nconst OUTPUT_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OUTPUT, ConfigEditOperation.REMOVE_OUTPUT])\nconst KINDS = new Set<string>(Object.values(extensionKinds))\n\n/** Identifiers the editor matches by name. */\nconst identifiers = { defineConfig: 'defineConfig', require: 'require', module: 'module', exports: 'exports' } as const\n\nconst moduleKinds = { esm: 'esm', cjs: 'cjs' } as const\ntype ModuleKind = ValueOf<typeof moduleKinds>\n\ntype EditResult = { source: string } | { reason: string }\ntype ParsedConfig = { program: Program; comments: Array<Comment>; configs: Array<ObjectExpression>; kind: ModuleKind }\ntype ValueNode = Expression | SpreadElement | null | undefined\ntype Import = { from: string; exported: string }\ntype FactoryCall = { importName: string; exportName: string; packageName: string; call: CallExpression }\ntype DisabledBlock = { packageName: string; line: number; end: number; code: Array<string> }\ntype OutputEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OUTPUT | typeof ConfigEditOperation.REMOVE_OUTPUT }>\ntype OptionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OPTION | typeof ConfigEditOperation.REMOVE_OPTION }>\ntype AddPluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.ADD_PLUGIN }>\ntype DisablePluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.DISABLE_PLUGIN }>\ntype RemoveExtensionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.REMOVE_EXTENSION }>\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value !== ''\n}\n\n/** Edits cross the wire, so their shape is checked before anything reads them. */\nfunction validateEdit(edit: ConfigEdit): string | undefined {\n const { operation, plugin, config, path, kind, input } = (typeof edit === 'object' && edit !== null ? edit : {}) as Record<string, unknown>\n\n if (typeof operation !== 'string' || !OPERATIONS.has(operation)) return `unknown operation ${JSON.stringify(operation)}`\n if (config !== undefined && typeof config !== 'string' && !Number.isSafeInteger(config)) return 'config must name an entry or give its index'\n\n if (operation === ConfigEditOperation.SET_INPUT) {\n return typeof input === 'string' && input.trim() !== '' ? undefined : 'the edit names no input'\n }\n\n const isOption = OPTION_OPERATIONS.has(operation)\n const isOutput = OUTPUT_OPERATIONS.has(operation)\n\n if (!isOutput && !isNonEmptyString(plugin)) return 'the edit names no plugin'\n\n if (kind !== undefined) {\n if (typeof kind !== 'string' || !KINDS.has(kind)) return `unknown kind ${JSON.stringify(kind)}`\n const takesKind = operation === ConfigEditOperation.ADD_PLUGIN || operation === ConfigEditOperation.REMOVE_EXTENSION\n if (takesKind && kind === extensionKinds.adapter) return `${operation} takes a plugin or a parser, since a config has one adapter`\n if (!isOption && !takesKind) return `${operation} edits the plugins array, so it takes no kind`\n }\n\n if (!isOption && !isOutput) return undefined\n\n if (!Array.isArray(path) || !path.every(isNonEmptyString)) return 'path must be a list of option names'\n if (path.length === 0) return 'no option path given'\n\n const unsafe = path.find((key) => !isSafeKey(key))\n if (unsafe !== undefined) return `${unsafe} cannot be used as an option name`\n\n if (isOutput && !isOutputKey(path[0]!)) return `output.${path[0]} can only be changed in the config file`\n\n return undefined\n}\n\n// Finding the config\n\n/** Steps through `as`/`satisfies` and `() => ...` wrappers to the config object. */\nfunction unwrapValue(node: ValueNode): ValueNode {\n if (!node) return undefined\n if (node.type === nodeTypes.tSAsExpression || node.type === nodeTypes.tSSatisfiesExpression) return unwrapValue(node.expression)\n if (node.type !== nodeTypes.arrowFunctionExpression && node.type !== nodeTypes.functionExpression) return node\n if (node.body?.type !== nodeTypes.blockStatement) return unwrapValue(node.body as Expression | null)\n\n const returned = node.body.body.find((statement) => statement.type === nodeTypes.returnStatement)\n return unwrapValue(returned?.type === nodeTypes.returnStatement ? returned.argument : undefined)\n}\n\nfunction isModuleExports(node: AssignmentExpression['left']): boolean {\n return (\n node.type === nodeTypes.memberExpression &&\n !node.computed &&\n node.object.type === nodeTypes.identifier &&\n node.object.name === identifiers.module &&\n node.property.type === nodeTypes.identifier &&\n node.property.name === identifiers.exports\n )\n}\n\n/** The exported config value and how the file exports it. */\nfunction findExport(program: Program): { exported: ValueNode; kind: ModuleKind } {\n for (const node of program.body) {\n if (node.type === nodeTypes.exportDefaultDeclaration) {\n // A `function` or `class` declaration is never a `defineConfig(...)` call, so `findConfigs` refuses it.\n return { exported: node.declaration as Expression, kind: moduleKinds.esm }\n }\n if (node.type === nodeTypes.expressionStatement && node.expression.type === nodeTypes.assignmentExpression && isModuleExports(node.expression.left)) {\n return { exported: node.expression.right, kind: moduleKinds.cjs }\n }\n }\n return { exported: undefined, kind: moduleKinds.esm }\n}\n\n/** Every config object in `export default` or `module.exports = defineConfig(...)`, or why the file is unmanaged. */\nfunction findConfigs(source: string): ParsedConfig | { reason: string } {\n const parsed = parseSource(source)\n if ('reason' in parsed) return parsed\n\n const { exported, kind } = findExport(parsed.program)\n const value = unwrapValue(exported)\n if (!value) return { reason: 'no `export default` or `module.exports` found' }\n if (value.type !== nodeTypes.callExpression || value.callee.type !== nodeTypes.identifier || value.callee.name !== identifiers.defineConfig) {\n return { reason: 'the exported config is not a defineConfig(...) call' }\n }\n\n const argument = unwrapValue(value.arguments[0])\n if (!argument) return { reason: 'defineConfig(...) was called without a config' }\n\n const entries = argument.type === nodeTypes.arrayExpression ? argument.elements.map((element) => unwrapValue(element)) : [argument]\n const configs = entries.filter((entry): entry is ObjectExpression => entry?.type === nodeTypes.objectExpression)\n if (configs.length !== entries.length) return { reason: 'config is not an object literal' }\n\n return { ...parsed, configs, kind }\n}\n\nfunction findConfigEntry(configs: Array<ObjectExpression>, ref: ConfigRef | undefined): ObjectExpression | undefined {\n return typeof ref === 'string' ? configs.find((entry) => getConfigName(entry) === ref) : configs[ref ?? 0]\n}\n\n// Reading object literals\n\nfunction getKey(entry: ObjectPropertyKind | BindingProperty | RestElement): string | undefined {\n if (entry.type !== nodeTypes.property || entry.computed) return undefined\n if (entry.key.type === nodeTypes.identifier) return entry.key.name\n return entry.key.type === nodeTypes.literal && typeof entry.key.value === 'string' ? entry.key.value : undefined\n}\n\n/** The last one wins when the key repeats, as at runtime. */\nfunction findProperty(node: ObjectExpression, key: string): { member: ObjectPropertyKind; index: number } | undefined {\n const index = node.properties.findLastIndex((entry) => getKey(entry) === key)\n return index === -1 ? undefined : { member: node.properties[index]!, index }\n}\n\nfunction getValue(node: ObjectExpression, key: string): ValueNode {\n const member = findProperty(node, key)?.member\n return member?.type === nodeTypes.property ? member.value : member\n}\n\nfunction getConfigName(config: ObjectExpression): string | undefined {\n const name = getValue(config, 'name')\n return name?.type === nodeTypes.literal && typeof name.value === 'string' ? name.value : undefined\n}\n\nfunction isOverridden(node: ObjectExpression, index: number): boolean {\n return node.properties.slice(index + 1).some((entry) => entry.type === nodeTypes.spreadElement)\n}\n\n/** `key: value`, not a method, getter, setter, or `{ key }` shorthand. */\nfunction isPlainProperty(member: Extract<ObjectPropertyKind, { type: typeof nodeTypes.property }>): boolean {\n return !member.method && !member.shorthand && member.kind === propertyKinds.init\n}\n\n/** A literal's value, `undefined` for code. */\nfunction readLiteral(node: ValueNode): OptionValue | undefined {\n switch (node?.type) {\n case nodeTypes.literal:\n // A bigint or a regex is code, not a value JSON can carry. A regex Node cannot compile also has a `null` value.\n return 'regex' in node || 'bigint' in node ? undefined : (node.value as OptionValue)\n case nodeTypes.templateLiteral:\n return node.expressions.length ? undefined : (node.quasis[0]?.value.cooked ?? '')\n case nodeTypes.unaryExpression: {\n const value = readLiteral(node.argument)\n if (typeof value !== 'number') return undefined\n if (node.operator === unaryOperators.minus) return -value\n if (node.operator === unaryOperators.plus) return value\n return undefined\n }\n case nodeTypes.arrayExpression: {\n const values = node.elements.map((element) => readLiteral(element))\n return values.every((value) => value !== undefined) ? values : undefined\n }\n case nodeTypes.objectExpression: {\n const entries: Record<string, OptionValue> = {}\n for (const entry of node.properties) {\n if (entry.type !== nodeTypes.property) return undefined\n const key = getKey(entry)\n const value = readLiteral(entry.value)\n // A `__proto__` key would replace the object's prototype instead of adding an entry.\n if (key === undefined || !isSafeKey(key) || value === undefined) return undefined\n entries[key] = value\n }\n return entries\n }\n }\n return undefined\n}\n\n// Imports and factory calls\n\nfunction getRequirePath(node: ValueNode): string | undefined {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier || node.callee.name !== identifiers.require) return undefined\n const [argument] = node.arguments\n return argument?.type === nodeTypes.literal && typeof argument.value === 'string' ? argument.value : undefined\n}\n\n/** `import { exported as local } from '...'`. A default or namespace import has no exported name, so its local name stands in. */\nfunction importBindings(statement: ImportDeclaration): Array<[string, Import]> {\n return statement.specifiers.map((specifier) => {\n const imported = specifier.type === nodeTypes.importSpecifier ? specifier.imported : specifier.local\n const exported = imported.type === nodeTypes.identifier ? imported.name : imported.value\n return [specifier.local.name, { from: statement.source.value, exported }]\n })\n}\n\n/** `const { exported: local } = require('...')`. */\nfunction requireBindings(statement: VariableDeclaration): Array<[string, Import]> {\n return statement.declarations.flatMap((declarator): Array<[string, Import]> => {\n const from = getRequirePath(declarator.init)\n if (from === undefined || declarator.id.type !== nodeTypes.objectPattern) return []\n\n return declarator.id.properties.flatMap((entry): Array<[string, Import]> => {\n if (entry.type !== nodeTypes.property || entry.value.type !== nodeTypes.identifier) return []\n return [[entry.value.name, { from, exported: getKey(entry) ?? entry.value.name }]]\n })\n })\n}\n\nfunction getImports(program: Program): Map<string, Import> {\n return new Map(\n program.body.flatMap((statement) => {\n if (statement.type === nodeTypes.importDeclaration) return importBindings(statement)\n if (statement.type === nodeTypes.variableDeclaration) return requireBindings(statement)\n return []\n }),\n )\n}\n\nfunction isImportStatement(node: Program['body'][number], kind: ModuleKind): boolean {\n if (kind === moduleKinds.esm) return node.type === nodeTypes.importDeclaration\n return node.type === nodeTypes.variableDeclaration && node.declarations.some((declarator) => getRequirePath(declarator.init) !== undefined)\n}\n\n/** The quote of the first string literal in the file, so new code matches it. */\nfunction detectQuote(node: unknown): Quote | undefined {\n if (!node || typeof node !== 'object') return undefined\n const { type, raw } = node as { type?: string; raw?: unknown }\n if (type === nodeTypes.literal && typeof raw === 'string' && (raw[0] === quotes.single || raw[0] === quotes.double)) return raw[0]\n for (const child of Object.values(node)) {\n const quote = detectQuote(child)\n if (quote) return quote\n }\n return undefined\n}\n\n/** The `adapter` value, or the elements of the `plugins` or `parsers` array. */\nfunction factoryNodes(config: ObjectExpression, kind: ExtensionKind): Array<ValueNode> {\n if (kind === extensionKinds.adapter) return [getValue(config, 'adapter')]\n const array = getValue(config, `${kind}s`)\n return array?.type === nodeTypes.arrayExpression ? array.elements : []\n}\n\n/** The factory calls of one kind whose callee the file imports. */\nfunction findCalls(program: Program, config: ObjectExpression, kind: ExtensionKind = extensionKinds.plugin): Array<FactoryCall> {\n const imports = getImports(program)\n return factoryNodes(config, kind).flatMap((node) => {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier) return []\n const imported = imports.get(node.callee.name)\n return imported ? [{ importName: node.callee.name, exportName: imported.exported, packageName: imported.from, call: node }] : []\n })\n}\n\n// Disabled plugins\n\n/** Whether nothing but whitespace precedes `offset` on its line. */\nfunction startsLine(source: string, offset: number): boolean {\n return source.slice(source.lastIndexOf('\\n', offset - 1) + 1, offset).trim() === ''\n}\n\n/** The `disable-plugin` blocks in this config, read from marker comments since the call is no longer a node. */\nfunction findDisabled(source: string, comments: Array<Comment>, config: ObjectExpression): Array<DisabledBlock> {\n const lines = source.split('\\n')\n\n return comments.flatMap((comment) => {\n const match = comment.type === commentTypes.line ? comment.value.trim().match(DISABLED_MARKER_PATTERN) : null\n // Only markers inside this entry, on a line of their own, so another entry or a trailing comment never matches.\n if (!match || comment.start < config.start || comment.end > config.end || !startsLine(source, comment.start)) return []\n\n const line = getPosition(source, comment.start).line\n const end = line + Number(match[2])\n const code = lines.slice(line, end).map((text) => text.replace(/^(\\s*)\\/\\/ ?/, '$1').replace(/^\\s+$/, ''))\n return [{ packageName: match[1]!, line, end, code }]\n })\n}\n\n// Reading options\n\n/** Literal members as `value` and code paths as `locked`, `undefined` for a computed key. */\nfunction readEditable(node: ObjectExpression, prefix: Array<string> = []): { value: Record<string, OptionValue>; locked: Array<Array<string>> } | undefined {\n const value: Record<string, OptionValue> = {}\n const locked: Array<Array<string>> = []\n\n for (const [index, entry] of node.properties.entries()) {\n if (entry.type === nodeTypes.spreadElement) continue\n const key = getKey(entry)\n if (key === undefined) return undefined\n if (findProperty(node, key)?.index !== index) continue\n\n const path = [...prefix, key]\n // A `__proto__` key replaces the prototype, so it reads as code.\n if (!isSafeKey(key)) {\n locked.push(path)\n continue\n }\n\n const member = isOverridden(node, index) ? undefined : entry.value\n const literal = readLiteral(member)\n if (literal !== undefined) {\n value[key] = literal\n continue\n }\n if (member?.type !== nodeTypes.objectExpression) {\n locked.push(path)\n continue\n }\n\n const nested = readEditable(member, path)\n if (!nested) return undefined\n value[key] = nested.value\n locked.push(...nested.locked)\n }\n return { value, locked }\n}\n\nfunction readObjectOptions(options: ObjectExpression): OptionsView {\n const entries: OptionsView = {}\n for (const [index, entry] of options.properties.entries()) {\n const key = getKey(entry)\n if (key === undefined || !isSafeKey(key)) continue\n\n const member = entry.type === nodeTypes.property && !isOverridden(options, index) ? entry.value : undefined\n const value = readLiteral(member)\n if (value !== undefined) {\n entries[key] = { literal: true, value }\n continue\n }\n entries[key] = { literal: false, ...(member?.type === nodeTypes.objectExpression ? readEditable(member) : undefined) }\n }\n return entries\n}\n\nfunction readCallOptions(call: CallExpression): OptionsView {\n const options = call.arguments[0]\n return options?.type === nodeTypes.objectExpression ? readObjectOptions(options) : {}\n}\n\nfunction readDisabledOptions(code: Array<string>): OptionsView {\n const call = parseExpression(code.join('\\n').trim().replace(/,$/, ''))\n return call?.type === nodeTypes.callExpression ? readCallOptions(call) : {}\n}\n\nfunction toPluginView({ importName, packageName, call }: FactoryCall): PluginView {\n return { importName, packageName, options: readCallOptions(call) }\n}\n\n/** Active and disabled plugins, in source order so a disabled plugin keeps its place. */\nfunction readPlugins({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): Array<PluginView> {\n const importNames = new Map([...getImports(parsed.program)].map(([local, { from }]) => [from, local]))\n\n const active = findCalls(parsed.program, config).map((call) => ({ line: getPosition(source, call.call.start).line, plugin: toPluginView(call) }))\n const disabled = findDisabled(source, parsed.comments, config).map(({ packageName, line, code }) => ({\n line,\n plugin: {\n importName: importNames.get(packageName) ?? toExportName(packageName),\n packageName,\n options: readDisabledOptions(code),\n disabled: true as const,\n },\n }))\n\n return [...active, ...disabled].sort((a, b) => a.line - b.line).map(({ plugin }) => plugin)\n}\n\nfunction readConfigView({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): ConfigView {\n const [adapter] = findCalls(parsed.program, config, extensionKinds.adapter).map(toPluginView)\n const parsers = findCalls(parsed.program, config, extensionKinds.parser).map(toPluginView)\n const output = getOutput(config)\n\n return {\n name: getConfigName(config),\n plugins: readPlugins({ source, parsed, config }),\n ...(adapter && { adapter }),\n ...(parsers.length ? { parsers } : {}),\n ...(!('reason' in output) && { output: pickOutput(readObjectOptions(output.object)) }),\n }\n}\n\n/** Which plugins the file declares and which options Studio may write. */\nexport function readConfig(source: string): ConfigFileView {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return { managed: false, reason: parsed.reason }\n\n return { managed: true, configs: parsed.configs.map((config) => readConfigView({ source, parsed, config })) }\n}\n\n/** The modules the file imports, empty when it cannot be parsed. */\nexport function readImports(source: string): Array<string> {\n const parsed = parseSource(source)\n if ('reason' in parsed) return []\n return [...new Set([...getImports(parsed.program).values()].map(({ from }) => from))]\n}\n\n// Editing options\n\ntype FoundPath = { object: ObjectExpression; index: number; value: Expression } | { object: ObjectExpression; missing: number } | { reason: string }\n\n/** Follows `path` to its literal, or to the first missing key. Refuses a value set in code. */\nfunction findPath(options: ObjectExpression, path: Array<string>): FoundPath {\n let object = options\n\n for (const [depth, key] of path.entries()) {\n const found = findProperty(object, key)\n if (!found) return { object, missing: depth }\n if (isOverridden(object, found.index)) {\n return { reason: `${path.slice(0, depth + 1).join('.')} can be overridden by a spread after it, so it is customized in code` }\n }\n\n const { member, index } = found\n const isLast = depth === path.length - 1\n if (isLast) {\n return member.type === nodeTypes.property && readLiteral(member.value) !== undefined\n ? { object, index, value: member.value }\n : { reason: `${path.join('.')} is customized in code` }\n }\n if (member.type !== nodeTypes.property || member.value.type !== nodeTypes.objectExpression) {\n return { reason: `${key} is not an object, so ${path.join('.')} cannot be reached` }\n }\n object = member.value\n }\n return { reason: 'no option path given' }\n}\n\nfunction setAtPath({\n source,\n options,\n path,\n value,\n quote,\n}: {\n source: string\n options: ObjectExpression\n path: Array<string>\n value: OptionValue\n quote: Quote\n}): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) {\n const [key, ...rest] = path.slice(target.missing)\n return { source: appendItem(source, target.object, `${printKey(key!, quote)}: ${printValue(wrapPath(rest, value), quote)}`) }\n }\n return { source: replaceText(source, target.value.start, target.value.end, printValue(value, quote)) }\n}\n\nfunction removeAtPath({ source, options, path }: { source: string; options: ObjectExpression; path: Array<string> }): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) return { source }\n return { source: removeItem(source, target.object, target.index) }\n}\n\nfunction setOption(source: string, call: CallExpression, path: Array<string>, value: unknown, quote: Quote): EditResult {\n if (!isOptionValue(value)) return { reason: 'the value is not a literal that can be written to a config file' }\n\n const options = call.arguments[0]\n if (!options) {\n const closing = call.end - 1\n if (source[closing] !== ')') return { reason: 'the factory call could not be located in the file' }\n return { source: replaceText(source, closing, closing, printValue(wrapPath(path, value), quote)) }\n }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return setAtPath({ source, options, path, value, quote })\n}\n\nfunction removeOption(source: string, call: CallExpression, path: Array<string>): EditResult {\n const options = call.arguments[0]\n if (!options) return { source }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return removeAtPath({ source, options, path })\n}\n\nfunction editOption({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: OptionEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n // A package can ship several factories (`parserTs`, `parserTsx`), so prefer the export its manifest names.\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const exportName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n const call = (calls.find((entry) => entry.exportName === exportName) ?? calls[0])?.call\n\n if (!call) {\n if (kind === extensionKinds.adapter) return { reason: `${edit.plugin} is not the config's adapter` }\n const disabled = kind === extensionKinds.plugin && findDisabled(source, parsed.comments, config).some((block) => block.packageName === edit.plugin)\n return { reason: disabled ? `${edit.plugin} is disabled, enable it first` : `${edit.plugin} is not in the ${kind}s array` }\n }\n\n if (edit.operation === ConfigEditOperation.SET_OPTION) return setOption(source, call, edit.path, edit.value, quote)\n return removeOption(source, call, edit.path)\n}\n\n// Editing the config's own fields\n\nfunction setInput(source: string, config: ObjectExpression, input: string, quote: Quote): EditResult {\n const value = printValue(input, quote)\n const found = findProperty(config, 'input')\n if (!found) return { source: appendItem(source, config, `input: ${value}`) }\n if (found.member.type !== nodeTypes.property || !isPlainProperty(found.member)) return { reason: 'input is not a plain property' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after input could override it' }\n return { source: replaceText(source, found.member.value.start, found.member.value.end, value) }\n}\n\nfunction getOutput(config: ObjectExpression): { object: ObjectExpression } | { reason: string } {\n const found = findProperty(config, 'output')\n if (found?.member.type !== nodeTypes.property || found.member.value.type !== nodeTypes.objectExpression) return { reason: 'output is not an object literal' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after output could override it' }\n return { object: found.member.value }\n}\n\nfunction editOutput({ source, config, edit, quote }: { source: string; config: ObjectExpression; edit: OutputEdit; quote: Quote }): EditResult {\n const output = getOutput(config)\n if ('reason' in output) return output\n if (edit.operation === ConfigEditOperation.REMOVE_OUTPUT) return removeAtPath({ source, options: output.object, path: edit.path })\n\n const [key, ...rest] = edit.path\n if (!isOptionValue(edit.value) || !isOutputValue({ key: key!, value: wrapPath(rest, edit.value) }))\n return { reason: `the value is not one output.${key} takes` }\n return setAtPath({ source, options: output.object, path: edit.path, value: edit.value, quote })\n}\n\n// Adding, disabling, and enabling plugins\n\n/** Adds the import after the last one, matching its semicolon style. */\nfunction addImport({\n source,\n parsed,\n importNames,\n moduleSpecifier,\n quote,\n}: {\n source: string\n parsed: ParsedConfig\n importNames: Array<string>\n moduleSpecifier: string\n quote: Quote\n}): string {\n const lastImport = parsed.program.body.findLast((node) => isImportStatement(node, parsed.kind))\n const afterLine = lastImport ? getPosition(source, lastImport.end).line : 0\n const lines = source.split('\\n')\n\n const semicolon = afterLine > 0 && lines[afterLine - 1]?.trimEnd().endsWith(';') ? ';' : ''\n const specifier = `${quote}${moduleSpecifier}${quote}`\n const statement =\n parsed.kind === moduleKinds.esm ? `import { ${importNames.join(', ')} } from ${specifier}` : `const { ${importNames.join(', ')} } = require(${specifier})`\n\n lines.splice(afterLine, 0, `${statement}${semicolon}`)\n if (afterLine === 0) lines.splice(1, 0, '')\n\n return lines.join('\\n')\n}\n\n/**\n * The parsers `defineConfig` applies when a config sets no `parsers`, by import name. Adding a parser\n * to such a config writes these too, or the new array would replace them.\n */\nconst DEFAULT_PARSERS = [\n { importName: 'parserTs', packageName: '@kubb/parser-ts' },\n { importName: 'parserTsx', packageName: '@kubb/parser-ts' },\n { importName: 'parserMd', packageName: '@kubb/parser-md' },\n] as const\n\n/**\n * Adds a plugin to `plugins`, or with `kind: 'parser'` a parser to `parsers`. Replaying the same add\n * is a no-op, while an import name taken by another package is an error.\n */\nfunction addPlugin({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: AddPluginEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n const isParser = kind === extensionKinds.parser\n if (!isAllowedPlugin({ packageName: edit.plugin, extensions, kind })) {\n return {\n reason: isParser ? `\"${edit.plugin}\" is not an installed Kubb parser` : `\"${edit.plugin}\" is not a @kubb/plugin-* package or an installed Kubb plugin`,\n }\n }\n\n const importName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n if (!IDENTIFIER_PATTERN.test(importName)) return { reason: `\"${importName}\" is not a valid import name` }\n // A package can ship several parsers (`parserTs` and `parserTsx`), so a parser is matched by its export too.\n if (findCalls(parsed.program, config, kind).some((entry) => entry.packageName === edit.plugin && (!isParser || entry.exportName === importName))) {\n return { source }\n }\n\n const options = edit.options ?? {}\n if (!isOptionValue(options)) return { reason: 'the options are not literals that can be written to a config file' }\n\n const key = `${kind}s`\n const array = getValue(config, key)\n if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` }\n // A config without `parsers` runs the defaults, so the new array lists them before the added parser.\n const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : []\n\n // The missing imports by package, so `parserTs` and `parserTsx` share one line.\n const imports = getImports(parsed.program)\n const missing = memo.create<string, Array<string>>()\n for (const item of [...defaults, { importName, packageName: edit.plugin }]) {\n const from = imports.get(item.importName)?.from\n if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` }\n if (!from) memo(missing, item.packageName, () => []).push(item.importName)\n }\n\n // The array sits below the imports, so adding to it first leaves the import lines where they are.\n const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ''})`\n const next =\n array?.type === nodeTypes.arrayExpression\n ? appendItem(source, array, call)\n : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(', ')}]`)\n\n return {\n source: [...missing].reduceRight(\n (current, [moduleSpecifier, importNames]) => addImport({ source: current, parsed, importNames, moduleSpecifier, quote }),\n next,\n ),\n }\n}\n\n/** One item per line, so a call can be commented out alone. Skipped when comments sit between items. */\nfunction splitPlugins(source: string, config: ObjectExpression): string | undefined {\n const array = getValue(config, 'plugins')\n if (array?.type !== nodeTypes.arrayExpression) return undefined\n\n const items = array.elements.flatMap((element) => (element ? [element] : []))\n const { start, end } = array\n const gaps = [source.slice(start + 1, items[0]?.start ?? end - 1), ...items.map((item, index) => source.slice(item.end, items[index + 1]?.start ?? end - 1))]\n if (!items.length || gaps.some((gap) => !/^[\\s,]*$/.test(gap))) return undefined\n\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n const lines = items.map((item) => `${indent} ${source.slice(item.start, item.end)},`)\n\n return replaceText(source, start, end, `[\\n${lines.join('\\n')}\\n${indent}]`)\n}\n\nfunction disablePlugin(source: string, program: Program, config: ObjectExpression, plugin: string): EditResult {\n const call = findCalls(program, config).find((entry) => entry.packageName === plugin)?.call\n if (!call) return { reason: `${plugin} is not in the plugins array` }\n\n const start = getPosition(source, call.start)\n const end = getPosition(source, call.end)\n const lines = source.split('\\n')\n const from = start.line - 1\n const to = end.line - 1\n const firstLine = lines[from] ?? ''\n\n // Only safe when the call sits alone on its lines: anything else on its first line, or on its last\n // line besides a trailing comma, would be swallowed into the comment and corrupt the file.\n if (firstLine.slice(0, start.column).trim() || !/^,?\\s*$/.test((lines[to] ?? '').slice(end.column))) {\n return { reason: `${plugin} shares a line with other code, so it cannot be commented out safely` }\n }\n\n const indent = firstLine.match(/^\\s*/)?.[0] ?? ''\n const commented = lines.slice(from, to + 1).map((line) => (line.trim() ? `${indent}// ${line.slice(indent.length)}` : `${indent}//`))\n lines.splice(from, commented.length, `${indent}// kubb:disabled ${plugin} ${commented.length}`, ...commented)\n\n return { source: lines.join('\\n') }\n}\n\n/** Disables the plugin, first putting a one-line `plugins: [a(), b()]` (what `add-plugin` writes) on separate lines. */\nfunction disablePluginInConfig({\n source,\n parsed,\n config,\n edit,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: DisablePluginEdit\n}): EditResult {\n const result = disablePlugin(source, parsed.program, config, edit.plugin)\n if (!('reason' in result) || !result.reason.includes('shares a line')) return result\n\n const split = splitPlugins(source, config)\n if (split === undefined) return result\n\n const reparsed = findConfigs(split)\n const reparsedConfig = 'reason' in reparsed ? undefined : findConfigEntry(reparsed.configs, edit.config)\n if ('reason' in reparsed || !reparsedConfig) return result\n\n return disablePlugin(split, reparsed.program, reparsedConfig, edit.plugin)\n}\n\nfunction enablePlugin(source: string, comments: Array<Comment>, config: ObjectExpression, plugin: string): EditResult {\n const block = findDisabled(source, comments, config).find((entry) => entry.packageName === plugin)\n if (!block) return { reason: `${plugin} is not disabled` }\n\n const lines = source.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1, ...block.code)\n return { source: lines.join('\\n') }\n}\n\n// Removing extensions\n\n/** Drops the import statements of `packageName` once nothing else in the file uses their names. */\nfunction removeUnusedImports(source: string, packageName: string): string {\n const parsed = parseSource(source)\n if ('reason' in parsed) return source\n\n // From the last statement up, so the offsets of the earlier ones stay valid.\n return parsed.program.body.reduceRight((current, statement) => {\n const bindings =\n statement.type === nodeTypes.importDeclaration\n ? importBindings(statement)\n : statement.type === nodeTypes.variableDeclaration\n ? requireBindings(statement)\n : []\n if (!bindings.length || bindings.some(([, { from }]) => from !== packageName)) return current\n\n const rest = replaceText(current, statement.start, statement.end)\n if (bindings.some(([local]) => new RegExp(`(?<![\\\\w$])${local.replaceAll('$', '\\\\$')}(?![\\\\w$])`).test(rest))) return current\n\n const lineStart = current.lastIndexOf('\\n', statement.start - 1) + 1\n const lineEnd = current.indexOf('\\n', statement.end)\n const after = lineEnd === -1 ? current.length : lineEnd + 1\n // At the top of the file, the blank line after the import goes too, so the file does not start with one.\n return replaceText(current, lineStart, lineStart === 0 && current[after] === '\\n' ? after + 1 : after)\n }, source)\n}\n\n/**\n * Removes every call of a plugin or parser package, and the block `disable-plugin` commented out,\n * then its unused imports. Removing what the config does not hold is a no-op. Refuses to empty\n * `parsers`, since a config with no parser cannot print files.\n */\nfunction removeExtension(source: string, edit: RemoveExtensionEdit): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n let current = source\n\n // One call at a time, re-parsing in between, since each removal moves the ones after it.\n for (;;) {\n const parsed = findConfigs(current)\n if ('reason' in parsed) return parsed\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n\n const array = getValue(config, `${kind}s`)\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const block = findDisabled(current, parsed.comments, config).find((entry) => entry.packageName === edit.plugin)\n\n if (calls[0] && array?.type === nodeTypes.arrayExpression) {\n const elements = array.elements.filter((element) => element !== null)\n if (kind === extensionKinds.parser && elements.length === calls.length) return { reason: `${edit.plugin} is the last parser in the parsers array` }\n current = removeItem(current, array, elements.indexOf(calls[0].call))\n continue\n }\n if (block && kind === extensionKinds.plugin) {\n const lines = current.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1)\n current = lines.join('\\n')\n continue\n }\n return { source: current === source ? source : removeUnusedImports(current, edit.plugin) }\n }\n}\n\n// Applying edits\n\n/** Every edit re-parses the file, since the previous one rewrote it. */\nfunction applyEdit({ source, edit, extensions }: { source: string; edit: ConfigEdit; extensions: InstalledExtensions }): EditResult {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return parsed\n\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n const quote = detectQuote(parsed.program) ?? quotes.single\n\n switch (edit.operation) {\n case ConfigEditOperation.SET_INPUT:\n return setInput(source, config, edit.input, quote)\n case ConfigEditOperation.SET_OUTPUT:\n case ConfigEditOperation.REMOVE_OUTPUT:\n return editOutput({ source, config, edit, quote })\n case ConfigEditOperation.DISABLE_PLUGIN:\n return disablePluginInConfig({ source, parsed, config, edit })\n case ConfigEditOperation.ENABLE_PLUGIN:\n return enablePlugin(source, parsed.comments, config, edit.plugin)\n case ConfigEditOperation.ADD_PLUGIN:\n return addPlugin({ source, parsed, config, edit, quote, extensions })\n case ConfigEditOperation.REMOVE_EXTENSION:\n return removeExtension(source, edit)\n case ConfigEditOperation.SET_OPTION:\n case ConfigEditOperation.REMOVE_OPTION:\n return editOption({ source, parsed, config, edit, quote, extensions })\n }\n}\n\n/** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */\nexport function editConfig({ source, edits, extensions = new Map() }: { source: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }): {\n source: string\n outcomes: Array<ConfigEditOutcome>\n changed: boolean\n} {\n let current = source\n\n const outcomes = edits.map((edit): ConfigEditOutcome => {\n const invalid = validateEdit(edit)\n if (invalid) return { edit, applied: false, reason: invalid }\n\n try {\n const result = applyEdit({ source: current, edit, extensions })\n if ('reason' in result) return { edit, applied: false, reason: result.reason }\n current = result.source\n return { edit, applied: true }\n } catch (error) {\n return { edit, applied: false, reason: getErrorMessage(error) }\n }\n })\n\n return { source: current, outcomes, changed: current !== source }\n}\n\n/** Applies `edits` to `filePath`, writing only when something changed. */\nexport async function editConfigFile({ filePath, edits, extensions }: { filePath: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }) {\n const current = await read(filePath)\n const result = editConfig({ source: current, edits, extensions })\n if (result.changed) await writeRaw(filePath, result.source)\n return result\n}\n"],"mappings":";;;;;;;;AAoBA,MAAa,YAAY;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,gBAAgB;CAChB,gBAAgB;CAChB,0BAA0B;CAC1B,qBAAqB;CACrB,oBAAoB;CACpB,YAAY;CACZ,mBAAmB;CACnB,iBAAiB;CACjB,SAAS;CACT,kBAAkB;CAClB,kBAAkB;CAClB,eAAe;CACf,UAAU;CACV,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,uBAAuB;CACvB,iBAAiB;CACjB,iBAAiB;CACjB,qBAAqB;AACvB;AAEA,MAAa,eAAe,EAAE,MAAM,OAAO;AAC3C,MAAa,gBAA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AE;IAAM,SAAS;GAAK;EAC/B,SAAS,OAAO;GACd,OAAO;IAAE;IAAM,SAAS;IAAO,QAAQC,eAAAA,gBAAgB,KAAK;GAAE;EAChE;CACF,CAAC;CAED,OAAO;EAAE,QAAQ;EAAS;EAAU,SAAS,YAAY;CAAO;AAClE;;AAGA,eAAsB,eAAe,EAAE,UAAU,OAAO,cAAgG;CAEtJ,MAAM,SAAS,WAAW;EAAE,QAAQ,MADdC,gBAAAA,KAAK,QAAQ;EACU;EAAO;CAAW,CAAC;CAChE,IAAI,OAAO,SAAS,MAAMC,gBAAAA,SAAS,UAAU,OAAO,MAAM;CAC1D,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"configFile-Bh_5k4pf.js","names":[],"sources":["../../../internals/shared/src/configFile/ast.ts","../../../internals/shared/src/configFile/types.ts","../../../internals/shared/src/configFile/rules.ts","../../../internals/shared/src/configFile/text.ts","../../../internals/shared/src/configFile/configFile.ts"],"sourcesContent":["import { getErrorMessage } from '@internals/utils'\nimport { type Comment, type Expression, type Program, parse } from 'yuku-parser'\n\nexport type {\n ArrayExpression,\n AssignmentExpression,\n BindingProperty,\n CallExpression,\n Comment,\n Expression,\n ImportDeclaration,\n ObjectExpression,\n ObjectPropertyKind,\n Program,\n RestElement,\n SpreadElement,\n VariableDeclaration,\n} from 'yuku-parser'\n\n/** Node types the config editor reads from the yuku AST. */\nexport const nodeTypes = {\n arrayExpression: 'ArrayExpression',\n arrowFunctionExpression: 'ArrowFunctionExpression',\n assignmentExpression: 'AssignmentExpression',\n blockStatement: 'BlockStatement',\n callExpression: 'CallExpression',\n exportDefaultDeclaration: 'ExportDefaultDeclaration',\n expressionStatement: 'ExpressionStatement',\n functionExpression: 'FunctionExpression',\n identifier: 'Identifier',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n literal: 'Literal',\n memberExpression: 'MemberExpression',\n objectExpression: 'ObjectExpression',\n objectPattern: 'ObjectPattern',\n property: 'Property',\n returnStatement: 'ReturnStatement',\n spreadElement: 'SpreadElement',\n tSAsExpression: 'TSAsExpression',\n tSSatisfiesExpression: 'TSSatisfiesExpression',\n templateLiteral: 'TemplateLiteral',\n unaryExpression: 'UnaryExpression',\n variableDeclaration: 'VariableDeclaration',\n} as const\n\nexport const commentTypes = { line: 'Line' } as const\nexport const propertyKinds = { init: 'init' } as const\nexport const unaryOperators = { minus: '-', plus: '+' } as const\nconst diagnosticSeverities = { error: 'error' } as const\n\n/** A parsed file: its statements and every comment in it, or why it could not be parsed. */\ntype ParsedSource = { program: Program; comments: Array<Comment> } | { reason: string }\n\n/**\n * Parses `source` as a TypeScript module. Never throws: a syntax error, or a native parser that\n * cannot load on this platform, comes back as a `reason`.\n */\nexport function parseSource(source: string): ParsedSource {\n try {\n // Parentheses are dropped, so `export default (defineConfig({}))` reads as the call itself.\n const { program, comments, diagnostics } = parse(source, { lang: 'ts', sourceType: 'module', preserveParens: false })\n if (diagnostics.some((diagnostic) => diagnostic.severity === diagnosticSeverities.error)) return { reason: 'the config file could not be parsed' }\n return { program, comments }\n } catch (error) {\n return { reason: `the config parser could not load on this platform: ${getErrorMessage(error)}` }\n }\n}\n\n/** Parses `source` as one expression, such as a commented-out `pluginTs({ ... })` call. */\nexport function parseExpression(source: string): Expression | undefined {\n const parsed = parseSource(source)\n if ('reason' in parsed) return undefined\n const [statement] = parsed.program.body\n return parsed.program.body.length === 1 && statement?.type === nodeTypes.expressionStatement ? statement.expression : undefined\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { ExtensionKind, ExtensionManifest } from '@kubb/core'\n\n/** Which `defineConfig(...)` entry an edit targets: its index or `name`, the first entry when omitted. */\nexport type ConfigRef = string | number\n\n/** A literal option value that survives a JSON round trip. */\nexport type OptionValue = string | number | boolean | null | Array<OptionValue> | { [key: string]: OptionValue }\n\nexport const extensionKinds = { plugin: 'plugin', adapter: 'adapter', parser: 'parser' } as const satisfies Record<string, ExtensionKind>\n\nexport const ConfigEditOperation = {\n SET_OPTION: 'set-option',\n REMOVE_OPTION: 'remove-option',\n ADD_PLUGIN: 'add-plugin',\n REMOVE_EXTENSION: 'remove-extension',\n DISABLE_PLUGIN: 'disable-plugin',\n ENABLE_PLUGIN: 'enable-plugin',\n SET_INPUT: 'set-input',\n SET_OUTPUT: 'set-output',\n REMOVE_OUTPUT: 'remove-output',\n} as const\nexport type ConfigEditOperation = ValueOf<typeof ConfigEditOperation>\n\n/**\n * One change to `kubb.config.ts`. `plugin` is the package name, and `kind` picks the `plugins` entry\n * (default), the `adapter`, or a `parsers` entry. `path` walks nested option objects.\n */\nexport type ConfigEdit =\n | { operation: typeof ConfigEditOperation.SET_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string> }\n /** With `kind: 'parser'`, adds to `parsers`. A config without `parsers` gets the defaults written next to it, so they keep running. */\n | {\n operation: typeof ConfigEditOperation.ADD_PLUGIN\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n options?: Record<string, unknown>\n }\n /** Deletes every call of a plugin, or a parser with `kind: 'parser'`, a disabled block included, and the imports nothing else uses. */\n | {\n operation: typeof ConfigEditOperation.REMOVE_EXTENSION\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n }\n | { operation: typeof ConfigEditOperation.DISABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.ENABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.SET_INPUT; config?: ConfigRef; input: string }\n | { operation: typeof ConfigEditOperation.SET_OUTPUT; config?: ConfigRef; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OUTPUT; config?: ConfigRef; path: Array<string> }\n\n/** Option keys, each with whether Studio may write it. `locked` lists the code paths inside a partly literal object. */\nexport type OptionsView = Record<string, { literal: boolean; value?: OptionValue; locked?: Array<Array<string>> }>\n\n/** A factory call in `plugins`, `adapter`, or `parsers`. `importName` is the local name, alias included. */\nexport type PluginView = {\n importName: string\n packageName: string\n options: OptionsView\n /** The call is commented out by `disable-plugin`. */\n disabled?: true\n}\n\nexport type ConfigView = {\n name?: string\n plugins: Array<PluginView>\n adapter?: PluginView\n parsers?: Array<PluginView>\n /** The root `output` members Studio may set, absent when `output` is not an object literal. */\n output?: OptionsView\n}\n\n/** The config file as Studio may edit it, or why it cannot. */\nexport type ConfigFileView = { managed: true; configs: Array<ConfigView> } | { managed: false; reason: string }\n\nexport type ConfigEditOutcome = {\n edit: ConfigEdit\n applied: boolean\n reason?: string\n}\n\nexport type ExtensionEntry = {\n package: string\n version: string\n manifest: ExtensionManifest\n /** Ships with `kubb` at its version, so updating `kubb` updates it and `kubb update` cannot. */\n bundled?: true\n}\n\n/** Installed extensions by package name, the only ones Studio may import besides `@kubb/plugin-*`. */\nexport type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>\n","import { type ExtensionKind, isPackageName } from '@kubb/core'\nimport { camelCase } from '@internals/utils'\nimport { extensionKinds, type InstalledExtensions, type OptionValue } from './types.ts'\n\n/** `@kubb/plugin-ts` becomes `plugin-ts`, the `name` Kubb plugin factories use. */\nexport function toPluginName(packageName: string): string {\n return packageName.split('/').pop() ?? packageName\n}\n\n/** `@kubb/plugin-react-query` becomes `pluginReactQuery`, the export a plugin package uses by convention. */\nexport function toExportName(packageName: string): string {\n return camelCase(toPluginName(packageName))\n}\n\nconst KUBB_PLUGIN_SPECIFIER = /^@kubb\\/plugin-[\\w.-]+$/\n\n/** Only a `@kubb/plugin-*` package or an installed extension of `kind` may be imported, never a path or URL. */\nexport function isAllowedPlugin({\n packageName,\n extensions,\n kind = extensionKinds.plugin,\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): boolean {\n if (!isPackageName(packageName)) return false\n return (kind === extensionKinds.plugin && KUBB_PLUGIN_SPECIFIER.test(packageName)) || extensions.get(packageName)?.manifest.kind === kind\n}\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype'])\n\n/** Whether `key` can be an option key without reaching the object's prototype. */\nexport function isSafeKey(key: string): boolean {\n return !UNSAFE_KEYS.has(key)\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\n/** Whether `value` survives a JSON round trip, so an edit never writes a lossy copy into the file. */\nexport function isOptionValue(value: unknown): value is OptionValue {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n if (typeof value === 'number') return Number.isFinite(value)\n if (Array.isArray(value)) return value.every(isOptionValue)\n if (isPlainObject(value)) return Object.entries(value).every(([key, entry]) => isSafeKey(key) && isOptionValue(entry))\n\n return false\n}\n\n/** The root `output` members Studio may set, with the values each takes. */\nconst OUTPUT_VALUES: Record<string, (value: unknown) => boolean> = {\n barrel: (value) => value === false || (isPlainObject(value) && Object.keys(value).length === 1 && (value.type === 'named' || value.type === 'all')),\n format: (value) => value === false || ['auto', 'prettier', 'biome', 'oxfmt'].includes(value as string),\n lint: (value) => value === false || ['auto', 'eslint', 'biome', 'oxlint'].includes(value as string),\n clean: (value) => typeof value === 'boolean',\n defaultBanner: (value) => value === false || value === 'simple' || value === 'full',\n}\n\nexport function isOutputKey(key: string): boolean {\n return Object.hasOwn(OUTPUT_VALUES, key)\n}\n\nexport function isOutputValue({ key, value }: { key: string; value: unknown }): boolean {\n return isOutputKey(key) && OUTPUT_VALUES[key]!(value)\n}\n\nexport function pickOutput<T>(output: Record<string, T>): Record<string, T> {\n return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)))\n}\n","import type { ValueOf } from '@internals/utils'\nimport { type ArrayExpression, nodeTypes, type ObjectExpression } from './ast.ts'\nimport type { OptionValue } from './types.ts'\n\n/**\n * A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,\n * never as source that breaks out of the import statement.\n */\nexport const IDENTIFIER_PATTERN = /^[A-Za-z_$][\\w$]*$/\n\nexport const quotes = { single: `'`, double: `\"` } as const\nexport type Quote = ValueOf<typeof quotes>\n\n/** `source` with the text between `start` and `end` replaced by `text`. */\nexport function replaceText(source: string, start: number, end: number, text = ''): string {\n return `${source.slice(0, start)}${text}${source.slice(end)}`\n}\n\n/** The 1-based line and 0-based column of `offset` in `source`. */\nexport function getPosition(source: string, offset: number): { line: number; column: number } {\n return { line: source.slice(0, offset).split('\\n').length, column: offset - source.lastIndexOf('\\n', offset - 1) - 1 }\n}\n\n/** Writes `value` as a single-line literal with the file's quote style. */\nexport function printValue(value: OptionValue, quote: Quote): string {\n if (typeof value === 'string') {\n // JSON's escaping covers every character that could end the literal or the line.\n const escaped = JSON.stringify(value).slice(1, -1)\n return quote === quotes.double ? `\"${escaped}\"` : `'${escaped.replaceAll(`\\\\\"`, `\"`).replaceAll(`'`, `\\\\'`)}'`\n }\n if (value === null || typeof value !== 'object') return String(value)\n if (Array.isArray(value)) return `[${value.map((item) => printValue(item, quote)).join(', ')}]`\n\n const entries = Object.entries(value)\n return entries.length ? `{ ${entries.map(([key, item]) => `${printKey(key, quote)}: ${printValue(item, quote)}`).join(', ')} }` : '{}'\n}\n\n/** An object key as source text: bare when it is an identifier, quoted otherwise. */\nexport function printKey(key: string, quote: Quote): string {\n return IDENTIFIER_PATTERN.test(key) ? key : printValue(key, quote)\n}\n\n/** `value` wrapped in one object per key of `path`: `wrapPath(['enum', 'type'], 'enum')` is `{ enum: { type: 'enum' } }`. */\nexport function wrapPath(path: Array<string>, value: OptionValue): OptionValue {\n return path.reduceRight<OptionValue>((inner, key) => ({ [key]: inner }), value)\n}\n\n/**\n * Adds `text` as the last item of an object or array literal, following its layout: on a line of\n * its own with the last item's indentation when the literal spans lines, inline otherwise.\n */\nexport function appendItem(source: string, container: ObjectExpression | ArrayExpression, text: string): string {\n const { start, end } = container\n const items: Array<{ start: number; end: number } | null> = container.type === nodeTypes.objectExpression ? container.properties : container.elements\n const last = items.filter((item) => item !== null).at(-1)\n\n if (!last) {\n const inner = source.slice(start + 1, end - 1)\n // A comment inside the empty literal stays, after the new item.\n if (inner.trim()) return replaceText(source, start + 1, start + 1, /^\\s/.test(inner) ? `${text},` : `${text}, `)\n return replaceText(source, start, end, container.type === nodeTypes.objectExpression ? `{ ${text} }` : `[${text}]`)\n }\n\n const between = source.slice(last.end, end - 1)\n // The closing bracket shares the last item's line: add the item inline.\n if (!between.includes('\\n')) return replaceText(source, last.end, last.end, `, ${text}`)\n\n const lineStart = source.lastIndexOf('\\n', last.start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n // After the last item's comma and any comment on its line, so neither moves. `between` holds a\n // newline, so one always follows.\n const lineEnd = source.indexOf('\\n', last.end)\n const comma = /^\\s*,/.test(between)\n\n return `${source.slice(0, last.end)}${comma ? '' : ','}${source.slice(last.end, lineEnd)}\\n${indent}${text}${comma ? ',' : ''}${source.slice(lineEnd)}`\n}\n\n/** Drops the item at `index` from an object or array literal, with its own lines when it sits on them alone. */\nexport function removeItem(source: string, node: ObjectExpression | ArrayExpression, index: number): string {\n const items: Array<{ start: number; end: number }> =\n node.type === nodeTypes.objectExpression ? node.properties : node.elements.filter((element) => element !== null)\n if (items.length === 1) return replaceText(source, node.start, node.end, node.type === nodeTypes.objectExpression ? '{}' : '[]')\n\n const { start, end } = items[index]!\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const nextNewline = source.indexOf('\\n', end)\n const lineEnd = nextNewline === -1 ? source.length : nextNewline\n if (!source.slice(lineStart, start).trim() && /^\\s*,?\\s*(\\/\\/.*)?$/.test(source.slice(end, lineEnd))) {\n return replaceText(source, lineStart, Math.min(lineEnd + 1, source.length))\n }\n\n const next = items[index + 1]\n return next ? replaceText(source, start, next.start) : replaceText(source, items[index - 1]!.end, end)\n}\n","import type { ExtensionKind } from '@kubb/core'\nimport { getErrorMessage, memo, read, writeRaw } from '@internals/utils'\nimport type { ValueOf } from '@internals/utils'\nimport {\n type AssignmentExpression,\n type BindingProperty,\n type CallExpression,\n type Comment,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectPropertyKind,\n type Program,\n type RestElement,\n type SpreadElement,\n type VariableDeclaration,\n commentTypes,\n nodeTypes,\n parseExpression,\n parseSource,\n propertyKinds,\n unaryOperators,\n} from './ast.ts'\nimport { isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isSafeKey, pickOutput, toExportName } from './rules.ts'\nimport { appendItem, getPosition, IDENTIFIER_PATTERN, printKey, printValue, quotes, type Quote, removeItem, replaceText, wrapPath } from './text.ts'\nimport {\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEditOutcome,\n type ConfigFileView,\n type ConfigRef,\n type ConfigView,\n extensionKinds,\n type InstalledExtensions,\n type OptionsView,\n type OptionValue,\n type PluginView,\n} from './types.ts'\n\n/** The marker `disable-plugin` writes, with the block's line count so `enable-plugin` restores exactly those lines. */\nconst DISABLED_MARKER_PATTERN = /^kubb:disabled (.+)\\s+(\\d+)$/\n\nconst OPERATIONS = new Set<string>(Object.values(ConfigEditOperation))\nconst OPTION_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OPTION, ConfigEditOperation.REMOVE_OPTION])\nconst OUTPUT_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OUTPUT, ConfigEditOperation.REMOVE_OUTPUT])\nconst KINDS = new Set<string>(Object.values(extensionKinds))\n\n/** Identifiers the editor matches by name. */\nconst identifiers = { defineConfig: 'defineConfig', require: 'require', module: 'module', exports: 'exports' } as const\n\nconst moduleKinds = { esm: 'esm', cjs: 'cjs' } as const\ntype ModuleKind = ValueOf<typeof moduleKinds>\n\ntype EditResult = { source: string } | { reason: string }\ntype ParsedConfig = { program: Program; comments: Array<Comment>; configs: Array<ObjectExpression>; kind: ModuleKind }\ntype ValueNode = Expression | SpreadElement | null | undefined\ntype Import = { from: string; exported: string }\ntype FactoryCall = { importName: string; exportName: string; packageName: string; call: CallExpression }\ntype DisabledBlock = { packageName: string; line: number; end: number; code: Array<string> }\ntype OutputEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OUTPUT | typeof ConfigEditOperation.REMOVE_OUTPUT }>\ntype OptionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OPTION | typeof ConfigEditOperation.REMOVE_OPTION }>\ntype AddPluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.ADD_PLUGIN }>\ntype DisablePluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.DISABLE_PLUGIN }>\ntype RemoveExtensionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.REMOVE_EXTENSION }>\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value !== ''\n}\n\n/** Edits cross the wire, so their shape is checked before anything reads them. */\nfunction validateEdit(edit: ConfigEdit): string | undefined {\n const { operation, plugin, config, path, kind, input } = (typeof edit === 'object' && edit !== null ? edit : {}) as Record<string, unknown>\n\n if (typeof operation !== 'string' || !OPERATIONS.has(operation)) return `unknown operation ${JSON.stringify(operation)}`\n if (config !== undefined && typeof config !== 'string' && !Number.isSafeInteger(config)) return 'config must name an entry or give its index'\n\n if (operation === ConfigEditOperation.SET_INPUT) {\n return typeof input === 'string' && input.trim() !== '' ? undefined : 'the edit names no input'\n }\n\n const isOption = OPTION_OPERATIONS.has(operation)\n const isOutput = OUTPUT_OPERATIONS.has(operation)\n\n if (!isOutput && !isNonEmptyString(plugin)) return 'the edit names no plugin'\n\n if (kind !== undefined) {\n if (typeof kind !== 'string' || !KINDS.has(kind)) return `unknown kind ${JSON.stringify(kind)}`\n const takesKind = operation === ConfigEditOperation.ADD_PLUGIN || operation === ConfigEditOperation.REMOVE_EXTENSION\n if (takesKind && kind === extensionKinds.adapter) return `${operation} takes a plugin or a parser, since a config has one adapter`\n if (!isOption && !takesKind) return `${operation} edits the plugins array, so it takes no kind`\n }\n\n if (!isOption && !isOutput) return undefined\n\n if (!Array.isArray(path) || !path.every(isNonEmptyString)) return 'path must be a list of option names'\n if (path.length === 0) return 'no option path given'\n\n const unsafe = path.find((key) => !isSafeKey(key))\n if (unsafe !== undefined) return `${unsafe} cannot be used as an option name`\n\n if (isOutput && !isOutputKey(path[0]!)) return `output.${path[0]} can only be changed in the config file`\n\n return undefined\n}\n\n// Finding the config\n\n/** Steps through `as`/`satisfies` and `() => ...` wrappers to the config object. */\nfunction unwrapValue(node: ValueNode): ValueNode {\n if (!node) return undefined\n if (node.type === nodeTypes.tSAsExpression || node.type === nodeTypes.tSSatisfiesExpression) return unwrapValue(node.expression)\n if (node.type !== nodeTypes.arrowFunctionExpression && node.type !== nodeTypes.functionExpression) return node\n if (node.body?.type !== nodeTypes.blockStatement) return unwrapValue(node.body as Expression | null)\n\n const returned = node.body.body.find((statement) => statement.type === nodeTypes.returnStatement)\n return unwrapValue(returned?.type === nodeTypes.returnStatement ? returned.argument : undefined)\n}\n\nfunction isModuleExports(node: AssignmentExpression['left']): boolean {\n return (\n node.type === nodeTypes.memberExpression &&\n !node.computed &&\n node.object.type === nodeTypes.identifier &&\n node.object.name === identifiers.module &&\n node.property.type === nodeTypes.identifier &&\n node.property.name === identifiers.exports\n )\n}\n\n/** The exported config value and how the file exports it. */\nfunction findExport(program: Program): { exported: ValueNode; kind: ModuleKind } {\n for (const node of program.body) {\n if (node.type === nodeTypes.exportDefaultDeclaration) {\n // A `function` or `class` declaration is never a `defineConfig(...)` call, so `findConfigs` refuses it.\n return { exported: node.declaration as Expression, kind: moduleKinds.esm }\n }\n if (node.type === nodeTypes.expressionStatement && node.expression.type === nodeTypes.assignmentExpression && isModuleExports(node.expression.left)) {\n return { exported: node.expression.right, kind: moduleKinds.cjs }\n }\n }\n return { exported: undefined, kind: moduleKinds.esm }\n}\n\n/** Every config object in `export default` or `module.exports = defineConfig(...)`, or why the file is unmanaged. */\nfunction findConfigs(source: string): ParsedConfig | { reason: string } {\n const parsed = parseSource(source)\n if ('reason' in parsed) return parsed\n\n const { exported, kind } = findExport(parsed.program)\n const value = unwrapValue(exported)\n if (!value) return { reason: 'no `export default` or `module.exports` found' }\n if (value.type !== nodeTypes.callExpression || value.callee.type !== nodeTypes.identifier || value.callee.name !== identifiers.defineConfig) {\n return { reason: 'the exported config is not a defineConfig(...) call' }\n }\n\n const argument = unwrapValue(value.arguments[0])\n if (!argument) return { reason: 'defineConfig(...) was called without a config' }\n\n const entries = argument.type === nodeTypes.arrayExpression ? argument.elements.map((element) => unwrapValue(element)) : [argument]\n const configs = entries.filter((entry): entry is ObjectExpression => entry?.type === nodeTypes.objectExpression)\n if (configs.length !== entries.length) return { reason: 'config is not an object literal' }\n\n return { ...parsed, configs, kind }\n}\n\nfunction findConfigEntry(configs: Array<ObjectExpression>, ref: ConfigRef | undefined): ObjectExpression | undefined {\n return typeof ref === 'string' ? configs.find((entry) => getConfigName(entry) === ref) : configs[ref ?? 0]\n}\n\n// Reading object literals\n\nfunction getKey(entry: ObjectPropertyKind | BindingProperty | RestElement): string | undefined {\n if (entry.type !== nodeTypes.property || entry.computed) return undefined\n if (entry.key.type === nodeTypes.identifier) return entry.key.name\n return entry.key.type === nodeTypes.literal && typeof entry.key.value === 'string' ? entry.key.value : undefined\n}\n\n/** The last one wins when the key repeats, as at runtime. */\nfunction findProperty(node: ObjectExpression, key: string): { member: ObjectPropertyKind; index: number } | undefined {\n const index = node.properties.findLastIndex((entry) => getKey(entry) === key)\n return index === -1 ? undefined : { member: node.properties[index]!, index }\n}\n\nfunction getValue(node: ObjectExpression, key: string): ValueNode {\n const member = findProperty(node, key)?.member\n return member?.type === nodeTypes.property ? member.value : member\n}\n\nfunction getConfigName(config: ObjectExpression): string | undefined {\n const name = getValue(config, 'name')\n return name?.type === nodeTypes.literal && typeof name.value === 'string' ? name.value : undefined\n}\n\nfunction isOverridden(node: ObjectExpression, index: number): boolean {\n return node.properties.slice(index + 1).some((entry) => entry.type === nodeTypes.spreadElement)\n}\n\n/** `key: value`, not a method, getter, setter, or `{ key }` shorthand. */\nfunction isPlainProperty(member: Extract<ObjectPropertyKind, { type: typeof nodeTypes.property }>): boolean {\n return !member.method && !member.shorthand && member.kind === propertyKinds.init\n}\n\n/** A literal's value, `undefined` for code. */\nfunction readLiteral(node: ValueNode): OptionValue | undefined {\n switch (node?.type) {\n case nodeTypes.literal:\n // A bigint or a regex is code, not a value JSON can carry. A regex Node cannot compile also has a `null` value.\n return 'regex' in node || 'bigint' in node ? undefined : (node.value as OptionValue)\n case nodeTypes.templateLiteral:\n return node.expressions.length ? undefined : (node.quasis[0]?.value.cooked ?? '')\n case nodeTypes.unaryExpression: {\n const value = readLiteral(node.argument)\n if (typeof value !== 'number') return undefined\n if (node.operator === unaryOperators.minus) return -value\n if (node.operator === unaryOperators.plus) return value\n return undefined\n }\n case nodeTypes.arrayExpression: {\n const values = node.elements.map((element) => readLiteral(element))\n return values.every((value) => value !== undefined) ? values : undefined\n }\n case nodeTypes.objectExpression: {\n const entries: Record<string, OptionValue> = {}\n for (const entry of node.properties) {\n if (entry.type !== nodeTypes.property) return undefined\n const key = getKey(entry)\n const value = readLiteral(entry.value)\n // A `__proto__` key would replace the object's prototype instead of adding an entry.\n if (key === undefined || !isSafeKey(key) || value === undefined) return undefined\n entries[key] = value\n }\n return entries\n }\n }\n return undefined\n}\n\n// Imports and factory calls\n\nfunction getRequirePath(node: ValueNode): string | undefined {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier || node.callee.name !== identifiers.require) return undefined\n const [argument] = node.arguments\n return argument?.type === nodeTypes.literal && typeof argument.value === 'string' ? argument.value : undefined\n}\n\n/** `import { exported as local } from '...'`. A default or namespace import has no exported name, so its local name stands in. */\nfunction importBindings(statement: ImportDeclaration): Array<[string, Import]> {\n return statement.specifiers.map((specifier) => {\n const imported = specifier.type === nodeTypes.importSpecifier ? specifier.imported : specifier.local\n const exported = imported.type === nodeTypes.identifier ? imported.name : imported.value\n return [specifier.local.name, { from: statement.source.value, exported }]\n })\n}\n\n/** `const { exported: local } = require('...')`. */\nfunction requireBindings(statement: VariableDeclaration): Array<[string, Import]> {\n return statement.declarations.flatMap((declarator): Array<[string, Import]> => {\n const from = getRequirePath(declarator.init)\n if (from === undefined || declarator.id.type !== nodeTypes.objectPattern) return []\n\n return declarator.id.properties.flatMap((entry): Array<[string, Import]> => {\n if (entry.type !== nodeTypes.property || entry.value.type !== nodeTypes.identifier) return []\n return [[entry.value.name, { from, exported: getKey(entry) ?? entry.value.name }]]\n })\n })\n}\n\nfunction getImports(program: Program): Map<string, Import> {\n return new Map(\n program.body.flatMap((statement) => {\n if (statement.type === nodeTypes.importDeclaration) return importBindings(statement)\n if (statement.type === nodeTypes.variableDeclaration) return requireBindings(statement)\n return []\n }),\n )\n}\n\nfunction isImportStatement(node: Program['body'][number], kind: ModuleKind): boolean {\n if (kind === moduleKinds.esm) return node.type === nodeTypes.importDeclaration\n return node.type === nodeTypes.variableDeclaration && node.declarations.some((declarator) => getRequirePath(declarator.init) !== undefined)\n}\n\n/** The quote of the first string literal in the file, so new code matches it. */\nfunction detectQuote(node: unknown): Quote | undefined {\n if (!node || typeof node !== 'object') return undefined\n const { type, raw } = node as { type?: string; raw?: unknown }\n if (type === nodeTypes.literal && typeof raw === 'string' && (raw[0] === quotes.single || raw[0] === quotes.double)) return raw[0]\n for (const child of Object.values(node)) {\n const quote = detectQuote(child)\n if (quote) return quote\n }\n return undefined\n}\n\n/** The `adapter` value, or the elements of the `plugins` or `parsers` array. */\nfunction factoryNodes(config: ObjectExpression, kind: ExtensionKind): Array<ValueNode> {\n if (kind === extensionKinds.adapter) return [getValue(config, 'adapter')]\n const array = getValue(config, `${kind}s`)\n return array?.type === nodeTypes.arrayExpression ? array.elements : []\n}\n\n/** The factory calls of one kind whose callee the file imports. */\nfunction findCalls(program: Program, config: ObjectExpression, kind: ExtensionKind = extensionKinds.plugin): Array<FactoryCall> {\n const imports = getImports(program)\n return factoryNodes(config, kind).flatMap((node) => {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier) return []\n const imported = imports.get(node.callee.name)\n return imported ? [{ importName: node.callee.name, exportName: imported.exported, packageName: imported.from, call: node }] : []\n })\n}\n\n// Disabled plugins\n\n/** Whether nothing but whitespace precedes `offset` on its line. */\nfunction startsLine(source: string, offset: number): boolean {\n return source.slice(source.lastIndexOf('\\n', offset - 1) + 1, offset).trim() === ''\n}\n\n/** The `disable-plugin` blocks in this config, read from marker comments since the call is no longer a node. */\nfunction findDisabled(source: string, comments: Array<Comment>, config: ObjectExpression): Array<DisabledBlock> {\n const lines = source.split('\\n')\n\n return comments.flatMap((comment) => {\n const match = comment.type === commentTypes.line ? comment.value.trim().match(DISABLED_MARKER_PATTERN) : null\n // Only markers inside this entry, on a line of their own, so another entry or a trailing comment never matches.\n if (!match || comment.start < config.start || comment.end > config.end || !startsLine(source, comment.start)) return []\n\n const line = getPosition(source, comment.start).line\n const end = line + Number(match[2])\n const code = lines.slice(line, end).map((text) => text.replace(/^(\\s*)\\/\\/ ?/, '$1').replace(/^\\s+$/, ''))\n return [{ packageName: match[1]!, line, end, code }]\n })\n}\n\n// Reading options\n\n/** Literal members as `value` and code paths as `locked`, `undefined` for a computed key. */\nfunction readEditable(node: ObjectExpression, prefix: Array<string> = []): { value: Record<string, OptionValue>; locked: Array<Array<string>> } | undefined {\n const value: Record<string, OptionValue> = {}\n const locked: Array<Array<string>> = []\n\n for (const [index, entry] of node.properties.entries()) {\n if (entry.type === nodeTypes.spreadElement) continue\n const key = getKey(entry)\n if (key === undefined) return undefined\n if (findProperty(node, key)?.index !== index) continue\n\n const path = [...prefix, key]\n // A `__proto__` key replaces the prototype, so it reads as code.\n if (!isSafeKey(key)) {\n locked.push(path)\n continue\n }\n\n const member = isOverridden(node, index) ? undefined : entry.value\n const literal = readLiteral(member)\n if (literal !== undefined) {\n value[key] = literal\n continue\n }\n if (member?.type !== nodeTypes.objectExpression) {\n locked.push(path)\n continue\n }\n\n const nested = readEditable(member, path)\n if (!nested) return undefined\n value[key] = nested.value\n locked.push(...nested.locked)\n }\n return { value, locked }\n}\n\nfunction readObjectOptions(options: ObjectExpression): OptionsView {\n const entries: OptionsView = {}\n for (const [index, entry] of options.properties.entries()) {\n const key = getKey(entry)\n if (key === undefined || !isSafeKey(key)) continue\n\n const member = entry.type === nodeTypes.property && !isOverridden(options, index) ? entry.value : undefined\n const value = readLiteral(member)\n if (value !== undefined) {\n entries[key] = { literal: true, value }\n continue\n }\n entries[key] = { literal: false, ...(member?.type === nodeTypes.objectExpression ? readEditable(member) : undefined) }\n }\n return entries\n}\n\nfunction readCallOptions(call: CallExpression): OptionsView {\n const options = call.arguments[0]\n return options?.type === nodeTypes.objectExpression ? readObjectOptions(options) : {}\n}\n\nfunction readDisabledOptions(code: Array<string>): OptionsView {\n const call = parseExpression(code.join('\\n').trim().replace(/,$/, ''))\n return call?.type === nodeTypes.callExpression ? readCallOptions(call) : {}\n}\n\nfunction toPluginView({ importName, packageName, call }: FactoryCall): PluginView {\n return { importName, packageName, options: readCallOptions(call) }\n}\n\n/** Active and disabled plugins, in source order so a disabled plugin keeps its place. */\nfunction readPlugins({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): Array<PluginView> {\n const importNames = new Map([...getImports(parsed.program)].map(([local, { from }]) => [from, local]))\n\n const active = findCalls(parsed.program, config).map((call) => ({ line: getPosition(source, call.call.start).line, plugin: toPluginView(call) }))\n const disabled = findDisabled(source, parsed.comments, config).map(({ packageName, line, code }) => ({\n line,\n plugin: {\n importName: importNames.get(packageName) ?? toExportName(packageName),\n packageName,\n options: readDisabledOptions(code),\n disabled: true as const,\n },\n }))\n\n return [...active, ...disabled].sort((a, b) => a.line - b.line).map(({ plugin }) => plugin)\n}\n\nfunction readConfigView({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): ConfigView {\n const [adapter] = findCalls(parsed.program, config, extensionKinds.adapter).map(toPluginView)\n const parsers = findCalls(parsed.program, config, extensionKinds.parser).map(toPluginView)\n const output = getOutput(config)\n\n return {\n name: getConfigName(config),\n plugins: readPlugins({ source, parsed, config }),\n ...(adapter && { adapter }),\n ...(parsers.length ? { parsers } : {}),\n ...(!('reason' in output) && { output: pickOutput(readObjectOptions(output.object)) }),\n }\n}\n\n/** Which plugins the file declares and which options Studio may write. */\nexport function readConfig(source: string): ConfigFileView {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return { managed: false, reason: parsed.reason }\n\n return { managed: true, configs: parsed.configs.map((config) => readConfigView({ source, parsed, config })) }\n}\n\n/** The modules the file imports, empty when it cannot be parsed. */\nexport function readImports(source: string): Array<string> {\n const parsed = parseSource(source)\n if ('reason' in parsed) return []\n return [...new Set([...getImports(parsed.program).values()].map(({ from }) => from))]\n}\n\n// Editing options\n\ntype FoundPath = { object: ObjectExpression; index: number; value: Expression } | { object: ObjectExpression; missing: number } | { reason: string }\n\n/** Follows `path` to its literal, or to the first missing key. Refuses a value set in code. */\nfunction findPath(options: ObjectExpression, path: Array<string>): FoundPath {\n let object = options\n\n for (const [depth, key] of path.entries()) {\n const found = findProperty(object, key)\n if (!found) return { object, missing: depth }\n if (isOverridden(object, found.index)) {\n return { reason: `${path.slice(0, depth + 1).join('.')} can be overridden by a spread after it, so it is customized in code` }\n }\n\n const { member, index } = found\n const isLast = depth === path.length - 1\n if (isLast) {\n return member.type === nodeTypes.property && readLiteral(member.value) !== undefined\n ? { object, index, value: member.value }\n : { reason: `${path.join('.')} is customized in code` }\n }\n if (member.type !== nodeTypes.property || member.value.type !== nodeTypes.objectExpression) {\n return { reason: `${key} is not an object, so ${path.join('.')} cannot be reached` }\n }\n object = member.value\n }\n return { reason: 'no option path given' }\n}\n\nfunction setAtPath({\n source,\n options,\n path,\n value,\n quote,\n}: {\n source: string\n options: ObjectExpression\n path: Array<string>\n value: OptionValue\n quote: Quote\n}): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) {\n const [key, ...rest] = path.slice(target.missing)\n return { source: appendItem(source, target.object, `${printKey(key!, quote)}: ${printValue(wrapPath(rest, value), quote)}`) }\n }\n return { source: replaceText(source, target.value.start, target.value.end, printValue(value, quote)) }\n}\n\nfunction removeAtPath({ source, options, path }: { source: string; options: ObjectExpression; path: Array<string> }): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) return { source }\n return { source: removeItem(source, target.object, target.index) }\n}\n\nfunction setOption(source: string, call: CallExpression, path: Array<string>, value: unknown, quote: Quote): EditResult {\n if (!isOptionValue(value)) return { reason: 'the value is not a literal that can be written to a config file' }\n\n const options = call.arguments[0]\n if (!options) {\n const closing = call.end - 1\n if (source[closing] !== ')') return { reason: 'the factory call could not be located in the file' }\n return { source: replaceText(source, closing, closing, printValue(wrapPath(path, value), quote)) }\n }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return setAtPath({ source, options, path, value, quote })\n}\n\nfunction removeOption(source: string, call: CallExpression, path: Array<string>): EditResult {\n const options = call.arguments[0]\n if (!options) return { source }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return removeAtPath({ source, options, path })\n}\n\nfunction editOption({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: OptionEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n // A package can ship several factories (`parserTs`, `parserTsx`), so prefer the export its manifest names.\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const exportName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n const call = (calls.find((entry) => entry.exportName === exportName) ?? calls[0])?.call\n\n if (!call) {\n if (kind === extensionKinds.adapter) return { reason: `${edit.plugin} is not the config's adapter` }\n const disabled = kind === extensionKinds.plugin && findDisabled(source, parsed.comments, config).some((block) => block.packageName === edit.plugin)\n return { reason: disabled ? `${edit.plugin} is disabled, enable it first` : `${edit.plugin} is not in the ${kind}s array` }\n }\n\n if (edit.operation === ConfigEditOperation.SET_OPTION) return setOption(source, call, edit.path, edit.value, quote)\n return removeOption(source, call, edit.path)\n}\n\n// Editing the config's own fields\n\nfunction setInput(source: string, config: ObjectExpression, input: string, quote: Quote): EditResult {\n const value = printValue(input, quote)\n const found = findProperty(config, 'input')\n if (!found) return { source: appendItem(source, config, `input: ${value}`) }\n if (found.member.type !== nodeTypes.property || !isPlainProperty(found.member)) return { reason: 'input is not a plain property' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after input could override it' }\n return { source: replaceText(source, found.member.value.start, found.member.value.end, value) }\n}\n\nfunction getOutput(config: ObjectExpression): { object: ObjectExpression } | { reason: string } {\n const found = findProperty(config, 'output')\n if (found?.member.type !== nodeTypes.property || found.member.value.type !== nodeTypes.objectExpression) return { reason: 'output is not an object literal' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after output could override it' }\n return { object: found.member.value }\n}\n\nfunction editOutput({ source, config, edit, quote }: { source: string; config: ObjectExpression; edit: OutputEdit; quote: Quote }): EditResult {\n const output = getOutput(config)\n if ('reason' in output) return output\n if (edit.operation === ConfigEditOperation.REMOVE_OUTPUT) return removeAtPath({ source, options: output.object, path: edit.path })\n\n const [key, ...rest] = edit.path\n if (!isOptionValue(edit.value) || !isOutputValue({ key: key!, value: wrapPath(rest, edit.value) }))\n return { reason: `the value is not one output.${key} takes` }\n return setAtPath({ source, options: output.object, path: edit.path, value: edit.value, quote })\n}\n\n// Adding, disabling, and enabling plugins\n\n/** Adds the import after the last one, matching its semicolon style. */\nfunction addImport({\n source,\n parsed,\n importNames,\n moduleSpecifier,\n quote,\n}: {\n source: string\n parsed: ParsedConfig\n importNames: Array<string>\n moduleSpecifier: string\n quote: Quote\n}): string {\n const lastImport = parsed.program.body.findLast((node) => isImportStatement(node, parsed.kind))\n const afterLine = lastImport ? getPosition(source, lastImport.end).line : 0\n const lines = source.split('\\n')\n\n const semicolon = afterLine > 0 && lines[afterLine - 1]?.trimEnd().endsWith(';') ? ';' : ''\n const specifier = `${quote}${moduleSpecifier}${quote}`\n const statement =\n parsed.kind === moduleKinds.esm ? `import { ${importNames.join(', ')} } from ${specifier}` : `const { ${importNames.join(', ')} } = require(${specifier})`\n\n lines.splice(afterLine, 0, `${statement}${semicolon}`)\n if (afterLine === 0) lines.splice(1, 0, '')\n\n return lines.join('\\n')\n}\n\n/**\n * The parsers `defineConfig` applies when a config sets no `parsers`, by import name. Adding a parser\n * to such a config writes these too, or the new array would replace them.\n */\nconst DEFAULT_PARSERS = [\n { importName: 'parserTs', packageName: '@kubb/parser-ts' },\n { importName: 'parserTsx', packageName: '@kubb/parser-ts' },\n { importName: 'parserMd', packageName: '@kubb/parser-md' },\n] as const\n\n/**\n * Adds a plugin to `plugins`, or with `kind: 'parser'` a parser to `parsers`. Replaying the same add\n * is a no-op, while an import name taken by another package is an error.\n */\nfunction addPlugin({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: AddPluginEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n const isParser = kind === extensionKinds.parser\n if (!isAllowedPlugin({ packageName: edit.plugin, extensions, kind })) {\n return {\n reason: isParser ? `\"${edit.plugin}\" is not an installed Kubb parser` : `\"${edit.plugin}\" is not a @kubb/plugin-* package or an installed Kubb plugin`,\n }\n }\n\n const importName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n if (!IDENTIFIER_PATTERN.test(importName)) return { reason: `\"${importName}\" is not a valid import name` }\n // A package can ship several parsers (`parserTs` and `parserTsx`), so a parser is matched by its export too.\n if (findCalls(parsed.program, config, kind).some((entry) => entry.packageName === edit.plugin && (!isParser || entry.exportName === importName))) {\n return { source }\n }\n\n const options = edit.options ?? {}\n if (!isOptionValue(options)) return { reason: 'the options are not literals that can be written to a config file' }\n\n const key = `${kind}s`\n const array = getValue(config, key)\n if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` }\n // A config without `parsers` runs the defaults, so the new array lists them before the added parser.\n const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : []\n\n // The missing imports by package, so `parserTs` and `parserTsx` share one line.\n const imports = getImports(parsed.program)\n const missing = memo.create<string, Array<string>>()\n for (const item of [...defaults, { importName, packageName: edit.plugin }]) {\n const from = imports.get(item.importName)?.from\n if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` }\n if (!from) memo(missing, item.packageName, () => []).push(item.importName)\n }\n\n // The array sits below the imports, so adding to it first leaves the import lines where they are.\n const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ''})`\n const next =\n array?.type === nodeTypes.arrayExpression\n ? appendItem(source, array, call)\n : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(', ')}]`)\n\n return {\n source: [...missing].reduceRight(\n (current, [moduleSpecifier, importNames]) => addImport({ source: current, parsed, importNames, moduleSpecifier, quote }),\n next,\n ),\n }\n}\n\n/** One item per line, so a call can be commented out alone. Skipped when comments sit between items. */\nfunction splitPlugins(source: string, config: ObjectExpression): string | undefined {\n const array = getValue(config, 'plugins')\n if (array?.type !== nodeTypes.arrayExpression) return undefined\n\n const items = array.elements.flatMap((element) => (element ? [element] : []))\n const { start, end } = array\n const gaps = [source.slice(start + 1, items[0]?.start ?? end - 1), ...items.map((item, index) => source.slice(item.end, items[index + 1]?.start ?? end - 1))]\n if (!items.length || gaps.some((gap) => !/^[\\s,]*$/.test(gap))) return undefined\n\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n const lines = items.map((item) => `${indent} ${source.slice(item.start, item.end)},`)\n\n return replaceText(source, start, end, `[\\n${lines.join('\\n')}\\n${indent}]`)\n}\n\nfunction disablePlugin(source: string, program: Program, config: ObjectExpression, plugin: string): EditResult {\n const call = findCalls(program, config).find((entry) => entry.packageName === plugin)?.call\n if (!call) return { reason: `${plugin} is not in the plugins array` }\n\n const start = getPosition(source, call.start)\n const end = getPosition(source, call.end)\n const lines = source.split('\\n')\n const from = start.line - 1\n const to = end.line - 1\n const firstLine = lines[from] ?? ''\n\n // Only safe when the call sits alone on its lines: anything else on its first line, or on its last\n // line besides a trailing comma, would be swallowed into the comment and corrupt the file.\n if (firstLine.slice(0, start.column).trim() || !/^,?\\s*$/.test((lines[to] ?? '').slice(end.column))) {\n return { reason: `${plugin} shares a line with other code, so it cannot be commented out safely` }\n }\n\n const indent = firstLine.match(/^\\s*/)?.[0] ?? ''\n const commented = lines.slice(from, to + 1).map((line) => (line.trim() ? `${indent}// ${line.slice(indent.length)}` : `${indent}//`))\n lines.splice(from, commented.length, `${indent}// kubb:disabled ${plugin} ${commented.length}`, ...commented)\n\n return { source: lines.join('\\n') }\n}\n\n/** Disables the plugin, first putting a one-line `plugins: [a(), b()]` (what `add-plugin` writes) on separate lines. */\nfunction disablePluginInConfig({\n source,\n parsed,\n config,\n edit,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: DisablePluginEdit\n}): EditResult {\n const result = disablePlugin(source, parsed.program, config, edit.plugin)\n if (!('reason' in result) || !result.reason.includes('shares a line')) return result\n\n const split = splitPlugins(source, config)\n if (split === undefined) return result\n\n const reparsed = findConfigs(split)\n const reparsedConfig = 'reason' in reparsed ? undefined : findConfigEntry(reparsed.configs, edit.config)\n if ('reason' in reparsed || !reparsedConfig) return result\n\n return disablePlugin(split, reparsed.program, reparsedConfig, edit.plugin)\n}\n\nfunction enablePlugin(source: string, comments: Array<Comment>, config: ObjectExpression, plugin: string): EditResult {\n const block = findDisabled(source, comments, config).find((entry) => entry.packageName === plugin)\n if (!block) return { reason: `${plugin} is not disabled` }\n\n const lines = source.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1, ...block.code)\n return { source: lines.join('\\n') }\n}\n\n// Removing extensions\n\n/** Drops the import statements of `packageName` once nothing else in the file uses their names. */\nfunction removeUnusedImports(source: string, packageName: string): string {\n const parsed = parseSource(source)\n if ('reason' in parsed) return source\n\n // From the last statement up, so the offsets of the earlier ones stay valid.\n return parsed.program.body.reduceRight((current, statement) => {\n const bindings =\n statement.type === nodeTypes.importDeclaration\n ? importBindings(statement)\n : statement.type === nodeTypes.variableDeclaration\n ? requireBindings(statement)\n : []\n if (!bindings.length || bindings.some(([, { from }]) => from !== packageName)) return current\n\n const rest = replaceText(current, statement.start, statement.end)\n if (bindings.some(([local]) => new RegExp(`(?<![\\\\w$])${local.replaceAll('$', '\\\\$')}(?![\\\\w$])`).test(rest))) return current\n\n const lineStart = current.lastIndexOf('\\n', statement.start - 1) + 1\n const lineEnd = current.indexOf('\\n', statement.end)\n const after = lineEnd === -1 ? current.length : lineEnd + 1\n // At the top of the file, the blank line after the import goes too, so the file does not start with one.\n return replaceText(current, lineStart, lineStart === 0 && current[after] === '\\n' ? after + 1 : after)\n }, source)\n}\n\n/**\n * Removes every call of a plugin or parser package, and the block `disable-plugin` commented out,\n * then its unused imports. Removing what the config does not hold is a no-op. Refuses to empty\n * `parsers`, since a config with no parser cannot print files.\n */\nfunction removeExtension(source: string, edit: RemoveExtensionEdit): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n let current = source\n\n // One call at a time, re-parsing in between, since each removal moves the ones after it.\n for (;;) {\n const parsed = findConfigs(current)\n if ('reason' in parsed) return parsed\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n\n const array = getValue(config, `${kind}s`)\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const block = findDisabled(current, parsed.comments, config).find((entry) => entry.packageName === edit.plugin)\n\n if (calls[0] && array?.type === nodeTypes.arrayExpression) {\n const elements = array.elements.filter((element) => element !== null)\n if (kind === extensionKinds.parser && elements.length === calls.length) return { reason: `${edit.plugin} is the last parser in the parsers array` }\n current = removeItem(current, array, elements.indexOf(calls[0].call))\n continue\n }\n if (block && kind === extensionKinds.plugin) {\n const lines = current.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1)\n current = lines.join('\\n')\n continue\n }\n return { source: current === source ? source : removeUnusedImports(current, edit.plugin) }\n }\n}\n\n// Applying edits\n\n/** Every edit re-parses the file, since the previous one rewrote it. */\nfunction applyEdit({ source, edit, extensions }: { source: string; edit: ConfigEdit; extensions: InstalledExtensions }): EditResult {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return parsed\n\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n const quote = detectQuote(parsed.program) ?? quotes.single\n\n switch (edit.operation) {\n case ConfigEditOperation.SET_INPUT:\n return setInput(source, config, edit.input, quote)\n case ConfigEditOperation.SET_OUTPUT:\n case ConfigEditOperation.REMOVE_OUTPUT:\n return editOutput({ source, config, edit, quote })\n case ConfigEditOperation.DISABLE_PLUGIN:\n return disablePluginInConfig({ source, parsed, config, edit })\n case ConfigEditOperation.ENABLE_PLUGIN:\n return enablePlugin(source, parsed.comments, config, edit.plugin)\n case ConfigEditOperation.ADD_PLUGIN:\n return addPlugin({ source, parsed, config, edit, quote, extensions })\n case ConfigEditOperation.REMOVE_EXTENSION:\n return removeExtension(source, edit)\n case ConfigEditOperation.SET_OPTION:\n case ConfigEditOperation.REMOVE_OPTION:\n return editOption({ source, parsed, config, edit, quote, extensions })\n }\n}\n\n/** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */\nexport function editConfig({ source, edits, extensions = new Map() }: { source: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }): {\n source: string\n outcomes: Array<ConfigEditOutcome>\n changed: boolean\n} {\n let current = source\n\n const outcomes = edits.map((edit): ConfigEditOutcome => {\n const invalid = validateEdit(edit)\n if (invalid) return { edit, applied: false, reason: invalid }\n\n try {\n const result = applyEdit({ source: current, edit, extensions })\n if ('reason' in result) return { edit, applied: false, reason: result.reason }\n current = result.source\n return { edit, applied: true }\n } catch (error) {\n return { edit, applied: false, reason: getErrorMessage(error) }\n }\n })\n\n return { source: current, outcomes, changed: current !== source }\n}\n\n/** Applies `edits` to `filePath`, writing only when something changed. */\nexport async function editConfigFile({ filePath, edits, extensions }: { filePath: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }) {\n const current = await read(filePath)\n const result = editConfig({ source: current, edits, extensions })\n if (result.changed) await writeRaw(filePath, result.source)\n return result\n}\n"],"mappings":";;;;;;;;AAoBA,MAAa,YAAY;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,gBAAgB;CAChB,gBAAgB;CAChB,0BAA0B;CAC1B,qBAAqB;CACrB,oBAAoB;CACpB,YAAY;CACZ,mBAAmB;CACnB,iBAAiB;CACjB,SAAS;CACT,kBAAkB;CAClB,kBAAkB;CAClB,eAAe;CACf,UAAU;CACV,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,uBAAuB;CACvB,iBAAiB;CACjB,iBAAiB;CACjB,qBAAqB;AACvB;AAEA,MAAa,eAAe,EAAE,MAAM,OAAO;AAC3C,MAAa,gBAAgB,EAAE,MAAM,OAAO;AAC5C,MAAa,iBAAiB;CAAE,OAAO;CAAK,MAAM;AAAI;AACtD,MAAM,uBAAuB,EAAE,OAAO,QAAQ;;;;;AAS9C,SAAgB,YAAY,QAA8B;CACxD,IAAI;EAEF,MAAM,EAAE,SAAS,UAAU,gBAAgB,MAAM,QAAQ;GAAE,MAAM;GAAM,YAAY;GAAU,gBAAgB;EAAM,CAAC;EACpH,IAAI,YAAY,MAAM,eAAe,WAAW,aAAa,qBAAqB,KAAK,GAAG,OAAO,EAAE,QAAQ,sCAAsC;EACjJ,OAAO;GAAE;GAAS;EAAS;CAC7B,SAAS,OAAO;EACd,OAAO,EAAE,QAAQ,sD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":3,"file":"package-CcsdQpSf.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-DM5mr0Yc.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-6qjg9Twy.cjs","names":["process","isCIEnvironment","x","isCIEnvironment","process","createSpinner","pairAgent","path","process","hostname","getMachineId","styleText","isRichOutput","writeCredentials","getCredentialsPath","PairingCanceledError","AgentPermission","toPermissionFlag","KUBB_CONFIG_FILENAME","isCIEnvironment","canUseTTY","prompts","getConfigs","Diagnostics","readCredentials","Hookable","logLevelMap","cliReporter","plainWriter","connectAgent","InvalidAgentTokenError","clearCredentials","defaultStudioUrl","trackRun","toError"],"sources":["../../../internals/utils/src/copyToClipboard.ts","../../../internals/utils/src/openInBrowser.ts","../src/runners/studio/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { x } from 'tinyexec'\nimport { isCIEnvironment } from './isCIEnvironment.ts'\n\nconst COMMANDS: Partial<Record<NodeJS.Platform, [string, ...Array<string>]>> = {\n darwin: ['pbcopy'],\n win32: ['clip.exe'],\n linux: ['xclip', '-selection', 'clipboard'],\n}\n\n/**\n * Copies text to the system clipboard with the platform's own tool. Resolves `false` in CI, on a\n * platform without a known tool, or when the tool is missing or fails.\n */\nexport async function copyToClipboard(text: string): Promise<boolean> {\n // Wayland sessions have no X selection for xclip to serve, so they use `wl-copy`.\n const command = process.platform === 'linux' && process.env.WAYLAND_DISPLAY ? (['wl-copy'] as const) : COMMANDS[process.platform]\n if (!command || isCIEnvironment()) return false\n\n const [name, ...args] = command\n // stdout and stderr are ignored: xclip and wl-copy stay alive to serve the selection and would hold open pipes until the timeout.\n const run = x(name, args, { timeout: 2_000, nodeOptions: { stdio: ['pipe', 'ignore', 'ignore'] } })\n // A missing tool closes stdin before the write lands; the rejection below reports it.\n run.process?.stdin?.once('error', () => {})\n run.process?.stdin?.end(text)\n\n return run.then(\n ({ exitCode }) => exitCode === 0,\n () => false,\n )\n}\n","import process from 'node:process'\nimport { x } from 'tinyexec'\nimport { isCIEnvironment } from './isCIEnvironment.ts'\n\nconst ignore = () => {}\n\n/**\n * Opens a URL or local file in the default browser, unless running in CI.\n */\nexport function openInBrowser(target: string): void {\n if (isCIEnvironment()) return\n\n if (process.platform === 'win32') {\n x('cmd', ['/c', 'start', '', target]).then(ignore, ignore)\n return\n }\n x(process.platform === 'darwin' ? 'open' : 'xdg-open', [target]).then(ignore, ignore)\n}\n","import { hostname } from 'node:os'\nimport { toPermissionFlag } from '../../ui/text.ts'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as prompts from '@clack/prompts'\nimport { KUBB_CONFIG_FILENAME } from '@internals/shared'\nimport { copyToClipboard, isCIEnvironment, openInBrowser, toError } from '@internals/utils'\nimport type { CLIOptions, Config } from '@kubb/core'\nimport { cliReporter, Diagnostics, Hookable, type KubbHooks, logLevel as logLevelMap } from '@kubb/core'\nimport { connectAgent, defaultStudioUrl, InvalidAgentTokenError, pairAgent, PairingCanceledError } from '@kubb/studio'\nimport { AgentPermission } from '@kubb/studio/protocol'\nimport { trackRun } from '../../Telemetry.ts'\nimport { plainWriter } from '../../loggers/plainWriter.ts'\nimport setupReporters from '../../loggers/reporters.ts'\nimport { logIntro, logOutro, logTip } from '../../ui/intro.ts'\nimport { logBlock, logStep } from '../../ui/log.ts'\nimport { createSpinner } from '../../ui/spinner.ts'\nimport { canUseTTY, isRichOutput } from '../../utils/env.ts'\nimport { getConfigs } from '../../config.ts'\nimport { clearCredentials, type Credentials, getCredentialsPath, getMachineId, readCredentials, writeCredentials } from './credentials.ts'\nimport { version } from '../../../package.json'\n\nexport type StudioOptions = {\n /**\n * Current `@kubb/cli` version, reported to Studio and used for the telemetry payload.\n */\n version: string\n configPath?: string\n /**\n * Base URL of the Studio instance, for a self-hosted deployment. Resolved before it reaches here,\n * since stored credentials are bound to it.\n */\n studioUrl: string\n /**\n * What Studio may do in this project. Each flag grants outright; the rest are asked once per\n * project through {@link resolvePermissions}.\n */\n permission: Record<AgentPermission, boolean>\n /**\n * Whether to open the approval page in a browser during pairing.\n */\n autoOpen: boolean\n logLevel?: CLIOptions['logLevel']\n}\n\nexport type SnapshotOptions = Pick<StudioOptions, 'configPath' | 'studioUrl' | 'logLevel'> & {\n /**\n * Organization CI API key. Falls back to `KUBB_TOKEN`.\n */\n token?: string\n /**\n * Stable identity for the CI agent. Falls back to CI auto-detection.\n */\n id?: string\n /** Identity of another CI agent to also compare with. Falls back to CI auto-detection. */\n baseId?: string\n /**\n * Package name for the generated tarball. Falls back to the nearest package.json.\n */\n name?: string\n /**\n * Package version for the generated tarball. Falls back to the nearest package.json.\n */\n packageVersion?: string\n /**\n * Print the result as one JSON object instead of a summary.\n */\n json?: boolean\n}\n\n/** The flags a `kubb studio` subcommand parsed; each one is optional since a subcommand declares only the flags it uses. */\nexport type StudioValues = {\n config?: string\n url?: string\n allowRead?: boolean\n allowReadAst?: boolean\n allowWrite?: boolean\n allowConfigEdit?: boolean\n allowInstall?: boolean\n allowUpdate?: boolean\n allowRemove?: boolean\n allowSaveInput?: boolean\n allowExec?: boolean\n open?: boolean\n logLevel?: CLIOptions['logLevel']\n}\n\ntype LoginOptions = {\n /**\n * Aborting this cancels an in-flight pairing request or poll and rejects with\n * {@link PairingCanceledError}. Wired to `kubb studio`'s shutdown signal, so Ctrl+C during\n * pairing cancels it instead of leaving the poll running.\n */\n signal?: AbortSignal\n /**\n * Credentials from before this login. When the fresh pairing resolves to the same agent on the\n * same Studio, its saved project permissions carry forward instead of being asked again.\n * Left out for an explicitly requested `kubb studio login`, which always starts clean.\n */\n previousCredentials?: Credentials | null\n}\n\n/**\n * Pairs this machine with Studio and stores the resulting token.\n *\n * The CLI holds a code and the browser approves it, rather than the user copying a token out of\n * the UI. The token comes back over the CLI's own HTTPS POST, so it never lands in a URL, a\n * server log, or a `Referer` header.\n */\nexport async function login({ studioUrl, autoOpen }: StudioOptions, { signal, previousCredentials }: LoginOptions = {}): Promise<Credentials> {\n const spinner = createSpinner()\n // A retry notice stays on screen a while before the countdown takes the line back.\n let retryUntil = 0\n // The spinner only starts once a code is shown.\n let waiting = false\n let countdown: NodeJS.Timeout | undefined\n\n try {\n const { token, agent } = await pairAgent({\n studioUrl,\n type: 'cli',\n name: path.basename(process.cwd()),\n hostname: hostname(),\n machineId: await getMachineId(),\n signal,\n onCode: (session) => {\n logStep(\n [\n 'Pair this machine',\n `${styleText('dim', 'Open')} ${styleText('cyan', session.verification_uri)}`,\n `${styleText('dim', 'Code')} ${styleText('bold', session.user_code)}`,\n ].join('\\n'),\n )\n\n if (autoOpen) {\n openInBrowser(session.verification_uri_complete)\n }\n\n // Same fallback as the poll in `@kubb/studio`, so the countdown ends when polling does.\n const deadline = Date.now() + (session.expires_in > 0 ? session.expires_in : 600) * 1000\n let copied = false\n const waitingText = () =>\n `Waiting for approval ${styleText('dim', `expires in ${formatCountdown(deadline - Date.now())}${copied ? ' · code copied' : ''} · ctrl+c to cancel`)}`\n clearInterval(countdown)\n spinner.start(waitingText())\n waiting = true\n // Plain output prints every message, so only an animated spinner ticks.\n if (isRichOutput()) countdown = setInterval(() => Date.now() > retryUntil && spinner.message(waitingText()), 1000)\n // Not awaited: the code shows at once, and the spinner picks up the copy when it lands.\n void copyToClipboard(session.user_code).then((done) => {\n copied = done\n })\n },\n onRetry: (error) => {\n retryUntil = Date.now() + 5000\n spinner.message(`Could not reach Kubb Studio, retrying: ${error.message}`)\n },\n })\n clearInterval(countdown)\n spinner.stop(`Paired as ${agent.name}${agent.organizationSlug ? ` · org ${agent.organizationSlug}` : ''}`)\n\n const keepsIdentity = previousCredentials?.studioUrl === studioUrl && previousCredentials.agentId === agent.id\n const credentials: Credentials = {\n studioUrl,\n token,\n agentId: agent.id,\n agentSlug: agent.slug,\n ...(agent.organizationSlug ? { organizationSlug: agent.organizationSlug } : {}),\n ...(keepsIdentity && previousCredentials?.projects ? { projects: previousCredentials.projects } : {}),\n }\n await writeCredentials(credentials)\n\n console.log(`Credentials stored in ${getCredentialsPath()}`)\n\n return credentials\n } catch (error) {\n clearInterval(countdown)\n if (waiting) {\n spinner.stop(error instanceof PairingCanceledError ? 'Pairing canceled' : 'Pairing failed')\n }\n throw error\n }\n}\n\n/** Time left on a pairing code as `m:ss`, never below `0:00`. */\nexport function formatCountdown(ms: number): string {\n const seconds = Math.max(0, Math.ceil(ms / 1000))\n\n return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`\n}\n\n/**\n * What each permission is asked as, in the order the list shows them.\n */\nconst PERMISSIONS: ReadonlyArray<{\n key: AgentPermission\n /**\n * Short label for status output and the connect summary.\n */\n label: string\n title: (configPath: string) => string\n hint: string\n}> = [\n { key: AgentPermission.READ, label: 'read source', title: () => 'Read generated files', hint: 'show code in the browser' },\n { key: AgentPermission.READ_AST, label: 'read spec', title: () => 'Read the parsed spec', hint: 'browse schemas and operations' },\n { key: AgentPermission.WRITE, label: 'write files', title: () => 'Write files to disk', hint: 'generate from the browser' },\n { key: AgentPermission.CONFIG_EDIT, label: 'edit config', title: (configPath) => `Change ${configPath}`, hint: 'edit plugin options' },\n { key: AgentPermission.INSTALL, label: 'add plugins', title: () => 'Install extensions from the registry', hint: 'kubb add from the browser' },\n { key: AgentPermission.UPDATE, label: 'update plugins', title: () => 'Update installed extensions', hint: 'kubb update from the browser' },\n { key: AgentPermission.REMOVE, label: 'remove plugins', title: () => 'Remove extensions', hint: 'kubb remove from the browser' },\n {\n key: AgentPermission.SAVE_INPUT,\n label: 'save input',\n title: (configPath) => `Save the spec from Studio as the input in ${configPath}`,\n hint: 'keep a pasted spec, URL, or git file',\n },\n { key: AgentPermission.EXEC, label: 'run tools', title: () => 'Run the formatter, linter, and postGenerate', hint: 'after each generation' },\n]\n\n/**\n * Two permissions per row, each marked granted or not, with the flags that grant the missing ones\n * after the last row. For `kubb studio status`.\n */\nexport function formatPermissionRows(granted: Partial<Record<AgentPermission, boolean>>): Array<string> {\n const width = Math.max(...PERMISSIONS.map(({ label }) => label.length))\n const cells = PERMISSIONS.map(({ key, label }) => `${granted[key] ? styleText('green', '✓') : styleText('red', '✖')} ${label.padEnd(width)}`)\n const rows = Array.from({ length: Math.ceil(cells.length / 2) }, (_, index) => cells.slice(index * 2, index * 2 + 2).join(' '))\n const flags = PERMISSIONS.filter(({ key }) => !granted[key])\n .map(({ key }) => toPermissionFlag(key))\n .join(' ')\n\n return flags ? [...rows.slice(0, -1), `${rows.at(-1)} ${styleText('dim', flags)}`] : rows\n}\n\n/**\n * Resolves Studio permissions for the current project.\n * Flags win, saved answers are reused, and the rest are asked in one list whose answers are stored\n * in `~/.kubb/credentials.json`.\n */\nexport async function resolvePermissions(\n options: StudioOptions,\n credentials: Credentials,\n configPath: string = KUBB_CONFIG_FILENAME,\n { edit = false }: { edit?: boolean } = {},\n): Promise<Record<AgentPermission, boolean>> {\n const project = process.cwd()\n const remembered = credentials.projects?.[project]\n const granted = Object.fromEntries(PERMISSIONS.map(({ key }) => [key, options.permission[key] || remembered?.[key] === true])) as Record<\n AgentPermission,\n boolean\n >\n // `edit` asks again for every permission no flag grants, with the saved ones checked.\n const pending = PERMISSIONS.filter(({ key }) => !options.permission[key] && (edit || typeof remembered?.[key] !== 'boolean'))\n\n if (!pending.length || isCIEnvironment() || !canUseTTY()) return granted\n\n prompts.updateSettings({ withGuide: true })\n const selected = await prompts.multiselect({\n message: 'What may Kubb Studio do in this project?',\n options: pending.map(({ key, title, hint }) => ({ value: key, label: title(configPath), hint })),\n ...(edit ? { initialValues: pending.filter(({ key }) => remembered?.[key] === true).map(({ key }) => key) } : {}),\n required: false,\n })\n // A canceled list grants nothing and saves nothing, so the next run asks again.\n if (prompts.isCancel(selected)) {\n if (edit) throw new Error('Canceled. Permissions are unchanged.')\n return granted\n }\n\n const answers = Object.fromEntries(pending.map(({ key }) => [key, selected.includes(key)]))\n await writeCredentials({\n ...credentials,\n projects: { ...credentials.projects, [project]: { ...remembered, ...answers } },\n })\n\n return { ...granted, ...answers }\n}\n\n/**\n * Loads the project's Kubb config the same way `kubb generate` does, one entry per `defineConfig(...)` entry.\n */\nexport async function loadConfigs(options: Pick<StudioOptions, 'configPath' | 'logLevel'>): Promise<{ configPath: string; configs: Array<Config> }> {\n const { configPath, configs } = await getConfigs({ configPath: options.configPath, logLevel: options.logLevel })\n\n if (!configs.length) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Config not defined, create a kubb.config.ts or pass it with --config',\n })\n }\n\n // `getConfigs` resolves this to an absolute path. Relativized here, once, so the permission\n // prompt and the path Studio receives over the wire both show the project-relative form instead\n // of leaking the local filesystem layout.\n return { configPath: path.relative(process.cwd(), configPath) || configPath, configs }\n}\n\nexport type PreparedConnection = {\n configPath: string\n credentials: Credentials\n permissions: StudioOptions['permission']\n}\n\n/** Validates the project and resolves pairing and permissions before starting its worker. */\nexport async function prepareConnection(options: StudioOptions, signal?: AbortSignal): Promise<PreparedConnection> {\n const { configPath } = await loadConfigs(options)\n const stored = await readCredentials()\n const credentials = await (async () => {\n if (stored?.studioUrl === options.studioUrl) return stored\n if (isCIEnvironment()) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Not paired with ${options.studioUrl}. In CI, run \\`kubb studio snapshot\\` instead, or run \\`kubb studio login\\` on a machine with a browser.`,\n })\n }\n return login(options, { signal })\n })()\n const permissions = await resolvePermissions(options, credentials, configPath)\n return { configPath, credentials, permissions }\n}\n\nexport type WorkerState = 'starting' | 'connected' | 'reconnecting' | 'authentication required' | 'stopped'\n\n/** Runs the same project connection in the foreground or in a background worker. */\nexport async function connect(\n options: StudioOptions,\n context: {\n prepared?: PreparedConnection\n signal?: AbortSignal\n onState?: (state: WorkerState) => void | Promise<void>\n } = {},\n): Promise<void> {\n const shutdown = new AbortController()\n const signal = context.signal ?? shutdown.signal\n const stop = () => shutdown.abort()\n const events = process as unknown as NodeJS.EventEmitter\n if (!context.signal) {\n events.once('SIGINT', stop)\n events.once('SIGTERM', stop)\n }\n let unwatch: (() => void) | undefined\n try {\n if (!context.prepared) {\n const { getWorkerStatus } = await import('./background.ts')\n const worker = await getWorkerStatus()\n if (worker.running)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'This project is running in the background. Run `kubb studio stop` first.',\n })\n }\n const prepared = context.prepared ?? (await prepareConnection(options, signal))\n let { credentials, permissions } = prepared\n const { configPath } = prepared\n let hinted = false\n // Set by a fresh pairing until it connects, so a token rejected right after approval fails the run instead of looping.\n let pairedAgain = false\n\n // The background worker writes to a log file, so it gets the plain logger rather than the\n // animated one. The logger also covers the `studio:*` events and each generation run.\n const hooks = new Hookable<KubbHooks>()\n setupReporters(hooks, {\n logLevel: logLevelMap[options.logLevel ?? 'info'],\n reporters: [cliReporter],\n ...(context.onState ? { writer: plainWriter } : {}),\n })\n // `b` hands the session to the background worker; only a foreground run in a terminal listens.\n const listens = !context.onState && process.stdin.isTTY === true && canUseTTY()\n let background = false\n hooks.hook('studio:connected', async () => {\n pairedAgain = false\n await context.onState?.('connected')\n if (listens && !unwatch) {\n unwatch = watchKeys({\n onBackground: () => {\n background = true\n stop()\n },\n onStop: stop,\n })\n }\n if (hinted || context.onState || options.logLevel === 'silent') return\n hinted = true\n logBlock([\n `${styleText('dim', 'Project')} ${path.basename(process.cwd())} ${styleText(\n 'dim',\n PERMISSIONS.filter(({ key }) => permissions[key])\n .map(({ label }) => label)\n .join(' · ') || 'no permissions',\n )}`,\n styleText('dim', listens ? 'Press b to keep running in the background, Ctrl+C to disconnect' : 'Press Ctrl+C to disconnect'),\n ])\n logTip()\n })\n hooks.hook('studio:reconnecting', () => context.onState?.('reconnecting'))\n\n for (;;) {\n try {\n await connectAgent({\n token: credentials.token,\n studioUrl: options.studioUrl,\n configPath,\n version: options.version,\n root: process.cwd(),\n permissions,\n loadConfigs: async () => (await loadConfigs(options)).configs,\n hooks,\n signal,\n })\n break\n } catch (error) {\n if (!(error instanceof InvalidAgentTokenError)) throw error\n await context.onState?.('authentication required')\n await clearCredentials()\n if (pairedAgain) throw new Error(`${error.message} Studio rejected the newly approved token too. Run \\`kubb studio login\\` and try again.`)\n if (context.onState || isCIEnvironment() || !canUseTTY()) throw new Error(`${error.message} Run \\`kubb studio login\\` to pair again.`)\n\n // The pairing prompts need stdin back.\n unwatch?.()\n unwatch = undefined\n console.log(styleText('yellow', `${error.message} Pairing again...`))\n credentials = await login(options, { signal, previousCredentials: credentials })\n pairedAgain = true\n permissions = await resolvePermissions(options, credentials, configPath)\n }\n }\n // Stops the \"Ready for jobs\" spinner, which would otherwise keep drawing under the closing line.\n await hooks.callHook('kubb:lifecycle:end')\n unwatch?.()\n if (background) {\n const { startWorker } = await import('./background.ts')\n await startWorker(options)\n if (options.logLevel !== 'silent') logOutro('Running in the background · kubb studio stop')\n return\n }\n if (!context.onState && signal.aborted && options.logLevel !== 'silent') logOutro('Disconnected')\n } catch (error) {\n if (!(error instanceof PairingCanceledError)) throw error\n } finally {\n unwatch?.()\n events.off('SIGINT', stop)\n events.off('SIGTERM', stop)\n }\n}\n\n/**\n * Listens for single keys on a TTY stdin. Raw mode turns Ctrl+C into a key instead of SIGINT, so it\n * is handled here too. Returns the function that restores the terminal, safe to call twice.\n */\nexport function watchKeys({ onBackground, onStop }: { onBackground: () => void; onStop: () => void }): () => void {\n const stdin = process.stdin\n const onData = (data: Buffer) => {\n const key = data.toString()\n if (key === 'b' || key === 'B') onBackground()\n if (key === '\\u0003') onStop()\n }\n // A clack spinner reads stdin too and exits the process on Ctrl+C, before the session can close\n // its socket, so its Ctrl+C alias is lifted while these keys are read.\n const cancelAlias = prompts.settings.aliases.get('\\u0003')\n prompts.settings.aliases.delete('\\u0003')\n stdin.setRawMode(true)\n stdin.on('data', onData)\n stdin.resume()\n let restored = false\n\n return () => {\n if (restored) return\n restored = true\n if (cancelAlias) prompts.settings.aliases.set('\\u0003', cancelAlias)\n stdin.off('data', onData)\n stdin.setRawMode(false)\n stdin.pause()\n }\n}\n\n/**\n * Runs a Studio command from its parsed flags: builds the {@link StudioOptions}, prints the intro,\n * and reports the run to telemetry. A failure is printed and sets the exit code instead of throwing.\n */\nexport async function runStudio(\n values: StudioValues,\n action: (options: StudioOptions) => Promise<unknown>,\n { block = false, json = false }: { block?: boolean; json?: boolean } = {},\n): Promise<void> {\n const options: StudioOptions = {\n version,\n configPath: values.config,\n studioUrl: values.url ?? defaultStudioUrl,\n permission: Object.fromEntries(Object.values(AgentPermission).map((key) => [key, values[key] ?? false])) as Record<AgentPermission, boolean>,\n autoOpen: values.open ?? true,\n logLevel: values.logLevel,\n }\n const report = trackRun({ command: 'studio', hrStart: process.hrtime() })\n\n try {\n if (options.logLevel !== 'silent' && !json) {\n logIntro({\n warning: styleText('yellow', 'This feature is still under development, use with caution'),\n block,\n })\n }\n\n await action(options)\n\n await report({ status: 'success' })\n } catch (error) {\n await report({ status: 'failed' })\n console.error(toError(error).message)\n process.exitCode = 1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,WAAyE;CAC7E,QAAQ,CAAC,QAAQ;CACjB,OAAO,CAAC,UAAU;CAClB,OAAO;EAAC;EAAS;EAAc;CAAW;AAC5C;;;;;AAMA,eAAsB,gBAAgB,MAAgC;CAEpE,MAAM,UAAUA,aAAAA,QAAQ,aAAa,WAAWA,aAAAA,QAAQ,IAAI,kBAAmB,CAAC,SAAS,IAAc,SAASA,aAAAA,QAAQ;CACxH,IAAI,CAAC,WAAWC,wBAAAA,gBAAgB,GAAG,OAAO;CAE1C,MAAM,CAAC,MAAM,GAAG,QAAQ;CAExB,MAAM,OAAA,GAAMC,SAAAA,EAAAA,CAAE,MAAM,MAAM;EAAE,SAAS;EAAO,aAAa,EAAE,OAAO;GAAC;GAAQ;GAAU;EAAQ,EAAE;CAAE,CAAC;CAElG,IAAI,SAAS,OAAO,KAAK,eAAe,CAAC,CAAC;CAC1C,IAAI,SAA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