@kaynooo/cli-check 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/cli.js +495 -183
- package/dist/errs-cli.js +139 -74
- package/dist/fix-cli.js +220 -316
- package/dist/j-cli.js +1831 -0
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import process16 from "process";
|
|
7
6
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
7
|
+
import process6 from "process";
|
|
9
8
|
import { parseArgs } from "util";
|
|
10
9
|
|
|
11
10
|
// ../kit/src/format.ts
|
|
12
|
-
import
|
|
11
|
+
import process3 from "process";
|
|
13
12
|
|
|
14
13
|
// ../kit/src/style.ts
|
|
15
|
-
import
|
|
14
|
+
import process2 from "process";
|
|
16
15
|
|
|
17
16
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
18
17
|
function x(s) {
|
|
@@ -282,20 +281,20 @@ var MARKS = {
|
|
|
282
281
|
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
283
282
|
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
284
283
|
};
|
|
285
|
-
function takesControlCodes(stream, env =
|
|
284
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
286
285
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
287
286
|
}
|
|
288
|
-
function paint(stream, env =
|
|
287
|
+
function paint(stream, env = process2.env) {
|
|
289
288
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
290
289
|
}
|
|
291
|
-
function marked(mark, text, stream, detail, env =
|
|
290
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
292
291
|
const colors = paint(stream, env);
|
|
293
292
|
const { symbol, word, paint: tint } = MARKS[mark];
|
|
294
293
|
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
295
294
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
296
295
|
}
|
|
297
296
|
function warn(text, detail) {
|
|
298
|
-
console.error(marked("warn", text,
|
|
297
|
+
console.error(marked("warn", text, process2.stderr, detail));
|
|
299
298
|
}
|
|
300
299
|
var STATUSES = {
|
|
301
300
|
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
@@ -344,7 +343,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
344
343
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
345
344
|
}
|
|
346
345
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
347
|
-
const colors = paint(
|
|
346
|
+
const colors = paint(process3.stdout);
|
|
348
347
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
349
348
|
const width = widths[index] ?? 0;
|
|
350
349
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -376,24 +375,30 @@ function printJson(value) {
|
|
|
376
375
|
}
|
|
377
376
|
|
|
378
377
|
// ../kit/src/help.ts
|
|
379
|
-
import
|
|
378
|
+
import process4 from "process";
|
|
380
379
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
381
380
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
382
381
|
var FULL_STOP = /\.$/;
|
|
383
|
-
function usageLine(usage, colors = paint(
|
|
382
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
384
383
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
385
384
|
}
|
|
386
|
-
function helpText(usage, options, colors = paint(
|
|
387
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
385
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
386
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
388
387
|
`);
|
|
389
388
|
}
|
|
390
|
-
function
|
|
389
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
390
|
+
if (exits.length === 0)
|
|
391
|
+
return [];
|
|
392
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
393
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
394
|
+
}
|
|
395
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
391
396
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
392
397
|
}
|
|
393
|
-
function wantsHelpJson(env =
|
|
398
|
+
function wantsHelpJson(env = process4.env) {
|
|
394
399
|
return env.KIT_HELP === "json";
|
|
395
400
|
}
|
|
396
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
401
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
397
402
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
398
403
|
`);
|
|
399
404
|
const first = lines[0];
|
|
@@ -404,15 +409,17 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
404
409
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
405
410
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
406
411
|
...replaces === undefined ? {} : { replaces },
|
|
407
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
412
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
413
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
414
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
408
415
|
};
|
|
409
416
|
}
|
|
410
|
-
function exampleRows(examples, colors = paint(
|
|
417
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
411
418
|
if (examples.length === 0)
|
|
412
419
|
return [];
|
|
413
420
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
414
421
|
}
|
|
415
|
-
function optionRows(options, colors = paint(
|
|
422
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
416
423
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
417
424
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
418
425
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -447,7 +454,7 @@ function closest(name, names) {
|
|
|
447
454
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
448
455
|
}
|
|
449
456
|
// ../kit/src/input.ts
|
|
450
|
-
import
|
|
457
|
+
import process5 from "process";
|
|
451
458
|
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
452
459
|
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
453
460
|
function duration(value, name, fallback, unit = "s") {
|
|
@@ -461,7 +468,7 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
461
468
|
}
|
|
462
469
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
463
470
|
if (path === "-") {
|
|
464
|
-
if (
|
|
471
|
+
if (process5.stdin.isTTY)
|
|
465
472
|
fail(noStdin);
|
|
466
473
|
return Bun.stdin.text();
|
|
467
474
|
}
|
|
@@ -520,7 +527,7 @@ var OUTPUT_OPTIONS = {
|
|
|
520
527
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
521
528
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
522
529
|
};
|
|
523
|
-
function applyOutput(color, plain, env =
|
|
530
|
+
function applyOutput(color, plain, env = process6.env) {
|
|
524
531
|
const when = plain === true ? "never" : color ?? "auto";
|
|
525
532
|
if (when === "auto")
|
|
526
533
|
return;
|
|
@@ -543,7 +550,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
543
550
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
544
551
|
let parsed;
|
|
545
552
|
try {
|
|
546
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
553
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
547
554
|
} catch (error) {
|
|
548
555
|
const message = parseError(error);
|
|
549
556
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -551,7 +558,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
551
558
|
const values = parsed.values;
|
|
552
559
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
553
560
|
if (values.help === true) {
|
|
554
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
561
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
555
562
|
throw new HelpShown;
|
|
556
563
|
}
|
|
557
564
|
checkChoices(parsed.values, all);
|
|
@@ -593,6 +600,18 @@ function listed(options, allowNegative) {
|
|
|
593
600
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
594
601
|
}));
|
|
595
602
|
}
|
|
603
|
+
function withAliases(args, options) {
|
|
604
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
605
|
+
if (named.size === 0)
|
|
606
|
+
return args;
|
|
607
|
+
const separator = args.indexOf("--");
|
|
608
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
609
|
+
return [...own.map((arg) => {
|
|
610
|
+
const at = arg.indexOf("=");
|
|
611
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
612
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
613
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
614
|
+
}
|
|
596
615
|
function withBare(args, options) {
|
|
597
616
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
598
617
|
if (bare.size === 0)
|
|
@@ -679,7 +698,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
679
698
|
}
|
|
680
699
|
// ../kit/src/process.ts
|
|
681
700
|
import { constants } from "os";
|
|
682
|
-
import
|
|
701
|
+
import process7 from "process";
|
|
683
702
|
var KILL_GRACE_MS = 2000;
|
|
684
703
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
685
704
|
function exitCodeOf(code, signal) {
|
|
@@ -701,7 +720,7 @@ function holdSignals(cleanup) {
|
|
|
701
720
|
},
|
|
702
721
|
release: () => {
|
|
703
722
|
for (const signal of SIGNALS)
|
|
704
|
-
|
|
723
|
+
process7.off(signal, onSignal);
|
|
705
724
|
}
|
|
706
725
|
};
|
|
707
726
|
function onSignal(signal) {
|
|
@@ -714,10 +733,10 @@ function holdSignals(cleanup) {
|
|
|
714
733
|
return;
|
|
715
734
|
held.release();
|
|
716
735
|
cleanup(signal);
|
|
717
|
-
|
|
736
|
+
process7.kill(process7.pid, signal);
|
|
718
737
|
}
|
|
719
738
|
for (const signal of SIGNALS)
|
|
720
|
-
|
|
739
|
+
process7.on(signal, onSignal);
|
|
721
740
|
return held;
|
|
722
741
|
}
|
|
723
742
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -731,7 +750,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
731
750
|
return;
|
|
732
751
|
try {
|
|
733
752
|
if (grouped)
|
|
734
|
-
|
|
753
|
+
process7.kill(-proc.pid, killing);
|
|
735
754
|
else
|
|
736
755
|
proc.kill(killing);
|
|
737
756
|
} catch {}
|
|
@@ -805,31 +824,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
805
824
|
var RESET_STYLE = `${ESC}[0m`;
|
|
806
825
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
807
826
|
// ../kit/src/cli.ts
|
|
808
|
-
import
|
|
827
|
+
import { readFileSync, realpathSync } from "fs";
|
|
828
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
829
|
+
import process10 from "process";
|
|
809
830
|
|
|
810
831
|
// ../kit/src/usage.ts
|
|
811
832
|
import { appendFileSync, mkdirSync } from "fs";
|
|
812
833
|
import { homedir as homedir2 } from "os";
|
|
813
834
|
import { dirname, isAbsolute, join as join2 } from "path";
|
|
814
|
-
import
|
|
835
|
+
import process9 from "process";
|
|
815
836
|
|
|
816
837
|
// ../kit/src/logs.ts
|
|
817
838
|
import { lstatSync, openSync } from "fs";
|
|
818
839
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
819
840
|
import { homedir, tmpdir } from "os";
|
|
820
841
|
import { join } from "path";
|
|
821
|
-
import
|
|
842
|
+
import process8 from "process";
|
|
822
843
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
823
844
|
var CLI_FOLDER = "kaynooo-cli";
|
|
824
845
|
function isPrivateDirectory(path) {
|
|
825
846
|
try {
|
|
826
847
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
827
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
848
|
+
return info !== undefined && info.isDirectory() && info.uid === (process8.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
828
849
|
} catch {
|
|
829
850
|
return false;
|
|
830
851
|
}
|
|
831
852
|
}
|
|
832
|
-
async function privateLogDirectory(name, env =
|
|
853
|
+
async function privateLogDirectory(name, env = process8.env) {
|
|
833
854
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
834
855
|
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
835
856
|
const path = join(base, name);
|
|
@@ -869,14 +890,14 @@ var usageError;
|
|
|
869
890
|
function noteUsageError(message) {
|
|
870
891
|
usageError = message;
|
|
871
892
|
}
|
|
872
|
-
function stateHome(env =
|
|
893
|
+
function stateHome(env = process9.env) {
|
|
873
894
|
const dir = env.XDG_STATE_HOME;
|
|
874
895
|
return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
|
|
875
896
|
}
|
|
876
|
-
function usagePath(env =
|
|
897
|
+
function usagePath(env = process9.env) {
|
|
877
898
|
return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
878
899
|
}
|
|
879
|
-
function usageRecorded(env =
|
|
900
|
+
function usageRecorded(env = process9.env) {
|
|
880
901
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
881
902
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
882
903
|
}
|
|
@@ -890,7 +911,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
890
911
|
usageError = undefined;
|
|
891
912
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
892
913
|
}
|
|
893
|
-
function recordUsage(entry, env =
|
|
914
|
+
function recordUsage(entry, env = process9.env) {
|
|
894
915
|
if (!usageRecorded(env))
|
|
895
916
|
return;
|
|
896
917
|
try {
|
|
@@ -908,8 +929,8 @@ var LEVEL_OPTIONS = {
|
|
|
908
929
|
};
|
|
909
930
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
910
931
|
function printError(prefix, message, hint, cause) {
|
|
911
|
-
const colors = paint(
|
|
912
|
-
const styled = takesControlCodes(
|
|
932
|
+
const colors = paint(process10.stderr);
|
|
933
|
+
const styled = takesControlCodes(process10.stderr);
|
|
913
934
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
914
935
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
915
936
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -991,11 +1012,22 @@ async function printCandidates(found) {
|
|
|
991
1012
|
console.log(line);
|
|
992
1013
|
return 0;
|
|
993
1014
|
}
|
|
994
|
-
|
|
1015
|
+
function packageVersion(entry = Bun.main) {
|
|
1016
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
1017
|
+
try {
|
|
1018
|
+
const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
|
|
1019
|
+
if (typeof version === "string")
|
|
1020
|
+
return version;
|
|
1021
|
+
} catch {}
|
|
1022
|
+
if (dirname2(dir) === dir)
|
|
1023
|
+
return "0.0.0";
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
|
|
995
1027
|
if (argv[0] === COMPLETE)
|
|
996
1028
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
997
1029
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
998
|
-
console.log(version);
|
|
1030
|
+
console.log(version ?? packageVersion());
|
|
999
1031
|
return 0;
|
|
1000
1032
|
}
|
|
1001
1033
|
let code;
|
|
@@ -1004,8 +1036,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
|
|
|
1004
1036
|
} catch (error) {
|
|
1005
1037
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1006
1038
|
}
|
|
1007
|
-
if (usage !== false)
|
|
1008
|
-
|
|
1039
|
+
if (usage !== false) {
|
|
1040
|
+
try {
|
|
1041
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1042
|
+
} catch {}
|
|
1043
|
+
}
|
|
1009
1044
|
return code;
|
|
1010
1045
|
}
|
|
1011
1046
|
// ../kit/src/secrets.ts
|
|
@@ -1015,11 +1050,12 @@ var {Glob } = globalThis.Bun;
|
|
|
1015
1050
|
var SESSION_FILES = new Glob("*.json");
|
|
1016
1051
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1017
1052
|
// package.json
|
|
1018
|
-
var version = "0.
|
|
1053
|
+
var version = "0.12.0";
|
|
1019
1054
|
|
|
1020
1055
|
// src/check.ts
|
|
1021
|
-
import {
|
|
1022
|
-
import
|
|
1056
|
+
import { writeFile as writeFile3 } from "fs/promises";
|
|
1057
|
+
import { join as join10 } from "path";
|
|
1058
|
+
import process15 from "process";
|
|
1023
1059
|
|
|
1024
1060
|
// ../kit/src/shell.ts
|
|
1025
1061
|
var SEPARATORS = new Set([`
|
|
@@ -1030,13 +1066,16 @@ var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
|
1030
1066
|
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
1031
1067
|
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
1032
1068
|
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
1033
|
-
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh"]);
|
|
1034
|
-
var
|
|
1069
|
+
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
|
|
1070
|
+
var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
|
|
1071
|
+
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
|
|
1072
|
+
var POWERSHELL = new Set(["pwsh", "powershell"]);
|
|
1035
1073
|
var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
1074
|
+
var FISH_VALUE_OPTIONS = new Set(["-C", "--init-command"]);
|
|
1036
1075
|
var PRINTERS = new Set(["echo", "printf"]);
|
|
1037
1076
|
var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
1038
|
-
function wrapper(short = "", long = [], operands = 0) {
|
|
1039
|
-
return { short, long, operands };
|
|
1077
|
+
function wrapper(short = "", long = [], operands = 0, runsString = false) {
|
|
1078
|
+
return { short, long, operands, runsString };
|
|
1040
1079
|
}
|
|
1041
1080
|
var WRAPPERS = new Map([
|
|
1042
1081
|
["command", wrapper()],
|
|
@@ -1054,6 +1093,11 @@ var WRAPPERS = new Map([
|
|
|
1054
1093
|
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
1055
1094
|
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
1056
1095
|
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
1096
|
+
["watch", wrapper("n", ["--interval"], 0, true)],
|
|
1097
|
+
["flock", wrapper("wE", ["--timeout", "--conflict-exit-code"], 1)],
|
|
1098
|
+
["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
|
|
1099
|
+
["unbuffer", wrapper()],
|
|
1100
|
+
["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
|
|
1057
1101
|
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
|
|
1058
1102
|
]);
|
|
1059
1103
|
function shellQuote(word) {
|
|
@@ -1063,8 +1107,8 @@ function shellQuote(word) {
|
|
|
1063
1107
|
// src/compose.ts
|
|
1064
1108
|
import { existsSync } from "fs";
|
|
1065
1109
|
import { homedir as homedir3 } from "os";
|
|
1066
|
-
import { basename, dirname as
|
|
1067
|
-
import
|
|
1110
|
+
import { basename, dirname as dirname3, join as join4, relative, resolve } from "path";
|
|
1111
|
+
import process12 from "process";
|
|
1068
1112
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1069
1113
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1070
1114
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1093,7 +1137,7 @@ function toolWords(program) {
|
|
|
1093
1137
|
}
|
|
1094
1138
|
async function readFiles(dir, names) {
|
|
1095
1139
|
for (const name of names) {
|
|
1096
|
-
const handle = Bun.file(
|
|
1140
|
+
const handle = Bun.file(join4(dir, name));
|
|
1097
1141
|
if (await handle.exists())
|
|
1098
1142
|
return { name, text: await handle.text() };
|
|
1099
1143
|
}
|
|
@@ -1108,7 +1152,7 @@ async function variables(composeDir) {
|
|
|
1108
1152
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1109
1153
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1110
1154
|
}
|
|
1111
|
-
for (const [key, value] of Object.entries(
|
|
1155
|
+
for (const [key, value] of Object.entries(process12.env)) {
|
|
1112
1156
|
if (value !== undefined)
|
|
1113
1157
|
env[key] = value;
|
|
1114
1158
|
}
|
|
@@ -1128,7 +1172,7 @@ function interpolate(text, env) {
|
|
|
1128
1172
|
function bindSource(source, composeDir, env) {
|
|
1129
1173
|
const path = interpolate(source, env);
|
|
1130
1174
|
if (path.startsWith("~"))
|
|
1131
|
-
return
|
|
1175
|
+
return join4(homedir3(), path.slice(1));
|
|
1132
1176
|
if (path.startsWith("/"))
|
|
1133
1177
|
return resolve(path);
|
|
1134
1178
|
return path.startsWith(".") ? resolve(composeDir, path) : undefined;
|
|
@@ -1175,7 +1219,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1175
1219
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1176
1220
|
const file = Bun.file(resolve(composeDir, name));
|
|
1177
1221
|
if (!await file.exists())
|
|
1178
|
-
fail(`COMPOSE_FILE names ${
|
|
1222
|
+
fail(`COMPOSE_FILE names ${join4(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1179
1223
|
files.push({ name, text: await file.text() });
|
|
1180
1224
|
}
|
|
1181
1225
|
return files;
|
|
@@ -1197,7 +1241,7 @@ async function readServices(composeDir) {
|
|
|
1197
1241
|
try {
|
|
1198
1242
|
parsed = parseServices(file.text, composeDir, env);
|
|
1199
1243
|
} catch (error) {
|
|
1200
|
-
fail(`cannot read ${
|
|
1244
|
+
fail(`cannot read ${join4(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1201
1245
|
}
|
|
1202
1246
|
for (const [name, extra] of parsed) {
|
|
1203
1247
|
const known = services.get(name);
|
|
@@ -1209,11 +1253,11 @@ async function readServices(composeDir) {
|
|
|
1209
1253
|
function climb(dir) {
|
|
1210
1254
|
const folders = [dir];
|
|
1211
1255
|
let current = dir;
|
|
1212
|
-
while (!existsSync(
|
|
1213
|
-
current =
|
|
1256
|
+
while (!existsSync(join4(current, ".git")) && dirname3(current) !== current) {
|
|
1257
|
+
current = dirname3(current);
|
|
1214
1258
|
folders.push(current);
|
|
1215
1259
|
}
|
|
1216
|
-
return existsSync(
|
|
1260
|
+
return existsSync(join4(current, ".git")) ? folders : [dir];
|
|
1217
1261
|
}
|
|
1218
1262
|
function containerPath(service, dir) {
|
|
1219
1263
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1224,7 +1268,7 @@ function containerPath(service, dir) {
|
|
|
1224
1268
|
if (deepest === undefined)
|
|
1225
1269
|
return;
|
|
1226
1270
|
const inside = relative(deepest.source, dir);
|
|
1227
|
-
return inside === "" ? deepest.target :
|
|
1271
|
+
return inside === "" ? deepest.target : join4(deepest.target, inside);
|
|
1228
1272
|
}
|
|
1229
1273
|
var noticed = new Set;
|
|
1230
1274
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1244,7 +1288,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1244
1288
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1245
1289
|
return;
|
|
1246
1290
|
}
|
|
1247
|
-
if (Bun.which("docker", { PATH:
|
|
1291
|
+
if (Bun.which("docker", { PATH: process12.env.PATH ?? "" }) === null) {
|
|
1248
1292
|
if (service !== undefined)
|
|
1249
1293
|
fail(`--in ${service}: docker not found`);
|
|
1250
1294
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1296,7 +1340,7 @@ class Stack {
|
|
|
1296
1340
|
}
|
|
1297
1341
|
static async running(composeDir) {
|
|
1298
1342
|
try {
|
|
1299
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1343
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process12.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1300
1344
|
if (ran.code !== 0)
|
|
1301
1345
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1302
1346
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1327,16 +1371,71 @@ function placeSettings(values) {
|
|
|
1327
1371
|
return { service: values.in, host: values.host };
|
|
1328
1372
|
}
|
|
1329
1373
|
|
|
1330
|
-
// src/
|
|
1331
|
-
import { existsSync as existsSync2 } from "fs";
|
|
1332
|
-
import {
|
|
1374
|
+
// src/fix.ts
|
|
1375
|
+
import { existsSync as existsSync2, statSync } from "fs";
|
|
1376
|
+
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1377
|
+
import { join as join8 } from "path";
|
|
1378
|
+
import process14 from "process";
|
|
1379
|
+
|
|
1380
|
+
// src/changes.ts
|
|
1381
|
+
import { stat as stat2 } from "fs/promises";
|
|
1382
|
+
import { join as join5 } from "path";
|
|
1333
1383
|
var {$ } = globalThis.Bun;
|
|
1384
|
+
async function dirtyFiles(dir) {
|
|
1385
|
+
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
1386
|
+
if (listed.exitCode !== 0)
|
|
1387
|
+
return;
|
|
1388
|
+
const files = new Map;
|
|
1389
|
+
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1390
|
+
try {
|
|
1391
|
+
const { size, mtimeMs } = await stat2(join5(dir, path));
|
|
1392
|
+
files.set(path, `${size}:${mtimeMs}`);
|
|
1393
|
+
} catch {
|
|
1394
|
+
files.set(path, "");
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return files;
|
|
1398
|
+
}
|
|
1399
|
+
function changedFiles(before, after) {
|
|
1400
|
+
return [...after].filter(([path, hash]) => before.get(path) !== hash).map(([path]) => path);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// src/makefile.ts
|
|
1404
|
+
var TARGET = /^([\w-]+(?:[ \t]+[\w-]+)*)[ \t]*::?(?!:?=)(.*)$/gm;
|
|
1405
|
+
var PHONY_LINE = /^\.PHONY:((?:.*\\\n)*.*)$/gm;
|
|
1406
|
+
var DEFINE_BLOCK = /^define\b.*\n(?:.*\n)*?endef\b.*$/gm;
|
|
1407
|
+
var BLANKS = /\s+/;
|
|
1408
|
+
var CONTINUATION = /\\\n/g;
|
|
1409
|
+
var EXTRA_BLANK_LINES = /\n\s*\n\s*\n/g;
|
|
1410
|
+
var LEADING_BLANK_LINES = /^\s*\n/;
|
|
1411
|
+
var TRAILING_WHITESPACE = /\s+$/;
|
|
1412
|
+
var FILE_LIKE = /[./]/;
|
|
1413
|
+
var PLACEHOLDER = "\x00phony\x00";
|
|
1414
|
+
function declarePhony(content, exists = () => false) {
|
|
1415
|
+
const declared = Array.from(content.matchAll(PHONY_LINE), (match) => match[1].replace(CONTINUATION, " ").split(BLANKS)).flat().filter((name) => name !== "");
|
|
1416
|
+
const found = Array.from(content.replace(DEFINE_BLOCK, "").matchAll(TARGET), (match) => ({ names: match[1].split(BLANKS), deps: match[2] })).filter(({ deps }) => !FILE_LIKE.test(deps)).flatMap(({ names }) => names).filter((name) => !exists(name));
|
|
1417
|
+
const targets = [...new Set([...declared, ...found])].sort((a, b) => a.localeCompare(b));
|
|
1418
|
+
let isFirst = true;
|
|
1419
|
+
const body = content.replace(PHONY_LINE, () => {
|
|
1420
|
+
const kept = isFirst ? PLACEHOLDER : "";
|
|
1421
|
+
isFirst = false;
|
|
1422
|
+
return kept;
|
|
1423
|
+
}).replace(EXTRA_BLANK_LINES, `
|
|
1424
|
+
|
|
1425
|
+
`).replace(LEADING_BLANK_LINES, "");
|
|
1426
|
+
const line = targets.length === 0 ? "" : `.PHONY: ${targets.join(" ")}`;
|
|
1427
|
+
const fixed = body.includes(PLACEHOLDER) || line === "" ? body.replace(PLACEHOLDER, () => line) : `${line}
|
|
1428
|
+
|
|
1429
|
+
${body}`;
|
|
1430
|
+
return { content: fixed.replace(LEADING_BLANK_LINES, "").replace(TRAILING_WHITESPACE, `
|
|
1431
|
+
`), targets };
|
|
1432
|
+
}
|
|
1334
1433
|
|
|
1335
1434
|
// src/steps.ts
|
|
1336
1435
|
import { readdir as readdir2 } from "fs/promises";
|
|
1337
|
-
import { join as
|
|
1436
|
+
import { join as join6 } from "path";
|
|
1338
1437
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1339
|
-
var
|
|
1438
|
+
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1340
1439
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1341
1440
|
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1342
1441
|
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
@@ -1346,7 +1445,7 @@ var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
|
1346
1445
|
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1347
1446
|
async function readFirst(dir, files) {
|
|
1348
1447
|
for (const file of files) {
|
|
1349
|
-
const handle = Bun.file(
|
|
1448
|
+
const handle = Bun.file(join6(dir, file));
|
|
1350
1449
|
if (await handle.exists())
|
|
1351
1450
|
return { file, text: await handle.text() };
|
|
1352
1451
|
}
|
|
@@ -1354,7 +1453,7 @@ async function readFirst(dir, files) {
|
|
|
1354
1453
|
}
|
|
1355
1454
|
async function read(dir, ...files) {
|
|
1356
1455
|
for (const file of files) {
|
|
1357
|
-
const handle = Bun.file(
|
|
1456
|
+
const handle = Bun.file(join6(dir, file));
|
|
1358
1457
|
if (await handle.exists())
|
|
1359
1458
|
return handle.text();
|
|
1360
1459
|
}
|
|
@@ -1365,11 +1464,11 @@ function scripts(file, text) {
|
|
|
1365
1464
|
const parsed = JSON.parse(text);
|
|
1366
1465
|
return parsed.scripts ?? {};
|
|
1367
1466
|
} catch {
|
|
1368
|
-
|
|
1467
|
+
fail(`${file} is not valid JSON`);
|
|
1369
1468
|
}
|
|
1370
1469
|
}
|
|
1371
1470
|
function targets(text) {
|
|
1372
|
-
return [...text.matchAll(
|
|
1471
|
+
return [...text.matchAll(TARGET2)].map((match) => match[1] ?? "");
|
|
1373
1472
|
}
|
|
1374
1473
|
async function recipes(dir, file, text) {
|
|
1375
1474
|
if (Bun.which("just") === null)
|
|
@@ -1414,7 +1513,7 @@ async function candidates(dir, bin) {
|
|
|
1414
1513
|
}
|
|
1415
1514
|
async function firstFile(dir, names) {
|
|
1416
1515
|
for (const name of names) {
|
|
1417
|
-
if (await Bun.file(
|
|
1516
|
+
if (await Bun.file(join6(dir, name)).exists())
|
|
1418
1517
|
return name;
|
|
1419
1518
|
}
|
|
1420
1519
|
return;
|
|
@@ -1441,9 +1540,9 @@ async function discoverProjects(dir) {
|
|
|
1441
1540
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1442
1541
|
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1443
1542
|
continue;
|
|
1444
|
-
const steps = await discover(
|
|
1543
|
+
const steps = await discover(join6(dir, entry.name));
|
|
1445
1544
|
if (steps.length > 0)
|
|
1446
|
-
projects.push({ name: entry.name, dir:
|
|
1545
|
+
projects.push({ name: entry.name, dir: join6(dir, entry.name), steps });
|
|
1447
1546
|
}
|
|
1448
1547
|
return projects;
|
|
1449
1548
|
}
|
|
@@ -1455,81 +1554,38 @@ async function discover(dir) {
|
|
|
1455
1554
|
});
|
|
1456
1555
|
}
|
|
1457
1556
|
|
|
1458
|
-
// src/
|
|
1459
|
-
var
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
}
|
|
1485
|
-
return [...found];
|
|
1486
|
-
}
|
|
1487
|
-
function isBare(script, tool) {
|
|
1488
|
-
return tool.test(script.trim()) && script.trim().replace(tool, "").split(WHITESPACE).every((word) => word.startsWith("-") || word === "");
|
|
1489
|
-
}
|
|
1490
|
-
async function narrow2(step, dir, changed) {
|
|
1491
|
-
const script = step.source === "package.json" ? (await scriptText(dir, step.name))?.trim() : undefined;
|
|
1492
|
-
const full = (why) => ({ command: step.command, note: `in full, ${why}` });
|
|
1493
|
-
if (script !== undefined && step.name === "lint" && isBare(script, LINTERS)) {
|
|
1494
|
-
const files = changed.filter((path) => LINTABLE.has(extname(path)));
|
|
1495
|
-
return files.length === 0 ? { command: "true", note: "nothing changed to lint" } : { command: `${step.command} -- ${files.map(quote).join(" ")}`, note: `${files.length} changed file${files.length === 1 ? "" : "s"}` };
|
|
1496
|
-
}
|
|
1497
|
-
if (script !== undefined && step.name === "test" && isBare(script, TEST_RUNNER)) {
|
|
1498
|
-
const tests = new Set;
|
|
1499
|
-
for (const path of changed) {
|
|
1500
|
-
if (TEST_FILE.test(path)) {
|
|
1501
|
-
tests.add(path);
|
|
1502
|
-
} else {
|
|
1503
|
-
for (const test of siblingTests(path, (candidate) => existsSync2(join5(dir, candidate)))) {
|
|
1504
|
-
tests.add(test);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
if (tests.size === 0)
|
|
1509
|
-
return full("no test sits next to the changed files");
|
|
1510
|
-
return { command: `${step.command} -- ${[...tests].map((test) => quote(`./${test}`)).join(" ")}`, note: `${tests.size} test file${tests.size === 1 ? "" : "s"}` };
|
|
1511
|
-
}
|
|
1512
|
-
return full(`${step.name} cannot be narrowed`);
|
|
1513
|
-
}
|
|
1514
|
-
function quote(path) {
|
|
1515
|
-
return `'${path.replaceAll("'", "'\\''")}'`;
|
|
1516
|
-
}
|
|
1517
|
-
async function scriptText(dir, name) {
|
|
1518
|
-
const text = await read(dir, "package.json");
|
|
1519
|
-
if (text === undefined)
|
|
1520
|
-
return;
|
|
1521
|
-
try {
|
|
1522
|
-
const value = JSON.parse(text).scripts?.[name];
|
|
1523
|
-
return typeof value === "string" ? value : undefined;
|
|
1524
|
-
} catch {
|
|
1525
|
-
return;
|
|
1526
|
-
}
|
|
1557
|
+
// src/options.ts
|
|
1558
|
+
var fixOptions = {
|
|
1559
|
+
list: { type: "boolean", short: "l", description: "print the steps (or, with --fix, the fixers) found, the commands that run them and where (host or service), without running them" },
|
|
1560
|
+
only: { type: "string", short: "o", description: `comma separated steps to run, among ${STEP_NAMES.join(", ")}; with --fix the fixers to run, by the names --list prints` },
|
|
1561
|
+
timeout: { type: "string", short: "t", description: "longest a step or fixer may run before it is ended (30s, 5m, 1h), none by default" },
|
|
1562
|
+
...placeOptions,
|
|
1563
|
+
json: jsonOption()
|
|
1564
|
+
};
|
|
1565
|
+
var options = {
|
|
1566
|
+
...fixOptions,
|
|
1567
|
+
fix: { type: "boolean", short: "f", description: "run the folder's fixers and formatters instead of the steps, as the fix bin does" },
|
|
1568
|
+
failed: { type: "boolean", description: "run only the steps that failed in the last run of this folder, read from the run folder" },
|
|
1569
|
+
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" },
|
|
1570
|
+
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions (needs the slot bin)" }
|
|
1571
|
+
};
|
|
1572
|
+
var COMMA = /\s*,\s*/;
|
|
1573
|
+
function pick(steps, only, noun = "step") {
|
|
1574
|
+
if (only === undefined)
|
|
1575
|
+
return steps;
|
|
1576
|
+
const names = only.split(COMMA).filter((name) => name !== "");
|
|
1577
|
+
if (names.length === 0)
|
|
1578
|
+
fail(`--only names no ${noun}, found ${steps.map((step) => step.name).join(", ")}`);
|
|
1579
|
+
const unknown = names.filter((name) => !steps.some((step) => step.name === name));
|
|
1580
|
+
if (unknown.length > 0)
|
|
1581
|
+
fail(`no ${unknown.join(", ")} ${noun} here, found ${[...new Set(steps.map((step) => step.name))].join(", ")}`);
|
|
1582
|
+
return steps.filter((step) => names.includes(step.name));
|
|
1527
1583
|
}
|
|
1528
1584
|
|
|
1529
1585
|
// src/run.ts
|
|
1530
|
-
import { mkdir as mkdir2, writeFile } from "fs/promises";
|
|
1531
|
-
import { basename as
|
|
1532
|
-
import
|
|
1586
|
+
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1587
|
+
import { basename as basename2, join as join7 } from "path";
|
|
1588
|
+
import process13 from "process";
|
|
1533
1589
|
|
|
1534
1590
|
// src/e2e.ts
|
|
1535
1591
|
var E2E_NOISE = [
|
|
@@ -1841,7 +1897,8 @@ var bunCheck = (lines) => {
|
|
|
1841
1897
|
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1842
1898
|
};
|
|
1843
1899
|
function bunCheckFields(block) {
|
|
1844
|
-
const attributes = Object.fromEntries([...block.
|
|
1900
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1901
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1845
1902
|
return {
|
|
1846
1903
|
file: attributes.file ?? "",
|
|
1847
1904
|
line: attributes.line ?? "",
|
|
@@ -2158,17 +2215,38 @@ function parseErrors(output) {
|
|
|
2158
2215
|
|
|
2159
2216
|
// src/run.ts
|
|
2160
2217
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2218
|
+
var RESULTS_FILE = "results.json";
|
|
2219
|
+
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2161
2220
|
async function logDirectory(cwd) {
|
|
2162
2221
|
const root = await privateLogDirectory("check");
|
|
2163
2222
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2164
|
-
const path =
|
|
2223
|
+
const path = join7(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process13.pid}`);
|
|
2165
2224
|
await mkdir2(path, { mode: 448 });
|
|
2166
2225
|
return path;
|
|
2167
2226
|
}
|
|
2227
|
+
async function lastFailed(cwd) {
|
|
2228
|
+
const root = await privateLogDirectory("check");
|
|
2229
|
+
const prefix = runPrefix(cwd);
|
|
2230
|
+
let latest;
|
|
2231
|
+
for (const name of await readdir3(root)) {
|
|
2232
|
+
if (!name.startsWith(prefix))
|
|
2233
|
+
continue;
|
|
2234
|
+
const file = join7(root, name, RESULTS_FILE);
|
|
2235
|
+
try {
|
|
2236
|
+
const { mtimeMs } = await stat3(file);
|
|
2237
|
+
if (latest === undefined || mtimeMs > latest.time)
|
|
2238
|
+
latest = { time: mtimeMs, file };
|
|
2239
|
+
} catch {}
|
|
2240
|
+
}
|
|
2241
|
+
if (latest === undefined)
|
|
2242
|
+
return;
|
|
2243
|
+
const results = JSON.parse(await Bun.file(latest.file).text());
|
|
2244
|
+
return results.filter((result) => !result.ok).map((result) => result.name);
|
|
2245
|
+
}
|
|
2168
2246
|
async function saveLog(output) {
|
|
2169
2247
|
const root = await privateLogDirectory("errs");
|
|
2170
2248
|
await sweepLogs(root);
|
|
2171
|
-
const path =
|
|
2249
|
+
const path = join7(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process13.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2172
2250
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2173
2251
|
return path;
|
|
2174
2252
|
}
|
|
@@ -2176,7 +2254,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2176
2254
|
const started = Date.now();
|
|
2177
2255
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2178
2256
|
cwd,
|
|
2179
|
-
env: { ...
|
|
2257
|
+
env: { ...process13.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2180
2258
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2181
2259
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2182
2260
|
});
|
|
@@ -2205,8 +2283,244 @@ function printOutcome(name, width, command, logFile, outcome) {
|
|
|
2205
2283
|
`));
|
|
2206
2284
|
}
|
|
2207
2285
|
|
|
2286
|
+
// src/fix.ts
|
|
2287
|
+
var fixUsage = `fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
2288
|
+
|
|
2289
|
+
Alias of \`check --fix\`. Runs the folder's fixers: the project's own \`fix\` script, else its \`lint:fix\` and \`format\` ones (package.json through bun run, composer.json, a Justfile or a Makefile), then the formatters its files call for: php-cs-fixer where configured and composer.json has no fixer, just --fmt, go fmt and go mod tidy, cargo fmt, ruff where configured, and every Makefile target declared .PHONY.
|
|
2290
|
+
It looks at the folder itself only, so each package of a monorepo gets its own run.
|
|
2291
|
+
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.
|
|
2292
|
+
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.
|
|
2293
|
+
A fixer still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2294
|
+
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.
|
|
2295
|
+
--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.`;
|
|
2296
|
+
var RUNNING = "KAYNOOO_CLI_FIX";
|
|
2297
|
+
var JUSTFILES2 = ["justfile", "Justfile", ".justfile"];
|
|
2298
|
+
var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
2299
|
+
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2300
|
+
var MAX_CHANGED = 30;
|
|
2301
|
+
async function replaceFile(path, content) {
|
|
2302
|
+
const temporary = `${path}.${process14.pid}.tmp`;
|
|
2303
|
+
await writeFile2(temporary, content, { mode: statSync(path).mode & 511 });
|
|
2304
|
+
await rename(temporary, path);
|
|
2305
|
+
}
|
|
2306
|
+
async function projectFixers(dir) {
|
|
2307
|
+
const found = await candidates(dir, "fix");
|
|
2308
|
+
const named = (name) => found.find((step) => step.name === name);
|
|
2309
|
+
const all = named("fix");
|
|
2310
|
+
if (all !== undefined)
|
|
2311
|
+
return [all];
|
|
2312
|
+
return [named("lint:fix") ?? named("lint-fix"), named("format")].filter((step) => step !== undefined);
|
|
2313
|
+
}
|
|
2314
|
+
async function toolFixers(dir) {
|
|
2315
|
+
const fixers = [];
|
|
2316
|
+
const makefile = await firstFile(dir, MAKEFILES);
|
|
2317
|
+
const justfile = await firstFile(dir, JUSTFILES2);
|
|
2318
|
+
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2319
|
+
if (makefile !== undefined) {
|
|
2320
|
+
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2321
|
+
const path = join8(cwd, makefile);
|
|
2322
|
+
const current = await Bun.file(path).text();
|
|
2323
|
+
const { content, targets } = declarePhony(current, (name) => existsSync2(join8(cwd, name)));
|
|
2324
|
+
if (content !== current)
|
|
2325
|
+
await replaceFile(path, content);
|
|
2326
|
+
return `.PHONY: ${targets.join(" ")}`;
|
|
2327
|
+
} });
|
|
2328
|
+
}
|
|
2329
|
+
if (justfile !== undefined)
|
|
2330
|
+
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2331
|
+
if (await Bun.file(join8(dir, "go.mod")).exists())
|
|
2332
|
+
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2333
|
+
if (await Bun.file(join8(dir, "Cargo.toml")).exists())
|
|
2334
|
+
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2335
|
+
if (ruff)
|
|
2336
|
+
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
2337
|
+
return fixers;
|
|
2338
|
+
}
|
|
2339
|
+
async function fixers(dir) {
|
|
2340
|
+
const project = await projectFixers(dir);
|
|
2341
|
+
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
2342
|
+
const php = csFixer === undefined || project.some((fixer) => fixer.source === "composer.json") ? [] : [{ name: "php-cs-fixer", command: "vendor/bin/php-cs-fixer fix", source: csFixer }];
|
|
2343
|
+
return [...project, ...php, ...await toolFixers(dir)];
|
|
2344
|
+
}
|
|
2345
|
+
function runsInService(fixer) {
|
|
2346
|
+
return fixer.write === undefined && fixer.requires === undefined;
|
|
2347
|
+
}
|
|
2348
|
+
async function runFixer(fixer, placement, cwd, logFile, settings) {
|
|
2349
|
+
if (fixer.write === undefined && placement !== undefined)
|
|
2350
|
+
return runStep(shellIn(placement, fixer.command, { [RUNNING]: "1" }), cwd, logFile, { ...settings, env: { [RUNNING]: "1" } });
|
|
2351
|
+
if (fixer.write === undefined)
|
|
2352
|
+
return runStep(fixer.command, cwd, logFile, { ...settings, env: { [RUNNING]: "1" } });
|
|
2353
|
+
const started = Date.now();
|
|
2354
|
+
let outcome;
|
|
2355
|
+
try {
|
|
2356
|
+
outcome = { ok: true, ms: 0, output: await fixer.write(cwd) };
|
|
2357
|
+
} catch (error) {
|
|
2358
|
+
outcome = { ok: false, ms: 0, output: error instanceof Error ? error.message : String(error) };
|
|
2359
|
+
}
|
|
2360
|
+
await writeFile2(logFile, outcome.output, { mode: 384, flag: "wx" });
|
|
2361
|
+
return { ...outcome, ms: Date.now() - started };
|
|
2362
|
+
}
|
|
2363
|
+
function printChanged(changed) {
|
|
2364
|
+
if (changed.length === 0) {
|
|
2365
|
+
console.log("nothing changed");
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
console.log(`changed ${changed.length} file${changed.length === 1 ? "" : "s"}:`);
|
|
2369
|
+
for (const path of changed.slice(0, MAX_CHANGED))
|
|
2370
|
+
console.log(` ${path}`);
|
|
2371
|
+
if (changed.length > MAX_CHANGED)
|
|
2372
|
+
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2373
|
+
}
|
|
2374
|
+
async function fix(args, cwd = process14.cwd()) {
|
|
2375
|
+
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"]] });
|
|
2376
|
+
return runFixers(parsed.values, cwd);
|
|
2377
|
+
}
|
|
2378
|
+
async function runFixers(values, cwd) {
|
|
2379
|
+
const parsed = { values };
|
|
2380
|
+
const settings = placeSettings(values);
|
|
2381
|
+
if (process14.env[RUNNING] !== undefined)
|
|
2382
|
+
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2383
|
+
const found = await fixers(cwd);
|
|
2384
|
+
if (found.length === 0)
|
|
2385
|
+
fail("nothing to fix here: no fix, lint:fix or format script, php-cs-fixer config, Makefile, Justfile, go.mod, Cargo.toml nor ruff config");
|
|
2386
|
+
const picked = pick(found, parsed.values.only, "fixer");
|
|
2387
|
+
const placements = new Map;
|
|
2388
|
+
for (const fixer of picked)
|
|
2389
|
+
placements.set(fixer, runsInService(fixer) ? await place(cwd, programOf(fixer.command), settings) : undefined);
|
|
2390
|
+
const json = parsed.values.json === true;
|
|
2391
|
+
const missing = (fixer) => fixer.requires !== undefined && Bun.which(fixer.requires) === null;
|
|
2392
|
+
if (parsed.values.list === true) {
|
|
2393
|
+
if (json)
|
|
2394
|
+
printJson(picked.map((fixer) => ({ name: fixer.name, command: fixer.command, source: fixer.source, ...placements.get(fixer) === undefined ? {} : { in: placements.get(fixer)?.service }, ...missing(fixer) ? { needs: fixer.requires } : {} })));
|
|
2395
|
+
else
|
|
2396
|
+
console.log(table(picked.map((fixer) => [fixer.name, fixer.command, missing(fixer) ? `${fixer.source}, needs ${fixer.requires}` : fixer.source, placements.get(fixer)?.service ?? "host"])));
|
|
2397
|
+
return 0;
|
|
2398
|
+
}
|
|
2399
|
+
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2400
|
+
const directory = await logDirectory(cwd);
|
|
2401
|
+
const held = holdSignals();
|
|
2402
|
+
const runSettings = { ...timeoutMs === undefined ? {} : { timeoutMs }, held };
|
|
2403
|
+
const stack = new Stack;
|
|
2404
|
+
const width = Math.max(...picked.map((fixer) => fixer.name.length));
|
|
2405
|
+
const before = await dirtyFiles(cwd);
|
|
2406
|
+
const ran = [];
|
|
2407
|
+
let failed = 0;
|
|
2408
|
+
let timedOut = false;
|
|
2409
|
+
try {
|
|
2410
|
+
for (const fixer of picked) {
|
|
2411
|
+
if (held.signal !== undefined)
|
|
2412
|
+
break;
|
|
2413
|
+
if (missing(fixer)) {
|
|
2414
|
+
if (!json)
|
|
2415
|
+
console.log(`skip ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2416
|
+
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
const logFile = join8(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2420
|
+
const placement = placements.get(fixer);
|
|
2421
|
+
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2422
|
+
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
2423
|
+
if (!json)
|
|
2424
|
+
printOutcome(fixer.name, width, placement === undefined ? fixer.command : `${fixer.command} (in ${placement.service})`, logFile, outcome);
|
|
2425
|
+
ran.push(outcomeJson(fixer.name, fixer.command, logFile, outcome, placement?.service));
|
|
2426
|
+
if (outcome.timedOut === true)
|
|
2427
|
+
timedOut = true;
|
|
2428
|
+
if (!outcome.ok)
|
|
2429
|
+
failed++;
|
|
2430
|
+
}
|
|
2431
|
+
} finally {
|
|
2432
|
+
held.release();
|
|
2433
|
+
}
|
|
2434
|
+
const after = before && await dirtyFiles(cwd);
|
|
2435
|
+
const changed = before !== undefined && after !== undefined ? changedFiles(before, after) : null;
|
|
2436
|
+
if (json)
|
|
2437
|
+
printJson({ fixers: ran, changed });
|
|
2438
|
+
else if (changed !== null)
|
|
2439
|
+
printChanged(changed);
|
|
2440
|
+
if (held.signal !== undefined)
|
|
2441
|
+
return exitCodeOf(null, held.signal);
|
|
2442
|
+
if (timedOut)
|
|
2443
|
+
return 2;
|
|
2444
|
+
return failed === 0 ? 0 : 1;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// src/narrow.ts
|
|
2448
|
+
import { existsSync as existsSync3 } from "fs";
|
|
2449
|
+
import { basename as basename3, dirname as dirname4, extname, join as join9 } from "path";
|
|
2450
|
+
var {$: $2 } = globalThis.Bun;
|
|
2451
|
+
var LINTERS = /^(?:keslint|eslint|oxlint)\b/;
|
|
2452
|
+
var LINTABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".svelte"]);
|
|
2453
|
+
var TEST_RUNNER = /^(?:bun test|\$npm_execpath test)\b/;
|
|
2454
|
+
var TEST_FILE = /\.(?:test|spec)\.[jt]sx?$/;
|
|
2455
|
+
var WHITESPACE = /\s+/;
|
|
2456
|
+
async function changedPaths(dir) {
|
|
2457
|
+
const tracked = await $2`git diff --name-only --relative -z HEAD`.cwd(dir).quiet().nothrow();
|
|
2458
|
+
const untracked = await $2`git ls-files -z --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
2459
|
+
if (tracked.exitCode !== 0 || untracked.exitCode !== 0)
|
|
2460
|
+
return;
|
|
2461
|
+
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync3(join9(dir, path)));
|
|
2462
|
+
}
|
|
2463
|
+
function siblingTests(path, exists) {
|
|
2464
|
+
const extension = extname(path);
|
|
2465
|
+
const name = basename3(path, extension);
|
|
2466
|
+
const dir = dirname4(path);
|
|
2467
|
+
const folders = [dir, join9(dir, "tests"), join9(dir, "..", "tests"), join9(dir, "__tests__")];
|
|
2468
|
+
const found = new Set;
|
|
2469
|
+
for (const folder of folders) {
|
|
2470
|
+
for (const kind of ["test", "spec"]) {
|
|
2471
|
+
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) => join9(folder, file))) {
|
|
2472
|
+
if (exists(candidate))
|
|
2473
|
+
found.add(candidate);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return [...found];
|
|
2478
|
+
}
|
|
2479
|
+
function isBare(script, tool) {
|
|
2480
|
+
return tool.test(script.trim()) && script.trim().replace(tool, "").split(WHITESPACE).every((word) => word.startsWith("-") || word === "");
|
|
2481
|
+
}
|
|
2482
|
+
async function narrow2(step, dir, changed) {
|
|
2483
|
+
const script = step.source === "package.json" ? (await scriptText(dir, step.name))?.trim() : undefined;
|
|
2484
|
+
const full = (why) => ({ command: step.command, note: `in full, ${why}` });
|
|
2485
|
+
if (script !== undefined && step.name === "lint" && isBare(script, LINTERS)) {
|
|
2486
|
+
const files = changed.filter((path) => LINTABLE.has(extname(path)));
|
|
2487
|
+
return files.length === 0 ? { command: "true", note: "nothing changed to lint" } : { command: `${step.command} -- ${files.map(quote).join(" ")}`, note: `${files.length} changed file${files.length === 1 ? "" : "s"}` };
|
|
2488
|
+
}
|
|
2489
|
+
if (script !== undefined && step.name === "test" && isBare(script, TEST_RUNNER)) {
|
|
2490
|
+
const tests = new Set;
|
|
2491
|
+
for (const path of changed) {
|
|
2492
|
+
if (TEST_FILE.test(path)) {
|
|
2493
|
+
tests.add(path);
|
|
2494
|
+
} else {
|
|
2495
|
+
for (const test of siblingTests(path, (candidate) => existsSync3(join9(dir, candidate)))) {
|
|
2496
|
+
tests.add(test);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
if (tests.size === 0)
|
|
2501
|
+
return full("no test sits next to the changed files");
|
|
2502
|
+
return { command: `${step.command} -- ${[...tests].map((test) => quote(`./${test}`)).join(" ")}`, note: `${tests.size} test file${tests.size === 1 ? "" : "s"}` };
|
|
2503
|
+
}
|
|
2504
|
+
return full(`${step.name} cannot be narrowed`);
|
|
2505
|
+
}
|
|
2506
|
+
function quote(path) {
|
|
2507
|
+
return `'${path.replaceAll("'", "'\\''")}'`;
|
|
2508
|
+
}
|
|
2509
|
+
async function scriptText(dir, name) {
|
|
2510
|
+
const text = await read(dir, "package.json");
|
|
2511
|
+
if (text === undefined)
|
|
2512
|
+
return;
|
|
2513
|
+
try {
|
|
2514
|
+
const value = JSON.parse(text).scripts?.[name];
|
|
2515
|
+
return typeof value === "string" ? value : undefined;
|
|
2516
|
+
} catch {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2208
2521
|
// src/check.ts
|
|
2209
|
-
var usage2 = `check [--only <steps>] [--changed] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2522
|
+
var usage2 = `check [--only <steps>] [--changed] [--failed] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2523
|
+
check --fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
2210
2524
|
|
|
2211
2525
|
Runs the repo's check, typecheck, lint and test steps, from package.json scripts (through bun run), composer.json, a Justfile or a Makefile, and for PHP from phpstan.neon (typecheck), .php-cs-fixer.dist.php (lint, dry-run) and phpunit.xml.dist (test) when composer.json has no such script.
|
|
2212
2526
|
A folder without steps but with subfolders that have some (api/ and client/) runs each one's, each line naming its subfolder.
|
|
@@ -2214,32 +2528,13 @@ A step runs inside the docker compose service that bind-mounts its folder (found
|
|
|
2214
2528
|
A passing step is one line, a failing one shows only what failed, and each step's full output is saved to the file whose path ends its line.
|
|
2215
2529
|
With --changed, lint and test run on the files changed against HEAD (staged, unstaged and untracked) when their script is a bare linter (keslint, eslint, oxlint) or a bare \`bun test\`: lint on the changed source files, test on the changed test files and the tests next to the changed sources. Every other step, and a test step finding no test for the diff, runs in full and the line says so.
|
|
2216
2530
|
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2531
|
+
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.
|
|
2532
|
+
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.
|
|
2217
2533
|
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.
|
|
2218
|
-
--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.`;
|
|
2219
|
-
var options = {
|
|
2220
|
-
list: { type: "boolean", short: "l", description: "print the steps found, the commands that run them and where (host or service), without running them" },
|
|
2221
|
-
only: { type: "string", short: "o", description: `comma separated steps to run, among ${STEP_NAMES.join(", ")}` },
|
|
2222
|
-
timeout: { type: "string", short: "t", description: "longest a step may run before it is ended (30s, 5m, 1h), none by default" },
|
|
2223
|
-
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" },
|
|
2224
|
-
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions (needs the slot bin)" },
|
|
2225
|
-
...placeOptions,
|
|
2226
|
-
json: jsonOption()
|
|
2227
|
-
};
|
|
2534
|
+
--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.`;
|
|
2228
2535
|
function slotted(command) {
|
|
2229
2536
|
return `slot -- sh -c ${shellQuote(command)}`;
|
|
2230
2537
|
}
|
|
2231
|
-
var COMMA = /\s*,\s*/;
|
|
2232
|
-
function pick(steps, only) {
|
|
2233
|
-
if (only === undefined)
|
|
2234
|
-
return steps;
|
|
2235
|
-
const names = only.split(COMMA).filter((name) => name !== "");
|
|
2236
|
-
if (names.length === 0)
|
|
2237
|
-
fail(`--only names no step, found ${steps.map((step) => step.name).join(", ")}`);
|
|
2238
|
-
const unknown = names.filter((name) => !steps.some((step) => step.name === name));
|
|
2239
|
-
if (unknown.length > 0)
|
|
2240
|
-
fail(`no ${unknown.join(", ")} step here, found ${[...new Set(steps.map((step) => step.name))].join(", ")}`);
|
|
2241
|
-
return steps.filter((step) => names.includes(step.name));
|
|
2242
|
-
}
|
|
2243
2538
|
async function plan(steps, settings) {
|
|
2244
2539
|
const planned = [];
|
|
2245
2540
|
for (const { project, ...step } of steps)
|
|
@@ -2264,14 +2559,33 @@ async function narrowed(steps) {
|
|
|
2264
2559
|
function launch(step) {
|
|
2265
2560
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2266
2561
|
}
|
|
2267
|
-
async function check(args, cwd =
|
|
2562
|
+
async function check(args, cwd = process15.cwd()) {
|
|
2268
2563
|
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"]] });
|
|
2269
2564
|
const settings = placeSettings(parsed.values);
|
|
2565
|
+
if (parsed.values.fix === true) {
|
|
2566
|
+
for (const flag of ["changed", "failed", "slot"]) {
|
|
2567
|
+
if (parsed.values[flag] === true)
|
|
2568
|
+
fail(`--${flag} does not apply to --fix`);
|
|
2569
|
+
}
|
|
2570
|
+
return runFixers(parsed.values, cwd);
|
|
2571
|
+
}
|
|
2572
|
+
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2573
|
+
if (parsed.values.slot === true && Bun.which("slot", { PATH: process15.env.PATH ?? "" }) === null)
|
|
2574
|
+
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2270
2575
|
const projects = await discoverProjects(cwd);
|
|
2271
2576
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
2272
2577
|
if (found.length === 0)
|
|
2273
2578
|
fail(`no ${STEP_NAMES.join(", ")} step in package.json, composer.json, a Justfile, a Makefile or a PHP tool's config, nor in a subfolder`);
|
|
2274
|
-
|
|
2579
|
+
let wanted = pick(found, parsed.values.only);
|
|
2580
|
+
if (parsed.values.failed === true) {
|
|
2581
|
+
const failed = await lastFailed(cwd);
|
|
2582
|
+
if (failed === undefined || failed.length === 0)
|
|
2583
|
+
fail("no failed step in the last run of this folder");
|
|
2584
|
+
wanted = wanted.filter((step) => failed.includes(step.project.name === undefined ? step.name : `${step.project.name}/${step.name}`));
|
|
2585
|
+
if (wanted.length === 0)
|
|
2586
|
+
fail(`none of the steps picked failed in the last run, which failed ${failed.join(", ")}`);
|
|
2587
|
+
}
|
|
2588
|
+
const planned = await plan(wanted, settings);
|
|
2275
2589
|
const steps = parsed.values.changed === true ? await narrowed(planned) : planned;
|
|
2276
2590
|
const json = parsed.values.json === true;
|
|
2277
2591
|
if (parsed.values.list === true) {
|
|
@@ -2281,9 +2595,6 @@ async function check(args, cwd = process13.cwd()) {
|
|
|
2281
2595
|
console.log(table(steps.map((step) => [step.label, step.command, step.source, step.placement?.service ?? "host"])));
|
|
2282
2596
|
return 0;
|
|
2283
2597
|
}
|
|
2284
|
-
if (parsed.values.slot === true && Bun.which("slot", { PATH: process13.env.PATH ?? "" }) === null)
|
|
2285
|
-
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2286
|
-
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2287
2598
|
const directory = await logDirectory(cwd);
|
|
2288
2599
|
const held = holdSignals();
|
|
2289
2600
|
const stack = new Stack;
|
|
@@ -2291,7 +2602,7 @@ async function check(args, cwd = process13.cwd()) {
|
|
|
2291
2602
|
const outcomes = [];
|
|
2292
2603
|
try {
|
|
2293
2604
|
for (const step of steps) {
|
|
2294
|
-
const logFile =
|
|
2605
|
+
const logFile = join10(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2295
2606
|
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2296
2607
|
const command = parsed.values.slot === true ? slotted(launch(step)) : launch(step);
|
|
2297
2608
|
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held }) : await refusedStep(down, logFile);
|
|
@@ -2304,6 +2615,7 @@ async function check(args, cwd = process13.cwd()) {
|
|
|
2304
2615
|
} finally {
|
|
2305
2616
|
held.release();
|
|
2306
2617
|
}
|
|
2618
|
+
await writeFile3(join10(directory, RESULTS_FILE), JSON.stringify(outcomes.map(({ name, ok }) => ({ name, ok }))), { mode: 384 });
|
|
2307
2619
|
if (json)
|
|
2308
2620
|
printJson(outcomes);
|
|
2309
2621
|
if (held.signal !== undefined)
|
|
@@ -2314,4 +2626,4 @@ async function check(args, cwd = process13.cwd()) {
|
|
|
2314
2626
|
}
|
|
2315
2627
|
|
|
2316
2628
|
// src/cli.ts
|
|
2317
|
-
|
|
2629
|
+
process16.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|