@kaynooo/cli-check 0.20.0 → 0.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -15
- package/dist/cli.js +521 -216
- package/dist/errs-cli.js +558 -189
- package/dist/j-cli.js +1612 -1251
- package/package.json +7 -9
- package/dist/fix-cli.js +0 -2135
package/dist/fix-cli.js
DELETED
|
@@ -1,2135 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
|
-
// @bun
|
|
3
|
-
|
|
4
|
-
// src/fix-cli.ts
|
|
5
|
-
import process22 from "process";
|
|
6
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process10 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 N = new Map;
|
|
15
|
-
var Nt = /\s+\S*$/;
|
|
16
|
-
var Y = /\s/;
|
|
17
|
-
function ko(t, e, r = "...") {
|
|
18
|
-
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
-
if (t.length <= e)
|
|
20
|
-
return t;
|
|
21
|
-
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
-
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
-
c = c.replace(Nt, "") || c;
|
|
24
|
-
if (o)
|
|
25
|
-
c = c.trimEnd();
|
|
26
|
-
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
-
}
|
|
28
|
-
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
29
|
-
var z = new Map;
|
|
30
|
-
|
|
31
|
-
// ../kit/src/mode.ts
|
|
32
|
-
import process2 from "process";
|
|
33
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
|
-
function isSet(value) {
|
|
36
|
-
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
|
-
}
|
|
38
|
-
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
39
|
-
const chosen = env.KIT_MODE;
|
|
40
|
-
if (chosen !== undefined && MODES.has(chosen))
|
|
41
|
-
return chosen;
|
|
42
|
-
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
43
|
-
return "agent";
|
|
44
|
-
if (stream.isTTY === true)
|
|
45
|
-
return "terminal";
|
|
46
|
-
return isSet(env.CI) ? "ci" : "pipe";
|
|
47
|
-
}
|
|
48
|
-
function isInteractive(streams = process2) {
|
|
49
|
-
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ../kit/src/style.ts
|
|
53
|
-
import process6 from "process";
|
|
54
|
-
|
|
55
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
56
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
57
|
-
function b(r) {
|
|
58
|
-
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
|
-
if (!G2.test(e))
|
|
60
|
-
return [0, 0, 0];
|
|
61
|
-
if (e.length === 3 || e.length === 4)
|
|
62
|
-
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
63
|
-
if (e.length !== 6 && e.length !== 8)
|
|
64
|
-
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
|
-
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
|
-
}
|
|
67
|
-
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") => {
|
|
68
|
-
let [l, n, c] = b(r);
|
|
69
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
70
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
71
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
72
|
-
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
|
-
if (e.FORCE_COLOR !== undefined)
|
|
74
|
-
return h.has(e.FORCE_COLOR);
|
|
75
|
-
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
76
|
-
return false;
|
|
77
|
-
return r?.isTTY === true;
|
|
78
|
-
}
|
|
79
|
-
function f(r, e = []) {
|
|
80
|
-
let l = "", n = "";
|
|
81
|
-
for (let t = 0, i = e.length;t < i; t++)
|
|
82
|
-
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
|
-
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
|
-
return new Proxy(c, { get(t, i) {
|
|
85
|
-
let a = B2[i];
|
|
86
|
-
if (Array.isArray(a)) {
|
|
87
|
-
let s = g.get(i);
|
|
88
|
-
if (s === undefined)
|
|
89
|
-
s = f(r, [...e, a]), g.set(i, s);
|
|
90
|
-
return s;
|
|
91
|
-
}
|
|
92
|
-
if (typeof a === "function")
|
|
93
|
-
return (...s) => {
|
|
94
|
-
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
95
|
-
if (u === undefined) {
|
|
96
|
-
if (g.size >= 64)
|
|
97
|
-
g.clear();
|
|
98
|
-
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
99
|
-
}
|
|
100
|
-
return u;
|
|
101
|
-
};
|
|
102
|
-
throw Error(`Unknown style: ${String(i)}`);
|
|
103
|
-
} });
|
|
104
|
-
}
|
|
105
|
-
function Fe(r = {}) {
|
|
106
|
-
return f(r);
|
|
107
|
-
}
|
|
108
|
-
var o = Fe();
|
|
109
|
-
|
|
110
|
-
// ../kit/src/theme.ts
|
|
111
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
112
|
-
import { homedir as homedir2 } from "os";
|
|
113
|
-
import { join as join3, resolve as resolve2 } from "path";
|
|
114
|
-
import process5 from "process";
|
|
115
|
-
|
|
116
|
-
// ../kit/src/config.ts
|
|
117
|
-
import { existsSync } from "fs";
|
|
118
|
-
import { dirname, join, resolve } from "path";
|
|
119
|
-
import process3 from "process";
|
|
120
|
-
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
121
|
-
const wanted = typeof names === "string" ? [names] : names;
|
|
122
|
-
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
123
|
-
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
124
|
-
if (found !== undefined)
|
|
125
|
-
return found;
|
|
126
|
-
if (stop(dir) || dirname(dir) === dir)
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ../kit/src/user-config.ts
|
|
132
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
133
|
-
import { homedir } from "os";
|
|
134
|
-
import { join as join2 } from "path";
|
|
135
|
-
import process4 from "process";
|
|
136
|
-
function configBase(where = {}) {
|
|
137
|
-
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
138
|
-
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
139
|
-
}
|
|
140
|
-
function userConfigPath(bin, where = {}) {
|
|
141
|
-
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
142
|
-
}
|
|
143
|
-
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
144
|
-
const current = userConfigPath(bin, where);
|
|
145
|
-
if (existsSync2(current))
|
|
146
|
-
return current;
|
|
147
|
-
const base = configBase(where);
|
|
148
|
-
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
149
|
-
}
|
|
150
|
-
function readUserConfig(bin, where = {}, legacy = []) {
|
|
151
|
-
const path = userConfigReadPath(bin, legacy, where);
|
|
152
|
-
if (!existsSync2(path))
|
|
153
|
-
return {};
|
|
154
|
-
try {
|
|
155
|
-
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
156
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
157
|
-
} catch {
|
|
158
|
-
return {};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// ../kit/src/theme.ts
|
|
163
|
-
var ENDS = new Map;
|
|
164
|
-
var DEFAULT = {
|
|
165
|
-
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" },
|
|
166
|
-
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" },
|
|
167
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
168
|
-
bins: {},
|
|
169
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
170
|
-
};
|
|
171
|
-
var 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" };
|
|
172
|
-
var 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" };
|
|
173
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
174
|
-
var PRESETS = {
|
|
175
|
-
default: {},
|
|
176
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
177
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
178
|
-
ascii: { glyphs: ASCII }
|
|
179
|
-
};
|
|
180
|
-
var 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"]);
|
|
181
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
182
|
-
var CONTROL = /\p{Cc}/u;
|
|
183
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
184
|
-
var SPACES = /\s+/;
|
|
185
|
-
function isColorSpec(spec) {
|
|
186
|
-
if (typeof spec === "number")
|
|
187
|
-
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
188
|
-
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
189
|
-
}
|
|
190
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
191
|
-
function cubeLevel(channel) {
|
|
192
|
-
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
193
|
-
}
|
|
194
|
-
function nearest256(hex) {
|
|
195
|
-
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
196
|
-
const levels = rgb.map(cubeLevel);
|
|
197
|
-
const cube = levels.map((level) => CUBE[level]);
|
|
198
|
-
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
199
|
-
const greyValue = 8 + grey * 10;
|
|
200
|
-
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
201
|
-
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
202
|
-
}
|
|
203
|
-
function hasTrueColor(env) {
|
|
204
|
-
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
205
|
-
}
|
|
206
|
-
function tinted(colors, spec, env = process5.env) {
|
|
207
|
-
if (typeof spec === "number")
|
|
208
|
-
return colors.ansi256(spec);
|
|
209
|
-
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
210
|
-
if (HEX.test(token))
|
|
211
|
-
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
212
|
-
return chain[token] ?? chain;
|
|
213
|
-
}, colors);
|
|
214
|
-
}
|
|
215
|
-
function isRecord(value) {
|
|
216
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
217
|
-
}
|
|
218
|
-
function readThemeFile(path, warn) {
|
|
219
|
-
try {
|
|
220
|
-
const stat = statSync(path, { throwIfNoEntry: false });
|
|
221
|
-
if (stat === undefined)
|
|
222
|
-
return;
|
|
223
|
-
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
224
|
-
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
228
|
-
if (isRecord(parsed))
|
|
229
|
-
return parsed;
|
|
230
|
-
warn(`${path} is not a JSON object, theme ignored`);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
function applyPreset(theme, name, warn, where) {
|
|
237
|
-
if (name === undefined)
|
|
238
|
-
return;
|
|
239
|
-
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
240
|
-
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const preset = PRESETS[name];
|
|
244
|
-
Object.assign(theme.colors, preset.colors);
|
|
245
|
-
Object.assign(theme.glyphs, preset.glyphs);
|
|
246
|
-
if (preset.accents !== undefined)
|
|
247
|
-
theme.accents = [...preset.accents];
|
|
248
|
-
if (Object.hasOwn(preset, "gradient"))
|
|
249
|
-
theme.gradient = preset.gradient;
|
|
250
|
-
return name;
|
|
251
|
-
}
|
|
252
|
-
function applyFile(theme, file, where, warn) {
|
|
253
|
-
if (isRecord(file.colors)) {
|
|
254
|
-
for (const [key, value] of Object.entries(file.colors)) {
|
|
255
|
-
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
256
|
-
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
257
|
-
else if (!isColorSpec(value))
|
|
258
|
-
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
259
|
-
else
|
|
260
|
-
theme.colors[key] = value;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (isRecord(file.glyphs)) {
|
|
264
|
-
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
265
|
-
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
266
|
-
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
267
|
-
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
268
|
-
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
269
|
-
else
|
|
270
|
-
theme.glyphs[key] = value;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
274
|
-
theme.accents = [...file.accents];
|
|
275
|
-
else if (file.accents !== undefined)
|
|
276
|
-
warn(`${where}: accents must be a non-empty list of colours`);
|
|
277
|
-
if (file.gradient === null)
|
|
278
|
-
theme.gradient = undefined;
|
|
279
|
-
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
280
|
-
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
281
|
-
else if (file.gradient !== undefined)
|
|
282
|
-
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
283
|
-
if (isRecord(file.bins)) {
|
|
284
|
-
for (const [bin, value] of Object.entries(file.bins)) {
|
|
285
|
-
if (isColorSpec(value))
|
|
286
|
-
theme.bins[bin] = value;
|
|
287
|
-
else
|
|
288
|
-
warn(`${where}: bin ${bin} has no valid colour`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function endsWalk(home) {
|
|
293
|
-
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
294
|
-
}
|
|
295
|
-
var warned = new Set;
|
|
296
|
-
function warnOnce(message) {
|
|
297
|
-
if (warned.has(message))
|
|
298
|
-
return;
|
|
299
|
-
warned.add(message);
|
|
300
|
-
console.error(`warning: theme ${message}`);
|
|
301
|
-
}
|
|
302
|
-
function isPath(chosen) {
|
|
303
|
-
return chosen.includes("/") || chosen.endsWith(".json");
|
|
304
|
-
}
|
|
305
|
-
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
306
|
-
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
307
|
-
const sources = [];
|
|
308
|
-
const chosen = env.KIT_THEME ?? "";
|
|
309
|
-
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
310
|
-
if (isPath(chosen))
|
|
311
|
-
wanted.push(resolve2(from, chosen));
|
|
312
|
-
const files = [];
|
|
313
|
-
for (const path of wanted) {
|
|
314
|
-
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
315
|
-
if (path !== undefined && file !== undefined)
|
|
316
|
-
files.push({ path, file });
|
|
317
|
-
}
|
|
318
|
-
let preset = "default";
|
|
319
|
-
if (chosen !== "" && !isPath(chosen)) {
|
|
320
|
-
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
321
|
-
} else {
|
|
322
|
-
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
323
|
-
if (named !== undefined)
|
|
324
|
-
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
325
|
-
}
|
|
326
|
-
for (const { path, file } of files) {
|
|
327
|
-
applyFile(theme, file, path, warn);
|
|
328
|
-
sources.push(path);
|
|
329
|
-
}
|
|
330
|
-
return { theme, sources, preset };
|
|
331
|
-
}
|
|
332
|
-
var current;
|
|
333
|
-
var currentKey = "";
|
|
334
|
-
function activeTheme() {
|
|
335
|
-
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
336
|
-
if (current === undefined || key !== currentKey) {
|
|
337
|
-
current = loadTheme();
|
|
338
|
-
currentKey = key;
|
|
339
|
-
}
|
|
340
|
-
return current;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// ../kit/src/style.ts
|
|
344
|
-
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
345
|
-
function takesControlCodes(stream, env = process6.env) {
|
|
346
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
347
|
-
}
|
|
348
|
-
function paint(stream, env = process6.env) {
|
|
349
|
-
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
350
|
-
}
|
|
351
|
-
function marked(mark, text, stream, detail, env = process6.env) {
|
|
352
|
-
const colors = paint(stream, env);
|
|
353
|
-
let head = MARK_WORDS[mark];
|
|
354
|
-
if (takesControlCodes(stream, env)) {
|
|
355
|
-
const { theme } = activeTheme();
|
|
356
|
-
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
357
|
-
}
|
|
358
|
-
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
359
|
-
}
|
|
360
|
-
function warn(text, detail) {
|
|
361
|
-
console.error(marked("warn", text, process6.stderr, detail));
|
|
362
|
-
}
|
|
363
|
-
function role(name, stream, env = process6.env) {
|
|
364
|
-
const colors = paint(stream, env);
|
|
365
|
-
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
366
|
-
}
|
|
367
|
-
var STATUS_WORDS = {
|
|
368
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
369
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
370
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
371
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
372
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
373
|
-
};
|
|
374
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
|
-
function header(bin, context, stream, env = process6.env) {
|
|
376
|
-
if (!takesControlCodes(stream, env))
|
|
377
|
-
return "";
|
|
378
|
-
const colors = paint(stream, env);
|
|
379
|
-
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
380
|
-
const { theme } = activeTheme();
|
|
381
|
-
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
382
|
-
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
383
|
-
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// ../kit/src/format.ts
|
|
387
|
-
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
388
|
-
function formatSeconds(total) {
|
|
389
|
-
let rest = Math.max(0, Math.round(total));
|
|
390
|
-
const amounts = UNITS.map(([unit, size]) => {
|
|
391
|
-
const amount = Math.floor(rest / size);
|
|
392
|
-
rest -= amount * size;
|
|
393
|
-
return `${amount}${unit}`;
|
|
394
|
-
});
|
|
395
|
-
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
396
|
-
if (first === -1)
|
|
397
|
-
return "0s";
|
|
398
|
-
const next = amounts[first + 1];
|
|
399
|
-
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
400
|
-
}
|
|
401
|
-
function formatDuration(ms) {
|
|
402
|
-
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
403
|
-
}
|
|
404
|
-
function upTo(text, separator) {
|
|
405
|
-
const end = text.indexOf(separator);
|
|
406
|
-
return end === -1 ? text : text.slice(0, end);
|
|
407
|
-
}
|
|
408
|
-
function truncate(text, width) {
|
|
409
|
-
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
410
|
-
}
|
|
411
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
412
|
-
var ESCAPE = String.fromCharCode(27);
|
|
413
|
-
function textWidth(text) {
|
|
414
|
-
return Bun.stringWidth(text);
|
|
415
|
-
}
|
|
416
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
417
|
-
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
418
|
-
if (outputMode(stream, env) === "agent")
|
|
419
|
-
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
420
|
-
`);
|
|
421
|
-
const widths = [];
|
|
422
|
-
for (const row of cells) {
|
|
423
|
-
for (const [index, cell] of row.entries())
|
|
424
|
-
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
425
|
-
}
|
|
426
|
-
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
427
|
-
const colors = paint(stream);
|
|
428
|
-
const lines = shown.map((row) => row.map((cell, index) => {
|
|
429
|
-
const width = widths[index] ?? 0;
|
|
430
|
-
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
431
|
-
if (align[index] === "right")
|
|
432
|
-
return `${gap}${cell}`;
|
|
433
|
-
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
434
|
-
}).join(" ").trimEnd());
|
|
435
|
-
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
436
|
-
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
437
|
-
`);
|
|
438
|
-
}
|
|
439
|
-
function narrow(rows, widths, limit) {
|
|
440
|
-
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
441
|
-
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
442
|
-
const floor = 8;
|
|
443
|
-
while (used() > limit) {
|
|
444
|
-
let widest = -1;
|
|
445
|
-
for (const [index, width] of widths.entries()) {
|
|
446
|
-
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
447
|
-
widest = index;
|
|
448
|
-
}
|
|
449
|
-
if (widest === -1)
|
|
450
|
-
break;
|
|
451
|
-
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
452
|
-
}
|
|
453
|
-
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
454
|
-
}
|
|
455
|
-
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
456
|
-
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
457
|
-
}
|
|
458
|
-
function printJson(value) {
|
|
459
|
-
console.log(jsonText(value));
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// ../kit/src/help.ts
|
|
463
|
-
import process8 from "process";
|
|
464
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
465
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
466
|
-
var FULL_STOP = /\.$/;
|
|
467
|
-
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
468
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
469
|
-
}
|
|
470
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
471
|
-
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
472
|
-
`);
|
|
473
|
-
}
|
|
474
|
-
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
475
|
-
if (exits.length === 0)
|
|
476
|
-
return [];
|
|
477
|
-
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
478
|
-
}
|
|
479
|
-
function wantsHelpJson(env = process8.env) {
|
|
480
|
-
return env.KIT_HELP === "json";
|
|
481
|
-
}
|
|
482
|
-
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
483
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
484
|
-
`);
|
|
485
|
-
const first = lines[0];
|
|
486
|
-
const colon = first.indexOf(": ");
|
|
487
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
488
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
489
|
-
return {
|
|
490
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
491
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
492
|
-
...replaces === undefined ? {} : { replaces },
|
|
493
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
494
|
-
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
495
|
-
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
499
|
-
if (examples.length === 0 || outputMode() === "agent")
|
|
500
|
-
return [];
|
|
501
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
502
|
-
}
|
|
503
|
-
var MAX_INLINE_CHOICES = 24;
|
|
504
|
-
function optionRows(options, colors = paint(process8.stdout)) {
|
|
505
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
506
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
507
|
-
const choices = option.choices?.join("|");
|
|
508
|
-
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
509
|
-
const named = inline ? `<${choices}>` : "<value>";
|
|
510
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
511
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
512
|
-
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
513
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
514
|
-
});
|
|
515
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
516
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// ../kit/src/text.ts
|
|
520
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
521
|
-
function stripAnsi(text) {
|
|
522
|
-
return text.replace(ANSI, "");
|
|
523
|
-
}
|
|
524
|
-
function distance(a, b) {
|
|
525
|
-
const left = [...a];
|
|
526
|
-
const right = [...b];
|
|
527
|
-
let before = [];
|
|
528
|
-
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
529
|
-
for (const [i, x] of left.entries()) {
|
|
530
|
-
const current = [i + 1];
|
|
531
|
-
for (const [j, y] of right.entries()) {
|
|
532
|
-
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
533
|
-
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
534
|
-
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
535
|
-
current.push(cost);
|
|
536
|
-
}
|
|
537
|
-
before = previous;
|
|
538
|
-
previous = current;
|
|
539
|
-
}
|
|
540
|
-
return previous[right.length] ?? 0;
|
|
541
|
-
}
|
|
542
|
-
function closest(name, names) {
|
|
543
|
-
const started = names.find((known) => known.startsWith(name));
|
|
544
|
-
if (started !== undefined)
|
|
545
|
-
return started;
|
|
546
|
-
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
547
|
-
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
548
|
-
}
|
|
549
|
-
// ../kit/src/input.ts
|
|
550
|
-
import process9 from "process";
|
|
551
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
552
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
553
|
-
function duration(value, name, fallback, unit = "s") {
|
|
554
|
-
if (value === undefined)
|
|
555
|
-
return fallback;
|
|
556
|
-
const match = DURATION.exec(value.trim());
|
|
557
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
558
|
-
if (ms < 1)
|
|
559
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
560
|
-
return ms;
|
|
561
|
-
}
|
|
562
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
563
|
-
if (path === "-") {
|
|
564
|
-
if (process9.stdin.isTTY)
|
|
565
|
-
fail(noStdin);
|
|
566
|
-
return Bun.stdin.text();
|
|
567
|
-
}
|
|
568
|
-
const file = Bun.file(path);
|
|
569
|
-
if (!await file.exists())
|
|
570
|
-
fail(`no file ${path}`);
|
|
571
|
-
return file.text();
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
// ../kit/src/args.ts
|
|
575
|
-
var DASHES = /^-+/;
|
|
576
|
-
function jsonOption(holds) {
|
|
577
|
-
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
578
|
-
}
|
|
579
|
-
class Exit extends Error {
|
|
580
|
-
code;
|
|
581
|
-
hint;
|
|
582
|
-
constructor(message, code, hint) {
|
|
583
|
-
super(message);
|
|
584
|
-
this.code = code;
|
|
585
|
-
this.hint = hint;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
function fail(message, code = 2, hint) {
|
|
589
|
-
throw new Exit(message, code, hint);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
class UsageError extends Exit {
|
|
593
|
-
constructor(message, hint) {
|
|
594
|
-
super(message, 2, hint);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
function badUsage(message) {
|
|
598
|
-
throw new UsageError(message);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
class HelpShown extends Exit {
|
|
602
|
-
constructor() {
|
|
603
|
-
super("help shown", 0);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
class Completing {
|
|
608
|
-
options;
|
|
609
|
-
positionals;
|
|
610
|
-
candidates;
|
|
611
|
-
constructor(options, positionals = [], candidates = {}) {
|
|
612
|
-
this.options = options;
|
|
613
|
-
this.positionals = positionals;
|
|
614
|
-
this.candidates = candidates;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
var completion = { active: false };
|
|
618
|
-
var OUTPUT_OPTIONS = {
|
|
619
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
620
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
621
|
-
};
|
|
622
|
-
function applyOutput(color, plain, env = process10.env) {
|
|
623
|
-
const when = plain === true ? "never" : color ?? "auto";
|
|
624
|
-
if (when === "auto")
|
|
625
|
-
return;
|
|
626
|
-
if (when !== "always" && when !== "never")
|
|
627
|
-
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
628
|
-
if (when === "always") {
|
|
629
|
-
env.FORCE_COLOR = "1";
|
|
630
|
-
delete env.NO_COLOR;
|
|
631
|
-
} else {
|
|
632
|
-
env.NO_COLOR = "1";
|
|
633
|
-
delete env.FORCE_COLOR;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
function parse(args, usage, options, settings = {}) {
|
|
637
|
-
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
638
|
-
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
639
|
-
const listing = listed(all, settings.allowNegative === true);
|
|
640
|
-
if (completion.active)
|
|
641
|
-
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
642
|
-
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
643
|
-
let parsed;
|
|
644
|
-
try {
|
|
645
|
-
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
646
|
-
} catch (error) {
|
|
647
|
-
const message = parseError(error);
|
|
648
|
-
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
649
|
-
}
|
|
650
|
-
const values = parsed.values;
|
|
651
|
-
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
652
|
-
if (values.help === true) {
|
|
653
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
654
|
-
throw new HelpShown;
|
|
655
|
-
}
|
|
656
|
-
checkChoices(parsed.values, all);
|
|
657
|
-
checkConflicts(parsed.values, all);
|
|
658
|
-
if (settings.positionals !== undefined)
|
|
659
|
-
checkPositionals(parsed.positionals, settings.positionals);
|
|
660
|
-
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
661
|
-
}
|
|
662
|
-
function splitRest(args, passes) {
|
|
663
|
-
const separator = passes ? args.indexOf("--") : -1;
|
|
664
|
-
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
665
|
-
}
|
|
666
|
-
function splitTrailing(args, options, count) {
|
|
667
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
668
|
-
let seen = 0;
|
|
669
|
-
if (count === 0)
|
|
670
|
-
return { own: args, rest: undefined };
|
|
671
|
-
for (let at = 0;at < args.length; at++) {
|
|
672
|
-
const word = args[at];
|
|
673
|
-
if (word === "--")
|
|
674
|
-
break;
|
|
675
|
-
if (word.startsWith("-")) {
|
|
676
|
-
if (takesValue(word))
|
|
677
|
-
at++;
|
|
678
|
-
continue;
|
|
679
|
-
}
|
|
680
|
-
seen++;
|
|
681
|
-
if (seen === count)
|
|
682
|
-
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
683
|
-
}
|
|
684
|
-
return { own: args, rest: undefined };
|
|
685
|
-
}
|
|
686
|
-
function listed(options, allowNegative) {
|
|
687
|
-
if (!allowNegative)
|
|
688
|
-
return options;
|
|
689
|
-
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
690
|
-
if (option.type !== "boolean" || option.negative === undefined)
|
|
691
|
-
return [[name, option]];
|
|
692
|
-
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
693
|
-
}));
|
|
694
|
-
}
|
|
695
|
-
function withAliases(args, options) {
|
|
696
|
-
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
697
|
-
if (named.size === 0)
|
|
698
|
-
return args;
|
|
699
|
-
const separator = args.indexOf("--");
|
|
700
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
701
|
-
return [...own.map((arg) => {
|
|
702
|
-
const at = arg.indexOf("=");
|
|
703
|
-
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
704
|
-
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
705
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
706
|
-
}
|
|
707
|
-
function withBare(args, options) {
|
|
708
|
-
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
709
|
-
if (bare.size === 0)
|
|
710
|
-
return args;
|
|
711
|
-
const separator = args.indexOf("--");
|
|
712
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
713
|
-
return [...own.flatMap((arg, index) => {
|
|
714
|
-
const optional = bare.get(arg);
|
|
715
|
-
const next = own[index + 1];
|
|
716
|
-
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
717
|
-
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
718
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
719
|
-
}
|
|
720
|
-
function checkConflicts(values, options) {
|
|
721
|
-
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
722
|
-
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
723
|
-
const other = given(name) ? conflicts.find(given) : undefined;
|
|
724
|
-
if (other !== undefined)
|
|
725
|
-
badUsage(`--${name} cannot be used with --${other}`);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
function checkChoices(values, options) {
|
|
729
|
-
for (const [name, option] of Object.entries(options)) {
|
|
730
|
-
if (option.choices === undefined)
|
|
731
|
-
continue;
|
|
732
|
-
const given = values[name];
|
|
733
|
-
for (const value of Array.isArray(given) ? given : [given]) {
|
|
734
|
-
if (typeof value === "string")
|
|
735
|
-
oneOf(value, name, option.choices);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
function oneOf(value, name, choices) {
|
|
740
|
-
if (!choices.includes(value))
|
|
741
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
742
|
-
return value;
|
|
743
|
-
}
|
|
744
|
-
function checkPositionals(given, names) {
|
|
745
|
-
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
746
|
-
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
747
|
-
if (given.length < required)
|
|
748
|
-
badUsage(`missing ${names[given.length]}`);
|
|
749
|
-
if (!variadic && given.length > names.length)
|
|
750
|
-
badUsage(`unexpected argument ${given[names.length]}`);
|
|
751
|
-
}
|
|
752
|
-
function joinDashValues(args, options) {
|
|
753
|
-
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
754
|
-
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
755
|
-
const joined = [];
|
|
756
|
-
for (let i = 0;i < args.length; i++) {
|
|
757
|
-
const arg = args[i] ?? "";
|
|
758
|
-
if (arg === "--")
|
|
759
|
-
return [...joined, ...args.slice(i)];
|
|
760
|
-
const name = longOf.get(arg);
|
|
761
|
-
const next = args[i + 1];
|
|
762
|
-
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
763
|
-
joined.push(`--${name}=${next}`);
|
|
764
|
-
i++;
|
|
765
|
-
} else {
|
|
766
|
-
joined.push(arg);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return joined;
|
|
770
|
-
}
|
|
771
|
-
function parseError(error) {
|
|
772
|
-
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
773
|
-
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
774
|
-
}
|
|
775
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
776
|
-
function nearestOption(message, options, allowNegative) {
|
|
777
|
-
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
778
|
-
if (typed === undefined)
|
|
779
|
-
return;
|
|
780
|
-
const word = typed.replace(DASHES, "");
|
|
781
|
-
if (word.length < 2 && !typed.startsWith("--"))
|
|
782
|
-
return;
|
|
783
|
-
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
784
|
-
...option.short === undefined ? [] : [`-${option.short}`],
|
|
785
|
-
`--${name}`,
|
|
786
|
-
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
787
|
-
]);
|
|
788
|
-
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
789
|
-
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
790
|
-
}
|
|
791
|
-
// ../kit/src/argv.ts
|
|
792
|
-
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
793
|
-
import { resolve as resolve3 } from "path";
|
|
794
|
-
import process11 from "process";
|
|
795
|
-
function commandLine() {
|
|
796
|
-
try {
|
|
797
|
-
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
798
|
-
} catch {
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
function realPath(word) {
|
|
803
|
-
try {
|
|
804
|
-
return realpathSync(resolve3(word));
|
|
805
|
-
} catch {
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
810
|
-
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
811
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
812
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
813
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
814
|
-
}
|
|
815
|
-
// ../kit/src/process.ts
|
|
816
|
-
import { constants } from "os";
|
|
817
|
-
import process12 from "process";
|
|
818
|
-
var KILL_GRACE_MS = 2000;
|
|
819
|
-
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
820
|
-
function exitCodeOf(code, signal) {
|
|
821
|
-
if (code !== null)
|
|
822
|
-
return code;
|
|
823
|
-
if (typeof signal === "number")
|
|
824
|
-
return 128 + signal;
|
|
825
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
826
|
-
}
|
|
827
|
-
function holdSignals(cleanup) {
|
|
828
|
-
let received;
|
|
829
|
-
let child;
|
|
830
|
-
const held = {
|
|
831
|
-
get signal() {
|
|
832
|
-
return received;
|
|
833
|
-
},
|
|
834
|
-
forward: (to) => {
|
|
835
|
-
child = to;
|
|
836
|
-
},
|
|
837
|
-
release: () => {
|
|
838
|
-
for (const signal of SIGNALS)
|
|
839
|
-
process12.off(signal, onSignal);
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
function onSignal(signal) {
|
|
843
|
-
received = signal;
|
|
844
|
-
if (child !== undefined) {
|
|
845
|
-
child.kill(signal);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
if (cleanup === undefined)
|
|
849
|
-
return;
|
|
850
|
-
held.release();
|
|
851
|
-
cleanup(signal);
|
|
852
|
-
process12.kill(process12.pid, signal);
|
|
853
|
-
}
|
|
854
|
-
for (const signal of SIGNALS)
|
|
855
|
-
process12.on(signal, onSignal);
|
|
856
|
-
return held;
|
|
857
|
-
}
|
|
858
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
859
|
-
const chunks = [];
|
|
860
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
861
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
862
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
863
|
-
const timers = [];
|
|
864
|
-
const killGroup = (killing) => {
|
|
865
|
-
if (state.done)
|
|
866
|
-
return;
|
|
867
|
-
try {
|
|
868
|
-
if (grouped)
|
|
869
|
-
process12.kill(-proc.pid, killing);
|
|
870
|
-
else
|
|
871
|
-
proc.kill(killing);
|
|
872
|
-
} catch {}
|
|
873
|
-
};
|
|
874
|
-
const stop = () => {
|
|
875
|
-
killGroup("SIGTERM");
|
|
876
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
877
|
-
};
|
|
878
|
-
const onAbort = () => stop();
|
|
879
|
-
if (timeoutMs !== undefined) {
|
|
880
|
-
timers.push(setTimeout(() => {
|
|
881
|
-
state.timedOut = true;
|
|
882
|
-
stop();
|
|
883
|
-
}, timeoutMs));
|
|
884
|
-
}
|
|
885
|
-
if (signal?.aborted === true)
|
|
886
|
-
onAbort();
|
|
887
|
-
else
|
|
888
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
889
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
890
|
-
const drain = async (stream, name) => {
|
|
891
|
-
for await (const data of stream) {
|
|
892
|
-
if (state.failure !== undefined)
|
|
893
|
-
continue;
|
|
894
|
-
try {
|
|
895
|
-
onChunk?.({ stream: name, data });
|
|
896
|
-
} catch (error) {
|
|
897
|
-
state.failure = error;
|
|
898
|
-
stop();
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
if (state.kept + data.length > maxBytes) {
|
|
902
|
-
state.truncated = true;
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
state.kept += data.length;
|
|
906
|
-
chunks.push({ stream: name, data });
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
try {
|
|
910
|
-
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
911
|
-
await proc.exited;
|
|
912
|
-
} finally {
|
|
913
|
-
state.done = true;
|
|
914
|
-
for (const timer of timers)
|
|
915
|
-
clearTimeout(timer);
|
|
916
|
-
signal?.removeEventListener("abort", onAbort);
|
|
917
|
-
}
|
|
918
|
-
if (state.failure !== undefined)
|
|
919
|
-
throw state.failure;
|
|
920
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
921
|
-
let output;
|
|
922
|
-
let text;
|
|
923
|
-
return {
|
|
924
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
925
|
-
chunks,
|
|
926
|
-
timedOut: state.timedOut,
|
|
927
|
-
truncated: state.truncated,
|
|
928
|
-
get output() {
|
|
929
|
-
return output ??= joined();
|
|
930
|
-
},
|
|
931
|
-
get text() {
|
|
932
|
-
return text ??= (output ??= joined()).toString();
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
// ../kit/src/progress.ts
|
|
938
|
-
var ESC = String.fromCharCode(27);
|
|
939
|
-
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
940
|
-
var RESET_STYLE = `${ESC}[0m`;
|
|
941
|
-
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
942
|
-
// ../kit/src/cli.ts
|
|
943
|
-
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
944
|
-
import { dirname as dirname3, join as join6 } from "path";
|
|
945
|
-
import process16 from "process";
|
|
946
|
-
|
|
947
|
-
// ../kit/src/notify.ts
|
|
948
|
-
import process13 from "process";
|
|
949
|
-
var NOTIFY_AFTER_MS = 1e4;
|
|
950
|
-
var CANCELLED = 130;
|
|
951
|
-
function base64(text) {
|
|
952
|
-
return Buffer.from(text).toString("base64");
|
|
953
|
-
}
|
|
954
|
-
function notification(title, body, env = process13.env) {
|
|
955
|
-
const id = `kit${process13.pid}`;
|
|
956
|
-
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\\`];
|
|
957
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
958
|
-
}
|
|
959
|
-
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
960
|
-
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
961
|
-
return;
|
|
962
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
// ../kit/src/usage.ts
|
|
966
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
967
|
-
import { homedir as homedir4 } from "os";
|
|
968
|
-
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
969
|
-
import process15 from "process";
|
|
970
|
-
|
|
971
|
-
// ../kit/src/logs.ts
|
|
972
|
-
import { lstatSync, openSync } from "fs";
|
|
973
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
974
|
-
import { homedir as homedir3, tmpdir } from "os";
|
|
975
|
-
import { join as join4 } from "path";
|
|
976
|
-
import process14 from "process";
|
|
977
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
978
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
979
|
-
function isPrivateDirectory(path) {
|
|
980
|
-
try {
|
|
981
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
982
|
-
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
983
|
-
} catch {
|
|
984
|
-
return false;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
async function privateLogDirectory(name, env = process14.env) {
|
|
988
|
-
const runtime = env.XDG_RUNTIME_DIR;
|
|
989
|
-
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
990
|
-
const path = join4(base, name);
|
|
991
|
-
try {
|
|
992
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
993
|
-
if (isPrivateDirectory(path))
|
|
994
|
-
return path;
|
|
995
|
-
} catch {}
|
|
996
|
-
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
997
|
-
}
|
|
998
|
-
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
999
|
-
let names;
|
|
1000
|
-
try {
|
|
1001
|
-
names = await readdir(dir);
|
|
1002
|
-
} catch {
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
for (const name of names) {
|
|
1006
|
-
const path = join4(dir, name);
|
|
1007
|
-
try {
|
|
1008
|
-
const info = await stat(path);
|
|
1009
|
-
if (info.isDirectory())
|
|
1010
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
1011
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
1012
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1013
|
-
} catch {
|
|
1014
|
-
continue;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// ../kit/src/usage.ts
|
|
1020
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1021
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1022
|
-
var LONGEST_NAME = 40;
|
|
1023
|
-
var usageError;
|
|
1024
|
-
function noteUsageError(message) {
|
|
1025
|
-
usageError = message;
|
|
1026
|
-
}
|
|
1027
|
-
function stateHome(env = process15.env) {
|
|
1028
|
-
const dir = env.XDG_STATE_HOME;
|
|
1029
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1030
|
-
}
|
|
1031
|
-
function usagePath(env = process15.env) {
|
|
1032
|
-
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1033
|
-
}
|
|
1034
|
-
function usageRecorded(env = process15.env) {
|
|
1035
|
-
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1036
|
-
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1037
|
-
}
|
|
1038
|
-
function flagNames(argv) {
|
|
1039
|
-
const end = argv.indexOf("--");
|
|
1040
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1041
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1042
|
-
}
|
|
1043
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1044
|
-
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1045
|
-
usageError = undefined;
|
|
1046
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1047
|
-
}
|
|
1048
|
-
function recordUsage(entry, env = process15.env) {
|
|
1049
|
-
if (!usageRecorded(env))
|
|
1050
|
-
return;
|
|
1051
|
-
try {
|
|
1052
|
-
const path = usagePath(env);
|
|
1053
|
-
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1054
|
-
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1055
|
-
`, { mode: 384 });
|
|
1056
|
-
} catch {}
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// ../kit/src/cli.ts
|
|
1060
|
-
var LEVEL_OPTIONS = {
|
|
1061
|
-
...OUTPUT_OPTIONS,
|
|
1062
|
-
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1063
|
-
};
|
|
1064
|
-
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1065
|
-
function printError(prefix, message, hint, cause) {
|
|
1066
|
-
const colors = paint(process16.stderr);
|
|
1067
|
-
const styled = takesControlCodes(process16.stderr);
|
|
1068
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1069
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1070
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1071
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1072
|
-
}
|
|
1073
|
-
function printJsonError(message, hint, cause) {
|
|
1074
|
-
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1075
|
-
}
|
|
1076
|
-
function wantsJson(argv) {
|
|
1077
|
-
const end = argv.indexOf("--");
|
|
1078
|
-
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1079
|
-
}
|
|
1080
|
-
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1081
|
-
if (error instanceof HelpShown)
|
|
1082
|
-
return 0;
|
|
1083
|
-
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1084
|
-
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1085
|
-
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1086
|
-
if (error instanceof Exit && error.code === 2)
|
|
1087
|
-
noteUsageError(error.message);
|
|
1088
|
-
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1089
|
-
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1090
|
-
return error instanceof Exit ? error.code : 1;
|
|
1091
|
-
}
|
|
1092
|
-
var COMPLETE = "__complete";
|
|
1093
|
-
var FILES = "__files__";
|
|
1094
|
-
async function completingOf(run) {
|
|
1095
|
-
completion.active = true;
|
|
1096
|
-
try {
|
|
1097
|
-
await run([]);
|
|
1098
|
-
} catch (error) {
|
|
1099
|
-
if (error instanceof Completing)
|
|
1100
|
-
return error;
|
|
1101
|
-
} finally {
|
|
1102
|
-
completion.active = false;
|
|
1103
|
-
}
|
|
1104
|
-
return new Completing({});
|
|
1105
|
-
}
|
|
1106
|
-
function candidateLine(candidate) {
|
|
1107
|
-
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1108
|
-
}
|
|
1109
|
-
function positionalBeingTyped(before, { options, positionals }) {
|
|
1110
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1111
|
-
const typed = [];
|
|
1112
|
-
let at = 0;
|
|
1113
|
-
while (at < before.length) {
|
|
1114
|
-
const word = before[at];
|
|
1115
|
-
if (word === "--") {
|
|
1116
|
-
typed.push(...before.slice(at + 1));
|
|
1117
|
-
break;
|
|
1118
|
-
}
|
|
1119
|
-
if (!word.startsWith("-"))
|
|
1120
|
-
typed.push(word);
|
|
1121
|
-
else if (takesValue(word))
|
|
1122
|
-
at++;
|
|
1123
|
-
at++;
|
|
1124
|
-
}
|
|
1125
|
-
const last = positionals.at(-1);
|
|
1126
|
-
if (typed.length < positionals.length)
|
|
1127
|
-
return { name: positionals[typed.length], typed };
|
|
1128
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1129
|
-
}
|
|
1130
|
-
async function leafCandidates(run, words) {
|
|
1131
|
-
const completing = await completingOf(run);
|
|
1132
|
-
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1133
|
-
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1134
|
-
const flag = words.at(-2);
|
|
1135
|
-
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1136
|
-
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1137
|
-
if (option?.type === "string") {
|
|
1138
|
-
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1139
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1140
|
-
}
|
|
1141
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1142
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1143
|
-
}
|
|
1144
|
-
async function printCandidates(found) {
|
|
1145
|
-
for (const line of await found)
|
|
1146
|
-
console.log(line);
|
|
1147
|
-
return 0;
|
|
1148
|
-
}
|
|
1149
|
-
function packageVersion(entry = Bun.main) {
|
|
1150
|
-
let resolved = entry;
|
|
1151
|
-
try {
|
|
1152
|
-
resolved = realpathSync2(entry);
|
|
1153
|
-
} catch {}
|
|
1154
|
-
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1155
|
-
try {
|
|
1156
|
-
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
1157
|
-
if (typeof version === "string")
|
|
1158
|
-
return version;
|
|
1159
|
-
} catch {}
|
|
1160
|
-
if (dirname3(dir) === dir)
|
|
1161
|
-
return "0.0.0";
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1165
|
-
if (argv[0] === COMPLETE)
|
|
1166
|
-
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1167
|
-
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1168
|
-
console.log(version ?? packageVersion());
|
|
1169
|
-
return 0;
|
|
1170
|
-
}
|
|
1171
|
-
let code;
|
|
1172
|
-
const started = performance.now();
|
|
1173
|
-
try {
|
|
1174
|
-
code = await run(argv);
|
|
1175
|
-
} catch (error) {
|
|
1176
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1177
|
-
}
|
|
1178
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1179
|
-
if (usage !== false) {
|
|
1180
|
-
try {
|
|
1181
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1182
|
-
} catch {}
|
|
1183
|
-
}
|
|
1184
|
-
return code;
|
|
1185
|
-
}
|
|
1186
|
-
// ../kit/src/excerpt.ts
|
|
1187
|
-
var BASH_ECHO = /^\$ /;
|
|
1188
|
-
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1189
|
-
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
1190
|
-
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
1191
|
-
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
1192
|
-
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
1193
|
-
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1194
|
-
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
1195
|
-
var TSC_ERROR = /\berror TS\d+/;
|
|
1196
|
-
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
1197
|
-
var TSC_FRAME = /^\s*[~^|]/;
|
|
1198
|
-
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
1199
|
-
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
1200
|
-
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
1201
|
-
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
1202
|
-
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
1203
|
-
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
1204
|
-
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
1205
|
-
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
1206
|
-
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
1207
|
-
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
1208
|
-
var MAX_TESTS = 10;
|
|
1209
|
-
var MAX_LINES = 100;
|
|
1210
|
-
var TAIL = 30;
|
|
1211
|
-
var bunTest = (lines) => {
|
|
1212
|
-
const seen = new Set;
|
|
1213
|
-
const blocks = [];
|
|
1214
|
-
for (const [index, line] of lines.entries()) {
|
|
1215
|
-
const name = line.replace(DURATION2, "");
|
|
1216
|
-
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
1217
|
-
continue;
|
|
1218
|
-
seen.add(name);
|
|
1219
|
-
if (blocks.length < MAX_TESTS)
|
|
1220
|
-
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
1221
|
-
`).trim());
|
|
1222
|
-
}
|
|
1223
|
-
if (blocks.length === 0)
|
|
1224
|
-
return;
|
|
1225
|
-
if (seen.size > MAX_TESTS)
|
|
1226
|
-
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1227
|
-
return [...blocks.join(`
|
|
1228
|
-
|
|
1229
|
-
`).split(`
|
|
1230
|
-
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
1231
|
-
};
|
|
1232
|
-
var bunCheck = (lines) => {
|
|
1233
|
-
const text = lines.join(`
|
|
1234
|
-
`);
|
|
1235
|
-
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
1236
|
-
if (blocks === null)
|
|
1237
|
-
return;
|
|
1238
|
-
const errors = blocks.map((block) => {
|
|
1239
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1240
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1241
|
-
});
|
|
1242
|
-
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
1243
|
-
};
|
|
1244
|
-
function bunCheckFields(block) {
|
|
1245
|
-
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
1246
|
-
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
1247
|
-
return {
|
|
1248
|
-
file: attributes.file ?? "",
|
|
1249
|
-
line: attributes.line ?? "",
|
|
1250
|
-
column: attributes.column ?? "",
|
|
1251
|
-
code: attributes.code ?? "",
|
|
1252
|
-
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
1253
|
-
`).slice(1, -1).join(`
|
|
1254
|
-
`).trim()
|
|
1255
|
-
};
|
|
1256
|
-
}
|
|
1257
|
-
var tsc = (lines) => {
|
|
1258
|
-
const kept = [];
|
|
1259
|
-
let inError = false;
|
|
1260
|
-
for (const line of lines) {
|
|
1261
|
-
if (TSC_ERROR.test(line)) {
|
|
1262
|
-
inError = true;
|
|
1263
|
-
kept.push(line);
|
|
1264
|
-
} else if (TSC_SUMMARY.test(line)) {
|
|
1265
|
-
inError = false;
|
|
1266
|
-
kept.push(line);
|
|
1267
|
-
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
1268
|
-
kept.push(line);
|
|
1269
|
-
} else {
|
|
1270
|
-
inError = false;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
1274
|
-
};
|
|
1275
|
-
var eslint = (lines) => {
|
|
1276
|
-
const kept = [];
|
|
1277
|
-
let file = "";
|
|
1278
|
-
let shown = "";
|
|
1279
|
-
for (const line of lines) {
|
|
1280
|
-
if (ESLINT_PROBLEM.test(line)) {
|
|
1281
|
-
if (file !== shown) {
|
|
1282
|
-
kept.push(file);
|
|
1283
|
-
shown = file;
|
|
1284
|
-
}
|
|
1285
|
-
kept.push(line);
|
|
1286
|
-
} else if (ESLINT_SUMMARY.test(line)) {
|
|
1287
|
-
kept.push(line);
|
|
1288
|
-
} else if (line.trim() !== "") {
|
|
1289
|
-
file = line;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
1293
|
-
};
|
|
1294
|
-
var phpstan = (lines) => {
|
|
1295
|
-
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
1296
|
-
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
1297
|
-
};
|
|
1298
|
-
var php = (lines) => {
|
|
1299
|
-
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
1300
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1301
|
-
};
|
|
1302
|
-
var vitest = (lines) => {
|
|
1303
|
-
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
1304
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1305
|
-
};
|
|
1306
|
-
var playwright = (lines) => {
|
|
1307
|
-
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
1308
|
-
return start === -1 ? undefined : lines.slice(start);
|
|
1309
|
-
};
|
|
1310
|
-
var phpCsFixer = (lines) => {
|
|
1311
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1312
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1313
|
-
};
|
|
1314
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1315
|
-
function squeeze(lines) {
|
|
1316
|
-
const out = [];
|
|
1317
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1318
|
-
if (line !== "" || out.at(-1) !== "")
|
|
1319
|
-
out.push(line);
|
|
1320
|
-
}
|
|
1321
|
-
while (out.at(-1) === "")
|
|
1322
|
-
out.pop();
|
|
1323
|
-
return out;
|
|
1324
|
-
}
|
|
1325
|
-
function cut(shown) {
|
|
1326
|
-
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
1327
|
-
`) : shown.join(`
|
|
1328
|
-
`);
|
|
1329
|
-
}
|
|
1330
|
-
function recognised(lines, parsers) {
|
|
1331
|
-
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
1332
|
-
}
|
|
1333
|
-
function failureExcerpt(output) {
|
|
1334
|
-
const lines = stripAnsi(output).split(`
|
|
1335
|
-
`);
|
|
1336
|
-
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
1337
|
-
lines.shift();
|
|
1338
|
-
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1339
|
-
}
|
|
1340
|
-
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
1341
|
-
// ../kit/src/folders.ts
|
|
1342
|
-
import { homedir as homedir5 } from "os";
|
|
1343
|
-
import { join as join7 } from "path";
|
|
1344
|
-
import process17 from "process";
|
|
1345
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1346
|
-
function ignoredFolders(extra = [], where = {}) {
|
|
1347
|
-
const configured = readUserConfig("config", where).ignore;
|
|
1348
|
-
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1349
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1350
|
-
}
|
|
1351
|
-
function cacheFolder({ home = homedir5(), env = process17.env } = {}) {
|
|
1352
|
-
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
1353
|
-
}
|
|
1354
|
-
// ../kit/src/secrets.ts
|
|
1355
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1356
|
-
// ../kit/src/sessions.ts
|
|
1357
|
-
var {Glob } = globalThis.Bun;
|
|
1358
|
-
var SESSION_FILES = new Glob("*.json");
|
|
1359
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1360
|
-
// package.json
|
|
1361
|
-
var version = "0.20.0";
|
|
1362
|
-
|
|
1363
|
-
// src/fix.ts
|
|
1364
|
-
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1365
|
-
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1366
|
-
import { join as join12 } from "path";
|
|
1367
|
-
import process21 from "process";
|
|
1368
|
-
|
|
1369
|
-
// src/changes.ts
|
|
1370
|
-
import { stat as stat2 } from "fs/promises";
|
|
1371
|
-
import { join as join8 } from "path";
|
|
1372
|
-
var {$ } = globalThis.Bun;
|
|
1373
|
-
async function dirtyFiles(dir) {
|
|
1374
|
-
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
1375
|
-
if (listed.exitCode !== 0)
|
|
1376
|
-
return;
|
|
1377
|
-
const files = new Map;
|
|
1378
|
-
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1379
|
-
try {
|
|
1380
|
-
const { size, mtimeMs } = await stat2(join8(dir, path));
|
|
1381
|
-
files.set(path, `${size}:${mtimeMs}`);
|
|
1382
|
-
} catch {
|
|
1383
|
-
files.set(path, "");
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
return files;
|
|
1387
|
-
}
|
|
1388
|
-
function changedFiles(before, after) {
|
|
1389
|
-
return [...after].filter(([path, hash]) => before.get(path) !== hash).map(([path]) => path);
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
// src/compose.ts
|
|
1393
|
-
import { existsSync as existsSync4 } from "fs";
|
|
1394
|
-
import { homedir as homedir6 } from "os";
|
|
1395
|
-
import { basename, dirname as dirname4, join as join9, relative, resolve as resolve4 } from "path";
|
|
1396
|
-
import process19 from "process";
|
|
1397
|
-
|
|
1398
|
-
// ../kit/src/shell.ts
|
|
1399
|
-
var SEPARATORS = new Set([`
|
|
1400
|
-
`, ";", "|"]);
|
|
1401
|
-
var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
|
|
1402
|
-
var GLOB_CHARS = new Set(["*", "?", "["]);
|
|
1403
|
-
var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
1404
|
-
var SAFE_WORD = /^[\w@%+=:,./-]+$/;
|
|
1405
|
-
var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
1406
|
-
var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
1407
|
-
var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
|
|
1408
|
-
var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
|
|
1409
|
-
var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
|
|
1410
|
-
var POWERSHELL = new Set(["pwsh", "powershell"]);
|
|
1411
|
-
var SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
1412
|
-
var FISH_VALUE_OPTIONS = new Set(["-C", "--init-command"]);
|
|
1413
|
-
var PRINTERS = new Set(["echo", "printf"]);
|
|
1414
|
-
var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
1415
|
-
function wrapper(short = "", long = [], operands = 0, runsString = false) {
|
|
1416
|
-
return { short, long, operands, runsString };
|
|
1417
|
-
}
|
|
1418
|
-
var WRAPPERS = new Map([
|
|
1419
|
-
["command", wrapper()],
|
|
1420
|
-
["builtin", wrapper()],
|
|
1421
|
-
["nohup", wrapper()],
|
|
1422
|
-
["setsid", wrapper()],
|
|
1423
|
-
["busybox", wrapper()],
|
|
1424
|
-
["exec", wrapper("a")],
|
|
1425
|
-
["time", wrapper("fo", ["--format", "--output"])],
|
|
1426
|
-
["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
|
|
1427
|
-
["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
|
|
1428
|
-
["doas", wrapper("uC")],
|
|
1429
|
-
["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
|
|
1430
|
-
["nice", wrapper("n", ["--adjustment"])],
|
|
1431
|
-
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
1432
|
-
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
1433
|
-
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
1434
|
-
["watch", wrapper("n", ["--interval"], 0, true)],
|
|
1435
|
-
["flock", wrapper("wE", ["--timeout", "--conflict-exit-code"], 1)],
|
|
1436
|
-
["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
|
|
1437
|
-
["unbuffer", wrapper()],
|
|
1438
|
-
["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
|
|
1439
|
-
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
|
|
1440
|
-
]);
|
|
1441
|
-
function shellQuote(word) {
|
|
1442
|
-
return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
// src/compose.ts
|
|
1446
|
-
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1447
|
-
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1448
|
-
var PS_TIMEOUT_MS = 20000;
|
|
1449
|
-
var VARIABLE = /\$\{(\w+)(?::?-([^${}]*))?\}|\$(\w+)/g;
|
|
1450
|
-
var ENV_LINE = /^\s*(?:export\s+)?(\w+)=(.*)$/;
|
|
1451
|
-
var QUOTED = /^(['"])(.*)\1$/;
|
|
1452
|
-
var TOOL_WORDS = {
|
|
1453
|
-
bun: ["bun"],
|
|
1454
|
-
bunx: ["bun"],
|
|
1455
|
-
node: ["node", "bun"],
|
|
1456
|
-
npm: ["node", "bun"],
|
|
1457
|
-
npx: ["node", "bun"],
|
|
1458
|
-
pnpm: ["node", "bun"],
|
|
1459
|
-
yarn: ["node", "bun"],
|
|
1460
|
-
composer: ["php"],
|
|
1461
|
-
php: ["php"],
|
|
1462
|
-
phpunit: ["php"],
|
|
1463
|
-
phpstan: ["php"],
|
|
1464
|
-
paratest: ["php"],
|
|
1465
|
-
pest: ["php"],
|
|
1466
|
-
symfony: ["php"]
|
|
1467
|
-
};
|
|
1468
|
-
function toolWords(program) {
|
|
1469
|
-
const name = basename(program);
|
|
1470
|
-
return TOOL_WORDS[name] ?? (program.includes("vendor/bin/") ? ["php"] : []);
|
|
1471
|
-
}
|
|
1472
|
-
async function readFiles(dir, names) {
|
|
1473
|
-
for (const name of names) {
|
|
1474
|
-
const handle = Bun.file(join9(dir, name));
|
|
1475
|
-
if (await handle.exists())
|
|
1476
|
-
return { name, text: await handle.text() };
|
|
1477
|
-
}
|
|
1478
|
-
return;
|
|
1479
|
-
}
|
|
1480
|
-
async function variables(composeDir) {
|
|
1481
|
-
const env = {};
|
|
1482
|
-
const text = (await readFiles(composeDir, [".env"]))?.text ?? "";
|
|
1483
|
-
for (const line of text.split(`
|
|
1484
|
-
`)) {
|
|
1485
|
-
const match = ENV_LINE.exec(line);
|
|
1486
|
-
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1487
|
-
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1488
|
-
}
|
|
1489
|
-
for (const [key, value] of Object.entries(process19.env)) {
|
|
1490
|
-
if (value !== undefined)
|
|
1491
|
-
env[key] = value;
|
|
1492
|
-
}
|
|
1493
|
-
env.PWD = composeDir;
|
|
1494
|
-
return env;
|
|
1495
|
-
}
|
|
1496
|
-
function interpolate(text, env) {
|
|
1497
|
-
let current = text;
|
|
1498
|
-
for (let round = 0;round < 4 && current.includes("$"); round++) {
|
|
1499
|
-
current = current.replaceAll(VARIABLE, (_, braced, fallback, bare) => {
|
|
1500
|
-
const value = env[braced ?? bare ?? ""];
|
|
1501
|
-
return value !== undefined && value !== "" ? value : fallback ?? "";
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
return current;
|
|
1505
|
-
}
|
|
1506
|
-
function bindSource(source, composeDir, env) {
|
|
1507
|
-
const path = interpolate(source, env);
|
|
1508
|
-
if (path.startsWith("~"))
|
|
1509
|
-
return join9(homedir6(), path.slice(1));
|
|
1510
|
-
if (path.startsWith("/"))
|
|
1511
|
-
return resolve4(path);
|
|
1512
|
-
return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
|
|
1513
|
-
}
|
|
1514
|
-
function mountsOf(volumes, composeDir, env) {
|
|
1515
|
-
if (!Array.isArray(volumes))
|
|
1516
|
-
return [];
|
|
1517
|
-
const mounts = [];
|
|
1518
|
-
for (const volume of volumes) {
|
|
1519
|
-
let source;
|
|
1520
|
-
let target;
|
|
1521
|
-
if (typeof volume === "string") {
|
|
1522
|
-
[source, target] = interpolate(volume, env).split(":");
|
|
1523
|
-
} else if (typeof volume === "object" && volume !== null) {
|
|
1524
|
-
const object = volume;
|
|
1525
|
-
if (object.type === "bind" && typeof object.source === "string" && typeof object.target === "string")
|
|
1526
|
-
({ source, target } = object);
|
|
1527
|
-
}
|
|
1528
|
-
const resolved = source === undefined ? undefined : bindSource(source, composeDir, env);
|
|
1529
|
-
if (resolved !== undefined && target?.startsWith("/") === true)
|
|
1530
|
-
mounts.push({ source: resolved, target });
|
|
1531
|
-
}
|
|
1532
|
-
return mounts;
|
|
1533
|
-
}
|
|
1534
|
-
function buildText(build) {
|
|
1535
|
-
if (typeof build === "string")
|
|
1536
|
-
return build;
|
|
1537
|
-
return typeof build === "object" && build !== null ? Object.values(build).filter((value) => typeof value === "string").join(" ") : "";
|
|
1538
|
-
}
|
|
1539
|
-
function parseServices(text, composeDir, env) {
|
|
1540
|
-
const services = new Map;
|
|
1541
|
-
const parsed = Bun.YAML.parse(text);
|
|
1542
|
-
for (const [name, service] of Object.entries(parsed?.services ?? {})) {
|
|
1543
|
-
if (service !== null && typeof service === "object")
|
|
1544
|
-
services.set(name, { ...service, mounts: mountsOf(service.volumes, composeDir, env) });
|
|
1545
|
-
}
|
|
1546
|
-
return services;
|
|
1547
|
-
}
|
|
1548
|
-
async function composeFiles(composeDir, env) {
|
|
1549
|
-
const listed = env.COMPOSE_FILE;
|
|
1550
|
-
if (listed !== undefined && listed !== "") {
|
|
1551
|
-
const files = [];
|
|
1552
|
-
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1553
|
-
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1554
|
-
const file = Bun.file(resolve4(composeDir, name));
|
|
1555
|
-
if (!await file.exists())
|
|
1556
|
-
fail(`COMPOSE_FILE names ${join9(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1557
|
-
files.push({ name, text: await file.text() });
|
|
1558
|
-
}
|
|
1559
|
-
return files;
|
|
1560
|
-
}
|
|
1561
|
-
const base = await readFiles(composeDir, COMPOSE_FILES);
|
|
1562
|
-
if (base === undefined)
|
|
1563
|
-
return [];
|
|
1564
|
-
const override = await readFiles(composeDir, OVERRIDE_FILES);
|
|
1565
|
-
return override === undefined ? [base] : [base, override];
|
|
1566
|
-
}
|
|
1567
|
-
async function readServices(composeDir) {
|
|
1568
|
-
const env = await variables(composeDir);
|
|
1569
|
-
const files = await composeFiles(composeDir, env);
|
|
1570
|
-
if (files.length === 0)
|
|
1571
|
-
return;
|
|
1572
|
-
const services = new Map;
|
|
1573
|
-
for (const file of files) {
|
|
1574
|
-
let parsed;
|
|
1575
|
-
try {
|
|
1576
|
-
parsed = parseServices(file.text, composeDir, env);
|
|
1577
|
-
} catch (error) {
|
|
1578
|
-
fail(`cannot read ${join9(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1579
|
-
}
|
|
1580
|
-
for (const [name, extra] of parsed) {
|
|
1581
|
-
const known = services.get(name);
|
|
1582
|
-
services.set(name, known === undefined ? extra : { ...known, ...extra, mounts: [...known.mounts, ...extra.mounts], image: extra.image ?? known.image, build: extra.build ?? known.build });
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
return [...services].map(([name, service]) => ({ name, mounts: service.mounts, profile: `${name} ${typeof service.image === "string" ? service.image : ""} ${buildText(service.build)}`.toLowerCase() }));
|
|
1586
|
-
}
|
|
1587
|
-
function climb(dir) {
|
|
1588
|
-
const folders = [dir];
|
|
1589
|
-
let current = dir;
|
|
1590
|
-
while (!existsSync4(join9(current, ".git")) && dirname4(current) !== current) {
|
|
1591
|
-
current = dirname4(current);
|
|
1592
|
-
folders.push(current);
|
|
1593
|
-
}
|
|
1594
|
-
return existsSync4(join9(current, ".git")) ? folders : [dir];
|
|
1595
|
-
}
|
|
1596
|
-
function containerPath(service, dir) {
|
|
1597
|
-
const holding = service.mounts.filter((mount) => {
|
|
1598
|
-
const inside = relative(mount.source, dir);
|
|
1599
|
-
return !inside.startsWith("..") && !inside.startsWith("/");
|
|
1600
|
-
});
|
|
1601
|
-
const deepest = holding.toSorted((a, b) => b.source.length - a.source.length)[0];
|
|
1602
|
-
if (deepest === undefined)
|
|
1603
|
-
return;
|
|
1604
|
-
const inside = relative(deepest.source, dir);
|
|
1605
|
-
return inside === "" ? deepest.target : join9(deepest.target, inside);
|
|
1606
|
-
}
|
|
1607
|
-
var noticed = new Set;
|
|
1608
|
-
async function place(dir, program, { service, host } = {}) {
|
|
1609
|
-
if (host === true)
|
|
1610
|
-
return;
|
|
1611
|
-
let found;
|
|
1612
|
-
for (const composeDir of climb(dir)) {
|
|
1613
|
-
const services = await readServices(composeDir);
|
|
1614
|
-
const mounting = (services ?? []).filter((candidate) => containerPath(candidate, dir) !== undefined);
|
|
1615
|
-
if (services !== undefined && (mounting.length > 0 || services.some((candidate) => candidate.name === service))) {
|
|
1616
|
-
found = { composeDir, services, mounting };
|
|
1617
|
-
break;
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
if (found === undefined) {
|
|
1621
|
-
if (service !== undefined)
|
|
1622
|
-
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
if (Bun.which("docker", { PATH: process19.env.PATH ?? "" }) === null) {
|
|
1626
|
-
if (service !== undefined)
|
|
1627
|
-
fail(`--in ${service}: docker not found`);
|
|
1628
|
-
if (!noticed.has(found.composeDir)) {
|
|
1629
|
-
noticed.add(found.composeDir);
|
|
1630
|
-
warn(`host, docker not found: the compose project in ${found.composeDir} is not reached`);
|
|
1631
|
-
}
|
|
1632
|
-
return;
|
|
1633
|
-
}
|
|
1634
|
-
const chosen = choose(found.mounting, found.services, dir, program, service);
|
|
1635
|
-
return { service: chosen.name, composeDir: found.composeDir, workdir: containerPath(chosen, dir) ?? dir };
|
|
1636
|
-
}
|
|
1637
|
-
function choose(mounting, services, dir, program, service) {
|
|
1638
|
-
if (service !== undefined) {
|
|
1639
|
-
const named = mounting.find((candidate) => candidate.name === service);
|
|
1640
|
-
if (named === undefined)
|
|
1641
|
-
fail(`--in ${service}: ${services.some((candidate) => candidate.name === service) ? `the service does not mount ${dir}` : `no such service, found ${services.map((candidate) => candidate.name).join(", ")}`}`);
|
|
1642
|
-
return named;
|
|
1643
|
-
}
|
|
1644
|
-
const [only] = mounting;
|
|
1645
|
-
if (mounting.length === 1 && only !== undefined)
|
|
1646
|
-
return only;
|
|
1647
|
-
const words = toolWords(program);
|
|
1648
|
-
const fitting = mounting.filter((candidate) => words.some((word) => candidate.profile.includes(word)));
|
|
1649
|
-
const [fit] = fitting;
|
|
1650
|
-
if (fitting.length !== 1 || fit === undefined)
|
|
1651
|
-
fail(`${mounting.map((candidate) => candidate.name).join(", ")} all mount ${dir} and none stands out for ${basename(program)}: pick one with --in <service>, or run on the host with --host`);
|
|
1652
|
-
return fit;
|
|
1653
|
-
}
|
|
1654
|
-
function execArgv(placement, argv, env) {
|
|
1655
|
-
const variables = Object.entries({ NO_COLOR: "1", FORCE_COLOR: "0", ...env }).flatMap(([name, value]) => ["-e", `${name}=${value}`]);
|
|
1656
|
-
return ["docker", "compose", "exec", "-T", "-w", placement.workdir, ...variables, placement.service, ...argv];
|
|
1657
|
-
}
|
|
1658
|
-
function shellIn(placement, command, env = {}) {
|
|
1659
|
-
return `cd ${shellQuote(placement.composeDir)} && ${execArgv(placement, ["sh", "-c", command], env).map((word) => shellQuote(word)).join(" ")}`;
|
|
1660
|
-
}
|
|
1661
|
-
function argvIn(placement, argv) {
|
|
1662
|
-
return execArgv(placement, argv, {});
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
class Stack {
|
|
1666
|
-
answers = new Map;
|
|
1667
|
-
async ask(composeDir) {
|
|
1668
|
-
let answer = this.answers.get(composeDir);
|
|
1669
|
-
if (answer === undefined) {
|
|
1670
|
-
answer = Stack.running(composeDir);
|
|
1671
|
-
this.answers.set(composeDir, answer);
|
|
1672
|
-
}
|
|
1673
|
-
return answer;
|
|
1674
|
-
}
|
|
1675
|
-
static async running(composeDir) {
|
|
1676
|
-
try {
|
|
1677
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process19.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1678
|
-
if (ran.code !== 0)
|
|
1679
|
-
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1680
|
-
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
1681
|
-
return ran.text.split(`
|
|
1682
|
-
`).map((line) => line.trim()).filter((line) => line !== "");
|
|
1683
|
-
} catch (error) {
|
|
1684
|
-
return `cannot run docker compose in ${composeDir}: ${error instanceof Error ? error.message : String(error)}`;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
async problem(placement) {
|
|
1688
|
-
const answer = await this.ask(placement.composeDir);
|
|
1689
|
-
if (typeof answer === "string")
|
|
1690
|
-
return answer;
|
|
1691
|
-
return answer.includes(placement.service) ? undefined : `the ${placement.service} service is not running (compose project in ${placement.composeDir}): start it yourself, or run on the host with --host`;
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
function programOf(command) {
|
|
1695
|
-
const end = command.indexOf(" ");
|
|
1696
|
-
return end === -1 ? command : command.slice(0, end);
|
|
1697
|
-
}
|
|
1698
|
-
var placeOptions = {
|
|
1699
|
-
in: { type: "string", description: "run in this compose service instead of the one found mounting the folder" },
|
|
1700
|
-
host: { type: "boolean", description: "run on the host even when a compose service mounts the folder" }
|
|
1701
|
-
};
|
|
1702
|
-
function placeSettings(values) {
|
|
1703
|
-
if (values.in !== undefined && values.host === true)
|
|
1704
|
-
fail("--in and --host exclude each other");
|
|
1705
|
-
return { service: values.in, host: values.host };
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
// src/makefile.ts
|
|
1709
|
-
var TARGET = /^([\w-]+(?:[ \t]+[\w-]+)*)[ \t]*::?(?!:?=)(.*)$/gm;
|
|
1710
|
-
var PHONY_LINE = /^\.PHONY:((?:.*\\\n)*.*)$/gm;
|
|
1711
|
-
var DEFINE_BLOCK = /^define\b.*\n(?:.*\n)*?endef\b.*$/gm;
|
|
1712
|
-
var BLANKS = /\s+/;
|
|
1713
|
-
var CONTINUATION = /\\\n/g;
|
|
1714
|
-
var EXTRA_BLANK_LINES = /\n\s*\n\s*\n/g;
|
|
1715
|
-
var LEADING_BLANK_LINES = /^\s*\n/;
|
|
1716
|
-
var TRAILING_WHITESPACE = /\s+$/;
|
|
1717
|
-
var FILE_LIKE = /[./]/;
|
|
1718
|
-
var PLACEHOLDER = "\x00phony\x00";
|
|
1719
|
-
function declarePhony(content, exists = () => false) {
|
|
1720
|
-
const declared = Array.from(content.matchAll(PHONY_LINE), (match) => match[1].replace(CONTINUATION, " ").split(BLANKS)).flat().filter((name) => name !== "");
|
|
1721
|
-
const found = Array.from(content.replace(DEFINE_BLOCK, "").matchAll(TARGET), (match) => ({ names: match[1].split(BLANKS), deps: match[2] })).filter(({ deps }) => !FILE_LIKE.test(deps)).flatMap(({ names }) => names).filter((name) => !exists(name));
|
|
1722
|
-
const targets = [...new Set([...declared, ...found])].sort((a, b) => a.localeCompare(b));
|
|
1723
|
-
let isFirst = true;
|
|
1724
|
-
const body = content.replace(PHONY_LINE, () => {
|
|
1725
|
-
const kept = isFirst ? PLACEHOLDER : "";
|
|
1726
|
-
isFirst = false;
|
|
1727
|
-
return kept;
|
|
1728
|
-
}).replace(EXTRA_BLANK_LINES, `
|
|
1729
|
-
|
|
1730
|
-
`).replace(LEADING_BLANK_LINES, "");
|
|
1731
|
-
const line = targets.length === 0 ? "" : `.PHONY: ${targets.join(" ")}`;
|
|
1732
|
-
const fixed = body.includes(PLACEHOLDER) || line === "" ? body.replace(PLACEHOLDER, () => line) : `${line}
|
|
1733
|
-
|
|
1734
|
-
${body}`;
|
|
1735
|
-
return { content: fixed.replace(LEADING_BLANK_LINES, "").replace(TRAILING_WHITESPACE, `
|
|
1736
|
-
`), targets };
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
// src/steps.ts
|
|
1740
|
-
import { readdir as readdir2 } from "fs/promises";
|
|
1741
|
-
import { join as join10 } from "path";
|
|
1742
|
-
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1743
|
-
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1744
|
-
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
1745
|
-
var TASK_RUNNERS = new Set(["Justfile", "Makefile"]);
|
|
1746
|
-
var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
1747
|
-
var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
|
|
1748
|
-
var JUST_TIMEOUT_MS = 1e4;
|
|
1749
|
-
var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"];
|
|
1750
|
-
var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
1751
|
-
async function readFirst(dir, files) {
|
|
1752
|
-
for (const file of files) {
|
|
1753
|
-
const handle = Bun.file(join10(dir, file));
|
|
1754
|
-
if (await handle.exists())
|
|
1755
|
-
return { file, text: await handle.text() };
|
|
1756
|
-
}
|
|
1757
|
-
return;
|
|
1758
|
-
}
|
|
1759
|
-
async function read(dir, ...files) {
|
|
1760
|
-
for (const file of files) {
|
|
1761
|
-
const handle = Bun.file(join10(dir, file));
|
|
1762
|
-
if (await handle.exists())
|
|
1763
|
-
return handle.text();
|
|
1764
|
-
}
|
|
1765
|
-
return;
|
|
1766
|
-
}
|
|
1767
|
-
function scripts(file, text) {
|
|
1768
|
-
try {
|
|
1769
|
-
const parsed = JSON.parse(text);
|
|
1770
|
-
return parsed.scripts ?? {};
|
|
1771
|
-
} catch {
|
|
1772
|
-
fail(`${file} is not valid JSON`);
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
function targets(text) {
|
|
1776
|
-
return [...text.matchAll(TARGET2)].map((match) => match[1] ?? "");
|
|
1777
|
-
}
|
|
1778
|
-
async function recipes(dir, file, text) {
|
|
1779
|
-
if (Bun.which("just") === null)
|
|
1780
|
-
return targets(text);
|
|
1781
|
-
try {
|
|
1782
|
-
const ran = await runCommand(["just", "--justfile", file, "--dump", "--dump-format", "json"], { cwd: dir, timeoutMs: JUST_TIMEOUT_MS });
|
|
1783
|
-
const dump = JSON.parse(ran.text);
|
|
1784
|
-
if (ran.code !== 0)
|
|
1785
|
-
return targets(text);
|
|
1786
|
-
return Object.entries(dump.recipes ?? {}).filter(([, recipe]) => recipe.private !== true && (recipe.parameters ?? []).every((parameter) => parameter.default !== null || parameter.kind === "star")).map(([name]) => name);
|
|
1787
|
-
} catch {
|
|
1788
|
-
return targets(text);
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
function callsSelf(value, bin) {
|
|
1792
|
-
return typeof value === "string" && (value === bin || value.startsWith(`${bin} `) || value.startsWith(`${bin} `));
|
|
1793
|
-
}
|
|
1794
|
-
async function candidates(dir, bin) {
|
|
1795
|
-
const steps = [];
|
|
1796
|
-
const packageJson = await read(dir, "package.json");
|
|
1797
|
-
const composerJson = await read(dir, "composer.json");
|
|
1798
|
-
const justfile = await readFirst(dir, JUSTFILES);
|
|
1799
|
-
const makefile = await read(dir, ...MAKEFILES);
|
|
1800
|
-
if (packageJson !== undefined) {
|
|
1801
|
-
for (const [name, value] of Object.entries(scripts("package.json", packageJson))) {
|
|
1802
|
-
if (!callsSelf(value, bin))
|
|
1803
|
-
steps.push({ name, command: `bun run ${name}`, source: "package.json" });
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
if (composerJson !== undefined) {
|
|
1807
|
-
for (const name of Object.keys(scripts("composer.json", composerJson)))
|
|
1808
|
-
steps.push({ name, command: `composer run ${name}`, source: "composer.json" });
|
|
1809
|
-
}
|
|
1810
|
-
if (justfile !== undefined) {
|
|
1811
|
-
for (const name of await recipes(dir, justfile.file, justfile.text))
|
|
1812
|
-
steps.push({ name, command: `just ${name}`, source: "Justfile" });
|
|
1813
|
-
}
|
|
1814
|
-
for (const name of targets(makefile ?? ""))
|
|
1815
|
-
steps.push({ name, command: `make ${name}`, source: "Makefile" });
|
|
1816
|
-
steps.push(...await phpSteps(dir));
|
|
1817
|
-
return steps;
|
|
1818
|
-
}
|
|
1819
|
-
async function firstFile(dir, names) {
|
|
1820
|
-
for (const name of names) {
|
|
1821
|
-
if (await Bun.file(join10(dir, name)).exists())
|
|
1822
|
-
return name;
|
|
1823
|
-
}
|
|
1824
|
-
return;
|
|
1825
|
-
}
|
|
1826
|
-
async function phpSteps(dir) {
|
|
1827
|
-
const steps = [];
|
|
1828
|
-
const phpstan = await firstFile(dir, PHPSTAN_CONFIGS);
|
|
1829
|
-
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
1830
|
-
const phpunit = await firstFile(dir, PHPUNIT_CONFIGS);
|
|
1831
|
-
if (phpstan !== undefined)
|
|
1832
|
-
steps.push({ name: "typecheck", command: "vendor/bin/phpstan analyse --no-progress --memory-limit=1G", source: phpstan });
|
|
1833
|
-
if (csFixer !== undefined)
|
|
1834
|
-
steps.push({ name: "lint", command: "vendor/bin/php-cs-fixer fix --dry-run -v", source: csFixer });
|
|
1835
|
-
if (phpunit !== undefined)
|
|
1836
|
-
steps.push({ name: "test", command: "vendor/bin/phpunit", source: phpunit });
|
|
1837
|
-
return steps;
|
|
1838
|
-
}
|
|
1839
|
-
async function discoverProjects(dir) {
|
|
1840
|
-
const own = await discover(dir);
|
|
1841
|
-
if (own.length > 0)
|
|
1842
|
-
return [{ dir, steps: own }];
|
|
1843
|
-
const projects = [];
|
|
1844
|
-
const entries = await readdir2(dir, { withFileTypes: true });
|
|
1845
|
-
const ignored = ignoredFolders(["var", "tmp"]);
|
|
1846
|
-
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1847
|
-
if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1848
|
-
continue;
|
|
1849
|
-
const steps = await discover(join10(dir, entry.name));
|
|
1850
|
-
if (steps.length > 0)
|
|
1851
|
-
projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
|
|
1852
|
-
}
|
|
1853
|
-
return projects;
|
|
1854
|
-
}
|
|
1855
|
-
async function discover(dir) {
|
|
1856
|
-
const found = await candidates(dir, "check");
|
|
1857
|
-
const runnerCheck = found.find((candidate) => candidate.name === "check" && TASK_RUNNERS.has(candidate.source));
|
|
1858
|
-
return STEP_NAMES.flatMap((name) => {
|
|
1859
|
-
const step = name === "check" && runnerCheck !== undefined ? runnerCheck : found.find((candidate) => candidate.name === name);
|
|
1860
|
-
return step === undefined ? [] : [step];
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
// src/options.ts
|
|
1865
|
-
var fixOptions = {
|
|
1866
|
-
list: { type: "boolean", short: "l", description: "print the steps (or, with --fix, the fixers) found, the commands that run them and where (host or service), without running them" },
|
|
1867
|
-
only: { type: "string", short: "o", description: `comma separated steps to run, among ${STEP_NAMES.join(", ")}; with --fix the fixers to run, by the names --list prints` },
|
|
1868
|
-
timeout: { type: "string", short: "t", description: "longest a step or fixer may run before it is ended (30s, 5m, 1h), none by default" },
|
|
1869
|
-
...placeOptions,
|
|
1870
|
-
json: jsonOption()
|
|
1871
|
-
};
|
|
1872
|
-
var options = {
|
|
1873
|
-
...fixOptions,
|
|
1874
|
-
fix: { type: "boolean", short: "f", description: "run the folder's fixers and formatters instead of the steps, as the fix bin does" },
|
|
1875
|
-
quiet: { type: "boolean", short: "q", description: "print nothing for a passing step, and nothing at all when every step passes" },
|
|
1876
|
-
failed: { type: "boolean", description: "run only the steps that failed in the last run of this folder, read from the run folder" },
|
|
1877
|
-
changed: { type: "boolean", short: "c", description: "narrow lint and test to the files changed against HEAD (a bare linter script, a bare bun test script), every other step runs in full and says so" },
|
|
1878
|
-
slot: { type: "boolean", description: "run each step through slot, queued behind the machine-wide slots of the other sessions, as it does by default when the slot bin is installed; fails without the bin" },
|
|
1879
|
-
"no-slot": { type: "boolean", description: "run the steps at once, without queueing behind the other sessions' slots" },
|
|
1880
|
-
parallel: { type: "boolean", description: "run the steps at the same time, printing each one's output in step order" }
|
|
1881
|
-
};
|
|
1882
|
-
var COMMA = /\s*,\s*/;
|
|
1883
|
-
function pick(steps, only, noun = "step") {
|
|
1884
|
-
if (only === undefined)
|
|
1885
|
-
return steps;
|
|
1886
|
-
const names = only.split(COMMA).filter((name) => name !== "");
|
|
1887
|
-
if (names.length === 0)
|
|
1888
|
-
fail(`--only names no ${noun}, found ${steps.map((step) => step.name).join(", ")}`);
|
|
1889
|
-
const unknown = names.filter((name) => !steps.some((step) => step.name === name));
|
|
1890
|
-
if (unknown.length > 0)
|
|
1891
|
-
fail(`no ${unknown.join(", ")} ${noun} here, found ${[...new Set(steps.map((step) => step.name))].join(", ")}`);
|
|
1892
|
-
return steps.filter((step) => names.includes(step.name));
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
// src/run.ts
|
|
1896
|
-
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1897
|
-
import { basename as basename2, join as join11 } from "path";
|
|
1898
|
-
import process20 from "process";
|
|
1899
|
-
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
1900
|
-
var RESULTS_FILE = "results.json";
|
|
1901
|
-
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
1902
|
-
async function logDirectory(cwd) {
|
|
1903
|
-
const root = await privateLogDirectory("check");
|
|
1904
|
-
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
1905
|
-
const path = join11(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process20.pid}`);
|
|
1906
|
-
await mkdir2(path, { mode: 448 });
|
|
1907
|
-
return path;
|
|
1908
|
-
}
|
|
1909
|
-
async function lastResults(cwd) {
|
|
1910
|
-
const root = await privateLogDirectory("check");
|
|
1911
|
-
const prefix = runPrefix(cwd);
|
|
1912
|
-
let latest;
|
|
1913
|
-
for (const name of await readdir3(root)) {
|
|
1914
|
-
if (!name.startsWith(prefix))
|
|
1915
|
-
continue;
|
|
1916
|
-
const file = join11(root, name, RESULTS_FILE);
|
|
1917
|
-
try {
|
|
1918
|
-
const { mtimeMs } = await stat3(file);
|
|
1919
|
-
if (latest === undefined || mtimeMs > latest.time)
|
|
1920
|
-
latest = { time: mtimeMs, file };
|
|
1921
|
-
} catch {}
|
|
1922
|
-
}
|
|
1923
|
-
if (latest === undefined)
|
|
1924
|
-
return;
|
|
1925
|
-
return JSON.parse(await Bun.file(latest.file).text());
|
|
1926
|
-
}
|
|
1927
|
-
async function lastFailed(cwd) {
|
|
1928
|
-
return (await lastResults(cwd))?.filter((result) => !result.ok).map((result) => result.name);
|
|
1929
|
-
}
|
|
1930
|
-
async function saveLog(output) {
|
|
1931
|
-
const root = await privateLogDirectory("errs");
|
|
1932
|
-
await sweepLogs(root);
|
|
1933
|
-
const path = join11(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process20.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
1934
|
-
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
1935
|
-
return path;
|
|
1936
|
-
}
|
|
1937
|
-
async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}) {
|
|
1938
|
-
const started = Date.now();
|
|
1939
|
-
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
1940
|
-
cwd,
|
|
1941
|
-
env: { ...process20.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
1942
|
-
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
1943
|
-
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
1944
|
-
});
|
|
1945
|
-
const output = stripAnsi(text);
|
|
1946
|
-
await writeFile(logFile, output, { mode: 384, flag: "wx" });
|
|
1947
|
-
return { ok: code === 0, ms: Date.now() - started, output, ...timedOut ? { timedOut } : {} };
|
|
1948
|
-
}
|
|
1949
|
-
async function refusedStep(reason, logFile) {
|
|
1950
|
-
await writeFile(logFile, reason, { mode: 384, flag: "wx" });
|
|
1951
|
-
return { ok: false, ms: 0, output: reason };
|
|
1952
|
-
}
|
|
1953
|
-
function outcomeJson(name, command, logFile, outcome, service) {
|
|
1954
|
-
return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
|
|
1955
|
-
}
|
|
1956
|
-
function printOutcome(name, width, command, logFile, outcome) {
|
|
1957
|
-
const colors = paint(process20.stdout);
|
|
1958
|
-
const path = role("path", process20.stdout);
|
|
1959
|
-
const took = colors.dim(formatDuration(outcome.ms));
|
|
1960
|
-
if (outcome.ok) {
|
|
1961
|
-
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
1962
|
-
return;
|
|
1963
|
-
}
|
|
1964
|
-
const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
|
|
1965
|
-
console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
|
|
1966
|
-
if (outcome.timedOut === true)
|
|
1967
|
-
console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
|
|
1968
|
-
console.log(failureExcerpt(outcome.output).split(`
|
|
1969
|
-
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
1970
|
-
`));
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
// src/fix.ts
|
|
1974
|
-
var fixUsage = `fix [--only <fixers>] [--timeout <duration>] [--in <service> | --host] [--list]
|
|
1975
|
-
|
|
1976
|
-
Alias of \`check --fix\`. Runs the folder's fixers: the project's own \`fix\` script, else its \`lint:fix\` and \`format\` ones (package.json through bun run, composer.json, a Justfile or a Makefile), then the formatters its files call for: php-cs-fixer where configured and composer.json has no fixer, just --fmt, go fmt and go mod tidy, cargo fmt, ruff where configured, and every Makefile target declared .PHONY.
|
|
1977
|
-
It looks at the folder itself only, so each package of a monorepo gets its own run.
|
|
1978
|
-
A script or php-cs-fixer runs inside the docker compose service that bind-mounts the folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path; a service that is down is never started, the fixer fails naming it. The formatters run on the host. --in picks the service, --host forces the host.
|
|
1979
|
-
Prints one line per fixer, what a failing one said, then the files the run changed. Each fixer's full output is saved to the file whose path ends its line.
|
|
1980
|
-
A fixer still running after --timeout is ended with everything it started, but not what it started inside a container.
|
|
1981
|
-
--json prints {fixers: [{name, command, in?, ok, ms, log, failed?} or {name, command, skipped}], changed} once every fixer ran, changed null outside a git repository.`;
|
|
1982
|
-
var EXITS = [[0, "every fixer ran or was skipped for a missing binary"], [1, "one failed"], [2, "bad usage, nothing applies or a fixer timed out"]];
|
|
1983
|
-
var RUNNING = "KAYNOOO_CLI_FIX";
|
|
1984
|
-
var JUSTFILES2 = ["justfile", "Justfile", ".justfile"];
|
|
1985
|
-
var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
1986
|
-
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
1987
|
-
var MAX_CHANGED = 30;
|
|
1988
|
-
async function replaceFile(path, content) {
|
|
1989
|
-
const temporary = `${path}.${process21.pid}.tmp`;
|
|
1990
|
-
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
1991
|
-
await rename(temporary, path);
|
|
1992
|
-
}
|
|
1993
|
-
async function projectFixers(dir) {
|
|
1994
|
-
const found = await candidates(dir, "fix");
|
|
1995
|
-
const named = (name) => found.find((step) => step.name === name);
|
|
1996
|
-
const all = named("fix");
|
|
1997
|
-
if (all !== undefined)
|
|
1998
|
-
return [all];
|
|
1999
|
-
return [named("lint:fix") ?? named("lint-fix"), named("format")].filter((step) => step !== undefined);
|
|
2000
|
-
}
|
|
2001
|
-
async function toolFixers(dir) {
|
|
2002
|
-
const fixers = [];
|
|
2003
|
-
const makefile = await firstFile(dir, MAKEFILES);
|
|
2004
|
-
const justfile = await firstFile(dir, JUSTFILES2);
|
|
2005
|
-
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2006
|
-
if (makefile !== undefined) {
|
|
2007
|
-
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2008
|
-
const path = join12(cwd, makefile);
|
|
2009
|
-
const current = await Bun.file(path).text();
|
|
2010
|
-
const { content, targets } = declarePhony(current, (name) => existsSync5(join12(cwd, name)));
|
|
2011
|
-
if (content !== current)
|
|
2012
|
-
await replaceFile(path, content);
|
|
2013
|
-
return `.PHONY: ${targets.join(" ")}`;
|
|
2014
|
-
} });
|
|
2015
|
-
}
|
|
2016
|
-
if (justfile !== undefined)
|
|
2017
|
-
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2018
|
-
if (await Bun.file(join12(dir, "go.mod")).exists())
|
|
2019
|
-
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2020
|
-
if (await Bun.file(join12(dir, "Cargo.toml")).exists())
|
|
2021
|
-
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2022
|
-
if (ruff)
|
|
2023
|
-
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
2024
|
-
return fixers;
|
|
2025
|
-
}
|
|
2026
|
-
async function fixers(dir) {
|
|
2027
|
-
const project = await projectFixers(dir);
|
|
2028
|
-
const csFixer = await firstFile(dir, CS_FIXER_CONFIGS);
|
|
2029
|
-
const php = csFixer === undefined || project.some((fixer) => fixer.source === "composer.json") ? [] : [{ name: "php-cs-fixer", command: "vendor/bin/php-cs-fixer fix", source: csFixer }];
|
|
2030
|
-
return [...project, ...php, ...await toolFixers(dir)];
|
|
2031
|
-
}
|
|
2032
|
-
function runsInService(fixer) {
|
|
2033
|
-
return fixer.write === undefined && fixer.requires === undefined;
|
|
2034
|
-
}
|
|
2035
|
-
async function runFixer(fixer, placement, cwd, logFile, settings) {
|
|
2036
|
-
if (fixer.write === undefined && placement !== undefined)
|
|
2037
|
-
return runStep(shellIn(placement, fixer.command, { [RUNNING]: "1" }), cwd, logFile, { ...settings, env: { [RUNNING]: "1" } });
|
|
2038
|
-
if (fixer.write === undefined)
|
|
2039
|
-
return runStep(fixer.command, cwd, logFile, { ...settings, env: { [RUNNING]: "1" } });
|
|
2040
|
-
const started = Date.now();
|
|
2041
|
-
let outcome;
|
|
2042
|
-
try {
|
|
2043
|
-
outcome = { ok: true, ms: 0, output: await fixer.write(cwd) };
|
|
2044
|
-
} catch (error) {
|
|
2045
|
-
outcome = { ok: false, ms: 0, output: error instanceof Error ? error.message : String(error) };
|
|
2046
|
-
}
|
|
2047
|
-
await writeFile2(logFile, outcome.output, { mode: 384, flag: "wx" });
|
|
2048
|
-
return { ...outcome, ms: Date.now() - started };
|
|
2049
|
-
}
|
|
2050
|
-
function printChanged(changed) {
|
|
2051
|
-
if (changed.length === 0) {
|
|
2052
|
-
console.log("nothing changed");
|
|
2053
|
-
return;
|
|
2054
|
-
}
|
|
2055
|
-
console.log(`changed ${changed.length} file${changed.length === 1 ? "" : "s"}:`);
|
|
2056
|
-
for (const path of changed.slice(0, MAX_CHANGED))
|
|
2057
|
-
console.log(` ${path}`);
|
|
2058
|
-
if (changed.length > MAX_CHANGED)
|
|
2059
|
-
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2060
|
-
}
|
|
2061
|
-
async function fix(args, cwd = process21.cwd()) {
|
|
2062
|
-
const parsed = parse(args, fixUsage, fixOptions, { exits: EXITS, replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
|
|
2063
|
-
return runFixers(parsed.values, cwd);
|
|
2064
|
-
}
|
|
2065
|
-
async function runFixers(values, cwd) {
|
|
2066
|
-
const parsed = { values };
|
|
2067
|
-
const settings = placeSettings(values);
|
|
2068
|
-
if (process21.env[RUNNING] !== undefined)
|
|
2069
|
-
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2070
|
-
const found = await fixers(cwd);
|
|
2071
|
-
if (found.length === 0)
|
|
2072
|
-
fail("nothing to fix here: no fix, lint:fix or format script, php-cs-fixer config, Makefile, Justfile, go.mod, Cargo.toml nor ruff config");
|
|
2073
|
-
const picked = pick(found, parsed.values.only, "fixer");
|
|
2074
|
-
const placements = new Map;
|
|
2075
|
-
for (const fixer of picked)
|
|
2076
|
-
placements.set(fixer, runsInService(fixer) ? await place(cwd, programOf(fixer.command), settings) : undefined);
|
|
2077
|
-
const json = parsed.values.json === true;
|
|
2078
|
-
const missing = (fixer) => fixer.requires !== undefined && Bun.which(fixer.requires) === null;
|
|
2079
|
-
if (parsed.values.list === true) {
|
|
2080
|
-
if (json)
|
|
2081
|
-
printJson(picked.map((fixer) => ({ name: fixer.name, command: fixer.command, source: fixer.source, ...placements.get(fixer) === undefined ? {} : { in: placements.get(fixer)?.service }, ...missing(fixer) ? { needs: fixer.requires } : {} })));
|
|
2082
|
-
else
|
|
2083
|
-
console.log(table(picked.map((fixer) => [fixer.name, fixer.command, missing(fixer) ? `${fixer.source}, needs ${fixer.requires}` : fixer.source, placements.get(fixer)?.service ?? "host"])));
|
|
2084
|
-
return 0;
|
|
2085
|
-
}
|
|
2086
|
-
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2087
|
-
const directory = await logDirectory(cwd);
|
|
2088
|
-
const held = holdSignals();
|
|
2089
|
-
const runSettings = { ...timeoutMs === undefined ? {} : { timeoutMs }, held };
|
|
2090
|
-
const stack = new Stack;
|
|
2091
|
-
const width = Math.max(...picked.map((fixer) => fixer.name.length));
|
|
2092
|
-
const before = await dirtyFiles(cwd);
|
|
2093
|
-
const ran = [];
|
|
2094
|
-
let failed = 0;
|
|
2095
|
-
let timedOut = false;
|
|
2096
|
-
try {
|
|
2097
|
-
for (const fixer of picked) {
|
|
2098
|
-
if (held.signal !== undefined)
|
|
2099
|
-
break;
|
|
2100
|
-
if (missing(fixer)) {
|
|
2101
|
-
if (!json)
|
|
2102
|
-
console.log(`${paint(process21.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2103
|
-
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2104
|
-
continue;
|
|
2105
|
-
}
|
|
2106
|
-
const logFile = join12(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2107
|
-
const placement = placements.get(fixer);
|
|
2108
|
-
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2109
|
-
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
2110
|
-
if (!json)
|
|
2111
|
-
printOutcome(fixer.name, width, placement === undefined ? fixer.command : `${fixer.command} (in ${placement.service})`, logFile, outcome);
|
|
2112
|
-
ran.push(outcomeJson(fixer.name, fixer.command, logFile, outcome, placement?.service));
|
|
2113
|
-
if (outcome.timedOut === true)
|
|
2114
|
-
timedOut = true;
|
|
2115
|
-
if (!outcome.ok)
|
|
2116
|
-
failed++;
|
|
2117
|
-
}
|
|
2118
|
-
} finally {
|
|
2119
|
-
held.release();
|
|
2120
|
-
}
|
|
2121
|
-
const after = before && await dirtyFiles(cwd);
|
|
2122
|
-
const changed = before !== undefined && after !== undefined ? changedFiles(before, after) : null;
|
|
2123
|
-
if (json)
|
|
2124
|
-
printJson({ fixers: ran, changed });
|
|
2125
|
-
else if (changed !== null)
|
|
2126
|
-
printChanged(changed);
|
|
2127
|
-
if (held.signal !== undefined)
|
|
2128
|
-
return exitCodeOf(null, held.signal);
|
|
2129
|
-
if (timedOut)
|
|
2130
|
-
return 2;
|
|
2131
|
-
return failed === 0 ? 0 : 1;
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
// src/fix-cli.ts
|
|
2135
|
-
process22.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });
|