@kaynooo/cli-check 0.18.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cli.js +329 -732
- package/dist/errs-cli.js +313 -229
- package/dist/fix-cli.js +274 -705
- package/dist/j-cli.js +603 -139
- package/package.json +2 -2
package/dist/errs-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/errs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process22 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -461,24 +461,20 @@ function printJson(value) {
|
|
|
461
461
|
|
|
462
462
|
// ../kit/src/help.ts
|
|
463
463
|
import process8 from "process";
|
|
464
|
-
var OPTIONAL =
|
|
464
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
465
465
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
466
466
|
var FULL_STOP = /\.$/;
|
|
467
467
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
468
468
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
469
469
|
}
|
|
470
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
471
|
-
return [usageLine(usage, colors),
|
|
470
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
471
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
472
472
|
`);
|
|
473
473
|
}
|
|
474
474
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
475
475
|
if (exits.length === 0)
|
|
476
476
|
return [];
|
|
477
|
-
|
|
478
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
479
|
-
}
|
|
480
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
481
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
477
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
482
478
|
}
|
|
483
479
|
function wantsHelpJson(env = process8.env) {
|
|
484
480
|
return env.KIT_HELP === "json";
|
|
@@ -504,32 +500,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
504
500
|
return [];
|
|
505
501
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
506
502
|
}
|
|
503
|
+
var MAX_INLINE_CHOICES = 24;
|
|
507
504
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
508
505
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
509
506
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
510
|
-
const
|
|
507
|
+
const choices = option.choices?.join("|");
|
|
508
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
509
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
511
510
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
512
511
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
513
|
-
|
|
512
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
513
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
514
514
|
});
|
|
515
515
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
516
516
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
// ../kit/src/text.ts
|
|
520
|
-
var ANSI =
|
|
520
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
521
521
|
function stripAnsi(text) {
|
|
522
522
|
return text.replace(ANSI, "");
|
|
523
523
|
}
|
|
524
524
|
function distance(a, b) {
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
const left = [...a];
|
|
526
|
+
const right = [...b];
|
|
527
|
+
let before = [];
|
|
528
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
529
|
+
for (const [i, x] of left.entries()) {
|
|
527
530
|
const current = [i + 1];
|
|
528
|
-
for (const [j,
|
|
529
|
-
|
|
531
|
+
for (const [j, y] of right.entries()) {
|
|
532
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
533
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
534
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
535
|
+
current.push(cost);
|
|
536
|
+
}
|
|
537
|
+
before = previous;
|
|
530
538
|
previous = current;
|
|
531
539
|
}
|
|
532
|
-
return previous[
|
|
540
|
+
return previous[right.length] ?? 0;
|
|
533
541
|
}
|
|
534
542
|
function closest(name, names) {
|
|
535
543
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -934,31 +942,49 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
934
942
|
// ../kit/src/cli.ts
|
|
935
943
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
936
944
|
import { dirname as dirname3, join as join6 } from "path";
|
|
937
|
-
import
|
|
945
|
+
import process16 from "process";
|
|
946
|
+
|
|
947
|
+
// ../kit/src/notify.ts
|
|
948
|
+
import process13 from "process";
|
|
949
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
950
|
+
var CANCELLED = 130;
|
|
951
|
+
function base64(text) {
|
|
952
|
+
return Buffer.from(text).toString("base64");
|
|
953
|
+
}
|
|
954
|
+
function notification(title, body, env = process13.env) {
|
|
955
|
+
const id = `kit${process13.pid}`;
|
|
956
|
+
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\\`];
|
|
957
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
958
|
+
}
|
|
959
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
960
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
961
|
+
return;
|
|
962
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
963
|
+
}
|
|
938
964
|
|
|
939
965
|
// ../kit/src/usage.ts
|
|
940
966
|
import { appendFileSync, mkdirSync } from "fs";
|
|
941
967
|
import { homedir as homedir4 } from "os";
|
|
942
968
|
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
943
|
-
import
|
|
969
|
+
import process15 from "process";
|
|
944
970
|
|
|
945
971
|
// ../kit/src/logs.ts
|
|
946
972
|
import { lstatSync, openSync } from "fs";
|
|
947
973
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
948
974
|
import { homedir as homedir3, tmpdir } from "os";
|
|
949
975
|
import { join as join4 } from "path";
|
|
950
|
-
import
|
|
976
|
+
import process14 from "process";
|
|
951
977
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
952
978
|
var CLI_FOLDER = "kaynooo-cli";
|
|
953
979
|
function isPrivateDirectory(path) {
|
|
954
980
|
try {
|
|
955
981
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
956
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
982
|
+
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
957
983
|
} catch {
|
|
958
984
|
return false;
|
|
959
985
|
}
|
|
960
986
|
}
|
|
961
|
-
async function privateLogDirectory(name, env =
|
|
987
|
+
async function privateLogDirectory(name, env = process14.env) {
|
|
962
988
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
963
989
|
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
964
990
|
const path = join4(base, name);
|
|
@@ -998,14 +1024,14 @@ var usageError;
|
|
|
998
1024
|
function noteUsageError(message) {
|
|
999
1025
|
usageError = message;
|
|
1000
1026
|
}
|
|
1001
|
-
function stateHome(env =
|
|
1027
|
+
function stateHome(env = process15.env) {
|
|
1002
1028
|
const dir = env.XDG_STATE_HOME;
|
|
1003
1029
|
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1004
1030
|
}
|
|
1005
|
-
function usagePath(env =
|
|
1031
|
+
function usagePath(env = process15.env) {
|
|
1006
1032
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1007
1033
|
}
|
|
1008
|
-
function usageRecorded(env =
|
|
1034
|
+
function usageRecorded(env = process15.env) {
|
|
1009
1035
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1010
1036
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1011
1037
|
}
|
|
@@ -1019,7 +1045,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1019
1045
|
usageError = undefined;
|
|
1020
1046
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1021
1047
|
}
|
|
1022
|
-
function recordUsage(entry, env =
|
|
1048
|
+
function recordUsage(entry, env = process15.env) {
|
|
1023
1049
|
if (!usageRecorded(env))
|
|
1024
1050
|
return;
|
|
1025
1051
|
try {
|
|
@@ -1037,8 +1063,8 @@ var LEVEL_OPTIONS = {
|
|
|
1037
1063
|
};
|
|
1038
1064
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1039
1065
|
function printError(prefix, message, hint, cause) {
|
|
1040
|
-
const colors = paint(
|
|
1041
|
-
const styled = takesControlCodes(
|
|
1066
|
+
const colors = paint(process16.stderr);
|
|
1067
|
+
const styled = takesControlCodes(process16.stderr);
|
|
1042
1068
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1043
1069
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1044
1070
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1121,7 +1147,11 @@ async function printCandidates(found) {
|
|
|
1121
1147
|
return 0;
|
|
1122
1148
|
}
|
|
1123
1149
|
function packageVersion(entry = Bun.main) {
|
|
1124
|
-
|
|
1150
|
+
let resolved = entry;
|
|
1151
|
+
try {
|
|
1152
|
+
resolved = realpathSync2(entry);
|
|
1153
|
+
} catch {}
|
|
1154
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1125
1155
|
try {
|
|
1126
1156
|
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
1127
1157
|
if (typeof version === "string")
|
|
@@ -1139,11 +1169,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1139
1169
|
return 0;
|
|
1140
1170
|
}
|
|
1141
1171
|
let code;
|
|
1172
|
+
const started = performance.now();
|
|
1142
1173
|
try {
|
|
1143
1174
|
code = await run(argv);
|
|
1144
1175
|
} catch (error) {
|
|
1145
1176
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1146
1177
|
}
|
|
1178
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1147
1179
|
if (usage !== false) {
|
|
1148
1180
|
try {
|
|
1149
1181
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1151,13 +1183,174 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1151
1183
|
}
|
|
1152
1184
|
return code;
|
|
1153
1185
|
}
|
|
1186
|
+
// ../kit/src/excerpt.ts
|
|
1187
|
+
var BASH_ECHO = /^\$ /;
|
|
1188
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1189
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1190
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1191
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1192
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1193
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1194
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1195
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
1196
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1197
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
1198
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1199
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1200
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1201
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1202
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1203
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1204
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1205
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1206
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1207
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1208
|
+
var MAX_TESTS = 10;
|
|
1209
|
+
var MAX_LINES = 100;
|
|
1210
|
+
var TAIL = 30;
|
|
1211
|
+
var bunTest = (lines) => {
|
|
1212
|
+
const seen = new Set;
|
|
1213
|
+
const blocks = [];
|
|
1214
|
+
for (const [index, line] of lines.entries()) {
|
|
1215
|
+
const name = line.replace(DURATION2, "");
|
|
1216
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1217
|
+
continue;
|
|
1218
|
+
seen.add(name);
|
|
1219
|
+
if (blocks.length < MAX_TESTS)
|
|
1220
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1221
|
+
`).trim());
|
|
1222
|
+
}
|
|
1223
|
+
if (blocks.length === 0)
|
|
1224
|
+
return;
|
|
1225
|
+
if (seen.size > MAX_TESTS)
|
|
1226
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1227
|
+
return [...blocks.join(`
|
|
1228
|
+
|
|
1229
|
+
`).split(`
|
|
1230
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1231
|
+
};
|
|
1232
|
+
var bunCheck = (lines) => {
|
|
1233
|
+
const text = lines.join(`
|
|
1234
|
+
`);
|
|
1235
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1236
|
+
if (blocks === null)
|
|
1237
|
+
return;
|
|
1238
|
+
const errors = blocks.map((block) => {
|
|
1239
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1240
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1241
|
+
});
|
|
1242
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1243
|
+
};
|
|
1244
|
+
function bunCheckFields(block) {
|
|
1245
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1246
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1247
|
+
return {
|
|
1248
|
+
file: attributes.file ?? "",
|
|
1249
|
+
line: attributes.line ?? "",
|
|
1250
|
+
column: attributes.column ?? "",
|
|
1251
|
+
code: attributes.code ?? "",
|
|
1252
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1253
|
+
`).slice(1, -1).join(`
|
|
1254
|
+
`).trim()
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
var tsc = (lines) => {
|
|
1258
|
+
const kept = [];
|
|
1259
|
+
let inError = false;
|
|
1260
|
+
for (const line of lines) {
|
|
1261
|
+
if (TSC_ERROR.test(line)) {
|
|
1262
|
+
inError = true;
|
|
1263
|
+
kept.push(line);
|
|
1264
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
1265
|
+
inError = false;
|
|
1266
|
+
kept.push(line);
|
|
1267
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1268
|
+
kept.push(line);
|
|
1269
|
+
} else {
|
|
1270
|
+
inError = false;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1274
|
+
};
|
|
1275
|
+
var eslint = (lines) => {
|
|
1276
|
+
const kept = [];
|
|
1277
|
+
let file = "";
|
|
1278
|
+
let shown = "";
|
|
1279
|
+
for (const line of lines) {
|
|
1280
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
1281
|
+
if (file !== shown) {
|
|
1282
|
+
kept.push(file);
|
|
1283
|
+
shown = file;
|
|
1284
|
+
}
|
|
1285
|
+
kept.push(line);
|
|
1286
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1287
|
+
kept.push(line);
|
|
1288
|
+
} else if (line.trim() !== "") {
|
|
1289
|
+
file = line;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1293
|
+
};
|
|
1294
|
+
var phpstan = (lines) => {
|
|
1295
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1296
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1297
|
+
};
|
|
1298
|
+
var php = (lines) => {
|
|
1299
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1300
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1301
|
+
};
|
|
1302
|
+
var vitest = (lines) => {
|
|
1303
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1304
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1305
|
+
};
|
|
1306
|
+
var playwright = (lines) => {
|
|
1307
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1308
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1309
|
+
};
|
|
1310
|
+
var phpCsFixer = (lines) => {
|
|
1311
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1312
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1313
|
+
};
|
|
1314
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1315
|
+
function squeeze(lines) {
|
|
1316
|
+
const out = [];
|
|
1317
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1318
|
+
if (line !== "" || out.at(-1) !== "")
|
|
1319
|
+
out.push(line);
|
|
1320
|
+
}
|
|
1321
|
+
while (out.at(-1) === "")
|
|
1322
|
+
out.pop();
|
|
1323
|
+
return out;
|
|
1324
|
+
}
|
|
1325
|
+
function cut(shown) {
|
|
1326
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1327
|
+
`) : shown.join(`
|
|
1328
|
+
`);
|
|
1329
|
+
}
|
|
1330
|
+
function recognised(lines, parsers) {
|
|
1331
|
+
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1332
|
+
}
|
|
1333
|
+
function failureExcerpt(output) {
|
|
1334
|
+
const lines = stripAnsi(output).split(`
|
|
1335
|
+
`);
|
|
1336
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1337
|
+
lines.shift();
|
|
1338
|
+
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1339
|
+
}
|
|
1340
|
+
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
1154
1341
|
// ../kit/src/folders.ts
|
|
1342
|
+
import { homedir as homedir5 } from "os";
|
|
1343
|
+
import { join as join7 } from "path";
|
|
1344
|
+
import process17 from "process";
|
|
1155
1345
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1156
1346
|
function ignoredFolders(extra = [], where = {}) {
|
|
1157
1347
|
const configured = readUserConfig("config", where).ignore;
|
|
1158
1348
|
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1159
1349
|
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1160
1350
|
}
|
|
1351
|
+
function cacheFolder({ home = homedir5(), env = process17.env } = {}) {
|
|
1352
|
+
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
1353
|
+
}
|
|
1161
1354
|
// ../kit/src/secrets.ts
|
|
1162
1355
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1163
1356
|
// ../kit/src/sessions.ts
|
|
@@ -1165,17 +1358,17 @@ var {Glob } = globalThis.Bun;
|
|
|
1165
1358
|
var SESSION_FILES = new Glob("*.json");
|
|
1166
1359
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1167
1360
|
// package.json
|
|
1168
|
-
var version = "0.
|
|
1361
|
+
var version = "0.20.0";
|
|
1169
1362
|
|
|
1170
1363
|
// src/errs.ts
|
|
1171
1364
|
import { relative as relative2 } from "path";
|
|
1172
|
-
import
|
|
1365
|
+
import process21 from "process";
|
|
1173
1366
|
|
|
1174
1367
|
// src/compose.ts
|
|
1175
1368
|
import { existsSync as existsSync4 } from "fs";
|
|
1176
|
-
import { homedir as
|
|
1177
|
-
import { basename, dirname as dirname4, join as
|
|
1178
|
-
import
|
|
1369
|
+
import { homedir as homedir6 } from "os";
|
|
1370
|
+
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
|
|
1371
|
+
import process19 from "process";
|
|
1179
1372
|
|
|
1180
1373
|
// ../kit/src/shell.ts
|
|
1181
1374
|
var SEPARATORS = new Set([`
|
|
@@ -1253,7 +1446,7 @@ function toolWords(program) {
|
|
|
1253
1446
|
}
|
|
1254
1447
|
async function readFiles(dir, names) {
|
|
1255
1448
|
for (const name of names) {
|
|
1256
|
-
const handle = Bun.file(
|
|
1449
|
+
const handle = Bun.file(join8(dir, name));
|
|
1257
1450
|
if (await handle.exists())
|
|
1258
1451
|
return { name, text: await handle.text() };
|
|
1259
1452
|
}
|
|
@@ -1268,7 +1461,7 @@ async function variables(composeDir) {
|
|
|
1268
1461
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1269
1462
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1270
1463
|
}
|
|
1271
|
-
for (const [key, value] of Object.entries(
|
|
1464
|
+
for (const [key, value] of Object.entries(process19.env)) {
|
|
1272
1465
|
if (value !== undefined)
|
|
1273
1466
|
env[key] = value;
|
|
1274
1467
|
}
|
|
@@ -1288,7 +1481,7 @@ function interpolate(text, env) {
|
|
|
1288
1481
|
function bindSource(source, composeDir, env) {
|
|
1289
1482
|
const path = interpolate(source, env);
|
|
1290
1483
|
if (path.startsWith("~"))
|
|
1291
|
-
return
|
|
1484
|
+
return join8(homedir6(), path.slice(1));
|
|
1292
1485
|
if (path.startsWith("/"))
|
|
1293
1486
|
return resolve4(path);
|
|
1294
1487
|
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
@@ -1335,7 +1528,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1335
1528
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1336
1529
|
const file = Bun.file(resolve4(composeDir, name));
|
|
1337
1530
|
if (!await file.exists())
|
|
1338
|
-
fail(`COMPOSE_FILE names ${
|
|
1531
|
+
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1339
1532
|
files.push({ name, text: await file.text() });
|
|
1340
1533
|
}
|
|
1341
1534
|
return files;
|
|
@@ -1357,7 +1550,7 @@ async function readServices(composeDir) {
|
|
|
1357
1550
|
try {
|
|
1358
1551
|
parsed = parseServices(file.text, composeDir, env);
|
|
1359
1552
|
} catch (error) {
|
|
1360
|
-
fail(`cannot read ${
|
|
1553
|
+
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");
|
|
1361
1554
|
}
|
|
1362
1555
|
for (const [name, extra] of parsed) {
|
|
1363
1556
|
const known = services.get(name);
|
|
@@ -1369,11 +1562,11 @@ async function readServices(composeDir) {
|
|
|
1369
1562
|
function climb(dir) {
|
|
1370
1563
|
const folders = [dir];
|
|
1371
1564
|
let current = dir;
|
|
1372
|
-
while (!existsSync4(
|
|
1565
|
+
while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1373
1566
|
current = dirname4(current);
|
|
1374
1567
|
folders.push(current);
|
|
1375
1568
|
}
|
|
1376
|
-
return existsSync4(
|
|
1569
|
+
return existsSync4(join8(current, ".git")) ? folders : [dir];
|
|
1377
1570
|
}
|
|
1378
1571
|
function containerPath(service, dir) {
|
|
1379
1572
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1384,7 +1577,7 @@ function containerPath(service, dir) {
|
|
|
1384
1577
|
if (deepest === undefined)
|
|
1385
1578
|
return;
|
|
1386
1579
|
const inside = relative(deepest.source, dir);
|
|
1387
|
-
return inside === "" ? deepest.target :
|
|
1580
|
+
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1388
1581
|
}
|
|
1389
1582
|
var noticed = new Set;
|
|
1390
1583
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1404,7 +1597,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1404
1597
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1405
1598
|
return;
|
|
1406
1599
|
}
|
|
1407
|
-
if (Bun.which("docker", { PATH:
|
|
1600
|
+
if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
|
|
1408
1601
|
if (service !== undefined)
|
|
1409
1602
|
fail(`--in ${service}: docker not found`);
|
|
1410
1603
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1456,7 +1649,7 @@ class Stack {
|
|
|
1456
1649
|
}
|
|
1457
1650
|
static async running(composeDir) {
|
|
1458
1651
|
try {
|
|
1459
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1652
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1460
1653
|
if (ran.code !== 0)
|
|
1461
1654
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1462
1655
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1739,155 +1932,7 @@ var collectCsFixer = (lines, used) => {
|
|
|
1739
1932
|
};
|
|
1740
1933
|
|
|
1741
1934
|
// src/output.ts
|
|
1742
|
-
var BASH_ECHO =
|
|
1743
|
-
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1744
|
-
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1745
|
-
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1746
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1747
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1748
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1749
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1750
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1751
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1752
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1753
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1754
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1755
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1756
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1757
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1758
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1759
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1760
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1761
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1762
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1763
|
-
var MAX_TESTS = 10;
|
|
1764
|
-
var MAX_LINES = 100;
|
|
1765
|
-
var TAIL = 30;
|
|
1766
|
-
var bunTest = (lines) => {
|
|
1767
|
-
const seen = new Set;
|
|
1768
|
-
const blocks = [];
|
|
1769
|
-
for (const [index, line] of lines.entries()) {
|
|
1770
|
-
const name = line.replace(DURATION2, "");
|
|
1771
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1772
|
-
continue;
|
|
1773
|
-
seen.add(name);
|
|
1774
|
-
if (blocks.length < MAX_TESTS)
|
|
1775
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1776
|
-
`).trim());
|
|
1777
|
-
}
|
|
1778
|
-
if (blocks.length === 0)
|
|
1779
|
-
return;
|
|
1780
|
-
if (seen.size > MAX_TESTS)
|
|
1781
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1782
|
-
return [...blocks.join(`
|
|
1783
|
-
|
|
1784
|
-
`).split(`
|
|
1785
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1786
|
-
};
|
|
1787
|
-
var bunCheck = (lines) => {
|
|
1788
|
-
const text = lines.join(`
|
|
1789
|
-
`);
|
|
1790
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1791
|
-
if (blocks === null)
|
|
1792
|
-
return;
|
|
1793
|
-
const errors = blocks.map((block) => {
|
|
1794
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1795
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1796
|
-
});
|
|
1797
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1798
|
-
};
|
|
1799
|
-
function bunCheckFields(block) {
|
|
1800
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1801
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1802
|
-
return {
|
|
1803
|
-
file: attributes.file ?? "",
|
|
1804
|
-
line: attributes.line ?? "",
|
|
1805
|
-
column: attributes.column ?? "",
|
|
1806
|
-
code: attributes.code ?? "",
|
|
1807
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1808
|
-
`).slice(1, -1).join(`
|
|
1809
|
-
`).trim()
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
var tsc = (lines) => {
|
|
1813
|
-
const kept = [];
|
|
1814
|
-
let inError = false;
|
|
1815
|
-
for (const line of lines) {
|
|
1816
|
-
if (TSC_ERROR.test(line)) {
|
|
1817
|
-
inError = true;
|
|
1818
|
-
kept.push(line);
|
|
1819
|
-
} else if (TSC_SUMMARY.test(line)) {
|
|
1820
|
-
inError = false;
|
|
1821
|
-
kept.push(line);
|
|
1822
|
-
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1823
|
-
kept.push(line);
|
|
1824
|
-
} else {
|
|
1825
|
-
inError = false;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1829
|
-
};
|
|
1830
|
-
var eslint = (lines) => {
|
|
1831
|
-
const kept = [];
|
|
1832
|
-
let file = "";
|
|
1833
|
-
let shown = "";
|
|
1834
|
-
for (const line of lines) {
|
|
1835
|
-
if (ESLINT_PROBLEM.test(line)) {
|
|
1836
|
-
if (file !== shown) {
|
|
1837
|
-
kept.push(file);
|
|
1838
|
-
shown = file;
|
|
1839
|
-
}
|
|
1840
|
-
kept.push(line);
|
|
1841
|
-
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1842
|
-
kept.push(line);
|
|
1843
|
-
} else if (line.trim() !== "") {
|
|
1844
|
-
file = line;
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1848
|
-
};
|
|
1849
|
-
var phpstan = (lines) => {
|
|
1850
|
-
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1851
|
-
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1852
|
-
};
|
|
1853
|
-
var php = (lines) => {
|
|
1854
|
-
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1855
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1856
|
-
};
|
|
1857
|
-
var vitest = (lines) => {
|
|
1858
|
-
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1859
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1860
|
-
};
|
|
1861
|
-
var playwright = (lines) => {
|
|
1862
|
-
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1863
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1864
|
-
};
|
|
1865
|
-
var phpCsFixer = (lines) => {
|
|
1866
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1867
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1868
|
-
};
|
|
1869
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1870
|
-
function squeeze(lines) {
|
|
1871
|
-
const out = [];
|
|
1872
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1873
|
-
if (line !== "" || out.at(-1) !== "")
|
|
1874
|
-
out.push(line);
|
|
1875
|
-
}
|
|
1876
|
-
while (out.at(-1) === "")
|
|
1877
|
-
out.pop();
|
|
1878
|
-
return out;
|
|
1879
|
-
}
|
|
1880
|
-
function failureExcerpt(output) {
|
|
1881
|
-
const lines = stripAnsi(output).split(`
|
|
1882
|
-
`);
|
|
1883
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1884
|
-
lines.shift();
|
|
1885
|
-
const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1886
|
-
const shown = squeeze(parsed ?? lines.slice(-TAIL));
|
|
1887
|
-
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1888
|
-
`) : shown.join(`
|
|
1889
|
-
`);
|
|
1890
|
-
}
|
|
1935
|
+
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;
|
|
1891
1936
|
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
1892
1937
|
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
1893
1938
|
var TSC_SOURCE_LINE = /^\d+ /;
|
|
@@ -1898,9 +1943,13 @@ var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
|
1898
1943
|
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1899
1944
|
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
1900
1945
|
var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
|
|
1946
|
+
var GO_LINTER = /^(.*\S)\s+\(([a-z][\w-]*)\)$/;
|
|
1901
1947
|
var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
|
|
1902
1948
|
var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
|
|
1903
|
-
var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
|
|
1949
|
+
var CARGO_HEADER = /^(error|warning)(?:\[([\w-]+)\])?: (.*)$/;
|
|
1950
|
+
var CONTINUATION = /^\s+\S/;
|
|
1951
|
+
var MAX_CONTINUATION = 20;
|
|
1952
|
+
var KAY_SUMMARY = /^(?:\d+ errors?(?:, \d+ warnings?)?|\d+ warnings?)(?:, failing under --deny-warnings)?$|^checked with /;
|
|
1904
1953
|
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)/;
|
|
1905
1954
|
var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
|
|
1906
1955
|
var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
|
|
@@ -1914,9 +1963,11 @@ var PYTEST_FRAME = /^in \S/;
|
|
|
1914
1963
|
var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
|
|
1915
1964
|
var PYTEST_EXCEPTION_END = /[\s:]/;
|
|
1916
1965
|
var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
|
|
1966
|
+
var GENERIC_LINE = /^(\S[^:]*):(\d+)(?::(\d+))?: (?:fatal )?(error|warning|note): (.*)$/;
|
|
1967
|
+
var GENERIC_RULE = /\s(?:\[([\w-]+)\]|\(([a-z][\w-]*)\))$/;
|
|
1917
1968
|
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)/;
|
|
1918
1969
|
function isNoise(line) {
|
|
1919
|
-
return line.trim() === "" || [NOISE,
|
|
1970
|
+
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));
|
|
1920
1971
|
}
|
|
1921
1972
|
var collectBunCheck = (lines, used) => {
|
|
1922
1973
|
const errors = [];
|
|
@@ -1942,11 +1993,11 @@ var collectBunTest = (lines, used) => {
|
|
|
1942
1993
|
if (!line.startsWith("(fail) "))
|
|
1943
1994
|
continue;
|
|
1944
1995
|
used.add(index);
|
|
1945
|
-
const test = line.slice("(fail) ".length).replace(
|
|
1996
|
+
const test = line.slice("(fail) ".length).replace(DURATION3, "");
|
|
1946
1997
|
if (seen.has(test))
|
|
1947
1998
|
continue;
|
|
1948
1999
|
seen.add(test);
|
|
1949
|
-
const start = lines.findLastIndex((text, at) => at < index &&
|
|
2000
|
+
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY2.test(text)) + 1;
|
|
1950
2001
|
const block = lines.slice(start, index);
|
|
1951
2002
|
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
1952
2003
|
for (let at = start;at < index; at++)
|
|
@@ -1983,10 +2034,10 @@ var collectTsc = (lines, used) => {
|
|
|
1983
2034
|
pretty = plain === null;
|
|
1984
2035
|
errors.push(current);
|
|
1985
2036
|
used.add(index);
|
|
1986
|
-
} else if (current !== undefined &&
|
|
2037
|
+
} else if (current !== undefined && TSC_CONTINUATION2.test(line) && !TSC_FRAME2.test(line)) {
|
|
1987
2038
|
current.message += ` ${line.trim()}`;
|
|
1988
2039
|
used.add(index);
|
|
1989
|
-
} else if (current !== undefined && pretty && (
|
|
2040
|
+
} else if (current !== undefined && pretty && (TSC_FRAME2.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
1990
2041
|
used.add(index);
|
|
1991
2042
|
} else if (!(pretty && line.trim() === "")) {
|
|
1992
2043
|
current = undefined;
|
|
@@ -2000,7 +2051,7 @@ var collectEslint = (lines, used) => {
|
|
|
2000
2051
|
for (const [index, line] of lines.entries()) {
|
|
2001
2052
|
if (used.has(index))
|
|
2002
2053
|
continue;
|
|
2003
|
-
const match =
|
|
2054
|
+
const match = ESLINT_PROBLEM2.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
2004
2055
|
if (match !== null && file !== undefined) {
|
|
2005
2056
|
const text = match[4] ?? "";
|
|
2006
2057
|
const rule = ESLINT_RULE.exec(text);
|
|
@@ -2019,25 +2070,33 @@ var collectGo = (lines, used) => {
|
|
|
2019
2070
|
const match = used.has(index) ? null : GO_ERROR.exec(line);
|
|
2020
2071
|
if (match === null)
|
|
2021
2072
|
continue;
|
|
2022
|
-
|
|
2073
|
+
const linter = GO_LINTER.exec(match[4] ?? "");
|
|
2074
|
+
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] ?? "" });
|
|
2023
2075
|
used.add(index);
|
|
2024
2076
|
}
|
|
2025
2077
|
return errors;
|
|
2026
2078
|
};
|
|
2079
|
+
function headerAbove(lines, arrow, used) {
|
|
2080
|
+
let at = arrow - 1;
|
|
2081
|
+
while (at > 0 && arrow - at <= MAX_CONTINUATION && !used.has(at) && CONTINUATION.test(lines[at] ?? "") && !ARROW.test(lines[at] ?? ""))
|
|
2082
|
+
at--;
|
|
2083
|
+
return at;
|
|
2084
|
+
}
|
|
2027
2085
|
var collectArrowed = (lines, used) => {
|
|
2028
2086
|
const errors = [];
|
|
2029
2087
|
for (const [index, line] of lines.entries()) {
|
|
2030
2088
|
const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
|
|
2031
|
-
const
|
|
2089
|
+
const at = arrow === null ? -1 : headerAbove(lines, index, used);
|
|
2090
|
+
const header = at === -1 ? null : lines[at] ?? "";
|
|
2032
2091
|
const cargo = header === null ? null : CARGO_HEADER.exec(header);
|
|
2033
2092
|
const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
|
|
2034
|
-
if (arrow === null || cargo === null && ruff === null || used.has(
|
|
2093
|
+
if (arrow === null || cargo === null && ruff === null || used.has(at))
|
|
2035
2094
|
continue;
|
|
2036
|
-
const [, file, row, column] = arrow;
|
|
2037
|
-
const fields = { file
|
|
2038
|
-
errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
|
|
2039
|
-
|
|
2040
|
-
|
|
2095
|
+
const [, file = "", row, column] = arrow;
|
|
2096
|
+
const fields = { file, line: Number(row), column: Number(column) };
|
|
2097
|
+
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] ?? "" });
|
|
2098
|
+
for (let taken = at;taken <= index; taken++)
|
|
2099
|
+
used.add(taken);
|
|
2041
2100
|
for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
|
|
2042
2101
|
if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
|
|
2043
2102
|
break;
|
|
@@ -2101,40 +2160,63 @@ var collectPytest = (lines, used) => {
|
|
|
2101
2160
|
}
|
|
2102
2161
|
return errors;
|
|
2103
2162
|
};
|
|
2104
|
-
var
|
|
2163
|
+
var collectGeneric = (lines, used) => {
|
|
2164
|
+
const errors = [];
|
|
2165
|
+
for (const [index, line] of lines.entries()) {
|
|
2166
|
+
const match = used.has(index) ? null : GENERIC_LINE.exec(line);
|
|
2167
|
+
if (match === null)
|
|
2168
|
+
continue;
|
|
2169
|
+
used.add(index);
|
|
2170
|
+
if (match[4] === "note")
|
|
2171
|
+
continue;
|
|
2172
|
+
const text = match[5] ?? "";
|
|
2173
|
+
const ruled = GENERIC_RULE.exec(text);
|
|
2174
|
+
const rule = ruled?.[1] ?? ruled?.[2];
|
|
2175
|
+
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() });
|
|
2176
|
+
}
|
|
2177
|
+
return errors;
|
|
2178
|
+
};
|
|
2179
|
+
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint, collectGeneric];
|
|
2105
2180
|
function parseErrors(output) {
|
|
2106
2181
|
const lines = stripAnsi(output).split(`
|
|
2107
2182
|
`);
|
|
2108
|
-
if (
|
|
2183
|
+
if (BASH_ECHO2.test(lines[0] ?? ""))
|
|
2109
2184
|
lines.shift();
|
|
2110
2185
|
const used = new Set;
|
|
2111
|
-
const
|
|
2186
|
+
const seen = new Set;
|
|
2187
|
+
const errors = COLLECTORS.flatMap((collect) => collect(lines, used)).filter((error) => {
|
|
2188
|
+
const key = [error.file, error.line, error.column, error.message, error.test].join("\x00");
|
|
2189
|
+
if (seen.has(key))
|
|
2190
|
+
return false;
|
|
2191
|
+
seen.add(key);
|
|
2192
|
+
return true;
|
|
2193
|
+
});
|
|
2112
2194
|
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
2113
2195
|
return { errors, unrecognised };
|
|
2114
2196
|
}
|
|
2115
2197
|
|
|
2116
2198
|
// src/run.ts
|
|
2117
2199
|
import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
|
|
2118
|
-
import { basename as basename2, join as
|
|
2119
|
-
import
|
|
2200
|
+
import { basename as basename2, join as join9 } from "path";
|
|
2201
|
+
import process20 from "process";
|
|
2120
2202
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2121
2203
|
var RESULTS_FILE = "results.json";
|
|
2122
2204
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2123
2205
|
async function logDirectory(cwd) {
|
|
2124
2206
|
const root = await privateLogDirectory("check");
|
|
2125
2207
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2126
|
-
const path =
|
|
2208
|
+
const path = join9(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
|
|
2127
2209
|
await mkdir2(path, { mode: 448 });
|
|
2128
2210
|
return path;
|
|
2129
2211
|
}
|
|
2130
|
-
async function
|
|
2212
|
+
async function lastResults(cwd) {
|
|
2131
2213
|
const root = await privateLogDirectory("check");
|
|
2132
2214
|
const prefix = runPrefix(cwd);
|
|
2133
2215
|
let latest;
|
|
2134
2216
|
for (const name of await readdir2(root)) {
|
|
2135
2217
|
if (!name.startsWith(prefix))
|
|
2136
2218
|
continue;
|
|
2137
|
-
const file =
|
|
2219
|
+
const file = join9(root, name, RESULTS_FILE);
|
|
2138
2220
|
try {
|
|
2139
2221
|
const { mtimeMs } = await stat2(file);
|
|
2140
2222
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2143,13 +2225,15 @@ async function lastFailed(cwd) {
|
|
|
2143
2225
|
}
|
|
2144
2226
|
if (latest === undefined)
|
|
2145
2227
|
return;
|
|
2146
|
-
|
|
2147
|
-
|
|
2228
|
+
return JSON.parse(await Bun.file(latest.file).text());
|
|
2229
|
+
}
|
|
2230
|
+
async function lastFailed(cwd) {
|
|
2231
|
+
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
2148
2232
|
}
|
|
2149
2233
|
async function saveLog(output) {
|
|
2150
2234
|
const root = await privateLogDirectory("errs");
|
|
2151
2235
|
await sweepLogs(root);
|
|
2152
|
-
const path =
|
|
2236
|
+
const path = join9(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2153
2237
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2154
2238
|
return path;
|
|
2155
2239
|
}
|
|
@@ -2157,7 +2241,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2157
2241
|
const started = Date.now();
|
|
2158
2242
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2159
2243
|
cwd,
|
|
2160
|
-
env: { ...
|
|
2244
|
+
env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2161
2245
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2162
2246
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2163
2247
|
});
|
|
@@ -2173,8 +2257,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2173
2257
|
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) } };
|
|
2174
2258
|
}
|
|
2175
2259
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2176
|
-
const colors = paint(
|
|
2177
|
-
const path = role("path",
|
|
2260
|
+
const colors = paint(process20.stdout);
|
|
2261
|
+
const path = role("path", process20.stdout);
|
|
2178
2262
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2179
2263
|
if (outcome.ok) {
|
|
2180
2264
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2194,11 +2278,11 @@ var usage2 = `errs [options] [log]
|
|
|
2194
2278
|
errs [options] -- <command> [args...]
|
|
2195
2279
|
errs --in <service> | --host -- <command> [args...]
|
|
2196
2280
|
|
|
2197
|
-
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json), php-cs-fixer, go (build, vet), cargo (rustc), ruff (concise and full) or pytest log, read from the file given, from stdin (no argument or -), or from the output of the command run after --.
|
|
2281
|
+
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, kay check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json), php-cs-fixer, go (build, vet), cargo (rustc), ruff (concise and full) or pytest log, or any line shaped \`file:line[:col]: error|warning: message\` (mypy, gcc, clang, \`shellcheck -f gcc\`, golangci-lint), read from the file given, from stdin (no argument or -), or from the output of the command run after --.
|
|
2198
2282
|
The lines no format recognised are counted on stderr, never dropped silently, and a command's full output is saved to a log file whose path is printed with that count.
|
|
2199
2283
|
A command runs inside the docker compose service that bind-mounts the current folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path, with its output read here; a service that is down is never started, the call fails naming it. --in picks the service, --host forces the host.
|
|
2200
|
-
|
|
2201
|
-
|
|
2284
|
+
--json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, kay check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer, go, cargo, ruff, pytest, generic. An error repeated with the same file, position and message is printed once.`;
|
|
2285
|
+
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"]];
|
|
2202
2286
|
var options = {
|
|
2203
2287
|
...placeOptions,
|
|
2204
2288
|
json: jsonOption()
|
|
@@ -2231,7 +2315,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2231
2315
|
const held = holdSignals();
|
|
2232
2316
|
let ran;
|
|
2233
2317
|
try {
|
|
2234
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...
|
|
2318
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process21.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
2235
2319
|
} catch (error) {
|
|
2236
2320
|
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2237
2321
|
} finally {
|
|
@@ -2239,10 +2323,10 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2239
2323
|
}
|
|
2240
2324
|
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
2241
2325
|
}
|
|
2242
|
-
async function errs(args, cwd =
|
|
2326
|
+
async function errs(args, cwd = process21.cwd()) {
|
|
2243
2327
|
const first = args[0];
|
|
2244
2328
|
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2245
|
-
const parsed = parse(bare ? [] : args, usage2, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
2329
|
+
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"]] });
|
|
2246
2330
|
if (parsed.positionals.length > 1)
|
|
2247
2331
|
fail(`give one log, or a command after --
|
|
2248
2332
|
|
|
@@ -2263,4 +2347,4 @@ ${usage2}`);
|
|
|
2263
2347
|
}
|
|
2264
2348
|
|
|
2265
2349
|
// src/errs-cli.ts
|
|
2266
|
-
|
|
2350
|
+
process22.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|