@kaynooo/cli-workspace 0.10.2 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit-cli.js +286 -46
- package/dist/cli.js +399 -102
- package/dist/repos-cli.js +159 -44
- package/dist/sweep-cli.js +217 -45
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process24 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -517,7 +517,7 @@ function printJson(value) {
|
|
|
517
517
|
|
|
518
518
|
// ../kit/src/help.ts
|
|
519
519
|
import process8 from "process";
|
|
520
|
-
var OPTIONAL =
|
|
520
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
521
521
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
522
522
|
var FULL_STOP = /\.$/;
|
|
523
523
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -556,29 +556,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
556
556
|
return [];
|
|
557
557
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
558
558
|
}
|
|
559
|
+
var MAX_INLINE_CHOICES = 24;
|
|
559
560
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
560
561
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
561
562
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
562
|
-
const
|
|
563
|
+
const choices = option.choices?.join("|");
|
|
564
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
565
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
563
566
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
564
567
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
565
|
-
|
|
568
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
569
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
566
570
|
});
|
|
567
571
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
568
572
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
569
573
|
}
|
|
570
574
|
|
|
571
575
|
// ../kit/src/text.ts
|
|
572
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
573
576
|
function distance(a, b) {
|
|
574
|
-
|
|
575
|
-
|
|
577
|
+
const left = [...a];
|
|
578
|
+
const right = [...b];
|
|
579
|
+
let before = [];
|
|
580
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
581
|
+
for (const [i, x] of left.entries()) {
|
|
576
582
|
const current = [i + 1];
|
|
577
|
-
for (const [j,
|
|
578
|
-
|
|
583
|
+
for (const [j, y] of right.entries()) {
|
|
584
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
585
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
586
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
587
|
+
current.push(cost);
|
|
588
|
+
}
|
|
589
|
+
before = previous;
|
|
579
590
|
previous = current;
|
|
580
591
|
}
|
|
581
|
-
return previous[
|
|
592
|
+
return previous[right.length] ?? 0;
|
|
582
593
|
}
|
|
583
594
|
function closest(name, names) {
|
|
584
595
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -645,7 +656,7 @@ class Completing {
|
|
|
645
656
|
}
|
|
646
657
|
var completion = { active: false };
|
|
647
658
|
var OUTPUT_OPTIONS = {
|
|
648
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
659
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
649
660
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
650
661
|
};
|
|
651
662
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -980,13 +991,91 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
980
991
|
// ../kit/src/cli.ts
|
|
981
992
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
982
993
|
import { dirname as dirname3, join as join5 } from "path";
|
|
983
|
-
import
|
|
994
|
+
import process15 from "process";
|
|
995
|
+
|
|
996
|
+
// ../kit/src/completions.ts
|
|
997
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
998
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
999
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1000
|
+
set -l current (commandline -ct)
|
|
1001
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1002
|
+
if test "$line" = __files__
|
|
1003
|
+
__fish_complete_path $current
|
|
1004
|
+
else
|
|
1005
|
+
echo $line
|
|
1006
|
+
end
|
|
1007
|
+
end
|
|
1008
|
+
end`;
|
|
1009
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1010
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1011
|
+
local -a lines
|
|
1012
|
+
COMPREPLY=()
|
|
1013
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1014
|
+
for line in "\${lines[@]}"; do
|
|
1015
|
+
if [[ $line == __files__ ]]; then
|
|
1016
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1017
|
+
else
|
|
1018
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1019
|
+
fi
|
|
1020
|
+
done
|
|
1021
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1022
|
+
}`;
|
|
1023
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1024
|
+
local line
|
|
1025
|
+
local -a described plain
|
|
1026
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1027
|
+
if [[ $line == __files__ ]]; then
|
|
1028
|
+
_files
|
|
1029
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1030
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1031
|
+
else
|
|
1032
|
+
plain+=("$line")
|
|
1033
|
+
fi
|
|
1034
|
+
done
|
|
1035
|
+
(( \${#described} )) && _describe -V value described
|
|
1036
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1037
|
+
return 0
|
|
1038
|
+
}`;
|
|
1039
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1040
|
+
if (shell === "fish")
|
|
1041
|
+
return `${header}
|
|
1042
|
+
${FISH_FUNCTION}
|
|
1043
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1044
|
+
`).join("")}`;
|
|
1045
|
+
if (shell === "bash")
|
|
1046
|
+
return `${header}
|
|
1047
|
+
${BASH_FUNCTION}
|
|
1048
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1049
|
+
`;
|
|
1050
|
+
return `${header}
|
|
1051
|
+
${ZSH_FUNCTION}
|
|
1052
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1053
|
+
`;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// ../kit/src/notify.ts
|
|
1057
|
+
import process13 from "process";
|
|
1058
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1059
|
+
var CANCELLED = 130;
|
|
1060
|
+
function base64(text) {
|
|
1061
|
+
return Buffer.from(text).toString("base64");
|
|
1062
|
+
}
|
|
1063
|
+
function notification(title, body, env = process13.env) {
|
|
1064
|
+
const id = `kit${process13.pid}`;
|
|
1065
|
+
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\\`];
|
|
1066
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1067
|
+
}
|
|
1068
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1069
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1070
|
+
return;
|
|
1071
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1072
|
+
}
|
|
984
1073
|
|
|
985
1074
|
// ../kit/src/usage.ts
|
|
986
1075
|
import { appendFileSync, mkdirSync } from "fs";
|
|
987
1076
|
import { homedir as homedir3 } from "os";
|
|
988
1077
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
989
|
-
import
|
|
1078
|
+
import process14 from "process";
|
|
990
1079
|
|
|
991
1080
|
// ../kit/src/logs.ts
|
|
992
1081
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1000,14 +1089,14 @@ var usageError;
|
|
|
1000
1089
|
function noteUsageError(message) {
|
|
1001
1090
|
usageError = message;
|
|
1002
1091
|
}
|
|
1003
|
-
function stateHome(env =
|
|
1092
|
+
function stateHome(env = process14.env) {
|
|
1004
1093
|
const dir = env.XDG_STATE_HOME;
|
|
1005
1094
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1006
1095
|
}
|
|
1007
|
-
function usagePath(env =
|
|
1096
|
+
function usagePath(env = process14.env) {
|
|
1008
1097
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1009
1098
|
}
|
|
1010
|
-
function usageRecorded(env =
|
|
1099
|
+
function usageRecorded(env = process14.env) {
|
|
1011
1100
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1012
1101
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1013
1102
|
}
|
|
@@ -1021,7 +1110,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1021
1110
|
usageError = undefined;
|
|
1022
1111
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1023
1112
|
}
|
|
1024
|
-
function recordUsage(entry, env =
|
|
1113
|
+
function recordUsage(entry, env = process14.env) {
|
|
1025
1114
|
if (!usageRecorded(env))
|
|
1026
1115
|
return;
|
|
1027
1116
|
try {
|
|
@@ -1037,7 +1126,11 @@ var LEVEL_OPTIONS = {
|
|
|
1037
1126
|
...OUTPUT_OPTIONS,
|
|
1038
1127
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1039
1128
|
};
|
|
1040
|
-
var TOP_OPTIONS = {
|
|
1129
|
+
var TOP_OPTIONS = {
|
|
1130
|
+
...LEVEL_OPTIONS,
|
|
1131
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1132
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1133
|
+
};
|
|
1041
1134
|
async function commandRows(all, colors) {
|
|
1042
1135
|
const commands = shown(all);
|
|
1043
1136
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1111,8 +1204,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1111
1204
|
`);
|
|
1112
1205
|
}
|
|
1113
1206
|
function printError(prefix, message, hint, cause) {
|
|
1114
|
-
const colors = paint(
|
|
1115
|
-
const styled = takesControlCodes(
|
|
1207
|
+
const colors = paint(process15.stderr);
|
|
1208
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1116
1209
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1117
1210
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1118
1211
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1155,11 +1248,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1155
1248
|
}
|
|
1156
1249
|
}
|
|
1157
1250
|
if (name === undefined && level.path.length > 1) {
|
|
1158
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1251
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1159
1252
|
return 2;
|
|
1160
1253
|
}
|
|
1161
1254
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1162
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1255
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1163
1256
|
return 0;
|
|
1164
1257
|
}
|
|
1165
1258
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1270,6 +1363,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1270
1363
|
}
|
|
1271
1364
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1272
1365
|
}
|
|
1366
|
+
var COMPLETIONS = "--completions";
|
|
1367
|
+
function flagValue([flag = "", ...rest]) {
|
|
1368
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1369
|
+
}
|
|
1370
|
+
function printCompletionScript(name, args) {
|
|
1371
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1372
|
+
if (shell === undefined || args.length !== 1) {
|
|
1373
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1374
|
+
return 2;
|
|
1375
|
+
}
|
|
1376
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1377
|
+
return 0;
|
|
1378
|
+
}
|
|
1273
1379
|
async function printCandidates(found) {
|
|
1274
1380
|
for (const line of await found)
|
|
1275
1381
|
console.log(line);
|
|
@@ -1294,10 +1400,15 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1294
1400
|
const version = cli.version ?? packageVersion();
|
|
1295
1401
|
if (argv[0] === COMPLETE)
|
|
1296
1402
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1403
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1404
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1405
|
+
const started = performance.now();
|
|
1297
1406
|
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 });
|
|
1407
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1408
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1298
1409
|
if (cli.usage !== false) {
|
|
1299
1410
|
try {
|
|
1300
|
-
recordUsage(usageEntry(cli.name,
|
|
1411
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1301
1412
|
} catch {}
|
|
1302
1413
|
}
|
|
1303
1414
|
return code;
|
|
@@ -1320,16 +1431,20 @@ function commandPath(scope, argv) {
|
|
|
1320
1431
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1321
1432
|
if (argv[0] === COMPLETE)
|
|
1322
1433
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1434
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1435
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1323
1436
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1324
1437
|
console.log(version ?? packageVersion());
|
|
1325
1438
|
return 0;
|
|
1326
1439
|
}
|
|
1327
1440
|
let code;
|
|
1441
|
+
const started = performance.now();
|
|
1328
1442
|
try {
|
|
1329
1443
|
code = await run(argv);
|
|
1330
1444
|
} catch (error) {
|
|
1331
1445
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1332
1446
|
}
|
|
1447
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1333
1448
|
if (usage !== false) {
|
|
1334
1449
|
try {
|
|
1335
1450
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1369,7 +1484,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1369
1484
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1370
1485
|
}
|
|
1371
1486
|
// ../kit/src/watch.ts
|
|
1372
|
-
import
|
|
1487
|
+
import process16 from "process";
|
|
1373
1488
|
import { format } from "util";
|
|
1374
1489
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1375
1490
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1391,7 +1506,7 @@ function withoutWatch(args) {
|
|
|
1391
1506
|
}
|
|
1392
1507
|
return rest;
|
|
1393
1508
|
}
|
|
1394
|
-
async function watching(value, step, stream =
|
|
1509
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1395
1510
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1396
1511
|
if (!takesControlCodes(stream))
|
|
1397
1512
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1399,12 +1514,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1399
1514
|
for (let round = 0;round < rounds; round++) {
|
|
1400
1515
|
const held = [];
|
|
1401
1516
|
const { log, info } = console;
|
|
1402
|
-
const write =
|
|
1517
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1403
1518
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1404
1519
|
`);
|
|
1405
1520
|
console.log = hold;
|
|
1406
1521
|
console.info = hold;
|
|
1407
|
-
|
|
1522
|
+
process16.stdout.write = (text) => {
|
|
1408
1523
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1409
1524
|
return true;
|
|
1410
1525
|
};
|
|
@@ -1413,7 +1528,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1413
1528
|
} finally {
|
|
1414
1529
|
console.log = log;
|
|
1415
1530
|
console.info = info;
|
|
1416
|
-
|
|
1531
|
+
process16.stdout.write = write;
|
|
1417
1532
|
}
|
|
1418
1533
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1419
1534
|
await sleep(interval);
|
|
@@ -1423,7 +1538,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1423
1538
|
// ../kit/src/workspace-root.ts
|
|
1424
1539
|
import { homedir as homedir4 } from "os";
|
|
1425
1540
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1426
|
-
import
|
|
1541
|
+
import process17 from "process";
|
|
1427
1542
|
function expandHome(path, home) {
|
|
1428
1543
|
if (path === "~")
|
|
1429
1544
|
return home;
|
|
@@ -1433,15 +1548,19 @@ function configured(env, home) {
|
|
|
1433
1548
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1434
1549
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1435
1550
|
}
|
|
1436
|
-
function workspaceRoot({ given, env =
|
|
1551
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1437
1552
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1438
1553
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1439
1554
|
}
|
|
1440
1555
|
// src/audit.ts
|
|
1441
|
-
import { existsSync as
|
|
1556
|
+
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync7, statSync as statSync2 } from "fs";
|
|
1442
1557
|
import { readdir } from "fs/promises";
|
|
1443
|
-
import { join as
|
|
1444
|
-
import
|
|
1558
|
+
import { join as join9, relative, resolve as resolve5 } from "path";
|
|
1559
|
+
import process19 from "process";
|
|
1560
|
+
|
|
1561
|
+
// src/osv.ts
|
|
1562
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
1563
|
+
import { join as join8 } from "path";
|
|
1445
1564
|
|
|
1446
1565
|
// src/report.ts
|
|
1447
1566
|
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
@@ -1558,14 +1677,121 @@ function workspaceFolders(root, children) {
|
|
|
1558
1677
|
return patterns.filter((pattern) => typeof pattern === "string").flatMap((pattern) => pattern.endsWith("/*") ? children(pattern.slice(0, -2)).map((name) => join7(pattern.slice(0, -2), name)) : [pattern]);
|
|
1559
1678
|
}
|
|
1560
1679
|
|
|
1680
|
+
// src/osv.ts
|
|
1681
|
+
var OSV = "https://api.osv.dev/v1";
|
|
1682
|
+
var BATCH = 1000;
|
|
1683
|
+
var DETAIL_CONCURRENCY = 8;
|
|
1684
|
+
var TIMEOUT_MS = 20000;
|
|
1685
|
+
var PACKAGE_BLOCK = /^\[\[package\]\]\s*$/m;
|
|
1686
|
+
var FIELD = /^(name|version|source) = (.+)$/gm;
|
|
1687
|
+
var QUOTED = /^"([^"]*)"$/;
|
|
1688
|
+
var LEADING_V = /^v/;
|
|
1689
|
+
function parseComposerLock(text) {
|
|
1690
|
+
const lock = JSON.parse(text);
|
|
1691
|
+
const entry = (prod) => (each) => ({ name: each.name, version: each.version.replace(LEADING_V, ""), prod });
|
|
1692
|
+
return [...(lock.packages ?? []).map(entry(true)), ...(lock["packages-dev"] ?? []).map(entry(false))];
|
|
1693
|
+
}
|
|
1694
|
+
function tomlPackages(text, fromRegistry) {
|
|
1695
|
+
const found = [];
|
|
1696
|
+
for (const block of text.split(PACKAGE_BLOCK).slice(1)) {
|
|
1697
|
+
const fields = new Map;
|
|
1698
|
+
for (const [, key, value] of block.matchAll(FIELD))
|
|
1699
|
+
fields.set(key, QUOTED.exec(value.trim())?.[1] ?? value.trim());
|
|
1700
|
+
const source = fields.get("source");
|
|
1701
|
+
const name = fields.get("name");
|
|
1702
|
+
const version = fields.get("version");
|
|
1703
|
+
if (name !== undefined && version !== undefined && source !== undefined && fromRegistry(source))
|
|
1704
|
+
found.push({ name, version, prod: true });
|
|
1705
|
+
}
|
|
1706
|
+
return found;
|
|
1707
|
+
}
|
|
1708
|
+
function parseCargoLock(text) {
|
|
1709
|
+
return tomlPackages(text, (source) => source.startsWith("registry+"));
|
|
1710
|
+
}
|
|
1711
|
+
function parseUvLock(text) {
|
|
1712
|
+
return tomlPackages(text, (source) => source.includes("registry"));
|
|
1713
|
+
}
|
|
1714
|
+
var ECOSYSTEMS = [
|
|
1715
|
+
{ lockfile: "composer.lock", osv: "Packagist", parse: parseComposerLock },
|
|
1716
|
+
{ lockfile: "Cargo.lock", osv: "crates.io", parse: parseCargoLock },
|
|
1717
|
+
{ lockfile: "uv.lock", osv: "PyPI", parse: parseUvLock }
|
|
1718
|
+
];
|
|
1719
|
+
function holdsOsvLock(dir) {
|
|
1720
|
+
return ECOSYSTEMS.some((each) => existsSync5(join8(dir, each.lockfile)));
|
|
1721
|
+
}
|
|
1722
|
+
var SEVERITY_NAMES = { LOW: "low", MODERATE: "moderate", MEDIUM: "moderate", HIGH: "high", CRITICAL: "critical" };
|
|
1723
|
+
async function ok2(response) {
|
|
1724
|
+
if (!response.ok)
|
|
1725
|
+
throw new Error(`osv.dev answered ${response.status}`);
|
|
1726
|
+
return response.json();
|
|
1727
|
+
}
|
|
1728
|
+
function rowOf(vuln, name) {
|
|
1729
|
+
const fixes = (vuln.affected ?? []).filter((each) => each.package?.name === name).flatMap((each) => each.ranges ?? []).flatMap((range) => range.events ?? []).map((event) => event.fixed).filter((fixed) => fixed !== undefined);
|
|
1730
|
+
return { id: 0, ghsa: vuln.id, url: `https://osv.dev/vulnerability/${vuln.id}`, title: vuln.summary ?? vuln.id, severity: SEVERITY_NAMES[vuln.database_specific?.severity?.toUpperCase() ?? ""] ?? "moderate", fixed: fixes.length === 0 ? undefined : fixedAt(fixes.map((fix) => `<${fix}`).join(" || ")) };
|
|
1731
|
+
}
|
|
1732
|
+
async function osvFindings(locked, ecosystem, direct, level, ignore, fetcher = fetch) {
|
|
1733
|
+
const hits = new Map;
|
|
1734
|
+
for (let start = 0;start < locked.length; start += BATCH) {
|
|
1735
|
+
const chunk = locked.slice(start, start + BATCH);
|
|
1736
|
+
const queries = chunk.map((each) => ({ package: { name: each.name, ecosystem }, version: each.version }));
|
|
1737
|
+
const answer = await ok2(await fetcher(`${OSV}/querybatch`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ queries }), signal: AbortSignal.timeout(TIMEOUT_MS) }));
|
|
1738
|
+
for (const [index, each] of chunk.entries()) {
|
|
1739
|
+
const ids = (answer.results[index]?.vulns ?? []).map((vuln) => vuln.id).filter((id) => !ignore.includes(id));
|
|
1740
|
+
if (ids.length > 0)
|
|
1741
|
+
hits.set(each, ids);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
const details = new Map;
|
|
1745
|
+
await pool([...new Set([...hits.values()].flat())], DETAIL_CONCURRENCY, async (id) => {
|
|
1746
|
+
details.set(id, await ok2(await fetcher(`${OSV}/vulns/${encodeURIComponent(id)}`, { signal: AbortSignal.timeout(TIMEOUT_MS) })));
|
|
1747
|
+
});
|
|
1748
|
+
const findings = [];
|
|
1749
|
+
let below = 0;
|
|
1750
|
+
for (const [each, ids] of hits) {
|
|
1751
|
+
const rows = ids.map((id) => rowOf(details.get(id), each.name));
|
|
1752
|
+
const advisories = rows.filter((row) => severityRank(row.severity) >= severityRank(level));
|
|
1753
|
+
below += rows.length - advisories.length;
|
|
1754
|
+
if (advisories.length === 0)
|
|
1755
|
+
continue;
|
|
1756
|
+
const fixes = advisories.map((row) => row.fixed);
|
|
1757
|
+
findings.push({
|
|
1758
|
+
package: each.name,
|
|
1759
|
+
severity: advisories.reduce((worst, row) => severityRank(row.severity) > severityRank(worst) ? row.severity : worst, advisories[0].severity),
|
|
1760
|
+
advisories,
|
|
1761
|
+
scope: each.prod ? "prod" : "dev",
|
|
1762
|
+
direct: direct.has(each.name),
|
|
1763
|
+
via: [],
|
|
1764
|
+
fix: fixes.includes(undefined) ? undefined : fixes.reduce((highest, fix) => Bun.semver.order(fix, highest) > 0 ? fix : highest)
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
return { findings: findings.toSorted((a, b) => severityRank(b.severity) - severityRank(a.severity) || Number(b.scope === "prod") - Number(a.scope === "prod") || a.package.localeCompare(b.package)), below };
|
|
1768
|
+
}
|
|
1769
|
+
function manifestNames(dir) {
|
|
1770
|
+
try {
|
|
1771
|
+
const manifest = JSON.parse(readFileSync6(join8(dir, "composer.json"), "utf8"));
|
|
1772
|
+
return new Set([...Object.keys(manifest.require ?? {}), ...Object.keys(manifest["require-dev"] ?? {})]);
|
|
1773
|
+
} catch {
|
|
1774
|
+
return new Set;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
async function osvAudit(dir, level, ignore, fetcher = fetch) {
|
|
1778
|
+
const all = { findings: [], below: 0 };
|
|
1779
|
+
for (const each of ECOSYSTEMS.filter((each) => existsSync5(join8(dir, each.lockfile)))) {
|
|
1780
|
+
const done = await osvFindings(each.parse(readFileSync6(join8(dir, each.lockfile), "utf8")), each.osv, each.lockfile === "composer.lock" ? manifestNames(dir) : new Set, level, ignore, fetcher);
|
|
1781
|
+
all.findings.push(...done.findings);
|
|
1782
|
+
all.below += done.below;
|
|
1783
|
+
}
|
|
1784
|
+
return all;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1561
1787
|
// src/audit.ts
|
|
1562
|
-
var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun repositories under root (the current folder by default), one table per repository
|
|
1788
|
+
var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun, Composer, Cargo and uv repositories under root (the current folder by default), one table per repository
|
|
1563
1789
|
|
|
1564
1790
|
Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via and the direct dependencies leading to it, upgrading one of which is what fixes it), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
|
|
1565
|
-
Advisories under --level (moderate by default) are counted under the table, and what \`bun audit\` warned about, such as a private registry that would not audit its packages, is repeated there. It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry; the walk goes three levels deep, stops at a
|
|
1791
|
+
Advisories under --level (moderate by default) are counted under the table, and what \`bun audit\` warned about, such as a private registry that would not audit its packages, is repeated there. It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry, and asks osv.dev about the packages of a composer.lock, Cargo.lock or uv.lock (a severity the source leaves out reads as moderate, and only composer's manifest tells direct from pulled in); the walk goes three levels deep, stops at a lockfile and skips node_modules and hidden folders.
|
|
1566
1792
|
|
|
1567
1793
|
Reach for it to sweep many repositories at once; \`pkg audit\` vets the one repository in a folder (package age, install scripts, licences) as well as its advisories, and shares --level, --prod and --ignore.`;
|
|
1568
|
-
var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no
|
|
1794
|
+
var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no lockfile sits under root, a usage error or a root that is no folder"]];
|
|
1569
1795
|
var OPTIONS = {
|
|
1570
1796
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
1571
1797
|
prod: { type: "boolean", description: "only the packages a production dependency needs" },
|
|
@@ -1580,8 +1806,11 @@ var VIA_SHOWN = 2;
|
|
|
1580
1806
|
function countAdvisories(findings) {
|
|
1581
1807
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1582
1808
|
}
|
|
1809
|
+
function holdsBunLock(dir) {
|
|
1810
|
+
return existsSync6(join9(dir, "bun.lock")) || existsSync6(join9(dir, "bun.lockb"));
|
|
1811
|
+
}
|
|
1583
1812
|
function holdsLock(dir) {
|
|
1584
|
-
return
|
|
1813
|
+
return holdsBunLock(dir) || holdsOsvLock(dir);
|
|
1585
1814
|
}
|
|
1586
1815
|
async function findRepos(root) {
|
|
1587
1816
|
if (holdsLock(root))
|
|
@@ -1597,7 +1826,7 @@ async function findRepos(root) {
|
|
|
1597
1826
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1598
1827
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith("."))
|
|
1599
1828
|
continue;
|
|
1600
|
-
const path =
|
|
1829
|
+
const path = join9(dir, entry.name);
|
|
1601
1830
|
if (holdsLock(path))
|
|
1602
1831
|
found.push(path);
|
|
1603
1832
|
else if (depth < MAX_DEPTH)
|
|
@@ -1610,13 +1839,24 @@ async function findRepos(root) {
|
|
|
1610
1839
|
function children(root) {
|
|
1611
1840
|
return (folder) => {
|
|
1612
1841
|
try {
|
|
1613
|
-
return readdirSync(
|
|
1842
|
+
return readdirSync(join9(root, folder), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
1614
1843
|
} catch {
|
|
1615
1844
|
return [];
|
|
1616
1845
|
}
|
|
1617
1846
|
};
|
|
1618
1847
|
}
|
|
1619
1848
|
async function audited(path, shown, level, ignore) {
|
|
1849
|
+
const bun = holdsBunLock(path) ? await bunAudited(path, shown, level, ignore) : { repo: shown, path, findings: [], below: 0, warnings: [], error: undefined };
|
|
1850
|
+
if (bun.error !== undefined || !holdsOsvLock(path))
|
|
1851
|
+
return bun;
|
|
1852
|
+
try {
|
|
1853
|
+
const osv = await osvAudit(path, level, ignore);
|
|
1854
|
+
return { ...bun, findings: [...bun.findings, ...osv.findings], below: bun.below + osv.below };
|
|
1855
|
+
} catch (error) {
|
|
1856
|
+
return { ...bun, error: `osv.dev: ${error instanceof Error ? error.message : String(error)}` };
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
async function bunAudited(path, shown, level, ignore) {
|
|
1620
1860
|
const [all, production] = await Promise.all([
|
|
1621
1861
|
runCommand(["bun", "audit", "--json"], { cwd: path, timeoutMs: AUDIT_MS }),
|
|
1622
1862
|
runCommand(["bun", "audit", "--json", "--prod"], { cwd: path, timeoutMs: AUDIT_MS })
|
|
@@ -1633,7 +1873,7 @@ async function audited(path, shown, level, ignore) {
|
|
|
1633
1873
|
}
|
|
1634
1874
|
function lockText(path) {
|
|
1635
1875
|
try {
|
|
1636
|
-
return
|
|
1876
|
+
return readFileSync7(join9(path, "bun.lock"), "utf8");
|
|
1637
1877
|
} catch {
|
|
1638
1878
|
return "";
|
|
1639
1879
|
}
|
|
@@ -1653,7 +1893,7 @@ function failure(ran) {
|
|
|
1653
1893
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1654
1894
|
}
|
|
1655
1895
|
function tint(severity) {
|
|
1656
|
-
const colors = paint(
|
|
1896
|
+
const colors = paint(process19.stdout);
|
|
1657
1897
|
if (severity === "critical" || severity === "high")
|
|
1658
1898
|
return colors.red;
|
|
1659
1899
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1671,12 +1911,12 @@ function rows(findings) {
|
|
|
1671
1911
|
async function audit(args) {
|
|
1672
1912
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
|
|
1673
1913
|
const root = resolve5(positionals[0] ?? ".");
|
|
1674
|
-
if (!
|
|
1914
|
+
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1675
1915
|
fail(`no folder ${root}`);
|
|
1676
1916
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1677
1917
|
const paths = await findRepos(root);
|
|
1678
1918
|
if (paths.length === 0)
|
|
1679
|
-
fail(`no bun.lock under ${root}`);
|
|
1919
|
+
fail(`no bun.lock, composer.lock, Cargo.lock or uv.lock under ${root}`);
|
|
1680
1920
|
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1681
1921
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1682
1922
|
if (values.json === true)
|
|
@@ -1688,8 +1928,8 @@ async function audit(args) {
|
|
|
1688
1928
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1689
1929
|
}
|
|
1690
1930
|
function show(audits, total) {
|
|
1691
|
-
const label = role("label",
|
|
1692
|
-
const path = role("path",
|
|
1931
|
+
const label = role("label", process19.stdout);
|
|
1932
|
+
const path = role("path", process19.stdout);
|
|
1693
1933
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1694
1934
|
if (flagged.length === 0) {
|
|
1695
1935
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1709,15 +1949,15 @@ function show(audits, total) {
|
|
|
1709
1949
|
}
|
|
1710
1950
|
|
|
1711
1951
|
// src/repos.ts
|
|
1712
|
-
import { existsSync as
|
|
1952
|
+
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1713
1953
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1714
|
-
import
|
|
1954
|
+
import process21 from "process";
|
|
1715
1955
|
|
|
1716
1956
|
// src/repos-scan.ts
|
|
1717
|
-
import { existsSync as
|
|
1957
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1718
1958
|
import { readdir as readdir2 } from "fs/promises";
|
|
1719
|
-
import { basename, join as
|
|
1720
|
-
import
|
|
1959
|
+
import { basename, join as join10 } from "path";
|
|
1960
|
+
import process20 from "process";
|
|
1721
1961
|
var MAX_DEPTH2 = 3;
|
|
1722
1962
|
var CONCURRENCY2 = 8;
|
|
1723
1963
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1739,7 +1979,7 @@ function reasonsOf(repo) {
|
|
|
1739
1979
|
return reasons;
|
|
1740
1980
|
}
|
|
1741
1981
|
async function findRepos2(root, skip) {
|
|
1742
|
-
if (
|
|
1982
|
+
if (existsSync7(join10(root, ".git")))
|
|
1743
1983
|
return [root];
|
|
1744
1984
|
const found = [];
|
|
1745
1985
|
async function walk(dir, depth) {
|
|
@@ -1752,8 +1992,8 @@ async function findRepos2(root, skip) {
|
|
|
1752
1992
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1753
1993
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1754
1994
|
continue;
|
|
1755
|
-
const path =
|
|
1756
|
-
if (
|
|
1995
|
+
const path = join10(dir, entry.name);
|
|
1996
|
+
if (existsSync7(join10(path, ".git")))
|
|
1757
1997
|
found.push(path);
|
|
1758
1998
|
else if (depth < MAX_DEPTH2)
|
|
1759
1999
|
await walk(path, depth + 1);
|
|
@@ -1764,7 +2004,7 @@ async function findRepos2(root, skip) {
|
|
|
1764
2004
|
}
|
|
1765
2005
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1766
2006
|
try {
|
|
1767
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
2007
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process20.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1768
2008
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1769
2009
|
} catch {
|
|
1770
2010
|
return;
|
|
@@ -1783,14 +2023,14 @@ async function packageReleases(path) {
|
|
|
1783
2023
|
names.add(name);
|
|
1784
2024
|
}
|
|
1785
2025
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1786
|
-
const folder = [
|
|
2026
|
+
const folder = [join10("packages", name), name].find((candidate) => existsSync7(join10(path, candidate)));
|
|
1787
2027
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1788
2028
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1789
2029
|
});
|
|
1790
2030
|
return releases.filter((release) => release !== undefined);
|
|
1791
2031
|
}
|
|
1792
|
-
async function inspect(path,
|
|
1793
|
-
const fetched =
|
|
2032
|
+
async function inspect(path, fetch2) {
|
|
2033
|
+
const fetched = fetch2 ? await read(path, ["fetch", "--quiet"], FETCH_MS) : "";
|
|
1794
2034
|
const [status, worktrees, packages] = await Promise.all([
|
|
1795
2035
|
read(path, ["status", "--porcelain=v2", "--branch"]),
|
|
1796
2036
|
read(path, ["worktree", "list", "--porcelain"]),
|
|
@@ -1841,7 +2081,7 @@ function firstLine(text) {
|
|
|
1841
2081
|
}
|
|
1842
2082
|
async function fastForward(path) {
|
|
1843
2083
|
try {
|
|
1844
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
2084
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process20.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1845
2085
|
if (ran.timedOut)
|
|
1846
2086
|
return "timed out";
|
|
1847
2087
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1870,7 +2110,7 @@ var OPTIONS2 = {
|
|
|
1870
2110
|
};
|
|
1871
2111
|
async function skipped() {
|
|
1872
2112
|
const file = userConfigReadPath("repos");
|
|
1873
|
-
if (!
|
|
2113
|
+
if (!existsSync8(file))
|
|
1874
2114
|
return new Set;
|
|
1875
2115
|
try {
|
|
1876
2116
|
const config = await Bun.file(file).json();
|
|
@@ -1884,7 +2124,7 @@ function releasedCell(repo) {
|
|
|
1884
2124
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1885
2125
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1886
2126
|
}
|
|
1887
|
-
function syncCell(repo, stream =
|
|
2127
|
+
function syncCell(repo, stream = process21.stdout) {
|
|
1888
2128
|
const colors = paint(stream);
|
|
1889
2129
|
const ahead = repo.ahead ?? 0;
|
|
1890
2130
|
const behind = repo.behind ?? 0;
|
|
@@ -1895,7 +2135,7 @@ function syncCell(repo, stream = process20.stdout) {
|
|
|
1895
2135
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1896
2136
|
}
|
|
1897
2137
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1898
|
-
function branchCell(repo, stream =
|
|
2138
|
+
function branchCell(repo, stream = process21.stdout) {
|
|
1899
2139
|
const colors = paint(stream);
|
|
1900
2140
|
if (repo.unreadable)
|
|
1901
2141
|
return colors.red("? (unreadable)");
|
|
@@ -1904,8 +2144,8 @@ function branchCell(repo, stream = process20.stdout) {
|
|
|
1904
2144
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1905
2145
|
}
|
|
1906
2146
|
function row(repo, shown) {
|
|
1907
|
-
const colors = paint(
|
|
1908
|
-
const tint = role("path",
|
|
2147
|
+
const colors = paint(process21.stdout);
|
|
2148
|
+
const tint = role("path", process21.stdout);
|
|
1909
2149
|
const unreleased = releasedCell(repo);
|
|
1910
2150
|
return [
|
|
1911
2151
|
tint(shown),
|
|
@@ -1921,9 +2161,9 @@ async function repos(args) {
|
|
|
1921
2161
|
if (values.watch !== undefined)
|
|
1922
2162
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1923
2163
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1924
|
-
if (!
|
|
2164
|
+
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
1925
2165
|
fail(`no folder ${root}`);
|
|
1926
|
-
const only = values.only
|
|
2166
|
+
const only = values.only;
|
|
1927
2167
|
const paths = await findRepos2(root, await skipped());
|
|
1928
2168
|
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY2), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1929
2169
|
const keeps = (repo) => {
|
|
@@ -1939,12 +2179,12 @@ async function repos(args) {
|
|
|
1939
2179
|
const blocker = pullBlocker(repo);
|
|
1940
2180
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1941
2181
|
if (blocker !== undefined) {
|
|
1942
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2182
|
+
log(marked("note", `${repo.name} skipped`, process21.stdout, blocker));
|
|
1943
2183
|
} else if (refused !== undefined) {
|
|
1944
2184
|
failedPulls++;
|
|
1945
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2185
|
+
log(marked("problem", `${repo.name} not pulled`, process21.stdout, refused));
|
|
1946
2186
|
} else {
|
|
1947
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2187
|
+
log(marked("ok", `${repo.name} pulled`, process21.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1948
2188
|
states[index] = await inspect(repo.path, false);
|
|
1949
2189
|
}
|
|
1950
2190
|
}
|
|
@@ -1959,7 +2199,7 @@ async function repos(args) {
|
|
|
1959
2199
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1960
2200
|
return failedPulls > 0 ? 1 : 0;
|
|
1961
2201
|
}
|
|
1962
|
-
const label = role("label",
|
|
2202
|
+
const label = role("label", process21.stdout);
|
|
1963
2203
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1964
2204
|
if (kept.length === 0) {
|
|
1965
2205
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1975,12 +2215,26 @@ async function repos(args) {
|
|
|
1975
2215
|
}
|
|
1976
2216
|
|
|
1977
2217
|
// src/sweep.ts
|
|
1978
|
-
import { existsSync as
|
|
2218
|
+
import { existsSync as existsSync11, statSync as statSync4 } from "fs";
|
|
1979
2219
|
import { homedir as homedir6 } from "os";
|
|
1980
2220
|
import { relative as relative3 } from "path";
|
|
1981
2221
|
|
|
1982
2222
|
// ../kit/src/prompt.ts
|
|
1983
|
-
import
|
|
2223
|
+
import process23 from "process";
|
|
2224
|
+
|
|
2225
|
+
// ../kit/src/job.ts
|
|
2226
|
+
import process22 from "process";
|
|
2227
|
+
function stopJob() {
|
|
2228
|
+
process22.kill(0, "SIGTSTP");
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// ../kit/src/picker/line.ts
|
|
2232
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2233
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2234
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2235
|
+
function isEditKey(key) {
|
|
2236
|
+
return EDIT_KEYS.has(key);
|
|
2237
|
+
}
|
|
1984
2238
|
|
|
1985
2239
|
// ../kit/src/picker/score.ts
|
|
1986
2240
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -2012,10 +2266,29 @@ var KEYS = {
|
|
|
2012
2266
|
"\n": "enter",
|
|
2013
2267
|
"\x03": "cancel",
|
|
2014
2268
|
"\x1B": "cancel",
|
|
2269
|
+
"\x1B[D": "left",
|
|
2270
|
+
"\x1BOD": "left",
|
|
2271
|
+
"\x1B[C": "right",
|
|
2272
|
+
"\x1BOC": "right",
|
|
2273
|
+
"\x1B[1;5D": "wordleft",
|
|
2274
|
+
"\x1B[1;3D": "wordleft",
|
|
2275
|
+
"\x1Bb": "wordleft",
|
|
2276
|
+
"\x1B[1;5C": "wordright",
|
|
2277
|
+
"\x1B[1;3C": "wordright",
|
|
2278
|
+
"\x1Bf": "wordright",
|
|
2279
|
+
"\x01": "linestart",
|
|
2280
|
+
"\x05": "lineend",
|
|
2015
2281
|
"\x7F": "erase",
|
|
2016
|
-
"\
|
|
2282
|
+
"\x1B[3~": "delete",
|
|
2283
|
+
"\b": "killword",
|
|
2284
|
+
"\x1B\x7F": "killword",
|
|
2285
|
+
"\x1B[3;5~": "killnext",
|
|
2286
|
+
"\x1Bd": "killnext",
|
|
2017
2287
|
"\x15": "clear",
|
|
2288
|
+
"\v": "killend",
|
|
2018
2289
|
"\x17": "word",
|
|
2290
|
+
"\x19": "yank",
|
|
2291
|
+
"\x1A": "suspend",
|
|
2019
2292
|
"\t": "tab",
|
|
2020
2293
|
"\x1F": "help",
|
|
2021
2294
|
"\x1BOP": "help",
|
|
@@ -2045,10 +2318,21 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
2045
2318
|
});
|
|
2046
2319
|
}
|
|
2047
2320
|
|
|
2321
|
+
// ../kit/src/redraw.ts
|
|
2322
|
+
var SYNC_START = "\x1B[?2026h";
|
|
2323
|
+
var SYNC_END = "\x1B[?2026l";
|
|
2324
|
+
function overwrite(lines, columns) {
|
|
2325
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2326
|
+
`);
|
|
2327
|
+
}
|
|
2328
|
+
function rowsTaken(lines, columns) {
|
|
2329
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2048
2332
|
// ../kit/src/prompt.ts
|
|
2049
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "
|
|
2333
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2050
2334
|
function readKeys(input, paste = { active: false }) {
|
|
2051
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
2335
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2052
2336
|
}
|
|
2053
2337
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2054
2338
|
let answered = fallback;
|
|
@@ -2072,7 +2356,7 @@ function asking(colors, question, typed, keys) {
|
|
|
2072
2356
|
function answer(colors, question, state, picked) {
|
|
2073
2357
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2074
2358
|
}
|
|
2075
|
-
async function ask(question, { hint, terminal =
|
|
2359
|
+
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2076
2360
|
const { stdin, stderr } = terminal;
|
|
2077
2361
|
if (!isInteractive(terminal))
|
|
2078
2362
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2082,12 +2366,22 @@ async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
|
2082
2366
|
const columns = () => stderr.columns || 80;
|
|
2083
2367
|
const draw = (state, last = false) => {
|
|
2084
2368
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2085
|
-
|
|
2086
|
-
|
|
2369
|
+
const rows = rowsTaken(frame, columns());
|
|
2370
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2087
2371
|
current = state;
|
|
2088
2372
|
};
|
|
2089
2373
|
const redraw = () => draw(current);
|
|
2090
2374
|
const paste = { active: false };
|
|
2375
|
+
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2376
|
+
const suspend = () => {
|
|
2377
|
+
if (stop === undefined)
|
|
2378
|
+
return;
|
|
2379
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2380
|
+
stdin.setRawMode(false);
|
|
2381
|
+
stop();
|
|
2382
|
+
stdin.setRawMode(true);
|
|
2383
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2384
|
+
};
|
|
2091
2385
|
try {
|
|
2092
2386
|
stderr.on?.("resize", redraw);
|
|
2093
2387
|
stdin.setRawMode(true);
|
|
@@ -2097,6 +2391,10 @@ async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
|
2097
2391
|
return await new Promise((resolve) => {
|
|
2098
2392
|
function onData(data) {
|
|
2099
2393
|
for (const key of readKeys(data.toString(), paste)) {
|
|
2394
|
+
if (key === "suspend") {
|
|
2395
|
+
suspend();
|
|
2396
|
+
continue;
|
|
2397
|
+
}
|
|
2100
2398
|
const pressed = press(key);
|
|
2101
2399
|
if (pressed !== undefined) {
|
|
2102
2400
|
settle(pressed);
|
|
@@ -2128,19 +2426,19 @@ async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
|
2128
2426
|
}
|
|
2129
2427
|
|
|
2130
2428
|
// src/apply.ts
|
|
2131
|
-
import { existsSync as
|
|
2429
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2132
2430
|
import { lstat as lstat3, rm } from "fs/promises";
|
|
2133
|
-
import { basename as basename4, join as
|
|
2431
|
+
import { basename as basename4, join as join13 } from "path";
|
|
2134
2432
|
|
|
2135
2433
|
// src/sweep-scan.ts
|
|
2136
|
-
import { existsSync as
|
|
2434
|
+
import { existsSync as existsSync9 } from "fs";
|
|
2137
2435
|
import { lstat as lstat2, readdir as readdir4, realpath } from "fs/promises";
|
|
2138
2436
|
import { homedir as homedir5 } from "os";
|
|
2139
|
-
import { basename as basename3, dirname as dirname5, join as
|
|
2437
|
+
import { basename as basename3, dirname as dirname5, join as join12 } from "path";
|
|
2140
2438
|
|
|
2141
2439
|
// src/size.ts
|
|
2142
2440
|
import { lstat, readdir as readdir3 } from "fs/promises";
|
|
2143
|
-
import { join as
|
|
2441
|
+
import { join as join11 } from "path";
|
|
2144
2442
|
var FS_LIMIT = 32;
|
|
2145
2443
|
var FIND_MS = 60000;
|
|
2146
2444
|
var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
|
|
@@ -2168,7 +2466,7 @@ async function walkSize(folder) {
|
|
|
2168
2466
|
return;
|
|
2169
2467
|
}
|
|
2170
2468
|
await Promise.all(entries.map(async (entry) => {
|
|
2171
|
-
const path =
|
|
2469
|
+
const path = join11(dir, entry.name);
|
|
2172
2470
|
if (entry.isDirectory())
|
|
2173
2471
|
return visit(path);
|
|
2174
2472
|
try {
|
|
@@ -2212,12 +2510,13 @@ async function sizeOf(folder) {
|
|
|
2212
2510
|
}
|
|
2213
2511
|
|
|
2214
2512
|
// src/sweep-scan.ts
|
|
2215
|
-
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
|
|
2513
|
+
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target", "vendor", ".venv", "__pycache__", ".gradle"]);
|
|
2514
|
+
var NEEDS_BESIDE = { target: ["Cargo.toml"], vendor: ["composer.json", "composer.lock"] };
|
|
2216
2515
|
var MAX_DEPTH3 = 3;
|
|
2217
|
-
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
|
|
2516
|
+
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit", "__pycache__", ".gradle"]);
|
|
2218
2517
|
var GLOBAL_CACHES = [".bun/install/cache", ".npm/_cacache", ".cache/pip", ".cache/uv", ".cache/ms-playwright", ".cache/puppeteer", ".cache/go-build", ".cache/typescript", ".cargo/registry"];
|
|
2219
2518
|
function isCachePath(path, home = homedir5()) {
|
|
2220
|
-
return GLOBAL_CACHES.some((cache) =>
|
|
2519
|
+
return GLOBAL_CACHES.some((cache) => join12(home, cache) === path) || basename3(path) === ".cache" && basename3(dirname5(path)) === "node_modules";
|
|
2221
2520
|
}
|
|
2222
2521
|
async function listing(dir) {
|
|
2223
2522
|
try {
|
|
@@ -2228,7 +2527,7 @@ async function listing(dir) {
|
|
|
2228
2527
|
}
|
|
2229
2528
|
async function addGlobalCaches(found, home) {
|
|
2230
2529
|
for (const cache of GLOBAL_CACHES) {
|
|
2231
|
-
const path =
|
|
2530
|
+
const path = join12(home, cache);
|
|
2232
2531
|
try {
|
|
2233
2532
|
const stat = await lstat2(path);
|
|
2234
2533
|
if (stat.isSymbolicLink())
|
|
@@ -2243,7 +2542,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2243
2542
|
const visit = async (dir, depth) => {
|
|
2244
2543
|
const entries = await listing(dir);
|
|
2245
2544
|
for (const entry of entries) {
|
|
2246
|
-
const path =
|
|
2545
|
+
const path = join12(dir, entry.name);
|
|
2247
2546
|
if (entry.name === ".git")
|
|
2248
2547
|
continue;
|
|
2249
2548
|
if (entry.name === ".worktrees" || entry.name === "worktrees" && basename3(dir) === ".claude") {
|
|
@@ -2253,13 +2552,13 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2253
2552
|
}
|
|
2254
2553
|
for (const worktree of await listing(path)) {
|
|
2255
2554
|
if (worktree.isDirectory())
|
|
2256
|
-
found.candidates.push({ path:
|
|
2555
|
+
found.candidates.push({ path: join12(path, worktree.name), kind: "worktree" });
|
|
2257
2556
|
else if (worktree.isSymbolicLink())
|
|
2258
|
-
found.skipped.push({ path:
|
|
2557
|
+
found.skipped.push({ path: join12(path, worktree.name), reason: "symlink" });
|
|
2259
2558
|
}
|
|
2260
2559
|
continue;
|
|
2261
2560
|
}
|
|
2262
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name
|
|
2561
|
+
if (FOLDER_NAMES.has(entry.name) && (NEEDS_BESIDE[entry.name]?.some((file) => existsSync9(join12(dir, file))) ?? true)) {
|
|
2263
2562
|
if (entry.isSymbolicLink()) {
|
|
2264
2563
|
found.skipped.push({ path, reason: "symlink" });
|
|
2265
2564
|
} else if (entry.isDirectory()) {
|
|
@@ -2267,9 +2566,9 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2267
2566
|
if (entry.name === "node_modules") {
|
|
2268
2567
|
const cache = (await listing(path)).find((inner) => inner.name === ".cache");
|
|
2269
2568
|
if (cache?.isSymbolicLink())
|
|
2270
|
-
found.skipped.push({ path:
|
|
2569
|
+
found.skipped.push({ path: join12(path, ".cache"), reason: "symlink" });
|
|
2271
2570
|
else if (cache?.isDirectory())
|
|
2272
|
-
found.candidates.push({ path:
|
|
2571
|
+
found.candidates.push({ path: join12(path, ".cache"), kind: "cache", inside: path });
|
|
2273
2572
|
}
|
|
2274
2573
|
}
|
|
2275
2574
|
continue;
|
|
@@ -2345,7 +2644,7 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2345
2644
|
const located = await toplevelOf(parent);
|
|
2346
2645
|
if (located === "failed")
|
|
2347
2646
|
return { skip: "git failed" };
|
|
2348
|
-
if (
|
|
2647
|
+
if (existsSync9(join12(path, ".git")))
|
|
2349
2648
|
return { skip: "holds a git repository" };
|
|
2350
2649
|
if (located === "none")
|
|
2351
2650
|
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
@@ -2413,7 +2712,7 @@ async function removeFolder(entry) {
|
|
|
2413
2712
|
const stat = await lstat3(entry.path);
|
|
2414
2713
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename4(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
|
|
2415
2714
|
return { path: entry.path, removed: false, error: "no longer a plain folder" };
|
|
2416
|
-
if (
|
|
2715
|
+
if (existsSync10(join13(entry.path, ".git")))
|
|
2417
2716
|
return { path: entry.path, removed: false, error: "holds a git repository" };
|
|
2418
2717
|
await rm(entry.path, { recursive: true, force: true });
|
|
2419
2718
|
return { path: entry.path, removed: true };
|
|
@@ -2446,7 +2745,7 @@ async function applyAll(entries, done) {
|
|
|
2446
2745
|
// src/sweep.ts
|
|
2447
2746
|
var LARGE = 100 * 1024 ** 2;
|
|
2448
2747
|
var BIG = 1024 ** 3;
|
|
2449
|
-
var USAGE3 = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, target beside a Cargo.toml), the caches (.nuxt, .next, .turbo, .svelte-kit and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (the configured workspace, ~/Workspace by default, ${MAX_DEPTH3} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
|
|
2748
|
+
var USAGE3 = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, .venv, target beside a Cargo.toml, vendor beside a composer.json or composer.lock), the caches (.nuxt, .next, .turbo, .svelte-kit, __pycache__, .gradle and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (the configured workspace, ~/Workspace by default, ${MAX_DEPTH3} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
|
|
2450
2749
|
|
|
2451
2750
|
Dry unless --apply, which deletes after a confirm showing the total (read from the terminal; off one, pass --yes). A folder is deleted for good, not trashed. Never touched: a symlink, a folder git tracks files in, a build folder git does not ignore. A worktree is removed with git worktree remove, never forced, and only when it is clean and every commit of its branch is on another branch or a remote; the others stay listed as kept and count for nothing in the total. With --docker the Docker usage comes after the list, left to dclean.`;
|
|
2452
2751
|
var EXITS3 = [[0, "it listed, or removed every entry it was allowed to"], [1, "a removal failed or the confirm was declined"], [2, "a usage error, a missing root, or --apply off a terminal without --yes"]];
|
|
@@ -2456,7 +2755,7 @@ var OPTIONS3 = {
|
|
|
2456
2755
|
yes: { type: "boolean", short: "y", description: "with --apply, skip the confirm" },
|
|
2457
2756
|
older: { type: "string", description: "only the entries whose repo last committed longer ago than this (30d, 12h)" },
|
|
2458
2757
|
min: { type: "string", description: "only the entries of at least this size (500K, 10M, 1G)" },
|
|
2459
|
-
only: { type: "string",
|
|
2758
|
+
only: { type: "string", choices: Object.keys(ONLY_KINDS), description: "leave the other kinds out (.nuxt, .next, .turbo, .svelte-kit, __pycache__ and .gradle are caches; the global caches are listed with no root or with caches)" },
|
|
2460
2759
|
docker: { type: "boolean", description: "add the docker system df output, which alone takes about ten seconds" },
|
|
2461
2760
|
json: jsonOption("{root, entries: [{path, kind (folder, worktree or cache), bytes, committedAt, action (remove or keep), reason}], skipped: [{path, reason}], reclaimable, docker, removed?}")
|
|
2462
2761
|
};
|
|
@@ -2475,10 +2774,8 @@ async function sweep(args) {
|
|
|
2475
2774
|
if (positionals.length > 1)
|
|
2476
2775
|
badUsage("give one root");
|
|
2477
2776
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2478
|
-
if (!
|
|
2777
|
+
if (!existsSync11(root) || !statSync4(root).isDirectory())
|
|
2479
2778
|
fail(`${root} is not a folder`);
|
|
2480
|
-
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
2481
|
-
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
2482
2779
|
const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0);
|
|
2483
2780
|
const minBytes = values.min === undefined ? 0 : parseSize(values.min);
|
|
2484
2781
|
if (minBytes === undefined)
|
|
@@ -2549,7 +2846,7 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2549
2846
|
}
|
|
2550
2847
|
|
|
2551
2848
|
// src/cli.ts
|
|
2552
|
-
|
|
2849
|
+
process24.exitCode = await runCli({
|
|
2553
2850
|
name: "ws",
|
|
2554
2851
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2555
2852
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|
|
@@ -2557,6 +2854,6 @@ process22.exitCode = await runCli({
|
|
|
2557
2854
|
commands: {
|
|
2558
2855
|
repos: { summary: "the git repositories that need attention: dirty, ahead or behind, worktrees, unreleased commits", run: repos },
|
|
2559
2856
|
sweep: { summary: "the regenerable folders, caches and clean worktrees, largest first, deleted only on --apply", run: sweep },
|
|
2560
|
-
audit: { summary: "the known vulnerabilities of the Bun repositories, one table per repository", run: audit }
|
|
2857
|
+
audit: { summary: "the known vulnerabilities of the Bun, Composer, Cargo and uv repositories, one table per repository", run: audit }
|
|
2561
2858
|
}
|
|
2562
2859
|
});
|