@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/repos-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/repos-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process20 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,41 +1396,32 @@ 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/repos.ts
|
|
1385
|
-
import { existsSync as
|
|
1416
|
+
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1386
1417
|
import { basename as basename2, relative } from "path";
|
|
1387
|
-
import
|
|
1418
|
+
import process19 from "process";
|
|
1388
1419
|
|
|
1389
1420
|
// src/repos-scan.ts
|
|
1390
|
-
import { existsSync as
|
|
1421
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1391
1422
|
import { readdir } from "fs/promises";
|
|
1392
1423
|
import { basename, join as join7 } from "path";
|
|
1393
|
-
import
|
|
1424
|
+
import process18 from "process";
|
|
1394
1425
|
var MAX_DEPTH = 3;
|
|
1395
1426
|
var CONCURRENCY = 8;
|
|
1396
1427
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1412,7 +1443,7 @@ function reasonsOf(repo) {
|
|
|
1412
1443
|
return reasons;
|
|
1413
1444
|
}
|
|
1414
1445
|
async function findRepos(root, skip) {
|
|
1415
|
-
if (
|
|
1446
|
+
if (existsSync4(join7(root, ".git")))
|
|
1416
1447
|
return [root];
|
|
1417
1448
|
const found = [];
|
|
1418
1449
|
async function walk(dir, depth) {
|
|
@@ -1426,7 +1457,7 @@ async function findRepos(root, skip) {
|
|
|
1426
1457
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1427
1458
|
continue;
|
|
1428
1459
|
const path = join7(dir, entry.name);
|
|
1429
|
-
if (
|
|
1460
|
+
if (existsSync4(join7(path, ".git")))
|
|
1430
1461
|
found.push(path);
|
|
1431
1462
|
else if (depth < MAX_DEPTH)
|
|
1432
1463
|
await walk(path, depth + 1);
|
|
@@ -1437,7 +1468,7 @@ async function findRepos(root, skip) {
|
|
|
1437
1468
|
}
|
|
1438
1469
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1439
1470
|
try {
|
|
1440
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1471
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1441
1472
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1442
1473
|
} catch {
|
|
1443
1474
|
return;
|
|
@@ -1456,7 +1487,7 @@ async function packageReleases(path) {
|
|
|
1456
1487
|
names.add(name);
|
|
1457
1488
|
}
|
|
1458
1489
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1459
|
-
const folder = [join7("packages", name), name].find((candidate) =>
|
|
1490
|
+
const folder = [join7("packages", name), name].find((candidate) => existsSync4(join7(path, candidate)));
|
|
1460
1491
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1461
1492
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1462
1493
|
});
|
|
@@ -1514,7 +1545,7 @@ function firstLine(text) {
|
|
|
1514
1545
|
}
|
|
1515
1546
|
async function fastForward(path) {
|
|
1516
1547
|
try {
|
|
1517
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1548
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1518
1549
|
if (ran.timedOut)
|
|
1519
1550
|
return "timed out";
|
|
1520
1551
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1543,7 +1574,7 @@ var OPTIONS = {
|
|
|
1543
1574
|
};
|
|
1544
1575
|
async function skipped() {
|
|
1545
1576
|
const file = userConfigReadPath("repos");
|
|
1546
|
-
if (!
|
|
1577
|
+
if (!existsSync5(file))
|
|
1547
1578
|
return new Set;
|
|
1548
1579
|
try {
|
|
1549
1580
|
const config = await Bun.file(file).json();
|
|
@@ -1557,7 +1588,7 @@ function releasedCell(repo) {
|
|
|
1557
1588
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1558
1589
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1559
1590
|
}
|
|
1560
|
-
function syncCell(repo, stream =
|
|
1591
|
+
function syncCell(repo, stream = process19.stdout) {
|
|
1561
1592
|
const colors = paint(stream);
|
|
1562
1593
|
const ahead = repo.ahead ?? 0;
|
|
1563
1594
|
const behind = repo.behind ?? 0;
|
|
@@ -1568,7 +1599,7 @@ function syncCell(repo, stream = process18.stdout) {
|
|
|
1568
1599
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1569
1600
|
}
|
|
1570
1601
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1571
|
-
function branchCell(repo, stream =
|
|
1602
|
+
function branchCell(repo, stream = process19.stdout) {
|
|
1572
1603
|
const colors = paint(stream);
|
|
1573
1604
|
if (repo.unreadable)
|
|
1574
1605
|
return colors.red("? (unreadable)");
|
|
@@ -1577,8 +1608,8 @@ function branchCell(repo, stream = process18.stdout) {
|
|
|
1577
1608
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1578
1609
|
}
|
|
1579
1610
|
function row(repo, shown) {
|
|
1580
|
-
const colors = paint(
|
|
1581
|
-
const tint = role("path",
|
|
1611
|
+
const colors = paint(process19.stdout);
|
|
1612
|
+
const tint = role("path", process19.stdout);
|
|
1582
1613
|
const unreleased = releasedCell(repo);
|
|
1583
1614
|
return [
|
|
1584
1615
|
tint(shown),
|
|
@@ -1594,11 +1625,11 @@ async function repos(args) {
|
|
|
1594
1625
|
if (values.watch !== undefined)
|
|
1595
1626
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1596
1627
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1597
|
-
if (!
|
|
1628
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1598
1629
|
fail(`no folder ${root}`);
|
|
1599
1630
|
const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
|
|
1600
1631
|
const paths = await findRepos(root, await skipped());
|
|
1601
|
-
const states = await pool(paths, CONCURRENCY, async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1632
|
+
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1602
1633
|
const keeps = (repo) => {
|
|
1603
1634
|
const reasons = reasonsOf(repo);
|
|
1604
1635
|
return only === undefined ? values.all === true || reasons.length > 0 || repo.unreadable : reasons.includes(only);
|
|
@@ -1612,12 +1643,12 @@ async function repos(args) {
|
|
|
1612
1643
|
const blocker = pullBlocker(repo);
|
|
1613
1644
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1614
1645
|
if (blocker !== undefined) {
|
|
1615
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1646
|
+
log(marked("note", `${repo.name} skipped`, process19.stdout, blocker));
|
|
1616
1647
|
} else if (refused !== undefined) {
|
|
1617
1648
|
failedPulls++;
|
|
1618
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1649
|
+
log(marked("problem", `${repo.name} not pulled`, process19.stdout, refused));
|
|
1619
1650
|
} else {
|
|
1620
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1651
|
+
log(marked("ok", `${repo.name} pulled`, process19.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1621
1652
|
states[index] = await inspect(repo.path, false);
|
|
1622
1653
|
}
|
|
1623
1654
|
}
|
|
@@ -1632,7 +1663,7 @@ async function repos(args) {
|
|
|
1632
1663
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1633
1664
|
return failedPulls > 0 ? 1 : 0;
|
|
1634
1665
|
}
|
|
1635
|
-
const label = role("label",
|
|
1666
|
+
const label = role("label", process19.stdout);
|
|
1636
1667
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1637
1668
|
if (kept.length === 0) {
|
|
1638
1669
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1648,4 +1679,4 @@ async function repos(args) {
|
|
|
1648
1679
|
}
|
|
1649
1680
|
|
|
1650
1681
|
// src/repos-cli.ts
|
|
1651
|
-
|
|
1682
|
+
process20.exitCode = await runMain({ name: "repos", run: repos });
|