@kaynooo/cli-workspace 0.10.1 → 0.10.2
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 +81 -58
- package/dist/cli.js +98 -76
- package/dist/repos-cli.js +83 -60
- package/dist/sweep-cli.js +76 -54
- 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 process22 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -523,18 +523,14 @@ 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";
|
|
@@ -821,9 +817,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
821
817
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
822
818
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
823
819
|
}
|
|
820
|
+
// ../kit/src/argv.ts
|
|
821
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
822
|
+
import { resolve as resolve3 } from "path";
|
|
823
|
+
import process10 from "process";
|
|
824
|
+
function commandLine() {
|
|
825
|
+
try {
|
|
826
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
827
|
+
} catch {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function realPath(word) {
|
|
832
|
+
try {
|
|
833
|
+
return realpathSync(resolve3(word));
|
|
834
|
+
} catch {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
839
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
840
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
841
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
842
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
843
|
+
}
|
|
824
844
|
// ../kit/src/process.ts
|
|
825
845
|
import { constants } from "os";
|
|
826
|
-
import
|
|
846
|
+
import process11 from "process";
|
|
827
847
|
var KILL_GRACE_MS = 2000;
|
|
828
848
|
function exitCodeOf(code, signal) {
|
|
829
849
|
if (code !== null)
|
|
@@ -843,7 +863,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
843
863
|
return;
|
|
844
864
|
try {
|
|
845
865
|
if (grouped)
|
|
846
|
-
|
|
866
|
+
process11.kill(-proc.pid, killing);
|
|
847
867
|
else
|
|
848
868
|
proc.kill(killing);
|
|
849
869
|
} catch {}
|
|
@@ -918,10 +938,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
918
938
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
919
939
|
|
|
920
940
|
// ../kit/src/tool.ts
|
|
921
|
-
import
|
|
941
|
+
import process12 from "process";
|
|
922
942
|
function cwdGone() {
|
|
923
943
|
try {
|
|
924
|
-
|
|
944
|
+
process12.cwd();
|
|
925
945
|
return false;
|
|
926
946
|
} catch {
|
|
927
947
|
return true;
|
|
@@ -943,7 +963,7 @@ function spawnFailure(command, error) {
|
|
|
943
963
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
944
964
|
let ran;
|
|
945
965
|
try {
|
|
946
|
-
ran = await runCommand(argv, { env:
|
|
966
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
947
967
|
} catch (error) {
|
|
948
968
|
throw spawnFailure(label, error);
|
|
949
969
|
}
|
|
@@ -958,15 +978,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
958
978
|
return { code: ran.code, ...streams };
|
|
959
979
|
}
|
|
960
980
|
// ../kit/src/cli.ts
|
|
961
|
-
import { readFileSync as
|
|
981
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
962
982
|
import { dirname as dirname3, join as join5 } from "path";
|
|
963
|
-
import
|
|
983
|
+
import process14 from "process";
|
|
964
984
|
|
|
965
985
|
// ../kit/src/usage.ts
|
|
966
986
|
import { appendFileSync, mkdirSync } from "fs";
|
|
967
987
|
import { homedir as homedir3 } from "os";
|
|
968
988
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
969
|
-
import
|
|
989
|
+
import process13 from "process";
|
|
970
990
|
|
|
971
991
|
// ../kit/src/logs.ts
|
|
972
992
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -980,14 +1000,14 @@ var usageError;
|
|
|
980
1000
|
function noteUsageError(message) {
|
|
981
1001
|
usageError = message;
|
|
982
1002
|
}
|
|
983
|
-
function stateHome(env =
|
|
1003
|
+
function stateHome(env = process13.env) {
|
|
984
1004
|
const dir = env.XDG_STATE_HOME;
|
|
985
1005
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
986
1006
|
}
|
|
987
|
-
function usagePath(env =
|
|
1007
|
+
function usagePath(env = process13.env) {
|
|
988
1008
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
989
1009
|
}
|
|
990
|
-
function usageRecorded(env =
|
|
1010
|
+
function usageRecorded(env = process13.env) {
|
|
991
1011
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
992
1012
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
993
1013
|
}
|
|
@@ -1001,7 +1021,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1001
1021
|
usageError = undefined;
|
|
1002
1022
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1003
1023
|
}
|
|
1004
|
-
function recordUsage(entry, env =
|
|
1024
|
+
function recordUsage(entry, env = process13.env) {
|
|
1005
1025
|
if (!usageRecorded(env))
|
|
1006
1026
|
return;
|
|
1007
1027
|
try {
|
|
@@ -1078,7 +1098,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1078
1098
|
header(colors, summary),
|
|
1079
1099
|
"",
|
|
1080
1100
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1081
|
-
...replacesRows(replaces, colors),
|
|
1082
1101
|
"",
|
|
1083
1102
|
...await commandRows(commands, colors),
|
|
1084
1103
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1092,8 +1111,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1092
1111
|
`);
|
|
1093
1112
|
}
|
|
1094
1113
|
function printError(prefix, message, hint, cause) {
|
|
1095
|
-
const colors = paint(
|
|
1096
|
-
const styled = takesControlCodes(
|
|
1114
|
+
const colors = paint(process14.stderr);
|
|
1115
|
+
const styled = takesControlCodes(process14.stderr);
|
|
1097
1116
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1098
1117
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1099
1118
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1136,11 +1155,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1136
1155
|
}
|
|
1137
1156
|
}
|
|
1138
1157
|
if (name === undefined && level.path.length > 1) {
|
|
1139
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1158
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
1140
1159
|
return 2;
|
|
1141
1160
|
}
|
|
1142
1161
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1143
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1162
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
1144
1163
|
return 0;
|
|
1145
1164
|
}
|
|
1146
1165
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1196,24 +1215,24 @@ function candidateLine(candidate) {
|
|
|
1196
1215
|
}
|
|
1197
1216
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1198
1217
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1199
|
-
|
|
1218
|
+
const typed = [];
|
|
1200
1219
|
let at = 0;
|
|
1201
1220
|
while (at < before.length) {
|
|
1202
1221
|
const word = before[at];
|
|
1203
1222
|
if (word === "--") {
|
|
1204
|
-
|
|
1223
|
+
typed.push(...before.slice(at + 1));
|
|
1205
1224
|
break;
|
|
1206
1225
|
}
|
|
1207
1226
|
if (!word.startsWith("-"))
|
|
1208
|
-
|
|
1227
|
+
typed.push(word);
|
|
1209
1228
|
else if (takesValue(word))
|
|
1210
1229
|
at++;
|
|
1211
1230
|
at++;
|
|
1212
1231
|
}
|
|
1213
1232
|
const last = positionals.at(-1);
|
|
1214
|
-
if (
|
|
1215
|
-
return positionals[
|
|
1216
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1233
|
+
if (typed.length < positionals.length)
|
|
1234
|
+
return { name: positionals[typed.length], typed };
|
|
1235
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1217
1236
|
}
|
|
1218
1237
|
async function leafCandidates(run, words) {
|
|
1219
1238
|
const completing = await completingOf(run);
|
|
@@ -1221,12 +1240,12 @@ async function leafCandidates(run, words) {
|
|
|
1221
1240
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1222
1241
|
const flag = words.at(-2);
|
|
1223
1242
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1243
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1224
1244
|
if (option?.type === "string") {
|
|
1225
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1245
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1226
1246
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1227
1247
|
}
|
|
1228
|
-
const
|
|
1229
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1248
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1230
1249
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1231
1250
|
}
|
|
1232
1251
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1257,9 +1276,13 @@ async function printCandidates(found) {
|
|
|
1257
1276
|
return 0;
|
|
1258
1277
|
}
|
|
1259
1278
|
function packageVersion(entry = Bun.main) {
|
|
1260
|
-
|
|
1279
|
+
let resolved = entry;
|
|
1280
|
+
try {
|
|
1281
|
+
resolved = realpathSync2(entry);
|
|
1282
|
+
} catch {}
|
|
1283
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1261
1284
|
try {
|
|
1262
|
-
const { version } = JSON.parse(
|
|
1285
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1263
1286
|
if (typeof version === "string")
|
|
1264
1287
|
return version;
|
|
1265
1288
|
} catch {}
|
|
@@ -1267,7 +1290,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1267
1290
|
return "0.0.0";
|
|
1268
1291
|
}
|
|
1269
1292
|
}
|
|
1270
|
-
async function runCli(cli, argv =
|
|
1293
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1271
1294
|
const version = cli.version ?? packageVersion();
|
|
1272
1295
|
if (argv[0] === COMPLETE)
|
|
1273
1296
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1294,7 +1317,7 @@ function commandPath(scope, argv) {
|
|
|
1294
1317
|
}
|
|
1295
1318
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1296
1319
|
}
|
|
1297
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1320
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1298
1321
|
if (argv[0] === COMPLETE)
|
|
1299
1322
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1300
1323
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1346,7 +1369,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1346
1369
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1347
1370
|
}
|
|
1348
1371
|
// ../kit/src/watch.ts
|
|
1349
|
-
import
|
|
1372
|
+
import process15 from "process";
|
|
1350
1373
|
import { format } from "util";
|
|
1351
1374
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1352
1375
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1368,7 +1391,7 @@ function withoutWatch(args) {
|
|
|
1368
1391
|
}
|
|
1369
1392
|
return rest;
|
|
1370
1393
|
}
|
|
1371
|
-
async function watching(value, step, stream =
|
|
1394
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1372
1395
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1373
1396
|
if (!takesControlCodes(stream))
|
|
1374
1397
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1376,12 +1399,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1376
1399
|
for (let round = 0;round < rounds; round++) {
|
|
1377
1400
|
const held = [];
|
|
1378
1401
|
const { log, info } = console;
|
|
1379
|
-
const write =
|
|
1402
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1380
1403
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1381
1404
|
`);
|
|
1382
1405
|
console.log = hold;
|
|
1383
1406
|
console.info = hold;
|
|
1384
|
-
|
|
1407
|
+
process15.stdout.write = (text) => {
|
|
1385
1408
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1386
1409
|
return true;
|
|
1387
1410
|
};
|
|
@@ -1390,7 +1413,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1390
1413
|
} finally {
|
|
1391
1414
|
console.log = log;
|
|
1392
1415
|
console.info = info;
|
|
1393
|
-
|
|
1416
|
+
process15.stdout.write = write;
|
|
1394
1417
|
}
|
|
1395
1418
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1396
1419
|
await sleep(interval);
|
|
@@ -1399,8 +1422,8 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1399
1422
|
}
|
|
1400
1423
|
// ../kit/src/workspace-root.ts
|
|
1401
1424
|
import { homedir as homedir4 } from "os";
|
|
1402
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1403
|
-
import
|
|
1425
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1426
|
+
import process16 from "process";
|
|
1404
1427
|
function expandHome(path, home) {
|
|
1405
1428
|
if (path === "~")
|
|
1406
1429
|
return home;
|
|
@@ -1410,18 +1433,18 @@ function configured(env, home) {
|
|
|
1410
1433
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1411
1434
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1412
1435
|
}
|
|
1413
|
-
function workspaceRoot({ given, env =
|
|
1436
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1414
1437
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1415
|
-
return
|
|
1438
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1416
1439
|
}
|
|
1417
1440
|
// src/audit.ts
|
|
1418
|
-
import { existsSync as existsSync5, readdirSync, readFileSync as
|
|
1441
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
|
|
1419
1442
|
import { readdir } from "fs/promises";
|
|
1420
|
-
import { join as join8, relative, resolve as
|
|
1421
|
-
import
|
|
1443
|
+
import { join as join8, relative, resolve as resolve5 } from "path";
|
|
1444
|
+
import process18 from "process";
|
|
1422
1445
|
|
|
1423
1446
|
// src/report.ts
|
|
1424
|
-
import { existsSync as existsSync4, readFileSync as
|
|
1447
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1425
1448
|
import { join as join7 } from "path";
|
|
1426
1449
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1427
1450
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1505,7 +1528,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1505
1528
|
}
|
|
1506
1529
|
function readManifest(path) {
|
|
1507
1530
|
try {
|
|
1508
|
-
return existsSync4(path) ? JSON.parse(
|
|
1531
|
+
return existsSync4(path) ? JSON.parse(readFileSync5(path, "utf8")) : {};
|
|
1509
1532
|
} catch {
|
|
1510
1533
|
return {};
|
|
1511
1534
|
}
|
|
@@ -1610,7 +1633,7 @@ async function audited(path, shown, level, ignore) {
|
|
|
1610
1633
|
}
|
|
1611
1634
|
function lockText(path) {
|
|
1612
1635
|
try {
|
|
1613
|
-
return
|
|
1636
|
+
return readFileSync6(join8(path, "bun.lock"), "utf8");
|
|
1614
1637
|
} catch {
|
|
1615
1638
|
return "";
|
|
1616
1639
|
}
|
|
@@ -1630,7 +1653,7 @@ function failure(ran) {
|
|
|
1630
1653
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1631
1654
|
}
|
|
1632
1655
|
function tint(severity) {
|
|
1633
|
-
const colors = paint(
|
|
1656
|
+
const colors = paint(process18.stdout);
|
|
1634
1657
|
if (severity === "critical" || severity === "high")
|
|
1635
1658
|
return colors.red;
|
|
1636
1659
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1647,7 +1670,7 @@ function rows(findings) {
|
|
|
1647
1670
|
}
|
|
1648
1671
|
async function audit(args) {
|
|
1649
1672
|
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 =
|
|
1673
|
+
const root = resolve5(positionals[0] ?? ".");
|
|
1651
1674
|
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1652
1675
|
fail(`no folder ${root}`);
|
|
1653
1676
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
@@ -1665,8 +1688,8 @@ async function audit(args) {
|
|
|
1665
1688
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1666
1689
|
}
|
|
1667
1690
|
function show(audits, total) {
|
|
1668
|
-
const label = role("label",
|
|
1669
|
-
const path = role("path",
|
|
1691
|
+
const label = role("label", process18.stdout);
|
|
1692
|
+
const path = role("path", process18.stdout);
|
|
1670
1693
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1671
1694
|
if (flagged.length === 0) {
|
|
1672
1695
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1688,13 +1711,13 @@ function show(audits, total) {
|
|
|
1688
1711
|
// src/repos.ts
|
|
1689
1712
|
import { existsSync as existsSync7, statSync as statSync3 } from "fs";
|
|
1690
1713
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1691
|
-
import
|
|
1714
|
+
import process20 from "process";
|
|
1692
1715
|
|
|
1693
1716
|
// src/repos-scan.ts
|
|
1694
1717
|
import { existsSync as existsSync6 } from "fs";
|
|
1695
1718
|
import { readdir as readdir2 } from "fs/promises";
|
|
1696
1719
|
import { basename, join as join9 } from "path";
|
|
1697
|
-
import
|
|
1720
|
+
import process19 from "process";
|
|
1698
1721
|
var MAX_DEPTH2 = 3;
|
|
1699
1722
|
var CONCURRENCY2 = 8;
|
|
1700
1723
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1741,7 +1764,7 @@ async function findRepos2(root, skip) {
|
|
|
1741
1764
|
}
|
|
1742
1765
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1743
1766
|
try {
|
|
1744
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1767
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1745
1768
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1746
1769
|
} catch {
|
|
1747
1770
|
return;
|
|
@@ -1818,7 +1841,7 @@ function firstLine(text) {
|
|
|
1818
1841
|
}
|
|
1819
1842
|
async function fastForward(path) {
|
|
1820
1843
|
try {
|
|
1821
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1844
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1822
1845
|
if (ran.timedOut)
|
|
1823
1846
|
return "timed out";
|
|
1824
1847
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1861,7 +1884,7 @@ function releasedCell(repo) {
|
|
|
1861
1884
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1862
1885
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1863
1886
|
}
|
|
1864
|
-
function syncCell(repo, stream =
|
|
1887
|
+
function syncCell(repo, stream = process20.stdout) {
|
|
1865
1888
|
const colors = paint(stream);
|
|
1866
1889
|
const ahead = repo.ahead ?? 0;
|
|
1867
1890
|
const behind = repo.behind ?? 0;
|
|
@@ -1872,7 +1895,7 @@ function syncCell(repo, stream = process19.stdout) {
|
|
|
1872
1895
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1873
1896
|
}
|
|
1874
1897
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1875
|
-
function branchCell(repo, stream =
|
|
1898
|
+
function branchCell(repo, stream = process20.stdout) {
|
|
1876
1899
|
const colors = paint(stream);
|
|
1877
1900
|
if (repo.unreadable)
|
|
1878
1901
|
return colors.red("? (unreadable)");
|
|
@@ -1881,8 +1904,8 @@ function branchCell(repo, stream = process19.stdout) {
|
|
|
1881
1904
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1882
1905
|
}
|
|
1883
1906
|
function row(repo, shown) {
|
|
1884
|
-
const colors = paint(
|
|
1885
|
-
const tint = role("path",
|
|
1907
|
+
const colors = paint(process20.stdout);
|
|
1908
|
+
const tint = role("path", process20.stdout);
|
|
1886
1909
|
const unreleased = releasedCell(repo);
|
|
1887
1910
|
return [
|
|
1888
1911
|
tint(shown),
|
|
@@ -1916,12 +1939,12 @@ async function repos(args) {
|
|
|
1916
1939
|
const blocker = pullBlocker(repo);
|
|
1917
1940
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1918
1941
|
if (blocker !== undefined) {
|
|
1919
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1942
|
+
log(marked("note", `${repo.name} skipped`, process20.stdout, blocker));
|
|
1920
1943
|
} else if (refused !== undefined) {
|
|
1921
1944
|
failedPulls++;
|
|
1922
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1945
|
+
log(marked("problem", `${repo.name} not pulled`, process20.stdout, refused));
|
|
1923
1946
|
} else {
|
|
1924
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1947
|
+
log(marked("ok", `${repo.name} pulled`, process20.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1925
1948
|
states[index] = await inspect(repo.path, false);
|
|
1926
1949
|
}
|
|
1927
1950
|
}
|
|
@@ -1936,7 +1959,7 @@ async function repos(args) {
|
|
|
1936
1959
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1937
1960
|
return failedPulls > 0 ? 1 : 0;
|
|
1938
1961
|
}
|
|
1939
|
-
const label = role("label",
|
|
1962
|
+
const label = role("label", process20.stdout);
|
|
1940
1963
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1941
1964
|
if (kept.length === 0) {
|
|
1942
1965
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1957,7 +1980,7 @@ import { homedir as homedir6 } from "os";
|
|
|
1957
1980
|
import { relative as relative3 } from "path";
|
|
1958
1981
|
|
|
1959
1982
|
// ../kit/src/prompt.ts
|
|
1960
|
-
import
|
|
1983
|
+
import process21 from "process";
|
|
1961
1984
|
|
|
1962
1985
|
// ../kit/src/picker/score.ts
|
|
1963
1986
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -2049,7 +2072,7 @@ function asking(colors, question, typed, keys) {
|
|
|
2049
2072
|
function answer(colors, question, state, picked) {
|
|
2050
2073
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2051
2074
|
}
|
|
2052
|
-
async function ask(question, { hint, terminal =
|
|
2075
|
+
async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
2053
2076
|
const { stdin, stderr } = terminal;
|
|
2054
2077
|
if (!isInteractive(terminal))
|
|
2055
2078
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2425,9 +2448,8 @@ var LARGE = 100 * 1024 ** 2;
|
|
|
2425
2448
|
var BIG = 1024 ** 3;
|
|
2426
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
|
|
2427
2450
|
|
|
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
|
|
2429
|
-
|
|
2430
|
-
Exits 0 when it listed, or removed every entry it was allowed to, 1 when a removal failed or the confirm was declined, 2 on a usage error, a missing root, or --apply off a terminal without --yes.`;
|
|
2451
|
+
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
|
+
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
2453
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
2432
2454
|
var OPTIONS3 = {
|
|
2433
2455
|
apply: { type: "boolean", description: "delete what is listed as removable, after the confirm" },
|
|
@@ -2449,7 +2471,7 @@ async function dockerUsage() {
|
|
|
2449
2471
|
}
|
|
2450
2472
|
}
|
|
2451
2473
|
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"] });
|
|
2474
|
+
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
2475
|
if (positionals.length > 1)
|
|
2454
2476
|
badUsage("give one root");
|
|
2455
2477
|
const root = workspaceRoot({ given: positionals[0] });
|
|
@@ -2527,7 +2549,7 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2527
2549
|
}
|
|
2528
2550
|
|
|
2529
2551
|
// src/cli.ts
|
|
2530
|
-
|
|
2552
|
+
process22.exitCode = await runCli({
|
|
2531
2553
|
name: "ws",
|
|
2532
2554
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2533
2555
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|