@kaynooo/cli-check 0.18.3 → 0.20.1
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 -3
- package/dist/cli.js +401 -723
- package/dist/errs-cli.js +384 -221
- package/dist/fix-cli.js +348 -698
- package/dist/j-cli.js +675 -132
- package/package.json +2 -2
package/dist/j-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/j-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process26 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -461,7 +461,7 @@ function printJson(value) {
|
|
|
461
461
|
|
|
462
462
|
// ../kit/src/help.ts
|
|
463
463
|
import process8 from "process";
|
|
464
|
-
var OPTIONAL =
|
|
464
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
465
465
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
466
466
|
var FULL_STOP = /\.$/;
|
|
467
467
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -500,32 +500,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
500
500
|
return [];
|
|
501
501
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
502
502
|
}
|
|
503
|
+
var MAX_INLINE_CHOICES = 24;
|
|
503
504
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
504
505
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
505
506
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
506
|
-
const
|
|
507
|
+
const choices = option.choices?.join("|");
|
|
508
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
509
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
507
510
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
508
511
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
509
|
-
|
|
512
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
513
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
510
514
|
});
|
|
511
515
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
512
516
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
513
517
|
}
|
|
514
518
|
|
|
515
519
|
// ../kit/src/text.ts
|
|
516
|
-
var ANSI =
|
|
520
|
+
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
517
521
|
function stripAnsi(text) {
|
|
518
522
|
return text.replace(ANSI, "");
|
|
519
523
|
}
|
|
520
524
|
function distance(a, b) {
|
|
521
|
-
|
|
522
|
-
|
|
525
|
+
const left = [...a];
|
|
526
|
+
const right = [...b];
|
|
527
|
+
let before = [];
|
|
528
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
529
|
+
for (const [i, x] of left.entries()) {
|
|
523
530
|
const current = [i + 1];
|
|
524
|
-
for (const [j,
|
|
525
|
-
|
|
531
|
+
for (const [j, y] of right.entries()) {
|
|
532
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
533
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
534
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
535
|
+
current.push(cost);
|
|
536
|
+
}
|
|
537
|
+
before = previous;
|
|
526
538
|
previous = current;
|
|
527
539
|
}
|
|
528
|
-
return previous[
|
|
540
|
+
return previous[right.length] ?? 0;
|
|
529
541
|
}
|
|
530
542
|
function closest(name, names) {
|
|
531
543
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -604,7 +616,7 @@ class Completing {
|
|
|
604
616
|
}
|
|
605
617
|
var completion = { active: false };
|
|
606
618
|
var OUTPUT_OPTIONS = {
|
|
607
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
619
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
608
620
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
609
621
|
};
|
|
610
622
|
function applyOutput(color, plain, env = process10.env) {
|
|
@@ -930,31 +942,109 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
930
942
|
// ../kit/src/cli.ts
|
|
931
943
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
932
944
|
import { dirname as dirname3, join as join6 } from "path";
|
|
933
|
-
import
|
|
945
|
+
import process16 from "process";
|
|
946
|
+
|
|
947
|
+
// ../kit/src/completions.ts
|
|
948
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
949
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
950
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
951
|
+
set -l current (commandline -ct)
|
|
952
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
953
|
+
if test "$line" = __files__
|
|
954
|
+
__fish_complete_path $current
|
|
955
|
+
else
|
|
956
|
+
echo $line
|
|
957
|
+
end
|
|
958
|
+
end
|
|
959
|
+
end`;
|
|
960
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
961
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
962
|
+
local -a lines
|
|
963
|
+
COMPREPLY=()
|
|
964
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
965
|
+
for line in "\${lines[@]}"; do
|
|
966
|
+
if [[ $line == __files__ ]]; then
|
|
967
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
968
|
+
else
|
|
969
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
970
|
+
fi
|
|
971
|
+
done
|
|
972
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
973
|
+
}`;
|
|
974
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
975
|
+
local line
|
|
976
|
+
local -a described plain
|
|
977
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
978
|
+
if [[ $line == __files__ ]]; then
|
|
979
|
+
_files
|
|
980
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
981
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
982
|
+
else
|
|
983
|
+
plain+=("$line")
|
|
984
|
+
fi
|
|
985
|
+
done
|
|
986
|
+
(( \${#described} )) && _describe -V value described
|
|
987
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
988
|
+
return 0
|
|
989
|
+
}`;
|
|
990
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
991
|
+
if (shell === "fish")
|
|
992
|
+
return `${header}
|
|
993
|
+
${FISH_FUNCTION}
|
|
994
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
995
|
+
`).join("")}`;
|
|
996
|
+
if (shell === "bash")
|
|
997
|
+
return `${header}
|
|
998
|
+
${BASH_FUNCTION}
|
|
999
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1000
|
+
`;
|
|
1001
|
+
return `${header}
|
|
1002
|
+
${ZSH_FUNCTION}
|
|
1003
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1004
|
+
`;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// ../kit/src/notify.ts
|
|
1008
|
+
import process13 from "process";
|
|
1009
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1010
|
+
var CANCELLED = 130;
|
|
1011
|
+
function base64(text) {
|
|
1012
|
+
return Buffer.from(text).toString("base64");
|
|
1013
|
+
}
|
|
1014
|
+
function notification(title, body, env = process13.env) {
|
|
1015
|
+
const id = `kit${process13.pid}`;
|
|
1016
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1017
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1018
|
+
}
|
|
1019
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1020
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1021
|
+
return;
|
|
1022
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1023
|
+
}
|
|
934
1024
|
|
|
935
1025
|
// ../kit/src/usage.ts
|
|
936
1026
|
import { appendFileSync, mkdirSync } from "fs";
|
|
937
1027
|
import { homedir as homedir4 } from "os";
|
|
938
1028
|
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
939
|
-
import
|
|
1029
|
+
import process15 from "process";
|
|
940
1030
|
|
|
941
1031
|
// ../kit/src/logs.ts
|
|
942
1032
|
import { lstatSync, openSync } from "fs";
|
|
943
1033
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
944
1034
|
import { homedir as homedir3, tmpdir } from "os";
|
|
945
1035
|
import { join as join4 } from "path";
|
|
946
|
-
import
|
|
1036
|
+
import process14 from "process";
|
|
947
1037
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
948
1038
|
var CLI_FOLDER = "kaynooo-cli";
|
|
949
1039
|
function isPrivateDirectory(path) {
|
|
950
1040
|
try {
|
|
951
1041
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
952
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1042
|
+
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
953
1043
|
} catch {
|
|
954
1044
|
return false;
|
|
955
1045
|
}
|
|
956
1046
|
}
|
|
957
|
-
async function privateLogDirectory(name, env =
|
|
1047
|
+
async function privateLogDirectory(name, env = process14.env) {
|
|
958
1048
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
959
1049
|
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
960
1050
|
const path = join4(base, name);
|
|
@@ -994,14 +1084,14 @@ var usageError;
|
|
|
994
1084
|
function noteUsageError(message) {
|
|
995
1085
|
usageError = message;
|
|
996
1086
|
}
|
|
997
|
-
function stateHome(env =
|
|
1087
|
+
function stateHome(env = process15.env) {
|
|
998
1088
|
const dir = env.XDG_STATE_HOME;
|
|
999
1089
|
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1000
1090
|
}
|
|
1001
|
-
function usagePath(env =
|
|
1091
|
+
function usagePath(env = process15.env) {
|
|
1002
1092
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1003
1093
|
}
|
|
1004
|
-
function usageRecorded(env =
|
|
1094
|
+
function usageRecorded(env = process15.env) {
|
|
1005
1095
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1006
1096
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1007
1097
|
}
|
|
@@ -1015,7 +1105,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1015
1105
|
usageError = undefined;
|
|
1016
1106
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1017
1107
|
}
|
|
1018
|
-
function recordUsage(entry, env =
|
|
1108
|
+
function recordUsage(entry, env = process15.env) {
|
|
1019
1109
|
if (!usageRecorded(env))
|
|
1020
1110
|
return;
|
|
1021
1111
|
try {
|
|
@@ -1031,10 +1121,14 @@ var LEVEL_OPTIONS = {
|
|
|
1031
1121
|
...OUTPUT_OPTIONS,
|
|
1032
1122
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1033
1123
|
};
|
|
1034
|
-
var TOP_OPTIONS = {
|
|
1124
|
+
var TOP_OPTIONS = {
|
|
1125
|
+
...LEVEL_OPTIONS,
|
|
1126
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1127
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1128
|
+
};
|
|
1035
1129
|
function printError(prefix, message, hint, cause) {
|
|
1036
|
-
const colors = paint(
|
|
1037
|
-
const styled = takesControlCodes(
|
|
1130
|
+
const colors = paint(process16.stderr);
|
|
1131
|
+
const styled = takesControlCodes(process16.stderr);
|
|
1038
1132
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1039
1133
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1040
1134
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1111,6 +1205,19 @@ async function leafCandidates(run, words) {
|
|
|
1111
1205
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1112
1206
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1113
1207
|
}
|
|
1208
|
+
var COMPLETIONS = "--completions";
|
|
1209
|
+
function flagValue([flag = "", ...rest]) {
|
|
1210
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1211
|
+
}
|
|
1212
|
+
function printCompletionScript(name, args) {
|
|
1213
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1214
|
+
if (shell === undefined || args.length !== 1) {
|
|
1215
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1216
|
+
return 2;
|
|
1217
|
+
}
|
|
1218
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1219
|
+
return 0;
|
|
1220
|
+
}
|
|
1114
1221
|
async function printCandidates(found) {
|
|
1115
1222
|
for (const line of await found)
|
|
1116
1223
|
console.log(line);
|
|
@@ -1134,16 +1241,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1134
1241
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1135
1242
|
if (argv[0] === COMPLETE)
|
|
1136
1243
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1244
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1245
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1137
1246
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1138
1247
|
console.log(version ?? packageVersion());
|
|
1139
1248
|
return 0;
|
|
1140
1249
|
}
|
|
1141
1250
|
let code;
|
|
1251
|
+
const started = performance.now();
|
|
1142
1252
|
try {
|
|
1143
1253
|
code = await run(argv);
|
|
1144
1254
|
} catch (error) {
|
|
1145
1255
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1146
1256
|
}
|
|
1257
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1147
1258
|
if (usage !== false) {
|
|
1148
1259
|
try {
|
|
1149
1260
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1151,13 +1262,174 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1151
1262
|
}
|
|
1152
1263
|
return code;
|
|
1153
1264
|
}
|
|
1265
|
+
// ../kit/src/excerpt.ts
|
|
1266
|
+
var BASH_ECHO = /^\$ /;
|
|
1267
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1268
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1269
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1270
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1271
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1272
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1273
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1274
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
1275
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1276
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
1277
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1278
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1279
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1280
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1281
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1282
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1283
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1284
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1285
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1286
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1287
|
+
var MAX_TESTS = 10;
|
|
1288
|
+
var MAX_LINES = 100;
|
|
1289
|
+
var TAIL = 30;
|
|
1290
|
+
var bunTest = (lines) => {
|
|
1291
|
+
const seen = new Set;
|
|
1292
|
+
const blocks = [];
|
|
1293
|
+
for (const [index, line] of lines.entries()) {
|
|
1294
|
+
const name = line.replace(DURATION2, "");
|
|
1295
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1296
|
+
continue;
|
|
1297
|
+
seen.add(name);
|
|
1298
|
+
if (blocks.length < MAX_TESTS)
|
|
1299
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1300
|
+
`).trim());
|
|
1301
|
+
}
|
|
1302
|
+
if (blocks.length === 0)
|
|
1303
|
+
return;
|
|
1304
|
+
if (seen.size > MAX_TESTS)
|
|
1305
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1306
|
+
return [...blocks.join(`
|
|
1307
|
+
|
|
1308
|
+
`).split(`
|
|
1309
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1310
|
+
};
|
|
1311
|
+
var bunCheck = (lines) => {
|
|
1312
|
+
const text = lines.join(`
|
|
1313
|
+
`);
|
|
1314
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1315
|
+
if (blocks === null)
|
|
1316
|
+
return;
|
|
1317
|
+
const errors = blocks.map((block) => {
|
|
1318
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1319
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1320
|
+
});
|
|
1321
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1322
|
+
};
|
|
1323
|
+
function bunCheckFields(block) {
|
|
1324
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1325
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1326
|
+
return {
|
|
1327
|
+
file: attributes.file ?? "",
|
|
1328
|
+
line: attributes.line ?? "",
|
|
1329
|
+
column: attributes.column ?? "",
|
|
1330
|
+
code: attributes.code ?? "",
|
|
1331
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1332
|
+
`).slice(1, -1).join(`
|
|
1333
|
+
`).trim()
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
var tsc = (lines) => {
|
|
1337
|
+
const kept = [];
|
|
1338
|
+
let inError = false;
|
|
1339
|
+
for (const line of lines) {
|
|
1340
|
+
if (TSC_ERROR.test(line)) {
|
|
1341
|
+
inError = true;
|
|
1342
|
+
kept.push(line);
|
|
1343
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
1344
|
+
inError = false;
|
|
1345
|
+
kept.push(line);
|
|
1346
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1347
|
+
kept.push(line);
|
|
1348
|
+
} else {
|
|
1349
|
+
inError = false;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1353
|
+
};
|
|
1354
|
+
var eslint = (lines) => {
|
|
1355
|
+
const kept = [];
|
|
1356
|
+
let file = "";
|
|
1357
|
+
let shown = "";
|
|
1358
|
+
for (const line of lines) {
|
|
1359
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
1360
|
+
if (file !== shown) {
|
|
1361
|
+
kept.push(file);
|
|
1362
|
+
shown = file;
|
|
1363
|
+
}
|
|
1364
|
+
kept.push(line);
|
|
1365
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1366
|
+
kept.push(line);
|
|
1367
|
+
} else if (line.trim() !== "") {
|
|
1368
|
+
file = line;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1372
|
+
};
|
|
1373
|
+
var phpstan = (lines) => {
|
|
1374
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1375
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1376
|
+
};
|
|
1377
|
+
var php = (lines) => {
|
|
1378
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1379
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1380
|
+
};
|
|
1381
|
+
var vitest = (lines) => {
|
|
1382
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1383
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1384
|
+
};
|
|
1385
|
+
var playwright = (lines) => {
|
|
1386
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1387
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
1388
|
+
};
|
|
1389
|
+
var phpCsFixer = (lines) => {
|
|
1390
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1391
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1392
|
+
};
|
|
1393
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1394
|
+
function squeeze(lines) {
|
|
1395
|
+
const out = [];
|
|
1396
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1397
|
+
if (line !== "" || out.at(-1) !== "")
|
|
1398
|
+
out.push(line);
|
|
1399
|
+
}
|
|
1400
|
+
while (out.at(-1) === "")
|
|
1401
|
+
out.pop();
|
|
1402
|
+
return out;
|
|
1403
|
+
}
|
|
1404
|
+
function cut(shown) {
|
|
1405
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1406
|
+
`) : shown.join(`
|
|
1407
|
+
`);
|
|
1408
|
+
}
|
|
1409
|
+
function recognised(lines, parsers) {
|
|
1410
|
+
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1411
|
+
}
|
|
1412
|
+
function failureExcerpt(output) {
|
|
1413
|
+
const lines = stripAnsi(output).split(`
|
|
1414
|
+
`);
|
|
1415
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1416
|
+
lines.shift();
|
|
1417
|
+
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1418
|
+
}
|
|
1419
|
+
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
1154
1420
|
// ../kit/src/folders.ts
|
|
1421
|
+
import { homedir as homedir5 } from "os";
|
|
1422
|
+
import { join as join7 } from "path";
|
|
1423
|
+
import process17 from "process";
|
|
1155
1424
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1156
1425
|
function ignoredFolders(extra = [], where = {}) {
|
|
1157
1426
|
const configured = readUserConfig("config", where).ignore;
|
|
1158
1427
|
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1159
1428
|
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1160
1429
|
}
|
|
1430
|
+
function cacheFolder({ home = homedir5(), env = process17.env } = {}) {
|
|
1431
|
+
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
1432
|
+
}
|
|
1161
1433
|
// ../kit/src/secrets.ts
|
|
1162
1434
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1163
1435
|
// ../kit/src/sessions.ts
|
|
@@ -1165,21 +1437,133 @@ var {Glob } = globalThis.Bun;
|
|
|
1165
1437
|
var SESSION_FILES = new Glob("*.json");
|
|
1166
1438
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1167
1439
|
// package.json
|
|
1168
|
-
var version = "0.
|
|
1440
|
+
var version = "0.20.1";
|
|
1169
1441
|
|
|
1170
1442
|
// src/j.ts
|
|
1171
|
-
import
|
|
1443
|
+
import process25 from "process";
|
|
1172
1444
|
|
|
1173
1445
|
// ../kit/src/picker.ts
|
|
1174
1446
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
1175
|
-
import {
|
|
1176
|
-
import
|
|
1177
|
-
|
|
1447
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1448
|
+
import process22 from "process";
|
|
1449
|
+
|
|
1450
|
+
// ../kit/src/picker/line.ts
|
|
1451
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1452
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1453
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1454
|
+
function isEditKey(key) {
|
|
1455
|
+
return EDIT_KEYS.has(key);
|
|
1456
|
+
}
|
|
1457
|
+
function endsKills(key) {
|
|
1458
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
1459
|
+
}
|
|
1460
|
+
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1461
|
+
var SPACE = /\s/;
|
|
1462
|
+
function isWord(char) {
|
|
1463
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
1464
|
+
}
|
|
1465
|
+
function wordStart(chars, from) {
|
|
1466
|
+
let at = from;
|
|
1467
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
1468
|
+
at--;
|
|
1469
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
1470
|
+
at--;
|
|
1471
|
+
return at;
|
|
1472
|
+
}
|
|
1473
|
+
function wordEnd(chars, from) {
|
|
1474
|
+
let at = from;
|
|
1475
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
1476
|
+
at++;
|
|
1477
|
+
while (at < chars.length && isWord(chars[at]))
|
|
1478
|
+
at++;
|
|
1479
|
+
return at;
|
|
1480
|
+
}
|
|
1481
|
+
function spacedStart(chars, from) {
|
|
1482
|
+
let at = from;
|
|
1483
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
1484
|
+
at--;
|
|
1485
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1486
|
+
at--;
|
|
1487
|
+
return at;
|
|
1488
|
+
}
|
|
1489
|
+
function cut2(chars, from, to) {
|
|
1490
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1491
|
+
}
|
|
1492
|
+
function insert(chars, at, text) {
|
|
1493
|
+
const typed = [...text];
|
|
1494
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1495
|
+
}
|
|
1496
|
+
function editLine(line, key) {
|
|
1497
|
+
const { killed = "", chained = false } = line;
|
|
1498
|
+
const chars = [...line.text];
|
|
1499
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1500
|
+
const edited = edit(chars, at, key, killed);
|
|
1501
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1502
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1503
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1504
|
+
if (taken === "")
|
|
1505
|
+
return { ...edited, killed, chained };
|
|
1506
|
+
if (!chained)
|
|
1507
|
+
return { ...edited, killed: taken, chained: true };
|
|
1508
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1509
|
+
}
|
|
1510
|
+
function edit(chars, at, key, killed) {
|
|
1511
|
+
const text = chars.join("");
|
|
1512
|
+
if (typeof key === "object")
|
|
1513
|
+
return insert(chars, at, key.text);
|
|
1514
|
+
switch (key) {
|
|
1515
|
+
case "left":
|
|
1516
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
1517
|
+
case "right":
|
|
1518
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1519
|
+
case "wordleft":
|
|
1520
|
+
return { text, caret: wordStart(chars, at) };
|
|
1521
|
+
case "wordright":
|
|
1522
|
+
return { text, caret: wordEnd(chars, at) };
|
|
1523
|
+
case "linestart":
|
|
1524
|
+
return { text, caret: 0 };
|
|
1525
|
+
case "lineend":
|
|
1526
|
+
return { text, caret: chars.length };
|
|
1527
|
+
case "erase":
|
|
1528
|
+
return cut2(chars, Math.max(at - 1, 0), at);
|
|
1529
|
+
case "delete":
|
|
1530
|
+
return cut2(chars, at, Math.min(at + 1, chars.length));
|
|
1531
|
+
case "word":
|
|
1532
|
+
return cut2(chars, spacedStart(chars, at), at);
|
|
1533
|
+
case "killword":
|
|
1534
|
+
return cut2(chars, wordStart(chars, at), at);
|
|
1535
|
+
case "killnext":
|
|
1536
|
+
return cut2(chars, at, wordEnd(chars, at));
|
|
1537
|
+
case "clear":
|
|
1538
|
+
return cut2(chars, 0, at);
|
|
1539
|
+
case "killend":
|
|
1540
|
+
return cut2(chars, at, chars.length);
|
|
1541
|
+
case "yank":
|
|
1542
|
+
return insert(chars, at, killed);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
function visible({ text, caret }, room) {
|
|
1546
|
+
const chars = [...text];
|
|
1547
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1548
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1549
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1550
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1551
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1552
|
+
let start = at;
|
|
1553
|
+
let end = at + 1;
|
|
1554
|
+
while (start > 0 && fits(start - 1, end))
|
|
1555
|
+
start--;
|
|
1556
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1557
|
+
end++;
|
|
1558
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1559
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1560
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1561
|
+
}
|
|
1178
1562
|
|
|
1179
1563
|
// ../kit/src/picker/score.ts
|
|
1180
1564
|
var MATCH = 16;
|
|
1181
1565
|
var CONSECUTIVE = 12;
|
|
1182
|
-
var
|
|
1566
|
+
var BOUNDARY2 = 10;
|
|
1183
1567
|
var PREFIX = 8;
|
|
1184
1568
|
var GAP = 1;
|
|
1185
1569
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1216,7 +1600,7 @@ function fuzzy(query, text) {
|
|
|
1216
1600
|
}
|
|
1217
1601
|
if (haystack[i] !== needle[j])
|
|
1218
1602
|
continue;
|
|
1219
|
-
const here = MATCH + (startsWord(text, i) ?
|
|
1603
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY2 : 0) + (i === 0 ? PREFIX : 0);
|
|
1220
1604
|
if (j === 0) {
|
|
1221
1605
|
best[0][i] = here - i * GAP;
|
|
1222
1606
|
continue;
|
|
@@ -1260,7 +1644,6 @@ function rank(query, lines) {
|
|
|
1260
1644
|
}
|
|
1261
1645
|
|
|
1262
1646
|
// ../kit/src/picker/state.ts
|
|
1263
|
-
var ANSI2 = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
1264
1647
|
var CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1265
1648
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1266
1649
|
var SGR = /^\x1B\[[0-9;]*m$/;
|
|
@@ -1268,7 +1651,6 @@ var RESET = /^\x1B\[0?m$/;
|
|
|
1268
1651
|
var COLUMN_GAP = 2;
|
|
1269
1652
|
var PASTE_START = "\x1B[200~";
|
|
1270
1653
|
var PASTE_END = "\x1B[201~";
|
|
1271
|
-
var LAST_WORD = /\S*\s*$/;
|
|
1272
1654
|
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1273
1655
|
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1274
1656
|
var WHEEL_LINES = 3;
|
|
@@ -1291,10 +1673,29 @@ var KEYS = {
|
|
|
1291
1673
|
"\n": "enter",
|
|
1292
1674
|
"\x03": "cancel",
|
|
1293
1675
|
"\x1B": "cancel",
|
|
1676
|
+
"\x1B[D": "left",
|
|
1677
|
+
"\x1BOD": "left",
|
|
1678
|
+
"\x1B[C": "right",
|
|
1679
|
+
"\x1BOC": "right",
|
|
1680
|
+
"\x1B[1;5D": "wordleft",
|
|
1681
|
+
"\x1B[1;3D": "wordleft",
|
|
1682
|
+
"\x1Bb": "wordleft",
|
|
1683
|
+
"\x1B[1;5C": "wordright",
|
|
1684
|
+
"\x1B[1;3C": "wordright",
|
|
1685
|
+
"\x1Bf": "wordright",
|
|
1686
|
+
"\x01": "linestart",
|
|
1687
|
+
"\x05": "lineend",
|
|
1294
1688
|
"\x7F": "erase",
|
|
1295
|
-
"\
|
|
1689
|
+
"\x1B[3~": "delete",
|
|
1690
|
+
"\b": "killword",
|
|
1691
|
+
"\x1B\x7F": "killword",
|
|
1692
|
+
"\x1B[3;5~": "killnext",
|
|
1693
|
+
"\x1Bd": "killnext",
|
|
1296
1694
|
"\x15": "clear",
|
|
1695
|
+
"\v": "killend",
|
|
1297
1696
|
"\x17": "word",
|
|
1697
|
+
"\x19": "yank",
|
|
1698
|
+
"\x1A": "suspend",
|
|
1298
1699
|
"\t": "tab",
|
|
1299
1700
|
"\x1F": "help",
|
|
1300
1701
|
"\x1BOP": "help",
|
|
@@ -1316,7 +1717,7 @@ function styled(line) {
|
|
|
1316
1717
|
colored ||= active !== "" && flat !== "";
|
|
1317
1718
|
styles.push(...repeat(active, flat.length));
|
|
1318
1719
|
}
|
|
1319
|
-
for (const found of line.matchAll(
|
|
1720
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1320
1721
|
add(line.slice(last, found.index));
|
|
1321
1722
|
last = found.index + found[0].length;
|
|
1322
1723
|
if (SGR.test(found[0]))
|
|
@@ -1328,7 +1729,7 @@ function styled(line) {
|
|
|
1328
1729
|
function lay(rows, searched) {
|
|
1329
1730
|
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1330
1731
|
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1331
|
-
return parsed.map((cells) => {
|
|
1732
|
+
return parsed.map((cells, at) => {
|
|
1332
1733
|
let text = "";
|
|
1333
1734
|
const styles = [];
|
|
1334
1735
|
let colored = false;
|
|
@@ -1347,7 +1748,7 @@ function lay(rows, searched) {
|
|
|
1347
1748
|
styles.push(...repeat("", pad));
|
|
1348
1749
|
}
|
|
1349
1750
|
}
|
|
1350
|
-
return { text, styles: colored ? styles : undefined, searchable: text.slice(0, searchEnd) };
|
|
1751
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1351
1752
|
});
|
|
1352
1753
|
}
|
|
1353
1754
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
@@ -1371,7 +1772,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1371
1772
|
});
|
|
1372
1773
|
}
|
|
1373
1774
|
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1374
|
-
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1775
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1375
1776
|
return withRows(state, rows);
|
|
1376
1777
|
}
|
|
1377
1778
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1381,8 +1782,9 @@ function withRows(state, rows, header = state.header) {
|
|
|
1381
1782
|
const matches = rank(state.query, searchable);
|
|
1382
1783
|
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1383
1784
|
}
|
|
1384
|
-
function withQuery(state,
|
|
1385
|
-
|
|
1785
|
+
function withQuery(state, key) {
|
|
1786
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1787
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1386
1788
|
}
|
|
1387
1789
|
function move(state, by) {
|
|
1388
1790
|
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
@@ -1393,13 +1795,17 @@ function highlighted(state) {
|
|
|
1393
1795
|
function press(state, key) {
|
|
1394
1796
|
if (state.done !== undefined)
|
|
1395
1797
|
return state;
|
|
1798
|
+
if (state.chained && endsKills(key))
|
|
1799
|
+
state = { ...state, chained: false };
|
|
1396
1800
|
if (state.help)
|
|
1397
1801
|
return { ...state, help: false };
|
|
1398
1802
|
if (typeof key === "object") {
|
|
1399
1803
|
if ("text" in key)
|
|
1400
|
-
return withQuery(state,
|
|
1804
|
+
return withQuery(state, key);
|
|
1401
1805
|
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1402
1806
|
}
|
|
1807
|
+
if (isEditKey(key))
|
|
1808
|
+
return withQuery(state, key);
|
|
1403
1809
|
switch (key) {
|
|
1404
1810
|
case "up":
|
|
1405
1811
|
return move(state, -1);
|
|
@@ -1417,12 +1823,8 @@ function press(state, key) {
|
|
|
1417
1823
|
return { ...state, done: "cancel" };
|
|
1418
1824
|
case "help":
|
|
1419
1825
|
return { ...state, help: true };
|
|
1420
|
-
case "
|
|
1421
|
-
return
|
|
1422
|
-
case "clear":
|
|
1423
|
-
return withQuery(state, "");
|
|
1424
|
-
case "word":
|
|
1425
|
-
return withQuery(state, state.query.replace(LAST_WORD, ""));
|
|
1826
|
+
case "suspend":
|
|
1827
|
+
return state;
|
|
1426
1828
|
case "enter":
|
|
1427
1829
|
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1428
1830
|
case "tab": {
|
|
@@ -1445,11 +1847,28 @@ function chosen(state) {
|
|
|
1445
1847
|
|
|
1446
1848
|
// ../kit/src/picker/terminal.ts
|
|
1447
1849
|
import { openSync as openSync2 } from "fs";
|
|
1448
|
-
import
|
|
1850
|
+
import process21 from "process";
|
|
1449
1851
|
import tty from "tty";
|
|
1450
1852
|
|
|
1853
|
+
// ../kit/src/job.ts
|
|
1854
|
+
import process19 from "process";
|
|
1855
|
+
function stopJob() {
|
|
1856
|
+
process19.kill(0, "SIGTSTP");
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// ../kit/src/redraw.ts
|
|
1860
|
+
var SYNC_START = "\x1B[?2026h";
|
|
1861
|
+
var SYNC_END = "\x1B[?2026l";
|
|
1862
|
+
function overwrite(lines, columns) {
|
|
1863
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1864
|
+
`);
|
|
1865
|
+
}
|
|
1866
|
+
function rowsTaken(lines, columns) {
|
|
1867
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1451
1870
|
// ../kit/src/picker/preview.ts
|
|
1452
|
-
import
|
|
1871
|
+
import process20 from "process";
|
|
1453
1872
|
|
|
1454
1873
|
// ../kit/src/shell.ts
|
|
1455
1874
|
var SEPARATORS = new Set([`
|
|
@@ -1518,7 +1937,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1518
1937
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1519
1938
|
const stop = () => {
|
|
1520
1939
|
try {
|
|
1521
|
-
|
|
1940
|
+
process20.kill(-proc.pid, "SIGKILL");
|
|
1522
1941
|
} catch {
|
|
1523
1942
|
proc.kill();
|
|
1524
1943
|
}
|
|
@@ -1593,13 +2012,20 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1593
2012
|
const { text, styles } = styled(line);
|
|
1594
2013
|
return fit(text, width, plain, plain, new Set, styles);
|
|
1595
2014
|
}
|
|
1596
|
-
function
|
|
1597
|
-
return
|
|
2015
|
+
function queryShown(state, layout) {
|
|
2016
|
+
return visible({ text: state.query, caret: state.caret }, Math.max(1, layout.listWidth - Bun.stringWidth(state.prompt)));
|
|
2017
|
+
}
|
|
2018
|
+
function caretCell(state, layout) {
|
|
2019
|
+
const shown = queryShown(state, layout);
|
|
2020
|
+
return { column: Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + shown.column + 1), char: shown.at ?? " " };
|
|
1598
2021
|
}
|
|
1599
2022
|
function helpLines(state, layout, theme) {
|
|
1600
2023
|
const lines = [
|
|
1601
2024
|
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
|
|
1602
|
-
|
|
2025
|
+
"left, right, ctrl-a, ctrl-e move in the query, ctrl or alt with left or right by a word",
|
|
2026
|
+
"ctrl-w or ctrl-backspace erase a word, ctrl-u back to the start, ctrl-k to the end, del ahead",
|
|
2027
|
+
"ctrl-y puts back what they erased, ctrl-z suspends to the shell",
|
|
2028
|
+
`enter picks${state.multi ? ", tab marks" : ""}, esc or ctrl-c cancels`,
|
|
1603
2029
|
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1604
2030
|
];
|
|
1605
2031
|
const title = "keys, any key closes this help";
|
|
@@ -1615,7 +2041,9 @@ function listLines(state, layout, theme) {
|
|
|
1615
2041
|
const top = Math.max(0, Math.min(state.cursor - Math.floor(rows / 2), state.matches.length - rows));
|
|
1616
2042
|
const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
|
|
1617
2043
|
const promptWidth = Bun.stringWidth(state.prompt);
|
|
1618
|
-
const
|
|
2044
|
+
const shown = queryShown(state, layout);
|
|
2045
|
+
const text = `${shown.before}${shown.at ?? ""}${shown.after}`;
|
|
2046
|
+
const query = { text, width: Bun.stringWidth(text) };
|
|
1619
2047
|
const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
|
|
1620
2048
|
const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks} ctrl-/ keys`, layout.listWidth, theme.label);
|
|
1621
2049
|
const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
|
|
@@ -1648,7 +2076,8 @@ var ESCAPE_WAIT_MS = 30;
|
|
|
1648
2076
|
var OPEN = { ctrl: "open" };
|
|
1649
2077
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1650
2078
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
1651
|
-
var
|
|
2079
|
+
var REVERSE = "\x1B[7m";
|
|
2080
|
+
var REVERSE_END = "\x1B[27m";
|
|
1652
2081
|
var PASTE_ON = "\x1B[?2004h";
|
|
1653
2082
|
var PASTE_OFF = "\x1B[?2004l";
|
|
1654
2083
|
var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
|
|
@@ -1666,7 +2095,7 @@ function openTerminal() {
|
|
|
1666
2095
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1667
2096
|
}
|
|
1668
2097
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
1669
|
-
const out =
|
|
2098
|
+
const out = process21.stderr;
|
|
1670
2099
|
let resize;
|
|
1671
2100
|
async function read(onChunk) {
|
|
1672
2101
|
const decoder = new TextDecoder;
|
|
@@ -1692,6 +2121,11 @@ function openTerminal() {
|
|
|
1692
2121
|
out.on("resize", onResize);
|
|
1693
2122
|
read(onChunk);
|
|
1694
2123
|
},
|
|
2124
|
+
suspend() {
|
|
2125
|
+
mode.setRawMode(false);
|
|
2126
|
+
stopJob();
|
|
2127
|
+
mode.setRawMode(true);
|
|
2128
|
+
},
|
|
1695
2129
|
close() {
|
|
1696
2130
|
if (resize !== undefined)
|
|
1697
2131
|
out.off("resize", resize);
|
|
@@ -1719,14 +2153,14 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1719
2153
|
if (restored)
|
|
1720
2154
|
return;
|
|
1721
2155
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1722
|
-
let frame = HIDE_CURSOR;
|
|
2156
|
+
let frame = SYNC_START + HIDE_CURSOR;
|
|
1723
2157
|
if (reserved !== layout.height || clear) {
|
|
1724
2158
|
frame += CLEAR_BELOW + `
|
|
1725
2159
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1726
2160
|
reserved = layout.height;
|
|
1727
2161
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
2162
|
+
const caret = caretCell(state, layout);
|
|
2163
|
+
frame += `\r${overwrite(render(state, layout, theme, preview), terminal.columns)}${up(layout.height - 1)}\r\x1B[${caret.column}G${REVERSE}${caret.char}${REVERSE_END}\r${SYNC_END}`;
|
|
1730
2164
|
terminal.write(frame);
|
|
1731
2165
|
}
|
|
1732
2166
|
function pageSize() {
|
|
@@ -1768,6 +2202,14 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1768
2202
|
terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1769
2203
|
terminal.close();
|
|
1770
2204
|
}
|
|
2205
|
+
function suspend() {
|
|
2206
|
+
if (terminal.suspend === undefined)
|
|
2207
|
+
return;
|
|
2208
|
+
terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
2209
|
+
terminal.suspend();
|
|
2210
|
+
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2211
|
+
draw(true);
|
|
2212
|
+
}
|
|
1771
2213
|
const stop = () => {
|
|
1772
2214
|
state = { ...state, done: "cancel" };
|
|
1773
2215
|
finish?.();
|
|
@@ -1801,6 +2243,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1801
2243
|
for (let key = pending.shift();key !== undefined && state.done === undefined; key = pending.shift()) {
|
|
1802
2244
|
if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
|
|
1803
2245
|
await reloadRows();
|
|
2246
|
+
else if (key === "suspend")
|
|
2247
|
+
suspend();
|
|
1804
2248
|
else
|
|
1805
2249
|
state = press({ ...state, page: pageSize() }, key);
|
|
1806
2250
|
}
|
|
@@ -1840,9 +2284,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1840
2284
|
const ended = new Promise((resolve) => {
|
|
1841
2285
|
finish = resolve;
|
|
1842
2286
|
});
|
|
1843
|
-
|
|
2287
|
+
process21.once("exit", restore);
|
|
1844
2288
|
for (const signal of SIGNALS2)
|
|
1845
|
-
|
|
2289
|
+
process21.once(signal, stop);
|
|
1846
2290
|
try {
|
|
1847
2291
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
1848
2292
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -1855,8 +2299,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1855
2299
|
await ended;
|
|
1856
2300
|
} finally {
|
|
1857
2301
|
for (const signal of SIGNALS2)
|
|
1858
|
-
|
|
1859
|
-
|
|
2302
|
+
process21.off(signal, stop);
|
|
2303
|
+
process21.off("exit", restore);
|
|
1860
2304
|
restore();
|
|
1861
2305
|
}
|
|
1862
2306
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -1887,7 +2331,7 @@ function heightFor(count) {
|
|
|
1887
2331
|
return String(Math.max(15, Math.ceil((count + 4) / 0.6)));
|
|
1888
2332
|
}
|
|
1889
2333
|
function historyFile(name) {
|
|
1890
|
-
return
|
|
2334
|
+
return join8(cacheFolder(), name, "history.json");
|
|
1891
2335
|
}
|
|
1892
2336
|
function history(name) {
|
|
1893
2337
|
try {
|
|
@@ -1898,12 +2342,12 @@ function history(name) {
|
|
|
1898
2342
|
}
|
|
1899
2343
|
}
|
|
1900
2344
|
function runs(name) {
|
|
1901
|
-
return history(name)[
|
|
2345
|
+
return history(name)[process22.cwd()] ?? [];
|
|
1902
2346
|
}
|
|
1903
2347
|
function record(name, run) {
|
|
1904
2348
|
const all = history(name);
|
|
1905
2349
|
const file = historyFile(name);
|
|
1906
|
-
all[
|
|
2350
|
+
all[process22.cwd()] = [run, ...(all[process22.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
|
|
1907
2351
|
mkdirSync2(dirname4(file), { recursive: true });
|
|
1908
2352
|
writeFileSync(file, JSON.stringify(all));
|
|
1909
2353
|
}
|
|
@@ -1927,44 +2371,129 @@ function list(rows) {
|
|
|
1927
2371
|
}
|
|
1928
2372
|
|
|
1929
2373
|
// ../kit/src/prompt.ts
|
|
1930
|
-
import
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2374
|
+
import process23 from "process";
|
|
2375
|
+
|
|
2376
|
+
// ../kit/src/answers.ts
|
|
2377
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
|
|
2378
|
+
import { dirname as dirname5, join as join9 } from "path";
|
|
2379
|
+
var KEPT = 50;
|
|
2380
|
+
function answersFile() {
|
|
2381
|
+
return join9(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2382
|
+
}
|
|
2383
|
+
function stored() {
|
|
2384
|
+
try {
|
|
2385
|
+
const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
|
|
2386
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
2387
|
+
return {};
|
|
2388
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2389
|
+
} catch {
|
|
2390
|
+
return {};
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
function earlierAnswers(key) {
|
|
2394
|
+
return stored()[key] ?? [];
|
|
1934
2395
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
2396
|
+
function rememberAnswer(key, answer) {
|
|
2397
|
+
const all = stored();
|
|
2398
|
+
const file = answersFile();
|
|
2399
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2400
|
+
try {
|
|
2401
|
+
mkdirSync3(dirname5(file), { recursive: true });
|
|
2402
|
+
writeFileSync2(file, JSON.stringify(all));
|
|
2403
|
+
} catch {}
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
// ../kit/src/prompt.ts
|
|
2407
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2408
|
+
var MAX_LISTED = 12;
|
|
2409
|
+
function readKeys(input, paste = { active: false }) {
|
|
2410
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2411
|
+
}
|
|
2412
|
+
function roomAfter(question, columns) {
|
|
2413
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2414
|
+
}
|
|
2415
|
+
function withCaret(colors, line, room, dim = false) {
|
|
2416
|
+
const { before, at, after } = visible(line, room);
|
|
2417
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
2418
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2419
|
+
}
|
|
2420
|
+
function sharedStart(texts) {
|
|
2421
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
2422
|
+
let length = first.length;
|
|
2423
|
+
for (const chars of rest) {
|
|
2424
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
2425
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
2426
|
+
}
|
|
2427
|
+
return first.slice(0, length).join("");
|
|
2428
|
+
}
|
|
2429
|
+
function listed2(colors, found, columns) {
|
|
2430
|
+
const shared = sharedStart(found);
|
|
2431
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
2432
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
2433
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
2434
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
2435
|
+
}
|
|
2436
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2437
|
+
let line = { text: "", caret: 0 };
|
|
1937
2438
|
let invalid;
|
|
1938
|
-
|
|
2439
|
+
let completions = [];
|
|
2440
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
2441
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2442
|
+
let recalled = -1;
|
|
2443
|
+
let draft = line;
|
|
2444
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1939
2445
|
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1940
2446
|
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1941
2447
|
if (state !== "asking")
|
|
1942
2448
|
return [answer(colors, question, state, shown())];
|
|
1943
|
-
const
|
|
1944
|
-
|
|
1945
|
-
const tail = characters.length > room ? `\u2026${characters.slice(1 - room).join("")}` : shown();
|
|
1946
|
-
const typed = value === "" ? colors.dim(tail) : tail;
|
|
1947
|
-
return [`${colors.cyan("?")} ${question} ${typed}${colors.dim("\u2588")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]];
|
|
2449
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2450
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1948
2451
|
}, (key) => {
|
|
1949
2452
|
if (key === "cancel")
|
|
1950
2453
|
return "cancel";
|
|
1951
2454
|
invalid = undefined;
|
|
2455
|
+
completions = [];
|
|
2456
|
+
if (line.chained === true && endsKills(key))
|
|
2457
|
+
line = { ...line, chained: false };
|
|
2458
|
+
if (key === "tab") {
|
|
2459
|
+
const chars = [...line.text];
|
|
2460
|
+
const before = chars.slice(0, line.caret).join("");
|
|
2461
|
+
const found = complete?.(before) ?? [];
|
|
2462
|
+
const filled = sharedStart(found);
|
|
2463
|
+
if ([...filled].length > [...before].length)
|
|
2464
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2465
|
+
else
|
|
2466
|
+
completions = found;
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
1952
2469
|
if (key === "enter") {
|
|
1953
2470
|
invalid = validate?.(taken());
|
|
1954
2471
|
return invalid === undefined ? "enter" : undefined;
|
|
1955
2472
|
}
|
|
1956
|
-
if (key === "
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2473
|
+
if (key === "up" || key === "down") {
|
|
2474
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2475
|
+
if (recalled === -1)
|
|
2476
|
+
draft = line;
|
|
2477
|
+
recalled = to;
|
|
2478
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2479
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2482
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2483
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
2484
|
+
line = editLine(line, edit);
|
|
1960
2485
|
return;
|
|
1961
2486
|
});
|
|
1962
|
-
|
|
2487
|
+
if (!accepted)
|
|
2488
|
+
return;
|
|
2489
|
+
if (remembered !== undefined && taken() !== "")
|
|
2490
|
+
rememberAnswer(remembered, taken());
|
|
2491
|
+
return taken();
|
|
1963
2492
|
}
|
|
1964
2493
|
function answer(colors, question, state, picked) {
|
|
1965
2494
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1966
2495
|
}
|
|
1967
|
-
async function ask(question, { hint, terminal =
|
|
2496
|
+
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
1968
2497
|
const { stdin, stderr } = terminal;
|
|
1969
2498
|
if (!isInteractive(terminal))
|
|
1970
2499
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -1974,12 +2503,22 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
1974
2503
|
const columns = () => stderr.columns || 80;
|
|
1975
2504
|
const draw = (state, last = false) => {
|
|
1976
2505
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1977
|
-
|
|
1978
|
-
|
|
2506
|
+
const rows = rowsTaken(frame, columns());
|
|
2507
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1979
2508
|
current = state;
|
|
1980
2509
|
};
|
|
1981
2510
|
const redraw = () => draw(current);
|
|
1982
2511
|
const paste = { active: false };
|
|
2512
|
+
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2513
|
+
const suspend = () => {
|
|
2514
|
+
if (stop === undefined)
|
|
2515
|
+
return;
|
|
2516
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2517
|
+
stdin.setRawMode(false);
|
|
2518
|
+
stop();
|
|
2519
|
+
stdin.setRawMode(true);
|
|
2520
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2521
|
+
};
|
|
1983
2522
|
try {
|
|
1984
2523
|
stderr.on?.("resize", redraw);
|
|
1985
2524
|
stdin.setRawMode(true);
|
|
@@ -1989,6 +2528,10 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
1989
2528
|
return await new Promise((resolve) => {
|
|
1990
2529
|
function onData(data) {
|
|
1991
2530
|
for (const key of readKeys(data.toString(), paste)) {
|
|
2531
|
+
if (key === "suspend") {
|
|
2532
|
+
suspend();
|
|
2533
|
+
continue;
|
|
2534
|
+
}
|
|
1992
2535
|
const pressed = press(key);
|
|
1993
2536
|
if (pressed !== undefined) {
|
|
1994
2537
|
settle(pressed);
|
|
@@ -2020,15 +2563,15 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2020
2563
|
}
|
|
2021
2564
|
|
|
2022
2565
|
// src/job-picker.ts
|
|
2023
|
-
import
|
|
2566
|
+
import process24 from "process";
|
|
2024
2567
|
|
|
2025
2568
|
// src/jobs.ts
|
|
2026
|
-
import { existsSync as existsSync5, readdirSync, readFileSync as
|
|
2027
|
-
import { dirname as
|
|
2569
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync7 } from "fs";
|
|
2570
|
+
import { dirname as dirname6, join as join11, resolve as resolvePath } from "path";
|
|
2028
2571
|
|
|
2029
2572
|
// src/steps.ts
|
|
2030
2573
|
import { readdir as readdir2 } from "fs/promises";
|
|
2031
|
-
import { join as
|
|
2574
|
+
import { join as join10 } from "path";
|
|
2032
2575
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
2033
2576
|
var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
2034
2577
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
@@ -2040,7 +2583,7 @@ var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"]
|
|
|
2040
2583
|
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
2041
2584
|
async function readFirst(dir, files) {
|
|
2042
2585
|
for (const file of files) {
|
|
2043
|
-
const handle = Bun.file(
|
|
2586
|
+
const handle = Bun.file(join10(dir, file));
|
|
2044
2587
|
if (await handle.exists())
|
|
2045
2588
|
return { file, text: await handle.text() };
|
|
2046
2589
|
}
|
|
@@ -2048,7 +2591,7 @@ async function readFirst(dir, files) {
|
|
|
2048
2591
|
}
|
|
2049
2592
|
async function read(dir, ...files) {
|
|
2050
2593
|
for (const file of files) {
|
|
2051
|
-
const handle = Bun.file(
|
|
2594
|
+
const handle = Bun.file(join10(dir, file));
|
|
2052
2595
|
if (await handle.exists())
|
|
2053
2596
|
return handle.text();
|
|
2054
2597
|
}
|
|
@@ -2108,7 +2651,7 @@ async function candidates(dir, bin) {
|
|
|
2108
2651
|
}
|
|
2109
2652
|
async function firstFile(dir, names) {
|
|
2110
2653
|
for (const name of names) {
|
|
2111
|
-
if (await Bun.file(
|
|
2654
|
+
if (await Bun.file(join10(dir, name)).exists())
|
|
2112
2655
|
return name;
|
|
2113
2656
|
}
|
|
2114
2657
|
return;
|
|
@@ -2136,9 +2679,9 @@ async function discoverProjects(dir) {
|
|
|
2136
2679
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
2137
2680
|
if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
|
|
2138
2681
|
continue;
|
|
2139
|
-
const steps = await discover(
|
|
2682
|
+
const steps = await discover(join10(dir, entry.name));
|
|
2140
2683
|
if (steps.length > 0)
|
|
2141
|
-
projects.push({ name: entry.name, dir:
|
|
2684
|
+
projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
|
|
2142
2685
|
}
|
|
2143
2686
|
return projects;
|
|
2144
2687
|
}
|
|
@@ -2181,12 +2724,12 @@ function list2(dir) {
|
|
|
2181
2724
|
}
|
|
2182
2725
|
}
|
|
2183
2726
|
function locate(dir, here, names) {
|
|
2184
|
-
for (let current = dir;; current =
|
|
2185
|
-
const found = names.find((name) => existsSync5(
|
|
2727
|
+
for (let current = dir;; current = join11(current, "..")) {
|
|
2728
|
+
const found = names.find((name) => existsSync5(join11(current, name)));
|
|
2186
2729
|
if (found !== undefined)
|
|
2187
|
-
return
|
|
2730
|
+
return join11(current, found);
|
|
2188
2731
|
const absolute = resolvePath(current);
|
|
2189
|
-
if (!here || existsSync5(
|
|
2732
|
+
if (!here || existsSync5(join11(current, ".git")) || dirname6(absolute) === absolute)
|
|
2190
2733
|
return;
|
|
2191
2734
|
}
|
|
2192
2735
|
}
|
|
@@ -2216,7 +2759,7 @@ function justFlags(dir, here) {
|
|
|
2216
2759
|
if (here)
|
|
2217
2760
|
return [];
|
|
2218
2761
|
const file = list2(dir).find((name) => JUSTFILE.test(name));
|
|
2219
|
-
return file === undefined ? undefined : ["--justfile",
|
|
2762
|
+
return file === undefined ? undefined : ["--justfile", join11(dir, file)];
|
|
2220
2763
|
}
|
|
2221
2764
|
function just(dir, here) {
|
|
2222
2765
|
const flags = justFlags(dir, here);
|
|
@@ -2276,10 +2819,10 @@ function show(source, target) {
|
|
|
2276
2819
|
`).trimEnd();
|
|
2277
2820
|
}
|
|
2278
2821
|
function make(dir) {
|
|
2279
|
-
const file = MAKEFILES.find((name) => existsSync5(
|
|
2822
|
+
const file = MAKEFILES.find((name) => existsSync5(join11(dir, name)));
|
|
2280
2823
|
if (file === undefined)
|
|
2281
2824
|
return [];
|
|
2282
|
-
const source =
|
|
2825
|
+
const source = readFileSync7(join11(dir, file), "utf-8");
|
|
2283
2826
|
return build({ kind: "make", tag: "make", runner: ["make"], separated: false, dir }, targets2(source).map((target) => ({ ...target, body: show(source, target.name) })));
|
|
2284
2827
|
}
|
|
2285
2828
|
function manager(dir, manifest) {
|
|
@@ -2287,11 +2830,11 @@ function manager(dir, manifest) {
|
|
|
2287
2830
|
const known = LOCKFILES.find(([, name]) => name === declared);
|
|
2288
2831
|
if (known !== undefined)
|
|
2289
2832
|
return known[1];
|
|
2290
|
-
for (let current = resolvePath(dir);; current =
|
|
2291
|
-
const found = LOCKFILES.find(([file]) => existsSync5(
|
|
2833
|
+
for (let current = resolvePath(dir);; current = dirname6(current)) {
|
|
2834
|
+
const found = LOCKFILES.find(([file]) => existsSync5(join11(current, file)));
|
|
2292
2835
|
if (found !== undefined)
|
|
2293
2836
|
return found[1];
|
|
2294
|
-
if (
|
|
2837
|
+
if (dirname6(current) === current)
|
|
2295
2838
|
return "bun";
|
|
2296
2839
|
}
|
|
2297
2840
|
}
|
|
@@ -2302,38 +2845,38 @@ function packageScripts(dir, here) {
|
|
|
2302
2845
|
const file = locate(dir, here, ["package.json"]);
|
|
2303
2846
|
if (file === undefined)
|
|
2304
2847
|
return [];
|
|
2305
|
-
const manifest = JSON.parse(
|
|
2306
|
-
const tool = manager(
|
|
2848
|
+
const manifest = JSON.parse(readFileSync7(file, "utf-8"));
|
|
2849
|
+
const tool = manager(dirname6(file), manifest);
|
|
2307
2850
|
const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, body: text2(command) }));
|
|
2308
|
-
return build({ kind: "package", tag: tool, runner: [tool, "run"], separated: tool === "npm", dir:
|
|
2851
|
+
return build({ kind: "package", tag: tool, runner: [tool, "run"], separated: tool === "npm", dir: dirname6(file) }, items);
|
|
2309
2852
|
}
|
|
2310
2853
|
function composer(dir, here) {
|
|
2311
2854
|
const file = locate(dir, here, ["composer.json"]);
|
|
2312
2855
|
if (file === undefined)
|
|
2313
2856
|
return [];
|
|
2314
|
-
const manifest = JSON.parse(
|
|
2857
|
+
const manifest = JSON.parse(readFileSync7(file, "utf-8"));
|
|
2315
2858
|
const descriptions = table2(manifest["scripts-descriptions"]);
|
|
2316
2859
|
const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, doc: field(descriptions, name), body: text2(command) }));
|
|
2317
|
-
return build({ kind: "composer", tag: "composer", runner: ["composer", "run"], separated: true, dir:
|
|
2860
|
+
return build({ kind: "composer", tag: "composer", runner: ["composer", "run"], separated: true, dir: dirname6(file) }, items);
|
|
2318
2861
|
}
|
|
2319
2862
|
function deno(dir, here) {
|
|
2320
2863
|
const file = locate(dir, here, ["deno.json", "deno.jsonc"]);
|
|
2321
2864
|
if (file === undefined)
|
|
2322
2865
|
return [];
|
|
2323
|
-
const manifest = Bun.JSONC.parse(
|
|
2866
|
+
const manifest = Bun.JSONC.parse(readFileSync7(file, "utf-8"));
|
|
2324
2867
|
const items = Object.entries(table2(manifest.tasks)).map(([name, task]) => ({ name, doc: field(task, "description"), body: field(task, "command") ?? text2(task) }));
|
|
2325
|
-
return build({ kind: "deno", tag: "deno", runner: ["deno", "task"], separated: false, dir:
|
|
2868
|
+
return build({ kind: "deno", tag: "deno", runner: ["deno", "task"], separated: false, dir: dirname6(file) }, items);
|
|
2326
2869
|
}
|
|
2327
2870
|
function taskfile(dir, here) {
|
|
2328
2871
|
const file = locate(dir, here, TASKFILES);
|
|
2329
2872
|
if (file === undefined)
|
|
2330
2873
|
return [];
|
|
2331
|
-
const tasks = table2(Bun.YAML.parse(
|
|
2874
|
+
const tasks = table2(Bun.YAML.parse(readFileSync7(file, "utf-8"))?.tasks);
|
|
2332
2875
|
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) }));
|
|
2333
|
-
return build({ kind: "task", tag: "task", runner: ["task"], separated: true, dir:
|
|
2876
|
+
return build({ kind: "task", tag: "task", runner: ["task"], separated: true, dir: dirname6(file) }, items);
|
|
2334
2877
|
}
|
|
2335
2878
|
function mise(dir, here) {
|
|
2336
|
-
if (!has("mise") || !here && !MISE_FILES.some((name) => existsSync5(
|
|
2879
|
+
if (!has("mise") || !here && !MISE_FILES.some((name) => existsSync5(join11(dir, name))))
|
|
2337
2880
|
return [];
|
|
2338
2881
|
const proc = Bun.spawnSync(["mise", "tasks", "ls", "--json"], { cwd: dir, stderr: "pipe" });
|
|
2339
2882
|
if (!proc.success)
|
|
@@ -2347,15 +2890,15 @@ function pyproject(dir, here) {
|
|
|
2347
2890
|
const file = locate(dir, here, ["pyproject.toml"]);
|
|
2348
2891
|
if (file === undefined)
|
|
2349
2892
|
return [];
|
|
2350
|
-
const manifest = Bun.TOML.parse(
|
|
2893
|
+
const manifest = Bun.TOML.parse(readFileSync7(file, "utf-8"));
|
|
2351
2894
|
const tool = table2(manifest.tool);
|
|
2352
2895
|
const project = table2(manifest.project);
|
|
2353
|
-
const uv = locate(
|
|
2896
|
+
const uv = locate(dirname6(file), true, ["uv.lock"]) !== undefined;
|
|
2354
2897
|
const poe = Object.entries(table2(table2(tool.poe).tasks)).filter(([name]) => !name.startsWith("_")).map(([name, task]) => ({ name, doc: field(task, "help"), body: field(task, "cmd") ?? field(task, "shell") ?? text2(task) }));
|
|
2355
2898
|
const entryPoints = Object.entries(table2(project.scripts)).map(([name, target]) => ({ name, body: text2(target) }));
|
|
2356
2899
|
return [
|
|
2357
|
-
...build({ kind: "poe", tag: "poe", runner: uv ? ["uv", "run", "poe"] : ["poe"], separated: false, dir:
|
|
2358
|
-
...build({ kind: "uv", tag: "uv", runner: ["uv", "run"], separated: false, dir:
|
|
2900
|
+
...build({ kind: "poe", tag: "poe", runner: uv ? ["uv", "run", "poe"] : ["poe"], separated: false, dir: dirname6(file) }, poe),
|
|
2901
|
+
...build({ kind: "uv", tag: "uv", runner: ["uv", "run"], separated: false, dir: dirname6(file) }, entryPoints)
|
|
2359
2902
|
];
|
|
2360
2903
|
}
|
|
2361
2904
|
var READERS = [just, make, packageScripts, composer, deno, taskfile, mise, pyproject];
|
|
@@ -2379,12 +2922,12 @@ function readOr(read, fallback) {
|
|
|
2379
2922
|
}
|
|
2380
2923
|
}
|
|
2381
2924
|
function workspaces() {
|
|
2382
|
-
const manifest = readOr(() => JSON.parse(
|
|
2925
|
+
const manifest = readOr(() => JSON.parse(readFileSync7("package.json", "utf-8")), {});
|
|
2383
2926
|
const declared = Array.isArray(manifest.workspaces) ? manifest.workspaces : table2(manifest.workspaces).packages;
|
|
2384
|
-
const pnpm = readOr(() => table2(Bun.YAML.parse(
|
|
2927
|
+
const pnpm = readOr(() => table2(Bun.YAML.parse(readFileSync7("pnpm-workspace.yaml", "utf-8"))).packages, undefined);
|
|
2385
2928
|
const patterns = [declared, pnpm].flatMap((value) => Array.isArray(value) ? value.filter((pattern) => typeof pattern === "string") : []);
|
|
2386
2929
|
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => new Bun.Glob(pattern.slice(1)));
|
|
2387
|
-
return patterns.filter((pattern) => !pattern.startsWith("!")).flatMap((pattern) => [...new Bun.Glob(`${pattern.replace(TRAILING_SLASHES, "")}/package.json`).scanSync({ cwd: "." })].map((file) =>
|
|
2930
|
+
return patterns.filter((pattern) => !pattern.startsWith("!")).flatMap((pattern) => [...new Bun.Glob(`${pattern.replace(TRAILING_SLASHES, "")}/package.json`).scanSync({ cwd: "." })].map((file) => dirname6(file))).filter((dir) => !dir.split("/").includes("node_modules") && !excluded.some((glob) => glob.match(dir)));
|
|
2388
2931
|
}
|
|
2389
2932
|
function folders2() {
|
|
2390
2933
|
return [...new Set([...children(), ...workspaces()])].filter((dir) => dir !== ".");
|
|
@@ -2394,7 +2937,7 @@ function guarded(reader, dir, here, isWarned = false) {
|
|
|
2394
2937
|
return reader(dir, here);
|
|
2395
2938
|
} catch (error) {
|
|
2396
2939
|
if (isWarned)
|
|
2397
|
-
warn(`j: skipped ${
|
|
2940
|
+
warn(`j: skipped ${join11(dir, MANIFEST_OF.get(reader) ?? "a manifest")}, it does not parse (${error instanceof Error ? error.message : String(error)})`);
|
|
2398
2941
|
return [];
|
|
2399
2942
|
}
|
|
2400
2943
|
}
|
|
@@ -2440,7 +2983,7 @@ function labelled(entries) {
|
|
|
2440
2983
|
return new Set(entries.map((entry) => entry.tag)).size > 1;
|
|
2441
2984
|
}
|
|
2442
2985
|
function row(entry, labels, signed) {
|
|
2443
|
-
const colors = paint(
|
|
2986
|
+
const colors = paint(process24.stderr);
|
|
2444
2987
|
const keyed = entry.dir === "." ? entry.name : `${colors.dim(`${entry.dir}/`)}${entry.name}`;
|
|
2445
2988
|
return {
|
|
2446
2989
|
hidden: [entry.kind, entry.dir, entry.name, id(entry)],
|
|
@@ -2454,7 +2997,7 @@ async function pickJob(entries, narrowed = false) {
|
|
|
2454
2997
|
prompt: `${[...new Set(entries.map((entry) => entry.tag))].join("/")}> `,
|
|
2455
2998
|
searched: labels ? 2 : 1,
|
|
2456
2999
|
...narrowed ? { height: heightFor(entries.length) } : {},
|
|
2457
|
-
preview: `${
|
|
3000
|
+
preview: `${process24.execPath} ${process24.argv[1]} --show {1} {2} {3}`
|
|
2458
3001
|
});
|
|
2459
3002
|
return entries.find((candidate) => id(candidate) === picked?.hidden[3]);
|
|
2460
3003
|
}
|
|
@@ -2475,7 +3018,7 @@ function preview(kind, dir, name) {
|
|
|
2475
3018
|
const entry = readKind(kind, dir).find((candidate) => candidate.name === name);
|
|
2476
3019
|
if (entry === undefined)
|
|
2477
3020
|
return;
|
|
2478
|
-
const colors = paint(
|
|
3021
|
+
const colors = paint(process25.stdout);
|
|
2479
3022
|
console.log(`${colors.dim(`$ ${dir === "." ? "" : `env -C ${dir} `}`)}${colors.bold([...entry.runner, entry.name].join(" "))}
|
|
2480
3023
|
`);
|
|
2481
3024
|
if (entry.body !== undefined)
|
|
@@ -2490,14 +3033,14 @@ function names(found) {
|
|
|
2490
3033
|
return same.length === 1 ? [[name, described(same[0])]] : [[name, same.map((entry) => entry.tag).join(", ")], ...same.map((entry) => [id(entry), described(entry)])];
|
|
2491
3034
|
});
|
|
2492
3035
|
}
|
|
2493
|
-
function
|
|
3036
|
+
function completions2() {
|
|
2494
3037
|
try {
|
|
2495
3038
|
return [...names(everything()), ["-", "the last one again, with its arguments"]];
|
|
2496
3039
|
} catch {
|
|
2497
3040
|
return [];
|
|
2498
3041
|
}
|
|
2499
3042
|
}
|
|
2500
|
-
function
|
|
3043
|
+
function listed3(found) {
|
|
2501
3044
|
const labels = labelled(found);
|
|
2502
3045
|
return byRecency(found, runs("j"), id).map((entry) => ({
|
|
2503
3046
|
label: [labels ? entry.tag : "", key(entry), signature(entry)].filter(Boolean).join(" "),
|
|
@@ -2508,7 +3051,7 @@ function listed2(found) {
|
|
|
2508
3051
|
}));
|
|
2509
3052
|
}
|
|
2510
3053
|
function listing(found) {
|
|
2511
|
-
const colors = paint(
|
|
3054
|
+
const colors = paint(process25.stdout);
|
|
2512
3055
|
const labels = labelled(found);
|
|
2513
3056
|
return table(found.map((entry) => [...labels ? [entry.tag] : [], key(entry), signature(entry), colors.dim(entry.doc ?? "")]));
|
|
2514
3057
|
}
|
|
@@ -2535,7 +3078,7 @@ async function j2(argv) {
|
|
|
2535
3078
|
if (found.length === 0)
|
|
2536
3079
|
fail("nothing to run here: no recipe, target, script or task", 1);
|
|
2537
3080
|
if (flag === "--list")
|
|
2538
|
-
list(
|
|
3081
|
+
list(listed3(found));
|
|
2539
3082
|
else
|
|
2540
3083
|
console.log(names(found).map(([name, description]) => `${name} ${description}`).join(`
|
|
2541
3084
|
`));
|
|
@@ -2547,7 +3090,7 @@ async function j2(argv) {
|
|
|
2547
3090
|
const parsed = last ? { values: {}, positionals: ["-"], rest: args.slice(1) } : parse(args, usage2, options, {
|
|
2548
3091
|
exits: EXITS,
|
|
2549
3092
|
positionals: ["[name]"],
|
|
2550
|
-
candidates: { "[name]":
|
|
3093
|
+
candidates: { "[name]": completions2 },
|
|
2551
3094
|
trailing: true,
|
|
2552
3095
|
replaces: "reading the Justfile, Makefile, package.json scripts or composer scripts to find what to run, then retyping it",
|
|
2553
3096
|
examples: ["j", ["j test", "run the test recipe, script or task"], ["j api/test --watch", "a child folder's, with an argument"], ["j just:check", "the one of a runner, when several share the name"], ["j -", "the last one again"]]
|
|
@@ -2598,7 +3141,7 @@ async function j2(argv) {
|
|
|
2598
3141
|
}
|
|
2599
3142
|
const answers = [];
|
|
2600
3143
|
for (const ask of asks) {
|
|
2601
|
-
const answer = await input2(ask);
|
|
3144
|
+
const answer = await input2(ask, { history: `j ${id(entry)} ${ask}` });
|
|
2602
3145
|
if (answer === undefined)
|
|
2603
3146
|
return 1;
|
|
2604
3147
|
answers.push(answer);
|
|
@@ -2609,4 +3152,4 @@ async function j2(argv) {
|
|
|
2609
3152
|
}
|
|
2610
3153
|
|
|
2611
3154
|
// src/j-cli.ts
|
|
2612
|
-
|
|
3155
|
+
process26.exitCode = await runMain({ name: "j", version, run: j2 });
|