@kaynooo/cli-workspace 0.11.1 → 0.14.1
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 +25 -25
- package/dist/cli.js +1077 -457
- package/package.json +9 -15
- package/dist/audit-cli.js +0 -1927
- package/dist/repos-cli.js +0 -1797
- package/dist/sweep-cli.js +0 -2187
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
import process24 from "process";
|
|
6
|
-
|
|
7
|
-
// ../kit/src/advisory.ts
|
|
8
|
-
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
9
|
-
function severityRank(severity) {
|
|
10
|
-
return SEVERITIES.indexOf(severity);
|
|
11
|
-
}
|
|
12
|
-
function isIgnored(advisory, ignore) {
|
|
13
|
-
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
14
|
-
}
|
|
15
|
-
// ../kit/src/args.ts
|
|
16
|
-
import process9 from "process";
|
|
17
|
-
import { parseArgs } from "util";
|
|
18
|
-
|
|
19
|
-
// ../kit/src/format.ts
|
|
20
|
-
import process7 from "process";
|
|
21
|
-
|
|
22
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
|
|
23
|
-
var r = new Map;
|
|
24
|
-
var i = new Map;
|
|
25
|
-
var l = new Map;
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
|
|
26
16
|
function a(e, t, o) {
|
|
27
17
|
return JSON.stringify([e ?? null, t ?? null, o]);
|
|
28
18
|
}
|
|
@@ -32,12 +22,15 @@ function y(e, t) {
|
|
|
32
22
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
33
23
|
return n;
|
|
34
24
|
}
|
|
25
|
+
var r, i, l;
|
|
26
|
+
var init_chunk_n6z2kk96 = __esm(() => {
|
|
27
|
+
r = new Map;
|
|
28
|
+
i = new Map;
|
|
29
|
+
l = new Map;
|
|
30
|
+
});
|
|
35
31
|
|
|
36
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.
|
|
37
|
-
|
|
38
|
-
var Nt = /\s+\S*$/;
|
|
39
|
-
var Y = /\s/;
|
|
40
|
-
function ko(t, e, r = "...") {
|
|
32
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
33
|
+
function Ao(t, e, r = "...") {
|
|
41
34
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
42
35
|
if (t.length <= e)
|
|
43
36
|
return t;
|
|
@@ -48,13 +41,22 @@ function ko(t, e, r = "...") {
|
|
|
48
41
|
c = c.trimEnd();
|
|
49
42
|
return s ? (c + n).slice(0, l) : c + n;
|
|
50
43
|
}
|
|
51
|
-
var
|
|
52
|
-
var
|
|
44
|
+
var N, Nt, Y, be, W;
|
|
45
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
46
|
+
N = new Map;
|
|
47
|
+
Nt = /\s+\S*$/;
|
|
48
|
+
Y = /\s/;
|
|
49
|
+
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));
|
|
50
|
+
W = new Map;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
54
|
+
var init_text = __esm(() => {
|
|
55
|
+
init_chunk_rkhsft4a();
|
|
56
|
+
});
|
|
53
57
|
|
|
54
58
|
// ../kit/src/mode.ts
|
|
55
59
|
import process2 from "process";
|
|
56
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
57
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
58
60
|
function isSet(value) {
|
|
59
61
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
60
62
|
}
|
|
@@ -71,12 +73,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
71
73
|
function isInteractive(streams = process2) {
|
|
72
74
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
73
75
|
}
|
|
76
|
+
var MODES, AGENT_VARIABLES;
|
|
77
|
+
var init_mode = __esm(() => {
|
|
78
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
79
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
80
|
+
});
|
|
74
81
|
|
|
75
|
-
//
|
|
76
|
-
import process6 from "process";
|
|
77
|
-
|
|
78
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
79
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
82
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
80
83
|
function b(r) {
|
|
81
84
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
82
85
|
if (!G2.test(e))
|
|
@@ -87,11 +90,6 @@ function b(r) {
|
|
|
87
90
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
88
91
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
89
92
|
}
|
|
90
|
-
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
91
|
-
let [l, n, c] = b(r);
|
|
92
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
93
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
94
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
95
93
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
96
94
|
if (e.FORCE_COLOR !== undefined)
|
|
97
95
|
return h.has(e.FORCE_COLOR);
|
|
@@ -105,7 +103,7 @@ function f(r, e = []) {
|
|
|
105
103
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
106
104
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
107
105
|
return new Proxy(c, { get(t, i) {
|
|
108
|
-
let a =
|
|
106
|
+
let a = B[i];
|
|
109
107
|
if (Array.isArray(a)) {
|
|
110
108
|
let s = g.get(i);
|
|
111
109
|
if (s === undefined)
|
|
@@ -128,13 +126,21 @@ function f(r, e = []) {
|
|
|
128
126
|
function Fe(r = {}) {
|
|
129
127
|
return f(r);
|
|
130
128
|
}
|
|
131
|
-
var
|
|
129
|
+
var G2, B, h, o;
|
|
130
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
131
|
+
G2 = /^[a-f0-9]+$/i;
|
|
132
|
+
B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
133
|
+
let [l, n, c] = b(r);
|
|
134
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
135
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
136
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
137
|
+
o = Fe();
|
|
138
|
+
});
|
|
132
139
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
import process5 from "process";
|
|
140
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
141
|
+
var init_colors = __esm(() => {
|
|
142
|
+
init_chunk_x450vn3m();
|
|
143
|
+
});
|
|
138
144
|
|
|
139
145
|
// ../kit/src/config.ts
|
|
140
146
|
import { existsSync } from "fs";
|
|
@@ -150,6 +156,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
158
|
}
|
|
159
|
+
var init_config = __esm(() => {
|
|
160
|
+
init_args();
|
|
161
|
+
});
|
|
153
162
|
|
|
154
163
|
// ../kit/src/user-config.ts
|
|
155
164
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -185,36 +194,49 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
|
185
194
|
const value = readUserConfig(bin, where, legacy)[key];
|
|
186
195
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
187
196
|
}
|
|
197
|
+
var init_user_config = () => {};
|
|
188
198
|
|
|
189
199
|
// ../kit/src/theme.ts
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
200
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
201
|
+
import { homedir as homedir2 } from "os";
|
|
202
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
203
|
+
import process5 from "process";
|
|
204
|
+
function toLinear(channel) {
|
|
205
|
+
const value = channel / 255;
|
|
206
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
207
|
+
}
|
|
208
|
+
function toOklab(hex) {
|
|
209
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
210
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
211
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
212
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
213
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
214
|
+
}
|
|
215
|
+
function fromOklab([lightness, a, b]) {
|
|
216
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
217
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
218
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
219
|
+
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
220
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
221
|
+
}
|
|
222
|
+
function gradientAt(theme, ratio) {
|
|
223
|
+
if (theme.gradient === undefined)
|
|
224
|
+
return;
|
|
225
|
+
const key = theme.gradient.join();
|
|
226
|
+
let ends = ENDS.get(key);
|
|
227
|
+
if (ends === undefined) {
|
|
228
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
229
|
+
ENDS.set(key, ends);
|
|
230
|
+
}
|
|
231
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
232
|
+
const [from, to] = ends;
|
|
233
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
234
|
+
}
|
|
212
235
|
function isColorSpec(spec) {
|
|
213
236
|
if (typeof spec === "number")
|
|
214
237
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
215
238
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
216
239
|
}
|
|
217
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
218
240
|
function cubeLevel(channel) {
|
|
219
241
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
220
242
|
}
|
|
@@ -239,6 +261,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
239
261
|
return chain[token] ?? chain;
|
|
240
262
|
}, colors);
|
|
241
263
|
}
|
|
264
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
265
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
266
|
+
}
|
|
242
267
|
function isRecord(value) {
|
|
243
268
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
244
269
|
}
|
|
@@ -319,7 +344,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
319
344
|
function endsWalk(home) {
|
|
320
345
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
321
346
|
}
|
|
322
|
-
var warned = new Set;
|
|
323
347
|
function warnOnce(message) {
|
|
324
348
|
if (warned.has(message))
|
|
325
349
|
return;
|
|
@@ -356,8 +380,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
356
380
|
}
|
|
357
381
|
return { theme, sources, preset };
|
|
358
382
|
}
|
|
359
|
-
var current;
|
|
360
|
-
var currentKey = "";
|
|
361
383
|
function activeTheme() {
|
|
362
384
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
363
385
|
if (current === undefined || key !== currentKey) {
|
|
@@ -366,9 +388,38 @@ function activeTheme() {
|
|
|
366
388
|
}
|
|
367
389
|
return current;
|
|
368
390
|
}
|
|
391
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
392
|
+
var init_theme = __esm(() => {
|
|
393
|
+
init_config();
|
|
394
|
+
init_user_config();
|
|
395
|
+
ENDS = new Map;
|
|
396
|
+
DEFAULT = {
|
|
397
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
398
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
399
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
400
|
+
bins: {},
|
|
401
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
402
|
+
};
|
|
403
|
+
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
404
|
+
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
405
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
406
|
+
PRESETS = {
|
|
407
|
+
default: {},
|
|
408
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
409
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
410
|
+
ascii: { glyphs: ASCII }
|
|
411
|
+
};
|
|
412
|
+
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
413
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
414
|
+
CONTROL = /\p{Cc}/u;
|
|
415
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
416
|
+
SPACES = /\s+/;
|
|
417
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
418
|
+
warned = new Set;
|
|
419
|
+
});
|
|
369
420
|
|
|
370
421
|
// ../kit/src/style.ts
|
|
371
|
-
|
|
422
|
+
import process6 from "process";
|
|
372
423
|
function takesControlCodes(stream, env = process6.env) {
|
|
373
424
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
374
425
|
}
|
|
@@ -397,14 +448,6 @@ function role(name, stream, env = process6.env) {
|
|
|
397
448
|
const colors = paint(stream, env);
|
|
398
449
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
399
450
|
}
|
|
400
|
-
var STATUS_WORDS = {
|
|
401
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
402
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
403
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
404
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
405
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
406
|
-
};
|
|
407
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
408
451
|
function header(bin, context, stream, env = process6.env) {
|
|
409
452
|
if (!takesControlCodes(stream, env))
|
|
410
453
|
return "";
|
|
@@ -420,7 +463,23 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
|
|
|
420
463
|
if (line !== "")
|
|
421
464
|
console.log(line);
|
|
422
465
|
}
|
|
423
|
-
|
|
466
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
467
|
+
var init_style = __esm(() => {
|
|
468
|
+
init_colors();
|
|
469
|
+
init_mode();
|
|
470
|
+
init_theme();
|
|
471
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
472
|
+
STATUS_WORDS = {
|
|
473
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
474
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
475
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
476
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
477
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
478
|
+
};
|
|
479
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
424
483
|
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
425
484
|
let e = r === "si" ? 1000 : 1024;
|
|
426
485
|
if (Math.abs(i) < e)
|
|
@@ -431,9 +490,17 @@ function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
|
431
490
|
while (Math.round(Math.abs(i) * a) / a >= e && o < s.length - 1);
|
|
432
491
|
return `${n ? y(n, { minimumFractionDigits: t, maximumFractionDigits: t }).format(i) : i.toFixed(t)} ${s[o]}`;
|
|
433
492
|
}
|
|
493
|
+
var init_chunk_knqbxp56 = __esm(() => {
|
|
494
|
+
init_chunk_n6z2kk96();
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/format/index.js
|
|
498
|
+
var init_format = __esm(() => {
|
|
499
|
+
init_chunk_knqbxp56();
|
|
500
|
+
});
|
|
434
501
|
|
|
435
502
|
// ../kit/src/format.ts
|
|
436
|
-
|
|
503
|
+
import process7 from "process";
|
|
437
504
|
function formatSeconds(total) {
|
|
438
505
|
let rest = Math.max(0, Math.round(total));
|
|
439
506
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -450,6 +517,9 @@ function formatSeconds(total) {
|
|
|
450
517
|
function formatDuration(ms) {
|
|
451
518
|
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
452
519
|
}
|
|
520
|
+
function formatElapsed(ms) {
|
|
521
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
522
|
+
}
|
|
453
523
|
function upTo(text, separator) {
|
|
454
524
|
const end = text.indexOf(separator);
|
|
455
525
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -462,10 +532,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
462
532
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
463
533
|
}
|
|
464
534
|
function truncate(text, width) {
|
|
465
|
-
return
|
|
535
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
466
536
|
}
|
|
467
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
468
|
-
var ESCAPE = String.fromCharCode(27);
|
|
469
537
|
function textWidth(text) {
|
|
470
538
|
return Bun.stringWidth(text);
|
|
471
539
|
}
|
|
@@ -514,14 +582,41 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
514
582
|
function printJson(value) {
|
|
515
583
|
console.log(jsonText(value));
|
|
516
584
|
}
|
|
585
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
586
|
+
var init_format2 = __esm(() => {
|
|
587
|
+
init_text();
|
|
588
|
+
init_mode();
|
|
589
|
+
init_style();
|
|
590
|
+
init_format();
|
|
591
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
592
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
593
|
+
ESCAPE = String.fromCharCode(27);
|
|
594
|
+
});
|
|
517
595
|
|
|
518
596
|
// ../kit/src/help.ts
|
|
519
597
|
import process8 from "process";
|
|
520
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
521
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
522
|
-
var FULL_STOP = /\.$/;
|
|
523
598
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
524
|
-
|
|
599
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
600
|
+
`);
|
|
601
|
+
const blank = lines.indexOf("");
|
|
602
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
603
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
604
|
+
const colon = synopses[0].indexOf(": ");
|
|
605
|
+
const inline = synopses[0].slice(colon + 2);
|
|
606
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
607
|
+
if (colon !== -1)
|
|
608
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
609
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
610
|
+
`)}`;
|
|
611
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
612
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
613
|
+
return [head, ...lead, ...rest].join(`
|
|
614
|
+
`);
|
|
615
|
+
}
|
|
616
|
+
function prose(line, colors) {
|
|
617
|
+
if (colors.cyan("x") === "x")
|
|
618
|
+
return line;
|
|
619
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
525
620
|
}
|
|
526
621
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
527
622
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -556,7 +651,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
556
651
|
return [];
|
|
557
652
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
558
653
|
}
|
|
559
|
-
var MAX_INLINE_CHOICES = 24;
|
|
560
654
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
561
655
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
562
656
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -571,6 +665,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
571
665
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
572
666
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
573
667
|
}
|
|
668
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
669
|
+
var init_help = __esm(() => {
|
|
670
|
+
init_mode();
|
|
671
|
+
init_style();
|
|
672
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
673
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
674
|
+
FULL_STOP = /\.$/;
|
|
675
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
676
|
+
});
|
|
574
677
|
|
|
575
678
|
// ../kit/src/text.ts
|
|
576
679
|
function distance(a, b) {
|
|
@@ -598,9 +701,9 @@ function closest(name, names) {
|
|
|
598
701
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
599
702
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
600
703
|
}
|
|
704
|
+
var init_text2 = () => {};
|
|
705
|
+
|
|
601
706
|
// ../kit/src/input.ts
|
|
602
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
603
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
604
707
|
function duration(value, name, fallback, unit = "s") {
|
|
605
708
|
if (value === undefined)
|
|
606
709
|
return fallback;
|
|
@@ -610,40 +713,26 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
610
713
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
611
714
|
return ms;
|
|
612
715
|
}
|
|
716
|
+
var DURATION, UNIT_MS;
|
|
717
|
+
var init_input = __esm(() => {
|
|
718
|
+
init_args();
|
|
719
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
720
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
721
|
+
});
|
|
613
722
|
|
|
614
723
|
// ../kit/src/args.ts
|
|
615
|
-
|
|
724
|
+
import process9 from "process";
|
|
725
|
+
import { parseArgs } from "util";
|
|
616
726
|
function jsonOption(holds) {
|
|
617
727
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
618
728
|
}
|
|
619
|
-
class Exit extends Error {
|
|
620
|
-
code;
|
|
621
|
-
hint;
|
|
622
|
-
constructor(message, code, hint) {
|
|
623
|
-
super(message);
|
|
624
|
-
this.code = code;
|
|
625
|
-
this.hint = hint;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
729
|
function fail(message, code = 2, hint) {
|
|
629
730
|
throw new Exit(message, code, hint);
|
|
630
731
|
}
|
|
631
|
-
|
|
632
|
-
class UsageError extends Exit {
|
|
633
|
-
constructor(message, hint) {
|
|
634
|
-
super(message, 2, hint);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
732
|
function badUsage(message) {
|
|
638
733
|
throw new UsageError(message);
|
|
639
734
|
}
|
|
640
735
|
|
|
641
|
-
class HelpShown extends Exit {
|
|
642
|
-
constructor() {
|
|
643
|
-
super("help shown", 0);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
736
|
class Completing {
|
|
648
737
|
options;
|
|
649
738
|
positionals;
|
|
@@ -654,11 +743,6 @@ class Completing {
|
|
|
654
743
|
this.candidates = candidates;
|
|
655
744
|
}
|
|
656
745
|
}
|
|
657
|
-
var completion = { active: false };
|
|
658
|
-
var OUTPUT_OPTIONS = {
|
|
659
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
660
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
661
|
-
};
|
|
662
746
|
function applyOutput(color, plain, env = process9.env) {
|
|
663
747
|
const when = plain === true ? "never" : color ?? "auto";
|
|
664
748
|
if (when === "auto")
|
|
@@ -812,7 +896,6 @@ function parseError(error) {
|
|
|
812
896
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
813
897
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
814
898
|
}
|
|
815
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
816
899
|
function nearestOption(message, options, allowNegative) {
|
|
817
900
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
818
901
|
if (typed === undefined)
|
|
@@ -828,6 +911,303 @@ function nearestOption(message, options, allowNegative) {
|
|
|
828
911
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
829
912
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
830
913
|
}
|
|
914
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
915
|
+
var init_args = __esm(() => {
|
|
916
|
+
init_format2();
|
|
917
|
+
init_help();
|
|
918
|
+
init_text2();
|
|
919
|
+
init_help();
|
|
920
|
+
init_input();
|
|
921
|
+
DASHES = /^-+/;
|
|
922
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
923
|
+
Exit = class Exit extends Error {
|
|
924
|
+
code;
|
|
925
|
+
hint;
|
|
926
|
+
[EXIT] = true;
|
|
927
|
+
constructor(message, code, hint) {
|
|
928
|
+
super(message);
|
|
929
|
+
this.code = code;
|
|
930
|
+
this.hint = hint;
|
|
931
|
+
}
|
|
932
|
+
static [Symbol.hasInstance](value) {
|
|
933
|
+
if (this !== Exit)
|
|
934
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
935
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
UsageError = class UsageError extends Exit {
|
|
939
|
+
constructor(message, hint) {
|
|
940
|
+
super(message, 2, hint);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
HelpShown = class HelpShown extends Exit {
|
|
944
|
+
constructor() {
|
|
945
|
+
super("help shown", 0);
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
completion = { active: false };
|
|
949
|
+
OUTPUT_OPTIONS = {
|
|
950
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
951
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
952
|
+
};
|
|
953
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
// ../kit/src/folders.ts
|
|
957
|
+
var SKIPPED_FOLDERS;
|
|
958
|
+
var init_folders = __esm(() => {
|
|
959
|
+
init_user_config();
|
|
960
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// ../kit/src/answers.ts
|
|
964
|
+
var init_answers = __esm(() => {
|
|
965
|
+
init_folders();
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
// ../kit/src/job.ts
|
|
969
|
+
import process24 from "process";
|
|
970
|
+
function stopJob() {
|
|
971
|
+
process24.kill(0, "SIGTSTP");
|
|
972
|
+
}
|
|
973
|
+
var init_job = () => {};
|
|
974
|
+
|
|
975
|
+
// ../kit/src/picker/line.ts
|
|
976
|
+
function isEditKey(key) {
|
|
977
|
+
return EDIT_KEYS.has(key);
|
|
978
|
+
}
|
|
979
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS;
|
|
980
|
+
var init_line = __esm(() => {
|
|
981
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
982
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
983
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
// ../kit/src/picker/score.ts
|
|
987
|
+
var BOUNDARY_AFTER, NONE;
|
|
988
|
+
var init_score = __esm(() => {
|
|
989
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
990
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
// ../kit/src/picker/state.ts
|
|
994
|
+
function repeat(value, count) {
|
|
995
|
+
return Array.from({ length: count }).fill(value);
|
|
996
|
+
}
|
|
997
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
998
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
999
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1000
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1001
|
+
if (wheel !== undefined)
|
|
1002
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1003
|
+
const named = codes.get(sequence);
|
|
1004
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1005
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1006
|
+
paste.active = sequence === PASTE_START;
|
|
1007
|
+
return [];
|
|
1008
|
+
}
|
|
1009
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1010
|
+
`))
|
|
1011
|
+
return [];
|
|
1012
|
+
if (key !== undefined)
|
|
1013
|
+
return [key];
|
|
1014
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
1018
|
+
var init_state = __esm(() => {
|
|
1019
|
+
init_text2();
|
|
1020
|
+
init_line();
|
|
1021
|
+
init_score();
|
|
1022
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1023
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1024
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1025
|
+
KEYS = {
|
|
1026
|
+
"\x1B[A": "up",
|
|
1027
|
+
"\x1BOA": "up",
|
|
1028
|
+
"\x10": "up",
|
|
1029
|
+
"\x1B[B": "down",
|
|
1030
|
+
"\x1BOB": "down",
|
|
1031
|
+
"\x0E": "down",
|
|
1032
|
+
"\x1B[5~": "pageup",
|
|
1033
|
+
"\x1B[6~": "pagedown",
|
|
1034
|
+
"\x1B[H": "home",
|
|
1035
|
+
"\x1B[1~": "home",
|
|
1036
|
+
"\x1BOH": "home",
|
|
1037
|
+
"\x1B[F": "end",
|
|
1038
|
+
"\x1B[4~": "end",
|
|
1039
|
+
"\x1BOF": "end",
|
|
1040
|
+
"\r": "enter",
|
|
1041
|
+
"\n": "enter",
|
|
1042
|
+
"\x03": "cancel",
|
|
1043
|
+
"\x1B": "cancel",
|
|
1044
|
+
"\x1B[D": "left",
|
|
1045
|
+
"\x1BOD": "left",
|
|
1046
|
+
"\x1B[C": "right",
|
|
1047
|
+
"\x1BOC": "right",
|
|
1048
|
+
"\x1B[1;5D": "wordleft",
|
|
1049
|
+
"\x1B[1;3D": "wordleft",
|
|
1050
|
+
"\x1Bb": "wordleft",
|
|
1051
|
+
"\x1B[1;5C": "wordright",
|
|
1052
|
+
"\x1B[1;3C": "wordright",
|
|
1053
|
+
"\x1Bf": "wordright",
|
|
1054
|
+
"\x01": "linestart",
|
|
1055
|
+
"\x05": "lineend",
|
|
1056
|
+
"\x7F": "erase",
|
|
1057
|
+
"\x1B[3~": "delete",
|
|
1058
|
+
"\b": "killword",
|
|
1059
|
+
"\x1B\x7F": "killword",
|
|
1060
|
+
"\x1B[3;5~": "killnext",
|
|
1061
|
+
"\x1Bd": "killnext",
|
|
1062
|
+
"\x15": "clear",
|
|
1063
|
+
"\v": "killend",
|
|
1064
|
+
"\x17": "word",
|
|
1065
|
+
"\x19": "yank",
|
|
1066
|
+
"\x1A": "suspend",
|
|
1067
|
+
"\t": "tab",
|
|
1068
|
+
"\x1F": "help",
|
|
1069
|
+
"\x1BOP": "help",
|
|
1070
|
+
"\x1B[11~": "help"
|
|
1071
|
+
};
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// ../kit/src/redraw.ts
|
|
1075
|
+
function overwrite(lines, columns) {
|
|
1076
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1077
|
+
`);
|
|
1078
|
+
}
|
|
1079
|
+
function rowsTaken(lines, columns) {
|
|
1080
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1081
|
+
}
|
|
1082
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1083
|
+
var init_redraw = __esm(() => {
|
|
1084
|
+
init_format2();
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
// ../kit/src/prompt.ts
|
|
1088
|
+
import process25 from "process";
|
|
1089
|
+
function readKeys(input, paste = { active: false }) {
|
|
1090
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1091
|
+
}
|
|
1092
|
+
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1093
|
+
let answered = fallback;
|
|
1094
|
+
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
1095
|
+
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
1096
|
+
if (key === "cancel")
|
|
1097
|
+
return "cancel";
|
|
1098
|
+
if (key === "enter")
|
|
1099
|
+
return answered === undefined ? undefined : "enter";
|
|
1100
|
+
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
1101
|
+
if (letter !== "y" && letter !== "n")
|
|
1102
|
+
return;
|
|
1103
|
+
answered = letter === "y";
|
|
1104
|
+
return "enter";
|
|
1105
|
+
});
|
|
1106
|
+
return accepted ? answered : undefined;
|
|
1107
|
+
}
|
|
1108
|
+
function asking(colors, question, typed, keys) {
|
|
1109
|
+
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
1110
|
+
}
|
|
1111
|
+
function answer(colors, question, state, picked) {
|
|
1112
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1113
|
+
}
|
|
1114
|
+
async function ask(question, { hint, terminal = process25 }, render, press) {
|
|
1115
|
+
const { stdin, stderr } = terminal;
|
|
1116
|
+
if (!isInteractive(terminal))
|
|
1117
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1118
|
+
const colors = paint(stderr);
|
|
1119
|
+
let current = "asking";
|
|
1120
|
+
let outcome;
|
|
1121
|
+
const columns = () => stderr.columns || 80;
|
|
1122
|
+
const draw = (state, last = false) => {
|
|
1123
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1124
|
+
const rows = rowsTaken(frame, columns());
|
|
1125
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1126
|
+
current = state;
|
|
1127
|
+
};
|
|
1128
|
+
const redraw = () => draw(current);
|
|
1129
|
+
const paste = { active: false };
|
|
1130
|
+
const stop = terminal.stop ?? (terminal === process25 ? stopJob : undefined);
|
|
1131
|
+
const suspend = () => {
|
|
1132
|
+
if (stop === undefined)
|
|
1133
|
+
return;
|
|
1134
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1135
|
+
stdin.setRawMode(false);
|
|
1136
|
+
stop();
|
|
1137
|
+
stdin.setRawMode(true);
|
|
1138
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1139
|
+
};
|
|
1140
|
+
try {
|
|
1141
|
+
stderr.on?.("resize", redraw);
|
|
1142
|
+
stdin.setRawMode(true);
|
|
1143
|
+
stdin.resume();
|
|
1144
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1145
|
+
draw("asking");
|
|
1146
|
+
return await new Promise((resolve) => {
|
|
1147
|
+
function onData(data) {
|
|
1148
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1149
|
+
if (key === "suspend") {
|
|
1150
|
+
suspend();
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
const pressed = press(key);
|
|
1154
|
+
if (pressed !== undefined) {
|
|
1155
|
+
settle(pressed);
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
draw("asking");
|
|
1160
|
+
}
|
|
1161
|
+
function onEnd() {
|
|
1162
|
+
settle("cancel");
|
|
1163
|
+
}
|
|
1164
|
+
function settle(settled) {
|
|
1165
|
+
outcome = settled;
|
|
1166
|
+
stdin.off("data", onData);
|
|
1167
|
+
stdin.off("end", onEnd);
|
|
1168
|
+
resolve(settled === "enter");
|
|
1169
|
+
}
|
|
1170
|
+
stdin.on("data", onData);
|
|
1171
|
+
stdin.on("end", onEnd);
|
|
1172
|
+
});
|
|
1173
|
+
} finally {
|
|
1174
|
+
stderr.off?.("resize", redraw);
|
|
1175
|
+
draw(outcome ?? "cancel", true);
|
|
1176
|
+
stderr.write(`
|
|
1177
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1178
|
+
stdin.setRawMode(false);
|
|
1179
|
+
stdin.pause();
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
var PROMPT_KEYS;
|
|
1183
|
+
var init_prompt = __esm(() => {
|
|
1184
|
+
init_answers();
|
|
1185
|
+
init_args();
|
|
1186
|
+
init_format2();
|
|
1187
|
+
init_job();
|
|
1188
|
+
init_mode();
|
|
1189
|
+
init_line();
|
|
1190
|
+
init_state();
|
|
1191
|
+
init_redraw();
|
|
1192
|
+
init_style();
|
|
1193
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
// src/cli.ts
|
|
1197
|
+
import process26 from "process";
|
|
1198
|
+
|
|
1199
|
+
// ../kit/src/advisory.ts
|
|
1200
|
+
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
1201
|
+
function severityRank(severity) {
|
|
1202
|
+
return SEVERITIES.indexOf(severity);
|
|
1203
|
+
}
|
|
1204
|
+
function isIgnored(advisory, ignore) {
|
|
1205
|
+
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// ../kit/src/index.ts
|
|
1209
|
+
init_args();
|
|
1210
|
+
|
|
831
1211
|
// ../kit/src/argv.ts
|
|
832
1212
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
833
1213
|
import { resolve as resolve3 } from "path";
|
|
@@ -852,10 +1232,24 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
852
1232
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
853
1233
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
854
1234
|
}
|
|
1235
|
+
// ../kit/src/chart.ts
|
|
1236
|
+
init_format2();
|
|
1237
|
+
init_mode();
|
|
1238
|
+
init_style();
|
|
1239
|
+
init_theme();
|
|
1240
|
+
// ../kit/src/ci.ts
|
|
1241
|
+
init_args();
|
|
1242
|
+
init_format2();
|
|
1243
|
+
|
|
1244
|
+
// ../kit/src/progress.ts
|
|
1245
|
+
init_format2();
|
|
1246
|
+
import process12 from "process";
|
|
1247
|
+
|
|
855
1248
|
// ../kit/src/process.ts
|
|
856
1249
|
import { constants } from "os";
|
|
857
1250
|
import process11 from "process";
|
|
858
1251
|
var KILL_GRACE_MS = 2000;
|
|
1252
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
859
1253
|
function exitCodeOf(code, signal) {
|
|
860
1254
|
if (code !== null)
|
|
861
1255
|
return code;
|
|
@@ -863,10 +1257,41 @@ function exitCodeOf(code, signal) {
|
|
|
863
1257
|
return 128 + signal;
|
|
864
1258
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
865
1259
|
}
|
|
866
|
-
|
|
1260
|
+
function holdSignals(cleanup) {
|
|
1261
|
+
let received;
|
|
1262
|
+
let child;
|
|
1263
|
+
const held = {
|
|
1264
|
+
get signal() {
|
|
1265
|
+
return received;
|
|
1266
|
+
},
|
|
1267
|
+
forward: (to) => {
|
|
1268
|
+
child = to;
|
|
1269
|
+
},
|
|
1270
|
+
release: () => {
|
|
1271
|
+
for (const signal of SIGNALS)
|
|
1272
|
+
process11.off(signal, onSignal);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
function onSignal(signal) {
|
|
1276
|
+
received = signal;
|
|
1277
|
+
if (child !== undefined) {
|
|
1278
|
+
child.kill(signal);
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if (cleanup === undefined)
|
|
1282
|
+
return;
|
|
1283
|
+
held.release();
|
|
1284
|
+
cleanup(signal);
|
|
1285
|
+
process11.kill(process11.pid, signal);
|
|
1286
|
+
}
|
|
1287
|
+
for (const signal of SIGNALS)
|
|
1288
|
+
process11.on(signal, onSignal);
|
|
1289
|
+
return held;
|
|
1290
|
+
}
|
|
1291
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
867
1292
|
const chunks = [];
|
|
868
1293
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
869
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1294
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
870
1295
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
871
1296
|
const timers = [];
|
|
872
1297
|
const killGroup = (killing) => {
|
|
@@ -942,17 +1367,234 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
942
1367
|
};
|
|
943
1368
|
}
|
|
944
1369
|
|
|
945
|
-
// ../kit/src/progress.ts
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
var
|
|
949
|
-
var
|
|
1370
|
+
// ../kit/src/progress.ts
|
|
1371
|
+
init_style();
|
|
1372
|
+
init_theme();
|
|
1373
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1374
|
+
var FRAME_MS = 200;
|
|
1375
|
+
var BAR_WIDTH = 20;
|
|
1376
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
1377
|
+
var ESC = String.fromCharCode(27);
|
|
1378
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1379
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1380
|
+
var CTRL_C = 3;
|
|
1381
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1382
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1383
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
1384
|
+
if (!takesControlCodes(stream, env))
|
|
1385
|
+
return { redraw: () => {
|
|
1386
|
+
return;
|
|
1387
|
+
}, print: (text) => void stream.write(`${text}
|
|
1388
|
+
`), stop: () => {
|
|
1389
|
+
return;
|
|
1390
|
+
}, pause: () => () => {
|
|
1391
|
+
return;
|
|
1392
|
+
} };
|
|
1393
|
+
const write = stream.write.bind(stream);
|
|
1394
|
+
let frame = 0;
|
|
1395
|
+
let drawn = false;
|
|
1396
|
+
let paused = false;
|
|
1397
|
+
let stopped = false;
|
|
1398
|
+
const columns = () => {
|
|
1399
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1400
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
1401
|
+
};
|
|
1402
|
+
const clear = () => {
|
|
1403
|
+
if (drawn)
|
|
1404
|
+
write(CLEAR_BELOW);
|
|
1405
|
+
drawn = false;
|
|
1406
|
+
};
|
|
1407
|
+
const draw = () => {
|
|
1408
|
+
if (paused)
|
|
1409
|
+
return;
|
|
1410
|
+
const width = columns() - 1;
|
|
1411
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1412
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1413
|
+
if (lines.length === 0) {
|
|
1414
|
+
clear();
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
1418
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1419
|
+
drawn = true;
|
|
1420
|
+
};
|
|
1421
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1422
|
+
stream.on?.("resize", draw);
|
|
1423
|
+
let restore = interceptOutput(clear);
|
|
1424
|
+
let release = swallowInput();
|
|
1425
|
+
const onExit = () => {
|
|
1426
|
+
clear();
|
|
1427
|
+
release();
|
|
1428
|
+
};
|
|
1429
|
+
const signals = holdSignals(stop);
|
|
1430
|
+
function stop() {
|
|
1431
|
+
stopped = true;
|
|
1432
|
+
clearInterval(timer);
|
|
1433
|
+
stream.off?.("resize", draw);
|
|
1434
|
+
clear();
|
|
1435
|
+
restore();
|
|
1436
|
+
release();
|
|
1437
|
+
process12.off("exit", onExit);
|
|
1438
|
+
signals.release();
|
|
1439
|
+
}
|
|
1440
|
+
function pause() {
|
|
1441
|
+
if (paused || stopped)
|
|
1442
|
+
return () => {
|
|
1443
|
+
return;
|
|
1444
|
+
};
|
|
1445
|
+
paused = true;
|
|
1446
|
+
clearInterval(timer);
|
|
1447
|
+
stream.off?.("resize", draw);
|
|
1448
|
+
clear();
|
|
1449
|
+
restore();
|
|
1450
|
+
release();
|
|
1451
|
+
return () => {
|
|
1452
|
+
if (!paused || stopped)
|
|
1453
|
+
return;
|
|
1454
|
+
paused = false;
|
|
1455
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1456
|
+
timer.unref();
|
|
1457
|
+
stream.on?.("resize", draw);
|
|
1458
|
+
restore = interceptOutput(clear);
|
|
1459
|
+
release = swallowInput();
|
|
1460
|
+
draw();
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
timer.unref();
|
|
1464
|
+
process12.on("exit", onExit);
|
|
1465
|
+
return {
|
|
1466
|
+
redraw: draw,
|
|
1467
|
+
print: (text) => {
|
|
1468
|
+
clear();
|
|
1469
|
+
write(`${text}
|
|
1470
|
+
`);
|
|
1471
|
+
draw();
|
|
1472
|
+
},
|
|
1473
|
+
stop,
|
|
1474
|
+
pause
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1478
|
+
const colors = paint(stream, env);
|
|
1479
|
+
const write = stream.write.bind(stream);
|
|
1480
|
+
const begun = performance.now();
|
|
1481
|
+
let started = begun;
|
|
1482
|
+
let current;
|
|
1483
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1484
|
+
const end = (line) => {
|
|
1485
|
+
region.stop();
|
|
1486
|
+
write(`${line}
|
|
1487
|
+
`);
|
|
1488
|
+
};
|
|
1489
|
+
return {
|
|
1490
|
+
update: (progress) => {
|
|
1491
|
+
const step = current?.step;
|
|
1492
|
+
current = progress;
|
|
1493
|
+
if (progress.step !== step) {
|
|
1494
|
+
started = performance.now();
|
|
1495
|
+
region.redraw();
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
stop: region.stop,
|
|
1499
|
+
pause: region.pause,
|
|
1500
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1501
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1505
|
+
const { theme } = activeTheme();
|
|
1506
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1507
|
+
if (total !== undefined && total > 0) {
|
|
1508
|
+
const counted = Math.min(done ?? 0, total);
|
|
1509
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1510
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1511
|
+
}
|
|
1512
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1513
|
+
return parts;
|
|
1514
|
+
}
|
|
1515
|
+
function plain(text) {
|
|
1516
|
+
return text;
|
|
1517
|
+
}
|
|
1518
|
+
function tintedParts(parts, colors) {
|
|
1519
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1520
|
+
}
|
|
1521
|
+
function cutToWidth(line, width) {
|
|
1522
|
+
if (Bun.stringWidth(line) <= width)
|
|
1523
|
+
return line;
|
|
1524
|
+
let room = width;
|
|
1525
|
+
let kept = "";
|
|
1526
|
+
let index = 0;
|
|
1527
|
+
let linked = false;
|
|
1528
|
+
while (index < line.length) {
|
|
1529
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1530
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1531
|
+
if (escape !== null) {
|
|
1532
|
+
kept += escape[0];
|
|
1533
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1534
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1538
|
+
const columns = Bun.stringWidth(char);
|
|
1539
|
+
if (columns > room)
|
|
1540
|
+
break;
|
|
1541
|
+
kept += char;
|
|
1542
|
+
room -= columns;
|
|
1543
|
+
index += char.length;
|
|
1544
|
+
}
|
|
1545
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1546
|
+
}
|
|
1547
|
+
function swallowInput() {
|
|
1548
|
+
const input = process12.stdin;
|
|
1549
|
+
if (!input.isTTY)
|
|
1550
|
+
return () => {
|
|
1551
|
+
return;
|
|
1552
|
+
};
|
|
1553
|
+
const onData = (data) => {
|
|
1554
|
+
if (data.includes(CTRL_C))
|
|
1555
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1556
|
+
};
|
|
1557
|
+
input.setRawMode(true);
|
|
1558
|
+
input.on("data", onData);
|
|
1559
|
+
input.resume();
|
|
1560
|
+
let released = false;
|
|
1561
|
+
return () => {
|
|
1562
|
+
if (released)
|
|
1563
|
+
return;
|
|
1564
|
+
released = true;
|
|
1565
|
+
input.off("data", onData);
|
|
1566
|
+
input.pause();
|
|
1567
|
+
input.setRawMode(false);
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
function interceptOutput(clear) {
|
|
1571
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1572
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1573
|
+
const original = Reflect.get(target, name);
|
|
1574
|
+
const wrapper = (...args) => {
|
|
1575
|
+
clear();
|
|
1576
|
+
return original.apply(target, args);
|
|
1577
|
+
};
|
|
1578
|
+
Reflect.set(target, name, wrapper);
|
|
1579
|
+
return { target, name, original, wrapper };
|
|
1580
|
+
});
|
|
1581
|
+
return () => {
|
|
1582
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1583
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1584
|
+
Reflect.set(target, name, original);
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// ../kit/src/ci.ts
|
|
1590
|
+
init_style();
|
|
950
1591
|
|
|
951
1592
|
// ../kit/src/tool.ts
|
|
952
|
-
|
|
1593
|
+
init_format2();
|
|
1594
|
+
import process13 from "process";
|
|
953
1595
|
function cwdGone() {
|
|
954
1596
|
try {
|
|
955
|
-
|
|
1597
|
+
process13.cwd();
|
|
956
1598
|
return false;
|
|
957
1599
|
} catch {
|
|
958
1600
|
return true;
|
|
@@ -971,10 +1613,10 @@ function spawnFailure(command, error) {
|
|
|
971
1613
|
const missing = !gone && error?.code === "ENOENT";
|
|
972
1614
|
return new SpawnError(`${command}: ${error instanceof Error ? error.message : String(error)}${gone ? " (the working directory was removed)" : ""}`, missing);
|
|
973
1615
|
}
|
|
974
|
-
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
1616
|
+
async function runTool(label, argv, { timeoutMs, cwd, onStart, env } = {}) {
|
|
975
1617
|
let ran;
|
|
976
1618
|
try {
|
|
977
|
-
ran = await runCommand(argv, { env:
|
|
1619
|
+
ran = await runCommand(argv, { env: { ...process13.env, ...env }, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
978
1620
|
} catch (error) {
|
|
979
1621
|
throw spawnFailure(label, error);
|
|
980
1622
|
}
|
|
@@ -989,9 +1631,49 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
989
1631
|
return { code: ran.code, ...streams };
|
|
990
1632
|
}
|
|
991
1633
|
// ../kit/src/cli.ts
|
|
1634
|
+
init_args();
|
|
992
1635
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
993
1636
|
import { dirname as dirname3, join as join5 } from "path";
|
|
994
|
-
import
|
|
1637
|
+
import process17 from "process";
|
|
1638
|
+
|
|
1639
|
+
// ../kit/src/askpass.ts
|
|
1640
|
+
import process14 from "process";
|
|
1641
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1642
|
+
async function askpassClient(argv) {
|
|
1643
|
+
const socketPath = process14.env[SOCKET_VARIABLE];
|
|
1644
|
+
if (socketPath === undefined)
|
|
1645
|
+
return;
|
|
1646
|
+
const request = { prompt: argv[0] ?? "", ...process14.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1647
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1648
|
+
let received = "";
|
|
1649
|
+
try {
|
|
1650
|
+
await Bun.connect({
|
|
1651
|
+
unix: socketPath,
|
|
1652
|
+
socket: {
|
|
1653
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1654
|
+
`),
|
|
1655
|
+
data: (_, chunk) => {
|
|
1656
|
+
received += chunk.toString();
|
|
1657
|
+
},
|
|
1658
|
+
close: () => resolve(received),
|
|
1659
|
+
error: () => resolve("")
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
} catch {
|
|
1663
|
+
return 1;
|
|
1664
|
+
}
|
|
1665
|
+
const reply = await promise;
|
|
1666
|
+
if (reply === "")
|
|
1667
|
+
return 1;
|
|
1668
|
+
const { answer } = JSON.parse(reply);
|
|
1669
|
+
if (request.notice === true)
|
|
1670
|
+
return 0;
|
|
1671
|
+
if (answer === undefined)
|
|
1672
|
+
return 1;
|
|
1673
|
+
process14.stdout.write(`${answer}
|
|
1674
|
+
`);
|
|
1675
|
+
return 0;
|
|
1676
|
+
}
|
|
995
1677
|
|
|
996
1678
|
// ../kit/src/completions.ts
|
|
997
1679
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1054,28 +1736,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1054
1736
|
}
|
|
1055
1737
|
|
|
1056
1738
|
// ../kit/src/notify.ts
|
|
1057
|
-
|
|
1739
|
+
init_format2();
|
|
1740
|
+
init_mode();
|
|
1741
|
+
import process15 from "process";
|
|
1058
1742
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1059
1743
|
var CANCELLED = 130;
|
|
1060
1744
|
function base64(text) {
|
|
1061
1745
|
return Buffer.from(text).toString("base64");
|
|
1062
1746
|
}
|
|
1063
|
-
function notification(title, body, env =
|
|
1064
|
-
const id = `kit${
|
|
1747
|
+
function notification(title, body, env = process15.env) {
|
|
1748
|
+
const id = `kit${process15.pid}`;
|
|
1065
1749
|
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1066
1750
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1067
1751
|
}
|
|
1068
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1752
|
+
function notifyEnd(command, code, ms, { stream = process15.stderr, env = process15.env } = {}) {
|
|
1069
1753
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1070
1754
|
return;
|
|
1071
1755
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1072
1756
|
}
|
|
1073
1757
|
|
|
1758
|
+
// ../kit/src/cli.ts
|
|
1759
|
+
init_style();
|
|
1760
|
+
init_text2();
|
|
1761
|
+
|
|
1074
1762
|
// ../kit/src/usage.ts
|
|
1075
1763
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1076
1764
|
import { homedir as homedir3 } from "os";
|
|
1077
1765
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1078
|
-
import
|
|
1766
|
+
import process16 from "process";
|
|
1079
1767
|
|
|
1080
1768
|
// ../kit/src/logs.ts
|
|
1081
1769
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1089,14 +1777,14 @@ var usageError;
|
|
|
1089
1777
|
function noteUsageError(message) {
|
|
1090
1778
|
usageError = message;
|
|
1091
1779
|
}
|
|
1092
|
-
function stateHome(env =
|
|
1780
|
+
function stateHome(env = process16.env) {
|
|
1093
1781
|
const dir = env.XDG_STATE_HOME;
|
|
1094
1782
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1095
1783
|
}
|
|
1096
|
-
function usagePath(env =
|
|
1784
|
+
function usagePath(env = process16.env) {
|
|
1097
1785
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1098
1786
|
}
|
|
1099
|
-
function usageRecorded(env =
|
|
1787
|
+
function usageRecorded(env = process16.env) {
|
|
1100
1788
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1101
1789
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1102
1790
|
}
|
|
@@ -1105,12 +1793,12 @@ function flagNames(argv) {
|
|
|
1105
1793
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1106
1794
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1107
1795
|
}
|
|
1108
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1796
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1109
1797
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1110
1798
|
usageError = undefined;
|
|
1111
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1799
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1112
1800
|
}
|
|
1113
|
-
function recordUsage(entry, env =
|
|
1801
|
+
function recordUsage(entry, env = process16.env) {
|
|
1114
1802
|
if (!usageRecorded(env))
|
|
1115
1803
|
return;
|
|
1116
1804
|
try {
|
|
@@ -1204,8 +1892,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1204
1892
|
`);
|
|
1205
1893
|
}
|
|
1206
1894
|
function printError(prefix, message, hint, cause) {
|
|
1207
|
-
const colors = paint(
|
|
1208
|
-
const styled = takesControlCodes(
|
|
1895
|
+
const colors = paint(process17.stderr);
|
|
1896
|
+
const styled = takesControlCodes(process17.stderr);
|
|
1209
1897
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1210
1898
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1211
1899
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1248,11 +1936,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1248
1936
|
}
|
|
1249
1937
|
}
|
|
1250
1938
|
if (name === undefined && level.path.length > 1) {
|
|
1251
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1939
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stderr));
|
|
1252
1940
|
return 2;
|
|
1253
1941
|
}
|
|
1254
1942
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1255
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1943
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stdout));
|
|
1256
1944
|
return 0;
|
|
1257
1945
|
}
|
|
1258
1946
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1398,6 +2086,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1398
2086
|
}
|
|
1399
2087
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1400
2088
|
const version = cli.version ?? packageVersion();
|
|
2089
|
+
const answered = await askpassClient(argv);
|
|
2090
|
+
if (answered !== undefined)
|
|
2091
|
+
return answered;
|
|
1401
2092
|
if (argv[0] === COMPLETE)
|
|
1402
2093
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1403
2094
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1408,7 +2099,7 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1408
2099
|
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1409
2100
|
if (cli.usage !== false) {
|
|
1410
2101
|
try {
|
|
1411
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
2102
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1412
2103
|
} catch {}
|
|
1413
2104
|
}
|
|
1414
2105
|
return code;
|
|
@@ -1428,45 +2119,43 @@ function commandPath(scope, argv) {
|
|
|
1428
2119
|
}
|
|
1429
2120
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1430
2121
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1451
|
-
} catch {}
|
|
1452
|
-
}
|
|
1453
|
-
return code;
|
|
1454
|
-
}
|
|
1455
|
-
// ../kit/src/folders.ts
|
|
1456
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
2122
|
+
|
|
2123
|
+
// ../kit/src/index.ts
|
|
2124
|
+
init_config();
|
|
2125
|
+
|
|
2126
|
+
// ../kit/src/excerpt.ts
|
|
2127
|
+
init_text2();
|
|
2128
|
+
|
|
2129
|
+
// ../kit/src/index.ts
|
|
2130
|
+
init_folders();
|
|
2131
|
+
init_format2();
|
|
2132
|
+
|
|
2133
|
+
// ../kit/src/git.ts
|
|
2134
|
+
init_args();
|
|
2135
|
+
// ../kit/src/limit.ts
|
|
2136
|
+
init_args();
|
|
2137
|
+
|
|
2138
|
+
// ../kit/src/index.ts
|
|
2139
|
+
init_mode();
|
|
2140
|
+
|
|
1457
2141
|
// ../kit/src/pool.ts
|
|
1458
|
-
async function pool(items, limit, task) {
|
|
2142
|
+
async function pool(items, limit, task, onDone) {
|
|
1459
2143
|
const results = Array.from({ length: items.length });
|
|
1460
2144
|
let next = 0;
|
|
2145
|
+
let done = 0;
|
|
1461
2146
|
async function worker() {
|
|
1462
2147
|
while (next < items.length) {
|
|
1463
2148
|
const index = next++;
|
|
1464
2149
|
results[index] = await task(items[index]);
|
|
2150
|
+
onDone?.(++done, items.length);
|
|
1465
2151
|
}
|
|
1466
2152
|
}
|
|
1467
2153
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
1468
2154
|
return results;
|
|
1469
2155
|
}
|
|
2156
|
+
// ../kit/src/report.ts
|
|
2157
|
+
init_style();
|
|
2158
|
+
init_text2();
|
|
1470
2159
|
// ../kit/src/secrets.ts
|
|
1471
2160
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1472
2161
|
// ../kit/src/sessions.ts
|
|
@@ -1483,8 +2172,18 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1483
2172
|
const suffix = match[2].toLowerCase();
|
|
1484
2173
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1485
2174
|
}
|
|
2175
|
+
|
|
2176
|
+
// ../kit/src/index.ts
|
|
2177
|
+
init_style();
|
|
2178
|
+
init_text2();
|
|
2179
|
+
init_theme();
|
|
2180
|
+
init_user_config();
|
|
2181
|
+
|
|
1486
2182
|
// ../kit/src/watch.ts
|
|
1487
|
-
|
|
2183
|
+
init_args();
|
|
2184
|
+
init_input();
|
|
2185
|
+
init_style();
|
|
2186
|
+
import process18 from "process";
|
|
1488
2187
|
import { format } from "util";
|
|
1489
2188
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1490
2189
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1506,7 +2205,7 @@ function withoutWatch(args) {
|
|
|
1506
2205
|
}
|
|
1507
2206
|
return rest;
|
|
1508
2207
|
}
|
|
1509
|
-
async function watching(value, step, stream =
|
|
2208
|
+
async function watching(value, step, stream = process18.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1510
2209
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1511
2210
|
if (!takesControlCodes(stream))
|
|
1512
2211
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1514,12 +2213,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1514
2213
|
for (let round = 0;round < rounds; round++) {
|
|
1515
2214
|
const held = [];
|
|
1516
2215
|
const { log, info } = console;
|
|
1517
|
-
const write =
|
|
2216
|
+
const write = process18.stdout.write.bind(process18.stdout);
|
|
1518
2217
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1519
2218
|
`);
|
|
1520
2219
|
console.log = hold;
|
|
1521
2220
|
console.info = hold;
|
|
1522
|
-
|
|
2221
|
+
process18.stdout.write = (text) => {
|
|
1523
2222
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1524
2223
|
return true;
|
|
1525
2224
|
};
|
|
@@ -1528,7 +2227,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1528
2227
|
} finally {
|
|
1529
2228
|
console.log = log;
|
|
1530
2229
|
console.info = info;
|
|
1531
|
-
|
|
2230
|
+
process18.stdout.write = write;
|
|
1532
2231
|
}
|
|
1533
2232
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1534
2233
|
await sleep(interval);
|
|
@@ -1536,9 +2235,10 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1536
2235
|
return code;
|
|
1537
2236
|
}
|
|
1538
2237
|
// ../kit/src/workspace-root.ts
|
|
2238
|
+
init_user_config();
|
|
1539
2239
|
import { homedir as homedir4 } from "os";
|
|
1540
2240
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1541
|
-
import
|
|
2241
|
+
import process19 from "process";
|
|
1542
2242
|
function expandHome(path, home) {
|
|
1543
2243
|
if (path === "~")
|
|
1544
2244
|
return home;
|
|
@@ -1548,7 +2248,7 @@ function configured(env, home) {
|
|
|
1548
2248
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1549
2249
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1550
2250
|
}
|
|
1551
|
-
function workspaceRoot({ given, env =
|
|
2251
|
+
function workspaceRoot({ given, env = process19.env, home = homedir4() } = {}) {
|
|
1552
2252
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1553
2253
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1554
2254
|
}
|
|
@@ -1556,7 +2256,7 @@ function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
|
1556
2256
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync7, statSync as statSync2 } from "fs";
|
|
1557
2257
|
import { readdir } from "fs/promises";
|
|
1558
2258
|
import { join as join9, relative, resolve as resolve5 } from "path";
|
|
1559
|
-
import
|
|
2259
|
+
import process21 from "process";
|
|
1560
2260
|
|
|
1561
2261
|
// src/osv.ts
|
|
1562
2262
|
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
@@ -1785,12 +2485,11 @@ async function osvAudit(dir, level, ignore, fetcher = fetch) {
|
|
|
1785
2485
|
}
|
|
1786
2486
|
|
|
1787
2487
|
// src/audit.ts
|
|
1788
|
-
var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun, Composer, Cargo and uv repositories under root (the current folder by default), one table per repository
|
|
1789
|
-
|
|
1790
|
-
Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via and the direct dependencies leading to it, upgrading one of which is what fixes it), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
|
|
1791
|
-
Advisories under --level (moderate by default) are counted under the table, and what \`bun audit\` warned about, such as a private registry that would not audit its packages, is repeated there. It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry, and asks osv.dev about the packages of a composer.lock, Cargo.lock or uv.lock (a severity the source leaves out reads as moderate, and only composer's manifest tells direct from pulled in); the walk goes three levels deep, stops at a lockfile and skips node_modules and hidden folders.
|
|
2488
|
+
var USAGE = `ws audit [options] [root]: the known vulnerabilities of the Bun, Composer, Cargo and uv repositories under root (the current folder by default), one table per repository
|
|
1792
2489
|
|
|
1793
|
-
|
|
2490
|
+
Each package with an advisory is one row: its worst severity, advisory count, prod or dev, direct or via the direct dependencies leading to it, and the version that fixes every advisory at once.
|
|
2491
|
+
It reaches the network: \`bun audit --json\` for a bun.lock, osv.dev for a composer.lock, Cargo.lock or uv.lock; the walk goes three levels deep and stops at a lockfile.
|
|
2492
|
+
To sweep many repositories at once; \`pkg audit\` vets the one repository in depth.`;
|
|
1794
2493
|
var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no lockfile sits under root, a usage error or a root that is no folder"]];
|
|
1795
2494
|
var OPTIONS = {
|
|
1796
2495
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
@@ -1893,7 +2592,7 @@ function failure(ran) {
|
|
|
1893
2592
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1894
2593
|
}
|
|
1895
2594
|
function tint(severity) {
|
|
1896
|
-
const colors = paint(
|
|
2595
|
+
const colors = paint(process21.stdout);
|
|
1897
2596
|
if (severity === "critical" || severity === "high")
|
|
1898
2597
|
return colors.red;
|
|
1899
2598
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1909,15 +2608,23 @@ function rows(findings) {
|
|
|
1909
2608
|
]);
|
|
1910
2609
|
}
|
|
1911
2610
|
async function audit(args) {
|
|
1912
|
-
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"] });
|
|
2611
|
+
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: ["ws audit", "ws audit ~/Workspace --level high --prod"] });
|
|
1913
2612
|
const root = resolve5(positionals[0] ?? ".");
|
|
1914
2613
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1915
2614
|
fail(`no folder ${root}`);
|
|
1916
2615
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1917
|
-
const
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2616
|
+
const progress = progressLine();
|
|
2617
|
+
let audits;
|
|
2618
|
+
try {
|
|
2619
|
+
progress.update({ step: "finding the repositories" });
|
|
2620
|
+
const paths = await findRepos(root);
|
|
2621
|
+
if (paths.length === 0)
|
|
2622
|
+
fail(`no bun.lock, composer.lock, Cargo.lock or uv.lock under ${root}`);
|
|
2623
|
+
progress.update({ step: "auditing", done: 0, total: paths.length, unit: "repositories" });
|
|
2624
|
+
audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []), (done, total) => progress.update({ step: "auditing", done, total, unit: "repositories" }));
|
|
2625
|
+
} finally {
|
|
2626
|
+
progress.stop();
|
|
2627
|
+
}
|
|
1921
2628
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1922
2629
|
if (values.json === true)
|
|
1923
2630
|
printJson(kept);
|
|
@@ -1928,8 +2635,8 @@ async function audit(args) {
|
|
|
1928
2635
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1929
2636
|
}
|
|
1930
2637
|
function show(audits, total) {
|
|
1931
|
-
const label = role("label",
|
|
1932
|
-
const path = role("path",
|
|
2638
|
+
const label = role("label", process21.stdout);
|
|
2639
|
+
const path = role("path", process21.stdout);
|
|
1933
2640
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1934
2641
|
if (flagged.length === 0) {
|
|
1935
2642
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1951,13 +2658,13 @@ function show(audits, total) {
|
|
|
1951
2658
|
// src/repos.ts
|
|
1952
2659
|
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1953
2660
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1954
|
-
import
|
|
2661
|
+
import process23 from "process";
|
|
1955
2662
|
|
|
1956
2663
|
// src/repos-scan.ts
|
|
1957
2664
|
import { existsSync as existsSync7 } from "fs";
|
|
1958
2665
|
import { readdir as readdir2 } from "fs/promises";
|
|
1959
2666
|
import { basename, join as join10 } from "path";
|
|
1960
|
-
import
|
|
2667
|
+
import process22 from "process";
|
|
1961
2668
|
var MAX_DEPTH2 = 3;
|
|
1962
2669
|
var CONCURRENCY2 = 8;
|
|
1963
2670
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -2004,7 +2711,7 @@ async function findRepos2(root, skip) {
|
|
|
2004
2711
|
}
|
|
2005
2712
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
2006
2713
|
try {
|
|
2007
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
2714
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process22.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
2008
2715
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
2009
2716
|
} catch {
|
|
2010
2717
|
return;
|
|
@@ -2081,7 +2788,7 @@ function firstLine(text) {
|
|
|
2081
2788
|
}
|
|
2082
2789
|
async function fastForward(path) {
|
|
2083
2790
|
try {
|
|
2084
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
2791
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process22.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
2085
2792
|
if (ran.timedOut)
|
|
2086
2793
|
return "timed out";
|
|
2087
2794
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -2091,17 +2798,14 @@ async function fastForward(path) {
|
|
|
2091
2798
|
}
|
|
2092
2799
|
|
|
2093
2800
|
// src/repos.ts
|
|
2094
|
-
var USAGE2 = `repos [options] [root]: the git repositories under root (the configured workspace
|
|
2801
|
+
var USAGE2 = `ws repos [options] [root]: the git repositories under root (the configured workspace by default) that need attention: dirty files, commits not pushed, an upstream ahead, commits since the latest tag
|
|
2095
2802
|
|
|
2096
|
-
A repository with
|
|
2097
|
-
|
|
2098
|
-
Ahead and behind are those of the last fetch unless --fetch refreshes the upstreams first, which reaches the remote.
|
|
2099
|
-
--pull fetches, then fast-forwards the repositories listed that are clean, on a branch and only behind their upstream, and touches nothing else: a dirty, ahead, diverged or detached one is reported as skipped. A repository pulled is listed again as it now stands.
|
|
2100
|
-
--path prints only the paths of the repositories listed, one per line, for xargs -d '\\n'.`;
|
|
2803
|
+
A clean repository, or one with only unreleased commits, is left out unless --all or --only unreleased. The walk goes ${MAX_DEPTH2} levels deep and skips the names in "skip" of \`~/.config/kaynooo-cli/repos.json\`; ahead and behind are those of the last fetch unless --fetch reaches the remote.
|
|
2804
|
+
--pull fetches, then fast-forwards only the repositories listed that are clean, on a branch and only behind their upstream; the others are reported as skipped.`;
|
|
2101
2805
|
var EXITS2 = [[0, "it listed the repositories, including when none needs attention"], [1, "a fast-forward --pull attempted failed"], [2, "a usage error, an unreadable config or a root that is no folder"]];
|
|
2102
2806
|
var OPTIONS2 = {
|
|
2103
2807
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
2104
|
-
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
2808
|
+
only: { type: "string", multiple: true, choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind, repeatable" },
|
|
2105
2809
|
watch: watchOption("the repositories"),
|
|
2106
2810
|
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
2107
2811
|
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
@@ -2124,7 +2828,7 @@ function releasedCell(repo) {
|
|
|
2124
2828
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
2125
2829
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
2126
2830
|
}
|
|
2127
|
-
function syncCell(repo, stream =
|
|
2831
|
+
function syncCell(repo, stream = process23.stdout) {
|
|
2128
2832
|
const colors = paint(stream);
|
|
2129
2833
|
const ahead = repo.ahead ?? 0;
|
|
2130
2834
|
const behind = repo.behind ?? 0;
|
|
@@ -2135,7 +2839,7 @@ function syncCell(repo, stream = process21.stdout) {
|
|
|
2135
2839
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
2136
2840
|
}
|
|
2137
2841
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
2138
|
-
function branchCell(repo, stream =
|
|
2842
|
+
function branchCell(repo, stream = process23.stdout) {
|
|
2139
2843
|
const colors = paint(stream);
|
|
2140
2844
|
if (repo.unreadable)
|
|
2141
2845
|
return colors.red("? (unreadable)");
|
|
@@ -2144,8 +2848,8 @@ function branchCell(repo, stream = process21.stdout) {
|
|
|
2144
2848
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
2145
2849
|
}
|
|
2146
2850
|
function row(repo, shown) {
|
|
2147
|
-
const colors = paint(
|
|
2148
|
-
const tint = role("path",
|
|
2851
|
+
const colors = paint(process23.stdout);
|
|
2852
|
+
const tint = role("path", process23.stdout);
|
|
2149
2853
|
const unreleased = releasedCell(repo);
|
|
2150
2854
|
return [
|
|
2151
2855
|
tint(shown),
|
|
@@ -2156,19 +2860,31 @@ function row(repo, shown) {
|
|
|
2156
2860
|
unreleased === "-" ? colors.dim("-") : colors.cyan(unreleased)
|
|
2157
2861
|
];
|
|
2158
2862
|
}
|
|
2159
|
-
async function repos(args) {
|
|
2160
|
-
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
2863
|
+
async function repos(args, watched = false) {
|
|
2864
|
+
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["ws repos", "ws repos ~/Workspace --only unreleased --fetch", ["ws repos --only behind --pull", "fast-forward what is behind and clean"], ["ws repos --only dirty --path", "the paths, for xargs"]] });
|
|
2161
2865
|
if (values.watch !== undefined)
|
|
2162
|
-
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
2866
|
+
return watching(values.watch, async () => repos(withoutWatch(args), true));
|
|
2163
2867
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2164
2868
|
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
2165
2869
|
fail(`no folder ${root}`);
|
|
2166
|
-
const only = values.only;
|
|
2167
|
-
const
|
|
2168
|
-
const
|
|
2870
|
+
const only = values.only ?? [];
|
|
2871
|
+
const progress = watched ? undefined : progressLine();
|
|
2872
|
+
const fetching = values.fetch === true || values.pull === true;
|
|
2873
|
+
const step = fetching ? "fetching" : "reading";
|
|
2874
|
+
let states;
|
|
2875
|
+
try {
|
|
2876
|
+
progress?.update({ step: "finding the repositories" });
|
|
2877
|
+
const paths = await findRepos2(root, await skipped());
|
|
2878
|
+
progress?.update({ step, done: 0, total: paths.length, unit: "repositories" });
|
|
2879
|
+
states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY2), async (path) => inspect(path, fetching), (done, total) => progress?.update({ step, done, total, unit: "repositories" }));
|
|
2880
|
+
} finally {
|
|
2881
|
+
progress?.stop();
|
|
2882
|
+
}
|
|
2169
2883
|
const keeps = (repo) => {
|
|
2170
2884
|
const reasons = reasonsOf(repo);
|
|
2171
|
-
|
|
2885
|
+
if (only.length > 0)
|
|
2886
|
+
return reasons.some((reason) => only.includes(reason));
|
|
2887
|
+
return values.all === true || reasons.some((reason) => reason !== "unreleased") || repo.unreadable;
|
|
2172
2888
|
};
|
|
2173
2889
|
let failedPulls = 0;
|
|
2174
2890
|
if (values.pull === true) {
|
|
@@ -2179,12 +2895,12 @@ async function repos(args) {
|
|
|
2179
2895
|
const blocker = pullBlocker(repo);
|
|
2180
2896
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
2181
2897
|
if (blocker !== undefined) {
|
|
2182
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2898
|
+
log(marked("note", `${repo.name} skipped`, process23.stdout, blocker));
|
|
2183
2899
|
} else if (refused !== undefined) {
|
|
2184
2900
|
failedPulls++;
|
|
2185
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2901
|
+
log(marked("problem", `${repo.name} not pulled`, process23.stdout, refused));
|
|
2186
2902
|
} else {
|
|
2187
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2903
|
+
log(marked("ok", `${repo.name} pulled`, process23.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
2188
2904
|
states[index] = await inspect(repo.path, false);
|
|
2189
2905
|
}
|
|
2190
2906
|
}
|
|
@@ -2199,7 +2915,7 @@ async function repos(args) {
|
|
|
2199
2915
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
2200
2916
|
return failedPulls > 0 ? 1 : 0;
|
|
2201
2917
|
}
|
|
2202
|
-
const label = role("label",
|
|
2918
|
+
const label = role("label", process23.stdout);
|
|
2203
2919
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
2204
2920
|
if (kept.length === 0) {
|
|
2205
2921
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -2218,212 +2934,7 @@ async function repos(args) {
|
|
|
2218
2934
|
import { existsSync as existsSync11, statSync as statSync4 } from "fs";
|
|
2219
2935
|
import { homedir as homedir6 } from "os";
|
|
2220
2936
|
import { relative as relative3 } from "path";
|
|
2221
|
-
|
|
2222
|
-
// ../kit/src/prompt.ts
|
|
2223
|
-
import process23 from "process";
|
|
2224
|
-
|
|
2225
|
-
// ../kit/src/job.ts
|
|
2226
|
-
import process22 from "process";
|
|
2227
|
-
function stopJob() {
|
|
2228
|
-
process22.kill(0, "SIGTSTP");
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
// ../kit/src/picker/line.ts
|
|
2232
|
-
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2233
|
-
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2234
|
-
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2235
|
-
function isEditKey(key) {
|
|
2236
|
-
return EDIT_KEYS.has(key);
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2239
|
-
// ../kit/src/picker/score.ts
|
|
2240
|
-
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2241
|
-
var NONE = Number.NEGATIVE_INFINITY;
|
|
2242
|
-
|
|
2243
|
-
// ../kit/src/picker/state.ts
|
|
2244
|
-
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2245
|
-
var PASTE_START = "\x1B[200~";
|
|
2246
|
-
var PASTE_END = "\x1B[201~";
|
|
2247
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2248
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
2249
|
-
var WHEEL_LINES = 3;
|
|
2250
|
-
var KEYS = {
|
|
2251
|
-
"\x1B[A": "up",
|
|
2252
|
-
"\x1BOA": "up",
|
|
2253
|
-
"\x10": "up",
|
|
2254
|
-
"\x1B[B": "down",
|
|
2255
|
-
"\x1BOB": "down",
|
|
2256
|
-
"\x0E": "down",
|
|
2257
|
-
"\x1B[5~": "pageup",
|
|
2258
|
-
"\x1B[6~": "pagedown",
|
|
2259
|
-
"\x1B[H": "home",
|
|
2260
|
-
"\x1B[1~": "home",
|
|
2261
|
-
"\x1BOH": "home",
|
|
2262
|
-
"\x1B[F": "end",
|
|
2263
|
-
"\x1B[4~": "end",
|
|
2264
|
-
"\x1BOF": "end",
|
|
2265
|
-
"\r": "enter",
|
|
2266
|
-
"\n": "enter",
|
|
2267
|
-
"\x03": "cancel",
|
|
2268
|
-
"\x1B": "cancel",
|
|
2269
|
-
"\x1B[D": "left",
|
|
2270
|
-
"\x1BOD": "left",
|
|
2271
|
-
"\x1B[C": "right",
|
|
2272
|
-
"\x1BOC": "right",
|
|
2273
|
-
"\x1B[1;5D": "wordleft",
|
|
2274
|
-
"\x1B[1;3D": "wordleft",
|
|
2275
|
-
"\x1Bb": "wordleft",
|
|
2276
|
-
"\x1B[1;5C": "wordright",
|
|
2277
|
-
"\x1B[1;3C": "wordright",
|
|
2278
|
-
"\x1Bf": "wordright",
|
|
2279
|
-
"\x01": "linestart",
|
|
2280
|
-
"\x05": "lineend",
|
|
2281
|
-
"\x7F": "erase",
|
|
2282
|
-
"\x1B[3~": "delete",
|
|
2283
|
-
"\b": "killword",
|
|
2284
|
-
"\x1B\x7F": "killword",
|
|
2285
|
-
"\x1B[3;5~": "killnext",
|
|
2286
|
-
"\x1Bd": "killnext",
|
|
2287
|
-
"\x15": "clear",
|
|
2288
|
-
"\v": "killend",
|
|
2289
|
-
"\x17": "word",
|
|
2290
|
-
"\x19": "yank",
|
|
2291
|
-
"\x1A": "suspend",
|
|
2292
|
-
"\t": "tab",
|
|
2293
|
-
"\x1F": "help",
|
|
2294
|
-
"\x1BOP": "help",
|
|
2295
|
-
"\x1B[11~": "help"
|
|
2296
|
-
};
|
|
2297
|
-
function repeat(value, count) {
|
|
2298
|
-
return Array.from({ length: count }).fill(value);
|
|
2299
|
-
}
|
|
2300
|
-
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2301
|
-
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2302
|
-
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2303
|
-
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2304
|
-
if (wheel !== undefined)
|
|
2305
|
-
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
2306
|
-
const named = codes.get(sequence);
|
|
2307
|
-
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2308
|
-
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2309
|
-
paste.active = sequence === PASTE_START;
|
|
2310
|
-
return [];
|
|
2311
|
-
}
|
|
2312
|
-
if (paste.active && (sequence === "\r" || sequence === `
|
|
2313
|
-
`))
|
|
2314
|
-
return [];
|
|
2315
|
-
if (key !== undefined)
|
|
2316
|
-
return [key];
|
|
2317
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
// ../kit/src/redraw.ts
|
|
2322
|
-
var SYNC_START = "\x1B[?2026h";
|
|
2323
|
-
var SYNC_END = "\x1B[?2026l";
|
|
2324
|
-
function overwrite(lines, columns) {
|
|
2325
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2326
|
-
`);
|
|
2327
|
-
}
|
|
2328
|
-
function rowsTaken(lines, columns) {
|
|
2329
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
// ../kit/src/prompt.ts
|
|
2333
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2334
|
-
function readKeys(input, paste = { active: false }) {
|
|
2335
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2336
|
-
}
|
|
2337
|
-
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2338
|
-
let answered = fallback;
|
|
2339
|
-
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
2340
|
-
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
2341
|
-
if (key === "cancel")
|
|
2342
|
-
return "cancel";
|
|
2343
|
-
if (key === "enter")
|
|
2344
|
-
return answered === undefined ? undefined : "enter";
|
|
2345
|
-
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
2346
|
-
if (letter !== "y" && letter !== "n")
|
|
2347
|
-
return;
|
|
2348
|
-
answered = letter === "y";
|
|
2349
|
-
return "enter";
|
|
2350
|
-
});
|
|
2351
|
-
return accepted ? answered : undefined;
|
|
2352
|
-
}
|
|
2353
|
-
function asking(colors, question, typed, keys) {
|
|
2354
|
-
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
2355
|
-
}
|
|
2356
|
-
function answer(colors, question, state, picked) {
|
|
2357
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2358
|
-
}
|
|
2359
|
-
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2360
|
-
const { stdin, stderr } = terminal;
|
|
2361
|
-
if (!isInteractive(terminal))
|
|
2362
|
-
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2363
|
-
const colors = paint(stderr);
|
|
2364
|
-
let current = "asking";
|
|
2365
|
-
let outcome;
|
|
2366
|
-
const columns = () => stderr.columns || 80;
|
|
2367
|
-
const draw = (state, last = false) => {
|
|
2368
|
-
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2369
|
-
const rows = rowsTaken(frame, columns());
|
|
2370
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2371
|
-
current = state;
|
|
2372
|
-
};
|
|
2373
|
-
const redraw = () => draw(current);
|
|
2374
|
-
const paste = { active: false };
|
|
2375
|
-
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2376
|
-
const suspend = () => {
|
|
2377
|
-
if (stop === undefined)
|
|
2378
|
-
return;
|
|
2379
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2380
|
-
stdin.setRawMode(false);
|
|
2381
|
-
stop();
|
|
2382
|
-
stdin.setRawMode(true);
|
|
2383
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2384
|
-
};
|
|
2385
|
-
try {
|
|
2386
|
-
stderr.on?.("resize", redraw);
|
|
2387
|
-
stdin.setRawMode(true);
|
|
2388
|
-
stdin.resume();
|
|
2389
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2390
|
-
draw("asking");
|
|
2391
|
-
return await new Promise((resolve) => {
|
|
2392
|
-
function onData(data) {
|
|
2393
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
2394
|
-
if (key === "suspend") {
|
|
2395
|
-
suspend();
|
|
2396
|
-
continue;
|
|
2397
|
-
}
|
|
2398
|
-
const pressed = press(key);
|
|
2399
|
-
if (pressed !== undefined) {
|
|
2400
|
-
settle(pressed);
|
|
2401
|
-
return;
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
draw("asking");
|
|
2405
|
-
}
|
|
2406
|
-
function onEnd() {
|
|
2407
|
-
settle("cancel");
|
|
2408
|
-
}
|
|
2409
|
-
function settle(settled) {
|
|
2410
|
-
outcome = settled;
|
|
2411
|
-
stdin.off("data", onData);
|
|
2412
|
-
stdin.off("end", onEnd);
|
|
2413
|
-
resolve(settled === "enter");
|
|
2414
|
-
}
|
|
2415
|
-
stdin.on("data", onData);
|
|
2416
|
-
stdin.on("end", onEnd);
|
|
2417
|
-
});
|
|
2418
|
-
} finally {
|
|
2419
|
-
stderr.off?.("resize", redraw);
|
|
2420
|
-
draw(outcome ?? "cancel", true);
|
|
2421
|
-
stderr.write(`
|
|
2422
|
-
\x1B[?25h\x1B[?2004l`);
|
|
2423
|
-
stdin.setRawMode(false);
|
|
2424
|
-
stdin.pause();
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2937
|
+
init_prompt();
|
|
2427
2938
|
|
|
2428
2939
|
// src/apply.ts
|
|
2429
2940
|
import { existsSync as existsSync10 } from "fs";
|
|
@@ -2441,7 +2952,8 @@ import { lstat, readdir as readdir3 } from "fs/promises";
|
|
|
2441
2952
|
import { join as join11 } from "path";
|
|
2442
2953
|
var FS_LIMIT = 32;
|
|
2443
2954
|
var FIND_MS = 60000;
|
|
2444
|
-
var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
|
|
2955
|
+
var FIND_LINE = /^(\w) (\d+) (\S+) (\d+) (\d+)$/gm;
|
|
2956
|
+
var OWN_UID = process.getuid?.() ?? -1;
|
|
2445
2957
|
var waiting = [];
|
|
2446
2958
|
var running = 0;
|
|
2447
2959
|
async function gated(call) {
|
|
@@ -2455,9 +2967,10 @@ async function gated(call) {
|
|
|
2455
2967
|
waiting.shift()?.();
|
|
2456
2968
|
}
|
|
2457
2969
|
}
|
|
2458
|
-
async function
|
|
2970
|
+
async function walk(folder, uid) {
|
|
2459
2971
|
const seen = new Set;
|
|
2460
2972
|
let total = 0;
|
|
2973
|
+
let foreign = 0;
|
|
2461
2974
|
const visit = async (dir) => {
|
|
2462
2975
|
let entries;
|
|
2463
2976
|
try {
|
|
@@ -2467,10 +2980,12 @@ async function walkSize(folder) {
|
|
|
2467
2980
|
}
|
|
2468
2981
|
await Promise.all(entries.map(async (entry) => {
|
|
2469
2982
|
const path = join11(dir, entry.name);
|
|
2470
|
-
if (entry.isDirectory())
|
|
2471
|
-
return visit(path);
|
|
2472
2983
|
try {
|
|
2473
2984
|
const stat = await gated(async () => lstat(path));
|
|
2985
|
+
if (stat.uid !== uid)
|
|
2986
|
+
foreign++;
|
|
2987
|
+
if (entry.isDirectory())
|
|
2988
|
+
return await visit(path);
|
|
2474
2989
|
if (stat.nlink > 1) {
|
|
2475
2990
|
const key = `${stat.dev}:${stat.ino}`;
|
|
2476
2991
|
if (seen.has(key))
|
|
@@ -2481,18 +2996,27 @@ async function walkSize(folder) {
|
|
|
2481
2996
|
} catch {}
|
|
2482
2997
|
}));
|
|
2483
2998
|
};
|
|
2999
|
+
try {
|
|
3000
|
+
if ((await lstat(folder)).uid !== uid)
|
|
3001
|
+
foreign++;
|
|
3002
|
+
} catch {}
|
|
2484
3003
|
await visit(folder);
|
|
2485
|
-
return total;
|
|
3004
|
+
return { bytes: total, foreign };
|
|
2486
3005
|
}
|
|
2487
|
-
async function findSize(folder) {
|
|
3006
|
+
async function findSize(folder, uid) {
|
|
2488
3007
|
try {
|
|
2489
|
-
const ran = await runCommand(["find", "-P", folder, "
|
|
3008
|
+
const ran = await runCommand(["find", "-P", folder, "-printf", "%y %n %D:%i %s %U\\n"], { timeoutMs: FIND_MS });
|
|
2490
3009
|
const lines = [...ran.text.matchAll(FIND_LINE)];
|
|
2491
3010
|
if (ran.timedOut || ran.code !== 0 && lines.length === 0)
|
|
2492
3011
|
return;
|
|
2493
3012
|
const seen = new Set;
|
|
2494
3013
|
let total = 0;
|
|
2495
|
-
|
|
3014
|
+
let foreign = 0;
|
|
3015
|
+
for (const [, type, links, id, bytes, owner] of lines) {
|
|
3016
|
+
if (Number(owner) !== uid)
|
|
3017
|
+
foreign++;
|
|
3018
|
+
if (type !== "f" && type !== "l")
|
|
3019
|
+
continue;
|
|
2496
3020
|
if (Number(links) > 1) {
|
|
2497
3021
|
if (seen.has(id))
|
|
2498
3022
|
continue;
|
|
@@ -2500,13 +3024,13 @@ async function findSize(folder) {
|
|
|
2500
3024
|
}
|
|
2501
3025
|
total += Number(bytes);
|
|
2502
3026
|
}
|
|
2503
|
-
return total;
|
|
3027
|
+
return { bytes: total, foreign };
|
|
2504
3028
|
} catch {
|
|
2505
3029
|
return;
|
|
2506
3030
|
}
|
|
2507
3031
|
}
|
|
2508
|
-
async function
|
|
2509
|
-
return await findSize(folder) ?? await
|
|
3032
|
+
async function measure(folder, uid = OWN_UID) {
|
|
3033
|
+
return await findSize(folder, uid) ?? await walk(folder, uid);
|
|
2510
3034
|
}
|
|
2511
3035
|
|
|
2512
3036
|
// src/sweep-scan.ts
|
|
@@ -2647,13 +3171,13 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2647
3171
|
if (existsSync9(join12(path, ".git")))
|
|
2648
3172
|
return { skip: "holds a git repository" };
|
|
2649
3173
|
if (located === "none")
|
|
2650
|
-
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
3174
|
+
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside, project: dirname5(inside ?? path) } } : { skip: "not in a git repository" };
|
|
2651
3175
|
const tracked = await gitIn(parent, ["ls-files", "--", name]);
|
|
2652
3176
|
if (tracked.code !== 0 || tracked.stdout !== "")
|
|
2653
3177
|
return { skip: "tracked by git" };
|
|
2654
3178
|
if (name !== "node_modules" && inside === undefined && (await gitIn(parent, ["check-ignore", "-q", "--", name])).code !== 0)
|
|
2655
3179
|
return { skip: "not ignored by git" };
|
|
2656
|
-
return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside } };
|
|
3180
|
+
return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside, project: located.top } };
|
|
2657
3181
|
}
|
|
2658
3182
|
async function judgeWorktree(path) {
|
|
2659
3183
|
const located = await toplevelOf(dirname5(path));
|
|
@@ -2685,23 +3209,26 @@ async function judgeWorktree(path) {
|
|
|
2685
3209
|
if (unique.stdout !== "")
|
|
2686
3210
|
return keep(`${unique.stdout.split(`
|
|
2687
3211
|
`).length} commits on no other branch or remote`);
|
|
2688
|
-
return { entry: { path, kind: "worktree", committedAt, action: "remove", repo: top } };
|
|
3212
|
+
return { entry: { path, kind: "worktree", committedAt, action: "remove", repo: top, project: path } };
|
|
2689
3213
|
}
|
|
2690
3214
|
async function judge(candidate) {
|
|
2691
3215
|
if (candidate.global === true)
|
|
2692
3216
|
return { entry: { path: candidate.path, kind: candidate.kind, committedAt: undefined, action: "remove" } };
|
|
2693
3217
|
return candidate.kind === "worktree" ? judgeWorktree(candidate.path) : judgeFolder(candidate.path, candidate.kind, candidate.inside);
|
|
2694
3218
|
}
|
|
2695
|
-
async function inspect2({ candidates, skipped }) {
|
|
3219
|
+
async function inspect2({ candidates, skipped }, onDone, uid) {
|
|
2696
3220
|
const entries = [];
|
|
2697
3221
|
const rejected = [...skipped];
|
|
2698
3222
|
await pool(candidates, 8, async (candidate) => {
|
|
2699
3223
|
const verdict = await judge(candidate);
|
|
2700
|
-
if ("skip" in verdict)
|
|
3224
|
+
if ("skip" in verdict) {
|
|
2701
3225
|
rejected.push({ path: candidate.path, reason: verdict.skip });
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
3226
|
+
return;
|
|
3227
|
+
}
|
|
3228
|
+
const { bytes, foreign } = await measure(candidate.path, uid);
|
|
3229
|
+
const owned = foreign > 0 && verdict.entry.action === "remove" ? { action: "keep", reason: `${foreign} ${foreign === 1 ? "entry" : "entries"} owned by another user (a container's?)` } : {};
|
|
3230
|
+
entries.push({ ...verdict.entry, ...owned, bytes });
|
|
3231
|
+
}, onDone);
|
|
2705
3232
|
const listed = new Set(entries.filter((entry) => entry.action === "remove").map((entry) => entry.path));
|
|
2706
3233
|
return { entries: entries.filter((entry) => entry.inside === undefined || !listed.has(entry.inside)), skipped: rejected };
|
|
2707
3234
|
}
|
|
@@ -2742,12 +3269,81 @@ async function applyAll(entries, done) {
|
|
|
2742
3269
|
return outcomes;
|
|
2743
3270
|
}
|
|
2744
3271
|
|
|
3272
|
+
// src/busy.ts
|
|
3273
|
+
import { readdir as readdir5, readFile, readlink } from "fs/promises";
|
|
3274
|
+
import { basename as basename5, join as join14 } from "path";
|
|
3275
|
+
var DEV_PROGRAMS = new Set(["node", "bun", "deno", "npm", "npx", "pnpm", "yarn", "bunx", "vite", "esbuild", "ruby", "java", "cargo", "go", "php", "php-fpm"]);
|
|
3276
|
+
var DEV_PREFIXES = ["python", "php"];
|
|
3277
|
+
var DOCKER_MS = 5000;
|
|
3278
|
+
var PID = /^\d+$/;
|
|
3279
|
+
var PARENT = /^ \S+ (\d+)/;
|
|
3280
|
+
function isDevProgram(comm) {
|
|
3281
|
+
return DEV_PROGRAMS.has(comm) || DEV_PREFIXES.some((prefix) => comm.startsWith(prefix));
|
|
3282
|
+
}
|
|
3283
|
+
async function quietly(read) {
|
|
3284
|
+
try {
|
|
3285
|
+
return await read();
|
|
3286
|
+
} catch {
|
|
3287
|
+
return;
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
async function lineage(pid, root) {
|
|
3291
|
+
const seen = new Set;
|
|
3292
|
+
for (let current = pid;current > 1 && !seen.has(current); ) {
|
|
3293
|
+
seen.add(current);
|
|
3294
|
+
const stat = await quietly(async () => readFile(join14(root, String(current), "stat"), "utf8"));
|
|
3295
|
+
const parent = Number(PARENT.exec(stat?.slice(stat.lastIndexOf(")") + 1) ?? "")?.[1]);
|
|
3296
|
+
if (!Number.isInteger(parent))
|
|
3297
|
+
break;
|
|
3298
|
+
current = parent;
|
|
3299
|
+
}
|
|
3300
|
+
return seen;
|
|
3301
|
+
}
|
|
3302
|
+
async function processPlaces(root = "/proc", self = process.pid) {
|
|
3303
|
+
const own = await lineage(self, root);
|
|
3304
|
+
const pids = (await quietly(async () => readdir5(root)) ?? []).filter((name) => PID.test(name)).map(Number).filter((pid) => !own.has(pid));
|
|
3305
|
+
const places = [];
|
|
3306
|
+
await Promise.all(pids.map(async (pid) => {
|
|
3307
|
+
const comm = (await quietly(async () => readFile(join14(root, String(pid), "comm"), "utf8")))?.trim();
|
|
3308
|
+
if (comm === undefined || !isDevProgram(comm))
|
|
3309
|
+
return;
|
|
3310
|
+
const cwd = await quietly(async () => readlink(join14(root, String(pid), "cwd")));
|
|
3311
|
+
const argv = (await quietly(async () => readFile(join14(root, String(pid), "cmdline"), "utf8")))?.split("\x00").filter((arg) => arg.startsWith("/")) ?? [];
|
|
3312
|
+
const who = `pid ${pid} ${comm}`;
|
|
3313
|
+
for (const path of [cwd, ...argv.slice(1)]) {
|
|
3314
|
+
if (path !== undefined)
|
|
3315
|
+
places.push({ path, who });
|
|
3316
|
+
}
|
|
3317
|
+
}));
|
|
3318
|
+
return places;
|
|
3319
|
+
}
|
|
3320
|
+
async function containerPlaces() {
|
|
3321
|
+
const ids = await quietly(async () => runCommand(["docker", "ps", "-q"], { timeoutMs: DOCKER_MS }));
|
|
3322
|
+
if (ids === undefined || ids.code !== 0 || ids.text.trim() === "")
|
|
3323
|
+
return [];
|
|
3324
|
+
const inspected = await quietly(async () => runCommand(["docker", "inspect", "--format", '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}}\t{{.Source}}{{end}}{{end}}', ...ids.text.trim().split(`
|
|
3325
|
+
`)], { timeoutMs: DOCKER_MS }));
|
|
3326
|
+
if (inspected === undefined || inspected.code !== 0)
|
|
3327
|
+
return [];
|
|
3328
|
+
return inspected.text.trim().split(`
|
|
3329
|
+
`).flatMap((line) => {
|
|
3330
|
+
const [name = "", ...sources] = line.split("\t");
|
|
3331
|
+
return sources.map((path) => ({ path, who: `container ${basename5(name)}` }));
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
var within = (path, folder) => path === folder || path.startsWith(`${folder}/`);
|
|
3335
|
+
function userOf(folder, processes, containers) {
|
|
3336
|
+
return processes.find((place) => within(place.path, folder))?.who ?? containers.find((place) => within(place.path, folder) || within(folder, place.path))?.who;
|
|
3337
|
+
}
|
|
3338
|
+
|
|
2745
3339
|
// src/sweep.ts
|
|
2746
3340
|
var LARGE = 100 * 1024 ** 2;
|
|
2747
3341
|
var BIG = 1024 ** 3;
|
|
2748
|
-
var USAGE3 = `sweep [options] [root]: lists the regenerable folders
|
|
3342
|
+
var USAGE3 = `ws sweep [options] [root]: lists the regenerable folders, caches and worktrees under root (the configured workspace by default, ${MAX_DEPTH3} levels down), largest first with the age of the repo's last commit
|
|
2749
3343
|
|
|
2750
|
-
Dry unless --apply, which deletes after a confirm showing the total (
|
|
3344
|
+
Dry unless --apply, which deletes for good, not trashed, after a confirm showing the total (off a terminal, pass --yes).
|
|
3345
|
+
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.
|
|
3346
|
+
What a running dev process or container uses, a folder holding files another user owns and a worktree that is not removable stay listed as kept, with the reason, and count for nothing in the total.`;
|
|
2751
3347
|
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"]];
|
|
2752
3348
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
2753
3349
|
var OPTIONS3 = {
|
|
@@ -2770,7 +3366,7 @@ async function dockerUsage() {
|
|
|
2770
3366
|
}
|
|
2771
3367
|
}
|
|
2772
3368
|
async function sweep(args) {
|
|
2773
|
-
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"] });
|
|
3369
|
+
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: ["ws sweep", "ws sweep ~/Workspace --older 30d --min 100M --apply", "ws sweep --only worktrees --apply"] });
|
|
2774
3370
|
if (positionals.length > 1)
|
|
2775
3371
|
badUsage("give one root");
|
|
2776
3372
|
const root = workspaceRoot({ given: positionals[0] });
|
|
@@ -2781,9 +3377,20 @@ async function sweep(args) {
|
|
|
2781
3377
|
if (minBytes === undefined)
|
|
2782
3378
|
badUsage(`--min takes a size such as 500K, 10M or 1G, not ${values.min}`);
|
|
2783
3379
|
const now = Date.now();
|
|
2784
|
-
const
|
|
2785
|
-
|
|
2786
|
-
|
|
3380
|
+
const progress = progressLine();
|
|
3381
|
+
let scanned;
|
|
3382
|
+
try {
|
|
3383
|
+
progress.update({ step: "finding the folders" });
|
|
3384
|
+
const found = await findCandidates(root, homedir6(), positionals.length === 0 || values.only === "caches");
|
|
3385
|
+
const wanted = values.only === undefined ? found.candidates : found.candidates.filter((candidate) => candidate.kind === ONLY_KINDS[values.only]);
|
|
3386
|
+
progress.update({ step: "sizing", done: 0, total: wanted.length, unit: "folders" });
|
|
3387
|
+
scanned = await inspect2({ candidates: wanted, skipped: found.skipped }, (done, total) => progress.update({ step: "sizing", done, total, unit: "folders" }));
|
|
3388
|
+
progress.update({ step: "looking for running servers and containers" });
|
|
3389
|
+
await keepWhatIsInUse(scanned.entries);
|
|
3390
|
+
} finally {
|
|
3391
|
+
progress.stop();
|
|
3392
|
+
}
|
|
3393
|
+
const { entries: all, skipped } = scanned;
|
|
2787
3394
|
const entries = all.filter((entry) => entry.bytes >= minBytes && (olderMs === undefined || entry.committedAt !== undefined && now - entry.committedAt >= olderMs)).sort((a, b) => b.bytes - a.bytes || a.path.localeCompare(b.path));
|
|
2788
3395
|
const removable = entries.filter((entry) => entry.action === "remove");
|
|
2789
3396
|
const reclaimable = removable.reduce((sum, entry) => sum + entry.bytes, 0);
|
|
@@ -2828,6 +3435,19 @@ function report2(root, outcome, json) {
|
|
|
2828
3435
|
else
|
|
2829
3436
|
problem(`kept ${relative3(root, outcome.path)}`, outcome.error);
|
|
2830
3437
|
}
|
|
3438
|
+
async function keepWhatIsInUse(entries) {
|
|
3439
|
+
const candidates = entries.filter((entry) => entry.action === "remove" && entry.project !== undefined);
|
|
3440
|
+
if (candidates.length === 0)
|
|
3441
|
+
return;
|
|
3442
|
+
const [processes, containers] = await Promise.all([processPlaces(), containerPlaces()]);
|
|
3443
|
+
for (const entry of candidates) {
|
|
3444
|
+
const who = userOf(entry.project, processes, containers);
|
|
3445
|
+
if (who !== undefined) {
|
|
3446
|
+
entry.action = "keep";
|
|
3447
|
+
entry.reason = `in use by ${who}`;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
2831
3451
|
function print(root, entries, skipped, reclaimable, now) {
|
|
2832
3452
|
if (entries.length === 0) {
|
|
2833
3453
|
console.log("nothing to sweep");
|
|
@@ -2846,7 +3466,7 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2846
3466
|
}
|
|
2847
3467
|
|
|
2848
3468
|
// src/cli.ts
|
|
2849
|
-
|
|
3469
|
+
process26.exitCode = await runCli({
|
|
2850
3470
|
name: "ws",
|
|
2851
3471
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2852
3472
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|