@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/j-cli.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/j-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process23 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,16 +1165,16 @@ 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/j.ts
|
|
1121
|
-
import
|
|
1171
|
+
import process22 from "process";
|
|
1122
1172
|
|
|
1123
1173
|
// ../kit/src/picker.ts
|
|
1124
|
-
import { existsSync as
|
|
1174
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
1125
1175
|
import { homedir as homedir5 } from "os";
|
|
1126
1176
|
import { dirname as dirname4, join as join7 } from "path";
|
|
1127
|
-
import
|
|
1177
|
+
import process19 from "process";
|
|
1128
1178
|
|
|
1129
1179
|
// ../kit/src/picker/score.ts
|
|
1130
1180
|
var MATCH = 16;
|
|
@@ -1219,7 +1269,9 @@ var COLUMN_GAP = 2;
|
|
|
1219
1269
|
var PASTE_START = "\x1B[200~";
|
|
1220
1270
|
var PASTE_END = "\x1B[201~";
|
|
1221
1271
|
var LAST_WORD = /\S*\s*$/;
|
|
1222
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1272
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1273
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1274
|
+
var WHEEL_LINES = 3;
|
|
1223
1275
|
var KEYS = {
|
|
1224
1276
|
"\x1B[A": "up",
|
|
1225
1277
|
"\x1BOA": "up",
|
|
@@ -1301,6 +1353,9 @@ function lay(rows, searched) {
|
|
|
1301
1353
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1302
1354
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1303
1355
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1356
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1357
|
+
if (wheel !== undefined)
|
|
1358
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1304
1359
|
const named = codes.get(sequence);
|
|
1305
1360
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1306
1361
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -1390,11 +1445,11 @@ function chosen(state) {
|
|
|
1390
1445
|
|
|
1391
1446
|
// ../kit/src/picker/terminal.ts
|
|
1392
1447
|
import { openSync as openSync2 } from "fs";
|
|
1393
|
-
import
|
|
1448
|
+
import process18 from "process";
|
|
1394
1449
|
import tty from "tty";
|
|
1395
1450
|
|
|
1396
1451
|
// ../kit/src/picker/preview.ts
|
|
1397
|
-
import
|
|
1452
|
+
import process17 from "process";
|
|
1398
1453
|
|
|
1399
1454
|
// ../kit/src/shell.ts
|
|
1400
1455
|
var SEPARATORS = new Set([`
|
|
@@ -1463,7 +1518,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1463
1518
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1464
1519
|
const stop = () => {
|
|
1465
1520
|
try {
|
|
1466
|
-
|
|
1521
|
+
process17.kill(-proc.pid, "SIGKILL");
|
|
1467
1522
|
} catch {
|
|
1468
1523
|
proc.kill();
|
|
1469
1524
|
}
|
|
@@ -1543,7 +1598,7 @@ function caretColumn(state, layout) {
|
|
|
1543
1598
|
}
|
|
1544
1599
|
function helpLines(state, layout, theme) {
|
|
1545
1600
|
const lines = [
|
|
1546
|
-
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1601
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
|
|
1547
1602
|
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1548
1603
|
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1549
1604
|
];
|
|
@@ -1593,8 +1648,11 @@ var ESCAPE_WAIT_MS = 30;
|
|
|
1593
1648
|
var OPEN = { ctrl: "open" };
|
|
1594
1649
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1595
1650
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
1651
|
+
var CARET = "\x1B[7m \x1B[27m";
|
|
1596
1652
|
var PASTE_ON = "\x1B[?2004h";
|
|
1597
1653
|
var PASTE_OFF = "\x1B[?2004l";
|
|
1654
|
+
var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
|
|
1655
|
+
var MOUSE_OFF = "\x1B[?1006l\x1B[?1000l";
|
|
1598
1656
|
var CLEAR_BELOW = "\r\x1B[J";
|
|
1599
1657
|
var SIGNALS2 = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1600
1658
|
function up(lines) {
|
|
@@ -1608,7 +1666,7 @@ function openTerminal() {
|
|
|
1608
1666
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1609
1667
|
}
|
|
1610
1668
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
1611
|
-
const out =
|
|
1669
|
+
const out = process18.stderr;
|
|
1612
1670
|
let resize;
|
|
1613
1671
|
async function read(onChunk) {
|
|
1614
1672
|
const decoder = new TextDecoder;
|
|
@@ -1657,21 +1715,18 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1657
1715
|
let finish;
|
|
1658
1716
|
let restored = false;
|
|
1659
1717
|
let escape;
|
|
1660
|
-
let caret;
|
|
1661
1718
|
function draw(clear = false) {
|
|
1662
1719
|
if (restored)
|
|
1663
1720
|
return;
|
|
1664
1721
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1665
1722
|
let frame = HIDE_CURSOR;
|
|
1666
1723
|
if (reserved !== layout.height || clear) {
|
|
1667
|
-
frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
|
|
1668
1724
|
frame += CLEAR_BELOW + `
|
|
1669
1725
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1670
1726
|
reserved = layout.height;
|
|
1671
1727
|
}
|
|
1672
|
-
caret = caretColumn(state, layout);
|
|
1673
1728
|
frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
|
|
1674
|
-
`)}${up(layout.height - 1)}\r\x1B[${
|
|
1729
|
+
`)}${up(layout.height - 1)}\r\x1B[${caretColumn(state, layout)}G${CARET}\r`;
|
|
1675
1730
|
terminal.write(frame);
|
|
1676
1731
|
}
|
|
1677
1732
|
function pageSize() {
|
|
@@ -1710,7 +1765,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1710
1765
|
clearTimeout(previewTimer);
|
|
1711
1766
|
clearTimeout(escape);
|
|
1712
1767
|
previewing.abort();
|
|
1713
|
-
terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1768
|
+
terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1714
1769
|
terminal.close();
|
|
1715
1770
|
}
|
|
1716
1771
|
const stop = () => {
|
|
@@ -1785,11 +1840,11 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1785
1840
|
const ended = new Promise((resolve) => {
|
|
1786
1841
|
finish = resolve;
|
|
1787
1842
|
});
|
|
1788
|
-
|
|
1843
|
+
process18.once("exit", restore);
|
|
1789
1844
|
for (const signal of SIGNALS2)
|
|
1790
|
-
|
|
1845
|
+
process18.once(signal, stop);
|
|
1791
1846
|
try {
|
|
1792
|
-
terminal.write(PASTE_ON);
|
|
1847
|
+
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
1793
1848
|
terminal.listen(onChunk, () => draw(true));
|
|
1794
1849
|
refreshPreview();
|
|
1795
1850
|
draw(true);
|
|
@@ -1800,8 +1855,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1800
1855
|
await ended;
|
|
1801
1856
|
} finally {
|
|
1802
1857
|
for (const signal of SIGNALS2)
|
|
1803
|
-
|
|
1804
|
-
|
|
1858
|
+
process18.off(signal, stop);
|
|
1859
|
+
process18.off("exit", restore);
|
|
1805
1860
|
restore();
|
|
1806
1861
|
}
|
|
1807
1862
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -1832,23 +1887,23 @@ function heightFor(count) {
|
|
|
1832
1887
|
return String(Math.max(15, Math.ceil((count + 4) / 0.6)));
|
|
1833
1888
|
}
|
|
1834
1889
|
function historyFile(name) {
|
|
1835
|
-
return join7(
|
|
1890
|
+
return join7(process19.env.XDG_CACHE_HOME ?? join7(homedir5(), ".cache"), name, "history.json");
|
|
1836
1891
|
}
|
|
1837
1892
|
function history(name) {
|
|
1838
1893
|
try {
|
|
1839
1894
|
const file = historyFile(name);
|
|
1840
|
-
return
|
|
1895
|
+
return existsSync4(file) ? JSON.parse(readFileSync5(file, "utf-8")) : {};
|
|
1841
1896
|
} catch {
|
|
1842
1897
|
return {};
|
|
1843
1898
|
}
|
|
1844
1899
|
}
|
|
1845
1900
|
function runs(name) {
|
|
1846
|
-
return history(name)[
|
|
1901
|
+
return history(name)[process19.cwd()] ?? [];
|
|
1847
1902
|
}
|
|
1848
1903
|
function record(name, run) {
|
|
1849
1904
|
const all = history(name);
|
|
1850
1905
|
const file = historyFile(name);
|
|
1851
|
-
all[
|
|
1906
|
+
all[process19.cwd()] = [run, ...(all[process19.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
|
|
1852
1907
|
mkdirSync2(dirname4(file), { recursive: true });
|
|
1853
1908
|
writeFileSync(file, JSON.stringify(all));
|
|
1854
1909
|
}
|
|
@@ -1872,7 +1927,7 @@ function list(rows) {
|
|
|
1872
1927
|
}
|
|
1873
1928
|
|
|
1874
1929
|
// ../kit/src/prompt.ts
|
|
1875
|
-
import
|
|
1930
|
+
import process20 from "process";
|
|
1876
1931
|
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
1877
1932
|
function readKeys(input, paste = { active: false }) {
|
|
1878
1933
|
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
@@ -1909,21 +1964,18 @@ async function input2(question, { default: fallback, mask = false, validate, ...
|
|
|
1909
1964
|
function answer(colors, question, state, picked) {
|
|
1910
1965
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1911
1966
|
}
|
|
1912
|
-
async function ask(question, { hint, terminal =
|
|
1967
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
1913
1968
|
const { stdin, stderr } = terminal;
|
|
1914
1969
|
if (!isInteractive(terminal))
|
|
1915
1970
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1916
1971
|
const colors = paint(stderr);
|
|
1917
|
-
let drawn = [];
|
|
1918
1972
|
let current = "asking";
|
|
1919
1973
|
let outcome;
|
|
1920
1974
|
const columns = () => stderr.columns || 80;
|
|
1921
|
-
const draw = (state) => {
|
|
1975
|
+
const draw = (state, last = false) => {
|
|
1922
1976
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
`)}`);
|
|
1926
|
-
drawn = frame;
|
|
1977
|
+
stderr.write(`\r\x1B[0J${frame.join(`
|
|
1978
|
+
`)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
|
|
1927
1979
|
current = state;
|
|
1928
1980
|
};
|
|
1929
1981
|
const redraw = () => draw(current);
|
|
@@ -1959,7 +2011,7 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
|
|
|
1959
2011
|
});
|
|
1960
2012
|
} finally {
|
|
1961
2013
|
stderr.off?.("resize", redraw);
|
|
1962
|
-
draw(outcome ?? "cancel");
|
|
2014
|
+
draw(outcome ?? "cancel", true);
|
|
1963
2015
|
stderr.write(`
|
|
1964
2016
|
\x1B[?25h\x1B[?2004l`);
|
|
1965
2017
|
stdin.setRawMode(false);
|
|
@@ -1968,10 +2020,10 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
|
|
|
1968
2020
|
}
|
|
1969
2021
|
|
|
1970
2022
|
// src/job-picker.ts
|
|
1971
|
-
import
|
|
2023
|
+
import process21 from "process";
|
|
1972
2024
|
|
|
1973
2025
|
// src/jobs.ts
|
|
1974
|
-
import { existsSync as
|
|
2026
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6 } from "fs";
|
|
1975
2027
|
import { dirname as dirname5, join as join9, resolve as resolvePath } from "path";
|
|
1976
2028
|
|
|
1977
2029
|
// src/steps.ts
|
|
@@ -1980,12 +2032,12 @@ import { join as join8 } from "path";
|
|
|
1980
2032
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1981
2033
|
var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1982
2034
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
2035
|
+
var TASK_RUNNERS = new Set(["Justfile", "Makefile"]);
|
|
1983
2036
|
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1984
2037
|
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1985
2038
|
var JUST_TIMEOUT_MS = 1e4;
|
|
1986
2039
|
var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"];
|
|
1987
2040
|
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1988
|
-
var SKIPPED = new Set([...SKIPPED_FOLDERS, "var", "tmp"]);
|
|
1989
2041
|
async function readFirst(dir, files) {
|
|
1990
2042
|
for (const file of files) {
|
|
1991
2043
|
const handle = Bun.file(join8(dir, file));
|
|
@@ -2080,8 +2132,9 @@ async function discoverProjects(dir) {
|
|
|
2080
2132
|
return [{ dir, steps: own }];
|
|
2081
2133
|
const projects = [];
|
|
2082
2134
|
const entries = await readdir2(dir, { withFileTypes: true });
|
|
2135
|
+
const ignored = ignoredFolders(["var", "tmp"]);
|
|
2083
2136
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
2084
|
-
if (!entry.isDirectory() || entry.name.startsWith(".") ||
|
|
2137
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
|
|
2085
2138
|
continue;
|
|
2086
2139
|
const steps = await discover(join8(dir, entry.name));
|
|
2087
2140
|
if (steps.length > 0)
|
|
@@ -2091,8 +2144,9 @@ async function discoverProjects(dir) {
|
|
|
2091
2144
|
}
|
|
2092
2145
|
async function discover(dir) {
|
|
2093
2146
|
const found = await candidates(dir, "check");
|
|
2147
|
+
const runnerCheck = found.find((candidate) => candidate.name === "check" && TASK_RUNNERS.has(candidate.source));
|
|
2094
2148
|
return STEP_NAMES.flatMap((name) => {
|
|
2095
|
-
const step = found.find((candidate) => candidate.name === name);
|
|
2149
|
+
const step = name === "check" && runnerCheck !== undefined ? runnerCheck : found.find((candidate) => candidate.name === name);
|
|
2096
2150
|
return step === undefined ? [] : [step];
|
|
2097
2151
|
});
|
|
2098
2152
|
}
|
|
@@ -2128,16 +2182,17 @@ function list2(dir) {
|
|
|
2128
2182
|
}
|
|
2129
2183
|
function locate(dir, here, names) {
|
|
2130
2184
|
for (let current = dir;; current = join9(current, "..")) {
|
|
2131
|
-
const found = names.find((name) =>
|
|
2185
|
+
const found = names.find((name) => existsSync5(join9(current, name)));
|
|
2132
2186
|
if (found !== undefined)
|
|
2133
2187
|
return join9(current, found);
|
|
2134
2188
|
const absolute = resolvePath(current);
|
|
2135
|
-
if (!here ||
|
|
2189
|
+
if (!here || existsSync5(join9(current, ".git")) || dirname5(absolute) === absolute)
|
|
2136
2190
|
return;
|
|
2137
2191
|
}
|
|
2138
2192
|
}
|
|
2139
2193
|
function children(dir = ".") {
|
|
2140
|
-
|
|
2194
|
+
const ignored = ignoredFolders();
|
|
2195
|
+
return readdirSync(dir, { withFileTypes: true }).filter((child) => child.isDirectory() && !child.name.startsWith(".") && !ignored.has(child.name)).map((child) => child.name).toSorted();
|
|
2141
2196
|
}
|
|
2142
2197
|
function build(base, items) {
|
|
2143
2198
|
return items.map((item) => ({ ...base, doc: null, parameters: [], ...item }));
|
|
@@ -2221,10 +2276,10 @@ function show(source, target) {
|
|
|
2221
2276
|
`).trimEnd();
|
|
2222
2277
|
}
|
|
2223
2278
|
function make(dir) {
|
|
2224
|
-
const file = MAKEFILES.find((name) =>
|
|
2279
|
+
const file = MAKEFILES.find((name) => existsSync5(join9(dir, name)));
|
|
2225
2280
|
if (file === undefined)
|
|
2226
2281
|
return [];
|
|
2227
|
-
const source =
|
|
2282
|
+
const source = readFileSync6(join9(dir, file), "utf-8");
|
|
2228
2283
|
return build({ kind: "make", tag: "make", runner: ["make"], separated: false, dir }, targets2(source).map((target) => ({ ...target, body: show(source, target.name) })));
|
|
2229
2284
|
}
|
|
2230
2285
|
function manager(dir, manifest) {
|
|
@@ -2233,7 +2288,7 @@ function manager(dir, manifest) {
|
|
|
2233
2288
|
if (known !== undefined)
|
|
2234
2289
|
return known[1];
|
|
2235
2290
|
for (let current = resolvePath(dir);; current = dirname5(current)) {
|
|
2236
|
-
const found = LOCKFILES.find(([file]) =>
|
|
2291
|
+
const found = LOCKFILES.find(([file]) => existsSync5(join9(current, file)));
|
|
2237
2292
|
if (found !== undefined)
|
|
2238
2293
|
return found[1];
|
|
2239
2294
|
if (dirname5(current) === current)
|
|
@@ -2247,7 +2302,7 @@ function packageScripts(dir, here) {
|
|
|
2247
2302
|
const file = locate(dir, here, ["package.json"]);
|
|
2248
2303
|
if (file === undefined)
|
|
2249
2304
|
return [];
|
|
2250
|
-
const manifest = JSON.parse(
|
|
2305
|
+
const manifest = JSON.parse(readFileSync6(file, "utf-8"));
|
|
2251
2306
|
const tool = manager(dirname5(file), manifest);
|
|
2252
2307
|
const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, body: text2(command) }));
|
|
2253
2308
|
return build({ kind: "package", tag: tool, runner: [tool, "run"], separated: tool === "npm", dir: dirname5(file) }, items);
|
|
@@ -2256,7 +2311,7 @@ function composer(dir, here) {
|
|
|
2256
2311
|
const file = locate(dir, here, ["composer.json"]);
|
|
2257
2312
|
if (file === undefined)
|
|
2258
2313
|
return [];
|
|
2259
|
-
const manifest = JSON.parse(
|
|
2314
|
+
const manifest = JSON.parse(readFileSync6(file, "utf-8"));
|
|
2260
2315
|
const descriptions = table2(manifest["scripts-descriptions"]);
|
|
2261
2316
|
const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, doc: field(descriptions, name), body: text2(command) }));
|
|
2262
2317
|
return build({ kind: "composer", tag: "composer", runner: ["composer", "run"], separated: true, dir: dirname5(file) }, items);
|
|
@@ -2265,7 +2320,7 @@ function deno(dir, here) {
|
|
|
2265
2320
|
const file = locate(dir, here, ["deno.json", "deno.jsonc"]);
|
|
2266
2321
|
if (file === undefined)
|
|
2267
2322
|
return [];
|
|
2268
|
-
const manifest = Bun.JSONC.parse(
|
|
2323
|
+
const manifest = Bun.JSONC.parse(readFileSync6(file, "utf-8"));
|
|
2269
2324
|
const items = Object.entries(table2(manifest.tasks)).map(([name, task]) => ({ name, doc: field(task, "description"), body: field(task, "command") ?? text2(task) }));
|
|
2270
2325
|
return build({ kind: "deno", tag: "deno", runner: ["deno", "task"], separated: false, dir: dirname5(file) }, items);
|
|
2271
2326
|
}
|
|
@@ -2273,12 +2328,12 @@ function taskfile(dir, here) {
|
|
|
2273
2328
|
const file = locate(dir, here, TASKFILES);
|
|
2274
2329
|
if (file === undefined)
|
|
2275
2330
|
return [];
|
|
2276
|
-
const tasks = table2(Bun.YAML.parse(
|
|
2331
|
+
const tasks = table2(Bun.YAML.parse(readFileSync6(file, "utf-8"))?.tasks);
|
|
2277
2332
|
const items = Object.entries(tasks).filter(([, task]) => !(task !== null && typeof task === "object" && task.internal === true)).map(([name, task]) => ({ name, doc: field(task, "desc") ?? field(task, "summary"), body: text2(task) }));
|
|
2278
2333
|
return build({ kind: "task", tag: "task", runner: ["task"], separated: true, dir: dirname5(file) }, items);
|
|
2279
2334
|
}
|
|
2280
2335
|
function mise(dir, here) {
|
|
2281
|
-
if (!has("mise") || !here && !MISE_FILES.some((name) =>
|
|
2336
|
+
if (!has("mise") || !here && !MISE_FILES.some((name) => existsSync5(join9(dir, name))))
|
|
2282
2337
|
return [];
|
|
2283
2338
|
const proc = Bun.spawnSync(["mise", "tasks", "ls", "--json"], { cwd: dir, stderr: "pipe" });
|
|
2284
2339
|
if (!proc.success)
|
|
@@ -2292,7 +2347,7 @@ function pyproject(dir, here) {
|
|
|
2292
2347
|
const file = locate(dir, here, ["pyproject.toml"]);
|
|
2293
2348
|
if (file === undefined)
|
|
2294
2349
|
return [];
|
|
2295
|
-
const manifest = Bun.TOML.parse(
|
|
2350
|
+
const manifest = Bun.TOML.parse(readFileSync6(file, "utf-8"));
|
|
2296
2351
|
const tool = table2(manifest.tool);
|
|
2297
2352
|
const project = table2(manifest.project);
|
|
2298
2353
|
const uv = locate(dirname5(file), true, ["uv.lock"]) !== undefined;
|
|
@@ -2324,9 +2379,9 @@ function readOr(read, fallback) {
|
|
|
2324
2379
|
}
|
|
2325
2380
|
}
|
|
2326
2381
|
function workspaces() {
|
|
2327
|
-
const manifest = readOr(() => JSON.parse(
|
|
2382
|
+
const manifest = readOr(() => JSON.parse(readFileSync6("package.json", "utf-8")), {});
|
|
2328
2383
|
const declared = Array.isArray(manifest.workspaces) ? manifest.workspaces : table2(manifest.workspaces).packages;
|
|
2329
|
-
const pnpm = readOr(() => table2(Bun.YAML.parse(
|
|
2384
|
+
const pnpm = readOr(() => table2(Bun.YAML.parse(readFileSync6("pnpm-workspace.yaml", "utf-8"))).packages, undefined);
|
|
2330
2385
|
const patterns = [declared, pnpm].flatMap((value) => Array.isArray(value) ? value.filter((pattern) => typeof pattern === "string") : []);
|
|
2331
2386
|
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => new Bun.Glob(pattern.slice(1)));
|
|
2332
2387
|
return patterns.filter((pattern) => !pattern.startsWith("!")).flatMap((pattern) => [...new Bun.Glob(`${pattern.replace(TRAILING_SLASHES, "")}/package.json`).scanSync({ cwd: "." })].map((file) => dirname5(file))).filter((dir) => !dir.split("/").includes("node_modules") && !excluded.some((glob) => glob.match(dir)));
|
|
@@ -2363,7 +2418,7 @@ function key(entry) {
|
|
|
2363
2418
|
function id(entry) {
|
|
2364
2419
|
return `${entry.tag}:${key(entry)}`;
|
|
2365
2420
|
}
|
|
2366
|
-
function
|
|
2421
|
+
function resolve4(entries, named) {
|
|
2367
2422
|
const qualified = QUALIFIED.exec(named);
|
|
2368
2423
|
const tagged = qualified && entries.some((entry) => entry.tag === qualified[1]) ? qualified : undefined;
|
|
2369
2424
|
const pool = tagged ? entries.filter((entry) => entry.tag === tagged[1]) : entries;
|
|
@@ -2372,7 +2427,7 @@ function resolve3(entries, named) {
|
|
|
2372
2427
|
return exact.length > 0 ? exact : pool.filter((entry) => entry.name === rest);
|
|
2373
2428
|
}
|
|
2374
2429
|
function shortest(entries, entry) {
|
|
2375
|
-
const found =
|
|
2430
|
+
const found = resolve4(entries, key(entry));
|
|
2376
2431
|
return found.length === 1 && found[0] === entry ? key(entry) : id(entry);
|
|
2377
2432
|
}
|
|
2378
2433
|
function signature(entry) {
|
|
@@ -2385,7 +2440,7 @@ function labelled(entries) {
|
|
|
2385
2440
|
return new Set(entries.map((entry) => entry.tag)).size > 1;
|
|
2386
2441
|
}
|
|
2387
2442
|
function row(entry, labels, signed) {
|
|
2388
|
-
const colors = paint(
|
|
2443
|
+
const colors = paint(process21.stderr);
|
|
2389
2444
|
const keyed = entry.dir === "." ? entry.name : `${colors.dim(`${entry.dir}/`)}${entry.name}`;
|
|
2390
2445
|
return {
|
|
2391
2446
|
hidden: [entry.kind, entry.dir, entry.name, id(entry)],
|
|
@@ -2399,7 +2454,7 @@ async function pickJob(entries, narrowed = false) {
|
|
|
2399
2454
|
prompt: `${[...new Set(entries.map((entry) => entry.tag))].join("/")}> `,
|
|
2400
2455
|
searched: labels ? 2 : 1,
|
|
2401
2456
|
...narrowed ? { height: heightFor(entries.length) } : {},
|
|
2402
|
-
preview: `${
|
|
2457
|
+
preview: `${process21.execPath} ${process21.argv[1]} --show {1} {2} {3}`
|
|
2403
2458
|
});
|
|
2404
2459
|
return entries.find((candidate) => id(candidate) === picked?.hidden[3]);
|
|
2405
2460
|
}
|
|
@@ -2421,7 +2476,7 @@ function preview(kind, dir, name) {
|
|
|
2421
2476
|
const entry = readKind(kind, dir).find((candidate) => candidate.name === name);
|
|
2422
2477
|
if (entry === undefined)
|
|
2423
2478
|
return;
|
|
2424
|
-
const colors = paint(
|
|
2479
|
+
const colors = paint(process22.stdout);
|
|
2425
2480
|
console.log(`${colors.dim(`$ ${dir === "." ? "" : `env -C ${dir} `}`)}${colors.bold([...entry.runner, entry.name].join(" "))}
|
|
2426
2481
|
`);
|
|
2427
2482
|
if (entry.body !== undefined)
|
|
@@ -2432,7 +2487,7 @@ function preview(kind, dir, name) {
|
|
|
2432
2487
|
function names(found) {
|
|
2433
2488
|
const described = (entry) => entry.doc === null || entry.doc === "" ? entry.tag : entry.doc;
|
|
2434
2489
|
return [...new Set(found.map(key))].flatMap((name) => {
|
|
2435
|
-
const same =
|
|
2490
|
+
const same = resolve4(found, name);
|
|
2436
2491
|
return same.length === 1 ? [[name, described(same[0])]] : [[name, same.map((entry) => entry.tag).join(", ")], ...same.map((entry) => [id(entry), described(entry)])];
|
|
2437
2492
|
});
|
|
2438
2493
|
}
|
|
@@ -2453,13 +2508,10 @@ function listed2(found) {
|
|
|
2453
2508
|
editsTyped: true
|
|
2454
2509
|
}));
|
|
2455
2510
|
}
|
|
2456
|
-
function
|
|
2457
|
-
const colors = paint(
|
|
2511
|
+
function listing(found) {
|
|
2512
|
+
const colors = paint(process22.stdout);
|
|
2458
2513
|
const labels = labelled(found);
|
|
2459
|
-
|
|
2460
|
-
const widths = rows[0]?.map((_, column) => Math.max(...rows.map((cells) => cells[column].length))) ?? [];
|
|
2461
|
-
return found.map((entry, index) => `${rows[index].map((cell, column) => cell.padEnd(widths[column])).join(" ")} ${colors.dim(entry.doc ?? "")}`.trimEnd()).join(`
|
|
2462
|
-
`);
|
|
2514
|
+
return table(found.map((entry) => [...labels ? [entry.tag] : [], key(entry), signature(entry), colors.dim(entry.doc ?? "")]));
|
|
2463
2515
|
}
|
|
2464
2516
|
function missing(entry, given) {
|
|
2465
2517
|
return entry.parameters.slice(given.length).filter((parameter) => parameter.default === null && parameter.kind === "singular").map((parameter) => parameter.name);
|
|
@@ -2522,12 +2574,12 @@ async function j2(argv) {
|
|
|
2522
2574
|
if (parsed.values.json === true)
|
|
2523
2575
|
printJson(found.map((each) => ({ id: id(each), key: key(each), runner: each.tag, dir: each.dir, name: each.name, doc: each.doc, parameters: each.parameters })));
|
|
2524
2576
|
else
|
|
2525
|
-
console.log(
|
|
2577
|
+
console.log(listing(found));
|
|
2526
2578
|
return 0;
|
|
2527
2579
|
}
|
|
2528
2580
|
entry = await pickJob(byRecency(found, previous, id));
|
|
2529
2581
|
} else {
|
|
2530
|
-
const matching =
|
|
2582
|
+
const matching = resolve4(found, named);
|
|
2531
2583
|
if (matching.length === 0) {
|
|
2532
2584
|
const nearest = closest(named, found.map(key));
|
|
2533
2585
|
fail(`nothing named ${named}${nearest === undefined ? "" : `, did you mean ${nearest}?`}`, 1);
|
|
@@ -2557,4 +2609,4 @@ async function j2(argv) {
|
|
|
2557
2609
|
}
|
|
2558
2610
|
|
|
2559
2611
|
// src/j-cli.ts
|
|
2560
|
-
|
|
2612
|
+
process23.exitCode = await runMain({ name: "j", version, run: j2 });
|