@kaynooo/cli-workspace 0.10.0 → 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/README.md +2 -0
- package/dist/audit-cli.js +113 -82
- package/dist/cli.js +164 -129
- package/dist/repos-cli.js +120 -89
- package/dist/sweep-cli.js +131 -96
- 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"];
|
|
@@ -32,6 +32,7 @@ function y(e, t) {
|
|
|
32
32
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
33
33
|
return n;
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
36
37
|
var N = new Map;
|
|
37
38
|
var Nt = /\s+\S*$/;
|
|
@@ -49,6 +50,7 @@ function ko(t, e, r = "...") {
|
|
|
49
50
|
}
|
|
50
51
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
51
52
|
var z = new Map;
|
|
53
|
+
|
|
52
54
|
// ../kit/src/mode.ts
|
|
53
55
|
import process2 from "process";
|
|
54
56
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -97,7 +99,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
97
99
|
return false;
|
|
98
100
|
return r?.isTTY === true;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function f(r, e = []) {
|
|
101
103
|
let l = "", n = "";
|
|
102
104
|
for (let t = 0, i = e.length;t < i; t++)
|
|
103
105
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -107,7 +109,7 @@ function f2(r, e = []) {
|
|
|
107
109
|
if (Array.isArray(a)) {
|
|
108
110
|
let s = g.get(i);
|
|
109
111
|
if (s === undefined)
|
|
110
|
-
s =
|
|
112
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
111
113
|
return s;
|
|
112
114
|
}
|
|
113
115
|
if (typeof a === "function")
|
|
@@ -116,20 +118,20 @@ function f2(r, e = []) {
|
|
|
116
118
|
if (u === undefined) {
|
|
117
119
|
if (g.size >= 64)
|
|
118
120
|
g.clear();
|
|
119
|
-
u =
|
|
121
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
120
122
|
}
|
|
121
123
|
return u;
|
|
122
124
|
};
|
|
123
125
|
throw Error(`Unknown style: ${String(i)}`);
|
|
124
126
|
} });
|
|
125
127
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
128
|
+
function Fe(r = {}) {
|
|
129
|
+
return f(r);
|
|
128
130
|
}
|
|
129
|
-
var
|
|
131
|
+
var o = Fe();
|
|
130
132
|
|
|
131
133
|
// ../kit/src/theme.ts
|
|
132
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
134
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
133
135
|
import { homedir as homedir2 } from "os";
|
|
134
136
|
import { join as join3, resolve as resolve2 } from "path";
|
|
135
137
|
import process5 from "process";
|
|
@@ -150,7 +152,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// ../kit/src/user-config.ts
|
|
153
|
-
import { existsSync as existsSync2 } from "fs";
|
|
155
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
154
156
|
import { homedir } from "os";
|
|
155
157
|
import { join as join2 } from "path";
|
|
156
158
|
import process4 from "process";
|
|
@@ -168,6 +170,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
168
170
|
const base = configBase(where);
|
|
169
171
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
170
172
|
}
|
|
173
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
174
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
175
|
+
if (!existsSync2(path))
|
|
176
|
+
return {};
|
|
177
|
+
try {
|
|
178
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
179
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
180
|
+
} catch {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
185
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
186
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
187
|
+
}
|
|
171
188
|
|
|
172
189
|
// ../kit/src/theme.ts
|
|
173
190
|
var ENDS = new Map;
|
|
@@ -234,7 +251,7 @@ function readThemeFile(path, warn) {
|
|
|
234
251
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
235
252
|
return;
|
|
236
253
|
}
|
|
237
|
-
const parsed = JSON.parse(
|
|
254
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
238
255
|
if (isRecord(parsed))
|
|
239
256
|
return parsed;
|
|
240
257
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -356,7 +373,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
356
373
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
357
374
|
}
|
|
358
375
|
function paint(stream, env = process6.env) {
|
|
359
|
-
return
|
|
376
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
360
377
|
}
|
|
361
378
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
362
379
|
const colors = paint(stream, env);
|
|
@@ -404,7 +421,7 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
|
|
|
404
421
|
console.log(line);
|
|
405
422
|
}
|
|
406
423
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
407
|
-
function
|
|
424
|
+
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
408
425
|
let e = r === "si" ? 1000 : 1024;
|
|
409
426
|
if (Math.abs(i) < e)
|
|
410
427
|
return `${i} B`;
|
|
@@ -506,18 +523,14 @@ var FULL_STOP = /\.$/;
|
|
|
506
523
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
507
524
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
508
525
|
}
|
|
509
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
510
|
-
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(`
|
|
511
528
|
`);
|
|
512
529
|
}
|
|
513
530
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
514
531
|
if (exits.length === 0)
|
|
515
532
|
return [];
|
|
516
|
-
|
|
517
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
518
|
-
}
|
|
519
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
520
|
-
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(", ")}`];
|
|
521
534
|
}
|
|
522
535
|
function wantsHelpJson(env = process8.env) {
|
|
523
536
|
return env.KIT_HELP === "json";
|
|
@@ -804,9 +817,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
804
817
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
805
818
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
806
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
|
+
}
|
|
807
844
|
// ../kit/src/process.ts
|
|
808
845
|
import { constants } from "os";
|
|
809
|
-
import
|
|
846
|
+
import process11 from "process";
|
|
810
847
|
var KILL_GRACE_MS = 2000;
|
|
811
848
|
function exitCodeOf(code, signal) {
|
|
812
849
|
if (code !== null)
|
|
@@ -826,7 +863,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
826
863
|
return;
|
|
827
864
|
try {
|
|
828
865
|
if (grouped)
|
|
829
|
-
|
|
866
|
+
process11.kill(-proc.pid, killing);
|
|
830
867
|
else
|
|
831
868
|
proc.kill(killing);
|
|
832
869
|
} catch {}
|
|
@@ -901,10 +938,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
901
938
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
902
939
|
|
|
903
940
|
// ../kit/src/tool.ts
|
|
904
|
-
import
|
|
941
|
+
import process12 from "process";
|
|
905
942
|
function cwdGone() {
|
|
906
943
|
try {
|
|
907
|
-
|
|
944
|
+
process12.cwd();
|
|
908
945
|
return false;
|
|
909
946
|
} catch {
|
|
910
947
|
return true;
|
|
@@ -926,7 +963,7 @@ function spawnFailure(command, error) {
|
|
|
926
963
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
927
964
|
let ran;
|
|
928
965
|
try {
|
|
929
|
-
ran = await runCommand(argv, { env:
|
|
966
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
930
967
|
} catch (error) {
|
|
931
968
|
throw spawnFailure(label, error);
|
|
932
969
|
}
|
|
@@ -941,15 +978,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
941
978
|
return { code: ran.code, ...streams };
|
|
942
979
|
}
|
|
943
980
|
// ../kit/src/cli.ts
|
|
944
|
-
import { readFileSync as
|
|
981
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
945
982
|
import { dirname as dirname3, join as join5 } from "path";
|
|
946
|
-
import
|
|
983
|
+
import process14 from "process";
|
|
947
984
|
|
|
948
985
|
// ../kit/src/usage.ts
|
|
949
986
|
import { appendFileSync, mkdirSync } from "fs";
|
|
950
987
|
import { homedir as homedir3 } from "os";
|
|
951
988
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
952
|
-
import
|
|
989
|
+
import process13 from "process";
|
|
953
990
|
|
|
954
991
|
// ../kit/src/logs.ts
|
|
955
992
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -963,14 +1000,14 @@ var usageError;
|
|
|
963
1000
|
function noteUsageError(message) {
|
|
964
1001
|
usageError = message;
|
|
965
1002
|
}
|
|
966
|
-
function stateHome(env =
|
|
1003
|
+
function stateHome(env = process13.env) {
|
|
967
1004
|
const dir = env.XDG_STATE_HOME;
|
|
968
1005
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
969
1006
|
}
|
|
970
|
-
function usagePath(env =
|
|
1007
|
+
function usagePath(env = process13.env) {
|
|
971
1008
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
972
1009
|
}
|
|
973
|
-
function usageRecorded(env =
|
|
1010
|
+
function usageRecorded(env = process13.env) {
|
|
974
1011
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
975
1012
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
976
1013
|
}
|
|
@@ -984,7 +1021,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
984
1021
|
usageError = undefined;
|
|
985
1022
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
986
1023
|
}
|
|
987
|
-
function recordUsage(entry, env =
|
|
1024
|
+
function recordUsage(entry, env = process13.env) {
|
|
988
1025
|
if (!usageRecorded(env))
|
|
989
1026
|
return;
|
|
990
1027
|
try {
|
|
@@ -1061,7 +1098,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1061
1098
|
header(colors, summary),
|
|
1062
1099
|
"",
|
|
1063
1100
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1064
|
-
...replacesRows(replaces, colors),
|
|
1065
1101
|
"",
|
|
1066
1102
|
...await commandRows(commands, colors),
|
|
1067
1103
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1075,8 +1111,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1075
1111
|
`);
|
|
1076
1112
|
}
|
|
1077
1113
|
function printError(prefix, message, hint, cause) {
|
|
1078
|
-
const colors = paint(
|
|
1079
|
-
const styled = takesControlCodes(
|
|
1114
|
+
const colors = paint(process14.stderr);
|
|
1115
|
+
const styled = takesControlCodes(process14.stderr);
|
|
1080
1116
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1081
1117
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1082
1118
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1119,11 +1155,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1119
1155
|
}
|
|
1120
1156
|
}
|
|
1121
1157
|
if (name === undefined && level.path.length > 1) {
|
|
1122
|
-
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));
|
|
1123
1159
|
return 2;
|
|
1124
1160
|
}
|
|
1125
1161
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1126
|
-
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));
|
|
1127
1163
|
return 0;
|
|
1128
1164
|
}
|
|
1129
1165
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1179,24 +1215,24 @@ function candidateLine(candidate) {
|
|
|
1179
1215
|
}
|
|
1180
1216
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1181
1217
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1182
|
-
|
|
1218
|
+
const typed = [];
|
|
1183
1219
|
let at = 0;
|
|
1184
1220
|
while (at < before.length) {
|
|
1185
1221
|
const word = before[at];
|
|
1186
1222
|
if (word === "--") {
|
|
1187
|
-
|
|
1223
|
+
typed.push(...before.slice(at + 1));
|
|
1188
1224
|
break;
|
|
1189
1225
|
}
|
|
1190
1226
|
if (!word.startsWith("-"))
|
|
1191
|
-
|
|
1227
|
+
typed.push(word);
|
|
1192
1228
|
else if (takesValue(word))
|
|
1193
1229
|
at++;
|
|
1194
1230
|
at++;
|
|
1195
1231
|
}
|
|
1196
1232
|
const last = positionals.at(-1);
|
|
1197
|
-
if (
|
|
1198
|
-
return positionals[
|
|
1199
|
-
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 };
|
|
1200
1236
|
}
|
|
1201
1237
|
async function leafCandidates(run, words) {
|
|
1202
1238
|
const completing = await completingOf(run);
|
|
@@ -1204,12 +1240,12 @@ async function leafCandidates(run, words) {
|
|
|
1204
1240
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1205
1241
|
const flag = words.at(-2);
|
|
1206
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);
|
|
1207
1244
|
if (option?.type === "string") {
|
|
1208
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1245
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1209
1246
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1210
1247
|
}
|
|
1211
|
-
const
|
|
1212
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1248
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1213
1249
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1214
1250
|
}
|
|
1215
1251
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1240,9 +1276,13 @@ async function printCandidates(found) {
|
|
|
1240
1276
|
return 0;
|
|
1241
1277
|
}
|
|
1242
1278
|
function packageVersion(entry = Bun.main) {
|
|
1243
|
-
|
|
1279
|
+
let resolved = entry;
|
|
1280
|
+
try {
|
|
1281
|
+
resolved = realpathSync2(entry);
|
|
1282
|
+
} catch {}
|
|
1283
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1244
1284
|
try {
|
|
1245
|
-
const { version } = JSON.parse(
|
|
1285
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1246
1286
|
if (typeof version === "string")
|
|
1247
1287
|
return version;
|
|
1248
1288
|
} catch {}
|
|
@@ -1250,7 +1290,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1250
1290
|
return "0.0.0";
|
|
1251
1291
|
}
|
|
1252
1292
|
}
|
|
1253
|
-
async function runCli(cli, argv =
|
|
1293
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1254
1294
|
const version = cli.version ?? packageVersion();
|
|
1255
1295
|
if (argv[0] === COMPLETE)
|
|
1256
1296
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1277,7 +1317,7 @@ function commandPath(scope, argv) {
|
|
|
1277
1317
|
}
|
|
1278
1318
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1279
1319
|
}
|
|
1280
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1320
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1281
1321
|
if (argv[0] === COMPLETE)
|
|
1282
1322
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1283
1323
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1329,7 +1369,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1329
1369
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1330
1370
|
}
|
|
1331
1371
|
// ../kit/src/watch.ts
|
|
1332
|
-
import
|
|
1372
|
+
import process15 from "process";
|
|
1333
1373
|
import { format } from "util";
|
|
1334
1374
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1335
1375
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1351,7 +1391,7 @@ function withoutWatch(args) {
|
|
|
1351
1391
|
}
|
|
1352
1392
|
return rest;
|
|
1353
1393
|
}
|
|
1354
|
-
async function watching(value, step, stream =
|
|
1394
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1355
1395
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1356
1396
|
if (!takesControlCodes(stream))
|
|
1357
1397
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1359,12 +1399,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1359
1399
|
for (let round = 0;round < rounds; round++) {
|
|
1360
1400
|
const held = [];
|
|
1361
1401
|
const { log, info } = console;
|
|
1362
|
-
const write =
|
|
1402
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1363
1403
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1364
1404
|
`);
|
|
1365
1405
|
console.log = hold;
|
|
1366
1406
|
console.info = hold;
|
|
1367
|
-
|
|
1407
|
+
process15.stdout.write = (text) => {
|
|
1368
1408
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1369
1409
|
return true;
|
|
1370
1410
|
};
|
|
@@ -1373,7 +1413,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1373
1413
|
} finally {
|
|
1374
1414
|
console.log = log;
|
|
1375
1415
|
console.info = info;
|
|
1376
|
-
|
|
1416
|
+
process15.stdout.write = write;
|
|
1377
1417
|
}
|
|
1378
1418
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1379
1419
|
await sleep(interval);
|
|
@@ -1381,39 +1421,30 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1381
1421
|
return code;
|
|
1382
1422
|
}
|
|
1383
1423
|
// ../kit/src/workspace-root.ts
|
|
1384
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1385
1424
|
import { homedir as homedir4 } from "os";
|
|
1386
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1387
|
-
import
|
|
1425
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1426
|
+
import process16 from "process";
|
|
1388
1427
|
function expandHome(path, home) {
|
|
1389
1428
|
if (path === "~")
|
|
1390
1429
|
return home;
|
|
1391
1430
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1392
1431
|
}
|
|
1393
1432
|
function configured(env, home) {
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1396
|
-
return;
|
|
1397
|
-
try {
|
|
1398
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1399
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1400
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1401
|
-
} catch {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1433
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1434
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1404
1435
|
}
|
|
1405
|
-
function workspaceRoot({ given, env =
|
|
1436
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1406
1437
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1407
|
-
return
|
|
1438
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1408
1439
|
}
|
|
1409
1440
|
// src/audit.ts
|
|
1410
|
-
import { existsSync as
|
|
1441
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
|
|
1411
1442
|
import { readdir } from "fs/promises";
|
|
1412
|
-
import { join as join8, relative, resolve as
|
|
1413
|
-
import
|
|
1443
|
+
import { join as join8, relative, resolve as resolve5 } from "path";
|
|
1444
|
+
import process18 from "process";
|
|
1414
1445
|
|
|
1415
1446
|
// src/report.ts
|
|
1416
|
-
import { existsSync as
|
|
1447
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1417
1448
|
import { join as join7 } from "path";
|
|
1418
1449
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1419
1450
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1497,7 +1528,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1497
1528
|
}
|
|
1498
1529
|
function readManifest(path) {
|
|
1499
1530
|
try {
|
|
1500
|
-
return
|
|
1531
|
+
return existsSync4(path) ? JSON.parse(readFileSync5(path, "utf8")) : {};
|
|
1501
1532
|
} catch {
|
|
1502
1533
|
return {};
|
|
1503
1534
|
}
|
|
@@ -1550,7 +1581,7 @@ function countAdvisories(findings) {
|
|
|
1550
1581
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1551
1582
|
}
|
|
1552
1583
|
function holdsLock(dir) {
|
|
1553
|
-
return
|
|
1584
|
+
return existsSync5(join8(dir, "bun.lock")) || existsSync5(join8(dir, "bun.lockb"));
|
|
1554
1585
|
}
|
|
1555
1586
|
async function findRepos(root) {
|
|
1556
1587
|
if (holdsLock(root))
|
|
@@ -1602,7 +1633,7 @@ async function audited(path, shown, level, ignore) {
|
|
|
1602
1633
|
}
|
|
1603
1634
|
function lockText(path) {
|
|
1604
1635
|
try {
|
|
1605
|
-
return
|
|
1636
|
+
return readFileSync6(join8(path, "bun.lock"), "utf8");
|
|
1606
1637
|
} catch {
|
|
1607
1638
|
return "";
|
|
1608
1639
|
}
|
|
@@ -1622,7 +1653,7 @@ function failure(ran) {
|
|
|
1622
1653
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1623
1654
|
}
|
|
1624
1655
|
function tint(severity) {
|
|
1625
|
-
const colors = paint(
|
|
1656
|
+
const colors = paint(process18.stdout);
|
|
1626
1657
|
if (severity === "critical" || severity === "high")
|
|
1627
1658
|
return colors.red;
|
|
1628
1659
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1639,14 +1670,14 @@ function rows(findings) {
|
|
|
1639
1670
|
}
|
|
1640
1671
|
async function audit(args) {
|
|
1641
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"] });
|
|
1642
|
-
const root =
|
|
1643
|
-
if (!
|
|
1673
|
+
const root = resolve5(positionals[0] ?? ".");
|
|
1674
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1644
1675
|
fail(`no folder ${root}`);
|
|
1645
1676
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1646
1677
|
const paths = await findRepos(root);
|
|
1647
1678
|
if (paths.length === 0)
|
|
1648
1679
|
fail(`no bun.lock under ${root}`);
|
|
1649
|
-
const audits = await pool(paths, CONCURRENCY, async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1680
|
+
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1650
1681
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1651
1682
|
if (values.json === true)
|
|
1652
1683
|
printJson(kept);
|
|
@@ -1657,8 +1688,8 @@ async function audit(args) {
|
|
|
1657
1688
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1658
1689
|
}
|
|
1659
1690
|
function show(audits, total) {
|
|
1660
|
-
const label = role("label",
|
|
1661
|
-
const path = role("path",
|
|
1691
|
+
const label = role("label", process18.stdout);
|
|
1692
|
+
const path = role("path", process18.stdout);
|
|
1662
1693
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1663
1694
|
if (flagged.length === 0) {
|
|
1664
1695
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1678,15 +1709,15 @@ function show(audits, total) {
|
|
|
1678
1709
|
}
|
|
1679
1710
|
|
|
1680
1711
|
// src/repos.ts
|
|
1681
|
-
import { existsSync as
|
|
1712
|
+
import { existsSync as existsSync7, statSync as statSync3 } from "fs";
|
|
1682
1713
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1683
|
-
import
|
|
1714
|
+
import process20 from "process";
|
|
1684
1715
|
|
|
1685
1716
|
// src/repos-scan.ts
|
|
1686
|
-
import { existsSync as
|
|
1717
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1687
1718
|
import { readdir as readdir2 } from "fs/promises";
|
|
1688
1719
|
import { basename, join as join9 } from "path";
|
|
1689
|
-
import
|
|
1720
|
+
import process19 from "process";
|
|
1690
1721
|
var MAX_DEPTH2 = 3;
|
|
1691
1722
|
var CONCURRENCY2 = 8;
|
|
1692
1723
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1708,7 +1739,7 @@ function reasonsOf(repo) {
|
|
|
1708
1739
|
return reasons;
|
|
1709
1740
|
}
|
|
1710
1741
|
async function findRepos2(root, skip) {
|
|
1711
|
-
if (
|
|
1742
|
+
if (existsSync6(join9(root, ".git")))
|
|
1712
1743
|
return [root];
|
|
1713
1744
|
const found = [];
|
|
1714
1745
|
async function walk(dir, depth) {
|
|
@@ -1722,7 +1753,7 @@ async function findRepos2(root, skip) {
|
|
|
1722
1753
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1723
1754
|
continue;
|
|
1724
1755
|
const path = join9(dir, entry.name);
|
|
1725
|
-
if (
|
|
1756
|
+
if (existsSync6(join9(path, ".git")))
|
|
1726
1757
|
found.push(path);
|
|
1727
1758
|
else if (depth < MAX_DEPTH2)
|
|
1728
1759
|
await walk(path, depth + 1);
|
|
@@ -1733,7 +1764,7 @@ async function findRepos2(root, skip) {
|
|
|
1733
1764
|
}
|
|
1734
1765
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1735
1766
|
try {
|
|
1736
|
-
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 });
|
|
1737
1768
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1738
1769
|
} catch {
|
|
1739
1770
|
return;
|
|
@@ -1752,7 +1783,7 @@ async function packageReleases(path) {
|
|
|
1752
1783
|
names.add(name);
|
|
1753
1784
|
}
|
|
1754
1785
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1755
|
-
const folder = [join9("packages", name), name].find((candidate) =>
|
|
1786
|
+
const folder = [join9("packages", name), name].find((candidate) => existsSync6(join9(path, candidate)));
|
|
1756
1787
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1757
1788
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1758
1789
|
});
|
|
@@ -1810,7 +1841,7 @@ function firstLine(text) {
|
|
|
1810
1841
|
}
|
|
1811
1842
|
async function fastForward(path) {
|
|
1812
1843
|
try {
|
|
1813
|
-
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 });
|
|
1814
1845
|
if (ran.timedOut)
|
|
1815
1846
|
return "timed out";
|
|
1816
1847
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1839,7 +1870,7 @@ var OPTIONS2 = {
|
|
|
1839
1870
|
};
|
|
1840
1871
|
async function skipped() {
|
|
1841
1872
|
const file = userConfigReadPath("repos");
|
|
1842
|
-
if (!
|
|
1873
|
+
if (!existsSync7(file))
|
|
1843
1874
|
return new Set;
|
|
1844
1875
|
try {
|
|
1845
1876
|
const config = await Bun.file(file).json();
|
|
@@ -1853,7 +1884,7 @@ function releasedCell(repo) {
|
|
|
1853
1884
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1854
1885
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1855
1886
|
}
|
|
1856
|
-
function syncCell(repo, stream =
|
|
1887
|
+
function syncCell(repo, stream = process20.stdout) {
|
|
1857
1888
|
const colors = paint(stream);
|
|
1858
1889
|
const ahead = repo.ahead ?? 0;
|
|
1859
1890
|
const behind = repo.behind ?? 0;
|
|
@@ -1864,7 +1895,7 @@ function syncCell(repo, stream = process19.stdout) {
|
|
|
1864
1895
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1865
1896
|
}
|
|
1866
1897
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1867
|
-
function branchCell(repo, stream =
|
|
1898
|
+
function branchCell(repo, stream = process20.stdout) {
|
|
1868
1899
|
const colors = paint(stream);
|
|
1869
1900
|
if (repo.unreadable)
|
|
1870
1901
|
return colors.red("? (unreadable)");
|
|
@@ -1873,8 +1904,8 @@ function branchCell(repo, stream = process19.stdout) {
|
|
|
1873
1904
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1874
1905
|
}
|
|
1875
1906
|
function row(repo, shown) {
|
|
1876
|
-
const colors = paint(
|
|
1877
|
-
const tint = role("path",
|
|
1907
|
+
const colors = paint(process20.stdout);
|
|
1908
|
+
const tint = role("path", process20.stdout);
|
|
1878
1909
|
const unreleased = releasedCell(repo);
|
|
1879
1910
|
return [
|
|
1880
1911
|
tint(shown),
|
|
@@ -1890,11 +1921,11 @@ async function repos(args) {
|
|
|
1890
1921
|
if (values.watch !== undefined)
|
|
1891
1922
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1892
1923
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1893
|
-
if (!
|
|
1924
|
+
if (!existsSync7(root) || !statSync3(root).isDirectory())
|
|
1894
1925
|
fail(`no folder ${root}`);
|
|
1895
1926
|
const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
|
|
1896
1927
|
const paths = await findRepos2(root, await skipped());
|
|
1897
|
-
const states = await pool(paths, CONCURRENCY2, async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1928
|
+
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY2), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1898
1929
|
const keeps = (repo) => {
|
|
1899
1930
|
const reasons = reasonsOf(repo);
|
|
1900
1931
|
return only === undefined ? values.all === true || reasons.length > 0 || repo.unreadable : reasons.includes(only);
|
|
@@ -1908,12 +1939,12 @@ async function repos(args) {
|
|
|
1908
1939
|
const blocker = pullBlocker(repo);
|
|
1909
1940
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1910
1941
|
if (blocker !== undefined) {
|
|
1911
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1942
|
+
log(marked("note", `${repo.name} skipped`, process20.stdout, blocker));
|
|
1912
1943
|
} else if (refused !== undefined) {
|
|
1913
1944
|
failedPulls++;
|
|
1914
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1945
|
+
log(marked("problem", `${repo.name} not pulled`, process20.stdout, refused));
|
|
1915
1946
|
} else {
|
|
1916
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1947
|
+
log(marked("ok", `${repo.name} pulled`, process20.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1917
1948
|
states[index] = await inspect(repo.path, false);
|
|
1918
1949
|
}
|
|
1919
1950
|
}
|
|
@@ -1928,7 +1959,7 @@ async function repos(args) {
|
|
|
1928
1959
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1929
1960
|
return failedPulls > 0 ? 1 : 0;
|
|
1930
1961
|
}
|
|
1931
|
-
const label = role("label",
|
|
1962
|
+
const label = role("label", process20.stdout);
|
|
1932
1963
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1933
1964
|
if (kept.length === 0) {
|
|
1934
1965
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1944,12 +1975,12 @@ async function repos(args) {
|
|
|
1944
1975
|
}
|
|
1945
1976
|
|
|
1946
1977
|
// src/sweep.ts
|
|
1947
|
-
import { existsSync as
|
|
1978
|
+
import { existsSync as existsSync10, statSync as statSync4 } from "fs";
|
|
1948
1979
|
import { homedir as homedir6 } from "os";
|
|
1949
1980
|
import { relative as relative3 } from "path";
|
|
1950
1981
|
|
|
1951
1982
|
// ../kit/src/prompt.ts
|
|
1952
|
-
import
|
|
1983
|
+
import process21 from "process";
|
|
1953
1984
|
|
|
1954
1985
|
// ../kit/src/picker/score.ts
|
|
1955
1986
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1959,7 +1990,9 @@ var NONE = Number.NEGATIVE_INFINITY;
|
|
|
1959
1990
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1960
1991
|
var PASTE_START = "\x1B[200~";
|
|
1961
1992
|
var PASTE_END = "\x1B[201~";
|
|
1962
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1993
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1994
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1995
|
+
var WHEEL_LINES = 3;
|
|
1963
1996
|
var KEYS = {
|
|
1964
1997
|
"\x1B[A": "up",
|
|
1965
1998
|
"\x1BOA": "up",
|
|
@@ -1988,9 +2021,15 @@ var KEYS = {
|
|
|
1988
2021
|
"\x1BOP": "help",
|
|
1989
2022
|
"\x1B[11~": "help"
|
|
1990
2023
|
};
|
|
2024
|
+
function repeat(value, count) {
|
|
2025
|
+
return Array.from({ length: count }).fill(value);
|
|
2026
|
+
}
|
|
1991
2027
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1992
2028
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1993
2029
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2030
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2031
|
+
if (wheel !== undefined)
|
|
2032
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1994
2033
|
const named = codes.get(sequence);
|
|
1995
2034
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1996
2035
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -2033,21 +2072,18 @@ function asking(colors, question, typed, keys) {
|
|
|
2033
2072
|
function answer(colors, question, state, picked) {
|
|
2034
2073
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2035
2074
|
}
|
|
2036
|
-
async function ask(question, { hint, terminal =
|
|
2075
|
+
async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
2037
2076
|
const { stdin, stderr } = terminal;
|
|
2038
2077
|
if (!isInteractive(terminal))
|
|
2039
2078
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2040
2079
|
const colors = paint(stderr);
|
|
2041
|
-
let drawn = [];
|
|
2042
2080
|
let current = "asking";
|
|
2043
2081
|
let outcome;
|
|
2044
2082
|
const columns = () => stderr.columns || 80;
|
|
2045
|
-
const draw = (state) => {
|
|
2083
|
+
const draw = (state, last = false) => {
|
|
2046
2084
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
`)}`);
|
|
2050
|
-
drawn = frame;
|
|
2085
|
+
stderr.write(`\r\x1B[0J${frame.join(`
|
|
2086
|
+
`)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
|
|
2051
2087
|
current = state;
|
|
2052
2088
|
};
|
|
2053
2089
|
const redraw = () => draw(current);
|
|
@@ -2083,7 +2119,7 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2083
2119
|
});
|
|
2084
2120
|
} finally {
|
|
2085
2121
|
stderr.off?.("resize", redraw);
|
|
2086
|
-
draw(outcome ?? "cancel");
|
|
2122
|
+
draw(outcome ?? "cancel", true);
|
|
2087
2123
|
stderr.write(`
|
|
2088
2124
|
\x1B[?25h\x1B[?2004l`);
|
|
2089
2125
|
stdin.setRawMode(false);
|
|
@@ -2092,12 +2128,12 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2092
2128
|
}
|
|
2093
2129
|
|
|
2094
2130
|
// src/apply.ts
|
|
2095
|
-
import { existsSync as
|
|
2131
|
+
import { existsSync as existsSync9 } from "fs";
|
|
2096
2132
|
import { lstat as lstat3, rm } from "fs/promises";
|
|
2097
2133
|
import { basename as basename4, join as join12 } from "path";
|
|
2098
2134
|
|
|
2099
2135
|
// src/sweep-scan.ts
|
|
2100
|
-
import { existsSync as
|
|
2136
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2101
2137
|
import { lstat as lstat2, readdir as readdir4, realpath } from "fs/promises";
|
|
2102
2138
|
import { homedir as homedir5 } from "os";
|
|
2103
2139
|
import { basename as basename3, dirname as dirname5, join as join11 } from "path";
|
|
@@ -2223,7 +2259,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2223
2259
|
}
|
|
2224
2260
|
continue;
|
|
2225
2261
|
}
|
|
2226
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" ||
|
|
2262
|
+
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync8(join11(dir, "Cargo.toml")))) {
|
|
2227
2263
|
if (entry.isSymbolicLink()) {
|
|
2228
2264
|
found.skipped.push({ path, reason: "symlink" });
|
|
2229
2265
|
} else if (entry.isDirectory()) {
|
|
@@ -2309,7 +2345,7 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2309
2345
|
const located = await toplevelOf(parent);
|
|
2310
2346
|
if (located === "failed")
|
|
2311
2347
|
return { skip: "git failed" };
|
|
2312
|
-
if (
|
|
2348
|
+
if (existsSync8(join11(path, ".git")))
|
|
2313
2349
|
return { skip: "holds a git repository" };
|
|
2314
2350
|
if (located === "none")
|
|
2315
2351
|
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
@@ -2377,7 +2413,7 @@ async function removeFolder(entry) {
|
|
|
2377
2413
|
const stat = await lstat3(entry.path);
|
|
2378
2414
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename4(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
|
|
2379
2415
|
return { path: entry.path, removed: false, error: "no longer a plain folder" };
|
|
2380
|
-
if (
|
|
2416
|
+
if (existsSync9(join12(entry.path, ".git")))
|
|
2381
2417
|
return { path: entry.path, removed: false, error: "holds a git repository" };
|
|
2382
2418
|
await rm(entry.path, { recursive: true, force: true });
|
|
2383
2419
|
return { path: entry.path, removed: true };
|
|
@@ -2412,9 +2448,8 @@ var LARGE = 100 * 1024 ** 2;
|
|
|
2412
2448
|
var BIG = 1024 ** 3;
|
|
2413
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
|
|
2414
2450
|
|
|
2415
|
-
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
|
|
2416
|
-
|
|
2417
|
-
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"]];
|
|
2418
2453
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
2419
2454
|
var OPTIONS3 = {
|
|
2420
2455
|
apply: { type: "boolean", description: "delete what is listed as removable, after the confirm" },
|
|
@@ -2436,11 +2471,11 @@ async function dockerUsage() {
|
|
|
2436
2471
|
}
|
|
2437
2472
|
}
|
|
2438
2473
|
async function sweep(args) {
|
|
2439
|
-
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"] });
|
|
2440
2475
|
if (positionals.length > 1)
|
|
2441
2476
|
badUsage("give one root");
|
|
2442
2477
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2443
|
-
if (!
|
|
2478
|
+
if (!existsSync10(root) || !statSync4(root).isDirectory())
|
|
2444
2479
|
fail(`${root} is not a folder`);
|
|
2445
2480
|
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
2446
2481
|
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
@@ -2460,7 +2495,7 @@ async function sweep(args) {
|
|
|
2460
2495
|
if (values.apply === true && removable.length > 0 && values.yes !== true) {
|
|
2461
2496
|
if (!json)
|
|
2462
2497
|
print(root, entries, skipped.length, reclaimable, now);
|
|
2463
|
-
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${
|
|
2498
|
+
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${tt(reclaimable)})?`, { default: false, hint: "pass --yes to skip the confirm" });
|
|
2464
2499
|
if (agreed !== true) {
|
|
2465
2500
|
if (json)
|
|
2466
2501
|
fail("nothing deleted: the confirm was declined", 1, "pass --yes to skip the confirm");
|
|
@@ -2480,7 +2515,7 @@ async function sweep(args) {
|
|
|
2480
2515
|
console.log("dry run, pass --apply to delete");
|
|
2481
2516
|
} else {
|
|
2482
2517
|
const bytes = new Map(removable.map((entry) => [entry.path, entry.bytes]));
|
|
2483
|
-
note(`freed ${
|
|
2518
|
+
note(`freed ${tt(outcomes.reduce((sum, outcome) => sum + (outcome.removed ? bytes.get(outcome.path) ?? 0 : 0), 0))}`);
|
|
2484
2519
|
}
|
|
2485
2520
|
if (docker !== undefined)
|
|
2486
2521
|
console.log(`
|
|
@@ -2505,16 +2540,16 @@ function print(root, entries, skipped, reclaimable, now) {
|
|
|
2505
2540
|
const path = role("path", process.stdout);
|
|
2506
2541
|
const sized = (bytes) => {
|
|
2507
2542
|
if (bytes >= BIG)
|
|
2508
|
-
return colors.red(
|
|
2509
|
-
return bytes >= LARGE ? colors.yellow(
|
|
2543
|
+
return colors.red(tt(bytes));
|
|
2544
|
+
return bytes >= LARGE ? colors.yellow(tt(bytes)) : tt(bytes);
|
|
2510
2545
|
};
|
|
2511
2546
|
console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [sized(entry.bytes), entry.committedAt === undefined ? colors.dim("-") : colors.dim(formatAge(entry.committedAt, now)), entry.kind, path(relative3(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
|
|
2512
2547
|
console.log(`
|
|
2513
|
-
${
|
|
2548
|
+
${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
|
|
2514
2549
|
}
|
|
2515
2550
|
|
|
2516
2551
|
// src/cli.ts
|
|
2517
|
-
|
|
2552
|
+
process22.exitCode = await runCli({
|
|
2518
2553
|
name: "ws",
|
|
2519
2554
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2520
2555
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|