@kaynooo/cli-code 0.0.0-stage → 0.5.0
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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/hotspots.js +889 -0
- package/dist/peek.js +1176 -0
- package/dist/todo-scan.js +927 -0
- package/package.json +44 -4
|
@@ -0,0 +1,927 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/todo-scan.ts
|
|
5
|
+
import { join as join2 } from "path";
|
|
6
|
+
import process7 from "process";
|
|
7
|
+
|
|
8
|
+
// ../kit/src/args.ts
|
|
9
|
+
import { fstatSync } from "fs";
|
|
10
|
+
import process3 from "process";
|
|
11
|
+
import { parseArgs } from "util";
|
|
12
|
+
|
|
13
|
+
// ../kit/src/format.ts
|
|
14
|
+
import process2 from "process";
|
|
15
|
+
|
|
16
|
+
// ../kit/src/style.ts
|
|
17
|
+
import process from "process";
|
|
18
|
+
|
|
19
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
20
|
+
function x(s) {
|
|
21
|
+
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
22
|
+
if (!/^[a-f0-9]+$/.test(r))
|
|
23
|
+
return [0, 0, 0];
|
|
24
|
+
let t = r.length, n = (c) => Number.parseInt(c, 16);
|
|
25
|
+
if (t === 3 || t === 4) {
|
|
26
|
+
let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
|
|
27
|
+
return g !== undefined ? [c, u, h, g] : [c, u, h];
|
|
28
|
+
}
|
|
29
|
+
if (t !== 6 && t !== 8)
|
|
30
|
+
throw Error(`Invalid hex color length: ${t}`);
|
|
31
|
+
let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
|
|
32
|
+
if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
|
|
33
|
+
throw Error(`Invalid hex color value: ${s}`);
|
|
34
|
+
return y !== undefined ? [a, b, o, y] : [a, b, o];
|
|
35
|
+
}
|
|
36
|
+
function A(s) {
|
|
37
|
+
let [r, t, n, a] = s;
|
|
38
|
+
if (a)
|
|
39
|
+
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
40
|
+
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
41
|
+
}
|
|
42
|
+
function R(s, r, t) {
|
|
43
|
+
s = (s % 360 + 360) % 360, t /= 100;
|
|
44
|
+
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
45
|
+
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
46
|
+
return Math.round(255 * y);
|
|
47
|
+
};
|
|
48
|
+
return [a(0), a(8), a(4)];
|
|
49
|
+
}
|
|
50
|
+
function k(s) {
|
|
51
|
+
let [r, t, n] = s;
|
|
52
|
+
r /= 255, t /= 255, n /= 255;
|
|
53
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
54
|
+
if (a !== b) {
|
|
55
|
+
let u = a - b;
|
|
56
|
+
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
57
|
+
o = (t - n) / u + (t < n ? 6 : 0);
|
|
58
|
+
else if (a === t)
|
|
59
|
+
o = (n - r) / u + 2;
|
|
60
|
+
else
|
|
61
|
+
o = (r - t) / u + 4;
|
|
62
|
+
o /= 6;
|
|
63
|
+
}
|
|
64
|
+
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
65
|
+
}
|
|
66
|
+
function H(s, r, t) {
|
|
67
|
+
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
68
|
+
let n = (a) => {
|
|
69
|
+
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
70
|
+
return Math.round(255 * o);
|
|
71
|
+
};
|
|
72
|
+
return [n(5), n(3), n(1)];
|
|
73
|
+
}
|
|
74
|
+
function f(s) {
|
|
75
|
+
let [r, t, n] = s;
|
|
76
|
+
r /= 255, t /= 255, n /= 255;
|
|
77
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
78
|
+
if (o !== 0) {
|
|
79
|
+
if (a === r)
|
|
80
|
+
y = (t - n) / o + (t < n ? 6 : 0);
|
|
81
|
+
else if (a === t)
|
|
82
|
+
y = (n - r) / o + 2;
|
|
83
|
+
else
|
|
84
|
+
y = (r - t) / o + 4;
|
|
85
|
+
y /= 6;
|
|
86
|
+
}
|
|
87
|
+
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
88
|
+
}
|
|
89
|
+
function O(s) {
|
|
90
|
+
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
91
|
+
if (a === 1)
|
|
92
|
+
return [0, 0, 0, 100];
|
|
93
|
+
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
94
|
+
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
95
|
+
}
|
|
96
|
+
function v(s, r, t, n) {
|
|
97
|
+
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
98
|
+
}
|
|
99
|
+
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
100
|
+
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
101
|
+
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
102
|
+
function T(s) {
|
|
103
|
+
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
104
|
+
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
105
|
+
}
|
|
106
|
+
function M(s, r, t) {
|
|
107
|
+
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
108
|
+
return [u(o), u(y), u(c)];
|
|
109
|
+
}
|
|
110
|
+
function d(s) {
|
|
111
|
+
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
112
|
+
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
113
|
+
}
|
|
114
|
+
function C(s, r, t) {
|
|
115
|
+
let n = t * Math.PI / 180;
|
|
116
|
+
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
117
|
+
}
|
|
118
|
+
function l(s) {
|
|
119
|
+
let r = s / 255;
|
|
120
|
+
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
class e {
|
|
124
|
+
r;
|
|
125
|
+
g;
|
|
126
|
+
b;
|
|
127
|
+
a;
|
|
128
|
+
constructor(s, r, t, n = 1) {
|
|
129
|
+
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
130
|
+
}
|
|
131
|
+
static from(s, r) {
|
|
132
|
+
if (s === "hex") {
|
|
133
|
+
let [t, n, a, b] = x(r);
|
|
134
|
+
return new e(t, n, a, b);
|
|
135
|
+
}
|
|
136
|
+
if (s === "rgb") {
|
|
137
|
+
if (Array.isArray(r)) {
|
|
138
|
+
let [o, y, c, u] = r;
|
|
139
|
+
return new e(o, y, c, u);
|
|
140
|
+
}
|
|
141
|
+
let { r: t, g: n, b: a, a: b } = r;
|
|
142
|
+
return new e(t, n, a, b);
|
|
143
|
+
}
|
|
144
|
+
if (s === "hsl") {
|
|
145
|
+
let t, n, a, b;
|
|
146
|
+
if (Array.isArray(r))
|
|
147
|
+
[t, n, a, b] = r;
|
|
148
|
+
else
|
|
149
|
+
({ h: t, s: n, l: a, a: b } = r);
|
|
150
|
+
let [o, y, c] = R(t, n, a);
|
|
151
|
+
return new e(o, y, c, b);
|
|
152
|
+
}
|
|
153
|
+
if (s === "hsv") {
|
|
154
|
+
let t, n, a, b;
|
|
155
|
+
if (Array.isArray(r))
|
|
156
|
+
[t, n, a, b] = r;
|
|
157
|
+
else
|
|
158
|
+
({ h: t, s: n, v: a, a: b } = r);
|
|
159
|
+
let [o, y, c] = H(t, n, a);
|
|
160
|
+
return new e(o, y, c, b);
|
|
161
|
+
}
|
|
162
|
+
if (s === "cmyk") {
|
|
163
|
+
let t, n, a, b, o;
|
|
164
|
+
if (Array.isArray(r))
|
|
165
|
+
[t, n, a, b, o] = r;
|
|
166
|
+
else
|
|
167
|
+
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
168
|
+
let [y, c, u] = v(t, n, a, b);
|
|
169
|
+
return new e(y, c, u, o);
|
|
170
|
+
}
|
|
171
|
+
if (s === "oklch") {
|
|
172
|
+
let t, n, a, b;
|
|
173
|
+
if (Array.isArray(r))
|
|
174
|
+
[t, n, a, b] = r;
|
|
175
|
+
else
|
|
176
|
+
({ l: t, c: n, h: a, a: b } = r);
|
|
177
|
+
let [o, y, c] = C(t, n, a);
|
|
178
|
+
return new e(o, y, c, b);
|
|
179
|
+
}
|
|
180
|
+
if (s === "oklab") {
|
|
181
|
+
let t, n, a, b;
|
|
182
|
+
if (Array.isArray(r))
|
|
183
|
+
[t, n, a, b] = r;
|
|
184
|
+
else
|
|
185
|
+
({ l: t, a: n, b: a, alpha: b } = r);
|
|
186
|
+
let [o, y, c] = M(t, n, a);
|
|
187
|
+
return new e(o, y, c, b);
|
|
188
|
+
}
|
|
189
|
+
throw Error("Invalid input");
|
|
190
|
+
}
|
|
191
|
+
to(s) {
|
|
192
|
+
switch (s) {
|
|
193
|
+
case "rgb":
|
|
194
|
+
return [this.r, this.g, this.b];
|
|
195
|
+
case "rgba":
|
|
196
|
+
return [this.r, this.g, this.b, this.a];
|
|
197
|
+
case "hex":
|
|
198
|
+
return A([this.r, this.g, this.b]);
|
|
199
|
+
case "hexa":
|
|
200
|
+
return A([this.r, this.g, this.b, this.a]);
|
|
201
|
+
case "hsl":
|
|
202
|
+
return k([this.r, this.g, this.b]);
|
|
203
|
+
case "hsla":
|
|
204
|
+
return [...k([this.r, this.g, this.b]), this.a];
|
|
205
|
+
case "hsv":
|
|
206
|
+
return f([this.r, this.g, this.b]);
|
|
207
|
+
case "hsva":
|
|
208
|
+
return [...f([this.r, this.g, this.b]), this.a];
|
|
209
|
+
case "cmyk":
|
|
210
|
+
return O([this.r, this.g, this.b]);
|
|
211
|
+
case "cmyka":
|
|
212
|
+
return [...O([this.r, this.g, this.b]), this.a];
|
|
213
|
+
case "oklch":
|
|
214
|
+
return d([this.r, this.g, this.b]);
|
|
215
|
+
case "oklcha":
|
|
216
|
+
return [...d([this.r, this.g, this.b]), this.a];
|
|
217
|
+
case "oklab":
|
|
218
|
+
return T([this.r, this.g, this.b]);
|
|
219
|
+
case "oklaba":
|
|
220
|
+
return [...T([this.r, this.g, this.b]), this.a];
|
|
221
|
+
default:
|
|
222
|
+
return [this.r, this.g, this.b];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
getLuminance() {
|
|
226
|
+
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
227
|
+
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
228
|
+
}
|
|
229
|
+
contrastRatio(s) {
|
|
230
|
+
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
231
|
+
return (n + 0.05) / (a + 0.05);
|
|
232
|
+
}
|
|
233
|
+
bestContrastForeground() {
|
|
234
|
+
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
235
|
+
return t >= n ? s : r;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
240
|
+
var r = 39;
|
|
241
|
+
var o = 49;
|
|
242
|
+
var f2 = "\x1B[";
|
|
243
|
+
var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
244
|
+
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
245
|
+
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
246
|
+
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
247
|
+
var b = new Set(["", "1", "2", "3", "true"]);
|
|
248
|
+
function h(i, n = globalThis.process?.env ?? {}) {
|
|
249
|
+
if (n.FORCE_COLOR !== undefined)
|
|
250
|
+
return b.has(n.FORCE_COLOR);
|
|
251
|
+
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
252
|
+
return false;
|
|
253
|
+
return i?.isTTY === true;
|
|
254
|
+
}
|
|
255
|
+
function d2(i, n, a) {
|
|
256
|
+
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
257
|
+
return n;
|
|
258
|
+
let l = "", s = "";
|
|
259
|
+
for (let g = 0, y = i.length;g < y; g++) {
|
|
260
|
+
let [c, p] = i[g];
|
|
261
|
+
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
262
|
+
}
|
|
263
|
+
return l + n + s;
|
|
264
|
+
}
|
|
265
|
+
function u(i, n = []) {
|
|
266
|
+
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
267
|
+
let g = C2[s];
|
|
268
|
+
if (Array.isArray(g))
|
|
269
|
+
return u(i, [...n, g]);
|
|
270
|
+
if (typeof g === "function")
|
|
271
|
+
return (...y) => u(i, [...n, g(...y)]);
|
|
272
|
+
throw Error(`Unknown style: ${String(s)}`);
|
|
273
|
+
} });
|
|
274
|
+
}
|
|
275
|
+
function le(i = {}) {
|
|
276
|
+
return u(i);
|
|
277
|
+
}
|
|
278
|
+
var t = le();
|
|
279
|
+
|
|
280
|
+
// ../kit/src/style.ts
|
|
281
|
+
var MARKS = {
|
|
282
|
+
ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
|
|
283
|
+
warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
|
|
284
|
+
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
285
|
+
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
286
|
+
};
|
|
287
|
+
function takesControlCodes(stream, env = process.env) {
|
|
288
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
289
|
+
}
|
|
290
|
+
function paint(stream, env = process.env) {
|
|
291
|
+
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
292
|
+
}
|
|
293
|
+
function marked(mark, text, stream, detail, env = process.env) {
|
|
294
|
+
const colors = paint(stream, env);
|
|
295
|
+
const { symbol, word, paint: tint } = MARKS[mark];
|
|
296
|
+
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
297
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
298
|
+
}
|
|
299
|
+
function warn(text, detail) {
|
|
300
|
+
console.error(marked("warn", text, process.stderr, detail));
|
|
301
|
+
}
|
|
302
|
+
var STATUSES = {
|
|
303
|
+
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
304
|
+
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
305
|
+
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
306
|
+
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
307
|
+
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
308
|
+
};
|
|
309
|
+
var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
|
|
310
|
+
|
|
311
|
+
// ../kit/src/format.ts
|
|
312
|
+
function upTo(text, separator) {
|
|
313
|
+
const end = text.indexOf(separator);
|
|
314
|
+
return end === -1 ? text : text.slice(0, end);
|
|
315
|
+
}
|
|
316
|
+
function truncate(text, width) {
|
|
317
|
+
return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
|
|
318
|
+
}
|
|
319
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
320
|
+
var ESCAPE = String.fromCharCode(27);
|
|
321
|
+
function textWidth(text) {
|
|
322
|
+
return Bun.stringWidth(text);
|
|
323
|
+
}
|
|
324
|
+
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
325
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
326
|
+
const widths = [];
|
|
327
|
+
for (const row of cells) {
|
|
328
|
+
for (const [index, cell] of row.entries())
|
|
329
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
330
|
+
}
|
|
331
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
332
|
+
const colors = paint(process2.stdout);
|
|
333
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
334
|
+
const width = widths[index] ?? 0;
|
|
335
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
336
|
+
if (align[index] === "right")
|
|
337
|
+
return `${gap}${cell}`;
|
|
338
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
339
|
+
}).join(" ").trimEnd());
|
|
340
|
+
return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
|
|
341
|
+
`);
|
|
342
|
+
}
|
|
343
|
+
function narrow(rows, widths, limit) {
|
|
344
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
345
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
346
|
+
const floor = 8;
|
|
347
|
+
while (used() > limit) {
|
|
348
|
+
let widest = -1;
|
|
349
|
+
for (const [index, width] of widths.entries()) {
|
|
350
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
351
|
+
widest = index;
|
|
352
|
+
}
|
|
353
|
+
if (widest === -1)
|
|
354
|
+
break;
|
|
355
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
356
|
+
}
|
|
357
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
358
|
+
}
|
|
359
|
+
function printJson(value) {
|
|
360
|
+
console.log(JSON.stringify(value, undefined, 2));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ../kit/src/text.ts
|
|
364
|
+
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
365
|
+
function distance(a, b) {
|
|
366
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
367
|
+
for (const [i, left] of [...a].entries()) {
|
|
368
|
+
const current = [i + 1];
|
|
369
|
+
for (const [j, right] of [...b].entries())
|
|
370
|
+
current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
|
|
371
|
+
previous = current;
|
|
372
|
+
}
|
|
373
|
+
return previous[b.length] ?? 0;
|
|
374
|
+
}
|
|
375
|
+
function closest(name, names) {
|
|
376
|
+
const started = names.find((known) => known.startsWith(name));
|
|
377
|
+
if (started !== undefined)
|
|
378
|
+
return started;
|
|
379
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
380
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ../kit/src/args.ts
|
|
384
|
+
function jsonOption(holds) {
|
|
385
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
class Exit extends Error {
|
|
389
|
+
code;
|
|
390
|
+
hint;
|
|
391
|
+
constructor(message, code, hint) {
|
|
392
|
+
super(message);
|
|
393
|
+
this.code = code;
|
|
394
|
+
this.hint = hint;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function fail(message, code = 2, hint) {
|
|
398
|
+
throw new Exit(message, code, hint);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
class UsageError extends Exit {
|
|
402
|
+
constructor(message, hint) {
|
|
403
|
+
super(message, 2, hint);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function badUsage(message) {
|
|
407
|
+
throw new UsageError(message);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
class HelpShown extends Exit {
|
|
411
|
+
constructor() {
|
|
412
|
+
super("help shown", 0);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
class Completing {
|
|
417
|
+
options;
|
|
418
|
+
constructor(options) {
|
|
419
|
+
this.options = options;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
var completion = { active: false };
|
|
423
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
424
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
425
|
+
var FULL_STOP = /\.$/;
|
|
426
|
+
var DASHES = /^-+/;
|
|
427
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
428
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
429
|
+
}
|
|
430
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
431
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
432
|
+
`);
|
|
433
|
+
}
|
|
434
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
435
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
436
|
+
}
|
|
437
|
+
function wantsHelpJson(env = process3.env) {
|
|
438
|
+
return env.KIT_HELP === "json";
|
|
439
|
+
}
|
|
440
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
441
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
442
|
+
`);
|
|
443
|
+
const first = lines[0];
|
|
444
|
+
const colon = first.indexOf(": ");
|
|
445
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
446
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
447
|
+
return {
|
|
448
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
449
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
450
|
+
...replaces === undefined ? {} : { replaces },
|
|
451
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
455
|
+
if (examples.length === 0)
|
|
456
|
+
return [];
|
|
457
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
458
|
+
}
|
|
459
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
460
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
461
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
462
|
+
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
463
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
|
|
464
|
+
});
|
|
465
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
466
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
467
|
+
}
|
|
468
|
+
var OUTPUT_OPTIONS = {
|
|
469
|
+
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
470
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
471
|
+
};
|
|
472
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
473
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
474
|
+
if (when === "auto")
|
|
475
|
+
return;
|
|
476
|
+
if (when !== "always" && when !== "never")
|
|
477
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
478
|
+
if (when === "always") {
|
|
479
|
+
env.FORCE_COLOR = "1";
|
|
480
|
+
delete env.NO_COLOR;
|
|
481
|
+
} else {
|
|
482
|
+
env.NO_COLOR = "1";
|
|
483
|
+
delete env.FORCE_COLOR;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function parse(args, usage, options, settings = {}) {
|
|
487
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
488
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
489
|
+
if (completion.active)
|
|
490
|
+
throw new Completing(all);
|
|
491
|
+
const separator = settings.rest === true ? args.indexOf("--") : -1;
|
|
492
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
493
|
+
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
494
|
+
let parsed;
|
|
495
|
+
try {
|
|
496
|
+
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
497
|
+
} catch (error) {
|
|
498
|
+
const message = parseError(error);
|
|
499
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
500
|
+
}
|
|
501
|
+
const values = parsed.values;
|
|
502
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
503
|
+
if (values.help === true) {
|
|
504
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
|
|
505
|
+
throw new HelpShown;
|
|
506
|
+
}
|
|
507
|
+
if (settings.positionals !== undefined)
|
|
508
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
509
|
+
return { ...parsed, positionals: parsed.positionals, rest };
|
|
510
|
+
}
|
|
511
|
+
function checkPositionals(given, names) {
|
|
512
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
513
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
514
|
+
if (given.length < required)
|
|
515
|
+
badUsage(`missing ${names[given.length]}`);
|
|
516
|
+
if (!variadic && given.length > names.length)
|
|
517
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
518
|
+
}
|
|
519
|
+
function joinDashValues(args, options) {
|
|
520
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
521
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
522
|
+
const joined = [];
|
|
523
|
+
for (let i = 0;i < args.length; i++) {
|
|
524
|
+
const arg = args[i] ?? "";
|
|
525
|
+
if (arg === "--")
|
|
526
|
+
return [...joined, ...args.slice(i)];
|
|
527
|
+
const name = longOf.get(arg);
|
|
528
|
+
const next = args[i + 1];
|
|
529
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
530
|
+
joined.push(`--${name}=${next}`);
|
|
531
|
+
i++;
|
|
532
|
+
} else {
|
|
533
|
+
joined.push(arg);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return joined;
|
|
537
|
+
}
|
|
538
|
+
function parseError(error) {
|
|
539
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
540
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
541
|
+
}
|
|
542
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
543
|
+
function nearestOption(message, options, allowNegative) {
|
|
544
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
545
|
+
if (typed === undefined)
|
|
546
|
+
return;
|
|
547
|
+
const word = typed.replace(DASHES, "");
|
|
548
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
549
|
+
return;
|
|
550
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
551
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
552
|
+
`--${name}`,
|
|
553
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
554
|
+
]);
|
|
555
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
556
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
557
|
+
}
|
|
558
|
+
var WHOLE = /^\d+$/;
|
|
559
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
560
|
+
if (value === undefined)
|
|
561
|
+
return fallback;
|
|
562
|
+
const number = Number(value);
|
|
563
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
564
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
565
|
+
return number;
|
|
566
|
+
}
|
|
567
|
+
function isStdinPiped() {
|
|
568
|
+
const stat = fstatSync(0);
|
|
569
|
+
return stat.isFIFO() || stat.isFile();
|
|
570
|
+
}
|
|
571
|
+
// ../kit/src/process.ts
|
|
572
|
+
import { constants } from "os";
|
|
573
|
+
import process4 from "process";
|
|
574
|
+
var KILL_GRACE_MS = 2000;
|
|
575
|
+
function exitCodeOf(code, signal) {
|
|
576
|
+
if (code !== null)
|
|
577
|
+
return code;
|
|
578
|
+
if (typeof signal === "number")
|
|
579
|
+
return 128 + signal;
|
|
580
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
581
|
+
}
|
|
582
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
583
|
+
const chunks = [];
|
|
584
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
585
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
586
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
587
|
+
const timers = [];
|
|
588
|
+
const killGroup = (killing) => {
|
|
589
|
+
if (state.done)
|
|
590
|
+
return;
|
|
591
|
+
try {
|
|
592
|
+
if (grouped)
|
|
593
|
+
process4.kill(-proc.pid, killing);
|
|
594
|
+
else
|
|
595
|
+
proc.kill(killing);
|
|
596
|
+
} catch {}
|
|
597
|
+
};
|
|
598
|
+
const stop = () => {
|
|
599
|
+
killGroup("SIGTERM");
|
|
600
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
601
|
+
};
|
|
602
|
+
const onAbort = () => stop();
|
|
603
|
+
if (timeoutMs !== undefined) {
|
|
604
|
+
timers.push(setTimeout(() => {
|
|
605
|
+
state.timedOut = true;
|
|
606
|
+
stop();
|
|
607
|
+
}, timeoutMs));
|
|
608
|
+
}
|
|
609
|
+
if (signal?.aborted === true)
|
|
610
|
+
onAbort();
|
|
611
|
+
else
|
|
612
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
613
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
614
|
+
const drain = async (stream, name) => {
|
|
615
|
+
for await (const data of stream) {
|
|
616
|
+
if (state.failure !== undefined)
|
|
617
|
+
continue;
|
|
618
|
+
try {
|
|
619
|
+
onChunk?.({ stream: name, data });
|
|
620
|
+
} catch (error) {
|
|
621
|
+
state.failure = error;
|
|
622
|
+
stop();
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
if (state.kept + data.length > maxBytes) {
|
|
626
|
+
state.truncated = true;
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
state.kept += data.length;
|
|
630
|
+
chunks.push({ stream: name, data });
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
try {
|
|
634
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
635
|
+
await proc.exited;
|
|
636
|
+
} finally {
|
|
637
|
+
state.done = true;
|
|
638
|
+
for (const timer of timers)
|
|
639
|
+
clearTimeout(timer);
|
|
640
|
+
signal?.removeEventListener("abort", onAbort);
|
|
641
|
+
}
|
|
642
|
+
if (state.failure !== undefined)
|
|
643
|
+
throw state.failure;
|
|
644
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
645
|
+
let output;
|
|
646
|
+
let text;
|
|
647
|
+
return {
|
|
648
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
649
|
+
chunks,
|
|
650
|
+
timedOut: state.timedOut,
|
|
651
|
+
truncated: state.truncated,
|
|
652
|
+
get output() {
|
|
653
|
+
return output ??= joined();
|
|
654
|
+
},
|
|
655
|
+
get text() {
|
|
656
|
+
return text ??= (output ??= joined()).toString();
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ../kit/src/progress.ts
|
|
662
|
+
var ESC = String.fromCharCode(27);
|
|
663
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
664
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
665
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
666
|
+
// ../kit/src/cli.ts
|
|
667
|
+
import process5 from "process";
|
|
668
|
+
var LEVEL_OPTIONS = {
|
|
669
|
+
...OUTPUT_OPTIONS,
|
|
670
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
671
|
+
};
|
|
672
|
+
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
673
|
+
function printError(prefix, message, hint, cause) {
|
|
674
|
+
const colors = paint(process5.stderr);
|
|
675
|
+
const styled = takesControlCodes(process5.stderr);
|
|
676
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
677
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
678
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
679
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
680
|
+
}
|
|
681
|
+
function printJsonError(message, hint, cause) {
|
|
682
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
683
|
+
}
|
|
684
|
+
function wantsJson(argv) {
|
|
685
|
+
const end = argv.indexOf("--");
|
|
686
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
687
|
+
}
|
|
688
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
689
|
+
if (error instanceof HelpShown)
|
|
690
|
+
return 0;
|
|
691
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
692
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
693
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
694
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
695
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
696
|
+
return error instanceof Exit ? error.code : 1;
|
|
697
|
+
}
|
|
698
|
+
var COMPLETE = "__complete";
|
|
699
|
+
var FILES = "__files__";
|
|
700
|
+
async function optionsOf(run) {
|
|
701
|
+
completion.active = true;
|
|
702
|
+
try {
|
|
703
|
+
await run([]);
|
|
704
|
+
} catch (error) {
|
|
705
|
+
if (error instanceof Completing)
|
|
706
|
+
return error.options;
|
|
707
|
+
} finally {
|
|
708
|
+
completion.active = false;
|
|
709
|
+
}
|
|
710
|
+
return {};
|
|
711
|
+
}
|
|
712
|
+
async function leafCandidates(run, words) {
|
|
713
|
+
if (!(words.at(-1) ?? "").startsWith("-"))
|
|
714
|
+
return [FILES];
|
|
715
|
+
return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
716
|
+
}
|
|
717
|
+
async function printCandidates(found) {
|
|
718
|
+
for (const line of await found)
|
|
719
|
+
console.log(line);
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
async function runMain({ name, version, run, redact }, argv = process5.argv.slice(2)) {
|
|
723
|
+
if (argv[0] === COMPLETE)
|
|
724
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
725
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
726
|
+
console.log(version);
|
|
727
|
+
return 0;
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
return await run(argv);
|
|
731
|
+
} catch (error) {
|
|
732
|
+
return reportThrown(name, error, redact, wantsJson(argv));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
// ../kit/src/limit.ts
|
|
736
|
+
function limitOptions(fallback) {
|
|
737
|
+
return {
|
|
738
|
+
limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
739
|
+
full: { type: "boolean", description: "show every row" }
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function limitOf(values, fallback) {
|
|
743
|
+
if (values.full === true && values.limit !== undefined)
|
|
744
|
+
badUsage("--limit and --full exclude each other");
|
|
745
|
+
if (values.full === true || values.json === true && values.limit === undefined)
|
|
746
|
+
return Number.POSITIVE_INFINITY;
|
|
747
|
+
return wholeNumber(values.limit, "limit", fallback);
|
|
748
|
+
}
|
|
749
|
+
function moreFooter(more) {
|
|
750
|
+
return `${more} more, rerun with --full`;
|
|
751
|
+
}
|
|
752
|
+
function capped(rows, limit) {
|
|
753
|
+
const more = rows.length - limit;
|
|
754
|
+
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
755
|
+
}
|
|
756
|
+
// ../kit/src/logs.ts
|
|
757
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
758
|
+
// ../kit/src/secrets.ts
|
|
759
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
760
|
+
// ../kit/src/sessions.ts
|
|
761
|
+
var {Glob } = globalThis.Bun;
|
|
762
|
+
var SESSION_FILES = new Glob("*.json");
|
|
763
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
764
|
+
// package.json
|
|
765
|
+
var version = "0.5.0";
|
|
766
|
+
|
|
767
|
+
// src/files.ts
|
|
768
|
+
import { existsSync, readdirSync, statSync } from "fs";
|
|
769
|
+
import { join, relative } from "path";
|
|
770
|
+
var MAX_BYTES = 2000000;
|
|
771
|
+
var SNIFF_BYTES = 8000;
|
|
772
|
+
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
773
|
+
function walk(dir, found) {
|
|
774
|
+
let entries;
|
|
775
|
+
try {
|
|
776
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
777
|
+
} catch {
|
|
778
|
+
return found;
|
|
779
|
+
}
|
|
780
|
+
for (const entry of entries) {
|
|
781
|
+
if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
782
|
+
continue;
|
|
783
|
+
if (entry.isDirectory())
|
|
784
|
+
walk(join(dir, entry.name), found);
|
|
785
|
+
else if (entry.isFile())
|
|
786
|
+
found.push(join(dir, entry.name));
|
|
787
|
+
}
|
|
788
|
+
return found;
|
|
789
|
+
}
|
|
790
|
+
async function listFiles(paths, cwd) {
|
|
791
|
+
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
792
|
+
if (listed.code === 0)
|
|
793
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join(cwd, path))).sort();
|
|
794
|
+
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join(cwd, path));
|
|
795
|
+
return roots.flatMap((root) => statSync(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
|
|
796
|
+
}
|
|
797
|
+
async function readText(path) {
|
|
798
|
+
const file = Bun.file(path);
|
|
799
|
+
try {
|
|
800
|
+
if (file.size > MAX_BYTES || (await file.slice(0, SNIFF_BYTES).bytes()).includes(0))
|
|
801
|
+
return;
|
|
802
|
+
return await file.text();
|
|
803
|
+
} catch {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// src/todo.ts
|
|
809
|
+
var COMMENT = /(?<![:\w/])\/\/|\/\*|<!--|(?:^|\s)(?:#|--)(?=\s)|^\s*\*(?=\s|$)/;
|
|
810
|
+
var MARKUP = /\.(?:md|mdx|markdown|html?|xml)$/i;
|
|
811
|
+
var MARKUP_COMMENT = /<!--/;
|
|
812
|
+
var CLOSERS = /\s*(?:\*\/|-->)\s*$/;
|
|
813
|
+
var MARKER = /^(?:@|\[)?(TODO|FIXME)\b/;
|
|
814
|
+
var QUOTES = ["'", '"', "`"];
|
|
815
|
+
var ESCAPE2 = /\\./g;
|
|
816
|
+
var AFTER_FIRST_LINE = /\n[\s\S]*/;
|
|
817
|
+
var REF = /(?<![\w./-])(\w[\w.-]*\/(?!\.+#)[\w.][\w.-]*)#(\d+)\b/g;
|
|
818
|
+
function isQuoted(line, index) {
|
|
819
|
+
const before = line.slice(0, index).replaceAll(ESCAPE2, "");
|
|
820
|
+
return QUOTES.some((quote) => before.split(quote).length % 2 === 0);
|
|
821
|
+
}
|
|
822
|
+
function marksIn(text, path) {
|
|
823
|
+
const marks = [];
|
|
824
|
+
const comment = MARKUP.test(path) ? MARKUP_COMMENT : COMMENT;
|
|
825
|
+
for (const [i, line] of text.split(`
|
|
826
|
+
`).entries()) {
|
|
827
|
+
const opener = comment.exec(line);
|
|
828
|
+
if (opener === null || isQuoted(line, opener.index))
|
|
829
|
+
continue;
|
|
830
|
+
const body = line.slice(opener.index + opener[0].length).replace(CLOSERS, "").trim();
|
|
831
|
+
const marker = MARKER.exec(body)?.[1];
|
|
832
|
+
const refs = [...body.matchAll(REF)].map((found) => ({ repo: found[1] ?? "", number: Number(found[2]) }));
|
|
833
|
+
if (marker !== undefined || refs.length > 0)
|
|
834
|
+
marks.push({ path, line: i + 1, kind: marker ?? "ref", text: body, refs });
|
|
835
|
+
}
|
|
836
|
+
return marks;
|
|
837
|
+
}
|
|
838
|
+
function stdoutOf(chunks) {
|
|
839
|
+
return Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
840
|
+
}
|
|
841
|
+
function refKey(ref) {
|
|
842
|
+
return `${ref.repo}#${ref.number}`;
|
|
843
|
+
}
|
|
844
|
+
async function lookUpOnGitHub(repo, numbers, cwd) {
|
|
845
|
+
const states = new Map;
|
|
846
|
+
for (const ran of await Promise.all(numbers.map(async (number) => ({ number, ran: await runCommand(["gh", "api", `repos/${repo}/issues/${number}`, "--jq", ".state"], { cwd }) })))) {
|
|
847
|
+
if (ran.ran.code !== 0)
|
|
848
|
+
return ran.ran.text.trim().replace(AFTER_FIRST_LINE, "");
|
|
849
|
+
states.set(refKey({ repo, number: Number(ran.number) }), stdoutOf(ran.ran.chunks).trim());
|
|
850
|
+
}
|
|
851
|
+
return states;
|
|
852
|
+
}
|
|
853
|
+
async function lookUp(refs, cwd) {
|
|
854
|
+
const lookup = { states: new Map, failed: new Map };
|
|
855
|
+
const byRepo = Map.groupBy(refs, (ref) => ref.repo);
|
|
856
|
+
for (const [repo, ofRepo] of byRepo) {
|
|
857
|
+
const numbers = [...new Set(ofRepo.map((ref) => String(ref.number)))];
|
|
858
|
+
const ran = Bun.which("ft") === null ? undefined : await runCommand(["ft", "issue", ...numbers, "-r", repo, "--json"], { cwd });
|
|
859
|
+
if (ran === undefined || ran.code !== 0) {
|
|
860
|
+
const onGitHub = Bun.which("gh") === null ? "gh is not installed" : await lookUpOnGitHub(repo, numbers, cwd);
|
|
861
|
+
if (typeof onGitHub === "string") {
|
|
862
|
+
lookup.failed.set(repo, `ft: ${ran === undefined ? "not installed" : ran.text.trim().replace(AFTER_FIRST_LINE, "")}; gh: ${onGitHub}`);
|
|
863
|
+
} else {
|
|
864
|
+
for (const [key, state] of onGitHub)
|
|
865
|
+
lookup.states.set(key, state);
|
|
866
|
+
}
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
const parsed = JSON.parse(stdoutOf(ran.chunks));
|
|
870
|
+
for (const issue of Array.isArray(parsed) ? parsed : [parsed])
|
|
871
|
+
lookup.states.set(refKey({ repo, number: issue.number }), issue.state);
|
|
872
|
+
}
|
|
873
|
+
return lookup;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// src/todo-scan.ts
|
|
877
|
+
var USAGE = `todo-scan [options] [path...]: lists the TODO, FIXME and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
|
|
878
|
+
|
|
879
|
+
--stale keeps only the comments naming a closed issue, each issue's state looked up with ft, or gh for a GitHub repository, and exits 1 when it finds one.
|
|
880
|
+
|
|
881
|
+
Lists at most 100 comments, the count of the rest after them (--limit <n>, --full for all); --json is never cut unless --limit is given.
|
|
882
|
+
|
|
883
|
+
Exits 0 when it listed the comments or found no stale one, 1 when --stale finds one, 2 on a usage error or when --stale could not look a repository up (ft and gh both failed), so a clean exit never hides an unchecked issue.`;
|
|
884
|
+
var LIST_LIMIT = 100;
|
|
885
|
+
var OPTIONS = {
|
|
886
|
+
stale: { type: "boolean", description: "only the comments naming a closed issue, looked up with ft or gh" },
|
|
887
|
+
...limitOptions(LIST_LIMIT),
|
|
888
|
+
json: jsonOption("[{path, line, kind, text, refs: [{repo, number, state?}]}]")
|
|
889
|
+
};
|
|
890
|
+
function printLines(lines, footer) {
|
|
891
|
+
const all = [...lines, ...footer === undefined ? [] : [footer]];
|
|
892
|
+
if (all.length > 0)
|
|
893
|
+
console.log(all.join(`
|
|
894
|
+
`));
|
|
895
|
+
}
|
|
896
|
+
async function main(args) {
|
|
897
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
898
|
+
const cwd = process7.cwd();
|
|
899
|
+
const limit = limitOf(values, LIST_LIMIT);
|
|
900
|
+
const marks = [];
|
|
901
|
+
for (const path of await listFiles(positionals, cwd)) {
|
|
902
|
+
const text = await readText(join2(cwd, path));
|
|
903
|
+
if (text !== undefined)
|
|
904
|
+
marks.push(...marksIn(text, path));
|
|
905
|
+
}
|
|
906
|
+
if (values.stale !== true) {
|
|
907
|
+
const { shown, footer } = capped(marks, limit);
|
|
908
|
+
if (values.json === true)
|
|
909
|
+
printJson(shown);
|
|
910
|
+
else
|
|
911
|
+
printLines(shown.map((mark) => `${mark.path}:${mark.line}: ${mark.text}`), footer);
|
|
912
|
+
return 0;
|
|
913
|
+
}
|
|
914
|
+
const { states, failed } = await lookUp(marks.flatMap((mark) => mark.refs), cwd);
|
|
915
|
+
for (const [repo, reason] of failed)
|
|
916
|
+
warn(`could not look ${repo} up`, reason);
|
|
917
|
+
const stale = marks.filter((mark) => mark.refs.some((ref) => states.get(refKey(ref)) === "closed"));
|
|
918
|
+
const { shown, footer } = capped(stale, limit);
|
|
919
|
+
if (values.json === true)
|
|
920
|
+
printJson(shown.map((mark) => ({ ...mark, refs: mark.refs.map((ref) => ({ ...ref, state: states.get(refKey(ref)) })) })));
|
|
921
|
+
else
|
|
922
|
+
printLines(shown.map((mark) => `${mark.path}:${mark.line}: ${mark.refs.filter((ref) => states.get(refKey(ref)) === "closed").map(refKey).join(", ")} closed: ${mark.text}`), footer);
|
|
923
|
+
if (stale.length > 0)
|
|
924
|
+
return 1;
|
|
925
|
+
return failed.size > 0 ? 2 : 0;
|
|
926
|
+
}
|
|
927
|
+
process7.exitCode = await runMain({ name: "todo-scan", version, run: main });
|