@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/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process23 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,12 +1358,12 @@ 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/check.ts
|
|
1171
1364
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
1172
|
-
import { basename as basename4, join as
|
|
1173
|
-
import
|
|
1365
|
+
import { basename as basename4, join as join14 } from "path";
|
|
1366
|
+
import process22 from "process";
|
|
1174
1367
|
|
|
1175
1368
|
// ../kit/src/shell.ts
|
|
1176
1369
|
var SEPARATORS = new Set([`
|
|
@@ -1221,9 +1414,9 @@ function shellQuote(word) {
|
|
|
1221
1414
|
|
|
1222
1415
|
// src/compose.ts
|
|
1223
1416
|
import { existsSync as existsSync4 } from "fs";
|
|
1224
|
-
import { homedir as
|
|
1225
|
-
import { basename, dirname as dirname4, join as
|
|
1226
|
-
import
|
|
1417
|
+
import { homedir as homedir6 } from "os";
|
|
1418
|
+
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
|
|
1419
|
+
import process19 from "process";
|
|
1227
1420
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1228
1421
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1229
1422
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1252,7 +1445,7 @@ function toolWords(program) {
|
|
|
1252
1445
|
}
|
|
1253
1446
|
async function readFiles(dir, names) {
|
|
1254
1447
|
for (const name of names) {
|
|
1255
|
-
const handle = Bun.file(
|
|
1448
|
+
const handle = Bun.file(join8(dir, name));
|
|
1256
1449
|
if (await handle.exists())
|
|
1257
1450
|
return { name, text: await handle.text() };
|
|
1258
1451
|
}
|
|
@@ -1267,7 +1460,7 @@ async function variables(composeDir) {
|
|
|
1267
1460
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1268
1461
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1269
1462
|
}
|
|
1270
|
-
for (const [key, value] of Object.entries(
|
|
1463
|
+
for (const [key, value] of Object.entries(process19.env)) {
|
|
1271
1464
|
if (value !== undefined)
|
|
1272
1465
|
env[key] = value;
|
|
1273
1466
|
}
|
|
@@ -1287,7 +1480,7 @@ function interpolate(text, env) {
|
|
|
1287
1480
|
function bindSource(source, composeDir, env) {
|
|
1288
1481
|
const path = interpolate(source, env);
|
|
1289
1482
|
if (path.startsWith("~"))
|
|
1290
|
-
return
|
|
1483
|
+
return join8(homedir6(), path.slice(1));
|
|
1291
1484
|
if (path.startsWith("/"))
|
|
1292
1485
|
return resolve4(path);
|
|
1293
1486
|
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
@@ -1334,7 +1527,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1334
1527
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1335
1528
|
const file = Bun.file(resolve4(composeDir, name));
|
|
1336
1529
|
if (!await file.exists())
|
|
1337
|
-
fail(`COMPOSE_FILE names ${
|
|
1530
|
+
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1338
1531
|
files.push({ name, text: await file.text() });
|
|
1339
1532
|
}
|
|
1340
1533
|
return files;
|
|
@@ -1356,7 +1549,7 @@ async function readServices(composeDir) {
|
|
|
1356
1549
|
try {
|
|
1357
1550
|
parsed = parseServices(file.text, composeDir, env);
|
|
1358
1551
|
} catch (error) {
|
|
1359
|
-
fail(`cannot read ${
|
|
1552
|
+
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");
|
|
1360
1553
|
}
|
|
1361
1554
|
for (const [name, extra] of parsed) {
|
|
1362
1555
|
const known = services.get(name);
|
|
@@ -1368,11 +1561,11 @@ async function readServices(composeDir) {
|
|
|
1368
1561
|
function climb(dir) {
|
|
1369
1562
|
const folders = [dir];
|
|
1370
1563
|
let current = dir;
|
|
1371
|
-
while (!existsSync4(
|
|
1564
|
+
while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1372
1565
|
current = dirname4(current);
|
|
1373
1566
|
folders.push(current);
|
|
1374
1567
|
}
|
|
1375
|
-
return existsSync4(
|
|
1568
|
+
return existsSync4(join8(current, ".git")) ? folders : [dir];
|
|
1376
1569
|
}
|
|
1377
1570
|
function containerPath(service, dir) {
|
|
1378
1571
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1383,7 +1576,7 @@ function containerPath(service, dir) {
|
|
|
1383
1576
|
if (deepest === undefined)
|
|
1384
1577
|
return;
|
|
1385
1578
|
const inside = relative(deepest.source, dir);
|
|
1386
|
-
return inside === "" ? deepest.target :
|
|
1579
|
+
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1387
1580
|
}
|
|
1388
1581
|
var noticed = new Set;
|
|
1389
1582
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1403,7 +1596,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1403
1596
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1404
1597
|
return;
|
|
1405
1598
|
}
|
|
1406
|
-
if (Bun.which("docker", { PATH:
|
|
1599
|
+
if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
|
|
1407
1600
|
if (service !== undefined)
|
|
1408
1601
|
fail(`--in ${service}: docker not found`);
|
|
1409
1602
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1455,7 +1648,7 @@ class Stack {
|
|
|
1455
1648
|
}
|
|
1456
1649
|
static async running(composeDir) {
|
|
1457
1650
|
try {
|
|
1458
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1651
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1459
1652
|
if (ran.code !== 0)
|
|
1460
1653
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1461
1654
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1489,12 +1682,12 @@ function placeSettings(values) {
|
|
|
1489
1682
|
// src/fix.ts
|
|
1490
1683
|
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1491
1684
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1492
|
-
import { join as
|
|
1493
|
-
import
|
|
1685
|
+
import { join as join12 } from "path";
|
|
1686
|
+
import process21 from "process";
|
|
1494
1687
|
|
|
1495
1688
|
// src/changes.ts
|
|
1496
1689
|
import { stat as stat2 } from "fs/promises";
|
|
1497
|
-
import { join as
|
|
1690
|
+
import { join as join9 } from "path";
|
|
1498
1691
|
var {$ } = globalThis.Bun;
|
|
1499
1692
|
async function dirtyFiles(dir) {
|
|
1500
1693
|
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
@@ -1503,7 +1696,7 @@ async function dirtyFiles(dir) {
|
|
|
1503
1696
|
const files = new Map;
|
|
1504
1697
|
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1505
1698
|
try {
|
|
1506
|
-
const { size, mtimeMs } = await stat2(
|
|
1699
|
+
const { size, mtimeMs } = await stat2(join9(dir, path));
|
|
1507
1700
|
files.set(path, `${size}:${mtimeMs}`);
|
|
1508
1701
|
} catch {
|
|
1509
1702
|
files.set(path, "");
|
|
@@ -1548,7 +1741,7 @@ ${body}`;
|
|
|
1548
1741
|
|
|
1549
1742
|
// src/steps.ts
|
|
1550
1743
|
import { readdir as readdir2 } from "fs/promises";
|
|
1551
|
-
import { join as
|
|
1744
|
+
import { join as join10 } from "path";
|
|
1552
1745
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1553
1746
|
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1554
1747
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
@@ -1560,7 +1753,7 @@ var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"]
|
|
|
1560
1753
|
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1561
1754
|
async function readFirst(dir, files) {
|
|
1562
1755
|
for (const file of files) {
|
|
1563
|
-
const handle = Bun.file(
|
|
1756
|
+
const handle = Bun.file(join10(dir, file));
|
|
1564
1757
|
if (await handle.exists())
|
|
1565
1758
|
return { file, text: await handle.text() };
|
|
1566
1759
|
}
|
|
@@ -1568,7 +1761,7 @@ async function readFirst(dir, files) {
|
|
|
1568
1761
|
}
|
|
1569
1762
|
async function read(dir, ...files) {
|
|
1570
1763
|
for (const file of files) {
|
|
1571
|
-
const handle = Bun.file(
|
|
1764
|
+
const handle = Bun.file(join10(dir, file));
|
|
1572
1765
|
if (await handle.exists())
|
|
1573
1766
|
return handle.text();
|
|
1574
1767
|
}
|
|
@@ -1628,7 +1821,7 @@ async function candidates(dir, bin) {
|
|
|
1628
1821
|
}
|
|
1629
1822
|
async function firstFile(dir, names) {
|
|
1630
1823
|
for (const name of names) {
|
|
1631
|
-
if (await Bun.file(
|
|
1824
|
+
if (await Bun.file(join10(dir, name)).exists())
|
|
1632
1825
|
return name;
|
|
1633
1826
|
}
|
|
1634
1827
|
return;
|
|
@@ -1656,9 +1849,9 @@ async function discoverProjects(dir) {
|
|
|
1656
1849
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1657
1850
|
if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1658
1851
|
continue;
|
|
1659
|
-
const steps = await discover(
|
|
1852
|
+
const steps = await discover(join10(dir, entry.name));
|
|
1660
1853
|
if (steps.length > 0)
|
|
1661
|
-
projects.push({ name: entry.name, dir:
|
|
1854
|
+
projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
|
|
1662
1855
|
}
|
|
1663
1856
|
return projects;
|
|
1664
1857
|
}
|
|
@@ -1685,7 +1878,9 @@ var options = {
|
|
|
1685
1878
|
quiet: { type: "boolean", short: "q", description: "print nothing for a passing step, and nothing at all when every step passes" },
|
|
1686
1879
|
failed: { type: "boolean", description: "run only the steps that failed in the last run of this folder, read from the run folder" },
|
|
1687
1880
|
changed: { type: "boolean", short: "c", description: "narrow lint and test to the files changed against HEAD (a bare linter script, a bare bun test script), every other step runs in full and says so" },
|
|
1688
|
-
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions
|
|
1881
|
+
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions, as it does by default when the slot bin is installed; fails without the bin" },
|
|
1882
|
+
"no-slot": { type: "boolean", description: "run the steps at once, without queueing behind the other sessions' slots" },
|
|
1883
|
+
parallel: { type: "boolean", description: "run the steps at the same time, printing each one's output in step order" }
|
|
1689
1884
|
};
|
|
1690
1885
|
var COMMA = /\s*,\s*/;
|
|
1691
1886
|
function pick(steps, only, noun = "step") {
|
|
@@ -1702,654 +1897,26 @@ function pick(steps, only, noun = "step") {
|
|
|
1702
1897
|
|
|
1703
1898
|
// src/run.ts
|
|
1704
1899
|
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1705
|
-
import { basename as basename2, join as
|
|
1706
|
-
import
|
|
1707
|
-
|
|
1708
|
-
// src/e2e.ts
|
|
1709
|
-
var E2E_NOISE = [
|
|
1710
|
-
/^(?: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)/,
|
|
1711
|
-
/^[\u00B7F\u00D7\u00B0T\u00B1]+$/,
|
|
1712
|
-
/^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/
|
|
1713
|
-
];
|
|
1714
|
-
var PLAYWRIGHT_HEADER = /^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1715
|
-
var PLAYWRIGHT_SUMMARY = /^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/;
|
|
1716
|
-
var PLAYWRIGHT_ENTRY = /^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
|
|
1717
|
-
var PLAYWRIGHT_RETRY = /^\s+Retry #\d+ \u2500+$/;
|
|
1718
|
-
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1719
|
-
var EXPECTED = /^\s+Expected: (.*)$/;
|
|
1720
|
-
var RECEIVED = /^\s+Received: (.*)$/;
|
|
1721
|
-
var VITEST_FAIL = /^ FAIL {2}(?:\|[^|]+\| )?(.+)$/;
|
|
1722
|
-
var VITEST_SUITE = /^(.+?) \[ .+ \]$/;
|
|
1723
|
-
var VITEST_FRAME = /^\s*\u276F (\S+):(\d+):(\d+)$/;
|
|
1724
|
-
function key(project, file, line, column, title) {
|
|
1725
|
-
return `${project ?? ""}|${file}:${line}:${column} \u203A ${title}`;
|
|
1726
|
-
}
|
|
1727
|
-
function firstFrame(block) {
|
|
1728
|
-
return block.map((line) => FRAME.exec(line)).find((match) => match !== null && !match[1]?.includes("node_modules")) ?? undefined;
|
|
1729
|
-
}
|
|
1730
|
-
var collectPlaywright = (lines, used) => {
|
|
1731
|
-
const flaky = new Set;
|
|
1732
|
-
let section = "";
|
|
1733
|
-
for (const [index, line] of lines.entries()) {
|
|
1734
|
-
const summary = PLAYWRIGHT_SUMMARY.exec(line);
|
|
1735
|
-
const entry = PLAYWRIGHT_ENTRY.exec(line);
|
|
1736
|
-
if (summary !== null) {
|
|
1737
|
-
section = summary[1] ?? "";
|
|
1738
|
-
used.add(index);
|
|
1739
|
-
} else if (entry !== null && section !== "") {
|
|
1740
|
-
if (section === "flaky")
|
|
1741
|
-
flaky.add(key(entry[1], entry[2], entry[3], entry[4], entry[5]));
|
|
1742
|
-
used.add(index);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
const errors = [];
|
|
1746
|
-
for (let index = 0;index < lines.length; index++) {
|
|
1747
|
-
const header = PLAYWRIGHT_HEADER.exec(lines[index] ?? "");
|
|
1748
|
-
if (header === null)
|
|
1749
|
-
continue;
|
|
1750
|
-
let end = index + 1;
|
|
1751
|
-
while (end < lines.length && !PLAYWRIGHT_HEADER.test(lines[end] ?? "") && !PLAYWRIGHT_SUMMARY.test(lines[end] ?? ""))
|
|
1752
|
-
end++;
|
|
1753
|
-
for (let at = index;at < end; at++)
|
|
1754
|
-
used.add(at);
|
|
1755
|
-
const [, project, file, line, column, title] = header;
|
|
1756
|
-
const retry = lines.findIndex((text, at) => at > index && at < end && PLAYWRIGHT_RETRY.test(text));
|
|
1757
|
-
const block = lines.slice(index + 1, retry === -1 ? end : retry);
|
|
1758
|
-
const frame = firstFrame(block);
|
|
1759
|
-
const message = block.find((text) => text.trim() !== "")?.trim() ?? "failed";
|
|
1760
|
-
const expected = block.map((text) => EXPECTED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1761
|
-
const received = block.map((text) => RECEIVED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
|
|
1762
|
-
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
1763
|
-
index = end - 1;
|
|
1764
|
-
if (flaky.has(key(project, file, line, column, title)))
|
|
1765
|
-
continue;
|
|
1766
|
-
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}` });
|
|
1767
|
-
}
|
|
1768
|
-
return errors;
|
|
1769
|
-
};
|
|
1770
|
-
var collectVitest = (lines, used) => {
|
|
1771
|
-
const errors = [];
|
|
1772
|
-
for (let index = 0;index < lines.length; index++) {
|
|
1773
|
-
const header = VITEST_FAIL.exec(lines[index] ?? "")?.[1];
|
|
1774
|
-
if (header === undefined)
|
|
1775
|
-
continue;
|
|
1776
|
-
let end = index + 1;
|
|
1777
|
-
while (end < lines.length && !(lines[end] ?? "").startsWith("\u23AF") && !VITEST_FAIL.test(lines[end] ?? ""))
|
|
1778
|
-
end++;
|
|
1779
|
-
for (let at = index;at < end; at++)
|
|
1780
|
-
used.add(at);
|
|
1781
|
-
const block = lines.slice(index + 1, end);
|
|
1782
|
-
const frame = block.map((text) => VITEST_FRAME.exec(text)).find((match) => match !== null && !match[1]?.includes("node_modules"));
|
|
1783
|
-
const suite = VITEST_SUITE.exec(header)?.[1];
|
|
1784
|
-
const [file = "", ...names] = (suite ?? header).split(" > ");
|
|
1785
|
-
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(" > ") } : {} });
|
|
1786
|
-
index = end - 1;
|
|
1787
|
-
}
|
|
1788
|
-
return errors;
|
|
1789
|
-
};
|
|
1790
|
-
|
|
1791
|
-
// src/php.ts
|
|
1792
|
-
var PHP_NOISE = [
|
|
1793
|
-
/^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,
|
|
1794
|
-
/^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,
|
|
1795
|
-
/^ -{3,}(?: -{3,})*\s*$/,
|
|
1796
|
-
/^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,
|
|
1797
|
-
/^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,
|
|
1798
|
-
/^(?: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:)/
|
|
1799
|
-
];
|
|
1800
|
-
var MAX_DIFF_LINES = 6;
|
|
1801
|
-
var PHPUNIT_HEADER = /^There (?:was|were) \d+ ([a-z ]+?)s?:$/i;
|
|
1802
|
-
var PHPUNIT_TRIGGERED = /^\d+ tests? triggered \d+ [\w ]+?s?:$/;
|
|
1803
|
-
var PHPUNIT_END = /^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/;
|
|
1804
|
-
var PHPUNIT_ITEM = /^\d+\) (.*)$/;
|
|
1805
|
-
var PHP_LOCATION = /^([\w./-]+\.php):(\d+)$/;
|
|
1806
|
-
var PHPSTAN_FILE = /^ {2}Line {3}(\S.*)$/;
|
|
1807
|
-
var PHPSTAN_GENERAL = /^ {2}Error\s*$/;
|
|
1808
|
-
var PHPSTAN_MESSAGE = /^ {2}(\S.*)$/;
|
|
1809
|
-
var PHPSTAN_ROW = /^ {2}(\d+|-) +(\S.*)$/;
|
|
1810
|
-
var PHPSTAN_CONTINUATION = /^ {9}(\S.*)$/;
|
|
1811
|
-
var PHPSTAN_IDENTIFIER = /^ {9}\uD83E\uDEAA\s+(\S+)\s*$/;
|
|
1812
|
-
var PHPSTAN_TIP = /^ {9}\uD83D\uDCA1/;
|
|
1813
|
-
var PHPSTAN_BORDER = /^ -{3,}(?: -{3,})*\s*$/;
|
|
1814
|
-
var PHPSTAN_RAW = /^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/;
|
|
1815
|
-
var PHPSTAN_JSON = /^\{.*"totals"/;
|
|
1816
|
-
var CS_FIXER_FILE = /^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/;
|
|
1817
|
-
var CS_FIXER_DIFF_START = /^\s+-+ begin diff -+$/;
|
|
1818
|
-
var CS_FIXER_DIFF_END = /^\s+-+ end diff -+$/;
|
|
1819
|
-
function isHeader(line) {
|
|
1820
|
-
return PHPUNIT_HEADER.test(line) || PHPUNIT_TRIGGERED.test(line);
|
|
1821
|
-
}
|
|
1822
|
-
function diffSummary(message) {
|
|
1823
|
-
const start = message.findIndex((line) => line === "+++ Actual");
|
|
1824
|
-
if (start === -1)
|
|
1825
|
-
return "";
|
|
1826
|
-
const changed = message.slice(start + 1).filter((line) => line.startsWith("-") || line.startsWith("+")).map((line) => `${line[0]} ${line.slice(1).trim()}`);
|
|
1827
|
-
const shown = changed.slice(0, MAX_DIFF_LINES).join(" | ");
|
|
1828
|
-
return changed.length === 0 ? "" : ` (${shown}${changed.length > MAX_DIFF_LINES ? " | ..." : ""})`;
|
|
1829
|
-
}
|
|
1830
|
-
function phpunitError(test, body) {
|
|
1831
|
-
const at = body.findIndex((line) => PHP_LOCATION.test(line));
|
|
1832
|
-
const location = PHP_LOCATION.exec(body[at] ?? "");
|
|
1833
|
-
const message = body.slice(0, at === -1 ? body.length : at).map((line) => line.trimEnd());
|
|
1834
|
-
const first = message.find((line) => line.trim() !== "") ?? "failed";
|
|
1835
|
-
return { tool: "phpunit", file: location?.[1] ?? "", line: Number(location?.[2] ?? 0), column: 0, severity: "error", message: `${first}${diffSummary(message)}`, test };
|
|
1836
|
-
}
|
|
1837
|
-
var collectPhpunit = (lines, used) => {
|
|
1838
|
-
const errors = [];
|
|
1839
|
-
for (let index = 0;index < lines.length; index++) {
|
|
1840
|
-
const line = lines[index] ?? "";
|
|
1841
|
-
const kind = PHPUNIT_HEADER.exec(line)?.[1];
|
|
1842
|
-
if (kind === undefined && !PHPUNIT_TRIGGERED.test(line))
|
|
1843
|
-
continue;
|
|
1844
|
-
let end = index + 1;
|
|
1845
|
-
while (end < lines.length && !PHPUNIT_END.test(lines[end] ?? "") && !isHeader(lines[end] ?? ""))
|
|
1846
|
-
end++;
|
|
1847
|
-
for (let at = index;at < end; at++)
|
|
1848
|
-
used.add(at);
|
|
1849
|
-
if (kind === "error" || kind === "failure") {
|
|
1850
|
-
const starts = Array.from({ length: end - index - 1 }, (_, at) => index + 1 + at).filter((at) => PHPUNIT_ITEM.test(lines[at] ?? ""));
|
|
1851
|
-
for (const [position, start] of starts.entries())
|
|
1852
|
-
errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start] ?? "")?.[1] ?? "", lines.slice(start + 1, starts[position + 1] ?? end)));
|
|
1853
|
-
}
|
|
1854
|
-
index = end - 1;
|
|
1855
|
-
}
|
|
1856
|
-
return errors;
|
|
1857
|
-
};
|
|
1858
|
-
function appendMessage(error, text) {
|
|
1859
|
-
error.message = `${error.message} ${text}`;
|
|
1860
|
-
}
|
|
1861
|
-
function phpstanJson(text) {
|
|
1862
|
-
try {
|
|
1863
|
-
const report = JSON.parse(text);
|
|
1864
|
-
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 } })));
|
|
1865
|
-
return [...fromFiles, ...(report.errors ?? []).map((message) => ({ file: "", line: 0, message }))];
|
|
1866
|
-
} catch {
|
|
1867
|
-
return;
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
var collectPhpstan = (lines, used) => {
|
|
1871
|
-
const errors = [];
|
|
1872
|
-
let file;
|
|
1873
|
-
let current;
|
|
1874
|
-
let rows = 0;
|
|
1875
|
-
let tip = false;
|
|
1876
|
-
let general = false;
|
|
1877
|
-
for (const [index, text] of lines.entries()) {
|
|
1878
|
-
const line = text.trimEnd();
|
|
1879
|
-
if (used.has(index))
|
|
1880
|
-
continue;
|
|
1881
|
-
if (PHPSTAN_JSON.test(line)) {
|
|
1882
|
-
const parsed = phpstanJson(line);
|
|
1883
|
-
for (const entry of parsed ?? []) {
|
|
1884
|
-
errors.push({ tool: "phpstan", file: entry.file, line: entry.line, column: 0, severity: "error", message: entry.message, ...entry.rule === undefined ? {} : { rule: entry.rule } });
|
|
1885
|
-
}
|
|
1886
|
-
if (parsed !== undefined)
|
|
1887
|
-
used.add(index);
|
|
1888
|
-
continue;
|
|
1889
|
-
}
|
|
1890
|
-
const raw = PHPSTAN_RAW.exec(line);
|
|
1891
|
-
if (raw !== null) {
|
|
1892
|
-
errors.push({ tool: "phpstan", file: raw[1] ?? "", line: Number(raw[2]), column: 0, severity: "error", message: raw[3] ?? "" });
|
|
1893
|
-
used.add(index);
|
|
1894
|
-
continue;
|
|
1895
|
-
}
|
|
1896
|
-
const header = PHPSTAN_FILE.exec(line);
|
|
1897
|
-
if (header !== null || PHPSTAN_GENERAL.test(line)) {
|
|
1898
|
-
file = header?.[1] ?? "";
|
|
1899
|
-
general = header === null;
|
|
1900
|
-
current = undefined;
|
|
1901
|
-
rows = 0;
|
|
1902
|
-
used.add(index);
|
|
1903
|
-
continue;
|
|
1904
|
-
}
|
|
1905
|
-
if (file === undefined)
|
|
1906
|
-
continue;
|
|
1907
|
-
const message = PHPSTAN_MESSAGE.exec(line)?.[1];
|
|
1908
|
-
if (general && message !== undefined && !PHPSTAN_BORDER.test(line)) {
|
|
1909
|
-
errors.push({ tool: "phpstan", file: "", line: 0, column: 0, severity: "error", message });
|
|
1910
|
-
rows++;
|
|
1911
|
-
used.add(index);
|
|
1912
|
-
continue;
|
|
1913
|
-
}
|
|
1914
|
-
const row = PHPSTAN_ROW.exec(line);
|
|
1915
|
-
const identifier = PHPSTAN_IDENTIFIER.exec(line)?.[1];
|
|
1916
|
-
const continuation = PHPSTAN_CONTINUATION.exec(line)?.[1];
|
|
1917
|
-
if (PHPSTAN_BORDER.test(line) && rows > 0) {
|
|
1918
|
-
file = undefined;
|
|
1919
|
-
general = false;
|
|
1920
|
-
current = undefined;
|
|
1921
|
-
} else if (row !== null) {
|
|
1922
|
-
current = { tool: "phpstan", file, line: row[1] === "-" ? 0 : Number(row[1]), column: 0, severity: "error", message: row[2] ?? "" };
|
|
1923
|
-
errors.push(current);
|
|
1924
|
-
rows++;
|
|
1925
|
-
tip = false;
|
|
1926
|
-
used.add(index);
|
|
1927
|
-
} else if (identifier !== undefined && current !== undefined) {
|
|
1928
|
-
current.rule = identifier;
|
|
1929
|
-
used.add(index);
|
|
1930
|
-
} else if (PHPSTAN_TIP.test(line)) {
|
|
1931
|
-
tip = true;
|
|
1932
|
-
used.add(index);
|
|
1933
|
-
} else if (continuation !== undefined && current !== undefined) {
|
|
1934
|
-
if (!tip)
|
|
1935
|
-
appendMessage(current, continuation);
|
|
1936
|
-
used.add(index);
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
return errors;
|
|
1940
|
-
};
|
|
1941
|
-
var collectCsFixer = (lines, used) => {
|
|
1942
|
-
const errors = [];
|
|
1943
|
-
for (let index = 0;index < lines.length; index++) {
|
|
1944
|
-
const match = CS_FIXER_FILE.exec(lines[index] ?? "");
|
|
1945
|
-
if (match === null)
|
|
1946
|
-
continue;
|
|
1947
|
-
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" });
|
|
1948
|
-
used.add(index);
|
|
1949
|
-
if (!CS_FIXER_DIFF_START.test(lines[index + 1] ?? ""))
|
|
1950
|
-
continue;
|
|
1951
|
-
const end = lines.findIndex((text, at) => at > index && CS_FIXER_DIFF_END.test(text));
|
|
1952
|
-
for (let at = index + 1;at <= (end === -1 ? index + 1 : end); at++)
|
|
1953
|
-
used.add(at);
|
|
1954
|
-
index = end === -1 ? index + 1 : end;
|
|
1955
|
-
}
|
|
1956
|
-
return errors;
|
|
1957
|
-
};
|
|
1958
|
-
|
|
1959
|
-
// src/output.ts
|
|
1960
|
-
var BASH_ECHO = /^\$ /;
|
|
1961
|
-
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1962
|
-
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1963
|
-
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1964
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1965
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1966
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1967
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1968
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1969
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1970
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1971
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1972
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1973
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1974
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1975
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1976
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1977
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1978
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1979
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1980
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1981
|
-
var MAX_TESTS = 10;
|
|
1982
|
-
var MAX_LINES = 100;
|
|
1983
|
-
var TAIL = 30;
|
|
1984
|
-
var bunTest = (lines) => {
|
|
1985
|
-
const seen = new Set;
|
|
1986
|
-
const blocks = [];
|
|
1987
|
-
for (const [index, line] of lines.entries()) {
|
|
1988
|
-
const name = line.replace(DURATION2, "");
|
|
1989
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1990
|
-
continue;
|
|
1991
|
-
seen.add(name);
|
|
1992
|
-
if (blocks.length < MAX_TESTS)
|
|
1993
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1994
|
-
`).trim());
|
|
1995
|
-
}
|
|
1996
|
-
if (blocks.length === 0)
|
|
1997
|
-
return;
|
|
1998
|
-
if (seen.size > MAX_TESTS)
|
|
1999
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
2000
|
-
return [...blocks.join(`
|
|
2001
|
-
|
|
2002
|
-
`).split(`
|
|
2003
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
2004
|
-
};
|
|
2005
|
-
var bunCheck = (lines) => {
|
|
2006
|
-
const text = lines.join(`
|
|
2007
|
-
`);
|
|
2008
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
2009
|
-
if (blocks === null)
|
|
2010
|
-
return;
|
|
2011
|
-
const errors = blocks.map((block) => {
|
|
2012
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
2013
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
2014
|
-
});
|
|
2015
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
2016
|
-
};
|
|
2017
|
-
function bunCheckFields(block) {
|
|
2018
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
2019
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
2020
|
-
return {
|
|
2021
|
-
file: attributes.file ?? "",
|
|
2022
|
-
line: attributes.line ?? "",
|
|
2023
|
-
column: attributes.column ?? "",
|
|
2024
|
-
code: attributes.code ?? "",
|
|
2025
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
2026
|
-
`).slice(1, -1).join(`
|
|
2027
|
-
`).trim()
|
|
2028
|
-
};
|
|
2029
|
-
}
|
|
2030
|
-
var tsc = (lines) => {
|
|
2031
|
-
const kept = [];
|
|
2032
|
-
let inError = false;
|
|
2033
|
-
for (const line of lines) {
|
|
2034
|
-
if (TSC_ERROR.test(line)) {
|
|
2035
|
-
inError = true;
|
|
2036
|
-
kept.push(line);
|
|
2037
|
-
} else if (TSC_SUMMARY.test(line)) {
|
|
2038
|
-
inError = false;
|
|
2039
|
-
kept.push(line);
|
|
2040
|
-
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
2041
|
-
kept.push(line);
|
|
2042
|
-
} else {
|
|
2043
|
-
inError = false;
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
2047
|
-
};
|
|
2048
|
-
var eslint = (lines) => {
|
|
2049
|
-
const kept = [];
|
|
2050
|
-
let file = "";
|
|
2051
|
-
let shown = "";
|
|
2052
|
-
for (const line of lines) {
|
|
2053
|
-
if (ESLINT_PROBLEM.test(line)) {
|
|
2054
|
-
if (file !== shown) {
|
|
2055
|
-
kept.push(file);
|
|
2056
|
-
shown = file;
|
|
2057
|
-
}
|
|
2058
|
-
kept.push(line);
|
|
2059
|
-
} else if (ESLINT_SUMMARY.test(line)) {
|
|
2060
|
-
kept.push(line);
|
|
2061
|
-
} else if (line.trim() !== "") {
|
|
2062
|
-
file = line;
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
2066
|
-
};
|
|
2067
|
-
var phpstan = (lines) => {
|
|
2068
|
-
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
2069
|
-
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
2070
|
-
};
|
|
2071
|
-
var php = (lines) => {
|
|
2072
|
-
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
2073
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
2074
|
-
};
|
|
2075
|
-
var vitest = (lines) => {
|
|
2076
|
-
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
2077
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
2078
|
-
};
|
|
2079
|
-
var playwright = (lines) => {
|
|
2080
|
-
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
2081
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
2082
|
-
};
|
|
2083
|
-
var phpCsFixer = (lines) => {
|
|
2084
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
2085
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
2086
|
-
};
|
|
2087
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
2088
|
-
function squeeze(lines) {
|
|
2089
|
-
const out = [];
|
|
2090
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
2091
|
-
if (line !== "" || out.at(-1) !== "")
|
|
2092
|
-
out.push(line);
|
|
2093
|
-
}
|
|
2094
|
-
while (out.at(-1) === "")
|
|
2095
|
-
out.pop();
|
|
2096
|
-
return out;
|
|
2097
|
-
}
|
|
2098
|
-
function failureExcerpt(output) {
|
|
2099
|
-
const lines = stripAnsi(output).split(`
|
|
2100
|
-
`);
|
|
2101
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
2102
|
-
lines.shift();
|
|
2103
|
-
const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
2104
|
-
const shown = squeeze(parsed ?? lines.slice(-TAIL));
|
|
2105
|
-
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
2106
|
-
`) : shown.join(`
|
|
2107
|
-
`);
|
|
2108
|
-
}
|
|
2109
|
-
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
2110
|
-
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
2111
|
-
var TSC_SOURCE_LINE = /^\d+ /;
|
|
2112
|
-
var ESLINT_FIELDS = /^ +(\d+):(\d+) +(error|warning) +(\S.*)$/;
|
|
2113
|
-
var ESLINT_RULE = / {2,}(\S+)$/;
|
|
2114
|
-
var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
|
|
2115
|
-
var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
2116
|
-
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
2117
|
-
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
2118
|
-
var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
|
|
2119
|
-
var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
|
|
2120
|
-
var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
|
|
2121
|
-
var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
|
|
2122
|
-
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)/;
|
|
2123
|
-
var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
|
|
2124
|
-
var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
|
|
2125
|
-
var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
|
|
2126
|
-
var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
|
|
2127
|
-
var PYTEST_E_LINE = /^E {3}(.*)$/;
|
|
2128
|
-
var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
|
|
2129
|
-
var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
|
|
2130
|
-
var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
|
|
2131
|
-
var PYTEST_FRAME = /^in \S/;
|
|
2132
|
-
var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
|
|
2133
|
-
var PYTEST_EXCEPTION_END = /[\s:]/;
|
|
2134
|
-
var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
|
|
2135
|
-
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)/;
|
|
2136
|
-
function isNoise(line) {
|
|
2137
|
-
return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, GO_NOISE, CARGO_NOISE, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
|
|
2138
|
-
}
|
|
2139
|
-
var collectBunCheck = (lines, used) => {
|
|
2140
|
-
const errors = [];
|
|
2141
|
-
for (let index = 0;index < lines.length; index++) {
|
|
2142
|
-
if (!(lines[index] ?? "").startsWith("<error file="))
|
|
2143
|
-
continue;
|
|
2144
|
-
const end = lines.findIndex((line, at) => at >= index && line === "</error>");
|
|
2145
|
-
if (end === -1)
|
|
2146
|
-
break;
|
|
2147
|
-
const { file, line, column, code, message } = bunCheckFields(lines.slice(index, end + 1).join(`
|
|
2148
|
-
`));
|
|
2149
|
-
errors.push({ tool: "bun check", file, line: Number(line), column: Number(column), rule: code, severity: "error", message: message.replaceAll(/\s*\n\s*/g, " ") });
|
|
2150
|
-
for (let at = index;at <= end; at++)
|
|
2151
|
-
used.add(at);
|
|
2152
|
-
index = end;
|
|
2153
|
-
}
|
|
2154
|
-
return errors;
|
|
2155
|
-
};
|
|
2156
|
-
var collectBunTest = (lines, used) => {
|
|
2157
|
-
const errors = [];
|
|
2158
|
-
const seen = new Set;
|
|
2159
|
-
for (const [index, line] of lines.entries()) {
|
|
2160
|
-
if (!line.startsWith("(fail) "))
|
|
2161
|
-
continue;
|
|
2162
|
-
used.add(index);
|
|
2163
|
-
const test = line.slice("(fail) ".length).replace(DURATION2, "");
|
|
2164
|
-
if (seen.has(test))
|
|
2165
|
-
continue;
|
|
2166
|
-
seen.add(test);
|
|
2167
|
-
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1;
|
|
2168
|
-
const block = lines.slice(start, index);
|
|
2169
|
-
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
2170
|
-
for (let at = start;at < index; at++)
|
|
2171
|
-
used.add(at);
|
|
2172
|
-
const frame = block.slice(Math.max(failure, 0)).map((text) => BUN_TEST_FRAME.exec(text)).find((match) => match !== null);
|
|
2173
|
-
const header = lines.slice(0, index).findLast((text) => BUN_TEST_FILE.test(text));
|
|
2174
|
-
const expected = block.map((text) => BUN_TEST_EXPECTED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
2175
|
-
const received = block.map((text) => BUN_TEST_RECEIVED.exec(text)?.[1]).find((text) => text !== undefined);
|
|
2176
|
-
const reason = failure === -1 ? "failed" : (block[failure] ?? "").slice("error:".length).trim();
|
|
2177
|
-
const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
|
|
2178
|
-
errors.push({
|
|
2179
|
-
tool: "bun test",
|
|
2180
|
-
file: frame?.[1] ?? header?.replace(":", "") ?? "",
|
|
2181
|
-
line: Number(frame?.[2] ?? 0),
|
|
2182
|
-
column: Number(frame?.[3] ?? 0),
|
|
2183
|
-
severity: "error",
|
|
2184
|
-
message: `${reason}${values}`,
|
|
2185
|
-
test
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
return errors;
|
|
2189
|
-
};
|
|
2190
|
-
var collectTsc = (lines, used) => {
|
|
2191
|
-
const errors = [];
|
|
2192
|
-
let current;
|
|
2193
|
-
let pretty = false;
|
|
2194
|
-
for (const [index, line] of lines.entries()) {
|
|
2195
|
-
if (used.has(index))
|
|
2196
|
-
continue;
|
|
2197
|
-
const plain = TSC_PLAIN_ERROR.exec(line);
|
|
2198
|
-
const match = plain ?? TSC_PRETTY_ERROR.exec(line);
|
|
2199
|
-
if (match !== null) {
|
|
2200
|
-
current = { tool: "tsc", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" };
|
|
2201
|
-
pretty = plain === null;
|
|
2202
|
-
errors.push(current);
|
|
2203
|
-
used.add(index);
|
|
2204
|
-
} else if (current !== undefined && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
2205
|
-
current.message += ` ${line.trim()}`;
|
|
2206
|
-
used.add(index);
|
|
2207
|
-
} else if (current !== undefined && pretty && (TSC_FRAME.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
2208
|
-
used.add(index);
|
|
2209
|
-
} else if (!(pretty && line.trim() === "")) {
|
|
2210
|
-
current = undefined;
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
return errors;
|
|
2214
|
-
};
|
|
2215
|
-
var collectEslint = (lines, used) => {
|
|
2216
|
-
const errors = [];
|
|
2217
|
-
let file;
|
|
2218
|
-
for (const [index, line] of lines.entries()) {
|
|
2219
|
-
if (used.has(index))
|
|
2220
|
-
continue;
|
|
2221
|
-
const match = ESLINT_PROBLEM.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
2222
|
-
if (match !== null && file !== undefined) {
|
|
2223
|
-
const text = match[4] ?? "";
|
|
2224
|
-
const rule = ESLINT_RULE.exec(text);
|
|
2225
|
-
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) });
|
|
2226
|
-
used.add(index);
|
|
2227
|
-
used.add(file);
|
|
2228
|
-
} else if (!isNoise(line)) {
|
|
2229
|
-
file = index;
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
return errors;
|
|
2233
|
-
};
|
|
2234
|
-
var collectGo = (lines, used) => {
|
|
2235
|
-
const errors = [];
|
|
2236
|
-
for (const [index, line] of lines.entries()) {
|
|
2237
|
-
const match = used.has(index) ? null : GO_ERROR.exec(line);
|
|
2238
|
-
if (match === null)
|
|
2239
|
-
continue;
|
|
2240
|
-
errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
|
|
2241
|
-
used.add(index);
|
|
2242
|
-
}
|
|
2243
|
-
return errors;
|
|
2244
|
-
};
|
|
2245
|
-
var collectArrowed = (lines, used) => {
|
|
2246
|
-
const errors = [];
|
|
2247
|
-
for (const [index, line] of lines.entries()) {
|
|
2248
|
-
const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
|
|
2249
|
-
const header = arrow === null ? null : lines[index - 1] ?? "";
|
|
2250
|
-
const cargo = header === null ? null : CARGO_HEADER.exec(header);
|
|
2251
|
-
const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
|
|
2252
|
-
if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
|
|
2253
|
-
continue;
|
|
2254
|
-
const [, file, row, column] = arrow;
|
|
2255
|
-
const fields = { file: file ?? "", line: Number(row), column: Number(column) };
|
|
2256
|
-
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] ?? "" });
|
|
2257
|
-
used.add(index - 1);
|
|
2258
|
-
used.add(index);
|
|
2259
|
-
for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
|
|
2260
|
-
if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
|
|
2261
|
-
break;
|
|
2262
|
-
used.add(frame);
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
return errors;
|
|
2266
|
-
};
|
|
2267
|
-
var collectRuff = (lines, used) => {
|
|
2268
|
-
const errors = [];
|
|
2269
|
-
for (const [index, line] of lines.entries()) {
|
|
2270
|
-
const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
|
|
2271
|
-
if (match === null)
|
|
2272
|
-
continue;
|
|
2273
|
-
errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
|
|
2274
|
-
used.add(index);
|
|
2275
|
-
}
|
|
2276
|
-
return errors;
|
|
2277
|
-
};
|
|
2278
|
-
var collectPytest = (lines, used) => {
|
|
2279
|
-
const errors = [];
|
|
2280
|
-
const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
|
|
2281
|
-
const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
|
|
2282
|
-
if (start === -1)
|
|
2283
|
-
return errors;
|
|
2284
|
-
const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
|
|
2285
|
-
const stop = end === -1 ? lines.length : end;
|
|
2286
|
-
let message = [];
|
|
2287
|
-
let frame;
|
|
2288
|
-
for (let index = start;index < stop; index++) {
|
|
2289
|
-
const line = lines[index] ?? "";
|
|
2290
|
-
const failure = PYTEST_E_LINE.exec(line);
|
|
2291
|
-
if (failure !== null) {
|
|
2292
|
-
message.push((failure[1] ?? "").trim());
|
|
2293
|
-
} else {
|
|
2294
|
-
if (frame !== undefined && message.length > 0) {
|
|
2295
|
-
errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
|
|
2296
|
-
frame = undefined;
|
|
2297
|
-
}
|
|
2298
|
-
const location = PYTEST_LOCATION.exec(line);
|
|
2299
|
-
if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
|
|
2300
|
-
frame = { file: location[1] ?? "", line: Number(location[2]) };
|
|
2301
|
-
} else if (location !== null) {
|
|
2302
|
-
const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
|
|
2303
|
-
const first = message[0] ?? "";
|
|
2304
|
-
const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
|
|
2305
|
-
errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
|
|
2306
|
-
}
|
|
2307
|
-
if (PYTEST_SECTION.test(line))
|
|
2308
|
-
frame = undefined;
|
|
2309
|
-
if (line.trim() !== "")
|
|
2310
|
-
message = [];
|
|
2311
|
-
}
|
|
2312
|
-
used.add(index);
|
|
2313
|
-
}
|
|
2314
|
-
if (frame !== undefined && message.length > 0)
|
|
2315
|
-
errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
|
|
2316
|
-
for (let index = stop;index < lines.length; index++) {
|
|
2317
|
-
if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
|
|
2318
|
-
used.add(index);
|
|
2319
|
-
}
|
|
2320
|
-
return errors;
|
|
2321
|
-
};
|
|
2322
|
-
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
|
|
2323
|
-
function parseErrors(output) {
|
|
2324
|
-
const lines = stripAnsi(output).split(`
|
|
2325
|
-
`);
|
|
2326
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
2327
|
-
lines.shift();
|
|
2328
|
-
const used = new Set;
|
|
2329
|
-
const errors = COLLECTORS.flatMap((collect) => collect(lines, used));
|
|
2330
|
-
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
2331
|
-
return { errors, unrecognised };
|
|
2332
|
-
}
|
|
2333
|
-
|
|
2334
|
-
// src/run.ts
|
|
1900
|
+
import { basename as basename2, join as join11 } from "path";
|
|
1901
|
+
import process20 from "process";
|
|
2335
1902
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2336
1903
|
var RESULTS_FILE = "results.json";
|
|
2337
1904
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2338
1905
|
async function logDirectory(cwd) {
|
|
2339
1906
|
const root = await privateLogDirectory("check");
|
|
2340
1907
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2341
|
-
const path =
|
|
1908
|
+
const path = join11(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
|
|
2342
1909
|
await mkdir2(path, { mode: 448 });
|
|
2343
1910
|
return path;
|
|
2344
1911
|
}
|
|
2345
|
-
async function
|
|
1912
|
+
async function lastResults(cwd) {
|
|
2346
1913
|
const root = await privateLogDirectory("check");
|
|
2347
1914
|
const prefix = runPrefix(cwd);
|
|
2348
1915
|
let latest;
|
|
2349
1916
|
for (const name of await readdir3(root)) {
|
|
2350
1917
|
if (!name.startsWith(prefix))
|
|
2351
1918
|
continue;
|
|
2352
|
-
const file =
|
|
1919
|
+
const file = join11(root, name, RESULTS_FILE);
|
|
2353
1920
|
try {
|
|
2354
1921
|
const { mtimeMs } = await stat3(file);
|
|
2355
1922
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2358,13 +1925,15 @@ async function lastFailed(cwd) {
|
|
|
2358
1925
|
}
|
|
2359
1926
|
if (latest === undefined)
|
|
2360
1927
|
return;
|
|
2361
|
-
|
|
2362
|
-
|
|
1928
|
+
return JSON.parse(await Bun.file(latest.file).text());
|
|
1929
|
+
}
|
|
1930
|
+
async function lastFailed(cwd) {
|
|
1931
|
+
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
2363
1932
|
}
|
|
2364
1933
|
async function saveLog(output) {
|
|
2365
1934
|
const root = await privateLogDirectory("errs");
|
|
2366
1935
|
await sweepLogs(root);
|
|
2367
|
-
const path =
|
|
1936
|
+
const path = join11(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2368
1937
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2369
1938
|
return path;
|
|
2370
1939
|
}
|
|
@@ -2372,7 +1941,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2372
1941
|
const started = Date.now();
|
|
2373
1942
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2374
1943
|
cwd,
|
|
2375
|
-
env: { ...
|
|
1944
|
+
env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2376
1945
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2377
1946
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2378
1947
|
});
|
|
@@ -2388,8 +1957,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2388
1957
|
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) } };
|
|
2389
1958
|
}
|
|
2390
1959
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2391
|
-
const colors = paint(
|
|
2392
|
-
const path = role("path",
|
|
1960
|
+
const colors = paint(process20.stdout);
|
|
1961
|
+
const path = role("path", process20.stdout);
|
|
2393
1962
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2394
1963
|
if (outcome.ok) {
|
|
2395
1964
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2412,15 +1981,15 @@ It looks at the folder itself only, so each package of a monorepo gets its own r
|
|
|
2412
1981
|
A script or php-cs-fixer runs inside the docker compose service that bind-mounts the folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the fixer fails naming it. The formatters run on the host. --in picks the service, --host forces the host.
|
|
2413
1982
|
Prints one line per fixer, what a failing one said, then the files the run changed. Each fixer's full output is saved to the file whose path ends its line.
|
|
2414
1983
|
A fixer still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2415
|
-
Exits 0 when every fixer ran or was skipped for a missing binary, 1 when one failed, 2 on bad usage, when nothing applies or when a fixer timed out.
|
|
2416
1984
|
--json prints {fixers: [{name, command, in?, ok, ms, log, failed?} or {name, command, skipped}], changed} once every fixer ran, changed null outside a git repository.`;
|
|
1985
|
+
var EXITS = [[0, "every fixer ran or was skipped for a missing binary"], [1, "one failed"], [2, "bad usage, nothing applies or a fixer timed out"]];
|
|
2417
1986
|
var RUNNING = "KAYNOOO_CLI_FIX";
|
|
2418
1987
|
var JUSTFILES2 = ["justfile", "Justfile", ".justfile"];
|
|
2419
1988
|
var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
2420
1989
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2421
1990
|
var MAX_CHANGED = 30;
|
|
2422
1991
|
async function replaceFile(path, content) {
|
|
2423
|
-
const temporary = `${path}.${
|
|
1992
|
+
const temporary = `${path}.${process21.pid}.tmp`;
|
|
2424
1993
|
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
2425
1994
|
await rename(temporary, path);
|
|
2426
1995
|
}
|
|
@@ -2439,9 +2008,9 @@ async function toolFixers(dir) {
|
|
|
2439
2008
|
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2440
2009
|
if (makefile !== undefined) {
|
|
2441
2010
|
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2442
|
-
const path =
|
|
2011
|
+
const path = join12(cwd, makefile);
|
|
2443
2012
|
const current = await Bun.file(path).text();
|
|
2444
|
-
const { content, targets } = declarePhony(current, (name) => existsSync5(
|
|
2013
|
+
const { content, targets } = declarePhony(current, (name) => existsSync5(join12(cwd, name)));
|
|
2445
2014
|
if (content !== current)
|
|
2446
2015
|
await replaceFile(path, content);
|
|
2447
2016
|
return `.PHONY: ${targets.join(" ")}`;
|
|
@@ -2449,9 +2018,9 @@ async function toolFixers(dir) {
|
|
|
2449
2018
|
}
|
|
2450
2019
|
if (justfile !== undefined)
|
|
2451
2020
|
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2452
|
-
if (await Bun.file(
|
|
2021
|
+
if (await Bun.file(join12(dir, "go.mod")).exists())
|
|
2453
2022
|
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2454
|
-
if (await Bun.file(
|
|
2023
|
+
if (await Bun.file(join12(dir, "Cargo.toml")).exists())
|
|
2455
2024
|
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2456
2025
|
if (ruff)
|
|
2457
2026
|
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
@@ -2492,14 +2061,14 @@ function printChanged(changed) {
|
|
|
2492
2061
|
if (changed.length > MAX_CHANGED)
|
|
2493
2062
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2494
2063
|
}
|
|
2495
|
-
async function fix(args, cwd =
|
|
2496
|
-
const parsed = parse(args, fixUsage, fixOptions, { replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
|
|
2064
|
+
async function fix(args, cwd = process21.cwd()) {
|
|
2065
|
+
const parsed = parse(args, fixUsage, fixOptions, { exits: EXITS, replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
|
|
2497
2066
|
return runFixers(parsed.values, cwd);
|
|
2498
2067
|
}
|
|
2499
2068
|
async function runFixers(values, cwd) {
|
|
2500
2069
|
const parsed = { values };
|
|
2501
2070
|
const settings = placeSettings(values);
|
|
2502
|
-
if (
|
|
2071
|
+
if (process21.env[RUNNING] !== undefined)
|
|
2503
2072
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2504
2073
|
const found = await fixers(cwd);
|
|
2505
2074
|
if (found.length === 0)
|
|
@@ -2533,11 +2102,11 @@ async function runFixers(values, cwd) {
|
|
|
2533
2102
|
break;
|
|
2534
2103
|
if (missing(fixer)) {
|
|
2535
2104
|
if (!json)
|
|
2536
|
-
console.log(`${paint(
|
|
2105
|
+
console.log(`${paint(process21.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2537
2106
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2538
2107
|
continue;
|
|
2539
2108
|
}
|
|
2540
|
-
const logFile =
|
|
2109
|
+
const logFile = join12(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2541
2110
|
const placement = placements.get(fixer);
|
|
2542
2111
|
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2543
2112
|
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
@@ -2567,7 +2136,7 @@ async function runFixers(values, cwd) {
|
|
|
2567
2136
|
|
|
2568
2137
|
// src/narrow.ts
|
|
2569
2138
|
import { existsSync as existsSync6 } from "fs";
|
|
2570
|
-
import { basename as basename3, dirname as dirname5, extname, join as
|
|
2139
|
+
import { basename as basename3, dirname as dirname5, extname, join as join13 } from "path";
|
|
2571
2140
|
var {$: $2 } = globalThis.Bun;
|
|
2572
2141
|
var LINTERS = /^(?:keslint|eslint|oxlint)\b/;
|
|
2573
2142
|
var LINTABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".svelte"]);
|
|
@@ -2579,17 +2148,17 @@ async function changedPaths(dir) {
|
|
|
2579
2148
|
const untracked = await $2`git ls-files -z --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
2580
2149
|
if (tracked.exitCode !== 0 || untracked.exitCode !== 0)
|
|
2581
2150
|
return;
|
|
2582
|
-
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync6(
|
|
2151
|
+
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync6(join13(dir, path)));
|
|
2583
2152
|
}
|
|
2584
2153
|
function siblingTests(path, exists) {
|
|
2585
2154
|
const extension = extname(path);
|
|
2586
2155
|
const name = basename3(path, extension);
|
|
2587
2156
|
const dir = dirname5(path);
|
|
2588
|
-
const folders = [dir,
|
|
2157
|
+
const folders = [dir, join13(dir, "tests"), join13(dir, "..", "tests"), join13(dir, "__tests__")];
|
|
2589
2158
|
const found = new Set;
|
|
2590
2159
|
for (const folder of folders) {
|
|
2591
2160
|
for (const kind of ["test", "spec"]) {
|
|
2592
|
-
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) =>
|
|
2161
|
+
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) => join13(folder, file))) {
|
|
2593
2162
|
if (exists(candidate))
|
|
2594
2163
|
found.add(candidate);
|
|
2595
2164
|
}
|
|
@@ -2613,7 +2182,7 @@ async function narrow2(step, dir, changed) {
|
|
|
2613
2182
|
if (TEST_FILE.test(path)) {
|
|
2614
2183
|
tests.add(path);
|
|
2615
2184
|
} else {
|
|
2616
|
-
for (const test of siblingTests(path, (candidate) => existsSync6(
|
|
2185
|
+
for (const test of siblingTests(path, (candidate) => existsSync6(join13(dir, candidate)))) {
|
|
2617
2186
|
tests.add(test);
|
|
2618
2187
|
}
|
|
2619
2188
|
}
|
|
@@ -2640,7 +2209,7 @@ async function scriptText(dir, name) {
|
|
|
2640
2209
|
}
|
|
2641
2210
|
|
|
2642
2211
|
// src/check.ts
|
|
2643
|
-
var usage2 = `check [--only <steps>] [--changed] [--failed] [--quiet] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2212
|
+
var usage2 = `check [--only <steps>] [--changed] [--failed] [--quiet] [--timeout <duration>] [--slot | --no-slot] [--parallel] [--in <service> | --host] [--list]
|
|
2644
2213
|
check --fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
2645
2214
|
|
|
2646
2215
|
Runs the repo's check, typecheck, lint and test steps, from package.json scripts (through bun run), composer.json, a Justfile or a Makefile, and for PHP from phpstan.neon (typecheck), .php-cs-fixer.dist.php (lint, dry-run) and phpunit.xml.dist (test) when composer.json has no such script.
|
|
@@ -2648,12 +2217,14 @@ A folder without steps but with subfolders that have some (api/ and client/) run
|
|
|
2648
2217
|
A step runs inside the docker compose service that bind-mounts its folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the step fails naming it. --in picks the service, --host forces the host.
|
|
2649
2218
|
A passing step is one line, a failing one shows only what failed, and each step's full output is saved to the file whose path ends its line.
|
|
2650
2219
|
With --changed, lint and test run on the files changed against HEAD (staged, unstaged and untracked) when their script is a bare linter (keslint, eslint, oxlint) or a bare \`bun test\`: lint on the changed source files, test on the changed test files and the tests next to the changed sources. Every other step, and a test step finding no test for the diff, runs in full and the line says so.
|
|
2220
|
+
Each step queues for one of the machine-wide slots shared by every session (slot, half the CPUs) when the slot bin is installed, so concurrent runs do not overload the machine; --no-slot skips the queue, --slot fails when the bin is missing.
|
|
2221
|
+
With --parallel, the steps run at the same time, each one's output held and printed in step order as the earlier ones finish; each still queues for its own slot. Steps writing the same files may trip over each other.
|
|
2651
2222
|
With --quiet, passing steps print nothing, and a fully passing run prints nothing at all: only the failing steps and the closing summary of a run that failed.
|
|
2652
2223
|
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2653
2224
|
With --failed, only the steps that failed in the last run of this folder run again, read from that run's folder of logs; when no last run failed, it says so and exits 2.
|
|
2654
|
-
With --fix, the folder's fixers and formatters run instead of the steps, exactly as the \`fix\` bin does (it is the alias of \`check --fix\`): its own scripts, php-cs-fixer, just --fmt, go fmt, cargo fmt, ruff and the Makefile's .PHONY targets, then the files the run changed are listed. --only then names fixers, as --list prints them; --changed, --failed
|
|
2655
|
-
Exits 0 when every step passed, 1 when one failed, 2 on bad usage, when no step is found or when a step timed out.
|
|
2225
|
+
With --fix, the folder's fixers and formatters run instead of the steps, exactly as the \`fix\` bin does (it is the alias of \`check --fix\`): its own scripts, php-cs-fixer, just --fmt, go fmt, cargo fmt, ruff and the Makefile's .PHONY targets, then the files the run changed are listed. --only then names fixers, as --list prints them; --changed, --failed, --slot, --no-slot and --parallel do not apply.
|
|
2656
2226
|
--json prints [{name, command, in?, ok, ms, log, failed?}] once every step ran, --list --json [{name, command, source, in?}], in the compose service the step ran in; with --fix the shape \`fix --json\` prints.`;
|
|
2227
|
+
var EXITS2 = [[0, "every step passed"], [1, "one failed"], [2, "bad usage, no step is found or a step timed out"]];
|
|
2657
2228
|
function slotted(command) {
|
|
2658
2229
|
return `slot -- sh -c ${shellQuote(command)}`;
|
|
2659
2230
|
}
|
|
@@ -2682,25 +2253,29 @@ function launch(step) {
|
|
|
2682
2253
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2683
2254
|
}
|
|
2684
2255
|
function summaryLine(outcomes) {
|
|
2685
|
-
const colors = paint(
|
|
2256
|
+
const colors = paint(process22.stdout);
|
|
2686
2257
|
const failed = outcomes.filter((outcome) => !outcome.ok).length;
|
|
2687
2258
|
const passed = outcomes.length - failed;
|
|
2688
2259
|
const parts = [colors.green(`${passed} passed`), ...failed === 0 ? [] : [colors.red(`${failed} failed`)], colors.dim(formatDuration(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0)))];
|
|
2689
2260
|
return parts.join(colors.dim(" \xB7 "));
|
|
2690
2261
|
}
|
|
2691
|
-
async function check(args, cwd =
|
|
2692
|
-
const parsed = parse(args, usage2, options, { replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2262
|
+
async function check(args, cwd = process22.cwd()) {
|
|
2263
|
+
const parsed = parse(args, usage2, options, { exits: EXITS2, replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2693
2264
|
const settings = placeSettings(parsed.values);
|
|
2694
2265
|
if (parsed.values.fix === true) {
|
|
2695
|
-
for (const flag of ["changed", "failed", "slot"]) {
|
|
2266
|
+
for (const flag of ["changed", "failed", "slot", "no-slot", "parallel"]) {
|
|
2696
2267
|
if (parsed.values[flag] === true)
|
|
2697
2268
|
fail(`--${flag} does not apply to --fix`);
|
|
2698
2269
|
}
|
|
2699
2270
|
return runFixers(parsed.values, cwd);
|
|
2700
2271
|
}
|
|
2701
2272
|
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2702
|
-
if (parsed.values.slot === true &&
|
|
2273
|
+
if (parsed.values.slot === true && parsed.values["no-slot"] === true)
|
|
2274
|
+
fail("--slot and --no-slot exclude each other");
|
|
2275
|
+
const hasSlot = Bun.which("slot", { PATH: process22.env.PATH ?? "" }) !== null;
|
|
2276
|
+
if (parsed.values.slot === true && !hasSlot)
|
|
2703
2277
|
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2278
|
+
const slotting = parsed.values["no-slot"] !== true && hasSlot;
|
|
2704
2279
|
const projects = await discoverProjects(cwd);
|
|
2705
2280
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
2706
2281
|
if (found.length === 0)
|
|
@@ -2730,25 +2305,47 @@ async function check(args, cwd = process20.cwd()) {
|
|
|
2730
2305
|
const width = Math.max(...steps.map((step) => step.label.length));
|
|
2731
2306
|
const outcomes = [];
|
|
2732
2307
|
const quiet = parsed.values.quiet === true;
|
|
2733
|
-
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
|
|
2308
|
+
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`, process22.stdout);
|
|
2734
2309
|
if (heading !== "")
|
|
2735
2310
|
console.log(heading);
|
|
2311
|
+
const execute = async (step, signals) => {
|
|
2312
|
+
const logFile = join14(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2313
|
+
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2314
|
+
const command = slotting ? slotted(launch(step)) : launch(step);
|
|
2315
|
+
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held: signals }) : await refusedStep(down, logFile);
|
|
2316
|
+
return { step, logFile, outcome };
|
|
2317
|
+
};
|
|
2318
|
+
const report = ({ step, logFile, outcome }) => {
|
|
2319
|
+
if (!json && !(quiet && outcome.ok))
|
|
2320
|
+
printOutcome(step.label, width, `${step.command}${step.note === undefined ? "" : ` (${step.note})`}${step.placement === undefined ? "" : ` (in ${step.placement.service})`}`, logFile, outcome);
|
|
2321
|
+
outcomes.push(outcomeJson(step.label, step.command, logFile, outcome, step.placement?.service));
|
|
2322
|
+
};
|
|
2736
2323
|
try {
|
|
2737
|
-
|
|
2738
|
-
const
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2324
|
+
if (parsed.values.parallel === true) {
|
|
2325
|
+
const children = new Set;
|
|
2326
|
+
const shared = { get signal() {
|
|
2327
|
+
return held.signal;
|
|
2328
|
+
}, forward: (child) => children.add(child), release: held.release };
|
|
2329
|
+
held.forward({ kill: (signal) => {
|
|
2330
|
+
for (const child of children) {
|
|
2331
|
+
child.kill(signal);
|
|
2332
|
+
}
|
|
2333
|
+
} });
|
|
2334
|
+
for (const run of steps.map(async (step) => execute(step, shared)))
|
|
2335
|
+
report(await run);
|
|
2336
|
+
} else {
|
|
2337
|
+
for (const step of steps) {
|
|
2338
|
+
report(await execute(step, held));
|
|
2339
|
+
if (held.signal !== undefined)
|
|
2340
|
+
break;
|
|
2341
|
+
}
|
|
2747
2342
|
}
|
|
2748
2343
|
} finally {
|
|
2749
2344
|
held.release();
|
|
2750
2345
|
}
|
|
2751
|
-
|
|
2346
|
+
const ran = outcomes.map(({ name, ok }) => ({ name, ok }));
|
|
2347
|
+
const kept = (await lastResults(cwd) ?? []).filter(({ name }) => !ran.some((each) => each.name === name));
|
|
2348
|
+
await writeFile3(join14(directory, RESULTS_FILE), JSON.stringify([...kept, ...ran]), { mode: 384 });
|
|
2752
2349
|
if (json)
|
|
2753
2350
|
printJson(outcomes);
|
|
2754
2351
|
else if (heading !== "" || quiet && !outcomes.every((outcome) => outcome.ok))
|
|
@@ -2761,4 +2358,4 @@ async function check(args, cwd = process20.cwd()) {
|
|
|
2761
2358
|
}
|
|
2762
2359
|
|
|
2763
2360
|
// src/cli.ts
|
|
2764
|
-
|
|
2361
|
+
process23.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|