[{"data":1,"prerenderedAt":1053},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks":3},{"id":4,"title":5,"body":6,"description":1035,"extension":1036,"frontmatter":1037,"heading":5,"meta":1044,"navigation":1046,"order":1041,"path":1047,"seo":1048,"sitemap":1049,"source":1050,"stem":1051,"__hash__":1052},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks.md","Lifecycle hooks",{"type":7,"value":8,"toc":1023},"minimark",[9,30,37,42,52,334,338,341,344,348,359,479,483,492,718,722,725,872,876,879,971,975],[10,11,12,13,17,18,25,26,29],"p",{},"Kubb runs on one shared, typed hook emitter, and every phase of a build fires a ",[14,15,16],"code",{},"kubb:*"," hook on it. Plugins listen through their ",[19,20,22],"a",{"href":21},".\u002Fplugins",[14,23,24],{},"hooks"," map. Outside code listens through ",[14,27,28],{},"kubb.hooks",".",[10,31,32,33,36],{},"Every hook name and its payload lives in the ",[14,34,35],{},"KubbHooks"," type. Handlers can be async, and Kubb awaits each one.",[38,39,41],"h2",{"id":40},"listening","Listening",[10,43,44,45,48,49,29],{},"Attach a listener with ",[14,46,47],{},"kubb.hooks.hook(name, handler)"," before you call ",[14,50,51],{},"build()",[53,54,58],"pre",{"language":55,"code":56,"class":57},"ts","import { createKubb } from 'kubb'\n\nconst kubb = createKubb({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fgen' },\n})\n\nkubb.hooks.hook('kubb:plugin:end', ({ plugin, duration }) => {\n  console.log(`${plugin.name} finished in ${duration}ms`)\n})\n\nkubb.hooks.hook('kubb:build:end', ({ files }) => {\n  console.log(`Generated ${files.length} files`)\n})\n\nawait kubb.build()","highlights",[14,59,61,88,89,88,91,88,109,88,126,88,150,88,155,88,157,88,200,88,245,88,249,88,251,88,281,88,313,88,317,88,319],{"class":60},"language-ts",[62,63,66,70,74,78,81,84],"span",{"class":64,"style":65},"line","display: inline",[62,67,69],{"style":68},"color:#d73a49;--hls-dark:#f97583","import ",[62,71,73],{"style":72},"color:#005cc5;--hls-dark:#79b8ff","{ ",[62,75,77],{"style":76},"color:#24292e;--hls-dark:#e1e4e8","createKubb ",[62,79,80],{"style":72},"} ",[62,82,83],{"style":68},"from ",[62,85,87],{"style":86},"color:#032f62;--hls-dark:#9ecbff","'kubb'","\n",[62,90],{"class":64,"style":65},[62,92,93,96,99,102,106],{"class":64,"style":65},[62,94,95],{"style":68},"const ",[62,97,98],{"style":76},"kubb ",[62,100,101],{"style":68},"= ",[62,103,105],{"style":104},"color:#6f42c1;--hls-dark:#b392f0","createKubb",[62,107,108],{"style":72},"({",[62,110,111,114,117,120,123],{"class":64,"style":65},[62,112,113],{"style":72},"  ",[62,115,116],{"style":72},"input",[62,118,119],{"style":68},": ",[62,121,122],{"style":86},"'.\u002FpetStore.yaml'",[62,124,125],{"style":68},",",[62,127,128,130,133,135,137,140,142,145,148],{"class":64,"style":65},[62,129,113],{"style":68},[62,131,132],{"style":72},"output",[62,134,119],{"style":68},[62,136,73],{"style":72},[62,138,139],{"style":72},"path",[62,141,119],{"style":68},[62,143,144],{"style":86},"'.\u002Fgen' ",[62,146,147],{"style":72},"}",[62,149,125],{"style":68},[62,151,152],{"class":64,"style":65},[62,153,154],{"style":72},"})",[62,156],{"class":64,"style":65},[62,158,159,162,164,166,168,171,174,177,180,183,186,188,191,194,197],{"class":64,"style":65},[62,160,161],{"style":76},"kubb",[62,163,29],{"style":68},[62,165,24],{"style":72},[62,167,29],{"style":68},[62,169,170],{"style":104},"hook",[62,172,173],{"style":72},"(",[62,175,176],{"style":86},"'kubb:plugin:end'",[62,178,179],{"style":68},", ",[62,181,182],{"style":72},"({ ",[62,184,185],{"style":76},"plugin",[62,187,179],{"style":68},[62,189,190],{"style":76},"duration ",[62,192,193],{"style":72},"}) ",[62,195,196],{"style":68},"=> ",[62,198,199],{"style":72},"{",[62,201,202,204,207,209,212,214,217,220,222,224,227,229,232,234,237,239,242],{"class":64,"style":65},[62,203,113],{"style":72},[62,205,206],{"style":76},"console",[62,208,29],{"style":68},[62,210,211],{"style":104},"log",[62,213,173],{"style":72},[62,215,216],{"style":86},"`",[62,218,219],{"style":76},"${",[62,221,185],{"style":76},[62,223,29],{"style":68},[62,225,226],{"style":72},"name",[62,228,147],{"style":76},[62,230,231],{"style":86}," finished in ",[62,233,219],{"style":76},[62,235,236],{"style":76},"duration",[62,238,147],{"style":76},[62,240,241],{"style":86},"ms`",[62,243,244],{"style":72},")",[62,246,247],{"class":64,"style":65},[62,248,154],{"style":72},[62,250],{"class":64,"style":65},[62,252,253,255,257,259,261,263,265,268,270,272,275,277,279],{"class":64,"style":65},[62,254,161],{"style":76},[62,256,29],{"style":68},[62,258,24],{"style":72},[62,260,29],{"style":68},[62,262,170],{"style":104},[62,264,173],{"style":72},[62,266,267],{"style":86},"'kubb:build:end'",[62,269,179],{"style":68},[62,271,182],{"style":72},[62,273,274],{"style":76},"files ",[62,276,193],{"style":72},[62,278,196],{"style":68},[62,280,199],{"style":72},[62,282,283,285,287,289,291,293,296,298,301,303,306,308,311],{"class":64,"style":65},[62,284,113],{"style":72},[62,286,206],{"style":76},[62,288,29],{"style":68},[62,290,211],{"style":104},[62,292,173],{"style":72},[62,294,295],{"style":86},"`Generated ",[62,297,219],{"style":76},[62,299,300],{"style":76},"files",[62,302,29],{"style":68},[62,304,305],{"style":72},"length",[62,307,147],{"style":76},[62,309,310],{"style":86}," files`",[62,312,244],{"style":72},[62,314,315],{"class":64,"style":65},[62,316,154],{"style":72},[62,318],{"class":64,"style":65},[62,320,321,324,326,328,331],{"class":64,"style":65},[62,322,323],{"style":68},"await ",[62,325,161],{"style":76},[62,327,29],{"style":68},[62,329,330],{"style":104},"build",[62,332,333],{"style":72},"()",[38,335,337],{"id":336},"firing-order","Firing order",[10,339,340],{},"A full generation run fires the hooks in this order.",[342,343],"lifecycle-timeline",{},[38,345,347],{"id":346},"generation-run","Generation run",[10,349,350,351,354,355,358],{},"These wrap a full run. A direct ",[14,352,353],{},".build()"," or ",[14,356,357],{},".safeBuild()"," does not fire them.",[360,361,362,378],"table",{},[363,364,365],"thead",{},[366,367,368,372,375],"tr",{},[369,370,371],"th",{},"Hook",[369,373,374],{},"Payload",[369,376,377],{},"When it fires",[379,380,381,397,412,425,437,452,467],"tbody",{},[366,382,383,389,394],{},[384,385,386],"td",{},[14,387,388],{},"kubb:lifecycle:start",[384,390,391],{},[14,392,393],{},"{ version }",[384,395,396],{},"The bundler plugin starts, before anything else",[366,398,399,404,409],{},[384,400,401],{},[14,402,403],{},"kubb:generation:start",[384,405,406],{},[14,407,408],{},"{ config }",[384,410,411],{},"A run begins, before setup",[366,413,414,419,422],{},[384,415,416],{},[14,417,418],{},"kubb:setup:start",[384,420,421],{},"none",[384,423,424],{},"Before the driver and storage are initialized",[366,426,427,432,434],{},[384,428,429],{},[14,430,431],{},"kubb:setup:end",[384,433,421],{},[384,435,436],{},"After setup, before the build pipeline",[366,438,439,444,449],{},[384,440,441],{},[14,442,443],{},"kubb:generation:end",[384,445,446],{},[14,447,448],{},"{ config, storage, status, diagnostics, filesCreated, hrStart }",[384,450,451],{},"The run finishes, after the output passes",[366,453,454,459,464],{},[384,455,456],{},[14,457,458],{},"kubb:generation:summary",[384,460,461],{},[14,462,463],{},"KubbGenerationSummaryContext",[384,465,466],{},"After the run, with the summary the reporters render",[366,468,469,474,476],{},[384,470,471],{},[14,472,473],{},"kubb:lifecycle:end",[384,475,421],{},[384,477,478],{},"The bundler plugin is done",[38,480,482],{"id":481},"build-pipeline","Build pipeline",[10,484,485,486,488,489,491],{},"These come from the pipeline, so ",[14,487,353],{}," and ",[14,490,357],{}," fire them too.",[360,493,494,504],{},[363,495,496],{},[366,497,498,500,502],{},[369,499,371],{},[369,501,374],{},[369,503,377],{},[379,505,506,521,536,551,566,580,595,610,625,640,675,689,703],{},[366,507,508,513,518],{},[384,509,510],{},[14,511,512],{},"kubb:plugin:setup",[384,514,515],{},[14,516,517],{},"KubbPluginSetupContext",[384,519,520],{},"Once per plugin during setup, to register generators, resolvers, macros, and options",[366,522,523,528,533],{},[384,524,525],{},[14,526,527],{},"kubb:build:start",[384,529,530],{},[14,531,532],{},"{ config, adapter, meta, getPlugin, files, upsertFile }",[384,534,535],{},"The AST is ready, before plugins run. Skipped when no adapter parsed input",[366,537,538,543,548],{},[384,539,540],{},[14,541,542],{},"kubb:plugin:start",[384,544,545],{},[14,546,547],{},"{ plugin }",[384,549,550],{},"Before a plugin's generators run",[366,552,553,558,563],{},[384,554,555],{},[14,556,557],{},"kubb:generate:schema",[384,559,560],{},[14,561,562],{},"(node, ctx)",[384,564,565],{},"For each schema node the adapter produced",[366,567,568,573,577],{},[384,569,570],{},[14,571,572],{},"kubb:generate:operation",[384,574,575],{},[14,576,562],{},[384,578,579],{},"For each operation node",[366,581,582,587,592],{},[384,583,584],{},[14,585,586],{},"kubb:generate:operations",[384,588,589],{},[14,590,591],{},"(nodes, ctx)",[384,593,594],{},"Once with every operation node",[366,596,597,602,607],{},[384,598,599],{},[14,600,601],{},"kubb:plugin:end",[384,603,604],{},[14,605,606],{},"{ plugin, duration, success, error, config, files, upsertFile }",[384,608,609],{},"After a plugin finishes, with its timing and a file snapshot",[366,611,612,617,622],{},[384,613,614],{},[14,615,616],{},"kubb:plugins:end",[384,618,619],{},[14,620,621],{},"{ config, files, upsertFile }",[384,623,624],{},"After every plugin has generated, before files hit disk. The spot to add aggregate files like a barrel",[366,626,627,632,637],{},[384,628,629],{},[14,630,631],{},"kubb:files:processing:start",[384,633,634],{},[14,635,636],{},"{ files }",[384,638,639],{},"Before the batch of generated files is written",[366,641,642,647,651],{},[384,643,644],{},[14,645,646],{},"kubb:files:processing:update",[384,648,649],{},[14,650,636],{},[384,652,653,654,656,657,660,661,664,665,488,668,671,672],{},"As files are written. Here ",[14,655,300],{}," holds progress records (",[14,658,659],{},"{ processed, total, percentage, file, config }","), not the ",[14,662,663],{},"FileNode"," array the ",[14,666,667],{},":start",[14,669,670],{},":end"," variants carry. The source is on ",[14,673,674],{},"kubb:file:processed",[366,676,677,681,686],{},[384,678,679],{},[14,680,674],{},[384,682,683],{},[14,684,685],{},"{ file, source }",[384,687,688],{},"After each file is parsed and handed to the storage, with the source before any output pass rewrites it",[366,690,691,696,700],{},[384,692,693],{},[14,694,695],{},"kubb:files:processing:end",[384,697,698],{},[14,699,636],{},[384,701,702],{},"After the batch is written",[366,704,705,710,715],{},[384,706,707],{},[14,708,709],{},"kubb:build:end",[384,711,712],{},[14,713,714],{},"{ files, config, outputDir }",[384,716,717],{},"After every file is written",[38,719,721],{"id":720},"output-passes","Output passes",[10,723,724],{},"These run after a successful build, only during a full generation run.",[360,726,727,737],{},[363,728,729],{},[366,730,731,733,735],{},[369,732,371],{},[369,734,374],{},[369,736,377],{},[379,738,739,751,763,775,787,803,821,839,857],{},[366,740,741,746,748],{},[384,742,743],{},[14,744,745],{},"kubb:format:start",[384,747,421],{},[384,749,750],{},"Before the formatter runs",[366,752,753,758,760],{},[384,754,755],{},[14,756,757],{},"kubb:format:end",[384,759,421],{},[384,761,762],{},"After formatting",[366,764,765,770,772],{},[384,766,767],{},[14,768,769],{},"kubb:lint:start",[384,771,421],{},[384,773,774],{},"Before the linter runs",[366,776,777,782,784],{},[384,778,779],{},[14,780,781],{},"kubb:lint:end",[384,783,421],{},[384,785,786],{},"After linting",[366,788,789,794,796],{},[384,790,791],{},[14,792,793],{},"kubb:hooks:start",[384,795,421],{},[384,797,798,799,802],{},"Before the ",[14,800,801],{},"postGenerate"," commands run",[366,804,805,810,815],{},[384,806,807],{},[14,808,809],{},"kubb:hook:start",[384,811,812],{},[14,813,814],{},"{ id, command, name, args }",[384,816,817,818,820],{},"Before one ",[14,819,801],{}," command runs",[366,822,823,828,833],{},[384,824,825],{},[14,826,827],{},"kubb:hook:line",[384,829,830],{},[14,831,832],{},"KubbHookLineContext",[384,834,835,836,838],{},"For each output line a ",[14,837,801],{}," command emits",[366,840,841,846,851],{},[384,842,843],{},[14,844,845],{},"kubb:hook:end",[384,847,848],{},[14,849,850],{},"KubbHookEndContext",[384,852,853,854,856],{},"After one ",[14,855,801],{}," command finishes",[366,858,859,864,866],{},[384,860,861],{},[14,862,863],{},"kubb:hooks:end",[384,865,421],{},[384,867,868,869,871],{},"After every ",[14,870,801],{}," command",[38,873,875],{"id":874},"messaging","Messaging",[10,877,878],{},"These carry log messages and diagnostics, and can fire at any point.",[360,880,881,891],{},[363,882,883],{},[366,884,885,887,889],{},[369,886,371],{},[369,888,374],{},[369,890,377],{},[379,892,893,908,922,936,951],{},[366,894,895,900,905],{},[384,896,897],{},[14,898,899],{},"kubb:info",[384,901,902],{},[14,903,904],{},"{ message, info }",[384,906,907],{},"An informational message",[366,909,910,915,919],{},[384,911,912],{},[14,913,914],{},"kubb:success",[384,916,917],{},[14,918,904],{},[384,920,921],{},"A step completed successfully",[366,923,924,929,933],{},[384,925,926],{},[14,927,928],{},"kubb:warn",[384,930,931],{},[14,932,904],{},[384,934,935],{},"A non-fatal problem",[366,937,938,943,948],{},[384,939,940],{},[14,941,942],{},"kubb:error",[384,944,945],{},[14,946,947],{},"{ error, meta }",[384,949,950],{},"An unstructured error, so its stack survives",[366,952,953,958,963],{},[384,954,955],{},[14,956,957],{},"kubb:diagnostic",[384,959,960],{},[14,961,962],{},"{ diagnostic }",[384,964,965,966,970],{},"A structured ",[19,967,969],{"href":968},"..\u002Fdiagnostics","diagnostic"," (warning, info, or an update notice)",[38,972,974],{"id":973},"related","Related",[976,977,978,990,1007,1014],"ul",{},[979,980,981,984,985,987,988],"li",{},[19,982,983],{"href":21},"Plugins"," for the plugin ",[14,986,24],{}," map and ",[14,989,517],{},[979,991,992,996,997,179,999,179,1001,1003,1004],{},[19,993,995],{"href":994},".\u002Fengine","Engine"," for ",[14,998,105],{},[14,1000,353],{},[14,1002,357],{},", and ",[14,1005,1006],{},".generate()",[979,1008,1009,1013],{},[19,1010,1012],{"href":1011},"\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions#plugins","Plugin concepts"," for the lifecycle as prose",[979,1015,1016,1019,1020,1022],{},[19,1017,1018],{"href":968},"Diagnostics"," for the shape of ",[14,1021,957],{}," payloads",{"title":1024,"searchDepth":1025,"depth":1025,"links":1026},"",5,[1027,1029,1030,1031,1032,1033,1034],{"id":40,"depth":1028,"text":41},2,{"id":336,"depth":1028,"text":337},{"id":346,"depth":1028,"text":347},{"id":481,"depth":1028,"text":482},{"id":720,"depth":1028,"text":721},{"id":874,"depth":1028,"text":875},{"id":973,"depth":1028,"text":974},"Every kubb:* hook a build fires, its payload, and when it fires. Listen with kubb.hooks.hook(name, handler) or from a plugin's hooks map.","md",{"layout":1038,"title":5,"description":1035,"outline":1039,"order":1041,"navigation":1042},"doc",[1028,1040],3,11,{"title":5,"icon":1043},"i-iconoir-refresh-double",{"layout":1038,"outline":1045},[1028,1040],{"title":5,"icon":1043},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks",{"title":5,"description":1035},{"loc":1047},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fhooks","BSjzrl6qO8XTItlIK6XIfmbRoFpGlBsXoOkwpbUjL00",1793747910139]