@kaynooo/cli-code 0.14.3 → 0.15.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/dist/cli.js +257 -68
- package/dist/hotspots-cli.js +186 -44
- package/dist/peek-cli.js +170 -36
- package/dist/todo-scan-cli.js +210 -33
- package/package.json +2 -2
package/dist/peek-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/peek-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process17 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -422,6 +422,23 @@ function fileLink(text, path, stream, from = process6.cwd(), env = process6.env)
|
|
|
422
422
|
}
|
|
423
423
|
|
|
424
424
|
// ../kit/src/format.ts
|
|
425
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
426
|
+
function formatSeconds(total) {
|
|
427
|
+
let rest = Math.max(0, Math.round(total));
|
|
428
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
429
|
+
const amount = Math.floor(rest / size);
|
|
430
|
+
rest -= amount * size;
|
|
431
|
+
return `${amount}${unit}`;
|
|
432
|
+
});
|
|
433
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
434
|
+
if (first === -1)
|
|
435
|
+
return "0s";
|
|
436
|
+
const next = amounts[first + 1];
|
|
437
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
438
|
+
}
|
|
439
|
+
function formatDuration(ms) {
|
|
440
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
441
|
+
}
|
|
425
442
|
function upTo(text, separator) {
|
|
426
443
|
const end = text.indexOf(separator);
|
|
427
444
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -482,7 +499,7 @@ function printJson(value) {
|
|
|
482
499
|
|
|
483
500
|
// ../kit/src/help.ts
|
|
484
501
|
import process8 from "process";
|
|
485
|
-
var OPTIONAL =
|
|
502
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
486
503
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
487
504
|
var FULL_STOP = /\.$/;
|
|
488
505
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -521,29 +538,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
521
538
|
return [];
|
|
522
539
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
523
540
|
}
|
|
541
|
+
var MAX_INLINE_CHOICES = 24;
|
|
524
542
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
525
543
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
526
544
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
527
|
-
const
|
|
545
|
+
const choices = option.choices?.join("|");
|
|
546
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
547
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
528
548
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
529
549
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
530
|
-
|
|
550
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
551
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
531
552
|
});
|
|
532
553
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
533
554
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
534
555
|
}
|
|
535
556
|
|
|
536
557
|
// ../kit/src/text.ts
|
|
537
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
538
558
|
function distance(a, b) {
|
|
539
|
-
|
|
540
|
-
|
|
559
|
+
const left = [...a];
|
|
560
|
+
const right = [...b];
|
|
561
|
+
let before = [];
|
|
562
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
563
|
+
for (const [i, x] of left.entries()) {
|
|
541
564
|
const current = [i + 1];
|
|
542
|
-
for (const [j,
|
|
543
|
-
|
|
565
|
+
for (const [j, y] of right.entries()) {
|
|
566
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
567
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
568
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
569
|
+
current.push(cost);
|
|
570
|
+
}
|
|
571
|
+
before = previous;
|
|
544
572
|
previous = current;
|
|
545
573
|
}
|
|
546
|
-
return previous[
|
|
574
|
+
return previous[right.length] ?? 0;
|
|
547
575
|
}
|
|
548
576
|
function closest(name, names) {
|
|
549
577
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -624,7 +652,7 @@ class Completing {
|
|
|
624
652
|
}
|
|
625
653
|
var completion = { active: false };
|
|
626
654
|
var OUTPUT_OPTIONS = {
|
|
627
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
655
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
628
656
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
629
657
|
};
|
|
630
658
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -918,13 +946,91 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
918
946
|
// ../kit/src/cli.ts
|
|
919
947
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
920
948
|
import { dirname as dirname3, join as join5 } from "path";
|
|
921
|
-
import
|
|
949
|
+
import process14 from "process";
|
|
950
|
+
|
|
951
|
+
// ../kit/src/completions.ts
|
|
952
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
953
|
+
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'
|
|
954
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
955
|
+
set -l current (commandline -ct)
|
|
956
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
957
|
+
if test "$line" = __files__
|
|
958
|
+
__fish_complete_path $current
|
|
959
|
+
else
|
|
960
|
+
echo $line
|
|
961
|
+
end
|
|
962
|
+
end
|
|
963
|
+
end`;
|
|
964
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
965
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
966
|
+
local -a lines
|
|
967
|
+
COMPREPLY=()
|
|
968
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
969
|
+
for line in "\${lines[@]}"; do
|
|
970
|
+
if [[ $line == __files__ ]]; then
|
|
971
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
972
|
+
else
|
|
973
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
974
|
+
fi
|
|
975
|
+
done
|
|
976
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
977
|
+
}`;
|
|
978
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
979
|
+
local line
|
|
980
|
+
local -a described plain
|
|
981
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
982
|
+
if [[ $line == __files__ ]]; then
|
|
983
|
+
_files
|
|
984
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
985
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
986
|
+
else
|
|
987
|
+
plain+=("$line")
|
|
988
|
+
fi
|
|
989
|
+
done
|
|
990
|
+
(( \${#described} )) && _describe -V value described
|
|
991
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
992
|
+
return 0
|
|
993
|
+
}`;
|
|
994
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
995
|
+
if (shell === "fish")
|
|
996
|
+
return `${header}
|
|
997
|
+
${FISH_FUNCTION}
|
|
998
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
999
|
+
`).join("")}`;
|
|
1000
|
+
if (shell === "bash")
|
|
1001
|
+
return `${header}
|
|
1002
|
+
${BASH_FUNCTION}
|
|
1003
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1004
|
+
`;
|
|
1005
|
+
return `${header}
|
|
1006
|
+
${ZSH_FUNCTION}
|
|
1007
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1008
|
+
`;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// ../kit/src/notify.ts
|
|
1012
|
+
import process12 from "process";
|
|
1013
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1014
|
+
var CANCELLED = 130;
|
|
1015
|
+
function base64(text) {
|
|
1016
|
+
return Buffer.from(text).toString("base64");
|
|
1017
|
+
}
|
|
1018
|
+
function notification(title, body, env = process12.env) {
|
|
1019
|
+
const id = `kit${process12.pid}`;
|
|
1020
|
+
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\\`];
|
|
1021
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1022
|
+
}
|
|
1023
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
1024
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1025
|
+
return;
|
|
1026
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1027
|
+
}
|
|
922
1028
|
|
|
923
1029
|
// ../kit/src/usage.ts
|
|
924
1030
|
import { appendFileSync, mkdirSync } from "fs";
|
|
925
1031
|
import { homedir as homedir3 } from "os";
|
|
926
1032
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
927
|
-
import
|
|
1033
|
+
import process13 from "process";
|
|
928
1034
|
|
|
929
1035
|
// ../kit/src/logs.ts
|
|
930
1036
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -938,14 +1044,14 @@ var usageError;
|
|
|
938
1044
|
function noteUsageError(message) {
|
|
939
1045
|
usageError = message;
|
|
940
1046
|
}
|
|
941
|
-
function stateHome(env =
|
|
1047
|
+
function stateHome(env = process13.env) {
|
|
942
1048
|
const dir = env.XDG_STATE_HOME;
|
|
943
1049
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
944
1050
|
}
|
|
945
|
-
function usagePath(env =
|
|
1051
|
+
function usagePath(env = process13.env) {
|
|
946
1052
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
947
1053
|
}
|
|
948
|
-
function usageRecorded(env =
|
|
1054
|
+
function usageRecorded(env = process13.env) {
|
|
949
1055
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
950
1056
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
951
1057
|
}
|
|
@@ -959,7 +1065,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
959
1065
|
usageError = undefined;
|
|
960
1066
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
961
1067
|
}
|
|
962
|
-
function recordUsage(entry, env =
|
|
1068
|
+
function recordUsage(entry, env = process13.env) {
|
|
963
1069
|
if (!usageRecorded(env))
|
|
964
1070
|
return;
|
|
965
1071
|
try {
|
|
@@ -975,7 +1081,11 @@ var LEVEL_OPTIONS = {
|
|
|
975
1081
|
...OUTPUT_OPTIONS,
|
|
976
1082
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
977
1083
|
};
|
|
978
|
-
var TOP_OPTIONS = {
|
|
1084
|
+
var TOP_OPTIONS = {
|
|
1085
|
+
...LEVEL_OPTIONS,
|
|
1086
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1087
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1088
|
+
};
|
|
979
1089
|
async function commandRows(all, colors) {
|
|
980
1090
|
const commands = shown(all);
|
|
981
1091
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1049,8 +1159,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1049
1159
|
`);
|
|
1050
1160
|
}
|
|
1051
1161
|
function printError(prefix, message, hint, cause) {
|
|
1052
|
-
const colors = paint(
|
|
1053
|
-
const styled = takesControlCodes(
|
|
1162
|
+
const colors = paint(process14.stderr);
|
|
1163
|
+
const styled = takesControlCodes(process14.stderr);
|
|
1054
1164
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1055
1165
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1056
1166
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1093,11 +1203,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1093
1203
|
}
|
|
1094
1204
|
}
|
|
1095
1205
|
if (name === undefined && level.path.length > 1) {
|
|
1096
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1206
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
1097
1207
|
return 2;
|
|
1098
1208
|
}
|
|
1099
1209
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1100
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1210
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
1101
1211
|
return 0;
|
|
1102
1212
|
}
|
|
1103
1213
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1208,6 +1318,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1208
1318
|
}
|
|
1209
1319
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1210
1320
|
}
|
|
1321
|
+
var COMPLETIONS = "--completions";
|
|
1322
|
+
function flagValue([flag = "", ...rest]) {
|
|
1323
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1324
|
+
}
|
|
1325
|
+
function printCompletionScript(name, args) {
|
|
1326
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1327
|
+
if (shell === undefined || args.length !== 1) {
|
|
1328
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1329
|
+
return 2;
|
|
1330
|
+
}
|
|
1331
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1332
|
+
return 0;
|
|
1333
|
+
}
|
|
1211
1334
|
async function printCandidates(found) {
|
|
1212
1335
|
for (const line of await found)
|
|
1213
1336
|
console.log(line);
|
|
@@ -1232,10 +1355,15 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1232
1355
|
const version = cli.version ?? packageVersion();
|
|
1233
1356
|
if (argv[0] === COMPLETE)
|
|
1234
1357
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1358
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1359
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1360
|
+
const started = performance.now();
|
|
1235
1361
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1362
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1363
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1236
1364
|
if (cli.usage !== false) {
|
|
1237
1365
|
try {
|
|
1238
|
-
recordUsage(usageEntry(cli.name,
|
|
1366
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1239
1367
|
} catch {}
|
|
1240
1368
|
}
|
|
1241
1369
|
return code;
|
|
@@ -1258,16 +1386,20 @@ function commandPath(scope, argv) {
|
|
|
1258
1386
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1259
1387
|
if (argv[0] === COMPLETE)
|
|
1260
1388
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1389
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1390
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1261
1391
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1262
1392
|
console.log(version ?? packageVersion());
|
|
1263
1393
|
return 0;
|
|
1264
1394
|
}
|
|
1265
1395
|
let code;
|
|
1396
|
+
const started = performance.now();
|
|
1266
1397
|
try {
|
|
1267
1398
|
code = await run(argv);
|
|
1268
1399
|
} catch (error) {
|
|
1269
1400
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1270
1401
|
}
|
|
1402
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1271
1403
|
if (usage !== false) {
|
|
1272
1404
|
try {
|
|
1273
1405
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1312,7 +1444,7 @@ var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
|
1312
1444
|
// src/peek.ts
|
|
1313
1445
|
import { realpathSync as realpathSync3 } from "fs";
|
|
1314
1446
|
import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve5, sep } from "path";
|
|
1315
|
-
import
|
|
1447
|
+
import process16 from "process";
|
|
1316
1448
|
|
|
1317
1449
|
// src/files.ts
|
|
1318
1450
|
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
@@ -1357,9 +1489,11 @@ async function readText(path) {
|
|
|
1357
1489
|
|
|
1358
1490
|
// src/source.ts
|
|
1359
1491
|
var LOCATION = /^(?:\.\/)?([^\s:()]+)(?::(\d+)(?::\d+)?|\((\d+),\d+\))(?=[:\s)]|$)/;
|
|
1360
|
-
var DECLARATION = /^(?:
|
|
1361
|
-
var
|
|
1362
|
-
var
|
|
1492
|
+
var DECLARATION = /^(?:(?:export|default|declare|abstract|async|pub(?:\([^)]*\))?|public|private|protected|internal|final|open|sealed|static|suspend)\s+)*(?:function\*?|class|interface|type|enum|const|let|var|namespace|module|def|func|fun|fn|struct|trait|impl)\s/;
|
|
1493
|
+
var MODIFIER_WORDS = String.raw`(?:public|private|protected|internal|final|open|sealed|static|async|suspend|override|readonly|abstract|get|set|pub(?:\([^)]*\))?|function|fn|def|func|fun)\s+`;
|
|
1494
|
+
var RETURN_TYPE = String.raw`(?:[\w$.]+(?:<[^>]*>)?(?:\[\])*\??\s+(?=[#\w$]+\s*(?:<[^>]*>\s*)?\())?`;
|
|
1495
|
+
var MODIFIERS = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?`);
|
|
1496
|
+
var MEMBER = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?[#\w$]+\s*(?:<[^>]*>\s*)?\(`);
|
|
1363
1497
|
var RECEIVER = /^(?:\([^)]*\)\s*)?/;
|
|
1364
1498
|
var STAR = /^\*?\s*/;
|
|
1365
1499
|
var HOLDS_MEMBERS = /\b(?:class|interface|trait|impl|struct)\s/;
|
|
@@ -1489,7 +1623,7 @@ function outline(text, path) {
|
|
|
1489
1623
|
if (indent === 0 && DECLARATION.test(text) && !LOCAL_BINDING.test(text)) {
|
|
1490
1624
|
entries.push({ line: i + 1, depth: 0, text: signature(line) });
|
|
1491
1625
|
memberIndent = HOLDS_MEMBERS.test(text) ? -1 : undefined;
|
|
1492
|
-
} else if (indent === 0 && text !== "" && !text.startsWith("}") && !LEADING.test(text)) {
|
|
1626
|
+
} else if (indent === 0 && text !== "" && !text.startsWith("{") && !text.startsWith("}") && !LEADING.test(text)) {
|
|
1493
1627
|
memberIndent = undefined;
|
|
1494
1628
|
} else if (memberIndent !== undefined && indent > 0 && (memberIndent === -1 || indent === memberIndent) && MEMBER.test(text) && !CALL_KEYWORDS.test(text)) {
|
|
1495
1629
|
memberIndent = indent;
|
|
@@ -1560,13 +1694,13 @@ function cut(text) {
|
|
|
1560
1694
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1561
1695
|
}
|
|
1562
1696
|
async function readableRoot() {
|
|
1563
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1564
|
-
return realpathSync3(ran.code === 0 ? ran.text.trim() :
|
|
1697
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process16.cwd() });
|
|
1698
|
+
return realpathSync3(ran.code === 0 ? ran.text.trim() : process16.cwd());
|
|
1565
1699
|
}
|
|
1566
1700
|
async function isOutside(path) {
|
|
1567
1701
|
let real;
|
|
1568
1702
|
try {
|
|
1569
|
-
real = realpathSync3(resolve5(
|
|
1703
|
+
real = realpathSync3(resolve5(process16.cwd(), path));
|
|
1570
1704
|
} catch {
|
|
1571
1705
|
return false;
|
|
1572
1706
|
}
|
|
@@ -1580,7 +1714,7 @@ async function checkInside(path) {
|
|
|
1580
1714
|
async function pipedSpans(text, context) {
|
|
1581
1715
|
const spans = [];
|
|
1582
1716
|
for (const [path, numbers] of locations(text)) {
|
|
1583
|
-
const source = await isOutside(path) ? undefined : await readText(resolve5(
|
|
1717
|
+
const source = await isOutside(path) ? undefined : await readText(resolve5(process16.cwd(), path));
|
|
1584
1718
|
if (source !== undefined)
|
|
1585
1719
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1586
1720
|
`).length, numbers, context));
|
|
@@ -1589,7 +1723,7 @@ async function pipedSpans(text, context) {
|
|
|
1589
1723
|
}
|
|
1590
1724
|
async function textOf(path) {
|
|
1591
1725
|
await checkInside(path);
|
|
1592
|
-
const text = await readText(resolve5(
|
|
1726
|
+
const text = await readText(resolve5(process16.cwd(), path));
|
|
1593
1727
|
if (text === undefined)
|
|
1594
1728
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1595
1729
|
return text;
|
|
@@ -1647,8 +1781,8 @@ async function spanOf(target) {
|
|
|
1647
1781
|
async function* sources(paths) {
|
|
1648
1782
|
for (const path of paths)
|
|
1649
1783
|
await checkInside(path);
|
|
1650
|
-
for (const path of await listFiles(paths,
|
|
1651
|
-
const text = await readText(join7(
|
|
1784
|
+
for (const path of await listFiles(paths, process16.cwd())) {
|
|
1785
|
+
const text = await readText(join7(process16.cwd(), path));
|
|
1652
1786
|
if (text !== undefined)
|
|
1653
1787
|
yield { path, text };
|
|
1654
1788
|
}
|
|
@@ -1748,4 +1882,4 @@ async function peek(args) {
|
|
|
1748
1882
|
}
|
|
1749
1883
|
|
|
1750
1884
|
// src/peek-cli.ts
|
|
1751
|
-
|
|
1885
|
+
process17.exitCode = await runMain({ name: "peek", run: peek });
|