[{"data":1,"prerenderedAt":352},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions":3},{"id":4,"title":5,"body":6,"description":336,"extension":337,"frontmatter":338,"heading":5,"meta":343,"navigation":345,"order":326,"path":346,"seo":347,"sitemap":348,"source":349,"stem":350,"__hash__":351},"docs\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions.md","Extension model",{"type":7,"value":8,"toc":321},"minimark",[9,28,33,133,140,144,164,167,172,175,178,186,190,205,221,224,228,247,255,259,262,273,277,280,292,296,314],[10,11,12,13,18,19,23,24,27],"p",{},"Use an existing ",[14,15,17],"a",{"href":16},"\u002Fextensions\u002Fkind\u002Fplugins","plugin"," when it generates the output you need. To add an output or replace a pipeline layer, build on ",[20,21,22],"code",{},"kubb\u002Fkit",", a subpath of the ",[20,25,26],{},"kubb"," package.",[29,30,32],"h2",{"id":31},"choose-an-extension","Choose an extension",[34,35,36,52],"table",{},[37,38,39],"thead",{},[40,41,42,46,49],"tr",{},[43,44,45],"th",{},"You need to change",[43,47,48],{},"Extension",[43,50,51],{},"Why",[53,54,55,67,78,89,100,111,122],"tbody",{},[40,56,57,61,64],{},[58,59,60],"td",{},"Input format",[58,62,63],{},"Adapter",[58,65,66],{},"Translate the format into Kubb's shared AST.",[40,68,69,72,75],{},[58,70,71],{},"Schema meaning before generation",[58,73,74],{},"Macro",[58,76,77],{},"Transform nodes before the plugin processes them.",[40,79,80,83,86],{},[58,81,82],{},"Generated names or paths",[58,84,85],{},"Resolver",[58,87,88],{},"Keep declarations and imports consistent.",[40,90,91,94,97],{},[58,92,93],{},"Code emitted for a schema type",[58,95,96],{},"Printer",[58,98,99],{},"Change one output target without changing the input model.",[40,101,102,105,108],{},[58,103,104],{},"A new kind of output",[58,106,107],{},"Plugin and generators",[58,109,110],{},"Choose the files and content to generate.",[40,112,113,116,119],{},[58,114,115],{},"File syntax or assembly",[58,117,118],{},"Parser",[58,120,121],{},"Convert emitted nodes into source text.",[40,123,124,127,130],{},[58,125,126],{},"Where files are stored",[58,128,129],{},"Storage",[58,131,132],{},"Reuse generation with another destination.",[10,134,135,136,139],{},"For example, turning a date into a TypeScript ",[20,137,138],{},"Date"," type is a printer customization. Moving model files into a folder is a resolver customization. Changing a schema before several generators consume it calls for a macro. Macros run before printer handlers, so a macro change is visible to every output target while a printer change stays in one.",[29,141,143],{"id":142},"plugins","Plugins",[10,145,146,147,150,151,154,155,159,160,163],{},"A plugin factory returns a name, options, and lifecycle hooks. It registers generators and a resolver during ",[20,148,149],{},"kubb:plugin:setup",", then produces files during generation. Setup can use the setup context through its ",[20,152,153],{},"ctx"," argument or through ",[14,156,158],{"href":157},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins#setup-context","composables"," such as ",[20,161,162],{},"addGenerator()",", which work in any function setup calls.",[165,166],"plugin-anatomy",{},[168,169,171],"h3",{"id":170},"lifecycle","Lifecycle",[10,173,174],{},"Setup runs once per plugin. Kubb then walks schemas and operations, invokes generators, collects files, and runs output passes. Hooks let a plugin observe or change specific stages.",[176,177],"lifecycle-timeline",{},[10,179,180,181,185],{},"The ",[14,182,184],{"href":183},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks","lifecycle reference"," lists the firing order and payloads.",[168,187,189],{"id":188},"dependencies","Dependencies and ordering",[10,191,192,193,196,197,200,201,204],{},"Declared dependencies run before their dependents. Kubb uses ",[20,194,195],{},"enforce: 'pre'",", normal plugins, then ",[20,198,199],{},"enforce: 'post'"," and declaration order to break ties. Dependencies take priority over ",[20,202,203],{},"enforce",".",[10,206,207,208,211,212,215,216,220],{},"A plugin declares its dependencies as a record keyed by plugin name. A missing required entry fails the run with ",[20,209,210],{},"KUBB_MISSING_DEPENDENCY"," before any plugin runs, and an ",[20,213,214],{},"optional: true"," entry is skipped when its plugin is missing. See ",[14,217,219],{"href":218},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fextensions#dependencies","Extensions",". Resolvers let cooperating plugins read each other's names and paths instead of guessing them.",[10,222,223],{},"Post-enforced plugins can process other plugins' emitted files. The built-in barrel plugin uses this to generate re-exports.",[29,225,227],{"id":226},"generators","Generators",[10,229,230,231,234,235,238,239,242,243,246],{},"A generator handles ",[20,232,233],{},"schema"," nodes, ",[20,236,237],{},"operation"," nodes, or the complete ",[20,240,241],{},"operations"," batch. Splitting output into generators keeps each task separate. An optional ",[20,244,245],{},"match"," predicate filters schema and operation handlers. It does not filter the batch handler.",[10,248,249,250,254],{},"Generators return files directly or elements for a renderer. See ",[14,251,253],{"href":252},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fgenerators","Generator reference"," for handler signatures and context properties.",[29,256,258],{"id":257},"resolvers","Resolvers",[10,260,261],{},"A resolver determines identifiers, filenames, and paths. Generators use the active resolver, and dependent plugins read it to import the correct output.",[10,263,264,265,268,269,204],{},"The plugin's ",[20,266,267],{},"resolver"," option patches its defaults. Use it to rename or relocate output. Use macros to change the underlying schema. See ",[14,270,272],{"href":271},"\u002Fdocs\u002F5.x\u002Fhow-to\u002Fresolvers","Override a resolver",[29,274,276],{"id":275},"macros","Macros and printers",[10,278,279],{},"Macros rewrite the AST before generation. Printers turn schema nodes into output for one target, such as TypeScript types or Zod expressions.",[10,281,282,283,287,288,204],{},"Use a macro when the schema meaning changes. Override a printer when one target needs different code. See ",[14,284,286],{"href":285},"\u002Fdocs\u002F5.x\u002Fhow-to\u002Fmacros","Write a macro"," and ",[14,289,291],{"href":290},"\u002Fdocs\u002F5.x\u002Fhow-to\u002Fprinters","Override a printer",[29,293,295],{"id":294},"renderers","Renderers",[10,297,298,299,302,303,306,307,310,311,204],{},"Generators can build ",[20,300,301],{},"FileNode","s with ",[20,304,305],{},"ast.factory"," or return elements that a renderer converts into files. ",[20,308,309],{},"kubb\u002Fjsx"," provides the JSX renderer without React. Enable it per generator through ",[20,312,313],{},"renderer",[10,315,316,317,204],{},"A custom renderer is useful for another templating format. Direct node builders need no renderer. See ",[14,318,320],{"href":319},"\u002Fdocs\u002F5.x\u002Freference\u002Fjsx#renderers","JSX reference",{"title":322,"searchDepth":323,"depth":323,"links":324},"",5,[325,327,332,333,334,335],{"id":31,"depth":326,"text":32},2,{"id":142,"depth":326,"text":143,"children":328},[329,331],{"id":170,"depth":330,"text":171},3,{"id":188,"depth":330,"text":189},{"id":226,"depth":326,"text":227},{"id":257,"depth":326,"text":258},{"id":275,"depth":326,"text":276},{"id":294,"depth":326,"text":295},"Understand plugin lifecycles, generators, resolvers, macros, and renderers when extending Kubb.","md",{"layout":339,"title":5,"description":336,"outline":340,"order":326,"navigation":341},"doc",[326,330],{"title":5,"icon":342},"i-iconoir-ev-plug",{"layout":339,"outline":344},[326,330],{"title":5,"icon":342},"\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions",{"title":5,"description":336},{"loc":346},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions.md","docs\u002F5.x\u002Fexplanation\u002Fextensions","Tk7UYFGmuqkkIimlcf3HYucH2A0EmJbeFFXjo3oeO0k",1792931640004]