@kaynooo/cli-code 0.14.1 → 0.14.3
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 -1
- package/dist/cli.js +127 -77
- package/dist/hotspots-cli.js +109 -57
- package/dist/peek-cli.js +110 -59
- package/dist/todo-scan-cli.js +102 -51
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ hotspots --since '3 months ago' --limit 10
|
|
|
25
25
|
- `--around <regex> -C <n>` prints the `n` (3) lines on each side of each matching line, spans that touch merged, at most 20 spans (`--limit`, `--full`, the count of the rest after them).
|
|
26
26
|
- Piped into with no file and no mode, it reads the `path:line` opening each line of the input (`errs`, `rg -n`, `grep -n`, a linter's `path:line:col`, tsc's `path(line,col)`) and prints the `-C` (3) lines around each, spans that touch merged and files in the order first named; a path outside the repository or not readable is skipped, and nothing readable exits 1.
|
|
27
27
|
- `--json` prints the spans as `[{path, from, to, lines}]`, `--refs` as `[{path, line, text}]` and `--outline` as `[{path, line, depth, text}]`, the lines never cut; a failure prints as `{"error"}` on stderr.
|
|
28
|
-
- `--def`, `--refs` and `--around` look through the paths given, the files git keeps here by default (`git ls-files` with the untracked files `.gitignore` lets through), and outside a repository a walk leaving dot folders and `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` out; binary files and files over 2 MB are skipped.
|
|
28
|
+
- `--def`, `--refs` and `--around` look through the paths given, the files git keeps here by default (`git ls-files` with the untracked files `.gitignore` lets through), and outside a repository a walk leaving dot folders and `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` and the names in the `ignore` array of `~/.config/kaynooo-cli/config.json` out; binary files and files over 2 MB are skipped.
|
|
29
29
|
- The symbols are found by pattern, not by a type checker: a name declared twice in a file shows twice, and a symbol re-exported under another name is not followed.
|
|
30
30
|
- A path must lie inside the repository (a symlink out of it counts as outside), absolute or relative. Exits 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.
|
|
31
31
|
|
|
@@ -41,3 +41,5 @@ hotspots --since '3 months ago' --limit 10
|
|
|
41
41
|
- Churn is the commits touching the file since `--since` (any date git reads, `6 months ago` by default), counted from one `git log`. The score uses `recent`, the commits weighted by age (half as much every `--half-life`, `90d` by default, `0` to count them alike), and leaves out the commits touching more than `--bulk` files (25), the format and rename sweeps. Complexity is the decision points of the file (`if`, loops, `case`, `catch`, `&&`, `||`, `??`, ternaries, `and`/`or`) plus one, counted with comments and strings blanked; it is computed in-house (js, ts, vue, svelte, astro, kay, php, py, go, rs, rb, java, kt, swift, cs, c, cpp, scala, dart, lua and shell files are ranked) so the bin needs no dependency and reads any language the same way.
|
|
42
42
|
- `--limit <n>` (`-n`) sets how many files are listed (20, the count of the rest after them), `--full` lists all, `--json` is never cut unless `--limit` is given. `--all` keeps test files and generated files (`dist/`, `*.d.ts`, `*.min.js`, snapshots, files whose first lines say generated), `--json` prints `[{rank, path, score, churn, recent, complexity, worst, lines}]`. The most complex declaration is found from the indentation alone (a class is opened into its methods), so it reads any language the same way.
|
|
43
43
|
- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
|
|
44
|
+
|
|
45
|
+
`~/.config/kaynooo-cli/hotspots.json` (`$XDG_CONFIG_HOME/kaynooo-cli/` when set) changes the defaults of `hotspots`: `since` (a date as git reads it, `6 months ago`), `bulk` (25) and `limit` (20, the files listed).
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -465,18 +488,14 @@ var FULL_STOP = /\.$/;
|
|
|
465
488
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
466
489
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
467
490
|
}
|
|
468
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
469
|
-
return [usageLine(usage, colors),
|
|
491
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
492
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
470
493
|
`);
|
|
471
494
|
}
|
|
472
495
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
473
496
|
if (exits.length === 0)
|
|
474
497
|
return [];
|
|
475
|
-
|
|
476
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
477
|
-
}
|
|
478
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
479
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
498
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
480
499
|
}
|
|
481
500
|
function wantsHelpJson(env = process8.env) {
|
|
482
501
|
return env.KIT_HELP === "json";
|
|
@@ -777,9 +796,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
777
796
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
778
797
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
779
798
|
}
|
|
799
|
+
// ../kit/src/argv.ts
|
|
800
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
801
|
+
import { resolve as resolve4 } from "path";
|
|
802
|
+
import process10 from "process";
|
|
803
|
+
function commandLine() {
|
|
804
|
+
try {
|
|
805
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
806
|
+
} catch {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function realPath(word) {
|
|
811
|
+
try {
|
|
812
|
+
return realpathSync(resolve4(word));
|
|
813
|
+
} catch {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
818
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
819
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve4(word) === script || realPath(word) === target));
|
|
820
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
821
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
822
|
+
}
|
|
780
823
|
// ../kit/src/process.ts
|
|
781
824
|
import { constants } from "os";
|
|
782
|
-
import
|
|
825
|
+
import process11 from "process";
|
|
783
826
|
var KILL_GRACE_MS = 2000;
|
|
784
827
|
function exitCodeOf(code, signal) {
|
|
785
828
|
if (code !== null)
|
|
@@ -799,7 +842,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
799
842
|
return;
|
|
800
843
|
try {
|
|
801
844
|
if (grouped)
|
|
802
|
-
|
|
845
|
+
process11.kill(-proc.pid, killing);
|
|
803
846
|
else
|
|
804
847
|
proc.kill(killing);
|
|
805
848
|
} catch {}
|
|
@@ -873,15 +916,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
916
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
917
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
918
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
919
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
877
920
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
|
-
import
|
|
921
|
+
import process13 from "process";
|
|
879
922
|
|
|
880
923
|
// ../kit/src/usage.ts
|
|
881
924
|
import { appendFileSync, mkdirSync } from "fs";
|
|
882
925
|
import { homedir as homedir3 } from "os";
|
|
883
926
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
884
|
-
import
|
|
927
|
+
import process12 from "process";
|
|
885
928
|
|
|
886
929
|
// ../kit/src/logs.ts
|
|
887
930
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -895,14 +938,14 @@ var usageError;
|
|
|
895
938
|
function noteUsageError(message) {
|
|
896
939
|
usageError = message;
|
|
897
940
|
}
|
|
898
|
-
function stateHome(env =
|
|
941
|
+
function stateHome(env = process12.env) {
|
|
899
942
|
const dir = env.XDG_STATE_HOME;
|
|
900
943
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
901
944
|
}
|
|
902
|
-
function usagePath(env =
|
|
945
|
+
function usagePath(env = process12.env) {
|
|
903
946
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
904
947
|
}
|
|
905
|
-
function usageRecorded(env =
|
|
948
|
+
function usageRecorded(env = process12.env) {
|
|
906
949
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
907
950
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
908
951
|
}
|
|
@@ -916,7 +959,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
916
959
|
usageError = undefined;
|
|
917
960
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
918
961
|
}
|
|
919
|
-
function recordUsage(entry, env =
|
|
962
|
+
function recordUsage(entry, env = process12.env) {
|
|
920
963
|
if (!usageRecorded(env))
|
|
921
964
|
return;
|
|
922
965
|
try {
|
|
@@ -993,7 +1036,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
993
1036
|
header(colors, summary),
|
|
994
1037
|
"",
|
|
995
1038
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
996
|
-
...replacesRows(replaces, colors),
|
|
997
1039
|
"",
|
|
998
1040
|
...await commandRows(commands, colors),
|
|
999
1041
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1007,8 +1049,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1007
1049
|
`);
|
|
1008
1050
|
}
|
|
1009
1051
|
function printError(prefix, message, hint, cause) {
|
|
1010
|
-
const colors = paint(
|
|
1011
|
-
const styled = takesControlCodes(
|
|
1052
|
+
const colors = paint(process13.stderr);
|
|
1053
|
+
const styled = takesControlCodes(process13.stderr);
|
|
1012
1054
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1013
1055
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1014
1056
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1051,11 +1093,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1051
1093
|
}
|
|
1052
1094
|
}
|
|
1053
1095
|
if (name === undefined && level.path.length > 1) {
|
|
1054
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1096
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
1055
1097
|
return 2;
|
|
1056
1098
|
}
|
|
1057
1099
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1058
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1100
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
1059
1101
|
return 0;
|
|
1060
1102
|
}
|
|
1061
1103
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1111,24 +1153,24 @@ function candidateLine(candidate) {
|
|
|
1111
1153
|
}
|
|
1112
1154
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1113
1155
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1114
|
-
|
|
1156
|
+
const typed = [];
|
|
1115
1157
|
let at = 0;
|
|
1116
1158
|
while (at < before.length) {
|
|
1117
1159
|
const word = before[at];
|
|
1118
1160
|
if (word === "--") {
|
|
1119
|
-
|
|
1161
|
+
typed.push(...before.slice(at + 1));
|
|
1120
1162
|
break;
|
|
1121
1163
|
}
|
|
1122
1164
|
if (!word.startsWith("-"))
|
|
1123
|
-
|
|
1165
|
+
typed.push(word);
|
|
1124
1166
|
else if (takesValue(word))
|
|
1125
1167
|
at++;
|
|
1126
1168
|
at++;
|
|
1127
1169
|
}
|
|
1128
1170
|
const last = positionals.at(-1);
|
|
1129
|
-
if (
|
|
1130
|
-
return positionals[
|
|
1131
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1171
|
+
if (typed.length < positionals.length)
|
|
1172
|
+
return { name: positionals[typed.length], typed };
|
|
1173
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1132
1174
|
}
|
|
1133
1175
|
async function leafCandidates(run, words) {
|
|
1134
1176
|
const completing = await completingOf(run);
|
|
@@ -1136,12 +1178,12 @@ async function leafCandidates(run, words) {
|
|
|
1136
1178
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1137
1179
|
const flag = words.at(-2);
|
|
1138
1180
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1181
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1139
1182
|
if (option?.type === "string") {
|
|
1140
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1183
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1141
1184
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1142
1185
|
}
|
|
1143
|
-
const
|
|
1144
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1186
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1145
1187
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1146
1188
|
}
|
|
1147
1189
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1172,9 +1214,13 @@ async function printCandidates(found) {
|
|
|
1172
1214
|
return 0;
|
|
1173
1215
|
}
|
|
1174
1216
|
function packageVersion(entry = Bun.main) {
|
|
1175
|
-
|
|
1217
|
+
let resolved = entry;
|
|
1218
|
+
try {
|
|
1219
|
+
resolved = realpathSync2(entry);
|
|
1220
|
+
} catch {}
|
|
1221
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1176
1222
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1223
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1178
1224
|
if (typeof version === "string")
|
|
1179
1225
|
return version;
|
|
1180
1226
|
} catch {}
|
|
@@ -1182,7 +1228,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1182
1228
|
return "0.0.0";
|
|
1183
1229
|
}
|
|
1184
1230
|
}
|
|
1185
|
-
async function runCli(cli, argv =
|
|
1231
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1186
1232
|
const version = cli.version ?? packageVersion();
|
|
1187
1233
|
if (argv[0] === COMPLETE)
|
|
1188
1234
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1209,7 +1255,7 @@ function commandPath(scope, argv) {
|
|
|
1209
1255
|
}
|
|
1210
1256
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1211
1257
|
}
|
|
1212
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1258
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1213
1259
|
if (argv[0] === COMPLETE)
|
|
1214
1260
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1215
1261
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1231,6 +1277,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1277
|
}
|
|
1232
1278
|
// ../kit/src/folders.ts
|
|
1233
1279
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1280
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1281
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1282
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1283
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1284
|
+
}
|
|
1234
1285
|
// ../kit/src/limit.ts
|
|
1235
1286
|
function limitOptions(fallback) {
|
|
1236
1287
|
return {
|
|
@@ -1260,7 +1311,7 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1260
1311
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1261
1312
|
// src/hotspots.ts
|
|
1262
1313
|
import { basename, join as join7 } from "path";
|
|
1263
|
-
import
|
|
1314
|
+
import process15 from "process";
|
|
1264
1315
|
|
|
1265
1316
|
// src/churn.ts
|
|
1266
1317
|
var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|kay|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
|
|
@@ -1301,11 +1352,11 @@ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
|
|
|
1301
1352
|
}
|
|
1302
1353
|
|
|
1303
1354
|
// src/files.ts
|
|
1304
|
-
import { existsSync as
|
|
1355
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1305
1356
|
import { join as join6, relative } from "path";
|
|
1306
1357
|
var MAX_BYTES = 2000000;
|
|
1307
1358
|
var SNIFF_BYTES = 8000;
|
|
1308
|
-
function walk(dir, found) {
|
|
1359
|
+
function walk(dir, found, ignored) {
|
|
1309
1360
|
let entries;
|
|
1310
1361
|
try {
|
|
1311
1362
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1313,10 +1364,10 @@ function walk(dir, found) {
|
|
|
1313
1364
|
return found;
|
|
1314
1365
|
}
|
|
1315
1366
|
for (const entry of entries) {
|
|
1316
|
-
if (entry.name.startsWith(".") ||
|
|
1367
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1317
1368
|
continue;
|
|
1318
1369
|
if (entry.isDirectory())
|
|
1319
|
-
walk(join6(dir, entry.name), found);
|
|
1370
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1320
1371
|
else if (entry.isFile())
|
|
1321
1372
|
found.push(join6(dir, entry.name));
|
|
1322
1373
|
}
|
|
@@ -1325,9 +1376,10 @@ function walk(dir, found) {
|
|
|
1325
1376
|
async function listFiles(paths, cwd) {
|
|
1326
1377
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1327
1378
|
if (listed.code === 0)
|
|
1328
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1379
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1329
1380
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1330
|
-
|
|
1381
|
+
const ignored = ignoredFolders();
|
|
1382
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1331
1383
|
}
|
|
1332
1384
|
async function readText(path) {
|
|
1333
1385
|
const file = Bun.file(path);
|
|
@@ -1390,18 +1442,18 @@ ${blanked(template)}`) : text.replace(MARKUP_BLOCK, blanked);
|
|
|
1390
1442
|
}
|
|
1391
1443
|
|
|
1392
1444
|
// src/hotspots.ts
|
|
1393
|
-
var
|
|
1394
|
-
var
|
|
1445
|
+
var SETTINGS = readUserConfig("hotspots");
|
|
1446
|
+
var DEFAULT_SINCE = typeof SETTINGS.since === "string" && SETTINGS.since !== "" ? SETTINGS.since : "6 months ago";
|
|
1447
|
+
var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
|
|
1395
1448
|
var DAY_MS2 = 86400000;
|
|
1396
1449
|
var DEFAULT_HALF_LIFE = "90d";
|
|
1397
|
-
var DEFAULT_COUNT = 20;
|
|
1450
|
+
var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
|
|
1398
1451
|
var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1399
1452
|
|
|
1400
1453
|
Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. Each file also shows its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
|
|
1401
1454
|
|
|
1402
|
-
Lists at most ${DEFAULT_COUNT} files, the count of the rest after them (--limit <n>, --full for all); --json is never cut unless --limit is given
|
|
1403
|
-
|
|
1404
|
-
Exits 0 when it ranked the files, 1 when no file has commits in the window, 2 on a usage error or outside a git repository.`;
|
|
1455
|
+
Lists at most ${DEFAULT_COUNT} files, the count of the rest after them (--limit <n>, --full for all); --json is never cut unless --limit is given.`;
|
|
1456
|
+
var EXITS = [[0, "it ranked the files"], [1, "no file has commits in the window"], [2, "a usage error or outside a git repository"]];
|
|
1405
1457
|
var OPTIONS = {
|
|
1406
1458
|
since: { type: "string", short: "s", description: `only count the commits since this date, as git reads it (${DEFAULT_SINCE})` },
|
|
1407
1459
|
"half-life": { type: "string", description: `how long until a commit counts half as much (${DEFAULT_HALF_LIFE}), 0 for no decay` },
|
|
@@ -1413,11 +1465,11 @@ var OPTIONS = {
|
|
|
1413
1465
|
var HOT = 0.66;
|
|
1414
1466
|
var WARM = 0.33;
|
|
1415
1467
|
async function hotspots(args) {
|
|
1416
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'hotspots src --since "3 months ago" --limit 10'] });
|
|
1468
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'hotspots src --since "3 months ago" --limit 10'] });
|
|
1417
1469
|
if (positionals.length > 1)
|
|
1418
1470
|
badUsage("give one folder");
|
|
1419
1471
|
const count = limitOf(values, DEFAULT_COUNT);
|
|
1420
|
-
const cwd =
|
|
1472
|
+
const cwd = process15.cwd();
|
|
1421
1473
|
const bulk = Number(values.bulk ?? DEFAULT_BULK);
|
|
1422
1474
|
if (!Number.isInteger(bulk) || bulk < 1)
|
|
1423
1475
|
badUsage(`--bulk takes a number of files, not ${values.bulk}`);
|
|
@@ -1448,8 +1500,8 @@ async function hotspots(args) {
|
|
|
1448
1500
|
printJson(shown);
|
|
1449
1501
|
return 0;
|
|
1450
1502
|
}
|
|
1451
|
-
const colors = paint(
|
|
1452
|
-
const path = role("path",
|
|
1503
|
+
const colors = paint(process15.stdout);
|
|
1504
|
+
const path = role("path", process15.stdout);
|
|
1453
1505
|
const top = shown.reduce((highest, row) => Math.max(highest, row.score), 0);
|
|
1454
1506
|
const heat = (score, text) => {
|
|
1455
1507
|
if (top > 0 && score >= top * HOT)
|
|
@@ -1457,16 +1509,16 @@ async function hotspots(args) {
|
|
|
1457
1509
|
return top > 0 && score >= top * WARM ? colors.yellow(text) : text;
|
|
1458
1510
|
};
|
|
1459
1511
|
printHeader("hotspots", `${basename(cwd)} \xB7 since ${values.since ?? DEFAULT_SINCE}`);
|
|
1460
|
-
console.log(table([["rank", "score", "churn", "recent", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.complexity, row.lines].map(String), fileLink(path(row.path), row.path,
|
|
1512
|
+
console.log(table([["rank", "score", "churn", "recent", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.complexity, row.lines].map(String), fileLink(path(row.path), row.path, process15.stdout, cwd), row.worst === undefined ? "" : `${row.worst.name} (${row.worst.complexity}, line ${row.worst.line})`])], { header: true, align: ["right", "right", "right", "right", "right", "right", "left", "left"] }));
|
|
1461
1513
|
if (footer !== undefined)
|
|
1462
1514
|
console.log(footer);
|
|
1463
1515
|
return 0;
|
|
1464
1516
|
}
|
|
1465
1517
|
|
|
1466
1518
|
// src/peek.ts
|
|
1467
|
-
import { realpathSync as
|
|
1468
|
-
import { isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as
|
|
1469
|
-
import
|
|
1519
|
+
import { realpathSync as realpathSync3 } from "fs";
|
|
1520
|
+
import { isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as resolve5, sep } from "path";
|
|
1521
|
+
import process16 from "process";
|
|
1470
1522
|
|
|
1471
1523
|
// src/source.ts
|
|
1472
1524
|
var LOCATION = /^(?:\.\/)?([^\s:()]+)(?::(\d+)(?::\d+)?|\((\d+),\d+\))(?=[:\s)]|$)/;
|
|
@@ -1651,9 +1703,8 @@ peek --around <regex> [-C 3] [path...] the lines around each match, overlapping
|
|
|
1651
1703
|
<output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1652
1704
|
The paths default to the files git keeps here (.gitignore holds).
|
|
1653
1705
|
--refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
|
|
1654
|
-
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given
|
|
1655
|
-
|
|
1656
|
-
Exits 0 when it printed something, 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.`;
|
|
1706
|
+
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
|
|
1707
|
+
var EXITS2 = [[0, "it printed something"], [1, "nothing is found, a file cannot be read or a span starts past the end"], [2, "a usage error or a path outside the repository"]];
|
|
1657
1708
|
var REFS_LIMIT = 100;
|
|
1658
1709
|
var AROUND_LIMIT = 20;
|
|
1659
1710
|
var PARENT = `..${sep}`;
|
|
@@ -1674,13 +1725,13 @@ function cut(text) {
|
|
|
1674
1725
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1675
1726
|
}
|
|
1676
1727
|
async function readableRoot() {
|
|
1677
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1678
|
-
return
|
|
1728
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process16.cwd() });
|
|
1729
|
+
return realpathSync3(ran.code === 0 ? ran.text.trim() : process16.cwd());
|
|
1679
1730
|
}
|
|
1680
1731
|
async function isOutside(path) {
|
|
1681
1732
|
let real;
|
|
1682
1733
|
try {
|
|
1683
|
-
real =
|
|
1734
|
+
real = realpathSync3(resolve5(process16.cwd(), path));
|
|
1684
1735
|
} catch {
|
|
1685
1736
|
return false;
|
|
1686
1737
|
}
|
|
@@ -1694,7 +1745,7 @@ async function checkInside(path) {
|
|
|
1694
1745
|
async function pipedSpans(text, context) {
|
|
1695
1746
|
const spans = [];
|
|
1696
1747
|
for (const [path, numbers] of locations(text)) {
|
|
1697
|
-
const source = await isOutside(path) ? undefined : await readText(
|
|
1748
|
+
const source = await isOutside(path) ? undefined : await readText(resolve5(process16.cwd(), path));
|
|
1698
1749
|
if (source !== undefined)
|
|
1699
1750
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1700
1751
|
`).length, numbers, context));
|
|
@@ -1703,7 +1754,7 @@ async function pipedSpans(text, context) {
|
|
|
1703
1754
|
}
|
|
1704
1755
|
async function textOf(path) {
|
|
1705
1756
|
await checkInside(path);
|
|
1706
|
-
const text = await readText(
|
|
1757
|
+
const text = await readText(resolve5(process16.cwd(), path));
|
|
1707
1758
|
if (text === undefined)
|
|
1708
1759
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1709
1760
|
return text;
|
|
@@ -1761,8 +1812,8 @@ async function spanOf(target) {
|
|
|
1761
1812
|
async function* sources(paths) {
|
|
1762
1813
|
for (const path of paths)
|
|
1763
1814
|
await checkInside(path);
|
|
1764
|
-
for (const path of await listFiles(paths,
|
|
1765
|
-
const text = await readText(join8(
|
|
1815
|
+
for (const path of await listFiles(paths, process16.cwd())) {
|
|
1816
|
+
const text = await readText(join8(process16.cwd(), path));
|
|
1766
1817
|
if (text !== undefined)
|
|
1767
1818
|
yield { path, text };
|
|
1768
1819
|
}
|
|
@@ -1786,7 +1837,7 @@ async function definitionsOf(symbols, paths) {
|
|
|
1786
1837
|
return [...found.values()].flat();
|
|
1787
1838
|
}
|
|
1788
1839
|
async function peek(args) {
|
|
1789
|
-
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
1840
|
+
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
1790
1841
|
const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1791
1842
|
const json = values.json === true;
|
|
1792
1843
|
if (values["defs-first"] === true && values.refs === undefined)
|
|
@@ -1863,7 +1914,7 @@ async function peek(args) {
|
|
|
1863
1914
|
|
|
1864
1915
|
// src/todo-scan.ts
|
|
1865
1916
|
import { join as join9 } from "path";
|
|
1866
|
-
import
|
|
1917
|
+
import process17 from "process";
|
|
1867
1918
|
|
|
1868
1919
|
// src/todo.ts
|
|
1869
1920
|
var COMMENT2 = /(?<![:\w/])\/\/|\/\*|<!--|(?:^|\s)(?:#|--)(?=\s)|^\s*\*(?=\s|$)/;
|
|
@@ -1938,9 +1989,8 @@ var USAGE3 = `todo-scan [options] [path...]: lists the TODO, FIXME and owner/rep
|
|
|
1938
1989
|
|
|
1939
1990
|
--stale keeps only the comments naming a closed issue, each issue's state looked up with ft, or gh for a GitHub repository, and exits 1 when it finds one.
|
|
1940
1991
|
|
|
1941
|
-
Lists at most 100 comments, the count of the rest after them (--limit <n>, --full for all); --json is never cut unless --limit is given
|
|
1942
|
-
|
|
1943
|
-
Exits 0 when it listed the comments or found no stale one, 1 when --stale finds one, 2 on a usage error or when --stale could not look a repository up (ft and gh both failed), so a clean exit never hides an unchecked issue.`;
|
|
1992
|
+
Lists at most 100 comments, the count of the rest after them (--limit <n>, --full for all); --json is never cut unless --limit is given.`;
|
|
1993
|
+
var EXITS3 = [[0, "it listed the comments or found no stale one"], [1, "--stale finds one"], [2, "a usage error or when --stale could not look a repository up (ft and gh both failed)"]];
|
|
1944
1994
|
var LIST_LIMIT = 100;
|
|
1945
1995
|
var OPTIONS3 = {
|
|
1946
1996
|
stale: { type: "boolean", description: "only the comments naming a closed issue, looked up with ft or gh" },
|
|
@@ -1954,8 +2004,8 @@ function printLines(lines, footer) {
|
|
|
1954
2004
|
`));
|
|
1955
2005
|
}
|
|
1956
2006
|
async function todoScan(args) {
|
|
1957
|
-
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
1958
|
-
const cwd =
|
|
2007
|
+
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
2008
|
+
const cwd = process17.cwd();
|
|
1959
2009
|
const limit = limitOf(values, LIST_LIMIT);
|
|
1960
2010
|
const marks = [];
|
|
1961
2011
|
for (const path of await listFiles(positionals, cwd)) {
|
|
@@ -1986,7 +2036,7 @@ async function todoScan(args) {
|
|
|
1986
2036
|
}
|
|
1987
2037
|
|
|
1988
2038
|
// src/cli.ts
|
|
1989
|
-
|
|
2039
|
+
process18.exitCode = await runCli({
|
|
1990
2040
|
name: "src",
|
|
1991
2041
|
about: "reads and ranks the source of a folder: line spans, TODO comments and the files worth splitting",
|
|
1992
2042
|
replaces: "sed -n N,Mp, grep -n chains and grep -rn TODO",
|