@kaynooo/cli-code 0.15.1 → 0.17.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/README.md +19 -19
- package/dist/cli.js +675 -210
- package/package.json +10 -16
- package/dist/hotspots-cli.js +0 -1661
- package/dist/peek-cli.js +0 -1885
- package/dist/todo-scan-cli.js +0 -1654
package/dist/cli.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
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
|
-
|
|
6
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process9 from "process";
|
|
8
|
-
import { parseArgs } from "util";
|
|
9
|
-
|
|
10
|
-
// ../kit/src/format.ts
|
|
11
|
-
import process7 from "process";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
-
var ct = /[aeiou]y$/;
|
|
15
|
-
var N = new Map;
|
|
16
|
-
var Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
|
|
17
|
-
var Gt = /(?:knife|life|wife)$/;
|
|
18
|
-
function K(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function G(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
19
17
|
if (e === 1 || e === 0 && n === "singular")
|
|
20
18
|
return t;
|
|
21
19
|
if (r !== undefined)
|
|
@@ -28,12 +26,10 @@ function K(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
|
28
26
|
return `${t.slice(0, -1)}ves`;
|
|
29
27
|
return Gt.test(t) ? `${t.slice(0, -2)}ves` : `${t}s`;
|
|
30
28
|
}
|
|
31
|
-
function
|
|
32
|
-
return `${t} ${
|
|
29
|
+
function bo(t, e, { zero: r = "plural", ...n } = {}) {
|
|
30
|
+
return `${t} ${G(e, t, { ...n, zero: r })}`;
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
var Y = /\s/;
|
|
36
|
-
function ko(t, e, r = "...") {
|
|
32
|
+
function Ao(t, e, r = "...") {
|
|
37
33
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
38
34
|
if (t.length <= e)
|
|
39
35
|
return t;
|
|
@@ -44,13 +40,25 @@ function ko(t, e, r = "...") {
|
|
|
44
40
|
c = c.trimEnd();
|
|
45
41
|
return s ? (c + n).slice(0, l) : c + n;
|
|
46
42
|
}
|
|
47
|
-
var
|
|
48
|
-
var
|
|
43
|
+
var ct, N, Ot, Gt, Nt, Y, be, W;
|
|
44
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
45
|
+
ct = /[aeiou]y$/;
|
|
46
|
+
N = new Map;
|
|
47
|
+
Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
|
|
48
|
+
Gt = /(?:knife|life|wife)$/;
|
|
49
|
+
Nt = /\s+\S*$/;
|
|
50
|
+
Y = /\s/;
|
|
51
|
+
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));
|
|
52
|
+
W = new Map;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
56
|
+
var init_text = __esm(() => {
|
|
57
|
+
init_chunk_rkhsft4a();
|
|
58
|
+
});
|
|
49
59
|
|
|
50
60
|
// ../kit/src/mode.ts
|
|
51
61
|
import process2 from "process";
|
|
52
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
53
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
54
62
|
function isSet(value) {
|
|
55
63
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
56
64
|
}
|
|
@@ -64,14 +72,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
64
72
|
return "terminal";
|
|
65
73
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
66
74
|
}
|
|
75
|
+
var MODES, AGENT_VARIABLES;
|
|
76
|
+
var init_mode = __esm(() => {
|
|
77
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
78
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
79
|
+
});
|
|
67
80
|
|
|
68
|
-
//
|
|
69
|
-
import { resolve as resolve3 } from "path";
|
|
70
|
-
import process6 from "process";
|
|
71
|
-
import { pathToFileURL } from "url";
|
|
72
|
-
|
|
73
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
74
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
81
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
75
82
|
function b(r) {
|
|
76
83
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
77
84
|
if (!G2.test(e))
|
|
@@ -82,11 +89,6 @@ function b(r) {
|
|
|
82
89
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
83
90
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
84
91
|
}
|
|
85
|
-
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") => {
|
|
86
|
-
let [l, n, c] = b(r);
|
|
87
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
88
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
89
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
90
92
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
91
93
|
if (e.FORCE_COLOR !== undefined)
|
|
92
94
|
return h.has(e.FORCE_COLOR);
|
|
@@ -100,7 +102,7 @@ function f(r, e = []) {
|
|
|
100
102
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
101
103
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
102
104
|
return new Proxy(c, { get(t, i) {
|
|
103
|
-
let a =
|
|
105
|
+
let a = B[i];
|
|
104
106
|
if (Array.isArray(a)) {
|
|
105
107
|
let s = g.get(i);
|
|
106
108
|
if (s === undefined)
|
|
@@ -123,13 +125,21 @@ function f(r, e = []) {
|
|
|
123
125
|
function Fe(r = {}) {
|
|
124
126
|
return f(r);
|
|
125
127
|
}
|
|
126
|
-
var
|
|
128
|
+
var G2, B, h, o;
|
|
129
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
130
|
+
G2 = /^[a-f0-9]+$/i;
|
|
131
|
+
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") => {
|
|
132
|
+
let [l, n, c] = b(r);
|
|
133
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
134
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
135
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
136
|
+
o = Fe();
|
|
137
|
+
});
|
|
127
138
|
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
import process5 from "process";
|
|
139
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
140
|
+
var init_colors = __esm(() => {
|
|
141
|
+
init_chunk_x450vn3m();
|
|
142
|
+
});
|
|
133
143
|
|
|
134
144
|
// ../kit/src/config.ts
|
|
135
145
|
import { existsSync } from "fs";
|
|
@@ -145,6 +155,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
145
155
|
return;
|
|
146
156
|
}
|
|
147
157
|
}
|
|
158
|
+
var init_config = __esm(() => {
|
|
159
|
+
init_args();
|
|
160
|
+
});
|
|
148
161
|
|
|
149
162
|
// ../kit/src/user-config.ts
|
|
150
163
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -180,36 +193,49 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
|
180
193
|
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
194
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
195
|
}
|
|
196
|
+
var init_user_config = () => {};
|
|
183
197
|
|
|
184
198
|
// ../kit/src/theme.ts
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
200
|
+
import { homedir as homedir2 } from "os";
|
|
201
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
202
|
+
import process5 from "process";
|
|
203
|
+
function toLinear(channel) {
|
|
204
|
+
const value = channel / 255;
|
|
205
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
206
|
+
}
|
|
207
|
+
function toOklab(hex) {
|
|
208
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
209
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
210
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
211
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
212
|
+
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];
|
|
213
|
+
}
|
|
214
|
+
function fromOklab([lightness, a, b]) {
|
|
215
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
216
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
217
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
218
|
+
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];
|
|
219
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
220
|
+
}
|
|
221
|
+
function gradientAt(theme, ratio) {
|
|
222
|
+
if (theme.gradient === undefined)
|
|
223
|
+
return;
|
|
224
|
+
const key = theme.gradient.join();
|
|
225
|
+
let ends = ENDS.get(key);
|
|
226
|
+
if (ends === undefined) {
|
|
227
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
228
|
+
ENDS.set(key, ends);
|
|
229
|
+
}
|
|
230
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
231
|
+
const [from, to] = ends;
|
|
232
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
233
|
+
}
|
|
207
234
|
function isColorSpec(spec) {
|
|
208
235
|
if (typeof spec === "number")
|
|
209
236
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
210
237
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
211
238
|
}
|
|
212
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
213
239
|
function cubeLevel(channel) {
|
|
214
240
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
215
241
|
}
|
|
@@ -234,6 +260,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
234
260
|
return chain[token] ?? chain;
|
|
235
261
|
}, colors);
|
|
236
262
|
}
|
|
263
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
264
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
265
|
+
}
|
|
237
266
|
function isRecord(value) {
|
|
238
267
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
239
268
|
}
|
|
@@ -314,7 +343,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
314
343
|
function endsWalk(home) {
|
|
315
344
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
316
345
|
}
|
|
317
|
-
var warned = new Set;
|
|
318
346
|
function warnOnce(message) {
|
|
319
347
|
if (warned.has(message))
|
|
320
348
|
return;
|
|
@@ -351,8 +379,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
351
379
|
}
|
|
352
380
|
return { theme, sources, preset };
|
|
353
381
|
}
|
|
354
|
-
var current;
|
|
355
|
-
var currentKey = "";
|
|
356
382
|
function activeTheme() {
|
|
357
383
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
358
384
|
if (current === undefined || key !== currentKey) {
|
|
@@ -361,9 +387,40 @@ function activeTheme() {
|
|
|
361
387
|
}
|
|
362
388
|
return current;
|
|
363
389
|
}
|
|
390
|
+
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 = "";
|
|
391
|
+
var init_theme = __esm(() => {
|
|
392
|
+
init_config();
|
|
393
|
+
init_user_config();
|
|
394
|
+
ENDS = new Map;
|
|
395
|
+
DEFAULT = {
|
|
396
|
+
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" },
|
|
397
|
+
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" },
|
|
398
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
399
|
+
bins: {},
|
|
400
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
401
|
+
};
|
|
402
|
+
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" };
|
|
403
|
+
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" };
|
|
404
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
405
|
+
PRESETS = {
|
|
406
|
+
default: {},
|
|
407
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
408
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
409
|
+
ascii: { glyphs: ASCII }
|
|
410
|
+
};
|
|
411
|
+
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"]);
|
|
412
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
413
|
+
CONTROL = /\p{Cc}/u;
|
|
414
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
415
|
+
SPACES = /\s+/;
|
|
416
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
417
|
+
warned = new Set;
|
|
418
|
+
});
|
|
364
419
|
|
|
365
420
|
// ../kit/src/style.ts
|
|
366
|
-
|
|
421
|
+
import { resolve as resolve3 } from "path";
|
|
422
|
+
import process6 from "process";
|
|
423
|
+
import { pathToFileURL } from "url";
|
|
367
424
|
function takesControlCodes(stream, env = process6.env) {
|
|
368
425
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
369
426
|
}
|
|
@@ -386,14 +443,6 @@ function role(name, stream, env = process6.env) {
|
|
|
386
443
|
const colors = paint(stream, env);
|
|
387
444
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
388
445
|
}
|
|
389
|
-
var STATUS_WORDS = {
|
|
390
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
391
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
392
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
393
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
394
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
395
|
-
};
|
|
396
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
397
446
|
function header(bin, context, stream, env = process6.env) {
|
|
398
447
|
if (!takesControlCodes(stream, env))
|
|
399
448
|
return "";
|
|
@@ -420,9 +469,24 @@ function hyperlink(text, url, stream, env = process6.env) {
|
|
|
420
469
|
function fileLink(text, path, stream, from = process6.cwd(), env = process6.env) {
|
|
421
470
|
return hyperlink(text, pathToFileURL(resolve3(from, path)).href, stream, env);
|
|
422
471
|
}
|
|
472
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
473
|
+
var init_style = __esm(() => {
|
|
474
|
+
init_colors();
|
|
475
|
+
init_mode();
|
|
476
|
+
init_theme();
|
|
477
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
478
|
+
STATUS_WORDS = {
|
|
479
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
480
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
481
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
482
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
483
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
484
|
+
};
|
|
485
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
486
|
+
});
|
|
423
487
|
|
|
424
488
|
// ../kit/src/format.ts
|
|
425
|
-
|
|
489
|
+
import process7 from "process";
|
|
426
490
|
function formatSeconds(total) {
|
|
427
491
|
let rest = Math.max(0, Math.round(total));
|
|
428
492
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -439,15 +503,16 @@ function formatSeconds(total) {
|
|
|
439
503
|
function formatDuration(ms) {
|
|
440
504
|
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
441
505
|
}
|
|
506
|
+
function formatElapsed(ms) {
|
|
507
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
508
|
+
}
|
|
442
509
|
function upTo(text, separator) {
|
|
443
510
|
const end = text.indexOf(separator);
|
|
444
511
|
return end === -1 ? text : text.slice(0, end);
|
|
445
512
|
}
|
|
446
513
|
function truncate(text, width) {
|
|
447
|
-
return
|
|
514
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
448
515
|
}
|
|
449
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
450
|
-
var ESCAPE = String.fromCharCode(27);
|
|
451
516
|
function textWidth(text) {
|
|
452
517
|
return Bun.stringWidth(text);
|
|
453
518
|
}
|
|
@@ -496,12 +561,18 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
496
561
|
function printJson(value) {
|
|
497
562
|
console.log(jsonText(value));
|
|
498
563
|
}
|
|
564
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
565
|
+
var init_format = __esm(() => {
|
|
566
|
+
init_text();
|
|
567
|
+
init_mode();
|
|
568
|
+
init_style();
|
|
569
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
570
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
571
|
+
ESCAPE = String.fromCharCode(27);
|
|
572
|
+
});
|
|
499
573
|
|
|
500
574
|
// ../kit/src/help.ts
|
|
501
575
|
import process8 from "process";
|
|
502
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
503
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
504
|
-
var FULL_STOP = /\.$/;
|
|
505
576
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
506
577
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
507
578
|
}
|
|
@@ -538,7 +609,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
538
609
|
return [];
|
|
539
610
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
540
611
|
}
|
|
541
|
-
var MAX_INLINE_CHOICES = 24;
|
|
542
612
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
543
613
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
544
614
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -553,6 +623,14 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
553
623
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
554
624
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
555
625
|
}
|
|
626
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
|
|
627
|
+
var init_help = __esm(() => {
|
|
628
|
+
init_mode();
|
|
629
|
+
init_style();
|
|
630
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
631
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
632
|
+
FULL_STOP = /\.$/;
|
|
633
|
+
});
|
|
556
634
|
|
|
557
635
|
// ../kit/src/text.ts
|
|
558
636
|
function distance(a, b) {
|
|
@@ -580,9 +658,10 @@ function closest(name, names) {
|
|
|
580
658
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
581
659
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
582
660
|
}
|
|
661
|
+
var init_text2 = () => {};
|
|
662
|
+
|
|
583
663
|
// ../kit/src/input.ts
|
|
584
664
|
import { fstatSync } from "fs";
|
|
585
|
-
var WHOLE = /^\d+$/;
|
|
586
665
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
587
666
|
if (value === undefined)
|
|
588
667
|
return fallback;
|
|
@@ -591,8 +670,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
591
670
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
592
671
|
return number;
|
|
593
672
|
}
|
|
594
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
595
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
596
673
|
function duration(value, name, fallback, unit = "s") {
|
|
597
674
|
if (value === undefined)
|
|
598
675
|
return fallback;
|
|
@@ -606,40 +683,27 @@ function isStdinPiped() {
|
|
|
606
683
|
const stat = fstatSync(0);
|
|
607
684
|
return stat.isFIFO() || stat.isFile();
|
|
608
685
|
}
|
|
686
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
687
|
+
var init_input = __esm(() => {
|
|
688
|
+
init_args();
|
|
689
|
+
WHOLE = /^\d+$/;
|
|
690
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
691
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
692
|
+
});
|
|
609
693
|
|
|
610
694
|
// ../kit/src/args.ts
|
|
611
|
-
|
|
695
|
+
import process9 from "process";
|
|
696
|
+
import { parseArgs } from "util";
|
|
612
697
|
function jsonOption(holds) {
|
|
613
698
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
614
699
|
}
|
|
615
|
-
class Exit extends Error {
|
|
616
|
-
code;
|
|
617
|
-
hint;
|
|
618
|
-
constructor(message, code, hint) {
|
|
619
|
-
super(message);
|
|
620
|
-
this.code = code;
|
|
621
|
-
this.hint = hint;
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
700
|
function fail(message, code = 2, hint) {
|
|
625
701
|
throw new Exit(message, code, hint);
|
|
626
702
|
}
|
|
627
|
-
|
|
628
|
-
class UsageError extends Exit {
|
|
629
|
-
constructor(message, hint) {
|
|
630
|
-
super(message, 2, hint);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
703
|
function badUsage(message) {
|
|
634
704
|
throw new UsageError(message);
|
|
635
705
|
}
|
|
636
706
|
|
|
637
|
-
class HelpShown extends Exit {
|
|
638
|
-
constructor() {
|
|
639
|
-
super("help shown", 0);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
707
|
class Completing {
|
|
644
708
|
options;
|
|
645
709
|
positionals;
|
|
@@ -650,11 +714,6 @@ class Completing {
|
|
|
650
714
|
this.candidates = candidates;
|
|
651
715
|
}
|
|
652
716
|
}
|
|
653
|
-
var completion = { active: false };
|
|
654
|
-
var OUTPUT_OPTIONS = {
|
|
655
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
656
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
657
|
-
};
|
|
658
717
|
function applyOutput(color, plain, env = process9.env) {
|
|
659
718
|
const when = plain === true ? "never" : color ?? "auto";
|
|
660
719
|
if (when === "auto")
|
|
@@ -808,7 +867,6 @@ function parseError(error) {
|
|
|
808
867
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
809
868
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
810
869
|
}
|
|
811
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
812
870
|
function nearestOption(message, options, allowNegative) {
|
|
813
871
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
814
872
|
if (typed === undefined)
|
|
@@ -824,6 +882,59 @@ function nearestOption(message, options, allowNegative) {
|
|
|
824
882
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
825
883
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
826
884
|
}
|
|
885
|
+
var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
886
|
+
var init_args = __esm(() => {
|
|
887
|
+
init_format();
|
|
888
|
+
init_help();
|
|
889
|
+
init_text2();
|
|
890
|
+
init_help();
|
|
891
|
+
init_input();
|
|
892
|
+
DASHES = /^-+/;
|
|
893
|
+
Exit = class Exit extends Error {
|
|
894
|
+
code;
|
|
895
|
+
hint;
|
|
896
|
+
constructor(message, code, hint) {
|
|
897
|
+
super(message);
|
|
898
|
+
this.code = code;
|
|
899
|
+
this.hint = hint;
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
UsageError = class UsageError extends Exit {
|
|
903
|
+
constructor(message, hint) {
|
|
904
|
+
super(message, 2, hint);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
HelpShown = class HelpShown extends Exit {
|
|
908
|
+
constructor() {
|
|
909
|
+
super("help shown", 0);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
completion = { active: false };
|
|
913
|
+
OUTPUT_OPTIONS = {
|
|
914
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
915
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
916
|
+
};
|
|
917
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// ../kit/src/folders.ts
|
|
921
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
922
|
+
const configured = readUserConfig("config", where).ignore;
|
|
923
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
924
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
925
|
+
}
|
|
926
|
+
var SKIPPED_FOLDERS;
|
|
927
|
+
var init_folders = __esm(() => {
|
|
928
|
+
init_user_config();
|
|
929
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// src/cli.ts
|
|
933
|
+
import process21 from "process";
|
|
934
|
+
|
|
935
|
+
// ../kit/src/index.ts
|
|
936
|
+
init_args();
|
|
937
|
+
|
|
827
938
|
// ../kit/src/argv.ts
|
|
828
939
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
829
940
|
import { resolve as resolve4 } from "path";
|
|
@@ -848,10 +959,24 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
848
959
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
849
960
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
850
961
|
}
|
|
962
|
+
// ../kit/src/chart.ts
|
|
963
|
+
init_format();
|
|
964
|
+
init_mode();
|
|
965
|
+
init_style();
|
|
966
|
+
init_theme();
|
|
967
|
+
// ../kit/src/ci.ts
|
|
968
|
+
init_args();
|
|
969
|
+
init_format();
|
|
970
|
+
|
|
971
|
+
// ../kit/src/progress.ts
|
|
972
|
+
init_format();
|
|
973
|
+
import process12 from "process";
|
|
974
|
+
|
|
851
975
|
// ../kit/src/process.ts
|
|
852
976
|
import { constants } from "os";
|
|
853
977
|
import process11 from "process";
|
|
854
978
|
var KILL_GRACE_MS = 2000;
|
|
979
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
855
980
|
function exitCodeOf(code, signal) {
|
|
856
981
|
if (code !== null)
|
|
857
982
|
return code;
|
|
@@ -859,10 +984,41 @@ function exitCodeOf(code, signal) {
|
|
|
859
984
|
return 128 + signal;
|
|
860
985
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
861
986
|
}
|
|
862
|
-
|
|
987
|
+
function holdSignals(cleanup) {
|
|
988
|
+
let received;
|
|
989
|
+
let child;
|
|
990
|
+
const held = {
|
|
991
|
+
get signal() {
|
|
992
|
+
return received;
|
|
993
|
+
},
|
|
994
|
+
forward: (to) => {
|
|
995
|
+
child = to;
|
|
996
|
+
},
|
|
997
|
+
release: () => {
|
|
998
|
+
for (const signal of SIGNALS)
|
|
999
|
+
process11.off(signal, onSignal);
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
function onSignal(signal) {
|
|
1003
|
+
received = signal;
|
|
1004
|
+
if (child !== undefined) {
|
|
1005
|
+
child.kill(signal);
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
if (cleanup === undefined)
|
|
1009
|
+
return;
|
|
1010
|
+
held.release();
|
|
1011
|
+
cleanup(signal);
|
|
1012
|
+
process11.kill(process11.pid, signal);
|
|
1013
|
+
}
|
|
1014
|
+
for (const signal of SIGNALS)
|
|
1015
|
+
process11.on(signal, onSignal);
|
|
1016
|
+
return held;
|
|
1017
|
+
}
|
|
1018
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
863
1019
|
const chunks = [];
|
|
864
1020
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
865
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1021
|
+
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 } : {} });
|
|
866
1022
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
867
1023
|
const timers = [];
|
|
868
1024
|
const killGroup = (killing) => {
|
|
@@ -939,14 +1095,273 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
939
1095
|
}
|
|
940
1096
|
|
|
941
1097
|
// ../kit/src/progress.ts
|
|
1098
|
+
init_style();
|
|
1099
|
+
init_theme();
|
|
1100
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1101
|
+
var FRAME_MS = 200;
|
|
1102
|
+
var BAR_WIDTH = 20;
|
|
1103
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
942
1104
|
var ESC = String.fromCharCode(27);
|
|
943
1105
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
944
1106
|
var RESET_STYLE = `${ESC}[0m`;
|
|
1107
|
+
var CTRL_C = 3;
|
|
945
1108
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1109
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1110
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
1111
|
+
if (!takesControlCodes(stream, env))
|
|
1112
|
+
return { redraw: () => {
|
|
1113
|
+
return;
|
|
1114
|
+
}, print: (text) => void stream.write(`${text}
|
|
1115
|
+
`), stop: () => {
|
|
1116
|
+
return;
|
|
1117
|
+
}, pause: () => () => {
|
|
1118
|
+
return;
|
|
1119
|
+
} };
|
|
1120
|
+
const write = stream.write.bind(stream);
|
|
1121
|
+
let frame = 0;
|
|
1122
|
+
let drawn = false;
|
|
1123
|
+
let paused = false;
|
|
1124
|
+
let stopped = false;
|
|
1125
|
+
const columns = () => {
|
|
1126
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1127
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
1128
|
+
};
|
|
1129
|
+
const clear = () => {
|
|
1130
|
+
if (drawn)
|
|
1131
|
+
write(CLEAR_BELOW);
|
|
1132
|
+
drawn = false;
|
|
1133
|
+
};
|
|
1134
|
+
const draw = () => {
|
|
1135
|
+
if (paused)
|
|
1136
|
+
return;
|
|
1137
|
+
const width = columns() - 1;
|
|
1138
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1139
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1140
|
+
if (lines.length === 0) {
|
|
1141
|
+
clear();
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
1145
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1146
|
+
drawn = true;
|
|
1147
|
+
};
|
|
1148
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1149
|
+
stream.on?.("resize", draw);
|
|
1150
|
+
let restore = interceptOutput(clear);
|
|
1151
|
+
let release = swallowInput();
|
|
1152
|
+
const onExit = () => {
|
|
1153
|
+
clear();
|
|
1154
|
+
release();
|
|
1155
|
+
};
|
|
1156
|
+
const signals = holdSignals(stop);
|
|
1157
|
+
function stop() {
|
|
1158
|
+
stopped = true;
|
|
1159
|
+
clearInterval(timer);
|
|
1160
|
+
stream.off?.("resize", draw);
|
|
1161
|
+
clear();
|
|
1162
|
+
restore();
|
|
1163
|
+
release();
|
|
1164
|
+
process12.off("exit", onExit);
|
|
1165
|
+
signals.release();
|
|
1166
|
+
}
|
|
1167
|
+
function pause() {
|
|
1168
|
+
if (paused || stopped)
|
|
1169
|
+
return () => {
|
|
1170
|
+
return;
|
|
1171
|
+
};
|
|
1172
|
+
paused = true;
|
|
1173
|
+
clearInterval(timer);
|
|
1174
|
+
stream.off?.("resize", draw);
|
|
1175
|
+
clear();
|
|
1176
|
+
restore();
|
|
1177
|
+
release();
|
|
1178
|
+
return () => {
|
|
1179
|
+
if (!paused || stopped)
|
|
1180
|
+
return;
|
|
1181
|
+
paused = false;
|
|
1182
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1183
|
+
timer.unref();
|
|
1184
|
+
stream.on?.("resize", draw);
|
|
1185
|
+
restore = interceptOutput(clear);
|
|
1186
|
+
release = swallowInput();
|
|
1187
|
+
draw();
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
timer.unref();
|
|
1191
|
+
process12.on("exit", onExit);
|
|
1192
|
+
return {
|
|
1193
|
+
redraw: draw,
|
|
1194
|
+
print: (text) => {
|
|
1195
|
+
clear();
|
|
1196
|
+
write(`${text}
|
|
1197
|
+
`);
|
|
1198
|
+
draw();
|
|
1199
|
+
},
|
|
1200
|
+
stop,
|
|
1201
|
+
pause
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1205
|
+
const colors = paint(stream, env);
|
|
1206
|
+
const write = stream.write.bind(stream);
|
|
1207
|
+
const begun = performance.now();
|
|
1208
|
+
let started = begun;
|
|
1209
|
+
let current;
|
|
1210
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1211
|
+
const end = (line) => {
|
|
1212
|
+
region.stop();
|
|
1213
|
+
write(`${line}
|
|
1214
|
+
`);
|
|
1215
|
+
};
|
|
1216
|
+
return {
|
|
1217
|
+
update: (progress) => {
|
|
1218
|
+
const step = current?.step;
|
|
1219
|
+
current = progress;
|
|
1220
|
+
if (progress.step !== step) {
|
|
1221
|
+
started = performance.now();
|
|
1222
|
+
region.redraw();
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
stop: region.stop,
|
|
1226
|
+
pause: region.pause,
|
|
1227
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1228
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1232
|
+
const { theme } = activeTheme();
|
|
1233
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1234
|
+
if (total !== undefined && total > 0) {
|
|
1235
|
+
const counted = Math.min(done ?? 0, total);
|
|
1236
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1237
|
+
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 });
|
|
1238
|
+
}
|
|
1239
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1240
|
+
return parts;
|
|
1241
|
+
}
|
|
1242
|
+
function plain(text) {
|
|
1243
|
+
return text;
|
|
1244
|
+
}
|
|
1245
|
+
function tintedParts(parts, colors) {
|
|
1246
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1247
|
+
}
|
|
1248
|
+
function cutToWidth(line, width) {
|
|
1249
|
+
if (Bun.stringWidth(line) <= width)
|
|
1250
|
+
return line;
|
|
1251
|
+
let room = width;
|
|
1252
|
+
let kept = "";
|
|
1253
|
+
let index = 0;
|
|
1254
|
+
let linked = false;
|
|
1255
|
+
while (index < line.length) {
|
|
1256
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1257
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1258
|
+
if (escape !== null) {
|
|
1259
|
+
kept += escape[0];
|
|
1260
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1261
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1265
|
+
const columns = Bun.stringWidth(char);
|
|
1266
|
+
if (columns > room)
|
|
1267
|
+
break;
|
|
1268
|
+
kept += char;
|
|
1269
|
+
room -= columns;
|
|
1270
|
+
index += char.length;
|
|
1271
|
+
}
|
|
1272
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1273
|
+
}
|
|
1274
|
+
function swallowInput() {
|
|
1275
|
+
const input = process12.stdin;
|
|
1276
|
+
if (!input.isTTY)
|
|
1277
|
+
return () => {
|
|
1278
|
+
return;
|
|
1279
|
+
};
|
|
1280
|
+
const onData = (data) => {
|
|
1281
|
+
if (data.includes(CTRL_C))
|
|
1282
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1283
|
+
};
|
|
1284
|
+
input.setRawMode(true);
|
|
1285
|
+
input.on("data", onData);
|
|
1286
|
+
input.resume();
|
|
1287
|
+
let released = false;
|
|
1288
|
+
return () => {
|
|
1289
|
+
if (released)
|
|
1290
|
+
return;
|
|
1291
|
+
released = true;
|
|
1292
|
+
input.off("data", onData);
|
|
1293
|
+
input.pause();
|
|
1294
|
+
input.setRawMode(false);
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
function interceptOutput(clear) {
|
|
1298
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1299
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1300
|
+
const original = Reflect.get(target, name);
|
|
1301
|
+
const wrapper = (...args) => {
|
|
1302
|
+
clear();
|
|
1303
|
+
return original.apply(target, args);
|
|
1304
|
+
};
|
|
1305
|
+
Reflect.set(target, name, wrapper);
|
|
1306
|
+
return { target, name, original, wrapper };
|
|
1307
|
+
});
|
|
1308
|
+
return () => {
|
|
1309
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1310
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1311
|
+
Reflect.set(target, name, original);
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// ../kit/src/ci.ts
|
|
1317
|
+
init_style();
|
|
1318
|
+
|
|
1319
|
+
// ../kit/src/tool.ts
|
|
1320
|
+
init_format();
|
|
946
1321
|
// ../kit/src/cli.ts
|
|
1322
|
+
init_args();
|
|
947
1323
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
948
1324
|
import { dirname as dirname3, join as join5 } from "path";
|
|
949
|
-
import
|
|
1325
|
+
import process16 from "process";
|
|
1326
|
+
|
|
1327
|
+
// ../kit/src/askpass.ts
|
|
1328
|
+
import process13 from "process";
|
|
1329
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1330
|
+
async function askpassClient(argv) {
|
|
1331
|
+
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
1332
|
+
if (socketPath === undefined)
|
|
1333
|
+
return;
|
|
1334
|
+
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1335
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1336
|
+
let received = "";
|
|
1337
|
+
try {
|
|
1338
|
+
await Bun.connect({
|
|
1339
|
+
unix: socketPath,
|
|
1340
|
+
socket: {
|
|
1341
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1342
|
+
`),
|
|
1343
|
+
data: (_, chunk) => {
|
|
1344
|
+
received += chunk.toString();
|
|
1345
|
+
},
|
|
1346
|
+
close: () => resolve(received),
|
|
1347
|
+
error: () => resolve("")
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
} catch {
|
|
1351
|
+
return 1;
|
|
1352
|
+
}
|
|
1353
|
+
const reply = await promise;
|
|
1354
|
+
if (reply === "")
|
|
1355
|
+
return 1;
|
|
1356
|
+
const { answer } = JSON.parse(reply);
|
|
1357
|
+
if (request.notice === true)
|
|
1358
|
+
return 0;
|
|
1359
|
+
if (answer === undefined)
|
|
1360
|
+
return 1;
|
|
1361
|
+
process13.stdout.write(`${answer}
|
|
1362
|
+
`);
|
|
1363
|
+
return 0;
|
|
1364
|
+
}
|
|
950
1365
|
|
|
951
1366
|
// ../kit/src/completions.ts
|
|
952
1367
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1009,28 +1424,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1009
1424
|
}
|
|
1010
1425
|
|
|
1011
1426
|
// ../kit/src/notify.ts
|
|
1012
|
-
|
|
1427
|
+
init_format();
|
|
1428
|
+
init_mode();
|
|
1429
|
+
import process14 from "process";
|
|
1013
1430
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1014
1431
|
var CANCELLED = 130;
|
|
1015
1432
|
function base64(text) {
|
|
1016
1433
|
return Buffer.from(text).toString("base64");
|
|
1017
1434
|
}
|
|
1018
|
-
function notification(title, body, env =
|
|
1019
|
-
const id = `kit${
|
|
1435
|
+
function notification(title, body, env = process14.env) {
|
|
1436
|
+
const id = `kit${process14.pid}`;
|
|
1020
1437
|
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\\`];
|
|
1021
1438
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1022
1439
|
}
|
|
1023
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1440
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1024
1441
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1025
1442
|
return;
|
|
1026
1443
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1027
1444
|
}
|
|
1028
1445
|
|
|
1446
|
+
// ../kit/src/cli.ts
|
|
1447
|
+
init_style();
|
|
1448
|
+
init_text2();
|
|
1449
|
+
|
|
1029
1450
|
// ../kit/src/usage.ts
|
|
1030
1451
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1031
1452
|
import { homedir as homedir3 } from "os";
|
|
1032
1453
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1033
|
-
import
|
|
1454
|
+
import process15 from "process";
|
|
1034
1455
|
|
|
1035
1456
|
// ../kit/src/logs.ts
|
|
1036
1457
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1044,14 +1465,14 @@ var usageError;
|
|
|
1044
1465
|
function noteUsageError(message) {
|
|
1045
1466
|
usageError = message;
|
|
1046
1467
|
}
|
|
1047
|
-
function stateHome(env =
|
|
1468
|
+
function stateHome(env = process15.env) {
|
|
1048
1469
|
const dir = env.XDG_STATE_HOME;
|
|
1049
1470
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1050
1471
|
}
|
|
1051
|
-
function usagePath(env =
|
|
1472
|
+
function usagePath(env = process15.env) {
|
|
1052
1473
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1053
1474
|
}
|
|
1054
|
-
function usageRecorded(env =
|
|
1475
|
+
function usageRecorded(env = process15.env) {
|
|
1055
1476
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1056
1477
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1057
1478
|
}
|
|
@@ -1065,7 +1486,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1065
1486
|
usageError = undefined;
|
|
1066
1487
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1067
1488
|
}
|
|
1068
|
-
function recordUsage(entry, env =
|
|
1489
|
+
function recordUsage(entry, env = process15.env) {
|
|
1069
1490
|
if (!usageRecorded(env))
|
|
1070
1491
|
return;
|
|
1071
1492
|
try {
|
|
@@ -1159,8 +1580,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1159
1580
|
`);
|
|
1160
1581
|
}
|
|
1161
1582
|
function printError(prefix, message, hint, cause) {
|
|
1162
|
-
const colors = paint(
|
|
1163
|
-
const styled = takesControlCodes(
|
|
1583
|
+
const colors = paint(process16.stderr);
|
|
1584
|
+
const styled = takesControlCodes(process16.stderr);
|
|
1164
1585
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1165
1586
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1166
1587
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1203,11 +1624,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1203
1624
|
}
|
|
1204
1625
|
}
|
|
1205
1626
|
if (name === undefined && level.path.length > 1) {
|
|
1206
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1627
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stderr));
|
|
1207
1628
|
return 2;
|
|
1208
1629
|
}
|
|
1209
1630
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1210
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1631
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stdout));
|
|
1211
1632
|
return 0;
|
|
1212
1633
|
}
|
|
1213
1634
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1353,6 +1774,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1353
1774
|
}
|
|
1354
1775
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1355
1776
|
const version = cli.version ?? packageVersion();
|
|
1777
|
+
const answered = await askpassClient(argv);
|
|
1778
|
+
if (answered !== undefined)
|
|
1779
|
+
return answered;
|
|
1356
1780
|
if (argv[0] === COMPLETE)
|
|
1357
1781
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1358
1782
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1383,38 +1807,21 @@ function commandPath(scope, argv) {
|
|
|
1383
1807
|
}
|
|
1384
1808
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1385
1809
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1401
|
-
}
|
|
1402
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1403
|
-
if (usage !== false) {
|
|
1404
|
-
try {
|
|
1405
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1406
|
-
} catch {}
|
|
1407
|
-
}
|
|
1408
|
-
return code;
|
|
1409
|
-
}
|
|
1410
|
-
// ../kit/src/folders.ts
|
|
1411
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1412
|
-
function ignoredFolders(extra = [], where = {}) {
|
|
1413
|
-
const configured = readUserConfig("config", where).ignore;
|
|
1414
|
-
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1415
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1416
|
-
}
|
|
1810
|
+
|
|
1811
|
+
// ../kit/src/index.ts
|
|
1812
|
+
init_config();
|
|
1813
|
+
|
|
1814
|
+
// ../kit/src/excerpt.ts
|
|
1815
|
+
init_text2();
|
|
1816
|
+
|
|
1817
|
+
// ../kit/src/index.ts
|
|
1818
|
+
init_folders();
|
|
1819
|
+
init_format();
|
|
1820
|
+
|
|
1821
|
+
// ../kit/src/git.ts
|
|
1822
|
+
init_args();
|
|
1417
1823
|
// ../kit/src/limit.ts
|
|
1824
|
+
init_args();
|
|
1418
1825
|
function limitOptions(fallback) {
|
|
1419
1826
|
return {
|
|
1420
1827
|
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
@@ -1435,21 +1842,46 @@ function capped(rows, limit) {
|
|
|
1435
1842
|
const more = rows.length - limit;
|
|
1436
1843
|
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1437
1844
|
}
|
|
1845
|
+
|
|
1846
|
+
// ../kit/src/index.ts
|
|
1847
|
+
init_mode();
|
|
1848
|
+
|
|
1849
|
+
// ../kit/src/report.ts
|
|
1850
|
+
init_style();
|
|
1851
|
+
init_text2();
|
|
1438
1852
|
// ../kit/src/secrets.ts
|
|
1439
1853
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1440
1854
|
// ../kit/src/sessions.ts
|
|
1441
1855
|
var {Glob } = globalThis.Bun;
|
|
1442
1856
|
var SESSION_FILES = new Glob("*.json");
|
|
1443
1857
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1858
|
+
|
|
1859
|
+
// ../kit/src/index.ts
|
|
1860
|
+
init_style();
|
|
1861
|
+
init_text2();
|
|
1862
|
+
init_theme();
|
|
1863
|
+
init_user_config();
|
|
1864
|
+
|
|
1865
|
+
// ../kit/src/watch.ts
|
|
1866
|
+
init_args();
|
|
1867
|
+
init_input();
|
|
1868
|
+
init_style();
|
|
1869
|
+
// ../kit/src/workspace-root.ts
|
|
1870
|
+
init_user_config();
|
|
1444
1871
|
// src/hotspots.ts
|
|
1445
1872
|
import { basename, join as join7 } from "path";
|
|
1446
|
-
import
|
|
1873
|
+
import process18 from "process";
|
|
1447
1874
|
|
|
1448
1875
|
// src/churn.ts
|
|
1876
|
+
import { availableParallelism } from "os";
|
|
1449
1877
|
var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|kay|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
|
|
1450
1878
|
var TESTS = /(?:^|\/)(?:tests?|__tests__|spec|e2e|__mocks__|fixtures)\/|\.(?:test|spec|bench)\.[^/]+$|(?:^|\/)test_[^/]+$|_test\.(?:go|py)$/;
|
|
1451
1879
|
var GENERATED = /(?:^|\/)(?:dist|build|out|generated|\.nuxt|\.output|\.next)\/|\.min\.[cm]?js$|\.d\.ts$|\.(?:generated|gen)\.[^/]+$|\.pb\.go$|\.snap$/;
|
|
1452
1880
|
var LEADING_NEWLINE = /^\n/;
|
|
1881
|
+
var COMMITS_PER_RUN = 500;
|
|
1882
|
+
var MOST_RUNS = Math.max(1, Math.min(4, Math.floor(availableParallelism() / 2)));
|
|
1883
|
+
var COMMIT_START = 1;
|
|
1884
|
+
var LOG_FORMAT = ["--no-renames", "--numstat", "--format=%x01%ct%x02%ae", "-z"];
|
|
1453
1885
|
var GENERATED_HEADER = /@generated|generated by|do not edit/i;
|
|
1454
1886
|
var DECISION = /\b(?:if|elif|elsif|for|foreach|while|until|case|when|catch|except|rescue|match|guard|and|or)\b|&&|\|\||\?\?|\s\?(?![,):.?])/g;
|
|
1455
1887
|
var COMMENT_OR_STRING = /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|^[ \t]*#[^\n]*)|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/gm;
|
|
@@ -1462,14 +1894,40 @@ function isGenerated(text) {
|
|
|
1462
1894
|
function complexityOf(text) {
|
|
1463
1895
|
return 1 + (text.replace(COMMENT_OR_STRING, (_, comment) => comment === undefined ? '""' : "").match(DECISION)?.length ?? 0);
|
|
1464
1896
|
}
|
|
1465
|
-
async function
|
|
1466
|
-
const
|
|
1467
|
-
|
|
1897
|
+
async function readLog(cwd, commits, onProgress) {
|
|
1898
|
+
const runs = Math.min(MOST_RUNS, Math.ceil(commits.length / COMMITS_PER_RUN));
|
|
1899
|
+
const size = Math.ceil(commits.length / runs);
|
|
1900
|
+
let read = 0;
|
|
1901
|
+
const logs = await Promise.all(Array.from({ length: runs }, async (_, run) => runCommand(["git", "log", "--no-walk=unsorted", "--stdin", ...LOG_FORMAT], {
|
|
1902
|
+
cwd,
|
|
1903
|
+
input: `${commits.slice(run * size, (run + 1) * size).join(`
|
|
1904
|
+
`)}
|
|
1905
|
+
`,
|
|
1906
|
+
onChunk: ({ stream, data }) => {
|
|
1907
|
+
if (stream !== "stdout" || onProgress === undefined)
|
|
1908
|
+
return;
|
|
1909
|
+
for (const byte of data) {
|
|
1910
|
+
if (byte === COMMIT_START)
|
|
1911
|
+
read++;
|
|
1912
|
+
}
|
|
1913
|
+
onProgress(read, commits.length);
|
|
1914
|
+
}
|
|
1915
|
+
})));
|
|
1916
|
+
return logs.some((log) => log.code !== 0) ? undefined : logs.map((log) => log.text).join("");
|
|
1917
|
+
}
|
|
1918
|
+
async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now(), onProgress }) {
|
|
1919
|
+
const [listed, top] = await Promise.all([runCommand(["git", "rev-list", `--since=${since}`, "HEAD"], { cwd }), runCommand(["git", "rev-parse", "--show-prefix"], { cwd })]);
|
|
1920
|
+
if (listed.code !== 0 || top.code !== 0)
|
|
1921
|
+
return;
|
|
1922
|
+
const commits = listed.text.split(`
|
|
1923
|
+
`).filter(Boolean);
|
|
1924
|
+
const log = commits.length === 0 ? "" : await readLog(cwd, commits, onProgress);
|
|
1925
|
+
if (log === undefined)
|
|
1468
1926
|
return;
|
|
1469
1927
|
const prefix = top.text.trim();
|
|
1470
1928
|
const churn = new Map;
|
|
1471
1929
|
const authors = new Map;
|
|
1472
|
-
for (const commit of log.
|
|
1930
|
+
for (const commit of log.split("\x01").slice(1)) {
|
|
1473
1931
|
const [head = "", ...entries] = commit.split("\x00");
|
|
1474
1932
|
const [stamp = "", author = ""] = head.split("\x02");
|
|
1475
1933
|
const all = entries.map((entry) => entry.replace(LEADING_NEWLINE, "")).filter((entry) => entry !== "").map((entry) => {
|
|
@@ -1589,7 +2047,7 @@ var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
|
|
|
1589
2047
|
var DAY_MS2 = 86400000;
|
|
1590
2048
|
var DEFAULT_HALF_LIFE = "90d";
|
|
1591
2049
|
var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
|
|
1592
|
-
var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
2050
|
+
var USAGE = `src hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1593
2051
|
|
|
1594
2052
|
Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. --by-lines scores the lines changed instead of the commits. Each file also shows how many lines changed, its author count ("solo" when one author wrote every change) and its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
|
|
1595
2053
|
|
|
@@ -1607,31 +2065,37 @@ var OPTIONS = {
|
|
|
1607
2065
|
var HOT = 0.66;
|
|
1608
2066
|
var WARM = 0.33;
|
|
1609
2067
|
async function hotspots(args) {
|
|
1610
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'hotspots src --since "3 months ago" --limit 10'] });
|
|
2068
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'src hotspots src --since "3 months ago" --limit 10'] });
|
|
1611
2069
|
if (positionals.length > 1)
|
|
1612
2070
|
badUsage("give one folder");
|
|
1613
2071
|
const count = limitOf(values, DEFAULT_COUNT);
|
|
1614
|
-
const cwd =
|
|
2072
|
+
const cwd = process18.cwd();
|
|
1615
2073
|
const bulk = Number(values.bulk ?? DEFAULT_BULK);
|
|
1616
2074
|
if (!Number.isInteger(bulk) || bulk < 1)
|
|
1617
2075
|
badUsage(`--bulk takes a number of files, not ${values.bulk}`);
|
|
1618
2076
|
const halfLifeMs = values["half-life"] === "0" ? 0 : duration(values["half-life"], "half-life", 90 * DAY_MS2);
|
|
1619
|
-
const
|
|
1620
|
-
if (churn === undefined)
|
|
1621
|
-
fail("not a git repository, churn comes from its log");
|
|
2077
|
+
const progress = progressLine();
|
|
1622
2078
|
const ranked = [];
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
2079
|
+
try {
|
|
2080
|
+
progress.update({ step: "reading the git log" });
|
|
2081
|
+
const churn = await churnSince(cwd, values.since ?? DEFAULT_SINCE, { bulk, halfLifeMs, onProgress: (done, total) => progress.update({ step: "reading the git log", done, total, unit: "commits" }) });
|
|
2082
|
+
if (churn === undefined)
|
|
2083
|
+
fail("not a git repository, churn comes from its log");
|
|
2084
|
+
const listed = (await listFiles(positionals[0] === undefined ? [] : [positionals[0]], cwd)).filter((path) => churn.has(path) && (values.all === true || isCandidate(path)));
|
|
2085
|
+
for (const [done, path] of listed.entries()) {
|
|
2086
|
+
progress.update({ step: "measuring the files", done, total: listed.length, unit: "files" });
|
|
2087
|
+
const touched = churn.get(path);
|
|
2088
|
+
const text = await readText(join7(cwd, path));
|
|
2089
|
+
if (text === undefined || values.all !== true && isGenerated(text))
|
|
2090
|
+
continue;
|
|
2091
|
+
const complexity = complexityOf(text);
|
|
2092
|
+
const worst = worstUnit(text, path);
|
|
2093
|
+
ranked.push({ path, score: Math.round(complexity * (values["by-lines"] === true ? touched.linesWeight : touched.weight)), churn: touched.commits, recent: Math.round(touched.weight * 10) / 10, changed: touched.lines, authors: touched.authors, solo: touched.authors === 1, complexity, worst: worst === undefined ? undefined : { name: worst.name, line: worst.line, complexity: worst.complexity }, lines: text.split(`
|
|
1633
2094
|
`).length - (text.endsWith(`
|
|
1634
2095
|
`) ? 1 : 0) });
|
|
2096
|
+
}
|
|
2097
|
+
} finally {
|
|
2098
|
+
progress.stop();
|
|
1635
2099
|
}
|
|
1636
2100
|
if (ranked.length === 0)
|
|
1637
2101
|
fail("no file with commits in that window", 1);
|
|
@@ -1642,8 +2106,8 @@ async function hotspots(args) {
|
|
|
1642
2106
|
printJson(shown);
|
|
1643
2107
|
return 0;
|
|
1644
2108
|
}
|
|
1645
|
-
const colors = paint(
|
|
1646
|
-
const path = role("path",
|
|
2109
|
+
const colors = paint(process18.stdout);
|
|
2110
|
+
const path = role("path", process18.stdout);
|
|
1647
2111
|
const top = shown.reduce((highest, row) => Math.max(highest, row.score), 0);
|
|
1648
2112
|
const heat = (score, text) => {
|
|
1649
2113
|
if (top > 0 && score >= top * HOT)
|
|
@@ -1651,7 +2115,7 @@ async function hotspots(args) {
|
|
|
1651
2115
|
return top > 0 && score >= top * WARM ? colors.yellow(text) : text;
|
|
1652
2116
|
};
|
|
1653
2117
|
printHeader("hotspots", `${basename(cwd)} \xB7 since ${values.since ?? DEFAULT_SINCE}`);
|
|
1654
|
-
console.log(table([["rank", "score", "churn", "recent", "changed", "authors", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.changed].map(String), row.solo ? colors.dim("1 solo") : String(row.authors), ...[row.complexity, row.lines].map(String), fileLink(path(row.path), row.path,
|
|
2118
|
+
console.log(table([["rank", "score", "churn", "recent", "changed", "authors", "complexity", "lines", "file", "most complex declaration"], ...shown.map((row) => [colors.dim(String(row.rank)), heat(row.score, String(row.score)), ...[row.churn, row.recent, row.changed].map(String), row.solo ? colors.dim("1 solo") : String(row.authors), ...[row.complexity, row.lines].map(String), fileLink(path(row.path), row.path, process18.stdout, cwd), row.worst === undefined ? "" : `${row.worst.name} (${row.worst.complexity}, line ${row.worst.line})`])], { header: true, align: ["right", "right", "right", "right", "right", "right", "right", "right", "left", "left"] }));
|
|
1655
2119
|
if (footer !== undefined)
|
|
1656
2120
|
console.log(footer);
|
|
1657
2121
|
return 0;
|
|
@@ -1660,7 +2124,8 @@ async function hotspots(args) {
|
|
|
1660
2124
|
// src/peek.ts
|
|
1661
2125
|
import { realpathSync as realpathSync3 } from "fs";
|
|
1662
2126
|
import { isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as resolve5, sep } from "path";
|
|
1663
|
-
import
|
|
2127
|
+
import process19 from "process";
|
|
2128
|
+
init_text();
|
|
1664
2129
|
|
|
1665
2130
|
// src/source.ts
|
|
1666
2131
|
var LOCATION = /^(?:\.\/)?([^\s:()]+)(?::(\d+)(?::\d+)?|\((\d+),\d+\))(?=[:\s)]|$)/;
|
|
@@ -1837,14 +2302,14 @@ function locations(text) {
|
|
|
1837
2302
|
}
|
|
1838
2303
|
|
|
1839
2304
|
// src/peek.ts
|
|
1840
|
-
var USAGE2 = `peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
|
|
2305
|
+
var USAGE2 = `src peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
|
|
1841
2306
|
|
|
1842
|
-
peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
|
|
1843
|
-
peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
|
|
1844
|
-
peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
|
|
1845
|
-
peek --outline <file>... the declarations and class members, a Markdown file's headings
|
|
1846
|
-
peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
|
|
1847
|
-
<output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
2307
|
+
src peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
|
|
2308
|
+
src peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
|
|
2309
|
+
src peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
|
|
2310
|
+
src peek --outline <file>... the declarations and class members, a Markdown file's headings
|
|
2311
|
+
src peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
|
|
2312
|
+
<output> | src peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1848
2313
|
The paths default to the files git keeps here (.gitignore holds).
|
|
1849
2314
|
--refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
|
|
1850
2315
|
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
|
|
@@ -1869,13 +2334,13 @@ function cut(text) {
|
|
|
1869
2334
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1870
2335
|
}
|
|
1871
2336
|
async function readableRoot() {
|
|
1872
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1873
|
-
return realpathSync3(ran.code === 0 ? ran.text.trim() :
|
|
2337
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process19.cwd() });
|
|
2338
|
+
return realpathSync3(ran.code === 0 ? ran.text.trim() : process19.cwd());
|
|
1874
2339
|
}
|
|
1875
2340
|
async function isOutside(path) {
|
|
1876
2341
|
let real;
|
|
1877
2342
|
try {
|
|
1878
|
-
real = realpathSync3(resolve5(
|
|
2343
|
+
real = realpathSync3(resolve5(process19.cwd(), path));
|
|
1879
2344
|
} catch {
|
|
1880
2345
|
return false;
|
|
1881
2346
|
}
|
|
@@ -1889,7 +2354,7 @@ async function checkInside(path) {
|
|
|
1889
2354
|
async function pipedSpans(text, context) {
|
|
1890
2355
|
const spans = [];
|
|
1891
2356
|
for (const [path, numbers] of locations(text)) {
|
|
1892
|
-
const source = await isOutside(path) ? undefined : await readText(resolve5(
|
|
2357
|
+
const source = await isOutside(path) ? undefined : await readText(resolve5(process19.cwd(), path));
|
|
1893
2358
|
if (source !== undefined)
|
|
1894
2359
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1895
2360
|
`).length, numbers, context));
|
|
@@ -1898,7 +2363,7 @@ async function pipedSpans(text, context) {
|
|
|
1898
2363
|
}
|
|
1899
2364
|
async function textOf(path) {
|
|
1900
2365
|
await checkInside(path);
|
|
1901
|
-
const text = await readText(resolve5(
|
|
2366
|
+
const text = await readText(resolve5(process19.cwd(), path));
|
|
1902
2367
|
if (text === undefined)
|
|
1903
2368
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1904
2369
|
return text;
|
|
@@ -1950,14 +2415,14 @@ async function spanOf(target) {
|
|
|
1950
2415
|
if (from < 1 || to < from)
|
|
1951
2416
|
badUsage(`${target}: a span reads <file>:<from>-<to>, from 1 and from <= to`);
|
|
1952
2417
|
if (from > count)
|
|
1953
|
-
fail(`${path} has ${
|
|
2418
|
+
fail(`${path} has ${bo(count, "line")}, ${target} starts past the end`, 1);
|
|
1954
2419
|
return { path, from, to: Math.min(to, count) };
|
|
1955
2420
|
}
|
|
1956
2421
|
async function* sources(paths) {
|
|
1957
2422
|
for (const path of paths)
|
|
1958
2423
|
await checkInside(path);
|
|
1959
|
-
for (const path of await listFiles(paths,
|
|
1960
|
-
const text = await readText(join8(
|
|
2424
|
+
for (const path of await listFiles(paths, process19.cwd())) {
|
|
2425
|
+
const text = await readText(join8(process19.cwd(), path));
|
|
1961
2426
|
if (text !== undefined)
|
|
1962
2427
|
yield { path, text };
|
|
1963
2428
|
}
|
|
@@ -1981,7 +2446,7 @@ async function definitionsOf(symbols, paths) {
|
|
|
1981
2446
|
return [...found.values()].flat();
|
|
1982
2447
|
}
|
|
1983
2448
|
async function peek(args) {
|
|
1984
|
-
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
2449
|
+
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["src peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["src peek --def parseArgs src", "a whole declaration"]] });
|
|
1985
2450
|
const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1986
2451
|
const json = values.json === true;
|
|
1987
2452
|
if (values["defs-first"] === true && values.refs === undefined)
|
|
@@ -2058,7 +2523,7 @@ async function peek(args) {
|
|
|
2058
2523
|
|
|
2059
2524
|
// src/todo-scan.ts
|
|
2060
2525
|
import { join as join9 } from "path";
|
|
2061
|
-
import
|
|
2526
|
+
import process20 from "process";
|
|
2062
2527
|
|
|
2063
2528
|
// src/todo.ts
|
|
2064
2529
|
var COMMENT = /(?<![:\w/])\/\/|\/\*|<!--|(?:^|\s)(?:#|--)(?=\s)|^\s*\*(?=\s|$)/;
|
|
@@ -2163,7 +2628,7 @@ async function lookUp(refs, cwd) {
|
|
|
2163
2628
|
}
|
|
2164
2629
|
|
|
2165
2630
|
// src/todo-scan.ts
|
|
2166
|
-
var USAGE3 = `todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
|
|
2631
|
+
var USAGE3 = `src todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
|
|
2167
2632
|
|
|
2168
2633
|
--older <duration> keeps only the comments whose line last changed longer ago than that (30d, 12w, 6m: git blame dates each one, a file git cannot blame is left out) and shows each one's age.
|
|
2169
2634
|
|
|
@@ -2186,8 +2651,8 @@ function printLines(lines, footer) {
|
|
|
2186
2651
|
`));
|
|
2187
2652
|
}
|
|
2188
2653
|
async function todoScan(args) {
|
|
2189
|
-
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, 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"]] });
|
|
2190
|
-
const cwd =
|
|
2654
|
+
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["src todo-scan src", ["src todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
2655
|
+
const cwd = process20.cwd();
|
|
2191
2656
|
const limit = limitOf(values, LIST_LIMIT);
|
|
2192
2657
|
const found = [];
|
|
2193
2658
|
for (const path of await listFiles(positionals, cwd)) {
|
|
@@ -2225,7 +2690,7 @@ async function todoScan(args) {
|
|
|
2225
2690
|
}
|
|
2226
2691
|
|
|
2227
2692
|
// src/cli.ts
|
|
2228
|
-
|
|
2693
|
+
process21.exitCode = await runCli({
|
|
2229
2694
|
name: "src",
|
|
2230
2695
|
about: "reads and ranks the source of a folder: line spans, TODO comments and the files worth splitting",
|
|
2231
2696
|
replaces: "sed -n N,Mp, grep -n chains and grep -rn TODO",
|