@kaynooo/cli-code 0.9.0 → 0.10.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/dist/cli.js +283 -86
- package/dist/hotspots-cli.js +270 -73
- package/dist/peek-cli.js +264 -77
- package/dist/todo-scan-cli.js +259 -72
- package/package.json +1 -1
package/dist/hotspots-cli.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/hotspots-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process14 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process8 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process6 from "process";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/style.ts
|
|
14
|
-
import
|
|
14
|
+
import process5 from "process";
|
|
15
15
|
|
|
16
16
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
17
|
function x(s) {
|
|
@@ -274,36 +274,222 @@ function le(i = {}) {
|
|
|
274
274
|
}
|
|
275
275
|
var t = le();
|
|
276
276
|
|
|
277
|
-
// ../kit/src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
// ../kit/src/theme.ts
|
|
278
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
279
|
+
import { homedir as homedir2 } from "os";
|
|
280
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
281
|
+
import process4 from "process";
|
|
282
|
+
|
|
283
|
+
// ../kit/src/config.ts
|
|
284
|
+
import { existsSync } from "fs";
|
|
285
|
+
import { dirname, join, resolve } from "path";
|
|
286
|
+
import process2 from "process";
|
|
287
|
+
function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
288
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
289
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
290
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
291
|
+
if (found !== undefined)
|
|
292
|
+
return found;
|
|
293
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ../kit/src/user-config.ts
|
|
299
|
+
import { homedir } from "os";
|
|
300
|
+
import { join as join2 } from "path";
|
|
301
|
+
import process3 from "process";
|
|
302
|
+
function configBase(where = {}) {
|
|
303
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
304
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
305
|
+
}
|
|
306
|
+
function userConfigPath(bin, where = {}) {
|
|
307
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ../kit/src/theme.ts
|
|
311
|
+
var DEFAULT = {
|
|
312
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
313
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
314
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
315
|
+
bins: {}
|
|
316
|
+
};
|
|
317
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
318
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
319
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
320
|
+
var PRESETS = {
|
|
321
|
+
default: {},
|
|
322
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
323
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
324
|
+
ascii: { glyphs: ASCII }
|
|
283
325
|
};
|
|
284
|
-
|
|
326
|
+
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
327
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
328
|
+
var CONTROL = /\p{Cc}/u;
|
|
329
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
330
|
+
var SPACES = /\s+/;
|
|
331
|
+
function isColorSpec(spec) {
|
|
332
|
+
if (typeof spec === "number")
|
|
333
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
334
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
335
|
+
}
|
|
336
|
+
function tinted(colors, spec) {
|
|
337
|
+
if (typeof spec === "number")
|
|
338
|
+
return colors.ansi256(spec);
|
|
339
|
+
return spec.trim().split(SPACES).reduce((chain, token) => HEX.test(token) ? chain.hex(token) : chain[token] ?? chain, colors);
|
|
340
|
+
}
|
|
341
|
+
function isRecord(value) {
|
|
342
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
343
|
+
}
|
|
344
|
+
function readThemeFile(path, warn) {
|
|
345
|
+
try {
|
|
346
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
347
|
+
if (stat === undefined)
|
|
348
|
+
return;
|
|
349
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
350
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
354
|
+
if (isRecord(parsed))
|
|
355
|
+
return parsed;
|
|
356
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
359
|
+
}
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
function applyPreset(theme, name, warn, where) {
|
|
363
|
+
if (name === undefined)
|
|
364
|
+
return;
|
|
365
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
366
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const preset = PRESETS[name];
|
|
370
|
+
Object.assign(theme.colors, preset.colors);
|
|
371
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
372
|
+
if (preset.accents !== undefined)
|
|
373
|
+
theme.accents = [...preset.accents];
|
|
374
|
+
return name;
|
|
375
|
+
}
|
|
376
|
+
function applyFile(theme, file, where, warn) {
|
|
377
|
+
if (isRecord(file.colors)) {
|
|
378
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
379
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
380
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
381
|
+
else if (!isColorSpec(value))
|
|
382
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
383
|
+
else
|
|
384
|
+
theme.colors[key] = value;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (isRecord(file.glyphs)) {
|
|
388
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
389
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
390
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
391
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
392
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
393
|
+
else
|
|
394
|
+
theme.glyphs[key] = value;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
398
|
+
theme.accents = [...file.accents];
|
|
399
|
+
else if (file.accents !== undefined)
|
|
400
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
401
|
+
if (isRecord(file.bins)) {
|
|
402
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
403
|
+
if (isColorSpec(value))
|
|
404
|
+
theme.bins[bin] = value;
|
|
405
|
+
else
|
|
406
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function endsWalk(home) {
|
|
411
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
412
|
+
}
|
|
413
|
+
var warned = new Set;
|
|
414
|
+
function warnOnce(message) {
|
|
415
|
+
if (warned.has(message))
|
|
416
|
+
return;
|
|
417
|
+
warned.add(message);
|
|
418
|
+
console.error(`warning: theme ${message}`);
|
|
419
|
+
}
|
|
420
|
+
function isPath(chosen) {
|
|
421
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
422
|
+
}
|
|
423
|
+
function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
424
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
425
|
+
const sources = [];
|
|
426
|
+
const chosen = env.KIT_THEME ?? "";
|
|
427
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
428
|
+
if (isPath(chosen))
|
|
429
|
+
wanted.push(resolve2(from, chosen));
|
|
430
|
+
const files = [];
|
|
431
|
+
for (const path of wanted) {
|
|
432
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
433
|
+
if (path !== undefined && file !== undefined)
|
|
434
|
+
files.push({ path, file });
|
|
435
|
+
}
|
|
436
|
+
let preset = "default";
|
|
437
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
438
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
439
|
+
} else {
|
|
440
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
441
|
+
if (named !== undefined)
|
|
442
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
443
|
+
}
|
|
444
|
+
for (const { path, file } of files) {
|
|
445
|
+
applyFile(theme, file, path, warn);
|
|
446
|
+
sources.push(path);
|
|
447
|
+
}
|
|
448
|
+
return { theme, sources, preset };
|
|
449
|
+
}
|
|
450
|
+
var current;
|
|
451
|
+
var currentKey = "";
|
|
452
|
+
function activeTheme() {
|
|
453
|
+
const key = `${process4.cwd()}\x00${process4.env.KIT_THEME ?? ""}\x00${process4.env.XDG_CONFIG_HOME ?? ""}`;
|
|
454
|
+
if (current === undefined || key !== currentKey) {
|
|
455
|
+
current = loadTheme();
|
|
456
|
+
currentKey = key;
|
|
457
|
+
}
|
|
458
|
+
return current;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ../kit/src/style.ts
|
|
462
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
463
|
+
function takesControlCodes(stream, env = process5.env) {
|
|
285
464
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
286
465
|
}
|
|
287
|
-
function paint(stream, env =
|
|
466
|
+
function paint(stream, env = process5.env) {
|
|
288
467
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
289
468
|
}
|
|
290
|
-
function marked(mark, text, stream, detail, env =
|
|
469
|
+
function marked(mark, text, stream, detail, env = process5.env) {
|
|
291
470
|
const colors = paint(stream, env);
|
|
292
|
-
|
|
293
|
-
|
|
471
|
+
let head = MARK_WORDS[mark];
|
|
472
|
+
if (takesControlCodes(stream, env)) {
|
|
473
|
+
const { theme } = activeTheme();
|
|
474
|
+
head = tinted(colors.bold, theme.colors[mark])(theme.glyphs[mark]);
|
|
475
|
+
}
|
|
294
476
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
295
477
|
}
|
|
296
478
|
function warn(text, detail) {
|
|
297
|
-
console.error(marked("warn", text,
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
479
|
+
console.error(marked("warn", text, process5.stderr, detail));
|
|
480
|
+
}
|
|
481
|
+
function role(name, stream, env = process5.env) {
|
|
482
|
+
const colors = paint(stream, env);
|
|
483
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
|
|
484
|
+
}
|
|
485
|
+
var STATUS_WORDS = {
|
|
486
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
487
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
488
|
+
running: ["running", "in_progress", "started"],
|
|
489
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
490
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
305
491
|
};
|
|
306
|
-
var STATUS_OF = new Map(Object.entries(
|
|
492
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
307
493
|
|
|
308
494
|
// ../kit/src/format.ts
|
|
309
495
|
function upTo(text, separator) {
|
|
@@ -318,7 +504,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
318
504
|
function textWidth(text) {
|
|
319
505
|
return Bun.stringWidth(text);
|
|
320
506
|
}
|
|
321
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
507
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process6.stdout } = {}) {
|
|
322
508
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
323
509
|
const widths = [];
|
|
324
510
|
for (const row of cells) {
|
|
@@ -326,7 +512,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
326
512
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
327
513
|
}
|
|
328
514
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
329
|
-
const colors = paint(
|
|
515
|
+
const colors = paint(stream);
|
|
330
516
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
331
517
|
const width = widths[index] ?? 0;
|
|
332
518
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -334,7 +520,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
334
520
|
return `${gap}${cell}`;
|
|
335
521
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
336
522
|
}).join(" ").trimEnd());
|
|
337
|
-
|
|
523
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
524
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
338
525
|
`);
|
|
339
526
|
}
|
|
340
527
|
function narrow(rows, widths, limit) {
|
|
@@ -358,27 +545,27 @@ function printJson(value) {
|
|
|
358
545
|
}
|
|
359
546
|
|
|
360
547
|
// ../kit/src/help.ts
|
|
361
|
-
import
|
|
548
|
+
import process7 from "process";
|
|
362
549
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
363
550
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
364
551
|
var FULL_STOP = /\.$/;
|
|
365
|
-
function usageLine(usage, colors = paint(
|
|
552
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
366
553
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
367
554
|
}
|
|
368
|
-
function helpText(usage, options, colors = paint(
|
|
555
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
369
556
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
370
557
|
`);
|
|
371
558
|
}
|
|
372
|
-
function exitRows(exits, colors = paint(
|
|
559
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
373
560
|
if (exits.length === 0)
|
|
374
561
|
return [];
|
|
375
562
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
376
563
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
377
564
|
}
|
|
378
|
-
function replacesRows(replaces, colors = paint(
|
|
565
|
+
function replacesRows(replaces, colors = paint(process7.stdout)) {
|
|
379
566
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
380
567
|
}
|
|
381
|
-
function wantsHelpJson(env =
|
|
568
|
+
function wantsHelpJson(env = process7.env) {
|
|
382
569
|
return env.KIT_HELP === "json";
|
|
383
570
|
}
|
|
384
571
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -397,12 +584,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
397
584
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
398
585
|
};
|
|
399
586
|
}
|
|
400
|
-
function exampleRows(examples, colors = paint(
|
|
587
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
401
588
|
if (examples.length === 0)
|
|
402
589
|
return [];
|
|
403
590
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
404
591
|
}
|
|
405
|
-
function optionRows(options, colors = paint(
|
|
592
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
406
593
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
407
594
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
408
595
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -509,7 +696,7 @@ var OUTPUT_OPTIONS = {
|
|
|
509
696
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
510
697
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
511
698
|
};
|
|
512
|
-
function applyOutput(color, plain, env =
|
|
699
|
+
function applyOutput(color, plain, env = process8.env) {
|
|
513
700
|
const when = plain === true ? "never" : color ?? "auto";
|
|
514
701
|
if (when === "auto")
|
|
515
702
|
return;
|
|
@@ -680,7 +867,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
680
867
|
}
|
|
681
868
|
// ../kit/src/process.ts
|
|
682
869
|
import { constants } from "os";
|
|
683
|
-
import
|
|
870
|
+
import process9 from "process";
|
|
684
871
|
var KILL_GRACE_MS = 2000;
|
|
685
872
|
function exitCodeOf(code, signal) {
|
|
686
873
|
if (code !== null)
|
|
@@ -700,7 +887,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
700
887
|
return;
|
|
701
888
|
try {
|
|
702
889
|
if (grouped)
|
|
703
|
-
|
|
890
|
+
process9.kill(-proc.pid, killing);
|
|
704
891
|
else
|
|
705
892
|
proc.kill(killing);
|
|
706
893
|
} catch {}
|
|
@@ -774,15 +961,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
774
961
|
var RESET_STYLE = `${ESC}[0m`;
|
|
775
962
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
776
963
|
// ../kit/src/cli.ts
|
|
777
|
-
import { readFileSync, realpathSync } from "fs";
|
|
778
|
-
import { dirname as
|
|
779
|
-
import
|
|
964
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
965
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
966
|
+
import process11 from "process";
|
|
780
967
|
|
|
781
968
|
// ../kit/src/usage.ts
|
|
782
969
|
import { appendFileSync, mkdirSync } from "fs";
|
|
783
|
-
import { homedir } from "os";
|
|
784
|
-
import { dirname, isAbsolute, join } from "path";
|
|
785
|
-
import
|
|
970
|
+
import { homedir as homedir3 } from "os";
|
|
971
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
972
|
+
import process10 from "process";
|
|
786
973
|
|
|
787
974
|
// ../kit/src/logs.ts
|
|
788
975
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -796,14 +983,14 @@ var usageError;
|
|
|
796
983
|
function noteUsageError(message) {
|
|
797
984
|
usageError = message;
|
|
798
985
|
}
|
|
799
|
-
function stateHome(env =
|
|
986
|
+
function stateHome(env = process10.env) {
|
|
800
987
|
const dir = env.XDG_STATE_HOME;
|
|
801
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
988
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
802
989
|
}
|
|
803
|
-
function usagePath(env =
|
|
804
|
-
return
|
|
990
|
+
function usagePath(env = process10.env) {
|
|
991
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
805
992
|
}
|
|
806
|
-
function usageRecorded(env =
|
|
993
|
+
function usageRecorded(env = process10.env) {
|
|
807
994
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
808
995
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
809
996
|
}
|
|
@@ -817,12 +1004,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
817
1004
|
usageError = undefined;
|
|
818
1005
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
819
1006
|
}
|
|
820
|
-
function recordUsage(entry, env =
|
|
1007
|
+
function recordUsage(entry, env = process10.env) {
|
|
821
1008
|
if (!usageRecorded(env))
|
|
822
1009
|
return;
|
|
823
1010
|
try {
|
|
824
1011
|
const path = usagePath(env);
|
|
825
|
-
mkdirSync(
|
|
1012
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
826
1013
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
827
1014
|
`, { mode: 384 });
|
|
828
1015
|
} catch {}
|
|
@@ -908,8 +1095,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
908
1095
|
`);
|
|
909
1096
|
}
|
|
910
1097
|
function printError(prefix, message, hint, cause) {
|
|
911
|
-
const colors = paint(
|
|
912
|
-
const styled = takesControlCodes(
|
|
1098
|
+
const colors = paint(process11.stderr);
|
|
1099
|
+
const styled = takesControlCodes(process11.stderr);
|
|
913
1100
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
914
1101
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
915
1102
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -952,11 +1139,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
952
1139
|
}
|
|
953
1140
|
}
|
|
954
1141
|
if (name === undefined && level.path.length > 1) {
|
|
955
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1142
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
|
|
956
1143
|
return 2;
|
|
957
1144
|
}
|
|
958
1145
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
959
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1146
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
|
|
960
1147
|
return 0;
|
|
961
1148
|
}
|
|
962
1149
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1073,17 +1260,17 @@ async function printCandidates(found) {
|
|
|
1073
1260
|
return 0;
|
|
1074
1261
|
}
|
|
1075
1262
|
function packageVersion(entry = Bun.main) {
|
|
1076
|
-
for (let dir =
|
|
1263
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1077
1264
|
try {
|
|
1078
|
-
const { version } = JSON.parse(
|
|
1265
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1079
1266
|
if (typeof version === "string")
|
|
1080
1267
|
return version;
|
|
1081
1268
|
} catch {}
|
|
1082
|
-
if (
|
|
1269
|
+
if (dirname3(dir) === dir)
|
|
1083
1270
|
return "0.0.0";
|
|
1084
1271
|
}
|
|
1085
1272
|
}
|
|
1086
|
-
async function runCli(cli, argv =
|
|
1273
|
+
async function runCli(cli, argv = process11.argv.slice(2)) {
|
|
1087
1274
|
const version = cli.version ?? packageVersion();
|
|
1088
1275
|
if (argv[0] === COMPLETE)
|
|
1089
1276
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1110,7 +1297,7 @@ function commandPath(scope, argv) {
|
|
|
1110
1297
|
}
|
|
1111
1298
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1112
1299
|
}
|
|
1113
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1300
|
+
async function runMain({ name, version, run, redact, usage }, argv = process11.argv.slice(2)) {
|
|
1114
1301
|
if (argv[0] === COMPLETE)
|
|
1115
1302
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1116
1303
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1158,8 +1345,8 @@ var {Glob } = globalThis.Bun;
|
|
|
1158
1345
|
var SESSION_FILES = new Glob("*.json");
|
|
1159
1346
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1160
1347
|
// src/hotspots.ts
|
|
1161
|
-
import { join as
|
|
1162
|
-
import
|
|
1348
|
+
import { join as join7 } from "path";
|
|
1349
|
+
import process13 from "process";
|
|
1163
1350
|
|
|
1164
1351
|
// src/churn.ts
|
|
1165
1352
|
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)$/;
|
|
@@ -1200,8 +1387,8 @@ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
|
|
|
1200
1387
|
}
|
|
1201
1388
|
|
|
1202
1389
|
// src/files.ts
|
|
1203
|
-
import { existsSync, readdirSync, statSync } from "fs";
|
|
1204
|
-
import { join as
|
|
1390
|
+
import { existsSync as existsSync3, readdirSync, statSync as statSync2 } from "fs";
|
|
1391
|
+
import { join as join6, relative } from "path";
|
|
1205
1392
|
var MAX_BYTES = 2000000;
|
|
1206
1393
|
var SNIFF_BYTES = 8000;
|
|
1207
1394
|
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
@@ -1216,18 +1403,18 @@ function walk(dir, found) {
|
|
|
1216
1403
|
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1217
1404
|
continue;
|
|
1218
1405
|
if (entry.isDirectory())
|
|
1219
|
-
walk(
|
|
1406
|
+
walk(join6(dir, entry.name), found);
|
|
1220
1407
|
else if (entry.isFile())
|
|
1221
|
-
found.push(
|
|
1408
|
+
found.push(join6(dir, entry.name));
|
|
1222
1409
|
}
|
|
1223
1410
|
return found;
|
|
1224
1411
|
}
|
|
1225
1412
|
async function listFiles(paths, cwd) {
|
|
1226
1413
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1227
1414
|
if (listed.code === 0)
|
|
1228
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1229
|
-
const roots = paths.length === 0 ? [cwd] : paths.map((path) =>
|
|
1230
|
-
return roots.flatMap((root) =>
|
|
1415
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync3(join6(cwd, path))).sort();
|
|
1416
|
+
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1417
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
|
|
1231
1418
|
}
|
|
1232
1419
|
async function readText(path) {
|
|
1233
1420
|
const file = Bun.file(path);
|
|
@@ -1310,12 +1497,14 @@ var OPTIONS = {
|
|
|
1310
1497
|
all: { type: "boolean", short: "a", description: "keep test files and generated files" },
|
|
1311
1498
|
json: jsonOption("[{rank, path, score, churn, recent, complexity, worst, lines}], never cut unless --limit is given")
|
|
1312
1499
|
};
|
|
1500
|
+
var HOT = 0.66;
|
|
1501
|
+
var WARM = 0.33;
|
|
1313
1502
|
async function hotspots(args) {
|
|
1314
1503
|
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'] });
|
|
1315
1504
|
if (positionals.length > 1)
|
|
1316
1505
|
badUsage("give one folder");
|
|
1317
1506
|
const count = limitOf(values, DEFAULT_COUNT);
|
|
1318
|
-
const cwd =
|
|
1507
|
+
const cwd = process13.cwd();
|
|
1319
1508
|
const bulk = Number(values.bulk ?? DEFAULT_BULK);
|
|
1320
1509
|
if (!Number.isInteger(bulk) || bulk < 1)
|
|
1321
1510
|
badUsage(`--bulk takes a number of files, not ${values.bulk}`);
|
|
@@ -1328,7 +1517,7 @@ async function hotspots(args) {
|
|
|
1328
1517
|
const touched = churn.get(path);
|
|
1329
1518
|
if (touched === undefined || values.all !== true && !isCandidate(path))
|
|
1330
1519
|
continue;
|
|
1331
|
-
const text = await readText(
|
|
1520
|
+
const text = await readText(join7(cwd, path));
|
|
1332
1521
|
if (text === undefined || values.all !== true && isGenerated(text))
|
|
1333
1522
|
continue;
|
|
1334
1523
|
const complexity = complexityOf(text);
|
|
@@ -1346,11 +1535,19 @@ async function hotspots(args) {
|
|
|
1346
1535
|
printJson(shown);
|
|
1347
1536
|
return 0;
|
|
1348
1537
|
}
|
|
1349
|
-
|
|
1538
|
+
const colors = paint(process13.stdout);
|
|
1539
|
+
const path = role("path", process13.stdout);
|
|
1540
|
+
const top = shown.reduce((highest, row) => Math.max(highest, row.score), 0);
|
|
1541
|
+
const heat = (score, text) => {
|
|
1542
|
+
if (top > 0 && score >= top * HOT)
|
|
1543
|
+
return colors.red(text);
|
|
1544
|
+
return top > 0 && score >= top * WARM ? colors.yellow(text) : text;
|
|
1545
|
+
};
|
|
1546
|
+
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), path(row.path), row.worst === undefined ? "" : `${row.worst.name} (${row.worst.complexity}, line ${row.worst.line})`])], { header: true, align: ["right", "right", "right", "right", "right", "right", "left", "left"] }));
|
|
1350
1547
|
if (footer !== undefined)
|
|
1351
1548
|
console.log(footer);
|
|
1352
1549
|
return 0;
|
|
1353
1550
|
}
|
|
1354
1551
|
|
|
1355
1552
|
// src/hotspots-cli.ts
|
|
1356
|
-
|
|
1553
|
+
process14.exitCode = await runMain({ name: "hotspots", run: hotspots });
|