@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/README.md
CHANGED
|
@@ -30,6 +30,8 @@ Without `--fetch` the ahead and behind counts are those of the last fetch. The w
|
|
|
30
30
|
{ "skip": ["archived-thing", "vendored-clone"] }
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
`concurrency` (a positive whole number, 8 by default) in the same file sets how many repositories are read at once. `audit` reads the same key from `~/.config/kaynooo-cli/audit.json` (4 by default, the repositories audited at once).
|
|
34
|
+
|
|
33
35
|
## sweep
|
|
34
36
|
|
|
35
37
|
`sweep` reclaims disk across many repos: it lists the regenerable folders and clean git worktrees under a root, largest first, and deletes them only on `--apply`.
|
package/dist/audit-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/audit-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -18,6 +18,7 @@ import { parseArgs } from "util";
|
|
|
18
18
|
|
|
19
19
|
// ../kit/src/format.ts
|
|
20
20
|
import process7 from "process";
|
|
21
|
+
|
|
21
22
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
22
23
|
var N = new Map;
|
|
23
24
|
var Nt = /\s+\S*$/;
|
|
@@ -35,6 +36,7 @@ function ko(t, e, r = "...") {
|
|
|
35
36
|
}
|
|
36
37
|
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));
|
|
37
38
|
var z = new Map;
|
|
39
|
+
|
|
38
40
|
// ../kit/src/mode.ts
|
|
39
41
|
import process2 from "process";
|
|
40
42
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -83,7 +85,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
83
85
|
return false;
|
|
84
86
|
return r?.isTTY === true;
|
|
85
87
|
}
|
|
86
|
-
function
|
|
88
|
+
function f(r, e = []) {
|
|
87
89
|
let l = "", n = "";
|
|
88
90
|
for (let t = 0, i = e.length;t < i; t++)
|
|
89
91
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -93,7 +95,7 @@ function f2(r, e = []) {
|
|
|
93
95
|
if (Array.isArray(a)) {
|
|
94
96
|
let s = g.get(i);
|
|
95
97
|
if (s === undefined)
|
|
96
|
-
s =
|
|
98
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
97
99
|
return s;
|
|
98
100
|
}
|
|
99
101
|
if (typeof a === "function")
|
|
@@ -102,20 +104,20 @@ function f2(r, e = []) {
|
|
|
102
104
|
if (u === undefined) {
|
|
103
105
|
if (g.size >= 64)
|
|
104
106
|
g.clear();
|
|
105
|
-
u =
|
|
107
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
106
108
|
}
|
|
107
109
|
return u;
|
|
108
110
|
};
|
|
109
111
|
throw Error(`Unknown style: ${String(i)}`);
|
|
110
112
|
} });
|
|
111
113
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
114
|
+
function Fe(r = {}) {
|
|
115
|
+
return f(r);
|
|
114
116
|
}
|
|
115
|
-
var
|
|
117
|
+
var o = Fe();
|
|
116
118
|
|
|
117
119
|
// ../kit/src/theme.ts
|
|
118
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
120
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
119
121
|
import { homedir as homedir2 } from "os";
|
|
120
122
|
import { join as join3, resolve as resolve2 } from "path";
|
|
121
123
|
import process5 from "process";
|
|
@@ -136,7 +138,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
// ../kit/src/user-config.ts
|
|
139
|
-
import { existsSync as existsSync2 } from "fs";
|
|
141
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
140
142
|
import { homedir } from "os";
|
|
141
143
|
import { join as join2 } from "path";
|
|
142
144
|
import process4 from "process";
|
|
@@ -154,6 +156,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
154
156
|
const base = configBase(where);
|
|
155
157
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
156
158
|
}
|
|
159
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
160
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
161
|
+
if (!existsSync2(path))
|
|
162
|
+
return {};
|
|
163
|
+
try {
|
|
164
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
165
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
166
|
+
} catch {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
171
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
172
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
173
|
+
}
|
|
157
174
|
|
|
158
175
|
// ../kit/src/theme.ts
|
|
159
176
|
var ENDS = new Map;
|
|
@@ -220,7 +237,7 @@ function readThemeFile(path, warn) {
|
|
|
220
237
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
221
238
|
return;
|
|
222
239
|
}
|
|
223
|
-
const parsed = JSON.parse(
|
|
240
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
224
241
|
if (isRecord(parsed))
|
|
225
242
|
return parsed;
|
|
226
243
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -342,7 +359,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
342
359
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
343
360
|
}
|
|
344
361
|
function paint(stream, env = process6.env) {
|
|
345
|
-
return
|
|
362
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
346
363
|
}
|
|
347
364
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
348
365
|
const colors = paint(stream, env);
|
|
@@ -481,18 +498,14 @@ var FULL_STOP = /\.$/;
|
|
|
481
498
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
482
499
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
483
500
|
}
|
|
484
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
485
|
-
return [usageLine(usage, colors),
|
|
501
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
502
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
486
503
|
`);
|
|
487
504
|
}
|
|
488
505
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
489
506
|
if (exits.length === 0)
|
|
490
507
|
return [];
|
|
491
|
-
|
|
492
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
493
|
-
}
|
|
494
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
495
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
508
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
496
509
|
}
|
|
497
510
|
function wantsHelpJson(env = process8.env) {
|
|
498
511
|
return env.KIT_HELP === "json";
|
|
@@ -779,9 +792,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
779
792
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
780
793
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
781
794
|
}
|
|
795
|
+
// ../kit/src/argv.ts
|
|
796
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
797
|
+
import { resolve as resolve3 } from "path";
|
|
798
|
+
import process10 from "process";
|
|
799
|
+
function commandLine() {
|
|
800
|
+
try {
|
|
801
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
802
|
+
} catch {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
function realPath(word) {
|
|
807
|
+
try {
|
|
808
|
+
return realpathSync(resolve3(word));
|
|
809
|
+
} catch {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
814
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
815
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
816
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
817
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
818
|
+
}
|
|
782
819
|
// ../kit/src/process.ts
|
|
783
820
|
import { constants } from "os";
|
|
784
|
-
import
|
|
821
|
+
import process11 from "process";
|
|
785
822
|
var KILL_GRACE_MS = 2000;
|
|
786
823
|
function exitCodeOf(code, signal) {
|
|
787
824
|
if (code !== null)
|
|
@@ -801,7 +838,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
801
838
|
return;
|
|
802
839
|
try {
|
|
803
840
|
if (grouped)
|
|
804
|
-
|
|
841
|
+
process11.kill(-proc.pid, killing);
|
|
805
842
|
else
|
|
806
843
|
proc.kill(killing);
|
|
807
844
|
} catch {}
|
|
@@ -876,10 +913,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
876
913
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
877
914
|
|
|
878
915
|
// ../kit/src/tool.ts
|
|
879
|
-
import
|
|
916
|
+
import process12 from "process";
|
|
880
917
|
function cwdGone() {
|
|
881
918
|
try {
|
|
882
|
-
|
|
919
|
+
process12.cwd();
|
|
883
920
|
return false;
|
|
884
921
|
} catch {
|
|
885
922
|
return true;
|
|
@@ -901,7 +938,7 @@ function spawnFailure(command, error) {
|
|
|
901
938
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
902
939
|
let ran;
|
|
903
940
|
try {
|
|
904
|
-
ran = await runCommand(argv, { env:
|
|
941
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
905
942
|
} catch (error) {
|
|
906
943
|
throw spawnFailure(label, error);
|
|
907
944
|
}
|
|
@@ -916,15 +953,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
916
953
|
return { code: ran.code, ...streams };
|
|
917
954
|
}
|
|
918
955
|
// ../kit/src/cli.ts
|
|
919
|
-
import { readFileSync as
|
|
956
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
920
957
|
import { dirname as dirname3, join as join5 } from "path";
|
|
921
|
-
import
|
|
958
|
+
import process14 from "process";
|
|
922
959
|
|
|
923
960
|
// ../kit/src/usage.ts
|
|
924
961
|
import { appendFileSync, mkdirSync } from "fs";
|
|
925
962
|
import { homedir as homedir3 } from "os";
|
|
926
963
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
927
|
-
import
|
|
964
|
+
import process13 from "process";
|
|
928
965
|
|
|
929
966
|
// ../kit/src/logs.ts
|
|
930
967
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -938,14 +975,14 @@ var usageError;
|
|
|
938
975
|
function noteUsageError(message) {
|
|
939
976
|
usageError = message;
|
|
940
977
|
}
|
|
941
|
-
function stateHome(env =
|
|
978
|
+
function stateHome(env = process13.env) {
|
|
942
979
|
const dir = env.XDG_STATE_HOME;
|
|
943
980
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
944
981
|
}
|
|
945
|
-
function usagePath(env =
|
|
982
|
+
function usagePath(env = process13.env) {
|
|
946
983
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
947
984
|
}
|
|
948
|
-
function usageRecorded(env =
|
|
985
|
+
function usageRecorded(env = process13.env) {
|
|
949
986
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
950
987
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
951
988
|
}
|
|
@@ -959,7 +996,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
959
996
|
usageError = undefined;
|
|
960
997
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
961
998
|
}
|
|
962
|
-
function recordUsage(entry, env =
|
|
999
|
+
function recordUsage(entry, env = process13.env) {
|
|
963
1000
|
if (!usageRecorded(env))
|
|
964
1001
|
return;
|
|
965
1002
|
try {
|
|
@@ -1036,7 +1073,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1036
1073
|
header(colors, summary),
|
|
1037
1074
|
"",
|
|
1038
1075
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1039
|
-
...replacesRows(replaces, colors),
|
|
1040
1076
|
"",
|
|
1041
1077
|
...await commandRows(commands, colors),
|
|
1042
1078
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1050,8 +1086,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1050
1086
|
`);
|
|
1051
1087
|
}
|
|
1052
1088
|
function printError(prefix, message, hint, cause) {
|
|
1053
|
-
const colors = paint(
|
|
1054
|
-
const styled = takesControlCodes(
|
|
1089
|
+
const colors = paint(process14.stderr);
|
|
1090
|
+
const styled = takesControlCodes(process14.stderr);
|
|
1055
1091
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1056
1092
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1057
1093
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1094,11 +1130,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1094
1130
|
}
|
|
1095
1131
|
}
|
|
1096
1132
|
if (name === undefined && level.path.length > 1) {
|
|
1097
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1133
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
1098
1134
|
return 2;
|
|
1099
1135
|
}
|
|
1100
1136
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1101
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1137
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
1102
1138
|
return 0;
|
|
1103
1139
|
}
|
|
1104
1140
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1154,24 +1190,24 @@ function candidateLine(candidate) {
|
|
|
1154
1190
|
}
|
|
1155
1191
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1156
1192
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1157
|
-
|
|
1193
|
+
const typed = [];
|
|
1158
1194
|
let at = 0;
|
|
1159
1195
|
while (at < before.length) {
|
|
1160
1196
|
const word = before[at];
|
|
1161
1197
|
if (word === "--") {
|
|
1162
|
-
|
|
1198
|
+
typed.push(...before.slice(at + 1));
|
|
1163
1199
|
break;
|
|
1164
1200
|
}
|
|
1165
1201
|
if (!word.startsWith("-"))
|
|
1166
|
-
|
|
1202
|
+
typed.push(word);
|
|
1167
1203
|
else if (takesValue(word))
|
|
1168
1204
|
at++;
|
|
1169
1205
|
at++;
|
|
1170
1206
|
}
|
|
1171
1207
|
const last = positionals.at(-1);
|
|
1172
|
-
if (
|
|
1173
|
-
return positionals[
|
|
1174
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1208
|
+
if (typed.length < positionals.length)
|
|
1209
|
+
return { name: positionals[typed.length], typed };
|
|
1210
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1175
1211
|
}
|
|
1176
1212
|
async function leafCandidates(run, words) {
|
|
1177
1213
|
const completing = await completingOf(run);
|
|
@@ -1179,12 +1215,12 @@ async function leafCandidates(run, words) {
|
|
|
1179
1215
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1180
1216
|
const flag = words.at(-2);
|
|
1181
1217
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1218
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1182
1219
|
if (option?.type === "string") {
|
|
1183
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1220
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1184
1221
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1185
1222
|
}
|
|
1186
|
-
const
|
|
1187
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1223
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1188
1224
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1189
1225
|
}
|
|
1190
1226
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1215,9 +1251,13 @@ async function printCandidates(found) {
|
|
|
1215
1251
|
return 0;
|
|
1216
1252
|
}
|
|
1217
1253
|
function packageVersion(entry = Bun.main) {
|
|
1218
|
-
|
|
1254
|
+
let resolved = entry;
|
|
1255
|
+
try {
|
|
1256
|
+
resolved = realpathSync2(entry);
|
|
1257
|
+
} catch {}
|
|
1258
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1219
1259
|
try {
|
|
1220
|
-
const { version } = JSON.parse(
|
|
1260
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1221
1261
|
if (typeof version === "string")
|
|
1222
1262
|
return version;
|
|
1223
1263
|
} catch {}
|
|
@@ -1225,7 +1265,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1225
1265
|
return "0.0.0";
|
|
1226
1266
|
}
|
|
1227
1267
|
}
|
|
1228
|
-
async function runCli(cli, argv =
|
|
1268
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1229
1269
|
const version = cli.version ?? packageVersion();
|
|
1230
1270
|
if (argv[0] === COMPLETE)
|
|
1231
1271
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1252,7 +1292,7 @@ function commandPath(scope, argv) {
|
|
|
1252
1292
|
}
|
|
1253
1293
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1254
1294
|
}
|
|
1255
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1295
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1256
1296
|
if (argv[0] === COMPLETE)
|
|
1257
1297
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1258
1298
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1304,7 +1344,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1304
1344
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1305
1345
|
}
|
|
1306
1346
|
// ../kit/src/watch.ts
|
|
1307
|
-
import
|
|
1347
|
+
import process15 from "process";
|
|
1308
1348
|
import { format } from "util";
|
|
1309
1349
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1310
1350
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1326,7 +1366,7 @@ function withoutWatch(args) {
|
|
|
1326
1366
|
}
|
|
1327
1367
|
return rest;
|
|
1328
1368
|
}
|
|
1329
|
-
async function watching(value, step, stream =
|
|
1369
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1330
1370
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1331
1371
|
if (!takesControlCodes(stream))
|
|
1332
1372
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1334,12 +1374,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1334
1374
|
for (let round = 0;round < rounds; round++) {
|
|
1335
1375
|
const held = [];
|
|
1336
1376
|
const { log, info } = console;
|
|
1337
|
-
const write =
|
|
1377
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1338
1378
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1339
1379
|
`);
|
|
1340
1380
|
console.log = hold;
|
|
1341
1381
|
console.info = hold;
|
|
1342
|
-
|
|
1382
|
+
process15.stdout.write = (text) => {
|
|
1343
1383
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1344
1384
|
return true;
|
|
1345
1385
|
};
|
|
@@ -1348,7 +1388,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1348
1388
|
} finally {
|
|
1349
1389
|
console.log = log;
|
|
1350
1390
|
console.info = info;
|
|
1351
|
-
|
|
1391
|
+
process15.stdout.write = write;
|
|
1352
1392
|
}
|
|
1353
1393
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1354
1394
|
await sleep(interval);
|
|
@@ -1356,39 +1396,30 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1356
1396
|
return code;
|
|
1357
1397
|
}
|
|
1358
1398
|
// ../kit/src/workspace-root.ts
|
|
1359
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1360
1399
|
import { homedir as homedir4 } from "os";
|
|
1361
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1362
|
-
import
|
|
1400
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1401
|
+
import process16 from "process";
|
|
1363
1402
|
function expandHome(path, home) {
|
|
1364
1403
|
if (path === "~")
|
|
1365
1404
|
return home;
|
|
1366
1405
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1367
1406
|
}
|
|
1368
1407
|
function configured(env, home) {
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
return;
|
|
1372
|
-
try {
|
|
1373
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1374
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1375
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1376
|
-
} catch {
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1408
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1409
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1379
1410
|
}
|
|
1380
|
-
function workspaceRoot({ given, env =
|
|
1411
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1381
1412
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1382
|
-
return
|
|
1413
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1383
1414
|
}
|
|
1384
1415
|
// src/audit.ts
|
|
1385
|
-
import { existsSync as
|
|
1416
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
|
|
1386
1417
|
import { readdir } from "fs/promises";
|
|
1387
|
-
import { join as join8, relative, resolve as
|
|
1388
|
-
import
|
|
1418
|
+
import { join as join8, relative, resolve as resolve5 } from "path";
|
|
1419
|
+
import process18 from "process";
|
|
1389
1420
|
|
|
1390
1421
|
// src/report.ts
|
|
1391
|
-
import { existsSync as
|
|
1422
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1392
1423
|
import { join as join7 } from "path";
|
|
1393
1424
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1394
1425
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1472,7 +1503,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1472
1503
|
}
|
|
1473
1504
|
function readManifest(path) {
|
|
1474
1505
|
try {
|
|
1475
|
-
return
|
|
1506
|
+
return existsSync4(path) ? JSON.parse(readFileSync5(path, "utf8")) : {};
|
|
1476
1507
|
} catch {
|
|
1477
1508
|
return {};
|
|
1478
1509
|
}
|
|
@@ -1525,7 +1556,7 @@ function countAdvisories(findings) {
|
|
|
1525
1556
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1526
1557
|
}
|
|
1527
1558
|
function holdsLock(dir) {
|
|
1528
|
-
return
|
|
1559
|
+
return existsSync5(join8(dir, "bun.lock")) || existsSync5(join8(dir, "bun.lockb"));
|
|
1529
1560
|
}
|
|
1530
1561
|
async function findRepos(root) {
|
|
1531
1562
|
if (holdsLock(root))
|
|
@@ -1577,7 +1608,7 @@ async function audited(path, shown, level, ignore) {
|
|
|
1577
1608
|
}
|
|
1578
1609
|
function lockText(path) {
|
|
1579
1610
|
try {
|
|
1580
|
-
return
|
|
1611
|
+
return readFileSync6(join8(path, "bun.lock"), "utf8");
|
|
1581
1612
|
} catch {
|
|
1582
1613
|
return "";
|
|
1583
1614
|
}
|
|
@@ -1597,7 +1628,7 @@ function failure(ran) {
|
|
|
1597
1628
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1598
1629
|
}
|
|
1599
1630
|
function tint(severity) {
|
|
1600
|
-
const colors = paint(
|
|
1631
|
+
const colors = paint(process18.stdout);
|
|
1601
1632
|
if (severity === "critical" || severity === "high")
|
|
1602
1633
|
return colors.red;
|
|
1603
1634
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1614,14 +1645,14 @@ function rows(findings) {
|
|
|
1614
1645
|
}
|
|
1615
1646
|
async function audit(args) {
|
|
1616
1647
|
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"] });
|
|
1617
|
-
const root =
|
|
1618
|
-
if (!
|
|
1648
|
+
const root = resolve5(positionals[0] ?? ".");
|
|
1649
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1619
1650
|
fail(`no folder ${root}`);
|
|
1620
1651
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1621
1652
|
const paths = await findRepos(root);
|
|
1622
1653
|
if (paths.length === 0)
|
|
1623
1654
|
fail(`no bun.lock under ${root}`);
|
|
1624
|
-
const audits = await pool(paths, CONCURRENCY, async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1655
|
+
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1625
1656
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1626
1657
|
if (values.json === true)
|
|
1627
1658
|
printJson(kept);
|
|
@@ -1632,8 +1663,8 @@ async function audit(args) {
|
|
|
1632
1663
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1633
1664
|
}
|
|
1634
1665
|
function show(audits, total) {
|
|
1635
|
-
const label = role("label",
|
|
1636
|
-
const path = role("path",
|
|
1666
|
+
const label = role("label", process18.stdout);
|
|
1667
|
+
const path = role("path", process18.stdout);
|
|
1637
1668
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1638
1669
|
if (flagged.length === 0) {
|
|
1639
1670
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1653,4 +1684,4 @@ function show(audits, total) {
|
|
|
1653
1684
|
}
|
|
1654
1685
|
|
|
1655
1686
|
// src/audit-cli.ts
|
|
1656
|
-
|
|
1687
|
+
process19.exitCode = await runMain({ name: "audit", run: audit });
|