@kaynooo/cli-check 0.18.2 → 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/dist/fix-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/fix-cli.ts
5
- import process20 from "process";
5
+ import process22 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process10 from "process";
8
8
  import { parseArgs } from "util";
@@ -461,24 +461,20 @@ function printJson(value) {
461
461
 
462
462
  // ../kit/src/help.ts
463
463
  import process8 from "process";
464
- var OPTIONAL = /\[[^\]]+\]/g;
464
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
465
465
  var USAGE_PREFIX = /^usage:\s*/i;
466
466
  var FULL_STOP = /\.$/;
467
467
  function usageLine(usage, colors = paint(process8.stdout)) {
468
468
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
469
469
  }
470
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
471
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
470
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
471
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
472
472
  `);
473
473
  }
474
474
  function exitRows(exits, colors = paint(process8.stdout)) {
475
475
  if (exits.length === 0)
476
476
  return [];
477
- const width = Math.max(...exits.map(([code]) => String(code).length));
478
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
479
- }
480
- function replacesRows(replaces, colors = paint(process8.stdout)) {
481
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
477
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
482
478
  }
483
479
  function wantsHelpJson(env = process8.env) {
484
480
  return env.KIT_HELP === "json";
@@ -504,32 +500,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
504
500
  return [];
505
501
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
506
502
  }
503
+ var MAX_INLINE_CHOICES = 24;
507
504
  function optionRows(options, colors = paint(process8.stdout)) {
508
505
  const rows = Object.entries(options).map(([name, option]) => {
509
506
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
510
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
507
+ const choices = option.choices?.join("|");
508
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
509
+ const named = inline ? `<${choices}>` : "<value>";
511
510
  const placeholder = option.optional === undefined ? named : `[${named}]`;
512
511
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
513
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
512
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
513
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
514
514
  });
515
515
  const width = Math.max(0, ...rows.map((row) => row.width));
516
516
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
517
517
  }
518
518
 
519
519
  // ../kit/src/text.ts
520
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
520
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
521
521
  function stripAnsi(text) {
522
522
  return text.replace(ANSI, "");
523
523
  }
524
524
  function distance(a, b) {
525
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
526
- for (const [i, left] of [...a].entries()) {
525
+ const left = [...a];
526
+ const right = [...b];
527
+ let before = [];
528
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
529
+ for (const [i, x] of left.entries()) {
527
530
  const current = [i + 1];
528
- for (const [j, right] of [...b].entries())
529
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
531
+ for (const [j, y] of right.entries()) {
532
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
533
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
534
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
535
+ current.push(cost);
536
+ }
537
+ before = previous;
530
538
  previous = current;
531
539
  }
532
- return previous[b.length] ?? 0;
540
+ return previous[right.length] ?? 0;
533
541
  }
534
542
  function closest(name, names) {
535
543
  const started = names.find((known) => known.startsWith(name));
@@ -608,7 +616,7 @@ class Completing {
608
616
  }
609
617
  var completion = { active: false };
610
618
  var OUTPUT_OPTIONS = {
611
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
619
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
612
620
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
613
621
  };
614
622
  function applyOutput(color, plain, env = process10.env) {
@@ -934,31 +942,109 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
934
942
  // ../kit/src/cli.ts
935
943
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
936
944
  import { dirname as dirname3, join as join6 } from "path";
937
- import process15 from "process";
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
+ }
938
1024
 
939
1025
  // ../kit/src/usage.ts
940
1026
  import { appendFileSync, mkdirSync } from "fs";
941
1027
  import { homedir as homedir4 } from "os";
942
1028
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
943
- import process14 from "process";
1029
+ import process15 from "process";
944
1030
 
945
1031
  // ../kit/src/logs.ts
946
1032
  import { lstatSync, openSync } from "fs";
947
1033
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
948
1034
  import { homedir as homedir3, tmpdir } from "os";
949
1035
  import { join as join4 } from "path";
950
- import process13 from "process";
1036
+ import process14 from "process";
951
1037
  var DAY_MS = 24 * 60 * 60 * 1000;
952
1038
  var CLI_FOLDER = "kaynooo-cli";
953
1039
  function isPrivateDirectory(path) {
954
1040
  try {
955
1041
  const info = lstatSync(path, { throwIfNoEntry: false });
956
- return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1042
+ return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
957
1043
  } catch {
958
1044
  return false;
959
1045
  }
960
1046
  }
961
- async function privateLogDirectory(name, env = process13.env) {
1047
+ async function privateLogDirectory(name, env = process14.env) {
962
1048
  const runtime = env.XDG_RUNTIME_DIR;
963
1049
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
964
1050
  const path = join4(base, name);
@@ -998,14 +1084,14 @@ var usageError;
998
1084
  function noteUsageError(message) {
999
1085
  usageError = message;
1000
1086
  }
1001
- function stateHome(env = process14.env) {
1087
+ function stateHome(env = process15.env) {
1002
1088
  const dir = env.XDG_STATE_HOME;
1003
1089
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1004
1090
  }
1005
- function usagePath(env = process14.env) {
1091
+ function usagePath(env = process15.env) {
1006
1092
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1007
1093
  }
1008
- function usageRecorded(env = process14.env) {
1094
+ function usageRecorded(env = process15.env) {
1009
1095
  const off = env.KAYNOOO_CLI_NO_USAGE;
1010
1096
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1011
1097
  }
@@ -1019,7 +1105,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1019
1105
  usageError = undefined;
1020
1106
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1021
1107
  }
1022
- function recordUsage(entry, env = process14.env) {
1108
+ function recordUsage(entry, env = process15.env) {
1023
1109
  if (!usageRecorded(env))
1024
1110
  return;
1025
1111
  try {
@@ -1035,10 +1121,14 @@ var LEVEL_OPTIONS = {
1035
1121
  ...OUTPUT_OPTIONS,
1036
1122
  help: { type: "boolean", short: "h", description: "show this help" }
1037
1123
  };
1038
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
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
+ };
1039
1129
  function printError(prefix, message, hint, cause) {
1040
- const colors = paint(process15.stderr);
1041
- const styled = takesControlCodes(process15.stderr);
1130
+ const colors = paint(process16.stderr);
1131
+ const styled = takesControlCodes(process16.stderr);
1042
1132
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1043
1133
  const under = (label, text, tint) => text === undefined ? "" : `
1044
1134
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1115,13 +1205,30 @@ async function leafCandidates(run, words) {
1115
1205
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1116
1206
  return values === undefined ? [FILES] : values.map(candidateLine);
1117
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
+ }
1118
1221
  async function printCandidates(found) {
1119
1222
  for (const line of await found)
1120
1223
  console.log(line);
1121
1224
  return 0;
1122
1225
  }
1123
1226
  function packageVersion(entry = Bun.main) {
1124
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1227
+ let resolved = entry;
1228
+ try {
1229
+ resolved = realpathSync2(entry);
1230
+ } catch {}
1231
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1125
1232
  try {
1126
1233
  const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1127
1234
  if (typeof version === "string")
@@ -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.18.2";
1440
+ var version = "0.20.1";
1169
1441
 
1170
1442
  // src/fix.ts
1171
1443
  import { existsSync as existsSync5, statSync as statSync2 } from "fs";
1172
1444
  import { rename, writeFile as writeFile2 } from "fs/promises";
1173
- import { join as join11 } from "path";
1174
- import process19 from "process";
1445
+ import { join as join12 } from "path";
1446
+ import process21 from "process";
1175
1447
 
1176
1448
  // src/changes.ts
1177
1449
  import { stat as stat2 } from "fs/promises";
1178
- import { join as join7 } from "path";
1450
+ import { join as join8 } from "path";
1179
1451
  var {$ } = globalThis.Bun;
1180
1452
  async function dirtyFiles(dir) {
1181
1453
  const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
@@ -1184,7 +1456,7 @@ async function dirtyFiles(dir) {
1184
1456
  const files = new Map;
1185
1457
  for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
1186
1458
  try {
1187
- const { size, mtimeMs } = await stat2(join7(dir, path));
1459
+ const { size, mtimeMs } = await stat2(join8(dir, path));
1188
1460
  files.set(path, `${size}:${mtimeMs}`);
1189
1461
  } catch {
1190
1462
  files.set(path, "");
@@ -1198,9 +1470,9 @@ function changedFiles(before, after) {
1198
1470
 
1199
1471
  // src/compose.ts
1200
1472
  import { existsSync as existsSync4 } from "fs";
1201
- import { homedir as homedir5 } from "os";
1202
- import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
1203
- import process17 from "process";
1473
+ import { homedir as homedir6 } from "os";
1474
+ import { basename, dirname as dirname4, join as join9, relative, resolve as resolve4 } from "path";
1475
+ import process19 from "process";
1204
1476
 
1205
1477
  // ../kit/src/shell.ts
1206
1478
  var SEPARATORS = new Set([`
@@ -1278,7 +1550,7 @@ function toolWords(program) {
1278
1550
  }
1279
1551
  async function readFiles(dir, names) {
1280
1552
  for (const name of names) {
1281
- const handle = Bun.file(join8(dir, name));
1553
+ const handle = Bun.file(join9(dir, name));
1282
1554
  if (await handle.exists())
1283
1555
  return { name, text: await handle.text() };
1284
1556
  }
@@ -1293,7 +1565,7 @@ async function variables(composeDir) {
1293
1565
  if (match !== null && !line.trimStart().startsWith("#"))
1294
1566
  env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
1295
1567
  }
1296
- for (const [key, value] of Object.entries(process17.env)) {
1568
+ for (const [key, value] of Object.entries(process19.env)) {
1297
1569
  if (value !== undefined)
1298
1570
  env[key] = value;
1299
1571
  }
@@ -1313,7 +1585,7 @@ function interpolate(text, env) {
1313
1585
  function bindSource(source, composeDir, env) {
1314
1586
  const path = interpolate(source, env);
1315
1587
  if (path.startsWith("~"))
1316
- return join8(homedir5(), path.slice(1));
1588
+ return join9(homedir6(), path.slice(1));
1317
1589
  if (path.startsWith("/"))
1318
1590
  return resolve4(path);
1319
1591
  return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
@@ -1360,7 +1632,7 @@ async function composeFiles(composeDir, env) {
1360
1632
  for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
1361
1633
  const file = Bun.file(resolve4(composeDir, name));
1362
1634
  if (!await file.exists())
1363
- fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1635
+ fail(`COMPOSE_FILE names ${join9(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1364
1636
  files.push({ name, text: await file.text() });
1365
1637
  }
1366
1638
  return files;
@@ -1382,7 +1654,7 @@ async function readServices(composeDir) {
1382
1654
  try {
1383
1655
  parsed = parseServices(file.text, composeDir, env);
1384
1656
  } catch (error) {
1385
- 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");
1657
+ fail(`cannot read ${join9(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
1386
1658
  }
1387
1659
  for (const [name, extra] of parsed) {
1388
1660
  const known = services.get(name);
@@ -1394,11 +1666,11 @@ async function readServices(composeDir) {
1394
1666
  function climb(dir) {
1395
1667
  const folders = [dir];
1396
1668
  let current = dir;
1397
- while (!existsSync4(join8(current, ".git")) && dirname4(current) !== current) {
1669
+ while (!existsSync4(join9(current, ".git")) && dirname4(current) !== current) {
1398
1670
  current = dirname4(current);
1399
1671
  folders.push(current);
1400
1672
  }
1401
- return existsSync4(join8(current, ".git")) ? folders : [dir];
1673
+ return existsSync4(join9(current, ".git")) ? folders : [dir];
1402
1674
  }
1403
1675
  function containerPath(service, dir) {
1404
1676
  const holding = service.mounts.filter((mount) => {
@@ -1409,7 +1681,7 @@ function containerPath(service, dir) {
1409
1681
  if (deepest === undefined)
1410
1682
  return;
1411
1683
  const inside = relative(deepest.source, dir);
1412
- return inside === "" ? deepest.target : join8(deepest.target, inside);
1684
+ return inside === "" ? deepest.target : join9(deepest.target, inside);
1413
1685
  }
1414
1686
  var noticed = new Set;
1415
1687
  async function place(dir, program, { service, host } = {}) {
@@ -1429,7 +1701,7 @@ async function place(dir, program, { service, host } = {}) {
1429
1701
  fail(`--in ${service}: no compose project mounts ${dir}`);
1430
1702
  return;
1431
1703
  }
1432
- if (Bun.which("docker", { PATH: process17.env.PATH ?? "" }) === null) {
1704
+ if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
1433
1705
  if (service !== undefined)
1434
1706
  fail(`--in ${service}: docker not found`);
1435
1707
  if (!noticed.has(found.composeDir)) {
@@ -1481,7 +1753,7 @@ class Stack {
1481
1753
  }
1482
1754
  static async running(composeDir) {
1483
1755
  try {
1484
- const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process17.env, timeoutMs: PS_TIMEOUT_MS });
1756
+ const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
1485
1757
  if (ran.code !== 0)
1486
1758
  return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
1487
1759
  `).at(-1) ?? `exit ${ran.code}`}`;
@@ -1545,7 +1817,7 @@ ${body}`;
1545
1817
 
1546
1818
  // src/steps.ts
1547
1819
  import { readdir as readdir2 } from "fs/promises";
1548
- import { join as join9 } from "path";
1820
+ import { join as join10 } from "path";
1549
1821
  var STEP_NAMES = ["check", "typecheck", "lint", "test"];
1550
1822
  var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
1551
1823
  var JUSTFILES = ["justfile", "Justfile", ".justfile"];
@@ -1557,7 +1829,7 @@ var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"]
1557
1829
  var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
1558
1830
  async function readFirst(dir, files) {
1559
1831
  for (const file of files) {
1560
- const handle = Bun.file(join9(dir, file));
1832
+ const handle = Bun.file(join10(dir, file));
1561
1833
  if (await handle.exists())
1562
1834
  return { file, text: await handle.text() };
1563
1835
  }
@@ -1565,7 +1837,7 @@ async function readFirst(dir, files) {
1565
1837
  }
1566
1838
  async function read(dir, ...files) {
1567
1839
  for (const file of files) {
1568
- const handle = Bun.file(join9(dir, file));
1840
+ const handle = Bun.file(join10(dir, file));
1569
1841
  if (await handle.exists())
1570
1842
  return handle.text();
1571
1843
  }
@@ -1625,7 +1897,7 @@ async function candidates(dir, bin) {
1625
1897
  }
1626
1898
  async function firstFile(dir, names) {
1627
1899
  for (const name of names) {
1628
- if (await Bun.file(join9(dir, name)).exists())
1900
+ if (await Bun.file(join10(dir, name)).exists())
1629
1901
  return name;
1630
1902
  }
1631
1903
  return;
@@ -1653,9 +1925,9 @@ async function discoverProjects(dir) {
1653
1925
  for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
1654
1926
  if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
1655
1927
  continue;
1656
- const steps = await discover(join9(dir, entry.name));
1928
+ const steps = await discover(join10(dir, entry.name));
1657
1929
  if (steps.length > 0)
1658
- projects.push({ name: entry.name, dir: join9(dir, entry.name), steps });
1930
+ projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
1659
1931
  }
1660
1932
  return projects;
1661
1933
  }
@@ -1678,11 +1950,14 @@ var fixOptions = {
1678
1950
  };
1679
1951
  var options = {
1680
1952
  ...fixOptions,
1953
+ only: { ...fixOptions.only, candidates: () => [...STEP_NAMES] },
1681
1954
  fix: { type: "boolean", short: "f", description: "run the folder's fixers and formatters instead of the steps, as the fix bin does" },
1682
1955
  quiet: { type: "boolean", short: "q", description: "print nothing for a passing step, and nothing at all when every step passes" },
1683
1956
  failed: { type: "boolean", description: "run only the steps that failed in the last run of this folder, read from the run folder" },
1684
1957
  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" },
1685
- slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions (needs the slot bin)" }
1958
+ 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" },
1959
+ "no-slot": { type: "boolean", description: "run the steps at once, without queueing behind the other sessions' slots" },
1960
+ parallel: { type: "boolean", description: "run the steps at the same time, printing each one's output in step order" }
1686
1961
  };
1687
1962
  var COMMA = /\s*,\s*/;
1688
1963
  function pick(steps, only, noun = "step") {
@@ -1699,654 +1974,26 @@ function pick(steps, only, noun = "step") {
1699
1974
 
1700
1975
  // src/run.ts
1701
1976
  import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
1702
- import { basename as basename2, join as join10 } from "path";
1703
- import process18 from "process";
1704
-
1705
- // src/e2e.ts
1706
- var E2E_NOISE = [
1707
- /^(?: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)/,
1708
- /^[\u00B7F\u00D7\u00B0T\u00B1]+$/,
1709
- /^(?: RUN {2}v|\s*[\u276F\u2713\u00D7\u2193] |\s+(?:Test Files|Tests|Start at|Duration|Errors) {2}|\u23AF)/
1710
- ];
1711
- var PLAYWRIGHT_HEADER = /^ {2}\d+\) (?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
1712
- var PLAYWRIGHT_SUMMARY = /^ {2}\d+ (failed|flaky|passed|skipped|did not run|interrupted)\b/;
1713
- var PLAYWRIGHT_ENTRY = /^ {4}(?:\[([^\]]+)\] \u203A )?(.+?):(\d+):(\d+) \u203A (.+?) \u2500+$/;
1714
- var PLAYWRIGHT_RETRY = /^\s+Retry #\d+ \u2500+$/;
1715
- var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
1716
- var EXPECTED = /^\s+Expected: (.*)$/;
1717
- var RECEIVED = /^\s+Received: (.*)$/;
1718
- var VITEST_FAIL = /^ FAIL {2}(?:\|[^|]+\| )?(.+)$/;
1719
- var VITEST_SUITE = /^(.+?) \[ .+ \]$/;
1720
- var VITEST_FRAME = /^\s*\u276F (\S+):(\d+):(\d+)$/;
1721
- function key(project, file, line, column, title) {
1722
- return `${project ?? ""}|${file}:${line}:${column} \u203A ${title}`;
1723
- }
1724
- function firstFrame(block) {
1725
- return block.map((line) => FRAME.exec(line)).find((match) => match !== null && !match[1]?.includes("node_modules")) ?? undefined;
1726
- }
1727
- var collectPlaywright = (lines, used) => {
1728
- const flaky = new Set;
1729
- let section = "";
1730
- for (const [index, line] of lines.entries()) {
1731
- const summary = PLAYWRIGHT_SUMMARY.exec(line);
1732
- const entry = PLAYWRIGHT_ENTRY.exec(line);
1733
- if (summary !== null) {
1734
- section = summary[1] ?? "";
1735
- used.add(index);
1736
- } else if (entry !== null && section !== "") {
1737
- if (section === "flaky")
1738
- flaky.add(key(entry[1], entry[2], entry[3], entry[4], entry[5]));
1739
- used.add(index);
1740
- }
1741
- }
1742
- const errors = [];
1743
- for (let index = 0;index < lines.length; index++) {
1744
- const header = PLAYWRIGHT_HEADER.exec(lines[index] ?? "");
1745
- if (header === null)
1746
- continue;
1747
- let end = index + 1;
1748
- while (end < lines.length && !PLAYWRIGHT_HEADER.test(lines[end] ?? "") && !PLAYWRIGHT_SUMMARY.test(lines[end] ?? ""))
1749
- end++;
1750
- for (let at = index;at < end; at++)
1751
- used.add(at);
1752
- const [, project, file, line, column, title] = header;
1753
- const retry = lines.findIndex((text, at) => at > index && at < end && PLAYWRIGHT_RETRY.test(text));
1754
- const block = lines.slice(index + 1, retry === -1 ? end : retry);
1755
- const frame = firstFrame(block);
1756
- const message = block.find((text) => text.trim() !== "")?.trim() ?? "failed";
1757
- const expected = block.map((text) => EXPECTED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
1758
- const received = block.map((text) => RECEIVED.exec(text)?.[1]?.trim()).find((text) => text !== undefined);
1759
- const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
1760
- index = end - 1;
1761
- if (flaky.has(key(project, file, line, column, title)))
1762
- continue;
1763
- 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}` });
1764
- }
1765
- return errors;
1766
- };
1767
- var collectVitest = (lines, used) => {
1768
- const errors = [];
1769
- for (let index = 0;index < lines.length; index++) {
1770
- const header = VITEST_FAIL.exec(lines[index] ?? "")?.[1];
1771
- if (header === undefined)
1772
- continue;
1773
- let end = index + 1;
1774
- while (end < lines.length && !(lines[end] ?? "").startsWith("\u23AF") && !VITEST_FAIL.test(lines[end] ?? ""))
1775
- end++;
1776
- for (let at = index;at < end; at++)
1777
- used.add(at);
1778
- const block = lines.slice(index + 1, end);
1779
- const frame = block.map((text) => VITEST_FRAME.exec(text)).find((match) => match !== null && !match[1]?.includes("node_modules"));
1780
- const suite = VITEST_SUITE.exec(header)?.[1];
1781
- const [file = "", ...names] = (suite ?? header).split(" > ");
1782
- 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(" > ") } : {} });
1783
- index = end - 1;
1784
- }
1785
- return errors;
1786
- };
1787
-
1788
- // src/php.ts
1789
- var PHP_NOISE = [
1790
- /^(?:PHPUnit \d|ParaTest v|Runtime: |Configuration: |Processes: |Random Seed: |Time: |Tests: |OK(?:,| \()|FAILURES!|ERRORS!|WARNINGS!|No tests executed|--$)/,
1791
- /^[.FEWRISD]+\s+\d+ \/ \d+ \(\d+%\)$/,
1792
- /^ -{3,}(?: -{3,})*\s*$/,
1793
- /^\s*\d+\/\d+ \[[=>\-\u2593\u2591 ]*\]\s+\d+%/,
1794
- /^(?:Note: Using configuration file|\s*\[(?:OK|ERROR)\] )/,
1795
- /^(?: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:)/
1796
- ];
1797
- var MAX_DIFF_LINES = 6;
1798
- var PHPUNIT_HEADER = /^There (?:was|were) \d+ ([a-z ]+?)s?:$/i;
1799
- var PHPUNIT_TRIGGERED = /^\d+ tests? triggered \d+ [\w ]+?s?:$/;
1800
- var PHPUNIT_END = /^(?:--|FAILURES!|ERRORS!|WARNINGS!|OK\b.*|Tests: .*|No tests executed!)$/;
1801
- var PHPUNIT_ITEM = /^\d+\) (.*)$/;
1802
- var PHP_LOCATION = /^([\w./-]+\.php):(\d+)$/;
1803
- var PHPSTAN_FILE = /^ {2}Line {3}(\S.*)$/;
1804
- var PHPSTAN_GENERAL = /^ {2}Error\s*$/;
1805
- var PHPSTAN_MESSAGE = /^ {2}(\S.*)$/;
1806
- var PHPSTAN_ROW = /^ {2}(\d+|-) +(\S.*)$/;
1807
- var PHPSTAN_CONTINUATION = /^ {9}(\S.*)$/;
1808
- var PHPSTAN_IDENTIFIER = /^ {9}\uD83E\uDEAA\s+(\S+)\s*$/;
1809
- var PHPSTAN_TIP = /^ {9}\uD83D\uDCA1/;
1810
- var PHPSTAN_BORDER = /^ -{3,}(?: -{3,})*\s*$/;
1811
- var PHPSTAN_RAW = /^(\S.*?\.(?:php|phtml|twig|neon|inc)):(\d+):(\S.*)$/;
1812
- var PHPSTAN_JSON = /^\{.*"totals"/;
1813
- var CS_FIXER_FILE = /^\s+\d+\) (\S.*?\.php)(?: \((.+)\))?$/;
1814
- var CS_FIXER_DIFF_START = /^\s+-+ begin diff -+$/;
1815
- var CS_FIXER_DIFF_END = /^\s+-+ end diff -+$/;
1816
- function isHeader(line) {
1817
- return PHPUNIT_HEADER.test(line) || PHPUNIT_TRIGGERED.test(line);
1818
- }
1819
- function diffSummary(message) {
1820
- const start = message.findIndex((line) => line === "+++ Actual");
1821
- if (start === -1)
1822
- return "";
1823
- const changed = message.slice(start + 1).filter((line) => line.startsWith("-") || line.startsWith("+")).map((line) => `${line[0]} ${line.slice(1).trim()}`);
1824
- const shown = changed.slice(0, MAX_DIFF_LINES).join(" | ");
1825
- return changed.length === 0 ? "" : ` (${shown}${changed.length > MAX_DIFF_LINES ? " | ..." : ""})`;
1826
- }
1827
- function phpunitError(test, body) {
1828
- const at = body.findIndex((line) => PHP_LOCATION.test(line));
1829
- const location = PHP_LOCATION.exec(body[at] ?? "");
1830
- const message = body.slice(0, at === -1 ? body.length : at).map((line) => line.trimEnd());
1831
- const first = message.find((line) => line.trim() !== "") ?? "failed";
1832
- return { tool: "phpunit", file: location?.[1] ?? "", line: Number(location?.[2] ?? 0), column: 0, severity: "error", message: `${first}${diffSummary(message)}`, test };
1833
- }
1834
- var collectPhpunit = (lines, used) => {
1835
- const errors = [];
1836
- for (let index = 0;index < lines.length; index++) {
1837
- const line = lines[index] ?? "";
1838
- const kind = PHPUNIT_HEADER.exec(line)?.[1];
1839
- if (kind === undefined && !PHPUNIT_TRIGGERED.test(line))
1840
- continue;
1841
- let end = index + 1;
1842
- while (end < lines.length && !PHPUNIT_END.test(lines[end] ?? "") && !isHeader(lines[end] ?? ""))
1843
- end++;
1844
- for (let at = index;at < end; at++)
1845
- used.add(at);
1846
- if (kind === "error" || kind === "failure") {
1847
- const starts = Array.from({ length: end - index - 1 }, (_, at) => index + 1 + at).filter((at) => PHPUNIT_ITEM.test(lines[at] ?? ""));
1848
- for (const [position, start] of starts.entries())
1849
- errors.push(phpunitError(PHPUNIT_ITEM.exec(lines[start] ?? "")?.[1] ?? "", lines.slice(start + 1, starts[position + 1] ?? end)));
1850
- }
1851
- index = end - 1;
1852
- }
1853
- return errors;
1854
- };
1855
- function appendMessage(error, text) {
1856
- error.message = `${error.message} ${text}`;
1857
- }
1858
- function phpstanJson(text) {
1859
- try {
1860
- const report = JSON.parse(text);
1861
- 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 } })));
1862
- return [...fromFiles, ...(report.errors ?? []).map((message) => ({ file: "", line: 0, message }))];
1863
- } catch {
1864
- return;
1865
- }
1866
- }
1867
- var collectPhpstan = (lines, used) => {
1868
- const errors = [];
1869
- let file;
1870
- let current;
1871
- let rows = 0;
1872
- let tip = false;
1873
- let general = false;
1874
- for (const [index, text] of lines.entries()) {
1875
- const line = text.trimEnd();
1876
- if (used.has(index))
1877
- continue;
1878
- if (PHPSTAN_JSON.test(line)) {
1879
- const parsed = phpstanJson(line);
1880
- for (const entry of parsed ?? []) {
1881
- errors.push({ tool: "phpstan", file: entry.file, line: entry.line, column: 0, severity: "error", message: entry.message, ...entry.rule === undefined ? {} : { rule: entry.rule } });
1882
- }
1883
- if (parsed !== undefined)
1884
- used.add(index);
1885
- continue;
1886
- }
1887
- const raw = PHPSTAN_RAW.exec(line);
1888
- if (raw !== null) {
1889
- errors.push({ tool: "phpstan", file: raw[1] ?? "", line: Number(raw[2]), column: 0, severity: "error", message: raw[3] ?? "" });
1890
- used.add(index);
1891
- continue;
1892
- }
1893
- const header = PHPSTAN_FILE.exec(line);
1894
- if (header !== null || PHPSTAN_GENERAL.test(line)) {
1895
- file = header?.[1] ?? "";
1896
- general = header === null;
1897
- current = undefined;
1898
- rows = 0;
1899
- used.add(index);
1900
- continue;
1901
- }
1902
- if (file === undefined)
1903
- continue;
1904
- const message = PHPSTAN_MESSAGE.exec(line)?.[1];
1905
- if (general && message !== undefined && !PHPSTAN_BORDER.test(line)) {
1906
- errors.push({ tool: "phpstan", file: "", line: 0, column: 0, severity: "error", message });
1907
- rows++;
1908
- used.add(index);
1909
- continue;
1910
- }
1911
- const row = PHPSTAN_ROW.exec(line);
1912
- const identifier = PHPSTAN_IDENTIFIER.exec(line)?.[1];
1913
- const continuation = PHPSTAN_CONTINUATION.exec(line)?.[1];
1914
- if (PHPSTAN_BORDER.test(line) && rows > 0) {
1915
- file = undefined;
1916
- general = false;
1917
- current = undefined;
1918
- } else if (row !== null) {
1919
- current = { tool: "phpstan", file, line: row[1] === "-" ? 0 : Number(row[1]), column: 0, severity: "error", message: row[2] ?? "" };
1920
- errors.push(current);
1921
- rows++;
1922
- tip = false;
1923
- used.add(index);
1924
- } else if (identifier !== undefined && current !== undefined) {
1925
- current.rule = identifier;
1926
- used.add(index);
1927
- } else if (PHPSTAN_TIP.test(line)) {
1928
- tip = true;
1929
- used.add(index);
1930
- } else if (continuation !== undefined && current !== undefined) {
1931
- if (!tip)
1932
- appendMessage(current, continuation);
1933
- used.add(index);
1934
- }
1935
- }
1936
- return errors;
1937
- };
1938
- var collectCsFixer = (lines, used) => {
1939
- const errors = [];
1940
- for (let index = 0;index < lines.length; index++) {
1941
- const match = CS_FIXER_FILE.exec(lines[index] ?? "");
1942
- if (match === null)
1943
- continue;
1944
- 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" });
1945
- used.add(index);
1946
- if (!CS_FIXER_DIFF_START.test(lines[index + 1] ?? ""))
1947
- continue;
1948
- const end = lines.findIndex((text, at) => at > index && CS_FIXER_DIFF_END.test(text));
1949
- for (let at = index + 1;at <= (end === -1 ? index + 1 : end); at++)
1950
- used.add(at);
1951
- index = end === -1 ? index + 1 : end;
1952
- }
1953
- return errors;
1954
- };
1955
-
1956
- // src/output.ts
1957
- var BASH_ECHO = /^\$ /;
1958
- var DURATION2 = / \[[\d.]+m?s\]$/;
1959
- var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
1960
- var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
1961
- var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
1962
- var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
1963
- var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
1964
- var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
1965
- var TSC_ERROR = /\berror TS\d+/;
1966
- var TSC_CONTINUATION = /^\s{2,}\S/;
1967
- var TSC_FRAME = /^\s*[~^|]/;
1968
- var TSC_SUMMARY = /^Found \d+ errors?/;
1969
- var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
1970
- var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
1971
- var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
1972
- var PHPSTAN_NOISE = /^\s*\[OK\]/;
1973
- var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
1974
- var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
1975
- var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
1976
- var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
1977
- var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
1978
- var MAX_TESTS = 10;
1979
- var MAX_LINES = 100;
1980
- var TAIL = 30;
1981
- var bunTest = (lines) => {
1982
- const seen = new Set;
1983
- const blocks = [];
1984
- for (const [index, line] of lines.entries()) {
1985
- const name = line.replace(DURATION2, "");
1986
- if (!line.startsWith("(fail) ") || seen.has(name))
1987
- continue;
1988
- seen.add(name);
1989
- if (blocks.length < MAX_TESTS)
1990
- blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
1991
- `).trim());
1992
- }
1993
- if (blocks.length === 0)
1994
- return;
1995
- if (seen.size > MAX_TESTS)
1996
- blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
1997
- return [...blocks.join(`
1998
-
1999
- `).split(`
2000
- `), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
2001
- };
2002
- var bunCheck = (lines) => {
2003
- const text = lines.join(`
2004
- `);
2005
- const blocks = text.match(BUN_CHECK_BLOCK);
2006
- if (blocks === null)
2007
- return;
2008
- const errors = blocks.map((block) => {
2009
- const { file, line, column, code, message } = bunCheckFields(block);
2010
- return `${file}:${line}:${column} ${code}: ${message}`;
2011
- });
2012
- return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
2013
- };
2014
- function bunCheckFields(block) {
2015
- const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
2016
- `)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
2017
- return {
2018
- file: attributes.file ?? "",
2019
- line: attributes.line ?? "",
2020
- column: attributes.column ?? "",
2021
- code: attributes.code ?? "",
2022
- message: block.replace(BUN_CHECK_SOURCE, "").split(`
2023
- `).slice(1, -1).join(`
2024
- `).trim()
2025
- };
2026
- }
2027
- var tsc = (lines) => {
2028
- const kept = [];
2029
- let inError = false;
2030
- for (const line of lines) {
2031
- if (TSC_ERROR.test(line)) {
2032
- inError = true;
2033
- kept.push(line);
2034
- } else if (TSC_SUMMARY.test(line)) {
2035
- inError = false;
2036
- kept.push(line);
2037
- } else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
2038
- kept.push(line);
2039
- } else {
2040
- inError = false;
2041
- }
2042
- }
2043
- return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
2044
- };
2045
- var eslint = (lines) => {
2046
- const kept = [];
2047
- let file = "";
2048
- let shown = "";
2049
- for (const line of lines) {
2050
- if (ESLINT_PROBLEM.test(line)) {
2051
- if (file !== shown) {
2052
- kept.push(file);
2053
- shown = file;
2054
- }
2055
- kept.push(line);
2056
- } else if (ESLINT_SUMMARY.test(line)) {
2057
- kept.push(line);
2058
- } else if (line.trim() !== "") {
2059
- file = line;
2060
- }
2061
- }
2062
- return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
2063
- };
2064
- var phpstan = (lines) => {
2065
- const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
2066
- return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
2067
- };
2068
- var php = (lines) => {
2069
- const start = lines.findIndex((line) => PHP_FAILURES.test(line));
2070
- return start === -1 ? undefined : lines.slice(start);
2071
- };
2072
- var vitest = (lines) => {
2073
- const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
2074
- return start === -1 ? undefined : lines.slice(start);
2075
- };
2076
- var playwright = (lines) => {
2077
- const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
2078
- return start === -1 ? undefined : lines.slice(start);
2079
- };
2080
- var phpCsFixer = (lines) => {
2081
- const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
2082
- return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
2083
- };
2084
- var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
2085
- function squeeze(lines) {
2086
- const out = [];
2087
- for (const line of lines.map((text) => text.trimEnd())) {
2088
- if (line !== "" || out.at(-1) !== "")
2089
- out.push(line);
2090
- }
2091
- while (out.at(-1) === "")
2092
- out.pop();
2093
- return out;
2094
- }
2095
- function failureExcerpt(output) {
2096
- const lines = stripAnsi(output).split(`
2097
- `);
2098
- if (BASH_ECHO.test(lines[0] ?? ""))
2099
- lines.shift();
2100
- const parsed = PARSERS.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
2101
- const shown = squeeze(parsed ?? lines.slice(-TAIL));
2102
- return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
2103
- `) : shown.join(`
2104
- `);
2105
- }
2106
- var TSC_PLAIN_ERROR = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
2107
- var TSC_PRETTY_ERROR = /^(.+?):(\d+):(\d+) - error (TS\d+): (.*)$/;
2108
- var TSC_SOURCE_LINE = /^\d+ /;
2109
- var ESLINT_FIELDS = /^ +(\d+):(\d+) +(error|warning) +(\S.*)$/;
2110
- var ESLINT_RULE = / {2,}(\S+)$/;
2111
- var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
2112
- var BUN_TEST_RECEIVED = /^Received: (.*)$/;
2113
- var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
2114
- var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
2115
- var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
2116
- var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
2117
- var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
2118
- var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
2119
- 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)/;
2120
- var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
2121
- var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
2122
- var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
2123
- var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
2124
- var PYTEST_E_LINE = /^E {3}(.*)$/;
2125
- var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
2126
- var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
2127
- var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
2128
- var PYTEST_FRAME = /^in \S/;
2129
- var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
2130
- var PYTEST_EXCEPTION_END = /[\s:]/;
2131
- var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
2132
- 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)/;
2133
- function isNoise(line) {
2134
- 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));
2135
- }
2136
- var collectBunCheck = (lines, used) => {
2137
- const errors = [];
2138
- for (let index = 0;index < lines.length; index++) {
2139
- if (!(lines[index] ?? "").startsWith("<error file="))
2140
- continue;
2141
- const end = lines.findIndex((line, at) => at >= index && line === "</error>");
2142
- if (end === -1)
2143
- break;
2144
- const { file, line, column, code, message } = bunCheckFields(lines.slice(index, end + 1).join(`
2145
- `));
2146
- errors.push({ tool: "bun check", file, line: Number(line), column: Number(column), rule: code, severity: "error", message: message.replaceAll(/\s*\n\s*/g, " ") });
2147
- for (let at = index;at <= end; at++)
2148
- used.add(at);
2149
- index = end;
2150
- }
2151
- return errors;
2152
- };
2153
- var collectBunTest = (lines, used) => {
2154
- const errors = [];
2155
- const seen = new Set;
2156
- for (const [index, line] of lines.entries()) {
2157
- if (!line.startsWith("(fail) "))
2158
- continue;
2159
- used.add(index);
2160
- const test = line.slice("(fail) ".length).replace(DURATION2, "");
2161
- if (seen.has(test))
2162
- continue;
2163
- seen.add(test);
2164
- const start = lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1;
2165
- const block = lines.slice(start, index);
2166
- const failure = block.findIndex((text) => text.startsWith("error:"));
2167
- for (let at = start;at < index; at++)
2168
- used.add(at);
2169
- const frame = block.slice(Math.max(failure, 0)).map((text) => BUN_TEST_FRAME.exec(text)).find((match) => match !== null);
2170
- const header = lines.slice(0, index).findLast((text) => BUN_TEST_FILE.test(text));
2171
- const expected = block.map((text) => BUN_TEST_EXPECTED.exec(text)?.[1]).find((text) => text !== undefined);
2172
- const received = block.map((text) => BUN_TEST_RECEIVED.exec(text)?.[1]).find((text) => text !== undefined);
2173
- const reason = failure === -1 ? "failed" : (block[failure] ?? "").slice("error:".length).trim();
2174
- const values = expected === undefined || received === undefined ? "" : ` (expected ${expected}, received ${received})`;
2175
- errors.push({
2176
- tool: "bun test",
2177
- file: frame?.[1] ?? header?.replace(":", "") ?? "",
2178
- line: Number(frame?.[2] ?? 0),
2179
- column: Number(frame?.[3] ?? 0),
2180
- severity: "error",
2181
- message: `${reason}${values}`,
2182
- test
2183
- });
2184
- }
2185
- return errors;
2186
- };
2187
- var collectTsc = (lines, used) => {
2188
- const errors = [];
2189
- let current;
2190
- let pretty = false;
2191
- for (const [index, line] of lines.entries()) {
2192
- if (used.has(index))
2193
- continue;
2194
- const plain = TSC_PLAIN_ERROR.exec(line);
2195
- const match = plain ?? TSC_PRETTY_ERROR.exec(line);
2196
- if (match !== null) {
2197
- current = { tool: "tsc", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" };
2198
- pretty = plain === null;
2199
- errors.push(current);
2200
- used.add(index);
2201
- } else if (current !== undefined && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
2202
- current.message += ` ${line.trim()}`;
2203
- used.add(index);
2204
- } else if (current !== undefined && pretty && (TSC_FRAME.test(line) || TSC_SOURCE_LINE.test(line))) {
2205
- used.add(index);
2206
- } else if (!(pretty && line.trim() === "")) {
2207
- current = undefined;
2208
- }
2209
- }
2210
- return errors;
2211
- };
2212
- var collectEslint = (lines, used) => {
2213
- const errors = [];
2214
- let file;
2215
- for (const [index, line] of lines.entries()) {
2216
- if (used.has(index))
2217
- continue;
2218
- const match = ESLINT_PROBLEM.test(line) ? ESLINT_FIELDS.exec(line) : null;
2219
- if (match !== null && file !== undefined) {
2220
- const text = match[4] ?? "";
2221
- const rule = ESLINT_RULE.exec(text);
2222
- 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) });
2223
- used.add(index);
2224
- used.add(file);
2225
- } else if (!isNoise(line)) {
2226
- file = index;
2227
- }
2228
- }
2229
- return errors;
2230
- };
2231
- var collectGo = (lines, used) => {
2232
- const errors = [];
2233
- for (const [index, line] of lines.entries()) {
2234
- const match = used.has(index) ? null : GO_ERROR.exec(line);
2235
- if (match === null)
2236
- continue;
2237
- errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
2238
- used.add(index);
2239
- }
2240
- return errors;
2241
- };
2242
- var collectArrowed = (lines, used) => {
2243
- const errors = [];
2244
- for (const [index, line] of lines.entries()) {
2245
- const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
2246
- const header = arrow === null ? null : lines[index - 1] ?? "";
2247
- const cargo = header === null ? null : CARGO_HEADER.exec(header);
2248
- const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
2249
- if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
2250
- continue;
2251
- const [, file, row, column] = arrow;
2252
- const fields = { file: file ?? "", line: Number(row), column: Number(column) };
2253
- 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] ?? "" });
2254
- used.add(index - 1);
2255
- used.add(index);
2256
- for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
2257
- if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
2258
- break;
2259
- used.add(frame);
2260
- }
2261
- }
2262
- return errors;
2263
- };
2264
- var collectRuff = (lines, used) => {
2265
- const errors = [];
2266
- for (const [index, line] of lines.entries()) {
2267
- const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
2268
- if (match === null)
2269
- continue;
2270
- errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
2271
- used.add(index);
2272
- }
2273
- return errors;
2274
- };
2275
- var collectPytest = (lines, used) => {
2276
- const errors = [];
2277
- const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
2278
- const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
2279
- if (start === -1)
2280
- return errors;
2281
- const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
2282
- const stop = end === -1 ? lines.length : end;
2283
- let message = [];
2284
- let frame;
2285
- for (let index = start;index < stop; index++) {
2286
- const line = lines[index] ?? "";
2287
- const failure = PYTEST_E_LINE.exec(line);
2288
- if (failure !== null) {
2289
- message.push((failure[1] ?? "").trim());
2290
- } else {
2291
- if (frame !== undefined && message.length > 0) {
2292
- errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
2293
- frame = undefined;
2294
- }
2295
- const location = PYTEST_LOCATION.exec(line);
2296
- if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
2297
- frame = { file: location[1] ?? "", line: Number(location[2]) };
2298
- } else if (location !== null) {
2299
- const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
2300
- const first = message[0] ?? "";
2301
- const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
2302
- errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
2303
- }
2304
- if (PYTEST_SECTION.test(line))
2305
- frame = undefined;
2306
- if (line.trim() !== "")
2307
- message = [];
2308
- }
2309
- used.add(index);
2310
- }
2311
- if (frame !== undefined && message.length > 0)
2312
- errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
2313
- for (let index = stop;index < lines.length; index++) {
2314
- if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
2315
- used.add(index);
2316
- }
2317
- return errors;
2318
- };
2319
- var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
2320
- function parseErrors(output) {
2321
- const lines = stripAnsi(output).split(`
2322
- `);
2323
- if (BASH_ECHO.test(lines[0] ?? ""))
2324
- lines.shift();
2325
- const used = new Set;
2326
- const errors = COLLECTORS.flatMap((collect) => collect(lines, used));
2327
- const unrecognised = lines.filter((line, index) => !used.has(index) && !isNoise(line)).length;
2328
- return { errors, unrecognised };
2329
- }
2330
-
2331
- // src/run.ts
1977
+ import { basename as basename2, join as join11 } from "path";
1978
+ import process20 from "process";
2332
1979
  var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
2333
1980
  var RESULTS_FILE = "results.json";
2334
1981
  var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
2335
1982
  async function logDirectory(cwd) {
2336
1983
  const root = await privateLogDirectory("check");
2337
1984
  await sweepLogs(root, LOG_MAX_AGE_MS);
2338
- const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process18.pid}`);
1985
+ const path = join11(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
2339
1986
  await mkdir2(path, { mode: 448 });
2340
1987
  return path;
2341
1988
  }
2342
- async function lastFailed(cwd) {
1989
+ async function lastResults(cwd) {
2343
1990
  const root = await privateLogDirectory("check");
2344
1991
  const prefix = runPrefix(cwd);
2345
1992
  let latest;
2346
1993
  for (const name of await readdir3(root)) {
2347
1994
  if (!name.startsWith(prefix))
2348
1995
  continue;
2349
- const file = join10(root, name, RESULTS_FILE);
1996
+ const file = join11(root, name, RESULTS_FILE);
2350
1997
  try {
2351
1998
  const { mtimeMs } = await stat3(file);
2352
1999
  if (latest === undefined || mtimeMs > latest.time)
@@ -2355,13 +2002,15 @@ async function lastFailed(cwd) {
2355
2002
  }
2356
2003
  if (latest === undefined)
2357
2004
  return;
2358
- const results = JSON.parse(await Bun.file(latest.file).text());
2359
- return results.filter((result) => !result.ok).map((result) => result.name);
2005
+ return JSON.parse(await Bun.file(latest.file).text());
2006
+ }
2007
+ async function lastFailed(cwd) {
2008
+ return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
2360
2009
  }
2361
2010
  async function saveLog(output) {
2362
2011
  const root = await privateLogDirectory("errs");
2363
2012
  await sweepLogs(root);
2364
- const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process18.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2013
+ const path = join11(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2365
2014
  await writeFile(path, output, { mode: 384, flag: "wx" });
2366
2015
  return path;
2367
2016
  }
@@ -2369,7 +2018,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
2369
2018
  const started = Date.now();
2370
2019
  const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
2371
2020
  cwd,
2372
- env: { ...process18.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2021
+ env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2373
2022
  ...timeoutMs === undefined ? {} : { timeoutMs },
2374
2023
  ...held === undefined ? {} : { onStart: (child) => held.forward(child) }
2375
2024
  });
@@ -2385,8 +2034,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
2385
2034
  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) } };
2386
2035
  }
2387
2036
  function printOutcome(name, width, command, logFile, outcome) {
2388
- const colors = paint(process18.stdout);
2389
- const path = role("path", process18.stdout);
2037
+ const colors = paint(process20.stdout);
2038
+ const path = role("path", process20.stdout);
2390
2039
  const took = colors.dim(formatDuration(outcome.ms));
2391
2040
  if (outcome.ok) {
2392
2041
  console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
@@ -2409,15 +2058,15 @@ It looks at the folder itself only, so each package of a monorepo gets its own r
2409
2058
  A script or php-cs-fixer runs inside the docker compose service that bind-mounts the folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the fixer fails naming it. The formatters run on the host. --in picks the service, --host forces the host.
2410
2059
  Prints one line per fixer, what a failing one said, then the files the run changed. Each fixer's full output is saved to the file whose path ends its line.
2411
2060
  A fixer still running after --timeout is ended with everything it started, but not what it started inside a container.
2412
- Exits 0 when every fixer ran or was skipped for a missing binary, 1 when one failed, 2 on bad usage, when nothing applies or when a fixer timed out.
2413
2061
  --json prints {fixers: [{name, command, in?, ok, ms, log, failed?} or {name, command, skipped}], changed} once every fixer ran, changed null outside a git repository.`;
2062
+ var EXITS = [[0, "every fixer ran or was skipped for a missing binary"], [1, "one failed"], [2, "bad usage, nothing applies or a fixer timed out"]];
2414
2063
  var RUNNING = "KAYNOOO_CLI_FIX";
2415
2064
  var JUSTFILES2 = ["justfile", "Justfile", ".justfile"];
2416
2065
  var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
2417
2066
  var RUFF_SECTION = /^\[tool\.ruff/m;
2418
2067
  var MAX_CHANGED = 30;
2419
2068
  async function replaceFile(path, content) {
2420
- const temporary = `${path}.${process19.pid}.tmp`;
2069
+ const temporary = `${path}.${process21.pid}.tmp`;
2421
2070
  await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
2422
2071
  await rename(temporary, path);
2423
2072
  }
@@ -2436,9 +2085,9 @@ async function toolFixers(dir) {
2436
2085
  const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
2437
2086
  if (makefile !== undefined) {
2438
2087
  fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
2439
- const path = join11(cwd, makefile);
2088
+ const path = join12(cwd, makefile);
2440
2089
  const current = await Bun.file(path).text();
2441
- const { content, targets } = declarePhony(current, (name) => existsSync5(join11(cwd, name)));
2090
+ const { content, targets } = declarePhony(current, (name) => existsSync5(join12(cwd, name)));
2442
2091
  if (content !== current)
2443
2092
  await replaceFile(path, content);
2444
2093
  return `.PHONY: ${targets.join(" ")}`;
@@ -2446,14 +2095,15 @@ async function toolFixers(dir) {
2446
2095
  }
2447
2096
  if (justfile !== undefined)
2448
2097
  fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
2449
- if (await Bun.file(join11(dir, "go.mod")).exists())
2098
+ if (await Bun.file(join12(dir, "go.mod")).exists())
2450
2099
  fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
2451
- if (await Bun.file(join11(dir, "Cargo.toml")).exists())
2100
+ if (await Bun.file(join12(dir, "Cargo.toml")).exists())
2452
2101
  fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
2453
2102
  if (ruff)
2454
2103
  fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
2455
2104
  return fixers;
2456
2105
  }
2106
+ var fixParseOptions = { ...fixOptions, only: { ...fixOptions.only, candidates: async () => (await fixers(process21.cwd())).map((fixer) => fixer.name) } };
2457
2107
  async function fixers(dir) {
2458
2108
  const project = await projectFixers(dir);
2459
2109
  const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
@@ -2489,14 +2139,14 @@ function printChanged(changed) {
2489
2139
  if (changed.length > MAX_CHANGED)
2490
2140
  console.log(` and ${changed.length - MAX_CHANGED} more`);
2491
2141
  }
2492
- async function fix(args, cwd = process19.cwd()) {
2493
- const parsed = parse(args, fixUsage, fixOptions, { replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
2142
+ async function fix(args, cwd = process21.cwd()) {
2143
+ 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"]] });
2494
2144
  return runFixers(parsed.values, cwd);
2495
2145
  }
2496
2146
  async function runFixers(values, cwd) {
2497
2147
  const parsed = { values };
2498
2148
  const settings = placeSettings(values);
2499
- if (process19.env[RUNNING] !== undefined)
2149
+ if (process21.env[RUNNING] !== undefined)
2500
2150
  fail("a fixer called fix again, which would recurse: give its script another command");
2501
2151
  const found = await fixers(cwd);
2502
2152
  if (found.length === 0)
@@ -2530,11 +2180,11 @@ async function runFixers(values, cwd) {
2530
2180
  break;
2531
2181
  if (missing(fixer)) {
2532
2182
  if (!json)
2533
- console.log(`${paint(process19.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
2183
+ console.log(`${paint(process21.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
2534
2184
  ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
2535
2185
  continue;
2536
2186
  }
2537
- const logFile = join11(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
2187
+ const logFile = join12(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
2538
2188
  const placement = placements.get(fixer);
2539
2189
  const down = placement === undefined ? undefined : await stack.problem(placement);
2540
2190
  const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
@@ -2563,4 +2213,4 @@ async function runFixers(values, cwd) {
2563
2213
  }
2564
2214
 
2565
2215
  // src/fix-cli.ts
2566
- process20.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });
2216
+ process22.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });