@kaynooo/cli-code 0.7.1 → 0.8.0
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 +4 -3
- package/dist/hotspots.js +95 -53
- package/dist/peek.js +131 -74
- package/dist/todo-scan.js +81 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,10 @@ hotspots --since '3 months ago' --limit 10
|
|
|
19
19
|
|
|
20
20
|
- `peek <file[:from-to]>...` prints each span under a `<file>:<from>-<to>` header, each line with its number, so an edit can target it; `<file>:<n>` is one line, a bare `<file>` the whole file. A line past 300 characters is cut.
|
|
21
21
|
- `--def <symbol>` prints each declaration of the symbol, the comments and decorators right above it included: a `function`, `class`, `interface`, `type`, `enum`, `const`/`let`/`var` or `namespace` (and Python's `def`/`class`, Go's `func`, Rust's `fn`/`struct`/`trait`), or a class member whose parameters follow its name. Its end is where its braces close, strings and line comments left out of the count, or for Python and YAML where its indentation ends.
|
|
22
|
-
- `--refs <symbol>` lists the lines naming the symbol as a whole word, grouped by file, one trimmed line each.
|
|
22
|
+
- `--refs <symbol>` lists the lines naming the symbol as a whole word, grouped by file, one trimmed line each, at most 100 (`--limit <n>`, `--full` for all, the count of the rest after them). `--defs-first` prints the symbol's declarations before them (`{definitions, references}` under `--json`).
|
|
23
|
+
- `--def` repeats for several symbols in one call (`peek --def a --def b src`); one with no declaration is named and exits 1.
|
|
23
24
|
- `--outline <file>...` lists the declarations at the top of each file and the members one level inside its classes, with their line numbers; a Markdown file lists its headings.
|
|
24
|
-
- `--around <regex> -C <n>` prints the `n` (3) lines on each side of each matching line, spans that touch merged.
|
|
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).
|
|
25
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.
|
|
26
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.
|
|
27
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.
|
|
@@ -37,6 +38,6 @@ hotspots --since '3 months ago' --limit 10
|
|
|
37
38
|
## hotspots
|
|
38
39
|
|
|
39
40
|
- `hotspots [dir]` ranks the source files by complexity times churn, so the files both hard to read and often edited come first: rank, score, churn, recent, complexity, lines, file and the file's most complex declaration. The files are the ones git keeps (`.gitignore` honoured).
|
|
40
|
-
- 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 so the bin needs no dependency and reads any language the same way.
|
|
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.
|
|
41
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.
|
|
42
43
|
- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
|
package/dist/hotspots.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/hotspots.ts
|
|
5
|
-
import { join as
|
|
6
|
-
import
|
|
7
|
-
|
|
5
|
+
import { join as join4 } from "path";
|
|
6
|
+
import process10 from "process";
|
|
8
7
|
// ../kit/src/args.ts
|
|
9
|
-
import
|
|
8
|
+
import process5 from "process";
|
|
10
9
|
import { parseArgs } from "util";
|
|
11
10
|
|
|
12
11
|
// ../kit/src/format.ts
|
|
13
|
-
import
|
|
12
|
+
import process3 from "process";
|
|
14
13
|
|
|
15
14
|
// ../kit/src/style.ts
|
|
16
|
-
import
|
|
15
|
+
import process2 from "process";
|
|
17
16
|
|
|
18
17
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
19
18
|
function x(s) {
|
|
@@ -283,20 +282,20 @@ var MARKS = {
|
|
|
283
282
|
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
284
283
|
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
285
284
|
};
|
|
286
|
-
function takesControlCodes(stream, env =
|
|
285
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
287
286
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
288
287
|
}
|
|
289
|
-
function paint(stream, env =
|
|
288
|
+
function paint(stream, env = process2.env) {
|
|
290
289
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
291
290
|
}
|
|
292
|
-
function marked(mark, text, stream, detail, env =
|
|
291
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
293
292
|
const colors = paint(stream, env);
|
|
294
293
|
const { symbol, word, paint: tint } = MARKS[mark];
|
|
295
294
|
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
296
295
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
297
296
|
}
|
|
298
297
|
function warn(text, detail) {
|
|
299
|
-
console.error(marked("warn", text,
|
|
298
|
+
console.error(marked("warn", text, process2.stderr, detail));
|
|
300
299
|
}
|
|
301
300
|
var STATUSES = {
|
|
302
301
|
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
@@ -328,7 +327,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
328
327
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
329
328
|
}
|
|
330
329
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
331
|
-
const colors = paint(
|
|
330
|
+
const colors = paint(process3.stdout);
|
|
332
331
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
333
332
|
const width = widths[index] ?? 0;
|
|
334
333
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -360,24 +359,30 @@ function printJson(value) {
|
|
|
360
359
|
}
|
|
361
360
|
|
|
362
361
|
// ../kit/src/help.ts
|
|
363
|
-
import
|
|
362
|
+
import process4 from "process";
|
|
364
363
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
365
364
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
366
365
|
var FULL_STOP = /\.$/;
|
|
367
|
-
function usageLine(usage, colors = paint(
|
|
366
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
368
367
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
369
368
|
}
|
|
370
|
-
function helpText(usage, options, colors = paint(
|
|
371
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
369
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
370
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
372
371
|
`);
|
|
373
372
|
}
|
|
374
|
-
function
|
|
373
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
374
|
+
if (exits.length === 0)
|
|
375
|
+
return [];
|
|
376
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
377
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
378
|
+
}
|
|
379
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
375
380
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
376
381
|
}
|
|
377
|
-
function wantsHelpJson(env =
|
|
382
|
+
function wantsHelpJson(env = process4.env) {
|
|
378
383
|
return env.KIT_HELP === "json";
|
|
379
384
|
}
|
|
380
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
385
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
381
386
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
382
387
|
`);
|
|
383
388
|
const first = lines[0];
|
|
@@ -388,15 +393,17 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
388
393
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
389
394
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
390
395
|
...replaces === undefined ? {} : { replaces },
|
|
391
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
396
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
397
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
398
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
392
399
|
};
|
|
393
400
|
}
|
|
394
|
-
function exampleRows(examples, colors = paint(
|
|
401
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
395
402
|
if (examples.length === 0)
|
|
396
403
|
return [];
|
|
397
404
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
398
405
|
}
|
|
399
|
-
function optionRows(options, colors = paint(
|
|
406
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
400
407
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
401
408
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
402
409
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -503,7 +510,7 @@ var OUTPUT_OPTIONS = {
|
|
|
503
510
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
504
511
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
505
512
|
};
|
|
506
|
-
function applyOutput(color, plain, env =
|
|
513
|
+
function applyOutput(color, plain, env = process5.env) {
|
|
507
514
|
const when = plain === true ? "never" : color ?? "auto";
|
|
508
515
|
if (when === "auto")
|
|
509
516
|
return;
|
|
@@ -526,7 +533,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
526
533
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
527
534
|
let parsed;
|
|
528
535
|
try {
|
|
529
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
536
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
530
537
|
} catch (error) {
|
|
531
538
|
const message = parseError(error);
|
|
532
539
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -534,7 +541,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
534
541
|
const values = parsed.values;
|
|
535
542
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
536
543
|
if (values.help === true) {
|
|
537
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
544
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
538
545
|
throw new HelpShown;
|
|
539
546
|
}
|
|
540
547
|
checkChoices(parsed.values, all);
|
|
@@ -576,6 +583,18 @@ function listed(options, allowNegative) {
|
|
|
576
583
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
577
584
|
}));
|
|
578
585
|
}
|
|
586
|
+
function withAliases(args, options) {
|
|
587
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
588
|
+
if (named.size === 0)
|
|
589
|
+
return args;
|
|
590
|
+
const separator = args.indexOf("--");
|
|
591
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
592
|
+
return [...own.map((arg) => {
|
|
593
|
+
const at = arg.indexOf("=");
|
|
594
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
595
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
596
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
597
|
+
}
|
|
579
598
|
function withBare(args, options) {
|
|
580
599
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
581
600
|
if (bare.size === 0)
|
|
@@ -662,7 +681,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
662
681
|
}
|
|
663
682
|
// ../kit/src/process.ts
|
|
664
683
|
import { constants } from "os";
|
|
665
|
-
import
|
|
684
|
+
import process6 from "process";
|
|
666
685
|
var KILL_GRACE_MS = 2000;
|
|
667
686
|
function exitCodeOf(code, signal) {
|
|
668
687
|
if (code !== null)
|
|
@@ -682,7 +701,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
682
701
|
return;
|
|
683
702
|
try {
|
|
684
703
|
if (grouped)
|
|
685
|
-
|
|
704
|
+
process6.kill(-proc.pid, killing);
|
|
686
705
|
else
|
|
687
706
|
proc.kill(killing);
|
|
688
707
|
} catch {}
|
|
@@ -756,13 +775,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
756
775
|
var RESET_STYLE = `${ESC}[0m`;
|
|
757
776
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
758
777
|
// ../kit/src/cli.ts
|
|
759
|
-
import
|
|
778
|
+
import { readFileSync, realpathSync } from "fs";
|
|
779
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
780
|
+
import process8 from "process";
|
|
760
781
|
|
|
761
782
|
// ../kit/src/usage.ts
|
|
762
783
|
import { appendFileSync, mkdirSync } from "fs";
|
|
763
784
|
import { homedir } from "os";
|
|
764
785
|
import { dirname, isAbsolute, join } from "path";
|
|
765
|
-
import
|
|
786
|
+
import process7 from "process";
|
|
766
787
|
|
|
767
788
|
// ../kit/src/logs.ts
|
|
768
789
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -776,14 +797,14 @@ var usageError;
|
|
|
776
797
|
function noteUsageError(message) {
|
|
777
798
|
usageError = message;
|
|
778
799
|
}
|
|
779
|
-
function stateHome(env =
|
|
800
|
+
function stateHome(env = process7.env) {
|
|
780
801
|
const dir = env.XDG_STATE_HOME;
|
|
781
802
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
782
803
|
}
|
|
783
|
-
function usagePath(env =
|
|
804
|
+
function usagePath(env = process7.env) {
|
|
784
805
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
785
806
|
}
|
|
786
|
-
function usageRecorded(env =
|
|
807
|
+
function usageRecorded(env = process7.env) {
|
|
787
808
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
788
809
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
789
810
|
}
|
|
@@ -797,7 +818,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
797
818
|
usageError = undefined;
|
|
798
819
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
799
820
|
}
|
|
800
|
-
function recordUsage(entry, env =
|
|
821
|
+
function recordUsage(entry, env = process7.env) {
|
|
801
822
|
if (!usageRecorded(env))
|
|
802
823
|
return;
|
|
803
824
|
try {
|
|
@@ -815,8 +836,8 @@ var LEVEL_OPTIONS = {
|
|
|
815
836
|
};
|
|
816
837
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
817
838
|
function printError(prefix, message, hint, cause) {
|
|
818
|
-
const colors = paint(
|
|
819
|
-
const styled = takesControlCodes(
|
|
839
|
+
const colors = paint(process8.stderr);
|
|
840
|
+
const styled = takesControlCodes(process8.stderr);
|
|
820
841
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
821
842
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
822
843
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -898,11 +919,22 @@ async function printCandidates(found) {
|
|
|
898
919
|
console.log(line);
|
|
899
920
|
return 0;
|
|
900
921
|
}
|
|
901
|
-
|
|
922
|
+
function packageVersion(entry = Bun.main) {
|
|
923
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
924
|
+
try {
|
|
925
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
926
|
+
if (typeof version === "string")
|
|
927
|
+
return version;
|
|
928
|
+
} catch {}
|
|
929
|
+
if (dirname2(dir) === dir)
|
|
930
|
+
return "0.0.0";
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
async function runMain({ name, version, run, redact, usage }, argv = process8.argv.slice(2)) {
|
|
902
934
|
if (argv[0] === COMPLETE)
|
|
903
935
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
904
936
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
905
|
-
console.log(version);
|
|
937
|
+
console.log(version ?? packageVersion());
|
|
906
938
|
return 0;
|
|
907
939
|
}
|
|
908
940
|
let code;
|
|
@@ -911,8 +943,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
|
|
|
911
943
|
} catch (error) {
|
|
912
944
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
913
945
|
}
|
|
914
|
-
if (usage !== false)
|
|
915
|
-
|
|
946
|
+
if (usage !== false) {
|
|
947
|
+
try {
|
|
948
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
949
|
+
} catch {}
|
|
950
|
+
}
|
|
916
951
|
return code;
|
|
917
952
|
}
|
|
918
953
|
// ../kit/src/limit.ts
|
|
@@ -942,11 +977,8 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
942
977
|
var {Glob } = globalThis.Bun;
|
|
943
978
|
var SESSION_FILES = new Glob("*.json");
|
|
944
979
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
945
|
-
// package.json
|
|
946
|
-
var version = "0.7.1";
|
|
947
|
-
|
|
948
980
|
// src/churn.ts
|
|
949
|
-
var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
|
|
981
|
+
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)$/;
|
|
950
982
|
var TESTS = /(?:^|\/)(?:tests?|__tests__|spec|e2e|__mocks__|fixtures)\/|\.(?:test|spec|bench)\.[^/]+$|(?:^|\/)test_[^/]+$|_test\.(?:go|py)$/;
|
|
951
983
|
var GENERATED = /(?:^|\/)(?:dist|build|out|generated|\.nuxt|\.output|\.next)\/|\.min\.[cm]?js$|\.d\.ts$|\.(?:generated|gen)\.[^/]+$|\.pb\.go$|\.snap$/;
|
|
952
984
|
var LEADING_NEWLINE = /^\n/;
|
|
@@ -985,7 +1017,7 @@ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
|
|
|
985
1017
|
|
|
986
1018
|
// src/files.ts
|
|
987
1019
|
import { existsSync, readdirSync, statSync } from "fs";
|
|
988
|
-
import { join as
|
|
1020
|
+
import { join as join3, relative } from "path";
|
|
989
1021
|
var MAX_BYTES = 2000000;
|
|
990
1022
|
var SNIFF_BYTES = 8000;
|
|
991
1023
|
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
@@ -1000,17 +1032,17 @@ function walk(dir, found) {
|
|
|
1000
1032
|
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1001
1033
|
continue;
|
|
1002
1034
|
if (entry.isDirectory())
|
|
1003
|
-
walk(
|
|
1035
|
+
walk(join3(dir, entry.name), found);
|
|
1004
1036
|
else if (entry.isFile())
|
|
1005
|
-
found.push(
|
|
1037
|
+
found.push(join3(dir, entry.name));
|
|
1006
1038
|
}
|
|
1007
1039
|
return found;
|
|
1008
1040
|
}
|
|
1009
1041
|
async function listFiles(paths, cwd) {
|
|
1010
1042
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1011
1043
|
if (listed.code === 0)
|
|
1012
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(
|
|
1013
|
-
const roots = paths.length === 0 ? [cwd] : paths.map((path) =>
|
|
1044
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join3(cwd, path))).sort();
|
|
1045
|
+
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join3(cwd, path));
|
|
1014
1046
|
return roots.flatMap((root) => statSync(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
|
|
1015
1047
|
}
|
|
1016
1048
|
async function readText(path) {
|
|
@@ -1028,6 +1060,13 @@ async function readText(path) {
|
|
|
1028
1060
|
var CONTAINER = /^(?:(?:export|default|declare|abstract|final|readonly|public|pub|private|protected|internal|sealed|data|open)\s+)*(?:class|impl|trait|interface|namespace|module|object|mod|struct|enum)\b/;
|
|
1029
1061
|
var CLOSER = /^[\s)\]};]*$|^\s*(?:\/\/|\/\*|\*|#)/;
|
|
1030
1062
|
var LONGEST_NAME2 = 60;
|
|
1063
|
+
var MARKUP_BLOCK = /^<(template|style)\b[\s\S]*?\n<\/\1>/gm;
|
|
1064
|
+
var KAY_FILE = /^---\n([\s\S]*?\n)---(?:\n|$)([\s\S]*)$/;
|
|
1065
|
+
function blanked(text) {
|
|
1066
|
+
return `
|
|
1067
|
+
`.repeat(text.split(`
|
|
1068
|
+
`).length - 1);
|
|
1069
|
+
}
|
|
1031
1070
|
function indentOf(line) {
|
|
1032
1071
|
return line.length - line.trimStart().length;
|
|
1033
1072
|
}
|
|
@@ -1056,8 +1095,11 @@ function unitsAt(lines, from, to, indent) {
|
|
|
1056
1095
|
`)) }];
|
|
1057
1096
|
});
|
|
1058
1097
|
}
|
|
1059
|
-
function worstUnit(text) {
|
|
1060
|
-
const
|
|
1098
|
+
function worstUnit(text, path = "") {
|
|
1099
|
+
const code = path.endsWith(".kay") ? text.replace(KAY_FILE, (_, script, template) => `
|
|
1100
|
+
${script}
|
|
1101
|
+
${blanked(template)}`) : text.replace(MARKUP_BLOCK, blanked);
|
|
1102
|
+
const lines = code.split(`
|
|
1061
1103
|
`);
|
|
1062
1104
|
const top = unitsAt(lines, 0, lines.length, 0);
|
|
1063
1105
|
return top.reduce((worst, unit) => worst === undefined || unit.complexity > worst.complexity ? unit : worst, undefined);
|
|
@@ -1089,7 +1131,7 @@ async function main(args) {
|
|
|
1089
1131
|
if (positionals.length > 1)
|
|
1090
1132
|
badUsage("give one folder");
|
|
1091
1133
|
const count = limitOf(values, DEFAULT_COUNT);
|
|
1092
|
-
const cwd =
|
|
1134
|
+
const cwd = process10.cwd();
|
|
1093
1135
|
const bulk = Number(values.bulk ?? DEFAULT_BULK);
|
|
1094
1136
|
if (!Number.isInteger(bulk) || bulk < 1)
|
|
1095
1137
|
badUsage(`--bulk takes a number of files, not ${values.bulk}`);
|
|
@@ -1102,11 +1144,11 @@ async function main(args) {
|
|
|
1102
1144
|
const touched = churn.get(path);
|
|
1103
1145
|
if (touched === undefined || values.all !== true && !isCandidate(path))
|
|
1104
1146
|
continue;
|
|
1105
|
-
const text = await readText(
|
|
1147
|
+
const text = await readText(join4(cwd, path));
|
|
1106
1148
|
if (text === undefined || values.all !== true && isGenerated(text))
|
|
1107
1149
|
continue;
|
|
1108
1150
|
const complexity = complexityOf(text);
|
|
1109
|
-
const worst = worstUnit(text);
|
|
1151
|
+
const worst = worstUnit(text, path);
|
|
1110
1152
|
ranked.push({ path, score: Math.round(complexity * touched.weight), churn: touched.commits, recent: Math.round(touched.weight * 10) / 10, complexity, worst: worst === undefined ? undefined : { name: worst.name, line: worst.line, complexity: worst.complexity }, lines: text.split(`
|
|
1111
1153
|
`).length - (text.endsWith(`
|
|
1112
1154
|
`) ? 1 : 0) });
|
|
@@ -1125,4 +1167,4 @@ async function main(args) {
|
|
|
1125
1167
|
console.log(footer);
|
|
1126
1168
|
return 0;
|
|
1127
1169
|
}
|
|
1128
|
-
|
|
1170
|
+
process10.exitCode = await runMain({ name: "hotspots", run: main });
|
package/dist/peek.js
CHANGED
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/peek.ts
|
|
5
|
-
import { realpathSync } from "fs";
|
|
6
|
-
import { isAbsolute as isAbsolute2, join as
|
|
7
|
-
import
|
|
8
|
-
|
|
5
|
+
import { realpathSync as realpathSync2 } from "fs";
|
|
6
|
+
import { isAbsolute as isAbsolute2, join as join4, relative as relative2, resolve, sep } from "path";
|
|
7
|
+
import process10 from "process";
|
|
9
8
|
// ../kit/src/args.ts
|
|
10
|
-
import
|
|
9
|
+
import process5 from "process";
|
|
11
10
|
import { parseArgs } from "util";
|
|
12
11
|
|
|
13
12
|
// ../kit/src/format.ts
|
|
14
|
-
import
|
|
13
|
+
import process3 from "process";
|
|
15
14
|
|
|
16
15
|
// ../kit/src/style.ts
|
|
17
|
-
import
|
|
16
|
+
import process2 from "process";
|
|
18
17
|
|
|
19
18
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
20
19
|
function x(s) {
|
|
@@ -284,20 +283,20 @@ var MARKS = {
|
|
|
284
283
|
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
285
284
|
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
286
285
|
};
|
|
287
|
-
function takesControlCodes(stream, env =
|
|
286
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
288
287
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
289
288
|
}
|
|
290
|
-
function paint(stream, env =
|
|
289
|
+
function paint(stream, env = process2.env) {
|
|
291
290
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
292
291
|
}
|
|
293
|
-
function marked(mark, text, stream, detail, env =
|
|
292
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
294
293
|
const colors = paint(stream, env);
|
|
295
294
|
const { symbol, word, paint: tint } = MARKS[mark];
|
|
296
295
|
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
297
296
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
298
297
|
}
|
|
299
298
|
function warn(text, detail) {
|
|
300
|
-
console.error(marked("warn", text,
|
|
299
|
+
console.error(marked("warn", text, process2.stderr, detail));
|
|
301
300
|
}
|
|
302
301
|
var STATUSES = {
|
|
303
302
|
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
@@ -329,7 +328,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
329
328
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
330
329
|
}
|
|
331
330
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
332
|
-
const colors = paint(
|
|
331
|
+
const colors = paint(process3.stdout);
|
|
333
332
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
334
333
|
const width = widths[index] ?? 0;
|
|
335
334
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -361,24 +360,30 @@ function printJson(value) {
|
|
|
361
360
|
}
|
|
362
361
|
|
|
363
362
|
// ../kit/src/help.ts
|
|
364
|
-
import
|
|
363
|
+
import process4 from "process";
|
|
365
364
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
366
365
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
367
366
|
var FULL_STOP = /\.$/;
|
|
368
|
-
function usageLine(usage, colors = paint(
|
|
367
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
369
368
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
370
369
|
}
|
|
371
|
-
function helpText(usage, options, colors = paint(
|
|
372
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
370
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
371
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
373
372
|
`);
|
|
374
373
|
}
|
|
375
|
-
function
|
|
374
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
375
|
+
if (exits.length === 0)
|
|
376
|
+
return [];
|
|
377
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
378
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
379
|
+
}
|
|
380
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
376
381
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
377
382
|
}
|
|
378
|
-
function wantsHelpJson(env =
|
|
383
|
+
function wantsHelpJson(env = process4.env) {
|
|
379
384
|
return env.KIT_HELP === "json";
|
|
380
385
|
}
|
|
381
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
386
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
382
387
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
383
388
|
`);
|
|
384
389
|
const first = lines[0];
|
|
@@ -389,15 +394,17 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
389
394
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
390
395
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
391
396
|
...replaces === undefined ? {} : { replaces },
|
|
392
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
397
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
398
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
399
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
393
400
|
};
|
|
394
401
|
}
|
|
395
|
-
function exampleRows(examples, colors = paint(
|
|
402
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
396
403
|
if (examples.length === 0)
|
|
397
404
|
return [];
|
|
398
405
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
399
406
|
}
|
|
400
|
-
function optionRows(options, colors = paint(
|
|
407
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
401
408
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
402
409
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
403
410
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -504,7 +511,7 @@ var OUTPUT_OPTIONS = {
|
|
|
504
511
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
505
512
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
506
513
|
};
|
|
507
|
-
function applyOutput(color, plain, env =
|
|
514
|
+
function applyOutput(color, plain, env = process5.env) {
|
|
508
515
|
const when = plain === true ? "never" : color ?? "auto";
|
|
509
516
|
if (when === "auto")
|
|
510
517
|
return;
|
|
@@ -527,7 +534,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
527
534
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
528
535
|
let parsed;
|
|
529
536
|
try {
|
|
530
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
537
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
531
538
|
} catch (error) {
|
|
532
539
|
const message = parseError(error);
|
|
533
540
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -535,7 +542,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
535
542
|
const values = parsed.values;
|
|
536
543
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
537
544
|
if (values.help === true) {
|
|
538
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
545
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
539
546
|
throw new HelpShown;
|
|
540
547
|
}
|
|
541
548
|
checkChoices(parsed.values, all);
|
|
@@ -577,6 +584,18 @@ function listed(options, allowNegative) {
|
|
|
577
584
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
578
585
|
}));
|
|
579
586
|
}
|
|
587
|
+
function withAliases(args, options) {
|
|
588
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
589
|
+
if (named.size === 0)
|
|
590
|
+
return args;
|
|
591
|
+
const separator = args.indexOf("--");
|
|
592
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
593
|
+
return [...own.map((arg) => {
|
|
594
|
+
const at = arg.indexOf("=");
|
|
595
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
596
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
597
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
598
|
+
}
|
|
580
599
|
function withBare(args, options) {
|
|
581
600
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
582
601
|
if (bare.size === 0)
|
|
@@ -663,7 +682,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
663
682
|
}
|
|
664
683
|
// ../kit/src/process.ts
|
|
665
684
|
import { constants } from "os";
|
|
666
|
-
import
|
|
685
|
+
import process6 from "process";
|
|
667
686
|
var KILL_GRACE_MS = 2000;
|
|
668
687
|
function exitCodeOf(code, signal) {
|
|
669
688
|
if (code !== null)
|
|
@@ -683,7 +702,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
683
702
|
return;
|
|
684
703
|
try {
|
|
685
704
|
if (grouped)
|
|
686
|
-
|
|
705
|
+
process6.kill(-proc.pid, killing);
|
|
687
706
|
else
|
|
688
707
|
proc.kill(killing);
|
|
689
708
|
} catch {}
|
|
@@ -757,13 +776,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
757
776
|
var RESET_STYLE = `${ESC}[0m`;
|
|
758
777
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
759
778
|
// ../kit/src/cli.ts
|
|
760
|
-
import
|
|
779
|
+
import { readFileSync, realpathSync } from "fs";
|
|
780
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
781
|
+
import process8 from "process";
|
|
761
782
|
|
|
762
783
|
// ../kit/src/usage.ts
|
|
763
784
|
import { appendFileSync, mkdirSync } from "fs";
|
|
764
785
|
import { homedir } from "os";
|
|
765
786
|
import { dirname, isAbsolute, join } from "path";
|
|
766
|
-
import
|
|
787
|
+
import process7 from "process";
|
|
767
788
|
|
|
768
789
|
// ../kit/src/logs.ts
|
|
769
790
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -777,14 +798,14 @@ var usageError;
|
|
|
777
798
|
function noteUsageError(message) {
|
|
778
799
|
usageError = message;
|
|
779
800
|
}
|
|
780
|
-
function stateHome(env =
|
|
801
|
+
function stateHome(env = process7.env) {
|
|
781
802
|
const dir = env.XDG_STATE_HOME;
|
|
782
803
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
783
804
|
}
|
|
784
|
-
function usagePath(env =
|
|
805
|
+
function usagePath(env = process7.env) {
|
|
785
806
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
786
807
|
}
|
|
787
|
-
function usageRecorded(env =
|
|
808
|
+
function usageRecorded(env = process7.env) {
|
|
788
809
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
789
810
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
790
811
|
}
|
|
@@ -798,7 +819,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
798
819
|
usageError = undefined;
|
|
799
820
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
800
821
|
}
|
|
801
|
-
function recordUsage(entry, env =
|
|
822
|
+
function recordUsage(entry, env = process7.env) {
|
|
802
823
|
if (!usageRecorded(env))
|
|
803
824
|
return;
|
|
804
825
|
try {
|
|
@@ -816,8 +837,8 @@ var LEVEL_OPTIONS = {
|
|
|
816
837
|
};
|
|
817
838
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
818
839
|
function printError(prefix, message, hint, cause) {
|
|
819
|
-
const colors = paint(
|
|
820
|
-
const styled = takesControlCodes(
|
|
840
|
+
const colors = paint(process8.stderr);
|
|
841
|
+
const styled = takesControlCodes(process8.stderr);
|
|
821
842
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
822
843
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
823
844
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -899,11 +920,22 @@ async function printCandidates(found) {
|
|
|
899
920
|
console.log(line);
|
|
900
921
|
return 0;
|
|
901
922
|
}
|
|
902
|
-
|
|
923
|
+
function packageVersion(entry = Bun.main) {
|
|
924
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
925
|
+
try {
|
|
926
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
927
|
+
if (typeof version === "string")
|
|
928
|
+
return version;
|
|
929
|
+
} catch {}
|
|
930
|
+
if (dirname2(dir) === dir)
|
|
931
|
+
return "0.0.0";
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
async function runMain({ name, version, run, redact, usage }, argv = process8.argv.slice(2)) {
|
|
903
935
|
if (argv[0] === COMPLETE)
|
|
904
936
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
905
937
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
906
|
-
console.log(version);
|
|
938
|
+
console.log(version ?? packageVersion());
|
|
907
939
|
return 0;
|
|
908
940
|
}
|
|
909
941
|
let code;
|
|
@@ -912,8 +944,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
|
|
|
912
944
|
} catch (error) {
|
|
913
945
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
914
946
|
}
|
|
915
|
-
if (usage !== false)
|
|
916
|
-
|
|
947
|
+
if (usage !== false) {
|
|
948
|
+
try {
|
|
949
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
950
|
+
} catch {}
|
|
951
|
+
}
|
|
917
952
|
return code;
|
|
918
953
|
}
|
|
919
954
|
// ../kit/src/limit.ts
|
|
@@ -943,12 +978,9 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
943
978
|
var {Glob } = globalThis.Bun;
|
|
944
979
|
var SESSION_FILES = new Glob("*.json");
|
|
945
980
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
946
|
-
// package.json
|
|
947
|
-
var version = "0.7.1";
|
|
948
|
-
|
|
949
981
|
// src/files.ts
|
|
950
982
|
import { existsSync, readdirSync, statSync } from "fs";
|
|
951
|
-
import { join as
|
|
983
|
+
import { join as join3, relative } from "path";
|
|
952
984
|
var MAX_BYTES = 2000000;
|
|
953
985
|
var SNIFF_BYTES = 8000;
|
|
954
986
|
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
@@ -963,17 +995,17 @@ function walk(dir, found) {
|
|
|
963
995
|
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
964
996
|
continue;
|
|
965
997
|
if (entry.isDirectory())
|
|
966
|
-
walk(
|
|
998
|
+
walk(join3(dir, entry.name), found);
|
|
967
999
|
else if (entry.isFile())
|
|
968
|
-
found.push(
|
|
1000
|
+
found.push(join3(dir, entry.name));
|
|
969
1001
|
}
|
|
970
1002
|
return found;
|
|
971
1003
|
}
|
|
972
1004
|
async function listFiles(paths, cwd) {
|
|
973
1005
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
974
1006
|
if (listed.code === 0)
|
|
975
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(
|
|
976
|
-
const roots = paths.length === 0 ? [cwd] : paths.map((path) =>
|
|
1007
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join3(cwd, path))).sort();
|
|
1008
|
+
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join3(cwd, path));
|
|
977
1009
|
return roots.flatMap((root) => statSync(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
|
|
978
1010
|
}
|
|
979
1011
|
async function readText(path) {
|
|
@@ -1163,23 +1195,25 @@ function locations(text) {
|
|
|
1163
1195
|
var USAGE = `peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
|
|
1164
1196
|
|
|
1165
1197
|
peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
|
|
1166
|
-
peek --def <symbol> [path...] the whole declaration of the symbol, its comments included
|
|
1167
|
-
peek --refs <symbol> [path...] the lines naming the symbol, grouped by file
|
|
1198
|
+
peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
|
|
1199
|
+
peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
|
|
1168
1200
|
peek --outline <file>... the declarations and class members, a Markdown file's headings
|
|
1169
1201
|
peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
|
|
1170
1202
|
<output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1171
1203
|
The paths default to the files git keeps here (.gitignore holds).
|
|
1172
|
-
--refs lists at most 100 lines, the count of the rest after them (--limit <n>, --full for all).
|
|
1173
|
-
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}], --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.
|
|
1204
|
+
--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).
|
|
1205
|
+
--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.
|
|
1174
1206
|
|
|
1175
1207
|
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.`;
|
|
1176
1208
|
var REFS_LIMIT = 100;
|
|
1209
|
+
var AROUND_LIMIT = 20;
|
|
1177
1210
|
var PARENT = `..${sep}`;
|
|
1178
1211
|
var OPTIONS = {
|
|
1179
|
-
def: { type: "string", short: "d", description: "print the declaration of this symbol" },
|
|
1212
|
+
def: { type: "string", short: "d", multiple: true, description: "print the declaration of this symbol, repeat for more" },
|
|
1180
1213
|
refs: { type: "string", short: "r", description: "list the lines naming this symbol" },
|
|
1181
1214
|
outline: { type: "boolean", short: "o", description: "list the declarations of the files given" },
|
|
1182
1215
|
around: { type: "string", short: "a", description: "print the lines around the matches of this regular expression" },
|
|
1216
|
+
"defs-first": { type: "boolean", description: "with --refs, print the symbol's declarations before its lines" },
|
|
1183
1217
|
context: { type: "string", short: "C", description: "lines on each side of an --around match or a piped location (3)" },
|
|
1184
1218
|
...limitOptions(REFS_LIMIT),
|
|
1185
1219
|
json: jsonOption()
|
|
@@ -1191,13 +1225,13 @@ function cut(text) {
|
|
|
1191
1225
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1192
1226
|
}
|
|
1193
1227
|
async function readableRoot() {
|
|
1194
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1195
|
-
return
|
|
1228
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process10.cwd() });
|
|
1229
|
+
return realpathSync2(ran.code === 0 ? ran.text.trim() : process10.cwd());
|
|
1196
1230
|
}
|
|
1197
1231
|
async function isOutside(path) {
|
|
1198
1232
|
let real;
|
|
1199
1233
|
try {
|
|
1200
|
-
real =
|
|
1234
|
+
real = realpathSync2(resolve(process10.cwd(), path));
|
|
1201
1235
|
} catch {
|
|
1202
1236
|
return false;
|
|
1203
1237
|
}
|
|
@@ -1211,7 +1245,7 @@ async function checkInside(path) {
|
|
|
1211
1245
|
async function pipedSpans(text, context) {
|
|
1212
1246
|
const spans = [];
|
|
1213
1247
|
for (const [path, numbers] of locations(text)) {
|
|
1214
|
-
const source = await isOutside(path) ? undefined : await readText(resolve(
|
|
1248
|
+
const source = await isOutside(path) ? undefined : await readText(resolve(process10.cwd(), path));
|
|
1215
1249
|
if (source !== undefined)
|
|
1216
1250
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1217
1251
|
`).length, numbers, context));
|
|
@@ -1220,12 +1254,12 @@ async function pipedSpans(text, context) {
|
|
|
1220
1254
|
}
|
|
1221
1255
|
async function textOf(path) {
|
|
1222
1256
|
await checkInside(path);
|
|
1223
|
-
const text = await readText(resolve(
|
|
1257
|
+
const text = await readText(resolve(process10.cwd(), path));
|
|
1224
1258
|
if (text === undefined)
|
|
1225
1259
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1226
1260
|
return text;
|
|
1227
1261
|
}
|
|
1228
|
-
async function
|
|
1262
|
+
async function readSpans(spans) {
|
|
1229
1263
|
const texts = new Map;
|
|
1230
1264
|
const read = [];
|
|
1231
1265
|
for (const span of spans) {
|
|
@@ -1234,14 +1268,23 @@ async function printSpans(spans, json) {
|
|
|
1234
1268
|
texts.set(span.path, lines);
|
|
1235
1269
|
read.push({ ...span, lines: lines.slice(span.from - 1, span.to) });
|
|
1236
1270
|
}
|
|
1271
|
+
return read;
|
|
1272
|
+
}
|
|
1273
|
+
function formatSpans(read) {
|
|
1274
|
+
return read.map((span) => [`${span.path}:${span.from}-${span.to}`, ...span.lines.map((line, i) => `${String(span.from + i).padStart(String(span.to).length)} ${cut(line)}`)].join(`
|
|
1275
|
+
`)).join(`
|
|
1276
|
+
|
|
1277
|
+
`);
|
|
1278
|
+
}
|
|
1279
|
+
async function printSpans(spans, json, footer) {
|
|
1280
|
+
const read = await readSpans(spans);
|
|
1237
1281
|
if (json) {
|
|
1238
1282
|
printJson(read);
|
|
1239
1283
|
return;
|
|
1240
1284
|
}
|
|
1241
|
-
console.log(read
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
`));
|
|
1285
|
+
console.log(formatSpans(read));
|
|
1286
|
+
if (footer !== undefined)
|
|
1287
|
+
console.log(footer);
|
|
1245
1288
|
}
|
|
1246
1289
|
function printByFile(rows) {
|
|
1247
1290
|
const blocks = Map.groupBy(rows, (row) => row.path).entries().map(([path, ofPath]) => {
|
|
@@ -1269,8 +1312,8 @@ async function spanOf(target) {
|
|
|
1269
1312
|
async function* sources(paths) {
|
|
1270
1313
|
for (const path of paths)
|
|
1271
1314
|
await checkInside(path);
|
|
1272
|
-
for (const path of await listFiles(paths,
|
|
1273
|
-
const text = await readText(
|
|
1315
|
+
for (const path of await listFiles(paths, process10.cwd())) {
|
|
1316
|
+
const text = await readText(join4(process10.cwd(), path));
|
|
1274
1317
|
if (text !== undefined)
|
|
1275
1318
|
yield { path, text };
|
|
1276
1319
|
}
|
|
@@ -1282,10 +1325,23 @@ function regex(source) {
|
|
|
1282
1325
|
return badUsage(`--around is no valid regular expression: ${error instanceof Error ? error.message : String(error)}`);
|
|
1283
1326
|
}
|
|
1284
1327
|
}
|
|
1328
|
+
async function definitionsOf(symbols, paths) {
|
|
1329
|
+
const found = new Map(symbols.map((symbol) => [symbol, []]));
|
|
1330
|
+
for await (const { path, text } of sources(paths)) {
|
|
1331
|
+
for (const symbol of symbols)
|
|
1332
|
+
found.get(symbol)?.push(...definitions(text, path, symbol));
|
|
1333
|
+
}
|
|
1334
|
+
const missing = symbols.filter((symbol) => found.get(symbol)?.length === 0);
|
|
1335
|
+
if (missing.length > 0)
|
|
1336
|
+
fail(`no declaration of ${missing.join(", ")} found`, 1);
|
|
1337
|
+
return [...found.values()].flat();
|
|
1338
|
+
}
|
|
1285
1339
|
async function main(args) {
|
|
1286
1340
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { 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"]] });
|
|
1287
|
-
const modes = [values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1341
|
+
const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1288
1342
|
const json = values.json === true;
|
|
1343
|
+
if (values["defs-first"] === true && values.refs === undefined)
|
|
1344
|
+
badUsage("--defs-first goes with --refs");
|
|
1289
1345
|
if (modes.length > 1)
|
|
1290
1346
|
badUsage("give one of --def, --refs, --outline and --around");
|
|
1291
1347
|
const isPiped = modes.length === 0 && positionals.length === 0 && isStdinPiped();
|
|
@@ -1298,12 +1354,8 @@ async function main(args) {
|
|
|
1298
1354
|
await printSpans(spans, json);
|
|
1299
1355
|
return 0;
|
|
1300
1356
|
}
|
|
1301
|
-
if (values.def !== undefined) {
|
|
1302
|
-
const spans =
|
|
1303
|
-
for await (const { path, text } of sources(positionals))
|
|
1304
|
-
spans.push(...definitions(text, path, values.def));
|
|
1305
|
-
if (spans.length === 0)
|
|
1306
|
-
fail(`no declaration of ${values.def} found`, 1);
|
|
1357
|
+
if (values.def !== undefined && values.def.length > 0) {
|
|
1358
|
+
const spans = await definitionsOf(values.def, positionals);
|
|
1307
1359
|
await printSpans(spans, json);
|
|
1308
1360
|
return 0;
|
|
1309
1361
|
}
|
|
@@ -1317,9 +1369,13 @@ async function main(args) {
|
|
|
1317
1369
|
if (rows.length === 0)
|
|
1318
1370
|
fail(`nothing names ${values.refs}`, 1);
|
|
1319
1371
|
const { shown, footer } = capped(rows, limitOf({ ...values, json }, REFS_LIMIT));
|
|
1372
|
+
const defs = values["defs-first"] === true ? await readSpans(await definitionsOf([values.refs], positionals)) : [];
|
|
1320
1373
|
if (json) {
|
|
1321
|
-
printJson(shown);
|
|
1374
|
+
printJson(values["defs-first"] === true ? { definitions: defs, references: shown } : shown);
|
|
1322
1375
|
} else {
|
|
1376
|
+
if (defs.length > 0)
|
|
1377
|
+
console.log(`${formatSpans(defs)}
|
|
1378
|
+
`);
|
|
1323
1379
|
printByFile(shown.map((row) => ({ ...row, text: cut(row.text) })));
|
|
1324
1380
|
if (footer !== undefined)
|
|
1325
1381
|
console.log(footer);
|
|
@@ -1346,7 +1402,8 @@ async function main(args) {
|
|
|
1346
1402
|
spans.push(...around(text, path, pattern, context));
|
|
1347
1403
|
if (spans.length === 0)
|
|
1348
1404
|
fail(`no line matches ${values.around}`, 1);
|
|
1349
|
-
|
|
1405
|
+
const { shown, footer } = capped(spans, limitOf({ ...values, json }, AROUND_LIMIT));
|
|
1406
|
+
await printSpans(shown, json, footer);
|
|
1350
1407
|
return 0;
|
|
1351
1408
|
}
|
|
1352
1409
|
if (positionals.length === 0)
|
|
@@ -1354,4 +1411,4 @@ async function main(args) {
|
|
|
1354
1411
|
await printSpans(await Promise.all(positionals.map(spanOf)), json);
|
|
1355
1412
|
return 0;
|
|
1356
1413
|
}
|
|
1357
|
-
|
|
1414
|
+
process10.exitCode = await runMain({ name: "peek", run: main });
|
package/dist/todo-scan.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/todo-scan.ts
|
|
5
|
-
import { join as
|
|
6
|
-
import
|
|
7
|
-
|
|
5
|
+
import { join as join4 } from "path";
|
|
6
|
+
import process10 from "process";
|
|
8
7
|
// ../kit/src/args.ts
|
|
9
|
-
import
|
|
8
|
+
import process5 from "process";
|
|
10
9
|
import { parseArgs } from "util";
|
|
11
10
|
|
|
12
11
|
// ../kit/src/format.ts
|
|
13
|
-
import
|
|
12
|
+
import process3 from "process";
|
|
14
13
|
|
|
15
14
|
// ../kit/src/style.ts
|
|
16
|
-
import
|
|
15
|
+
import process2 from "process";
|
|
17
16
|
|
|
18
17
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
19
18
|
function x(s) {
|
|
@@ -283,20 +282,20 @@ var MARKS = {
|
|
|
283
282
|
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
284
283
|
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
285
284
|
};
|
|
286
|
-
function takesControlCodes(stream, env =
|
|
285
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
287
286
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
288
287
|
}
|
|
289
|
-
function paint(stream, env =
|
|
288
|
+
function paint(stream, env = process2.env) {
|
|
290
289
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
291
290
|
}
|
|
292
|
-
function marked(mark, text, stream, detail, env =
|
|
291
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
293
292
|
const colors = paint(stream, env);
|
|
294
293
|
const { symbol, word, paint: tint } = MARKS[mark];
|
|
295
294
|
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
296
295
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
297
296
|
}
|
|
298
297
|
function warn(text, detail) {
|
|
299
|
-
console.error(marked("warn", text,
|
|
298
|
+
console.error(marked("warn", text, process2.stderr, detail));
|
|
300
299
|
}
|
|
301
300
|
var STATUSES = {
|
|
302
301
|
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
@@ -328,7 +327,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
328
327
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
329
328
|
}
|
|
330
329
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
331
|
-
const colors = paint(
|
|
330
|
+
const colors = paint(process3.stdout);
|
|
332
331
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
333
332
|
const width = widths[index] ?? 0;
|
|
334
333
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -360,24 +359,30 @@ function printJson(value) {
|
|
|
360
359
|
}
|
|
361
360
|
|
|
362
361
|
// ../kit/src/help.ts
|
|
363
|
-
import
|
|
362
|
+
import process4 from "process";
|
|
364
363
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
365
364
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
366
365
|
var FULL_STOP = /\.$/;
|
|
367
|
-
function usageLine(usage, colors = paint(
|
|
366
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
368
367
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
369
368
|
}
|
|
370
|
-
function helpText(usage, options, colors = paint(
|
|
371
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
369
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
370
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
372
371
|
`);
|
|
373
372
|
}
|
|
374
|
-
function
|
|
373
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
374
|
+
if (exits.length === 0)
|
|
375
|
+
return [];
|
|
376
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
377
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
378
|
+
}
|
|
379
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
375
380
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
376
381
|
}
|
|
377
|
-
function wantsHelpJson(env =
|
|
382
|
+
function wantsHelpJson(env = process4.env) {
|
|
378
383
|
return env.KIT_HELP === "json";
|
|
379
384
|
}
|
|
380
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
385
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
381
386
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
382
387
|
`);
|
|
383
388
|
const first = lines[0];
|
|
@@ -388,15 +393,17 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
388
393
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
389
394
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
390
395
|
...replaces === undefined ? {} : { replaces },
|
|
391
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
396
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
397
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
398
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
392
399
|
};
|
|
393
400
|
}
|
|
394
|
-
function exampleRows(examples, colors = paint(
|
|
401
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
395
402
|
if (examples.length === 0)
|
|
396
403
|
return [];
|
|
397
404
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
398
405
|
}
|
|
399
|
-
function optionRows(options, colors = paint(
|
|
406
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
400
407
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
401
408
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
402
409
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -503,7 +510,7 @@ var OUTPUT_OPTIONS = {
|
|
|
503
510
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
504
511
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
505
512
|
};
|
|
506
|
-
function applyOutput(color, plain, env =
|
|
513
|
+
function applyOutput(color, plain, env = process5.env) {
|
|
507
514
|
const when = plain === true ? "never" : color ?? "auto";
|
|
508
515
|
if (when === "auto")
|
|
509
516
|
return;
|
|
@@ -526,7 +533,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
526
533
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
527
534
|
let parsed;
|
|
528
535
|
try {
|
|
529
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
536
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
530
537
|
} catch (error) {
|
|
531
538
|
const message = parseError(error);
|
|
532
539
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -534,7 +541,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
534
541
|
const values = parsed.values;
|
|
535
542
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
536
543
|
if (values.help === true) {
|
|
537
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
544
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
538
545
|
throw new HelpShown;
|
|
539
546
|
}
|
|
540
547
|
checkChoices(parsed.values, all);
|
|
@@ -576,6 +583,18 @@ function listed(options, allowNegative) {
|
|
|
576
583
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
577
584
|
}));
|
|
578
585
|
}
|
|
586
|
+
function withAliases(args, options) {
|
|
587
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
588
|
+
if (named.size === 0)
|
|
589
|
+
return args;
|
|
590
|
+
const separator = args.indexOf("--");
|
|
591
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
592
|
+
return [...own.map((arg) => {
|
|
593
|
+
const at = arg.indexOf("=");
|
|
594
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
595
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
596
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
597
|
+
}
|
|
579
598
|
function withBare(args, options) {
|
|
580
599
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
581
600
|
if (bare.size === 0)
|
|
@@ -662,7 +681,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
662
681
|
}
|
|
663
682
|
// ../kit/src/process.ts
|
|
664
683
|
import { constants } from "os";
|
|
665
|
-
import
|
|
684
|
+
import process6 from "process";
|
|
666
685
|
var KILL_GRACE_MS = 2000;
|
|
667
686
|
function exitCodeOf(code, signal) {
|
|
668
687
|
if (code !== null)
|
|
@@ -682,7 +701,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
682
701
|
return;
|
|
683
702
|
try {
|
|
684
703
|
if (grouped)
|
|
685
|
-
|
|
704
|
+
process6.kill(-proc.pid, killing);
|
|
686
705
|
else
|
|
687
706
|
proc.kill(killing);
|
|
688
707
|
} catch {}
|
|
@@ -756,13 +775,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
756
775
|
var RESET_STYLE = `${ESC}[0m`;
|
|
757
776
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
758
777
|
// ../kit/src/cli.ts
|
|
759
|
-
import
|
|
778
|
+
import { readFileSync, realpathSync } from "fs";
|
|
779
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
780
|
+
import process8 from "process";
|
|
760
781
|
|
|
761
782
|
// ../kit/src/usage.ts
|
|
762
783
|
import { appendFileSync, mkdirSync } from "fs";
|
|
763
784
|
import { homedir } from "os";
|
|
764
785
|
import { dirname, isAbsolute, join } from "path";
|
|
765
|
-
import
|
|
786
|
+
import process7 from "process";
|
|
766
787
|
|
|
767
788
|
// ../kit/src/logs.ts
|
|
768
789
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -776,14 +797,14 @@ var usageError;
|
|
|
776
797
|
function noteUsageError(message) {
|
|
777
798
|
usageError = message;
|
|
778
799
|
}
|
|
779
|
-
function stateHome(env =
|
|
800
|
+
function stateHome(env = process7.env) {
|
|
780
801
|
const dir = env.XDG_STATE_HOME;
|
|
781
802
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
782
803
|
}
|
|
783
|
-
function usagePath(env =
|
|
804
|
+
function usagePath(env = process7.env) {
|
|
784
805
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
785
806
|
}
|
|
786
|
-
function usageRecorded(env =
|
|
807
|
+
function usageRecorded(env = process7.env) {
|
|
787
808
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
788
809
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
789
810
|
}
|
|
@@ -797,7 +818,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
797
818
|
usageError = undefined;
|
|
798
819
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
799
820
|
}
|
|
800
|
-
function recordUsage(entry, env =
|
|
821
|
+
function recordUsage(entry, env = process7.env) {
|
|
801
822
|
if (!usageRecorded(env))
|
|
802
823
|
return;
|
|
803
824
|
try {
|
|
@@ -815,8 +836,8 @@ var LEVEL_OPTIONS = {
|
|
|
815
836
|
};
|
|
816
837
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
817
838
|
function printError(prefix, message, hint, cause) {
|
|
818
|
-
const colors = paint(
|
|
819
|
-
const styled = takesControlCodes(
|
|
839
|
+
const colors = paint(process8.stderr);
|
|
840
|
+
const styled = takesControlCodes(process8.stderr);
|
|
820
841
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
821
842
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
822
843
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -898,11 +919,22 @@ async function printCandidates(found) {
|
|
|
898
919
|
console.log(line);
|
|
899
920
|
return 0;
|
|
900
921
|
}
|
|
901
|
-
|
|
922
|
+
function packageVersion(entry = Bun.main) {
|
|
923
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
924
|
+
try {
|
|
925
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
926
|
+
if (typeof version === "string")
|
|
927
|
+
return version;
|
|
928
|
+
} catch {}
|
|
929
|
+
if (dirname2(dir) === dir)
|
|
930
|
+
return "0.0.0";
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
async function runMain({ name, version, run, redact, usage }, argv = process8.argv.slice(2)) {
|
|
902
934
|
if (argv[0] === COMPLETE)
|
|
903
935
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
904
936
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
905
|
-
console.log(version);
|
|
937
|
+
console.log(version ?? packageVersion());
|
|
906
938
|
return 0;
|
|
907
939
|
}
|
|
908
940
|
let code;
|
|
@@ -911,8 +943,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process7.ar
|
|
|
911
943
|
} catch (error) {
|
|
912
944
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
913
945
|
}
|
|
914
|
-
if (usage !== false)
|
|
915
|
-
|
|
946
|
+
if (usage !== false) {
|
|
947
|
+
try {
|
|
948
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
949
|
+
} catch {}
|
|
950
|
+
}
|
|
916
951
|
return code;
|
|
917
952
|
}
|
|
918
953
|
// ../kit/src/limit.ts
|
|
@@ -942,12 +977,9 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
942
977
|
var {Glob } = globalThis.Bun;
|
|
943
978
|
var SESSION_FILES = new Glob("*.json");
|
|
944
979
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
945
|
-
// package.json
|
|
946
|
-
var version = "0.7.1";
|
|
947
|
-
|
|
948
980
|
// src/files.ts
|
|
949
981
|
import { existsSync, readdirSync, statSync } from "fs";
|
|
950
|
-
import { join as
|
|
982
|
+
import { join as join3, relative } from "path";
|
|
951
983
|
var MAX_BYTES = 2000000;
|
|
952
984
|
var SNIFF_BYTES = 8000;
|
|
953
985
|
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
@@ -962,17 +994,17 @@ function walk(dir, found) {
|
|
|
962
994
|
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
963
995
|
continue;
|
|
964
996
|
if (entry.isDirectory())
|
|
965
|
-
walk(
|
|
997
|
+
walk(join3(dir, entry.name), found);
|
|
966
998
|
else if (entry.isFile())
|
|
967
|
-
found.push(
|
|
999
|
+
found.push(join3(dir, entry.name));
|
|
968
1000
|
}
|
|
969
1001
|
return found;
|
|
970
1002
|
}
|
|
971
1003
|
async function listFiles(paths, cwd) {
|
|
972
1004
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
973
1005
|
if (listed.code === 0)
|
|
974
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(
|
|
975
|
-
const roots = paths.length === 0 ? [cwd] : paths.map((path) =>
|
|
1006
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join3(cwd, path))).sort();
|
|
1007
|
+
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join3(cwd, path));
|
|
976
1008
|
return roots.flatMap((root) => statSync(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
|
|
977
1009
|
}
|
|
978
1010
|
async function readText(path) {
|
|
@@ -1076,11 +1108,11 @@ function printLines(lines, footer) {
|
|
|
1076
1108
|
}
|
|
1077
1109
|
async function main(args) {
|
|
1078
1110
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { 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"]] });
|
|
1079
|
-
const cwd =
|
|
1111
|
+
const cwd = process10.cwd();
|
|
1080
1112
|
const limit = limitOf(values, LIST_LIMIT);
|
|
1081
1113
|
const marks = [];
|
|
1082
1114
|
for (const path of await listFiles(positionals, cwd)) {
|
|
1083
|
-
const text = await readText(
|
|
1115
|
+
const text = await readText(join4(cwd, path));
|
|
1084
1116
|
if (text !== undefined)
|
|
1085
1117
|
marks.push(...marksIn(text, path));
|
|
1086
1118
|
}
|
|
@@ -1105,4 +1137,4 @@ async function main(args) {
|
|
|
1105
1137
|
return 1;
|
|
1106
1138
|
return failed.size > 0 ? 2 : 0;
|
|
1107
1139
|
}
|
|
1108
|
-
|
|
1140
|
+
process10.exitCode = await runMain({ name: "todo-scan", run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-code",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "peek, todo-scan and hotspots: source read by spans, symbols and outlines in one call, the TODO and issue-reference comments of a repository with stale ones flagged, and the files ranked by complexity times git churn.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|