@kaynooo/cli-workspace 0.10.1 → 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 +257 -75
- package/dist/cli.js +372 -132
- package/dist/repos-cli.js +126 -69
- package/dist/sweep-cli.js +188 -73
- 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,24 +517,20 @@ 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)) {
|
|
524
524
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
525
525
|
}
|
|
526
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
527
|
-
return [usageLine(usage, colors),
|
|
526
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
527
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
528
528
|
`);
|
|
529
529
|
}
|
|
530
530
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
531
531
|
if (exits.length === 0)
|
|
532
532
|
return [];
|
|
533
|
-
|
|
534
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
535
|
-
}
|
|
536
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
537
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
533
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
538
534
|
}
|
|
539
535
|
function wantsHelpJson(env = process8.env) {
|
|
540
536
|
return env.KIT_HELP === "json";
|
|
@@ -560,29 +556,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
560
556
|
return [];
|
|
561
557
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
562
558
|
}
|
|
559
|
+
var MAX_INLINE_CHOICES = 24;
|
|
563
560
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
564
561
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
565
562
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
566
|
-
const
|
|
563
|
+
const choices = option.choices?.join("|");
|
|
564
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
565
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
567
566
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
568
567
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
569
|
-
|
|
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 };
|
|
570
570
|
});
|
|
571
571
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
572
572
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
573
573
|
}
|
|
574
574
|
|
|
575
575
|
// ../kit/src/text.ts
|
|
576
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
577
576
|
function distance(a, b) {
|
|
578
|
-
|
|
579
|
-
|
|
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()) {
|
|
580
582
|
const current = [i + 1];
|
|
581
|
-
for (const [j,
|
|
582
|
-
|
|
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;
|
|
583
590
|
previous = current;
|
|
584
591
|
}
|
|
585
|
-
return previous[
|
|
592
|
+
return previous[right.length] ?? 0;
|
|
586
593
|
}
|
|
587
594
|
function closest(name, names) {
|
|
588
595
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -821,9 +828,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
821
828
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
822
829
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
823
830
|
}
|
|
831
|
+
// ../kit/src/argv.ts
|
|
832
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
833
|
+
import { resolve as resolve3 } from "path";
|
|
834
|
+
import process10 from "process";
|
|
835
|
+
function commandLine() {
|
|
836
|
+
try {
|
|
837
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
838
|
+
} catch {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function realPath(word) {
|
|
843
|
+
try {
|
|
844
|
+
return realpathSync(resolve3(word));
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
850
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
851
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
852
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
853
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
854
|
+
}
|
|
824
855
|
// ../kit/src/process.ts
|
|
825
856
|
import { constants } from "os";
|
|
826
|
-
import
|
|
857
|
+
import process11 from "process";
|
|
827
858
|
var KILL_GRACE_MS = 2000;
|
|
828
859
|
function exitCodeOf(code, signal) {
|
|
829
860
|
if (code !== null)
|
|
@@ -843,7 +874,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
843
874
|
return;
|
|
844
875
|
try {
|
|
845
876
|
if (grouped)
|
|
846
|
-
|
|
877
|
+
process11.kill(-proc.pid, killing);
|
|
847
878
|
else
|
|
848
879
|
proc.kill(killing);
|
|
849
880
|
} catch {}
|
|
@@ -918,10 +949,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
918
949
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
919
950
|
|
|
920
951
|
// ../kit/src/tool.ts
|
|
921
|
-
import
|
|
952
|
+
import process12 from "process";
|
|
922
953
|
function cwdGone() {
|
|
923
954
|
try {
|
|
924
|
-
|
|
955
|
+
process12.cwd();
|
|
925
956
|
return false;
|
|
926
957
|
} catch {
|
|
927
958
|
return true;
|
|
@@ -943,7 +974,7 @@ function spawnFailure(command, error) {
|
|
|
943
974
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
944
975
|
let ran;
|
|
945
976
|
try {
|
|
946
|
-
ran = await runCommand(argv, { env:
|
|
977
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
947
978
|
} catch (error) {
|
|
948
979
|
throw spawnFailure(label, error);
|
|
949
980
|
}
|
|
@@ -958,15 +989,33 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
958
989
|
return { code: ran.code, ...streams };
|
|
959
990
|
}
|
|
960
991
|
// ../kit/src/cli.ts
|
|
961
|
-
import { readFileSync as
|
|
992
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
962
993
|
import { dirname as dirname3, join as join5 } from "path";
|
|
994
|
+
import process15 from "process";
|
|
995
|
+
|
|
996
|
+
// ../kit/src/notify.ts
|
|
963
997
|
import process13 from "process";
|
|
998
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
999
|
+
var CANCELLED = 130;
|
|
1000
|
+
function base64(text) {
|
|
1001
|
+
return Buffer.from(text).toString("base64");
|
|
1002
|
+
}
|
|
1003
|
+
function notification(title, body, env = process13.env) {
|
|
1004
|
+
const id = `kit${process13.pid}`;
|
|
1005
|
+
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\\`];
|
|
1006
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1007
|
+
}
|
|
1008
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1009
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1010
|
+
return;
|
|
1011
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1012
|
+
}
|
|
964
1013
|
|
|
965
1014
|
// ../kit/src/usage.ts
|
|
966
1015
|
import { appendFileSync, mkdirSync } from "fs";
|
|
967
1016
|
import { homedir as homedir3 } from "os";
|
|
968
1017
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
969
|
-
import
|
|
1018
|
+
import process14 from "process";
|
|
970
1019
|
|
|
971
1020
|
// ../kit/src/logs.ts
|
|
972
1021
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -980,14 +1029,14 @@ var usageError;
|
|
|
980
1029
|
function noteUsageError(message) {
|
|
981
1030
|
usageError = message;
|
|
982
1031
|
}
|
|
983
|
-
function stateHome(env =
|
|
1032
|
+
function stateHome(env = process14.env) {
|
|
984
1033
|
const dir = env.XDG_STATE_HOME;
|
|
985
1034
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
986
1035
|
}
|
|
987
|
-
function usagePath(env =
|
|
1036
|
+
function usagePath(env = process14.env) {
|
|
988
1037
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
989
1038
|
}
|
|
990
|
-
function usageRecorded(env =
|
|
1039
|
+
function usageRecorded(env = process14.env) {
|
|
991
1040
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
992
1041
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
993
1042
|
}
|
|
@@ -1001,7 +1050,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1001
1050
|
usageError = undefined;
|
|
1002
1051
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1003
1052
|
}
|
|
1004
|
-
function recordUsage(entry, env =
|
|
1053
|
+
function recordUsage(entry, env = process14.env) {
|
|
1005
1054
|
if (!usageRecorded(env))
|
|
1006
1055
|
return;
|
|
1007
1056
|
try {
|
|
@@ -1078,7 +1127,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1078
1127
|
header(colors, summary),
|
|
1079
1128
|
"",
|
|
1080
1129
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1081
|
-
...replacesRows(replaces, colors),
|
|
1082
1130
|
"",
|
|
1083
1131
|
...await commandRows(commands, colors),
|
|
1084
1132
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1092,8 +1140,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1092
1140
|
`);
|
|
1093
1141
|
}
|
|
1094
1142
|
function printError(prefix, message, hint, cause) {
|
|
1095
|
-
const colors = paint(
|
|
1096
|
-
const styled = takesControlCodes(
|
|
1143
|
+
const colors = paint(process15.stderr);
|
|
1144
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1097
1145
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1098
1146
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1099
1147
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1136,11 +1184,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1136
1184
|
}
|
|
1137
1185
|
}
|
|
1138
1186
|
if (name === undefined && level.path.length > 1) {
|
|
1139
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1187
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1140
1188
|
return 2;
|
|
1141
1189
|
}
|
|
1142
1190
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1143
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1191
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1144
1192
|
return 0;
|
|
1145
1193
|
}
|
|
1146
1194
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1196,24 +1244,24 @@ function candidateLine(candidate) {
|
|
|
1196
1244
|
}
|
|
1197
1245
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1198
1246
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1199
|
-
|
|
1247
|
+
const typed = [];
|
|
1200
1248
|
let at = 0;
|
|
1201
1249
|
while (at < before.length) {
|
|
1202
1250
|
const word = before[at];
|
|
1203
1251
|
if (word === "--") {
|
|
1204
|
-
|
|
1252
|
+
typed.push(...before.slice(at + 1));
|
|
1205
1253
|
break;
|
|
1206
1254
|
}
|
|
1207
1255
|
if (!word.startsWith("-"))
|
|
1208
|
-
|
|
1256
|
+
typed.push(word);
|
|
1209
1257
|
else if (takesValue(word))
|
|
1210
1258
|
at++;
|
|
1211
1259
|
at++;
|
|
1212
1260
|
}
|
|
1213
1261
|
const last = positionals.at(-1);
|
|
1214
|
-
if (
|
|
1215
|
-
return positionals[
|
|
1216
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1262
|
+
if (typed.length < positionals.length)
|
|
1263
|
+
return { name: positionals[typed.length], typed };
|
|
1264
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1217
1265
|
}
|
|
1218
1266
|
async function leafCandidates(run, words) {
|
|
1219
1267
|
const completing = await completingOf(run);
|
|
@@ -1221,12 +1269,12 @@ async function leafCandidates(run, words) {
|
|
|
1221
1269
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1222
1270
|
const flag = words.at(-2);
|
|
1223
1271
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1272
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1224
1273
|
if (option?.type === "string") {
|
|
1225
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1274
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1226
1275
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1227
1276
|
}
|
|
1228
|
-
const
|
|
1229
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1277
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1230
1278
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1231
1279
|
}
|
|
1232
1280
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1257,9 +1305,13 @@ async function printCandidates(found) {
|
|
|
1257
1305
|
return 0;
|
|
1258
1306
|
}
|
|
1259
1307
|
function packageVersion(entry = Bun.main) {
|
|
1260
|
-
|
|
1308
|
+
let resolved = entry;
|
|
1309
|
+
try {
|
|
1310
|
+
resolved = realpathSync2(entry);
|
|
1311
|
+
} catch {}
|
|
1312
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1261
1313
|
try {
|
|
1262
|
-
const { version } = JSON.parse(
|
|
1314
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1263
1315
|
if (typeof version === "string")
|
|
1264
1316
|
return version;
|
|
1265
1317
|
} catch {}
|
|
@@ -1267,14 +1319,17 @@ function packageVersion(entry = Bun.main) {
|
|
|
1267
1319
|
return "0.0.0";
|
|
1268
1320
|
}
|
|
1269
1321
|
}
|
|
1270
|
-
async function runCli(cli, argv =
|
|
1322
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1271
1323
|
const version = cli.version ?? packageVersion();
|
|
1272
1324
|
if (argv[0] === COMPLETE)
|
|
1273
1325
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1326
|
+
const started = performance.now();
|
|
1274
1327
|
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 });
|
|
1328
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1329
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1275
1330
|
if (cli.usage !== false) {
|
|
1276
1331
|
try {
|
|
1277
|
-
recordUsage(usageEntry(cli.name,
|
|
1332
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1278
1333
|
} catch {}
|
|
1279
1334
|
}
|
|
1280
1335
|
return code;
|
|
@@ -1294,7 +1349,7 @@ function commandPath(scope, argv) {
|
|
|
1294
1349
|
}
|
|
1295
1350
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1296
1351
|
}
|
|
1297
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1352
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1298
1353
|
if (argv[0] === COMPLETE)
|
|
1299
1354
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1300
1355
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1302,11 +1357,13 @@ async function runMain({ name, version, run, redact, usage }, argv = process13.a
|
|
|
1302
1357
|
return 0;
|
|
1303
1358
|
}
|
|
1304
1359
|
let code;
|
|
1360
|
+
const started = performance.now();
|
|
1305
1361
|
try {
|
|
1306
1362
|
code = await run(argv);
|
|
1307
1363
|
} catch (error) {
|
|
1308
1364
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1309
1365
|
}
|
|
1366
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1310
1367
|
if (usage !== false) {
|
|
1311
1368
|
try {
|
|
1312
1369
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1346,7 +1403,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1346
1403
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1347
1404
|
}
|
|
1348
1405
|
// ../kit/src/watch.ts
|
|
1349
|
-
import
|
|
1406
|
+
import process16 from "process";
|
|
1350
1407
|
import { format } from "util";
|
|
1351
1408
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1352
1409
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1368,7 +1425,7 @@ function withoutWatch(args) {
|
|
|
1368
1425
|
}
|
|
1369
1426
|
return rest;
|
|
1370
1427
|
}
|
|
1371
|
-
async function watching(value, step, stream =
|
|
1428
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1372
1429
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1373
1430
|
if (!takesControlCodes(stream))
|
|
1374
1431
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1376,12 +1433,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1376
1433
|
for (let round = 0;round < rounds; round++) {
|
|
1377
1434
|
const held = [];
|
|
1378
1435
|
const { log, info } = console;
|
|
1379
|
-
const write =
|
|
1436
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1380
1437
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1381
1438
|
`);
|
|
1382
1439
|
console.log = hold;
|
|
1383
1440
|
console.info = hold;
|
|
1384
|
-
|
|
1441
|
+
process16.stdout.write = (text) => {
|
|
1385
1442
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1386
1443
|
return true;
|
|
1387
1444
|
};
|
|
@@ -1390,7 +1447,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1390
1447
|
} finally {
|
|
1391
1448
|
console.log = log;
|
|
1392
1449
|
console.info = info;
|
|
1393
|
-
|
|
1450
|
+
process16.stdout.write = write;
|
|
1394
1451
|
}
|
|
1395
1452
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1396
1453
|
await sleep(interval);
|
|
@@ -1399,8 +1456,8 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1399
1456
|
}
|
|
1400
1457
|
// ../kit/src/workspace-root.ts
|
|
1401
1458
|
import { homedir as homedir4 } from "os";
|
|
1402
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1403
|
-
import
|
|
1459
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1460
|
+
import process17 from "process";
|
|
1404
1461
|
function expandHome(path, home) {
|
|
1405
1462
|
if (path === "~")
|
|
1406
1463
|
return home;
|
|
@@ -1410,18 +1467,22 @@ function configured(env, home) {
|
|
|
1410
1467
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1411
1468
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1412
1469
|
}
|
|
1413
|
-
function workspaceRoot({ given, env =
|
|
1470
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1414
1471
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1415
|
-
return
|
|
1472
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1416
1473
|
}
|
|
1417
1474
|
// src/audit.ts
|
|
1418
|
-
import { existsSync as
|
|
1475
|
+
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync7, statSync as statSync2 } from "fs";
|
|
1419
1476
|
import { readdir } from "fs/promises";
|
|
1420
|
-
import { join as
|
|
1421
|
-
import
|
|
1477
|
+
import { join as join9, relative, resolve as resolve5 } from "path";
|
|
1478
|
+
import process19 from "process";
|
|
1479
|
+
|
|
1480
|
+
// src/osv.ts
|
|
1481
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
1482
|
+
import { join as join8 } from "path";
|
|
1422
1483
|
|
|
1423
1484
|
// src/report.ts
|
|
1424
|
-
import { existsSync as existsSync4, readFileSync as
|
|
1485
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1425
1486
|
import { join as join7 } from "path";
|
|
1426
1487
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1427
1488
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1505,7 +1566,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1505
1566
|
}
|
|
1506
1567
|
function readManifest(path) {
|
|
1507
1568
|
try {
|
|
1508
|
-
return existsSync4(path) ? JSON.parse(
|
|
1569
|
+
return existsSync4(path) ? JSON.parse(readFileSync5(path, "utf8")) : {};
|
|
1509
1570
|
} catch {
|
|
1510
1571
|
return {};
|
|
1511
1572
|
}
|
|
@@ -1535,14 +1596,121 @@ function workspaceFolders(root, children) {
|
|
|
1535
1596
|
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]);
|
|
1536
1597
|
}
|
|
1537
1598
|
|
|
1599
|
+
// src/osv.ts
|
|
1600
|
+
var OSV = "https://api.osv.dev/v1";
|
|
1601
|
+
var BATCH = 1000;
|
|
1602
|
+
var DETAIL_CONCURRENCY = 8;
|
|
1603
|
+
var TIMEOUT_MS = 20000;
|
|
1604
|
+
var PACKAGE_BLOCK = /^\[\[package\]\]\s*$/m;
|
|
1605
|
+
var FIELD = /^(name|version|source) = (.+)$/gm;
|
|
1606
|
+
var QUOTED = /^"([^"]*)"$/;
|
|
1607
|
+
var LEADING_V = /^v/;
|
|
1608
|
+
function parseComposerLock(text) {
|
|
1609
|
+
const lock = JSON.parse(text);
|
|
1610
|
+
const entry = (prod) => (each) => ({ name: each.name, version: each.version.replace(LEADING_V, ""), prod });
|
|
1611
|
+
return [...(lock.packages ?? []).map(entry(true)), ...(lock["packages-dev"] ?? []).map(entry(false))];
|
|
1612
|
+
}
|
|
1613
|
+
function tomlPackages(text, fromRegistry) {
|
|
1614
|
+
const found = [];
|
|
1615
|
+
for (const block of text.split(PACKAGE_BLOCK).slice(1)) {
|
|
1616
|
+
const fields = new Map;
|
|
1617
|
+
for (const [, key, value] of block.matchAll(FIELD))
|
|
1618
|
+
fields.set(key, QUOTED.exec(value.trim())?.[1] ?? value.trim());
|
|
1619
|
+
const source = fields.get("source");
|
|
1620
|
+
const name = fields.get("name");
|
|
1621
|
+
const version = fields.get("version");
|
|
1622
|
+
if (name !== undefined && version !== undefined && source !== undefined && fromRegistry(source))
|
|
1623
|
+
found.push({ name, version, prod: true });
|
|
1624
|
+
}
|
|
1625
|
+
return found;
|
|
1626
|
+
}
|
|
1627
|
+
function parseCargoLock(text) {
|
|
1628
|
+
return tomlPackages(text, (source) => source.startsWith("registry+"));
|
|
1629
|
+
}
|
|
1630
|
+
function parseUvLock(text) {
|
|
1631
|
+
return tomlPackages(text, (source) => source.includes("registry"));
|
|
1632
|
+
}
|
|
1633
|
+
var ECOSYSTEMS = [
|
|
1634
|
+
{ lockfile: "composer.lock", osv: "Packagist", parse: parseComposerLock },
|
|
1635
|
+
{ lockfile: "Cargo.lock", osv: "crates.io", parse: parseCargoLock },
|
|
1636
|
+
{ lockfile: "uv.lock", osv: "PyPI", parse: parseUvLock }
|
|
1637
|
+
];
|
|
1638
|
+
function holdsOsvLock(dir) {
|
|
1639
|
+
return ECOSYSTEMS.some((each) => existsSync5(join8(dir, each.lockfile)));
|
|
1640
|
+
}
|
|
1641
|
+
var SEVERITY_NAMES = { LOW: "low", MODERATE: "moderate", MEDIUM: "moderate", HIGH: "high", CRITICAL: "critical" };
|
|
1642
|
+
async function ok2(response) {
|
|
1643
|
+
if (!response.ok)
|
|
1644
|
+
throw new Error(`osv.dev answered ${response.status}`);
|
|
1645
|
+
return response.json();
|
|
1646
|
+
}
|
|
1647
|
+
function rowOf(vuln, name) {
|
|
1648
|
+
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);
|
|
1649
|
+
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(" || ")) };
|
|
1650
|
+
}
|
|
1651
|
+
async function osvFindings(locked, ecosystem, direct, level, ignore, fetcher = fetch) {
|
|
1652
|
+
const hits = new Map;
|
|
1653
|
+
for (let start = 0;start < locked.length; start += BATCH) {
|
|
1654
|
+
const chunk = locked.slice(start, start + BATCH);
|
|
1655
|
+
const queries = chunk.map((each) => ({ package: { name: each.name, ecosystem }, version: each.version }));
|
|
1656
|
+
const answer = await ok2(await fetcher(`${OSV}/querybatch`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ queries }), signal: AbortSignal.timeout(TIMEOUT_MS) }));
|
|
1657
|
+
for (const [index, each] of chunk.entries()) {
|
|
1658
|
+
const ids = (answer.results[index]?.vulns ?? []).map((vuln) => vuln.id).filter((id) => !ignore.includes(id));
|
|
1659
|
+
if (ids.length > 0)
|
|
1660
|
+
hits.set(each, ids);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
const details = new Map;
|
|
1664
|
+
await pool([...new Set([...hits.values()].flat())], DETAIL_CONCURRENCY, async (id) => {
|
|
1665
|
+
details.set(id, await ok2(await fetcher(`${OSV}/vulns/${encodeURIComponent(id)}`, { signal: AbortSignal.timeout(TIMEOUT_MS) })));
|
|
1666
|
+
});
|
|
1667
|
+
const findings = [];
|
|
1668
|
+
let below = 0;
|
|
1669
|
+
for (const [each, ids] of hits) {
|
|
1670
|
+
const rows = ids.map((id) => rowOf(details.get(id), each.name));
|
|
1671
|
+
const advisories = rows.filter((row) => severityRank(row.severity) >= severityRank(level));
|
|
1672
|
+
below += rows.length - advisories.length;
|
|
1673
|
+
if (advisories.length === 0)
|
|
1674
|
+
continue;
|
|
1675
|
+
const fixes = advisories.map((row) => row.fixed);
|
|
1676
|
+
findings.push({
|
|
1677
|
+
package: each.name,
|
|
1678
|
+
severity: advisories.reduce((worst, row) => severityRank(row.severity) > severityRank(worst) ? row.severity : worst, advisories[0].severity),
|
|
1679
|
+
advisories,
|
|
1680
|
+
scope: each.prod ? "prod" : "dev",
|
|
1681
|
+
direct: direct.has(each.name),
|
|
1682
|
+
via: [],
|
|
1683
|
+
fix: fixes.includes(undefined) ? undefined : fixes.reduce((highest, fix) => Bun.semver.order(fix, highest) > 0 ? fix : highest)
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
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 };
|
|
1687
|
+
}
|
|
1688
|
+
function manifestNames(dir) {
|
|
1689
|
+
try {
|
|
1690
|
+
const manifest = JSON.parse(readFileSync6(join8(dir, "composer.json"), "utf8"));
|
|
1691
|
+
return new Set([...Object.keys(manifest.require ?? {}), ...Object.keys(manifest["require-dev"] ?? {})]);
|
|
1692
|
+
} catch {
|
|
1693
|
+
return new Set;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
async function osvAudit(dir, level, ignore, fetcher = fetch) {
|
|
1697
|
+
const all = { findings: [], below: 0 };
|
|
1698
|
+
for (const each of ECOSYSTEMS.filter((each) => existsSync5(join8(dir, each.lockfile)))) {
|
|
1699
|
+
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);
|
|
1700
|
+
all.findings.push(...done.findings);
|
|
1701
|
+
all.below += done.below;
|
|
1702
|
+
}
|
|
1703
|
+
return all;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1538
1706
|
// src/audit.ts
|
|
1539
|
-
var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun repositories under root (the current folder by default), one table per repository
|
|
1707
|
+
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
|
|
1540
1708
|
|
|
1541
1709
|
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.
|
|
1542
|
-
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
|
|
1710
|
+
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.
|
|
1543
1711
|
|
|
1544
1712
|
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.`;
|
|
1545
|
-
var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no
|
|
1713
|
+
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"]];
|
|
1546
1714
|
var OPTIONS = {
|
|
1547
1715
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
1548
1716
|
prod: { type: "boolean", description: "only the packages a production dependency needs" },
|
|
@@ -1557,8 +1725,11 @@ var VIA_SHOWN = 2;
|
|
|
1557
1725
|
function countAdvisories(findings) {
|
|
1558
1726
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1559
1727
|
}
|
|
1728
|
+
function holdsBunLock(dir) {
|
|
1729
|
+
return existsSync6(join9(dir, "bun.lock")) || existsSync6(join9(dir, "bun.lockb"));
|
|
1730
|
+
}
|
|
1560
1731
|
function holdsLock(dir) {
|
|
1561
|
-
return
|
|
1732
|
+
return holdsBunLock(dir) || holdsOsvLock(dir);
|
|
1562
1733
|
}
|
|
1563
1734
|
async function findRepos(root) {
|
|
1564
1735
|
if (holdsLock(root))
|
|
@@ -1574,7 +1745,7 @@ async function findRepos(root) {
|
|
|
1574
1745
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1575
1746
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith("."))
|
|
1576
1747
|
continue;
|
|
1577
|
-
const path =
|
|
1748
|
+
const path = join9(dir, entry.name);
|
|
1578
1749
|
if (holdsLock(path))
|
|
1579
1750
|
found.push(path);
|
|
1580
1751
|
else if (depth < MAX_DEPTH)
|
|
@@ -1587,13 +1758,24 @@ async function findRepos(root) {
|
|
|
1587
1758
|
function children(root) {
|
|
1588
1759
|
return (folder) => {
|
|
1589
1760
|
try {
|
|
1590
|
-
return readdirSync(
|
|
1761
|
+
return readdirSync(join9(root, folder), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
1591
1762
|
} catch {
|
|
1592
1763
|
return [];
|
|
1593
1764
|
}
|
|
1594
1765
|
};
|
|
1595
1766
|
}
|
|
1596
1767
|
async function audited(path, shown, level, ignore) {
|
|
1768
|
+
const bun = holdsBunLock(path) ? await bunAudited(path, shown, level, ignore) : { repo: shown, path, findings: [], below: 0, warnings: [], error: undefined };
|
|
1769
|
+
if (bun.error !== undefined || !holdsOsvLock(path))
|
|
1770
|
+
return bun;
|
|
1771
|
+
try {
|
|
1772
|
+
const osv = await osvAudit(path, level, ignore);
|
|
1773
|
+
return { ...bun, findings: [...bun.findings, ...osv.findings], below: bun.below + osv.below };
|
|
1774
|
+
} catch (error) {
|
|
1775
|
+
return { ...bun, error: `osv.dev: ${error instanceof Error ? error.message : String(error)}` };
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
async function bunAudited(path, shown, level, ignore) {
|
|
1597
1779
|
const [all, production] = await Promise.all([
|
|
1598
1780
|
runCommand(["bun", "audit", "--json"], { cwd: path, timeoutMs: AUDIT_MS }),
|
|
1599
1781
|
runCommand(["bun", "audit", "--json", "--prod"], { cwd: path, timeoutMs: AUDIT_MS })
|
|
@@ -1610,7 +1792,7 @@ async function audited(path, shown, level, ignore) {
|
|
|
1610
1792
|
}
|
|
1611
1793
|
function lockText(path) {
|
|
1612
1794
|
try {
|
|
1613
|
-
return
|
|
1795
|
+
return readFileSync7(join9(path, "bun.lock"), "utf8");
|
|
1614
1796
|
} catch {
|
|
1615
1797
|
return "";
|
|
1616
1798
|
}
|
|
@@ -1630,7 +1812,7 @@ function failure(ran) {
|
|
|
1630
1812
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1631
1813
|
}
|
|
1632
1814
|
function tint(severity) {
|
|
1633
|
-
const colors = paint(
|
|
1815
|
+
const colors = paint(process19.stdout);
|
|
1634
1816
|
if (severity === "critical" || severity === "high")
|
|
1635
1817
|
return colors.red;
|
|
1636
1818
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1647,13 +1829,13 @@ function rows(findings) {
|
|
|
1647
1829
|
}
|
|
1648
1830
|
async function audit(args) {
|
|
1649
1831
|
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"] });
|
|
1650
|
-
const root =
|
|
1651
|
-
if (!
|
|
1832
|
+
const root = resolve5(positionals[0] ?? ".");
|
|
1833
|
+
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1652
1834
|
fail(`no folder ${root}`);
|
|
1653
1835
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1654
1836
|
const paths = await findRepos(root);
|
|
1655
1837
|
if (paths.length === 0)
|
|
1656
|
-
fail(`no bun.lock under ${root}`);
|
|
1838
|
+
fail(`no bun.lock, composer.lock, Cargo.lock or uv.lock under ${root}`);
|
|
1657
1839
|
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1658
1840
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1659
1841
|
if (values.json === true)
|
|
@@ -1665,8 +1847,8 @@ async function audit(args) {
|
|
|
1665
1847
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1666
1848
|
}
|
|
1667
1849
|
function show(audits, total) {
|
|
1668
|
-
const label = role("label",
|
|
1669
|
-
const path = role("path",
|
|
1850
|
+
const label = role("label", process19.stdout);
|
|
1851
|
+
const path = role("path", process19.stdout);
|
|
1670
1852
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1671
1853
|
if (flagged.length === 0) {
|
|
1672
1854
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1686,15 +1868,15 @@ function show(audits, total) {
|
|
|
1686
1868
|
}
|
|
1687
1869
|
|
|
1688
1870
|
// src/repos.ts
|
|
1689
|
-
import { existsSync as
|
|
1871
|
+
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1690
1872
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1691
|
-
import
|
|
1873
|
+
import process21 from "process";
|
|
1692
1874
|
|
|
1693
1875
|
// src/repos-scan.ts
|
|
1694
|
-
import { existsSync as
|
|
1876
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1695
1877
|
import { readdir as readdir2 } from "fs/promises";
|
|
1696
|
-
import { basename, join as
|
|
1697
|
-
import
|
|
1878
|
+
import { basename, join as join10 } from "path";
|
|
1879
|
+
import process20 from "process";
|
|
1698
1880
|
var MAX_DEPTH2 = 3;
|
|
1699
1881
|
var CONCURRENCY2 = 8;
|
|
1700
1882
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1716,7 +1898,7 @@ function reasonsOf(repo) {
|
|
|
1716
1898
|
return reasons;
|
|
1717
1899
|
}
|
|
1718
1900
|
async function findRepos2(root, skip) {
|
|
1719
|
-
if (
|
|
1901
|
+
if (existsSync7(join10(root, ".git")))
|
|
1720
1902
|
return [root];
|
|
1721
1903
|
const found = [];
|
|
1722
1904
|
async function walk(dir, depth) {
|
|
@@ -1729,8 +1911,8 @@ async function findRepos2(root, skip) {
|
|
|
1729
1911
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1730
1912
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1731
1913
|
continue;
|
|
1732
|
-
const path =
|
|
1733
|
-
if (
|
|
1914
|
+
const path = join10(dir, entry.name);
|
|
1915
|
+
if (existsSync7(join10(path, ".git")))
|
|
1734
1916
|
found.push(path);
|
|
1735
1917
|
else if (depth < MAX_DEPTH2)
|
|
1736
1918
|
await walk(path, depth + 1);
|
|
@@ -1741,7 +1923,7 @@ async function findRepos2(root, skip) {
|
|
|
1741
1923
|
}
|
|
1742
1924
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1743
1925
|
try {
|
|
1744
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1926
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process20.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1745
1927
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1746
1928
|
} catch {
|
|
1747
1929
|
return;
|
|
@@ -1760,14 +1942,14 @@ async function packageReleases(path) {
|
|
|
1760
1942
|
names.add(name);
|
|
1761
1943
|
}
|
|
1762
1944
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1763
|
-
const folder = [
|
|
1945
|
+
const folder = [join10("packages", name), name].find((candidate) => existsSync7(join10(path, candidate)));
|
|
1764
1946
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1765
1947
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1766
1948
|
});
|
|
1767
1949
|
return releases.filter((release) => release !== undefined);
|
|
1768
1950
|
}
|
|
1769
|
-
async function inspect(path,
|
|
1770
|
-
const fetched =
|
|
1951
|
+
async function inspect(path, fetch2) {
|
|
1952
|
+
const fetched = fetch2 ? await read(path, ["fetch", "--quiet"], FETCH_MS) : "";
|
|
1771
1953
|
const [status, worktrees, packages] = await Promise.all([
|
|
1772
1954
|
read(path, ["status", "--porcelain=v2", "--branch"]),
|
|
1773
1955
|
read(path, ["worktree", "list", "--porcelain"]),
|
|
@@ -1818,7 +2000,7 @@ function firstLine(text) {
|
|
|
1818
2000
|
}
|
|
1819
2001
|
async function fastForward(path) {
|
|
1820
2002
|
try {
|
|
1821
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
2003
|
+
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 });
|
|
1822
2004
|
if (ran.timedOut)
|
|
1823
2005
|
return "timed out";
|
|
1824
2006
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1847,7 +2029,7 @@ var OPTIONS2 = {
|
|
|
1847
2029
|
};
|
|
1848
2030
|
async function skipped() {
|
|
1849
2031
|
const file = userConfigReadPath("repos");
|
|
1850
|
-
if (!
|
|
2032
|
+
if (!existsSync8(file))
|
|
1851
2033
|
return new Set;
|
|
1852
2034
|
try {
|
|
1853
2035
|
const config = await Bun.file(file).json();
|
|
@@ -1861,7 +2043,7 @@ function releasedCell(repo) {
|
|
|
1861
2043
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1862
2044
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1863
2045
|
}
|
|
1864
|
-
function syncCell(repo, stream =
|
|
2046
|
+
function syncCell(repo, stream = process21.stdout) {
|
|
1865
2047
|
const colors = paint(stream);
|
|
1866
2048
|
const ahead = repo.ahead ?? 0;
|
|
1867
2049
|
const behind = repo.behind ?? 0;
|
|
@@ -1872,7 +2054,7 @@ function syncCell(repo, stream = process19.stdout) {
|
|
|
1872
2054
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1873
2055
|
}
|
|
1874
2056
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1875
|
-
function branchCell(repo, stream =
|
|
2057
|
+
function branchCell(repo, stream = process21.stdout) {
|
|
1876
2058
|
const colors = paint(stream);
|
|
1877
2059
|
if (repo.unreadable)
|
|
1878
2060
|
return colors.red("? (unreadable)");
|
|
@@ -1881,8 +2063,8 @@ function branchCell(repo, stream = process19.stdout) {
|
|
|
1881
2063
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1882
2064
|
}
|
|
1883
2065
|
function row(repo, shown) {
|
|
1884
|
-
const colors = paint(
|
|
1885
|
-
const tint = role("path",
|
|
2066
|
+
const colors = paint(process21.stdout);
|
|
2067
|
+
const tint = role("path", process21.stdout);
|
|
1886
2068
|
const unreleased = releasedCell(repo);
|
|
1887
2069
|
return [
|
|
1888
2070
|
tint(shown),
|
|
@@ -1898,7 +2080,7 @@ async function repos(args) {
|
|
|
1898
2080
|
if (values.watch !== undefined)
|
|
1899
2081
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1900
2082
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1901
|
-
if (!
|
|
2083
|
+
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
1902
2084
|
fail(`no folder ${root}`);
|
|
1903
2085
|
const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
|
|
1904
2086
|
const paths = await findRepos2(root, await skipped());
|
|
@@ -1916,12 +2098,12 @@ async function repos(args) {
|
|
|
1916
2098
|
const blocker = pullBlocker(repo);
|
|
1917
2099
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1918
2100
|
if (blocker !== undefined) {
|
|
1919
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2101
|
+
log(marked("note", `${repo.name} skipped`, process21.stdout, blocker));
|
|
1920
2102
|
} else if (refused !== undefined) {
|
|
1921
2103
|
failedPulls++;
|
|
1922
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2104
|
+
log(marked("problem", `${repo.name} not pulled`, process21.stdout, refused));
|
|
1923
2105
|
} else {
|
|
1924
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2106
|
+
log(marked("ok", `${repo.name} pulled`, process21.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1925
2107
|
states[index] = await inspect(repo.path, false);
|
|
1926
2108
|
}
|
|
1927
2109
|
}
|
|
@@ -1936,7 +2118,7 @@ async function repos(args) {
|
|
|
1936
2118
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1937
2119
|
return failedPulls > 0 ? 1 : 0;
|
|
1938
2120
|
}
|
|
1939
|
-
const label = role("label",
|
|
2121
|
+
const label = role("label", process21.stdout);
|
|
1940
2122
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1941
2123
|
if (kept.length === 0) {
|
|
1942
2124
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1952,12 +2134,26 @@ async function repos(args) {
|
|
|
1952
2134
|
}
|
|
1953
2135
|
|
|
1954
2136
|
// src/sweep.ts
|
|
1955
|
-
import { existsSync as
|
|
2137
|
+
import { existsSync as existsSync11, statSync as statSync4 } from "fs";
|
|
1956
2138
|
import { homedir as homedir6 } from "os";
|
|
1957
2139
|
import { relative as relative3 } from "path";
|
|
1958
2140
|
|
|
1959
2141
|
// ../kit/src/prompt.ts
|
|
1960
|
-
import
|
|
2142
|
+
import process23 from "process";
|
|
2143
|
+
|
|
2144
|
+
// ../kit/src/job.ts
|
|
2145
|
+
import process22 from "process";
|
|
2146
|
+
function stopJob() {
|
|
2147
|
+
process22.kill(0, "SIGTSTP");
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
// ../kit/src/picker/line.ts
|
|
2151
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2152
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2153
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2154
|
+
function isEditKey(key) {
|
|
2155
|
+
return EDIT_KEYS.has(key);
|
|
2156
|
+
}
|
|
1961
2157
|
|
|
1962
2158
|
// ../kit/src/picker/score.ts
|
|
1963
2159
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1989,10 +2185,29 @@ var KEYS = {
|
|
|
1989
2185
|
"\n": "enter",
|
|
1990
2186
|
"\x03": "cancel",
|
|
1991
2187
|
"\x1B": "cancel",
|
|
2188
|
+
"\x1B[D": "left",
|
|
2189
|
+
"\x1BOD": "left",
|
|
2190
|
+
"\x1B[C": "right",
|
|
2191
|
+
"\x1BOC": "right",
|
|
2192
|
+
"\x1B[1;5D": "wordleft",
|
|
2193
|
+
"\x1B[1;3D": "wordleft",
|
|
2194
|
+
"\x1Bb": "wordleft",
|
|
2195
|
+
"\x1B[1;5C": "wordright",
|
|
2196
|
+
"\x1B[1;3C": "wordright",
|
|
2197
|
+
"\x1Bf": "wordright",
|
|
2198
|
+
"\x01": "linestart",
|
|
2199
|
+
"\x05": "lineend",
|
|
1992
2200
|
"\x7F": "erase",
|
|
1993
|
-
"\
|
|
2201
|
+
"\x1B[3~": "delete",
|
|
2202
|
+
"\b": "killword",
|
|
2203
|
+
"\x1B\x7F": "killword",
|
|
2204
|
+
"\x1B[3;5~": "killnext",
|
|
2205
|
+
"\x1Bd": "killnext",
|
|
1994
2206
|
"\x15": "clear",
|
|
2207
|
+
"\v": "killend",
|
|
1995
2208
|
"\x17": "word",
|
|
2209
|
+
"\x19": "yank",
|
|
2210
|
+
"\x1A": "suspend",
|
|
1996
2211
|
"\t": "tab",
|
|
1997
2212
|
"\x1F": "help",
|
|
1998
2213
|
"\x1BOP": "help",
|
|
@@ -2022,10 +2237,21 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
2022
2237
|
});
|
|
2023
2238
|
}
|
|
2024
2239
|
|
|
2240
|
+
// ../kit/src/redraw.ts
|
|
2241
|
+
var SYNC_START = "\x1B[?2026h";
|
|
2242
|
+
var SYNC_END = "\x1B[?2026l";
|
|
2243
|
+
function overwrite(lines, columns) {
|
|
2244
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2245
|
+
`);
|
|
2246
|
+
}
|
|
2247
|
+
function rowsTaken(lines, columns) {
|
|
2248
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2025
2251
|
// ../kit/src/prompt.ts
|
|
2026
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "
|
|
2252
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2027
2253
|
function readKeys(input, paste = { active: false }) {
|
|
2028
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
2254
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2029
2255
|
}
|
|
2030
2256
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2031
2257
|
let answered = fallback;
|
|
@@ -2049,7 +2275,7 @@ function asking(colors, question, typed, keys) {
|
|
|
2049
2275
|
function answer(colors, question, state, picked) {
|
|
2050
2276
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2051
2277
|
}
|
|
2052
|
-
async function ask(question, { hint, terminal =
|
|
2278
|
+
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2053
2279
|
const { stdin, stderr } = terminal;
|
|
2054
2280
|
if (!isInteractive(terminal))
|
|
2055
2281
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2059,12 +2285,22 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2059
2285
|
const columns = () => stderr.columns || 80;
|
|
2060
2286
|
const draw = (state, last = false) => {
|
|
2061
2287
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2062
|
-
|
|
2063
|
-
|
|
2288
|
+
const rows = rowsTaken(frame, columns());
|
|
2289
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2064
2290
|
current = state;
|
|
2065
2291
|
};
|
|
2066
2292
|
const redraw = () => draw(current);
|
|
2067
2293
|
const paste = { active: false };
|
|
2294
|
+
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2295
|
+
const suspend = () => {
|
|
2296
|
+
if (stop === undefined)
|
|
2297
|
+
return;
|
|
2298
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2299
|
+
stdin.setRawMode(false);
|
|
2300
|
+
stop();
|
|
2301
|
+
stdin.setRawMode(true);
|
|
2302
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2303
|
+
};
|
|
2068
2304
|
try {
|
|
2069
2305
|
stderr.on?.("resize", redraw);
|
|
2070
2306
|
stdin.setRawMode(true);
|
|
@@ -2074,6 +2310,10 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2074
2310
|
return await new Promise((resolve) => {
|
|
2075
2311
|
function onData(data) {
|
|
2076
2312
|
for (const key of readKeys(data.toString(), paste)) {
|
|
2313
|
+
if (key === "suspend") {
|
|
2314
|
+
suspend();
|
|
2315
|
+
continue;
|
|
2316
|
+
}
|
|
2077
2317
|
const pressed = press(key);
|
|
2078
2318
|
if (pressed !== undefined) {
|
|
2079
2319
|
settle(pressed);
|
|
@@ -2105,19 +2345,19 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2105
2345
|
}
|
|
2106
2346
|
|
|
2107
2347
|
// src/apply.ts
|
|
2108
|
-
import { existsSync as
|
|
2348
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2109
2349
|
import { lstat as lstat3, rm } from "fs/promises";
|
|
2110
|
-
import { basename as basename4, join as
|
|
2350
|
+
import { basename as basename4, join as join13 } from "path";
|
|
2111
2351
|
|
|
2112
2352
|
// src/sweep-scan.ts
|
|
2113
|
-
import { existsSync as
|
|
2353
|
+
import { existsSync as existsSync9 } from "fs";
|
|
2114
2354
|
import { lstat as lstat2, readdir as readdir4, realpath } from "fs/promises";
|
|
2115
2355
|
import { homedir as homedir5 } from "os";
|
|
2116
|
-
import { basename as basename3, dirname as dirname5, join as
|
|
2356
|
+
import { basename as basename3, dirname as dirname5, join as join12 } from "path";
|
|
2117
2357
|
|
|
2118
2358
|
// src/size.ts
|
|
2119
2359
|
import { lstat, readdir as readdir3 } from "fs/promises";
|
|
2120
|
-
import { join as
|
|
2360
|
+
import { join as join11 } from "path";
|
|
2121
2361
|
var FS_LIMIT = 32;
|
|
2122
2362
|
var FIND_MS = 60000;
|
|
2123
2363
|
var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
|
|
@@ -2145,7 +2385,7 @@ async function walkSize(folder) {
|
|
|
2145
2385
|
return;
|
|
2146
2386
|
}
|
|
2147
2387
|
await Promise.all(entries.map(async (entry) => {
|
|
2148
|
-
const path =
|
|
2388
|
+
const path = join11(dir, entry.name);
|
|
2149
2389
|
if (entry.isDirectory())
|
|
2150
2390
|
return visit(path);
|
|
2151
2391
|
try {
|
|
@@ -2189,12 +2429,13 @@ async function sizeOf(folder) {
|
|
|
2189
2429
|
}
|
|
2190
2430
|
|
|
2191
2431
|
// src/sweep-scan.ts
|
|
2192
|
-
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
|
|
2432
|
+
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target", "vendor", ".venv", "__pycache__", ".gradle"]);
|
|
2433
|
+
var NEEDS_BESIDE = { target: ["Cargo.toml"], vendor: ["composer.json", "composer.lock"] };
|
|
2193
2434
|
var MAX_DEPTH3 = 3;
|
|
2194
|
-
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
|
|
2435
|
+
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit", "__pycache__", ".gradle"]);
|
|
2195
2436
|
var GLOBAL_CACHES = [".bun/install/cache", ".npm/_cacache", ".cache/pip", ".cache/uv", ".cache/ms-playwright", ".cache/puppeteer", ".cache/go-build", ".cache/typescript", ".cargo/registry"];
|
|
2196
2437
|
function isCachePath(path, home = homedir5()) {
|
|
2197
|
-
return GLOBAL_CACHES.some((cache) =>
|
|
2438
|
+
return GLOBAL_CACHES.some((cache) => join12(home, cache) === path) || basename3(path) === ".cache" && basename3(dirname5(path)) === "node_modules";
|
|
2198
2439
|
}
|
|
2199
2440
|
async function listing(dir) {
|
|
2200
2441
|
try {
|
|
@@ -2205,7 +2446,7 @@ async function listing(dir) {
|
|
|
2205
2446
|
}
|
|
2206
2447
|
async function addGlobalCaches(found, home) {
|
|
2207
2448
|
for (const cache of GLOBAL_CACHES) {
|
|
2208
|
-
const path =
|
|
2449
|
+
const path = join12(home, cache);
|
|
2209
2450
|
try {
|
|
2210
2451
|
const stat = await lstat2(path);
|
|
2211
2452
|
if (stat.isSymbolicLink())
|
|
@@ -2220,7 +2461,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2220
2461
|
const visit = async (dir, depth) => {
|
|
2221
2462
|
const entries = await listing(dir);
|
|
2222
2463
|
for (const entry of entries) {
|
|
2223
|
-
const path =
|
|
2464
|
+
const path = join12(dir, entry.name);
|
|
2224
2465
|
if (entry.name === ".git")
|
|
2225
2466
|
continue;
|
|
2226
2467
|
if (entry.name === ".worktrees" || entry.name === "worktrees" && basename3(dir) === ".claude") {
|
|
@@ -2230,13 +2471,13 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2230
2471
|
}
|
|
2231
2472
|
for (const worktree of await listing(path)) {
|
|
2232
2473
|
if (worktree.isDirectory())
|
|
2233
|
-
found.candidates.push({ path:
|
|
2474
|
+
found.candidates.push({ path: join12(path, worktree.name), kind: "worktree" });
|
|
2234
2475
|
else if (worktree.isSymbolicLink())
|
|
2235
|
-
found.skipped.push({ path:
|
|
2476
|
+
found.skipped.push({ path: join12(path, worktree.name), reason: "symlink" });
|
|
2236
2477
|
}
|
|
2237
2478
|
continue;
|
|
2238
2479
|
}
|
|
2239
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name
|
|
2480
|
+
if (FOLDER_NAMES.has(entry.name) && (NEEDS_BESIDE[entry.name]?.some((file) => existsSync9(join12(dir, file))) ?? true)) {
|
|
2240
2481
|
if (entry.isSymbolicLink()) {
|
|
2241
2482
|
found.skipped.push({ path, reason: "symlink" });
|
|
2242
2483
|
} else if (entry.isDirectory()) {
|
|
@@ -2244,9 +2485,9 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2244
2485
|
if (entry.name === "node_modules") {
|
|
2245
2486
|
const cache = (await listing(path)).find((inner) => inner.name === ".cache");
|
|
2246
2487
|
if (cache?.isSymbolicLink())
|
|
2247
|
-
found.skipped.push({ path:
|
|
2488
|
+
found.skipped.push({ path: join12(path, ".cache"), reason: "symlink" });
|
|
2248
2489
|
else if (cache?.isDirectory())
|
|
2249
|
-
found.candidates.push({ path:
|
|
2490
|
+
found.candidates.push({ path: join12(path, ".cache"), kind: "cache", inside: path });
|
|
2250
2491
|
}
|
|
2251
2492
|
}
|
|
2252
2493
|
continue;
|
|
@@ -2322,7 +2563,7 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2322
2563
|
const located = await toplevelOf(parent);
|
|
2323
2564
|
if (located === "failed")
|
|
2324
2565
|
return { skip: "git failed" };
|
|
2325
|
-
if (
|
|
2566
|
+
if (existsSync9(join12(path, ".git")))
|
|
2326
2567
|
return { skip: "holds a git repository" };
|
|
2327
2568
|
if (located === "none")
|
|
2328
2569
|
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
@@ -2390,7 +2631,7 @@ async function removeFolder(entry) {
|
|
|
2390
2631
|
const stat = await lstat3(entry.path);
|
|
2391
2632
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename4(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
|
|
2392
2633
|
return { path: entry.path, removed: false, error: "no longer a plain folder" };
|
|
2393
|
-
if (
|
|
2634
|
+
if (existsSync10(join13(entry.path, ".git")))
|
|
2394
2635
|
return { path: entry.path, removed: false, error: "holds a git repository" };
|
|
2395
2636
|
await rm(entry.path, { recursive: true, force: true });
|
|
2396
2637
|
return { path: entry.path, removed: true };
|
|
@@ -2423,18 +2664,17 @@ async function applyAll(entries, done) {
|
|
|
2423
2664
|
// src/sweep.ts
|
|
2424
2665
|
var LARGE = 100 * 1024 ** 2;
|
|
2425
2666
|
var BIG = 1024 ** 3;
|
|
2426
|
-
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
|
|
2427
|
-
|
|
2428
|
-
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.
|
|
2667
|
+
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
|
|
2429
2668
|
|
|
2430
|
-
|
|
2669
|
+
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.`;
|
|
2670
|
+
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"]];
|
|
2431
2671
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
2432
2672
|
var OPTIONS3 = {
|
|
2433
2673
|
apply: { type: "boolean", description: "delete what is listed as removable, after the confirm" },
|
|
2434
2674
|
yes: { type: "boolean", short: "y", description: "with --apply, skip the confirm" },
|
|
2435
2675
|
older: { type: "string", description: "only the entries whose repo last committed longer ago than this (30d, 12h)" },
|
|
2436
2676
|
min: { type: "string", description: "only the entries of at least this size (500K, 10M, 1G)" },
|
|
2437
|
-
only: { type: "string", description: "worktrees, folders or caches: leave the other kinds out (.nuxt, .next, .turbo
|
|
2677
|
+
only: { type: "string", description: "worktrees, folders or caches: 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)" },
|
|
2438
2678
|
docker: { type: "boolean", description: "add the docker system df output, which alone takes about ten seconds" },
|
|
2439
2679
|
json: jsonOption("{root, entries: [{path, kind (folder, worktree or cache), bytes, committedAt, action (remove or keep), reason}], skipped: [{path, reason}], reclaimable, docker, removed?}")
|
|
2440
2680
|
};
|
|
@@ -2449,11 +2689,11 @@ async function dockerUsage() {
|
|
|
2449
2689
|
}
|
|
2450
2690
|
}
|
|
2451
2691
|
async function sweep(args) {
|
|
2452
|
-
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["sweep", "sweep ~/Workspace --older 30d --min 100M --apply", "sweep --only worktrees --apply"] });
|
|
2692
|
+
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["sweep", "sweep ~/Workspace --older 30d --min 100M --apply", "sweep --only worktrees --apply"] });
|
|
2453
2693
|
if (positionals.length > 1)
|
|
2454
2694
|
badUsage("give one root");
|
|
2455
2695
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2456
|
-
if (!
|
|
2696
|
+
if (!existsSync11(root) || !statSync4(root).isDirectory())
|
|
2457
2697
|
fail(`${root} is not a folder`);
|
|
2458
2698
|
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
2459
2699
|
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
@@ -2527,7 +2767,7 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2527
2767
|
}
|
|
2528
2768
|
|
|
2529
2769
|
// src/cli.ts
|
|
2530
|
-
|
|
2770
|
+
process24.exitCode = await runCli({
|
|
2531
2771
|
name: "ws",
|
|
2532
2772
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2533
2773
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|
|
@@ -2535,6 +2775,6 @@ process21.exitCode = await runCli({
|
|
|
2535
2775
|
commands: {
|
|
2536
2776
|
repos: { summary: "the git repositories that need attention: dirty, ahead or behind, worktrees, unreleased commits", run: repos },
|
|
2537
2777
|
sweep: { summary: "the regenerable folders, caches and clean worktrees, largest first, deleted only on --apply", run: sweep },
|
|
2538
|
-
audit: { summary: "the known vulnerabilities of the Bun repositories, one table per repository", run: audit }
|
|
2778
|
+
audit: { summary: "the known vulnerabilities of the Bun, Composer, Cargo and uv repositories, one table per repository", run: audit }
|
|
2539
2779
|
}
|
|
2540
2780
|
});
|