@kaynooo/cli-check 0.9.1 → 0.11.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 +20 -0
- package/dist/cli.js +440 -286
- package/dist/errs-cli.js +217 -157
- package/dist/fix-cli.js +454 -300
- package/dist/j-cli.js +1779 -0
- package/package.json +5 -4
package/dist/fix-cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/fix-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process15 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process5 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/format.ts
|
|
@@ -375,6 +375,55 @@ function printJson(value) {
|
|
|
375
375
|
console.log(JSON.stringify(value, undefined, 2));
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
// ../kit/src/help.ts
|
|
379
|
+
import process3 from "process";
|
|
380
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
381
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
382
|
+
var FULL_STOP = /\.$/;
|
|
383
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
384
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
385
|
+
}
|
|
386
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
387
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
388
|
+
`);
|
|
389
|
+
}
|
|
390
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
391
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
392
|
+
}
|
|
393
|
+
function wantsHelpJson(env = process3.env) {
|
|
394
|
+
return env.KIT_HELP === "json";
|
|
395
|
+
}
|
|
396
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
397
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
398
|
+
`);
|
|
399
|
+
const first = lines[0];
|
|
400
|
+
const colon = first.indexOf(": ");
|
|
401
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
402
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
403
|
+
return {
|
|
404
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
405
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
406
|
+
...replaces === undefined ? {} : { replaces },
|
|
407
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
411
|
+
if (examples.length === 0)
|
|
412
|
+
return [];
|
|
413
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
414
|
+
}
|
|
415
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
416
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
417
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
418
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
419
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
420
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
421
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
422
|
+
});
|
|
423
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
424
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
378
427
|
// ../kit/src/text.ts
|
|
379
428
|
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
380
429
|
function stripAnsi(text) {
|
|
@@ -397,8 +446,33 @@ function closest(name, names) {
|
|
|
397
446
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
398
447
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
399
448
|
}
|
|
449
|
+
// ../kit/src/input.ts
|
|
450
|
+
import process4 from "process";
|
|
451
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
452
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
453
|
+
function duration(value, name, fallback, unit = "s") {
|
|
454
|
+
if (value === undefined)
|
|
455
|
+
return fallback;
|
|
456
|
+
const match = DURATION.exec(value.trim());
|
|
457
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
458
|
+
if (ms < 1)
|
|
459
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
460
|
+
return ms;
|
|
461
|
+
}
|
|
462
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
463
|
+
if (path === "-") {
|
|
464
|
+
if (process4.stdin.isTTY)
|
|
465
|
+
fail(noStdin);
|
|
466
|
+
return Bun.stdin.text();
|
|
467
|
+
}
|
|
468
|
+
const file = Bun.file(path);
|
|
469
|
+
if (!await file.exists())
|
|
470
|
+
fail(`no file ${path}`);
|
|
471
|
+
return file.text();
|
|
472
|
+
}
|
|
400
473
|
|
|
401
474
|
// ../kit/src/args.ts
|
|
475
|
+
var DASHES = /^-+/;
|
|
402
476
|
function jsonOption(holds) {
|
|
403
477
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
404
478
|
}
|
|
@@ -442,58 +516,11 @@ class Completing {
|
|
|
442
516
|
}
|
|
443
517
|
}
|
|
444
518
|
var completion = { active: false };
|
|
445
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
446
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
447
|
-
var FULL_STOP = /\.$/;
|
|
448
|
-
var DASHES = /^-+/;
|
|
449
|
-
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
450
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
451
|
-
}
|
|
452
|
-
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
453
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
454
|
-
`);
|
|
455
|
-
}
|
|
456
|
-
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
457
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
458
|
-
}
|
|
459
|
-
function wantsHelpJson(env = process3.env) {
|
|
460
|
-
return env.KIT_HELP === "json";
|
|
461
|
-
}
|
|
462
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
463
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
464
|
-
`);
|
|
465
|
-
const first = lines[0];
|
|
466
|
-
const colon = first.indexOf(": ");
|
|
467
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
468
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
469
|
-
return {
|
|
470
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
471
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
472
|
-
...replaces === undefined ? {} : { replaces },
|
|
473
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
477
|
-
if (examples.length === 0)
|
|
478
|
-
return [];
|
|
479
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
480
|
-
}
|
|
481
|
-
function optionRows(options, colors = paint(process3.stdout)) {
|
|
482
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
483
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
484
|
-
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
485
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
486
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
487
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
488
|
-
});
|
|
489
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
490
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
491
|
-
}
|
|
492
519
|
var OUTPUT_OPTIONS = {
|
|
493
520
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
494
521
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
495
522
|
};
|
|
496
|
-
function applyOutput(color, plain, env =
|
|
523
|
+
function applyOutput(color, plain, env = process5.env) {
|
|
497
524
|
const when = plain === true ? "never" : color ?? "auto";
|
|
498
525
|
if (when === "auto")
|
|
499
526
|
return;
|
|
@@ -650,31 +677,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
650
677
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
651
678
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
652
679
|
}
|
|
653
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
654
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
655
|
-
function duration(value, name, fallback, unit = "s") {
|
|
656
|
-
if (value === undefined)
|
|
657
|
-
return fallback;
|
|
658
|
-
const match = DURATION.exec(value.trim());
|
|
659
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
660
|
-
if (ms < 1)
|
|
661
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
|
-
return ms;
|
|
663
|
-
}
|
|
664
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
665
|
-
if (path === "-") {
|
|
666
|
-
if (process3.stdin.isTTY)
|
|
667
|
-
fail(noStdin);
|
|
668
|
-
return Bun.stdin.text();
|
|
669
|
-
}
|
|
670
|
-
const file = Bun.file(path);
|
|
671
|
-
if (!await file.exists())
|
|
672
|
-
fail(`no file ${path}`);
|
|
673
|
-
return file.text();
|
|
674
|
-
}
|
|
675
680
|
// ../kit/src/process.ts
|
|
676
681
|
import { constants } from "os";
|
|
677
|
-
import
|
|
682
|
+
import process6 from "process";
|
|
678
683
|
var KILL_GRACE_MS = 2000;
|
|
679
684
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
680
685
|
function exitCodeOf(code, signal) {
|
|
@@ -696,7 +701,7 @@ function holdSignals(cleanup) {
|
|
|
696
701
|
},
|
|
697
702
|
release: () => {
|
|
698
703
|
for (const signal of SIGNALS)
|
|
699
|
-
|
|
704
|
+
process6.off(signal, onSignal);
|
|
700
705
|
}
|
|
701
706
|
};
|
|
702
707
|
function onSignal(signal) {
|
|
@@ -709,10 +714,10 @@ function holdSignals(cleanup) {
|
|
|
709
714
|
return;
|
|
710
715
|
held.release();
|
|
711
716
|
cleanup(signal);
|
|
712
|
-
|
|
717
|
+
process6.kill(process6.pid, signal);
|
|
713
718
|
}
|
|
714
719
|
for (const signal of SIGNALS)
|
|
715
|
-
|
|
720
|
+
process6.on(signal, onSignal);
|
|
716
721
|
return held;
|
|
717
722
|
}
|
|
718
723
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -726,7 +731,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
726
731
|
return;
|
|
727
732
|
try {
|
|
728
733
|
if (grouped)
|
|
729
|
-
|
|
734
|
+
process6.kill(-proc.pid, killing);
|
|
730
735
|
else
|
|
731
736
|
proc.kill(killing);
|
|
732
737
|
} catch {}
|
|
@@ -800,15 +805,111 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
800
805
|
var RESET_STYLE = `${ESC}[0m`;
|
|
801
806
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
802
807
|
// ../kit/src/cli.ts
|
|
803
|
-
import
|
|
808
|
+
import process9 from "process";
|
|
809
|
+
|
|
810
|
+
// ../kit/src/usage.ts
|
|
811
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
812
|
+
import { homedir as homedir2 } from "os";
|
|
813
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
814
|
+
import process8 from "process";
|
|
815
|
+
|
|
816
|
+
// ../kit/src/logs.ts
|
|
817
|
+
import { lstatSync, openSync } from "fs";
|
|
818
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
819
|
+
import { homedir, tmpdir } from "os";
|
|
820
|
+
import { join } from "path";
|
|
821
|
+
import process7 from "process";
|
|
822
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
823
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
824
|
+
function isPrivateDirectory(path) {
|
|
825
|
+
try {
|
|
826
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
827
|
+
return info !== undefined && info.isDirectory() && info.uid === (process7.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
828
|
+
} catch {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
async function privateLogDirectory(name, env = process7.env) {
|
|
833
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
834
|
+
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
835
|
+
const path = join(base, name);
|
|
836
|
+
try {
|
|
837
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
838
|
+
if (isPrivateDirectory(path))
|
|
839
|
+
return path;
|
|
840
|
+
} catch {}
|
|
841
|
+
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
842
|
+
}
|
|
843
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
844
|
+
let names;
|
|
845
|
+
try {
|
|
846
|
+
names = await readdir(dir);
|
|
847
|
+
} catch {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
for (const name of names) {
|
|
851
|
+
const path = join(dir, name);
|
|
852
|
+
try {
|
|
853
|
+
const info = await stat(path);
|
|
854
|
+
if (info.isDirectory())
|
|
855
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
856
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
857
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
858
|
+
} catch {
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// ../kit/src/usage.ts
|
|
865
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
866
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
867
|
+
var LONGEST_NAME = 40;
|
|
868
|
+
var usageError;
|
|
869
|
+
function noteUsageError(message) {
|
|
870
|
+
usageError = message;
|
|
871
|
+
}
|
|
872
|
+
function stateHome(env = process8.env) {
|
|
873
|
+
const dir = env.XDG_STATE_HOME;
|
|
874
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
|
|
875
|
+
}
|
|
876
|
+
function usagePath(env = process8.env) {
|
|
877
|
+
return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
878
|
+
}
|
|
879
|
+
function usageRecorded(env = process8.env) {
|
|
880
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
881
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
882
|
+
}
|
|
883
|
+
function flagNames(argv) {
|
|
884
|
+
const end = argv.indexOf("--");
|
|
885
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
886
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
887
|
+
}
|
|
888
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
889
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
890
|
+
usageError = undefined;
|
|
891
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
892
|
+
}
|
|
893
|
+
function recordUsage(entry, env = process8.env) {
|
|
894
|
+
if (!usageRecorded(env))
|
|
895
|
+
return;
|
|
896
|
+
try {
|
|
897
|
+
const path = usagePath(env);
|
|
898
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
899
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
900
|
+
`, { mode: 384 });
|
|
901
|
+
} catch {}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// ../kit/src/cli.ts
|
|
804
905
|
var LEVEL_OPTIONS = {
|
|
805
906
|
...OUTPUT_OPTIONS,
|
|
806
907
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
807
908
|
};
|
|
808
909
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
809
910
|
function printError(prefix, message, hint, cause) {
|
|
810
|
-
const colors = paint(
|
|
811
|
-
const styled = takesControlCodes(
|
|
911
|
+
const colors = paint(process9.stderr);
|
|
912
|
+
const styled = takesControlCodes(process9.stderr);
|
|
812
913
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
813
914
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
814
915
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -827,6 +928,8 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
827
928
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
828
929
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
829
930
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
931
|
+
if (error instanceof UsageError)
|
|
932
|
+
noteUsageError(error.message);
|
|
830
933
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
831
934
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
832
935
|
return error instanceof Exit ? error.code : 1;
|
|
@@ -888,65 +991,22 @@ async function printCandidates(found) {
|
|
|
888
991
|
console.log(line);
|
|
889
992
|
return 0;
|
|
890
993
|
}
|
|
891
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
994
|
+
async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
|
|
892
995
|
if (argv[0] === COMPLETE)
|
|
893
996
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
894
997
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
895
998
|
console.log(version);
|
|
896
999
|
return 0;
|
|
897
1000
|
}
|
|
1001
|
+
let code;
|
|
898
1002
|
try {
|
|
899
|
-
|
|
1003
|
+
code = await run(argv);
|
|
900
1004
|
} catch (error) {
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
// ../kit/src/logs.ts
|
|
905
|
-
import { lstatSync, openSync } from "fs";
|
|
906
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
907
|
-
import { homedir, tmpdir } from "os";
|
|
908
|
-
import { join } from "path";
|
|
909
|
-
import process6 from "process";
|
|
910
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
911
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
912
|
-
function isPrivateDirectory(path) {
|
|
913
|
-
try {
|
|
914
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
915
|
-
return info !== undefined && info.isDirectory() && info.uid === (process6.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
916
|
-
} catch {
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
async function privateLogDirectory(name, env = process6.env) {
|
|
921
|
-
const runtime = env.XDG_RUNTIME_DIR;
|
|
922
|
-
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
923
|
-
const path = join(base, name);
|
|
924
|
-
try {
|
|
925
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
926
|
-
if (isPrivateDirectory(path))
|
|
927
|
-
return path;
|
|
928
|
-
} catch {}
|
|
929
|
-
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
930
|
-
}
|
|
931
|
-
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
932
|
-
let names;
|
|
933
|
-
try {
|
|
934
|
-
names = await readdir(dir);
|
|
935
|
-
} catch {
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
for (const name of names) {
|
|
939
|
-
const path = join(dir, name);
|
|
940
|
-
try {
|
|
941
|
-
const info = await stat(path);
|
|
942
|
-
if (info.isDirectory())
|
|
943
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
944
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
945
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
946
|
-
} catch {
|
|
947
|
-
continue;
|
|
948
|
-
}
|
|
1005
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
949
1006
|
}
|
|
1007
|
+
if (usage !== false)
|
|
1008
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1009
|
+
return code;
|
|
950
1010
|
}
|
|
951
1011
|
// ../kit/src/secrets.ts
|
|
952
1012
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -955,17 +1015,17 @@ var {Glob } = globalThis.Bun;
|
|
|
955
1015
|
var SESSION_FILES = new Glob("*.json");
|
|
956
1016
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
957
1017
|
// package.json
|
|
958
|
-
var version = "0.
|
|
1018
|
+
var version = "0.11.0";
|
|
959
1019
|
|
|
960
1020
|
// src/fix.ts
|
|
961
|
-
import { existsSync as
|
|
1021
|
+
import { existsSync as existsSync3, statSync } from "fs";
|
|
962
1022
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
963
|
-
import { join as
|
|
964
|
-
import
|
|
1023
|
+
import { join as join9 } from "path";
|
|
1024
|
+
import process14 from "process";
|
|
965
1025
|
|
|
966
1026
|
// src/changes.ts
|
|
967
1027
|
import { stat as stat2 } from "fs/promises";
|
|
968
|
-
import { join as
|
|
1028
|
+
import { join as join3 } from "path";
|
|
969
1029
|
var {$ } = globalThis.Bun;
|
|
970
1030
|
async function dirtyFiles(dir) {
|
|
971
1031
|
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
@@ -974,7 +1034,7 @@ async function dirtyFiles(dir) {
|
|
|
974
1034
|
const files = new Map;
|
|
975
1035
|
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
976
1036
|
try {
|
|
977
|
-
const { size, mtimeMs } = await stat2(
|
|
1037
|
+
const { size, mtimeMs } = await stat2(join3(dir, path));
|
|
978
1038
|
files.set(path, `${size}:${mtimeMs}`);
|
|
979
1039
|
} catch {
|
|
980
1040
|
files.set(path, "");
|
|
@@ -987,8 +1047,8 @@ function changedFiles(before, after) {
|
|
|
987
1047
|
}
|
|
988
1048
|
|
|
989
1049
|
// src/check.ts
|
|
990
|
-
import { join as
|
|
991
|
-
import
|
|
1050
|
+
import { join as join8 } from "path";
|
|
1051
|
+
import process13 from "process";
|
|
992
1052
|
|
|
993
1053
|
// ../kit/src/shell.ts
|
|
994
1054
|
var SEPARATORS = new Set([`
|
|
@@ -1031,9 +1091,9 @@ function shellQuote(word) {
|
|
|
1031
1091
|
|
|
1032
1092
|
// src/compose.ts
|
|
1033
1093
|
import { existsSync } from "fs";
|
|
1034
|
-
import { homedir as
|
|
1035
|
-
import { basename, dirname, join as
|
|
1036
|
-
import
|
|
1094
|
+
import { homedir as homedir3 } from "os";
|
|
1095
|
+
import { basename, dirname as dirname2, join as join4, relative, resolve } from "path";
|
|
1096
|
+
import process11 from "process";
|
|
1037
1097
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1038
1098
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1039
1099
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1062,7 +1122,7 @@ function toolWords(program) {
|
|
|
1062
1122
|
}
|
|
1063
1123
|
async function readFiles(dir, names) {
|
|
1064
1124
|
for (const name of names) {
|
|
1065
|
-
const handle = Bun.file(
|
|
1125
|
+
const handle = Bun.file(join4(dir, name));
|
|
1066
1126
|
if (await handle.exists())
|
|
1067
1127
|
return { name, text: await handle.text() };
|
|
1068
1128
|
}
|
|
@@ -1077,7 +1137,7 @@ async function variables(composeDir) {
|
|
|
1077
1137
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1078
1138
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1079
1139
|
}
|
|
1080
|
-
for (const [key, value] of Object.entries(
|
|
1140
|
+
for (const [key, value] of Object.entries(process11.env)) {
|
|
1081
1141
|
if (value !== undefined)
|
|
1082
1142
|
env[key] = value;
|
|
1083
1143
|
}
|
|
@@ -1097,7 +1157,7 @@ function interpolate(text, env) {
|
|
|
1097
1157
|
function bindSource(source, composeDir, env) {
|
|
1098
1158
|
const path = interpolate(source, env);
|
|
1099
1159
|
if (path.startsWith("~"))
|
|
1100
|
-
return
|
|
1160
|
+
return join4(homedir3(), path.slice(1));
|
|
1101
1161
|
if (path.startsWith("/"))
|
|
1102
1162
|
return resolve(path);
|
|
1103
1163
|
return path.startsWith(".") ? resolve(composeDir, path) : undefined;
|
|
@@ -1144,7 +1204,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1144
1204
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1145
1205
|
const file = Bun.file(resolve(composeDir, name));
|
|
1146
1206
|
if (!await file.exists())
|
|
1147
|
-
fail(`COMPOSE_FILE names ${
|
|
1207
|
+
fail(`COMPOSE_FILE names ${join4(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1148
1208
|
files.push({ name, text: await file.text() });
|
|
1149
1209
|
}
|
|
1150
1210
|
return files;
|
|
@@ -1166,7 +1226,7 @@ async function readServices(composeDir) {
|
|
|
1166
1226
|
try {
|
|
1167
1227
|
parsed = parseServices(file.text, composeDir, env);
|
|
1168
1228
|
} catch (error) {
|
|
1169
|
-
fail(`cannot read ${
|
|
1229
|
+
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");
|
|
1170
1230
|
}
|
|
1171
1231
|
for (const [name, extra] of parsed) {
|
|
1172
1232
|
const known = services.get(name);
|
|
@@ -1178,11 +1238,11 @@ async function readServices(composeDir) {
|
|
|
1178
1238
|
function climb(dir) {
|
|
1179
1239
|
const folders = [dir];
|
|
1180
1240
|
let current = dir;
|
|
1181
|
-
while (!existsSync(
|
|
1182
|
-
current =
|
|
1241
|
+
while (!existsSync(join4(current, ".git")) && dirname2(current) !== current) {
|
|
1242
|
+
current = dirname2(current);
|
|
1183
1243
|
folders.push(current);
|
|
1184
1244
|
}
|
|
1185
|
-
return existsSync(
|
|
1245
|
+
return existsSync(join4(current, ".git")) ? folders : [dir];
|
|
1186
1246
|
}
|
|
1187
1247
|
function containerPath(service, dir) {
|
|
1188
1248
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1193,7 +1253,7 @@ function containerPath(service, dir) {
|
|
|
1193
1253
|
if (deepest === undefined)
|
|
1194
1254
|
return;
|
|
1195
1255
|
const inside = relative(deepest.source, dir);
|
|
1196
|
-
return inside === "" ? deepest.target :
|
|
1256
|
+
return inside === "" ? deepest.target : join4(deepest.target, inside);
|
|
1197
1257
|
}
|
|
1198
1258
|
var noticed = new Set;
|
|
1199
1259
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1213,7 +1273,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1213
1273
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1214
1274
|
return;
|
|
1215
1275
|
}
|
|
1216
|
-
if (Bun.which("docker", { PATH:
|
|
1276
|
+
if (Bun.which("docker", { PATH: process11.env.PATH ?? "" }) === null) {
|
|
1217
1277
|
if (service !== undefined)
|
|
1218
1278
|
fail(`--in ${service}: docker not found`);
|
|
1219
1279
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1265,7 +1325,7 @@ class Stack {
|
|
|
1265
1325
|
}
|
|
1266
1326
|
static async running(composeDir) {
|
|
1267
1327
|
try {
|
|
1268
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1328
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process11.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1269
1329
|
if (ran.code !== 0)
|
|
1270
1330
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1271
1331
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1296,10 +1356,209 @@ function placeSettings(values) {
|
|
|
1296
1356
|
return { service: values.in, host: values.host };
|
|
1297
1357
|
}
|
|
1298
1358
|
|
|
1299
|
-
// src/
|
|
1300
|
-
import {
|
|
1301
|
-
import { basename as basename2, join as
|
|
1302
|
-
|
|
1359
|
+
// src/narrow.ts
|
|
1360
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1361
|
+
import { basename as basename2, dirname as dirname3, extname, join as join6 } from "path";
|
|
1362
|
+
var {$: $2 } = globalThis.Bun;
|
|
1363
|
+
|
|
1364
|
+
// src/steps.ts
|
|
1365
|
+
import { readdir as readdir2 } from "fs/promises";
|
|
1366
|
+
import { join as join5 } from "path";
|
|
1367
|
+
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1368
|
+
var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1369
|
+
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1370
|
+
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1371
|
+
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1372
|
+
var JUST_TIMEOUT_MS = 1e4;
|
|
1373
|
+
var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"];
|
|
1374
|
+
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1375
|
+
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1376
|
+
async function readFirst(dir, files) {
|
|
1377
|
+
for (const file of files) {
|
|
1378
|
+
const handle = Bun.file(join5(dir, file));
|
|
1379
|
+
if (await handle.exists())
|
|
1380
|
+
return { file, text: await handle.text() };
|
|
1381
|
+
}
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
async function read(dir, ...files) {
|
|
1385
|
+
for (const file of files) {
|
|
1386
|
+
const handle = Bun.file(join5(dir, file));
|
|
1387
|
+
if (await handle.exists())
|
|
1388
|
+
return handle.text();
|
|
1389
|
+
}
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
function scripts(file, text) {
|
|
1393
|
+
try {
|
|
1394
|
+
const parsed = JSON.parse(text);
|
|
1395
|
+
return parsed.scripts ?? {};
|
|
1396
|
+
} catch {
|
|
1397
|
+
throw new Error(`${file} is not valid JSON`);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function targets(text) {
|
|
1401
|
+
return [...text.matchAll(TARGET)].map((match) => match[1] ?? "");
|
|
1402
|
+
}
|
|
1403
|
+
async function recipes(dir, file, text) {
|
|
1404
|
+
if (Bun.which("just") === null)
|
|
1405
|
+
return targets(text);
|
|
1406
|
+
try {
|
|
1407
|
+
const ran = await runCommand(["just", "--justfile", file, "--dump", "--dump-format", "json"], { cwd: dir, timeoutMs: JUST_TIMEOUT_MS });
|
|
1408
|
+
const dump = JSON.parse(ran.text);
|
|
1409
|
+
if (ran.code !== 0)
|
|
1410
|
+
return targets(text);
|
|
1411
|
+
return Object.entries(dump.recipes ?? {}).filter(([, recipe]) => recipe.private !== true && (recipe.parameters ?? []).every((parameter) => parameter.default !== null || parameter.kind === "star")).map(([name]) => name);
|
|
1412
|
+
} catch {
|
|
1413
|
+
return targets(text);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
function callsSelf(value, bin) {
|
|
1417
|
+
return typeof value === "string" && (value === bin || value.startsWith(`${bin} `) || value.startsWith(`${bin} `));
|
|
1418
|
+
}
|
|
1419
|
+
async function candidates(dir, bin) {
|
|
1420
|
+
const steps = [];
|
|
1421
|
+
const packageJson = await read(dir, "package.json");
|
|
1422
|
+
const composerJson = await read(dir, "composer.json");
|
|
1423
|
+
const justfile = await readFirst(dir, JUSTFILES);
|
|
1424
|
+
const makefile = await read(dir, ...MAKEFILES);
|
|
1425
|
+
if (packageJson !== undefined) {
|
|
1426
|
+
for (const [name, value] of Object.entries(scripts("package.json", packageJson))) {
|
|
1427
|
+
if (!callsSelf(value, bin))
|
|
1428
|
+
steps.push({ name, command: `bun run ${name}`, source: "package.json" });
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (composerJson !== undefined) {
|
|
1432
|
+
for (const name of Object.keys(scripts("composer.json", composerJson)))
|
|
1433
|
+
steps.push({ name, command: `composer run ${name}`, source: "composer.json" });
|
|
1434
|
+
}
|
|
1435
|
+
if (justfile !== undefined) {
|
|
1436
|
+
for (const name of await recipes(dir, justfile.file, justfile.text))
|
|
1437
|
+
steps.push({ name, command: `just ${name}`, source: "Justfile" });
|
|
1438
|
+
}
|
|
1439
|
+
for (const name of targets(makefile ?? ""))
|
|
1440
|
+
steps.push({ name, command: `make ${name}`, source: "Makefile" });
|
|
1441
|
+
steps.push(...await phpSteps(dir));
|
|
1442
|
+
return steps;
|
|
1443
|
+
}
|
|
1444
|
+
async function firstFile(dir, names) {
|
|
1445
|
+
for (const name of names) {
|
|
1446
|
+
if (await Bun.file(join5(dir, name)).exists())
|
|
1447
|
+
return name;
|
|
1448
|
+
}
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
async function phpSteps(dir) {
|
|
1452
|
+
const steps = [];
|
|
1453
|
+
const phpstan = await firstFile(dir, PHPSTAN_CONFIGS);
|
|
1454
|
+
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
1455
|
+
const phpunit = await firstFile(dir, PHPUNIT_CONFIGS);
|
|
1456
|
+
if (phpstan !== undefined)
|
|
1457
|
+
steps.push({ name: "typecheck", command: "vendor/bin/phpstan analyse --no-progress --memory-limit=1G", source: phpstan });
|
|
1458
|
+
if (csFixer !== undefined)
|
|
1459
|
+
steps.push({ name: "lint", command: "vendor/bin/php-cs-fixer fix --dry-run -v", source: csFixer });
|
|
1460
|
+
if (phpunit !== undefined)
|
|
1461
|
+
steps.push({ name: "test", command: "vendor/bin/phpunit", source: phpunit });
|
|
1462
|
+
return steps;
|
|
1463
|
+
}
|
|
1464
|
+
async function discoverProjects(dir) {
|
|
1465
|
+
const own = await discover(dir);
|
|
1466
|
+
if (own.length > 0)
|
|
1467
|
+
return [{ dir, steps: own }];
|
|
1468
|
+
const projects = [];
|
|
1469
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
1470
|
+
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1471
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1472
|
+
continue;
|
|
1473
|
+
const steps = await discover(join5(dir, entry.name));
|
|
1474
|
+
if (steps.length > 0)
|
|
1475
|
+
projects.push({ name: entry.name, dir: join5(dir, entry.name), steps });
|
|
1476
|
+
}
|
|
1477
|
+
return projects;
|
|
1478
|
+
}
|
|
1479
|
+
async function discover(dir) {
|
|
1480
|
+
const found = await candidates(dir, "check");
|
|
1481
|
+
return STEP_NAMES.flatMap((name) => {
|
|
1482
|
+
const step = found.find((candidate) => candidate.name === name);
|
|
1483
|
+
return step === undefined ? [] : [step];
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// src/narrow.ts
|
|
1488
|
+
var LINTERS = /^(?:keslint|eslint|oxlint)\b/;
|
|
1489
|
+
var LINTABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".svelte"]);
|
|
1490
|
+
var TEST_RUNNER = /^(?:bun test|\$npm_execpath test)\b/;
|
|
1491
|
+
var TEST_FILE = /\.(?:test|spec)\.[jt]sx?$/;
|
|
1492
|
+
var WHITESPACE = /\s+/;
|
|
1493
|
+
async function changedPaths(dir) {
|
|
1494
|
+
const tracked = await $2`git diff --name-only --relative -z HEAD`.cwd(dir).quiet().nothrow();
|
|
1495
|
+
const untracked = await $2`git ls-files -z --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
1496
|
+
if (tracked.exitCode !== 0 || untracked.exitCode !== 0)
|
|
1497
|
+
return;
|
|
1498
|
+
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync2(join6(dir, path)));
|
|
1499
|
+
}
|
|
1500
|
+
function siblingTests(path, exists) {
|
|
1501
|
+
const extension = extname(path);
|
|
1502
|
+
const name = basename2(path, extension);
|
|
1503
|
+
const dir = dirname3(path);
|
|
1504
|
+
const folders = [dir, join6(dir, "tests"), join6(dir, "..", "tests"), join6(dir, "__tests__")];
|
|
1505
|
+
const found = new Set;
|
|
1506
|
+
for (const folder of folders) {
|
|
1507
|
+
for (const kind of ["test", "spec"]) {
|
|
1508
|
+
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) => join6(folder, file))) {
|
|
1509
|
+
if (exists(candidate))
|
|
1510
|
+
found.add(candidate);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return [...found];
|
|
1515
|
+
}
|
|
1516
|
+
function isBare(script, tool) {
|
|
1517
|
+
return tool.test(script.trim()) && script.trim().replace(tool, "").split(WHITESPACE).every((word) => word.startsWith("-") || word === "");
|
|
1518
|
+
}
|
|
1519
|
+
async function narrow2(step, dir, changed) {
|
|
1520
|
+
const script = step.source === "package.json" ? (await scriptText(dir, step.name))?.trim() : undefined;
|
|
1521
|
+
const full = (why) => ({ command: step.command, note: `in full, ${why}` });
|
|
1522
|
+
if (script !== undefined && step.name === "lint" && isBare(script, LINTERS)) {
|
|
1523
|
+
const files = changed.filter((path) => LINTABLE.has(extname(path)));
|
|
1524
|
+
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"}` };
|
|
1525
|
+
}
|
|
1526
|
+
if (script !== undefined && step.name === "test" && isBare(script, TEST_RUNNER)) {
|
|
1527
|
+
const tests = new Set;
|
|
1528
|
+
for (const path of changed) {
|
|
1529
|
+
if (TEST_FILE.test(path)) {
|
|
1530
|
+
tests.add(path);
|
|
1531
|
+
} else {
|
|
1532
|
+
for (const test of siblingTests(path, (candidate) => existsSync2(join6(dir, candidate)))) {
|
|
1533
|
+
tests.add(test);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
if (tests.size === 0)
|
|
1538
|
+
return full("no test sits next to the changed files");
|
|
1539
|
+
return { command: `${step.command} -- ${[...tests].map((test) => quote(`./${test}`)).join(" ")}`, note: `${tests.size} test file${tests.size === 1 ? "" : "s"}` };
|
|
1540
|
+
}
|
|
1541
|
+
return full(`${step.name} cannot be narrowed`);
|
|
1542
|
+
}
|
|
1543
|
+
function quote(path) {
|
|
1544
|
+
return `'${path.replaceAll("'", "'\\''")}'`;
|
|
1545
|
+
}
|
|
1546
|
+
async function scriptText(dir, name) {
|
|
1547
|
+
const text = await read(dir, "package.json");
|
|
1548
|
+
if (text === undefined)
|
|
1549
|
+
return;
|
|
1550
|
+
try {
|
|
1551
|
+
const value = JSON.parse(text).scripts?.[name];
|
|
1552
|
+
return typeof value === "string" ? value : undefined;
|
|
1553
|
+
} catch {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/run.ts
|
|
1559
|
+
import { mkdir as mkdir2, writeFile } from "fs/promises";
|
|
1560
|
+
import { basename as basename3, join as join7 } from "path";
|
|
1561
|
+
import process12 from "process";
|
|
1303
1562
|
|
|
1304
1563
|
// src/e2e.ts
|
|
1305
1564
|
var E2E_NOISE = [
|
|
@@ -1931,14 +2190,14 @@ var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
|
1931
2190
|
async function logDirectory(cwd) {
|
|
1932
2191
|
const root = await privateLogDirectory("check");
|
|
1933
2192
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
1934
|
-
const path =
|
|
2193
|
+
const path = join7(root, `${basename3(cwd)}-${Bun.hash(cwd).toString(36)}-${Date.now().toString(36)}-${process12.pid}`);
|
|
1935
2194
|
await mkdir2(path, { mode: 448 });
|
|
1936
2195
|
return path;
|
|
1937
2196
|
}
|
|
1938
2197
|
async function saveLog(output) {
|
|
1939
2198
|
const root = await privateLogDirectory("errs");
|
|
1940
2199
|
await sweepLogs(root);
|
|
1941
|
-
const path =
|
|
2200
|
+
const path = join7(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process12.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
1942
2201
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
1943
2202
|
return path;
|
|
1944
2203
|
}
|
|
@@ -1946,7 +2205,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
1946
2205
|
const started = Date.now();
|
|
1947
2206
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
1948
2207
|
cwd,
|
|
1949
|
-
env: { ...
|
|
2208
|
+
env: { ...process12.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
1950
2209
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
1951
2210
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
1952
2211
|
});
|
|
@@ -1975,136 +2234,14 @@ function printOutcome(name, width, command, logFile, outcome) {
|
|
|
1975
2234
|
`));
|
|
1976
2235
|
}
|
|
1977
2236
|
|
|
1978
|
-
// src/steps.ts
|
|
1979
|
-
import { readdir as readdir2 } from "fs/promises";
|
|
1980
|
-
import { join as join5 } from "path";
|
|
1981
|
-
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1982
|
-
var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1983
|
-
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1984
|
-
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1985
|
-
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1986
|
-
var JUST_TIMEOUT_MS = 1e4;
|
|
1987
|
-
var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"];
|
|
1988
|
-
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1989
|
-
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1990
|
-
async function readFirst(dir, files) {
|
|
1991
|
-
for (const file of files) {
|
|
1992
|
-
const handle = Bun.file(join5(dir, file));
|
|
1993
|
-
if (await handle.exists())
|
|
1994
|
-
return { file, text: await handle.text() };
|
|
1995
|
-
}
|
|
1996
|
-
return;
|
|
1997
|
-
}
|
|
1998
|
-
async function read(dir, ...files) {
|
|
1999
|
-
for (const file of files) {
|
|
2000
|
-
const handle = Bun.file(join5(dir, file));
|
|
2001
|
-
if (await handle.exists())
|
|
2002
|
-
return handle.text();
|
|
2003
|
-
}
|
|
2004
|
-
return;
|
|
2005
|
-
}
|
|
2006
|
-
function scripts(file, text) {
|
|
2007
|
-
try {
|
|
2008
|
-
const parsed = JSON.parse(text);
|
|
2009
|
-
return parsed.scripts ?? {};
|
|
2010
|
-
} catch {
|
|
2011
|
-
throw new Error(`${file} is not valid JSON`);
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
function targets(text) {
|
|
2015
|
-
return [...text.matchAll(TARGET)].map((match) => match[1] ?? "");
|
|
2016
|
-
}
|
|
2017
|
-
async function recipes(dir, file, text) {
|
|
2018
|
-
if (Bun.which("just") === null)
|
|
2019
|
-
return targets(text);
|
|
2020
|
-
try {
|
|
2021
|
-
const ran = await runCommand(["just", "--justfile", file, "--dump", "--dump-format", "json"], { cwd: dir, timeoutMs: JUST_TIMEOUT_MS });
|
|
2022
|
-
const dump = JSON.parse(ran.text);
|
|
2023
|
-
if (ran.code !== 0)
|
|
2024
|
-
return targets(text);
|
|
2025
|
-
return Object.entries(dump.recipes ?? {}).filter(([, recipe]) => recipe.private !== true && (recipe.parameters ?? []).every((parameter) => parameter.default !== null || parameter.kind === "star")).map(([name]) => name);
|
|
2026
|
-
} catch {
|
|
2027
|
-
return targets(text);
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
function callsSelf(value, bin) {
|
|
2031
|
-
return typeof value === "string" && (value === bin || value.startsWith(`${bin} `) || value.startsWith(`${bin} `));
|
|
2032
|
-
}
|
|
2033
|
-
async function candidates(dir, bin) {
|
|
2034
|
-
const steps = [];
|
|
2035
|
-
const packageJson = await read(dir, "package.json");
|
|
2036
|
-
const composerJson = await read(dir, "composer.json");
|
|
2037
|
-
const justfile = await readFirst(dir, JUSTFILES);
|
|
2038
|
-
const makefile = await read(dir, ...MAKEFILES);
|
|
2039
|
-
if (packageJson !== undefined) {
|
|
2040
|
-
for (const [name, value] of Object.entries(scripts("package.json", packageJson))) {
|
|
2041
|
-
if (!callsSelf(value, bin))
|
|
2042
|
-
steps.push({ name, command: `bun run ${name}`, source: "package.json" });
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
if (composerJson !== undefined) {
|
|
2046
|
-
for (const name of Object.keys(scripts("composer.json", composerJson)))
|
|
2047
|
-
steps.push({ name, command: `composer run ${name}`, source: "composer.json" });
|
|
2048
|
-
}
|
|
2049
|
-
if (justfile !== undefined) {
|
|
2050
|
-
for (const name of await recipes(dir, justfile.file, justfile.text))
|
|
2051
|
-
steps.push({ name, command: `just ${name}`, source: "Justfile" });
|
|
2052
|
-
}
|
|
2053
|
-
for (const name of targets(makefile ?? ""))
|
|
2054
|
-
steps.push({ name, command: `make ${name}`, source: "Makefile" });
|
|
2055
|
-
steps.push(...await phpSteps(dir));
|
|
2056
|
-
return steps;
|
|
2057
|
-
}
|
|
2058
|
-
async function firstFile(dir, names) {
|
|
2059
|
-
for (const name of names) {
|
|
2060
|
-
if (await Bun.file(join5(dir, name)).exists())
|
|
2061
|
-
return name;
|
|
2062
|
-
}
|
|
2063
|
-
return;
|
|
2064
|
-
}
|
|
2065
|
-
async function phpSteps(dir) {
|
|
2066
|
-
const steps = [];
|
|
2067
|
-
const phpstan = await firstFile(dir, PHPSTAN_CONFIGS);
|
|
2068
|
-
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
2069
|
-
const phpunit = await firstFile(dir, PHPUNIT_CONFIGS);
|
|
2070
|
-
if (phpstan !== undefined)
|
|
2071
|
-
steps.push({ name: "typecheck", command: "vendor/bin/phpstan analyse --no-progress --memory-limit=1G", source: phpstan });
|
|
2072
|
-
if (csFixer !== undefined)
|
|
2073
|
-
steps.push({ name: "lint", command: "vendor/bin/php-cs-fixer fix --dry-run -v", source: csFixer });
|
|
2074
|
-
if (phpunit !== undefined)
|
|
2075
|
-
steps.push({ name: "test", command: "vendor/bin/phpunit", source: phpunit });
|
|
2076
|
-
return steps;
|
|
2077
|
-
}
|
|
2078
|
-
async function discoverProjects(dir) {
|
|
2079
|
-
const own = await discover(dir);
|
|
2080
|
-
if (own.length > 0)
|
|
2081
|
-
return [{ dir, steps: own }];
|
|
2082
|
-
const projects = [];
|
|
2083
|
-
const entries = await readdir2(dir, { withFileTypes: true });
|
|
2084
|
-
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
2085
|
-
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
2086
|
-
continue;
|
|
2087
|
-
const steps = await discover(join5(dir, entry.name));
|
|
2088
|
-
if (steps.length > 0)
|
|
2089
|
-
projects.push({ name: entry.name, dir: join5(dir, entry.name), steps });
|
|
2090
|
-
}
|
|
2091
|
-
return projects;
|
|
2092
|
-
}
|
|
2093
|
-
async function discover(dir) {
|
|
2094
|
-
const found = await candidates(dir, "check");
|
|
2095
|
-
return STEP_NAMES.flatMap((name) => {
|
|
2096
|
-
const step = found.find((candidate) => candidate.name === name);
|
|
2097
|
-
return step === undefined ? [] : [step];
|
|
2098
|
-
});
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
2237
|
// src/check.ts
|
|
2102
|
-
var
|
|
2238
|
+
var usage2 = `check [--only <steps>] [--changed] [--timeout <duration>] [--slot] [--in <service> | --host] [--list]
|
|
2103
2239
|
|
|
2104
2240
|
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.
|
|
2105
2241
|
A folder without steps but with subfolders that have some (api/ and client/) runs each one's, each line naming its subfolder.
|
|
2106
2242
|
A step runs inside the docker compose service that bind-mounts its folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the step fails naming it. --in picks the service, --host forces the host.
|
|
2107
2243
|
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.
|
|
2244
|
+
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.
|
|
2108
2245
|
A step still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
2109
2246
|
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.
|
|
2110
2247
|
--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.`;
|
|
@@ -2112,6 +2249,7 @@ var options = {
|
|
|
2112
2249
|
list: { type: "boolean", short: "l", description: "print the steps found, the commands that run them and where (host or service), without running them" },
|
|
2113
2250
|
only: { type: "string", short: "o", description: `comma separated steps to run, among ${STEP_NAMES.join(", ")}` },
|
|
2114
2251
|
timeout: { type: "string", short: "t", description: "longest a step may run before it is ended (30s, 5m, 1h), none by default" },
|
|
2252
|
+
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" },
|
|
2115
2253
|
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions (needs the slot bin)" },
|
|
2116
2254
|
...placeOptions,
|
|
2117
2255
|
json: jsonOption()
|
|
@@ -2137,17 +2275,33 @@ async function plan(steps, settings) {
|
|
|
2137
2275
|
planned.push({ ...step, dir: project.dir, label: project.name === undefined ? step.name : `${project.name}/${step.name}`, placement: await place(project.dir, programOf(step.command), settings) });
|
|
2138
2276
|
return planned;
|
|
2139
2277
|
}
|
|
2278
|
+
async function narrowed(steps) {
|
|
2279
|
+
const cache = new Map;
|
|
2280
|
+
const result = [];
|
|
2281
|
+
for (const step of steps) {
|
|
2282
|
+
if (!cache.has(step.dir)) {
|
|
2283
|
+
const paths = await changedPaths(step.dir);
|
|
2284
|
+
if (paths === undefined)
|
|
2285
|
+
fail("--changed needs a git repository");
|
|
2286
|
+
cache.set(step.dir, paths);
|
|
2287
|
+
}
|
|
2288
|
+
const { command, note } = await narrow2(step, step.dir, cache.get(step.dir) ?? []);
|
|
2289
|
+
result.push({ ...step, command, note });
|
|
2290
|
+
}
|
|
2291
|
+
return result;
|
|
2292
|
+
}
|
|
2140
2293
|
function launch(step) {
|
|
2141
2294
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2142
2295
|
}
|
|
2143
|
-
async function check(args, cwd =
|
|
2144
|
-
const parsed = parse(args,
|
|
2296
|
+
async function check(args, cwd = process13.cwd()) {
|
|
2297
|
+
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"]] });
|
|
2145
2298
|
const settings = placeSettings(parsed.values);
|
|
2146
2299
|
const projects = await discoverProjects(cwd);
|
|
2147
2300
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
2148
2301
|
if (found.length === 0)
|
|
2149
2302
|
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`);
|
|
2150
|
-
const
|
|
2303
|
+
const planned = await plan(pick(found, parsed.values.only), settings);
|
|
2304
|
+
const steps = parsed.values.changed === true ? await narrowed(planned) : planned;
|
|
2151
2305
|
const json = parsed.values.json === true;
|
|
2152
2306
|
if (parsed.values.list === true) {
|
|
2153
2307
|
if (json)
|
|
@@ -2156,7 +2310,7 @@ async function check(args, cwd = process10.cwd()) {
|
|
|
2156
2310
|
console.log(table(steps.map((step) => [step.label, step.command, step.source, step.placement?.service ?? "host"])));
|
|
2157
2311
|
return 0;
|
|
2158
2312
|
}
|
|
2159
|
-
if (parsed.values.slot === true && Bun.which("slot", { PATH:
|
|
2313
|
+
if (parsed.values.slot === true && Bun.which("slot", { PATH: process13.env.PATH ?? "" }) === null)
|
|
2160
2314
|
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2161
2315
|
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2162
2316
|
const directory = await logDirectory(cwd);
|
|
@@ -2166,12 +2320,12 @@ async function check(args, cwd = process10.cwd()) {
|
|
|
2166
2320
|
const outcomes = [];
|
|
2167
2321
|
try {
|
|
2168
2322
|
for (const step of steps) {
|
|
2169
|
-
const logFile =
|
|
2323
|
+
const logFile = join8(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2170
2324
|
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2171
2325
|
const command = parsed.values.slot === true ? slotted(launch(step)) : launch(step);
|
|
2172
2326
|
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held }) : await refusedStep(down, logFile);
|
|
2173
2327
|
if (!json)
|
|
2174
|
-
printOutcome(step.label, width, step.
|
|
2328
|
+
printOutcome(step.label, width, `${step.command}${step.note === undefined ? "" : ` (${step.note})`}${step.placement === undefined ? "" : ` (in ${step.placement.service})`}`, logFile, outcome);
|
|
2175
2329
|
outcomes.push(outcomeJson(step.label, step.command, logFile, outcome, step.placement?.service));
|
|
2176
2330
|
if (held.signal !== undefined)
|
|
2177
2331
|
break;
|
|
@@ -2220,7 +2374,7 @@ ${body}`;
|
|
|
2220
2374
|
}
|
|
2221
2375
|
|
|
2222
2376
|
// src/fix.ts
|
|
2223
|
-
var
|
|
2377
|
+
var usage3 = `fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
2224
2378
|
|
|
2225
2379
|
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.
|
|
2226
2380
|
It looks at the folder itself only, so each package of a monorepo gets its own run.
|
|
@@ -2242,7 +2396,7 @@ var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
|
2242
2396
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2243
2397
|
var MAX_CHANGED = 30;
|
|
2244
2398
|
async function replaceFile(path, content) {
|
|
2245
|
-
const temporary = `${path}.${
|
|
2399
|
+
const temporary = `${path}.${process14.pid}.tmp`;
|
|
2246
2400
|
await writeFile2(temporary, content, { mode: statSync(path).mode & 511 });
|
|
2247
2401
|
await rename(temporary, path);
|
|
2248
2402
|
}
|
|
@@ -2261,9 +2415,9 @@ async function toolFixers(dir) {
|
|
|
2261
2415
|
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2262
2416
|
if (makefile !== undefined) {
|
|
2263
2417
|
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2264
|
-
const path =
|
|
2418
|
+
const path = join9(cwd, makefile);
|
|
2265
2419
|
const current = await Bun.file(path).text();
|
|
2266
|
-
const { content, targets } = declarePhony(current, (name) =>
|
|
2420
|
+
const { content, targets } = declarePhony(current, (name) => existsSync3(join9(cwd, name)));
|
|
2267
2421
|
if (content !== current)
|
|
2268
2422
|
await replaceFile(path, content);
|
|
2269
2423
|
return `.PHONY: ${targets.join(" ")}`;
|
|
@@ -2271,9 +2425,9 @@ async function toolFixers(dir) {
|
|
|
2271
2425
|
}
|
|
2272
2426
|
if (justfile !== undefined)
|
|
2273
2427
|
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2274
|
-
if (await Bun.file(
|
|
2428
|
+
if (await Bun.file(join9(dir, "go.mod")).exists())
|
|
2275
2429
|
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2276
|
-
if (await Bun.file(
|
|
2430
|
+
if (await Bun.file(join9(dir, "Cargo.toml")).exists())
|
|
2277
2431
|
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2278
2432
|
if (ruff)
|
|
2279
2433
|
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
@@ -2314,10 +2468,10 @@ function printChanged(changed) {
|
|
|
2314
2468
|
if (changed.length > MAX_CHANGED)
|
|
2315
2469
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2316
2470
|
}
|
|
2317
|
-
async function fix(args, cwd =
|
|
2318
|
-
const parsed = parse(args,
|
|
2471
|
+
async function fix(args, cwd = process14.cwd()) {
|
|
2472
|
+
const parsed = parse(args, usage3, options2, { 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"]] });
|
|
2319
2473
|
const settings = placeSettings(parsed.values);
|
|
2320
|
-
if (
|
|
2474
|
+
if (process14.env[RUNNING] !== undefined)
|
|
2321
2475
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2322
2476
|
const found = await fixers(cwd);
|
|
2323
2477
|
if (found.length === 0)
|
|
@@ -2355,7 +2509,7 @@ async function fix(args, cwd = process11.cwd()) {
|
|
|
2355
2509
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2356
2510
|
continue;
|
|
2357
2511
|
}
|
|
2358
|
-
const logFile =
|
|
2512
|
+
const logFile = join9(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2359
2513
|
const placement = placements.get(fixer);
|
|
2360
2514
|
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2361
2515
|
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
@@ -2384,4 +2538,4 @@ async function fix(args, cwd = process11.cwd()) {
|
|
|
2384
2538
|
}
|
|
2385
2539
|
|
|
2386
2540
|
// src/fix-cli.ts
|
|
2387
|
-
|
|
2541
|
+
process15.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });
|