@contember/cli-common 2.2.0-alpha.3 → 2.2.0-alpha.4

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 (224) hide show
  1. package/dist/development/index.cjs +20 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +22 -2
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/application/Application.cjs +116 -59
  6. package/dist/development/src/application/Application.cjs.map +1 -1
  7. package/dist/development/src/application/Application.js +116 -59
  8. package/dist/development/src/application/Application.js.map +1 -1
  9. package/dist/development/src/application/CliError.cjs +104 -0
  10. package/dist/development/src/application/CliError.cjs.map +1 -0
  11. package/dist/development/src/application/CliError.js +104 -0
  12. package/dist/development/src/application/CliError.js.map +1 -0
  13. package/dist/development/src/application/Command.cjs +18 -5
  14. package/dist/development/src/application/Command.cjs.map +1 -1
  15. package/dist/development/src/application/Command.js +18 -5
  16. package/dist/development/src/application/Command.js.map +1 -1
  17. package/dist/development/src/application/CommandConfiguration.cjs +21 -3
  18. package/dist/development/src/application/CommandConfiguration.cjs.map +1 -1
  19. package/dist/development/src/application/CommandConfiguration.js +23 -5
  20. package/dist/development/src/application/CommandConfiguration.js.map +1 -1
  21. package/dist/development/src/application/CommandManager.cjs +139 -21
  22. package/dist/development/src/application/CommandManager.cjs.map +1 -1
  23. package/dist/development/src/application/CommandManager.js +139 -21
  24. package/dist/development/src/application/CommandManager.js.map +1 -1
  25. package/dist/development/src/application/ErrorRenderer.cjs +38 -0
  26. package/dist/development/src/application/ErrorRenderer.cjs.map +1 -0
  27. package/dist/development/src/application/ErrorRenderer.js +38 -0
  28. package/dist/development/src/application/ErrorRenderer.js.map +1 -0
  29. package/dist/development/src/application/GlobalOptions.cjs +54 -0
  30. package/dist/development/src/application/GlobalOptions.cjs.map +1 -0
  31. package/dist/development/src/application/GlobalOptions.js +54 -0
  32. package/dist/development/src/application/GlobalOptions.js.map +1 -0
  33. package/dist/development/src/application/Input.cjs +5 -0
  34. package/dist/development/src/application/Input.cjs.map +1 -1
  35. package/dist/development/src/application/Input.js +5 -0
  36. package/dist/development/src/application/Input.js.map +1 -1
  37. package/dist/development/src/application/InputParser.cjs +7 -3
  38. package/dist/development/src/application/InputParser.cjs.map +1 -1
  39. package/dist/development/src/application/InputParser.js +7 -3
  40. package/dist/development/src/application/InputParser.js.map +1 -1
  41. package/dist/development/src/application/Option.cjs +11 -0
  42. package/dist/development/src/application/Option.cjs.map +1 -1
  43. package/dist/development/src/application/Option.js +12 -1
  44. package/dist/development/src/application/Option.js.map +1 -1
  45. package/dist/development/src/application/Output.cjs +242 -0
  46. package/dist/development/src/application/Output.cjs.map +1 -0
  47. package/dist/development/src/application/Output.js +242 -0
  48. package/dist/development/src/application/Output.js.map +1 -0
  49. package/dist/development/src/application/exitProcess.cjs +7 -0
  50. package/dist/development/src/application/exitProcess.cjs.map +1 -0
  51. package/dist/development/src/application/exitProcess.js +7 -0
  52. package/dist/development/src/application/exitProcess.js.map +1 -0
  53. package/dist/development/src/npm/CommandRunner.cjs +126 -24
  54. package/dist/development/src/npm/CommandRunner.cjs.map +1 -1
  55. package/dist/development/src/npm/CommandRunner.js +126 -24
  56. package/dist/development/src/npm/CommandRunner.js.map +1 -1
  57. package/dist/development/src/npm/packageManagers/Bun.cjs +1 -2
  58. package/dist/development/src/npm/packageManagers/Bun.cjs.map +1 -1
  59. package/dist/development/src/npm/packageManagers/Bun.js +1 -2
  60. package/dist/development/src/npm/packageManagers/Bun.js.map +1 -1
  61. package/dist/development/src/npm/packageManagers/Npm.cjs +1 -2
  62. package/dist/development/src/npm/packageManagers/Npm.cjs.map +1 -1
  63. package/dist/development/src/npm/packageManagers/Npm.js +1 -2
  64. package/dist/development/src/npm/packageManagers/Npm.js.map +1 -1
  65. package/dist/development/src/npm/packageManagers/Pnpm.cjs +1 -2
  66. package/dist/development/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  67. package/dist/development/src/npm/packageManagers/Pnpm.js +1 -2
  68. package/dist/development/src/npm/packageManagers/Pnpm.js.map +1 -1
  69. package/dist/development/src/npm/packageManagers/Yarn.cjs +1 -2
  70. package/dist/development/src/npm/packageManagers/Yarn.cjs.map +1 -1
  71. package/dist/development/src/npm/packageManagers/Yarn.js +1 -2
  72. package/dist/development/src/npm/packageManagers/Yarn.js.map +1 -1
  73. package/dist/development/src/npm/packageManagers/YarnClassic.cjs +1 -2
  74. package/dist/development/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  75. package/dist/development/src/npm/packageManagers/YarnClassic.js +1 -2
  76. package/dist/development/src/npm/packageManagers/YarnClassic.js.map +1 -1
  77. package/dist/production/index.cjs +20 -0
  78. package/dist/production/index.cjs.map +1 -1
  79. package/dist/production/index.js +22 -2
  80. package/dist/production/index.js.map +1 -1
  81. package/dist/production/src/application/Application.cjs +116 -59
  82. package/dist/production/src/application/Application.cjs.map +1 -1
  83. package/dist/production/src/application/Application.js +116 -59
  84. package/dist/production/src/application/Application.js.map +1 -1
  85. package/dist/production/src/application/CliError.cjs +104 -0
  86. package/dist/production/src/application/CliError.cjs.map +1 -0
  87. package/dist/production/src/application/CliError.js +104 -0
  88. package/dist/production/src/application/CliError.js.map +1 -0
  89. package/dist/production/src/application/Command.cjs +18 -5
  90. package/dist/production/src/application/Command.cjs.map +1 -1
  91. package/dist/production/src/application/Command.js +18 -5
  92. package/dist/production/src/application/Command.js.map +1 -1
  93. package/dist/production/src/application/CommandConfiguration.cjs +21 -3
  94. package/dist/production/src/application/CommandConfiguration.cjs.map +1 -1
  95. package/dist/production/src/application/CommandConfiguration.js +23 -5
  96. package/dist/production/src/application/CommandConfiguration.js.map +1 -1
  97. package/dist/production/src/application/CommandManager.cjs +139 -21
  98. package/dist/production/src/application/CommandManager.cjs.map +1 -1
  99. package/dist/production/src/application/CommandManager.js +139 -21
  100. package/dist/production/src/application/CommandManager.js.map +1 -1
  101. package/dist/production/src/application/ErrorRenderer.cjs +38 -0
  102. package/dist/production/src/application/ErrorRenderer.cjs.map +1 -0
  103. package/dist/production/src/application/ErrorRenderer.js +38 -0
  104. package/dist/production/src/application/ErrorRenderer.js.map +1 -0
  105. package/dist/production/src/application/GlobalOptions.cjs +54 -0
  106. package/dist/production/src/application/GlobalOptions.cjs.map +1 -0
  107. package/dist/production/src/application/GlobalOptions.js +54 -0
  108. package/dist/production/src/application/GlobalOptions.js.map +1 -0
  109. package/dist/production/src/application/Input.cjs +5 -0
  110. package/dist/production/src/application/Input.cjs.map +1 -1
  111. package/dist/production/src/application/Input.js +5 -0
  112. package/dist/production/src/application/Input.js.map +1 -1
  113. package/dist/production/src/application/InputParser.cjs +7 -3
  114. package/dist/production/src/application/InputParser.cjs.map +1 -1
  115. package/dist/production/src/application/InputParser.js +7 -3
  116. package/dist/production/src/application/InputParser.js.map +1 -1
  117. package/dist/production/src/application/Option.cjs +11 -0
  118. package/dist/production/src/application/Option.cjs.map +1 -1
  119. package/dist/production/src/application/Option.js +12 -1
  120. package/dist/production/src/application/Option.js.map +1 -1
  121. package/dist/production/src/application/Output.cjs +242 -0
  122. package/dist/production/src/application/Output.cjs.map +1 -0
  123. package/dist/production/src/application/Output.js +242 -0
  124. package/dist/production/src/application/Output.js.map +1 -0
  125. package/dist/production/src/application/exitProcess.cjs +7 -0
  126. package/dist/production/src/application/exitProcess.cjs.map +1 -0
  127. package/dist/production/src/application/exitProcess.js +7 -0
  128. package/dist/production/src/application/exitProcess.js.map +1 -0
  129. package/dist/production/src/npm/CommandRunner.cjs +126 -24
  130. package/dist/production/src/npm/CommandRunner.cjs.map +1 -1
  131. package/dist/production/src/npm/CommandRunner.js +126 -24
  132. package/dist/production/src/npm/CommandRunner.js.map +1 -1
  133. package/dist/production/src/npm/packageManagers/Bun.cjs +1 -2
  134. package/dist/production/src/npm/packageManagers/Bun.cjs.map +1 -1
  135. package/dist/production/src/npm/packageManagers/Bun.js +1 -2
  136. package/dist/production/src/npm/packageManagers/Bun.js.map +1 -1
  137. package/dist/production/src/npm/packageManagers/Npm.cjs +1 -2
  138. package/dist/production/src/npm/packageManagers/Npm.cjs.map +1 -1
  139. package/dist/production/src/npm/packageManagers/Npm.js +1 -2
  140. package/dist/production/src/npm/packageManagers/Npm.js.map +1 -1
  141. package/dist/production/src/npm/packageManagers/Pnpm.cjs +1 -2
  142. package/dist/production/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  143. package/dist/production/src/npm/packageManagers/Pnpm.js +1 -2
  144. package/dist/production/src/npm/packageManagers/Pnpm.js.map +1 -1
  145. package/dist/production/src/npm/packageManagers/Yarn.cjs +1 -2
  146. package/dist/production/src/npm/packageManagers/Yarn.cjs.map +1 -1
  147. package/dist/production/src/npm/packageManagers/Yarn.js +1 -2
  148. package/dist/production/src/npm/packageManagers/Yarn.js.map +1 -1
  149. package/dist/production/src/npm/packageManagers/YarnClassic.cjs +1 -2
  150. package/dist/production/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  151. package/dist/production/src/npm/packageManagers/YarnClassic.js +1 -2
  152. package/dist/production/src/npm/packageManagers/YarnClassic.js.map +1 -1
  153. package/dist/types/application/Application.d.ts +22 -11
  154. package/dist/types/application/Application.d.ts.map +1 -1
  155. package/dist/types/application/Argument.d.ts.map +1 -1
  156. package/dist/types/application/CliError.d.ts +40 -0
  157. package/dist/types/application/CliError.d.ts.map +1 -0
  158. package/dist/types/application/Command.d.ts +12 -2
  159. package/dist/types/application/Command.d.ts.map +1 -1
  160. package/dist/types/application/CommandConfiguration.d.ts +7 -4
  161. package/dist/types/application/CommandConfiguration.d.ts.map +1 -1
  162. package/dist/types/application/CommandManager.d.ts +40 -2
  163. package/dist/types/application/CommandManager.d.ts.map +1 -1
  164. package/dist/types/application/ErrorRenderer.d.ts +8 -0
  165. package/dist/types/application/ErrorRenderer.d.ts.map +1 -0
  166. package/dist/types/application/GlobalOptions.d.ts +28 -0
  167. package/dist/types/application/GlobalOptions.d.ts.map +1 -0
  168. package/dist/types/application/Input.d.ts +2 -0
  169. package/dist/types/application/Input.d.ts.map +1 -1
  170. package/dist/types/application/InputParser.d.ts +5 -1
  171. package/dist/types/application/InputParser.d.ts.map +1 -1
  172. package/dist/types/application/Option.d.ts +2 -0
  173. package/dist/types/application/Option.d.ts.map +1 -1
  174. package/dist/types/application/Output.d.ts +81 -0
  175. package/dist/types/application/Output.d.ts.map +1 -0
  176. package/dist/types/application/UsageFormatter.d.ts.map +1 -1
  177. package/dist/types/application/exitProcess.d.ts +11 -0
  178. package/dist/types/application/exitProcess.d.ts.map +1 -0
  179. package/dist/types/application/index.d.ts +5 -0
  180. package/dist/types/application/index.d.ts.map +1 -1
  181. package/dist/types/index.d.ts +2 -2
  182. package/dist/types/index.d.ts.map +1 -1
  183. package/dist/types/npm/CommandRunner.d.ts +13 -0
  184. package/dist/types/npm/CommandRunner.d.ts.map +1 -1
  185. package/dist/types/npm/Package.d.ts.map +1 -1
  186. package/dist/types/npm/PackageWorkspace.d.ts.map +1 -1
  187. package/dist/types/npm/PackageWorkspaceResolver.d.ts.map +1 -1
  188. package/dist/types/npm/packageManagers/Bun.d.ts.map +1 -1
  189. package/dist/types/npm/packageManagers/Npm.d.ts.map +1 -1
  190. package/dist/types/npm/packageManagers/PackageManagerHelpers.d.ts.map +1 -1
  191. package/dist/types/npm/packageManagers/Pnpm.d.ts.map +1 -1
  192. package/dist/types/npm/packageManagers/Yarn.d.ts.map +1 -1
  193. package/dist/types/npm/packageManagers/YarnClassic.d.ts.map +1 -1
  194. package/dist/types/tsconfig.tsbuildinfo +1 -1
  195. package/dist/types/utils/findPackageRoot.d.ts.map +1 -1
  196. package/package.json +3 -2
  197. package/src/application/Application.ts +137 -75
  198. package/src/application/CliError.ts +117 -0
  199. package/src/application/Command.ts +27 -6
  200. package/src/application/CommandConfiguration.ts +22 -4
  201. package/src/application/CommandManager.ts +172 -22
  202. package/src/application/ErrorRenderer.ts +40 -0
  203. package/src/application/GlobalOptions.ts +76 -0
  204. package/src/application/Input.ts +6 -0
  205. package/src/application/InputParser.ts +13 -4
  206. package/src/application/Option.ts +12 -0
  207. package/src/application/Output.ts +329 -0
  208. package/src/application/exitProcess.ts +12 -0
  209. package/src/application/index.ts +5 -0
  210. package/src/index.ts +40 -2
  211. package/src/npm/CommandRunner.ts +166 -23
  212. package/src/npm/packageManagers/Bun.ts +1 -2
  213. package/src/npm/packageManagers/Npm.ts +1 -2
  214. package/src/npm/packageManagers/Pnpm.ts +1 -2
  215. package/src/npm/packageManagers/Yarn.ts +1 -2
  216. package/src/npm/packageManagers/YarnClassic.ts +1 -2
  217. package/tests/cases/unit/application.test.ts +426 -0
  218. package/tests/cases/unit/cliError.test.ts +127 -0
  219. package/tests/cases/unit/commandManager.test.ts +270 -0
  220. package/tests/cases/unit/commandRunner.test.ts +192 -0
  221. package/tests/cases/unit/inputParser.test.ts +21 -0
  222. package/tests/cases/unit/output.test.ts +393 -0
  223. package/tests/lib/testOutput.ts +35 -0
  224. package/types/chalk-table/index.d.ts +9 -0
@@ -0,0 +1,242 @@
1
+ import chalk from "chalk";
2
+ import chalkTable from "chalk-table";
3
+ import { Writable } from "node:stream";
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ let supportedChalkLevel = chalk.level;
8
+ const resolveOutputMode = (globals) => {
9
+ if (globals.json) {
10
+ return "json";
11
+ }
12
+ if (globals.quiet) {
13
+ return "quiet";
14
+ }
15
+ return "human";
16
+ };
17
+ class Output {
18
+ constructor(options = {}) {
19
+ __publicField(this, "currentMode", "human");
20
+ __publicField(this, "progressVisible", false);
21
+ __publicField(this, "stdout");
22
+ __publicField(this, "stderr");
23
+ __publicField(this, "stdinIsTty");
24
+ __publicField(this, "promptStderr");
25
+ this.stdout = options.stdout ?? createProcessStream(process.stdout);
26
+ this.stderr = options.stderr ?? createProcessStream(process.stderr);
27
+ this.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true);
28
+ this.promptStderr = options.stderr === void 0 ? process.stderr : createPromptStream(this.stderr);
29
+ this.stdout.onError?.(handleStreamError);
30
+ this.stderr.onError?.(handleStreamError);
31
+ }
32
+ get mode() {
33
+ return this.currentMode;
34
+ }
35
+ get isJson() {
36
+ return this.currentMode === "json";
37
+ }
38
+ get isQuiet() {
39
+ return this.currentMode === "quiet";
40
+ }
41
+ /** Set by `Application` once the global options are parsed. */
42
+ setMode(mode) {
43
+ this.currentMode = mode;
44
+ }
45
+ applyGlobalOptions(globals) {
46
+ this.setMode(resolveOutputMode(globals));
47
+ if (globals.color && this.currentMode === "human") {
48
+ if (chalk.level === 0) {
49
+ chalk.level = supportedChalkLevel;
50
+ } else {
51
+ supportedChalkLevel = chalk.level;
52
+ }
53
+ } else {
54
+ if (chalk.level !== 0) {
55
+ supportedChalkLevel = chalk.level;
56
+ }
57
+ chalk.level = 0;
58
+ }
59
+ }
60
+ data(value, rendering) {
61
+ const human = typeof rendering === "function" ? rendering : rendering?.human;
62
+ if (this.currentMode === "json") {
63
+ this.writeStdout(JSON.stringify(value ?? null, null, 2));
64
+ return;
65
+ }
66
+ if (this.currentMode === "quiet") {
67
+ const quietValue = typeof rendering === "object" && rendering.quiet ? rendering.quiet(value) : value;
68
+ for (const line of toScalarLines(quietValue)) {
69
+ this.writeStdout(line);
70
+ }
71
+ return;
72
+ }
73
+ this.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2));
74
+ }
75
+ table(columns, rows, quietField) {
76
+ if (this.currentMode === "json") {
77
+ this.writeStdout(JSON.stringify(rows, null, 2));
78
+ return;
79
+ }
80
+ if (this.currentMode === "quiet") {
81
+ const field = quietField ?? columns[0]?.field;
82
+ if (field === void 0) {
83
+ return;
84
+ }
85
+ for (const row of rows) {
86
+ this.writeStdout(formatCell(row[field]));
87
+ }
88
+ return;
89
+ }
90
+ if (rows.length === 0) {
91
+ return;
92
+ }
93
+ const data = rows.map((row) => {
94
+ const cells = {};
95
+ for (const column of columns) {
96
+ cells[column.field] = renderTableCell(column, row);
97
+ }
98
+ return cells;
99
+ });
100
+ this.writeStdout(chalkTable({ columns: columns.map((it) => ({ field: it.field, name: it.name })) }, data));
101
+ }
102
+ // DIAGNOSTICS → stderr
103
+ info(message) {
104
+ this.writeDiagnostic(message);
105
+ }
106
+ warn(message) {
107
+ this.writeDiagnostic(message, (text) => chalk.yellow(text));
108
+ }
109
+ error(message) {
110
+ this.writeDiagnostic(message, (text) => chalk.red(text));
111
+ }
112
+ // PROGRESS → stderr
113
+ progress(message) {
114
+ if (this.currentMode !== "human" || !this.stderr.isTty) {
115
+ return;
116
+ }
117
+ this.clearProgress();
118
+ writeStream(this.stderr, escapeTerminalText(message));
119
+ this.progressVisible = true;
120
+ }
121
+ clearProgress() {
122
+ if (!this.progressVisible) {
123
+ return;
124
+ }
125
+ this.progressVisible = false;
126
+ writeStream(this.stderr, "\r\x1B[K");
127
+ }
128
+ /** False unless both sides of an interactive prompt are TTYs in human mode. */
129
+ canPrompt() {
130
+ return this.currentMode === "human" && this.stdinIsTty() && this.stderr.isTty;
131
+ }
132
+ /** A real Writable suitable for the `stdout` option of interactive prompt libraries. */
133
+ get promptOutput() {
134
+ return this.promptStderr;
135
+ }
136
+ /**
137
+ * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for
138
+ * (help) or must always see (a fatal error) — everything else belongs to the methods above.
139
+ */
140
+ writeStderr(text) {
141
+ this.clearProgress();
142
+ writeStream(this.stderr, text + "\n");
143
+ }
144
+ writeStdout(text) {
145
+ this.clearProgress();
146
+ writeStream(this.stdout, text + "\n");
147
+ }
148
+ writeDiagnostic(message, format = (text) => text) {
149
+ if (this.currentMode !== "human") {
150
+ return;
151
+ }
152
+ this.clearProgress();
153
+ writeStream(this.stderr, format(escapeTerminalText(message)) + "\n");
154
+ }
155
+ }
156
+ const createProcessStream = (stream) => ({
157
+ write: (text) => {
158
+ stream.write(text);
159
+ },
160
+ get isTty() {
161
+ return stream.isTTY === true;
162
+ },
163
+ get columns() {
164
+ return stream.columns;
165
+ },
166
+ onError: (listener) => {
167
+ stream.on("error", (error) => listener(error));
168
+ }
169
+ });
170
+ class PromptWritable extends Writable {
171
+ constructor(stream) {
172
+ super({ decodeStrings: false });
173
+ this.stream = stream;
174
+ __publicField(this, "isTTY");
175
+ this.isTTY = stream.isTty;
176
+ }
177
+ get columns() {
178
+ return this.stream.columns ?? 80;
179
+ }
180
+ _write(chunk, encoding, callback) {
181
+ try {
182
+ writeStream(this.stream, typeof chunk === "string" ? chunk : Buffer.from(chunk).toString(encoding));
183
+ callback();
184
+ } catch (error) {
185
+ callback(error instanceof Error ? error : new Error(String(error)));
186
+ }
187
+ }
188
+ }
189
+ const createPromptStream = (stream) => new PromptWritable(stream);
190
+ const writeStream = (stream, text) => {
191
+ try {
192
+ stream.write(text);
193
+ } catch (error) {
194
+ handleStreamError(error);
195
+ }
196
+ };
197
+ const handleStreamError = (error) => {
198
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EPIPE") {
199
+ return;
200
+ }
201
+ throw error;
202
+ };
203
+ const escapeTerminalText = (value) => {
204
+ let escaped = "";
205
+ for (const character of value) {
206
+ if (!isTerminalControl(character)) {
207
+ escaped += character;
208
+ }
209
+ }
210
+ return escaped;
211
+ };
212
+ const isTerminalControl = (character) => {
213
+ const codePoint = character.codePointAt(0);
214
+ return codePoint !== void 0 && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159);
215
+ };
216
+ const renderTableCell = (column, row) => column.format ? column.format(row[column.field], row) : formatCell(row[column.field]);
217
+ const formatCell = (value) => {
218
+ if (value === void 0 || value === null) {
219
+ return "";
220
+ }
221
+ if (typeof value === "string") {
222
+ return escapeTerminalText(value);
223
+ }
224
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
225
+ return String(value);
226
+ }
227
+ return JSON.stringify(value) ?? "";
228
+ };
229
+ const toScalarLines = (value) => {
230
+ const values = Array.isArray(value) ? value : [value];
231
+ if (!values.every(isOutputScalar)) {
232
+ throw new TypeError("Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.");
233
+ }
234
+ return values.filter((it) => it !== void 0 && it !== null).map(formatCell);
235
+ };
236
+ const isOutputScalar = (value) => value === null || value === void 0 || ["string", "number", "boolean", "bigint"].includes(typeof value);
237
+ export {
238
+ Output,
239
+ escapeTerminalText,
240
+ resolveOutputMode
241
+ };
242
+ //# sourceMappingURL=Output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Output.js","sources":["../../../../../packages/cli-common/src/application/Output.ts"],"sourcesContent":["/// <reference path=\"../../types/chalk-table/index.d.ts\" />\n\nimport chalk from 'chalk'\nimport chalkTable from 'chalk-table'\nimport { Writable } from 'node:stream'\nimport type { GlobalOptionValues } from './GlobalOptions.js'\n\nexport type OutputMode = 'human' | 'json' | 'quiet'\n\nlet supportedChalkLevel = chalk.level\n\nexport interface OutputStream {\n\twrite(text: string): void\n\treadonly isTty: boolean\n\treadonly columns?: number\n\tonError?(listener: (error: unknown) => void): void\n}\n\nexport interface OutputOptions {\n\tstdout?: OutputStream\n\tstderr?: OutputStream\n\tisStdinTty?: () => boolean\n}\n\nexport interface PromptOutputStream extends Writable {\n\treadonly isTTY: boolean\n\treadonly columns: number\n}\n\nexport type OutputScalar = string | number | boolean | bigint | null | undefined\n\nexport interface OutputDataOptions<T> {\n\thuman?: (value: T) => string\n\tquiet?: (value: T) => OutputScalar | readonly OutputScalar[]\n}\n\n/**\n * Per field column specs, so that each `format` sees the exact type of its own field. Indexed by the\n * field name only to let {@link Output.table} render a cell without widening the union.\n */\nexport type OutputTableColumns<T> = {\n\t[K in keyof T & string]: {\n\t\tfield: K\n\t\tname: string\n\t\t/** Human mode only — `--json` still emits the raw row and `--quiet` the raw value. */\n\t\tformat?: (value: T[K], row: T) => string\n\t}\n}\n\nexport type OutputTableColumn<T> = OutputTableColumns<T>[keyof T & string]\n\nexport const resolveOutputMode = (globals: GlobalOptionValues): OutputMode => {\n\tif (globals.json) {\n\t\treturn 'json'\n\t}\n\tif (globals.quiet) {\n\t\treturn 'quiet'\n\t}\n\treturn 'human'\n}\n\n/**\n * The single output channel of the CLI: stdout carries data, stderr carries everything a human reads.\n *\n * The instance is created before argv is parsed, so the mode is mutable and set by `Application` once\n * the global options are known. Every consumer holds the same instance.\n */\nexport class Output {\n\tprivate currentMode: OutputMode = 'human'\n\tprivate progressVisible = false\n\tprivate readonly stdout: OutputStream\n\tprivate readonly stderr: OutputStream\n\tprivate readonly stdinIsTty: () => boolean\n\tprivate readonly promptStderr: PromptOutputStream\n\n\tconstructor(options: OutputOptions = {}) {\n\t\tthis.stdout = options.stdout ?? createProcessStream(process.stdout)\n\t\tthis.stderr = options.stderr ?? createProcessStream(process.stderr)\n\t\tthis.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true)\n\t\tthis.promptStderr = options.stderr === undefined ? process.stderr : createPromptStream(this.stderr)\n\t\tthis.stdout.onError?.(handleStreamError)\n\t\tthis.stderr.onError?.(handleStreamError)\n\t}\n\n\tpublic get mode(): OutputMode {\n\t\treturn this.currentMode\n\t}\n\n\tpublic get isJson(): boolean {\n\t\treturn this.currentMode === 'json'\n\t}\n\n\tpublic get isQuiet(): boolean {\n\t\treturn this.currentMode === 'quiet'\n\t}\n\n\t/** Set by `Application` once the global options are parsed. */\n\tpublic setMode(mode: OutputMode): void {\n\t\tthis.currentMode = mode\n\t}\n\n\tpublic applyGlobalOptions(globals: GlobalOptionValues): void {\n\t\tthis.setMode(resolveOutputMode(globals))\n\t\tif (globals.color && this.currentMode === 'human') {\n\t\t\tif (chalk.level === 0) {\n\t\t\t\tchalk.level = supportedChalkLevel\n\t\t\t} else {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t} else {\n\t\t\tif (chalk.level !== 0) {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t\tchalk.level = 0\n\t\t}\n\t}\n\n\t// DATA → stdout\n\n\t/** Prints command data with optional mode-specific projections. JSON always receives the raw value. */\n\tpublic data<T>(value: T, human?: (value: T) => string): void\n\tpublic data<T>(value: T, options?: OutputDataOptions<T>): void\n\tpublic data<T>(value: T, rendering?: ((value: T) => string) | OutputDataOptions<T>): void {\n\t\tconst human = typeof rendering === 'function' ? rendering : rendering?.human\n\t\tif (this.currentMode === 'json') {\n\t\t\tthis.writeStdout(JSON.stringify(value ?? null, null, 2))\n\t\t\treturn\n\t\t}\n\t\tif (this.currentMode === 'quiet') {\n\t\t\tconst quietValue = typeof rendering === 'object' && rendering.quiet ? rendering.quiet(value) : value\n\t\t\tfor (const line of toScalarLines(quietValue)) {\n\t\t\t\tthis.writeStdout(line)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2))\n\t}\n\n\tpublic table<T>(columns: OutputTableColumn<T>[], rows: T[], quietField?: keyof T & string): void {\n\t\tif (this.currentMode === 'json') {\n\t\t\tthis.writeStdout(JSON.stringify(rows, null, 2))\n\t\t\treturn\n\t\t}\n\t\tif (this.currentMode === 'quiet') {\n\t\t\tconst field = quietField ?? columns[0]?.field\n\t\t\tif (field === undefined) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tfor (const row of rows) {\n\t\t\t\tthis.writeStdout(formatCell(row[field]))\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (rows.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst data: Record<string, string>[] = rows.map(row => {\n\t\t\tconst cells: Record<string, string> = {}\n\t\t\tfor (const column of columns) {\n\t\t\t\tcells[column.field] = renderTableCell(column, row)\n\t\t\t}\n\t\t\treturn cells\n\t\t})\n\t\tthis.writeStdout(chalkTable<string>({ columns: columns.map(it => ({ field: it.field, name: it.name })) }, data))\n\t}\n\n\t// DIAGNOSTICS → stderr\n\n\tpublic info(message: string): void {\n\t\tthis.writeDiagnostic(message)\n\t}\n\n\tpublic warn(message: string): void {\n\t\tthis.writeDiagnostic(message, text => chalk.yellow(text))\n\t}\n\n\tpublic error(message: string): void {\n\t\tthis.writeDiagnostic(message, text => chalk.red(text))\n\t}\n\n\t// PROGRESS → stderr\n\n\tpublic progress(message: string): void {\n\t\tif (this.currentMode !== 'human' || !this.stderr.isTty) {\n\t\t\treturn\n\t\t}\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, escapeTerminalText(message))\n\t\tthis.progressVisible = true\n\t}\n\n\tpublic clearProgress(): void {\n\t\tif (!this.progressVisible) {\n\t\t\treturn\n\t\t}\n\t\tthis.progressVisible = false\n\t\twriteStream(this.stderr, '\\r\\u001b[K')\n\t}\n\n\t/** False unless both sides of an interactive prompt are TTYs in human mode. */\n\tpublic canPrompt(): boolean {\n\t\treturn this.currentMode === 'human' && this.stdinIsTty() && this.stderr.isTty\n\t}\n\n\t/** A real Writable suitable for the `stdout` option of interactive prompt libraries. */\n\tpublic get promptOutput(): PromptOutputStream {\n\t\treturn this.promptStderr\n\t}\n\n\t/**\n\t * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for\n\t * (help) or must always see (a fatal error) — everything else belongs to the methods above.\n\t */\n\tpublic writeStderr(text: string): void {\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, text + '\\n')\n\t}\n\n\tprivate writeStdout(text: string): void {\n\t\tthis.clearProgress()\n\t\twriteStream(this.stdout, text + '\\n')\n\t}\n\n\tprivate writeDiagnostic(message: string, format: (text: string) => string = text => text): void {\n\t\tif (this.currentMode !== 'human') {\n\t\t\treturn\n\t\t}\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, format(escapeTerminalText(message)) + '\\n')\n\t}\n}\n\nconst createProcessStream = (stream: NodeJS.WriteStream): OutputStream => ({\n\twrite: text => {\n\t\tstream.write(text)\n\t},\n\tget isTty() {\n\t\treturn stream.isTTY === true\n\t},\n\tget columns() {\n\t\treturn stream.columns\n\t},\n\tonError: listener => {\n\t\tstream.on('error', error => listener(error))\n\t},\n})\n\nclass PromptWritable extends Writable {\n\tpublic readonly isTTY: boolean\n\n\tconstructor(private readonly stream: OutputStream) {\n\t\tsuper({ decodeStrings: false })\n\t\tthis.isTTY = stream.isTty\n\t}\n\n\tpublic get columns(): number {\n\t\treturn this.stream.columns ?? 80\n\t}\n\n\tpublic override _write(chunk: string | Uint8Array, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n\t\ttry {\n\t\t\twriteStream(this.stream, typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString(encoding))\n\t\t\tcallback()\n\t\t} catch (error) {\n\t\t\tcallback(error instanceof Error ? error : new Error(String(error)))\n\t\t}\n\t}\n}\n\nconst createPromptStream = (stream: OutputStream): PromptOutputStream => new PromptWritable(stream)\n\nconst writeStream = (stream: OutputStream, text: string): void => {\n\ttry {\n\t\tstream.write(text)\n\t} catch (error) {\n\t\thandleStreamError(error)\n\t}\n}\n\nconst handleStreamError = (error: unknown): void => {\n\tif (typeof error === 'object' && error !== null && 'code' in error && error.code === 'EPIPE') {\n\t\treturn\n\t}\n\tthrow error\n}\n\n/** Removes terminal control characters from untrusted human-readable text. */\nexport const escapeTerminalText = (value: string): string => {\n\tlet escaped = ''\n\tfor (const character of value) {\n\t\tif (!isTerminalControl(character)) {\n\t\t\tescaped += character\n\t\t}\n\t}\n\treturn escaped\n}\n\nconst isTerminalControl = (character: string): boolean => {\n\tconst codePoint = character.codePointAt(0)\n\treturn codePoint !== undefined && (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f))\n}\n\n// generic in the field so that `format` is a single signature here, not a union of them\nconst renderTableCell = <T, K extends keyof T & string>(column: OutputTableColumns<T>[K], row: T): string =>\n\tcolumn.format ? column.format(row[column.field], row) : formatCell(row[column.field])\n\nconst formatCell = (value: unknown): string => {\n\tif (value === undefined || value === null) {\n\t\treturn ''\n\t}\n\tif (typeof value === 'string') {\n\t\treturn escapeTerminalText(value)\n\t}\n\tif (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {\n\t\treturn String(value)\n\t}\n\treturn JSON.stringify(value) ?? ''\n}\n\nconst toScalarLines = (value: unknown): string[] => {\n\tconst values: unknown[] = Array.isArray(value) ? value : [value]\n\tif (!values.every(isOutputScalar)) {\n\t\tthrow new TypeError('Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.')\n\t}\n\treturn values.filter(it => it !== undefined && it !== null).map(formatCell)\n}\n\nconst isOutputScalar = (value: unknown): value is OutputScalar =>\n\tvalue === null || value === undefined || ['string', 'number', 'boolean', 'bigint'].includes(typeof value)\n"],"names":[],"mappings":";;;;;;AASA,IAAI,sBAAsB,MAAM;AA0CzB,MAAM,oBAAoB,CAAC,YAA4C;AAC7E,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR;AACA,MAAI,QAAQ,OAAO;AAClB,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAQO,MAAM,OAAO;AAAA,EAQnB,YAAY,UAAyB,IAAI;AAPzC,kBAAA,MAAQ,eAA0B,OAAA;AAClC,kBAAA,MAAQ,mBAAkB,KAAA;AAC1B,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,YAAA;AACjB,kBAAA,MAAiB,cAAA;AAGhB,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,aAAa,QAAQ,eAAe,MAAM,QAAQ,MAAM,UAAU;AACvE,SAAK,eAAe,QAAQ,WAAW,SAAY,QAAQ,SAAS,mBAAmB,KAAK,MAAM;AAClG,SAAK,OAAO,UAAU,iBAAiB;AACvC,SAAK,OAAO,UAAU,iBAAiB;AAAA,EACxC;AAAA,EAEA,IAAW,OAAmB;AAC7B,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAW,SAAkB;AAC5B,WAAO,KAAK,gBAAgB;AAAA,EAC7B;AAAA,EAEA,IAAW,UA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AO,OAAO,CAAA,OAAM,OAAO,UAAa,OAAO,IAAI,EAAE,IAAI,UAAU;AAC3E;AAEA,MAAM,iBAAiB,CAAC,UACvB,UAAU,QAAQ,UAAU,UAAa,CAAC,UAAU,UAAU,WAAW,QAAQ,EAAE,SAAS,OAAO,KAAK;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const exitProcess = (code) => {
4
+ process.exitCode = code;
5
+ };
6
+ exports.exitProcess = exitProcess;
7
+ //# sourceMappingURL=exitProcess.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitProcess.cjs","sources":["../../../../../packages/cli-common/src/application/exitProcess.ts"],"sourcesContent":["/**\n * Ends the process with the given exit code without losing buffered output.\n *\n * `process.exit()` terminates immediately and discards whatever `process.stdout` has not yet handed\n * to the OS. Writes to a pipe are asynchronous, so anything past the 64 KB pipe buffer was silently\n * dropped — `contember commands --json | jq` got a truncated document while the same command\n * redirected to a file was complete. Assigning `exitCode` instead lets the runtime exit on its own\n * once the streams have drained, which also covers output written directly through `console.log`.\n */\nexport const exitProcess = (code: number): void => {\n\tprocess.exitCode = code\n}\n"],"names":[],"mappings":";;AASO,MAAM,cAAc,CAAC,SAAuB;AAClD,UAAQ,WAAW;AACpB;;"}
@@ -0,0 +1,7 @@
1
+ const exitProcess = (code) => {
2
+ process.exitCode = code;
3
+ };
4
+ export {
5
+ exitProcess
6
+ };
7
+ //# sourceMappingURL=exitProcess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitProcess.js","sources":["../../../../../packages/cli-common/src/application/exitProcess.ts"],"sourcesContent":["/**\n * Ends the process with the given exit code without losing buffered output.\n *\n * `process.exit()` terminates immediately and discards whatever `process.stdout` has not yet handed\n * to the OS. Writes to a pipe are asynchronous, so anything past the 64 KB pipe buffer was silently\n * dropped — `contember commands --json | jq` got a truncated document while the same command\n * redirected to a file was complete. Assigning `exitCode` instead lets the runtime exit on its own\n * once the streams have drained, which also covers output written directly through `console.log`.\n */\nexport const exitProcess = (code: number): void => {\n\tprocess.exitCode = code\n}\n"],"names":[],"mappings":"AASO,MAAM,cAAc,CAAC,SAAuB;AAClD,UAAQ,WAAW;AACpB;"}
@@ -1,57 +1,159 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const node_child_process = require("node:child_process");
4
- const chalk = require("chalk");
4
+ const node_string_decoder = require("node:string_decoder");
5
+ const Output = require("../application/Output.cjs");
5
6
  var __defProp = Object.defineProperty;
6
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
9
  class CommandRunner {
9
- constructor() {
10
+ constructor(output = new Output.Output()) {
11
+ this.output = output;
10
12
  __publicField(this, "runCommand", (command, args, options) => {
11
13
  const args2 = args.filter((it) => it !== void 0);
12
- if (!process.env.DISABLE_COMMAND_PRINTING) {
13
- console.error(chalk.gray(`$ ${command} ${args2.map((it) => `'${it.replace(/'/g, `'\\''`)}'`).join(" ")}`));
14
+ if (!process.env.DISABLE_COMMAND_PRINTING && options.display !== void 0) {
15
+ this.output.info(`$ ${options.display}`);
14
16
  }
15
17
  const child = node_child_process.spawn(command, args2, {
16
18
  cwd: options.cwd,
17
19
  env: { ...process.env, ...options.env || {} },
18
20
  detached: options.detached
19
21
  });
20
- if (options.stdin) {
21
- options.stdin.pipe(child.stdin);
22
- }
23
- let stdout = "";
24
- let stderr = "";
22
+ const stdoutChunks = [];
23
+ const stderrChunks = [];
24
+ const stdoutDiagnostics = new DiagnosticForwarder(this.output);
25
+ const stderrDiagnostics = new DiagnosticForwarder(this.output);
26
+ const humanMode = this.output.mode === "human";
27
+ const stdoutTarget = humanMode ? options.stdout : void 0;
28
+ const stderrTarget = humanMode ? options.stderr : void 0;
25
29
  child.stdout.on("data", (chunk) => {
26
- stdout += chunk.toString();
30
+ stdoutChunks.push(chunk);
31
+ if (stdoutTarget === void 0) {
32
+ stdoutDiagnostics.write(chunk);
33
+ }
27
34
  });
28
35
  child.stderr.on("data", (chunk) => {
29
- stderr += chunk.toString();
36
+ stderrChunks.push(chunk);
37
+ if (stderrTarget === void 0) {
38
+ stderrDiagnostics.write(chunk);
39
+ }
30
40
  });
31
- if (options.stdout) {
32
- child.stdout.pipe(options.stdout);
41
+ if (stdoutTarget !== void 0) {
42
+ child.stdout.pipe(stdoutTarget);
33
43
  }
34
- if (options.stderr) {
35
- child.stderr.pipe(options.stderr);
44
+ if (stderrTarget !== void 0) {
45
+ child.stderr.pipe(stderrTarget);
36
46
  }
37
- const output = new Promise((resolve, reject) => {
38
- child.on("exit", (exitCode) => {
39
- if (exitCode === 0) {
47
+ let rejectInput = () => void 0;
48
+ const inputFailure = new Promise((_resolve, reject) => {
49
+ rejectInput = reject;
50
+ });
51
+ const stopSupervisingInput = options.stdin === void 0 ? () => void 0 : superviseInput(options.stdin, child, rejectInput);
52
+ const childOutput = new Promise((resolve, reject) => {
53
+ let spawnCause;
54
+ child.once("error", (error) => {
55
+ spawnCause = error;
56
+ });
57
+ child.once("close", (exitCode, signal) => {
58
+ stopSupervisingInput();
59
+ stdoutDiagnostics.end();
60
+ stderrDiagnostics.end();
61
+ const stdout = Buffer.concat(stdoutChunks).toString();
62
+ const stderr = Buffer.concat(stderrChunks).toString();
63
+ if (spawnCause === void 0 && signal === null && exitCode === 0) {
40
64
  resolve(stdout);
41
65
  } else {
42
- reject(new ChildProcessError(exitCode, stderr));
66
+ reject(new ChildProcessError(spawnCause === void 0 ? exitCode : null, stdout, stderr, { cause: spawnCause, signal }));
43
67
  }
44
68
  });
45
69
  });
46
- return { output, child };
70
+ const output2 = options.stdin === void 0 ? childOutput : Promise.race([childOutput, inputFailure]);
71
+ return { output: output2, child };
47
72
  });
48
73
  }
49
74
  }
50
75
  class ChildProcessError extends Error {
51
- constructor(exitCode, stderr) {
52
- super(`Command has failed(${exitCode}): ${stderr} `);
76
+ constructor(exitCode, stdoutOrStderr, stderr, options = {}) {
77
+ const legacySignature = stderr === void 0;
78
+ const stdout = legacySignature ? "" : stdoutOrStderr;
79
+ const capturedStderr = legacySignature ? stdoutOrStderr : stderr;
80
+ const signal = options.signal ?? null;
81
+ const message = options.cause !== void 0 ? "Command could not be started." : signal !== null ? `Command terminated by signal ${signal}.` : `Command failed with exit code ${exitCode}.`;
82
+ super(message);
53
83
  this.exitCode = exitCode;
54
- this.stderr = stderr;
84
+ __publicField(this, "stdout");
85
+ __publicField(this, "stderr");
86
+ __publicField(this, "signal");
87
+ __publicField(this, "cause");
88
+ this.name = "ChildProcessError";
89
+ this.stdout = stdout;
90
+ this.stderr = capturedStderr;
91
+ this.signal = signal;
92
+ this.cause = options.cause;
93
+ }
94
+ }
95
+ const superviseInput = (source, child, reject) => {
96
+ let stopped = false;
97
+ const stop = () => {
98
+ if (stopped) {
99
+ return;
100
+ }
101
+ stopped = true;
102
+ source.unpipe(child.stdin);
103
+ source.off("error", onSourceError);
104
+ child.stdin.off("error", onDestinationError);
105
+ };
106
+ const fail = (error) => {
107
+ stop();
108
+ child.stdin.destroy();
109
+ if (child.exitCode === null && child.signalCode === null) {
110
+ child.kill();
111
+ }
112
+ reject(error);
113
+ };
114
+ const onSourceError = (error) => {
115
+ fail(error);
116
+ };
117
+ const onDestinationError = (error) => {
118
+ if (isErrorCode(error, "EPIPE")) {
119
+ stop();
120
+ return;
121
+ }
122
+ fail(error);
123
+ };
124
+ source.once("error", onSourceError);
125
+ child.stdin.once("error", onDestinationError);
126
+ source.pipe(child.stdin);
127
+ return stop;
128
+ };
129
+ const isErrorCode = (error, code) => "code" in error && error.code === code;
130
+ class DiagnosticForwarder {
131
+ constructor(output) {
132
+ this.output = output;
133
+ __publicField(this, "decoder", new node_string_decoder.StringDecoder());
134
+ __publicField(this, "pending", "");
135
+ }
136
+ write(chunk) {
137
+ this.consume(this.decoder.write(chunk));
138
+ }
139
+ end() {
140
+ this.consume(this.decoder.end());
141
+ if (this.pending !== "") {
142
+ this.output.info(this.pending);
143
+ this.pending = "";
144
+ }
145
+ }
146
+ consume(text) {
147
+ this.pending += text;
148
+ while (true) {
149
+ const separator = this.pending.search(/[\r\n]/);
150
+ if (separator === -1) {
151
+ return;
152
+ }
153
+ this.output.info(this.pending.slice(0, separator));
154
+ const separatorLength = this.pending[separator] === "\r" && this.pending[separator + 1] === "\n" ? 2 : 1;
155
+ this.pending = this.pending.slice(separator + separatorLength);
156
+ }
55
157
  }
56
158
  }
57
159
  exports.ChildProcessError = ChildProcessError;
@@ -1 +1 @@
1
- {"version":3,"file":"CommandRunner.cjs","sources":["../../../../../packages/cli-common/src/npm/CommandRunner.ts"],"sourcesContent":["import { ChildProcessWithoutNullStreams, spawn } from 'node:child_process'\nimport { Readable, Writable } from 'node:stream'\nimport chalk from 'chalk'\n\nexport type RunningCommand = { child: ChildProcessWithoutNullStreams; output: Promise<string> }\n\nexport class CommandRunner {\n\trunCommand = (\n\t\tcommand: string,\n\t\targs: (string | undefined)[],\n\t\toptions: {\n\t\t\tcwd: string\n\t\t\tstdin?: Readable\n\t\t\tstdout?: Writable\n\t\t\tstderr?: Writable\n\t\t\tenv?: NodeJS.ProcessEnv\n\t\t\tdetached?: boolean\n\t\t},\n\t): RunningCommand => {\n\t\tconst args2 = args.filter((it): it is string => it !== undefined)\n\t\tif (!process.env.DISABLE_COMMAND_PRINTING) {\n\t\t\tconsole.error(chalk.gray(`$ ${command} ${args2.map(it => `'${it.replace(/'/g, `'\\\\''`)}'`).join(' ')}`))\n\t\t}\n\t\tconst child = spawn(command, args2, {\n\t\t\tcwd: options.cwd,\n\t\t\tenv: { ...process.env, ...(options.env || {}) },\n\t\t\tdetached: options.detached,\n\t\t})\n\t\tif (options.stdin) {\n\t\t\toptions.stdin.pipe(child.stdin)\n\t\t}\n\n\t\tlet stdout = ''\n\t\tlet stderr = ''\n\n\t\tchild.stdout.on('data', (chunk): void => {\n\t\t\tstdout += chunk.toString()\n\t\t})\n\n\t\tchild.stderr.on('data', (chunk): void => {\n\t\t\tstderr += chunk.toString()\n\t\t})\n\t\tif (options.stdout) {\n\t\t\tchild.stdout.pipe(options.stdout)\n\t\t}\n\t\tif (options.stderr) {\n\t\t\tchild.stderr.pipe(options.stderr)\n\t\t}\n\n\t\tconst output = new Promise<string>((resolve, reject) => {\n\t\t\tchild.on('exit', (exitCode): void => {\n\t\t\t\tif (exitCode === 0) {\n\t\t\t\t\tresolve(stdout)\n\t\t\t\t} else {\n\t\t\t\t\treject(new ChildProcessError(exitCode, stderr))\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\n\t\treturn { output, child }\n\t}\n}\n\nexport class ChildProcessError extends Error {\n\tconstructor(public readonly exitCode: number | null, public readonly stderr: string) {\n\t\tsuper(`Command has failed(${exitCode}): ${stderr} `)\n\t}\n}\n"],"names":["spawn"],"mappings":";;;;;;;AAMO,MAAM,cAAc;AAAA,EAApB,cAAA;AACN,kBAAA,MAAA,cAAa,CACZ,SACA,MACA,YAQoB;AACpB,YAAM,QAAQ,KAAK,OAAO,CAAC,OAAqB,OAAO,MAAS;AAChE,UAAI,CAAC,QAAQ,IAAI,0BAA0B;AAC1C,gBAAQ,MAAM,MAAM,KAAK,KAAK,OAAO,IAAI,MAAM,IAAI,CAAA,OAAM,IAAI,GAAG,QAAQ,MAAM,OAAO,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;AAAA,MACxG;AACA,YAAM,QAAQA,mBAAAA,MAAM,SAAS,OAAO;AAAA,QACnC,KAAK,QAAQ;AAAA,QACb,KAAK,EAAE,GAAG,QAAQ,KAAK,GAAI,QAAQ,OAAO,GAAC;AAAA,QAC3C,UAAU,QAAQ;AAAA,MAAA,CAClB;AACD,UAAI,QAAQ,OAAO;AAClB,gBAAQ,MAAM,KAAK,MAAM,KAAK;AAAA,MAC/B;AAEA,UAAI,SAAS;AACb,UAAI,SAAS;AAEb,YAAM,OAAO,GAAG,QAAQ,CAAC,UAAgB;AACxC,kBAAU,MAAM,SAAA;AAAA,MACjB,CAAC;AAED,YAAM,OAAO,GAAG,QAAQ,CAAC,UAAgB;AACxC,kBAAU,MAAM,SAAA;AAAA,MACjB,CAAC;AACD,UAAI,QAAQ,QAAQ;AACnB,cAAM,OAAO,KAAK,QAAQ,MAAM;AAAA,MACjC;AACA,UAAI,QAAQ,QAAQ;AACnB,cAAM,OAAO,KAAK,QAAQ,MAAM;AAAA,MACjC;AAEA,YAAM,SAAS,IAAI,QAAgB,CAAC,SAAS,WAAW;AACvD,cAAM,GAAG,QAAQ,CAAC,aAAmB;AACpC,cAAI,aAAa,GAAG;AACnB,oBAAQ,MAAM;AAAA,UACf,OAAO;AACN,mBAAO,IAAI,kBAAkB,UAAU,MAAM,CAAC;AAAA,UAC/C;AAAA,QACD,CAAC;AAAA,MACF,CAAC;AAED,aAAO,EAAE,QAAQ,MAAA;AAAA,IAClB,CAAA;AAAA,EAAA;AACD;AAEO,MAAM,0BAA0B,MAAM;AAAA,EAC5C,YAA4B,UAAyC,QAAgB;AACpF,UAAM,sBAAsB,QAAQ,MAAM,MAAM,GAAG;AADxB,SAAA,WAAA;AAAyC,SAAA,SAAA;AAAA,EAErE;AACD;;;"}
1
+ {"version":3,"file":"CommandRunner.cjs","sources":["../../../../../packages/cli-common/src/npm/CommandRunner.ts"],"sourcesContent":["import { ChildProcessWithoutNullStreams, spawn } from 'node:child_process'\nimport { Readable, Writable } from 'node:stream'\nimport { StringDecoder } from 'node:string_decoder'\nimport { Output } from '../application/Output.js'\n\nexport type RunningCommand = { child: ChildProcessWithoutNullStreams; output: Promise<string> }\n\nexport class CommandRunner {\n\tconstructor(private readonly output: Output = new Output()) {\n\t}\n\n\trunCommand = (\n\t\tcommand: string,\n\t\targs: (string | undefined)[],\n\t\toptions: {\n\t\t\tcwd: string\n\t\t\tstdin?: Readable\n\t\t\tstdout?: Writable\n\t\t\tstderr?: Writable\n\t\t\tenv?: NodeJS.ProcessEnv\n\t\t\tdetached?: boolean\n\t\t\t/** Human-safe command summary. Never include raw arguments or credentials. */\n\t\t\tdisplay?: string\n\t\t},\n\t): RunningCommand => {\n\t\tconst args2 = args.filter((it): it is string => it !== undefined)\n\t\tif (!process.env.DISABLE_COMMAND_PRINTING && options.display !== undefined) {\n\t\t\tthis.output.info(`$ ${options.display}`)\n\t\t}\n\t\tconst child = spawn(command, args2, {\n\t\t\tcwd: options.cwd,\n\t\t\tenv: { ...process.env, ...(options.env || {}) },\n\t\t\tdetached: options.detached,\n\t\t})\n\t\tconst stdoutChunks: Buffer[] = []\n\t\tconst stderrChunks: Buffer[] = []\n\t\tconst stdoutDiagnostics = new DiagnosticForwarder(this.output)\n\t\tconst stderrDiagnostics = new DiagnosticForwarder(this.output)\n\t\tconst humanMode = this.output.mode === 'human'\n\t\tconst stdoutTarget = humanMode ? options.stdout : undefined\n\t\tconst stderrTarget = humanMode ? options.stderr : undefined\n\n\t\tchild.stdout.on('data', (chunk: Buffer): void => {\n\t\t\tstdoutChunks.push(chunk)\n\t\t\tif (stdoutTarget === undefined) {\n\t\t\t\tstdoutDiagnostics.write(chunk)\n\t\t\t}\n\t\t})\n\n\t\tchild.stderr.on('data', (chunk: Buffer): void => {\n\t\t\tstderrChunks.push(chunk)\n\t\t\tif (stderrTarget === undefined) {\n\t\t\t\tstderrDiagnostics.write(chunk)\n\t\t\t}\n\t\t})\n\t\tif (stdoutTarget !== undefined) {\n\t\t\tchild.stdout.pipe(stdoutTarget)\n\t\t}\n\t\tif (stderrTarget !== undefined) {\n\t\t\tchild.stderr.pipe(stderrTarget)\n\t\t}\n\n\t\tlet rejectInput: (error: Error) => void = () => undefined\n\t\tconst inputFailure = new Promise<never>((_resolve, reject) => {\n\t\t\trejectInput = reject\n\t\t})\n\t\tconst stopSupervisingInput = options.stdin === undefined\n\t\t\t? () => undefined\n\t\t\t: superviseInput(options.stdin, child, rejectInput)\n\n\t\tconst childOutput = new Promise<string>((resolve, reject) => {\n\t\t\tlet spawnCause: Error | undefined\n\t\t\tchild.once('error', (error): void => {\n\t\t\t\tspawnCause = error\n\t\t\t})\n\t\t\tchild.once('close', (exitCode, signal): void => {\n\t\t\t\tstopSupervisingInput()\n\t\t\t\tstdoutDiagnostics.end()\n\t\t\t\tstderrDiagnostics.end()\n\t\t\t\tconst stdout = Buffer.concat(stdoutChunks).toString()\n\t\t\t\tconst stderr = Buffer.concat(stderrChunks).toString()\n\t\t\t\tif (spawnCause === undefined && signal === null && exitCode === 0) {\n\t\t\t\t\tresolve(stdout)\n\t\t\t\t} else {\n\t\t\t\t\treject(new ChildProcessError(spawnCause === undefined ? exitCode : null, stdout, stderr, { cause: spawnCause, signal }))\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\t\tconst output = options.stdin === undefined ? childOutput : Promise.race([childOutput, inputFailure])\n\n\t\treturn { output, child }\n\t}\n}\n\nexport interface ChildProcessErrorOptions {\n\treadonly cause?: Error\n\treadonly signal?: NodeJS.Signals | null\n}\n\nexport class ChildProcessError extends Error {\n\tpublic readonly stdout: string\n\tpublic readonly stderr: string\n\tpublic readonly signal: NodeJS.Signals | null\n\tpublic override readonly cause: Error | undefined\n\n\tconstructor(exitCode: number | null, stderr: string)\n\tconstructor(\n\t\texitCode: number | null,\n\t\tstdout: string,\n\t\tstderr: string,\n\t\toptions?: ChildProcessErrorOptions,\n\t)\n\tconstructor(\n\t\tpublic readonly exitCode: number | null,\n\t\tstdoutOrStderr: string,\n\t\tstderr?: string,\n\t\toptions: ChildProcessErrorOptions = {},\n\t) {\n\t\tconst legacySignature = stderr === undefined\n\t\tconst stdout = legacySignature ? '' : stdoutOrStderr\n\t\tconst capturedStderr = legacySignature ? stdoutOrStderr : stderr\n\t\tconst signal = options.signal ?? null\n\t\tconst message = options.cause !== undefined\n\t\t\t? 'Command could not be started.'\n\t\t\t: signal !== null\n\t\t\t? `Command terminated by signal ${signal}.`\n\t\t\t: `Command failed with exit code ${exitCode}.`\n\t\tsuper(message)\n\t\tthis.name = 'ChildProcessError'\n\t\tthis.stdout = stdout\n\t\tthis.stderr = capturedStderr\n\t\tthis.signal = signal\n\t\tthis.cause = options.cause\n\t}\n}\n\nconst superviseInput = (\n\tsource: Readable,\n\tchild: ChildProcessWithoutNullStreams,\n\treject: (error: Error) => void,\n): () => void => {\n\tlet stopped = false\n\tconst stop = (): void => {\n\t\tif (stopped) {\n\t\t\treturn\n\t\t}\n\t\tstopped = true\n\t\tsource.unpipe(child.stdin)\n\t\tsource.off('error', onSourceError)\n\t\tchild.stdin.off('error', onDestinationError)\n\t}\n\tconst fail = (error: Error): void => {\n\t\tstop()\n\t\tchild.stdin.destroy()\n\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\tchild.kill()\n\t\t}\n\t\treject(error)\n\t}\n\tconst onSourceError = (error: Error): void => {\n\t\tfail(error)\n\t}\n\tconst onDestinationError = (error: Error): void => {\n\t\tif (isErrorCode(error, 'EPIPE')) {\n\t\t\tstop()\n\t\t\treturn\n\t\t}\n\t\tfail(error)\n\t}\n\n\tsource.once('error', onSourceError)\n\tchild.stdin.once('error', onDestinationError)\n\tsource.pipe(child.stdin)\n\treturn stop\n}\n\nconst isErrorCode = (error: Error, code: string): boolean => 'code' in error && error.code === code\n\n/** Streams child output as human diagnostics without allowing it to corrupt JSON or quiet output. */\nclass DiagnosticForwarder {\n\tprivate readonly decoder = new StringDecoder()\n\tprivate pending = ''\n\n\tconstructor(private readonly output: Output) {\n\t}\n\n\tpublic write(chunk: Buffer): void {\n\t\tthis.consume(this.decoder.write(chunk))\n\t}\n\n\tpublic end(): void {\n\t\tthis.consume(this.decoder.end())\n\t\tif (this.pending !== '') {\n\t\t\tthis.output.info(this.pending)\n\t\t\tthis.pending = ''\n\t\t}\n\t}\n\n\tprivate consume(text: string): void {\n\t\tthis.pending += text\n\t\twhile (true) {\n\t\t\tconst separator = this.pending.search(/[\\r\\n]/)\n\t\t\tif (separator === -1) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.output.info(this.pending.slice(0, separator))\n\t\t\tconst separatorLength = this.pending[separator] === '\\r' && this.pending[separator + 1] === '\\n' ? 2 : 1\n\t\t\tthis.pending = this.pending.slice(separator + separatorLength)\n\t\t}\n\t}\n}\n"],"names":["Output","spawn","output","StringDecoder"],"mappings":";;;;;;;;AAOO,MAAM,cAAc;AAAA,EAC1B,YAA6B,SAAiB,IAAIA,OAAAA,UAAU;AAA/B,SAAA,SAAA;AAG7B,kBAAA,MAAA,cAAa,CACZ,SACA,MACA,YAUoB;AACpB,YAAM,QAAQ,KAAK,OAAO,CAAC,OAAqB,OAAO,MAAS;AAChE,UAAI,CAAC,QAAQ,IAAI,4BAA4B,QAAQ,YAAY,QAAW;AAC3E,aAAK,OAAO,KAAK,KAAK,QAAQ,OAAO,EAAE;AAAA,MACxC;AACA,YAAM,QAAQC,mBAAAA,MAAM,SAAS,OAAO;AAAA,QACnC,KAAK,QAAQ;AAAA,QACb,KAAK,EAAE,GAAG,QAAQ,KAAK,GAAI,QAAQ,OAAO,GAAC;AAAA,QAC3C,UAAU,QAAQ;AAAA,MAAA,CAClB;AACD,YAAM,eAAyB,CAAA;AAC/B,YAAM,eAAyB,CAAA;AAC/B,YAAM,oBAAoB,IAAI,oBAAoB,KAAK,MAAM;AAC7D,YAAM,oBAAoB,IAAI,oBAAoB,KAAK,MAAM;AAC7D,YAAM,YAAY,KAAK,OAAO,SAAS;AACvC,YAAM,eAAe,YAAY,QAAQ,SAAS;AAClD,YAAM,eAAe,YAAY,QAAQ,SAAS;AAElD,YAAM,OAAO,GAAG,QAAQ,CAAC,UAAwB;AAChD,qBAAa,KAAK,KAAK;AACvB,YAAI,iBAAiB,QAAW;AAC/B,4BAAkB,MAAM,KAAK;AAAA,QAC9B;AAAA,MACD,CAAC;AAED,YAAM,OAAO,GAAG,QAAQ,CAAC,UAAwB;AAChD,qBAAa,KAAK,KAAK;AACvB,YAAI,iB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