@node-core/utils 7.1.0 → 7.2.1

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