@kaynooo/cli-check 0.22.2 → 0.22.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6wcnr992.js +5 -0
- package/dist/chunk-98tbscp4.js +8 -0
- package/dist/chunk-ef4tt9f7.js +10 -0
- package/dist/chunk-m3r6m4gc.js +76 -0
- package/dist/chunk-x48y9p19.js +2 -0
- package/dist/chunk-ykfkfr0c.js +3 -0
- package/dist/cli.js +5 -2675
- package/dist/errs-cli.js +4 -2728
- package/dist/j-cli.js +17 -3453
- package/package.json +15 -8
package/dist/errs-cli.js
CHANGED
|
@@ -1,2736 +1,12 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
|
-
var __esm = (fn, res, err) => () => {
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
res = fn(fn = 0);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
err = [e];
|
|
9
|
-
}
|
|
10
|
-
if (err)
|
|
11
|
-
throw err[0];
|
|
12
|
-
return res;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
-
function Ao(t, e, r = "...") {
|
|
17
|
-
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
18
|
-
if (t.length <= e)
|
|
19
|
-
return t;
|
|
20
|
-
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
21
|
-
if (o && !Y.test(t[c.length] ?? " "))
|
|
22
|
-
c = c.replace(Nt, "") || c;
|
|
23
|
-
if (o)
|
|
24
|
-
c = c.trimEnd();
|
|
25
|
-
return s ? (c + n).slice(0, l) : c + n;
|
|
26
|
-
}
|
|
27
|
-
var N, Nt, Y, be, W;
|
|
28
|
-
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
-
N = new Map;
|
|
30
|
-
Nt = /\s+\S*$/;
|
|
31
|
-
Y = /\s/;
|
|
32
|
-
be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
33
|
-
W = new Map;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
-
var init_text = __esm(() => {
|
|
38
|
-
init_chunk_rkhsft4a();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ../kit/src/mode.ts
|
|
42
|
-
import process2 from "process";
|
|
43
|
-
function isSet(value) {
|
|
44
|
-
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
45
|
-
}
|
|
46
|
-
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
47
|
-
const chosen = env.KIT_MODE;
|
|
48
|
-
if (chosen !== undefined && MODES.has(chosen))
|
|
49
|
-
return chosen;
|
|
50
|
-
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
51
|
-
return "agent";
|
|
52
|
-
if (stream.isTTY === true)
|
|
53
|
-
return "terminal";
|
|
54
|
-
return isSet(env.CI) ? "ci" : "pipe";
|
|
55
|
-
}
|
|
56
|
-
function isInteractive(streams = process2) {
|
|
57
|
-
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
58
|
-
}
|
|
59
|
-
var MODES, AGENT_VARIABLES;
|
|
60
|
-
var init_mode = __esm(() => {
|
|
61
|
-
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
-
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
66
|
-
function b(r) {
|
|
67
|
-
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
68
|
-
if (!G2.test(e))
|
|
69
|
-
return [0, 0, 0];
|
|
70
|
-
if (e.length === 3 || e.length === 4)
|
|
71
|
-
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
72
|
-
if (e.length !== 6 && e.length !== 8)
|
|
73
|
-
throw Error(`Invalid hex color length: ${e.length}`);
|
|
74
|
-
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
75
|
-
}
|
|
76
|
-
function C(r, e = globalThis.process?.env ?? {}) {
|
|
77
|
-
if (e.FORCE_COLOR !== undefined)
|
|
78
|
-
return h.has(e.FORCE_COLOR);
|
|
79
|
-
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
80
|
-
return false;
|
|
81
|
-
return r?.isTTY === true;
|
|
82
|
-
}
|
|
83
|
-
function f(r, e = []) {
|
|
84
|
-
let l = "", n = "";
|
|
85
|
-
for (let t = 0, i = e.length;t < i; t++)
|
|
86
|
-
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
87
|
-
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
88
|
-
return new Proxy(c, { get(t, i) {
|
|
89
|
-
let a = B[i];
|
|
90
|
-
if (Array.isArray(a)) {
|
|
91
|
-
let s = g.get(i);
|
|
92
|
-
if (s === undefined)
|
|
93
|
-
s = f(r, [...e, a]), g.set(i, s);
|
|
94
|
-
return s;
|
|
95
|
-
}
|
|
96
|
-
if (typeof a === "function")
|
|
97
|
-
return (...s) => {
|
|
98
|
-
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
99
|
-
if (u === undefined) {
|
|
100
|
-
if (g.size >= 64)
|
|
101
|
-
g.clear();
|
|
102
|
-
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
103
|
-
}
|
|
104
|
-
return u;
|
|
105
|
-
};
|
|
106
|
-
throw Error(`Unknown style: ${String(i)}`);
|
|
107
|
-
} });
|
|
108
|
-
}
|
|
109
|
-
function Fe(r = {}) {
|
|
110
|
-
return f(r);
|
|
111
|
-
}
|
|
112
|
-
var G2, B, h, o;
|
|
113
|
-
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
-
G2 = /^[a-f0-9]+$/i;
|
|
115
|
-
B = { 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, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
116
|
-
let [l, n, c] = b(r);
|
|
117
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
-
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
-
o = Fe();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
-
var init_colors = __esm(() => {
|
|
125
|
-
init_chunk_x450vn3m();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// ../kit/src/config.ts
|
|
129
|
-
import { existsSync } from "fs";
|
|
130
|
-
import { dirname, join, resolve } from "path";
|
|
131
|
-
import process3 from "process";
|
|
132
|
-
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
133
|
-
const wanted = typeof names === "string" ? [names] : names;
|
|
134
|
-
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
135
|
-
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
136
|
-
if (found !== undefined)
|
|
137
|
-
return found;
|
|
138
|
-
if (stop(dir) || dirname(dir) === dir)
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
var init_config = __esm(() => {
|
|
143
|
-
init_args();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// ../kit/src/user-config.ts
|
|
147
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
148
|
-
import { homedir } from "os";
|
|
149
|
-
import { isAbsolute, join as join2 } from "path";
|
|
150
|
-
import process4 from "process";
|
|
151
|
-
function xdgFolder(value, fallback) {
|
|
152
|
-
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
153
|
-
}
|
|
154
|
-
function configBase(where = {}) {
|
|
155
|
-
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
156
|
-
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
157
|
-
}
|
|
158
|
-
function userConfigPath(bin, where = {}) {
|
|
159
|
-
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
160
|
-
}
|
|
161
|
-
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
-
const current = userConfigPath(bin, where);
|
|
163
|
-
if (existsSync2(current))
|
|
164
|
-
return current;
|
|
165
|
-
const base = configBase(where);
|
|
166
|
-
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
-
}
|
|
168
|
-
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
-
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
-
if (!existsSync2(path))
|
|
171
|
-
return {};
|
|
172
|
-
try {
|
|
173
|
-
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
-
} catch {
|
|
176
|
-
return {};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
var init_user_config = () => {};
|
|
180
|
-
|
|
181
|
-
// ../kit/src/theme.ts
|
|
182
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
183
|
-
import { homedir as homedir2 } from "os";
|
|
184
|
-
import { join as join3, resolve as resolve2 } from "path";
|
|
185
|
-
import process5 from "process";
|
|
186
|
-
function isColorSpec(spec) {
|
|
187
|
-
if (typeof spec === "number")
|
|
188
|
-
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
189
|
-
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
190
|
-
}
|
|
191
|
-
function cubeLevel(channel) {
|
|
192
|
-
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
193
|
-
}
|
|
194
|
-
function nearest256(hex) {
|
|
195
|
-
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
196
|
-
const levels = rgb.map(cubeLevel);
|
|
197
|
-
const cube = levels.map((level) => CUBE[level]);
|
|
198
|
-
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
199
|
-
const greyValue = 8 + grey * 10;
|
|
200
|
-
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
201
|
-
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
202
|
-
}
|
|
203
|
-
function hasTrueColor(env) {
|
|
204
|
-
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
205
|
-
}
|
|
206
|
-
function tinted(colors, spec, env = process5.env) {
|
|
207
|
-
if (typeof spec === "number")
|
|
208
|
-
return colors.ansi256(spec);
|
|
209
|
-
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
210
|
-
if (HEX.test(token))
|
|
211
|
-
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
212
|
-
return chain[token] ?? chain;
|
|
213
|
-
}, colors);
|
|
214
|
-
}
|
|
215
|
-
function isRecord(value) {
|
|
216
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
217
|
-
}
|
|
218
|
-
function readThemeFile(path, warn) {
|
|
219
|
-
try {
|
|
220
|
-
const stat = statSync(path, { throwIfNoEntry: false });
|
|
221
|
-
if (stat === undefined)
|
|
222
|
-
return;
|
|
223
|
-
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
224
|
-
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
228
|
-
if (isRecord(parsed))
|
|
229
|
-
return parsed;
|
|
230
|
-
warn(`${path} is not a JSON object, theme ignored`);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
function applyPreset(theme, name, warn, where) {
|
|
237
|
-
if (name === undefined)
|
|
238
|
-
return;
|
|
239
|
-
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
240
|
-
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const preset = PRESETS[name];
|
|
244
|
-
Object.assign(theme.colors, preset.colors);
|
|
245
|
-
Object.assign(theme.glyphs, preset.glyphs);
|
|
246
|
-
if (preset.accents !== undefined)
|
|
247
|
-
theme.accents = [...preset.accents];
|
|
248
|
-
if (Object.hasOwn(preset, "gradient"))
|
|
249
|
-
theme.gradient = preset.gradient;
|
|
250
|
-
return name;
|
|
251
|
-
}
|
|
252
|
-
function applyFile(theme, file, where, warn) {
|
|
253
|
-
if (isRecord(file.colors)) {
|
|
254
|
-
for (const [key, value] of Object.entries(file.colors)) {
|
|
255
|
-
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
256
|
-
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
257
|
-
else if (!isColorSpec(value))
|
|
258
|
-
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
259
|
-
else
|
|
260
|
-
theme.colors[key] = value;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (isRecord(file.glyphs)) {
|
|
264
|
-
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
265
|
-
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
266
|
-
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
267
|
-
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
268
|
-
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
269
|
-
else
|
|
270
|
-
theme.glyphs[key] = value;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
274
|
-
theme.accents = [...file.accents];
|
|
275
|
-
else if (file.accents !== undefined)
|
|
276
|
-
warn(`${where}: accents must be a non-empty list of colours`);
|
|
277
|
-
if (file.gradient === null)
|
|
278
|
-
theme.gradient = undefined;
|
|
279
|
-
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
280
|
-
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
281
|
-
else if (file.gradient !== undefined)
|
|
282
|
-
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
283
|
-
if (isRecord(file.bins)) {
|
|
284
|
-
for (const [bin, value] of Object.entries(file.bins)) {
|
|
285
|
-
if (isColorSpec(value))
|
|
286
|
-
theme.bins[bin] = value;
|
|
287
|
-
else
|
|
288
|
-
warn(`${where}: bin ${bin} has no valid colour`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function endsWalk(home) {
|
|
293
|
-
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
294
|
-
}
|
|
295
|
-
function warnOnce(message) {
|
|
296
|
-
if (warned.has(message))
|
|
297
|
-
return;
|
|
298
|
-
warned.add(message);
|
|
299
|
-
console.error(`warning: theme ${message}`);
|
|
300
|
-
}
|
|
301
|
-
function isPath(chosen) {
|
|
302
|
-
return chosen.includes("/") || chosen.endsWith(".json");
|
|
303
|
-
}
|
|
304
|
-
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
305
|
-
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
306
|
-
const sources = [];
|
|
307
|
-
const chosen = env.KIT_THEME ?? "";
|
|
308
|
-
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
309
|
-
if (isPath(chosen))
|
|
310
|
-
wanted.push(resolve2(from, chosen));
|
|
311
|
-
const files = [];
|
|
312
|
-
for (const path of wanted) {
|
|
313
|
-
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
314
|
-
if (path !== undefined && file !== undefined)
|
|
315
|
-
files.push({ path, file });
|
|
316
|
-
}
|
|
317
|
-
let preset = "default";
|
|
318
|
-
if (chosen !== "" && !isPath(chosen)) {
|
|
319
|
-
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
320
|
-
} else {
|
|
321
|
-
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
322
|
-
if (named !== undefined)
|
|
323
|
-
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
324
|
-
}
|
|
325
|
-
for (const { path, file } of files) {
|
|
326
|
-
applyFile(theme, file, path, warn);
|
|
327
|
-
sources.push(path);
|
|
328
|
-
}
|
|
329
|
-
return { theme, sources, preset };
|
|
330
|
-
}
|
|
331
|
-
function activeTheme() {
|
|
332
|
-
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
333
|
-
if (current === undefined || key !== currentKey) {
|
|
334
|
-
current = loadTheme();
|
|
335
|
-
currentKey = key;
|
|
336
|
-
}
|
|
337
|
-
return current;
|
|
338
|
-
}
|
|
339
|
-
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
340
|
-
var init_theme = __esm(() => {
|
|
341
|
-
init_config();
|
|
342
|
-
init_user_config();
|
|
343
|
-
ENDS = new Map;
|
|
344
|
-
DEFAULT = {
|
|
345
|
-
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
346
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
347
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
348
|
-
bins: {},
|
|
349
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
350
|
-
};
|
|
351
|
-
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
352
|
-
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
353
|
-
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
354
|
-
PRESETS = {
|
|
355
|
-
default: {},
|
|
356
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
357
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
358
|
-
ascii: { glyphs: ASCII }
|
|
359
|
-
};
|
|
360
|
-
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
361
|
-
HEX = /^#[0-9a-f]{6}$/i;
|
|
362
|
-
CONTROL = /\p{Cc}/u;
|
|
363
|
-
MAX_FILE_BYTES = 64 * 1024;
|
|
364
|
-
SPACES = /\s+/;
|
|
365
|
-
CUBE = [0, 95, 135, 175, 215, 255];
|
|
366
|
-
warned = new Set;
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
// ../kit/src/style.ts
|
|
370
|
-
import process6 from "process";
|
|
371
|
-
function takesControlCodes(stream, env = process6.env) {
|
|
372
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
373
|
-
}
|
|
374
|
-
function paint(stream, env = process6.env) {
|
|
375
|
-
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
376
|
-
}
|
|
377
|
-
function marked(mark, text, stream, detail, env = process6.env) {
|
|
378
|
-
const colors = paint(stream, env);
|
|
379
|
-
let head = MARK_WORDS[mark];
|
|
380
|
-
if (takesControlCodes(stream, env)) {
|
|
381
|
-
const { theme } = activeTheme();
|
|
382
|
-
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
383
|
-
}
|
|
384
|
-
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
385
|
-
}
|
|
386
|
-
function warn(text, detail) {
|
|
387
|
-
console.error(marked("warn", text, process6.stderr, detail));
|
|
388
|
-
}
|
|
389
|
-
function role(name, stream, env = process6.env) {
|
|
390
|
-
const colors = paint(stream, env);
|
|
391
|
-
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
392
|
-
}
|
|
393
|
-
function header(bin, context, stream, env = process6.env) {
|
|
394
|
-
if (!takesControlCodes(stream, env))
|
|
395
|
-
return "";
|
|
396
|
-
const colors = paint(stream, env);
|
|
397
|
-
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
398
|
-
const { theme } = activeTheme();
|
|
399
|
-
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
400
|
-
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
401
|
-
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
402
|
-
}
|
|
403
|
-
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
404
|
-
var init_style = __esm(() => {
|
|
405
|
-
init_colors();
|
|
406
|
-
init_mode();
|
|
407
|
-
init_theme();
|
|
408
|
-
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
409
|
-
STATUS_WORDS = {
|
|
410
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
411
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
412
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
413
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
414
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
415
|
-
};
|
|
416
|
-
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
// ../kit/src/format.ts
|
|
420
|
-
import process7 from "process";
|
|
421
|
-
function formatSeconds(total) {
|
|
422
|
-
let rest = Math.max(0, Math.round(total));
|
|
423
|
-
const amounts = UNITS.map(([unit, size]) => {
|
|
424
|
-
const amount = Math.floor(rest / size);
|
|
425
|
-
rest -= amount * size;
|
|
426
|
-
return `${amount}${unit}`;
|
|
427
|
-
});
|
|
428
|
-
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
429
|
-
if (first === -1)
|
|
430
|
-
return "0s";
|
|
431
|
-
const next = amounts[first + 1];
|
|
432
|
-
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
433
|
-
}
|
|
434
|
-
function formatDuration(ms) {
|
|
435
|
-
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
436
|
-
}
|
|
437
|
-
function upTo(text, separator) {
|
|
438
|
-
const end = text.indexOf(separator);
|
|
439
|
-
return end === -1 ? text : text.slice(0, end);
|
|
440
|
-
}
|
|
441
|
-
function truncate(text, width) {
|
|
442
|
-
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
443
|
-
}
|
|
444
|
-
function textWidth(text) {
|
|
445
|
-
return Bun.stringWidth(text);
|
|
446
|
-
}
|
|
447
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
448
|
-
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
449
|
-
if (outputMode(stream, env) === "agent")
|
|
450
|
-
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
451
|
-
`);
|
|
452
|
-
const widths = [];
|
|
453
|
-
for (const row of cells) {
|
|
454
|
-
for (const [index, cell] of row.entries())
|
|
455
|
-
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
456
|
-
}
|
|
457
|
-
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
458
|
-
const colors = paint(stream);
|
|
459
|
-
const lines = shown.map((row) => row.map((cell, index) => {
|
|
460
|
-
const width = widths[index] ?? 0;
|
|
461
|
-
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
462
|
-
if (align[index] === "right")
|
|
463
|
-
return `${gap}${cell}`;
|
|
464
|
-
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
465
|
-
}).join(" ").trimEnd());
|
|
466
|
-
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
467
|
-
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
468
|
-
`);
|
|
469
|
-
}
|
|
470
|
-
function narrow(rows, widths, limit) {
|
|
471
|
-
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
472
|
-
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
473
|
-
const floor = 8;
|
|
474
|
-
while (used() > limit) {
|
|
475
|
-
let widest = -1;
|
|
476
|
-
for (const [index, width] of widths.entries()) {
|
|
477
|
-
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
478
|
-
widest = index;
|
|
479
|
-
}
|
|
480
|
-
if (widest === -1)
|
|
481
|
-
break;
|
|
482
|
-
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
483
|
-
}
|
|
484
|
-
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
485
|
-
}
|
|
486
|
-
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
487
|
-
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
488
|
-
}
|
|
489
|
-
function printJson(value) {
|
|
490
|
-
console.log(jsonText(value));
|
|
491
|
-
}
|
|
492
|
-
var UNITS, LINE_BREAKS, ESCAPE;
|
|
493
|
-
var init_format = __esm(() => {
|
|
494
|
-
init_text();
|
|
495
|
-
init_mode();
|
|
496
|
-
init_style();
|
|
497
|
-
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
498
|
-
LINE_BREAKS = /\s*\n\s*/g;
|
|
499
|
-
ESCAPE = String.fromCharCode(27);
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
// ../kit/src/help.ts
|
|
503
|
-
import process8 from "process";
|
|
504
|
-
function usageLine(usage, colors = paint(process8.stdout), { summary: withSummary = true } = {}) {
|
|
505
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
506
|
-
`);
|
|
507
|
-
const blank = lines.indexOf("");
|
|
508
|
-
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
509
|
-
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
510
|
-
const colon = synopses[0].indexOf(": ");
|
|
511
|
-
const inline = synopses[0].slice(colon + 2);
|
|
512
|
-
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
513
|
-
if (colon !== -1)
|
|
514
|
-
synopses[0] = synopses[0].slice(0, colon);
|
|
515
|
-
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
516
|
-
`)}`;
|
|
517
|
-
const lead = summary === undefined || !withSummary ? [] : ["", colors.bold(prose(summary, colors))];
|
|
518
|
-
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
519
|
-
return [head, ...lead, ...rest].join(`
|
|
520
|
-
`);
|
|
521
|
-
}
|
|
522
|
-
function prose(line, colors) {
|
|
523
|
-
if (colors.cyan("x") === "x")
|
|
524
|
-
return line;
|
|
525
|
-
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
526
|
-
}
|
|
527
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [], bin } = {}) {
|
|
528
|
-
const { summary } = description(usage);
|
|
529
|
-
const head = bin === undefined ? [usageLine(usage, colors)] : [`${colors.bold(bin.name)} ${colors.dim(bin.version())}${summary === "" ? "" : ` ${summary}`}`, "", usageLine(usage, colors, { summary: false })];
|
|
530
|
-
return [...head, "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
531
|
-
`);
|
|
532
|
-
}
|
|
533
|
-
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
534
|
-
if (exits.length === 0)
|
|
535
|
-
return [];
|
|
536
|
-
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
537
|
-
}
|
|
538
|
-
function wantsHelpJson(env = process8.env) {
|
|
539
|
-
return env.KIT_HELP === "json";
|
|
540
|
-
}
|
|
541
|
-
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
542
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
543
|
-
`);
|
|
544
|
-
const first = lines[0];
|
|
545
|
-
const colon = first.indexOf(": ");
|
|
546
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
547
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
548
|
-
return {
|
|
549
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
550
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
551
|
-
...replaces === undefined ? {} : { replaces },
|
|
552
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
553
|
-
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
554
|
-
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
558
|
-
if (examples.length === 0 || outputMode() === "agent")
|
|
559
|
-
return [];
|
|
560
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
561
|
-
}
|
|
562
|
-
function optionRows(options, colors = paint(process8.stdout)) {
|
|
563
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
564
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
565
|
-
const choices = option.choices?.join("|");
|
|
566
|
-
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
567
|
-
const named = inline ? `<${choices}>` : "<value>";
|
|
568
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
569
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
570
|
-
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
571
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
572
|
-
});
|
|
573
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
574
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
575
|
-
}
|
|
576
|
-
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
577
|
-
var init_help = __esm(() => {
|
|
578
|
-
init_mode();
|
|
579
|
-
init_style();
|
|
580
|
-
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
581
|
-
USAGE_PREFIX = /^usage:\s*/i;
|
|
582
|
-
FULL_STOP = /\.$/;
|
|
583
|
-
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
// ../kit/src/text.ts
|
|
587
|
-
function stripAnsi(text) {
|
|
588
|
-
return text.replace(ANSI, "");
|
|
589
|
-
}
|
|
590
|
-
function distance(a, b) {
|
|
591
|
-
const left = [...a];
|
|
592
|
-
const right = [...b];
|
|
593
|
-
let before = [];
|
|
594
|
-
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
595
|
-
for (const [i, x] of left.entries()) {
|
|
596
|
-
const current = [i + 1];
|
|
597
|
-
for (const [j, y] of right.entries()) {
|
|
598
|
-
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
599
|
-
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
600
|
-
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
601
|
-
current.push(cost);
|
|
602
|
-
}
|
|
603
|
-
before = previous;
|
|
604
|
-
previous = current;
|
|
605
|
-
}
|
|
606
|
-
return previous[right.length] ?? 0;
|
|
607
|
-
}
|
|
608
|
-
function closest(name, names) {
|
|
609
|
-
const started = names.find((known) => known.startsWith(name));
|
|
610
|
-
if (started !== undefined)
|
|
611
|
-
return started;
|
|
612
|
-
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
613
|
-
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
614
|
-
}
|
|
615
|
-
var ANSI;
|
|
616
|
-
var init_text2 = __esm(() => {
|
|
617
|
-
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
// ../kit/src/input.ts
|
|
621
|
-
import process9 from "process";
|
|
622
|
-
function durationMs(text, unit) {
|
|
623
|
-
if (BARE_DURATION.test(text))
|
|
624
|
-
return Number(text) * UNIT_MS[unit];
|
|
625
|
-
if (!DURATION.test(text))
|
|
626
|
-
return 0;
|
|
627
|
-
let ms = 0;
|
|
628
|
-
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
629
|
-
ms += Number(amount) * UNIT_MS[part];
|
|
630
|
-
return ms;
|
|
631
|
-
}
|
|
632
|
-
function duration(value, name, fallback, unit = "s") {
|
|
633
|
-
if (value === undefined)
|
|
634
|
-
return fallback;
|
|
635
|
-
const ms = durationMs(value.trim(), unit);
|
|
636
|
-
if (ms < 1)
|
|
637
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
638
|
-
return ms;
|
|
639
|
-
}
|
|
640
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
641
|
-
if (path === "-") {
|
|
642
|
-
if (process9.stdin.isTTY)
|
|
643
|
-
fail(noStdin);
|
|
644
|
-
return Bun.stdin.text();
|
|
645
|
-
}
|
|
646
|
-
const file = Bun.file(path);
|
|
647
|
-
if (!await file.exists())
|
|
648
|
-
fail(`no file ${path}`);
|
|
649
|
-
return file.text();
|
|
650
|
-
}
|
|
651
|
-
var BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
652
|
-
var init_input = __esm(() => {
|
|
653
|
-
init_args();
|
|
654
|
-
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
655
|
-
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
656
|
-
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
657
|
-
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
// ../kit/src/args.ts
|
|
661
|
-
import process10 from "process";
|
|
662
|
-
import { parseArgs } from "util";
|
|
663
|
-
function jsonOption(holds) {
|
|
664
|
-
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
665
|
-
}
|
|
666
|
-
function fail(message, code = 2, hint) {
|
|
667
|
-
throw new Exit(message, code, hint);
|
|
668
|
-
}
|
|
669
|
-
function badUsage(message) {
|
|
670
|
-
throw new UsageError(message);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
class Completing {
|
|
674
|
-
options;
|
|
675
|
-
positionals;
|
|
676
|
-
candidates;
|
|
677
|
-
constructor(options, positionals = [], candidates = {}) {
|
|
678
|
-
this.options = options;
|
|
679
|
-
this.positionals = positionals;
|
|
680
|
-
this.candidates = candidates;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
function applyOutput(color, plain, env = process10.env) {
|
|
684
|
-
const when = plain === true ? "never" : color ?? "auto";
|
|
685
|
-
if (when === "auto")
|
|
686
|
-
return;
|
|
687
|
-
if (when !== "always" && when !== "never")
|
|
688
|
-
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
689
|
-
if (when === "always") {
|
|
690
|
-
env.FORCE_COLOR = "1";
|
|
691
|
-
delete env.NO_COLOR;
|
|
692
|
-
} else {
|
|
693
|
-
env.NO_COLOR = "1";
|
|
694
|
-
delete env.FORCE_COLOR;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
function parse(args, usage, options, settings = {}) {
|
|
698
|
-
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
699
|
-
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
700
|
-
const listing = listed(all, settings.allowNegative === true);
|
|
701
|
-
if (completion.active)
|
|
702
|
-
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
703
|
-
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
704
|
-
let parsed;
|
|
705
|
-
try {
|
|
706
|
-
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
707
|
-
} catch (error) {
|
|
708
|
-
const message = parseError(error);
|
|
709
|
-
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
710
|
-
}
|
|
711
|
-
const values = parsed.values;
|
|
712
|
-
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
713
|
-
if (values.help === true) {
|
|
714
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, { ...settings, bin: heading.bin }));
|
|
715
|
-
throw new HelpShown;
|
|
716
|
-
}
|
|
717
|
-
checkChoices(parsed.values, all);
|
|
718
|
-
checkConflicts(parsed.values, all);
|
|
719
|
-
if (settings.positionals !== undefined)
|
|
720
|
-
checkPositionals(parsed.positionals, settings.positionals);
|
|
721
|
-
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
722
|
-
}
|
|
723
|
-
function splitRest(args, passes) {
|
|
724
|
-
const separator = passes ? args.indexOf("--") : -1;
|
|
725
|
-
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
726
|
-
}
|
|
727
|
-
function splitTrailing(args, options, count) {
|
|
728
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
729
|
-
let seen = 0;
|
|
730
|
-
if (count === 0)
|
|
731
|
-
return { own: args, rest: undefined };
|
|
732
|
-
for (let at = 0;at < args.length; at++) {
|
|
733
|
-
const word = args[at];
|
|
734
|
-
if (word === "--")
|
|
735
|
-
break;
|
|
736
|
-
if (word.startsWith("-")) {
|
|
737
|
-
if (takesValue(word))
|
|
738
|
-
at++;
|
|
739
|
-
continue;
|
|
740
|
-
}
|
|
741
|
-
seen++;
|
|
742
|
-
if (seen === count)
|
|
743
|
-
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
744
|
-
}
|
|
745
|
-
return { own: args, rest: undefined };
|
|
746
|
-
}
|
|
747
|
-
function listed(options, allowNegative) {
|
|
748
|
-
if (!allowNegative)
|
|
749
|
-
return options;
|
|
750
|
-
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
751
|
-
if (option.type !== "boolean" || option.negative === undefined)
|
|
752
|
-
return [[name, option]];
|
|
753
|
-
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
754
|
-
}));
|
|
755
|
-
}
|
|
756
|
-
function withAliases(args, options) {
|
|
757
|
-
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
758
|
-
if (named.size === 0)
|
|
759
|
-
return args;
|
|
760
|
-
const separator = args.indexOf("--");
|
|
761
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
762
|
-
return [...own.map((arg) => {
|
|
763
|
-
const at = arg.indexOf("=");
|
|
764
|
-
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
765
|
-
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
766
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
767
|
-
}
|
|
768
|
-
function withBare(args, options) {
|
|
769
|
-
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
770
|
-
if (bare.size === 0)
|
|
771
|
-
return args;
|
|
772
|
-
const separator = args.indexOf("--");
|
|
773
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
774
|
-
return [...own.flatMap((arg, index) => {
|
|
775
|
-
const optional = bare.get(arg);
|
|
776
|
-
const next = own[index + 1];
|
|
777
|
-
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
778
|
-
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
779
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
780
|
-
}
|
|
781
|
-
function checkConflicts(values, options) {
|
|
782
|
-
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
783
|
-
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
784
|
-
const other = given(name) ? conflicts.find(given) : undefined;
|
|
785
|
-
if (other !== undefined)
|
|
786
|
-
badUsage(`--${name} cannot be used with --${other}`);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function checkChoices(values, options) {
|
|
790
|
-
for (const [name, option] of Object.entries(options)) {
|
|
791
|
-
if (option.choices === undefined)
|
|
792
|
-
continue;
|
|
793
|
-
const given = values[name];
|
|
794
|
-
for (const value of Array.isArray(given) ? given : [given]) {
|
|
795
|
-
if (typeof value === "string")
|
|
796
|
-
oneOf(value, name, option.choices);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
function oneOf(value, name, choices) {
|
|
801
|
-
if (!choices.includes(value))
|
|
802
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
803
|
-
return value;
|
|
804
|
-
}
|
|
805
|
-
function checkPositionals(given, names) {
|
|
806
|
-
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
807
|
-
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
808
|
-
if (given.length < required)
|
|
809
|
-
badUsage(`missing ${names[given.length]}`);
|
|
810
|
-
if (!variadic && given.length > names.length)
|
|
811
|
-
badUsage(`unexpected argument ${given[names.length]}`);
|
|
812
|
-
}
|
|
813
|
-
function joinDashValues(args, options) {
|
|
814
|
-
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
815
|
-
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
816
|
-
const joined = [];
|
|
817
|
-
for (let i = 0;i < args.length; i++) {
|
|
818
|
-
const arg = args[i] ?? "";
|
|
819
|
-
if (arg === "--")
|
|
820
|
-
return [...joined, ...args.slice(i)];
|
|
821
|
-
const name = longOf.get(arg);
|
|
822
|
-
const next = args[i + 1];
|
|
823
|
-
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
824
|
-
joined.push(`--${name}=${next}`);
|
|
825
|
-
i++;
|
|
826
|
-
} else {
|
|
827
|
-
joined.push(arg);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
return joined;
|
|
831
|
-
}
|
|
832
|
-
function parseError(error) {
|
|
833
|
-
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
834
|
-
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
835
|
-
}
|
|
836
|
-
function nearestOption(message, options, allowNegative) {
|
|
837
|
-
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
838
|
-
if (typed === undefined)
|
|
839
|
-
return;
|
|
840
|
-
const word = typed.replace(DASHES, "");
|
|
841
|
-
if (word.length < 2 && !typed.startsWith("--"))
|
|
842
|
-
return;
|
|
843
|
-
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
844
|
-
...option.short === undefined ? [] : [`-${option.short}`],
|
|
845
|
-
`--${name}`,
|
|
846
|
-
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
847
|
-
]);
|
|
848
|
-
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
849
|
-
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
850
|
-
}
|
|
851
|
-
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, heading, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
852
|
-
var init_args = __esm(() => {
|
|
853
|
-
init_format();
|
|
854
|
-
init_help();
|
|
855
|
-
init_text2();
|
|
856
|
-
init_help();
|
|
857
|
-
init_input();
|
|
858
|
-
DASHES = /^-+/;
|
|
859
|
-
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
860
|
-
Exit = class Exit extends Error {
|
|
861
|
-
code;
|
|
862
|
-
hint;
|
|
863
|
-
[EXIT] = true;
|
|
864
|
-
constructor(message, code, hint) {
|
|
865
|
-
super(message);
|
|
866
|
-
this.code = code;
|
|
867
|
-
this.hint = hint;
|
|
868
|
-
}
|
|
869
|
-
static [Symbol.hasInstance](value) {
|
|
870
|
-
if (this !== Exit)
|
|
871
|
-
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
872
|
-
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
|
-
UsageError = class UsageError extends Exit {
|
|
876
|
-
constructor(message, hint) {
|
|
877
|
-
super(message, 2, hint);
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
HelpShown = class HelpShown extends Exit {
|
|
881
|
-
constructor() {
|
|
882
|
-
super("help shown", 0);
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
completion = { active: false };
|
|
886
|
-
heading = { bin: undefined };
|
|
887
|
-
OUTPUT_OPTIONS = {
|
|
888
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
889
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
890
|
-
};
|
|
891
|
-
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
// ../kit/src/folders.ts
|
|
895
|
-
import { homedir as homedir5 } from "os";
|
|
896
|
-
import { join as join7 } from "path";
|
|
897
|
-
import process18 from "process";
|
|
898
|
-
function ignoredFolders(extra = [], where = {}) {
|
|
899
|
-
const configured = readUserConfig("config", where).ignore;
|
|
900
|
-
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
901
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
902
|
-
}
|
|
903
|
-
function cacheFolder({ home = homedir5(), env = process18.env } = {}) {
|
|
904
|
-
return xdgFolder(env.XDG_CACHE_HOME, join7(home, ".cache"));
|
|
905
|
-
}
|
|
906
|
-
var SKIPPED_FOLDERS;
|
|
907
|
-
var init_folders = __esm(() => {
|
|
908
|
-
init_user_config();
|
|
909
|
-
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
// src/errs-cli.ts
|
|
913
|
-
import process23 from "process";
|
|
914
|
-
|
|
915
|
-
// ../kit/src/index.ts
|
|
916
|
-
init_args();
|
|
917
|
-
|
|
918
|
-
// ../kit/src/argv.ts
|
|
919
|
-
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
920
|
-
import { resolve as resolve3 } from "path";
|
|
921
|
-
import process11 from "process";
|
|
922
|
-
function commandLine() {
|
|
923
|
-
try {
|
|
924
|
-
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
925
|
-
} catch {
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
function realPath(word) {
|
|
930
|
-
try {
|
|
931
|
-
return realpathSync(resolve3(word));
|
|
932
|
-
} catch {
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
937
|
-
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
938
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
939
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
940
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
941
|
-
}
|
|
942
|
-
// ../kit/src/chart.ts
|
|
943
|
-
init_format();
|
|
944
|
-
init_mode();
|
|
945
|
-
init_style();
|
|
946
|
-
init_theme();
|
|
947
|
-
// ../kit/src/ci.ts
|
|
948
|
-
init_args();
|
|
949
|
-
init_format();
|
|
950
|
-
|
|
951
|
-
// ../kit/src/progress.ts
|
|
952
|
-
init_format();
|
|
953
|
-
|
|
954
|
-
// ../kit/src/process.ts
|
|
955
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
956
|
-
import { constants } from "os";
|
|
957
|
-
import process12 from "process";
|
|
958
|
-
var KILL_GRACE_MS = 2000;
|
|
959
|
-
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
960
|
-
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
961
|
-
function exitCodeOf(code, signal) {
|
|
962
|
-
if (code !== null)
|
|
963
|
-
return code;
|
|
964
|
-
if (typeof signal === "number")
|
|
965
|
-
return 128 + signal;
|
|
966
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
967
|
-
}
|
|
968
|
-
function groupsOf(pid) {
|
|
969
|
-
try {
|
|
970
|
-
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
971
|
-
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
972
|
-
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
973
|
-
} catch {
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
function heardTheTerminal(child) {
|
|
978
|
-
if (child.pid === undefined)
|
|
979
|
-
return false;
|
|
980
|
-
const own = groupsOf("self");
|
|
981
|
-
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
982
|
-
}
|
|
983
|
-
function holdSignals(cleanup) {
|
|
984
|
-
let received;
|
|
985
|
-
let child;
|
|
986
|
-
const held = {
|
|
987
|
-
get signal() {
|
|
988
|
-
return received;
|
|
989
|
-
},
|
|
990
|
-
forward: (to) => {
|
|
991
|
-
child = to;
|
|
992
|
-
},
|
|
993
|
-
release: () => {
|
|
994
|
-
for (const signal of SIGNALS)
|
|
995
|
-
process12.off(signal, onSignal);
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
function onSignal(signal) {
|
|
999
|
-
received = signal;
|
|
1000
|
-
if (child !== undefined) {
|
|
1001
|
-
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1002
|
-
child.kill(signal);
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
if (cleanup === undefined)
|
|
1006
|
-
return;
|
|
1007
|
-
held.release();
|
|
1008
|
-
cleanup(signal);
|
|
1009
|
-
process12.kill(process12.pid, signal);
|
|
1010
|
-
}
|
|
1011
|
-
for (const signal of SIGNALS)
|
|
1012
|
-
process12.on(signal, onSignal);
|
|
1013
|
-
return held;
|
|
1014
|
-
}
|
|
1015
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1016
|
-
const chunks = [];
|
|
1017
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1018
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1019
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1020
|
-
const timers = [];
|
|
1021
|
-
const killGroup = (killing) => {
|
|
1022
|
-
if (state.done)
|
|
1023
|
-
return;
|
|
1024
|
-
try {
|
|
1025
|
-
if (grouped)
|
|
1026
|
-
process12.kill(-proc.pid, killing);
|
|
1027
|
-
else
|
|
1028
|
-
proc.kill(killing);
|
|
1029
|
-
} catch {}
|
|
1030
|
-
};
|
|
1031
|
-
const stop = () => {
|
|
1032
|
-
killGroup("SIGTERM");
|
|
1033
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1034
|
-
};
|
|
1035
|
-
const onAbort = () => stop();
|
|
1036
|
-
if (timeoutMs !== undefined) {
|
|
1037
|
-
timers.push(setTimeout(() => {
|
|
1038
|
-
state.timedOut = true;
|
|
1039
|
-
stop();
|
|
1040
|
-
}, timeoutMs));
|
|
1041
|
-
}
|
|
1042
|
-
if (signal?.aborted === true)
|
|
1043
|
-
onAbort();
|
|
1044
|
-
else
|
|
1045
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1046
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1047
|
-
const drain = async (stream, name) => {
|
|
1048
|
-
for await (const data of stream) {
|
|
1049
|
-
if (state.failure !== undefined)
|
|
1050
|
-
continue;
|
|
1051
|
-
try {
|
|
1052
|
-
onChunk?.({ stream: name, data });
|
|
1053
|
-
} catch (error) {
|
|
1054
|
-
state.failure = error;
|
|
1055
|
-
stop();
|
|
1056
|
-
continue;
|
|
1057
|
-
}
|
|
1058
|
-
if (state.truncated)
|
|
1059
|
-
continue;
|
|
1060
|
-
let kept = data;
|
|
1061
|
-
if (state.kept + data.length > maxBytes) {
|
|
1062
|
-
let cut = maxBytes - state.kept;
|
|
1063
|
-
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1064
|
-
cut--;
|
|
1065
|
-
kept = data.subarray(0, cut);
|
|
1066
|
-
state.truncated = true;
|
|
1067
|
-
}
|
|
1068
|
-
state.kept += kept.length;
|
|
1069
|
-
if (kept.length > 0)
|
|
1070
|
-
chunks.push({ stream: name, data: kept });
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
try {
|
|
1074
|
-
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1075
|
-
await proc.exited;
|
|
1076
|
-
} finally {
|
|
1077
|
-
state.done = true;
|
|
1078
|
-
for (const timer of timers)
|
|
1079
|
-
clearTimeout(timer);
|
|
1080
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1081
|
-
}
|
|
1082
|
-
if (state.failure !== undefined)
|
|
1083
|
-
throw state.failure;
|
|
1084
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1085
|
-
let output;
|
|
1086
|
-
let text;
|
|
1087
|
-
let stdout;
|
|
1088
|
-
return {
|
|
1089
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1090
|
-
chunks,
|
|
1091
|
-
timedOut: state.timedOut,
|
|
1092
|
-
truncated: state.truncated,
|
|
1093
|
-
get output() {
|
|
1094
|
-
return output ??= joined();
|
|
1095
|
-
},
|
|
1096
|
-
get text() {
|
|
1097
|
-
return text ??= (output ??= joined()).toString();
|
|
1098
|
-
},
|
|
1099
|
-
get stdout() {
|
|
1100
|
-
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1101
|
-
}
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
// ../kit/src/progress.ts
|
|
1106
|
-
init_style();
|
|
1107
|
-
init_theme();
|
|
1108
|
-
var ESC = String.fromCharCode(27);
|
|
1109
|
-
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1110
|
-
var RESET_STYLE = `${ESC}[0m`;
|
|
1111
|
-
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1112
|
-
|
|
1113
|
-
// ../kit/src/ci.ts
|
|
1114
|
-
init_style();
|
|
1115
|
-
|
|
1116
|
-
// ../kit/src/tool.ts
|
|
1117
|
-
init_format();
|
|
1118
|
-
// ../kit/src/cli.ts
|
|
1119
|
-
init_args();
|
|
1120
|
-
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1121
|
-
import { dirname as dirname3, join as join6 } from "path";
|
|
1122
|
-
import process17 from "process";
|
|
1123
|
-
|
|
1124
|
-
// ../kit/src/askpass.ts
|
|
1125
|
-
import process13 from "process";
|
|
1126
|
-
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1127
|
-
async function askpassClient(argv) {
|
|
1128
|
-
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
1129
|
-
if (socketPath === undefined)
|
|
1130
|
-
return;
|
|
1131
|
-
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1132
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
1133
|
-
let received = "";
|
|
1134
|
-
try {
|
|
1135
|
-
await Bun.connect({
|
|
1136
|
-
unix: socketPath,
|
|
1137
|
-
socket: {
|
|
1138
|
-
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1139
|
-
`),
|
|
1140
|
-
data: (_, chunk) => {
|
|
1141
|
-
received += chunk.toString();
|
|
1142
|
-
},
|
|
1143
|
-
close: () => resolve(received),
|
|
1144
|
-
error: () => resolve("")
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
} catch {
|
|
1148
|
-
return 1;
|
|
1149
|
-
}
|
|
1150
|
-
const reply = await promise;
|
|
1151
|
-
if (reply === "")
|
|
1152
|
-
return 1;
|
|
1153
|
-
const { answer } = JSON.parse(reply);
|
|
1154
|
-
if (request.notice === true)
|
|
1155
|
-
return 0;
|
|
1156
|
-
if (answer === undefined)
|
|
1157
|
-
return 1;
|
|
1158
|
-
process13.stdout.write(`${answer}
|
|
1159
|
-
`);
|
|
1160
|
-
return 0;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
// ../kit/src/completions.ts
|
|
1164
|
-
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1165
|
-
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1166
|
-
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1167
|
-
set -l current (commandline -ct)
|
|
1168
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1169
|
-
if test "$line" = __files__
|
|
1170
|
-
__fish_complete_path $current
|
|
1171
|
-
else
|
|
1172
|
-
echo $line
|
|
1173
|
-
end
|
|
1174
|
-
end
|
|
1175
|
-
end`;
|
|
1176
|
-
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1177
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1178
|
-
local -a lines
|
|
1179
|
-
COMPREPLY=()
|
|
1180
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1181
|
-
for line in "\${lines[@]}"; do
|
|
1182
|
-
if [[ $line == __files__ ]]; then
|
|
1183
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1184
|
-
else
|
|
1185
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1186
|
-
fi
|
|
1187
|
-
done
|
|
1188
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1189
|
-
}`;
|
|
1190
|
-
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1191
|
-
local line
|
|
1192
|
-
local -a described plain
|
|
1193
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1194
|
-
if [[ $line == __files__ ]]; then
|
|
1195
|
-
_files
|
|
1196
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
1197
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1198
|
-
else
|
|
1199
|
-
plain+=("$line")
|
|
1200
|
-
fi
|
|
1201
|
-
done
|
|
1202
|
-
(( \${#described} )) && _describe -V value described
|
|
1203
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1204
|
-
return 0
|
|
1205
|
-
}`;
|
|
1206
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1207
|
-
if (shell === "fish")
|
|
1208
|
-
return `${header}
|
|
1209
|
-
${FISH_FUNCTION}
|
|
1210
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1211
|
-
`).join("")}`;
|
|
1212
|
-
if (shell === "bash")
|
|
1213
|
-
return `${header}
|
|
1214
|
-
${BASH_FUNCTION}
|
|
1215
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1216
|
-
`;
|
|
1217
|
-
return `${header}
|
|
1218
|
-
${ZSH_FUNCTION}
|
|
1219
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1220
|
-
`;
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
// ../kit/src/notify.ts
|
|
1224
|
-
init_format();
|
|
1225
|
-
init_mode();
|
|
1226
|
-
import process14 from "process";
|
|
1227
|
-
var NOTIFY_AFTER_MS = 1e4;
|
|
1228
|
-
var CANCELLED = 130;
|
|
1229
|
-
function base64(text) {
|
|
1230
|
-
return Buffer.from(text).toString("base64");
|
|
1231
|
-
}
|
|
1232
|
-
function notification(title, body, env = process14.env) {
|
|
1233
|
-
const id = `kit${process14.pid}`;
|
|
1234
|
-
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1235
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1236
|
-
}
|
|
1237
|
-
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1238
|
-
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1239
|
-
return;
|
|
1240
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
// ../kit/src/cli.ts
|
|
1244
|
-
init_style();
|
|
1245
|
-
init_text2();
|
|
1246
|
-
|
|
1247
|
-
// ../kit/src/usage.ts
|
|
1248
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
1249
|
-
import { homedir as homedir4 } from "os";
|
|
1250
|
-
import { dirname as dirname2, join as join5 } from "path";
|
|
1251
|
-
import process16 from "process";
|
|
1252
|
-
|
|
1253
|
-
// ../kit/src/logs.ts
|
|
1254
|
-
init_user_config();
|
|
1255
|
-
import { lstatSync, openSync } from "fs";
|
|
1256
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
1257
|
-
import { homedir as homedir3, tmpdir } from "os";
|
|
1258
|
-
import { join as join4 } from "path";
|
|
1259
|
-
import process15 from "process";
|
|
1260
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1261
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
1262
|
-
function isPrivateDirectory(path) {
|
|
1263
|
-
try {
|
|
1264
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
1265
|
-
return info !== undefined && info.isDirectory() && info.uid === (process15.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
1266
|
-
} catch {
|
|
1267
|
-
return false;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
async function privateLogDirectory(name, env = process15.env) {
|
|
1271
|
-
const path = join4(xdgFolder(env.XDG_RUNTIME_DIR, join4(homedir3(), ".cache")), CLI_FOLDER, name);
|
|
1272
|
-
try {
|
|
1273
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
1274
|
-
if (isPrivateDirectory(path))
|
|
1275
|
-
return path;
|
|
1276
|
-
} catch {}
|
|
1277
|
-
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
1278
|
-
}
|
|
1279
|
-
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
1280
|
-
let names;
|
|
1281
|
-
try {
|
|
1282
|
-
names = await readdir(dir);
|
|
1283
|
-
} catch {
|
|
1284
|
-
return;
|
|
1285
|
-
}
|
|
1286
|
-
for (const name of names) {
|
|
1287
|
-
const path = join4(dir, name);
|
|
1288
|
-
try {
|
|
1289
|
-
const info = await stat(path);
|
|
1290
|
-
if (info.isDirectory())
|
|
1291
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
1292
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
1293
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1294
|
-
} catch {
|
|
1295
|
-
continue;
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
// ../kit/src/usage.ts
|
|
1301
|
-
init_user_config();
|
|
1302
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1303
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1304
|
-
var LONGEST_NAME = 40;
|
|
1305
|
-
var usageError;
|
|
1306
|
-
function noteUsageError(message) {
|
|
1307
|
-
usageError = message;
|
|
1308
|
-
}
|
|
1309
|
-
function stateHome(env = process16.env) {
|
|
1310
|
-
return xdgFolder(env.XDG_STATE_HOME, join5(homedir4(), ".local", "state"));
|
|
1311
|
-
}
|
|
1312
|
-
function usagePath(env = process16.env) {
|
|
1313
|
-
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1314
|
-
}
|
|
1315
|
-
function usageRecorded(env = process16.env) {
|
|
1316
|
-
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1317
|
-
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1318
|
-
}
|
|
1319
|
-
function flagNames(argv) {
|
|
1320
|
-
const end = argv.indexOf("--");
|
|
1321
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1322
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1323
|
-
}
|
|
1324
|
-
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1325
|
-
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1326
|
-
usageError = undefined;
|
|
1327
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1328
|
-
}
|
|
1329
|
-
function recordUsage(entry, env = process16.env) {
|
|
1330
|
-
if (!usageRecorded(env))
|
|
1331
|
-
return;
|
|
1332
|
-
try {
|
|
1333
|
-
const path = usagePath(env);
|
|
1334
|
-
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1335
|
-
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1336
|
-
`, { mode: 384 });
|
|
1337
|
-
} catch {}
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
// ../kit/src/cli.ts
|
|
1341
|
-
var LEVEL_OPTIONS = {
|
|
1342
|
-
...OUTPUT_OPTIONS,
|
|
1343
|
-
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1344
|
-
};
|
|
1345
|
-
var TOP_OPTIONS = {
|
|
1346
|
-
...LEVEL_OPTIONS,
|
|
1347
|
-
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1348
|
-
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1349
|
-
};
|
|
1350
|
-
function printError(prefix, message, hint, cause) {
|
|
1351
|
-
const colors = paint(process17.stderr);
|
|
1352
|
-
const styled = takesControlCodes(process17.stderr);
|
|
1353
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1354
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1355
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1356
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1357
|
-
}
|
|
1358
|
-
function printJsonError(message, hint, cause) {
|
|
1359
|
-
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1360
|
-
}
|
|
1361
|
-
function wantsJson(argv) {
|
|
1362
|
-
const end = argv.indexOf("--");
|
|
1363
|
-
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1364
|
-
}
|
|
1365
|
-
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1366
|
-
if (error instanceof HelpShown)
|
|
1367
|
-
return 0;
|
|
1368
|
-
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1369
|
-
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1370
|
-
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1371
|
-
if (error instanceof Exit && error.code === 2)
|
|
1372
|
-
noteUsageError(error.message);
|
|
1373
|
-
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1374
|
-
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1375
|
-
return error instanceof Exit ? error.code : 1;
|
|
1376
|
-
}
|
|
1377
|
-
var COMPLETE = "__complete";
|
|
1378
|
-
var FILES = "__files__";
|
|
1379
|
-
async function completingOf(run) {
|
|
1380
|
-
completion.active = true;
|
|
1381
|
-
try {
|
|
1382
|
-
await run([]);
|
|
1383
|
-
} catch (error) {
|
|
1384
|
-
if (error instanceof Completing)
|
|
1385
|
-
return error;
|
|
1386
|
-
} finally {
|
|
1387
|
-
completion.active = false;
|
|
1388
|
-
}
|
|
1389
|
-
return new Completing({});
|
|
1390
|
-
}
|
|
1391
|
-
function candidateLine(candidate) {
|
|
1392
|
-
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1393
|
-
}
|
|
1394
|
-
function positionalBeingTyped(before, { options, positionals }) {
|
|
1395
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1396
|
-
const typed = [];
|
|
1397
|
-
let at = 0;
|
|
1398
|
-
while (at < before.length) {
|
|
1399
|
-
const word = before[at];
|
|
1400
|
-
if (word === "--") {
|
|
1401
|
-
typed.push(...before.slice(at + 1));
|
|
1402
|
-
break;
|
|
1403
|
-
}
|
|
1404
|
-
if (!word.startsWith("-"))
|
|
1405
|
-
typed.push(word);
|
|
1406
|
-
else if (takesValue(word))
|
|
1407
|
-
at++;
|
|
1408
|
-
at++;
|
|
1409
|
-
}
|
|
1410
|
-
const last = positionals.at(-1);
|
|
1411
|
-
if (typed.length < positionals.length)
|
|
1412
|
-
return { name: positionals[typed.length], typed };
|
|
1413
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1414
|
-
}
|
|
1415
|
-
async function leafCandidates(run, words) {
|
|
1416
|
-
const completing = await completingOf(run);
|
|
1417
|
-
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1418
|
-
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1419
|
-
const flag = words.at(-2);
|
|
1420
|
-
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1421
|
-
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1422
|
-
if (option?.type === "string") {
|
|
1423
|
-
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1424
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1425
|
-
}
|
|
1426
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1427
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1428
|
-
}
|
|
1429
|
-
var COMPLETIONS = "--completions";
|
|
1430
|
-
function flagValue([flag = "", ...rest]) {
|
|
1431
|
-
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1432
|
-
}
|
|
1433
|
-
function printCompletionScript(name, args) {
|
|
1434
|
-
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1435
|
-
if (shell === undefined || args.length !== 1) {
|
|
1436
|
-
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1437
|
-
return 2;
|
|
1438
|
-
}
|
|
1439
|
-
console.log(completionScript(shell, [name]).trimEnd());
|
|
1440
|
-
return 0;
|
|
1441
|
-
}
|
|
1442
|
-
async function printCandidates(found) {
|
|
1443
|
-
for (const line of await found)
|
|
1444
|
-
console.log(line);
|
|
1445
|
-
return 0;
|
|
1446
|
-
}
|
|
1447
|
-
function packageVersion(entry = Bun.main) {
|
|
1448
|
-
let resolved = entry;
|
|
1449
|
-
try {
|
|
1450
|
-
resolved = realpathSync2(entry);
|
|
1451
|
-
} catch {}
|
|
1452
|
-
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1453
|
-
try {
|
|
1454
|
-
const { version } = JSON.parse(readFileSync5(join6(dir, "package.json"), "utf8"));
|
|
1455
|
-
if (typeof version === "string")
|
|
1456
|
-
return version;
|
|
1457
|
-
} catch {}
|
|
1458
|
-
if (dirname3(dir) === dir)
|
|
1459
|
-
return "0.0.0";
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1463
|
-
const answered = await askpassClient(argv);
|
|
1464
|
-
if (answered !== undefined)
|
|
1465
|
-
return answered;
|
|
1466
|
-
if (argv[0] === COMPLETE)
|
|
1467
|
-
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1468
|
-
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1469
|
-
return printCompletionScript(name, flagValue(argv));
|
|
1470
|
-
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1471
|
-
console.log(version ?? packageVersion());
|
|
1472
|
-
return 0;
|
|
1473
|
-
}
|
|
1474
|
-
let code;
|
|
1475
|
-
const started = performance.now();
|
|
1476
|
-
heading.bin = { name, version: () => version ?? packageVersion() };
|
|
1477
|
-
try {
|
|
1478
|
-
code = await run(argv);
|
|
1479
|
-
} catch (error) {
|
|
1480
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1481
|
-
} finally {
|
|
1482
|
-
heading.bin = undefined;
|
|
1483
|
-
}
|
|
1484
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1485
|
-
if (usage !== false) {
|
|
1486
|
-
try {
|
|
1487
|
-
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1488
|
-
} catch {}
|
|
1489
|
-
}
|
|
1490
|
-
return code;
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
// ../kit/src/index.ts
|
|
1494
|
-
init_config();
|
|
1495
|
-
|
|
1496
|
-
// ../kit/src/excerpt.ts
|
|
1497
|
-
init_text2();
|
|
1498
|
-
var BASH_ECHO = /^\$ /;
|
|
1499
|
-
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1500
|
-
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1501
|
-
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1502
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1503
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1504
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1505
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1506
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1507
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1508
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1509
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1510
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1511
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1512
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1513
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1514
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1515
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1516
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1517
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1518
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1519
|
-
var MAX_TESTS = 10;
|
|
1520
|
-
var MAX_LINES = 100;
|
|
1521
|
-
var TAIL = 30;
|
|
1522
|
-
var bunTest = (lines) => {
|
|
1523
|
-
const seen = new Set;
|
|
1524
|
-
const blocks = [];
|
|
1525
|
-
for (const [index, line] of lines.entries()) {
|
|
1526
|
-
const name = line.replace(DURATION2, "");
|
|
1527
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1528
|
-
continue;
|
|
1529
|
-
seen.add(name);
|
|
1530
|
-
if (blocks.length < MAX_TESTS)
|
|
1531
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1532
|
-
`).trim());
|
|
1533
|
-
}
|
|
1534
|
-
if (blocks.length === 0)
|
|
1535
|
-
return;
|
|
1536
|
-
if (seen.size > MAX_TESTS)
|
|
1537
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1538
|
-
return [...blocks.join(`
|
|
1539
|
-
|
|
1540
|
-
`).split(`
|
|
1541
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1542
|
-
};
|
|
1543
|
-
var bunCheck = (lines) => {
|
|
1544
|
-
const text = lines.join(`
|
|
1545
|
-
`);
|
|
1546
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1547
|
-
if (blocks === null)
|
|
1548
|
-
return;
|
|
1549
|
-
const errors = blocks.map((block) => {
|
|
1550
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1551
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1552
|
-
});
|
|
1553
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1554
|
-
};
|
|
1555
|
-
function bunCheckFields(block) {
|
|
1556
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1557
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1558
|
-
return {
|
|
1559
|
-
file: attributes.file ?? "",
|
|
1560
|
-
line: attributes.line ?? "",
|
|
1561
|
-
column: attributes.column ?? "",
|
|
1562
|
-
code: attributes.code ?? "",
|
|
1563
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1564
|
-
`).slice(1, -1).join(`
|
|
1565
|
-
`).trim()
|
|
1566
|
-
};
|
|
1567
|
-
}
|
|
1568
|
-
var tsc = (lines) => {
|
|
1569
|
-
const kept = [];
|
|
1570
|
-
let inError = false;
|
|
1571
|
-
for (const line of lines) {
|
|
1572
|
-
if (TSC_ERROR.test(line)) {
|
|
1573
|
-
inError = true;
|
|
1574
|
-
kept.push(line);
|
|
1575
|
-
} else if (TSC_SUMMARY.test(line)) {
|
|
1576
|
-
inError = false;
|
|
1577
|
-
kept.push(line);
|
|
1578
|
-
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1579
|
-
kept.push(line);
|
|
1580
|
-
} else {
|
|
1581
|
-
inError = false;
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1585
|
-
};
|
|
1586
|
-
var eslint = (lines) => {
|
|
1587
|
-
const kept = [];
|
|
1588
|
-
let file = "";
|
|
1589
|
-
let shown = "";
|
|
1590
|
-
for (const line of lines) {
|
|
1591
|
-
if (ESLINT_PROBLEM.test(line)) {
|
|
1592
|
-
if (file !== shown) {
|
|
1593
|
-
kept.push(file);
|
|
1594
|
-
shown = file;
|
|
1595
|
-
}
|
|
1596
|
-
kept.push(line);
|
|
1597
|
-
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1598
|
-
kept.push(line);
|
|
1599
|
-
} else if (line.trim() !== "") {
|
|
1600
|
-
file = line;
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1604
|
-
};
|
|
1605
|
-
var phpstan = (lines) => {
|
|
1606
|
-
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1607
|
-
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1608
|
-
};
|
|
1609
|
-
var php = (lines) => {
|
|
1610
|
-
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1611
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1612
|
-
};
|
|
1613
|
-
var vitest = (lines) => {
|
|
1614
|
-
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1615
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1616
|
-
};
|
|
1617
|
-
var playwright = (lines) => {
|
|
1618
|
-
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1619
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1620
|
-
};
|
|
1621
|
-
var phpCsFixer = (lines) => {
|
|
1622
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1623
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1624
|
-
};
|
|
1625
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1626
|
-
function squeeze(lines) {
|
|
1627
|
-
const out = [];
|
|
1628
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1629
|
-
if (line !== "" || out.at(-1) !== "")
|
|
1630
|
-
out.push(line);
|
|
1631
|
-
}
|
|
1632
|
-
while (out.at(-1) === "")
|
|
1633
|
-
out.pop();
|
|
1634
|
-
return out;
|
|
1635
|
-
}
|
|
1636
|
-
function cut(shown) {
|
|
1637
|
-
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1638
|
-
`) : shown.join(`
|
|
1639
|
-
`);
|
|
1640
|
-
}
|
|
1641
|
-
function recognised(lines, parsers) {
|
|
1642
|
-
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1643
|
-
}
|
|
1644
|
-
function failureExcerpt(output) {
|
|
1645
|
-
const lines = stripAnsi(output).split(`
|
|
1646
|
-
`);
|
|
1647
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1648
|
-
lines.shift();
|
|
1649
|
-
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1650
|
-
}
|
|
1651
|
-
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
1652
|
-
|
|
1653
|
-
// ../kit/src/index.ts
|
|
1654
|
-
init_folders();
|
|
1655
|
-
init_format();
|
|
1656
|
-
|
|
1657
|
-
// ../kit/src/git.ts
|
|
1658
|
-
init_args();
|
|
1659
|
-
// ../kit/src/limit.ts
|
|
1660
|
-
init_args();
|
|
1661
|
-
|
|
1662
|
-
// ../kit/src/index.ts
|
|
1663
|
-
init_mode();
|
|
1664
|
-
|
|
1665
|
-
// ../kit/src/report.ts
|
|
1666
|
-
init_style();
|
|
1667
|
-
init_text2();
|
|
1668
|
-
// ../kit/src/secrets.ts
|
|
1669
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1670
|
-
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1671
|
-
// ../kit/src/sessions.ts
|
|
1672
|
-
var {Glob } = globalThis.Bun;
|
|
1673
|
-
var SESSION_FILES = new Glob("*.json");
|
|
1674
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1675
|
-
|
|
1676
|
-
// ../kit/src/index.ts
|
|
1677
|
-
init_style();
|
|
1678
|
-
init_text2();
|
|
1679
|
-
init_theme();
|
|
1680
|
-
init_user_config();
|
|
1681
|
-
|
|
1682
|
-
// ../kit/src/watch.ts
|
|
1683
|
-
init_args();
|
|
1684
|
-
init_input();
|
|
1685
|
-
init_style();
|
|
1686
|
-
// ../kit/src/workspace-root.ts
|
|
1687
|
-
init_user_config();
|
|
1688
|
-
// package.json
|
|
1689
|
-
var version = "0.22.2";
|
|
1690
|
-
|
|
1691
|
-
// src/errs.ts
|
|
1692
|
-
import { relative as relative2 } from "path";
|
|
1693
|
-
import process22 from "process";
|
|
1694
|
-
|
|
1695
|
-
// src/compose.ts
|
|
1696
|
-
import { existsSync as existsSync4 } from "fs";
|
|
1697
|
-
import { homedir as homedir6 } from "os";
|
|
1698
|
-
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
|
|
1699
|
-
import process20 from "process";
|
|
1700
|
-
|
|
1701
|
-
// ../kit/src/shell.ts
|
|
1702
|
-
var SEPARATORS = new Set([`
|
|
1703
|
-
`, ";", "|"]);
|
|
1704
|
-
var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
|
|
1705
|
-
var GLOB_CHARS = new Set(["*", "?", "["]);
|
|
1706
|
-
var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
1707
|
-
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
1708
|
-
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
1709
|
-
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
1710
|
-
var FISH_COMBINERS = new Set(["and", "or", "not"]);
|
|
1711
|
-
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
|
|
1712
|
-
var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
|
|
1713
|
-
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
|
|
1714
|
-
var POWERSHELL = new Set(["pwsh", "powershell"]);
|
|
1715
|
-
var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
1716
|
-
var FISH_VALUE_OPTIONS = new Set(["-C", "--init-command"]);
|
|
1717
|
-
var PRINTERS = new Set(["echo", "printf"]);
|
|
1718
|
-
var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
1719
|
-
function wrapper(short = "", long = [], operands = 0, runsString = false) {
|
|
1720
|
-
return { short, long, operands, runsString };
|
|
1721
|
-
}
|
|
1722
|
-
var RUNNER = { ...wrapper(), afterDashes: true };
|
|
1723
|
-
var WRAPPERS = new Map([
|
|
1724
|
-
["command", wrapper()],
|
|
1725
|
-
["builtin", wrapper()],
|
|
1726
|
-
["nohup", wrapper()],
|
|
1727
|
-
["setsid", wrapper()],
|
|
1728
|
-
["busybox", wrapper()],
|
|
1729
|
-
["exec", wrapper("a")],
|
|
1730
|
-
["time", wrapper("fo", ["--format", "--output"])],
|
|
1731
|
-
["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
|
|
1732
|
-
["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
|
|
1733
|
-
["doas", wrapper("uC")],
|
|
1734
|
-
["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
|
|
1735
|
-
["nice", wrapper("n", ["--adjustment"])],
|
|
1736
|
-
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
1737
|
-
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
1738
|
-
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
1739
|
-
["watch", wrapper("n", ["--interval"], 0, true)],
|
|
1740
|
-
["flock", wrapper("wE", ["--timeout", "--conflict-exit-code"], 1)],
|
|
1741
|
-
["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
|
|
1742
|
-
["unbuffer", wrapper()],
|
|
1743
|
-
["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
|
|
1744
|
-
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])],
|
|
1745
|
-
["strace", wrapper("abeEIoOpPsSuUX", ["--trace", "--output", "--attach", "--string-limit", "--user", "--env", "--columns", "--trace-path", "--signal", "--status", "--summary-sort-by", "--summary-columns", "--const-print-style", "--interruptible", "--detach-on"])],
|
|
1746
|
-
["ltrace", wrapper("aeFlnopsuxX", ["--output", "--user", "--library", "--config", "--align", "--indent"])],
|
|
1747
|
-
["taskset", wrapper("", [], 1)],
|
|
1748
|
-
["fakeroot", wrapper("lsib", ["--lib", "--faked"])],
|
|
1749
|
-
["sshpass", wrapper("pfdP")],
|
|
1750
|
-
["coproc", wrapper()],
|
|
1751
|
-
["proxychains", wrapper("f")],
|
|
1752
|
-
["proxychains4", wrapper("f")],
|
|
1753
|
-
["torsocks", wrapper("upaP", ["--user", "--pass", "--address", "--port"])],
|
|
1754
|
-
["chrt", wrapper("TPD", ["--sched-runtime", "--sched-period", "--sched-deadline"], 1)],
|
|
1755
|
-
["unshare", wrapper("SGRw", ["--setuid", "--setgid", "--root", "--wd", "--map-user", "--map-group", "--map-users", "--map-groups", "--propagation", "--setgroups"])],
|
|
1756
|
-
["nsenter", wrapper("tSG", ["--target", "--setuid", "--setgid"])],
|
|
1757
|
-
["out", RUNNER],
|
|
1758
|
-
["slot", RUNNER],
|
|
1759
|
-
["waitfor", RUNNER],
|
|
1760
|
-
["base", RUNNER]
|
|
1761
|
-
]);
|
|
1762
|
-
function shellQuote(word) {
|
|
1763
|
-
return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
// src/compose.ts
|
|
1767
|
-
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1768
|
-
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1769
|
-
var PS_TIMEOUT_MS = 20000;
|
|
1770
|
-
var VARIABLE = /\$\{(\w+)(?::?-([^${}]*))?\}|\$(\w+)/g;
|
|
1771
|
-
var ENV_LINE = /^\s*(?:export\s+)?(\w+)=(.*)$/;
|
|
1772
|
-
var QUOTED = /^(['"])(.*)\1$/;
|
|
1773
|
-
var TOOL_WORDS = {
|
|
1774
|
-
bun: ["bun"],
|
|
1775
|
-
bunx: ["bun"],
|
|
1776
|
-
node: ["node", "bun"],
|
|
1777
|
-
npm: ["node", "bun"],
|
|
1778
|
-
npx: ["node", "bun"],
|
|
1779
|
-
pnpm: ["node", "bun"],
|
|
1780
|
-
yarn: ["node", "bun"],
|
|
1781
|
-
composer: ["php"],
|
|
1782
|
-
php: ["php"],
|
|
1783
|
-
phpunit: ["php"],
|
|
1784
|
-
phpstan: ["php"],
|
|
1785
|
-
paratest: ["php"],
|
|
1786
|
-
pest: ["php"],
|
|
1787
|
-
symfony: ["php"]
|
|
1788
|
-
};
|
|
1789
|
-
function toolWords(program) {
|
|
1790
|
-
const name = basename(program);
|
|
1791
|
-
return TOOL_WORDS[name] ?? (program.includes("vendor/bin/") ? ["php"] : []);
|
|
1792
|
-
}
|
|
1793
|
-
async function readFiles(dir, names) {
|
|
1794
|
-
for (const name of names) {
|
|
1795
|
-
const handle = Bun.file(join8(dir, name));
|
|
1796
|
-
if (await handle.exists())
|
|
1797
|
-
return { name, text: await handle.text() };
|
|
1798
|
-
}
|
|
1799
|
-
return;
|
|
1800
|
-
}
|
|
1801
|
-
async function variables(composeDir) {
|
|
1802
|
-
const env = {};
|
|
1803
|
-
const text = (await readFiles(composeDir, [".env"]))?.text ?? "";
|
|
1804
|
-
for (const line of text.split(`
|
|
1805
|
-
`)) {
|
|
1806
|
-
const match = ENV_LINE.exec(line);
|
|
1807
|
-
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1808
|
-
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1809
|
-
}
|
|
1810
|
-
for (const [key, value] of Object.entries(process20.env)) {
|
|
1811
|
-
if (value !== undefined)
|
|
1812
|
-
env[key] = value;
|
|
1813
|
-
}
|
|
1814
|
-
env.PWD = composeDir;
|
|
1815
|
-
return env;
|
|
1816
|
-
}
|
|
1817
|
-
function interpolate(text, env) {
|
|
1818
|
-
let current = text;
|
|
1819
|
-
for (let round = 0;round < 4 && current.includes("$"); round++) {
|
|
1820
|
-
current = current.replaceAll(VARIABLE, (_, braced, fallback, bare) => {
|
|
1821
|
-
const value = env[braced ?? bare ?? ""];
|
|
1822
|
-
return value !== undefined && value !== "" ? value : fallback ?? "";
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
return current;
|
|
1826
|
-
}
|
|
1827
|
-
function bindSource(source, composeDir, env) {
|
|
1828
|
-
const path = interpolate(source, env);
|
|
1829
|
-
if (path.startsWith("~"))
|
|
1830
|
-
return join8(homedir6(), path.slice(1));
|
|
1831
|
-
if (path.startsWith("/"))
|
|
1832
|
-
return resolve4(path);
|
|
1833
|
-
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
1834
|
-
}
|
|
1835
|
-
function mountsOf(volumes, composeDir, env) {
|
|
1836
|
-
if (!Array.isArray(volumes))
|
|
1837
|
-
return [];
|
|
1838
|
-
const mounts = [];
|
|
1839
|
-
for (const volume of volumes) {
|
|
1840
|
-
let source;
|
|
1841
|
-
let target;
|
|
1842
|
-
if (typeof volume === "string") {
|
|
1843
|
-
[source, target] = interpolate(volume, env).split(":");
|
|
1844
|
-
} else if (typeof volume === "object" && volume !== null) {
|
|
1845
|
-
const object = volume;
|
|
1846
|
-
if (object.type === "bind" && typeof object.source === "string" && typeof object.target === "string")
|
|
1847
|
-
({ source, target } = object);
|
|
1848
|
-
}
|
|
1849
|
-
const resolved = source === undefined ? undefined : bindSource(source, composeDir, env);
|
|
1850
|
-
if (resolved !== undefined && target?.startsWith("/") === true)
|
|
1851
|
-
mounts.push({ source: resolved, target });
|
|
1852
|
-
}
|
|
1853
|
-
return mounts;
|
|
1854
|
-
}
|
|
1855
|
-
function buildText(build) {
|
|
1856
|
-
if (typeof build === "string")
|
|
1857
|
-
return build;
|
|
1858
|
-
return typeof build === "object" && build !== null ? Object.values(build).filter((value) => typeof value === "string").join(" ") : "";
|
|
1859
|
-
}
|
|
1860
|
-
function parseServices(text, composeDir, env) {
|
|
1861
|
-
const services = new Map;
|
|
1862
|
-
const parsed = Bun.YAML.parse(text);
|
|
1863
|
-
for (const [name, service] of Object.entries(parsed?.services ?? {})) {
|
|
1864
|
-
if (service !== null && typeof service === "object")
|
|
1865
|
-
services.set(name, { ...service, mounts: mountsOf(service.volumes, composeDir, env) });
|
|
1866
|
-
}
|
|
1867
|
-
return services;
|
|
1868
|
-
}
|
|
1869
|
-
async function composeFiles(composeDir, env) {
|
|
1870
|
-
const listed = env.COMPOSE_FILE;
|
|
1871
|
-
if (listed !== undefined && listed !== "") {
|
|
1872
|
-
const files = [];
|
|
1873
|
-
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1874
|
-
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1875
|
-
const file = Bun.file(resolve4(composeDir, name));
|
|
1876
|
-
if (!await file.exists())
|
|
1877
|
-
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1878
|
-
files.push({ name, text: await file.text() });
|
|
1879
|
-
}
|
|
1880
|
-
return files;
|
|
1881
|
-
}
|
|
1882
|
-
const base = await readFiles(composeDir, COMPOSE_FILES);
|
|
1883
|
-
if (base === undefined)
|
|
1884
|
-
return [];
|
|
1885
|
-
const override = await readFiles(composeDir, OVERRIDE_FILES);
|
|
1886
|
-
return override === undefined ? [base] : [base, override];
|
|
1887
|
-
}
|
|
1888
|
-
async function readServices(composeDir) {
|
|
1889
|
-
const env = await variables(composeDir);
|
|
1890
|
-
const files = await composeFiles(composeDir, env);
|
|
1891
|
-
if (files.length === 0)
|
|
1892
|
-
return;
|
|
1893
|
-
const services = new Map;
|
|
1894
|
-
for (const file of files) {
|
|
1895
|
-
let parsed;
|
|
1896
|
-
try {
|
|
1897
|
-
parsed = parseServices(file.text, composeDir, env);
|
|
1898
|
-
} catch (error) {
|
|
1899
|
-
fail(`cannot read ${join8(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1900
|
-
}
|
|
1901
|
-
for (const [name, extra] of parsed) {
|
|
1902
|
-
const known = services.get(name);
|
|
1903
|
-
services.set(name, known === undefined ? extra : { ...known, ...extra, mounts: [...known.mounts, ...extra.mounts], image: extra.image ?? known.image, build: extra.build ?? known.build });
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
return [...services].map(([name, service]) => ({ name, mounts: service.mounts, profile: `${name} ${typeof service.image === "string" ? service.image : ""} ${buildText(service.build)}`.toLowerCase() }));
|
|
1907
|
-
}
|
|
1908
|
-
function climb(dir) {
|
|
1909
|
-
const folders = [dir];
|
|
1910
|
-
let current = dir;
|
|
1911
|
-
while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1912
|
-
current = dirname4(current);
|
|
1913
|
-
folders.push(current);
|
|
1914
|
-
}
|
|
1915
|
-
return existsSync4(join8(current, ".git")) ? folders : [dir];
|
|
1916
|
-
}
|
|
1917
|
-
function containerPath(service, dir) {
|
|
1918
|
-
const holding = service.mounts.filter((mount) => {
|
|
1919
|
-
const inside = relative(mount.source, dir);
|
|
1920
|
-
return !inside.startsWith("..") && !inside.startsWith("/");
|
|
1921
|
-
});
|
|
1922
|
-
const deepest = holding.toSorted((a, b) => b.source.length - a.source.length)[0];
|
|
1923
|
-
if (deepest === undefined)
|
|
1924
|
-
return;
|
|
1925
|
-
const inside = relative(deepest.source, dir);
|
|
1926
|
-
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1927
|
-
}
|
|
1928
|
-
var noticed = new Set;
|
|
1929
|
-
async function place(dir, program, { service, host } = {}) {
|
|
1930
|
-
if (host === true)
|
|
1931
|
-
return;
|
|
1932
|
-
let found;
|
|
1933
|
-
for (const composeDir of climb(dir)) {
|
|
1934
|
-
const services = await readServices(composeDir);
|
|
1935
|
-
const mounting = (services ?? []).filter((candidate) => containerPath(candidate, dir) !== undefined);
|
|
1936
|
-
if (services !== undefined && (mounting.length > 0 || services.some((candidate) => candidate.name === service))) {
|
|
1937
|
-
found = { composeDir, services, mounting };
|
|
1938
|
-
break;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
if (found === undefined) {
|
|
1942
|
-
if (service !== undefined)
|
|
1943
|
-
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1944
|
-
return;
|
|
1945
|
-
}
|
|
1946
|
-
if (Bun.which("docker", { PATH: process20.env.PATH ?? "" }) === null) {
|
|
1947
|
-
if (service !== undefined)
|
|
1948
|
-
fail(`--in ${service}: docker not found`);
|
|
1949
|
-
if (!noticed.has(found.composeDir)) {
|
|
1950
|
-
noticed.add(found.composeDir);
|
|
1951
|
-
warn(`host, docker not found: the compose project in ${found.composeDir} is not reached`);
|
|
1952
|
-
}
|
|
1953
|
-
return;
|
|
1954
|
-
}
|
|
1955
|
-
const chosen = choose(found.mounting, found.services, dir, program, service);
|
|
1956
|
-
return { service: chosen.name, composeDir: found.composeDir, workdir: containerPath(chosen, dir) ?? dir };
|
|
1957
|
-
}
|
|
1958
|
-
function choose(mounting, services, dir, program, service) {
|
|
1959
|
-
if (service !== undefined) {
|
|
1960
|
-
const named = mounting.find((candidate) => candidate.name === service);
|
|
1961
|
-
if (named === undefined)
|
|
1962
|
-
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(", ")}`}`);
|
|
1963
|
-
return named;
|
|
1964
|
-
}
|
|
1965
|
-
const [only] = mounting;
|
|
1966
|
-
if (mounting.length === 1 && only !== undefined)
|
|
1967
|
-
return only;
|
|
1968
|
-
const words = toolWords(program);
|
|
1969
|
-
const fitting = mounting.filter((candidate) => words.some((word) => candidate.profile.includes(word)));
|
|
1970
|
-
const [fit] = fitting;
|
|
1971
|
-
if (fitting.length !== 1 || fit === undefined)
|
|
1972
|
-
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`);
|
|
1973
|
-
return fit;
|
|
1974
|
-
}
|
|
1975
|
-
function execArgv(placement, argv, env) {
|
|
1976
|
-
const variables = Object.entries({ NO_COLOR: "1", FORCE_COLOR: "0", ...env }).flatMap(([name, value]) => ["-e", `${name}=${value}`]);
|
|
1977
|
-
return ["docker", "compose", "exec", "-T", "-w", placement.workdir, ...variables, placement.service, ...argv];
|
|
1978
|
-
}
|
|
1979
|
-
function shellIn(placement, command, env = {}) {
|
|
1980
|
-
return `cd ${shellQuote(placement.composeDir)} && ${execArgv(placement, ["sh", "-c", command], env).map((word) => shellQuote(word)).join(" ")}`;
|
|
1981
|
-
}
|
|
1982
|
-
function argvIn(placement, argv) {
|
|
1983
|
-
return execArgv(placement, argv, {});
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
class Stack {
|
|
1987
|
-
answers = new Map;
|
|
1988
|
-
async ask(composeDir) {
|
|
1989
|
-
let answer = this.answers.get(composeDir);
|
|
1990
|
-
if (answer === undefined) {
|
|
1991
|
-
answer = Stack.running(composeDir);
|
|
1992
|
-
this.answers.set(composeDir, answer);
|
|
1993
|
-
}
|
|
1994
|
-
return answer;
|
|
1995
|
-
}
|
|
1996
|
-
static async running(composeDir) {
|
|
1997
|
-
try {
|
|
1998
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process20.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1999
|
-
if (ran.code !== 0)
|
|
2000
|
-
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
2001
|
-
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
2002
|
-
return ran.text.split(`
|
|
2003
|
-
`).map((line) => line.trim()).filter((line) => line !== "");
|
|
2004
|
-
} catch (error) {
|
|
2005
|
-
return `cannot run docker compose in ${composeDir}: ${error instanceof Error ? error.message : String(error)}`;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
async problem(placement) {
|
|
2009
|
-
const answer = await this.ask(placement.composeDir);
|
|
2010
|
-
if (typeof answer === "string")
|
|
2011
|
-
return answer;
|
|
2012
|
-
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`;
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
function programOf(command) {
|
|
2016
|
-
const end = command.indexOf(" ");
|
|
2017
|
-
return end === -1 ? command : command.slice(0, end);
|
|
2018
|
-
}
|
|
2019
|
-
var placeOptions = {
|
|
2020
|
-
in: { type: "string", description: "run in this compose service instead of the one found mounting the folder" },
|
|
2021
|
-
host: { type: "boolean", description: "run on the host even when a compose service mounts the folder" }
|
|
2022
|
-
};
|
|
2023
|
-
function placeSettings(values) {
|
|
2024
|
-
if (values.in !== undefined && values.host === true)
|
|
2025
|
-
fail("--in and --host exclude each other");
|
|
2026
|
-
return { service: values.in, host: values.host };
|
|
2027
|
-
}
|
|
2028
|
-
|
|
2029
|
-
// src/e2e.ts
|
|
2030
|
-
var E2E_NOISE = [
|
|
2031
|
-
/^(?: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)/,
|
|
2032
|
-
/^[\u00B7F\u00D7\u00B0T\u00B1]+$/,
|
|
2033
|
-
/^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/
|
|
2034
|
-
];
|
|
2035
|
-
var PLAYWRIGHT_HEADER = /^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
2036
|
-
var PLAYWRIGHT_SUMMARY = /^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/;
|
|
2037
|
-
var PLAYWRIGHT_ENTRY = /^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
2038
|
-
var PLAYWRIGHT_RETRY = /^\s+Retry #\d+ \u2500+$/;
|
|
2039
|
-
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
2040
|
-
var EXPECTED = /^\s+Expected: (.*)$/;
|
|
2041
|
-
var RECEIVED = /^\s+Received: (.*)$/;
|
|
2042
|
-
var VITEST_FAIL = /^ FAIL {2}(?:\|[^|]+\| )?(.+)$/;
|
|
2043
|
-
var VITEST_SUITE = /^(.+?) \[ .+ \]$/;
|
|
2044
|
-
var VITEST_FRAME = /^\s*\u276F (\S+):(\d+):(\d+)$/;
|
|
2045
|
-
function key(project, file, line, column, title) {
|
|
2046
|
-
return `${project ?? ""}|${file}:${line}:${column} \u203A ${title}`;
|
|
2047
|
-
}
|
|
2048
|
-
function firstFrame(block) {
|
|
2049
|
-
return block.map((line) => FRAME.exec(line)).find((match) => match !== null && !match[1]?.includes("node_modules")) ?? undefined;
|
|
2050
|
-
}
|
|
2051
|
-
var collectPlaywright = (lines, used) => {
|
|
2052
|
-
const flaky = new Set;
|
|
2053
|
-
let section = "";
|
|
2054
|
-
for (const [index, line] of lines.entries()) {
|
|
2055
|
-
const summary = PLAYWRIGHT_SUMMARY.exec(line);
|
|
2056
|
-
const entry = PLAYWRIGHT_ENTRY.exec(line);
|
|
2057
|
-
if (summary !== null) {
|
|
2058
|
-
section = summary[1] ?? "";
|
|
2059
|
-
used.add(index);
|
|
2060
|
-
} else if (entry !== null && section !== "") {
|
|
2061
|
-
if (section === "flaky")
|
|
2062
|
-
flaky.add(key(entry[1], entry[2], entry[3], entry[4], entry[5]));
|
|
2063
|
-
used.add(index);
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
const errors = [];
|
|
2067
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2068
|
-
const header = PLAYWRIGHT_HEADER.exec(lines[index] ?? "");
|
|
2069
|
-
if (header === null)
|
|
2070
|
-
continue;
|
|
2071
|
-
let end = index + 1;
|
|
2072
|
-
while (end < lines.length && !PLAYWRIGHT_HEADER.test(lines[end] ?? "") && !PLAYWRIGHT_SUMMARY.test(lines[end] ?? ""))
|
|
2073
|
-
end++;
|
|
2074
|
-
for (let at = index;at < end; at++)
|
|
2075
|
-
used.add(at);
|
|
2076
|
-
const [, project, file, line, column, title] = header;
|
|
2077
|
-
const retry = lines.findIndex((text, at) => at > index && at < end && PLAYWRIGHT_RETRY.test(text));
|
|
2078
|
-
const block = lines.slice(index + 1, retry === -1 ? end : retry);
|
|
2079
|
-
const frame = firstFrame(block);
|
|
2080
|
-
const message = block.find((text) => text.trim() !== "")?.trim() ?? "failed";
|
|
2081
|
-
const expected = block.map((text) => EXPECTED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
2082
|
-
const received = block.map((text) => RECEIVED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
2083
|
-
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
2084
|
-
index = end - 1;
|
|
2085
|
-
if (flaky.has(key(project, file, line, column, title)))
|
|
2086
|
-
continue;
|
|
2087
|
-
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}` });
|
|
2088
|
-
}
|
|
2089
|
-
return errors;
|
|
2090
|
-
};
|
|
2091
|
-
var collectVitest = (lines, used) => {
|
|
2092
|
-
const errors = [];
|
|
2093
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2094
|
-
const header = VITEST_FAIL.exec(lines[index] ?? "")?.[1];
|
|
2095
|
-
if (header === undefined)
|
|
2096
|
-
continue;
|
|
2097
|
-
let end = index + 1;
|
|
2098
|
-
while (end < lines.length && !(lines[end] ?? "").startsWith("\u23AF") && !VITEST_FAIL.test(lines[end] ?? ""))
|
|
2099
|
-
end++;
|
|
2100
|
-
for (let at = index;at < end; at++)
|
|
2101
|
-
used.add(at);
|
|
2102
|
-
const block = lines.slice(index + 1, end);
|
|
2103
|
-
const frame = block.map((text) => VITEST_FRAME.exec(text)).find((match) => match !== null && !match[1]?.includes("node_modules"));
|
|
2104
|
-
const suite = VITEST_SUITE.exec(header)?.[1];
|
|
2105
|
-
const [file = "", ...names] = (suite ?? header).split(" > ");
|
|
2106
|
-
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(" > ") } : {} });
|
|
2107
|
-
index = end - 1;
|
|
2108
|
-
}
|
|
2109
|
-
return errors;
|
|
2110
|
-
};
|
|
2111
|
-
|
|
2112
|
-
// src/php.ts
|
|
2113
|
-
var PHP_NOISE = [
|
|
2114
|
-
/^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,
|
|
2115
|
-
/^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,
|
|
2116
|
-
/^ -{3,}(?: -{3,})*\s*$/,
|
|
2117
|
-
/^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,
|
|
2118
|
-
/^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,
|
|
2119
|
-
/^(?: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:)/
|
|
2120
|
-
];
|
|
2121
|
-
var MAX_DIFF_LINES = 6;
|
|
2122
|
-
var PHPUNIT_HEADER = /^There (?:was|were) \d+ ([a-z ]+?)s?:$/i;
|
|
2123
|
-
var PHPUNIT_TRIGGERED = /^\d+ tests? triggered \d+ [\w ]+?s?:$/;
|
|
2124
|
-
var PHPUNIT_END = /^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/;
|
|
2125
|
-
var PHPUNIT_ITEM = /^\d+\) (.*)$/;
|
|
2126
|
-
var PHP_LOCATION = /^([\w./-]+\.php):(\d+)$/;
|
|
2127
|
-
var PHPSTAN_FILE = /^ {2}Line {3}(\S.*)$/;
|
|
2128
|
-
var PHPSTAN_GENERAL = /^ {2}Error\s*$/;
|
|
2129
|
-
var PHPSTAN_MESSAGE = /^ {2}(\S.*)$/;
|
|
2130
|
-
var PHPSTAN_ROW = /^ {2}(\d+|-) +(\S.*)$/;
|
|
2131
|
-
var PHPSTAN_CONTINUATION = /^ {9}(\S.*)$/;
|
|
2132
|
-
var PHPSTAN_IDENTIFIER = /^ {9}\uD83E\uDEAA\s+(\S+)\s*$/;
|
|
2133
|
-
var PHPSTAN_TIP = /^ {9}\uD83D\uDCA1/;
|
|
2134
|
-
var PHPSTAN_BORDER = /^ -{3,}(?: -{3,})*\s*$/;
|
|
2135
|
-
var PHPSTAN_RAW = /^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/;
|
|
2136
|
-
var PHPSTAN_JSON = /^\{.*"totals"/;
|
|
2137
|
-
var CS_FIXER_FILE = /^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/;
|
|
2138
|
-
var CS_FIXER_DIFF_START = /^\s+-+ begin diff -+$/;
|
|
2139
|
-
var CS_FIXER_DIFF_END = /^\s+-+ end diff -+$/;
|
|
2140
|
-
function isHeader(line) {
|
|
2141
|
-
return PHPUNIT_HEADER.test(line) || PHPUNIT_TRIGGERED.test(line);
|
|
2142
|
-
}
|
|
2143
|
-
function diffSummary(message) {
|
|
2144
|
-
const start = message.findIndex((line) => line === "+++ Actual");
|
|
2145
|
-
if (start === -1)
|
|
2146
|
-
return "";
|
|
2147
|
-
const changed = message.slice(start + 1).filter((line) => line.startsWith("-") || line.startsWith("+")).map((line) => `${line[0]} ${line.slice(1).trim()}`);
|
|
2148
|
-
const shown = changed.slice(0, MAX_DIFF_LINES).join(" | ");
|
|
2149
|
-
return changed.length === 0 ? "" : ` (${shown}${changed.length > MAX_DIFF_LINES ? " | ..." : ""})`;
|
|
2150
|
-
}
|
|
2151
|
-
function phpunitError(test, body) {
|
|
2152
|
-
const at = body.findIndex((line) => PHP_LOCATION.test(line));
|
|
2153
|
-
const location = PHP_LOCATION.exec(body[at] ?? "");
|
|
2154
|
-
const message = body.slice(0, at === -1 ? body.length : at).map((line) => line.trimEnd());
|
|
2155
|
-
const first = message.find((line) => line.trim() !== "") ?? "failed";
|
|
2156
|
-
return { tool: "phpunit", file: location?.[1] ?? "", line: Number(location?.[2] ?? 0), column: 0, severity: "error", message: `${first}${diffSummary(message)}`, test };
|
|
2157
|
-
}
|
|
2158
|
-
var collectPhpunit = (lines, used) => {
|
|
2159
|
-
const errors = [];
|
|
2160
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2161
|
-
const line = lines[index] ?? "";
|
|
2162
|
-
const kind = PHPUNIT_HEADER.exec(line)?.[1];
|
|
2163
|
-
if (kind === undefined && !PHPUNIT_TRIGGERED.test(line))
|
|
2164
|
-
continue;
|
|
2165
|
-
let end = index + 1;
|
|
2166
|
-
while (end < lines.length && !PHPUNIT_END.test(lines[end] ?? "") && !isHeader(lines[end] ?? ""))
|
|
2167
|
-
end++;
|
|
2168
|
-
for (let at = index;at < end; at++)
|
|
2169
|
-
used.add(at);
|
|
2170
|
-
if (kind === "error" || kind === "failure") {
|
|
2171
|
-
const starts = Array.from({ length: end - index - 1 }, (_, at) => index + 1 + at).filter((at) => PHPUNIT_ITEM.test(lines[at] ?? ""));
|
|
2172
|
-
for (const [position, start] of starts.entries())
|
|
2173
|
-
errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start] ?? "")?.[1] ?? "", lines.slice(start + 1, starts[position + 1] ?? end)));
|
|
2174
|
-
}
|
|
2175
|
-
index = end - 1;
|
|
2176
|
-
}
|
|
2177
|
-
return errors;
|
|
2178
|
-
};
|
|
2179
|
-
function appendMessage(error, text) {
|
|
2180
|
-
error.message = `${error.message} ${text}`;
|
|
2181
|
-
}
|
|
2182
|
-
function phpstanJson(text) {
|
|
2183
|
-
try {
|
|
2184
|
-
const report = JSON.parse(text);
|
|
2185
|
-
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 } })));
|
|
2186
|
-
return [...fromFiles, ...(report.errors ?? []).map((message) => ({ file: "", line: 0, message }))];
|
|
2187
|
-
} catch {
|
|
2188
|
-
return;
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
var collectPhpstan = (lines, used) => {
|
|
2192
|
-
const errors = [];
|
|
2193
|
-
let file;
|
|
2194
|
-
let current;
|
|
2195
|
-
let rows = 0;
|
|
2196
|
-
let tip = false;
|
|
2197
|
-
let general = false;
|
|
2198
|
-
for (const [index, text] of lines.entries()) {
|
|
2199
|
-
const line = text.trimEnd();
|
|
2200
|
-
if (used.has(index))
|
|
2201
|
-
continue;
|
|
2202
|
-
if (PHPSTAN_JSON.test(line)) {
|
|
2203
|
-
const parsed = phpstanJson(line);
|
|
2204
|
-
for (const entry of parsed ?? []) {
|
|
2205
|
-
errors.push({ tool: "phpstan", file: entry.file, line: entry.line, column: 0, severity: "error", message: entry.message, ...entry.rule === undefined ? {} : { rule: entry.rule } });
|
|
2206
|
-
}
|
|
2207
|
-
if (parsed !== undefined)
|
|
2208
|
-
used.add(index);
|
|
2209
|
-
continue;
|
|
2210
|
-
}
|
|
2211
|
-
const raw = PHPSTAN_RAW.exec(line);
|
|
2212
|
-
if (raw !== null) {
|
|
2213
|
-
errors.push({ tool: "phpstan", file: raw[1] ?? "", line: Number(raw[2]), column: 0, severity: "error", message: raw[3] ?? "" });
|
|
2214
|
-
used.add(index);
|
|
2215
|
-
continue;
|
|
2216
|
-
}
|
|
2217
|
-
const header = PHPSTAN_FILE.exec(line);
|
|
2218
|
-
if (header !== null || PHPSTAN_GENERAL.test(line)) {
|
|
2219
|
-
file = header?.[1] ?? "";
|
|
2220
|
-
general = header === null;
|
|
2221
|
-
current = undefined;
|
|
2222
|
-
rows = 0;
|
|
2223
|
-
used.add(index);
|
|
2224
|
-
continue;
|
|
2225
|
-
}
|
|
2226
|
-
if (file === undefined)
|
|
2227
|
-
continue;
|
|
2228
|
-
const message = PHPSTAN_MESSAGE.exec(line)?.[1];
|
|
2229
|
-
if (general && message !== undefined && !PHPSTAN_BORDER.test(line)) {
|
|
2230
|
-
errors.push({ tool: "phpstan", file: "", line: 0, column: 0, severity: "error", message });
|
|
2231
|
-
rows++;
|
|
2232
|
-
used.add(index);
|
|
2233
|
-
continue;
|
|
2234
|
-
}
|
|
2235
|
-
const row = PHPSTAN_ROW.exec(line);
|
|
2236
|
-
const identifier = PHPSTAN_IDENTIFIER.exec(line)?.[1];
|
|
2237
|
-
const continuation = PHPSTAN_CONTINUATION.exec(line)?.[1];
|
|
2238
|
-
if (PHPSTAN_BORDER.test(line) && rows > 0) {
|
|
2239
|
-
file = undefined;
|
|
2240
|
-
general = false;
|
|
2241
|
-
current = undefined;
|
|
2242
|
-
} else if (row !== null) {
|
|
2243
|
-
current = { tool: "phpstan", file, line: row[1] === "-" ? 0 : Number(row[1]), column: 0, severity: "error", message: row[2] ?? "" };
|
|
2244
|
-
errors.push(current);
|
|
2245
|
-
rows++;
|
|
2246
|
-
tip = false;
|
|
2247
|
-
used.add(index);
|
|
2248
|
-
} else if (identifier !== undefined && current !== undefined) {
|
|
2249
|
-
current.rule = identifier;
|
|
2250
|
-
used.add(index);
|
|
2251
|
-
} else if (PHPSTAN_TIP.test(line)) {
|
|
2252
|
-
tip = true;
|
|
2253
|
-
used.add(index);
|
|
2254
|
-
} else if (continuation !== undefined && current !== undefined) {
|
|
2255
|
-
if (!tip)
|
|
2256
|
-
appendMessage(current, continuation);
|
|
2257
|
-
used.add(index);
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
return errors;
|
|
2261
|
-
};
|
|
2262
|
-
var collectCsFixer = (lines, used) => {
|
|
2263
|
-
const errors = [];
|
|
2264
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2265
|
-
const match = CS_FIXER_FILE.exec(lines[index] ?? "");
|
|
2266
|
-
if (match === null)
|
|
2267
|
-
continue;
|
|
2268
|
-
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" });
|
|
2269
|
-
used.add(index);
|
|
2270
|
-
if (!CS_FIXER_DIFF_START.test(lines[index + 1] ?? ""))
|
|
2271
|
-
continue;
|
|
2272
|
-
const end = lines.findIndex((text, at) => at > index && CS_FIXER_DIFF_END.test(text));
|
|
2273
|
-
for (let at = index + 1;at <= (end === -1 ? index + 1 : end); at++)
|
|
2274
|
-
used.add(at);
|
|
2275
|
-
index = end === -1 ? index + 1 : end;
|
|
2276
|
-
}
|
|
2277
|
-
return errors;
|
|
2278
|
-
};
|
|
2279
|
-
|
|
2280
|
-
// src/output.ts
|
|
2281
|
-
var { BASH_ECHO: BASH_ECHO2, DURATION: DURATION3, BOUNDARY: BOUNDARY2, BUN_TEST_SUMMARY: BUN_TEST_SUMMARY2, BUN_CHECK_SUMMARY: BUN_CHECK_SUMMARY2, TSC_CONTINUATION: TSC_CONTINUATION2, TSC_FRAME: TSC_FRAME2, TSC_SUMMARY: TSC_SUMMARY2, ESLINT_PROBLEM: ESLINT_PROBLEM2, ESLINT_SUMMARY: ESLINT_SUMMARY2 } = LOG_PATTERNS;
|
|
2282
|
-
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
2283
|
-
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
2284
|
-
var TSC_SOURCE_LINE = /^\d+ /;
|
|
2285
|
-
var ESLINT_FIELDS = /^ +(\d+):(\d+) +(error|warning) +(\S.*)$/;
|
|
2286
|
-
var ESLINT_RULE = / {2,}(\S+)$/;
|
|
2287
|
-
var ESLINT_FILE = /^(?:\/|~\/|\.{1,2}[/\\]|[a-z]:\\)|^[^\s/\\]+[/\\]\S*$/i;
|
|
2288
|
-
var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
|
|
2289
|
-
var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
2290
|
-
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
2291
|
-
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
2292
|
-
var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
|
|
2293
|
-
var GO_LINTER = /^(.*\S)\s+\(([a-z][\w-]*)\)$/;
|
|
2294
|
-
var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
|
|
2295
|
-
var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
|
|
2296
|
-
var CARGO_HEADER = /^(error|warning)(?:\[([\w-]+)\])?: (.*)$/;
|
|
2297
|
-
var LINE_BREAK = /\r?\n/;
|
|
2298
|
-
var CONTINUATION = /^\s+\S/;
|
|
2299
|
-
var MAX_CONTINUATION = 20;
|
|
2300
|
-
var KAY_SUMMARY = /^(?:\d+ errors?(?:, \d+ warnings?)?|\d+ warnings?)(?:, failing under --deny-warnings)?$|^checked with /;
|
|
2301
|
-
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)/;
|
|
2302
|
-
var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
|
|
2303
|
-
var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
|
|
2304
|
-
var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
|
|
2305
|
-
var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
|
|
2306
|
-
var PYTEST_E_LINE = /^E {3}(.*)$/;
|
|
2307
|
-
var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
|
|
2308
|
-
var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
|
|
2309
|
-
var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
|
|
2310
|
-
var PYTEST_FRAME = /^in \S/;
|
|
2311
|
-
var PYTEST_SECTION = /^_{3,} (.*) _{3,}$/;
|
|
2312
|
-
var PYTEST_SUMMARY = /^(?:FAILED|ERROR) ([^\s:]+?\.py)(?:::(.*)| - (.*))?$/;
|
|
2313
|
-
var PYTEST_ERROR_SECTION = /^ERROR (?:at (?:setup|teardown) of |collecting )/;
|
|
2314
|
-
var PYTEST_EXCEPTION_END = /[\s:]/;
|
|
2315
|
-
var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
|
|
2316
|
-
var GENERIC_LINE = /^(\S[^:]*):(\d+)(?::(\d+))?: (?:fatal )?(error|warning|note): (.*)$/;
|
|
2317
|
-
var GENERIC_RULE = /\s(?:\[([\w-]+)\]|\(([a-z][\w-]*)\))$/;
|
|
2318
|
-
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)/;
|
|
2319
|
-
function isNoise(line) {
|
|
2320
|
-
return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY2, BUN_CHECK_SUMMARY2, TSC_SUMMARY2, ESLINT_SUMMARY2, BOUNDARY2, BASH_ECHO2, GO_NOISE, CARGO_NOISE, KAY_SUMMARY, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
|
|
2321
|
-
}
|
|
2322
|
-
var collectBunCheck = (lines, used) => {
|
|
2323
|
-
const errors = [];
|
|
2324
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2325
|
-
if (!(lines[index] ?? "").startsWith("<error file="))
|
|
2326
|
-
continue;
|
|
2327
|
-
const end = lines.findIndex((line, at) => at >= index && line === "</error>");
|
|
2328
|
-
if (end === -1)
|
|
2329
|
-
break;
|
|
2330
|
-
const { file, line, column, code, message } = bunCheckFields(lines.slice(index, end + 1).join(`
|
|
2331
|
-
`));
|
|
2332
|
-
errors.push({ tool: "bun check", file, line: Number(line), column: Number(column), rule: code, severity: "error", message: message.replaceAll(/\s*\n\s*/g, " ") });
|
|
2333
|
-
for (let at = index;at <= end; at++)
|
|
2334
|
-
used.add(at);
|
|
2335
|
-
index = end;
|
|
2336
|
-
}
|
|
2337
|
-
return errors;
|
|
2338
|
-
};
|
|
2339
|
-
var collectBunTest = (lines, used) => {
|
|
2340
|
-
const errors = [];
|
|
2341
|
-
const seen = new Set;
|
|
2342
|
-
const names = new Set;
|
|
2343
|
-
for (const [index, line] of lines.entries()) {
|
|
2344
|
-
if (!line.startsWith("(fail) "))
|
|
2345
|
-
continue;
|
|
2346
|
-
used.add(index);
|
|
2347
|
-
const test = line.slice("(fail) ".length).replace(DURATION3, "");
|
|
2348
|
-
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY2.test(text)) + 1;
|
|
2349
|
-
const block = lines.slice(start, index);
|
|
2350
|
-
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
2351
|
-
for (let at = start;at < index; at++)
|
|
2352
|
-
used.add(at);
|
|
2353
|
-
const frame = block.slice(Math.max(failure, 0)).map((text) => BUN_TEST_FRAME.exec(text)).find((match) => match !== null);
|
|
2354
|
-
const header = lines.slice(0, index).findLast((text) => BUN_TEST_FILE.test(text));
|
|
2355
|
-
const key = `${header ?? ""}\x00${test}`;
|
|
2356
|
-
if (seen.has(key) || failure === -1 && names.has(test))
|
|
2357
|
-
continue;
|
|
2358
|
-
seen.add(key);
|
|
2359
|
-
names.add(test);
|
|
2360
|
-
const expected = block.map((text) => BUN_TEST_EXPECTED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
2361
|
-
const received = block.map((text) => BUN_TEST_RECEIVED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
2362
|
-
const reason = failure === -1 ? "failed" : (block[failure] ?? "").slice("error:".length).trim();
|
|
2363
|
-
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
2364
|
-
errors.push({
|
|
2365
|
-
tool: "bun test",
|
|
2366
|
-
file: frame?.[1] ?? header?.replace(":", "") ?? "",
|
|
2367
|
-
line: Number(frame?.[2] ?? 0),
|
|
2368
|
-
column: Number(frame?.[3] ?? 0),
|
|
2369
|
-
severity: "error",
|
|
2370
|
-
message: `${reason}${values}`,
|
|
2371
|
-
test
|
|
2372
|
-
});
|
|
2373
|
-
}
|
|
2374
|
-
return errors;
|
|
2375
|
-
};
|
|
2376
|
-
var collectTsc = (lines, used) => {
|
|
2377
|
-
const errors = [];
|
|
2378
|
-
let current;
|
|
2379
|
-
let pretty = false;
|
|
2380
|
-
for (const [index, line] of lines.entries()) {
|
|
2381
|
-
if (used.has(index))
|
|
2382
|
-
continue;
|
|
2383
|
-
const plain = TSC_PLAIN_ERROR.exec(line);
|
|
2384
|
-
const match = plain ?? TSC_PRETTY_ERROR.exec(line);
|
|
2385
|
-
if (match !== null) {
|
|
2386
|
-
current = { tool: "tsc", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" };
|
|
2387
|
-
pretty = plain === null;
|
|
2388
|
-
errors.push(current);
|
|
2389
|
-
used.add(index);
|
|
2390
|
-
} else if (current !== undefined && TSC_CONTINUATION2.test(line) && !TSC_FRAME2.test(line)) {
|
|
2391
|
-
current.message += ` ${line.trim()}`;
|
|
2392
|
-
used.add(index);
|
|
2393
|
-
} else if (current !== undefined && pretty && (TSC_FRAME2.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
2394
|
-
used.add(index);
|
|
2395
|
-
} else if (!(pretty && line.trim() === "")) {
|
|
2396
|
-
current = undefined;
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
return errors;
|
|
2400
|
-
};
|
|
2401
|
-
var collectEslint = (lines, used) => {
|
|
2402
|
-
const errors = [];
|
|
2403
|
-
let file;
|
|
2404
|
-
for (const [index, line] of lines.entries()) {
|
|
2405
|
-
if (used.has(index))
|
|
2406
|
-
continue;
|
|
2407
|
-
const match = ESLINT_PROBLEM2.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
2408
|
-
if (match !== null && file !== undefined) {
|
|
2409
|
-
const text = match[4] ?? "";
|
|
2410
|
-
const rule = ESLINT_RULE.exec(text);
|
|
2411
|
-
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) });
|
|
2412
|
-
used.add(index);
|
|
2413
|
-
used.add(file);
|
|
2414
|
-
} else if (!isNoise(line) && !line.includes(": ") && ESLINT_FILE.test(line.trimEnd())) {
|
|
2415
|
-
file = index;
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
return errors;
|
|
2419
|
-
};
|
|
2420
|
-
var collectGo = (lines, used) => {
|
|
2421
|
-
const errors = [];
|
|
2422
|
-
for (const [index, line] of lines.entries()) {
|
|
2423
|
-
const match = used.has(index) ? null : GO_ERROR.exec(line);
|
|
2424
|
-
if (match === null)
|
|
2425
|
-
continue;
|
|
2426
|
-
const linter = GO_LINTER.exec(match[4] ?? "");
|
|
2427
|
-
errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), ...linter === null ? {} : { rule: linter[2] }, severity: "error", message: linter === null ? match[4] ?? "" : linter[1] ?? "" });
|
|
2428
|
-
used.add(index);
|
|
2429
|
-
}
|
|
2430
|
-
return errors;
|
|
2431
|
-
};
|
|
2432
|
-
function headerAbove(lines, arrow, used) {
|
|
2433
|
-
let at = arrow - 1;
|
|
2434
|
-
while (at > 0 && arrow - at <= MAX_CONTINUATION && !used.has(at) && CONTINUATION.test(lines[at] ?? "") && !ARROW.test(lines[at] ?? ""))
|
|
2435
|
-
at--;
|
|
2436
|
-
return at;
|
|
2437
|
-
}
|
|
2438
|
-
var collectArrowed = (lines, used) => {
|
|
2439
|
-
const errors = [];
|
|
2440
|
-
for (const [index, line] of lines.entries()) {
|
|
2441
|
-
const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
|
|
2442
|
-
const at = arrow === null ? -1 : headerAbove(lines, index, used);
|
|
2443
|
-
const header = at === -1 ? null : lines[at] ?? "";
|
|
2444
|
-
const cargo = header === null ? null : CARGO_HEADER.exec(header);
|
|
2445
|
-
const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
|
|
2446
|
-
if (arrow === null || cargo === null && ruff === null || used.has(at))
|
|
2447
|
-
continue;
|
|
2448
|
-
const [, file = "", row, column] = arrow;
|
|
2449
|
-
const fields = { file, line: Number(row), column: Number(column) };
|
|
2450
|
-
errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: file.endsWith(".rs") ? "cargo" : "kay check", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
|
|
2451
|
-
for (let taken = at;taken <= index; taken++)
|
|
2452
|
-
used.add(taken);
|
|
2453
|
-
for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
|
|
2454
|
-
if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
|
|
2455
|
-
break;
|
|
2456
|
-
used.add(frame);
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
return errors;
|
|
2460
|
-
};
|
|
2461
|
-
var collectRuff = (lines, used) => {
|
|
2462
|
-
const errors = [];
|
|
2463
|
-
for (const [index, line] of lines.entries()) {
|
|
2464
|
-
const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
|
|
2465
|
-
if (match === null)
|
|
2466
|
-
continue;
|
|
2467
|
-
errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
|
|
2468
|
-
used.add(index);
|
|
2469
|
-
}
|
|
2470
|
-
return errors;
|
|
2471
|
-
};
|
|
2472
|
-
var collectPytest = (lines, used) => {
|
|
2473
|
-
const errors = [];
|
|
2474
|
-
const silent = new Map;
|
|
2475
|
-
let section;
|
|
2476
|
-
const closeSection = () => {
|
|
2477
|
-
if (section === undefined || errors.length !== section.errors)
|
|
2478
|
-
return;
|
|
2479
|
-
const key = section.title.replace(PYTEST_ERROR_SECTION, "");
|
|
2480
|
-
silent.set(key, (silent.get(key) ?? 0) + 1);
|
|
2481
|
-
};
|
|
2482
|
-
const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
|
|
2483
|
-
const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
|
|
2484
|
-
if (start === -1)
|
|
2485
|
-
return errors;
|
|
2486
|
-
const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
|
|
2487
|
-
const stop = end === -1 ? lines.length : end;
|
|
2488
|
-
let message = [];
|
|
2489
|
-
let frame;
|
|
2490
|
-
for (let index = start;index < stop; index++) {
|
|
2491
|
-
const line = lines[index] ?? "";
|
|
2492
|
-
const failure = PYTEST_E_LINE.exec(line);
|
|
2493
|
-
if (failure !== null) {
|
|
2494
|
-
message.push((failure[1] ?? "").trim());
|
|
2495
|
-
} else {
|
|
2496
|
-
if (frame !== undefined && message.length > 0) {
|
|
2497
|
-
errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
|
|
2498
|
-
frame = undefined;
|
|
2499
|
-
}
|
|
2500
|
-
const location = PYTEST_LOCATION.exec(line);
|
|
2501
|
-
if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
|
|
2502
|
-
frame = { file: location[1] ?? "", line: Number(location[2]) };
|
|
2503
|
-
} else if (location !== null) {
|
|
2504
|
-
const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
|
|
2505
|
-
const first = message[0] ?? "";
|
|
2506
|
-
const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
|
|
2507
|
-
errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
|
|
2508
|
-
}
|
|
2509
|
-
const opened = PYTEST_SECTION.exec(line);
|
|
2510
|
-
if (opened !== null) {
|
|
2511
|
-
frame = undefined;
|
|
2512
|
-
closeSection();
|
|
2513
|
-
section = { title: opened[1] ?? "", errors: errors.length };
|
|
2514
|
-
}
|
|
2515
|
-
if (line.trim() !== "")
|
|
2516
|
-
message = [];
|
|
2517
|
-
}
|
|
2518
|
-
used.add(index);
|
|
2519
|
-
}
|
|
2520
|
-
if (frame !== undefined && message.length > 0)
|
|
2521
|
-
errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
|
|
2522
|
-
closeSection();
|
|
2523
|
-
for (let index = stop;index < lines.length; index++) {
|
|
2524
|
-
if (!PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
|
|
2525
|
-
continue;
|
|
2526
|
-
used.add(index);
|
|
2527
|
-
const [, file = "", rest, fileReason] = PYTEST_SUMMARY.exec(lines[index] ?? "") ?? [];
|
|
2528
|
-
const parts = summaryParts(file, rest, fileReason, silent);
|
|
2529
|
-
if (parts === undefined)
|
|
2530
|
-
continue;
|
|
2531
|
-
const { key, name, reason } = parts;
|
|
2532
|
-
const left = silent.get(key) ?? 0;
|
|
2533
|
-
silent.set(key, left - 1);
|
|
2534
|
-
errors.push({ tool: "pytest", file, line: 0, column: 0, severity: "error", message: reason ?? "failed", test: name === undefined ? file : `${file}::${name}` });
|
|
2535
|
-
}
|
|
2536
|
-
return errors;
|
|
2537
|
-
};
|
|
2538
|
-
function summaryParts(file, rest, fileReason, silent) {
|
|
2539
|
-
const keyOf = (name) => name === undefined ? file : name.replaceAll("::", ".");
|
|
2540
|
-
const candidates = [];
|
|
2541
|
-
if (rest === undefined) {
|
|
2542
|
-
candidates.push({ name: undefined, reason: fileReason });
|
|
2543
|
-
} else {
|
|
2544
|
-
for (let at = rest.indexOf(" - ");at !== -1; at = rest.indexOf(" - ", at + 1))
|
|
2545
|
-
candidates.push({ name: rest.slice(0, at), reason: rest.slice(at + 3) });
|
|
2546
|
-
candidates.push({ name: rest, reason: undefined });
|
|
2547
|
-
}
|
|
2548
|
-
const found = candidates.find((candidate) => (silent.get(keyOf(candidate.name)) ?? 0) > 0);
|
|
2549
|
-
return found === undefined ? undefined : { key: keyOf(found.name), ...found };
|
|
2550
|
-
}
|
|
2551
|
-
var collectGeneric = (lines, used) => {
|
|
2552
|
-
const errors = [];
|
|
2553
|
-
for (const [index, line] of lines.entries()) {
|
|
2554
|
-
const match = used.has(index) ? null : GENERIC_LINE.exec(line);
|
|
2555
|
-
if (match === null)
|
|
2556
|
-
continue;
|
|
2557
|
-
used.add(index);
|
|
2558
|
-
if (match[4] === "note")
|
|
2559
|
-
continue;
|
|
2560
|
-
const text = match[5] ?? "";
|
|
2561
|
-
const ruled = GENERIC_RULE.exec(text);
|
|
2562
|
-
const rule = ruled?.[1] ?? ruled?.[2];
|
|
2563
|
-
errors.push({ tool: "generic", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), rule, severity: match[4] === "warning" ? "warning" : "error", message: ruled === null ? text : text.slice(0, ruled.index).trimEnd() });
|
|
2564
|
-
}
|
|
2565
|
-
return errors;
|
|
2566
|
-
};
|
|
2567
|
-
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint, collectGeneric];
|
|
2568
|
-
function parseErrors(output) {
|
|
2569
|
-
const lines = stripAnsi(output).split(LINE_BREAK);
|
|
2570
|
-
if (BASH_ECHO2.test(lines[0] ?? ""))
|
|
2571
|
-
lines.shift();
|
|
2572
|
-
const used = new Set;
|
|
2573
|
-
const seen = new Set;
|
|
2574
|
-
const errors = COLLECTORS.flatMap((collect) => collect(lines, used)).filter((error) => {
|
|
2575
|
-
const key = [error.file, error.line, error.column, error.message, error.test].join("\x00");
|
|
2576
|
-
if (seen.has(key))
|
|
2577
|
-
return false;
|
|
2578
|
-
seen.add(key);
|
|
2579
|
-
return true;
|
|
2580
|
-
});
|
|
2581
|
-
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
2582
|
-
return { errors, unrecognised };
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
|
-
// src/run.ts
|
|
2586
|
-
import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
|
|
2587
|
-
import { basename as basename2, join as join9 } from "path";
|
|
2588
|
-
import process21 from "process";
|
|
2589
|
-
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2590
|
-
var RESULTS_FILE = "results.json";
|
|
2591
|
-
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2592
|
-
async function logDirectory(cwd) {
|
|
2593
|
-
const root = await privateLogDirectory("check");
|
|
2594
|
-
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2595
|
-
const path = join9(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process21.pid}`);
|
|
2596
|
-
await mkdir2(path, { mode: 448 });
|
|
2597
|
-
return path;
|
|
2598
|
-
}
|
|
2599
|
-
async function lastResults(cwd) {
|
|
2600
|
-
const root = await privateLogDirectory("check");
|
|
2601
|
-
const prefix = runPrefix(cwd);
|
|
2602
|
-
let latest;
|
|
2603
|
-
for (const name of await readdir2(root)) {
|
|
2604
|
-
if (!name.startsWith(prefix))
|
|
2605
|
-
continue;
|
|
2606
|
-
const file = join9(root, name, RESULTS_FILE);
|
|
2607
|
-
try {
|
|
2608
|
-
const { mtimeMs } = await stat2(file);
|
|
2609
|
-
if (latest === undefined || mtimeMs > latest.time)
|
|
2610
|
-
latest = { time: mtimeMs, file };
|
|
2611
|
-
} catch {}
|
|
2612
|
-
}
|
|
2613
|
-
if (latest === undefined)
|
|
2614
|
-
return;
|
|
2615
|
-
return JSON.parse(await Bun.file(latest.file).text());
|
|
2616
|
-
}
|
|
2617
|
-
async function lastFailed(cwd) {
|
|
2618
|
-
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
2619
|
-
}
|
|
2620
|
-
async function saveLog(output) {
|
|
2621
|
-
const root = await privateLogDirectory("errs");
|
|
2622
|
-
await sweepLogs(root);
|
|
2623
|
-
const path = join9(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process21.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2624
|
-
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2625
|
-
return path;
|
|
2626
|
-
}
|
|
2627
|
-
async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}) {
|
|
2628
|
-
const started = Date.now();
|
|
2629
|
-
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2630
|
-
cwd,
|
|
2631
|
-
env: { ...process21.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2632
|
-
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2633
|
-
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2634
|
-
});
|
|
2635
|
-
const output = stripAnsi(text);
|
|
2636
|
-
await writeFile(logFile, output, { mode: 384, flag: "wx" });
|
|
2637
|
-
return { ok: code === 0, ms: Date.now() - started, output, ...timedOut ? { timedOut } : {} };
|
|
2638
|
-
}
|
|
2639
|
-
async function refusedStep(reason, logFile) {
|
|
2640
|
-
await writeFile(logFile, reason, { mode: 384, flag: "wx" });
|
|
2641
|
-
return { ok: false, ms: 0, output: reason };
|
|
2642
|
-
}
|
|
2643
|
-
function outcomeJson(name, command, logFile, outcome, service) {
|
|
2644
|
-
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) } };
|
|
2645
|
-
}
|
|
2646
|
-
function printOutcome(name, width, command, logFile, outcome) {
|
|
2647
|
-
const colors = paint(process21.stdout);
|
|
2648
|
-
const path = role("path", process21.stdout);
|
|
2649
|
-
const took = colors.dim(formatDuration(outcome.ms));
|
|
2650
|
-
if (outcome.ok) {
|
|
2651
|
-
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
2652
|
-
return;
|
|
2653
|
-
}
|
|
2654
|
-
const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
|
|
2655
|
-
console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
|
|
2656
|
-
if (outcome.timedOut === true)
|
|
2657
|
-
console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
|
|
2658
|
-
console.log(failureExcerpt(outcome.output).split(`
|
|
2659
|
-
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
2660
|
-
`));
|
|
2661
|
-
}
|
|
2662
|
-
|
|
2663
|
-
// src/errs.ts
|
|
2664
|
-
var usage2 = `errs [options] [log]
|
|
3
|
+
import{warn,stripAnsi,printJson,readInput,jsonOption,fail,parse}from"./chunk-ef4tt9f7.js";import{holdSignals,runCommand,runMain,bunCheckFields,LOG_PATTERNS,version}from"./chunk-m3r6m4gc.js";import{place,argvIn,Stack,placeOptions,placeSettings,saveLog}from"./chunk-98tbscp4.js";import process2 from"process";import{relative}from"path";import process from"process";var E2E_NOISE=[/^(?: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)/,/^[\u00B7F\u00D7\u00B0T\u00B1]+$/,/^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/],PLAYWRIGHT_HEADER=/^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/,PLAYWRIGHT_SUMMARY=/^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/,PLAYWRIGHT_ENTRY=/^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/,PLAYWRIGHT_RETRY=/^\s+Retry #\d+ \u2500+$/,FRAME=/^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/,EXPECTED=/^\s+Expected: (.*)$/,RECEIVED=/^\s+Received: (.*)$/,VITEST_FAIL=/^ FAIL {2}(?:\|[^|]+\| )?(.+)$/,VITEST_SUITE=/^(.+?) \[ .+ \]$/,VITEST_FRAME=/^\s*\u276F (\S+):(\d+):(\d+)$/;function key(project,file,line,column,title){return`${project??""}|${file}:${line}:${column} \u203A ${title}`}function firstFrame(block){return block.map((line)=>FRAME.exec(line)).find((match)=>match!==null&&!match[1]?.includes("node_modules"))??void 0}var collectPlaywright=(lines,used)=>{let flaky=new Set,section="";for(let[index,line]of lines.entries()){let summary=PLAYWRIGHT_SUMMARY.exec(line),entry=PLAYWRIGHT_ENTRY.exec(line);if(summary!==null)section=summary[1]??"",used.add(index);else if(entry!==null&§ion!==""){if(section==="flaky")flaky.add(key(entry[1],entry[2],entry[3],entry[4],entry[5]));used.add(index)}}let errors=[];for(let index=0;index<lines.length;index++){let header=PLAYWRIGHT_HEADER.exec(lines[index]??"");if(header===null)continue;let end=index+1;while(end<lines.length&&!PLAYWRIGHT_HEADER.test(lines[end]??"")&&!PLAYWRIGHT_SUMMARY.test(lines[end]??""))end++;for(let at=index;at<end;at++)used.add(at);let[,project,file,line,column,title]=header,retry=lines.findIndex((text,at)=>at>index&&at<end&&PLAYWRIGHT_RETRY.test(text)),block=lines.slice(index+1,retry===-1?end:retry),frame=firstFrame(block),message=block.find((text)=>text.trim()!=="")?.trim()??"failed",expected=block.map((text)=>EXPECTED.exec(text)?.[1]?.trim()).find((text)=>text!==void 0),received=block.map((text)=>RECEIVED.exec(text)?.[1]?.trim()).find((text)=>text!==void 0),values=expected===void 0||received===void 0?"":` (expected ${expected}, received ${received})`;if(index=end-1,flaky.has(key(project,file,line,column,title)))continue;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===void 0?"":`[${project}] `}${title}`})}return errors},collectVitest=(lines,used)=>{let errors=[];for(let index=0;index<lines.length;index++){let header=VITEST_FAIL.exec(lines[index]??"")?.[1];if(header===void 0)continue;let end=index+1;while(end<lines.length&&!(lines[end]??"").startsWith("\u23AF")&&!VITEST_FAIL.test(lines[end]??""))end++;for(let at=index;at<end;at++)used.add(at);let block=lines.slice(index+1,end),frame=block.map((text)=>VITEST_FRAME.exec(text)).find((match)=>match!==null&&!match[1]?.includes("node_modules")),suite=VITEST_SUITE.exec(header)?.[1],[file="",...names]=(suite??header).split(" > ");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===void 0&&names.length>0?{test:names.join(" > ")}:{}}),index=end-1}return errors};var PHP_NOISE=[/^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,/^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,/^ -{3,}(?: -{3,})*\s*$/,/^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,/^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,/^(?: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:)/];var PHPUNIT_HEADER=/^There (?:was|were) \d+ ([a-z ]+?)s?:$/i,PHPUNIT_TRIGGERED=/^\d+ tests? triggered \d+ [\w ]+?s?:$/,PHPUNIT_END=/^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/,PHPUNIT_ITEM=/^\d+\) (.*)$/,PHP_LOCATION=/^([\w./-]+\.php):(\d+)$/,PHPSTAN_FILE=/^ {2}Line {3}(\S.*)$/,PHPSTAN_GENERAL=/^ {2}Error\s*$/,PHPSTAN_MESSAGE=/^ {2}(\S.*)$/,PHPSTAN_ROW=/^ {2}(\d+|-) +(\S.*)$/,PHPSTAN_CONTINUATION=/^ {9}(\S.*)$/,PHPSTAN_IDENTIFIER=/^ {9}\uD83E\uDEAA\s+(\S+)\s*$/,PHPSTAN_TIP=/^ {9}\uD83D\uDCA1/,PHPSTAN_BORDER=/^ -{3,}(?: -{3,})*\s*$/,PHPSTAN_RAW=/^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/,PHPSTAN_JSON=/^\{.*"totals"/,CS_FIXER_FILE=/^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/,CS_FIXER_DIFF_START=/^\s+-+ begin diff -+$/,CS_FIXER_DIFF_END=/^\s+-+ end diff -+$/;function isHeader(line){return PHPUNIT_HEADER.test(line)||PHPUNIT_TRIGGERED.test(line)}function diffSummary(message){let start=message.findIndex((line)=>line==="+++ Actual");if(start===-1)return"";let changed=message.slice(start+1).filter((line)=>line.startsWith("-")||line.startsWith("+")).map((line)=>`${line[0]} ${line.slice(1).trim()}`),shown=changed.slice(0,6).join(" | ");return changed.length===0?"":` (${shown}${changed.length>6?" | ...":""})`}function phpunitError(test,body){let at=body.findIndex((line)=>PHP_LOCATION.test(line)),location=PHP_LOCATION.exec(body[at]??""),message=body.slice(0,at===-1?body.length:at).map((line)=>line.trimEnd()),first=message.find((line)=>line.trim()!=="")??"failed";return{tool:"phpunit",file:location?.[1]??"",line:Number(location?.[2]??0),column:0,severity:"error",message:`${first}${diffSummary(message)}`,test}}var collectPhpunit=(lines,used)=>{let errors=[];for(let index=0;index<lines.length;index++){let line=lines[index]??"",kind=PHPUNIT_HEADER.exec(line)?.[1];if(kind===void 0&&!PHPUNIT_TRIGGERED.test(line))continue;let end=index+1;while(end<lines.length&&!PHPUNIT_END.test(lines[end]??"")&&!isHeader(lines[end]??""))end++;for(let at=index;at<end;at++)used.add(at);if(kind==="error"||kind==="failure"){let starts=Array.from({length:end-index-1},(_,at)=>index+1+at).filter((at)=>PHPUNIT_ITEM.test(lines[at]??""));for(let[position,start]of starts.entries())errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start]??"")?.[1]??"",lines.slice(start+1,starts[position+1]??end)))}index=end-1}return errors};function appendMessage(error,text){error.message=`${error.message} ${text}`}function phpstanJson(text){try{let report=JSON.parse(text);return[...Object.entries(report.files??{}).flatMap(([file,entry])=>entry.messages.map((message)=>({file,line:message.line??0,message:message.message,...message.identifier===void 0?{}:{rule:message.identifier}}))),...(report.errors??[]).map((message)=>({file:"",line:0,message}))]}catch{return}}var collectPhpstan=(lines,used)=>{let errors=[],file,current,rows=0,tip=!1,general=!1;for(let[index,text]of lines.entries()){let line=text.trimEnd();if(used.has(index))continue;if(PHPSTAN_JSON.test(line)){let parsed=phpstanJson(line);for(let entry of parsed??[])errors.push({tool:"phpstan",file:entry.file,line:entry.line,column:0,severity:"error",message:entry.message,...entry.rule===void 0?{}:{rule:entry.rule}});if(parsed!==void 0)used.add(index);continue}let raw=PHPSTAN_RAW.exec(line);if(raw!==null){errors.push({tool:"phpstan",file:raw[1]??"",line:Number(raw[2]),column:0,severity:"error",message:raw[3]??""}),used.add(index);continue}let header=PHPSTAN_FILE.exec(line);if(header!==null||PHPSTAN_GENERAL.test(line)){file=header?.[1]??"",general=header===null,current=void 0,rows=0,used.add(index);continue}if(file===void 0)continue;let message=PHPSTAN_MESSAGE.exec(line)?.[1];if(general&&message!==void 0&&!PHPSTAN_BORDER.test(line)){errors.push({tool:"phpstan",file:"",line:0,column:0,severity:"error",message}),rows++,used.add(index);continue}let row=PHPSTAN_ROW.exec(line),identifier=PHPSTAN_IDENTIFIER.exec(line)?.[1],continuation=PHPSTAN_CONTINUATION.exec(line)?.[1];if(PHPSTAN_BORDER.test(line)&&rows>0)file=void 0,general=!1,current=void 0;else if(row!==null)current={tool:"phpstan",file,line:row[1]==="-"?0:Number(row[1]),column:0,severity:"error",message:row[2]??""},errors.push(current),rows++,tip=!1,used.add(index);else if(identifier!==void 0&¤t!==void 0)current.rule=identifier,used.add(index);else if(PHPSTAN_TIP.test(line))tip=!0,used.add(index);else if(continuation!==void 0&¤t!==void 0){if(!tip)appendMessage(current,continuation);used.add(index)}}return errors},collectCsFixer=(lines,used)=>{let errors=[];for(let index=0;index<lines.length;index++){let match=CS_FIXER_FILE.exec(lines[index]??"");if(match===null)continue;if(errors.push({tool:"php-cs-fixer",file:match[1]??"",line:0,column:0,...match[2]===void 0?{}:{rule:match[2]},severity:"error",message:"style issues to fix"}),used.add(index),!CS_FIXER_DIFF_START.test(lines[index+1]??""))continue;let end=lines.findIndex((text,at)=>at>index&&CS_FIXER_DIFF_END.test(text));for(let at=index+1;at<=(end===-1?index+1:end);at++)used.add(at);index=end===-1?index+1:end}return errors};var{BASH_ECHO,DURATION,BOUNDARY,BUN_TEST_SUMMARY,BUN_CHECK_SUMMARY,TSC_CONTINUATION,TSC_FRAME,TSC_SUMMARY,ESLINT_PROBLEM,ESLINT_SUMMARY}=LOG_PATTERNS,TSC_PLAIN_ERROR=/^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/,TSC_PRETTY_ERROR=/^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/,TSC_SOURCE_LINE=/^\d+ /,ESLINT_FIELDS=/^ +(\d+):(\d+) +(error|warning) +(\S.*)$/,ESLINT_RULE=/ {2,}(\S+)$/,ESLINT_FILE=/^(?:\/|~\/|\.{1,2}[/\\]|[a-z]:\\)|^[^\s/\\]+[/\\]\S*$/i,BUN_TEST_EXPECTED=/^Expected: (.*)$/,BUN_TEST_RECEIVED=/^Received: (.*)$/,BUN_TEST_FRAME=/^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/,BUN_TEST_FILE=/^\S+\.test\.[jt]sx?:$/,GO_ERROR=/^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/,GO_LINTER=/^(.*\S)\s+\(([a-z][\w-]*)\)$/,GO_NOISE=/^# \S+(?: \[\S+\])?$/,ARROW=/^\s*--> (.+?):(\d+):(\d+)$/,CARGO_HEADER=/^(error|warning)(?:\[([\w-]+)\])?: (.*)$/,LINE_BREAK=/\r?\n/,CONTINUATION=/^\s+\S/,MAX_CONTINUATION=20,KAY_SUMMARY=/^(?:\d+ errors?(?:, \d+ warnings?)?|\d+ warnings?)(?:, failing under --deny-warnings)?$|^checked with /,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)/,RUFF_CONCISE=/^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/,RUFF_HEADER=/^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/,RUFF_NOISE=/^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/,PYTEST_LOCATION=/^(\S+\.py):(\d+): (\S.*)$/,PYTEST_E_LINE=/^E {3}(.*)$/,PYTEST_BANNER=/^={3,} (.*?) ={3,}$/,PYTEST_FAILURES=new Set(["FAILURES","ERRORS"]),PYTEST_SUMMARY_LINE=/^(?:FAILED|ERROR) \S/,PYTEST_FRAME=/^in \S/,PYTEST_SECTION=/^_{3,} (.*) _{3,}$/,PYTEST_SUMMARY=/^(?:FAILED|ERROR) ([^\s:]+?\.py)(?:::(.*)| - (.*))?$/,PYTEST_ERROR_SECTION=/^ERROR (?:at (?:setup|teardown) of |collecting )/,PYTEST_EXCEPTION_END=/[\s:]/,PYTEST_NOISE=/^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/,GENERIC_LINE=/^(\S[^:]*):(\d+)(?::(\d+))?: (?:fatal )?(error|warning|note): (.*)$/,GENERIC_RULE=/\s(?:\[([\w-]+)\]|\(([a-z][\w-]*)\))$/,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)/;function isNoise(line){return line.trim()===""||[NOISE,BUN_TEST_SUMMARY,BUN_CHECK_SUMMARY,TSC_SUMMARY,ESLINT_SUMMARY,BOUNDARY,BASH_ECHO,GO_NOISE,CARGO_NOISE,KAY_SUMMARY,RUFF_NOISE,PYTEST_NOISE,PYTEST_BANNER,...PHP_NOISE,...E2E_NOISE].some((pattern)=>pattern.test(line))}var collectBunCheck=(lines,used)=>{let errors=[];for(let index=0;index<lines.length;index++){if(!(lines[index]??"").startsWith("<error file="))continue;let end=lines.findIndex((line,at)=>at>=index&&line==="</error>");if(end===-1)break;let{file,line,column,code,message}=bunCheckFields(lines.slice(index,end+1).join(`
|
|
4
|
+
`));errors.push({tool:"bun check",file,line:Number(line),column:Number(column),rule:code,severity:"error",message:message.replaceAll(/\s*\n\s*/g," ")});for(let at=index;at<=end;at++)used.add(at);index=end}return errors},collectBunTest=(lines,used)=>{let errors=[],seen=new Set,names=new Set;for(let[index,line]of lines.entries()){if(!line.startsWith("(fail) "))continue;used.add(index);let test=line.slice(7).replace(DURATION,""),start=lines.findLastIndex((text,at)=>at<index&&BOUNDARY.test(text))+1,block=lines.slice(start,index),failure=block.findIndex((text)=>text.startsWith("error:"));for(let at=start;at<index;at++)used.add(at);let frame=block.slice(Math.max(failure,0)).map((text)=>BUN_TEST_FRAME.exec(text)).find((match)=>match!==null),header=lines.slice(0,index).findLast((text)=>BUN_TEST_FILE.test(text)),key=`${header??""}\x00${test}`;if(seen.has(key)||failure===-1&&names.has(test))continue;seen.add(key),names.add(test);let expected=block.map((text)=>BUN_TEST_EXPECTED.exec(text)?.[1]).find((text)=>text!==void 0),received=block.map((text)=>BUN_TEST_RECEIVED.exec(text)?.[1]).find((text)=>text!==void 0),reason=failure===-1?"failed":(block[failure]??"").slice(6).trim(),values=expected===void 0||received===void 0?"":` (expected ${expected}, received ${received})`;errors.push({tool:"bun test",file:frame?.[1]??header?.replace(":","")??"",line:Number(frame?.[2]??0),column:Number(frame?.[3]??0),severity:"error",message:`${reason}${values}`,test})}return errors},collectTsc=(lines,used)=>{let errors=[],current,pretty=!1;for(let[index,line]of lines.entries()){if(used.has(index))continue;let plain=TSC_PLAIN_ERROR.exec(line),match=plain??TSC_PRETTY_ERROR.exec(line);if(match!==null)current={tool:"tsc",file:match[1]??"",line:Number(match[2]),column:Number(match[3]),rule:match[4],severity:"error",message:match[5]??""},pretty=plain===null,errors.push(current),used.add(index);else if(current!==void 0&&TSC_CONTINUATION.test(line)&&!TSC_FRAME.test(line))current.message+=` ${line.trim()}`,used.add(index);else if(current!==void 0&&pretty&&(TSC_FRAME.test(line)||TSC_SOURCE_LINE.test(line)))used.add(index);else if(!(pretty&&line.trim()===""))current=void 0}return errors},collectEslint=(lines,used)=>{let errors=[],file;for(let[index,line]of lines.entries()){if(used.has(index))continue;let match=ESLINT_PROBLEM.test(line)?ESLINT_FIELDS.exec(line):null;if(match!==null&&file!==void 0){let text=match[4]??"",rule=ESLINT_RULE.exec(text);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)}),used.add(index),used.add(file)}else if(!isNoise(line)&&!line.includes(": ")&&ESLINT_FILE.test(line.trimEnd()))file=index}return errors},collectGo=(lines,used)=>{let errors=[];for(let[index,line]of lines.entries()){let match=used.has(index)?null:GO_ERROR.exec(line);if(match===null)continue;let linter=GO_LINTER.exec(match[4]??"");errors.push({tool:"go",file:match[1]??"",line:Number(match[2]),column:Number(match[3]??0),...linter===null?{}:{rule:linter[2]},severity:"error",message:linter===null?match[4]??"":linter[1]??""}),used.add(index)}return errors};function headerAbove(lines,arrow,used){let at=arrow-1;while(at>0&&arrow-at<=MAX_CONTINUATION&&!used.has(at)&&CONTINUATION.test(lines[at]??"")&&!ARROW.test(lines[at]??""))at--;return at}var collectArrowed=(lines,used)=>{let errors=[];for(let[index,line]of lines.entries()){let arrow=used.has(index)||index===0?null:ARROW.exec(line),at=arrow===null?-1:headerAbove(lines,index,used),header=at===-1?null:lines[at]??"",cargo=header===null?null:CARGO_HEADER.exec(header),ruff=header===null||cargo!==null?null:RUFF_HEADER.exec(header);if(arrow===null||cargo===null&&ruff===null||used.has(at))continue;let[,file="",row,column]=arrow,fields={file,line:Number(row),column:Number(column)};errors.push(cargo===null?{tool:"ruff",...fields,rule:ruff?.[1],severity:"error",message:ruff?.[2]??""}:{tool:file.endsWith(".rs")?"cargo":"kay check",...fields,rule:cargo[2],severity:cargo[1]==="warning"?"warning":"error",message:cargo[3]??""});for(let taken=at;taken<=index;taken++)used.add(taken);for(let frame=index+1;frame<lines.length&&(lines[frame]??"").trim()!=="";frame++){if(CARGO_HEADER.test(lines[frame]??"")||RUFF_HEADER.test(lines[frame]??""))break;used.add(frame)}}return errors},collectRuff=(lines,used)=>{let errors=[];for(let[index,line]of lines.entries()){let match=used.has(index)?null:RUFF_CONCISE.exec(line);if(match===null)continue;errors.push({tool:"ruff",file:match[1]??"",line:Number(match[2]),column:Number(match[3]),rule:match[4],severity:"error",message:match[5]??""}),used.add(index)}return errors},collectPytest=(lines,used)=>{let errors=[],silent=new Map,section,closeSection=()=>{if(section===void 0||errors.length!==section.errors)return;let key=section.title.replace(PYTEST_ERROR_SECTION,"");silent.set(key,(silent.get(key)??0)+1)},title=(line)=>PYTEST_BANNER.exec(line??"")?.[1],start=lines.findIndex((line)=>PYTEST_FAILURES.has(title(line)??""));if(start===-1)return errors;let end=lines.findIndex((line,index)=>index>start&&title(line)!==void 0&&!PYTEST_FAILURES.has(title(line)??"")),stop=end===-1?lines.length:end,message=[],frame;for(let index=start;index<stop;index++){let line=lines[index]??"",failure=PYTEST_E_LINE.exec(line);if(failure!==null)message.push((failure[1]??"").trim());else{if(frame!==void 0&&message.length>0)errors.push({tool:"pytest",...frame,column:0,severity:"error",message:message[0]??""}),frame=void 0;let location=PYTEST_LOCATION.exec(line);if(location!==null&&PYTEST_FRAME.test(location[3]??""))frame={file:location[1]??"",line:Number(location[2])};else if(location!==null){let[exception=""]=(location[3]??"").split(PYTEST_EXCEPTION_END),first=message[0]??"",text=first===""||first.startsWith(exception)?first||(location[3]??""):`${location[3]??""}: ${first}`;errors.push({tool:"pytest",file:location[1]??"",line:Number(location[2]),column:0,severity:"error",message:text})}let opened=PYTEST_SECTION.exec(line);if(opened!==null)frame=void 0,closeSection(),section={title:opened[1]??"",errors:errors.length};if(line.trim()!=="")message=[]}used.add(index)}if(frame!==void 0&&message.length>0)errors.push({tool:"pytest",...frame,column:0,severity:"error",message:message[0]??""});closeSection();for(let index=stop;index<lines.length;index++){if(!PYTEST_SUMMARY_LINE.test(lines[index]??""))continue;used.add(index);let[,file="",rest,fileReason]=PYTEST_SUMMARY.exec(lines[index]??"")??[],parts=summaryParts(file,rest,fileReason,silent);if(parts===void 0)continue;let{key,name,reason}=parts,left=silent.get(key)??0;silent.set(key,left-1),errors.push({tool:"pytest",file,line:0,column:0,severity:"error",message:reason??"failed",test:name===void 0?file:`${file}::${name}`})}return errors};function summaryParts(file,rest,fileReason,silent){let keyOf=(name)=>name===void 0?file:name.replaceAll("::","."),candidates=[];if(rest===void 0)candidates.push({name:void 0,reason:fileReason});else{for(let at=rest.indexOf(" - ");at!==-1;at=rest.indexOf(" - ",at+1))candidates.push({name:rest.slice(0,at),reason:rest.slice(at+3)});candidates.push({name:rest,reason:void 0})}let found=candidates.find((candidate)=>(silent.get(keyOf(candidate.name))??0)>0);return found===void 0?void 0:{key:keyOf(found.name),...found}}var collectGeneric=(lines,used)=>{let errors=[];for(let[index,line]of lines.entries()){let match=used.has(index)?null:GENERIC_LINE.exec(line);if(match===null)continue;if(used.add(index),match[4]==="note")continue;let text=match[5]??"",ruled=GENERIC_RULE.exec(text),rule=ruled?.[1]??ruled?.[2];errors.push({tool:"generic",file:match[1]??"",line:Number(match[2]),column:Number(match[3]??0),rule,severity:match[4]==="warning"?"warning":"error",message:ruled===null?text:text.slice(0,ruled.index).trimEnd()})}return errors},COLLECTORS=[collectBunCheck,collectBunTest,collectVitest,collectPlaywright,collectPhpunit,collectPhpstan,collectCsFixer,collectPytest,collectArrowed,collectRuff,collectGo,collectTsc,collectEslint,collectGeneric];function parseErrors(output){let lines=stripAnsi(output).split(LINE_BREAK);if(BASH_ECHO.test(lines[0]??""))lines.shift();let used=new Set,seen=new Set,errors=COLLECTORS.flatMap((collect)=>collect(lines,used)).filter((error)=>{let key=[error.file,error.line,error.column,error.message,error.test].join("\x00");if(seen.has(key))return!1;return seen.add(key),!0}),unrecognised=lines.filter((line,index)=>!used.has(index)&&!isNoise(line)).length;return{errors,unrecognised}}var usage=`errs [options] [log]
|
|
2665
5
|
errs [options] -- <command> [args...]
|
|
2666
6
|
errs --in <service> | --host -- <command> [args...]
|
|
2667
7
|
|
|
2668
8
|
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, eslint, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer, go, cargo, ruff or pytest log, or any \`file:line[:col]: error|warning: message\` line, read from a file, from stdin or from the output of the command run after --.
|
|
2669
9
|
The lines no format recognised are counted on stderr, never dropped, and a command's full output is saved to a log file whose path is printed with that count.
|
|
2670
|
-
A command runs inside the running compose service that bind-mounts the current folder and never starts one; --in picks the service, --host forces the host
|
|
2671
|
-
var EXITS = [[0, "no error was found and the command, if any, passed"], [1, "errors were found or the command failed"], [2, "a usage error"]];
|
|
2672
|
-
var options = {
|
|
2673
|
-
...placeOptions,
|
|
2674
|
-
json: jsonOption("{errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}")
|
|
2675
|
-
};
|
|
2676
|
-
function display(file, cwd) {
|
|
2677
|
-
const path = file.startsWith("/") ? relative2(cwd, file) : file;
|
|
2678
|
-
return path.startsWith("..") ? file : path;
|
|
2679
|
-
}
|
|
2680
|
-
function formatError(error, cwd) {
|
|
2681
|
-
const where = `${display(error.file, cwd)}:${error.line}:${error.column}`;
|
|
2682
|
-
const label = error.test === undefined ? "" : `${error.test}: `;
|
|
2683
|
-
const level = error.severity === "warning" ? "warning: " : "";
|
|
2684
|
-
const rule = error.rule === undefined ? "" : ` (${error.rule})`;
|
|
2685
|
-
return `${where}: ${level}${label}${error.message}${rule}`;
|
|
2686
|
-
}
|
|
2687
|
-
async function readInput2(command, run, settings, cwd) {
|
|
2688
|
-
const [path] = command;
|
|
2689
|
-
if (!run && (settings.service !== undefined || settings.host === true))
|
|
2690
|
-
fail("--in and --host apply to a command run after --");
|
|
2691
|
-
if (!run && (path === undefined || path === "-"))
|
|
2692
|
-
return { text: await readInput("-", { noStdin: "give a log, a command after --, or pipe the output on stdin" }) };
|
|
2693
|
-
if (!run && path !== undefined)
|
|
2694
|
-
return { text: await readInput(path), log: path };
|
|
2695
|
-
if (path === undefined)
|
|
2696
|
-
fail("give the command after --");
|
|
2697
|
-
const placement = await place(cwd, path, settings);
|
|
2698
|
-
const down = placement === undefined ? undefined : await new Stack().problem(placement);
|
|
2699
|
-
if (down !== undefined)
|
|
2700
|
-
fail(down, 1);
|
|
2701
|
-
const held = holdSignals();
|
|
2702
|
-
let ran;
|
|
2703
|
-
try {
|
|
2704
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process22.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
2705
|
-
} catch (error) {
|
|
2706
|
-
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2707
|
-
} finally {
|
|
2708
|
-
held.release();
|
|
2709
|
-
}
|
|
2710
|
-
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
2711
|
-
}
|
|
2712
|
-
async function errs(args, cwd = process22.cwd()) {
|
|
2713
|
-
const first = args[0];
|
|
2714
|
-
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2715
|
-
const parsed = parse(bare ? [] : args, usage2, options, { exits: EXITS, rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
2716
|
-
if (parsed.positionals.length > 1)
|
|
2717
|
-
fail(`give one log, or a command after --
|
|
2718
|
-
|
|
2719
|
-
${usage2}`);
|
|
2720
|
-
const input = await readInput2(bare ? args : parsed.rest ?? parsed.positionals, bare || parsed.rest !== undefined, placeSettings(parsed.values), cwd);
|
|
2721
|
-
const { errors, unrecognised } = parseErrors(input.text);
|
|
2722
|
-
if (parsed.values.json === true) {
|
|
2723
|
-
printJson({ errors, unrecognised, ...input.log === undefined ? {} : { log: input.log }, ...input.code === undefined ? {} : { code: input.code } });
|
|
2724
|
-
} else {
|
|
2725
|
-
for (const error of errors)
|
|
2726
|
-
console.log(formatError(error, cwd));
|
|
2727
|
-
if (unrecognised > 0)
|
|
2728
|
-
warn(`${unrecognised} ${unrecognised === 1 ? "line" : "lines"} not recognised`, input.log === undefined ? undefined : `see ${input.log}`);
|
|
2729
|
-
if (errors.length === 0 && input.code !== undefined && input.code !== 0)
|
|
2730
|
-
warn(`the command exited ${input.code} with no error recognised`, input.log === undefined ? undefined : `see ${input.log}`);
|
|
2731
|
-
}
|
|
2732
|
-
return errors.length > 0 || (input.code ?? 0) !== 0 ? 1 : 0;
|
|
2733
|
-
}
|
|
10
|
+
A command runs inside the running compose service that bind-mounts the current folder and never starts one; --in picks the service, --host forces the host.`,EXITS=[[0,"no error was found and the command, if any, passed"],[1,"errors were found or the command failed"],[2,"a usage error"]],options={...placeOptions,json:jsonOption("{errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}")};function display(file,cwd){let path=file.startsWith("/")?relative(cwd,file):file;return path.startsWith("..")?file:path}function formatError(error,cwd){let where=`${display(error.file,cwd)}:${error.line}:${error.column}`,label=error.test===void 0?"":`${error.test}: `,level=error.severity==="warning"?"warning: ":"",rule=error.rule===void 0?"":` (${error.rule})`;return`${where}: ${level}${label}${error.message}${rule}`}async function readInput2(command,run,settings,cwd){let[path]=command;if(!run&&(settings.service!==void 0||settings.host===!0))fail("--in and --host apply to a command run after --");if(!run&&(path===void 0||path==="-"))return{text:await readInput("-",{noStdin:"give a log, a command after --, or pipe the output on stdin"})};if(!run&&path!==void 0)return{text:await readInput(path),log:path};if(path===void 0)fail("give the command after --");let placement=await place(cwd,path,settings),down=placement===void 0?void 0:await new Stack().problem(placement);if(down!==void 0)fail(down,1);let held=holdSignals(),ran;try{ran=await runCommand(placement===void 0?command:argvIn(placement,command),{...placement===void 0?{}:{cwd:placement.composeDir},env:{...process.env,NO_COLOR:"1",FORCE_COLOR:"0"},onStart:(child)=>held.forward(child)})}catch(error){fail(`cannot run ${command[0]}: ${error instanceof Error?error.message:String(error)}`)}finally{held.release()}return{text:stripAnsi(ran.text),log:await saveLog(ran.output),code:ran.code}}async function errs(args,cwd=process.cwd()){let first=args[0],bare=first!==void 0&&!first.startsWith("-")&&!await Bun.file(first).exists(),parsed=parse(bare?[]:args,usage,options,{exits:EXITS,rest:!0,replaces:"reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them",examples:[["errs -- bun run check","the type errors of a run"],["bun test 2>&1 | errs","the failed tests from stdin"],["errs -- vendor/bin/phpunit","each failed PHP test with its file and line"]]});if(parsed.positionals.length>1)fail(`give one log, or a command after --
|
|
2734
11
|
|
|
2735
|
-
|
|
2736
|
-
process23.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|
|
12
|
+
${usage}`);let input=await readInput2(bare?args:parsed.rest??parsed.positionals,bare||parsed.rest!==void 0,placeSettings(parsed.values),cwd),{errors,unrecognised}=parseErrors(input.text);if(parsed.values.json===!0)printJson({errors,unrecognised,...input.log===void 0?{}:{log:input.log},...input.code===void 0?{}:{code:input.code}});else{for(let error of errors)console.log(formatError(error,cwd));if(unrecognised>0)warn(`${unrecognised} ${unrecognised===1?"line":"lines"} not recognised`,input.log===void 0?void 0:`see ${input.log}`);if(errors.length===0&&input.code!==void 0&&input.code!==0)warn(`the command exited ${input.code} with no error recognised`,input.log===void 0?void 0:`see ${input.log}`)}return errors.length>0||(input.code??0)!==0?1:0}process2.exitCode=await runMain({name:"errs",version,run:async(args)=>errs(args)});
|