@kaynooo/cli-check 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/cli.js +135 -80
- package/dist/errs-cli.js +112 -62
- package/dist/fix-cli.js +122 -69
- package/dist/j-cli.js +159 -107
- package/package.json +2 -2
package/dist/errs-cli.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/errs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process20 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
|
+
|
|
12
13
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
14
|
var N = new Map;
|
|
14
15
|
var Nt = /\s+\S*$/;
|
|
@@ -26,6 +27,7 @@ function ko(t, e, r = "...") {
|
|
|
26
27
|
}
|
|
27
28
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
28
29
|
var z = new Map;
|
|
30
|
+
|
|
29
31
|
// ../kit/src/mode.ts
|
|
30
32
|
import process2 from "process";
|
|
31
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -74,7 +76,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
74
76
|
return false;
|
|
75
77
|
return r?.isTTY === true;
|
|
76
78
|
}
|
|
77
|
-
function
|
|
79
|
+
function f(r, e = []) {
|
|
78
80
|
let l = "", n = "";
|
|
79
81
|
for (let t = 0, i = e.length;t < i; t++)
|
|
80
82
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -84,7 +86,7 @@ function f2(r, e = []) {
|
|
|
84
86
|
if (Array.isArray(a)) {
|
|
85
87
|
let s = g.get(i);
|
|
86
88
|
if (s === undefined)
|
|
87
|
-
s =
|
|
89
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
88
90
|
return s;
|
|
89
91
|
}
|
|
90
92
|
if (typeof a === "function")
|
|
@@ -93,20 +95,20 @@ function f2(r, e = []) {
|
|
|
93
95
|
if (u === undefined) {
|
|
94
96
|
if (g.size >= 64)
|
|
95
97
|
g.clear();
|
|
96
|
-
u =
|
|
98
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
97
99
|
}
|
|
98
100
|
return u;
|
|
99
101
|
};
|
|
100
102
|
throw Error(`Unknown style: ${String(i)}`);
|
|
101
103
|
} });
|
|
102
104
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
105
|
+
function Fe(r = {}) {
|
|
106
|
+
return f(r);
|
|
105
107
|
}
|
|
106
|
-
var
|
|
108
|
+
var o = Fe();
|
|
107
109
|
|
|
108
110
|
// ../kit/src/theme.ts
|
|
109
|
-
import { existsSync as
|
|
111
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
110
112
|
import { homedir as homedir2 } from "os";
|
|
111
113
|
import { join as join3, resolve as resolve2 } from "path";
|
|
112
114
|
import process5 from "process";
|
|
@@ -127,6 +129,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
// ../kit/src/user-config.ts
|
|
132
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
130
133
|
import { homedir } from "os";
|
|
131
134
|
import { join as join2 } from "path";
|
|
132
135
|
import process4 from "process";
|
|
@@ -137,6 +140,24 @@ function configBase(where = {}) {
|
|
|
137
140
|
function userConfigPath(bin, where = {}) {
|
|
138
141
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
139
142
|
}
|
|
143
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
144
|
+
const current = userConfigPath(bin, where);
|
|
145
|
+
if (existsSync2(current))
|
|
146
|
+
return current;
|
|
147
|
+
const base = configBase(where);
|
|
148
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
149
|
+
}
|
|
150
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
151
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
152
|
+
if (!existsSync2(path))
|
|
153
|
+
return {};
|
|
154
|
+
try {
|
|
155
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
156
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
157
|
+
} catch {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
140
161
|
|
|
141
162
|
// ../kit/src/theme.ts
|
|
142
163
|
var ENDS = new Map;
|
|
@@ -203,7 +224,7 @@ function readThemeFile(path, warn) {
|
|
|
203
224
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
204
225
|
return;
|
|
205
226
|
}
|
|
206
|
-
const parsed = JSON.parse(
|
|
227
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
207
228
|
if (isRecord(parsed))
|
|
208
229
|
return parsed;
|
|
209
230
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -269,7 +290,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
269
290
|
}
|
|
270
291
|
}
|
|
271
292
|
function endsWalk(home) {
|
|
272
|
-
return (dir) => dir === resolve2(home) ||
|
|
293
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
273
294
|
}
|
|
274
295
|
var warned = new Set;
|
|
275
296
|
function warnOnce(message) {
|
|
@@ -325,7 +346,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
325
346
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
326
347
|
}
|
|
327
348
|
function paint(stream, env = process6.env) {
|
|
328
|
-
return
|
|
349
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
329
350
|
}
|
|
330
351
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
331
352
|
const colors = paint(stream, env);
|
|
@@ -759,9 +780,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
759
780
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
760
781
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
761
782
|
}
|
|
783
|
+
// ../kit/src/argv.ts
|
|
784
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
785
|
+
import { resolve as resolve3 } from "path";
|
|
786
|
+
import process11 from "process";
|
|
787
|
+
function commandLine() {
|
|
788
|
+
try {
|
|
789
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
790
|
+
} catch {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function realPath(word) {
|
|
795
|
+
try {
|
|
796
|
+
return realpathSync(resolve3(word));
|
|
797
|
+
} catch {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
802
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
803
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
804
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
805
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
806
|
+
}
|
|
762
807
|
// ../kit/src/process.ts
|
|
763
808
|
import { constants } from "os";
|
|
764
|
-
import
|
|
809
|
+
import process12 from "process";
|
|
765
810
|
var KILL_GRACE_MS = 2000;
|
|
766
811
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
767
812
|
function exitCodeOf(code, signal) {
|
|
@@ -783,7 +828,7 @@ function holdSignals(cleanup) {
|
|
|
783
828
|
},
|
|
784
829
|
release: () => {
|
|
785
830
|
for (const signal of SIGNALS)
|
|
786
|
-
|
|
831
|
+
process12.off(signal, onSignal);
|
|
787
832
|
}
|
|
788
833
|
};
|
|
789
834
|
function onSignal(signal) {
|
|
@@ -796,10 +841,10 @@ function holdSignals(cleanup) {
|
|
|
796
841
|
return;
|
|
797
842
|
held.release();
|
|
798
843
|
cleanup(signal);
|
|
799
|
-
|
|
844
|
+
process12.kill(process12.pid, signal);
|
|
800
845
|
}
|
|
801
846
|
for (const signal of SIGNALS)
|
|
802
|
-
|
|
847
|
+
process12.on(signal, onSignal);
|
|
803
848
|
return held;
|
|
804
849
|
}
|
|
805
850
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -813,7 +858,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
813
858
|
return;
|
|
814
859
|
try {
|
|
815
860
|
if (grouped)
|
|
816
|
-
|
|
861
|
+
process12.kill(-proc.pid, killing);
|
|
817
862
|
else
|
|
818
863
|
proc.kill(killing);
|
|
819
864
|
} catch {}
|
|
@@ -887,33 +932,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
887
932
|
var RESET_STYLE = `${ESC}[0m`;
|
|
888
933
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
889
934
|
// ../kit/src/cli.ts
|
|
890
|
-
import { readFileSync as
|
|
935
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
891
936
|
import { dirname as dirname3, join as join6 } from "path";
|
|
892
|
-
import
|
|
937
|
+
import process15 from "process";
|
|
893
938
|
|
|
894
939
|
// ../kit/src/usage.ts
|
|
895
940
|
import { appendFileSync, mkdirSync } from "fs";
|
|
896
941
|
import { homedir as homedir4 } from "os";
|
|
897
942
|
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
898
|
-
import
|
|
943
|
+
import process14 from "process";
|
|
899
944
|
|
|
900
945
|
// ../kit/src/logs.ts
|
|
901
946
|
import { lstatSync, openSync } from "fs";
|
|
902
947
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
903
948
|
import { homedir as homedir3, tmpdir } from "os";
|
|
904
949
|
import { join as join4 } from "path";
|
|
905
|
-
import
|
|
950
|
+
import process13 from "process";
|
|
906
951
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
907
952
|
var CLI_FOLDER = "kaynooo-cli";
|
|
908
953
|
function isPrivateDirectory(path) {
|
|
909
954
|
try {
|
|
910
955
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
911
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
956
|
+
return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
912
957
|
} catch {
|
|
913
958
|
return false;
|
|
914
959
|
}
|
|
915
960
|
}
|
|
916
|
-
async function privateLogDirectory(name, env =
|
|
961
|
+
async function privateLogDirectory(name, env = process13.env) {
|
|
917
962
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
918
963
|
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
919
964
|
const path = join4(base, name);
|
|
@@ -953,14 +998,14 @@ var usageError;
|
|
|
953
998
|
function noteUsageError(message) {
|
|
954
999
|
usageError = message;
|
|
955
1000
|
}
|
|
956
|
-
function stateHome(env =
|
|
1001
|
+
function stateHome(env = process14.env) {
|
|
957
1002
|
const dir = env.XDG_STATE_HOME;
|
|
958
1003
|
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
959
1004
|
}
|
|
960
|
-
function usagePath(env =
|
|
1005
|
+
function usagePath(env = process14.env) {
|
|
961
1006
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
962
1007
|
}
|
|
963
|
-
function usageRecorded(env =
|
|
1008
|
+
function usageRecorded(env = process14.env) {
|
|
964
1009
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
965
1010
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
966
1011
|
}
|
|
@@ -974,7 +1019,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
974
1019
|
usageError = undefined;
|
|
975
1020
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
976
1021
|
}
|
|
977
|
-
function recordUsage(entry, env =
|
|
1022
|
+
function recordUsage(entry, env = process14.env) {
|
|
978
1023
|
if (!usageRecorded(env))
|
|
979
1024
|
return;
|
|
980
1025
|
try {
|
|
@@ -992,8 +1037,8 @@ var LEVEL_OPTIONS = {
|
|
|
992
1037
|
};
|
|
993
1038
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
994
1039
|
function printError(prefix, message, hint, cause) {
|
|
995
|
-
const colors = paint(
|
|
996
|
-
const styled = takesControlCodes(
|
|
1040
|
+
const colors = paint(process15.stderr);
|
|
1041
|
+
const styled = takesControlCodes(process15.stderr);
|
|
997
1042
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
998
1043
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
999
1044
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1037,24 +1082,24 @@ function candidateLine(candidate) {
|
|
|
1037
1082
|
}
|
|
1038
1083
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1039
1084
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1040
|
-
|
|
1085
|
+
const typed = [];
|
|
1041
1086
|
let at = 0;
|
|
1042
1087
|
while (at < before.length) {
|
|
1043
1088
|
const word = before[at];
|
|
1044
1089
|
if (word === "--") {
|
|
1045
|
-
|
|
1090
|
+
typed.push(...before.slice(at + 1));
|
|
1046
1091
|
break;
|
|
1047
1092
|
}
|
|
1048
1093
|
if (!word.startsWith("-"))
|
|
1049
|
-
|
|
1094
|
+
typed.push(word);
|
|
1050
1095
|
else if (takesValue(word))
|
|
1051
1096
|
at++;
|
|
1052
1097
|
at++;
|
|
1053
1098
|
}
|
|
1054
1099
|
const last = positionals.at(-1);
|
|
1055
|
-
if (
|
|
1056
|
-
return positionals[
|
|
1057
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1100
|
+
if (typed.length < positionals.length)
|
|
1101
|
+
return { name: positionals[typed.length], typed };
|
|
1102
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1058
1103
|
}
|
|
1059
1104
|
async function leafCandidates(run, words) {
|
|
1060
1105
|
const completing = await completingOf(run);
|
|
@@ -1062,12 +1107,12 @@ async function leafCandidates(run, words) {
|
|
|
1062
1107
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1063
1108
|
const flag = words.at(-2);
|
|
1064
1109
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1110
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1065
1111
|
if (option?.type === "string") {
|
|
1066
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1112
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1067
1113
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1068
1114
|
}
|
|
1069
|
-
const
|
|
1070
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1115
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1071
1116
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1072
1117
|
}
|
|
1073
1118
|
async function printCandidates(found) {
|
|
@@ -1076,9 +1121,9 @@ async function printCandidates(found) {
|
|
|
1076
1121
|
return 0;
|
|
1077
1122
|
}
|
|
1078
1123
|
function packageVersion(entry = Bun.main) {
|
|
1079
|
-
for (let dir = dirname3(
|
|
1124
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
1080
1125
|
try {
|
|
1081
|
-
const { version } = JSON.parse(
|
|
1126
|
+
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
1082
1127
|
if (typeof version === "string")
|
|
1083
1128
|
return version;
|
|
1084
1129
|
} catch {}
|
|
@@ -1086,7 +1131,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1086
1131
|
return "0.0.0";
|
|
1087
1132
|
}
|
|
1088
1133
|
}
|
|
1089
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1134
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1090
1135
|
if (argv[0] === COMPLETE)
|
|
1091
1136
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1092
1137
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1108,6 +1153,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process14.a
|
|
|
1108
1153
|
}
|
|
1109
1154
|
// ../kit/src/folders.ts
|
|
1110
1155
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1156
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1157
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1158
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1159
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1160
|
+
}
|
|
1111
1161
|
// ../kit/src/secrets.ts
|
|
1112
1162
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1113
1163
|
// ../kit/src/sessions.ts
|
|
@@ -1115,17 +1165,17 @@ var {Glob } = globalThis.Bun;
|
|
|
1115
1165
|
var SESSION_FILES = new Glob("*.json");
|
|
1116
1166
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1117
1167
|
// package.json
|
|
1118
|
-
var version = "0.18.
|
|
1168
|
+
var version = "0.18.2";
|
|
1119
1169
|
|
|
1120
1170
|
// src/errs.ts
|
|
1121
1171
|
import { relative as relative2 } from "path";
|
|
1122
|
-
import
|
|
1172
|
+
import process19 from "process";
|
|
1123
1173
|
|
|
1124
1174
|
// src/compose.ts
|
|
1125
|
-
import { existsSync as
|
|
1175
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1126
1176
|
import { homedir as homedir5 } from "os";
|
|
1127
|
-
import { basename, dirname as dirname4, join as join7, relative, resolve as
|
|
1128
|
-
import
|
|
1177
|
+
import { basename, dirname as dirname4, join as join7, relative, resolve as resolve4 } from "path";
|
|
1178
|
+
import process17 from "process";
|
|
1129
1179
|
|
|
1130
1180
|
// ../kit/src/shell.ts
|
|
1131
1181
|
var SEPARATORS = new Set([`
|
|
@@ -1218,7 +1268,7 @@ async function variables(composeDir) {
|
|
|
1218
1268
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1219
1269
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1220
1270
|
}
|
|
1221
|
-
for (const [key, value] of Object.entries(
|
|
1271
|
+
for (const [key, value] of Object.entries(process17.env)) {
|
|
1222
1272
|
if (value !== undefined)
|
|
1223
1273
|
env[key] = value;
|
|
1224
1274
|
}
|
|
@@ -1240,8 +1290,8 @@ function bindSource(source, composeDir, env) {
|
|
|
1240
1290
|
if (path.startsWith("~"))
|
|
1241
1291
|
return join7(homedir5(), path.slice(1));
|
|
1242
1292
|
if (path.startsWith("/"))
|
|
1243
|
-
return
|
|
1244
|
-
return path.startsWith(".") ?
|
|
1293
|
+
return resolve4(path);
|
|
1294
|
+
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
1245
1295
|
}
|
|
1246
1296
|
function mountsOf(volumes, composeDir, env) {
|
|
1247
1297
|
if (!Array.isArray(volumes))
|
|
@@ -1283,7 +1333,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1283
1333
|
const files = [];
|
|
1284
1334
|
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1285
1335
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1286
|
-
const file = Bun.file(
|
|
1336
|
+
const file = Bun.file(resolve4(composeDir, name));
|
|
1287
1337
|
if (!await file.exists())
|
|
1288
1338
|
fail(`COMPOSE_FILE names ${join7(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1289
1339
|
files.push({ name, text: await file.text() });
|
|
@@ -1319,11 +1369,11 @@ async function readServices(composeDir) {
|
|
|
1319
1369
|
function climb(dir) {
|
|
1320
1370
|
const folders = [dir];
|
|
1321
1371
|
let current = dir;
|
|
1322
|
-
while (!
|
|
1372
|
+
while (!existsSync4(join7(current, ".git")) && dirname4(current) !== current) {
|
|
1323
1373
|
current = dirname4(current);
|
|
1324
1374
|
folders.push(current);
|
|
1325
1375
|
}
|
|
1326
|
-
return
|
|
1376
|
+
return existsSync4(join7(current, ".git")) ? folders : [dir];
|
|
1327
1377
|
}
|
|
1328
1378
|
function containerPath(service, dir) {
|
|
1329
1379
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1354,7 +1404,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1354
1404
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1355
1405
|
return;
|
|
1356
1406
|
}
|
|
1357
|
-
if (Bun.which("docker", { PATH:
|
|
1407
|
+
if (Bun.which("docker", { PATH: process17.env.PATH ?? "" }) === null) {
|
|
1358
1408
|
if (service !== undefined)
|
|
1359
1409
|
fail(`--in ${service}: docker not found`);
|
|
1360
1410
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1406,7 +1456,7 @@ class Stack {
|
|
|
1406
1456
|
}
|
|
1407
1457
|
static async running(composeDir) {
|
|
1408
1458
|
try {
|
|
1409
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1459
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process17.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1410
1460
|
if (ran.code !== 0)
|
|
1411
1461
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1412
1462
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -2066,14 +2116,14 @@ function parseErrors(output) {
|
|
|
2066
2116
|
// src/run.ts
|
|
2067
2117
|
import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
|
|
2068
2118
|
import { basename as basename2, join as join8 } from "path";
|
|
2069
|
-
import
|
|
2119
|
+
import process18 from "process";
|
|
2070
2120
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2071
2121
|
var RESULTS_FILE = "results.json";
|
|
2072
2122
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2073
2123
|
async function logDirectory(cwd) {
|
|
2074
2124
|
const root = await privateLogDirectory("check");
|
|
2075
2125
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2076
|
-
const path = join8(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${
|
|
2126
|
+
const path = join8(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process18.pid}`);
|
|
2077
2127
|
await mkdir2(path, { mode: 448 });
|
|
2078
2128
|
return path;
|
|
2079
2129
|
}
|
|
@@ -2099,7 +2149,7 @@ async function lastFailed(cwd) {
|
|
|
2099
2149
|
async function saveLog(output) {
|
|
2100
2150
|
const root = await privateLogDirectory("errs");
|
|
2101
2151
|
await sweepLogs(root);
|
|
2102
|
-
const path = join8(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${
|
|
2152
|
+
const path = join8(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process18.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2103
2153
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2104
2154
|
return path;
|
|
2105
2155
|
}
|
|
@@ -2107,7 +2157,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2107
2157
|
const started = Date.now();
|
|
2108
2158
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2109
2159
|
cwd,
|
|
2110
|
-
env: { ...
|
|
2160
|
+
env: { ...process18.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2111
2161
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2112
2162
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2113
2163
|
});
|
|
@@ -2123,8 +2173,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2123
2173
|
return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
|
|
2124
2174
|
}
|
|
2125
2175
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2126
|
-
const colors = paint(
|
|
2127
|
-
const path = role("path",
|
|
2176
|
+
const colors = paint(process18.stdout);
|
|
2177
|
+
const path = role("path", process18.stdout);
|
|
2128
2178
|
const took = colors.dim(formatDuration(outcome.ms));
|
|
2129
2179
|
if (outcome.ok) {
|
|
2130
2180
|
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
@@ -2181,7 +2231,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2181
2231
|
const held = holdSignals();
|
|
2182
2232
|
let ran;
|
|
2183
2233
|
try {
|
|
2184
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...
|
|
2234
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process19.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
2185
2235
|
} catch (error) {
|
|
2186
2236
|
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2187
2237
|
} finally {
|
|
@@ -2189,7 +2239,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2189
2239
|
}
|
|
2190
2240
|
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
2191
2241
|
}
|
|
2192
|
-
async function errs(args, cwd =
|
|
2242
|
+
async function errs(args, cwd = process19.cwd()) {
|
|
2193
2243
|
const first = args[0];
|
|
2194
2244
|
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2195
2245
|
const parsed = parse(bare ? [] : args, usage2, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
@@ -2213,4 +2263,4 @@ ${usage2}`);
|
|
|
2213
2263
|
}
|
|
2214
2264
|
|
|
2215
2265
|
// src/errs-cli.ts
|
|
2216
|
-
|
|
2266
|
+
process20.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|