index.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  1. var __defProp = Object.defineProperty;
  2. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  3. // src/constants/ansi-escape-codes.constants.ts
  4. var ANSI_ESCAPE = "\x1B[";
  5. var ANSI_ESCAPE_CODES = {
  6. CURSOR_HIDE: ANSI_ESCAPE + "?25l",
  7. CURSOR_SHOW: ANSI_ESCAPE + "?25h"
  8. };
  9. // src/constants/environment-variables.constants.ts
  10. var ListrEnvironmentVariables = /* @__PURE__ */ ((ListrEnvironmentVariables2) => {
  11. ListrEnvironmentVariables2["FORCE_UNICODE"] = "LISTR_FORCE_UNICODE";
  12. ListrEnvironmentVariables2["FORCE_TTY"] = "LISTR_FORCE_TTY";
  13. ListrEnvironmentVariables2["DISABLE_COLOR"] = "NO_COLOR";
  14. ListrEnvironmentVariables2["FORCE_COLOR"] = "FORCE_COLOR";
  15. return ListrEnvironmentVariables2;
  16. })(ListrEnvironmentVariables || {});
  17. // src/constants/listr-error.constants.ts
  18. var ListrErrorTypes = /* @__PURE__ */ ((ListrErrorTypes2) => {
  19. ListrErrorTypes2["WILL_RETRY"] = "WILL_RETRY";
  20. ListrErrorTypes2["WILL_ROLLBACK"] = "WILL_ROLLBACK";
  21. ListrErrorTypes2["HAS_FAILED_TO_ROLLBACK"] = "HAS_FAILED_TO_ROLLBACK";
  22. ListrErrorTypes2["HAS_FAILED"] = "HAS_FAILED";
  23. ListrErrorTypes2["HAS_FAILED_WITHOUT_ERROR"] = "HAS_FAILED_WITHOUT_ERROR";
  24. return ListrErrorTypes2;
  25. })(ListrErrorTypes || {});
  26. // src/constants/listr-events.constants.ts
  27. var ListrEventType = /* @__PURE__ */ ((ListrEventType2) => {
  28. ListrEventType2["SHOULD_REFRESH_RENDER"] = "SHOUD_REFRESH_RENDER";
  29. return ListrEventType2;
  30. })(ListrEventType || {});
  31. // src/constants/listr-renderer.constants.ts
  32. var ListrRendererSelection = /* @__PURE__ */ ((ListrRendererSelection2) => {
  33. ListrRendererSelection2["PRIMARY"] = "PRIMARY";
  34. ListrRendererSelection2["SECONDARY"] = "SECONDARY";
  35. ListrRendererSelection2["SILENT"] = "SILENT";
  36. return ListrRendererSelection2;
  37. })(ListrRendererSelection || {});
  38. // src/constants/listr-task-events.constants.ts
  39. var ListrTaskEventType = /* @__PURE__ */ ((ListrTaskEventType2) => {
  40. ListrTaskEventType2["TITLE"] = "TITLE";
  41. ListrTaskEventType2["STATE"] = "STATE";
  42. ListrTaskEventType2["ENABLED"] = "ENABLED";
  43. ListrTaskEventType2["SUBTASK"] = "SUBTASK";
  44. ListrTaskEventType2["PROMPT"] = "PROMPT";
  45. ListrTaskEventType2["OUTPUT"] = "OUTPUT";
  46. ListrTaskEventType2["MESSAGE"] = "MESSAGE";
  47. ListrTaskEventType2["CLOSED"] = "CLOSED";
  48. return ListrTaskEventType2;
  49. })(ListrTaskEventType || {});
  50. // src/constants/listr-task-state.constants.ts
  51. var ListrTaskState = /* @__PURE__ */ ((ListrTaskState2) => {
  52. ListrTaskState2["WAITING"] = "WAITING";
  53. ListrTaskState2["STARTED"] = "STARTED";
  54. ListrTaskState2["COMPLETED"] = "COMPLETED";
  55. ListrTaskState2["FAILED"] = "FAILED";
  56. ListrTaskState2["SKIPPED"] = "SKIPPED";
  57. ListrTaskState2["ROLLING_BACK"] = "ROLLING_BACK";
  58. ListrTaskState2["ROLLED_BACK"] = "ROLLED_BACK";
  59. ListrTaskState2["RETRY"] = "RETRY";
  60. ListrTaskState2["PAUSED"] = "PAUSED";
  61. ListrTaskState2["PROMPT"] = "PROMPT";
  62. ListrTaskState2["PROMPT_COMPLETED"] = "PROMPT_COMPLETED";
  63. ListrTaskState2["PROMPT_FAILED"] = "PROMPT_FAILED";
  64. return ListrTaskState2;
  65. })(ListrTaskState || {});
  66. // src/lib/event-manager.ts
  67. import EventEmitter from "eventemitter3";
  68. var EventManager = class {
  69. static {
  70. __name(this, "EventManager");
  71. }
  72. emitter = new EventEmitter();
  73. emit(dispatch, args) {
  74. this.emitter.emit(dispatch, args);
  75. }
  76. on(dispatch, handler) {
  77. this.emitter.addListener(dispatch, handler);
  78. }
  79. once(dispatch, handler) {
  80. this.emitter.once(dispatch, handler);
  81. }
  82. off(dispatch, handler) {
  83. this.emitter.off(dispatch, handler);
  84. }
  85. complete() {
  86. this.emitter.removeAllListeners();
  87. }
  88. };
  89. // src/interfaces/event.interface.ts
  90. var BaseEventMap = class {
  91. static {
  92. __name(this, "BaseEventMap");
  93. }
  94. };
  95. // src/utils/environment/is-observable.ts
  96. function isObservable(obj) {
  97. return !!obj && typeof obj === "object" && typeof obj.subscribe === "function";
  98. }
  99. __name(isObservable, "isObservable");
  100. // src/utils/environment/is-readable.ts
  101. function isReadable(obj) {
  102. return !!obj && typeof obj === "object" && obj.readable === true && typeof obj.read === "function" && typeof obj.on === "function";
  103. }
  104. __name(isReadable, "isReadable");
  105. // src/utils/environment/is-unicode-supported.ts
  106. function isUnicodeSupported() {
  107. return !!process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] || process.platform !== "win32" || !!process.env.CI || !!process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
  108. }
  109. __name(isUnicodeSupported, "isUnicodeSupported");
  110. // src/utils/format/cleanse-ansi.constants.ts
  111. var CLEAR_LINE_REGEX = "(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+";
  112. var BELL_REGEX = /\u0007/;
  113. // src/utils/format/cleanse-ansi.ts
  114. function cleanseAnsi(chunk) {
  115. return String(chunk).replace(new RegExp(CLEAR_LINE_REGEX, "gmi"), "").replace(new RegExp(BELL_REGEX, "gmi"), "").trim();
  116. }
  117. __name(cleanseAnsi, "cleanseAnsi");
  118. // src/utils/format/color.ts
  119. import { createColors } from "colorette";
  120. var color = createColors();
  121. // src/utils/format/indent.ts
  122. function indent(string, count) {
  123. return string.replace(/^(?!\s*$)/gm, " ".repeat(count));
  124. }
  125. __name(indent, "indent");
  126. // src/utils/format/figures.ts
  127. var FIGURES_MAIN = {
  128. warning: "\u26A0",
  129. cross: "\u2716",
  130. arrowDown: "\u2193",
  131. tick: "\u2714",
  132. arrowRight: "\u2192",
  133. pointer: "\u276F",
  134. checkboxOn: "\u2612",
  135. arrowLeft: "\u2190",
  136. squareSmallFilled: "\u25FC",
  137. pointerSmall: "\u203A"
  138. };
  139. var FIGURES_FALLBACK = {
  140. ...FIGURES_MAIN,
  141. warning: "\u203C",
  142. cross: "\xD7",
  143. tick: "\u221A",
  144. pointer: ">",
  145. checkboxOn: "[\xD7]",
  146. squareSmallFilled: "\u25A0"
  147. };
  148. var figures = isUnicodeSupported() ? FIGURES_MAIN : FIGURES_FALLBACK;
  149. // src/utils/format/splat.ts
  150. import { format } from "util";
  151. function splat(message, ...splat2) {
  152. return format(String(message), ...splat2);
  153. }
  154. __name(splat, "splat");
  155. // src/utils/logger/logger.constants.ts
  156. var ListrLogLevels = /* @__PURE__ */ ((ListrLogLevels2) => {
  157. ListrLogLevels2["STARTED"] = "STARTED";
  158. ListrLogLevels2["COMPLETED"] = "COMPLETED";
  159. ListrLogLevels2["FAILED"] = "FAILED";
  160. ListrLogLevels2["SKIPPED"] = "SKIPPED";
  161. ListrLogLevels2["OUTPUT"] = "OUTPUT";
  162. ListrLogLevels2["TITLE"] = "TITLE";
  163. ListrLogLevels2["ROLLBACK"] = "ROLLBACK";
  164. ListrLogLevels2["RETRY"] = "RETRY";
  165. ListrLogLevels2["PROMPT"] = "PROMPT";
  166. ListrLogLevels2["PAUSED"] = "PAUSED";
  167. return ListrLogLevels2;
  168. })(ListrLogLevels || {});
  169. var LISTR_LOGGER_STYLE = {
  170. icon: {
  171. ["STARTED" /* STARTED */]: figures.pointer,
  172. ["FAILED" /* FAILED */]: figures.cross,
  173. ["SKIPPED" /* SKIPPED */]: figures.arrowDown,
  174. ["COMPLETED" /* COMPLETED */]: figures.tick,
  175. ["OUTPUT" /* OUTPUT */]: figures.pointerSmall,
  176. ["TITLE" /* TITLE */]: figures.arrowRight,
  177. ["RETRY" /* RETRY */]: figures.warning,
  178. ["ROLLBACK" /* ROLLBACK */]: figures.arrowLeft,
  179. ["PAUSED" /* PAUSED */]: figures.squareSmallFilled
  180. },
  181. color: {
  182. ["STARTED" /* STARTED */]: color.yellow,
  183. ["FAILED" /* FAILED */]: color.red,
  184. ["SKIPPED" /* SKIPPED */]: color.yellow,
  185. ["COMPLETED" /* COMPLETED */]: color.green,
  186. ["RETRY" /* RETRY */]: color.yellowBright,
  187. ["ROLLBACK" /* ROLLBACK */]: color.redBright,
  188. ["PAUSED" /* PAUSED */]: color.yellowBright
  189. }
  190. };
  191. var LISTR_LOGGER_STDERR_LEVELS = ["RETRY" /* RETRY */, "ROLLBACK" /* ROLLBACK */, "FAILED" /* FAILED */];
  192. // src/utils/logger/logger.ts
  193. import { EOL } from "os";
  194. var ListrLogger = class {
  195. constructor(options) {
  196. this.options = options;
  197. this.options = {
  198. useIcons: true,
  199. toStderr: [],
  200. ...options ?? {}
  201. };
  202. this.options.fields ??= {};
  203. this.options.fields.prefix ??= [];
  204. this.options.fields.suffix ??= [];
  205. this.process = this.options.processOutput ?? new ProcessOutput();
  206. }
  207. static {
  208. __name(this, "ListrLogger");
  209. }
  210. process;
  211. log(level, message, options) {
  212. const output = this.format(level, message, options);
  213. if (this.options.toStderr.includes(level)) {
  214. this.process.toStderr(output);
  215. return;
  216. }
  217. this.process.toStdout(output);
  218. }
  219. toStdout(message, options, eol = true) {
  220. this.process.toStdout(this.format(null, message, options), eol);
  221. }
  222. toStderr(message, options, eol = true) {
  223. this.process.toStderr(this.format(null, message, options), eol);
  224. }
  225. wrap(message, options) {
  226. if (!message) {
  227. return message;
  228. }
  229. return this.applyFormat(`[${message}]`, options);
  230. }
  231. splat(...args) {
  232. const message = args.shift() ?? "";
  233. return args.length === 0 ? message : splat(message, args);
  234. }
  235. suffix(message, ...suffixes) {
  236. suffixes.filter(Boolean).forEach((suffix) => {
  237. message += this.spacing(message);
  238. if (typeof suffix === "string") {
  239. message += this.wrap(suffix);
  240. } else if (typeof suffix === "object") {
  241. suffix.args ??= [];
  242. if (typeof suffix.condition === "function" ? !suffix.condition(...suffix.args) : !(suffix.condition ?? true)) {
  243. return message;
  244. }
  245. message += this.wrap(typeof suffix.field === "function" ? suffix.field(...suffix.args) : suffix.field, {
  246. format: suffix?.format(...suffix.args)
  247. });
  248. }
  249. });
  250. return message;
  251. }
  252. prefix(message, ...prefixes) {
  253. prefixes.filter(Boolean).forEach((prefix) => {
  254. message = this.spacing(message) + message;
  255. if (typeof prefix === "string") {
  256. message = this.wrap(prefix) + message;
  257. } else if (typeof prefix === "object") {
  258. prefix.args ??= [];
  259. if (typeof prefix.condition === "function" ? !prefix.condition(...prefix.args) : !(prefix.condition ?? true)) {
  260. return message;
  261. }
  262. message = this.wrap(typeof prefix.field === "function" ? prefix.field(...prefix.args) : prefix.field, {
  263. format: prefix?.format()
  264. }) + message;
  265. }
  266. });
  267. return message;
  268. }
  269. fields(message, options) {
  270. if (this.options?.fields?.prefix) {
  271. message = this.prefix(message, ...this.options.fields.prefix);
  272. }
  273. if (options?.prefix) {
  274. message = this.prefix(message, ...options.prefix);
  275. }
  276. if (options?.suffix) {
  277. message = this.suffix(message, ...options.suffix);
  278. }
  279. if (this.options?.fields?.suffix) {
  280. message = this.suffix(message, ...this.options.fields.suffix);
  281. }
  282. return message;
  283. }
  284. icon(level, icon) {
  285. if (!level) {
  286. return null;
  287. }
  288. if (!icon) {
  289. const i = this.options.icon?.[level];
  290. icon = typeof i === "function" ? i() : i;
  291. }
  292. const coloring = this.options.color?.[level];
  293. if (icon && coloring) {
  294. icon = coloring(icon);
  295. }
  296. return icon;
  297. }
  298. format(level, message, options) {
  299. if (!Array.isArray(message)) {
  300. message = [message];
  301. }
  302. message = this.splat(message.shift(), ...message).toString().split(EOL).filter((m) => !m || m.trim() !== "").map((m) => {
  303. return this.style(
  304. level,
  305. this.fields(m, {
  306. prefix: Array.isArray(options?.prefix) ? options.prefix : [options?.prefix],
  307. suffix: Array.isArray(options?.suffix) ? options.suffix : [options?.suffix]
  308. })
  309. );
  310. }).join(EOL);
  311. return message;
  312. }
  313. style(level, message) {
  314. if (!level || !message) {
  315. return message;
  316. }
  317. const icon = this.icon(level, !this.options.useIcons && this.wrap(level));
  318. if (icon) {
  319. message = icon + " " + message;
  320. }
  321. return message;
  322. }
  323. applyFormat(message, options) {
  324. if (options?.format) {
  325. return options.format(message);
  326. }
  327. return message;
  328. }
  329. spacing(message) {
  330. return typeof message === "undefined" || message.trim() === "" ? "" : " ";
  331. }
  332. };
  333. // src/utils/process-output/process-output-buffer.ts
  334. import { StringDecoder } from "string_decoder";
  335. var ProcessOutputBuffer = class {
  336. constructor(options) {
  337. this.options = options;
  338. }
  339. static {
  340. __name(this, "ProcessOutputBuffer");
  341. }
  342. buffer = [];
  343. decoder = new StringDecoder();
  344. get all() {
  345. return this.buffer;
  346. }
  347. get last() {
  348. return this.buffer.at(-1);
  349. }
  350. get length() {
  351. return this.buffer.length;
  352. }
  353. write(data, ...args) {
  354. const callback = args[args.length - 1];
  355. this.buffer.push({
  356. time: Date.now(),
  357. stream: this.options?.stream,
  358. entry: this.decoder.write(typeof data === "string" ? Buffer.from(data, typeof args[0] === "string" ? args[0] : void 0) : Buffer.from(data))
  359. });
  360. if (this.options?.limit) {
  361. this.buffer = this.buffer.slice(-this.options.limit);
  362. }
  363. if (typeof callback === "function") {
  364. callback();
  365. }
  366. return true;
  367. }
  368. reset() {
  369. this.buffer = [];
  370. }
  371. };
  372. // src/utils/process-output/process-output-stream.ts
  373. var ProcessOutputStream = class {
  374. constructor(stream) {
  375. this.stream = stream;
  376. this.method = stream.write;
  377. this.buffer = new ProcessOutputBuffer({ stream });
  378. }
  379. static {
  380. __name(this, "ProcessOutputStream");
  381. }
  382. method;
  383. buffer;
  384. get out() {
  385. return Object.assign({}, this.stream, {
  386. write: this.write.bind(this)
  387. });
  388. }
  389. hijack() {
  390. this.stream.write = this.buffer.write.bind(this.buffer);
  391. }
  392. release() {
  393. this.stream.write = this.method;
  394. const buffer = [...this.buffer.all];
  395. this.buffer.reset();
  396. return buffer;
  397. }
  398. write(...args) {
  399. return this.method.apply(this.stream, args);
  400. }
  401. };
  402. // src/utils/process-output/process-output.ts
  403. import { EOL as EOL2 } from "os";
  404. var ProcessOutput = class {
  405. constructor(stdout, stderr, options) {
  406. this.options = options;
  407. this.stream = {
  408. stdout: new ProcessOutputStream(stdout ?? process.stdout),
  409. stderr: new ProcessOutputStream(stderr ?? process.stderr)
  410. };
  411. this.options = {
  412. dump: ["stdout", "stderr"],
  413. leaveEmptyLine: true,
  414. ...options
  415. };
  416. }
  417. static {
  418. __name(this, "ProcessOutput");
  419. }
  420. stream;
  421. active;
  422. get stdout() {
  423. return this.stream.stdout.out;
  424. }
  425. get stderr() {
  426. return this.stream.stderr.out;
  427. }
  428. hijack() {
  429. if (this.active) {
  430. throw new Error("ProcessOutput has been already hijacked!");
  431. }
  432. this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_HIDE);
  433. Object.values(this.stream).forEach((stream) => stream.hijack());
  434. this.active = true;
  435. }
  436. release() {
  437. const output = Object.entries(this.stream).map(([name, stream]) => ({ name, buffer: stream.release() })).filter((output2) => this.options.dump.includes(output2.name)).flatMap((output2) => output2.buffer).sort((a, b) => a.time - b.time).map((message) => {
  438. return {
  439. ...message,
  440. entry: cleanseAnsi(message.entry)
  441. };
  442. }).filter((message) => message.entry);
  443. if (output.length > 0) {
  444. if (this.options.leaveEmptyLine) {
  445. this.stdout.write(EOL2);
  446. }
  447. output.forEach((message) => {
  448. const stream = message.stream ?? this.stdout;
  449. stream.write(message.entry + EOL2);
  450. });
  451. }
  452. this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_SHOW);
  453. this.active = false;
  454. }
  455. toStdout(buffer, eol = true) {
  456. if (eol) {
  457. buffer = buffer + EOL2;
  458. }
  459. return this.stream.stdout.write(buffer);
  460. }
  461. toStderr(buffer, eol = true) {
  462. if (eol) {
  463. buffer = buffer + EOL2;
  464. }
  465. return this.stream.stderr.write(buffer);
  466. }
  467. };
  468. // src/utils/process-output/writable.ts
  469. import { Writable } from "stream";
  470. function createWritable(cb) {
  471. const writable = new Writable();
  472. writable.rows = Infinity;
  473. writable.columns = Infinity;
  474. writable.write = (chunk) => {
  475. cb(chunk.toString());
  476. return true;
  477. };
  478. return writable;
  479. }
  480. __name(createWritable, "createWritable");
  481. // src/utils/prompts/adapter.ts
  482. var ListrPromptAdapter = class {
  483. constructor(task, wrapper) {
  484. this.task = task;
  485. this.wrapper = wrapper;
  486. }
  487. static {
  488. __name(this, "ListrPromptAdapter");
  489. }
  490. state;
  491. reportStarted() {
  492. this.state = this.task.state;
  493. if (this.task.prompt) {
  494. throw new PromptError("There is already an active prompt attached to this task which may not be cleaned up properly.");
  495. }
  496. this.task.prompt = this;
  497. this.task.state$ = "PROMPT" /* PROMPT */;
  498. }
  499. reportFailed() {
  500. this.task.state$ = "PROMPT_FAILED" /* PROMPT_FAILED */;
  501. this.restoreState();
  502. }
  503. reportCompleted() {
  504. this.task.state$ = "PROMPT_COMPLETED" /* PROMPT_COMPLETED */;
  505. this.restoreState();
  506. }
  507. restoreState() {
  508. this.task.prompt = void 0;
  509. if (this.state) {
  510. this.task.state = this.state;
  511. }
  512. }
  513. };
  514. // src/utils/ui/spinner.ts
  515. var Spinner = class {
  516. static {
  517. __name(this, "Spinner");
  518. }
  519. spinner = !isUnicodeSupported() ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
  520. id;
  521. spinnerPosition = 0;
  522. spin() {
  523. this.spinnerPosition = ++this.spinnerPosition % this.spinner.length;
  524. }
  525. fetch() {
  526. return this.spinner[this.spinnerPosition];
  527. }
  528. isRunning() {
  529. return !!this.id;
  530. }
  531. start(cb, interval = 100) {
  532. this.id = setInterval(() => {
  533. this.spin();
  534. if (cb) {
  535. cb();
  536. }
  537. }, interval);
  538. }
  539. stop() {
  540. clearInterval(this.id);
  541. }
  542. };
  543. // src/renderer/default/renderer.constants.ts
  544. var ListrDefaultRendererLogLevels = /* @__PURE__ */ ((ListrDefaultRendererLogLevels2) => {
  545. ListrDefaultRendererLogLevels2["SKIPPED_WITH_COLLAPSE"] = "SKIPPED_WITH_COLLAPSE";
  546. ListrDefaultRendererLogLevels2["SKIPPED_WITHOUT_COLLAPSE"] = "SKIPPED_WITHOUT_COLLAPSE";
  547. ListrDefaultRendererLogLevels2["OUTPUT"] = "OUTPUT";
  548. ListrDefaultRendererLogLevels2["OUTPUT_WITH_BOTTOMBAR"] = "OUTPUT_WITH_BOTTOMBAR";
  549. ListrDefaultRendererLogLevels2["PENDING"] = "PENDING";
  550. ListrDefaultRendererLogLevels2["COMPLETED"] = "COMPLETED";
  551. ListrDefaultRendererLogLevels2["COMPLETED_WITH_FAILED_SUBTASKS"] = "COMPLETED_WITH_FAILED_SUBTASKS";
  552. ListrDefaultRendererLogLevels2["COMPLETED_WITH_FAILED_SISTER_TASKS"] = "COMPLETED_WITH_SISTER_TASKS_FAILED";
  553. ListrDefaultRendererLogLevels2["RETRY"] = "RETRY";
  554. ListrDefaultRendererLogLevels2["ROLLING_BACK"] = "ROLLING_BACK";
  555. ListrDefaultRendererLogLevels2["ROLLED_BACK"] = "ROLLED_BACK";
  556. ListrDefaultRendererLogLevels2["FAILED"] = "FAILED";
  557. ListrDefaultRendererLogLevels2["FAILED_WITH_FAILED_SUBTASKS"] = "FAILED_WITH_SUBTASKS";
  558. ListrDefaultRendererLogLevels2["WAITING"] = "WAITING";
  559. ListrDefaultRendererLogLevels2["PAUSED"] = "PAUSED";
  560. return ListrDefaultRendererLogLevels2;
  561. })(ListrDefaultRendererLogLevels || {});
  562. var LISTR_DEFAULT_RENDERER_STYLE = {
  563. icon: {
  564. ["SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */]: figures.arrowDown,
  565. ["SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */]: figures.warning,
  566. ["OUTPUT" /* OUTPUT */]: figures.pointerSmall,
  567. ["OUTPUT_WITH_BOTTOMBAR" /* OUTPUT_WITH_BOTTOMBAR */]: figures.pointerSmall,
  568. ["PENDING" /* PENDING */]: figures.pointer,
  569. ["COMPLETED" /* COMPLETED */]: figures.tick,
  570. ["COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */]: figures.warning,
  571. ["COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */]: figures.squareSmallFilled,
  572. ["RETRY" /* RETRY */]: figures.warning,
  573. ["ROLLING_BACK" /* ROLLING_BACK */]: figures.warning,
  574. ["ROLLED_BACK" /* ROLLED_BACK */]: figures.arrowLeft,
  575. ["FAILED" /* FAILED */]: figures.cross,
  576. ["FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */]: figures.pointer,
  577. ["WAITING" /* WAITING */]: figures.squareSmallFilled,
  578. ["PAUSED" /* PAUSED */]: figures.squareSmallFilled
  579. },
  580. color: {
  581. ["SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */]: color.yellow,
  582. ["SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */]: color.yellow,
  583. ["PENDING" /* PENDING */]: color.yellow,
  584. ["COMPLETED" /* COMPLETED */]: color.green,
  585. ["COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */]: color.yellow,
  586. ["COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */]: color.red,
  587. ["RETRY" /* RETRY */]: color.yellowBright,
  588. ["ROLLING_BACK" /* ROLLING_BACK */]: color.redBright,
  589. ["ROLLED_BACK" /* ROLLED_BACK */]: color.redBright,
  590. ["FAILED" /* FAILED */]: color.red,
  591. ["FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */]: color.red,
  592. ["WAITING" /* WAITING */]: color.dim,
  593. ["PAUSED" /* PAUSED */]: color.yellowBright
  594. }
  595. };
  596. // src/renderer/default/renderer.ts
  597. import { EOL as EOL3 } from "os";
  598. // src/presets/timer/parser.ts
  599. function parseTimer(duration) {
  600. const seconds = Math.floor(duration / 1e3);
  601. const minutes = Math.floor(seconds / 60);
  602. let parsedTime;
  603. if (seconds === 0 && minutes === 0) {
  604. parsedTime = `0.${Math.floor(duration / 100)}s`;
  605. }
  606. if (seconds > 0) {
  607. parsedTime = `${seconds % 60}s`;
  608. }
  609. if (minutes > 0) {
  610. parsedTime = `${minutes}m${parsedTime}`;
  611. }
  612. return parsedTime;
  613. }
  614. __name(parseTimer, "parseTimer");
  615. // src/presets/timer/preset.ts
  616. var PRESET_TIMER = {
  617. condition: true,
  618. field: parseTimer,
  619. format: /* @__PURE__ */ __name(() => color.dim, "format")
  620. };
  621. // src/presets/timestamp/parser.ts
  622. function parseTimestamp() {
  623. const now = /* @__PURE__ */ new Date();
  624. return String(now.getHours()).padStart(2, "0") + ":" + String(now.getMinutes()).padStart(2, "0") + ":" + String(now.getSeconds()).padStart(2, "0");
  625. }
  626. __name(parseTimestamp, "parseTimestamp");
  627. // src/presets/timestamp/preset.ts
  628. var PRESET_TIMESTAMP = {
  629. condition: true,
  630. field: parseTimestamp,
  631. format: /* @__PURE__ */ __name(() => color.dim, "format")
  632. };
  633. // src/renderer/default/renderer.ts
  634. var DefaultRenderer = class _DefaultRenderer {
  635. constructor(tasks, options, events) {
  636. this.tasks = tasks;
  637. this.options = options;
  638. this.events = events;
  639. this.options = {
  640. ..._DefaultRenderer.rendererOptions,
  641. ...this.options,
  642. icon: {
  643. ...LISTR_DEFAULT_RENDERER_STYLE.icon,
  644. ...options?.icon ?? {}
  645. },
  646. color: {
  647. ...LISTR_DEFAULT_RENDERER_STYLE.color,
  648. ...options?.color ?? {}
  649. }
  650. };
  651. this.spinner = this.options.spinner ?? new Spinner();
  652. this.logger = this.options.logger ?? new ListrLogger({ useIcons: true, toStderr: [] });
  653. this.logger.options.icon = this.options.icon;
  654. this.logger.options.color = this.options.color;
  655. }
  656. static {
  657. __name(this, "DefaultRenderer");
  658. }
  659. static nonTTY = false;
  660. static rendererOptions = {
  661. indentation: 2,
  662. clearOutput: false,
  663. showSubtasks: true,
  664. collapseSubtasks: true,
  665. collapseSkips: true,
  666. showSkipMessage: true,
  667. suffixSkips: false,
  668. collapseErrors: true,
  669. showErrorMessage: true,
  670. suffixRetries: true,
  671. lazy: false,
  672. removeEmptyLines: true,
  673. formatOutput: "wrap",
  674. pausedTimer: {
  675. ...PRESET_TIMER,
  676. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  677. }
  678. };
  679. static rendererTaskOptions = {
  680. outputBar: true
  681. };
  682. prompt;
  683. activePrompt;
  684. spinner;
  685. logger;
  686. updater;
  687. truncate;
  688. wrap;
  689. buffer = {
  690. output: /* @__PURE__ */ new Map(),
  691. bottom: /* @__PURE__ */ new Map()
  692. };
  693. cache = {
  694. render: /* @__PURE__ */ new Map(),
  695. rendererOptions: /* @__PURE__ */ new Map(),
  696. rendererTaskOptions: /* @__PURE__ */ new Map()
  697. };
  698. async render() {
  699. const { createLogUpdate } = await import("log-update");
  700. const { default: truncate } = await import("cli-truncate");
  701. const { default: wrap } = await import("wrap-ansi");
  702. this.updater = createLogUpdate(this.logger.process.stdout);
  703. this.truncate = truncate;
  704. this.wrap = wrap;
  705. this.logger.process.hijack();
  706. if (!this.options?.lazy) {
  707. this.spinner.start(() => {
  708. this.update();
  709. });
  710. }
  711. this.events.on("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */, () => {
  712. this.update();
  713. });
  714. }
  715. update() {
  716. this.updater(this.create());
  717. }
  718. end() {
  719. this.spinner.stop();
  720. this.updater.clear();
  721. this.updater.done();
  722. if (!this.options.clearOutput) {
  723. this.logger.process.toStdout(this.create({ prompt: false }));
  724. }
  725. this.logger.process.release();
  726. }
  727. create(options) {
  728. options = {
  729. tasks: true,
  730. bottomBar: true,
  731. prompt: true,
  732. ...options
  733. };
  734. const render = [];
  735. const renderTasks = this.renderer(this.tasks);
  736. const renderBottomBar = this.renderBottomBar();
  737. const renderPrompt = this.renderPrompt();
  738. if (options.tasks && renderTasks.length > 0) {
  739. render.push(...renderTasks);
  740. }
  741. if (options.bottomBar && renderBottomBar.length > 0) {
  742. if (render.length > 0) {
  743. render.push("");
  744. }
  745. render.push(...renderBottomBar);
  746. }
  747. if (options.prompt && renderPrompt.length > 0) {
  748. if (render.length > 0) {
  749. render.push("");
  750. }
  751. render.push(...renderPrompt);
  752. }
  753. return render.join(EOL3);
  754. }
  755. // eslint-disable-next-line complexity
  756. style(task, output = false) {
  757. const rendererOptions = this.cache.rendererOptions.get(task.id);
  758. if (task.isSkipped()) {
  759. if (output || rendererOptions.collapseSkips) {
  760. return this.logger.icon("SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */);
  761. } else if (rendererOptions.collapseSkips === false) {
  762. return this.logger.icon("SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */);
  763. }
  764. }
  765. if (output) {
  766. if (this.shouldOutputToBottomBar(task)) {
  767. return this.logger.icon("OUTPUT_WITH_BOTTOMBAR" /* OUTPUT_WITH_BOTTOMBAR */);
  768. }
  769. return this.logger.icon("OUTPUT" /* OUTPUT */);
  770. }
  771. if (task.hasSubtasks()) {
  772. if (task.isStarted() || task.isPrompt() && rendererOptions.showSubtasks !== false && !task.subtasks.every((subtask) => !subtask.hasTitle())) {
  773. return this.logger.icon("PENDING" /* PENDING */);
  774. } else if (task.isCompleted() && task.subtasks.some((subtask) => subtask.hasFailed())) {
  775. return this.logger.icon("COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */);
  776. } else if (task.hasFailed()) {
  777. return this.logger.icon("FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */);
  778. }
  779. }
  780. if (task.isStarted() || task.isPrompt()) {
  781. return this.logger.icon("PENDING" /* PENDING */, !this.options?.lazy && this.spinner.fetch());
  782. } else if (task.isCompleted()) {
  783. return this.logger.icon("COMPLETED" /* COMPLETED */);
  784. } else if (task.isRetrying()) {
  785. return this.logger.icon("RETRY" /* RETRY */, !this.options?.lazy && this.spinner.fetch());
  786. } else if (task.isRollingBack()) {
  787. return this.logger.icon("ROLLING_BACK" /* ROLLING_BACK */, !this.options?.lazy && this.spinner.fetch());
  788. } else if (task.hasRolledBack()) {
  789. return this.logger.icon("ROLLED_BACK" /* ROLLED_BACK */);
  790. } else if (task.hasFailed()) {
  791. return this.logger.icon("FAILED" /* FAILED */);
  792. } else if (task.isPaused()) {
  793. return this.logger.icon("PAUSED" /* PAUSED */);
  794. }
  795. return this.logger.icon("WAITING" /* WAITING */);
  796. }
  797. format(message, icon, level) {
  798. if (message.trim() === "") {
  799. return [];
  800. }
  801. if (icon) {
  802. message = icon + " " + message;
  803. }
  804. let parsed;
  805. const columns = (process.stdout.columns ?? 80) - level * this.options.indentation - 2;
  806. switch (this.options.formatOutput) {
  807. case "truncate":
  808. parsed = message.split(EOL3).map((s, i) => {
  809. return this.truncate(this.indent(s, i), columns);
  810. });
  811. break;
  812. case "wrap":
  813. parsed = this.wrap(message, columns, { hard: true, trim: false }).split(EOL3).map((s, i) => this.indent(s, i));
  814. break;
  815. default:
  816. throw new ListrRendererError("Format option for the renderer is wrong.");
  817. }
  818. if (this.options.removeEmptyLines) {
  819. parsed = parsed.filter(Boolean);
  820. }
  821. return parsed.map((str) => indent(str, level * this.options.indentation));
  822. }
  823. shouldOutputToOutputBar(task) {
  824. const outputBar = this.cache.rendererTaskOptions.get(task.id).outputBar;
  825. return typeof outputBar === "number" && outputBar !== 0 || typeof outputBar === "boolean" && outputBar !== false;
  826. }
  827. shouldOutputToBottomBar(task) {
  828. const bottomBar = this.cache.rendererTaskOptions.get(task.id).bottomBar;
  829. return typeof bottomBar === "number" && bottomBar !== 0 || typeof bottomBar === "boolean" && bottomBar !== false || !task.hasTitle();
  830. }
  831. renderer(tasks, level = 0) {
  832. return tasks.flatMap((task) => {
  833. if (!task.isEnabled()) {
  834. return [];
  835. }
  836. if (this.cache.render.has(task.id)) {
  837. return this.cache.render.get(task.id);
  838. }
  839. this.calculate(task);
  840. this.setupBuffer(task);
  841. const rendererOptions = this.cache.rendererOptions.get(task.id);
  842. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  843. const output = [];
  844. if (task.isPrompt()) {
  845. if (this.activePrompt && this.activePrompt !== task.id) {
  846. throw new ListrRendererError("Only one prompt can be active at the given time, please re-evaluate your task design.");
  847. } else if (!this.activePrompt) {
  848. task.on("PROMPT" /* PROMPT */, (prompt) => {
  849. const cleansed = cleanseAnsi(prompt);
  850. if (cleansed) {
  851. this.prompt = cleansed;
  852. }
  853. });
  854. task.on("STATE" /* STATE */, (state) => {
  855. if (state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */ || task.hasFinalized() || task.hasReset()) {
  856. this.prompt = null;
  857. this.activePrompt = null;
  858. task.off("PROMPT" /* PROMPT */);
  859. }
  860. });
  861. this.activePrompt = task.id;
  862. }
  863. }
  864. if (task.hasTitle()) {
  865. if (!(tasks.some((task2) => task2.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) {
  866. if (task.hasFailed() && rendererOptions.collapseErrors) {
  867. output.push(...this.format(!task.hasSubtasks() && task.message.error && rendererOptions.showErrorMessage ? task.message.error : task.title, this.style(task), level));
  868. } else if (task.isSkipped() && rendererOptions.collapseSkips) {
  869. output.push(
  870. ...this.format(
  871. this.logger.suffix(task.message.skip && rendererOptions.showSkipMessage ? task.message.skip : task.title, {
  872. field: "SKIPPED" /* SKIPPED */,
  873. condition: rendererOptions.suffixSkips,
  874. format: /* @__PURE__ */ __name(() => color.dim, "format")
  875. }),
  876. this.style(task),
  877. level
  878. )
  879. );
  880. } else if (task.isRetrying()) {
  881. output.push(
  882. ...this.format(
  883. this.logger.suffix(task.title, {
  884. field: `${"RETRY" /* RETRY */}:${task.message.retry.count}`,
  885. format: /* @__PURE__ */ __name(() => color.yellow, "format"),
  886. condition: rendererOptions.suffixRetries
  887. }),
  888. this.style(task),
  889. level
  890. )
  891. );
  892. } else if (task.isCompleted() && task.hasTitle() && assertFunctionOrSelf(rendererTaskOptions.timer?.condition, task.message.duration)) {
  893. output.push(
  894. ...this.format(
  895. this.logger.suffix(task?.title, {
  896. ...rendererTaskOptions.timer,
  897. args: [task.message.duration]
  898. }),
  899. this.style(task),
  900. level
  901. )
  902. );
  903. } else if (task.isPaused()) {
  904. output.push(
  905. ...this.format(
  906. this.logger.suffix(task.title, {
  907. ...rendererOptions.pausedTimer,
  908. args: [task.message.paused - Date.now()]
  909. }),
  910. this.style(task),
  911. level
  912. )
  913. );
  914. } else {
  915. output.push(...this.format(task.title, this.style(task), level));
  916. }
  917. } else {
  918. output.push(...this.format(task.title, this.logger.icon("COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */), level));
  919. }
  920. }
  921. if (!task.hasSubtasks() || !rendererOptions.showSubtasks) {
  922. if (task.hasFailed() && rendererOptions.collapseErrors === false && (rendererOptions.showErrorMessage || !rendererOptions.showSubtasks)) {
  923. output.push(...this.dump(task, level, "FAILED" /* FAILED */));
  924. } else if (task.isSkipped() && rendererOptions.collapseSkips === false && (rendererOptions.showSkipMessage || !rendererOptions.showSubtasks)) {
  925. output.push(...this.dump(task, level, "SKIPPED" /* SKIPPED */));
  926. }
  927. }
  928. if (task.isPending() || rendererTaskOptions.persistentOutput) {
  929. output.push(...this.renderOutputBar(task, level));
  930. }
  931. if (
  932. // check if renderer option is on first
  933. rendererOptions.showSubtasks !== false && // if it doesnt have subtasks no need to check
  934. task.hasSubtasks() && (task.isPending() || task.hasFinalized() && !task.hasTitle() || // have to be completed and have subtasks
  935. task.isCompleted() && rendererOptions.collapseSubtasks === false && !task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === true) || // if any of the subtasks have the collapse option of
  936. task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === false) || // if any of the subtasks has failed
  937. task.subtasks.some((subtask) => subtask.hasFailed()) || // if any of the subtasks rolled back
  938. task.subtasks.some((subtask) => subtask.hasRolledBack()))
  939. ) {
  940. const subtaskLevel = !task.hasTitle() ? level : level + 1;
  941. const subtaskRender = this.renderer(task.subtasks, subtaskLevel);
  942. output.push(...subtaskRender);
  943. }
  944. if (task.hasFinalized()) {
  945. if (!rendererTaskOptions.persistentOutput) {
  946. this.buffer.bottom.delete(task.id);
  947. this.buffer.output.delete(task.id);
  948. }
  949. }
  950. if (task.isClosed()) {
  951. this.cache.render.set(task.id, output);
  952. this.reset(task);
  953. }
  954. return output;
  955. });
  956. }
  957. renderOutputBar(task, level) {
  958. const output = this.buffer.output.get(task.id);
  959. if (!output) {
  960. return [];
  961. }
  962. return output.all.flatMap((o) => this.dump(task, level, "OUTPUT" /* OUTPUT */, o.entry));
  963. }
  964. renderBottomBar() {
  965. if (this.buffer.bottom.size === 0) {
  966. return [];
  967. }
  968. return Array.from(this.buffer.bottom.values()).flatMap((output) => output.all).sort((a, b) => a.time - b.time).map((output) => output.entry);
  969. }
  970. renderPrompt() {
  971. if (!this.prompt) {
  972. return [];
  973. }
  974. return [this.prompt];
  975. }
  976. calculate(task) {
  977. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  978. return;
  979. }
  980. const rendererOptions = {
  981. ...this.options,
  982. ...task.rendererOptions
  983. };
  984. this.cache.rendererOptions.set(task.id, rendererOptions);
  985. this.cache.rendererTaskOptions.set(task.id, {
  986. ..._DefaultRenderer.rendererTaskOptions,
  987. timer: rendererOptions.timer,
  988. ...task.rendererTaskOptions
  989. });
  990. }
  991. setupBuffer(task) {
  992. if (this.buffer.bottom.has(task.id) || this.buffer.output.has(task.id)) {
  993. return;
  994. }
  995. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  996. if (this.shouldOutputToBottomBar(task) && !this.buffer.bottom.has(task.id)) {
  997. this.buffer.bottom.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.bottomBar === "number" ? rendererTaskOptions.bottomBar : 1 }));
  998. task.on("OUTPUT" /* OUTPUT */, (output) => {
  999. const data = this.dump(task, -1, "OUTPUT" /* OUTPUT */, output);
  1000. this.buffer.bottom.get(task.id).write(data.join(EOL3));
  1001. });
  1002. task.on("STATE" /* STATE */, (state) => {
  1003. switch (state) {
  1004. case ("RETRY" /* RETRY */ || "ROLLING_BACK" /* ROLLING_BACK */):
  1005. this.buffer.bottom.delete(task.id);
  1006. break;
  1007. }
  1008. });
  1009. } else if (this.shouldOutputToOutputBar(task) && !this.buffer.output.has(task.id)) {
  1010. this.buffer.output.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.outputBar === "number" ? rendererTaskOptions.outputBar : 1 }));
  1011. task.on("OUTPUT" /* OUTPUT */, (output) => {
  1012. this.buffer.output.get(task.id).write(output);
  1013. });
  1014. task.on("STATE" /* STATE */, (state) => {
  1015. switch (state) {
  1016. case ("RETRY" /* RETRY */ || "ROLLING_BACK" /* ROLLING_BACK */):
  1017. this.buffer.output.delete(task.id);
  1018. break;
  1019. }
  1020. });
  1021. }
  1022. }
  1023. reset(task) {
  1024. this.cache.rendererOptions.delete(task.id);
  1025. this.cache.rendererTaskOptions.delete(task.id);
  1026. this.buffer.output.delete(task.id);
  1027. }
  1028. dump(task, level, source = "OUTPUT" /* OUTPUT */, data) {
  1029. if (!data) {
  1030. switch (source) {
  1031. case "OUTPUT" /* OUTPUT */:
  1032. data = task.output;
  1033. break;
  1034. case "SKIPPED" /* SKIPPED */:
  1035. data = task.message.skip;
  1036. break;
  1037. case "FAILED" /* FAILED */:
  1038. data = task.message.error;
  1039. break;
  1040. }
  1041. }
  1042. if (task.hasTitle() && source === "FAILED" /* FAILED */ && data === task.title || typeof data !== "string") {
  1043. return [];
  1044. }
  1045. if (source === "OUTPUT" /* OUTPUT */) {
  1046. data = cleanseAnsi(data);
  1047. }
  1048. return this.format(data, this.style(task, true), level + 1);
  1049. }
  1050. indent(str, i) {
  1051. return i > 0 ? indent(str.trimEnd(), this.options.indentation) : str.trimEnd();
  1052. }
  1053. };
  1054. // src/renderer/silent/renderer.ts
  1055. var SilentRenderer = class {
  1056. constructor(tasks, options) {
  1057. this.tasks = tasks;
  1058. this.options = options;
  1059. }
  1060. static {
  1061. __name(this, "SilentRenderer");
  1062. }
  1063. static nonTTY = true;
  1064. static rendererOptions;
  1065. static rendererTaskOptions;
  1066. render() {
  1067. return;
  1068. }
  1069. end() {
  1070. return;
  1071. }
  1072. };
  1073. // src/renderer/simple/renderer.ts
  1074. var SimpleRenderer = class _SimpleRenderer {
  1075. constructor(tasks, options) {
  1076. this.tasks = tasks;
  1077. this.options = options;
  1078. this.options = {
  1079. ..._SimpleRenderer.rendererOptions,
  1080. ...options,
  1081. icon: {
  1082. ...LISTR_LOGGER_STYLE.icon,
  1083. ...options?.icon ?? {}
  1084. },
  1085. color: {
  1086. ...LISTR_LOGGER_STYLE.color,
  1087. ...options?.color ?? {}
  1088. }
  1089. };
  1090. this.logger = this.options.logger ?? new ListrLogger({ useIcons: true, toStderr: LISTR_LOGGER_STDERR_LEVELS });
  1091. this.logger.options.icon = this.options.icon;
  1092. this.logger.options.color = this.options.color;
  1093. if (this.options.timestamp) {
  1094. this.logger.options.fields.prefix.unshift(this.options.timestamp);
  1095. }
  1096. }
  1097. static {
  1098. __name(this, "SimpleRenderer");
  1099. }
  1100. static nonTTY = true;
  1101. static rendererOptions = {
  1102. pausedTimer: {
  1103. ...PRESET_TIMER,
  1104. field: /* @__PURE__ */ __name((time) => `${"PAUSED" /* PAUSED */}:${time}`, "field"),
  1105. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  1106. }
  1107. };
  1108. static rendererTaskOptions = {};
  1109. logger;
  1110. cache = {
  1111. rendererOptions: /* @__PURE__ */ new Map(),
  1112. rendererTaskOptions: /* @__PURE__ */ new Map()
  1113. };
  1114. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1115. end() {
  1116. }
  1117. render() {
  1118. this.renderer(this.tasks);
  1119. }
  1120. renderer(tasks) {
  1121. tasks.forEach((task) => {
  1122. this.calculate(task);
  1123. task.once("CLOSED" /* CLOSED */, () => {
  1124. this.reset(task);
  1125. });
  1126. const rendererOptions = this.cache.rendererOptions.get(task.id);
  1127. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  1128. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1129. this.renderer(subtasks);
  1130. });
  1131. task.on("STATE" /* STATE */, (state) => {
  1132. if (!task.hasTitle()) {
  1133. return;
  1134. }
  1135. if (state === "STARTED" /* STARTED */) {
  1136. this.logger.log("STARTED" /* STARTED */, task.title);
  1137. } else if (state === "COMPLETED" /* COMPLETED */) {
  1138. const timer = rendererTaskOptions?.timer;
  1139. this.logger.log(
  1140. "COMPLETED" /* COMPLETED */,
  1141. task.title,
  1142. timer && {
  1143. suffix: {
  1144. ...timer,
  1145. condition: !!task.message?.duration && timer.condition,
  1146. args: [task.message.duration]
  1147. }
  1148. }
  1149. );
  1150. } else if (state === "PROMPT" /* PROMPT */) {
  1151. this.logger.process.hijack();
  1152. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1153. this.logger.process.toStderr(prompt, false);
  1154. });
  1155. } else if (state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */) {
  1156. task.off("PROMPT" /* PROMPT */);
  1157. this.logger.process.release();
  1158. }
  1159. });
  1160. task.on("OUTPUT" /* OUTPUT */, (output) => {
  1161. this.logger.log("OUTPUT" /* OUTPUT */, output);
  1162. });
  1163. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1164. if (message.error) {
  1165. this.logger.log("FAILED" /* FAILED */, task.title, {
  1166. suffix: {
  1167. field: `${"FAILED" /* FAILED */}: ${message.error}`,
  1168. format: /* @__PURE__ */ __name(() => color.red, "format")
  1169. }
  1170. });
  1171. } else if (message.skip) {
  1172. this.logger.log("SKIPPED" /* SKIPPED */, task.title, {
  1173. suffix: {
  1174. field: `${"SKIPPED" /* SKIPPED */}: ${message.skip}`,
  1175. format: /* @__PURE__ */ __name(() => color.yellow, "format")
  1176. }
  1177. });
  1178. } else if (message.rollback) {
  1179. this.logger.log("ROLLBACK" /* ROLLBACK */, task.title, {
  1180. suffix: {
  1181. field: `${"ROLLBACK" /* ROLLBACK */}: ${message.rollback}`,
  1182. format: /* @__PURE__ */ __name(() => color.red, "format")
  1183. }
  1184. });
  1185. } else if (message.retry) {
  1186. this.logger.log("RETRY" /* RETRY */, task.title, {
  1187. suffix: {
  1188. field: `${"RETRY" /* RETRY */}:${message.retry.count}`,
  1189. format: /* @__PURE__ */ __name(() => color.red, "format")
  1190. }
  1191. });
  1192. } else if (message.paused) {
  1193. const timer = rendererOptions?.pausedTimer;
  1194. this.logger.log(
  1195. "PAUSED" /* PAUSED */,
  1196. task.title,
  1197. timer && {
  1198. suffix: {
  1199. ...timer,
  1200. condition: !!message?.paused && timer.condition,
  1201. args: [message.paused - Date.now()]
  1202. }
  1203. }
  1204. );
  1205. }
  1206. });
  1207. });
  1208. }
  1209. calculate(task) {
  1210. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  1211. return;
  1212. }
  1213. const rendererOptions = {
  1214. ...this.options,
  1215. ...task.rendererOptions
  1216. };
  1217. this.cache.rendererOptions.set(task.id, rendererOptions);
  1218. this.cache.rendererTaskOptions.set(task.id, {
  1219. ..._SimpleRenderer.rendererTaskOptions,
  1220. timer: rendererOptions.timer,
  1221. ...task.rendererTaskOptions
  1222. });
  1223. }
  1224. reset(task) {
  1225. this.cache.rendererOptions.delete(task.id);
  1226. this.cache.rendererTaskOptions.delete(task.id);
  1227. }
  1228. };
  1229. // src/renderer/test/serializer.ts
  1230. var TestRendererSerializer = class {
  1231. constructor(options) {
  1232. this.options = options;
  1233. }
  1234. static {
  1235. __name(this, "TestRendererSerializer");
  1236. }
  1237. serialize(event, data, task) {
  1238. return JSON.stringify(this.generate(event, data, task));
  1239. }
  1240. generate(event, data, task) {
  1241. const output = {
  1242. event,
  1243. data
  1244. };
  1245. if (typeof this.options?.task !== "boolean") {
  1246. const t = Object.fromEntries(
  1247. this.options.task.map((entity) => {
  1248. const property = task[entity];
  1249. if (typeof property === "function") {
  1250. return [entity, property.call(task)];
  1251. }
  1252. return [entity, property];
  1253. })
  1254. );
  1255. if (Object.keys(task).length > 0) {
  1256. output.task = t;
  1257. }
  1258. }
  1259. return output;
  1260. }
  1261. };
  1262. // src/renderer/test/renderer.ts
  1263. var TestRenderer = class _TestRenderer {
  1264. constructor(tasks, options) {
  1265. this.tasks = tasks;
  1266. this.options = options;
  1267. this.options = { ..._TestRenderer.rendererOptions, ...this.options };
  1268. this.logger = this.options.logger ?? new ListrLogger({ useIcons: false });
  1269. this.serializer = new TestRendererSerializer(this.options);
  1270. }
  1271. static {
  1272. __name(this, "TestRenderer");
  1273. }
  1274. static nonTTY = true;
  1275. static rendererOptions = {
  1276. subtasks: true,
  1277. state: Object.values(ListrTaskState),
  1278. output: true,
  1279. prompt: true,
  1280. title: true,
  1281. messages: ["skip", "error", "retry", "rollback", "paused"],
  1282. messagesToStderr: ["error", "rollback", "retry"],
  1283. task: [
  1284. "hasRolledBack",
  1285. "isRollingBack",
  1286. "isCompleted",
  1287. "isSkipped",
  1288. "hasFinalized",
  1289. "hasSubtasks",
  1290. "title",
  1291. "hasReset",
  1292. "hasTitle",
  1293. "isPrompt",
  1294. "isPaused",
  1295. "isPending",
  1296. "isSkipped",
  1297. "isStarted",
  1298. "hasFailed",
  1299. "isEnabled",
  1300. "isRetrying",
  1301. "path"
  1302. ]
  1303. };
  1304. static rendererTaskOptions;
  1305. logger;
  1306. serializer;
  1307. render() {
  1308. this.renderer(this.tasks);
  1309. }
  1310. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1311. end() {
  1312. }
  1313. // verbose renderer multi-level
  1314. renderer(tasks) {
  1315. tasks.forEach((task) => {
  1316. if (this.options.subtasks) {
  1317. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1318. this.renderer(subtasks);
  1319. });
  1320. }
  1321. if (this.options.state) {
  1322. task.on("STATE" /* STATE */, (state) => {
  1323. this.logger.toStdout(this.serializer.serialize("STATE" /* STATE */, state, task));
  1324. });
  1325. }
  1326. if (this.options.output) {
  1327. task.on("OUTPUT" /* OUTPUT */, (data) => {
  1328. this.logger.toStdout(this.serializer.serialize("OUTPUT" /* OUTPUT */, data, task));
  1329. });
  1330. }
  1331. if (this.options.prompt) {
  1332. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1333. this.logger.toStdout(this.serializer.serialize("PROMPT" /* PROMPT */, prompt, task));
  1334. });
  1335. }
  1336. if (this.options.title) {
  1337. task.on("TITLE" /* TITLE */, (title) => {
  1338. this.logger.toStdout(this.serializer.serialize("TITLE" /* TITLE */, title, task));
  1339. });
  1340. }
  1341. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1342. const parsed = Object.fromEntries(
  1343. Object.entries(message).map(([key, value]) => {
  1344. if (this.options.messages.includes(key)) {
  1345. return [key, value];
  1346. }
  1347. }).filter(Boolean)
  1348. );
  1349. if (Object.keys(parsed).length > 0) {
  1350. const output = this.serializer.serialize("MESSAGE" /* MESSAGE */, parsed, task);
  1351. if (this.options.messagesToStderr.some((state) => Object.keys(parsed).includes(state))) {
  1352. this.logger.toStderr(output);
  1353. } else {
  1354. this.logger.toStdout(output);
  1355. }
  1356. }
  1357. });
  1358. });
  1359. }
  1360. };
  1361. // src/renderer/verbose/renderer.ts
  1362. var VerboseRenderer = class _VerboseRenderer {
  1363. constructor(tasks, options) {
  1364. this.tasks = tasks;
  1365. this.options = options;
  1366. this.options = {
  1367. ..._VerboseRenderer.rendererOptions,
  1368. ...this.options,
  1369. icon: {
  1370. ...LISTR_LOGGER_STYLE.icon,
  1371. ...options?.icon ?? {}
  1372. },
  1373. color: {
  1374. ...LISTR_LOGGER_STYLE.color,
  1375. ...options?.color ?? {}
  1376. }
  1377. };
  1378. this.logger = this.options.logger ?? new ListrLogger({ useIcons: false, toStderr: LISTR_LOGGER_STDERR_LEVELS });
  1379. this.logger.options.icon = this.options.icon;
  1380. this.logger.options.color = this.options.color;
  1381. if (this.options.timestamp) {
  1382. this.logger.options.fields.prefix.unshift(this.options.timestamp);
  1383. }
  1384. }
  1385. static {
  1386. __name(this, "VerboseRenderer");
  1387. }
  1388. static nonTTY = true;
  1389. static rendererOptions = {
  1390. logTitleChange: false,
  1391. pausedTimer: {
  1392. ...PRESET_TIMER,
  1393. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  1394. }
  1395. };
  1396. static rendererTaskOptions;
  1397. logger;
  1398. cache = {
  1399. rendererOptions: /* @__PURE__ */ new Map(),
  1400. rendererTaskOptions: /* @__PURE__ */ new Map()
  1401. };
  1402. render() {
  1403. this.renderer(this.tasks);
  1404. }
  1405. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1406. end() {
  1407. }
  1408. renderer(tasks) {
  1409. tasks.forEach((task) => {
  1410. this.calculate(task);
  1411. task.once("CLOSED" /* CLOSED */, () => {
  1412. this.reset(task);
  1413. });
  1414. const rendererOptions = this.cache.rendererOptions.get(task.id);
  1415. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  1416. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1417. this.renderer(subtasks);
  1418. });
  1419. task.on("STATE" /* STATE */, (state) => {
  1420. if (!task.hasTitle()) {
  1421. return;
  1422. }
  1423. if (state === "STARTED" /* STARTED */) {
  1424. this.logger.log("STARTED" /* STARTED */, task.title);
  1425. } else if (state === "COMPLETED" /* COMPLETED */) {
  1426. const timer = rendererTaskOptions.timer;
  1427. this.logger.log(
  1428. "COMPLETED" /* COMPLETED */,
  1429. task.title,
  1430. timer && {
  1431. suffix: {
  1432. ...timer,
  1433. condition: !!task.message?.duration && timer.condition,
  1434. args: [task.message.duration]
  1435. }
  1436. }
  1437. );
  1438. }
  1439. });
  1440. task.on("OUTPUT" /* OUTPUT */, (data) => {
  1441. this.logger.log("OUTPUT" /* OUTPUT */, data);
  1442. });
  1443. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1444. const cleansed = cleanseAnsi(prompt);
  1445. if (cleansed) {
  1446. this.logger.log("PROMPT" /* PROMPT */, cleansed);
  1447. }
  1448. });
  1449. if (this.options?.logTitleChange !== false) {
  1450. task.on("TITLE" /* TITLE */, (title) => {
  1451. this.logger.log("TITLE" /* TITLE */, title);
  1452. });
  1453. }
  1454. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1455. if (message?.error) {
  1456. this.logger.log("FAILED" /* FAILED */, message.error);
  1457. } else if (message?.skip) {
  1458. this.logger.log("SKIPPED" /* SKIPPED */, message.skip);
  1459. } else if (message?.rollback) {
  1460. this.logger.log("ROLLBACK" /* ROLLBACK */, message.rollback);
  1461. } else if (message?.retry) {
  1462. this.logger.log("RETRY" /* RETRY */, task.title, { suffix: message.retry.count.toString() });
  1463. } else if (message?.paused) {
  1464. const timer = rendererOptions?.pausedTimer;
  1465. this.logger.log(
  1466. "PAUSED" /* PAUSED */,
  1467. task.title,
  1468. timer && {
  1469. suffix: {
  1470. ...timer,
  1471. condition: !!message?.paused && timer.condition,
  1472. args: [message.paused - Date.now()]
  1473. }
  1474. }
  1475. );
  1476. }
  1477. });
  1478. });
  1479. }
  1480. calculate(task) {
  1481. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  1482. return;
  1483. }
  1484. const rendererOptions = {
  1485. ...this.options,
  1486. ...task.rendererOptions
  1487. };
  1488. this.cache.rendererOptions.set(task.id, rendererOptions);
  1489. this.cache.rendererTaskOptions.set(task.id, {
  1490. ..._VerboseRenderer.rendererTaskOptions,
  1491. timer: rendererOptions.timer,
  1492. ...task.rendererTaskOptions
  1493. });
  1494. }
  1495. reset(task) {
  1496. this.cache.rendererOptions.delete(task.id);
  1497. this.cache.rendererTaskOptions.delete(task.id);
  1498. }
  1499. };
  1500. // src/utils/ui/renderer.ts
  1501. var RENDERERS = {
  1502. default: DefaultRenderer,
  1503. simple: SimpleRenderer,
  1504. verbose: VerboseRenderer,
  1505. test: TestRenderer,
  1506. silent: SilentRenderer
  1507. };
  1508. function isRendererSupported(renderer) {
  1509. return process.stdout.isTTY === true || renderer.nonTTY === true;
  1510. }
  1511. __name(isRendererSupported, "isRendererSupported");
  1512. function getRendererClass(renderer) {
  1513. if (typeof renderer === "string") {
  1514. return RENDERERS[renderer] ?? RENDERERS.default;
  1515. }
  1516. return typeof renderer === "function" ? renderer : RENDERERS.default;
  1517. }
  1518. __name(getRendererClass, "getRendererClass");
  1519. function getRenderer(options) {
  1520. if (assertFunctionOrSelf(options?.silentRendererCondition)) {
  1521. return { renderer: getRendererClass("silent"), selection: "SILENT" /* SILENT */ };
  1522. }
  1523. const r = {
  1524. renderer: getRendererClass(options.renderer),
  1525. options: options.rendererOptions,
  1526. selection: "PRIMARY" /* PRIMARY */
  1527. };
  1528. if (!isRendererSupported(r.renderer) || assertFunctionOrSelf(options?.fallbackRendererCondition)) {
  1529. return {
  1530. renderer: getRendererClass(options.fallbackRenderer),
  1531. options: options.fallbackRendererOptions,
  1532. selection: "SECONDARY" /* SECONDARY */
  1533. };
  1534. }
  1535. return r;
  1536. }
  1537. __name(getRenderer, "getRenderer");
  1538. // src/utils/assert.ts
  1539. function assertFunctionOrSelf(functionOrSelf, ...args) {
  1540. if (typeof functionOrSelf === "function") {
  1541. return functionOrSelf(...args);
  1542. } else {
  1543. return functionOrSelf;
  1544. }
  1545. }
  1546. __name(assertFunctionOrSelf, "assertFunctionOrSelf");
  1547. // src/utils/clone.ts
  1548. import rfdc from "rfdc";
  1549. var clone = rfdc({ circles: true });
  1550. function cloneObject(obj) {
  1551. return clone(obj);
  1552. }
  1553. __name(cloneObject, "cloneObject");
  1554. // src/utils/concurrency.ts
  1555. var Concurrency = class {
  1556. static {
  1557. __name(this, "Concurrency");
  1558. }
  1559. concurrency;
  1560. count;
  1561. queue;
  1562. constructor(options) {
  1563. this.concurrency = options.concurrency;
  1564. this.count = 0;
  1565. this.queue = /* @__PURE__ */ new Set();
  1566. }
  1567. add(fn) {
  1568. if (this.count < this.concurrency) {
  1569. return this.run(fn);
  1570. }
  1571. return new Promise((resolve) => {
  1572. const callback = /* @__PURE__ */ __name(() => resolve(this.run(fn)), "callback");
  1573. this.queue.add(callback);
  1574. });
  1575. }
  1576. flush() {
  1577. for (const callback of this.queue) {
  1578. if (this.count >= this.concurrency) {
  1579. break;
  1580. }
  1581. this.queue.delete(callback);
  1582. callback();
  1583. }
  1584. }
  1585. run(fn) {
  1586. this.count++;
  1587. const promise = fn();
  1588. const cleanup = /* @__PURE__ */ __name(() => {
  1589. this.count--;
  1590. this.flush();
  1591. }, "cleanup");
  1592. promise.then(cleanup, () => {
  1593. this.queue.clear();
  1594. });
  1595. return promise;
  1596. }
  1597. };
  1598. // src/utils/delay.ts
  1599. function delay(time) {
  1600. return new Promise((resolve) => {
  1601. setTimeout(resolve, time);
  1602. });
  1603. }
  1604. __name(delay, "delay");
  1605. // src/interfaces/listr-error.interface.ts
  1606. var ListrError = class extends Error {
  1607. constructor(error, type, task) {
  1608. super(error.message);
  1609. this.error = error;
  1610. this.type = type;
  1611. this.task = task;
  1612. this.name = "ListrError";
  1613. this.path = task.path;
  1614. if (task?.options.collectErrors === "full") {
  1615. this.task = cloneObject(task);
  1616. this.ctx = cloneObject(task.listr.ctx);
  1617. }
  1618. this.stack = error?.stack;
  1619. }
  1620. static {
  1621. __name(this, "ListrError");
  1622. }
  1623. path;
  1624. ctx;
  1625. };
  1626. // src/interfaces/listr-renderer-error.interface.ts
  1627. var ListrRendererError = class extends Error {
  1628. static {
  1629. __name(this, "ListrRendererError");
  1630. }
  1631. };
  1632. // src/interfaces/prompt-error.interface.ts
  1633. var PromptError = class extends Error {
  1634. static {
  1635. __name(this, "PromptError");
  1636. }
  1637. };
  1638. // src/lib/task-wrapper.ts
  1639. var TaskWrapper = class {
  1640. constructor(task) {
  1641. this.task = task;
  1642. }
  1643. static {
  1644. __name(this, "TaskWrapper");
  1645. }
  1646. /* istanbul ignore next */
  1647. get title() {
  1648. return this.task.title;
  1649. }
  1650. /**
  1651. * Title of the current task.
  1652. *
  1653. * @see {@link https://listr2.kilic.dev/task/title.html}
  1654. */
  1655. set title(title) {
  1656. title = Array.isArray(title) ? title : [title];
  1657. this.task.title$ = splat(title.shift(), ...title);
  1658. }
  1659. /* istanbul ignore next */
  1660. get output() {
  1661. return this.task.output;
  1662. }
  1663. /* istanbul ignore next */
  1664. /**
  1665. * Send output from the current task to the renderer.
  1666. *
  1667. * @see {@link https://listr2.kilic.dev/task/output.html}
  1668. */
  1669. set output(output) {
  1670. output = Array.isArray(output) ? output : [output];
  1671. this.task.output$ = splat(output.shift(), ...output);
  1672. }
  1673. /* istanbul ignore next */
  1674. /** Send an output to the output channel as prompt. */
  1675. set promptOutput(output) {
  1676. this.task.promptOutput$ = output;
  1677. }
  1678. /**
  1679. * Creates a new set of Listr subtasks.
  1680. *
  1681. * @see {@link https://listr2.kilic.dev/task/subtasks.html}
  1682. */
  1683. newListr(task, options) {
  1684. let tasks;
  1685. if (typeof task === "function") {
  1686. tasks = task(this);
  1687. } else {
  1688. tasks = task;
  1689. }
  1690. return new Listr(tasks, options, this.task);
  1691. }
  1692. /**
  1693. * Report an error that has to be collected and handled.
  1694. *
  1695. * @see {@link https://listr2.kilic.dev/task/error-handling.html}
  1696. */
  1697. report(error, type) {
  1698. if (this.task.options.collectErrors !== false) {
  1699. this.task.listr.errors.push(new ListrError(error, type, this.task));
  1700. }
  1701. this.task.message$ = { error: error.message ?? this.task?.title };
  1702. }
  1703. /**
  1704. * Skip the current task.
  1705. *
  1706. * @see {@link https://listr2.kilic.dev/task/skip.html}
  1707. */
  1708. skip(message, ...metadata) {
  1709. this.task.state$ = "SKIPPED" /* SKIPPED */;
  1710. if (message) {
  1711. this.task.message$ = { skip: message ? splat(message, ...metadata) : this.task?.title };
  1712. }
  1713. }
  1714. /**
  1715. * Check whether this task is currently in a retry state.
  1716. *
  1717. * @see {@link https://listr2.kilic.dev/task/retry.html}
  1718. */
  1719. isRetrying() {
  1720. return this.task.isRetrying() ? this.task.retry : { count: 0 };
  1721. }
  1722. /* istanbul ignore next */
  1723. /**
  1724. * Create a new prompt for getting user input through the prompt adapter.
  1725. * This will create a new prompt through the adapter if the task is not currently rendering a prompt or will return the active instance.
  1726. *
  1727. * This part of the application requires optional peer dependencies, please refer to documentation.
  1728. *
  1729. * @see {@link https://listr2.kilic.dev/task/prompt.html}
  1730. */
  1731. prompt(adapter) {
  1732. if (this.task.prompt) {
  1733. return this.task.prompt;
  1734. }
  1735. return new adapter(this.task, this);
  1736. }
  1737. /* istanbul ignore next */
  1738. /**
  1739. * Generates a fake stdout for your use case, where it will be tunnelled through Listr to handle the rendering process.
  1740. *
  1741. * @see {@link https://listr2.kilic.dev/renderer/process-output.html}
  1742. */
  1743. stdout(type) {
  1744. return createWritable((chunk) => {
  1745. switch (type) {
  1746. case "PROMPT" /* PROMPT */:
  1747. this.promptOutput = chunk;
  1748. break;
  1749. default:
  1750. this.output = chunk;
  1751. }
  1752. });
  1753. }
  1754. /** Run this task. */
  1755. run(ctx) {
  1756. return this.task.run(ctx, this);
  1757. }
  1758. };
  1759. // src/lib/task.ts
  1760. import { randomUUID } from "crypto";
  1761. // src/lib/listr-task-event-manager.ts
  1762. var ListrTaskEventManager = class extends EventManager {
  1763. static {
  1764. __name(this, "ListrTaskEventManager");
  1765. }
  1766. };
  1767. // src/lib/task.ts
  1768. var Task = class extends ListrTaskEventManager {
  1769. constructor(listr, task, options, rendererOptions, rendererTaskOptions) {
  1770. super();
  1771. this.listr = listr;
  1772. this.task = task;
  1773. this.options = options;
  1774. this.rendererOptions = rendererOptions;
  1775. this.rendererTaskOptions = rendererTaskOptions;
  1776. if (task.title) {
  1777. const title = Array.isArray(task?.title) ? task.title : [task.title];
  1778. this.title = splat(title.shift(), ...title);
  1779. this.initialTitle = this.title;
  1780. }
  1781. this.taskFn = task.task;
  1782. this.parent = listr.parentTask;
  1783. }
  1784. static {
  1785. __name(this, "Task");
  1786. }
  1787. /** Unique id per task, can be used for identifying a Task. */
  1788. id = randomUUID();
  1789. /** The current state of the task. */
  1790. state = "WAITING" /* WAITING */;
  1791. /** Subtasks of the current task. */
  1792. subtasks;
  1793. /** Title of the task. */
  1794. title;
  1795. /** Initial/Untouched version of the title for using whenever task has a reset. */
  1796. initialTitle;
  1797. /** Output channel for the task. */
  1798. output;
  1799. /** Current state of the retry process whenever the task is retrying. */
  1800. retry;
  1801. /**
  1802. * A channel for messages.
  1803. *
  1804. * This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
  1805. */
  1806. message = {};
  1807. /** Current prompt instance or prompt error whenever the task is prompting. */
  1808. prompt;
  1809. /** Parent task of the current task. */
  1810. parent;
  1811. /** Enable flag of this task. */
  1812. enabled;
  1813. /** User provided Task callback function to run. */
  1814. taskFn;
  1815. /** Marks the task as closed. This is different from finalized since this is not really related to task itself. */
  1816. closed;
  1817. /**
  1818. * Update the current state of the Task and emit the neccassary events.
  1819. */
  1820. set state$(state) {
  1821. this.state = state;
  1822. this.emit("STATE" /* STATE */, state);
  1823. if (this.hasSubtasks() && this.hasFailed()) {
  1824. for (const subtask of this.subtasks) {
  1825. if (subtask.state === "STARTED" /* STARTED */) {
  1826. subtask.state$ = "FAILED" /* FAILED */;
  1827. }
  1828. }
  1829. }
  1830. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1831. }
  1832. /**
  1833. * Update the current output of the Task and emit the neccassary events.
  1834. */
  1835. set output$(data) {
  1836. this.output = data;
  1837. this.emit("OUTPUT" /* OUTPUT */, data);
  1838. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1839. }
  1840. /**
  1841. * Update the current prompt output of the Task and emit the neccassary events.
  1842. */
  1843. set promptOutput$(data) {
  1844. this.emit("PROMPT" /* PROMPT */, data);
  1845. if (cleanseAnsi(data)) {
  1846. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1847. }
  1848. }
  1849. /**
  1850. * Update or extend the current message of the Task and emit the neccassary events.
  1851. */
  1852. set message$(data) {
  1853. this.message = { ...this.message, ...data };
  1854. this.emit("MESSAGE" /* MESSAGE */, data);
  1855. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1856. }
  1857. /**
  1858. * Update the current title of the Task and emit the neccassary events.
  1859. */
  1860. set title$(title) {
  1861. this.title = title;
  1862. this.emit("TITLE" /* TITLE */, title);
  1863. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1864. }
  1865. /**
  1866. * Current task path in the hierarchy.
  1867. */
  1868. get path() {
  1869. return [...this.listr.path, this.initialTitle];
  1870. }
  1871. /**
  1872. * Checks whether the current task with the given context should be set as enabled.
  1873. */
  1874. async check(ctx) {
  1875. if (this.state === "WAITING" /* WAITING */) {
  1876. this.enabled = await assertFunctionOrSelf(this.task?.enabled ?? true, ctx);
  1877. this.emit("ENABLED" /* ENABLED */, this.enabled);
  1878. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1879. }
  1880. return this.enabled;
  1881. }
  1882. /** Returns whether this task has subtasks. */
  1883. hasSubtasks() {
  1884. return this.subtasks?.length > 0;
  1885. }
  1886. /** Returns whether this task is finalized in someform. */
  1887. hasFinalized() {
  1888. return this.isCompleted() || this.hasFailed() || this.isSkipped() || this.hasRolledBack();
  1889. }
  1890. /** Returns whether this task is in progress. */
  1891. isPending() {
  1892. return this.isStarted() || this.isPrompt() || this.hasReset();
  1893. }
  1894. /** Returns whether this task has started. */
  1895. isStarted() {
  1896. return this.state === "STARTED" /* STARTED */;
  1897. }
  1898. /** Returns whether this task is skipped. */
  1899. isSkipped() {
  1900. return this.state === "SKIPPED" /* SKIPPED */;
  1901. }
  1902. /** Returns whether this task has been completed. */
  1903. isCompleted() {
  1904. return this.state === "COMPLETED" /* COMPLETED */;
  1905. }
  1906. /** Returns whether this task has been failed. */
  1907. hasFailed() {
  1908. return this.state === "FAILED" /* FAILED */;
  1909. }
  1910. /** Returns whether this task has an active rollback task going on. */
  1911. isRollingBack() {
  1912. return this.state === "ROLLING_BACK" /* ROLLING_BACK */;
  1913. }
  1914. /** Returns whether the rollback action was successful. */
  1915. hasRolledBack() {
  1916. return this.state === "ROLLED_BACK" /* ROLLED_BACK */;
  1917. }
  1918. /** Returns whether this task has an actively retrying task going on. */
  1919. isRetrying() {
  1920. return this.state === "RETRY" /* RETRY */;
  1921. }
  1922. /** Returns whether this task has some kind of reset like retry and rollback going on. */
  1923. hasReset() {
  1924. return this.state === "RETRY" /* RETRY */ || this.state === "ROLLING_BACK" /* ROLLING_BACK */;
  1925. }
  1926. /** Returns whether enabled function resolves to true. */
  1927. isEnabled() {
  1928. return this.enabled;
  1929. }
  1930. /** Returns whether this task actually has a title. */
  1931. hasTitle() {
  1932. return typeof this?.title === "string";
  1933. }
  1934. /** Returns whether this task has a prompt inside. */
  1935. isPrompt() {
  1936. return this.state === "PROMPT" /* PROMPT */ || this.state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */;
  1937. }
  1938. /** Returns whether this task is currently paused. */
  1939. isPaused() {
  1940. return this.state === "PAUSED" /* PAUSED */;
  1941. }
  1942. /** Returns whether this task is closed. */
  1943. isClosed() {
  1944. return this.closed;
  1945. }
  1946. /** Pause the given task for certain time. */
  1947. async pause(time) {
  1948. const state = this.state;
  1949. this.state$ = "PAUSED" /* PAUSED */;
  1950. this.message$ = {
  1951. paused: Date.now() + time
  1952. };
  1953. await delay(time);
  1954. this.state$ = state;
  1955. this.message$ = {
  1956. paused: null
  1957. };
  1958. }
  1959. /** Run the current task. */
  1960. async run(context, wrapper) {
  1961. const handleResult = /* @__PURE__ */ __name((result) => {
  1962. if (result instanceof Listr) {
  1963. result.options = { ...this.options, ...result.options };
  1964. result.rendererClass = getRendererClass("silent");
  1965. this.subtasks = result.tasks;
  1966. result.errors = this.listr.errors;
  1967. this.emit("SUBTASK" /* SUBTASK */, this.subtasks);
  1968. result = result.run(context);
  1969. } else if (result instanceof Promise) {
  1970. result = result.then(handleResult);
  1971. } else if (isReadable(result)) {
  1972. result = new Promise((resolve, reject) => {
  1973. result.on("data", (data) => {
  1974. this.output$ = data.toString();
  1975. });
  1976. result.on("error", (error) => reject(error));
  1977. result.on("end", () => resolve(null));
  1978. });
  1979. } else if (isObservable(result)) {
  1980. result = new Promise((resolve, reject) => {
  1981. result.subscribe({
  1982. next: /* @__PURE__ */ __name((data) => {
  1983. this.output$ = data;
  1984. }, "next"),
  1985. error: reject,
  1986. complete: resolve
  1987. });
  1988. });
  1989. }
  1990. return result;
  1991. }, "handleResult");
  1992. const startTime = Date.now();
  1993. this.state$ = "STARTED" /* STARTED */;
  1994. const skipped = await assertFunctionOrSelf(this.task?.skip ?? false, context);
  1995. if (skipped) {
  1996. if (typeof skipped === "string") {
  1997. this.message$ = { skip: skipped };
  1998. } else if (this.hasTitle()) {
  1999. this.message$ = { skip: this.title };
  2000. } else {
  2001. this.message$ = { skip: "Skipped task without a title." };
  2002. }
  2003. this.state$ = "SKIPPED" /* SKIPPED */;
  2004. return;
  2005. }
  2006. try {
  2007. const retryCount = typeof this.task?.retry === "number" && this.task.retry > 0 ? this.task.retry + 1 : typeof this.task?.retry === "object" && this.task.retry.tries > 0 ? this.task.retry.tries + 1 : 1;
  2008. const retryDelay = typeof this.task.retry === "object" && this.task.retry.delay;
  2009. for (let retries = 1; retries <= retryCount; retries++) {
  2010. try {
  2011. await handleResult(this.taskFn(context, wrapper));
  2012. break;
  2013. } catch (err) {
  2014. if (retries !== retryCount) {
  2015. this.retry = { count: retries, error: err };
  2016. this.message$ = { retry: this.retry };
  2017. this.title$ = this.initialTitle;
  2018. this.output = void 0;
  2019. wrapper.report(err, "WILL_RETRY" /* WILL_RETRY */);
  2020. this.state$ = "RETRY" /* RETRY */;
  2021. if (retryDelay) {
  2022. await this.pause(retryDelay);
  2023. }
  2024. } else {
  2025. throw err;
  2026. }
  2027. }
  2028. }
  2029. if (this.isStarted() || this.isRetrying()) {
  2030. this.message$ = { duration: Date.now() - startTime };
  2031. this.state$ = "COMPLETED" /* COMPLETED */;
  2032. }
  2033. } catch (error) {
  2034. if (this.prompt instanceof PromptError) {
  2035. error = this.prompt;
  2036. }
  2037. if (this.task?.rollback) {
  2038. wrapper.report(error, "WILL_ROLLBACK" /* WILL_ROLLBACK */);
  2039. try {
  2040. this.state$ = "ROLLING_BACK" /* ROLLING_BACK */;
  2041. await this.task.rollback(context, wrapper);
  2042. this.message$ = { rollback: this.title };
  2043. this.state$ = "ROLLED_BACK" /* ROLLED_BACK */;
  2044. } catch (err) {
  2045. this.state$ = "FAILED" /* FAILED */;
  2046. wrapper.report(err, "HAS_FAILED_TO_ROLLBACK" /* HAS_FAILED_TO_ROLLBACK */);
  2047. this.close();
  2048. throw err;
  2049. }
  2050. if (this.listr.options?.exitAfterRollback !== false) {
  2051. this.close();
  2052. throw error;
  2053. }
  2054. } else {
  2055. this.state$ = "FAILED" /* FAILED */;
  2056. if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf(this.task?.exitOnError, context) !== false) {
  2057. wrapper.report(error, "HAS_FAILED" /* HAS_FAILED */);
  2058. this.close();
  2059. throw error;
  2060. } else if (!this.hasSubtasks()) {
  2061. wrapper.report(error, "HAS_FAILED_WITHOUT_ERROR" /* HAS_FAILED_WITHOUT_ERROR */);
  2062. }
  2063. }
  2064. } finally {
  2065. this.close();
  2066. }
  2067. }
  2068. close() {
  2069. this.emit("CLOSED" /* CLOSED */);
  2070. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  2071. this.complete();
  2072. }
  2073. };
  2074. // src/lib/listr-event-manager.ts
  2075. var ListrEventManager = class extends EventManager {
  2076. static {
  2077. __name(this, "ListrEventManager");
  2078. }
  2079. };
  2080. // src/listr.ts
  2081. var Listr = class {
  2082. constructor(task, options, parentTask) {
  2083. this.task = task;
  2084. this.options = options;
  2085. this.parentTask = parentTask;
  2086. this.options = {
  2087. concurrent: false,
  2088. renderer: "default",
  2089. fallbackRenderer: "simple",
  2090. exitOnError: true,
  2091. exitAfterRollback: true,
  2092. collectErrors: false,
  2093. registerSignalListeners: true,
  2094. ...this.parentTask?.options ?? {},
  2095. ...options
  2096. };
  2097. if (this.options.concurrent === true) {
  2098. this.options.concurrent = Infinity;
  2099. } else if (typeof this.options.concurrent !== "number") {
  2100. this.options.concurrent = 1;
  2101. }
  2102. this.concurrency = new Concurrency({ concurrency: this.options.concurrent });
  2103. if (parentTask) {
  2104. this.path = [...parentTask.listr.path, parentTask.title];
  2105. this.errors = parentTask.listr.errors;
  2106. }
  2107. if (this.parentTask?.listr.events instanceof ListrEventManager) {
  2108. this.events = this.parentTask.listr.events;
  2109. } else {
  2110. this.events = new ListrEventManager();
  2111. }
  2112. if (this.options?.forceTTY || process.env["LISTR_FORCE_TTY" /* FORCE_TTY */]) {
  2113. process.stdout.isTTY = true;
  2114. process.stderr.isTTY = true;
  2115. }
  2116. if (this.options?.forceUnicode) {
  2117. process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] = "1";
  2118. }
  2119. const renderer = getRenderer({
  2120. renderer: this.options.renderer,
  2121. rendererOptions: this.options.rendererOptions,
  2122. fallbackRenderer: this.options.fallbackRenderer,
  2123. fallbackRendererOptions: this.options.fallbackRendererOptions,
  2124. fallbackRendererCondition: this.options?.fallbackRendererCondition,
  2125. silentRendererCondition: this.options?.silentRendererCondition
  2126. });
  2127. this.rendererClass = renderer.renderer;
  2128. this.rendererClassOptions = renderer.options;
  2129. this.rendererSelection = renderer.selection;
  2130. this.add(task ?? []);
  2131. if (this.options.registerSignalListeners) {
  2132. this.boundSignalHandler = this.signalHandler.bind(this);
  2133. process.once("SIGINT", this.boundSignalHandler).setMaxListeners(0);
  2134. }
  2135. }
  2136. static {
  2137. __name(this, "Listr");
  2138. }
  2139. tasks = [];
  2140. errors = [];
  2141. ctx;
  2142. events;
  2143. path = [];
  2144. rendererClass;
  2145. rendererClassOptions;
  2146. rendererSelection;
  2147. boundSignalHandler;
  2148. concurrency;
  2149. renderer;
  2150. /**
  2151. * Whether this is the root task.
  2152. */
  2153. isRoot() {
  2154. return !this.parentTask;
  2155. }
  2156. /**
  2157. * Whether this is a subtask of another task list.
  2158. */
  2159. isSubtask() {
  2160. return !!this.parentTask;
  2161. }
  2162. /**
  2163. * Add tasks to current task list.
  2164. *
  2165. * @see {@link https://listr2.kilic.dev/task/task.html}
  2166. */
  2167. add(tasks) {
  2168. this.tasks.push(...this.generate(tasks));
  2169. }
  2170. /**
  2171. * Run the task list.
  2172. *
  2173. * @see {@link https://listr2.kilic.dev/listr/listr.html#run-the-generated-task-list}
  2174. */
  2175. async run(context) {
  2176. if (!this.renderer) {
  2177. this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.events);
  2178. }
  2179. await this.renderer.render();
  2180. this.ctx = this.options?.ctx ?? context ?? {};
  2181. await Promise.all(this.tasks.map((task) => task.check(this.ctx)));
  2182. try {
  2183. await Promise.all(this.tasks.map((task) => this.concurrency.add(() => this.runTask(task))));
  2184. this.renderer.end();
  2185. this.removeSignalHandler();
  2186. } catch (err) {
  2187. if (this.options.exitOnError !== false) {
  2188. this.renderer.end(err);
  2189. this.removeSignalHandler();
  2190. throw err;
  2191. }
  2192. }
  2193. return this.ctx;
  2194. }
  2195. generate(tasks) {
  2196. tasks = Array.isArray(tasks) ? tasks : [tasks];
  2197. return tasks.map((task) => {
  2198. let rendererTaskOptions;
  2199. if (this.rendererSelection === "PRIMARY" /* PRIMARY */) {
  2200. rendererTaskOptions = task.rendererOptions;
  2201. } else if (this.rendererSelection === "SECONDARY" /* SECONDARY */) {
  2202. rendererTaskOptions = task.fallbackRendererOptions;
  2203. }
  2204. return new Task(
  2205. this,
  2206. task,
  2207. this.options,
  2208. this.rendererClassOptions,
  2209. rendererTaskOptions
  2210. );
  2211. });
  2212. }
  2213. async runTask(task) {
  2214. if (!await task.check(this.ctx)) {
  2215. return;
  2216. }
  2217. return new TaskWrapper(task).run(this.ctx);
  2218. }
  2219. signalHandler() {
  2220. this.tasks?.forEach(async (task) => {
  2221. if (task.isPending()) {
  2222. task.state$ = "FAILED" /* FAILED */;
  2223. }
  2224. });
  2225. if (this.isRoot()) {
  2226. this.renderer?.end(new Error("Interrupted."));
  2227. process.exit(127);
  2228. }
  2229. }
  2230. removeSignalHandler() {
  2231. if (this.boundSignalHandler) {
  2232. process.removeListener("SIGINT", this.boundSignalHandler);
  2233. }
  2234. }
  2235. };
  2236. export {
  2237. ANSI_ESCAPE,
  2238. ANSI_ESCAPE_CODES,
  2239. BaseEventMap,
  2240. Concurrency,
  2241. DefaultRenderer,
  2242. EventManager,
  2243. LISTR_DEFAULT_RENDERER_STYLE,
  2244. LISTR_LOGGER_STDERR_LEVELS,
  2245. LISTR_LOGGER_STYLE,
  2246. Listr,
  2247. ListrDefaultRendererLogLevels,
  2248. ListrEnvironmentVariables,
  2249. ListrError,
  2250. ListrErrorTypes,
  2251. ListrEventManager,
  2252. ListrEventType,
  2253. ListrLogLevels,
  2254. ListrLogger,
  2255. ListrPromptAdapter,
  2256. ListrRendererError,
  2257. ListrRendererSelection,
  2258. ListrTaskEventManager,
  2259. ListrTaskEventType,
  2260. ListrTaskState,
  2261. PRESET_TIMER,
  2262. PRESET_TIMESTAMP,
  2263. ProcessOutput,
  2264. ProcessOutputBuffer,
  2265. ProcessOutputStream,
  2266. PromptError,
  2267. SilentRenderer,
  2268. SimpleRenderer,
  2269. Spinner,
  2270. TestRenderer,
  2271. TestRendererSerializer,
  2272. VerboseRenderer,
  2273. assertFunctionOrSelf,
  2274. cleanseAnsi,
  2275. cloneObject,
  2276. color,
  2277. createWritable,
  2278. delay,
  2279. figures,
  2280. getRenderer,
  2281. getRendererClass,
  2282. indent,
  2283. isObservable,
  2284. isReadable,
  2285. isUnicodeSupported,
  2286. parseTimer,
  2287. parseTimestamp,
  2288. splat
  2289. };