@kaynooo/cli-check 0.0.0-stage → 0.8.0
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.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/cli.js +1948 -0
- package/dist/errs-cli.js +1808 -0
- package/dist/fix-cli.js +2172 -0
- package/package.json +32 -4
package/dist/errs-cli.js
ADDED
|
@@ -0,0 +1,1808 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/errs-cli.ts
|
|
5
|
+
import process11 from "process";
|
|
6
|
+
|
|
7
|
+
// ../kit/src/args.ts
|
|
8
|
+
import process3 from "process";
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
|
|
11
|
+
// ../kit/src/format.ts
|
|
12
|
+
import process2 from "process";
|
|
13
|
+
|
|
14
|
+
// ../kit/src/style.ts
|
|
15
|
+
import process from "process";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
18
|
+
function x(s) {
|
|
19
|
+
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
20
|
+
if (!/^[a-f0-9]+$/.test(r))
|
|
21
|
+
return [0, 0, 0];
|
|
22
|
+
let t = r.length, n = (c) => Number.parseInt(c, 16);
|
|
23
|
+
if (t === 3 || t === 4) {
|
|
24
|
+
let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
|
|
25
|
+
return g !== undefined ? [c, u, h, g] : [c, u, h];
|
|
26
|
+
}
|
|
27
|
+
if (t !== 6 && t !== 8)
|
|
28
|
+
throw Error(`Invalid hex color length: ${t}`);
|
|
29
|
+
let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
|
|
30
|
+
if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
|
|
31
|
+
throw Error(`Invalid hex color value: ${s}`);
|
|
32
|
+
return y !== undefined ? [a, b, o, y] : [a, b, o];
|
|
33
|
+
}
|
|
34
|
+
function A(s) {
|
|
35
|
+
let [r, t, n, a] = s;
|
|
36
|
+
if (a)
|
|
37
|
+
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
38
|
+
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
39
|
+
}
|
|
40
|
+
function R(s, r, t) {
|
|
41
|
+
s = (s % 360 + 360) % 360, t /= 100;
|
|
42
|
+
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
43
|
+
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
44
|
+
return Math.round(255 * y);
|
|
45
|
+
};
|
|
46
|
+
return [a(0), a(8), a(4)];
|
|
47
|
+
}
|
|
48
|
+
function k(s) {
|
|
49
|
+
let [r, t, n] = s;
|
|
50
|
+
r /= 255, t /= 255, n /= 255;
|
|
51
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
52
|
+
if (a !== b) {
|
|
53
|
+
let u = a - b;
|
|
54
|
+
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
55
|
+
o = (t - n) / u + (t < n ? 6 : 0);
|
|
56
|
+
else if (a === t)
|
|
57
|
+
o = (n - r) / u + 2;
|
|
58
|
+
else
|
|
59
|
+
o = (r - t) / u + 4;
|
|
60
|
+
o /= 6;
|
|
61
|
+
}
|
|
62
|
+
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
63
|
+
}
|
|
64
|
+
function H(s, r, t) {
|
|
65
|
+
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
66
|
+
let n = (a) => {
|
|
67
|
+
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
68
|
+
return Math.round(255 * o);
|
|
69
|
+
};
|
|
70
|
+
return [n(5), n(3), n(1)];
|
|
71
|
+
}
|
|
72
|
+
function f(s) {
|
|
73
|
+
let [r, t, n] = s;
|
|
74
|
+
r /= 255, t /= 255, n /= 255;
|
|
75
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
76
|
+
if (o !== 0) {
|
|
77
|
+
if (a === r)
|
|
78
|
+
y = (t - n) / o + (t < n ? 6 : 0);
|
|
79
|
+
else if (a === t)
|
|
80
|
+
y = (n - r) / o + 2;
|
|
81
|
+
else
|
|
82
|
+
y = (r - t) / o + 4;
|
|
83
|
+
y /= 6;
|
|
84
|
+
}
|
|
85
|
+
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
86
|
+
}
|
|
87
|
+
function O(s) {
|
|
88
|
+
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
89
|
+
if (a === 1)
|
|
90
|
+
return [0, 0, 0, 100];
|
|
91
|
+
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
92
|
+
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
93
|
+
}
|
|
94
|
+
function v(s, r, t, n) {
|
|
95
|
+
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
96
|
+
}
|
|
97
|
+
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
98
|
+
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
99
|
+
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
100
|
+
function T(s) {
|
|
101
|
+
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
102
|
+
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
103
|
+
}
|
|
104
|
+
function M(s, r, t) {
|
|
105
|
+
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
106
|
+
return [u(o), u(y), u(c)];
|
|
107
|
+
}
|
|
108
|
+
function d(s) {
|
|
109
|
+
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
110
|
+
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
111
|
+
}
|
|
112
|
+
function C(s, r, t) {
|
|
113
|
+
let n = t * Math.PI / 180;
|
|
114
|
+
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
115
|
+
}
|
|
116
|
+
function l(s) {
|
|
117
|
+
let r = s / 255;
|
|
118
|
+
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class e {
|
|
122
|
+
r;
|
|
123
|
+
g;
|
|
124
|
+
b;
|
|
125
|
+
a;
|
|
126
|
+
constructor(s, r, t, n = 1) {
|
|
127
|
+
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
128
|
+
}
|
|
129
|
+
static from(s, r) {
|
|
130
|
+
if (s === "hex") {
|
|
131
|
+
let [t, n, a, b] = x(r);
|
|
132
|
+
return new e(t, n, a, b);
|
|
133
|
+
}
|
|
134
|
+
if (s === "rgb") {
|
|
135
|
+
if (Array.isArray(r)) {
|
|
136
|
+
let [o, y, c, u] = r;
|
|
137
|
+
return new e(o, y, c, u);
|
|
138
|
+
}
|
|
139
|
+
let { r: t, g: n, b: a, a: b } = r;
|
|
140
|
+
return new e(t, n, a, b);
|
|
141
|
+
}
|
|
142
|
+
if (s === "hsl") {
|
|
143
|
+
let t, n, a, b;
|
|
144
|
+
if (Array.isArray(r))
|
|
145
|
+
[t, n, a, b] = r;
|
|
146
|
+
else
|
|
147
|
+
({ h: t, s: n, l: a, a: b } = r);
|
|
148
|
+
let [o, y, c] = R(t, n, a);
|
|
149
|
+
return new e(o, y, c, b);
|
|
150
|
+
}
|
|
151
|
+
if (s === "hsv") {
|
|
152
|
+
let t, n, a, b;
|
|
153
|
+
if (Array.isArray(r))
|
|
154
|
+
[t, n, a, b] = r;
|
|
155
|
+
else
|
|
156
|
+
({ h: t, s: n, v: a, a: b } = r);
|
|
157
|
+
let [o, y, c] = H(t, n, a);
|
|
158
|
+
return new e(o, y, c, b);
|
|
159
|
+
}
|
|
160
|
+
if (s === "cmyk") {
|
|
161
|
+
let t, n, a, b, o;
|
|
162
|
+
if (Array.isArray(r))
|
|
163
|
+
[t, n, a, b, o] = r;
|
|
164
|
+
else
|
|
165
|
+
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
166
|
+
let [y, c, u] = v(t, n, a, b);
|
|
167
|
+
return new e(y, c, u, o);
|
|
168
|
+
}
|
|
169
|
+
if (s === "oklch") {
|
|
170
|
+
let t, n, a, b;
|
|
171
|
+
if (Array.isArray(r))
|
|
172
|
+
[t, n, a, b] = r;
|
|
173
|
+
else
|
|
174
|
+
({ l: t, c: n, h: a, a: b } = r);
|
|
175
|
+
let [o, y, c] = C(t, n, a);
|
|
176
|
+
return new e(o, y, c, b);
|
|
177
|
+
}
|
|
178
|
+
if (s === "oklab") {
|
|
179
|
+
let t, n, a, b;
|
|
180
|
+
if (Array.isArray(r))
|
|
181
|
+
[t, n, a, b] = r;
|
|
182
|
+
else
|
|
183
|
+
({ l: t, a: n, b: a, alpha: b } = r);
|
|
184
|
+
let [o, y, c] = M(t, n, a);
|
|
185
|
+
return new e(o, y, c, b);
|
|
186
|
+
}
|
|
187
|
+
throw Error("Invalid input");
|
|
188
|
+
}
|
|
189
|
+
to(s) {
|
|
190
|
+
switch (s) {
|
|
191
|
+
case "rgb":
|
|
192
|
+
return [this.r, this.g, this.b];
|
|
193
|
+
case "rgba":
|
|
194
|
+
return [this.r, this.g, this.b, this.a];
|
|
195
|
+
case "hex":
|
|
196
|
+
return A([this.r, this.g, this.b]);
|
|
197
|
+
case "hexa":
|
|
198
|
+
return A([this.r, this.g, this.b, this.a]);
|
|
199
|
+
case "hsl":
|
|
200
|
+
return k([this.r, this.g, this.b]);
|
|
201
|
+
case "hsla":
|
|
202
|
+
return [...k([this.r, this.g, this.b]), this.a];
|
|
203
|
+
case "hsv":
|
|
204
|
+
return f([this.r, this.g, this.b]);
|
|
205
|
+
case "hsva":
|
|
206
|
+
return [...f([this.r, this.g, this.b]), this.a];
|
|
207
|
+
case "cmyk":
|
|
208
|
+
return O([this.r, this.g, this.b]);
|
|
209
|
+
case "cmyka":
|
|
210
|
+
return [...O([this.r, this.g, this.b]), this.a];
|
|
211
|
+
case "oklch":
|
|
212
|
+
return d([this.r, this.g, this.b]);
|
|
213
|
+
case "oklcha":
|
|
214
|
+
return [...d([this.r, this.g, this.b]), this.a];
|
|
215
|
+
case "oklab":
|
|
216
|
+
return T([this.r, this.g, this.b]);
|
|
217
|
+
case "oklaba":
|
|
218
|
+
return [...T([this.r, this.g, this.b]), this.a];
|
|
219
|
+
default:
|
|
220
|
+
return [this.r, this.g, this.b];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
getLuminance() {
|
|
224
|
+
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
225
|
+
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
226
|
+
}
|
|
227
|
+
contrastRatio(s) {
|
|
228
|
+
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
229
|
+
return (n + 0.05) / (a + 0.05);
|
|
230
|
+
}
|
|
231
|
+
bestContrastForeground() {
|
|
232
|
+
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
233
|
+
return t >= n ? s : r;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
238
|
+
var r = 39;
|
|
239
|
+
var o = 49;
|
|
240
|
+
var f2 = "\x1B[";
|
|
241
|
+
var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
242
|
+
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
243
|
+
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
244
|
+
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
245
|
+
var b = new Set(["", "1", "2", "3", "true"]);
|
|
246
|
+
function h(i, n = globalThis.process?.env ?? {}) {
|
|
247
|
+
if (n.FORCE_COLOR !== undefined)
|
|
248
|
+
return b.has(n.FORCE_COLOR);
|
|
249
|
+
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
250
|
+
return false;
|
|
251
|
+
return i?.isTTY === true;
|
|
252
|
+
}
|
|
253
|
+
function d2(i, n, a) {
|
|
254
|
+
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
255
|
+
return n;
|
|
256
|
+
let l = "", s = "";
|
|
257
|
+
for (let g = 0, y = i.length;g < y; g++) {
|
|
258
|
+
let [c, p] = i[g];
|
|
259
|
+
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
260
|
+
}
|
|
261
|
+
return l + n + s;
|
|
262
|
+
}
|
|
263
|
+
function u(i, n = []) {
|
|
264
|
+
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
265
|
+
let g = C2[s];
|
|
266
|
+
if (Array.isArray(g))
|
|
267
|
+
return u(i, [...n, g]);
|
|
268
|
+
if (typeof g === "function")
|
|
269
|
+
return (...y) => u(i, [...n, g(...y)]);
|
|
270
|
+
throw Error(`Unknown style: ${String(s)}`);
|
|
271
|
+
} });
|
|
272
|
+
}
|
|
273
|
+
function le(i = {}) {
|
|
274
|
+
return u(i);
|
|
275
|
+
}
|
|
276
|
+
var t = le();
|
|
277
|
+
|
|
278
|
+
// ../kit/src/style.ts
|
|
279
|
+
var MARKS = {
|
|
280
|
+
ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
|
|
281
|
+
warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
|
|
282
|
+
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
283
|
+
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
284
|
+
};
|
|
285
|
+
function takesControlCodes(stream, env = process.env) {
|
|
286
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
287
|
+
}
|
|
288
|
+
function paint(stream, env = process.env) {
|
|
289
|
+
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
290
|
+
}
|
|
291
|
+
function marked(mark, text, stream, detail, env = process.env) {
|
|
292
|
+
const colors = paint(stream, env);
|
|
293
|
+
const { symbol, word, paint: tint } = MARKS[mark];
|
|
294
|
+
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
295
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
296
|
+
}
|
|
297
|
+
function warn(text, detail) {
|
|
298
|
+
console.error(marked("warn", text, process.stderr, detail));
|
|
299
|
+
}
|
|
300
|
+
var STATUSES = {
|
|
301
|
+
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
302
|
+
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
303
|
+
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
304
|
+
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
305
|
+
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
306
|
+
};
|
|
307
|
+
var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
|
|
308
|
+
|
|
309
|
+
// ../kit/src/format.ts
|
|
310
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
311
|
+
function formatSeconds(total) {
|
|
312
|
+
let rest = Math.max(0, Math.round(total));
|
|
313
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
314
|
+
const amount = Math.floor(rest / size);
|
|
315
|
+
rest -= amount * size;
|
|
316
|
+
return `${amount}${unit}`;
|
|
317
|
+
});
|
|
318
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
319
|
+
if (first === -1)
|
|
320
|
+
return "0s";
|
|
321
|
+
const next = amounts[first + 1];
|
|
322
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
323
|
+
}
|
|
324
|
+
function formatDuration(ms) {
|
|
325
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
326
|
+
}
|
|
327
|
+
function upTo(text, separator) {
|
|
328
|
+
const end = text.indexOf(separator);
|
|
329
|
+
return end === -1 ? text : text.slice(0, end);
|
|
330
|
+
}
|
|
331
|
+
function truncate(text, width) {
|
|
332
|
+
return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
|
|
333
|
+
}
|
|
334
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
335
|
+
var ESCAPE = String.fromCharCode(27);
|
|
336
|
+
function textWidth(text) {
|
|
337
|
+
return Bun.stringWidth(text);
|
|
338
|
+
}
|
|
339
|
+
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
340
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
341
|
+
const widths = [];
|
|
342
|
+
for (const row of cells) {
|
|
343
|
+
for (const [index, cell] of row.entries())
|
|
344
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
345
|
+
}
|
|
346
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
347
|
+
const colors = paint(process2.stdout);
|
|
348
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
349
|
+
const width = widths[index] ?? 0;
|
|
350
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
351
|
+
if (align[index] === "right")
|
|
352
|
+
return `${gap}${cell}`;
|
|
353
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
354
|
+
}).join(" ").trimEnd());
|
|
355
|
+
return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
|
|
356
|
+
`);
|
|
357
|
+
}
|
|
358
|
+
function narrow(rows, widths, limit) {
|
|
359
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
360
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
361
|
+
const floor = 8;
|
|
362
|
+
while (used() > limit) {
|
|
363
|
+
let widest = -1;
|
|
364
|
+
for (const [index, width] of widths.entries()) {
|
|
365
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
366
|
+
widest = index;
|
|
367
|
+
}
|
|
368
|
+
if (widest === -1)
|
|
369
|
+
break;
|
|
370
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
371
|
+
}
|
|
372
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
373
|
+
}
|
|
374
|
+
function printJson(value) {
|
|
375
|
+
console.log(JSON.stringify(value, undefined, 2));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ../kit/src/text.ts
|
|
379
|
+
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
380
|
+
function stripAnsi(text) {
|
|
381
|
+
return text.replace(ANSI, "");
|
|
382
|
+
}
|
|
383
|
+
function distance(a, b) {
|
|
384
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
385
|
+
for (const [i, left] of [...a].entries()) {
|
|
386
|
+
const current = [i + 1];
|
|
387
|
+
for (const [j, right] of [...b].entries())
|
|
388
|
+
current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
|
|
389
|
+
previous = current;
|
|
390
|
+
}
|
|
391
|
+
return previous[b.length] ?? 0;
|
|
392
|
+
}
|
|
393
|
+
function closest(name, names) {
|
|
394
|
+
const started = names.find((known) => known.startsWith(name));
|
|
395
|
+
if (started !== undefined)
|
|
396
|
+
return started;
|
|
397
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
398
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// ../kit/src/args.ts
|
|
402
|
+
function jsonOption(holds) {
|
|
403
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
class Exit extends Error {
|
|
407
|
+
code;
|
|
408
|
+
hint;
|
|
409
|
+
constructor(message, code, hint) {
|
|
410
|
+
super(message);
|
|
411
|
+
this.code = code;
|
|
412
|
+
this.hint = hint;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function fail(message, code = 2, hint) {
|
|
416
|
+
throw new Exit(message, code, hint);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
class UsageError extends Exit {
|
|
420
|
+
constructor(message, hint) {
|
|
421
|
+
super(message, 2, hint);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function badUsage(message) {
|
|
425
|
+
throw new UsageError(message);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
class HelpShown extends Exit {
|
|
429
|
+
constructor() {
|
|
430
|
+
super("help shown", 0);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
class Completing {
|
|
435
|
+
options;
|
|
436
|
+
constructor(options) {
|
|
437
|
+
this.options = options;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
var completion = { active: false };
|
|
441
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
442
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
443
|
+
var FULL_STOP = /\.$/;
|
|
444
|
+
var DASHES = /^-+/;
|
|
445
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
446
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
447
|
+
}
|
|
448
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
449
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
450
|
+
`);
|
|
451
|
+
}
|
|
452
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
453
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
454
|
+
}
|
|
455
|
+
function wantsHelpJson(env = process3.env) {
|
|
456
|
+
return env.KIT_HELP === "json";
|
|
457
|
+
}
|
|
458
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
459
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
460
|
+
`);
|
|
461
|
+
const first = lines[0];
|
|
462
|
+
const colon = first.indexOf(": ");
|
|
463
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
464
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
465
|
+
return {
|
|
466
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
467
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
468
|
+
...replaces === undefined ? {} : { replaces },
|
|
469
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
473
|
+
if (examples.length === 0)
|
|
474
|
+
return [];
|
|
475
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
476
|
+
}
|
|
477
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
478
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
479
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
480
|
+
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
481
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
|
|
482
|
+
});
|
|
483
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
484
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
485
|
+
}
|
|
486
|
+
var OUTPUT_OPTIONS = {
|
|
487
|
+
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
488
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
489
|
+
};
|
|
490
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
491
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
492
|
+
if (when === "auto")
|
|
493
|
+
return;
|
|
494
|
+
if (when !== "always" && when !== "never")
|
|
495
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
496
|
+
if (when === "always") {
|
|
497
|
+
env.FORCE_COLOR = "1";
|
|
498
|
+
delete env.NO_COLOR;
|
|
499
|
+
} else {
|
|
500
|
+
env.NO_COLOR = "1";
|
|
501
|
+
delete env.FORCE_COLOR;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function parse(args, usage, options, settings = {}) {
|
|
505
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
506
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
507
|
+
if (completion.active)
|
|
508
|
+
throw new Completing(all);
|
|
509
|
+
const separator = settings.rest === true ? args.indexOf("--") : -1;
|
|
510
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
511
|
+
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
512
|
+
let parsed;
|
|
513
|
+
try {
|
|
514
|
+
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
515
|
+
} catch (error) {
|
|
516
|
+
const message = parseError(error);
|
|
517
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
518
|
+
}
|
|
519
|
+
const values = parsed.values;
|
|
520
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
521
|
+
if (values.help === true) {
|
|
522
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
|
|
523
|
+
throw new HelpShown;
|
|
524
|
+
}
|
|
525
|
+
if (settings.positionals !== undefined)
|
|
526
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
527
|
+
return { ...parsed, positionals: parsed.positionals, rest };
|
|
528
|
+
}
|
|
529
|
+
function checkPositionals(given, names) {
|
|
530
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
531
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
532
|
+
if (given.length < required)
|
|
533
|
+
badUsage(`missing ${names[given.length]}`);
|
|
534
|
+
if (!variadic && given.length > names.length)
|
|
535
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
536
|
+
}
|
|
537
|
+
function joinDashValues(args, options) {
|
|
538
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
539
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
540
|
+
const joined = [];
|
|
541
|
+
for (let i = 0;i < args.length; i++) {
|
|
542
|
+
const arg = args[i] ?? "";
|
|
543
|
+
if (arg === "--")
|
|
544
|
+
return [...joined, ...args.slice(i)];
|
|
545
|
+
const name = longOf.get(arg);
|
|
546
|
+
const next = args[i + 1];
|
|
547
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
548
|
+
joined.push(`--${name}=${next}`);
|
|
549
|
+
i++;
|
|
550
|
+
} else {
|
|
551
|
+
joined.push(arg);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return joined;
|
|
555
|
+
}
|
|
556
|
+
function parseError(error) {
|
|
557
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
558
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
559
|
+
}
|
|
560
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
561
|
+
function nearestOption(message, options, allowNegative) {
|
|
562
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
563
|
+
if (typed === undefined)
|
|
564
|
+
return;
|
|
565
|
+
const word = typed.replace(DASHES, "");
|
|
566
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
567
|
+
return;
|
|
568
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
569
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
570
|
+
`--${name}`,
|
|
571
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
572
|
+
]);
|
|
573
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
574
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
575
|
+
}
|
|
576
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
577
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
578
|
+
function duration(value, name, fallback, unit = "s") {
|
|
579
|
+
if (value === undefined)
|
|
580
|
+
return fallback;
|
|
581
|
+
const match = DURATION.exec(value.trim());
|
|
582
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
583
|
+
if (ms < 1)
|
|
584
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
585
|
+
return ms;
|
|
586
|
+
}
|
|
587
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
588
|
+
if (path === "-") {
|
|
589
|
+
if (process3.stdin.isTTY)
|
|
590
|
+
fail(noStdin);
|
|
591
|
+
return Bun.stdin.text();
|
|
592
|
+
}
|
|
593
|
+
const file = Bun.file(path);
|
|
594
|
+
if (!await file.exists())
|
|
595
|
+
fail(`no file ${path}`);
|
|
596
|
+
return file.text();
|
|
597
|
+
}
|
|
598
|
+
// ../kit/src/process.ts
|
|
599
|
+
import { constants } from "os";
|
|
600
|
+
import process4 from "process";
|
|
601
|
+
var KILL_GRACE_MS = 2000;
|
|
602
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
603
|
+
function exitCodeOf(code, signal) {
|
|
604
|
+
if (code !== null)
|
|
605
|
+
return code;
|
|
606
|
+
if (typeof signal === "number")
|
|
607
|
+
return 128 + signal;
|
|
608
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
609
|
+
}
|
|
610
|
+
function holdSignals(cleanup) {
|
|
611
|
+
let received;
|
|
612
|
+
let child;
|
|
613
|
+
const held = {
|
|
614
|
+
get signal() {
|
|
615
|
+
return received;
|
|
616
|
+
},
|
|
617
|
+
forward: (to) => {
|
|
618
|
+
child = to;
|
|
619
|
+
},
|
|
620
|
+
release: () => {
|
|
621
|
+
for (const signal of SIGNALS)
|
|
622
|
+
process4.off(signal, onSignal);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
function onSignal(signal) {
|
|
626
|
+
received = signal;
|
|
627
|
+
if (child !== undefined) {
|
|
628
|
+
child.kill(signal);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (cleanup === undefined)
|
|
632
|
+
return;
|
|
633
|
+
held.release();
|
|
634
|
+
cleanup(signal);
|
|
635
|
+
process4.kill(process4.pid, signal);
|
|
636
|
+
}
|
|
637
|
+
for (const signal of SIGNALS)
|
|
638
|
+
process4.on(signal, onSignal);
|
|
639
|
+
return held;
|
|
640
|
+
}
|
|
641
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
642
|
+
const chunks = [];
|
|
643
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
644
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
645
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
646
|
+
const timers = [];
|
|
647
|
+
const killGroup = (killing) => {
|
|
648
|
+
if (state.done)
|
|
649
|
+
return;
|
|
650
|
+
try {
|
|
651
|
+
if (grouped)
|
|
652
|
+
process4.kill(-proc.pid, killing);
|
|
653
|
+
else
|
|
654
|
+
proc.kill(killing);
|
|
655
|
+
} catch {}
|
|
656
|
+
};
|
|
657
|
+
const stop = () => {
|
|
658
|
+
killGroup("SIGTERM");
|
|
659
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
660
|
+
};
|
|
661
|
+
const onAbort = () => stop();
|
|
662
|
+
if (timeoutMs !== undefined) {
|
|
663
|
+
timers.push(setTimeout(() => {
|
|
664
|
+
state.timedOut = true;
|
|
665
|
+
stop();
|
|
666
|
+
}, timeoutMs));
|
|
667
|
+
}
|
|
668
|
+
if (signal?.aborted === true)
|
|
669
|
+
onAbort();
|
|
670
|
+
else
|
|
671
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
672
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
673
|
+
const drain = async (stream, name) => {
|
|
674
|
+
for await (const data of stream) {
|
|
675
|
+
if (state.failure !== undefined)
|
|
676
|
+
continue;
|
|
677
|
+
try {
|
|
678
|
+
onChunk?.({ stream: name, data });
|
|
679
|
+
} catch (error) {
|
|
680
|
+
state.failure = error;
|
|
681
|
+
stop();
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
if (state.kept + data.length > maxBytes) {
|
|
685
|
+
state.truncated = true;
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
state.kept += data.length;
|
|
689
|
+
chunks.push({ stream: name, data });
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
try {
|
|
693
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
694
|
+
await proc.exited;
|
|
695
|
+
} finally {
|
|
696
|
+
state.done = true;
|
|
697
|
+
for (const timer of timers)
|
|
698
|
+
clearTimeout(timer);
|
|
699
|
+
signal?.removeEventListener("abort", onAbort);
|
|
700
|
+
}
|
|
701
|
+
if (state.failure !== undefined)
|
|
702
|
+
throw state.failure;
|
|
703
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
704
|
+
let output;
|
|
705
|
+
let text;
|
|
706
|
+
return {
|
|
707
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
708
|
+
chunks,
|
|
709
|
+
timedOut: state.timedOut,
|
|
710
|
+
truncated: state.truncated,
|
|
711
|
+
get output() {
|
|
712
|
+
return output ??= joined();
|
|
713
|
+
},
|
|
714
|
+
get text() {
|
|
715
|
+
return text ??= (output ??= joined()).toString();
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ../kit/src/progress.ts
|
|
721
|
+
var ESC = String.fromCharCode(27);
|
|
722
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
723
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
724
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
725
|
+
// ../kit/src/cli.ts
|
|
726
|
+
import process5 from "process";
|
|
727
|
+
var LEVEL_OPTIONS = {
|
|
728
|
+
...OUTPUT_OPTIONS,
|
|
729
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
730
|
+
};
|
|
731
|
+
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
732
|
+
function printError(prefix, message, hint, cause) {
|
|
733
|
+
const colors = paint(process5.stderr);
|
|
734
|
+
const styled = takesControlCodes(process5.stderr);
|
|
735
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
736
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
737
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
738
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
739
|
+
}
|
|
740
|
+
function printJsonError(message, hint, cause) {
|
|
741
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
742
|
+
}
|
|
743
|
+
function wantsJson(argv) {
|
|
744
|
+
const end = argv.indexOf("--");
|
|
745
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
746
|
+
}
|
|
747
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
748
|
+
if (error instanceof HelpShown)
|
|
749
|
+
return 0;
|
|
750
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
751
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
752
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
753
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
754
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
755
|
+
return error instanceof Exit ? error.code : 1;
|
|
756
|
+
}
|
|
757
|
+
var COMPLETE = "__complete";
|
|
758
|
+
var FILES = "__files__";
|
|
759
|
+
async function optionsOf(run) {
|
|
760
|
+
completion.active = true;
|
|
761
|
+
try {
|
|
762
|
+
await run([]);
|
|
763
|
+
} catch (error) {
|
|
764
|
+
if (error instanceof Completing)
|
|
765
|
+
return error.options;
|
|
766
|
+
} finally {
|
|
767
|
+
completion.active = false;
|
|
768
|
+
}
|
|
769
|
+
return {};
|
|
770
|
+
}
|
|
771
|
+
async function leafCandidates(run, words) {
|
|
772
|
+
if (!(words.at(-1) ?? "").startsWith("-"))
|
|
773
|
+
return [FILES];
|
|
774
|
+
return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
775
|
+
}
|
|
776
|
+
async function printCandidates(found) {
|
|
777
|
+
for (const line of await found)
|
|
778
|
+
console.log(line);
|
|
779
|
+
return 0;
|
|
780
|
+
}
|
|
781
|
+
async function runMain({ name, version, run, redact }, argv = process5.argv.slice(2)) {
|
|
782
|
+
if (argv[0] === COMPLETE)
|
|
783
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
784
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
785
|
+
console.log(version);
|
|
786
|
+
return 0;
|
|
787
|
+
}
|
|
788
|
+
try {
|
|
789
|
+
return await run(argv);
|
|
790
|
+
} catch (error) {
|
|
791
|
+
return reportThrown(name, error, redact, wantsJson(argv));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
// ../kit/src/logs.ts
|
|
795
|
+
import { lstatSync, openSync } from "fs";
|
|
796
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
797
|
+
import { homedir, tmpdir } from "os";
|
|
798
|
+
import { join } from "path";
|
|
799
|
+
import process6 from "process";
|
|
800
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
801
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
802
|
+
function isPrivateDirectory(path) {
|
|
803
|
+
try {
|
|
804
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
805
|
+
return info !== undefined && info.isDirectory() && info.uid === (process6.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
806
|
+
} catch {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
async function privateLogDirectory(name, env = process6.env) {
|
|
811
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
812
|
+
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
813
|
+
const path = join(base, name);
|
|
814
|
+
try {
|
|
815
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
816
|
+
if (isPrivateDirectory(path))
|
|
817
|
+
return path;
|
|
818
|
+
} catch {}
|
|
819
|
+
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
820
|
+
}
|
|
821
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
822
|
+
let names;
|
|
823
|
+
try {
|
|
824
|
+
names = await readdir(dir);
|
|
825
|
+
} catch {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
for (const name of names) {
|
|
829
|
+
const path = join(dir, name);
|
|
830
|
+
try {
|
|
831
|
+
const info = await stat(path);
|
|
832
|
+
if (info.isDirectory())
|
|
833
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
834
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
835
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
836
|
+
} catch {
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
// ../kit/src/secrets.ts
|
|
842
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
843
|
+
// ../kit/src/sessions.ts
|
|
844
|
+
var {Glob } = globalThis.Bun;
|
|
845
|
+
var SESSION_FILES = new Glob("*.json");
|
|
846
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
847
|
+
// package.json
|
|
848
|
+
var version = "0.8.0";
|
|
849
|
+
|
|
850
|
+
// src/errs.ts
|
|
851
|
+
import { relative as relative2 } from "path";
|
|
852
|
+
import process10 from "process";
|
|
853
|
+
|
|
854
|
+
// src/compose.ts
|
|
855
|
+
import { existsSync } from "fs";
|
|
856
|
+
import { homedir as homedir2 } from "os";
|
|
857
|
+
import { basename, dirname, join as join2, relative, resolve } from "path";
|
|
858
|
+
import process8 from "process";
|
|
859
|
+
|
|
860
|
+
// ../kit/src/shell.ts
|
|
861
|
+
var SEPARATORS = new Set([`
|
|
862
|
+
`, ";", "|"]);
|
|
863
|
+
var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
|
|
864
|
+
var GLOB_CHARS = new Set(["*", "?", "["]);
|
|
865
|
+
var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
866
|
+
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
867
|
+
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
868
|
+
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
869
|
+
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh"]);
|
|
870
|
+
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, "su", "runuser"]);
|
|
871
|
+
var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
872
|
+
var PRINTERS = new Set(["echo", "printf"]);
|
|
873
|
+
var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
874
|
+
function wrapper(short = "", long = [], operands = 0) {
|
|
875
|
+
return { short, long, operands };
|
|
876
|
+
}
|
|
877
|
+
var WRAPPERS = new Map([
|
|
878
|
+
["command", wrapper()],
|
|
879
|
+
["builtin", wrapper()],
|
|
880
|
+
["nohup", wrapper()],
|
|
881
|
+
["setsid", wrapper()],
|
|
882
|
+
["busybox", wrapper()],
|
|
883
|
+
["exec", wrapper("a")],
|
|
884
|
+
["time", wrapper("fo", ["--format", "--output"])],
|
|
885
|
+
["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
|
|
886
|
+
["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
|
|
887
|
+
["doas", wrapper("uC")],
|
|
888
|
+
["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
|
|
889
|
+
["nice", wrapper("n", ["--adjustment"])],
|
|
890
|
+
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
891
|
+
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
892
|
+
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
893
|
+
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
|
|
894
|
+
]);
|
|
895
|
+
function shellQuote(word) {
|
|
896
|
+
return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// src/compose.ts
|
|
900
|
+
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
901
|
+
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
902
|
+
var PS_TIMEOUT_MS = 20000;
|
|
903
|
+
var VARIABLE = /\$\{(\w+)(?::?-([^${}]*))?\}|\$(\w+)/g;
|
|
904
|
+
var ENV_LINE = /^\s*(?:export\s+)?(\w+)=(.*)$/;
|
|
905
|
+
var QUOTED = /^(['"])(.*)\1$/;
|
|
906
|
+
var TOOL_WORDS = {
|
|
907
|
+
bun: ["bun"],
|
|
908
|
+
bunx: ["bun"],
|
|
909
|
+
node: ["node", "bun"],
|
|
910
|
+
npm: ["node", "bun"],
|
|
911
|
+
npx: ["node", "bun"],
|
|
912
|
+
pnpm: ["node", "bun"],
|
|
913
|
+
yarn: ["node", "bun"],
|
|
914
|
+
composer: ["php"],
|
|
915
|
+
php: ["php"],
|
|
916
|
+
phpunit: ["php"],
|
|
917
|
+
phpstan: ["php"],
|
|
918
|
+
paratest: ["php"],
|
|
919
|
+
pest: ["php"],
|
|
920
|
+
symfony: ["php"]
|
|
921
|
+
};
|
|
922
|
+
function toolWords(program) {
|
|
923
|
+
const name = basename(program);
|
|
924
|
+
return TOOL_WORDS[name] ?? (program.includes("vendor/bin/") ? ["php"] : []);
|
|
925
|
+
}
|
|
926
|
+
async function readFiles(dir, names) {
|
|
927
|
+
for (const name of names) {
|
|
928
|
+
const handle = Bun.file(join2(dir, name));
|
|
929
|
+
if (await handle.exists())
|
|
930
|
+
return { name, text: await handle.text() };
|
|
931
|
+
}
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
async function variables(composeDir) {
|
|
935
|
+
const env = {};
|
|
936
|
+
const text = (await readFiles(composeDir, [".env"]))?.text ?? "";
|
|
937
|
+
for (const line of text.split(`
|
|
938
|
+
`)) {
|
|
939
|
+
const match = ENV_LINE.exec(line);
|
|
940
|
+
if (match !== null && !line.trimStart().startsWith("#"))
|
|
941
|
+
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
942
|
+
}
|
|
943
|
+
for (const [key, value] of Object.entries(process8.env)) {
|
|
944
|
+
if (value !== undefined)
|
|
945
|
+
env[key] = value;
|
|
946
|
+
}
|
|
947
|
+
env.PWD = composeDir;
|
|
948
|
+
return env;
|
|
949
|
+
}
|
|
950
|
+
function interpolate(text, env) {
|
|
951
|
+
let current = text;
|
|
952
|
+
for (let round = 0;round < 4 && current.includes("$"); round++) {
|
|
953
|
+
current = current.replaceAll(VARIABLE, (_, braced, fallback, bare) => {
|
|
954
|
+
const value = env[braced ?? bare ?? ""];
|
|
955
|
+
return value !== undefined && value !== "" ? value : fallback ?? "";
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
return current;
|
|
959
|
+
}
|
|
960
|
+
function bindSource(source, composeDir, env) {
|
|
961
|
+
const path = interpolate(source, env);
|
|
962
|
+
if (path.startsWith("~"))
|
|
963
|
+
return join2(homedir2(), path.slice(1));
|
|
964
|
+
if (path.startsWith("/"))
|
|
965
|
+
return resolve(path);
|
|
966
|
+
return path.startsWith(".") ? resolve(composeDir, path) : undefined;
|
|
967
|
+
}
|
|
968
|
+
function mountsOf(volumes, composeDir, env) {
|
|
969
|
+
if (!Array.isArray(volumes))
|
|
970
|
+
return [];
|
|
971
|
+
const mounts = [];
|
|
972
|
+
for (const volume of volumes) {
|
|
973
|
+
let source;
|
|
974
|
+
let target;
|
|
975
|
+
if (typeof volume === "string") {
|
|
976
|
+
[source, target] = interpolate(volume, env).split(":");
|
|
977
|
+
} else if (typeof volume === "object" && volume !== null) {
|
|
978
|
+
const object = volume;
|
|
979
|
+
if (object.type === "bind" && typeof object.source === "string" && typeof object.target === "string")
|
|
980
|
+
({ source, target } = object);
|
|
981
|
+
}
|
|
982
|
+
const resolved = source === undefined ? undefined : bindSource(source, composeDir, env);
|
|
983
|
+
if (resolved !== undefined && target?.startsWith("/") === true)
|
|
984
|
+
mounts.push({ source: resolved, target });
|
|
985
|
+
}
|
|
986
|
+
return mounts;
|
|
987
|
+
}
|
|
988
|
+
function buildText(build) {
|
|
989
|
+
if (typeof build === "string")
|
|
990
|
+
return build;
|
|
991
|
+
return typeof build === "object" && build !== null ? Object.values(build).filter((value) => typeof value === "string").join(" ") : "";
|
|
992
|
+
}
|
|
993
|
+
function parseServices(text, composeDir, env) {
|
|
994
|
+
const services = new Map;
|
|
995
|
+
const parsed = Bun.YAML.parse(text);
|
|
996
|
+
for (const [name, service] of Object.entries(parsed?.services ?? {})) {
|
|
997
|
+
if (service !== null && typeof service === "object")
|
|
998
|
+
services.set(name, { ...service, mounts: mountsOf(service.volumes, composeDir, env) });
|
|
999
|
+
}
|
|
1000
|
+
return services;
|
|
1001
|
+
}
|
|
1002
|
+
async function composeFiles(composeDir, env) {
|
|
1003
|
+
const listed = env.COMPOSE_FILE;
|
|
1004
|
+
if (listed !== undefined && listed !== "") {
|
|
1005
|
+
const files = [];
|
|
1006
|
+
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1007
|
+
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1008
|
+
const file = Bun.file(resolve(composeDir, name));
|
|
1009
|
+
if (!await file.exists())
|
|
1010
|
+
fail(`COMPOSE_FILE names ${join2(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1011
|
+
files.push({ name, text: await file.text() });
|
|
1012
|
+
}
|
|
1013
|
+
return files;
|
|
1014
|
+
}
|
|
1015
|
+
const base = await readFiles(composeDir, COMPOSE_FILES);
|
|
1016
|
+
if (base === undefined)
|
|
1017
|
+
return [];
|
|
1018
|
+
const override = await readFiles(composeDir, OVERRIDE_FILES);
|
|
1019
|
+
return override === undefined ? [base] : [base, override];
|
|
1020
|
+
}
|
|
1021
|
+
async function readServices(composeDir) {
|
|
1022
|
+
const env = await variables(composeDir);
|
|
1023
|
+
const files = await composeFiles(composeDir, env);
|
|
1024
|
+
if (files.length === 0)
|
|
1025
|
+
return;
|
|
1026
|
+
const services = new Map;
|
|
1027
|
+
for (const file of files) {
|
|
1028
|
+
let parsed;
|
|
1029
|
+
try {
|
|
1030
|
+
parsed = parseServices(file.text, composeDir, env);
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
fail(`cannot read ${join2(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1033
|
+
}
|
|
1034
|
+
for (const [name, extra] of parsed) {
|
|
1035
|
+
const known = services.get(name);
|
|
1036
|
+
services.set(name, known === undefined ? extra : { ...known, ...extra, mounts: [...known.mounts, ...extra.mounts], image: extra.image ?? known.image, build: extra.build ?? known.build });
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return [...services].map(([name, service]) => ({ name, mounts: service.mounts, profile: `${name} ${typeof service.image === "string" ? service.image : ""} ${buildText(service.build)}`.toLowerCase() }));
|
|
1040
|
+
}
|
|
1041
|
+
function climb(dir) {
|
|
1042
|
+
const folders = [dir];
|
|
1043
|
+
let current = dir;
|
|
1044
|
+
while (!existsSync(join2(current, ".git")) && dirname(current) !== current) {
|
|
1045
|
+
current = dirname(current);
|
|
1046
|
+
folders.push(current);
|
|
1047
|
+
}
|
|
1048
|
+
return existsSync(join2(current, ".git")) ? folders : [dir];
|
|
1049
|
+
}
|
|
1050
|
+
function containerPath(service, dir) {
|
|
1051
|
+
const holding = service.mounts.filter((mount) => {
|
|
1052
|
+
const inside = relative(mount.source, dir);
|
|
1053
|
+
return !inside.startsWith("..") && !inside.startsWith("/");
|
|
1054
|
+
});
|
|
1055
|
+
const deepest = holding.toSorted((a, b) => b.source.length - a.source.length)[0];
|
|
1056
|
+
if (deepest === undefined)
|
|
1057
|
+
return;
|
|
1058
|
+
const inside = relative(deepest.source, dir);
|
|
1059
|
+
return inside === "" ? deepest.target : join2(deepest.target, inside);
|
|
1060
|
+
}
|
|
1061
|
+
var noticed = new Set;
|
|
1062
|
+
async function place(dir, program, { service, host } = {}) {
|
|
1063
|
+
if (host === true)
|
|
1064
|
+
return;
|
|
1065
|
+
let found;
|
|
1066
|
+
for (const composeDir of climb(dir)) {
|
|
1067
|
+
const services = await readServices(composeDir);
|
|
1068
|
+
const mounting = (services ?? []).filter((candidate) => containerPath(candidate, dir) !== undefined);
|
|
1069
|
+
if (services !== undefined && (mounting.length > 0 || services.some((candidate) => candidate.name === service))) {
|
|
1070
|
+
found = { composeDir, services, mounting };
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (found === undefined) {
|
|
1075
|
+
if (service !== undefined)
|
|
1076
|
+
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
if (Bun.which("docker", { PATH: process8.env.PATH ?? "" }) === null) {
|
|
1080
|
+
if (service !== undefined)
|
|
1081
|
+
fail(`--in ${service}: docker not found`);
|
|
1082
|
+
if (!noticed.has(found.composeDir)) {
|
|
1083
|
+
noticed.add(found.composeDir);
|
|
1084
|
+
warn(`host, docker not found: the compose project in ${found.composeDir} is not reached`);
|
|
1085
|
+
}
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const chosen = choose(found.mounting, found.services, dir, program, service);
|
|
1089
|
+
return { service: chosen.name, composeDir: found.composeDir, workdir: containerPath(chosen, dir) ?? dir };
|
|
1090
|
+
}
|
|
1091
|
+
function choose(mounting, services, dir, program, service) {
|
|
1092
|
+
if (service !== undefined) {
|
|
1093
|
+
const named = mounting.find((candidate) => candidate.name === service);
|
|
1094
|
+
if (named === undefined)
|
|
1095
|
+
fail(`--in ${service}: ${services.some((candidate) => candidate.name === service) ? `the service does not mount ${dir}` : `no such service, found ${services.map((candidate) => candidate.name).join(", ")}`}`);
|
|
1096
|
+
return named;
|
|
1097
|
+
}
|
|
1098
|
+
const [only] = mounting;
|
|
1099
|
+
if (mounting.length === 1 && only !== undefined)
|
|
1100
|
+
return only;
|
|
1101
|
+
const words = toolWords(program);
|
|
1102
|
+
const fitting = mounting.filter((candidate) => words.some((word) => candidate.profile.includes(word)));
|
|
1103
|
+
const [fit] = fitting;
|
|
1104
|
+
if (fitting.length !== 1 || fit === undefined)
|
|
1105
|
+
fail(`${mounting.map((candidate) => candidate.name).join(", ")} all mount ${dir} and none stands out for ${basename(program)}: pick one with --in <service>, or run on the host with --host`);
|
|
1106
|
+
return fit;
|
|
1107
|
+
}
|
|
1108
|
+
function execArgv(placement, argv, env) {
|
|
1109
|
+
const variables = Object.entries({ NO_COLOR: "1", FORCE_COLOR: "0", ...env }).flatMap(([name, value]) => ["-e", `${name}=${value}`]);
|
|
1110
|
+
return ["docker", "compose", "exec", "-T", "-w", placement.workdir, ...variables, placement.service, ...argv];
|
|
1111
|
+
}
|
|
1112
|
+
function shellIn(placement, command, env = {}) {
|
|
1113
|
+
return `cd ${shellQuote(placement.composeDir)} && ${execArgv(placement, ["sh", "-c", command], env).map((word) => shellQuote(word)).join(" ")}`;
|
|
1114
|
+
}
|
|
1115
|
+
function argvIn(placement, argv) {
|
|
1116
|
+
return execArgv(placement, argv, {});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
class Stack {
|
|
1120
|
+
answers = new Map;
|
|
1121
|
+
async ask(composeDir) {
|
|
1122
|
+
let answer = this.answers.get(composeDir);
|
|
1123
|
+
if (answer === undefined) {
|
|
1124
|
+
answer = Stack.running(composeDir);
|
|
1125
|
+
this.answers.set(composeDir, answer);
|
|
1126
|
+
}
|
|
1127
|
+
return answer;
|
|
1128
|
+
}
|
|
1129
|
+
static async running(composeDir) {
|
|
1130
|
+
try {
|
|
1131
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process8.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1132
|
+
if (ran.code !== 0)
|
|
1133
|
+
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1134
|
+
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
1135
|
+
return ran.text.split(`
|
|
1136
|
+
`).map((line) => line.trim()).filter((line) => line !== "");
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
return `cannot run docker compose in ${composeDir}: ${error instanceof Error ? error.message : String(error)}`;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
async problem(placement) {
|
|
1142
|
+
const answer = await this.ask(placement.composeDir);
|
|
1143
|
+
if (typeof answer === "string")
|
|
1144
|
+
return answer;
|
|
1145
|
+
return answer.includes(placement.service) ? undefined : `the ${placement.service} service is not running (compose project in ${placement.composeDir}): start it yourself, or run on the host with --host`;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function programOf(command) {
|
|
1149
|
+
const end = command.indexOf(" ");
|
|
1150
|
+
return end === -1 ? command : command.slice(0, end);
|
|
1151
|
+
}
|
|
1152
|
+
var placeOptions = {
|
|
1153
|
+
in: { type: "string", description: "run in this compose service instead of the one found mounting the folder" },
|
|
1154
|
+
host: { type: "boolean", description: "run on the host even when a compose service mounts the folder" }
|
|
1155
|
+
};
|
|
1156
|
+
function placeSettings(values) {
|
|
1157
|
+
if (values.in !== undefined && values.host === true)
|
|
1158
|
+
fail("--in and --host exclude each other");
|
|
1159
|
+
return { service: values.in, host: values.host };
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// src/e2e.ts
|
|
1163
|
+
var E2E_NOISE = [
|
|
1164
|
+
/^(?:Running \d+ tests? using|\(node:\d+\) Warning|\(Use `node|\[\d+\/\d+\] |\s+[-\u2713\u2718\u00B0\u00D7]\s+\d+|To open last HTML|Serving HTML report|\s*npx playwright show-report)/,
|
|
1165
|
+
/^[\u00B7F\u00D7\u00B0T\u00B1]+$/,
|
|
1166
|
+
/^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/
|
|
1167
|
+
];
|
|
1168
|
+
var PLAYWRIGHT_HEADER = /^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1169
|
+
var PLAYWRIGHT_SUMMARY = /^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/;
|
|
1170
|
+
var PLAYWRIGHT_ENTRY = /^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1171
|
+
var PLAYWRIGHT_RETRY = /^\s+Retry #\d+ \u2500+$/;
|
|
1172
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1173
|
+
var EXPECTED = /^\s+Expected: (.*)$/;
|
|
1174
|
+
var RECEIVED = /^\s+Received: (.*)$/;
|
|
1175
|
+
var VITEST_FAIL = /^ FAIL {2}(?:\|[^|]+\| )?(.+)$/;
|
|
1176
|
+
var VITEST_SUITE = /^(.+?) \[ .+ \]$/;
|
|
1177
|
+
var VITEST_FRAME = /^\s*\u276F (\S+):(\d+):(\d+)$/;
|
|
1178
|
+
function key(project, file, line, column, title) {
|
|
1179
|
+
return `${project ?? ""}|${file}:${line}:${column} \u203A ${title}`;
|
|
1180
|
+
}
|
|
1181
|
+
function firstFrame(block) {
|
|
1182
|
+
return block.map((line) => FRAME.exec(line)).find((match) => match !== null && !match[1]?.includes("node_modules")) ?? undefined;
|
|
1183
|
+
}
|
|
1184
|
+
var collectPlaywright = (lines, used) => {
|
|
1185
|
+
const flaky = new Set;
|
|
1186
|
+
let section = "";
|
|
1187
|
+
for (const [index, line] of lines.entries()) {
|
|
1188
|
+
const summary = PLAYWRIGHT_SUMMARY.exec(line);
|
|
1189
|
+
const entry = PLAYWRIGHT_ENTRY.exec(line);
|
|
1190
|
+
if (summary !== null) {
|
|
1191
|
+
section = summary[1] ?? "";
|
|
1192
|
+
used.add(index);
|
|
1193
|
+
} else if (entry !== null && section !== "") {
|
|
1194
|
+
if (section === "flaky")
|
|
1195
|
+
flaky.add(key(entry[1], entry[2], entry[3], entry[4], entry[5]));
|
|
1196
|
+
used.add(index);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
const errors = [];
|
|
1200
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1201
|
+
const header = PLAYWRIGHT_HEADER.exec(lines[index] ?? "");
|
|
1202
|
+
if (header === null)
|
|
1203
|
+
continue;
|
|
1204
|
+
let end = index + 1;
|
|
1205
|
+
while (end < lines.length && !PLAYWRIGHT_HEADER.test(lines[end] ?? "") && !PLAYWRIGHT_SUMMARY.test(lines[end] ?? ""))
|
|
1206
|
+
end++;
|
|
1207
|
+
for (let at = index;at < end; at++)
|
|
1208
|
+
used.add(at);
|
|
1209
|
+
const [, project, file, line, column, title] = header;
|
|
1210
|
+
const retry = lines.findIndex((text, at) => at > index && at < end && PLAYWRIGHT_RETRY.test(text));
|
|
1211
|
+
const block = lines.slice(index + 1, retry === -1 ? end : retry);
|
|
1212
|
+
const frame = firstFrame(block);
|
|
1213
|
+
const message = block.find((text) => text.trim() !== "")?.trim() ?? "failed";
|
|
1214
|
+
const expected = block.map((text) => EXPECTED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1215
|
+
const received = block.map((text) => RECEIVED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1216
|
+
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
1217
|
+
index = end - 1;
|
|
1218
|
+
if (flaky.has(key(project, file, line, column, title)))
|
|
1219
|
+
continue;
|
|
1220
|
+
errors.push({ tool: "playwright", file: frame?.[1] ?? file ?? "", line: Number(frame?.[2] ?? line), column: Number(frame?.[3] ?? column), severity: "error", message: `${message}${values}`, test: `${project === undefined ? "" : `[${project}] `}${title}` });
|
|
1221
|
+
}
|
|
1222
|
+
return errors;
|
|
1223
|
+
};
|
|
1224
|
+
var collectVitest = (lines, used) => {
|
|
1225
|
+
const errors = [];
|
|
1226
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1227
|
+
const header = VITEST_FAIL.exec(lines[index] ?? "")?.[1];
|
|
1228
|
+
if (header === undefined)
|
|
1229
|
+
continue;
|
|
1230
|
+
let end = index + 1;
|
|
1231
|
+
while (end < lines.length && !(lines[end] ?? "").startsWith("\u23AF") && !VITEST_FAIL.test(lines[end] ?? ""))
|
|
1232
|
+
end++;
|
|
1233
|
+
for (let at = index;at < end; at++)
|
|
1234
|
+
used.add(at);
|
|
1235
|
+
const block = lines.slice(index + 1, end);
|
|
1236
|
+
const frame = block.map((text) => VITEST_FRAME.exec(text)).find((match) => match !== null && !match[1]?.includes("node_modules"));
|
|
1237
|
+
const suite = VITEST_SUITE.exec(header)?.[1];
|
|
1238
|
+
const [file = "", ...names] = (suite ?? header).split(" > ");
|
|
1239
|
+
errors.push({ tool: "vitest", file: frame?.[1] ?? file, line: Number(frame?.[2] ?? 0), column: Number(frame?.[3] ?? 0), severity: "error", message: block.find((text) => text.trim() !== "")?.trim() ?? "failed", ...suite === undefined && names.length > 0 ? { test: names.join(" > ") } : {} });
|
|
1240
|
+
index = end - 1;
|
|
1241
|
+
}
|
|
1242
|
+
return errors;
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
// src/php.ts
|
|
1246
|
+
var PHP_NOISE = [
|
|
1247
|
+
/^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,
|
|
1248
|
+
/^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,
|
|
1249
|
+
/^ -{3,}(?: -{3,})*\s*$/,
|
|
1250
|
+
/^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,
|
|
1251
|
+
/^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,
|
|
1252
|
+
/^(?:Loaded config|PHP runtime:|PHP CS Fixer \d|Running analysis|Parallel runner|Using cache file|Paths from configuration|Rules from configuration|Setting PHP_CS_FIXER|Unable to determine minimum|If you need help|Found \d+ of \d+ files|Checked all files|Fixed \d+ of \d+ files|Legend:)/
|
|
1253
|
+
];
|
|
1254
|
+
var MAX_DIFF_LINES = 6;
|
|
1255
|
+
var PHPUNIT_HEADER = /^There (?:was|were) \d+ ([a-z ]+?)s?:$/i;
|
|
1256
|
+
var PHPUNIT_TRIGGERED = /^\d+ tests? triggered \d+ [\w ]+?s?:$/;
|
|
1257
|
+
var PHPUNIT_END = /^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/;
|
|
1258
|
+
var PHPUNIT_ITEM = /^\d+\) (.*)$/;
|
|
1259
|
+
var PHP_LOCATION = /^([\w./-]+\.php):(\d+)$/;
|
|
1260
|
+
var PHPSTAN_FILE = /^ {2}Line {3}(\S.*)$/;
|
|
1261
|
+
var PHPSTAN_GENERAL = /^ {2}Error\s*$/;
|
|
1262
|
+
var PHPSTAN_MESSAGE = /^ {2}(\S.*)$/;
|
|
1263
|
+
var PHPSTAN_ROW = /^ {2}(\d+|-) +(\S.*)$/;
|
|
1264
|
+
var PHPSTAN_CONTINUATION = /^ {9}(\S.*)$/;
|
|
1265
|
+
var PHPSTAN_IDENTIFIER = /^ {9}\uD83E\uDEAA\s+(\S+)\s*$/;
|
|
1266
|
+
var PHPSTAN_TIP = /^ {9}\uD83D\uDCA1/;
|
|
1267
|
+
var PHPSTAN_BORDER = /^ -{3,}(?: -{3,})*\s*$/;
|
|
1268
|
+
var PHPSTAN_RAW = /^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/;
|
|
1269
|
+
var PHPSTAN_JSON = /^\{.*"totals"/;
|
|
1270
|
+
var CS_FIXER_FILE = /^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/;
|
|
1271
|
+
var CS_FIXER_DIFF_START = /^\s+-+ begin diff -+$/;
|
|
1272
|
+
var CS_FIXER_DIFF_END = /^\s+-+ end diff -+$/;
|
|
1273
|
+
function isHeader(line) {
|
|
1274
|
+
return PHPUNIT_HEADER.test(line) || PHPUNIT_TRIGGERED.test(line);
|
|
1275
|
+
}
|
|
1276
|
+
function diffSummary(message) {
|
|
1277
|
+
const start = message.findIndex((line) => line === "+++ Actual");
|
|
1278
|
+
if (start === -1)
|
|
1279
|
+
return "";
|
|
1280
|
+
const changed = message.slice(start + 1).filter((line) => line.startsWith("-") || line.startsWith("+")).map((line) => `${line[0]} ${line.slice(1).trim()}`);
|
|
1281
|
+
const shown = changed.slice(0, MAX_DIFF_LINES).join(" | ");
|
|
1282
|
+
return changed.length === 0 ? "" : ` (${shown}${changed.length > MAX_DIFF_LINES ? " | ..." : ""})`;
|
|
1283
|
+
}
|
|
1284
|
+
function phpunitError(test, body) {
|
|
1285
|
+
const at = body.findIndex((line) => PHP_LOCATION.test(line));
|
|
1286
|
+
const location = PHP_LOCATION.exec(body[at] ?? "");
|
|
1287
|
+
const message = body.slice(0, at === -1 ? body.length : at).map((line) => line.trimEnd());
|
|
1288
|
+
const first = message.find((line) => line.trim() !== "") ?? "failed";
|
|
1289
|
+
return { tool: "phpunit", file: location?.[1] ?? "", line: Number(location?.[2] ?? 0), column: 0, severity: "error", message: `${first}${diffSummary(message)}`, test };
|
|
1290
|
+
}
|
|
1291
|
+
var collectPhpunit = (lines, used) => {
|
|
1292
|
+
const errors = [];
|
|
1293
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1294
|
+
const line = lines[index] ?? "";
|
|
1295
|
+
const kind = PHPUNIT_HEADER.exec(line)?.[1];
|
|
1296
|
+
if (kind === undefined && !PHPUNIT_TRIGGERED.test(line))
|
|
1297
|
+
continue;
|
|
1298
|
+
let end = index + 1;
|
|
1299
|
+
while (end < lines.length && !PHPUNIT_END.test(lines[end] ?? "") && !isHeader(lines[end] ?? ""))
|
|
1300
|
+
end++;
|
|
1301
|
+
for (let at = index;at < end; at++)
|
|
1302
|
+
used.add(at);
|
|
1303
|
+
if (kind === "error" || kind === "failure") {
|
|
1304
|
+
const starts = Array.from({ length: end - index - 1 }, (_, at) => index + 1 + at).filter((at) => PHPUNIT_ITEM.test(lines[at] ?? ""));
|
|
1305
|
+
for (const [position, start] of starts.entries())
|
|
1306
|
+
errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start] ?? "")?.[1] ?? "", lines.slice(start + 1, starts[position + 1] ?? end)));
|
|
1307
|
+
}
|
|
1308
|
+
index = end - 1;
|
|
1309
|
+
}
|
|
1310
|
+
return errors;
|
|
1311
|
+
};
|
|
1312
|
+
function appendMessage(error, text) {
|
|
1313
|
+
error.message = `${error.message} ${text}`;
|
|
1314
|
+
}
|
|
1315
|
+
function phpstanJson(text) {
|
|
1316
|
+
try {
|
|
1317
|
+
const report = JSON.parse(text);
|
|
1318
|
+
const fromFiles = Object.entries(report.files ?? {}).flatMap(([file, entry]) => entry.messages.map((message) => ({ file, line: message.line ?? 0, message: message.message, ...message.identifier === undefined ? {} : { rule: message.identifier } })));
|
|
1319
|
+
return [...fromFiles, ...(report.errors ?? []).map((message) => ({ file: "", line: 0, message }))];
|
|
1320
|
+
} catch {
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
var collectPhpstan = (lines, used) => {
|
|
1325
|
+
const errors = [];
|
|
1326
|
+
let file;
|
|
1327
|
+
let current;
|
|
1328
|
+
let rows = 0;
|
|
1329
|
+
let tip = false;
|
|
1330
|
+
let general = false;
|
|
1331
|
+
for (const [index, text] of lines.entries()) {
|
|
1332
|
+
const line = text.trimEnd();
|
|
1333
|
+
if (used.has(index))
|
|
1334
|
+
continue;
|
|
1335
|
+
if (PHPSTAN_JSON.test(line)) {
|
|
1336
|
+
const parsed = phpstanJson(line);
|
|
1337
|
+
for (const entry of parsed ?? []) {
|
|
1338
|
+
errors.push({ tool: "phpstan", file: entry.file, line: entry.line, column: 0, severity: "error", message: entry.message, ...entry.rule === undefined ? {} : { rule: entry.rule } });
|
|
1339
|
+
}
|
|
1340
|
+
if (parsed !== undefined)
|
|
1341
|
+
used.add(index);
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
const raw = PHPSTAN_RAW.exec(line);
|
|
1345
|
+
if (raw !== null) {
|
|
1346
|
+
errors.push({ tool: "phpstan", file: raw[1] ?? "", line: Number(raw[2]), column: 0, severity: "error", message: raw[3] ?? "" });
|
|
1347
|
+
used.add(index);
|
|
1348
|
+
continue;
|
|
1349
|
+
}
|
|
1350
|
+
const header = PHPSTAN_FILE.exec(line);
|
|
1351
|
+
if (header !== null || PHPSTAN_GENERAL.test(line)) {
|
|
1352
|
+
file = header?.[1] ?? "";
|
|
1353
|
+
general = header === null;
|
|
1354
|
+
current = undefined;
|
|
1355
|
+
rows = 0;
|
|
1356
|
+
used.add(index);
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (file === undefined)
|
|
1360
|
+
continue;
|
|
1361
|
+
const message = PHPSTAN_MESSAGE.exec(line)?.[1];
|
|
1362
|
+
if (general && message !== undefined && !PHPSTAN_BORDER.test(line)) {
|
|
1363
|
+
errors.push({ tool: "phpstan", file: "", line: 0, column: 0, severity: "error", message });
|
|
1364
|
+
rows++;
|
|
1365
|
+
used.add(index);
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
const row = PHPSTAN_ROW.exec(line);
|
|
1369
|
+
const identifier = PHPSTAN_IDENTIFIER.exec(line)?.[1];
|
|
1370
|
+
const continuation = PHPSTAN_CONTINUATION.exec(line)?.[1];
|
|
1371
|
+
if (PHPSTAN_BORDER.test(line) && rows > 0) {
|
|
1372
|
+
file = undefined;
|
|
1373
|
+
general = false;
|
|
1374
|
+
current = undefined;
|
|
1375
|
+
} else if (row !== null) {
|
|
1376
|
+
current = { tool: "phpstan", file, line: row[1] === "-" ? 0 : Number(row[1]), column: 0, severity: "error", message: row[2] ?? "" };
|
|
1377
|
+
errors.push(current);
|
|
1378
|
+
rows++;
|
|
1379
|
+
tip = false;
|
|
1380
|
+
used.add(index);
|
|
1381
|
+
} else if (identifier !== undefined && current !== undefined) {
|
|
1382
|
+
current.rule = identifier;
|
|
1383
|
+
used.add(index);
|
|
1384
|
+
} else if (PHPSTAN_TIP.test(line)) {
|
|
1385
|
+
tip = true;
|
|
1386
|
+
used.add(index);
|
|
1387
|
+
} else if (continuation !== undefined && current !== undefined) {
|
|
1388
|
+
if (!tip)
|
|
1389
|
+
appendMessage(current, continuation);
|
|
1390
|
+
used.add(index);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
return errors;
|
|
1394
|
+
};
|
|
1395
|
+
var collectCsFixer = (lines, used) => {
|
|
1396
|
+
const errors = [];
|
|
1397
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1398
|
+
const match = CS_FIXER_FILE.exec(lines[index] ?? "");
|
|
1399
|
+
if (match === null)
|
|
1400
|
+
continue;
|
|
1401
|
+
errors.push({ tool: "php-cs-fixer", file: match[1] ?? "", line: 0, column: 0, ...match[2] === undefined ? {} : { rule: match[2] }, severity: "error", message: "style issues to fix" });
|
|
1402
|
+
used.add(index);
|
|
1403
|
+
if (!CS_FIXER_DIFF_START.test(lines[index + 1] ?? ""))
|
|
1404
|
+
continue;
|
|
1405
|
+
const end = lines.findIndex((text, at) => at > index && CS_FIXER_DIFF_END.test(text));
|
|
1406
|
+
for (let at = index + 1;at <= (end === -1 ? index + 1 : end); at++)
|
|
1407
|
+
used.add(at);
|
|
1408
|
+
index = end === -1 ? index + 1 : end;
|
|
1409
|
+
}
|
|
1410
|
+
return errors;
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
// src/output.ts
|
|
1414
|
+
var BASH_ECHO = /^\$ /;
|
|
1415
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1416
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1417
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1418
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1419
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1420
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1421
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1422
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
1423
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1424
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
1425
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1426
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1427
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1428
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1429
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1430
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1431
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1432
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1433
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1434
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1435
|
+
var MAX_TESTS = 10;
|
|
1436
|
+
var MAX_LINES = 100;
|
|
1437
|
+
var TAIL = 30;
|
|
1438
|
+
var bunTest = (lines) => {
|
|
1439
|
+
const seen = new Set;
|
|
1440
|
+
const blocks = [];
|
|
1441
|
+
for (const [index, line] of lines.entries()) {
|
|
1442
|
+
const name = line.replace(DURATION2, "");
|
|
1443
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1444
|
+
continue;
|
|
1445
|
+
seen.add(name);
|
|
1446
|
+
if (blocks.length < MAX_TESTS)
|
|
1447
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1448
|
+
`).trim());
|
|
1449
|
+
}
|
|
1450
|
+
if (blocks.length === 0)
|
|
1451
|
+
return;
|
|
1452
|
+
if (seen.size > MAX_TESTS)
|
|
1453
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1454
|
+
return [...blocks.join(`
|
|
1455
|
+
|
|
1456
|
+
`).split(`
|
|
1457
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1458
|
+
};
|
|
1459
|
+
var bunCheck = (lines) => {
|
|
1460
|
+
const text = lines.join(`
|
|
1461
|
+
`);
|
|
1462
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1463
|
+
if (blocks === null)
|
|
1464
|
+
return;
|
|
1465
|
+
const errors = blocks.map((block) => {
|
|
1466
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1467
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1468
|
+
});
|
|
1469
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1470
|
+
};
|
|
1471
|
+
function bunCheckFields(block) {
|
|
1472
|
+
const attributes = Object.fromEntries([...block.matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1473
|
+
return {
|
|
1474
|
+
file: attributes.file ?? "",
|
|
1475
|
+
line: attributes.line ?? "",
|
|
1476
|
+
column: attributes.column ?? "",
|
|
1477
|
+
code: attributes.code ?? "",
|
|
1478
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1479
|
+
`).slice(1, -1).join(`
|
|
1480
|
+
`).trim()
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
var tsc = (lines) => {
|
|
1484
|
+
const kept = [];
|
|
1485
|
+
let inError = false;
|
|
1486
|
+
for (const line of lines) {
|
|
1487
|
+
if (TSC_ERROR.test(line)) {
|
|
1488
|
+
inError = true;
|
|
1489
|
+
kept.push(line);
|
|
1490
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
1491
|
+
inError = false;
|
|
1492
|
+
kept.push(line);
|
|
1493
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1494
|
+
kept.push(line);
|
|
1495
|
+
} else {
|
|
1496
|
+
inError = false;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1500
|
+
};
|
|
1501
|
+
var eslint = (lines) => {
|
|
1502
|
+
const kept = [];
|
|
1503
|
+
let file = "";
|
|
1504
|
+
let shown = "";
|
|
1505
|
+
for (const line of lines) {
|
|
1506
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
1507
|
+
if (file !== shown) {
|
|
1508
|
+
kept.push(file);
|
|
1509
|
+
shown = file;
|
|
1510
|
+
}
|
|
1511
|
+
kept.push(line);
|
|
1512
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1513
|
+
kept.push(line);
|
|
1514
|
+
} else if (line.trim() !== "") {
|
|
1515
|
+
file = line;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1519
|
+
};
|
|
1520
|
+
var phpstan = (lines) => {
|
|
1521
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1522
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1523
|
+
};
|
|
1524
|
+
var php = (lines) => {
|
|
1525
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1526
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1527
|
+
};
|
|
1528
|
+
var vitest = (lines) => {
|
|
1529
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1530
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1531
|
+
};
|
|
1532
|
+
var playwright = (lines) => {
|
|
1533
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1534
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1535
|
+
};
|
|
1536
|
+
var phpCsFixer = (lines) => {
|
|
1537
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1538
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1539
|
+
};
|
|
1540
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1541
|
+
function squeeze(lines) {
|
|
1542
|
+
const out = [];
|
|
1543
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1544
|
+
if (line !== "" || out.at(-1) !== "")
|
|
1545
|
+
out.push(line);
|
|
1546
|
+
}
|
|
1547
|
+
while (out.at(-1) === "")
|
|
1548
|
+
out.pop();
|
|
1549
|
+
return out;
|
|
1550
|
+
}
|
|
1551
|
+
function failureExcerpt(output) {
|
|
1552
|
+
const lines = stripAnsi(output).split(`
|
|
1553
|
+
`);
|
|
1554
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1555
|
+
lines.shift();
|
|
1556
|
+
const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1557
|
+
const shown = squeeze(parsed ?? lines.slice(-TAIL));
|
|
1558
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1559
|
+
`) : shown.join(`
|
|
1560
|
+
`);
|
|
1561
|
+
}
|
|
1562
|
+
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
1563
|
+
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
1564
|
+
var TSC_SOURCE_LINE = /^\d+ /;
|
|
1565
|
+
var ESLINT_FIELDS = /^ +(\d+):(\d+) +(error|warning) +(\S.*)$/;
|
|
1566
|
+
var ESLINT_RULE = / {2,}(\S+)$/;
|
|
1567
|
+
var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
|
|
1568
|
+
var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
1569
|
+
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1570
|
+
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
1571
|
+
var NOISE = /^(?:bun test v|Errors {2}Files$|Ran \d+ tests?|note: |\s*\d+ expect\(\) calls|\s+\d+\s+\S+:\d+$|\s*\d+ errors? and \d+ warnings? potentially fixable)/;
|
|
1572
|
+
function isNoise(line) {
|
|
1573
|
+
return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
|
|
1574
|
+
}
|
|
1575
|
+
var collectBunCheck = (lines, used) => {
|
|
1576
|
+
const errors = [];
|
|
1577
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1578
|
+
if (!(lines[index] ?? "").startsWith("<error file="))
|
|
1579
|
+
continue;
|
|
1580
|
+
const end = lines.findIndex((line, at) => at >= index && line === "</error>");
|
|
1581
|
+
if (end === -1)
|
|
1582
|
+
break;
|
|
1583
|
+
const { file, line, column, code, message } = bunCheckFields(lines.slice(index, end + 1).join(`
|
|
1584
|
+
`));
|
|
1585
|
+
errors.push({ tool: "bun check", file, line: Number(line), column: Number(column), rule: code, severity: "error", message: message.replaceAll(/\s*\n\s*/g, " ") });
|
|
1586
|
+
for (let at = index;at <= end; at++)
|
|
1587
|
+
used.add(at);
|
|
1588
|
+
index = end;
|
|
1589
|
+
}
|
|
1590
|
+
return errors;
|
|
1591
|
+
};
|
|
1592
|
+
var collectBunTest = (lines, used) => {
|
|
1593
|
+
const errors = [];
|
|
1594
|
+
const seen = new Set;
|
|
1595
|
+
for (const [index, line] of lines.entries()) {
|
|
1596
|
+
if (!line.startsWith("(fail) "))
|
|
1597
|
+
continue;
|
|
1598
|
+
used.add(index);
|
|
1599
|
+
const test = line.slice("(fail) ".length).replace(DURATION2, "");
|
|
1600
|
+
if (seen.has(test))
|
|
1601
|
+
continue;
|
|
1602
|
+
seen.add(test);
|
|
1603
|
+
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1;
|
|
1604
|
+
const block = lines.slice(start, index);
|
|
1605
|
+
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
1606
|
+
for (let at = start;at < index; at++)
|
|
1607
|
+
used.add(at);
|
|
1608
|
+
const frame = block.slice(Math.max(failure, 0)).map((text) => BUN_TEST_FRAME.exec(text)).find((match) => match !== null);
|
|
1609
|
+
const header = lines.slice(0, index).findLast((text) => BUN_TEST_FILE.test(text));
|
|
1610
|
+
const expected = block.map((text) => BUN_TEST_EXPECTED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
1611
|
+
const received = block.map((text) => BUN_TEST_RECEIVED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
1612
|
+
const reason = failure === -1 ? "failed" : (block[failure] ?? "").slice("error:".length).trim();
|
|
1613
|
+
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
1614
|
+
errors.push({
|
|
1615
|
+
tool: "bun test",
|
|
1616
|
+
file: frame?.[1] ?? header?.replace(":", "") ?? "",
|
|
1617
|
+
line: Number(frame?.[2] ?? 0),
|
|
1618
|
+
column: Number(frame?.[3] ?? 0),
|
|
1619
|
+
severity: "error",
|
|
1620
|
+
message: `${reason}${values}`,
|
|
1621
|
+
test
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
return errors;
|
|
1625
|
+
};
|
|
1626
|
+
var collectTsc = (lines, used) => {
|
|
1627
|
+
const errors = [];
|
|
1628
|
+
let current;
|
|
1629
|
+
let pretty = false;
|
|
1630
|
+
for (const [index, line] of lines.entries()) {
|
|
1631
|
+
if (used.has(index))
|
|
1632
|
+
continue;
|
|
1633
|
+
const plain = TSC_PLAIN_ERROR.exec(line);
|
|
1634
|
+
const match = plain ?? TSC_PRETTY_ERROR.exec(line);
|
|
1635
|
+
if (match !== null) {
|
|
1636
|
+
current = { tool: "tsc", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" };
|
|
1637
|
+
pretty = plain === null;
|
|
1638
|
+
errors.push(current);
|
|
1639
|
+
used.add(index);
|
|
1640
|
+
} else if (current !== undefined && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1641
|
+
current.message += ` ${line.trim()}`;
|
|
1642
|
+
used.add(index);
|
|
1643
|
+
} else if (current !== undefined && pretty && (TSC_FRAME.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
1644
|
+
used.add(index);
|
|
1645
|
+
} else if (!(pretty && line.trim() === "")) {
|
|
1646
|
+
current = undefined;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return errors;
|
|
1650
|
+
};
|
|
1651
|
+
var collectEslint = (lines, used) => {
|
|
1652
|
+
const errors = [];
|
|
1653
|
+
let file;
|
|
1654
|
+
for (const [index, line] of lines.entries()) {
|
|
1655
|
+
if (used.has(index))
|
|
1656
|
+
continue;
|
|
1657
|
+
const match = ESLINT_PROBLEM.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
1658
|
+
if (match !== null && file !== undefined) {
|
|
1659
|
+
const text = match[4] ?? "";
|
|
1660
|
+
const rule = ESLINT_RULE.exec(text);
|
|
1661
|
+
errors.push({ tool: "eslint", file: (lines[file] ?? "").trim(), line: Number(match[1]), column: Number(match[2]), rule: rule?.[1], severity: match[3] === "warning" ? "warning" : "error", message: rule === null ? text : text.slice(0, rule.index) });
|
|
1662
|
+
used.add(index);
|
|
1663
|
+
used.add(file);
|
|
1664
|
+
} else if (!isNoise(line)) {
|
|
1665
|
+
file = index;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
return errors;
|
|
1669
|
+
};
|
|
1670
|
+
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectTsc, collectEslint];
|
|
1671
|
+
function parseErrors(output) {
|
|
1672
|
+
const lines = stripAnsi(output).split(`
|
|
1673
|
+
`);
|
|
1674
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1675
|
+
lines.shift();
|
|
1676
|
+
const used = new Set;
|
|
1677
|
+
const errors = COLLECTORS.flatMap((collect) => collect(lines, used));
|
|
1678
|
+
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
1679
|
+
return { errors, unrecognised };
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// src/run.ts
|
|
1683
|
+
import { mkdir as mkdir2, writeFile } from "fs/promises";
|
|
1684
|
+
import { basename as basename2, join as join3 } from "path";
|
|
1685
|
+
import process9 from "process";
|
|
1686
|
+
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
1687
|
+
async function logDirectory(cwd) {
|
|
1688
|
+
const root = await privateLogDirectory("check");
|
|
1689
|
+
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
1690
|
+
const path = join3(root, `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-${Date.now().toString(36)}-${process9.pid}`);
|
|
1691
|
+
await mkdir2(path, { mode: 448 });
|
|
1692
|
+
return path;
|
|
1693
|
+
}
|
|
1694
|
+
async function saveLog(output) {
|
|
1695
|
+
const root = await privateLogDirectory("errs");
|
|
1696
|
+
await sweepLogs(root);
|
|
1697
|
+
const path = join3(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process9.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
1698
|
+
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
1699
|
+
return path;
|
|
1700
|
+
}
|
|
1701
|
+
async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}) {
|
|
1702
|
+
const started = Date.now();
|
|
1703
|
+
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
1704
|
+
cwd,
|
|
1705
|
+
env: { ...process9.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
1706
|
+
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
1707
|
+
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
1708
|
+
});
|
|
1709
|
+
const output = stripAnsi(text);
|
|
1710
|
+
await writeFile(logFile, output, { mode: 384, flag: "wx" });
|
|
1711
|
+
return { ok: code === 0, ms: Date.now() - started, output, ...timedOut ? { timedOut } : {} };
|
|
1712
|
+
}
|
|
1713
|
+
async function refusedStep(reason, logFile) {
|
|
1714
|
+
await writeFile(logFile, reason, { mode: 384, flag: "wx" });
|
|
1715
|
+
return { ok: false, ms: 0, output: reason };
|
|
1716
|
+
}
|
|
1717
|
+
function outcomeJson(name, command, logFile, outcome, service) {
|
|
1718
|
+
return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
|
|
1719
|
+
}
|
|
1720
|
+
function printOutcome(name, width, command, logFile, outcome) {
|
|
1721
|
+
if (outcome.ok) {
|
|
1722
|
+
console.log(`ok ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${logFile}`);
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
const label = outcome.timedOut === true ? "TIME " : "FAIL ";
|
|
1726
|
+
console.log(`${label} ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${command} ${logFile}`);
|
|
1727
|
+
if (outcome.timedOut === true)
|
|
1728
|
+
console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
|
|
1729
|
+
console.log(failureExcerpt(outcome.output).split(`
|
|
1730
|
+
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
1731
|
+
`));
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// src/errs.ts
|
|
1735
|
+
var usage = `errs [options] [log]
|
|
1736
|
+
errs [options] -- <command> [args...]
|
|
1737
|
+
errs --in <service> | --host -- <command> [args...]
|
|
1738
|
+
|
|
1739
|
+
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json) or php-cs-fixer log, read from the file given, from stdin (no argument or -), or from the output of the command run after --.
|
|
1740
|
+
The lines no format recognised are counted on stderr, never dropped silently, and a command's full output is saved to a log file whose path is printed with that count.
|
|
1741
|
+
A command runs inside the docker compose service that bind-mounts the current folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path, with its output read here; a service that is down is never started, the call fails naming it. --in picks the service, --host forces the host.
|
|
1742
|
+
Exits 0 when no error was found and the command, if any, passed, 1 when errors were found or the command failed, 2 on a usage error.
|
|
1743
|
+
--json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer.`;
|
|
1744
|
+
var options = {
|
|
1745
|
+
...placeOptions,
|
|
1746
|
+
json: jsonOption()
|
|
1747
|
+
};
|
|
1748
|
+
function display(file, cwd) {
|
|
1749
|
+
const path = file.startsWith("/") ? relative2(cwd, file) : file;
|
|
1750
|
+
return path.startsWith("..") ? file : path;
|
|
1751
|
+
}
|
|
1752
|
+
function formatError(error, cwd) {
|
|
1753
|
+
const where = `${display(error.file, cwd)}:${error.line}:${error.column}`;
|
|
1754
|
+
const label = error.test === undefined ? "" : `${error.test}: `;
|
|
1755
|
+
const level = error.severity === "warning" ? "warning: " : "";
|
|
1756
|
+
const rule = error.rule === undefined ? "" : ` (${error.rule})`;
|
|
1757
|
+
return `${where}: ${level}${label}${error.message}${rule}`;
|
|
1758
|
+
}
|
|
1759
|
+
async function readInput2(command, run, settings, cwd) {
|
|
1760
|
+
const [path] = command;
|
|
1761
|
+
if (!run && (settings.service !== undefined || settings.host === true))
|
|
1762
|
+
fail("--in and --host apply to a command run after --");
|
|
1763
|
+
if (!run && (path === undefined || path === "-"))
|
|
1764
|
+
return { text: await readInput("-", { noStdin: "give a log, a command after --, or pipe the output on stdin" }) };
|
|
1765
|
+
if (!run && path !== undefined)
|
|
1766
|
+
return { text: await readInput(path), log: path };
|
|
1767
|
+
if (path === undefined)
|
|
1768
|
+
fail("give the command after --");
|
|
1769
|
+
const placement = await place(cwd, path, settings);
|
|
1770
|
+
const down = placement === undefined ? undefined : await new Stack().problem(placement);
|
|
1771
|
+
if (down !== undefined)
|
|
1772
|
+
fail(down, 1);
|
|
1773
|
+
const held = holdSignals();
|
|
1774
|
+
let ran;
|
|
1775
|
+
try {
|
|
1776
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process10.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
1777
|
+
} catch (error) {
|
|
1778
|
+
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1779
|
+
} finally {
|
|
1780
|
+
held.release();
|
|
1781
|
+
}
|
|
1782
|
+
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
1783
|
+
}
|
|
1784
|
+
async function errs(args, cwd = process10.cwd()) {
|
|
1785
|
+
const first = args[0];
|
|
1786
|
+
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
1787
|
+
const parsed = parse(bare ? [] : args, usage, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
1788
|
+
if (parsed.positionals.length > 1)
|
|
1789
|
+
fail(`give one log, or a command after --
|
|
1790
|
+
|
|
1791
|
+
${usage}`);
|
|
1792
|
+
const input = await readInput2(bare ? args : parsed.rest ?? parsed.positionals, bare || parsed.rest !== undefined, placeSettings(parsed.values), cwd);
|
|
1793
|
+
const { errors, unrecognised } = parseErrors(input.text);
|
|
1794
|
+
if (parsed.values.json === true) {
|
|
1795
|
+
printJson({ errors, unrecognised, ...input.log === undefined ? {} : { log: input.log }, ...input.code === undefined ? {} : { code: input.code } });
|
|
1796
|
+
} else {
|
|
1797
|
+
for (const error of errors)
|
|
1798
|
+
console.log(formatError(error, cwd));
|
|
1799
|
+
if (unrecognised > 0)
|
|
1800
|
+
warn(`${unrecognised} ${unrecognised === 1 ? "line" : "lines"} not recognised`, input.log === undefined ? undefined : `see ${input.log}`);
|
|
1801
|
+
if (errors.length === 0 && input.code !== undefined && input.code !== 0)
|
|
1802
|
+
warn(`the command exited ${input.code} with no error recognised`, input.log === undefined ? undefined : `see ${input.log}`);
|
|
1803
|
+
}
|
|
1804
|
+
return errors.length > 0 || (input.code ?? 0) !== 0 ? 1 : 0;
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
// src/errs-cli.ts
|
|
1808
|
+
process11.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|