@kaynooo/cli-check 0.0.0-stage → 0.9.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 +2150 -0
- package/dist/errs-cli.js +2010 -0
- package/dist/fix-cli.js +2374 -0
- package/package.json +32 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2150 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/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.2+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.2+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
|
+
positionals;
|
|
437
|
+
candidates;
|
|
438
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
439
|
+
this.options = options;
|
|
440
|
+
this.positionals = positionals;
|
|
441
|
+
this.candidates = candidates;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
var completion = { active: false };
|
|
445
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
446
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
447
|
+
var FULL_STOP = /\.$/;
|
|
448
|
+
var DASHES = /^-+/;
|
|
449
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
450
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
451
|
+
}
|
|
452
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
453
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
454
|
+
`);
|
|
455
|
+
}
|
|
456
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
457
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
458
|
+
}
|
|
459
|
+
function wantsHelpJson(env = process3.env) {
|
|
460
|
+
return env.KIT_HELP === "json";
|
|
461
|
+
}
|
|
462
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
463
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
464
|
+
`);
|
|
465
|
+
const first = lines[0];
|
|
466
|
+
const colon = first.indexOf(": ");
|
|
467
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
468
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
469
|
+
return {
|
|
470
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
471
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
472
|
+
...replaces === undefined ? {} : { replaces },
|
|
473
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
477
|
+
if (examples.length === 0)
|
|
478
|
+
return [];
|
|
479
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
480
|
+
}
|
|
481
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
482
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
483
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
484
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
485
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
486
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
487
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
488
|
+
});
|
|
489
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
490
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
491
|
+
}
|
|
492
|
+
var OUTPUT_OPTIONS = {
|
|
493
|
+
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
494
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
495
|
+
};
|
|
496
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
497
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
498
|
+
if (when === "auto")
|
|
499
|
+
return;
|
|
500
|
+
if (when !== "always" && when !== "never")
|
|
501
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
502
|
+
if (when === "always") {
|
|
503
|
+
env.FORCE_COLOR = "1";
|
|
504
|
+
delete env.NO_COLOR;
|
|
505
|
+
} else {
|
|
506
|
+
env.NO_COLOR = "1";
|
|
507
|
+
delete env.FORCE_COLOR;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function parse(args, usage, options, settings = {}) {
|
|
511
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
512
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
513
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
514
|
+
if (completion.active)
|
|
515
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
516
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
517
|
+
let parsed;
|
|
518
|
+
try {
|
|
519
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
520
|
+
} catch (error) {
|
|
521
|
+
const message = parseError(error);
|
|
522
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
523
|
+
}
|
|
524
|
+
const values = parsed.values;
|
|
525
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
526
|
+
if (values.help === true) {
|
|
527
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
528
|
+
throw new HelpShown;
|
|
529
|
+
}
|
|
530
|
+
checkChoices(parsed.values, all);
|
|
531
|
+
checkConflicts(parsed.values, all);
|
|
532
|
+
if (settings.positionals !== undefined)
|
|
533
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
534
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
535
|
+
}
|
|
536
|
+
function splitRest(args, passes) {
|
|
537
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
538
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
539
|
+
}
|
|
540
|
+
function splitTrailing(args, options, count) {
|
|
541
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
542
|
+
let seen = 0;
|
|
543
|
+
if (count === 0)
|
|
544
|
+
return { own: args, rest: undefined };
|
|
545
|
+
for (let at = 0;at < args.length; at++) {
|
|
546
|
+
const word = args[at];
|
|
547
|
+
if (word === "--")
|
|
548
|
+
break;
|
|
549
|
+
if (word.startsWith("-")) {
|
|
550
|
+
if (takesValue(word))
|
|
551
|
+
at++;
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
seen++;
|
|
555
|
+
if (seen === count)
|
|
556
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
557
|
+
}
|
|
558
|
+
return { own: args, rest: undefined };
|
|
559
|
+
}
|
|
560
|
+
function listed(options, allowNegative) {
|
|
561
|
+
if (!allowNegative)
|
|
562
|
+
return options;
|
|
563
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
564
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
565
|
+
return [[name, option]];
|
|
566
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
function withBare(args, options) {
|
|
570
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
571
|
+
if (bare.size === 0)
|
|
572
|
+
return args;
|
|
573
|
+
const separator = args.indexOf("--");
|
|
574
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
575
|
+
return [...own.flatMap((arg, index) => {
|
|
576
|
+
const optional = bare.get(arg);
|
|
577
|
+
const next = own[index + 1];
|
|
578
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
579
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
580
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
581
|
+
}
|
|
582
|
+
function checkConflicts(values, options) {
|
|
583
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
584
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
585
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
586
|
+
if (other !== undefined)
|
|
587
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function checkChoices(values, options) {
|
|
591
|
+
for (const [name, option] of Object.entries(options)) {
|
|
592
|
+
if (option.choices === undefined)
|
|
593
|
+
continue;
|
|
594
|
+
const given = values[name];
|
|
595
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
596
|
+
if (typeof value === "string")
|
|
597
|
+
oneOf(value, name, option.choices);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function oneOf(value, name, choices) {
|
|
602
|
+
if (!choices.includes(value))
|
|
603
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
604
|
+
return value;
|
|
605
|
+
}
|
|
606
|
+
function checkPositionals(given, names) {
|
|
607
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
608
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
609
|
+
if (given.length < required)
|
|
610
|
+
badUsage(`missing ${names[given.length]}`);
|
|
611
|
+
if (!variadic && given.length > names.length)
|
|
612
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
613
|
+
}
|
|
614
|
+
function joinDashValues(args, options) {
|
|
615
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
616
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
617
|
+
const joined = [];
|
|
618
|
+
for (let i = 0;i < args.length; i++) {
|
|
619
|
+
const arg = args[i] ?? "";
|
|
620
|
+
if (arg === "--")
|
|
621
|
+
return [...joined, ...args.slice(i)];
|
|
622
|
+
const name = longOf.get(arg);
|
|
623
|
+
const next = args[i + 1];
|
|
624
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
625
|
+
joined.push(`--${name}=${next}`);
|
|
626
|
+
i++;
|
|
627
|
+
} else {
|
|
628
|
+
joined.push(arg);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return joined;
|
|
632
|
+
}
|
|
633
|
+
function parseError(error) {
|
|
634
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
635
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
636
|
+
}
|
|
637
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
638
|
+
function nearestOption(message, options, allowNegative) {
|
|
639
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
640
|
+
if (typed === undefined)
|
|
641
|
+
return;
|
|
642
|
+
const word = typed.replace(DASHES, "");
|
|
643
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
644
|
+
return;
|
|
645
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
646
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
647
|
+
`--${name}`,
|
|
648
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
649
|
+
]);
|
|
650
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
651
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
652
|
+
}
|
|
653
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
654
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
655
|
+
function duration(value, name, fallback, unit = "s") {
|
|
656
|
+
if (value === undefined)
|
|
657
|
+
return fallback;
|
|
658
|
+
const match = DURATION.exec(value.trim());
|
|
659
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
660
|
+
if (ms < 1)
|
|
661
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
|
+
return ms;
|
|
663
|
+
}
|
|
664
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
665
|
+
if (path === "-") {
|
|
666
|
+
if (process3.stdin.isTTY)
|
|
667
|
+
fail(noStdin);
|
|
668
|
+
return Bun.stdin.text();
|
|
669
|
+
}
|
|
670
|
+
const file = Bun.file(path);
|
|
671
|
+
if (!await file.exists())
|
|
672
|
+
fail(`no file ${path}`);
|
|
673
|
+
return file.text();
|
|
674
|
+
}
|
|
675
|
+
// ../kit/src/process.ts
|
|
676
|
+
import { constants } from "os";
|
|
677
|
+
import process4 from "process";
|
|
678
|
+
var KILL_GRACE_MS = 2000;
|
|
679
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
680
|
+
function exitCodeOf(code, signal) {
|
|
681
|
+
if (code !== null)
|
|
682
|
+
return code;
|
|
683
|
+
if (typeof signal === "number")
|
|
684
|
+
return 128 + signal;
|
|
685
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
686
|
+
}
|
|
687
|
+
function holdSignals(cleanup) {
|
|
688
|
+
let received;
|
|
689
|
+
let child;
|
|
690
|
+
const held = {
|
|
691
|
+
get signal() {
|
|
692
|
+
return received;
|
|
693
|
+
},
|
|
694
|
+
forward: (to) => {
|
|
695
|
+
child = to;
|
|
696
|
+
},
|
|
697
|
+
release: () => {
|
|
698
|
+
for (const signal of SIGNALS)
|
|
699
|
+
process4.off(signal, onSignal);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
function onSignal(signal) {
|
|
703
|
+
received = signal;
|
|
704
|
+
if (child !== undefined) {
|
|
705
|
+
child.kill(signal);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (cleanup === undefined)
|
|
709
|
+
return;
|
|
710
|
+
held.release();
|
|
711
|
+
cleanup(signal);
|
|
712
|
+
process4.kill(process4.pid, signal);
|
|
713
|
+
}
|
|
714
|
+
for (const signal of SIGNALS)
|
|
715
|
+
process4.on(signal, onSignal);
|
|
716
|
+
return held;
|
|
717
|
+
}
|
|
718
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
719
|
+
const chunks = [];
|
|
720
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
721
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
722
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
723
|
+
const timers = [];
|
|
724
|
+
const killGroup = (killing) => {
|
|
725
|
+
if (state.done)
|
|
726
|
+
return;
|
|
727
|
+
try {
|
|
728
|
+
if (grouped)
|
|
729
|
+
process4.kill(-proc.pid, killing);
|
|
730
|
+
else
|
|
731
|
+
proc.kill(killing);
|
|
732
|
+
} catch {}
|
|
733
|
+
};
|
|
734
|
+
const stop = () => {
|
|
735
|
+
killGroup("SIGTERM");
|
|
736
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
737
|
+
};
|
|
738
|
+
const onAbort = () => stop();
|
|
739
|
+
if (timeoutMs !== undefined) {
|
|
740
|
+
timers.push(setTimeout(() => {
|
|
741
|
+
state.timedOut = true;
|
|
742
|
+
stop();
|
|
743
|
+
}, timeoutMs));
|
|
744
|
+
}
|
|
745
|
+
if (signal?.aborted === true)
|
|
746
|
+
onAbort();
|
|
747
|
+
else
|
|
748
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
749
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
750
|
+
const drain = async (stream, name) => {
|
|
751
|
+
for await (const data of stream) {
|
|
752
|
+
if (state.failure !== undefined)
|
|
753
|
+
continue;
|
|
754
|
+
try {
|
|
755
|
+
onChunk?.({ stream: name, data });
|
|
756
|
+
} catch (error) {
|
|
757
|
+
state.failure = error;
|
|
758
|
+
stop();
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (state.kept + data.length > maxBytes) {
|
|
762
|
+
state.truncated = true;
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
state.kept += data.length;
|
|
766
|
+
chunks.push({ stream: name, data });
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
try {
|
|
770
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
771
|
+
await proc.exited;
|
|
772
|
+
} finally {
|
|
773
|
+
state.done = true;
|
|
774
|
+
for (const timer of timers)
|
|
775
|
+
clearTimeout(timer);
|
|
776
|
+
signal?.removeEventListener("abort", onAbort);
|
|
777
|
+
}
|
|
778
|
+
if (state.failure !== undefined)
|
|
779
|
+
throw state.failure;
|
|
780
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
781
|
+
let output;
|
|
782
|
+
let text;
|
|
783
|
+
return {
|
|
784
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
785
|
+
chunks,
|
|
786
|
+
timedOut: state.timedOut,
|
|
787
|
+
truncated: state.truncated,
|
|
788
|
+
get output() {
|
|
789
|
+
return output ??= joined();
|
|
790
|
+
},
|
|
791
|
+
get text() {
|
|
792
|
+
return text ??= (output ??= joined()).toString();
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// ../kit/src/progress.ts
|
|
798
|
+
var ESC = String.fromCharCode(27);
|
|
799
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
800
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
801
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
802
|
+
// ../kit/src/cli.ts
|
|
803
|
+
import process5 from "process";
|
|
804
|
+
var LEVEL_OPTIONS = {
|
|
805
|
+
...OUTPUT_OPTIONS,
|
|
806
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
807
|
+
};
|
|
808
|
+
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
809
|
+
function printError(prefix, message, hint, cause) {
|
|
810
|
+
const colors = paint(process5.stderr);
|
|
811
|
+
const styled = takesControlCodes(process5.stderr);
|
|
812
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
813
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
814
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
815
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
816
|
+
}
|
|
817
|
+
function printJsonError(message, hint, cause) {
|
|
818
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
819
|
+
}
|
|
820
|
+
function wantsJson(argv) {
|
|
821
|
+
const end = argv.indexOf("--");
|
|
822
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
823
|
+
}
|
|
824
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
825
|
+
if (error instanceof HelpShown)
|
|
826
|
+
return 0;
|
|
827
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
828
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
829
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
830
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
831
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
832
|
+
return error instanceof Exit ? error.code : 1;
|
|
833
|
+
}
|
|
834
|
+
var COMPLETE = "__complete";
|
|
835
|
+
var FILES = "__files__";
|
|
836
|
+
async function completingOf(run) {
|
|
837
|
+
completion.active = true;
|
|
838
|
+
try {
|
|
839
|
+
await run([]);
|
|
840
|
+
} catch (error) {
|
|
841
|
+
if (error instanceof Completing)
|
|
842
|
+
return error;
|
|
843
|
+
} finally {
|
|
844
|
+
completion.active = false;
|
|
845
|
+
}
|
|
846
|
+
return new Completing({});
|
|
847
|
+
}
|
|
848
|
+
function candidateLine(candidate) {
|
|
849
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
850
|
+
}
|
|
851
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
852
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
853
|
+
let index = 0;
|
|
854
|
+
let at = 0;
|
|
855
|
+
while (at < before.length) {
|
|
856
|
+
const word = before[at];
|
|
857
|
+
if (word === "--") {
|
|
858
|
+
index += before.length - at - 1;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
if (!word.startsWith("-"))
|
|
862
|
+
index++;
|
|
863
|
+
else if (takesValue(word))
|
|
864
|
+
at++;
|
|
865
|
+
at++;
|
|
866
|
+
}
|
|
867
|
+
const last = positionals.at(-1);
|
|
868
|
+
if (index < positionals.length)
|
|
869
|
+
return positionals[index];
|
|
870
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
871
|
+
}
|
|
872
|
+
async function leafCandidates(run, words) {
|
|
873
|
+
const completing = await completingOf(run);
|
|
874
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
875
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
876
|
+
const flag = words.at(-2);
|
|
877
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
878
|
+
if (option?.type === "string") {
|
|
879
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
880
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
881
|
+
}
|
|
882
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
883
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
884
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
885
|
+
}
|
|
886
|
+
async function printCandidates(found) {
|
|
887
|
+
for (const line of await found)
|
|
888
|
+
console.log(line);
|
|
889
|
+
return 0;
|
|
890
|
+
}
|
|
891
|
+
async function runMain({ name, version, run, redact }, argv = process5.argv.slice(2)) {
|
|
892
|
+
if (argv[0] === COMPLETE)
|
|
893
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
894
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
895
|
+
console.log(version);
|
|
896
|
+
return 0;
|
|
897
|
+
}
|
|
898
|
+
try {
|
|
899
|
+
return await run(argv);
|
|
900
|
+
} catch (error) {
|
|
901
|
+
return reportThrown(name, error, redact, wantsJson(argv));
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
// ../kit/src/logs.ts
|
|
905
|
+
import { lstatSync, openSync } from "fs";
|
|
906
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
907
|
+
import { homedir, tmpdir } from "os";
|
|
908
|
+
import { join } from "path";
|
|
909
|
+
import process6 from "process";
|
|
910
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
911
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
912
|
+
function isPrivateDirectory(path) {
|
|
913
|
+
try {
|
|
914
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
915
|
+
return info !== undefined && info.isDirectory() && info.uid === (process6.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
916
|
+
} catch {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
async function privateLogDirectory(name, env = process6.env) {
|
|
921
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
922
|
+
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
923
|
+
const path = join(base, name);
|
|
924
|
+
try {
|
|
925
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
926
|
+
if (isPrivateDirectory(path))
|
|
927
|
+
return path;
|
|
928
|
+
} catch {}
|
|
929
|
+
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
930
|
+
}
|
|
931
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
932
|
+
let names;
|
|
933
|
+
try {
|
|
934
|
+
names = await readdir(dir);
|
|
935
|
+
} catch {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
for (const name of names) {
|
|
939
|
+
const path = join(dir, name);
|
|
940
|
+
try {
|
|
941
|
+
const info = await stat(path);
|
|
942
|
+
if (info.isDirectory())
|
|
943
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
944
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
945
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
946
|
+
} catch {
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
// ../kit/src/secrets.ts
|
|
952
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
953
|
+
// ../kit/src/sessions.ts
|
|
954
|
+
var {Glob } = globalThis.Bun;
|
|
955
|
+
var SESSION_FILES = new Glob("*.json");
|
|
956
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
957
|
+
// package.json
|
|
958
|
+
var version = "0.9.0";
|
|
959
|
+
|
|
960
|
+
// src/check.ts
|
|
961
|
+
import { join as join5 } from "path";
|
|
962
|
+
import process10 from "process";
|
|
963
|
+
|
|
964
|
+
// ../kit/src/shell.ts
|
|
965
|
+
var SEPARATORS = new Set([`
|
|
966
|
+
`, ";", "|"]);
|
|
967
|
+
var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
|
|
968
|
+
var GLOB_CHARS = new Set(["*", "?", "["]);
|
|
969
|
+
var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
970
|
+
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
971
|
+
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
972
|
+
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
973
|
+
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh"]);
|
|
974
|
+
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, "su", "runuser"]);
|
|
975
|
+
var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
976
|
+
var PRINTERS = new Set(["echo", "printf"]);
|
|
977
|
+
var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
978
|
+
function wrapper(short = "", long = [], operands = 0) {
|
|
979
|
+
return { short, long, operands };
|
|
980
|
+
}
|
|
981
|
+
var WRAPPERS = new Map([
|
|
982
|
+
["command", wrapper()],
|
|
983
|
+
["builtin", wrapper()],
|
|
984
|
+
["nohup", wrapper()],
|
|
985
|
+
["setsid", wrapper()],
|
|
986
|
+
["busybox", wrapper()],
|
|
987
|
+
["exec", wrapper("a")],
|
|
988
|
+
["time", wrapper("fo", ["--format", "--output"])],
|
|
989
|
+
["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
|
|
990
|
+
["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
|
|
991
|
+
["doas", wrapper("uC")],
|
|
992
|
+
["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
|
|
993
|
+
["nice", wrapper("n", ["--adjustment"])],
|
|
994
|
+
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
995
|
+
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
996
|
+
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
997
|
+
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
|
|
998
|
+
]);
|
|
999
|
+
function shellQuote(word) {
|
|
1000
|
+
return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// src/compose.ts
|
|
1004
|
+
import { existsSync } from "fs";
|
|
1005
|
+
import { homedir as homedir2 } from "os";
|
|
1006
|
+
import { basename, dirname, join as join2, relative, resolve } from "path";
|
|
1007
|
+
import process8 from "process";
|
|
1008
|
+
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1009
|
+
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1010
|
+
var PS_TIMEOUT_MS = 20000;
|
|
1011
|
+
var VARIABLE = /\$\{(\w+)(?::?-([^${}]*))?\}|\$(\w+)/g;
|
|
1012
|
+
var ENV_LINE = /^\s*(?:export\s+)?(\w+)=(.*)$/;
|
|
1013
|
+
var QUOTED = /^(['"])(.*)\1$/;
|
|
1014
|
+
var TOOL_WORDS = {
|
|
1015
|
+
bun: ["bun"],
|
|
1016
|
+
bunx: ["bun"],
|
|
1017
|
+
node: ["node", "bun"],
|
|
1018
|
+
npm: ["node", "bun"],
|
|
1019
|
+
npx: ["node", "bun"],
|
|
1020
|
+
pnpm: ["node", "bun"],
|
|
1021
|
+
yarn: ["node", "bun"],
|
|
1022
|
+
composer: ["php"],
|
|
1023
|
+
php: ["php"],
|
|
1024
|
+
phpunit: ["php"],
|
|
1025
|
+
phpstan: ["php"],
|
|
1026
|
+
paratest: ["php"],
|
|
1027
|
+
pest: ["php"],
|
|
1028
|
+
symfony: ["php"]
|
|
1029
|
+
};
|
|
1030
|
+
function toolWords(program) {
|
|
1031
|
+
const name = basename(program);
|
|
1032
|
+
return TOOL_WORDS[name] ?? (program.includes("vendor/bin/") ? ["php"] : []);
|
|
1033
|
+
}
|
|
1034
|
+
async function readFiles(dir, names) {
|
|
1035
|
+
for (const name of names) {
|
|
1036
|
+
const handle = Bun.file(join2(dir, name));
|
|
1037
|
+
if (await handle.exists())
|
|
1038
|
+
return { name, text: await handle.text() };
|
|
1039
|
+
}
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
async function variables(composeDir) {
|
|
1043
|
+
const env = {};
|
|
1044
|
+
const text = (await readFiles(composeDir, [".env"]))?.text ?? "";
|
|
1045
|
+
for (const line of text.split(`
|
|
1046
|
+
`)) {
|
|
1047
|
+
const match = ENV_LINE.exec(line);
|
|
1048
|
+
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1049
|
+
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1050
|
+
}
|
|
1051
|
+
for (const [key, value] of Object.entries(process8.env)) {
|
|
1052
|
+
if (value !== undefined)
|
|
1053
|
+
env[key] = value;
|
|
1054
|
+
}
|
|
1055
|
+
env.PWD = composeDir;
|
|
1056
|
+
return env;
|
|
1057
|
+
}
|
|
1058
|
+
function interpolate(text, env) {
|
|
1059
|
+
let current = text;
|
|
1060
|
+
for (let round = 0;round < 4 && current.includes("$"); round++) {
|
|
1061
|
+
current = current.replaceAll(VARIABLE, (_, braced, fallback, bare) => {
|
|
1062
|
+
const value = env[braced ?? bare ?? ""];
|
|
1063
|
+
return value !== undefined && value !== "" ? value : fallback ?? "";
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
return current;
|
|
1067
|
+
}
|
|
1068
|
+
function bindSource(source, composeDir, env) {
|
|
1069
|
+
const path = interpolate(source, env);
|
|
1070
|
+
if (path.startsWith("~"))
|
|
1071
|
+
return join2(homedir2(), path.slice(1));
|
|
1072
|
+
if (path.startsWith("/"))
|
|
1073
|
+
return resolve(path);
|
|
1074
|
+
return path.startsWith(".") ? resolve(composeDir, path) : undefined;
|
|
1075
|
+
}
|
|
1076
|
+
function mountsOf(volumes, composeDir, env) {
|
|
1077
|
+
if (!Array.isArray(volumes))
|
|
1078
|
+
return [];
|
|
1079
|
+
const mounts = [];
|
|
1080
|
+
for (const volume of volumes) {
|
|
1081
|
+
let source;
|
|
1082
|
+
let target;
|
|
1083
|
+
if (typeof volume === "string") {
|
|
1084
|
+
[source, target] = interpolate(volume, env).split(":");
|
|
1085
|
+
} else if (typeof volume === "object" && volume !== null) {
|
|
1086
|
+
const object = volume;
|
|
1087
|
+
if (object.type === "bind" && typeof object.source === "string" && typeof object.target === "string")
|
|
1088
|
+
({ source, target } = object);
|
|
1089
|
+
}
|
|
1090
|
+
const resolved = source === undefined ? undefined : bindSource(source, composeDir, env);
|
|
1091
|
+
if (resolved !== undefined && target?.startsWith("/") === true)
|
|
1092
|
+
mounts.push({ source: resolved, target });
|
|
1093
|
+
}
|
|
1094
|
+
return mounts;
|
|
1095
|
+
}
|
|
1096
|
+
function buildText(build) {
|
|
1097
|
+
if (typeof build === "string")
|
|
1098
|
+
return build;
|
|
1099
|
+
return typeof build === "object" && build !== null ? Object.values(build).filter((value) => typeof value === "string").join(" ") : "";
|
|
1100
|
+
}
|
|
1101
|
+
function parseServices(text, composeDir, env) {
|
|
1102
|
+
const services = new Map;
|
|
1103
|
+
const parsed = Bun.YAML.parse(text);
|
|
1104
|
+
for (const [name, service] of Object.entries(parsed?.services ?? {})) {
|
|
1105
|
+
if (service !== null && typeof service === "object")
|
|
1106
|
+
services.set(name, { ...service, mounts: mountsOf(service.volumes, composeDir, env) });
|
|
1107
|
+
}
|
|
1108
|
+
return services;
|
|
1109
|
+
}
|
|
1110
|
+
async function composeFiles(composeDir, env) {
|
|
1111
|
+
const listed = env.COMPOSE_FILE;
|
|
1112
|
+
if (listed !== undefined && listed !== "") {
|
|
1113
|
+
const files = [];
|
|
1114
|
+
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1115
|
+
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1116
|
+
const file = Bun.file(resolve(composeDir, name));
|
|
1117
|
+
if (!await file.exists())
|
|
1118
|
+
fail(`COMPOSE_FILE names ${join2(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1119
|
+
files.push({ name, text: await file.text() });
|
|
1120
|
+
}
|
|
1121
|
+
return files;
|
|
1122
|
+
}
|
|
1123
|
+
const base = await readFiles(composeDir, COMPOSE_FILES);
|
|
1124
|
+
if (base === undefined)
|
|
1125
|
+
return [];
|
|
1126
|
+
const override = await readFiles(composeDir, OVERRIDE_FILES);
|
|
1127
|
+
return override === undefined ? [base] : [base, override];
|
|
1128
|
+
}
|
|
1129
|
+
async function readServices(composeDir) {
|
|
1130
|
+
const env = await variables(composeDir);
|
|
1131
|
+
const files = await composeFiles(composeDir, env);
|
|
1132
|
+
if (files.length === 0)
|
|
1133
|
+
return;
|
|
1134
|
+
const services = new Map;
|
|
1135
|
+
for (const file of files) {
|
|
1136
|
+
let parsed;
|
|
1137
|
+
try {
|
|
1138
|
+
parsed = parseServices(file.text, composeDir, env);
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
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");
|
|
1141
|
+
}
|
|
1142
|
+
for (const [name, extra] of parsed) {
|
|
1143
|
+
const known = services.get(name);
|
|
1144
|
+
services.set(name, known === undefined ? extra : { ...known, ...extra, mounts: [...known.mounts, ...extra.mounts], image: extra.image ?? known.image, build: extra.build ?? known.build });
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return [...services].map(([name, service]) => ({ name, mounts: service.mounts, profile: `${name} ${typeof service.image === "string" ? service.image : ""} ${buildText(service.build)}`.toLowerCase() }));
|
|
1148
|
+
}
|
|
1149
|
+
function climb(dir) {
|
|
1150
|
+
const folders = [dir];
|
|
1151
|
+
let current = dir;
|
|
1152
|
+
while (!existsSync(join2(current, ".git")) && dirname(current) !== current) {
|
|
1153
|
+
current = dirname(current);
|
|
1154
|
+
folders.push(current);
|
|
1155
|
+
}
|
|
1156
|
+
return existsSync(join2(current, ".git")) ? folders : [dir];
|
|
1157
|
+
}
|
|
1158
|
+
function containerPath(service, dir) {
|
|
1159
|
+
const holding = service.mounts.filter((mount) => {
|
|
1160
|
+
const inside = relative(mount.source, dir);
|
|
1161
|
+
return !inside.startsWith("..") && !inside.startsWith("/");
|
|
1162
|
+
});
|
|
1163
|
+
const deepest = holding.toSorted((a, b) => b.source.length - a.source.length)[0];
|
|
1164
|
+
if (deepest === undefined)
|
|
1165
|
+
return;
|
|
1166
|
+
const inside = relative(deepest.source, dir);
|
|
1167
|
+
return inside === "" ? deepest.target : join2(deepest.target, inside);
|
|
1168
|
+
}
|
|
1169
|
+
var noticed = new Set;
|
|
1170
|
+
async function place(dir, program, { service, host } = {}) {
|
|
1171
|
+
if (host === true)
|
|
1172
|
+
return;
|
|
1173
|
+
let found;
|
|
1174
|
+
for (const composeDir of climb(dir)) {
|
|
1175
|
+
const services = await readServices(composeDir);
|
|
1176
|
+
const mounting = (services ?? []).filter((candidate) => containerPath(candidate, dir) !== undefined);
|
|
1177
|
+
if (services !== undefined && (mounting.length > 0 || services.some((candidate) => candidate.name === service))) {
|
|
1178
|
+
found = { composeDir, services, mounting };
|
|
1179
|
+
break;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (found === undefined) {
|
|
1183
|
+
if (service !== undefined)
|
|
1184
|
+
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
if (Bun.which("docker", { PATH: process8.env.PATH ?? "" }) === null) {
|
|
1188
|
+
if (service !== undefined)
|
|
1189
|
+
fail(`--in ${service}: docker not found`);
|
|
1190
|
+
if (!noticed.has(found.composeDir)) {
|
|
1191
|
+
noticed.add(found.composeDir);
|
|
1192
|
+
warn(`host, docker not found: the compose project in ${found.composeDir} is not reached`);
|
|
1193
|
+
}
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
const chosen = choose(found.mounting, found.services, dir, program, service);
|
|
1197
|
+
return { service: chosen.name, composeDir: found.composeDir, workdir: containerPath(chosen, dir) ?? dir };
|
|
1198
|
+
}
|
|
1199
|
+
function choose(mounting, services, dir, program, service) {
|
|
1200
|
+
if (service !== undefined) {
|
|
1201
|
+
const named = mounting.find((candidate) => candidate.name === service);
|
|
1202
|
+
if (named === undefined)
|
|
1203
|
+
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(", ")}`}`);
|
|
1204
|
+
return named;
|
|
1205
|
+
}
|
|
1206
|
+
const [only] = mounting;
|
|
1207
|
+
if (mounting.length === 1 && only !== undefined)
|
|
1208
|
+
return only;
|
|
1209
|
+
const words = toolWords(program);
|
|
1210
|
+
const fitting = mounting.filter((candidate) => words.some((word) => candidate.profile.includes(word)));
|
|
1211
|
+
const [fit] = fitting;
|
|
1212
|
+
if (fitting.length !== 1 || fit === undefined)
|
|
1213
|
+
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`);
|
|
1214
|
+
return fit;
|
|
1215
|
+
}
|
|
1216
|
+
function execArgv(placement, argv, env) {
|
|
1217
|
+
const variables = Object.entries({ NO_COLOR: "1", FORCE_COLOR: "0", ...env }).flatMap(([name, value]) => ["-e", `${name}=${value}`]);
|
|
1218
|
+
return ["docker", "compose", "exec", "-T", "-w", placement.workdir, ...variables, placement.service, ...argv];
|
|
1219
|
+
}
|
|
1220
|
+
function shellIn(placement, command, env = {}) {
|
|
1221
|
+
return `cd ${shellQuote(placement.composeDir)} && ${execArgv(placement, ["sh", "-c", command], env).map((word) => shellQuote(word)).join(" ")}`;
|
|
1222
|
+
}
|
|
1223
|
+
function argvIn(placement, argv) {
|
|
1224
|
+
return execArgv(placement, argv, {});
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
class Stack {
|
|
1228
|
+
answers = new Map;
|
|
1229
|
+
async ask(composeDir) {
|
|
1230
|
+
let answer = this.answers.get(composeDir);
|
|
1231
|
+
if (answer === undefined) {
|
|
1232
|
+
answer = Stack.running(composeDir);
|
|
1233
|
+
this.answers.set(composeDir, answer);
|
|
1234
|
+
}
|
|
1235
|
+
return answer;
|
|
1236
|
+
}
|
|
1237
|
+
static async running(composeDir) {
|
|
1238
|
+
try {
|
|
1239
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process8.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1240
|
+
if (ran.code !== 0)
|
|
1241
|
+
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1242
|
+
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
1243
|
+
return ran.text.split(`
|
|
1244
|
+
`).map((line) => line.trim()).filter((line) => line !== "");
|
|
1245
|
+
} catch (error) {
|
|
1246
|
+
return `cannot run docker compose in ${composeDir}: ${error instanceof Error ? error.message : String(error)}`;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
async problem(placement) {
|
|
1250
|
+
const answer = await this.ask(placement.composeDir);
|
|
1251
|
+
if (typeof answer === "string")
|
|
1252
|
+
return answer;
|
|
1253
|
+
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`;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
function programOf(command) {
|
|
1257
|
+
const end = command.indexOf(" ");
|
|
1258
|
+
return end === -1 ? command : command.slice(0, end);
|
|
1259
|
+
}
|
|
1260
|
+
var placeOptions = {
|
|
1261
|
+
in: { type: "string", description: "run in this compose service instead of the one found mounting the folder" },
|
|
1262
|
+
host: { type: "boolean", description: "run on the host even when a compose service mounts the folder" }
|
|
1263
|
+
};
|
|
1264
|
+
function placeSettings(values) {
|
|
1265
|
+
if (values.in !== undefined && values.host === true)
|
|
1266
|
+
fail("--in and --host exclude each other");
|
|
1267
|
+
return { service: values.in, host: values.host };
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/run.ts
|
|
1271
|
+
import { mkdir as mkdir2, writeFile } from "fs/promises";
|
|
1272
|
+
import { basename as basename2, join as join3 } from "path";
|
|
1273
|
+
import process9 from "process";
|
|
1274
|
+
|
|
1275
|
+
// src/e2e.ts
|
|
1276
|
+
var E2E_NOISE = [
|
|
1277
|
+
/^(?: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)/,
|
|
1278
|
+
/^[\u00B7F\u00D7\u00B0T\u00B1]+$/,
|
|
1279
|
+
/^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/
|
|
1280
|
+
];
|
|
1281
|
+
var PLAYWRIGHT_HEADER = /^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1282
|
+
var PLAYWRIGHT_SUMMARY = /^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/;
|
|
1283
|
+
var PLAYWRIGHT_ENTRY = /^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1284
|
+
var PLAYWRIGHT_RETRY = /^\s+Retry #\d+ \u2500+$/;
|
|
1285
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1286
|
+
var EXPECTED = /^\s+Expected: (.*)$/;
|
|
1287
|
+
var RECEIVED = /^\s+Received: (.*)$/;
|
|
1288
|
+
var VITEST_FAIL = /^ FAIL {2}(?:\|[^|]+\| )?(.+)$/;
|
|
1289
|
+
var VITEST_SUITE = /^(.+?) \[ .+ \]$/;
|
|
1290
|
+
var VITEST_FRAME = /^\s*\u276F (\S+):(\d+):(\d+)$/;
|
|
1291
|
+
function key(project, file, line, column, title) {
|
|
1292
|
+
return `${project ?? ""}|${file}:${line}:${column} \u203A ${title}`;
|
|
1293
|
+
}
|
|
1294
|
+
function firstFrame(block) {
|
|
1295
|
+
return block.map((line) => FRAME.exec(line)).find((match) => match !== null && !match[1]?.includes("node_modules")) ?? undefined;
|
|
1296
|
+
}
|
|
1297
|
+
var collectPlaywright = (lines, used) => {
|
|
1298
|
+
const flaky = new Set;
|
|
1299
|
+
let section = "";
|
|
1300
|
+
for (const [index, line] of lines.entries()) {
|
|
1301
|
+
const summary = PLAYWRIGHT_SUMMARY.exec(line);
|
|
1302
|
+
const entry = PLAYWRIGHT_ENTRY.exec(line);
|
|
1303
|
+
if (summary !== null) {
|
|
1304
|
+
section = summary[1] ?? "";
|
|
1305
|
+
used.add(index);
|
|
1306
|
+
} else if (entry !== null && section !== "") {
|
|
1307
|
+
if (section === "flaky")
|
|
1308
|
+
flaky.add(key(entry[1], entry[2], entry[3], entry[4], entry[5]));
|
|
1309
|
+
used.add(index);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
const errors = [];
|
|
1313
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1314
|
+
const header = PLAYWRIGHT_HEADER.exec(lines[index] ?? "");
|
|
1315
|
+
if (header === null)
|
|
1316
|
+
continue;
|
|
1317
|
+
let end = index + 1;
|
|
1318
|
+
while (end < lines.length && !PLAYWRIGHT_HEADER.test(lines[end] ?? "") && !PLAYWRIGHT_SUMMARY.test(lines[end] ?? ""))
|
|
1319
|
+
end++;
|
|
1320
|
+
for (let at = index;at < end; at++)
|
|
1321
|
+
used.add(at);
|
|
1322
|
+
const [, project, file, line, column, title] = header;
|
|
1323
|
+
const retry = lines.findIndex((text, at) => at > index && at < end && PLAYWRIGHT_RETRY.test(text));
|
|
1324
|
+
const block = lines.slice(index + 1, retry === -1 ? end : retry);
|
|
1325
|
+
const frame = firstFrame(block);
|
|
1326
|
+
const message = block.find((text) => text.trim() !== "")?.trim() ?? "failed";
|
|
1327
|
+
const expected = block.map((text) => EXPECTED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1328
|
+
const received = block.map((text) => RECEIVED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1329
|
+
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
1330
|
+
index = end - 1;
|
|
1331
|
+
if (flaky.has(key(project, file, line, column, title)))
|
|
1332
|
+
continue;
|
|
1333
|
+
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}` });
|
|
1334
|
+
}
|
|
1335
|
+
return errors;
|
|
1336
|
+
};
|
|
1337
|
+
var collectVitest = (lines, used) => {
|
|
1338
|
+
const errors = [];
|
|
1339
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1340
|
+
const header = VITEST_FAIL.exec(lines[index] ?? "")?.[1];
|
|
1341
|
+
if (header === undefined)
|
|
1342
|
+
continue;
|
|
1343
|
+
let end = index + 1;
|
|
1344
|
+
while (end < lines.length && !(lines[end] ?? "").startsWith("\u23AF") && !VITEST_FAIL.test(lines[end] ?? ""))
|
|
1345
|
+
end++;
|
|
1346
|
+
for (let at = index;at < end; at++)
|
|
1347
|
+
used.add(at);
|
|
1348
|
+
const block = lines.slice(index + 1, end);
|
|
1349
|
+
const frame = block.map((text) => VITEST_FRAME.exec(text)).find((match) => match !== null && !match[1]?.includes("node_modules"));
|
|
1350
|
+
const suite = VITEST_SUITE.exec(header)?.[1];
|
|
1351
|
+
const [file = "", ...names] = (suite ?? header).split(" > ");
|
|
1352
|
+
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(" > ") } : {} });
|
|
1353
|
+
index = end - 1;
|
|
1354
|
+
}
|
|
1355
|
+
return errors;
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
// src/php.ts
|
|
1359
|
+
var PHP_NOISE = [
|
|
1360
|
+
/^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,
|
|
1361
|
+
/^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,
|
|
1362
|
+
/^ -{3,}(?: -{3,})*\s*$/,
|
|
1363
|
+
/^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,
|
|
1364
|
+
/^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,
|
|
1365
|
+
/^(?: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:)/
|
|
1366
|
+
];
|
|
1367
|
+
var MAX_DIFF_LINES = 6;
|
|
1368
|
+
var PHPUNIT_HEADER = /^There (?:was|were) \d+ ([a-z ]+?)s?:$/i;
|
|
1369
|
+
var PHPUNIT_TRIGGERED = /^\d+ tests? triggered \d+ [\w ]+?s?:$/;
|
|
1370
|
+
var PHPUNIT_END = /^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/;
|
|
1371
|
+
var PHPUNIT_ITEM = /^\d+\) (.*)$/;
|
|
1372
|
+
var PHP_LOCATION = /^([\w./-]+\.php):(\d+)$/;
|
|
1373
|
+
var PHPSTAN_FILE = /^ {2}Line {3}(\S.*)$/;
|
|
1374
|
+
var PHPSTAN_GENERAL = /^ {2}Error\s*$/;
|
|
1375
|
+
var PHPSTAN_MESSAGE = /^ {2}(\S.*)$/;
|
|
1376
|
+
var PHPSTAN_ROW = /^ {2}(\d+|-) +(\S.*)$/;
|
|
1377
|
+
var PHPSTAN_CONTINUATION = /^ {9}(\S.*)$/;
|
|
1378
|
+
var PHPSTAN_IDENTIFIER = /^ {9}\uD83E\uDEAA\s+(\S+)\s*$/;
|
|
1379
|
+
var PHPSTAN_TIP = /^ {9}\uD83D\uDCA1/;
|
|
1380
|
+
var PHPSTAN_BORDER = /^ -{3,}(?: -{3,})*\s*$/;
|
|
1381
|
+
var PHPSTAN_RAW = /^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/;
|
|
1382
|
+
var PHPSTAN_JSON = /^\{.*"totals"/;
|
|
1383
|
+
var CS_FIXER_FILE = /^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/;
|
|
1384
|
+
var CS_FIXER_DIFF_START = /^\s+-+ begin diff -+$/;
|
|
1385
|
+
var CS_FIXER_DIFF_END = /^\s+-+ end diff -+$/;
|
|
1386
|
+
function isHeader(line) {
|
|
1387
|
+
return PHPUNIT_HEADER.test(line) || PHPUNIT_TRIGGERED.test(line);
|
|
1388
|
+
}
|
|
1389
|
+
function diffSummary(message) {
|
|
1390
|
+
const start = message.findIndex((line) => line === "+++ Actual");
|
|
1391
|
+
if (start === -1)
|
|
1392
|
+
return "";
|
|
1393
|
+
const changed = message.slice(start + 1).filter((line) => line.startsWith("-") || line.startsWith("+")).map((line) => `${line[0]} ${line.slice(1).trim()}`);
|
|
1394
|
+
const shown = changed.slice(0, MAX_DIFF_LINES).join(" | ");
|
|
1395
|
+
return changed.length === 0 ? "" : ` (${shown}${changed.length > MAX_DIFF_LINES ? " | ..." : ""})`;
|
|
1396
|
+
}
|
|
1397
|
+
function phpunitError(test, body) {
|
|
1398
|
+
const at = body.findIndex((line) => PHP_LOCATION.test(line));
|
|
1399
|
+
const location = PHP_LOCATION.exec(body[at] ?? "");
|
|
1400
|
+
const message = body.slice(0, at === -1 ? body.length : at).map((line) => line.trimEnd());
|
|
1401
|
+
const first = message.find((line) => line.trim() !== "") ?? "failed";
|
|
1402
|
+
return { tool: "phpunit", file: location?.[1] ?? "", line: Number(location?.[2] ?? 0), column: 0, severity: "error", message: `${first}${diffSummary(message)}`, test };
|
|
1403
|
+
}
|
|
1404
|
+
var collectPhpunit = (lines, used) => {
|
|
1405
|
+
const errors = [];
|
|
1406
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1407
|
+
const line = lines[index] ?? "";
|
|
1408
|
+
const kind = PHPUNIT_HEADER.exec(line)?.[1];
|
|
1409
|
+
if (kind === undefined && !PHPUNIT_TRIGGERED.test(line))
|
|
1410
|
+
continue;
|
|
1411
|
+
let end = index + 1;
|
|
1412
|
+
while (end < lines.length && !PHPUNIT_END.test(lines[end] ?? "") && !isHeader(lines[end] ?? ""))
|
|
1413
|
+
end++;
|
|
1414
|
+
for (let at = index;at < end; at++)
|
|
1415
|
+
used.add(at);
|
|
1416
|
+
if (kind === "error" || kind === "failure") {
|
|
1417
|
+
const starts = Array.from({ length: end - index - 1 }, (_, at) => index + 1 + at).filter((at) => PHPUNIT_ITEM.test(lines[at] ?? ""));
|
|
1418
|
+
for (const [position, start] of starts.entries())
|
|
1419
|
+
errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start] ?? "")?.[1] ?? "", lines.slice(start + 1, starts[position + 1] ?? end)));
|
|
1420
|
+
}
|
|
1421
|
+
index = end - 1;
|
|
1422
|
+
}
|
|
1423
|
+
return errors;
|
|
1424
|
+
};
|
|
1425
|
+
function appendMessage(error, text) {
|
|
1426
|
+
error.message = `${error.message} ${text}`;
|
|
1427
|
+
}
|
|
1428
|
+
function phpstanJson(text) {
|
|
1429
|
+
try {
|
|
1430
|
+
const report = JSON.parse(text);
|
|
1431
|
+
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 } })));
|
|
1432
|
+
return [...fromFiles, ...(report.errors ?? []).map((message) => ({ file: "", line: 0, message }))];
|
|
1433
|
+
} catch {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
var collectPhpstan = (lines, used) => {
|
|
1438
|
+
const errors = [];
|
|
1439
|
+
let file;
|
|
1440
|
+
let current;
|
|
1441
|
+
let rows = 0;
|
|
1442
|
+
let tip = false;
|
|
1443
|
+
let general = false;
|
|
1444
|
+
for (const [index, text] of lines.entries()) {
|
|
1445
|
+
const line = text.trimEnd();
|
|
1446
|
+
if (used.has(index))
|
|
1447
|
+
continue;
|
|
1448
|
+
if (PHPSTAN_JSON.test(line)) {
|
|
1449
|
+
const parsed = phpstanJson(line);
|
|
1450
|
+
for (const entry of parsed ?? []) {
|
|
1451
|
+
errors.push({ tool: "phpstan", file: entry.file, line: entry.line, column: 0, severity: "error", message: entry.message, ...entry.rule === undefined ? {} : { rule: entry.rule } });
|
|
1452
|
+
}
|
|
1453
|
+
if (parsed !== undefined)
|
|
1454
|
+
used.add(index);
|
|
1455
|
+
continue;
|
|
1456
|
+
}
|
|
1457
|
+
const raw = PHPSTAN_RAW.exec(line);
|
|
1458
|
+
if (raw !== null) {
|
|
1459
|
+
errors.push({ tool: "phpstan", file: raw[1] ?? "", line: Number(raw[2]), column: 0, severity: "error", message: raw[3] ?? "" });
|
|
1460
|
+
used.add(index);
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
const header = PHPSTAN_FILE.exec(line);
|
|
1464
|
+
if (header !== null || PHPSTAN_GENERAL.test(line)) {
|
|
1465
|
+
file = header?.[1] ?? "";
|
|
1466
|
+
general = header === null;
|
|
1467
|
+
current = undefined;
|
|
1468
|
+
rows = 0;
|
|
1469
|
+
used.add(index);
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
if (file === undefined)
|
|
1473
|
+
continue;
|
|
1474
|
+
const message = PHPSTAN_MESSAGE.exec(line)?.[1];
|
|
1475
|
+
if (general && message !== undefined && !PHPSTAN_BORDER.test(line)) {
|
|
1476
|
+
errors.push({ tool: "phpstan", file: "", line: 0, column: 0, severity: "error", message });
|
|
1477
|
+
rows++;
|
|
1478
|
+
used.add(index);
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
const row = PHPSTAN_ROW.exec(line);
|
|
1482
|
+
const identifier = PHPSTAN_IDENTIFIER.exec(line)?.[1];
|
|
1483
|
+
const continuation = PHPSTAN_CONTINUATION.exec(line)?.[1];
|
|
1484
|
+
if (PHPSTAN_BORDER.test(line) && rows > 0) {
|
|
1485
|
+
file = undefined;
|
|
1486
|
+
general = false;
|
|
1487
|
+
current = undefined;
|
|
1488
|
+
} else if (row !== null) {
|
|
1489
|
+
current = { tool: "phpstan", file, line: row[1] === "-" ? 0 : Number(row[1]), column: 0, severity: "error", message: row[2] ?? "" };
|
|
1490
|
+
errors.push(current);
|
|
1491
|
+
rows++;
|
|
1492
|
+
tip = false;
|
|
1493
|
+
used.add(index);
|
|
1494
|
+
} else if (identifier !== undefined && current !== undefined) {
|
|
1495
|
+
current.rule = identifier;
|
|
1496
|
+
used.add(index);
|
|
1497
|
+
} else if (PHPSTAN_TIP.test(line)) {
|
|
1498
|
+
tip = true;
|
|
1499
|
+
used.add(index);
|
|
1500
|
+
} else if (continuation !== undefined && current !== undefined) {
|
|
1501
|
+
if (!tip)
|
|
1502
|
+
appendMessage(current, continuation);
|
|
1503
|
+
used.add(index);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
return errors;
|
|
1507
|
+
};
|
|
1508
|
+
var collectCsFixer = (lines, used) => {
|
|
1509
|
+
const errors = [];
|
|
1510
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1511
|
+
const match = CS_FIXER_FILE.exec(lines[index] ?? "");
|
|
1512
|
+
if (match === null)
|
|
1513
|
+
continue;
|
|
1514
|
+
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" });
|
|
1515
|
+
used.add(index);
|
|
1516
|
+
if (!CS_FIXER_DIFF_START.test(lines[index + 1] ?? ""))
|
|
1517
|
+
continue;
|
|
1518
|
+
const end = lines.findIndex((text, at) => at > index && CS_FIXER_DIFF_END.test(text));
|
|
1519
|
+
for (let at = index + 1;at <= (end === -1 ? index + 1 : end); at++)
|
|
1520
|
+
used.add(at);
|
|
1521
|
+
index = end === -1 ? index + 1 : end;
|
|
1522
|
+
}
|
|
1523
|
+
return errors;
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// src/output.ts
|
|
1527
|
+
var BASH_ECHO = /^\$ /;
|
|
1528
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1529
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1530
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1531
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1532
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1533
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1534
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1535
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
1536
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1537
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
1538
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1539
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1540
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1541
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1542
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1543
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1544
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1545
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1546
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1547
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1548
|
+
var MAX_TESTS = 10;
|
|
1549
|
+
var MAX_LINES = 100;
|
|
1550
|
+
var TAIL = 30;
|
|
1551
|
+
var bunTest = (lines) => {
|
|
1552
|
+
const seen = new Set;
|
|
1553
|
+
const blocks = [];
|
|
1554
|
+
for (const [index, line] of lines.entries()) {
|
|
1555
|
+
const name = line.replace(DURATION2, "");
|
|
1556
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1557
|
+
continue;
|
|
1558
|
+
seen.add(name);
|
|
1559
|
+
if (blocks.length < MAX_TESTS)
|
|
1560
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1561
|
+
`).trim());
|
|
1562
|
+
}
|
|
1563
|
+
if (blocks.length === 0)
|
|
1564
|
+
return;
|
|
1565
|
+
if (seen.size > MAX_TESTS)
|
|
1566
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1567
|
+
return [...blocks.join(`
|
|
1568
|
+
|
|
1569
|
+
`).split(`
|
|
1570
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1571
|
+
};
|
|
1572
|
+
var bunCheck = (lines) => {
|
|
1573
|
+
const text = lines.join(`
|
|
1574
|
+
`);
|
|
1575
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1576
|
+
if (blocks === null)
|
|
1577
|
+
return;
|
|
1578
|
+
const errors = blocks.map((block) => {
|
|
1579
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1580
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1581
|
+
});
|
|
1582
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1583
|
+
};
|
|
1584
|
+
function bunCheckFields(block) {
|
|
1585
|
+
const attributes = Object.fromEntries([...block.matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1586
|
+
return {
|
|
1587
|
+
file: attributes.file ?? "",
|
|
1588
|
+
line: attributes.line ?? "",
|
|
1589
|
+
column: attributes.column ?? "",
|
|
1590
|
+
code: attributes.code ?? "",
|
|
1591
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1592
|
+
`).slice(1, -1).join(`
|
|
1593
|
+
`).trim()
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
var tsc = (lines) => {
|
|
1597
|
+
const kept = [];
|
|
1598
|
+
let inError = false;
|
|
1599
|
+
for (const line of lines) {
|
|
1600
|
+
if (TSC_ERROR.test(line)) {
|
|
1601
|
+
inError = true;
|
|
1602
|
+
kept.push(line);
|
|
1603
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
1604
|
+
inError = false;
|
|
1605
|
+
kept.push(line);
|
|
1606
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1607
|
+
kept.push(line);
|
|
1608
|
+
} else {
|
|
1609
|
+
inError = false;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1613
|
+
};
|
|
1614
|
+
var eslint = (lines) => {
|
|
1615
|
+
const kept = [];
|
|
1616
|
+
let file = "";
|
|
1617
|
+
let shown = "";
|
|
1618
|
+
for (const line of lines) {
|
|
1619
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
1620
|
+
if (file !== shown) {
|
|
1621
|
+
kept.push(file);
|
|
1622
|
+
shown = file;
|
|
1623
|
+
}
|
|
1624
|
+
kept.push(line);
|
|
1625
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1626
|
+
kept.push(line);
|
|
1627
|
+
} else if (line.trim() !== "") {
|
|
1628
|
+
file = line;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1632
|
+
};
|
|
1633
|
+
var phpstan = (lines) => {
|
|
1634
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1635
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1636
|
+
};
|
|
1637
|
+
var php = (lines) => {
|
|
1638
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1639
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1640
|
+
};
|
|
1641
|
+
var vitest = (lines) => {
|
|
1642
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1643
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1644
|
+
};
|
|
1645
|
+
var playwright = (lines) => {
|
|
1646
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1647
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1648
|
+
};
|
|
1649
|
+
var phpCsFixer = (lines) => {
|
|
1650
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1651
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1652
|
+
};
|
|
1653
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1654
|
+
function squeeze(lines) {
|
|
1655
|
+
const out = [];
|
|
1656
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1657
|
+
if (line !== "" || out.at(-1) !== "")
|
|
1658
|
+
out.push(line);
|
|
1659
|
+
}
|
|
1660
|
+
while (out.at(-1) === "")
|
|
1661
|
+
out.pop();
|
|
1662
|
+
return out;
|
|
1663
|
+
}
|
|
1664
|
+
function failureExcerpt(output) {
|
|
1665
|
+
const lines = stripAnsi(output).split(`
|
|
1666
|
+
`);
|
|
1667
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1668
|
+
lines.shift();
|
|
1669
|
+
const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1670
|
+
const shown = squeeze(parsed ?? lines.slice(-TAIL));
|
|
1671
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1672
|
+
`) : shown.join(`
|
|
1673
|
+
`);
|
|
1674
|
+
}
|
|
1675
|
+
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
1676
|
+
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
1677
|
+
var TSC_SOURCE_LINE = /^\d+ /;
|
|
1678
|
+
var ESLINT_FIELDS = /^ +(\d+):(\d+) +(error|warning) +(\S.*)$/;
|
|
1679
|
+
var ESLINT_RULE = / {2,}(\S+)$/;
|
|
1680
|
+
var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
|
|
1681
|
+
var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
1682
|
+
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1683
|
+
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
1684
|
+
var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
|
|
1685
|
+
var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
|
|
1686
|
+
var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
|
|
1687
|
+
var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
|
|
1688
|
+
var CARGO_NOISE = /^(?:\s+(?:Compiling|Finished|Checking|Fresh|Running|Blocking) |error: (?:aborting due to|could not compile)|warning: .* generated \d+ warnings?|Some errors have detailed explanations|For more information about (?:this|an) error|To learn more, run the command again)/;
|
|
1689
|
+
var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
|
|
1690
|
+
var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
|
|
1691
|
+
var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
|
|
1692
|
+
var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
|
|
1693
|
+
var PYTEST_E_LINE = /^E {3}(.*)$/;
|
|
1694
|
+
var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
|
|
1695
|
+
var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
|
|
1696
|
+
var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
|
|
1697
|
+
var PYTEST_EXCEPTION_END = /[\s:]/;
|
|
1698
|
+
var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
|
|
1699
|
+
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)/;
|
|
1700
|
+
function isNoise(line) {
|
|
1701
|
+
return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, GO_NOISE, CARGO_NOISE, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
|
|
1702
|
+
}
|
|
1703
|
+
var collectBunCheck = (lines, used) => {
|
|
1704
|
+
const errors = [];
|
|
1705
|
+
for (let index = 0;index < lines.length; index++) {
|
|
1706
|
+
if (!(lines[index] ?? "").startsWith("<error file="))
|
|
1707
|
+
continue;
|
|
1708
|
+
const end = lines.findIndex((line, at) => at >= index && line === "</error>");
|
|
1709
|
+
if (end === -1)
|
|
1710
|
+
break;
|
|
1711
|
+
const { file, line, column, code, message } = bunCheckFields(lines.slice(index, end + 1).join(`
|
|
1712
|
+
`));
|
|
1713
|
+
errors.push({ tool: "bun check", file, line: Number(line), column: Number(column), rule: code, severity: "error", message: message.replaceAll(/\s*\n\s*/g, " ") });
|
|
1714
|
+
for (let at = index;at <= end; at++)
|
|
1715
|
+
used.add(at);
|
|
1716
|
+
index = end;
|
|
1717
|
+
}
|
|
1718
|
+
return errors;
|
|
1719
|
+
};
|
|
1720
|
+
var collectBunTest = (lines, used) => {
|
|
1721
|
+
const errors = [];
|
|
1722
|
+
const seen = new Set;
|
|
1723
|
+
for (const [index, line] of lines.entries()) {
|
|
1724
|
+
if (!line.startsWith("(fail) "))
|
|
1725
|
+
continue;
|
|
1726
|
+
used.add(index);
|
|
1727
|
+
const test = line.slice("(fail) ".length).replace(DURATION2, "");
|
|
1728
|
+
if (seen.has(test))
|
|
1729
|
+
continue;
|
|
1730
|
+
seen.add(test);
|
|
1731
|
+
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1;
|
|
1732
|
+
const block = lines.slice(start, index);
|
|
1733
|
+
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
1734
|
+
for (let at = start;at < index; at++)
|
|
1735
|
+
used.add(at);
|
|
1736
|
+
const frame = block.slice(Math.max(failure, 0)).map((text) => BUN_TEST_FRAME.exec(text)).find((match) => match !== null);
|
|
1737
|
+
const header = lines.slice(0, index).findLast((text) => BUN_TEST_FILE.test(text));
|
|
1738
|
+
const expected = block.map((text) => BUN_TEST_EXPECTED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
1739
|
+
const received = block.map((text) => BUN_TEST_RECEIVED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
1740
|
+
const reason = failure === -1 ? "failed" : (block[failure] ?? "").slice("error:".length).trim();
|
|
1741
|
+
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
1742
|
+
errors.push({
|
|
1743
|
+
tool: "bun test",
|
|
1744
|
+
file: frame?.[1] ?? header?.replace(":", "") ?? "",
|
|
1745
|
+
line: Number(frame?.[2] ?? 0),
|
|
1746
|
+
column: Number(frame?.[3] ?? 0),
|
|
1747
|
+
severity: "error",
|
|
1748
|
+
message: `${reason}${values}`,
|
|
1749
|
+
test
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
return errors;
|
|
1753
|
+
};
|
|
1754
|
+
var collectTsc = (lines, used) => {
|
|
1755
|
+
const errors = [];
|
|
1756
|
+
let current;
|
|
1757
|
+
let pretty = false;
|
|
1758
|
+
for (const [index, line] of lines.entries()) {
|
|
1759
|
+
if (used.has(index))
|
|
1760
|
+
continue;
|
|
1761
|
+
const plain = TSC_PLAIN_ERROR.exec(line);
|
|
1762
|
+
const match = plain ?? TSC_PRETTY_ERROR.exec(line);
|
|
1763
|
+
if (match !== null) {
|
|
1764
|
+
current = { tool: "tsc", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" };
|
|
1765
|
+
pretty = plain === null;
|
|
1766
|
+
errors.push(current);
|
|
1767
|
+
used.add(index);
|
|
1768
|
+
} else if (current !== undefined && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1769
|
+
current.message += ` ${line.trim()}`;
|
|
1770
|
+
used.add(index);
|
|
1771
|
+
} else if (current !== undefined && pretty && (TSC_FRAME.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
1772
|
+
used.add(index);
|
|
1773
|
+
} else if (!(pretty && line.trim() === "")) {
|
|
1774
|
+
current = undefined;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
return errors;
|
|
1778
|
+
};
|
|
1779
|
+
var collectEslint = (lines, used) => {
|
|
1780
|
+
const errors = [];
|
|
1781
|
+
let file;
|
|
1782
|
+
for (const [index, line] of lines.entries()) {
|
|
1783
|
+
if (used.has(index))
|
|
1784
|
+
continue;
|
|
1785
|
+
const match = ESLINT_PROBLEM.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
1786
|
+
if (match !== null && file !== undefined) {
|
|
1787
|
+
const text = match[4] ?? "";
|
|
1788
|
+
const rule = ESLINT_RULE.exec(text);
|
|
1789
|
+
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) });
|
|
1790
|
+
used.add(index);
|
|
1791
|
+
used.add(file);
|
|
1792
|
+
} else if (!isNoise(line)) {
|
|
1793
|
+
file = index;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
return errors;
|
|
1797
|
+
};
|
|
1798
|
+
var collectGo = (lines, used) => {
|
|
1799
|
+
const errors = [];
|
|
1800
|
+
for (const [index, line] of lines.entries()) {
|
|
1801
|
+
const match = used.has(index) ? null : GO_ERROR.exec(line);
|
|
1802
|
+
if (match === null)
|
|
1803
|
+
continue;
|
|
1804
|
+
errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
|
|
1805
|
+
used.add(index);
|
|
1806
|
+
}
|
|
1807
|
+
return errors;
|
|
1808
|
+
};
|
|
1809
|
+
var collectArrowed = (lines, used) => {
|
|
1810
|
+
const errors = [];
|
|
1811
|
+
for (const [index, line] of lines.entries()) {
|
|
1812
|
+
const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
|
|
1813
|
+
const header = arrow === null ? null : lines[index - 1] ?? "";
|
|
1814
|
+
const cargo = header === null ? null : CARGO_HEADER.exec(header);
|
|
1815
|
+
const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
|
|
1816
|
+
if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
|
|
1817
|
+
continue;
|
|
1818
|
+
const [, file, row, column] = arrow;
|
|
1819
|
+
const fields = { file: file ?? "", line: Number(row), column: Number(column) };
|
|
1820
|
+
errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
|
|
1821
|
+
used.add(index - 1);
|
|
1822
|
+
used.add(index);
|
|
1823
|
+
for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
|
|
1824
|
+
if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
|
|
1825
|
+
break;
|
|
1826
|
+
used.add(frame);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
return errors;
|
|
1830
|
+
};
|
|
1831
|
+
var collectRuff = (lines, used) => {
|
|
1832
|
+
const errors = [];
|
|
1833
|
+
for (const [index, line] of lines.entries()) {
|
|
1834
|
+
const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
|
|
1835
|
+
if (match === null)
|
|
1836
|
+
continue;
|
|
1837
|
+
errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
|
|
1838
|
+
used.add(index);
|
|
1839
|
+
}
|
|
1840
|
+
return errors;
|
|
1841
|
+
};
|
|
1842
|
+
var collectPytest = (lines, used) => {
|
|
1843
|
+
const errors = [];
|
|
1844
|
+
const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
|
|
1845
|
+
const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
|
|
1846
|
+
if (start === -1)
|
|
1847
|
+
return errors;
|
|
1848
|
+
const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
|
|
1849
|
+
const stop = end === -1 ? lines.length : end;
|
|
1850
|
+
let message = [];
|
|
1851
|
+
for (let index = start;index < stop; index++) {
|
|
1852
|
+
const line = lines[index] ?? "";
|
|
1853
|
+
const failure = PYTEST_E_LINE.exec(line);
|
|
1854
|
+
if (failure !== null) {
|
|
1855
|
+
message.push((failure[1] ?? "").trim());
|
|
1856
|
+
} else {
|
|
1857
|
+
const location = PYTEST_LOCATION.exec(line);
|
|
1858
|
+
if (location !== null) {
|
|
1859
|
+
const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
|
|
1860
|
+
const first = message[0] ?? "";
|
|
1861
|
+
const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
|
|
1862
|
+
errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
|
|
1863
|
+
}
|
|
1864
|
+
if (line.trim() !== "")
|
|
1865
|
+
message = [];
|
|
1866
|
+
}
|
|
1867
|
+
used.add(index);
|
|
1868
|
+
}
|
|
1869
|
+
for (let index = stop;index < lines.length; index++) {
|
|
1870
|
+
if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
|
|
1871
|
+
used.add(index);
|
|
1872
|
+
}
|
|
1873
|
+
return errors;
|
|
1874
|
+
};
|
|
1875
|
+
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
|
|
1876
|
+
function parseErrors(output) {
|
|
1877
|
+
const lines = stripAnsi(output).split(`
|
|
1878
|
+
`);
|
|
1879
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1880
|
+
lines.shift();
|
|
1881
|
+
const used = new Set;
|
|
1882
|
+
const errors = COLLECTORS.flatMap((collect) => collect(lines, used));
|
|
1883
|
+
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
1884
|
+
return { errors, unrecognised };
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// src/run.ts
|
|
1888
|
+
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
1889
|
+
async function logDirectory(cwd) {
|
|
1890
|
+
const root = await privateLogDirectory("check");
|
|
1891
|
+
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
1892
|
+
const path = join3(root, `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-${Date.now().toString(36)}-${process9.pid}`);
|
|
1893
|
+
await mkdir2(path, { mode: 448 });
|
|
1894
|
+
return path;
|
|
1895
|
+
}
|
|
1896
|
+
async function saveLog(output) {
|
|
1897
|
+
const root = await privateLogDirectory("errs");
|
|
1898
|
+
await sweepLogs(root);
|
|
1899
|
+
const path = join3(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process9.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
1900
|
+
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
1901
|
+
return path;
|
|
1902
|
+
}
|
|
1903
|
+
async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}) {
|
|
1904
|
+
const started = Date.now();
|
|
1905
|
+
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
1906
|
+
cwd,
|
|
1907
|
+
env: { ...process9.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
1908
|
+
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
1909
|
+
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
1910
|
+
});
|
|
1911
|
+
const output = stripAnsi(text);
|
|
1912
|
+
await writeFile(logFile, output, { mode: 384, flag: "wx" });
|
|
1913
|
+
return { ok: code === 0, ms: Date.now() - started, output, ...timedOut ? { timedOut } : {} };
|
|
1914
|
+
}
|
|
1915
|
+
async function refusedStep(reason, logFile) {
|
|
1916
|
+
await writeFile(logFile, reason, { mode: 384, flag: "wx" });
|
|
1917
|
+
return { ok: false, ms: 0, output: reason };
|
|
1918
|
+
}
|
|
1919
|
+
function outcomeJson(name, command, logFile, outcome, service) {
|
|
1920
|
+
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) } };
|
|
1921
|
+
}
|
|
1922
|
+
function printOutcome(name, width, command, logFile, outcome) {
|
|
1923
|
+
if (outcome.ok) {
|
|
1924
|
+
console.log(`ok ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${logFile}`);
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
const label = outcome.timedOut === true ? "TIME " : "FAIL ";
|
|
1928
|
+
console.log(`${label} ${name.padEnd(width)} ${formatDuration(outcome.ms)} ${command} ${logFile}`);
|
|
1929
|
+
if (outcome.timedOut === true)
|
|
1930
|
+
console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
|
|
1931
|
+
console.log(failureExcerpt(outcome.output).split(`
|
|
1932
|
+
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
1933
|
+
`));
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
// src/steps.ts
|
|
1937
|
+
import { readdir as readdir2 } from "fs/promises";
|
|
1938
|
+
import { join as join4 } from "path";
|
|
1939
|
+
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1940
|
+
var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1941
|
+
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1942
|
+
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1943
|
+
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1944
|
+
var JUST_TIMEOUT_MS = 1e4;
|
|
1945
|
+
var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"];
|
|
1946
|
+
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1947
|
+
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1948
|
+
async function readFirst(dir, files) {
|
|
1949
|
+
for (const file of files) {
|
|
1950
|
+
const handle = Bun.file(join4(dir, file));
|
|
1951
|
+
if (await handle.exists())
|
|
1952
|
+
return { file, text: await handle.text() };
|
|
1953
|
+
}
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
async function read(dir, ...files) {
|
|
1957
|
+
for (const file of files) {
|
|
1958
|
+
const handle = Bun.file(join4(dir, file));
|
|
1959
|
+
if (await handle.exists())
|
|
1960
|
+
return handle.text();
|
|
1961
|
+
}
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
function scripts(file, text) {
|
|
1965
|
+
try {
|
|
1966
|
+
const parsed = JSON.parse(text);
|
|
1967
|
+
return parsed.scripts ?? {};
|
|
1968
|
+
} catch {
|
|
1969
|
+
throw new Error(`${file} is not valid JSON`);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
function targets(text) {
|
|
1973
|
+
return [...text.matchAll(TARGET)].map((match) => match[1] ?? "");
|
|
1974
|
+
}
|
|
1975
|
+
async function recipes(dir, file, text) {
|
|
1976
|
+
if (Bun.which("just") === null)
|
|
1977
|
+
return targets(text);
|
|
1978
|
+
try {
|
|
1979
|
+
const ran = await runCommand(["just", "--justfile", file, "--dump", "--dump-format", "json"], { cwd: dir, timeoutMs: JUST_TIMEOUT_MS });
|
|
1980
|
+
const dump = JSON.parse(ran.text);
|
|
1981
|
+
if (ran.code !== 0)
|
|
1982
|
+
return targets(text);
|
|
1983
|
+
return Object.entries(dump.recipes ?? {}).filter(([, recipe]) => recipe.private !== true && (recipe.parameters ?? []).every((parameter) => parameter.default !== null || parameter.kind === "star")).map(([name]) => name);
|
|
1984
|
+
} catch {
|
|
1985
|
+
return targets(text);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
function callsSelf(value, bin) {
|
|
1989
|
+
return typeof value === "string" && (value === bin || value.startsWith(`${bin} `) || value.startsWith(`${bin} `));
|
|
1990
|
+
}
|
|
1991
|
+
async function candidates(dir, bin) {
|
|
1992
|
+
const steps = [];
|
|
1993
|
+
const packageJson = await read(dir, "package.json");
|
|
1994
|
+
const composerJson = await read(dir, "composer.json");
|
|
1995
|
+
const justfile = await readFirst(dir, JUSTFILES);
|
|
1996
|
+
const makefile = await read(dir, ...MAKEFILES);
|
|
1997
|
+
if (packageJson !== undefined) {
|
|
1998
|
+
for (const [name, value] of Object.entries(scripts("package.json", packageJson))) {
|
|
1999
|
+
if (!callsSelf(value, bin))
|
|
2000
|
+
steps.push({ name, command: `bun run ${name}`, source: "package.json" });
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
if (composerJson !== undefined) {
|
|
2004
|
+
for (const name of Object.keys(scripts("composer.json", composerJson)))
|
|
2005
|
+
steps.push({ name, command: `composer run ${name}`, source: "composer.json" });
|
|
2006
|
+
}
|
|
2007
|
+
if (justfile !== undefined) {
|
|
2008
|
+
for (const name of await recipes(dir, justfile.file, justfile.text))
|
|
2009
|
+
steps.push({ name, command: `just ${name}`, source: "Justfile" });
|
|
2010
|
+
}
|
|
2011
|
+
for (const name of targets(makefile ?? ""))
|
|
2012
|
+
steps.push({ name, command: `make ${name}`, source: "Makefile" });
|
|
2013
|
+
steps.push(...await phpSteps(dir));
|
|
2014
|
+
return steps;
|
|
2015
|
+
}
|
|
2016
|
+
async function firstFile(dir, names) {
|
|
2017
|
+
for (const name of names) {
|
|
2018
|
+
if (await Bun.file(join4(dir, name)).exists())
|
|
2019
|
+
return name;
|
|
2020
|
+
}
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
async function phpSteps(dir) {
|
|
2024
|
+
const steps = [];
|
|
2025
|
+
const phpstan = await firstFile(dir, PHPSTAN_CONFIGS);
|
|
2026
|
+
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
2027
|
+
const phpunit = await firstFile(dir, PHPUNIT_CONFIGS);
|
|
2028
|
+
if (phpstan !== undefined)
|
|
2029
|
+
steps.push({ name: "typecheck", command: "vendor/bin/phpstan analyse --no-progress --memory-limit=1G", source: phpstan });
|
|
2030
|
+
if (csFixer !== undefined)
|
|
2031
|
+
steps.push({ name: "lint", command: "vendor/bin/php-cs-fixer fix --dry-run -v", source: csFixer });
|
|
2032
|
+
if (phpunit !== undefined)
|
|
2033
|
+
steps.push({ name: "test", command: "vendor/bin/phpunit", source: phpunit });
|
|
2034
|
+
return steps;
|
|
2035
|
+
}
|
|
2036
|
+
async function discoverProjects(dir) {
|
|
2037
|
+
const own = await discover(dir);
|
|
2038
|
+
if (own.length > 0)
|
|
2039
|
+
return [{ dir, steps: own }];
|
|
2040
|
+
const projects = [];
|
|
2041
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
2042
|
+
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
2043
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
2044
|
+
continue;
|
|
2045
|
+
const steps = await discover(join4(dir, entry.name));
|
|
2046
|
+
if (steps.length > 0)
|
|
2047
|
+
projects.push({ name: entry.name, dir: join4(dir, entry.name), steps });
|
|
2048
|
+
}
|
|
2049
|
+
return projects;
|
|
2050
|
+
}
|
|
2051
|
+
async function discover(dir) {
|
|
2052
|
+
const found = await candidates(dir, "check");
|
|
2053
|
+
return STEP_NAMES.flatMap((name) => {
|
|
2054
|
+
const step = found.find((candidate) => candidate.name === name);
|
|
2055
|
+
return step === undefined ? [] : [step];
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/check.ts
|
|
2060
|
+
var usage = `check [--only <steps>] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2061
|
+
|
|
2062
|
+
Runs the repo's check, typecheck, lint and test steps, from package.json scripts (through bun run), composer.json, a Justfile or a Makefile, and for PHP from phpstan.neon (typecheck), .php-cs-fixer.dist.php (lint, dry-run) and phpunit.xml.dist (test) when composer.json has no such script.
|
|
2063
|
+
A folder without steps but with subfolders that have some (api/ and client/) runs each one's, each line naming its subfolder.
|
|
2064
|
+
A step runs inside the docker compose service that bind-mounts its folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the step fails naming it. --in picks the service, --host forces the host.
|
|
2065
|
+
A passing step is one line, a failing one shows only what failed, and each step's full output is saved to the file whose path ends its line.
|
|
2066
|
+
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2067
|
+
Exits 0 when every step passed, 1 when one failed, 2 on bad usage, when no step is found or when a step timed out.
|
|
2068
|
+
--json prints [{name, command, in?, ok, ms, log, failed?}] once every step ran, --list --json [{name, command, source, in?}], in the compose service the step ran in.`;
|
|
2069
|
+
var options = {
|
|
2070
|
+
list: { type: "boolean", short: "l", description: "print the steps found, the commands that run them and where (host or service), without running them" },
|
|
2071
|
+
only: { type: "string", short: "o", description: `comma separated steps to run, among ${STEP_NAMES.join(", ")}` },
|
|
2072
|
+
timeout: { type: "string", short: "t", description: "longest a step may run before it is ended (30s, 5m, 1h), none by default" },
|
|
2073
|
+
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions (needs the slot bin)" },
|
|
2074
|
+
...placeOptions,
|
|
2075
|
+
json: jsonOption()
|
|
2076
|
+
};
|
|
2077
|
+
function slotted(command) {
|
|
2078
|
+
return `slot -- sh -c ${shellQuote(command)}`;
|
|
2079
|
+
}
|
|
2080
|
+
var COMMA = /\s*,\s*/;
|
|
2081
|
+
function pick(steps, only) {
|
|
2082
|
+
if (only === undefined)
|
|
2083
|
+
return steps;
|
|
2084
|
+
const names = only.split(COMMA).filter((name) => name !== "");
|
|
2085
|
+
if (names.length === 0)
|
|
2086
|
+
fail(`--only names no step, found ${steps.map((step) => step.name).join(", ")}`);
|
|
2087
|
+
const unknown = names.filter((name) => !steps.some((step) => step.name === name));
|
|
2088
|
+
if (unknown.length > 0)
|
|
2089
|
+
fail(`no ${unknown.join(", ")} step here, found ${[...new Set(steps.map((step) => step.name))].join(", ")}`);
|
|
2090
|
+
return steps.filter((step) => names.includes(step.name));
|
|
2091
|
+
}
|
|
2092
|
+
async function plan(steps, settings) {
|
|
2093
|
+
const planned = [];
|
|
2094
|
+
for (const { project, ...step } of steps)
|
|
2095
|
+
planned.push({ ...step, dir: project.dir, label: project.name === undefined ? step.name : `${project.name}/${step.name}`, placement: await place(project.dir, programOf(step.command), settings) });
|
|
2096
|
+
return planned;
|
|
2097
|
+
}
|
|
2098
|
+
function launch(step) {
|
|
2099
|
+
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2100
|
+
}
|
|
2101
|
+
async function check(args, cwd = process10.cwd()) {
|
|
2102
|
+
const parsed = parse(args, usage, options, { replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2103
|
+
const settings = placeSettings(parsed.values);
|
|
2104
|
+
const projects = await discoverProjects(cwd);
|
|
2105
|
+
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
2106
|
+
if (found.length === 0)
|
|
2107
|
+
fail(`no ${STEP_NAMES.join(", ")} step in package.json, composer.json, a Justfile, a Makefile or a PHP tool's config, nor in a subfolder`);
|
|
2108
|
+
const steps = await plan(pick(found, parsed.values.only), settings);
|
|
2109
|
+
const json = parsed.values.json === true;
|
|
2110
|
+
if (parsed.values.list === true) {
|
|
2111
|
+
if (json)
|
|
2112
|
+
printJson(steps.map(({ label, command, source, placement }) => ({ name: label, command, source, ...placement === undefined ? {} : { in: placement.service } })));
|
|
2113
|
+
else
|
|
2114
|
+
console.log(table(steps.map((step) => [step.label, step.command, step.source, step.placement?.service ?? "host"])));
|
|
2115
|
+
return 0;
|
|
2116
|
+
}
|
|
2117
|
+
if (parsed.values.slot === true && Bun.which("slot", { PATH: process10.env.PATH ?? "" }) === null)
|
|
2118
|
+
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2119
|
+
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2120
|
+
const directory = await logDirectory(cwd);
|
|
2121
|
+
const held = holdSignals();
|
|
2122
|
+
const stack = new Stack;
|
|
2123
|
+
const width = Math.max(...steps.map((step) => step.label.length));
|
|
2124
|
+
const outcomes = [];
|
|
2125
|
+
try {
|
|
2126
|
+
for (const step of steps) {
|
|
2127
|
+
const logFile = join5(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2128
|
+
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2129
|
+
const command = parsed.values.slot === true ? slotted(launch(step)) : launch(step);
|
|
2130
|
+
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held }) : await refusedStep(down, logFile);
|
|
2131
|
+
if (!json)
|
|
2132
|
+
printOutcome(step.label, width, step.placement === undefined ? step.command : `${step.command} (in ${step.placement.service})`, logFile, outcome);
|
|
2133
|
+
outcomes.push(outcomeJson(step.label, step.command, logFile, outcome, step.placement?.service));
|
|
2134
|
+
if (held.signal !== undefined)
|
|
2135
|
+
break;
|
|
2136
|
+
}
|
|
2137
|
+
} finally {
|
|
2138
|
+
held.release();
|
|
2139
|
+
}
|
|
2140
|
+
if (json)
|
|
2141
|
+
printJson(outcomes);
|
|
2142
|
+
if (held.signal !== undefined)
|
|
2143
|
+
return exitCodeOf(null, held.signal);
|
|
2144
|
+
if (outcomes.some((outcome) => outcome.timedOut === true))
|
|
2145
|
+
return 2;
|
|
2146
|
+
return outcomes.every((outcome) => outcome.ok) ? 0 : 1;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// src/cli.ts
|
|
2150
|
+
process11.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|