@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/errs-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/errs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process22 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -461,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,17 +1437,17 @@ 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/errs.ts
|
|
1171
1443
|
import { relative as relative2 } from "path";
|
|
1172
|
-
import
|
|
1444
|
+
import process21 from "process";
|
|
1173
1445
|
|
|
1174
1446
|
// src/compose.ts
|
|
1175
1447
|
import { existsSync as existsSync4 } from "fs";
|
|
1176
|
-
import { homedir as
|
|
1177
|
-
import { basename, dirname as dirname4, join as
|
|
1178
|
-
import
|
|
1448
|
+
import { homedir as homedir6 } from "os";
|
|
1449
|
+
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
|
|
1450
|
+
import process19 from "process";
|
|
1179
1451
|
|
|
1180
1452
|
// ../kit/src/shell.ts
|
|
1181
1453
|
var SEPARATORS = new Set([`
|
|
@@ -1253,7 +1525,7 @@ function toolWords(program) {
|
|
|
1253
1525
|
}
|
|
1254
1526
|
async function readFiles(dir, names) {
|
|
1255
1527
|
for (const name of names) {
|
|
1256
|
-
const handle = Bun.file(
|
|
1528
|
+
const handle = Bun.file(join8(dir, name));
|
|
1257
1529
|
if (await handle.exists())
|
|
1258
1530
|
return { name, text: await handle.text() };
|
|
1259
1531
|
}
|
|
@@ -1268,7 +1540,7 @@ async function variables(composeDir) {
|
|
|
1268
1540
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1269
1541
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1270
1542
|
}
|
|
1271
|
-
for (const [key, value] of Object.entries(
|
|
1543
|
+
for (const [key, value] of Object.entries(process19.env)) {
|
|
1272
1544
|
if (value !== undefined)
|
|
1273
1545
|
env[key] = value;
|
|
1274
1546
|
}
|
|
@@ -1288,7 +1560,7 @@ function interpolate(text, env) {
|
|
|
1288
1560
|
function bindSource(source, composeDir, env) {
|
|
1289
1561
|
const path = interpolate(source, env);
|
|
1290
1562
|
if (path.startsWith("~"))
|
|
1291
|
-
return
|
|
1563
|
+
return join8(homedir6(), path.slice(1));
|
|
1292
1564
|
if (path.startsWith("/"))
|
|
1293
1565
|
return resolve4(path);
|
|
1294
1566
|
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
@@ -1335,7 +1607,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1335
1607
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1336
1608
|
const file = Bun.file(resolve4(composeDir, name));
|
|
1337
1609
|
if (!await file.exists())
|
|
1338
|
-
fail(`COMPOSE_FILE names ${
|
|
1610
|
+
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1339
1611
|
files.push({ name, text: await file.text() });
|
|
1340
1612
|
}
|
|
1341
1613
|
return files;
|
|
@@ -1357,7 +1629,7 @@ async function readServices(composeDir) {
|
|
|
1357
1629
|
try {
|
|
1358
1630
|
parsed = parseServices(file.text, composeDir, env);
|
|
1359
1631
|
} catch (error) {
|
|
1360
|
-
fail(`cannot read ${
|
|
1632
|
+
fail(`cannot read ${join8(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1361
1633
|
}
|
|
1362
1634
|
for (const [name, extra] of parsed) {
|
|
1363
1635
|
const known = services.get(name);
|
|
@@ -1369,11 +1641,11 @@ async function readServices(composeDir) {
|
|
|
1369
1641
|
function climb(dir) {
|
|
1370
1642
|
const folders = [dir];
|
|
1371
1643
|
let current = dir;
|
|
1372
|
-
while (!existsSync4(
|
|
1644
|
+
while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1373
1645
|
current = dirname4(current);
|
|
1374
1646
|
folders.push(current);
|
|
1375
1647
|
}
|
|
1376
|
-
return existsSync4(
|
|
1648
|
+
return existsSync4(join8(current, ".git")) ? folders : [dir];
|
|
1377
1649
|
}
|
|
1378
1650
|
function containerPath(service, dir) {
|
|
1379
1651
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1384,7 +1656,7 @@ function containerPath(service, dir) {
|
|
|
1384
1656
|
if (deepest === undefined)
|
|
1385
1657
|
return;
|
|
1386
1658
|
const inside = relative(deepest.source, dir);
|
|
1387
|
-
return inside === "" ? deepest.target :
|
|
1659
|
+
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1388
1660
|
}
|
|
1389
1661
|
var noticed = new Set;
|
|
1390
1662
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1404,7 +1676,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1404
1676
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1405
1677
|
return;
|
|
1406
1678
|
}
|
|
1407
|
-
if (Bun.which("docker", { PATH:
|
|
1679
|
+
if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
|
|
1408
1680
|
if (service !== undefined)
|
|
1409
1681
|
fail(`--in ${service}: docker not found`);
|
|
1410
1682
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1456,7 +1728,7 @@ class Stack {
|
|
|
1456
1728
|
}
|
|
1457
1729
|
static async running(composeDir) {
|
|
1458
1730
|
try {
|
|
1459
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1731
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1460
1732
|
if (ran.code !== 0)
|
|
1461
1733
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1462
1734
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1739,155 +2011,7 @@ var collectCsFixer = (lines, used) => {
|
|
|
1739
2011
|
};
|
|
1740
2012
|
|
|
1741
2013
|
// src/output.ts
|
|
1742
|
-
var BASH_ECHO =
|
|
1743
|
-
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1744
|
-
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1745
|
-
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1746
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1747
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1748
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1749
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1750
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1751
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1752
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1753
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1754
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1755
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1756
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1757
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1758
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1759
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1760
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1761
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1762
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1763
|
-
var MAX_TESTS = 10;
|
|
1764
|
-
var MAX_LINES = 100;
|
|
1765
|
-
var TAIL = 30;
|
|
1766
|
-
var bunTest = (lines) => {
|
|
1767
|
-
const seen = new Set;
|
|
1768
|
-
const blocks = [];
|
|
1769
|
-
for (const [index, line] of lines.entries()) {
|
|
1770
|
-
const name = line.replace(DURATION2, "");
|
|
1771
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1772
|
-
continue;
|
|
1773
|
-
seen.add(name);
|
|
1774
|
-
if (blocks.length < MAX_TESTS)
|
|
1775
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1776
|
-
`).trim());
|
|
1777
|
-
}
|
|
1778
|
-
if (blocks.length === 0)
|
|
1779
|
-
return;
|
|
1780
|
-
if (seen.size > MAX_TESTS)
|
|
1781
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1782
|
-
return [...blocks.join(`
|
|
1783
|
-
|
|
1784
|
-
`).split(`
|
|
1785
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1786
|
-
};
|
|
1787
|
-
var bunCheck = (lines) => {
|
|
1788
|
-
const text = lines.join(`
|
|
1789
|
-
`);
|
|
1790
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1791
|
-
if (blocks === null)
|
|
1792
|
-
return;
|
|
1793
|
-
const errors = blocks.map((block) => {
|
|
1794
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1795
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1796
|
-
});
|
|
1797
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1798
|
-
};
|
|
1799
|
-
function bunCheckFields(block) {
|
|
1800
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1801
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1802
|
-
return {
|
|
1803
|
-
file: attributes.file ?? "",
|
|
1804
|
-
line: attributes.line ?? "",
|
|
1805
|
-
column: attributes.column ?? "",
|
|
1806
|
-
code: attributes.code ?? "",
|
|
1807
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1808
|
-
`).slice(1, -1).join(`
|
|
1809
|
-
`).trim()
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
var tsc = (lines) => {
|
|
1813
|
-
const kept = [];
|
|
1814
|
-
let inError = false;
|
|
1815
|
-
for (const line of lines) {
|
|
1816
|
-
if (TSC_ERROR.test(line)) {
|
|
1817
|
-
inError = true;
|
|
1818
|
-
kept.push(line);
|
|
1819
|
-
} else if (TSC_SUMMARY.test(line)) {
|
|
1820
|
-
inError = false;
|
|
1821
|
-
kept.push(line);
|
|
1822
|
-
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1823
|
-
kept.push(line);
|
|
1824
|
-
} else {
|
|
1825
|
-
inError = false;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1829
|
-
};
|
|
1830
|
-
var eslint = (lines) => {
|
|
1831
|
-
const kept = [];
|
|
1832
|
-
let file = "";
|
|
1833
|
-
let shown = "";
|
|
1834
|
-
for (const line of lines) {
|
|
1835
|
-
if (ESLINT_PROBLEM.test(line)) {
|
|
1836
|
-
if (file !== shown) {
|
|
1837
|
-
kept.push(file);
|
|
1838
|
-
shown = file;
|
|
1839
|
-
}
|
|
1840
|
-
kept.push(line);
|
|
1841
|
-
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1842
|
-
kept.push(line);
|
|
1843
|
-
} else if (line.trim() !== "") {
|
|
1844
|
-
file = line;
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1848
|
-
};
|
|
1849
|
-
var phpstan = (lines) => {
|
|
1850
|
-
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1851
|
-
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1852
|
-
};
|
|
1853
|
-
var php = (lines) => {
|
|
1854
|
-
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1855
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1856
|
-
};
|
|
1857
|
-
var vitest = (lines) => {
|
|
1858
|
-
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1859
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1860
|
-
};
|
|
1861
|
-
var playwright = (lines) => {
|
|
1862
|
-
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1863
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1864
|
-
};
|
|
1865
|
-
var phpCsFixer = (lines) => {
|
|
1866
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1867
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1868
|
-
};
|
|
1869
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1870
|
-
function squeeze(lines) {
|
|
1871
|
-
const out = [];
|
|
1872
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1873
|
-
if (line !== "" || out.at(-1) !== "")
|
|
1874
|
-
out.push(line);
|
|
1875
|
-
}
|
|
1876
|
-
while (out.at(-1) === "")
|
|
1877
|
-
out.pop();
|
|
1878
|
-
return out;
|
|
1879
|
-
}
|
|
1880
|
-
function failureExcerpt(output) {
|
|
1881
|
-
const lines = stripAnsi(output).split(`
|
|
1882
|
-
`);
|
|
1883
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1884
|
-
lines.shift();
|
|
1885
|
-
const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1886
|
-
const shown = squeeze(parsed ?? lines.slice(-TAIL));
|
|
1887
|
-
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1888
|
-
`) : shown.join(`
|
|
1889
|
-
`);
|
|
1890
|
-
}
|
|
2014
|
+
var { BASH_ECHO: BASH_ECHO2, DURATION: DURATION3, BOUNDARY: BOUNDARY2, BUN_TEST_SUMMARY: BUN_TEST_SUMMARY2, BUN_CHECK_SUMMARY: BUN_CHECK_SUMMARY2, TSC_CONTINUATION: TSC_CONTINUATION2, TSC_FRAME: TSC_FRAME2, TSC_SUMMARY: TSC_SUMMARY2, ESLINT_PROBLEM: ESLINT_PROBLEM2, ESLINT_SUMMARY: ESLINT_SUMMARY2 } = LOG_PATTERNS;
|
|
1891
2015
|
var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
1892
2016
|
var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
|
|
1893
2017
|
var TSC_SOURCE_LINE = /^\d+ /;
|
|
@@ -1898,9 +2022,13 @@ var BUN_TEST_RECEIVED = /^Received: (.*)$/;
|
|
|
1898
2022
|
var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
1899
2023
|
var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
|
|
1900
2024
|
var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
|
|
2025
|
+
var GO_LINTER = /^(.*\S)\s+\(([a-z][\w-]*)\)$/;
|
|
1901
2026
|
var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
|
|
1902
2027
|
var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
|
|
1903
|
-
var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
|
|
2028
|
+
var CARGO_HEADER = /^(error|warning)(?:\[([\w-]+)\])?: (.*)$/;
|
|
2029
|
+
var CONTINUATION = /^\s+\S/;
|
|
2030
|
+
var MAX_CONTINUATION = 20;
|
|
2031
|
+
var KAY_SUMMARY = /^(?:\d+ errors?(?:, \d+ warnings?)?|\d+ warnings?)(?:, failing under --deny-warnings)?$|^checked with /;
|
|
1904
2032
|
var CARGO_NOISE = /^(?:\s+(?:Compiling|Finished|Checking|Fresh|Running|Blocking) |error: (?:aborting due to|could not compile)|warning: .* generated \d+ warnings?|Some errors have detailed explanations|For more information about (?:this|an) error|To learn more, run the command again)/;
|
|
1905
2033
|
var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
|
|
1906
2034
|
var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
|
|
@@ -1914,9 +2042,11 @@ var PYTEST_FRAME = /^in \S/;
|
|
|
1914
2042
|
var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
|
|
1915
2043
|
var PYTEST_EXCEPTION_END = /[\s:]/;
|
|
1916
2044
|
var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
|
|
2045
|
+
var GENERIC_LINE = /^(\S[^:]*):(\d+)(?::(\d+))?: (?:fatal )?(error|warning|note): (.*)$/;
|
|
2046
|
+
var GENERIC_RULE = /\s(?:\[([\w-]+)\]|\(([a-z][\w-]*)\))$/;
|
|
1917
2047
|
var NOISE = /^(?:bun test v|Errors {2}Files$|Ran \d+ tests?|note: |\s*\d+ expect\(\) calls|\s+\d+\s+\S+:\d+$|\s*\d+ errors? and \d+ warnings? potentially fixable)/;
|
|
1918
2048
|
function isNoise(line) {
|
|
1919
|
-
return line.trim() === "" || [NOISE,
|
|
2049
|
+
return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY2, BUN_CHECK_SUMMARY2, TSC_SUMMARY2, ESLINT_SUMMARY2, BOUNDARY2, BASH_ECHO2, GO_NOISE, CARGO_NOISE, KAY_SUMMARY, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
|
|
1920
2050
|
}
|
|
1921
2051
|
var collectBunCheck = (lines, used) => {
|
|
1922
2052
|
const errors = [];
|
|
@@ -1942,11 +2072,11 @@ var collectBunTest = (lines, used) => {
|
|
|
1942
2072
|
if (!line.startsWith("(fail) "))
|
|
1943
2073
|
continue;
|
|
1944
2074
|
used.add(index);
|
|
1945
|
-
const test = line.slice("(fail) ".length).replace(
|
|
2075
|
+
const test = line.slice("(fail) ".length).replace(DURATION3, "");
|
|
1946
2076
|
if (seen.has(test))
|
|
1947
2077
|
continue;
|
|
1948
2078
|
seen.add(test);
|
|
1949
|
-
const start = lines.findLastIndex((text, at) => at < index &&
|
|
2079
|
+
const start = lines.findLastIndex((text, at) => at < index && BOUNDARY2.test(text)) + 1;
|
|
1950
2080
|
const block = lines.slice(start, index);
|
|
1951
2081
|
const failure = block.findIndex((text) => text.startsWith("error:"));
|
|
1952
2082
|
for (let at = start;at < index; at++)
|
|
@@ -1983,10 +2113,10 @@ var collectTsc = (lines, used) => {
|
|
|
1983
2113
|
pretty = plain === null;
|
|
1984
2114
|
errors.push(current);
|
|
1985
2115
|
used.add(index);
|
|
1986
|
-
} else if (current !== undefined &&
|
|
2116
|
+
} else if (current !== undefined && TSC_CONTINUATION2.test(line) && !TSC_FRAME2.test(line)) {
|
|
1987
2117
|
current.message += ` ${line.trim()}`;
|
|
1988
2118
|
used.add(index);
|
|
1989
|
-
} else if (current !== undefined && pretty && (
|
|
2119
|
+
} else if (current !== undefined && pretty && (TSC_FRAME2.test(line) || TSC_SOURCE_LINE.test(line))) {
|
|
1990
2120
|
used.add(index);
|
|
1991
2121
|
} else if (!(pretty && line.trim() === "")) {
|
|
1992
2122
|
current = undefined;
|
|
@@ -2000,7 +2130,7 @@ var collectEslint = (lines, used) => {
|
|
|
2000
2130
|
for (const [index, line] of lines.entries()) {
|
|
2001
2131
|
if (used.has(index))
|
|
2002
2132
|
continue;
|
|
2003
|
-
const match =
|
|
2133
|
+
const match = ESLINT_PROBLEM2.test(line) ? ESLINT_FIELDS.exec(line) : null;
|
|
2004
2134
|
if (match !== null && file !== undefined) {
|
|
2005
2135
|
const text = match[4] ?? "";
|
|
2006
2136
|
const rule = ESLINT_RULE.exec(text);
|
|
@@ -2019,25 +2149,33 @@ var collectGo = (lines, used) => {
|
|
|
2019
2149
|
const match = used.has(index) ? null : GO_ERROR.exec(line);
|
|
2020
2150
|
if (match === null)
|
|
2021
2151
|
continue;
|
|
2022
|
-
|
|
2152
|
+
const linter = GO_LINTER.exec(match[4] ?? "");
|
|
2153
|
+
errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), ...linter === null ? {} : { rule: linter[2] }, severity: "error", message: linter === null ? match[4] ?? "" : linter[1] ?? "" });
|
|
2023
2154
|
used.add(index);
|
|
2024
2155
|
}
|
|
2025
2156
|
return errors;
|
|
2026
2157
|
};
|
|
2158
|
+
function headerAbove(lines, arrow, used) {
|
|
2159
|
+
let at = arrow - 1;
|
|
2160
|
+
while (at > 0 && arrow - at <= MAX_CONTINUATION && !used.has(at) && CONTINUATION.test(lines[at] ?? "") && !ARROW.test(lines[at] ?? ""))
|
|
2161
|
+
at--;
|
|
2162
|
+
return at;
|
|
2163
|
+
}
|
|
2027
2164
|
var collectArrowed = (lines, used) => {
|
|
2028
2165
|
const errors = [];
|
|
2029
2166
|
for (const [index, line] of lines.entries()) {
|
|
2030
2167
|
const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
|
|
2031
|
-
const
|
|
2168
|
+
const at = arrow === null ? -1 : headerAbove(lines, index, used);
|
|
2169
|
+
const header = at === -1 ? null : lines[at] ?? "";
|
|
2032
2170
|
const cargo = header === null ? null : CARGO_HEADER.exec(header);
|
|
2033
2171
|
const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
|
|
2034
|
-
if (arrow === null || cargo === null && ruff === null || used.has(
|
|
2172
|
+
if (arrow === null || cargo === null && ruff === null || used.has(at))
|
|
2035
2173
|
continue;
|
|
2036
|
-
const [, file, row, column] = arrow;
|
|
2037
|
-
const fields = { file
|
|
2038
|
-
errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
|
|
2039
|
-
|
|
2040
|
-
|
|
2174
|
+
const [, file = "", row, column] = arrow;
|
|
2175
|
+
const fields = { file, line: Number(row), column: Number(column) };
|
|
2176
|
+
errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: file.endsWith(".rs") ? "cargo" : "kay check", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
|
|
2177
|
+
for (let taken = at;taken <= index; taken++)
|
|
2178
|
+
used.add(taken);
|
|
2041
2179
|
for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
|
|
2042
2180
|
if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
|
|
2043
2181
|
break;
|
|
@@ -2101,40 +2239,63 @@ var collectPytest = (lines, used) => {
|
|
|
2101
2239
|
}
|
|
2102
2240
|
return errors;
|
|
2103
2241
|
};
|
|
2104
|
-
var
|
|
2242
|
+
var collectGeneric = (lines, used) => {
|
|
2243
|
+
const errors = [];
|
|
2244
|
+
for (const [index, line] of lines.entries()) {
|
|
2245
|
+
const match = used.has(index) ? null : GENERIC_LINE.exec(line);
|
|
2246
|
+
if (match === null)
|
|
2247
|
+
continue;
|
|
2248
|
+
used.add(index);
|
|
2249
|
+
if (match[4] === "note")
|
|
2250
|
+
continue;
|
|
2251
|
+
const text = match[5] ?? "";
|
|
2252
|
+
const ruled = GENERIC_RULE.exec(text);
|
|
2253
|
+
const rule = ruled?.[1] ?? ruled?.[2];
|
|
2254
|
+
errors.push({ tool: "generic", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), rule, severity: match[4] === "warning" ? "warning" : "error", message: ruled === null ? text : text.slice(0, ruled.index).trimEnd() });
|
|
2255
|
+
}
|
|
2256
|
+
return errors;
|
|
2257
|
+
};
|
|
2258
|
+
var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint, collectGeneric];
|
|
2105
2259
|
function parseErrors(output) {
|
|
2106
2260
|
const lines = stripAnsi(output).split(`
|
|
2107
2261
|
`);
|
|
2108
|
-
if (
|
|
2262
|
+
if (BASH_ECHO2.test(lines[0] ?? ""))
|
|
2109
2263
|
lines.shift();
|
|
2110
2264
|
const used = new Set;
|
|
2111
|
-
const
|
|
2265
|
+
const seen = new Set;
|
|
2266
|
+
const errors = COLLECTORS.flatMap((collect) => collect(lines, used)).filter((error) => {
|
|
2267
|
+
const key = [error.file, error.line, error.column, error.message, error.test].join("\x00");
|
|
2268
|
+
if (seen.has(key))
|
|
2269
|
+
return false;
|
|
2270
|
+
seen.add(key);
|
|
2271
|
+
return true;
|
|
2272
|
+
});
|
|
2112
2273
|
const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
|
|
2113
2274
|
return { errors, unrecognised };
|
|
2114
2275
|
}
|
|
2115
2276
|
|
|
2116
2277
|
// src/run.ts
|
|
2117
2278
|
import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
|
|
2118
|
-
import { basename as basename2, join as
|
|
2119
|
-
import
|
|
2279
|
+
import { basename as basename2, join as join9 } from "path";
|
|
2280
|
+
import process20 from "process";
|
|
2120
2281
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2121
2282
|
var RESULTS_FILE = "results.json";
|
|
2122
2283
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2123
2284
|
async function logDirectory(cwd) {
|
|
2124
2285
|
const root = await privateLogDirectory("check");
|
|
2125
2286
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2126
|
-
const path =
|
|
2287
|
+
const path = join9(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
|
|
2127
2288
|
await mkdir2(path, { mode: 448 });
|
|
2128
2289
|
return path;
|
|
2129
2290
|
}
|
|
2130
|
-
async function
|
|
2291
|
+
async function lastResults(cwd) {
|
|
2131
2292
|
const root = await privateLogDirectory("check");
|
|
2132
2293
|
const prefix = runPrefix(cwd);
|
|
2133
2294
|
let latest;
|
|
2134
2295
|
for (const name of await readdir2(root)) {
|
|
2135
2296
|
if (!name.startsWith(prefix))
|
|
2136
2297
|
continue;
|
|
2137
|
-
const file =
|
|
2298
|
+
const file = join9(root, name, RESULTS_FILE);
|
|
2138
2299
|
try {
|
|
2139
2300
|
const { mtimeMs } = await stat2(file);
|
|
2140
2301
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2143,13 +2304,15 @@ async function lastFailed(cwd) {
|
|
|
2143
2304
|
}
|
|
2144
2305
|
if (latest === undefined)
|
|
2145
2306
|
return;
|
|
2146
|
-
|
|
2147
|
-
|
|
2307
|
+
return JSON.parse(await Bun.file(latest.file).text());
|
|
2308
|
+
}
|
|
2309
|
+
async function lastFailed(cwd) {
|
|
2310
|
+
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
2148
2311
|
}
|
|
2149
2312
|
async function saveLog(output) {
|
|
2150
2313
|
const root = await privateLogDirectory("errs");
|
|
2151
2314
|
await sweepLogs(root);
|
|
2152
|
-
const path =
|
|
2315
|
+
const path = join9(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2153
2316
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2154
2317
|
return path;
|
|
2155
2318
|
}
|
|
@@ -2157,7 +2320,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2157
2320
|
const started = Date.now();
|
|
2158
2321
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2159
2322
|
cwd,
|
|
2160
|
-
env: { ...
|
|
2323
|
+
env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2161
2324
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2162
2325
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2163
2326
|
});
|
|
@@ -2173,8 +2336,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2173
2336
|
return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
|
|
2174
2337
|
}
|
|
2175
2338
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2176
|
-
const colors = paint(
|
|
2177
|
-
const path = role("path",
|
|
2339
|
+
const colors = paint(process20.stdout);
|
|
2340
|
+
const path = role("path", process20.stdout);
|
|
2178
2341
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2179
2342
|
if (outcome.ok) {
|
|
2180
2343
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2194,10 +2357,10 @@ var usage2 = `errs [options] [log]
|
|
|
2194
2357
|
errs [options] -- <command> [args...]
|
|
2195
2358
|
errs --in <service> | --host -- <command> [args...]
|
|
2196
2359
|
|
|
2197
|
-
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json), php-cs-fixer, go (build, vet), cargo (rustc), ruff (concise and full) or pytest log, read from the file given, from stdin (no argument or -), or from the output of the command run after --.
|
|
2360
|
+
Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, kay check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json), php-cs-fixer, go (build, vet), cargo (rustc), ruff (concise and full) or pytest log, or any line shaped \`file:line[:col]: error|warning: message\` (mypy, gcc, clang, \`shellcheck -f gcc\`, golangci-lint), read from the file given, from stdin (no argument or -), or from the output of the command run after --.
|
|
2198
2361
|
The lines no format recognised are counted on stderr, never dropped silently, and a command's full output is saved to a log file whose path is printed with that count.
|
|
2199
2362
|
A command runs inside the docker compose service that bind-mounts the current folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path, with its output read here; a service that is down is never started, the call fails naming it. --in picks the service, --host forces the host.
|
|
2200
|
-
--json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer, go, cargo, ruff, pytest.`;
|
|
2363
|
+
--json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, kay check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer, go, cargo, ruff, pytest, generic. An error repeated with the same file, position and message is printed once.`;
|
|
2201
2364
|
var EXITS = [[0, "no error was found and the command, if any, passed"], [1, "errors were found or the command failed"], [2, "a usage error"]];
|
|
2202
2365
|
var options = {
|
|
2203
2366
|
...placeOptions,
|
|
@@ -2231,7 +2394,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2231
2394
|
const held = holdSignals();
|
|
2232
2395
|
let ran;
|
|
2233
2396
|
try {
|
|
2234
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...
|
|
2397
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process21.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
2235
2398
|
} catch (error) {
|
|
2236
2399
|
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2237
2400
|
} finally {
|
|
@@ -2239,7 +2402,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2239
2402
|
}
|
|
2240
2403
|
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
2241
2404
|
}
|
|
2242
|
-
async function errs(args, cwd =
|
|
2405
|
+
async function errs(args, cwd = process21.cwd()) {
|
|
2243
2406
|
const first = args[0];
|
|
2244
2407
|
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2245
2408
|
const parsed = parse(bare ? [] : args, usage2, options, { exits: EXITS, rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
@@ -2263,4 +2426,4 @@ ${usage2}`);
|
|
|
2263
2426
|
}
|
|
2264
2427
|
|
|
2265
2428
|
// src/errs-cli.ts
|
|
2266
|
-
|
|
2429
|
+
process22.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|