@kaynooo/cli-workspace 0.2.0 → 0.4.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/audit-cli.js +367 -127
- package/dist/cli.js +493 -218
- package/dist/repos-cli.js +403 -140
- package/dist/sweep-cli.js +420 -144
- package/package.json +2 -2
package/dist/audit-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/audit-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process17 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -13,14 +13,35 @@ function isIgnored(advisory, ignore) {
|
|
|
13
13
|
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
14
14
|
}
|
|
15
15
|
// ../kit/src/args.ts
|
|
16
|
-
import
|
|
16
|
+
import process9 from "process";
|
|
17
17
|
import { parseArgs } from "util";
|
|
18
18
|
|
|
19
19
|
// ../kit/src/format.ts
|
|
20
|
-
import
|
|
20
|
+
import process7 from "process";
|
|
21
21
|
|
|
22
|
-
// ../kit/src/
|
|
22
|
+
// ../kit/src/mode.ts
|
|
23
23
|
import process2 from "process";
|
|
24
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
25
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
26
|
+
function isSet(value) {
|
|
27
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
28
|
+
}
|
|
29
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
30
|
+
const chosen = env.KIT_MODE;
|
|
31
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
32
|
+
return chosen;
|
|
33
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
34
|
+
return "agent";
|
|
35
|
+
if (stream.isTTY === true)
|
|
36
|
+
return "terminal";
|
|
37
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
38
|
+
}
|
|
39
|
+
function isInteractive(streams = process2) {
|
|
40
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ../kit/src/style.ts
|
|
44
|
+
import process6 from "process";
|
|
24
45
|
|
|
25
46
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
26
47
|
function x(s) {
|
|
@@ -283,52 +304,256 @@ function le(i = {}) {
|
|
|
283
304
|
}
|
|
284
305
|
var t = le();
|
|
285
306
|
|
|
286
|
-
// ../kit/src/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
307
|
+
// ../kit/src/theme.ts
|
|
308
|
+
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
309
|
+
import { homedir as homedir2 } from "os";
|
|
310
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
311
|
+
import process5 from "process";
|
|
312
|
+
|
|
313
|
+
// ../kit/src/config.ts
|
|
314
|
+
import { existsSync } from "fs";
|
|
315
|
+
import { dirname, join, resolve } from "path";
|
|
316
|
+
import process3 from "process";
|
|
317
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
318
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
319
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
320
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
321
|
+
if (found !== undefined)
|
|
322
|
+
return found;
|
|
323
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ../kit/src/user-config.ts
|
|
329
|
+
import { existsSync as existsSync2 } from "fs";
|
|
330
|
+
import { homedir } from "os";
|
|
331
|
+
import { join as join2 } from "path";
|
|
332
|
+
import process4 from "process";
|
|
333
|
+
function configBase(where = {}) {
|
|
334
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
335
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
336
|
+
}
|
|
337
|
+
function userConfigPath(bin, where = {}) {
|
|
338
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
339
|
+
}
|
|
340
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
341
|
+
const current = userConfigPath(bin, where);
|
|
342
|
+
if (existsSync2(current))
|
|
343
|
+
return current;
|
|
344
|
+
const base = configBase(where);
|
|
345
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ../kit/src/theme.ts
|
|
349
|
+
var DEFAULT = {
|
|
350
|
+
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" },
|
|
351
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
352
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
353
|
+
bins: {}
|
|
292
354
|
};
|
|
293
|
-
|
|
294
|
-
|
|
355
|
+
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" };
|
|
356
|
+
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" };
|
|
357
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
358
|
+
var PRESETS = {
|
|
359
|
+
default: {},
|
|
360
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
361
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
362
|
+
ascii: { glyphs: ASCII }
|
|
363
|
+
};
|
|
364
|
+
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"]);
|
|
365
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
366
|
+
var CONTROL = /\p{Cc}/u;
|
|
367
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
368
|
+
var SPACES = /\s+/;
|
|
369
|
+
function isColorSpec(spec) {
|
|
370
|
+
if (typeof spec === "number")
|
|
371
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
372
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
373
|
+
}
|
|
374
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
375
|
+
function cubeLevel(channel) {
|
|
376
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
377
|
+
}
|
|
378
|
+
function nearest256(hex) {
|
|
379
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
380
|
+
const levels = rgb.map(cubeLevel);
|
|
381
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
382
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
383
|
+
const greyValue = 8 + grey * 10;
|
|
384
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
385
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
386
|
+
}
|
|
387
|
+
function hasTrueColor(env) {
|
|
388
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
389
|
+
}
|
|
390
|
+
function tinted(colors, spec, env = process5.env) {
|
|
391
|
+
if (typeof spec === "number")
|
|
392
|
+
return colors.ansi256(spec);
|
|
393
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
394
|
+
if (HEX.test(token))
|
|
395
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
396
|
+
return chain[token] ?? chain;
|
|
397
|
+
}, colors);
|
|
398
|
+
}
|
|
399
|
+
function isRecord(value) {
|
|
400
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
401
|
+
}
|
|
402
|
+
function readThemeFile(path, warn) {
|
|
403
|
+
try {
|
|
404
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
405
|
+
if (stat === undefined)
|
|
406
|
+
return;
|
|
407
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
408
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
412
|
+
if (isRecord(parsed))
|
|
413
|
+
return parsed;
|
|
414
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
417
|
+
}
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
function applyPreset(theme, name, warn, where) {
|
|
421
|
+
if (name === undefined)
|
|
422
|
+
return;
|
|
423
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
424
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const preset = PRESETS[name];
|
|
428
|
+
Object.assign(theme.colors, preset.colors);
|
|
429
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
430
|
+
if (preset.accents !== undefined)
|
|
431
|
+
theme.accents = [...preset.accents];
|
|
432
|
+
return name;
|
|
433
|
+
}
|
|
434
|
+
function applyFile(theme, file, where, warn) {
|
|
435
|
+
if (isRecord(file.colors)) {
|
|
436
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
437
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
438
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
439
|
+
else if (!isColorSpec(value))
|
|
440
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
441
|
+
else
|
|
442
|
+
theme.colors[key] = value;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (isRecord(file.glyphs)) {
|
|
446
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
447
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
448
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
449
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
450
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
451
|
+
else
|
|
452
|
+
theme.glyphs[key] = value;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
456
|
+
theme.accents = [...file.accents];
|
|
457
|
+
else if (file.accents !== undefined)
|
|
458
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
459
|
+
if (isRecord(file.bins)) {
|
|
460
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
461
|
+
if (isColorSpec(value))
|
|
462
|
+
theme.bins[bin] = value;
|
|
463
|
+
else
|
|
464
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function endsWalk(home) {
|
|
469
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
470
|
+
}
|
|
471
|
+
var warned = new Set;
|
|
472
|
+
function warnOnce(message) {
|
|
473
|
+
if (warned.has(message))
|
|
474
|
+
return;
|
|
475
|
+
warned.add(message);
|
|
476
|
+
console.error(`warning: theme ${message}`);
|
|
477
|
+
}
|
|
478
|
+
function isPath(chosen) {
|
|
479
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
480
|
+
}
|
|
481
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
482
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
483
|
+
const sources = [];
|
|
484
|
+
const chosen = env.KIT_THEME ?? "";
|
|
485
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
486
|
+
if (isPath(chosen))
|
|
487
|
+
wanted.push(resolve2(from, chosen));
|
|
488
|
+
const files = [];
|
|
489
|
+
for (const path of wanted) {
|
|
490
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
491
|
+
if (path !== undefined && file !== undefined)
|
|
492
|
+
files.push({ path, file });
|
|
493
|
+
}
|
|
494
|
+
let preset = "default";
|
|
495
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
496
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
497
|
+
} else {
|
|
498
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
499
|
+
if (named !== undefined)
|
|
500
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
501
|
+
}
|
|
502
|
+
for (const { path, file } of files) {
|
|
503
|
+
applyFile(theme, file, path, warn);
|
|
504
|
+
sources.push(path);
|
|
505
|
+
}
|
|
506
|
+
return { theme, sources, preset };
|
|
507
|
+
}
|
|
508
|
+
var current;
|
|
509
|
+
var currentKey = "";
|
|
510
|
+
function activeTheme() {
|
|
511
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
512
|
+
if (current === undefined || key !== currentKey) {
|
|
513
|
+
current = loadTheme();
|
|
514
|
+
currentKey = key;
|
|
515
|
+
}
|
|
516
|
+
return current;
|
|
295
517
|
}
|
|
296
|
-
|
|
518
|
+
|
|
519
|
+
// ../kit/src/style.ts
|
|
520
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
521
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
522
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
523
|
+
}
|
|
524
|
+
function paint(stream, env = process6.env) {
|
|
297
525
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
298
526
|
}
|
|
299
|
-
function marked(mark, text, stream, detail, env =
|
|
527
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
300
528
|
const colors = paint(stream, env);
|
|
301
|
-
|
|
302
|
-
|
|
529
|
+
let head = MARK_WORDS[mark];
|
|
530
|
+
if (takesControlCodes(stream, env)) {
|
|
531
|
+
const { theme } = activeTheme();
|
|
532
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
533
|
+
}
|
|
303
534
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
304
535
|
}
|
|
305
536
|
function ok(text, detail) {
|
|
306
|
-
console.log(marked("ok", text,
|
|
537
|
+
console.log(marked("ok", text, process6.stdout, detail));
|
|
307
538
|
}
|
|
308
539
|
function note(text, detail) {
|
|
309
|
-
console.log(marked("note", text,
|
|
540
|
+
console.log(marked("note", text, process6.stdout, detail));
|
|
310
541
|
}
|
|
311
542
|
function problem(text, detail) {
|
|
312
|
-
console.error(marked("problem", text,
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
var STATUSES = {
|
|
325
|
-
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
326
|
-
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
327
|
-
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
328
|
-
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
329
|
-
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
543
|
+
console.error(marked("problem", text, process6.stderr, detail));
|
|
544
|
+
}
|
|
545
|
+
function role(name, stream, env = process6.env) {
|
|
546
|
+
const colors = paint(stream, env);
|
|
547
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
548
|
+
}
|
|
549
|
+
var STATUS_WORDS = {
|
|
550
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
551
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
552
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
553
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
554
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
330
555
|
};
|
|
331
|
-
var STATUS_OF = new Map(Object.entries(
|
|
556
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
332
557
|
|
|
333
558
|
// ../kit/src/format.ts
|
|
334
559
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -367,15 +592,18 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
367
592
|
function textWidth(text) {
|
|
368
593
|
return Bun.stringWidth(text);
|
|
369
594
|
}
|
|
370
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
595
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
371
596
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
597
|
+
if (outputMode(stream, env) === "agent")
|
|
598
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
599
|
+
`);
|
|
372
600
|
const widths = [];
|
|
373
601
|
for (const row of cells) {
|
|
374
602
|
for (const [index, cell] of row.entries())
|
|
375
603
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
376
604
|
}
|
|
377
605
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
378
|
-
const colors = paint(
|
|
606
|
+
const colors = paint(stream);
|
|
379
607
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
380
608
|
const width = widths[index] ?? 0;
|
|
381
609
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -383,7 +611,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
383
611
|
return `${gap}${cell}`;
|
|
384
612
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
385
613
|
}).join(" ").trimEnd());
|
|
386
|
-
|
|
614
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
615
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
387
616
|
`);
|
|
388
617
|
}
|
|
389
618
|
function narrow(rows, widths, limit) {
|
|
@@ -402,32 +631,35 @@ function narrow(rows, widths, limit) {
|
|
|
402
631
|
}
|
|
403
632
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
404
633
|
}
|
|
634
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
635
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
636
|
+
}
|
|
405
637
|
function printJson(value) {
|
|
406
|
-
console.log(
|
|
638
|
+
console.log(jsonText(value));
|
|
407
639
|
}
|
|
408
640
|
|
|
409
641
|
// ../kit/src/help.ts
|
|
410
|
-
import
|
|
642
|
+
import process8 from "process";
|
|
411
643
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
412
644
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
413
645
|
var FULL_STOP = /\.$/;
|
|
414
|
-
function usageLine(usage, colors = paint(
|
|
646
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
415
647
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
416
648
|
}
|
|
417
|
-
function helpText(usage, options, colors = paint(
|
|
649
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
418
650
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
419
651
|
`);
|
|
420
652
|
}
|
|
421
|
-
function exitRows(exits, colors = paint(
|
|
653
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
422
654
|
if (exits.length === 0)
|
|
423
655
|
return [];
|
|
424
656
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
425
657
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
426
658
|
}
|
|
427
|
-
function replacesRows(replaces, colors = paint(
|
|
428
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
659
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
660
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
429
661
|
}
|
|
430
|
-
function wantsHelpJson(env =
|
|
662
|
+
function wantsHelpJson(env = process8.env) {
|
|
431
663
|
return env.KIT_HELP === "json";
|
|
432
664
|
}
|
|
433
665
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -446,12 +678,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
446
678
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
447
679
|
};
|
|
448
680
|
}
|
|
449
|
-
function exampleRows(examples, colors = paint(
|
|
450
|
-
if (examples.length === 0)
|
|
681
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
682
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
451
683
|
return [];
|
|
452
684
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
453
685
|
}
|
|
454
|
-
function optionRows(options, colors = paint(
|
|
686
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
455
687
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
456
688
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
457
689
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -544,7 +776,7 @@ var OUTPUT_OPTIONS = {
|
|
|
544
776
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
545
777
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
546
778
|
};
|
|
547
|
-
function applyOutput(color, plain, env =
|
|
779
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
548
780
|
const when = plain === true ? "never" : color ?? "auto";
|
|
549
781
|
if (when === "auto")
|
|
550
782
|
return;
|
|
@@ -715,7 +947,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
715
947
|
}
|
|
716
948
|
// ../kit/src/process.ts
|
|
717
949
|
import { constants } from "os";
|
|
718
|
-
import
|
|
950
|
+
import process10 from "process";
|
|
719
951
|
var KILL_GRACE_MS = 2000;
|
|
720
952
|
function exitCodeOf(code, signal) {
|
|
721
953
|
if (code !== null)
|
|
@@ -735,7 +967,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
735
967
|
return;
|
|
736
968
|
try {
|
|
737
969
|
if (grouped)
|
|
738
|
-
|
|
970
|
+
process10.kill(-proc.pid, killing);
|
|
739
971
|
else
|
|
740
972
|
proc.kill(killing);
|
|
741
973
|
} catch {}
|
|
@@ -810,10 +1042,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
810
1042
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
811
1043
|
|
|
812
1044
|
// ../kit/src/tool.ts
|
|
813
|
-
import
|
|
1045
|
+
import process11 from "process";
|
|
814
1046
|
function cwdGone() {
|
|
815
1047
|
try {
|
|
816
|
-
|
|
1048
|
+
process11.cwd();
|
|
817
1049
|
return false;
|
|
818
1050
|
} catch {
|
|
819
1051
|
return true;
|
|
@@ -835,7 +1067,7 @@ function spawnFailure(command, error) {
|
|
|
835
1067
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
836
1068
|
let ran;
|
|
837
1069
|
try {
|
|
838
|
-
ran = await runCommand(argv, { env:
|
|
1070
|
+
ran = await runCommand(argv, { env: process11.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
839
1071
|
} catch (error) {
|
|
840
1072
|
throw spawnFailure(label, error);
|
|
841
1073
|
}
|
|
@@ -850,15 +1082,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
850
1082
|
return { code: ran.code, ...streams };
|
|
851
1083
|
}
|
|
852
1084
|
// ../kit/src/cli.ts
|
|
853
|
-
import { readFileSync, realpathSync } from "fs";
|
|
854
|
-
import { dirname as
|
|
855
|
-
import
|
|
1085
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1086
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1087
|
+
import process13 from "process";
|
|
856
1088
|
|
|
857
1089
|
// ../kit/src/usage.ts
|
|
858
1090
|
import { appendFileSync, mkdirSync } from "fs";
|
|
859
|
-
import { homedir } from "os";
|
|
860
|
-
import { dirname, isAbsolute, join } from "path";
|
|
861
|
-
import
|
|
1091
|
+
import { homedir as homedir3 } from "os";
|
|
1092
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1093
|
+
import process12 from "process";
|
|
862
1094
|
|
|
863
1095
|
// ../kit/src/logs.ts
|
|
864
1096
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -872,14 +1104,14 @@ var usageError;
|
|
|
872
1104
|
function noteUsageError(message) {
|
|
873
1105
|
usageError = message;
|
|
874
1106
|
}
|
|
875
|
-
function stateHome(env =
|
|
1107
|
+
function stateHome(env = process12.env) {
|
|
876
1108
|
const dir = env.XDG_STATE_HOME;
|
|
877
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1109
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
878
1110
|
}
|
|
879
|
-
function usagePath(env =
|
|
880
|
-
return
|
|
1111
|
+
function usagePath(env = process12.env) {
|
|
1112
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
881
1113
|
}
|
|
882
|
-
function usageRecorded(env =
|
|
1114
|
+
function usageRecorded(env = process12.env) {
|
|
883
1115
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
884
1116
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
885
1117
|
}
|
|
@@ -893,12 +1125,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
893
1125
|
usageError = undefined;
|
|
894
1126
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
895
1127
|
}
|
|
896
|
-
function recordUsage(entry, env =
|
|
1128
|
+
function recordUsage(entry, env = process12.env) {
|
|
897
1129
|
if (!usageRecorded(env))
|
|
898
1130
|
return;
|
|
899
1131
|
try {
|
|
900
1132
|
const path = usagePath(env);
|
|
901
|
-
mkdirSync(
|
|
1133
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
902
1134
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
903
1135
|
`, { mode: 384 });
|
|
904
1136
|
} catch {}
|
|
@@ -984,8 +1216,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
984
1216
|
`);
|
|
985
1217
|
}
|
|
986
1218
|
function printError(prefix, message, hint, cause) {
|
|
987
|
-
const colors = paint(
|
|
988
|
-
const styled = takesControlCodes(
|
|
1219
|
+
const colors = paint(process13.stderr);
|
|
1220
|
+
const styled = takesControlCodes(process13.stderr);
|
|
989
1221
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
990
1222
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
991
1223
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1028,11 +1260,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1028
1260
|
}
|
|
1029
1261
|
}
|
|
1030
1262
|
if (name === undefined && level.path.length > 1) {
|
|
1031
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1263
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
1032
1264
|
return 2;
|
|
1033
1265
|
}
|
|
1034
1266
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1035
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1267
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
1036
1268
|
return 0;
|
|
1037
1269
|
}
|
|
1038
1270
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1149,17 +1381,17 @@ async function printCandidates(found) {
|
|
|
1149
1381
|
return 0;
|
|
1150
1382
|
}
|
|
1151
1383
|
function packageVersion(entry = Bun.main) {
|
|
1152
|
-
for (let dir =
|
|
1384
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1153
1385
|
try {
|
|
1154
|
-
const { version } = JSON.parse(
|
|
1386
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1155
1387
|
if (typeof version === "string")
|
|
1156
1388
|
return version;
|
|
1157
1389
|
} catch {}
|
|
1158
|
-
if (
|
|
1390
|
+
if (dirname3(dir) === dir)
|
|
1159
1391
|
return "0.0.0";
|
|
1160
1392
|
}
|
|
1161
1393
|
}
|
|
1162
|
-
async function runCli(cli, argv =
|
|
1394
|
+
async function runCli(cli, argv = process13.argv.slice(2)) {
|
|
1163
1395
|
const version = cli.version ?? packageVersion();
|
|
1164
1396
|
if (argv[0] === COMPLETE)
|
|
1165
1397
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1186,7 +1418,7 @@ function commandPath(scope, argv) {
|
|
|
1186
1418
|
}
|
|
1187
1419
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1188
1420
|
}
|
|
1189
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1421
|
+
async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
|
|
1190
1422
|
if (argv[0] === COMPLETE)
|
|
1191
1423
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1192
1424
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1206,6 +1438,19 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
|
|
|
1206
1438
|
}
|
|
1207
1439
|
return code;
|
|
1208
1440
|
}
|
|
1441
|
+
// ../kit/src/pool.ts
|
|
1442
|
+
async function pool(items, limit, task) {
|
|
1443
|
+
const results = Array.from({ length: items.length });
|
|
1444
|
+
let next = 0;
|
|
1445
|
+
async function worker() {
|
|
1446
|
+
while (next < items.length) {
|
|
1447
|
+
const index = next++;
|
|
1448
|
+
results[index] = await task(items[index]);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
1452
|
+
return results;
|
|
1453
|
+
}
|
|
1209
1454
|
// ../kit/src/secrets.ts
|
|
1210
1455
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1211
1456
|
// ../kit/src/sessions.ts
|
|
@@ -1222,34 +1467,41 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1222
1467
|
const suffix = match[2].toLowerCase();
|
|
1223
1468
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1224
1469
|
}
|
|
1225
|
-
// ../kit/src/
|
|
1226
|
-
import { existsSync } from "fs";
|
|
1227
|
-
import { homedir as
|
|
1228
|
-
import { join as
|
|
1229
|
-
import
|
|
1230
|
-
function
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1470
|
+
// ../kit/src/workspace-root.ts
|
|
1471
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1472
|
+
import { homedir as homedir4 } from "os";
|
|
1473
|
+
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1474
|
+
import process14 from "process";
|
|
1475
|
+
function expandHome(path, home) {
|
|
1476
|
+
if (path === "~")
|
|
1477
|
+
return home;
|
|
1478
|
+
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1479
|
+
}
|
|
1480
|
+
function configured(env, home) {
|
|
1481
|
+
const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
|
|
1482
|
+
if (!existsSync4(path))
|
|
1483
|
+
return;
|
|
1484
|
+
try {
|
|
1485
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1486
|
+
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1487
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1488
|
+
} catch {
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1236
1491
|
}
|
|
1237
|
-
function
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1240
|
-
return current;
|
|
1241
|
-
const base = configBase(where);
|
|
1242
|
-
return legacy.map((parts) => join3(base, ...parts)).find((path) => existsSync(path)) ?? current;
|
|
1492
|
+
function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
|
|
1493
|
+
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1494
|
+
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1243
1495
|
}
|
|
1244
1496
|
// src/audit.ts
|
|
1245
|
-
import { existsSync as
|
|
1497
|
+
import { existsSync as existsSync6, readdirSync, statSync as statSync2 } from "fs";
|
|
1246
1498
|
import { readdir } from "fs/promises";
|
|
1247
|
-
import { join as
|
|
1248
|
-
import
|
|
1499
|
+
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1500
|
+
import process16 from "process";
|
|
1249
1501
|
|
|
1250
1502
|
// src/report.ts
|
|
1251
|
-
import { existsSync as
|
|
1252
|
-
import { join as
|
|
1503
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
1504
|
+
import { join as join7 } from "path";
|
|
1253
1505
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1254
1506
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
1255
1507
|
var GHSA = /GHSA-[\w-]+$/;
|
|
@@ -1293,7 +1545,7 @@ function findingsOf(audit, reaching, direct, level, ignore = []) {
|
|
|
1293
1545
|
}
|
|
1294
1546
|
function readManifest(path) {
|
|
1295
1547
|
try {
|
|
1296
|
-
return
|
|
1548
|
+
return existsSync5(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
|
|
1297
1549
|
} catch {
|
|
1298
1550
|
return {};
|
|
1299
1551
|
}
|
|
@@ -1305,9 +1557,9 @@ function namesIn(manifest) {
|
|
|
1305
1557
|
});
|
|
1306
1558
|
}
|
|
1307
1559
|
function directDependencies(root, workspaces) {
|
|
1308
|
-
const names = new Set(namesIn(readManifest(
|
|
1560
|
+
const names = new Set(namesIn(readManifest(join7(root, "package.json"))));
|
|
1309
1561
|
for (const workspace of workspaces) {
|
|
1310
|
-
for (const name of namesIn(readManifest(
|
|
1562
|
+
for (const name of namesIn(readManifest(join7(root, workspace, "package.json"))))
|
|
1311
1563
|
names.add(name);
|
|
1312
1564
|
}
|
|
1313
1565
|
return names;
|
|
@@ -1319,8 +1571,8 @@ function workspacePatterns(field) {
|
|
|
1319
1571
|
return Array.isArray(packages) ? packages : [];
|
|
1320
1572
|
}
|
|
1321
1573
|
function workspaceFolders(root, children) {
|
|
1322
|
-
const patterns = workspacePatterns(readManifest(
|
|
1323
|
-
return patterns.filter((pattern) => typeof pattern === "string").flatMap((pattern) => pattern.endsWith("/*") ? children(pattern.slice(0, -2)).map((name) =>
|
|
1574
|
+
const patterns = workspacePatterns(readManifest(join7(root, "package.json")).workspaces);
|
|
1575
|
+
return patterns.filter((pattern) => typeof pattern === "string").flatMap((pattern) => pattern.endsWith("/*") ? children(pattern.slice(0, -2)).map((name) => join7(pattern.slice(0, -2), name)) : [pattern]);
|
|
1324
1576
|
}
|
|
1325
1577
|
|
|
1326
1578
|
// src/audit.ts
|
|
@@ -1341,7 +1593,7 @@ var MAX_DEPTH = 3;
|
|
|
1341
1593
|
var CONCURRENCY = 4;
|
|
1342
1594
|
var AUDIT_MS = 60000;
|
|
1343
1595
|
function holdsLock(dir) {
|
|
1344
|
-
return
|
|
1596
|
+
return existsSync6(join8(dir, "bun.lock")) || existsSync6(join8(dir, "bun.lockb"));
|
|
1345
1597
|
}
|
|
1346
1598
|
async function findRepos(root) {
|
|
1347
1599
|
if (holdsLock(root))
|
|
@@ -1357,7 +1609,7 @@ async function findRepos(root) {
|
|
|
1357
1609
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1358
1610
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith("."))
|
|
1359
1611
|
continue;
|
|
1360
|
-
const path =
|
|
1612
|
+
const path = join8(dir, entry.name);
|
|
1361
1613
|
if (holdsLock(path))
|
|
1362
1614
|
found.push(path);
|
|
1363
1615
|
else if (depth < MAX_DEPTH)
|
|
@@ -1367,22 +1619,10 @@ async function findRepos(root) {
|
|
|
1367
1619
|
await walk(root, 1);
|
|
1368
1620
|
return found;
|
|
1369
1621
|
}
|
|
1370
|
-
async function pool(items, limit, task) {
|
|
1371
|
-
const results = Array.from({ length: items.length });
|
|
1372
|
-
let next = 0;
|
|
1373
|
-
async function worker() {
|
|
1374
|
-
while (next < items.length) {
|
|
1375
|
-
const index = next++;
|
|
1376
|
-
results[index] = await task(items[index]);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
1380
|
-
return results;
|
|
1381
|
-
}
|
|
1382
1622
|
function children(root) {
|
|
1383
1623
|
return (folder) => {
|
|
1384
1624
|
try {
|
|
1385
|
-
return readdirSync(
|
|
1625
|
+
return readdirSync(join8(root, folder), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
1386
1626
|
} catch {
|
|
1387
1627
|
return [];
|
|
1388
1628
|
}
|
|
@@ -1409,7 +1649,7 @@ function failure(ran) {
|
|
|
1409
1649
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1410
1650
|
}
|
|
1411
1651
|
function tint(severity) {
|
|
1412
|
-
const colors = paint(
|
|
1652
|
+
const colors = paint(process16.stdout);
|
|
1413
1653
|
if (severity === "critical" || severity === "high")
|
|
1414
1654
|
return colors.red;
|
|
1415
1655
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1426,8 +1666,8 @@ function rows(findings) {
|
|
|
1426
1666
|
}
|
|
1427
1667
|
async function audit(args) {
|
|
1428
1668
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
|
|
1429
|
-
const root =
|
|
1430
|
-
if (!
|
|
1669
|
+
const root = resolve4(positionals[0] ?? ".");
|
|
1670
|
+
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1431
1671
|
fail(`no folder ${root}`);
|
|
1432
1672
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1433
1673
|
const paths = await findRepos(root);
|
|
@@ -1444,8 +1684,8 @@ async function audit(args) {
|
|
|
1444
1684
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1445
1685
|
}
|
|
1446
1686
|
function show(audits, total) {
|
|
1447
|
-
const label = role("label",
|
|
1448
|
-
const path = role("path",
|
|
1687
|
+
const label = role("label", process16.stdout);
|
|
1688
|
+
const path = role("path", process16.stdout);
|
|
1449
1689
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1450
1690
|
if (flagged.length === 0) {
|
|
1451
1691
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1459,4 +1699,4 @@ function show(audits, total) {
|
|
|
1459
1699
|
}
|
|
1460
1700
|
|
|
1461
1701
|
// src/audit-cli.ts
|
|
1462
|
-
|
|
1702
|
+
process17.exitCode = await runMain({ name: "audit", run: audit });
|