@kaynooo/cli-check 0.18.3 → 0.20.1
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 +401 -723
- package/dist/errs-cli.js +384 -221
- package/dist/fix-cli.js +348 -698
- package/dist/j-cli.js +675 -132
- 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,7 +461,7 @@ 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)) {
|
|
@@ -500,32 +500,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
500
500
|
return [];
|
|
501
501
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
502
502
|
}
|
|
503
|
+
var MAX_INLINE_CHOICES = 24;
|
|
503
504
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
504
505
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
505
506
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
506
|
-
const
|
|
507
|
+
const choices = option.choices?.join("|");
|
|
508
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
509
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
507
510
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
508
511
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
509
|
-
|
|
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 };
|
|
510
514
|
});
|
|
511
515
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
512
516
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
513
517
|
}
|
|
514
518
|
|
|
515
519
|
// ../kit/src/text.ts
|
|
516
|
-
var ANSI =
|
|
520
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
517
521
|
function stripAnsi(text) {
|
|
518
522
|
return text.replace(ANSI, "");
|
|
519
523
|
}
|
|
520
524
|
function distance(a, b) {
|
|
521
|
-
|
|
522
|
-
|
|
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()) {
|
|
523
530
|
const current = [i + 1];
|
|
524
|
-
for (const [j,
|
|
525
|
-
|
|
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;
|
|
526
538
|
previous = current;
|
|
527
539
|
}
|
|
528
|
-
return previous[
|
|
540
|
+
return previous[right.length] ?? 0;
|
|
529
541
|
}
|
|
530
542
|
function closest(name, names) {
|
|
531
543
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -604,7 +616,7 @@ class Completing {
|
|
|
604
616
|
}
|
|
605
617
|
var completion = { active: false };
|
|
606
618
|
var OUTPUT_OPTIONS = {
|
|
607
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
619
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
608
620
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
609
621
|
};
|
|
610
622
|
function applyOutput(color, plain, env = process10.env) {
|
|
@@ -930,31 +942,109 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
930
942
|
// ../kit/src/cli.ts
|
|
931
943
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
932
944
|
import { dirname as dirname3, join as join6 } from "path";
|
|
933
|
-
import
|
|
945
|
+
import process16 from "process";
|
|
946
|
+
|
|
947
|
+
// ../kit/src/completions.ts
|
|
948
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
949
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
950
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
951
|
+
set -l current (commandline -ct)
|
|
952
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
953
|
+
if test "$line" = __files__
|
|
954
|
+
__fish_complete_path $current
|
|
955
|
+
else
|
|
956
|
+
echo $line
|
|
957
|
+
end
|
|
958
|
+
end
|
|
959
|
+
end`;
|
|
960
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
961
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
962
|
+
local -a lines
|
|
963
|
+
COMPREPLY=()
|
|
964
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
965
|
+
for line in "\${lines[@]}"; do
|
|
966
|
+
if [[ $line == __files__ ]]; then
|
|
967
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
968
|
+
else
|
|
969
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
970
|
+
fi
|
|
971
|
+
done
|
|
972
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
973
|
+
}`;
|
|
974
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
975
|
+
local line
|
|
976
|
+
local -a described plain
|
|
977
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
978
|
+
if [[ $line == __files__ ]]; then
|
|
979
|
+
_files
|
|
980
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
981
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
982
|
+
else
|
|
983
|
+
plain+=("$line")
|
|
984
|
+
fi
|
|
985
|
+
done
|
|
986
|
+
(( \${#described} )) && _describe -V value described
|
|
987
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
988
|
+
return 0
|
|
989
|
+
}`;
|
|
990
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
991
|
+
if (shell === "fish")
|
|
992
|
+
return `${header}
|
|
993
|
+
${FISH_FUNCTION}
|
|
994
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
995
|
+
`).join("")}`;
|
|
996
|
+
if (shell === "bash")
|
|
997
|
+
return `${header}
|
|
998
|
+
${BASH_FUNCTION}
|
|
999
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1000
|
+
`;
|
|
1001
|
+
return `${header}
|
|
1002
|
+
${ZSH_FUNCTION}
|
|
1003
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1004
|
+
`;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// ../kit/src/notify.ts
|
|
1008
|
+
import process13 from "process";
|
|
1009
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1010
|
+
var CANCELLED = 130;
|
|
1011
|
+
function base64(text) {
|
|
1012
|
+
return Buffer.from(text).toString("base64");
|
|
1013
|
+
}
|
|
1014
|
+
function notification(title, body, env = process13.env) {
|
|
1015
|
+
const id = `kit${process13.pid}`;
|
|
1016
|
+
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\\`];
|
|
1017
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1018
|
+
}
|
|
1019
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1020
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1021
|
+
return;
|
|
1022
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1023
|
+
}
|
|
934
1024
|
|
|
935
1025
|
// ../kit/src/usage.ts
|
|
936
1026
|
import { appendFileSync, mkdirSync } from "fs";
|
|
937
1027
|
import { homedir as homedir4 } from "os";
|
|
938
1028
|
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
939
|
-
import
|
|
1029
|
+
import process15 from "process";
|
|
940
1030
|
|
|
941
1031
|
// ../kit/src/logs.ts
|
|
942
1032
|
import { lstatSync, openSync } from "fs";
|
|
943
1033
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
944
1034
|
import { homedir as homedir3, tmpdir } from "os";
|
|
945
1035
|
import { join as join4 } from "path";
|
|
946
|
-
import
|
|
1036
|
+
import process14 from "process";
|
|
947
1037
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
948
1038
|
var CLI_FOLDER = "kaynooo-cli";
|
|
949
1039
|
function isPrivateDirectory(path) {
|
|
950
1040
|
try {
|
|
951
1041
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
952
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1042
|
+
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
953
1043
|
} catch {
|
|
954
1044
|
return false;
|
|
955
1045
|
}
|
|
956
1046
|
}
|
|
957
|
-
async function privateLogDirectory(name, env =
|
|
1047
|
+
async function privateLogDirectory(name, env = process14.env) {
|
|
958
1048
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
959
1049
|
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
960
1050
|
const path = join4(base, name);
|
|
@@ -994,14 +1084,14 @@ var usageError;
|
|
|
994
1084
|
function noteUsageError(message) {
|
|
995
1085
|
usageError = message;
|
|
996
1086
|
}
|
|
997
|
-
function stateHome(env =
|
|
1087
|
+
function stateHome(env = process15.env) {
|
|
998
1088
|
const dir = env.XDG_STATE_HOME;
|
|
999
1089
|
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1000
1090
|
}
|
|
1001
|
-
function usagePath(env =
|
|
1091
|
+
function usagePath(env = process15.env) {
|
|
1002
1092
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1003
1093
|
}
|
|
1004
|
-
function usageRecorded(env =
|
|
1094
|
+
function usageRecorded(env = process15.env) {
|
|
1005
1095
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1006
1096
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1007
1097
|
}
|
|
@@ -1015,7 +1105,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1015
1105
|
usageError = undefined;
|
|
1016
1106
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1017
1107
|
}
|
|
1018
|
-
function recordUsage(entry, env =
|
|
1108
|
+
function recordUsage(entry, env = process15.env) {
|
|
1019
1109
|
if (!usageRecorded(env))
|
|
1020
1110
|
return;
|
|
1021
1111
|
try {
|
|
@@ -1031,10 +1121,14 @@ var LEVEL_OPTIONS = {
|
|
|
1031
1121
|
...OUTPUT_OPTIONS,
|
|
1032
1122
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1033
1123
|
};
|
|
1034
|
-
var TOP_OPTIONS = {
|
|
1124
|
+
var TOP_OPTIONS = {
|
|
1125
|
+
...LEVEL_OPTIONS,
|
|
1126
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1127
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1128
|
+
};
|
|
1035
1129
|
function printError(prefix, message, hint, cause) {
|
|
1036
|
-
const colors = paint(
|
|
1037
|
-
const styled = takesControlCodes(
|
|
1130
|
+
const colors = paint(process16.stderr);
|
|
1131
|
+
const styled = takesControlCodes(process16.stderr);
|
|
1038
1132
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1039
1133
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1040
1134
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1111,6 +1205,19 @@ async function leafCandidates(run, words) {
|
|
|
1111
1205
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1112
1206
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1113
1207
|
}
|
|
1208
|
+
var COMPLETIONS = "--completions";
|
|
1209
|
+
function flagValue([flag = "", ...rest]) {
|
|
1210
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1211
|
+
}
|
|
1212
|
+
function printCompletionScript(name, args) {
|
|
1213
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1214
|
+
if (shell === undefined || args.length !== 1) {
|
|
1215
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1216
|
+
return 2;
|
|
1217
|
+
}
|
|
1218
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1219
|
+
return 0;
|
|
1220
|
+
}
|
|
1114
1221
|
async function printCandidates(found) {
|
|
1115
1222
|
for (const line of await found)
|
|
1116
1223
|
console.log(line);
|
|
@@ -1134,16 +1241,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1134
1241
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1135
1242
|
if (argv[0] === COMPLETE)
|
|
1136
1243
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1244
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1245
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1137
1246
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1138
1247
|
console.log(version ?? packageVersion());
|
|
1139
1248
|
return 0;
|
|
1140
1249
|
}
|
|
1141
1250
|
let code;
|
|
1251
|
+
const started = performance.now();
|
|
1142
1252
|
try {
|
|
1143
1253
|
code = await run(argv);
|
|
1144
1254
|
} catch (error) {
|
|
1145
1255
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1146
1256
|
}
|
|
1257
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1147
1258
|
if (usage !== false) {
|
|
1148
1259
|
try {
|
|
1149
1260
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1151,13 +1262,174 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1151
1262
|
}
|
|
1152
1263
|
return code;
|
|
1153
1264
|
}
|
|
1265
|
+
// ../kit/src/excerpt.ts
|
|
1266
|
+
var BASH_ECHO = /^\$ /;
|
|
1267
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1268
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1269
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1270
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1271
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1272
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1273
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1274
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
1275
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1276
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
1277
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1278
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1279
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1280
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1281
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1282
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1283
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1284
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1285
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1286
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1287
|
+
var MAX_TESTS = 10;
|
|
1288
|
+
var MAX_LINES = 100;
|
|
1289
|
+
var TAIL = 30;
|
|
1290
|
+
var bunTest = (lines) => {
|
|
1291
|
+
const seen = new Set;
|
|
1292
|
+
const blocks = [];
|
|
1293
|
+
for (const [index, line] of lines.entries()) {
|
|
1294
|
+
const name = line.replace(DURATION2, "");
|
|
1295
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1296
|
+
continue;
|
|
1297
|
+
seen.add(name);
|
|
1298
|
+
if (blocks.length < MAX_TESTS)
|
|
1299
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1300
|
+
`).trim());
|
|
1301
|
+
}
|
|
1302
|
+
if (blocks.length === 0)
|
|
1303
|
+
return;
|
|
1304
|
+
if (seen.size > MAX_TESTS)
|
|
1305
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1306
|
+
return [...blocks.join(`
|
|
1307
|
+
|
|
1308
|
+
`).split(`
|
|
1309
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1310
|
+
};
|
|
1311
|
+
var bunCheck = (lines) => {
|
|
1312
|
+
const text = lines.join(`
|
|
1313
|
+
`);
|
|
1314
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1315
|
+
if (blocks === null)
|
|
1316
|
+
return;
|
|
1317
|
+
const errors = blocks.map((block) => {
|
|
1318
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1319
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1320
|
+
});
|
|
1321
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1322
|
+
};
|
|
1323
|
+
function bunCheckFields(block) {
|
|
1324
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1325
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1326
|
+
return {
|
|
1327
|
+
file: attributes.file ?? "",
|
|
1328
|
+
line: attributes.line ?? "",
|
|
1329
|
+
column: attributes.column ?? "",
|
|
1330
|
+
code: attributes.code ?? "",
|
|
1331
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1332
|
+
`).slice(1, -1).join(`
|
|
1333
|
+
`).trim()
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
var tsc = (lines) => {
|
|
1337
|
+
const kept = [];
|
|
1338
|
+
let inError = false;
|
|
1339
|
+
for (const line of lines) {
|
|
1340
|
+
if (TSC_ERROR.test(line)) {
|
|
1341
|
+
inError = true;
|
|
1342
|
+
kept.push(line);
|
|
1343
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
1344
|
+
inError = false;
|
|
1345
|
+
kept.push(line);
|
|
1346
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1347
|
+
kept.push(line);
|
|
1348
|
+
} else {
|
|
1349
|
+
inError = false;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1353
|
+
};
|
|
1354
|
+
var eslint = (lines) => {
|
|
1355
|
+
const kept = [];
|
|
1356
|
+
let file = "";
|
|
1357
|
+
let shown = "";
|
|
1358
|
+
for (const line of lines) {
|
|
1359
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
1360
|
+
if (file !== shown) {
|
|
1361
|
+
kept.push(file);
|
|
1362
|
+
shown = file;
|
|
1363
|
+
}
|
|
1364
|
+
kept.push(line);
|
|
1365
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1366
|
+
kept.push(line);
|
|
1367
|
+
} else if (line.trim() !== "") {
|
|
1368
|
+
file = line;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1372
|
+
};
|
|
1373
|
+
var phpstan = (lines) => {
|
|
1374
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1375
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1376
|
+
};
|
|
1377
|
+
var php = (lines) => {
|
|
1378
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1379
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1380
|
+
};
|
|
1381
|
+
var vitest = (lines) => {
|
|
1382
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1383
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1384
|
+
};
|
|
1385
|
+
var playwright = (lines) => {
|
|
1386
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1387
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1388
|
+
};
|
|
1389
|
+
var phpCsFixer = (lines) => {
|
|
1390
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1391
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1392
|
+
};
|
|
1393
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1394
|
+
function squeeze(lines) {
|
|
1395
|
+
const out = [];
|
|
1396
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1397
|
+
if (line !== "" || out.at(-1) !== "")
|
|
1398
|
+
out.push(line);
|
|
1399
|
+
}
|
|
1400
|
+
while (out.at(-1) === "")
|
|
1401
|
+
out.pop();
|
|
1402
|
+
return out;
|
|
1403
|
+
}
|
|
1404
|
+
function cut(shown) {
|
|
1405
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1406
|
+
`) : shown.join(`
|
|
1407
|
+
`);
|
|
1408
|
+
}
|
|
1409
|
+
function recognised(lines, parsers) {
|
|
1410
|
+
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1411
|
+
}
|
|
1412
|
+
function failureExcerpt(output) {
|
|
1413
|
+
const lines = stripAnsi(output).split(`
|
|
1414
|
+
`);
|
|
1415
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1416
|
+
lines.shift();
|
|
1417
|
+
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1418
|
+
}
|
|
1419
|
+
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
1420
|
// ../kit/src/folders.ts
|
|
1421
|
+
import { homedir as homedir5 } from "os";
|
|
1422
|
+
import { join as join7 } from "path";
|
|
1423
|
+
import process17 from "process";
|
|
1155
1424
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1156
1425
|
function ignoredFolders(extra = [], where = {}) {
|
|
1157
1426
|
const configured = readUserConfig("config", where).ignore;
|
|
1158
1427
|
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1159
1428
|
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1160
1429
|
}
|
|
1430
|
+
function cacheFolder({ home = homedir5(), env = process17.env } = {}) {
|
|
1431
|
+
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
1432
|
+
}
|
|
1161
1433
|
// ../kit/src/secrets.ts
|
|
1162
1434
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1163
1435
|
// ../kit/src/sessions.ts
|
|
@@ -1165,12 +1437,12 @@ var {Glob } = globalThis.Bun;
|
|
|
1165
1437
|
var SESSION_FILES = new Glob("*.json");
|
|
1166
1438
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1167
1439
|
// package.json
|
|
1168
|
-
var version = "0.
|
|
1440
|
+
var version = "0.20.1";
|
|
1169
1441
|
|
|
1170
1442
|
// src/check.ts
|
|
1171
1443
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
1172
|
-
import { basename as basename4, join as
|
|
1173
|
-
import
|
|
1444
|
+
import { basename as basename4, join as join14 } from "path";
|
|
1445
|
+
import process22 from "process";
|
|
1174
1446
|
|
|
1175
1447
|
// ../kit/src/shell.ts
|
|
1176
1448
|
var SEPARATORS = new Set([`
|
|
@@ -1221,9 +1493,9 @@ function shellQuote(word) {
|
|
|
1221
1493
|
|
|
1222
1494
|
// src/compose.ts
|
|
1223
1495
|
import { existsSync as existsSync4 } from "fs";
|
|
1224
|
-
import { homedir as
|
|
1225
|
-
import { basename, dirname as dirname4, join as
|
|
1226
|
-
import
|
|
1496
|
+
import { homedir as homedir6 } from "os";
|
|
1497
|
+
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
|
|
1498
|
+
import process19 from "process";
|
|
1227
1499
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1228
1500
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1229
1501
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1252,7 +1524,7 @@ function toolWords(program) {
|
|
|
1252
1524
|
}
|
|
1253
1525
|
async function readFiles(dir, names) {
|
|
1254
1526
|
for (const name of names) {
|
|
1255
|
-
const handle = Bun.file(
|
|
1527
|
+
const handle = Bun.file(join8(dir, name));
|
|
1256
1528
|
if (await handle.exists())
|
|
1257
1529
|
return { name, text: await handle.text() };
|
|
1258
1530
|
}
|
|
@@ -1267,7 +1539,7 @@ async function variables(composeDir) {
|
|
|
1267
1539
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1268
1540
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1269
1541
|
}
|
|
1270
|
-
for (const [key, value] of Object.entries(
|
|
1542
|
+
for (const [key, value] of Object.entries(process19.env)) {
|
|
1271
1543
|
if (value !== undefined)
|
|
1272
1544
|
env[key] = value;
|
|
1273
1545
|
}
|
|
@@ -1287,7 +1559,7 @@ function interpolate(text, env) {
|
|
|
1287
1559
|
function bindSource(source, composeDir, env) {
|
|
1288
1560
|
const path = interpolate(source, env);
|
|
1289
1561
|
if (path.startsWith("~"))
|
|
1290
|
-
return
|
|
1562
|
+
return join8(homedir6(), path.slice(1));
|
|
1291
1563
|
if (path.startsWith("/"))
|
|
1292
1564
|
return resolve4(path);
|
|
1293
1565
|
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
@@ -1334,7 +1606,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1334
1606
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1335
1607
|
const file = Bun.file(resolve4(composeDir, name));
|
|
1336
1608
|
if (!await file.exists())
|
|
1337
|
-
fail(`COMPOSE_FILE names ${
|
|
1609
|
+
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1338
1610
|
files.push({ name, text: await file.text() });
|
|
1339
1611
|
}
|
|
1340
1612
|
return files;
|
|
@@ -1356,7 +1628,7 @@ async function readServices(composeDir) {
|
|
|
1356
1628
|
try {
|
|
1357
1629
|
parsed = parseServices(file.text, composeDir, env);
|
|
1358
1630
|
} catch (error) {
|
|
1359
|
-
fail(`cannot read ${
|
|
1631
|
+
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
1632
|
}
|
|
1361
1633
|
for (const [name, extra] of parsed) {
|
|
1362
1634
|
const known = services.get(name);
|
|
@@ -1368,11 +1640,11 @@ async function readServices(composeDir) {
|
|
|
1368
1640
|
function climb(dir) {
|
|
1369
1641
|
const folders = [dir];
|
|
1370
1642
|
let current = dir;
|
|
1371
|
-
while (!existsSync4(
|
|
1643
|
+
while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1372
1644
|
current = dirname4(current);
|
|
1373
1645
|
folders.push(current);
|
|
1374
1646
|
}
|
|
1375
|
-
return existsSync4(
|
|
1647
|
+
return existsSync4(join8(current, ".git")) ? folders : [dir];
|
|
1376
1648
|
}
|
|
1377
1649
|
function containerPath(service, dir) {
|
|
1378
1650
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1383,7 +1655,7 @@ function containerPath(service, dir) {
|
|
|
1383
1655
|
if (deepest === undefined)
|
|
1384
1656
|
return;
|
|
1385
1657
|
const inside = relative(deepest.source, dir);
|
|
1386
|
-
return inside === "" ? deepest.target :
|
|
1658
|
+
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1387
1659
|
}
|
|
1388
1660
|
var noticed = new Set;
|
|
1389
1661
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1403,7 +1675,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1403
1675
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1404
1676
|
return;
|
|
1405
1677
|
}
|
|
1406
|
-
if (Bun.which("docker", { PATH:
|
|
1678
|
+
if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
|
|
1407
1679
|
if (service !== undefined)
|
|
1408
1680
|
fail(`--in ${service}: docker not found`);
|
|
1409
1681
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1455,7 +1727,7 @@ class Stack {
|
|
|
1455
1727
|
}
|
|
1456
1728
|
static async running(composeDir) {
|
|
1457
1729
|
try {
|
|
1458
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1730
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1459
1731
|
if (ran.code !== 0)
|
|
1460
1732
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1461
1733
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1489,12 +1761,12 @@ function placeSettings(values) {
|
|
|
1489
1761
|
// src/fix.ts
|
|
1490
1762
|
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1491
1763
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1492
|
-
import { join as
|
|
1493
|
-
import
|
|
1764
|
+
import { join as join12 } from "path";
|
|
1765
|
+
import process21 from "process";
|
|
1494
1766
|
|
|
1495
1767
|
// src/changes.ts
|
|
1496
1768
|
import { stat as stat2 } from "fs/promises";
|
|
1497
|
-
import { join as
|
|
1769
|
+
import { join as join9 } from "path";
|
|
1498
1770
|
var {$ } = globalThis.Bun;
|
|
1499
1771
|
async function dirtyFiles(dir) {
|
|
1500
1772
|
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
@@ -1503,7 +1775,7 @@ async function dirtyFiles(dir) {
|
|
|
1503
1775
|
const files = new Map;
|
|
1504
1776
|
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1505
1777
|
try {
|
|
1506
|
-
const { size, mtimeMs } = await stat2(
|
|
1778
|
+
const { size, mtimeMs } = await stat2(join9(dir, path));
|
|
1507
1779
|
files.set(path, `${size}:${mtimeMs}`);
|
|
1508
1780
|
} catch {
|
|
1509
1781
|
files.set(path, "");
|
|
@@ -1548,7 +1820,7 @@ ${body}`;
|
|
|
1548
1820
|
|
|
1549
1821
|
// src/steps.ts
|
|
1550
1822
|
import { readdir as readdir2 } from "fs/promises";
|
|
1551
|
-
import { join as
|
|
1823
|
+
import { join as join10 } from "path";
|
|
1552
1824
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1553
1825
|
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1554
1826
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
@@ -1560,7 +1832,7 @@ var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"]
|
|
|
1560
1832
|
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1561
1833
|
async function readFirst(dir, files) {
|
|
1562
1834
|
for (const file of files) {
|
|
1563
|
-
const handle = Bun.file(
|
|
1835
|
+
const handle = Bun.file(join10(dir, file));
|
|
1564
1836
|
if (await handle.exists())
|
|
1565
1837
|
return { file, text: await handle.text() };
|
|
1566
1838
|
}
|
|
@@ -1568,7 +1840,7 @@ async function readFirst(dir, files) {
|
|
|
1568
1840
|
}
|
|
1569
1841
|
async function read(dir, ...files) {
|
|
1570
1842
|
for (const file of files) {
|
|
1571
|
-
const handle = Bun.file(
|
|
1843
|
+
const handle = Bun.file(join10(dir, file));
|
|
1572
1844
|
if (await handle.exists())
|
|
1573
1845
|
return handle.text();
|
|
1574
1846
|
}
|
|
@@ -1628,7 +1900,7 @@ async function candidates(dir, bin) {
|
|
|
1628
1900
|
}
|
|
1629
1901
|
async function firstFile(dir, names) {
|
|
1630
1902
|
for (const name of names) {
|
|
1631
|
-
if (await Bun.file(
|
|
1903
|
+
if (await Bun.file(join10(dir, name)).exists())
|
|
1632
1904
|
return name;
|
|
1633
1905
|
}
|
|
1634
1906
|
return;
|
|
@@ -1656,9 +1928,9 @@ async function discoverProjects(dir) {
|
|
|
1656
1928
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1657
1929
|
if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1658
1930
|
continue;
|
|
1659
|
-
const steps = await discover(
|
|
1931
|
+
const steps = await discover(join10(dir, entry.name));
|
|
1660
1932
|
if (steps.length > 0)
|
|
1661
|
-
projects.push({ name: entry.name, dir:
|
|
1933
|
+
projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
|
|
1662
1934
|
}
|
|
1663
1935
|
return projects;
|
|
1664
1936
|
}
|
|
@@ -1681,11 +1953,14 @@ var fixOptions = {
|
|
|
1681
1953
|
};
|
|
1682
1954
|
var options = {
|
|
1683
1955
|
...fixOptions,
|
|
1956
|
+
only: { ...fixOptions.only, candidates: () => [...STEP_NAMES] },
|
|
1684
1957
|
fix: { type: "boolean", short: "f", description: "run the folder's fixers and formatters instead of the steps, as the fix bin does" },
|
|
1685
1958
|
quiet: { type: "boolean", short: "q", description: "print nothing for a passing step, and nothing at all when every step passes" },
|
|
1686
1959
|
failed: { type: "boolean", description: "run only the steps that failed in the last run of this folder, read from the run folder" },
|
|
1687
1960
|
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
|
|
1961
|
+
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" },
|
|
1962
|
+
"no-slot": { type: "boolean", description: "run the steps at once, without queueing behind the other sessions' slots" },
|
|
1963
|
+
parallel: { type: "boolean", description: "run the steps at the same time, printing each one's output in step order" }
|
|
1689
1964
|
};
|
|
1690
1965
|
var COMMA = /\s*,\s*/;
|
|
1691
1966
|
function pick(steps, only, noun = "step") {
|
|
@@ -1702,654 +1977,26 @@ function pick(steps, only, noun = "step") {
|
|
|
1702
1977
|
|
|
1703
1978
|
// src/run.ts
|
|
1704
1979
|
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
|
|
1980
|
+
import { basename as basename2, join as join11 } from "path";
|
|
1981
|
+
import process20 from "process";
|
|
2335
1982
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2336
1983
|
var RESULTS_FILE = "results.json";
|
|
2337
1984
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2338
1985
|
async function logDirectory(cwd) {
|
|
2339
1986
|
const root = await privateLogDirectory("check");
|
|
2340
1987
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2341
|
-
const path =
|
|
1988
|
+
const path = join11(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
|
|
2342
1989
|
await mkdir2(path, { mode: 448 });
|
|
2343
1990
|
return path;
|
|
2344
1991
|
}
|
|
2345
|
-
async function
|
|
1992
|
+
async function lastResults(cwd) {
|
|
2346
1993
|
const root = await privateLogDirectory("check");
|
|
2347
1994
|
const prefix = runPrefix(cwd);
|
|
2348
1995
|
let latest;
|
|
2349
1996
|
for (const name of await readdir3(root)) {
|
|
2350
1997
|
if (!name.startsWith(prefix))
|
|
2351
1998
|
continue;
|
|
2352
|
-
const file =
|
|
1999
|
+
const file = join11(root, name, RESULTS_FILE);
|
|
2353
2000
|
try {
|
|
2354
2001
|
const { mtimeMs } = await stat3(file);
|
|
2355
2002
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2358,13 +2005,15 @@ async function lastFailed(cwd) {
|
|
|
2358
2005
|
}
|
|
2359
2006
|
if (latest === undefined)
|
|
2360
2007
|
return;
|
|
2361
|
-
|
|
2362
|
-
|
|
2008
|
+
return JSON.parse(await Bun.file(latest.file).text());
|
|
2009
|
+
}
|
|
2010
|
+
async function lastFailed(cwd) {
|
|
2011
|
+
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
2363
2012
|
}
|
|
2364
2013
|
async function saveLog(output) {
|
|
2365
2014
|
const root = await privateLogDirectory("errs");
|
|
2366
2015
|
await sweepLogs(root);
|
|
2367
|
-
const path =
|
|
2016
|
+
const path = join11(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2368
2017
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2369
2018
|
return path;
|
|
2370
2019
|
}
|
|
@@ -2372,7 +2021,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2372
2021
|
const started = Date.now();
|
|
2373
2022
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2374
2023
|
cwd,
|
|
2375
|
-
env: { ...
|
|
2024
|
+
env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2376
2025
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2377
2026
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2378
2027
|
});
|
|
@@ -2388,8 +2037,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2388
2037
|
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
2038
|
}
|
|
2390
2039
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2391
|
-
const colors = paint(
|
|
2392
|
-
const path = role("path",
|
|
2040
|
+
const colors = paint(process20.stdout);
|
|
2041
|
+
const path = role("path", process20.stdout);
|
|
2393
2042
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2394
2043
|
if (outcome.ok) {
|
|
2395
2044
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2420,7 +2069,7 @@ var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
|
2420
2069
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2421
2070
|
var MAX_CHANGED = 30;
|
|
2422
2071
|
async function replaceFile(path, content) {
|
|
2423
|
-
const temporary = `${path}.${
|
|
2072
|
+
const temporary = `${path}.${process21.pid}.tmp`;
|
|
2424
2073
|
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
2425
2074
|
await rename(temporary, path);
|
|
2426
2075
|
}
|
|
@@ -2439,9 +2088,9 @@ async function toolFixers(dir) {
|
|
|
2439
2088
|
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2440
2089
|
if (makefile !== undefined) {
|
|
2441
2090
|
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2442
|
-
const path =
|
|
2091
|
+
const path = join12(cwd, makefile);
|
|
2443
2092
|
const current = await Bun.file(path).text();
|
|
2444
|
-
const { content, targets } = declarePhony(current, (name) => existsSync5(
|
|
2093
|
+
const { content, targets } = declarePhony(current, (name) => existsSync5(join12(cwd, name)));
|
|
2445
2094
|
if (content !== current)
|
|
2446
2095
|
await replaceFile(path, content);
|
|
2447
2096
|
return `.PHONY: ${targets.join(" ")}`;
|
|
@@ -2449,14 +2098,15 @@ async function toolFixers(dir) {
|
|
|
2449
2098
|
}
|
|
2450
2099
|
if (justfile !== undefined)
|
|
2451
2100
|
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2452
|
-
if (await Bun.file(
|
|
2101
|
+
if (await Bun.file(join12(dir, "go.mod")).exists())
|
|
2453
2102
|
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2454
|
-
if (await Bun.file(
|
|
2103
|
+
if (await Bun.file(join12(dir, "Cargo.toml")).exists())
|
|
2455
2104
|
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2456
2105
|
if (ruff)
|
|
2457
2106
|
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
2458
2107
|
return fixers;
|
|
2459
2108
|
}
|
|
2109
|
+
var fixParseOptions = { ...fixOptions, only: { ...fixOptions.only, candidates: async () => (await fixers(process21.cwd())).map((fixer) => fixer.name) } };
|
|
2460
2110
|
async function fixers(dir) {
|
|
2461
2111
|
const project = await projectFixers(dir);
|
|
2462
2112
|
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
@@ -2492,14 +2142,14 @@ function printChanged(changed) {
|
|
|
2492
2142
|
if (changed.length > MAX_CHANGED)
|
|
2493
2143
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2494
2144
|
}
|
|
2495
|
-
async function fix(args, cwd =
|
|
2496
|
-
const parsed = parse(args, fixUsage,
|
|
2145
|
+
async function fix(args, cwd = process21.cwd()) {
|
|
2146
|
+
const parsed = parse(args, fixUsage, fixParseOptions, { 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
2147
|
return runFixers(parsed.values, cwd);
|
|
2498
2148
|
}
|
|
2499
2149
|
async function runFixers(values, cwd) {
|
|
2500
2150
|
const parsed = { values };
|
|
2501
2151
|
const settings = placeSettings(values);
|
|
2502
|
-
if (
|
|
2152
|
+
if (process21.env[RUNNING] !== undefined)
|
|
2503
2153
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2504
2154
|
const found = await fixers(cwd);
|
|
2505
2155
|
if (found.length === 0)
|
|
@@ -2533,11 +2183,11 @@ async function runFixers(values, cwd) {
|
|
|
2533
2183
|
break;
|
|
2534
2184
|
if (missing(fixer)) {
|
|
2535
2185
|
if (!json)
|
|
2536
|
-
console.log(`${paint(
|
|
2186
|
+
console.log(`${paint(process21.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2537
2187
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2538
2188
|
continue;
|
|
2539
2189
|
}
|
|
2540
|
-
const logFile =
|
|
2190
|
+
const logFile = join12(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2541
2191
|
const placement = placements.get(fixer);
|
|
2542
2192
|
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2543
2193
|
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
@@ -2567,7 +2217,7 @@ async function runFixers(values, cwd) {
|
|
|
2567
2217
|
|
|
2568
2218
|
// src/narrow.ts
|
|
2569
2219
|
import { existsSync as existsSync6 } from "fs";
|
|
2570
|
-
import { basename as basename3, dirname as dirname5, extname, join as
|
|
2220
|
+
import { basename as basename3, dirname as dirname5, extname, join as join13 } from "path";
|
|
2571
2221
|
var {$: $2 } = globalThis.Bun;
|
|
2572
2222
|
var LINTERS = /^(?:keslint|eslint|oxlint)\b/;
|
|
2573
2223
|
var LINTABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".svelte"]);
|
|
@@ -2579,17 +2229,17 @@ async function changedPaths(dir) {
|
|
|
2579
2229
|
const untracked = await $2`git ls-files -z --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
2580
2230
|
if (tracked.exitCode !== 0 || untracked.exitCode !== 0)
|
|
2581
2231
|
return;
|
|
2582
|
-
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync6(
|
|
2232
|
+
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync6(join13(dir, path)));
|
|
2583
2233
|
}
|
|
2584
2234
|
function siblingTests(path, exists) {
|
|
2585
2235
|
const extension = extname(path);
|
|
2586
2236
|
const name = basename3(path, extension);
|
|
2587
2237
|
const dir = dirname5(path);
|
|
2588
|
-
const folders = [dir,
|
|
2238
|
+
const folders = [dir, join13(dir, "tests"), join13(dir, "..", "tests"), join13(dir, "__tests__")];
|
|
2589
2239
|
const found = new Set;
|
|
2590
2240
|
for (const folder of folders) {
|
|
2591
2241
|
for (const kind of ["test", "spec"]) {
|
|
2592
|
-
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) =>
|
|
2242
|
+
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) => join13(folder, file))) {
|
|
2593
2243
|
if (exists(candidate))
|
|
2594
2244
|
found.add(candidate);
|
|
2595
2245
|
}
|
|
@@ -2613,7 +2263,7 @@ async function narrow2(step, dir, changed) {
|
|
|
2613
2263
|
if (TEST_FILE.test(path)) {
|
|
2614
2264
|
tests.add(path);
|
|
2615
2265
|
} else {
|
|
2616
|
-
for (const test of siblingTests(path, (candidate) => existsSync6(
|
|
2266
|
+
for (const test of siblingTests(path, (candidate) => existsSync6(join13(dir, candidate)))) {
|
|
2617
2267
|
tests.add(test);
|
|
2618
2268
|
}
|
|
2619
2269
|
}
|
|
@@ -2640,7 +2290,7 @@ async function scriptText(dir, name) {
|
|
|
2640
2290
|
}
|
|
2641
2291
|
|
|
2642
2292
|
// src/check.ts
|
|
2643
|
-
var usage2 = `check [--only <steps>] [--changed] [--failed] [--quiet] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2293
|
+
var usage2 = `check [--only <steps>] [--changed] [--failed] [--quiet] [--timeout <duration>] [--slot | --no-slot] [--parallel] [--in <service> | --host] [--list]
|
|
2644
2294
|
check --fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
2645
2295
|
|
|
2646
2296
|
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,10 +2298,12 @@ A folder without steps but with subfolders that have some (api/ and client/) run
|
|
|
2648
2298
|
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
2299
|
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
2300
|
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.
|
|
2301
|
+
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.
|
|
2302
|
+
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
2303
|
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
2304
|
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2653
2305
|
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
|
|
2306
|
+
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.
|
|
2655
2307
|
--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.`;
|
|
2656
2308
|
var EXITS2 = [[0, "every step passed"], [1, "one failed"], [2, "bad usage, no step is found or a step timed out"]];
|
|
2657
2309
|
function slotted(command) {
|
|
@@ -2682,25 +2334,29 @@ function launch(step) {
|
|
|
2682
2334
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2683
2335
|
}
|
|
2684
2336
|
function summaryLine(outcomes) {
|
|
2685
|
-
const colors = paint(
|
|
2337
|
+
const colors = paint(process22.stdout);
|
|
2686
2338
|
const failed = outcomes.filter((outcome) => !outcome.ok).length;
|
|
2687
2339
|
const passed = outcomes.length - failed;
|
|
2688
2340
|
const parts = [colors.green(`${passed} passed`), ...failed === 0 ? [] : [colors.red(`${failed} failed`)], colors.dim(formatDuration(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0)))];
|
|
2689
2341
|
return parts.join(colors.dim(" \xB7 "));
|
|
2690
2342
|
}
|
|
2691
|
-
async function check(args, cwd =
|
|
2343
|
+
async function check(args, cwd = process22.cwd()) {
|
|
2692
2344
|
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
2345
|
const settings = placeSettings(parsed.values);
|
|
2694
2346
|
if (parsed.values.fix === true) {
|
|
2695
|
-
for (const flag of ["changed", "failed", "slot"]) {
|
|
2347
|
+
for (const flag of ["changed", "failed", "slot", "no-slot", "parallel"]) {
|
|
2696
2348
|
if (parsed.values[flag] === true)
|
|
2697
2349
|
fail(`--${flag} does not apply to --fix`);
|
|
2698
2350
|
}
|
|
2699
2351
|
return runFixers(parsed.values, cwd);
|
|
2700
2352
|
}
|
|
2701
2353
|
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2702
|
-
if (parsed.values.slot === true &&
|
|
2354
|
+
if (parsed.values.slot === true && parsed.values["no-slot"] === true)
|
|
2355
|
+
fail("--slot and --no-slot exclude each other");
|
|
2356
|
+
const hasSlot = Bun.which("slot", { PATH: process22.env.PATH ?? "" }) !== null;
|
|
2357
|
+
if (parsed.values.slot === true && !hasSlot)
|
|
2703
2358
|
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2359
|
+
const slotting = parsed.values["no-slot"] !== true && hasSlot;
|
|
2704
2360
|
const projects = await discoverProjects(cwd);
|
|
2705
2361
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
2706
2362
|
if (found.length === 0)
|
|
@@ -2730,25 +2386,47 @@ async function check(args, cwd = process20.cwd()) {
|
|
|
2730
2386
|
const width = Math.max(...steps.map((step) => step.label.length));
|
|
2731
2387
|
const outcomes = [];
|
|
2732
2388
|
const quiet = parsed.values.quiet === true;
|
|
2733
|
-
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
|
|
2389
|
+
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`, process22.stdout);
|
|
2734
2390
|
if (heading !== "")
|
|
2735
2391
|
console.log(heading);
|
|
2392
|
+
const execute = async (step, signals) => {
|
|
2393
|
+
const logFile = join14(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2394
|
+
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2395
|
+
const command = slotting ? slotted(launch(step)) : launch(step);
|
|
2396
|
+
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held: signals }) : await refusedStep(down, logFile);
|
|
2397
|
+
return { step, logFile, outcome };
|
|
2398
|
+
};
|
|
2399
|
+
const report = ({ step, logFile, outcome }) => {
|
|
2400
|
+
if (!json && !(quiet && outcome.ok))
|
|
2401
|
+
printOutcome(step.label, width, `${step.command}${step.note === undefined ? "" : ` (${step.note})`}${step.placement === undefined ? "" : ` (in ${step.placement.service})`}`, logFile, outcome);
|
|
2402
|
+
outcomes.push(outcomeJson(step.label, step.command, logFile, outcome, step.placement?.service));
|
|
2403
|
+
};
|
|
2736
2404
|
try {
|
|
2737
|
-
|
|
2738
|
-
const
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2405
|
+
if (parsed.values.parallel === true) {
|
|
2406
|
+
const children = new Set;
|
|
2407
|
+
const shared = { get signal() {
|
|
2408
|
+
return held.signal;
|
|
2409
|
+
}, forward: (child) => children.add(child), release: held.release };
|
|
2410
|
+
held.forward({ kill: (signal) => {
|
|
2411
|
+
for (const child of children) {
|
|
2412
|
+
child.kill(signal);
|
|
2413
|
+
}
|
|
2414
|
+
} });
|
|
2415
|
+
for (const run of steps.map(async (step) => execute(step, shared)))
|
|
2416
|
+
report(await run);
|
|
2417
|
+
} else {
|
|
2418
|
+
for (const step of steps) {
|
|
2419
|
+
report(await execute(step, held));
|
|
2420
|
+
if (held.signal !== undefined)
|
|
2421
|
+
break;
|
|
2422
|
+
}
|
|
2747
2423
|
}
|
|
2748
2424
|
} finally {
|
|
2749
2425
|
held.release();
|
|
2750
2426
|
}
|
|
2751
|
-
|
|
2427
|
+
const ran = outcomes.map(({ name, ok }) => ({ name, ok }));
|
|
2428
|
+
const kept = (await lastResults(cwd) ?? []).filter(({ name }) => !ran.some((each) => each.name === name));
|
|
2429
|
+
await writeFile3(join14(directory, RESULTS_FILE), JSON.stringify([...kept, ...ran]), { mode: 384 });
|
|
2752
2430
|
if (json)
|
|
2753
2431
|
printJson(outcomes);
|
|
2754
2432
|
else if (heading !== "" || quiet && !outcomes.every((outcome) => outcome.ok))
|
|
@@ -2761,4 +2439,4 @@ async function check(args, cwd = process20.cwd()) {
|
|
|
2761
2439
|
}
|
|
2762
2440
|
|
|
2763
2441
|
// src/cli.ts
|
|
2764
|
-
|
|
2442
|
+
process23.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|