@kaynooo/cli-workspace 0.10.2 → 0.11.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/audit-cli.js +203 -44
- package/dist/cli.js +315 -97
- package/dist/repos-cli.js +75 -41
- package/dist/sweep-cli.js +134 -41
- package/package.json +2 -2
package/dist/repos-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/repos-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -492,7 +492,7 @@ function printJson(value) {
|
|
|
492
492
|
|
|
493
493
|
// ../kit/src/help.ts
|
|
494
494
|
import process8 from "process";
|
|
495
|
-
var OPTIONAL =
|
|
495
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
496
496
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
497
497
|
var FULL_STOP = /\.$/;
|
|
498
498
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -531,29 +531,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
531
531
|
return [];
|
|
532
532
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
533
533
|
}
|
|
534
|
+
var MAX_INLINE_CHOICES = 24;
|
|
534
535
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
535
536
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
536
537
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
537
|
-
const
|
|
538
|
+
const choices = option.choices?.join("|");
|
|
539
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
540
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
538
541
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
539
542
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
540
|
-
|
|
543
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
544
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
541
545
|
});
|
|
542
546
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
543
547
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
544
548
|
}
|
|
545
549
|
|
|
546
550
|
// ../kit/src/text.ts
|
|
547
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
548
551
|
function distance(a, b) {
|
|
549
|
-
|
|
550
|
-
|
|
552
|
+
const left = [...a];
|
|
553
|
+
const right = [...b];
|
|
554
|
+
let before = [];
|
|
555
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
556
|
+
for (const [i, x] of left.entries()) {
|
|
551
557
|
const current = [i + 1];
|
|
552
|
-
for (const [j,
|
|
553
|
-
|
|
558
|
+
for (const [j, y] of right.entries()) {
|
|
559
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
560
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
561
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
562
|
+
current.push(cost);
|
|
563
|
+
}
|
|
564
|
+
before = previous;
|
|
554
565
|
previous = current;
|
|
555
566
|
}
|
|
556
|
-
return previous[
|
|
567
|
+
return previous[right.length] ?? 0;
|
|
557
568
|
}
|
|
558
569
|
function closest(name, names) {
|
|
559
570
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -955,13 +966,31 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
955
966
|
// ../kit/src/cli.ts
|
|
956
967
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
957
968
|
import { dirname as dirname3, join as join5 } from "path";
|
|
958
|
-
import
|
|
969
|
+
import process15 from "process";
|
|
970
|
+
|
|
971
|
+
// ../kit/src/notify.ts
|
|
972
|
+
import process13 from "process";
|
|
973
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
974
|
+
var CANCELLED = 130;
|
|
975
|
+
function base64(text) {
|
|
976
|
+
return Buffer.from(text).toString("base64");
|
|
977
|
+
}
|
|
978
|
+
function notification(title, body, env = process13.env) {
|
|
979
|
+
const id = `kit${process13.pid}`;
|
|
980
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
981
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
982
|
+
}
|
|
983
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
984
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
985
|
+
return;
|
|
986
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
987
|
+
}
|
|
959
988
|
|
|
960
989
|
// ../kit/src/usage.ts
|
|
961
990
|
import { appendFileSync, mkdirSync } from "fs";
|
|
962
991
|
import { homedir as homedir3 } from "os";
|
|
963
992
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
964
|
-
import
|
|
993
|
+
import process14 from "process";
|
|
965
994
|
|
|
966
995
|
// ../kit/src/logs.ts
|
|
967
996
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -975,14 +1004,14 @@ var usageError;
|
|
|
975
1004
|
function noteUsageError(message) {
|
|
976
1005
|
usageError = message;
|
|
977
1006
|
}
|
|
978
|
-
function stateHome(env =
|
|
1007
|
+
function stateHome(env = process14.env) {
|
|
979
1008
|
const dir = env.XDG_STATE_HOME;
|
|
980
1009
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
981
1010
|
}
|
|
982
|
-
function usagePath(env =
|
|
1011
|
+
function usagePath(env = process14.env) {
|
|
983
1012
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
984
1013
|
}
|
|
985
|
-
function usageRecorded(env =
|
|
1014
|
+
function usageRecorded(env = process14.env) {
|
|
986
1015
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
987
1016
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
988
1017
|
}
|
|
@@ -996,7 +1025,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
996
1025
|
usageError = undefined;
|
|
997
1026
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
998
1027
|
}
|
|
999
|
-
function recordUsage(entry, env =
|
|
1028
|
+
function recordUsage(entry, env = process14.env) {
|
|
1000
1029
|
if (!usageRecorded(env))
|
|
1001
1030
|
return;
|
|
1002
1031
|
try {
|
|
@@ -1086,8 +1115,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1086
1115
|
`);
|
|
1087
1116
|
}
|
|
1088
1117
|
function printError(prefix, message, hint, cause) {
|
|
1089
|
-
const colors = paint(
|
|
1090
|
-
const styled = takesControlCodes(
|
|
1118
|
+
const colors = paint(process15.stderr);
|
|
1119
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1091
1120
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1092
1121
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1093
1122
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1130,11 +1159,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1130
1159
|
}
|
|
1131
1160
|
}
|
|
1132
1161
|
if (name === undefined && level.path.length > 1) {
|
|
1133
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1162
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1134
1163
|
return 2;
|
|
1135
1164
|
}
|
|
1136
1165
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1137
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1166
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1138
1167
|
return 0;
|
|
1139
1168
|
}
|
|
1140
1169
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1269,10 +1298,13 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1269
1298
|
const version = cli.version ?? packageVersion();
|
|
1270
1299
|
if (argv[0] === COMPLETE)
|
|
1271
1300
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1301
|
+
const started = performance.now();
|
|
1272
1302
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1303
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1304
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1273
1305
|
if (cli.usage !== false) {
|
|
1274
1306
|
try {
|
|
1275
|
-
recordUsage(usageEntry(cli.name,
|
|
1307
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1276
1308
|
} catch {}
|
|
1277
1309
|
}
|
|
1278
1310
|
return code;
|
|
@@ -1300,11 +1332,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1300
1332
|
return 0;
|
|
1301
1333
|
}
|
|
1302
1334
|
let code;
|
|
1335
|
+
const started = performance.now();
|
|
1303
1336
|
try {
|
|
1304
1337
|
code = await run(argv);
|
|
1305
1338
|
} catch (error) {
|
|
1306
1339
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1307
1340
|
}
|
|
1341
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1308
1342
|
if (usage !== false) {
|
|
1309
1343
|
try {
|
|
1310
1344
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1344,7 +1378,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1344
1378
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1345
1379
|
}
|
|
1346
1380
|
// ../kit/src/watch.ts
|
|
1347
|
-
import
|
|
1381
|
+
import process16 from "process";
|
|
1348
1382
|
import { format } from "util";
|
|
1349
1383
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1350
1384
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1366,7 +1400,7 @@ function withoutWatch(args) {
|
|
|
1366
1400
|
}
|
|
1367
1401
|
return rest;
|
|
1368
1402
|
}
|
|
1369
|
-
async function watching(value, step, stream =
|
|
1403
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1370
1404
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1371
1405
|
if (!takesControlCodes(stream))
|
|
1372
1406
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1374,12 +1408,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1374
1408
|
for (let round = 0;round < rounds; round++) {
|
|
1375
1409
|
const held = [];
|
|
1376
1410
|
const { log, info } = console;
|
|
1377
|
-
const write =
|
|
1411
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1378
1412
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1379
1413
|
`);
|
|
1380
1414
|
console.log = hold;
|
|
1381
1415
|
console.info = hold;
|
|
1382
|
-
|
|
1416
|
+
process16.stdout.write = (text) => {
|
|
1383
1417
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1384
1418
|
return true;
|
|
1385
1419
|
};
|
|
@@ -1388,7 +1422,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1388
1422
|
} finally {
|
|
1389
1423
|
console.log = log;
|
|
1390
1424
|
console.info = info;
|
|
1391
|
-
|
|
1425
|
+
process16.stdout.write = write;
|
|
1392
1426
|
}
|
|
1393
1427
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1394
1428
|
await sleep(interval);
|
|
@@ -1398,7 +1432,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1398
1432
|
// ../kit/src/workspace-root.ts
|
|
1399
1433
|
import { homedir as homedir4 } from "os";
|
|
1400
1434
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1401
|
-
import
|
|
1435
|
+
import process17 from "process";
|
|
1402
1436
|
function expandHome(path, home) {
|
|
1403
1437
|
if (path === "~")
|
|
1404
1438
|
return home;
|
|
@@ -1408,20 +1442,20 @@ function configured(env, home) {
|
|
|
1408
1442
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1409
1443
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1410
1444
|
}
|
|
1411
|
-
function workspaceRoot({ given, env =
|
|
1445
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1412
1446
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1413
1447
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1414
1448
|
}
|
|
1415
1449
|
// src/repos.ts
|
|
1416
1450
|
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1417
1451
|
import { basename as basename2, relative } from "path";
|
|
1418
|
-
import
|
|
1452
|
+
import process20 from "process";
|
|
1419
1453
|
|
|
1420
1454
|
// src/repos-scan.ts
|
|
1421
1455
|
import { existsSync as existsSync4 } from "fs";
|
|
1422
1456
|
import { readdir } from "fs/promises";
|
|
1423
1457
|
import { basename, join as join7 } from "path";
|
|
1424
|
-
import
|
|
1458
|
+
import process19 from "process";
|
|
1425
1459
|
var MAX_DEPTH = 3;
|
|
1426
1460
|
var CONCURRENCY = 8;
|
|
1427
1461
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1468,7 +1502,7 @@ async function findRepos(root, skip) {
|
|
|
1468
1502
|
}
|
|
1469
1503
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1470
1504
|
try {
|
|
1471
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1505
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1472
1506
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1473
1507
|
} catch {
|
|
1474
1508
|
return;
|
|
@@ -1545,7 +1579,7 @@ function firstLine(text) {
|
|
|
1545
1579
|
}
|
|
1546
1580
|
async function fastForward(path) {
|
|
1547
1581
|
try {
|
|
1548
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1582
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1549
1583
|
if (ran.timedOut)
|
|
1550
1584
|
return "timed out";
|
|
1551
1585
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1588,7 +1622,7 @@ function releasedCell(repo) {
|
|
|
1588
1622
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1589
1623
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1590
1624
|
}
|
|
1591
|
-
function syncCell(repo, stream =
|
|
1625
|
+
function syncCell(repo, stream = process20.stdout) {
|
|
1592
1626
|
const colors = paint(stream);
|
|
1593
1627
|
const ahead = repo.ahead ?? 0;
|
|
1594
1628
|
const behind = repo.behind ?? 0;
|
|
@@ -1599,7 +1633,7 @@ function syncCell(repo, stream = process19.stdout) {
|
|
|
1599
1633
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1600
1634
|
}
|
|
1601
1635
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1602
|
-
function branchCell(repo, stream =
|
|
1636
|
+
function branchCell(repo, stream = process20.stdout) {
|
|
1603
1637
|
const colors = paint(stream);
|
|
1604
1638
|
if (repo.unreadable)
|
|
1605
1639
|
return colors.red("? (unreadable)");
|
|
@@ -1608,8 +1642,8 @@ function branchCell(repo, stream = process19.stdout) {
|
|
|
1608
1642
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1609
1643
|
}
|
|
1610
1644
|
function row(repo, shown) {
|
|
1611
|
-
const colors = paint(
|
|
1612
|
-
const tint = role("path",
|
|
1645
|
+
const colors = paint(process20.stdout);
|
|
1646
|
+
const tint = role("path", process20.stdout);
|
|
1613
1647
|
const unreleased = releasedCell(repo);
|
|
1614
1648
|
return [
|
|
1615
1649
|
tint(shown),
|
|
@@ -1643,12 +1677,12 @@ async function repos(args) {
|
|
|
1643
1677
|
const blocker = pullBlocker(repo);
|
|
1644
1678
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1645
1679
|
if (blocker !== undefined) {
|
|
1646
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1680
|
+
log(marked("note", `${repo.name} skipped`, process20.stdout, blocker));
|
|
1647
1681
|
} else if (refused !== undefined) {
|
|
1648
1682
|
failedPulls++;
|
|
1649
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1683
|
+
log(marked("problem", `${repo.name} not pulled`, process20.stdout, refused));
|
|
1650
1684
|
} else {
|
|
1651
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1685
|
+
log(marked("ok", `${repo.name} pulled`, process20.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1652
1686
|
states[index] = await inspect(repo.path, false);
|
|
1653
1687
|
}
|
|
1654
1688
|
}
|
|
@@ -1663,7 +1697,7 @@ async function repos(args) {
|
|
|
1663
1697
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1664
1698
|
return failedPulls > 0 ? 1 : 0;
|
|
1665
1699
|
}
|
|
1666
|
-
const label = role("label",
|
|
1700
|
+
const label = role("label", process20.stdout);
|
|
1667
1701
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1668
1702
|
if (kept.length === 0) {
|
|
1669
1703
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1679,4 +1713,4 @@ async function repos(args) {
|
|
|
1679
1713
|
}
|
|
1680
1714
|
|
|
1681
1715
|
// src/repos-cli.ts
|
|
1682
|
-
|
|
1716
|
+
process21.exitCode = await runMain({ name: "repos", run: repos });
|