@kaynooo/cli-check 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cli.js +348 -136
- package/dist/errs-cli.js +305 -105
- package/dist/fix-cli.js +323 -123
- package/dist/j-cli.js +981 -204
- package/package.json +7 -3
package/dist/fix-cli.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/fix-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process6 from "process";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/style.ts
|
|
14
|
-
import
|
|
14
|
+
import process5 from "process";
|
|
15
15
|
|
|
16
16
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
17
|
function x(s) {
|
|
@@ -274,36 +274,232 @@ function le(i = {}) {
|
|
|
274
274
|
}
|
|
275
275
|
var t = le();
|
|
276
276
|
|
|
277
|
-
// ../kit/src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
// ../kit/src/theme.ts
|
|
278
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
279
|
+
import { homedir as homedir2 } from "os";
|
|
280
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
281
|
+
import process4 from "process";
|
|
282
|
+
|
|
283
|
+
// ../kit/src/config.ts
|
|
284
|
+
import { existsSync } from "fs";
|
|
285
|
+
import { dirname, join, resolve } from "path";
|
|
286
|
+
import process2 from "process";
|
|
287
|
+
function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
288
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
289
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
290
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
291
|
+
if (found !== undefined)
|
|
292
|
+
return found;
|
|
293
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ../kit/src/user-config.ts
|
|
299
|
+
import { homedir } from "os";
|
|
300
|
+
import { join as join2 } from "path";
|
|
301
|
+
import process3 from "process";
|
|
302
|
+
function configBase(where = {}) {
|
|
303
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
304
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
305
|
+
}
|
|
306
|
+
function userConfigPath(bin, where = {}) {
|
|
307
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ../kit/src/theme.ts
|
|
311
|
+
var DEFAULT = {
|
|
312
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
313
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
314
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
315
|
+
bins: {}
|
|
316
|
+
};
|
|
317
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
318
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
319
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
320
|
+
var PRESETS = {
|
|
321
|
+
default: {},
|
|
322
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
323
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
324
|
+
ascii: { glyphs: ASCII }
|
|
283
325
|
};
|
|
284
|
-
|
|
326
|
+
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"]);
|
|
327
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
328
|
+
var CONTROL = /\p{Cc}/u;
|
|
329
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
330
|
+
var SPACES = /\s+/;
|
|
331
|
+
function isColorSpec(spec) {
|
|
332
|
+
if (typeof spec === "number")
|
|
333
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
334
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
335
|
+
}
|
|
336
|
+
function tinted(colors, spec) {
|
|
337
|
+
if (typeof spec === "number")
|
|
338
|
+
return colors.ansi256(spec);
|
|
339
|
+
return spec.trim().split(SPACES).reduce((chain, token) => HEX.test(token) ? chain.hex(token) : chain[token] ?? chain, colors);
|
|
340
|
+
}
|
|
341
|
+
function isRecord(value) {
|
|
342
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
343
|
+
}
|
|
344
|
+
function readThemeFile(path, warn) {
|
|
345
|
+
try {
|
|
346
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
347
|
+
if (stat === undefined)
|
|
348
|
+
return;
|
|
349
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
350
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
354
|
+
if (isRecord(parsed))
|
|
355
|
+
return parsed;
|
|
356
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
359
|
+
}
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
function applyPreset(theme, name, warn, where) {
|
|
363
|
+
if (name === undefined)
|
|
364
|
+
return;
|
|
365
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
366
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const preset = PRESETS[name];
|
|
370
|
+
Object.assign(theme.colors, preset.colors);
|
|
371
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
372
|
+
if (preset.accents !== undefined)
|
|
373
|
+
theme.accents = [...preset.accents];
|
|
374
|
+
return name;
|
|
375
|
+
}
|
|
376
|
+
function applyFile(theme, file, where, warn) {
|
|
377
|
+
if (isRecord(file.colors)) {
|
|
378
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
379
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
380
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
381
|
+
else if (!isColorSpec(value))
|
|
382
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
383
|
+
else
|
|
384
|
+
theme.colors[key] = value;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (isRecord(file.glyphs)) {
|
|
388
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
389
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
390
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
391
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
392
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
393
|
+
else
|
|
394
|
+
theme.glyphs[key] = value;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
398
|
+
theme.accents = [...file.accents];
|
|
399
|
+
else if (file.accents !== undefined)
|
|
400
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
401
|
+
if (isRecord(file.bins)) {
|
|
402
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
403
|
+
if (isColorSpec(value))
|
|
404
|
+
theme.bins[bin] = value;
|
|
405
|
+
else
|
|
406
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function endsWalk(home) {
|
|
411
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
412
|
+
}
|
|
413
|
+
var warned = new Set;
|
|
414
|
+
function warnOnce(message) {
|
|
415
|
+
if (warned.has(message))
|
|
416
|
+
return;
|
|
417
|
+
warned.add(message);
|
|
418
|
+
console.error(`warning: theme ${message}`);
|
|
419
|
+
}
|
|
420
|
+
function isPath(chosen) {
|
|
421
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
422
|
+
}
|
|
423
|
+
function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
424
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
425
|
+
const sources = [];
|
|
426
|
+
const chosen = env.KIT_THEME ?? "";
|
|
427
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
428
|
+
if (isPath(chosen))
|
|
429
|
+
wanted.push(resolve2(from, chosen));
|
|
430
|
+
const files = [];
|
|
431
|
+
for (const path of wanted) {
|
|
432
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
433
|
+
if (path !== undefined && file !== undefined)
|
|
434
|
+
files.push({ path, file });
|
|
435
|
+
}
|
|
436
|
+
let preset = "default";
|
|
437
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
438
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
439
|
+
} else {
|
|
440
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
441
|
+
if (named !== undefined)
|
|
442
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
443
|
+
}
|
|
444
|
+
for (const { path, file } of files) {
|
|
445
|
+
applyFile(theme, file, path, warn);
|
|
446
|
+
sources.push(path);
|
|
447
|
+
}
|
|
448
|
+
return { theme, sources, preset };
|
|
449
|
+
}
|
|
450
|
+
var current;
|
|
451
|
+
var currentKey = "";
|
|
452
|
+
function activeTheme() {
|
|
453
|
+
const key = `${process4.cwd()}\x00${process4.env.KIT_THEME ?? ""}\x00${process4.env.XDG_CONFIG_HOME ?? ""}`;
|
|
454
|
+
if (current === undefined || key !== currentKey) {
|
|
455
|
+
current = loadTheme();
|
|
456
|
+
currentKey = key;
|
|
457
|
+
}
|
|
458
|
+
return current;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ../kit/src/style.ts
|
|
462
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
463
|
+
function takesControlCodes(stream, env = process5.env) {
|
|
285
464
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
286
465
|
}
|
|
287
|
-
function paint(stream, env =
|
|
466
|
+
function paint(stream, env = process5.env) {
|
|
288
467
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
289
468
|
}
|
|
290
|
-
function marked(mark, text, stream, detail, env =
|
|
469
|
+
function marked(mark, text, stream, detail, env = process5.env) {
|
|
291
470
|
const colors = paint(stream, env);
|
|
292
|
-
|
|
293
|
-
|
|
471
|
+
let head = MARK_WORDS[mark];
|
|
472
|
+
if (takesControlCodes(stream, env)) {
|
|
473
|
+
const { theme } = activeTheme();
|
|
474
|
+
head = tinted(colors.bold, theme.colors[mark])(theme.glyphs[mark]);
|
|
475
|
+
}
|
|
294
476
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
295
477
|
}
|
|
296
478
|
function warn(text, detail) {
|
|
297
|
-
console.error(marked("warn", text,
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
479
|
+
console.error(marked("warn", text, process5.stderr, detail));
|
|
480
|
+
}
|
|
481
|
+
function role(name, stream, env = process5.env) {
|
|
482
|
+
const colors = paint(stream, env);
|
|
483
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
|
|
484
|
+
}
|
|
485
|
+
var STATUS_WORDS = {
|
|
486
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
487
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
488
|
+
running: ["running", "in_progress", "started"],
|
|
489
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
490
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
305
491
|
};
|
|
306
|
-
var STATUS_OF = new Map(Object.entries(
|
|
492
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
493
|
+
function header(bin, context, stream, env = process5.env) {
|
|
494
|
+
if (!takesControlCodes(stream, env))
|
|
495
|
+
return "";
|
|
496
|
+
const colors = paint(stream, env);
|
|
497
|
+
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
498
|
+
const { theme } = activeTheme();
|
|
499
|
+
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
500
|
+
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec);
|
|
501
|
+
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
502
|
+
}
|
|
307
503
|
|
|
308
504
|
// ../kit/src/format.ts
|
|
309
505
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -335,7 +531,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
335
531
|
function textWidth(text) {
|
|
336
532
|
return Bun.stringWidth(text);
|
|
337
533
|
}
|
|
338
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
534
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process6.stdout } = {}) {
|
|
339
535
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
340
536
|
const widths = [];
|
|
341
537
|
for (const row of cells) {
|
|
@@ -343,7 +539,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
343
539
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
344
540
|
}
|
|
345
541
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
346
|
-
const colors = paint(
|
|
542
|
+
const colors = paint(stream);
|
|
347
543
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
348
544
|
const width = widths[index] ?? 0;
|
|
349
545
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -351,7 +547,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
351
547
|
return `${gap}${cell}`;
|
|
352
548
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
353
549
|
}).join(" ").trimEnd());
|
|
354
|
-
|
|
550
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
551
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
355
552
|
`);
|
|
356
553
|
}
|
|
357
554
|
function narrow(rows, widths, limit) {
|
|
@@ -375,27 +572,27 @@ function printJson(value) {
|
|
|
375
572
|
}
|
|
376
573
|
|
|
377
574
|
// ../kit/src/help.ts
|
|
378
|
-
import
|
|
575
|
+
import process7 from "process";
|
|
379
576
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
380
577
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
381
578
|
var FULL_STOP = /\.$/;
|
|
382
|
-
function usageLine(usage, colors = paint(
|
|
579
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
383
580
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
384
581
|
}
|
|
385
|
-
function helpText(usage, options, colors = paint(
|
|
582
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
386
583
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
387
584
|
`);
|
|
388
585
|
}
|
|
389
|
-
function exitRows(exits, colors = paint(
|
|
586
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
390
587
|
if (exits.length === 0)
|
|
391
588
|
return [];
|
|
392
589
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
393
590
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
394
591
|
}
|
|
395
|
-
function replacesRows(replaces, colors = paint(
|
|
592
|
+
function replacesRows(replaces, colors = paint(process7.stdout)) {
|
|
396
593
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
397
594
|
}
|
|
398
|
-
function wantsHelpJson(env =
|
|
595
|
+
function wantsHelpJson(env = process7.env) {
|
|
399
596
|
return env.KIT_HELP === "json";
|
|
400
597
|
}
|
|
401
598
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -414,12 +611,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
414
611
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
415
612
|
};
|
|
416
613
|
}
|
|
417
|
-
function exampleRows(examples, colors = paint(
|
|
614
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
418
615
|
if (examples.length === 0)
|
|
419
616
|
return [];
|
|
420
617
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
421
618
|
}
|
|
422
|
-
function optionRows(options, colors = paint(
|
|
619
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
423
620
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
424
621
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
425
622
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -454,7 +651,7 @@ function closest(name, names) {
|
|
|
454
651
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
455
652
|
}
|
|
456
653
|
// ../kit/src/input.ts
|
|
457
|
-
import
|
|
654
|
+
import process8 from "process";
|
|
458
655
|
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
459
656
|
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
460
657
|
function duration(value, name, fallback, unit = "s") {
|
|
@@ -468,7 +665,7 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
468
665
|
}
|
|
469
666
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
470
667
|
if (path === "-") {
|
|
471
|
-
if (
|
|
668
|
+
if (process8.stdin.isTTY)
|
|
472
669
|
fail(noStdin);
|
|
473
670
|
return Bun.stdin.text();
|
|
474
671
|
}
|
|
@@ -527,7 +724,7 @@ var OUTPUT_OPTIONS = {
|
|
|
527
724
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
528
725
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
529
726
|
};
|
|
530
|
-
function applyOutput(color, plain, env =
|
|
727
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
531
728
|
const when = plain === true ? "never" : color ?? "auto";
|
|
532
729
|
if (when === "auto")
|
|
533
730
|
return;
|
|
@@ -698,7 +895,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
698
895
|
}
|
|
699
896
|
// ../kit/src/process.ts
|
|
700
897
|
import { constants } from "os";
|
|
701
|
-
import
|
|
898
|
+
import process10 from "process";
|
|
702
899
|
var KILL_GRACE_MS = 2000;
|
|
703
900
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
704
901
|
function exitCodeOf(code, signal) {
|
|
@@ -720,7 +917,7 @@ function holdSignals(cleanup) {
|
|
|
720
917
|
},
|
|
721
918
|
release: () => {
|
|
722
919
|
for (const signal of SIGNALS)
|
|
723
|
-
|
|
920
|
+
process10.off(signal, onSignal);
|
|
724
921
|
}
|
|
725
922
|
};
|
|
726
923
|
function onSignal(signal) {
|
|
@@ -733,10 +930,10 @@ function holdSignals(cleanup) {
|
|
|
733
930
|
return;
|
|
734
931
|
held.release();
|
|
735
932
|
cleanup(signal);
|
|
736
|
-
|
|
933
|
+
process10.kill(process10.pid, signal);
|
|
737
934
|
}
|
|
738
935
|
for (const signal of SIGNALS)
|
|
739
|
-
|
|
936
|
+
process10.on(signal, onSignal);
|
|
740
937
|
return held;
|
|
741
938
|
}
|
|
742
939
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -750,7 +947,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
750
947
|
return;
|
|
751
948
|
try {
|
|
752
949
|
if (grouped)
|
|
753
|
-
|
|
950
|
+
process10.kill(-proc.pid, killing);
|
|
754
951
|
else
|
|
755
952
|
proc.kill(killing);
|
|
756
953
|
} catch {}
|
|
@@ -824,42 +1021,42 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
824
1021
|
var RESET_STYLE = `${ESC}[0m`;
|
|
825
1022
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
826
1023
|
// ../kit/src/cli.ts
|
|
827
|
-
import { readFileSync, realpathSync } from "fs";
|
|
828
|
-
import { dirname as
|
|
829
|
-
import
|
|
1024
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1025
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1026
|
+
import process13 from "process";
|
|
830
1027
|
|
|
831
1028
|
// ../kit/src/usage.ts
|
|
832
1029
|
import { appendFileSync, mkdirSync } from "fs";
|
|
833
|
-
import { homedir as
|
|
834
|
-
import { dirname, isAbsolute, join as
|
|
835
|
-
import
|
|
1030
|
+
import { homedir as homedir4 } from "os";
|
|
1031
|
+
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
1032
|
+
import process12 from "process";
|
|
836
1033
|
|
|
837
1034
|
// ../kit/src/logs.ts
|
|
838
1035
|
import { lstatSync, openSync } from "fs";
|
|
839
1036
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
840
|
-
import { homedir, tmpdir } from "os";
|
|
841
|
-
import { join } from "path";
|
|
842
|
-
import
|
|
1037
|
+
import { homedir as homedir3, tmpdir } from "os";
|
|
1038
|
+
import { join as join4 } from "path";
|
|
1039
|
+
import process11 from "process";
|
|
843
1040
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
844
1041
|
var CLI_FOLDER = "kaynooo-cli";
|
|
845
1042
|
function isPrivateDirectory(path) {
|
|
846
1043
|
try {
|
|
847
1044
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
848
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1045
|
+
return info !== undefined && info.isDirectory() && info.uid === (process11.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
849
1046
|
} catch {
|
|
850
1047
|
return false;
|
|
851
1048
|
}
|
|
852
1049
|
}
|
|
853
|
-
async function privateLogDirectory(name, env =
|
|
1050
|
+
async function privateLogDirectory(name, env = process11.env) {
|
|
854
1051
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
855
|
-
const base = runtime === undefined || runtime === "" ?
|
|
856
|
-
const path =
|
|
1052
|
+
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1053
|
+
const path = join4(base, name);
|
|
857
1054
|
try {
|
|
858
1055
|
await mkdir(path, { recursive: true, mode: 448 });
|
|
859
1056
|
if (isPrivateDirectory(path))
|
|
860
1057
|
return path;
|
|
861
1058
|
} catch {}
|
|
862
|
-
return mkdtemp(
|
|
1059
|
+
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
863
1060
|
}
|
|
864
1061
|
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
865
1062
|
let names;
|
|
@@ -869,7 +1066,7 @@ async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
|
869
1066
|
return;
|
|
870
1067
|
}
|
|
871
1068
|
for (const name of names) {
|
|
872
|
-
const path =
|
|
1069
|
+
const path = join4(dir, name);
|
|
873
1070
|
try {
|
|
874
1071
|
const info = await stat(path);
|
|
875
1072
|
if (info.isDirectory())
|
|
@@ -890,14 +1087,14 @@ var usageError;
|
|
|
890
1087
|
function noteUsageError(message) {
|
|
891
1088
|
usageError = message;
|
|
892
1089
|
}
|
|
893
|
-
function stateHome(env =
|
|
1090
|
+
function stateHome(env = process12.env) {
|
|
894
1091
|
const dir = env.XDG_STATE_HOME;
|
|
895
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1092
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
896
1093
|
}
|
|
897
|
-
function usagePath(env =
|
|
898
|
-
return
|
|
1094
|
+
function usagePath(env = process12.env) {
|
|
1095
|
+
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
899
1096
|
}
|
|
900
|
-
function usageRecorded(env =
|
|
1097
|
+
function usageRecorded(env = process12.env) {
|
|
901
1098
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
902
1099
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
903
1100
|
}
|
|
@@ -911,12 +1108,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
911
1108
|
usageError = undefined;
|
|
912
1109
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
913
1110
|
}
|
|
914
|
-
function recordUsage(entry, env =
|
|
1111
|
+
function recordUsage(entry, env = process12.env) {
|
|
915
1112
|
if (!usageRecorded(env))
|
|
916
1113
|
return;
|
|
917
1114
|
try {
|
|
918
1115
|
const path = usagePath(env);
|
|
919
|
-
mkdirSync(
|
|
1116
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
920
1117
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
921
1118
|
`, { mode: 384 });
|
|
922
1119
|
} catch {}
|
|
@@ -929,8 +1126,8 @@ var LEVEL_OPTIONS = {
|
|
|
929
1126
|
};
|
|
930
1127
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
931
1128
|
function printError(prefix, message, hint, cause) {
|
|
932
|
-
const colors = paint(
|
|
933
|
-
const styled = takesControlCodes(
|
|
1129
|
+
const colors = paint(process13.stderr);
|
|
1130
|
+
const styled = takesControlCodes(process13.stderr);
|
|
934
1131
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
935
1132
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
936
1133
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -949,7 +1146,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
949
1146
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
950
1147
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
951
1148
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
952
|
-
if (error instanceof
|
|
1149
|
+
if (error instanceof Exit && error.code === 2)
|
|
953
1150
|
noteUsageError(error.message);
|
|
954
1151
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
955
1152
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -1013,17 +1210,17 @@ async function printCandidates(found) {
|
|
|
1013
1210
|
return 0;
|
|
1014
1211
|
}
|
|
1015
1212
|
function packageVersion(entry = Bun.main) {
|
|
1016
|
-
for (let dir =
|
|
1213
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1017
1214
|
try {
|
|
1018
|
-
const { version } = JSON.parse(
|
|
1215
|
+
const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
|
|
1019
1216
|
if (typeof version === "string")
|
|
1020
1217
|
return version;
|
|
1021
1218
|
} catch {}
|
|
1022
|
-
if (
|
|
1219
|
+
if (dirname3(dir) === dir)
|
|
1023
1220
|
return "0.0.0";
|
|
1024
1221
|
}
|
|
1025
1222
|
}
|
|
1026
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1223
|
+
async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
|
|
1027
1224
|
if (argv[0] === COMPLETE)
|
|
1028
1225
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1029
1226
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1050,17 +1247,17 @@ var {Glob } = globalThis.Bun;
|
|
|
1050
1247
|
var SESSION_FILES = new Glob("*.json");
|
|
1051
1248
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1052
1249
|
// package.json
|
|
1053
|
-
var version = "0.
|
|
1250
|
+
var version = "0.14.0";
|
|
1054
1251
|
|
|
1055
1252
|
// src/fix.ts
|
|
1056
|
-
import { existsSync as
|
|
1253
|
+
import { existsSync as existsSync4, statSync as statSync2 } from "fs";
|
|
1057
1254
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1058
|
-
import { join as
|
|
1059
|
-
import
|
|
1255
|
+
import { join as join11 } from "path";
|
|
1256
|
+
import process17 from "process";
|
|
1060
1257
|
|
|
1061
1258
|
// src/changes.ts
|
|
1062
1259
|
import { stat as stat2 } from "fs/promises";
|
|
1063
|
-
import { join as
|
|
1260
|
+
import { join as join7 } from "path";
|
|
1064
1261
|
var {$ } = globalThis.Bun;
|
|
1065
1262
|
async function dirtyFiles(dir) {
|
|
1066
1263
|
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
@@ -1069,7 +1266,7 @@ async function dirtyFiles(dir) {
|
|
|
1069
1266
|
const files = new Map;
|
|
1070
1267
|
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1071
1268
|
try {
|
|
1072
|
-
const { size, mtimeMs } = await stat2(
|
|
1269
|
+
const { size, mtimeMs } = await stat2(join7(dir, path));
|
|
1073
1270
|
files.set(path, `${size}:${mtimeMs}`);
|
|
1074
1271
|
} catch {
|
|
1075
1272
|
files.set(path, "");
|
|
@@ -1082,10 +1279,10 @@ function changedFiles(before, after) {
|
|
|
1082
1279
|
}
|
|
1083
1280
|
|
|
1084
1281
|
// src/compose.ts
|
|
1085
|
-
import { existsSync } from "fs";
|
|
1086
|
-
import { homedir as
|
|
1087
|
-
import { basename, dirname as
|
|
1088
|
-
import
|
|
1282
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1283
|
+
import { homedir as homedir5 } from "os";
|
|
1284
|
+
import { basename, dirname as dirname4, join as join8, relative, resolve as resolve3 } from "path";
|
|
1285
|
+
import process15 from "process";
|
|
1089
1286
|
|
|
1090
1287
|
// ../kit/src/shell.ts
|
|
1091
1288
|
var SEPARATORS = new Set([`
|
|
@@ -1163,7 +1360,7 @@ function toolWords(program) {
|
|
|
1163
1360
|
}
|
|
1164
1361
|
async function readFiles(dir, names) {
|
|
1165
1362
|
for (const name of names) {
|
|
1166
|
-
const handle = Bun.file(
|
|
1363
|
+
const handle = Bun.file(join8(dir, name));
|
|
1167
1364
|
if (await handle.exists())
|
|
1168
1365
|
return { name, text: await handle.text() };
|
|
1169
1366
|
}
|
|
@@ -1178,7 +1375,7 @@ async function variables(composeDir) {
|
|
|
1178
1375
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1179
1376
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1180
1377
|
}
|
|
1181
|
-
for (const [key, value] of Object.entries(
|
|
1378
|
+
for (const [key, value] of Object.entries(process15.env)) {
|
|
1182
1379
|
if (value !== undefined)
|
|
1183
1380
|
env[key] = value;
|
|
1184
1381
|
}
|
|
@@ -1198,10 +1395,10 @@ function interpolate(text, env) {
|
|
|
1198
1395
|
function bindSource(source, composeDir, env) {
|
|
1199
1396
|
const path = interpolate(source, env);
|
|
1200
1397
|
if (path.startsWith("~"))
|
|
1201
|
-
return
|
|
1398
|
+
return join8(homedir5(), path.slice(1));
|
|
1202
1399
|
if (path.startsWith("/"))
|
|
1203
|
-
return
|
|
1204
|
-
return path.startsWith(".") ?
|
|
1400
|
+
return resolve3(path);
|
|
1401
|
+
return path.startsWith(".") ? resolve3(composeDir, path) : undefined;
|
|
1205
1402
|
}
|
|
1206
1403
|
function mountsOf(volumes, composeDir, env) {
|
|
1207
1404
|
if (!Array.isArray(volumes))
|
|
@@ -1243,9 +1440,9 @@ async function composeFiles(composeDir, env) {
|
|
|
1243
1440
|
const files = [];
|
|
1244
1441
|
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1245
1442
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1246
|
-
const file = Bun.file(
|
|
1443
|
+
const file = Bun.file(resolve3(composeDir, name));
|
|
1247
1444
|
if (!await file.exists())
|
|
1248
|
-
fail(`COMPOSE_FILE names ${
|
|
1445
|
+
fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1249
1446
|
files.push({ name, text: await file.text() });
|
|
1250
1447
|
}
|
|
1251
1448
|
return files;
|
|
@@ -1267,7 +1464,7 @@ async function readServices(composeDir) {
|
|
|
1267
1464
|
try {
|
|
1268
1465
|
parsed = parseServices(file.text, composeDir, env);
|
|
1269
1466
|
} catch (error) {
|
|
1270
|
-
fail(`cannot read ${
|
|
1467
|
+
fail(`cannot read ${join8(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1271
1468
|
}
|
|
1272
1469
|
for (const [name, extra] of parsed) {
|
|
1273
1470
|
const known = services.get(name);
|
|
@@ -1279,11 +1476,11 @@ async function readServices(composeDir) {
|
|
|
1279
1476
|
function climb(dir) {
|
|
1280
1477
|
const folders = [dir];
|
|
1281
1478
|
let current = dir;
|
|
1282
|
-
while (!
|
|
1283
|
-
current =
|
|
1479
|
+
while (!existsSync3(join8(current, ".git")) && dirname4(current) !== current) {
|
|
1480
|
+
current = dirname4(current);
|
|
1284
1481
|
folders.push(current);
|
|
1285
1482
|
}
|
|
1286
|
-
return
|
|
1483
|
+
return existsSync3(join8(current, ".git")) ? folders : [dir];
|
|
1287
1484
|
}
|
|
1288
1485
|
function containerPath(service, dir) {
|
|
1289
1486
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1294,7 +1491,7 @@ function containerPath(service, dir) {
|
|
|
1294
1491
|
if (deepest === undefined)
|
|
1295
1492
|
return;
|
|
1296
1493
|
const inside = relative(deepest.source, dir);
|
|
1297
|
-
return inside === "" ? deepest.target :
|
|
1494
|
+
return inside === "" ? deepest.target : join8(deepest.target, inside);
|
|
1298
1495
|
}
|
|
1299
1496
|
var noticed = new Set;
|
|
1300
1497
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1314,7 +1511,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1314
1511
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1315
1512
|
return;
|
|
1316
1513
|
}
|
|
1317
|
-
if (Bun.which("docker", { PATH:
|
|
1514
|
+
if (Bun.which("docker", { PATH: process15.env.PATH ?? "" }) === null) {
|
|
1318
1515
|
if (service !== undefined)
|
|
1319
1516
|
fail(`--in ${service}: docker not found`);
|
|
1320
1517
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1366,7 +1563,7 @@ class Stack {
|
|
|
1366
1563
|
}
|
|
1367
1564
|
static async running(composeDir) {
|
|
1368
1565
|
try {
|
|
1369
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1566
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process15.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1370
1567
|
if (ran.code !== 0)
|
|
1371
1568
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1372
1569
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1430,7 +1627,7 @@ ${body}`;
|
|
|
1430
1627
|
|
|
1431
1628
|
// src/steps.ts
|
|
1432
1629
|
import { readdir as readdir2 } from "fs/promises";
|
|
1433
|
-
import { join as
|
|
1630
|
+
import { join as join9 } from "path";
|
|
1434
1631
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1435
1632
|
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1436
1633
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
@@ -1442,7 +1639,7 @@ var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
|
1442
1639
|
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1443
1640
|
async function readFirst(dir, files) {
|
|
1444
1641
|
for (const file of files) {
|
|
1445
|
-
const handle = Bun.file(
|
|
1642
|
+
const handle = Bun.file(join9(dir, file));
|
|
1446
1643
|
if (await handle.exists())
|
|
1447
1644
|
return { file, text: await handle.text() };
|
|
1448
1645
|
}
|
|
@@ -1450,7 +1647,7 @@ async function readFirst(dir, files) {
|
|
|
1450
1647
|
}
|
|
1451
1648
|
async function read(dir, ...files) {
|
|
1452
1649
|
for (const file of files) {
|
|
1453
|
-
const handle = Bun.file(
|
|
1650
|
+
const handle = Bun.file(join9(dir, file));
|
|
1454
1651
|
if (await handle.exists())
|
|
1455
1652
|
return handle.text();
|
|
1456
1653
|
}
|
|
@@ -1510,7 +1707,7 @@ async function candidates(dir, bin) {
|
|
|
1510
1707
|
}
|
|
1511
1708
|
async function firstFile(dir, names) {
|
|
1512
1709
|
for (const name of names) {
|
|
1513
|
-
if (await Bun.file(
|
|
1710
|
+
if (await Bun.file(join9(dir, name)).exists())
|
|
1514
1711
|
return name;
|
|
1515
1712
|
}
|
|
1516
1713
|
return;
|
|
@@ -1537,9 +1734,9 @@ async function discoverProjects(dir) {
|
|
|
1537
1734
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1538
1735
|
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1539
1736
|
continue;
|
|
1540
|
-
const steps = await discover(
|
|
1737
|
+
const steps = await discover(join9(dir, entry.name));
|
|
1541
1738
|
if (steps.length > 0)
|
|
1542
|
-
projects.push({ name: entry.name, dir:
|
|
1739
|
+
projects.push({ name: entry.name, dir: join9(dir, entry.name), steps });
|
|
1543
1740
|
}
|
|
1544
1741
|
return projects;
|
|
1545
1742
|
}
|
|
@@ -1581,8 +1778,8 @@ function pick(steps, only, noun = "step") {
|
|
|
1581
1778
|
|
|
1582
1779
|
// src/run.ts
|
|
1583
1780
|
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1584
|
-
import { basename as basename2, join as
|
|
1585
|
-
import
|
|
1781
|
+
import { basename as basename2, join as join10 } from "path";
|
|
1782
|
+
import process16 from "process";
|
|
1586
1783
|
|
|
1587
1784
|
// src/e2e.ts
|
|
1588
1785
|
var E2E_NOISE = [
|
|
@@ -2217,7 +2414,7 @@ var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
|
2217
2414
|
async function logDirectory(cwd) {
|
|
2218
2415
|
const root = await privateLogDirectory("check");
|
|
2219
2416
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2220
|
-
const path =
|
|
2417
|
+
const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process16.pid}`);
|
|
2221
2418
|
await mkdir2(path, { mode: 448 });
|
|
2222
2419
|
return path;
|
|
2223
2420
|
}
|
|
@@ -2228,7 +2425,7 @@ async function lastFailed(cwd) {
|
|
|
2228
2425
|
for (const name of await readdir3(root)) {
|
|
2229
2426
|
if (!name.startsWith(prefix))
|
|
2230
2427
|
continue;
|
|
2231
|
-
const file =
|
|
2428
|
+
const file = join10(root, name, RESULTS_FILE);
|
|
2232
2429
|
try {
|
|
2233
2430
|
const { mtimeMs } = await stat3(file);
|
|
2234
2431
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2243,7 +2440,7 @@ async function lastFailed(cwd) {
|
|
|
2243
2440
|
async function saveLog(output) {
|
|
2244
2441
|
const root = await privateLogDirectory("errs");
|
|
2245
2442
|
await sweepLogs(root);
|
|
2246
|
-
const path =
|
|
2443
|
+
const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process16.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2247
2444
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2248
2445
|
return path;
|
|
2249
2446
|
}
|
|
@@ -2251,7 +2448,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2251
2448
|
const started = Date.now();
|
|
2252
2449
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2253
2450
|
cwd,
|
|
2254
|
-
env: { ...
|
|
2451
|
+
env: { ...process16.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2255
2452
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2256
2453
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2257
2454
|
});
|
|
@@ -2267,14 +2464,17 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2267
2464
|
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) } };
|
|
2268
2465
|
}
|
|
2269
2466
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2467
|
+
const colors = paint(process16.stdout);
|
|
2468
|
+
const path = role("path", process16.stdout);
|
|
2469
|
+
const took = colors.dim(formatDuration(outcome.ms));
|
|
2270
2470
|
if (outcome.ok) {
|
|
2271
|
-
console.log(
|
|
2471
|
+
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
2272
2472
|
return;
|
|
2273
2473
|
}
|
|
2274
|
-
const label = outcome.timedOut === true ? "TIME " : "FAIL ";
|
|
2275
|
-
console.log(`${label} ${name.padEnd(width)} ${
|
|
2474
|
+
const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
|
|
2475
|
+
console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
|
|
2276
2476
|
if (outcome.timedOut === true)
|
|
2277
|
-
console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
|
|
2477
|
+
console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
|
|
2278
2478
|
console.log(failureExcerpt(outcome.output).split(`
|
|
2279
2479
|
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
2280
2480
|
`));
|
|
@@ -2296,8 +2496,8 @@ var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
|
2296
2496
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2297
2497
|
var MAX_CHANGED = 30;
|
|
2298
2498
|
async function replaceFile(path, content) {
|
|
2299
|
-
const temporary = `${path}.${
|
|
2300
|
-
await writeFile2(temporary, content, { mode:
|
|
2499
|
+
const temporary = `${path}.${process17.pid}.tmp`;
|
|
2500
|
+
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
2301
2501
|
await rename(temporary, path);
|
|
2302
2502
|
}
|
|
2303
2503
|
async function projectFixers(dir) {
|
|
@@ -2315,9 +2515,9 @@ async function toolFixers(dir) {
|
|
|
2315
2515
|
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2316
2516
|
if (makefile !== undefined) {
|
|
2317
2517
|
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2318
|
-
const path =
|
|
2518
|
+
const path = join11(cwd, makefile);
|
|
2319
2519
|
const current = await Bun.file(path).text();
|
|
2320
|
-
const { content, targets } = declarePhony(current, (name) =>
|
|
2520
|
+
const { content, targets } = declarePhony(current, (name) => existsSync4(join11(cwd, name)));
|
|
2321
2521
|
if (content !== current)
|
|
2322
2522
|
await replaceFile(path, content);
|
|
2323
2523
|
return `.PHONY: ${targets.join(" ")}`;
|
|
@@ -2325,9 +2525,9 @@ async function toolFixers(dir) {
|
|
|
2325
2525
|
}
|
|
2326
2526
|
if (justfile !== undefined)
|
|
2327
2527
|
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2328
|
-
if (await Bun.file(
|
|
2528
|
+
if (await Bun.file(join11(dir, "go.mod")).exists())
|
|
2329
2529
|
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2330
|
-
if (await Bun.file(
|
|
2530
|
+
if (await Bun.file(join11(dir, "Cargo.toml")).exists())
|
|
2331
2531
|
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2332
2532
|
if (ruff)
|
|
2333
2533
|
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
@@ -2368,14 +2568,14 @@ function printChanged(changed) {
|
|
|
2368
2568
|
if (changed.length > MAX_CHANGED)
|
|
2369
2569
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2370
2570
|
}
|
|
2371
|
-
async function fix(args, cwd =
|
|
2571
|
+
async function fix(args, cwd = process17.cwd()) {
|
|
2372
2572
|
const parsed = parse(args, fixUsage, fixOptions, { 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"]] });
|
|
2373
2573
|
return runFixers(parsed.values, cwd);
|
|
2374
2574
|
}
|
|
2375
2575
|
async function runFixers(values, cwd) {
|
|
2376
2576
|
const parsed = { values };
|
|
2377
2577
|
const settings = placeSettings(values);
|
|
2378
|
-
if (
|
|
2578
|
+
if (process17.env[RUNNING] !== undefined)
|
|
2379
2579
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2380
2580
|
const found = await fixers(cwd);
|
|
2381
2581
|
if (found.length === 0)
|
|
@@ -2409,11 +2609,11 @@ async function runFixers(values, cwd) {
|
|
|
2409
2609
|
break;
|
|
2410
2610
|
if (missing(fixer)) {
|
|
2411
2611
|
if (!json)
|
|
2412
|
-
console.log(
|
|
2612
|
+
console.log(`${paint(process17.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2413
2613
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2414
2614
|
continue;
|
|
2415
2615
|
}
|
|
2416
|
-
const logFile =
|
|
2616
|
+
const logFile = join11(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2417
2617
|
const placement = placements.get(fixer);
|
|
2418
2618
|
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2419
2619
|
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
@@ -2442,4 +2642,4 @@ async function runFixers(values, cwd) {
|
|
|
2442
2642
|
}
|
|
2443
2643
|
|
|
2444
2644
|
// src/fix-cli.ts
|
|
2445
|
-
|
|
2645
|
+
process18.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });
|