@kaynooo/cli-check 0.18.1 → 0.18.3
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 +1 -1
- package/dist/cli.js +94 -68
- package/dist/errs-cli.js +82 -58
- package/dist/fix-cli.js +87 -61
- package/dist/j-cli.js +104 -78
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ check --json # [{name, command, in?, ok, ms, log, failed?}] once every step
|
|
|
19
19
|
|
|
20
20
|
## Steps
|
|
21
21
|
|
|
22
|
-
`check`, `typecheck`, `lint` and `test`, run in that order, from the first source that has each one:
|
|
22
|
+
`check`, `typecheck`, `lint` and `test`, run in that order, from the first source that has each one, but for a Justfile or Makefile `check`, which wins over a script of that name: a task runner's check is the repo's whole validation and usually wraps the script, as `check: bun run check -p tsconfig.json` does.
|
|
23
23
|
|
|
24
24
|
| Source | Command |
|
|
25
25
|
| --- | --- |
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -467,18 +467,14 @@ var FULL_STOP = /\.$/;
|
|
|
467
467
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
468
468
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
469
469
|
}
|
|
470
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
471
|
-
return [usageLine(usage, colors),
|
|
470
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
471
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
472
472
|
`);
|
|
473
473
|
}
|
|
474
474
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
475
475
|
if (exits.length === 0)
|
|
476
476
|
return [];
|
|
477
|
-
|
|
478
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
479
|
-
}
|
|
480
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
481
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
477
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
482
478
|
}
|
|
483
479
|
function wantsHelpJson(env = process8.env) {
|
|
484
480
|
return env.KIT_HELP === "json";
|
|
@@ -780,9 +776,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
780
776
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
781
777
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
782
778
|
}
|
|
779
|
+
// ../kit/src/argv.ts
|
|
780
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
781
|
+
import { resolve as resolve3 } from "path";
|
|
782
|
+
import process11 from "process";
|
|
783
|
+
function commandLine() {
|
|
784
|
+
try {
|
|
785
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
786
|
+
} catch {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function realPath(word) {
|
|
791
|
+
try {
|
|
792
|
+
return realpathSync(resolve3(word));
|
|
793
|
+
} catch {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
798
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
799
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
800
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
801
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
802
|
+
}
|
|
783
803
|
// ../kit/src/process.ts
|
|
784
804
|
import { constants } from "os";
|
|
785
|
-
import
|
|
805
|
+
import process12 from "process";
|
|
786
806
|
var KILL_GRACE_MS = 2000;
|
|
787
807
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
788
808
|
function exitCodeOf(code, signal) {
|
|
@@ -804,7 +824,7 @@ function holdSignals(cleanup) {
|
|
|
804
824
|
},
|
|
805
825
|
release: () => {
|
|
806
826
|
for (const signal of SIGNALS)
|
|
807
|
-
|
|
827
|
+
process12.off(signal, onSignal);
|
|
808
828
|
}
|
|
809
829
|
};
|
|
810
830
|
function onSignal(signal) {
|
|
@@ -817,10 +837,10 @@ function holdSignals(cleanup) {
|
|
|
817
837
|
return;
|
|
818
838
|
held.release();
|
|
819
839
|
cleanup(signal);
|
|
820
|
-
|
|
840
|
+
process12.kill(process12.pid, signal);
|
|
821
841
|
}
|
|
822
842
|
for (const signal of SIGNALS)
|
|
823
|
-
|
|
843
|
+
process12.on(signal, onSignal);
|
|
824
844
|
return held;
|
|
825
845
|
}
|
|
826
846
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -834,7 +854,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
834
854
|
return;
|
|
835
855
|
try {
|
|
836
856
|
if (grouped)
|
|
837
|
-
|
|
857
|
+
process12.kill(-proc.pid, killing);
|
|
838
858
|
else
|
|
839
859
|
proc.kill(killing);
|
|
840
860
|
} catch {}
|
|
@@ -908,33 +928,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
908
928
|
var RESET_STYLE = `${ESC}[0m`;
|
|
909
929
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
910
930
|
// ../kit/src/cli.ts
|
|
911
|
-
import { readFileSync as
|
|
931
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
912
932
|
import { dirname as dirname3, join as join6 } from "path";
|
|
913
|
-
import
|
|
933
|
+
import process15 from "process";
|
|
914
934
|
|
|
915
935
|
// ../kit/src/usage.ts
|
|
916
936
|
import { appendFileSync, mkdirSync } from "fs";
|
|
917
937
|
import { homedir as homedir4 } from "os";
|
|
918
938
|
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
919
|
-
import
|
|
939
|
+
import process14 from "process";
|
|
920
940
|
|
|
921
941
|
// ../kit/src/logs.ts
|
|
922
942
|
import { lstatSync, openSync } from "fs";
|
|
923
943
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
924
944
|
import { homedir as homedir3, tmpdir } from "os";
|
|
925
945
|
import { join as join4 } from "path";
|
|
926
|
-
import
|
|
946
|
+
import process13 from "process";
|
|
927
947
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
928
948
|
var CLI_FOLDER = "kaynooo-cli";
|
|
929
949
|
function isPrivateDirectory(path) {
|
|
930
950
|
try {
|
|
931
951
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
932
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
952
|
+
return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
933
953
|
} catch {
|
|
934
954
|
return false;
|
|
935
955
|
}
|
|
936
956
|
}
|
|
937
|
-
async function privateLogDirectory(name, env =
|
|
957
|
+
async function privateLogDirectory(name, env = process13.env) {
|
|
938
958
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
939
959
|
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
940
960
|
const path = join4(base, name);
|
|
@@ -974,14 +994,14 @@ var usageError;
|
|
|
974
994
|
function noteUsageError(message) {
|
|
975
995
|
usageError = message;
|
|
976
996
|
}
|
|
977
|
-
function stateHome(env =
|
|
997
|
+
function stateHome(env = process14.env) {
|
|
978
998
|
const dir = env.XDG_STATE_HOME;
|
|
979
999
|
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
980
1000
|
}
|
|
981
|
-
function usagePath(env =
|
|
1001
|
+
function usagePath(env = process14.env) {
|
|
982
1002
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
983
1003
|
}
|
|
984
|
-
function usageRecorded(env =
|
|
1004
|
+
function usageRecorded(env = process14.env) {
|
|
985
1005
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
986
1006
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
987
1007
|
}
|
|
@@ -995,7 +1015,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
995
1015
|
usageError = undefined;
|
|
996
1016
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
997
1017
|
}
|
|
998
|
-
function recordUsage(entry, env =
|
|
1018
|
+
function recordUsage(entry, env = process14.env) {
|
|
999
1019
|
if (!usageRecorded(env))
|
|
1000
1020
|
return;
|
|
1001
1021
|
try {
|
|
@@ -1013,8 +1033,8 @@ var LEVEL_OPTIONS = {
|
|
|
1013
1033
|
};
|
|
1014
1034
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1015
1035
|
function printError(prefix, message, hint, cause) {
|
|
1016
|
-
const colors = paint(
|
|
1017
|
-
const styled = takesControlCodes(
|
|
1036
|
+
const colors = paint(process15.stderr);
|
|
1037
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1018
1038
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1019
1039
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1020
1040
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1058,24 +1078,24 @@ function candidateLine(candidate) {
|
|
|
1058
1078
|
}
|
|
1059
1079
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1060
1080
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1061
|
-
|
|
1081
|
+
const typed = [];
|
|
1062
1082
|
let at = 0;
|
|
1063
1083
|
while (at < before.length) {
|
|
1064
1084
|
const word = before[at];
|
|
1065
1085
|
if (word === "--") {
|
|
1066
|
-
|
|
1086
|
+
typed.push(...before.slice(at + 1));
|
|
1067
1087
|
break;
|
|
1068
1088
|
}
|
|
1069
1089
|
if (!word.startsWith("-"))
|
|
1070
|
-
|
|
1090
|
+
typed.push(word);
|
|
1071
1091
|
else if (takesValue(word))
|
|
1072
1092
|
at++;
|
|
1073
1093
|
at++;
|
|
1074
1094
|
}
|
|
1075
1095
|
const last = positionals.at(-1);
|
|
1076
|
-
if (
|
|
1077
|
-
return positionals[
|
|
1078
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1096
|
+
if (typed.length < positionals.length)
|
|
1097
|
+
return { name: positionals[typed.length], typed };
|
|
1098
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1079
1099
|
}
|
|
1080
1100
|
async function leafCandidates(run, words) {
|
|
1081
1101
|
const completing = await completingOf(run);
|
|
@@ -1083,12 +1103,12 @@ async function leafCandidates(run, words) {
|
|
|
1083
1103
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1084
1104
|
const flag = words.at(-2);
|
|
1085
1105
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1106
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1086
1107
|
if (option?.type === "string") {
|
|
1087
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1108
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1088
1109
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1089
1110
|
}
|
|
1090
|
-
const
|
|
1091
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1111
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1092
1112
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1093
1113
|
}
|
|
1094
1114
|
async function printCandidates(found) {
|
|
@@ -1097,9 +1117,13 @@ async function printCandidates(found) {
|
|
|
1097
1117
|
return 0;
|
|
1098
1118
|
}
|
|
1099
1119
|
function packageVersion(entry = Bun.main) {
|
|
1100
|
-
|
|
1120
|
+
let resolved = entry;
|
|
1121
|
+
try {
|
|
1122
|
+
resolved = realpathSync2(entry);
|
|
1123
|
+
} catch {}
|
|
1124
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1101
1125
|
try {
|
|
1102
|
-
const { version } = JSON.parse(
|
|
1126
|
+
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
1103
1127
|
if (typeof version === "string")
|
|
1104
1128
|
return version;
|
|
1105
1129
|
} catch {}
|
|
@@ -1107,7 +1131,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1107
1131
|
return "0.0.0";
|
|
1108
1132
|
}
|
|
1109
1133
|
}
|
|
1110
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1134
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1111
1135
|
if (argv[0] === COMPLETE)
|
|
1112
1136
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1113
1137
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1141,12 +1165,12 @@ var {Glob } = globalThis.Bun;
|
|
|
1141
1165
|
var SESSION_FILES = new Glob("*.json");
|
|
1142
1166
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1143
1167
|
// package.json
|
|
1144
|
-
var version = "0.18.
|
|
1168
|
+
var version = "0.18.3";
|
|
1145
1169
|
|
|
1146
1170
|
// src/check.ts
|
|
1147
1171
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
1148
1172
|
import { basename as basename4, join as join13 } from "path";
|
|
1149
|
-
import
|
|
1173
|
+
import process20 from "process";
|
|
1150
1174
|
|
|
1151
1175
|
// ../kit/src/shell.ts
|
|
1152
1176
|
var SEPARATORS = new Set([`
|
|
@@ -1198,8 +1222,8 @@ function shellQuote(word) {
|
|
|
1198
1222
|
// src/compose.ts
|
|
1199
1223
|
import { existsSync as existsSync4 } from "fs";
|
|
1200
1224
|
import { homedir as homedir5 } from "os";
|
|
1201
|
-
import { basename, dirname as dirname4, join as join7, relative, resolve as
|
|
1202
|
-
import
|
|
1225
|
+
import { basename, dirname as dirname4, join as join7, relative, resolve as resolve4 } from "path";
|
|
1226
|
+
import process17 from "process";
|
|
1203
1227
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1204
1228
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1205
1229
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1243,7 +1267,7 @@ async function variables(composeDir) {
|
|
|
1243
1267
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1244
1268
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1245
1269
|
}
|
|
1246
|
-
for (const [key, value] of Object.entries(
|
|
1270
|
+
for (const [key, value] of Object.entries(process17.env)) {
|
|
1247
1271
|
if (value !== undefined)
|
|
1248
1272
|
env[key] = value;
|
|
1249
1273
|
}
|
|
@@ -1265,8 +1289,8 @@ function bindSource(source, composeDir, env) {
|
|
|
1265
1289
|
if (path.startsWith("~"))
|
|
1266
1290
|
return join7(homedir5(), path.slice(1));
|
|
1267
1291
|
if (path.startsWith("/"))
|
|
1268
|
-
return
|
|
1269
|
-
return path.startsWith(".") ?
|
|
1292
|
+
return resolve4(path);
|
|
1293
|
+
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
1270
1294
|
}
|
|
1271
1295
|
function mountsOf(volumes, composeDir, env) {
|
|
1272
1296
|
if (!Array.isArray(volumes))
|
|
@@ -1308,7 +1332,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1308
1332
|
const files = [];
|
|
1309
1333
|
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1310
1334
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1311
|
-
const file = Bun.file(
|
|
1335
|
+
const file = Bun.file(resolve4(composeDir, name));
|
|
1312
1336
|
if (!await file.exists())
|
|
1313
1337
|
fail(`COMPOSE_FILE names ${join7(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1314
1338
|
files.push({ name, text: await file.text() });
|
|
@@ -1379,7 +1403,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1379
1403
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1380
1404
|
return;
|
|
1381
1405
|
}
|
|
1382
|
-
if (Bun.which("docker", { PATH:
|
|
1406
|
+
if (Bun.which("docker", { PATH: process17.env.PATH ?? "" }) === null) {
|
|
1383
1407
|
if (service !== undefined)
|
|
1384
1408
|
fail(`--in ${service}: docker not found`);
|
|
1385
1409
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1431,7 +1455,7 @@ class Stack {
|
|
|
1431
1455
|
}
|
|
1432
1456
|
static async running(composeDir) {
|
|
1433
1457
|
try {
|
|
1434
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1458
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process17.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1435
1459
|
if (ran.code !== 0)
|
|
1436
1460
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1437
1461
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1466,7 +1490,7 @@ function placeSettings(values) {
|
|
|
1466
1490
|
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1467
1491
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1468
1492
|
import { join as join11 } from "path";
|
|
1469
|
-
import
|
|
1493
|
+
import process19 from "process";
|
|
1470
1494
|
|
|
1471
1495
|
// src/changes.ts
|
|
1472
1496
|
import { stat as stat2 } from "fs/promises";
|
|
@@ -1528,6 +1552,7 @@ import { join as join9 } from "path";
|
|
|
1528
1552
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1529
1553
|
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1530
1554
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1555
|
+
var TASK_RUNNERS = new Set(["Justfile", "Makefile"]);
|
|
1531
1556
|
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1532
1557
|
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1533
1558
|
var JUST_TIMEOUT_MS = 1e4;
|
|
@@ -1639,8 +1664,9 @@ async function discoverProjects(dir) {
|
|
|
1639
1664
|
}
|
|
1640
1665
|
async function discover(dir) {
|
|
1641
1666
|
const found = await candidates(dir, "check");
|
|
1667
|
+
const runnerCheck = found.find((candidate) => candidate.name === "check" && TASK_RUNNERS.has(candidate.source));
|
|
1642
1668
|
return STEP_NAMES.flatMap((name) => {
|
|
1643
|
-
const step = found.find((candidate) => candidate.name === name);
|
|
1669
|
+
const step = name === "check" && runnerCheck !== undefined ? runnerCheck : found.find((candidate) => candidate.name === name);
|
|
1644
1670
|
return step === undefined ? [] : [step];
|
|
1645
1671
|
});
|
|
1646
1672
|
}
|
|
@@ -1677,7 +1703,7 @@ function pick(steps, only, noun = "step") {
|
|
|
1677
1703
|
// src/run.ts
|
|
1678
1704
|
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1679
1705
|
import { basename as basename2, join as join10 } from "path";
|
|
1680
|
-
import
|
|
1706
|
+
import process18 from "process";
|
|
1681
1707
|
|
|
1682
1708
|
// src/e2e.ts
|
|
1683
1709
|
var E2E_NOISE = [
|
|
@@ -2312,7 +2338,7 @@ var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
|
2312
2338
|
async function logDirectory(cwd) {
|
|
2313
2339
|
const root = await privateLogDirectory("check");
|
|
2314
2340
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2315
|
-
const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${
|
|
2341
|
+
const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process18.pid}`);
|
|
2316
2342
|
await mkdir2(path, { mode: 448 });
|
|
2317
2343
|
return path;
|
|
2318
2344
|
}
|
|
@@ -2338,7 +2364,7 @@ async function lastFailed(cwd) {
|
|
|
2338
2364
|
async function saveLog(output) {
|
|
2339
2365
|
const root = await privateLogDirectory("errs");
|
|
2340
2366
|
await sweepLogs(root);
|
|
2341
|
-
const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${
|
|
2367
|
+
const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process18.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2342
2368
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2343
2369
|
return path;
|
|
2344
2370
|
}
|
|
@@ -2346,7 +2372,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2346
2372
|
const started = Date.now();
|
|
2347
2373
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2348
2374
|
cwd,
|
|
2349
|
-
env: { ...
|
|
2375
|
+
env: { ...process18.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2350
2376
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2351
2377
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2352
2378
|
});
|
|
@@ -2362,8 +2388,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2362
2388
|
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) } };
|
|
2363
2389
|
}
|
|
2364
2390
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2365
|
-
const colors = paint(
|
|
2366
|
-
const path = role("path",
|
|
2391
|
+
const colors = paint(process18.stdout);
|
|
2392
|
+
const path = role("path", process18.stdout);
|
|
2367
2393
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2368
2394
|
if (outcome.ok) {
|
|
2369
2395
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2386,15 +2412,15 @@ It looks at the folder itself only, so each package of a monorepo gets its own r
|
|
|
2386
2412
|
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.
|
|
2387
2413
|
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.
|
|
2388
2414
|
A fixer still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2389
|
-
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.
|
|
2390
2415
|
--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.`;
|
|
2416
|
+
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"]];
|
|
2391
2417
|
var RUNNING = "KAYNOOO_CLI_FIX";
|
|
2392
2418
|
var JUSTFILES2 = ["justfile", "Justfile", ".justfile"];
|
|
2393
2419
|
var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
2394
2420
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2395
2421
|
var MAX_CHANGED = 30;
|
|
2396
2422
|
async function replaceFile(path, content) {
|
|
2397
|
-
const temporary = `${path}.${
|
|
2423
|
+
const temporary = `${path}.${process19.pid}.tmp`;
|
|
2398
2424
|
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
2399
2425
|
await rename(temporary, path);
|
|
2400
2426
|
}
|
|
@@ -2466,14 +2492,14 @@ function printChanged(changed) {
|
|
|
2466
2492
|
if (changed.length > MAX_CHANGED)
|
|
2467
2493
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2468
2494
|
}
|
|
2469
|
-
async function fix(args, cwd =
|
|
2470
|
-
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"]] });
|
|
2495
|
+
async function fix(args, cwd = process19.cwd()) {
|
|
2496
|
+
const parsed = parse(args, fixUsage, fixOptions, { exits: EXITS, replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
|
|
2471
2497
|
return runFixers(parsed.values, cwd);
|
|
2472
2498
|
}
|
|
2473
2499
|
async function runFixers(values, cwd) {
|
|
2474
2500
|
const parsed = { values };
|
|
2475
2501
|
const settings = placeSettings(values);
|
|
2476
|
-
if (
|
|
2502
|
+
if (process19.env[RUNNING] !== undefined)
|
|
2477
2503
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2478
2504
|
const found = await fixers(cwd);
|
|
2479
2505
|
if (found.length === 0)
|
|
@@ -2507,7 +2533,7 @@ async function runFixers(values, cwd) {
|
|
|
2507
2533
|
break;
|
|
2508
2534
|
if (missing(fixer)) {
|
|
2509
2535
|
if (!json)
|
|
2510
|
-
console.log(`${paint(
|
|
2536
|
+
console.log(`${paint(process19.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2511
2537
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2512
2538
|
continue;
|
|
2513
2539
|
}
|
|
@@ -2626,8 +2652,8 @@ With --quiet, passing steps print nothing, and a fully passing run prints nothin
|
|
|
2626
2652
|
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2627
2653
|
With --failed, only the steps that failed in the last run of this folder run again, read from that run's folder of logs; when no last run failed, it says so and exits 2.
|
|
2628
2654
|
With --fix, the folder's fixers and formatters run instead of the steps, exactly as the \`fix\` bin does (it is the alias of \`check --fix\`): its own scripts, php-cs-fixer, just --fmt, go fmt, cargo fmt, ruff and the Makefile's .PHONY targets, then the files the run changed are listed. --only then names fixers, as --list prints them; --changed, --failed and --slot do not apply.
|
|
2629
|
-
Exits 0 when every step passed, 1 when one failed, 2 on bad usage, when no step is found or when a step timed out.
|
|
2630
2655
|
--json prints [{name, command, in?, ok, ms, log, failed?}] once every step ran, --list --json [{name, command, source, in?}], in the compose service the step ran in; with --fix the shape \`fix --json\` prints.`;
|
|
2656
|
+
var EXITS2 = [[0, "every step passed"], [1, "one failed"], [2, "bad usage, no step is found or a step timed out"]];
|
|
2631
2657
|
function slotted(command) {
|
|
2632
2658
|
return `slot -- sh -c ${shellQuote(command)}`;
|
|
2633
2659
|
}
|
|
@@ -2656,14 +2682,14 @@ function launch(step) {
|
|
|
2656
2682
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2657
2683
|
}
|
|
2658
2684
|
function summaryLine(outcomes) {
|
|
2659
|
-
const colors = paint(
|
|
2685
|
+
const colors = paint(process20.stdout);
|
|
2660
2686
|
const failed = outcomes.filter((outcome) => !outcome.ok).length;
|
|
2661
2687
|
const passed = outcomes.length - failed;
|
|
2662
2688
|
const parts = [colors.green(`${passed} passed`), ...failed === 0 ? [] : [colors.red(`${failed} failed`)], colors.dim(formatDuration(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0)))];
|
|
2663
2689
|
return parts.join(colors.dim(" \xB7 "));
|
|
2664
2690
|
}
|
|
2665
|
-
async function check(args, cwd =
|
|
2666
|
-
const parsed = parse(args, usage2, options, { replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2691
|
+
async function check(args, cwd = process20.cwd()) {
|
|
2692
|
+
const parsed = parse(args, usage2, options, { exits: EXITS2, replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2667
2693
|
const settings = placeSettings(parsed.values);
|
|
2668
2694
|
if (parsed.values.fix === true) {
|
|
2669
2695
|
for (const flag of ["changed", "failed", "slot"]) {
|
|
@@ -2673,7 +2699,7 @@ async function check(args, cwd = process19.cwd()) {
|
|
|
2673
2699
|
return runFixers(parsed.values, cwd);
|
|
2674
2700
|
}
|
|
2675
2701
|
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2676
|
-
if (parsed.values.slot === true && Bun.which("slot", { PATH:
|
|
2702
|
+
if (parsed.values.slot === true && Bun.which("slot", { PATH: process20.env.PATH ?? "" }) === null)
|
|
2677
2703
|
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2678
2704
|
const projects = await discoverProjects(cwd);
|
|
2679
2705
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
@@ -2704,7 +2730,7 @@ async function check(args, cwd = process19.cwd()) {
|
|
|
2704
2730
|
const width = Math.max(...steps.map((step) => step.label.length));
|
|
2705
2731
|
const outcomes = [];
|
|
2706
2732
|
const quiet = parsed.values.quiet === true;
|
|
2707
|
-
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
|
|
2733
|
+
const heading = json || quiet ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`, process20.stdout);
|
|
2708
2734
|
if (heading !== "")
|
|
2709
2735
|
console.log(heading);
|
|
2710
2736
|
try {
|
|
@@ -2735,4 +2761,4 @@ async function check(args, cwd = process19.cwd()) {
|
|
|
2735
2761
|
}
|
|
2736
2762
|
|
|
2737
2763
|
// src/cli.ts
|
|
2738
|
-
|
|
2764
|
+
process21.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|