@kaynooo/cli-workspace 0.10.1 → 0.10.3

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/dist/audit-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/audit-cli.ts
5
- import process18 from "process";
5
+ import process19 from "process";
6
6
 
7
7
  // ../kit/src/advisory.ts
8
8
  var SEVERITIES = ["low", "moderate", "high", "critical"];
@@ -498,18 +498,14 @@ var FULL_STOP = /\.$/;
498
498
  function usageLine(usage, colors = paint(process8.stdout)) {
499
499
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
500
500
  }
501
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
502
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
501
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
502
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
503
503
  `);
504
504
  }
505
505
  function exitRows(exits, colors = paint(process8.stdout)) {
506
506
  if (exits.length === 0)
507
507
  return [];
508
- const width = Math.max(...exits.map(([code]) => String(code).length));
509
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
510
- }
511
- function replacesRows(replaces, colors = paint(process8.stdout)) {
512
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
508
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
513
509
  }
514
510
  function wantsHelpJson(env = process8.env) {
515
511
  return env.KIT_HELP === "json";
@@ -796,9 +792,33 @@ function nearestOption(message, options, allowNegative) {
796
792
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
797
793
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
798
794
  }
795
+ // ../kit/src/argv.ts
796
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
797
+ import { resolve as resolve3 } from "path";
798
+ import process10 from "process";
799
+ function commandLine() {
800
+ try {
801
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
802
+ } catch {
803
+ return;
804
+ }
805
+ }
806
+ function realPath(word) {
807
+ try {
808
+ return realpathSync(resolve3(word));
809
+ } catch {
810
+ return;
811
+ }
812
+ }
813
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
814
+ const target = script === undefined ? undefined : realPath(script) ?? script;
815
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
816
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
817
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
818
+ }
799
819
  // ../kit/src/process.ts
800
820
  import { constants } from "os";
801
- import process10 from "process";
821
+ import process11 from "process";
802
822
  var KILL_GRACE_MS = 2000;
803
823
  function exitCodeOf(code, signal) {
804
824
  if (code !== null)
@@ -818,7 +838,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
818
838
  return;
819
839
  try {
820
840
  if (grouped)
821
- process10.kill(-proc.pid, killing);
841
+ process11.kill(-proc.pid, killing);
822
842
  else
823
843
  proc.kill(killing);
824
844
  } catch {}
@@ -893,10 +913,10 @@ var RESET_STYLE = `${ESC}[0m`;
893
913
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
894
914
 
895
915
  // ../kit/src/tool.ts
896
- import process11 from "process";
916
+ import process12 from "process";
897
917
  function cwdGone() {
898
918
  try {
899
- process11.cwd();
919
+ process12.cwd();
900
920
  return false;
901
921
  } catch {
902
922
  return true;
@@ -918,7 +938,7 @@ function spawnFailure(command, error) {
918
938
  async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
919
939
  let ran;
920
940
  try {
921
- ran = await runCommand(argv, { env: process11.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
941
+ ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
922
942
  } catch (error) {
923
943
  throw spawnFailure(label, error);
924
944
  }
@@ -933,15 +953,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
933
953
  return { code: ran.code, ...streams };
934
954
  }
935
955
  // ../kit/src/cli.ts
936
- import { readFileSync as readFileSync3, realpathSync } from "fs";
956
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
937
957
  import { dirname as dirname3, join as join5 } from "path";
938
- import process13 from "process";
958
+ import process14 from "process";
939
959
 
940
960
  // ../kit/src/usage.ts
941
961
  import { appendFileSync, mkdirSync } from "fs";
942
962
  import { homedir as homedir3 } from "os";
943
963
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
944
- import process12 from "process";
964
+ import process13 from "process";
945
965
 
946
966
  // ../kit/src/logs.ts
947
967
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -955,14 +975,14 @@ var usageError;
955
975
  function noteUsageError(message) {
956
976
  usageError = message;
957
977
  }
958
- function stateHome(env = process12.env) {
978
+ function stateHome(env = process13.env) {
959
979
  const dir = env.XDG_STATE_HOME;
960
980
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
961
981
  }
962
- function usagePath(env = process12.env) {
982
+ function usagePath(env = process13.env) {
963
983
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
964
984
  }
965
- function usageRecorded(env = process12.env) {
985
+ function usageRecorded(env = process13.env) {
966
986
  const off = env.KAYNOOO_CLI_NO_USAGE;
967
987
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
968
988
  }
@@ -976,7 +996,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
976
996
  usageError = undefined;
977
997
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
978
998
  }
979
- function recordUsage(entry, env = process12.env) {
999
+ function recordUsage(entry, env = process13.env) {
980
1000
  if (!usageRecorded(env))
981
1001
  return;
982
1002
  try {
@@ -1053,7 +1073,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1053
1073
  header(colors, summary),
1054
1074
  "",
1055
1075
  usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
1056
- ...replacesRows(replaces, colors),
1057
1076
  "",
1058
1077
  ...await commandRows(commands, colors),
1059
1078
  ...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
@@ -1067,8 +1086,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1067
1086
  `);
1068
1087
  }
1069
1088
  function printError(prefix, message, hint, cause) {
1070
- const colors = paint(process13.stderr);
1071
- const styled = takesControlCodes(process13.stderr);
1089
+ const colors = paint(process14.stderr);
1090
+ const styled = takesControlCodes(process14.stderr);
1072
1091
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1073
1092
  const under = (label, text, tint) => text === undefined ? "" : `
1074
1093
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1111,11 +1130,11 @@ async function dispatch(level, typed, { version, redact }) {
1111
1130
  }
1112
1131
  }
1113
1132
  if (name === undefined && level.path.length > 1) {
1114
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
1133
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1115
1134
  return 2;
1116
1135
  }
1117
1136
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1118
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
1137
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1119
1138
  return 0;
1120
1139
  }
1121
1140
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1171,24 +1190,24 @@ function candidateLine(candidate) {
1171
1190
  }
1172
1191
  function positionalBeingTyped(before, { options, positionals }) {
1173
1192
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1174
- let index = 0;
1193
+ const typed = [];
1175
1194
  let at = 0;
1176
1195
  while (at < before.length) {
1177
1196
  const word = before[at];
1178
1197
  if (word === "--") {
1179
- index += before.length - at - 1;
1198
+ typed.push(...before.slice(at + 1));
1180
1199
  break;
1181
1200
  }
1182
1201
  if (!word.startsWith("-"))
1183
- index++;
1202
+ typed.push(word);
1184
1203
  else if (takesValue(word))
1185
1204
  at++;
1186
1205
  at++;
1187
1206
  }
1188
1207
  const last = positionals.at(-1);
1189
- if (index < positionals.length)
1190
- return positionals[index];
1191
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1208
+ if (typed.length < positionals.length)
1209
+ return { name: positionals[typed.length], typed };
1210
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1192
1211
  }
1193
1212
  async function leafCandidates(run, words) {
1194
1213
  const completing = await completingOf(run);
@@ -1196,12 +1215,12 @@ async function leafCandidates(run, words) {
1196
1215
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1197
1216
  const flag = words.at(-2);
1198
1217
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1218
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1199
1219
  if (option?.type === "string") {
1200
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1220
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1201
1221
  return values === undefined ? [FILES] : values.map(candidateLine);
1202
1222
  }
1203
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1204
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1223
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1205
1224
  return values === undefined ? [FILES] : values.map(candidateLine);
1206
1225
  }
1207
1226
  async function candidates(scope, defaultCommand, words, before = []) {
@@ -1232,9 +1251,13 @@ async function printCandidates(found) {
1232
1251
  return 0;
1233
1252
  }
1234
1253
  function packageVersion(entry = Bun.main) {
1235
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1254
+ let resolved = entry;
1255
+ try {
1256
+ resolved = realpathSync2(entry);
1257
+ } catch {}
1258
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1236
1259
  try {
1237
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1260
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1238
1261
  if (typeof version === "string")
1239
1262
  return version;
1240
1263
  } catch {}
@@ -1242,7 +1265,7 @@ function packageVersion(entry = Bun.main) {
1242
1265
  return "0.0.0";
1243
1266
  }
1244
1267
  }
1245
- async function runCli(cli, argv = process13.argv.slice(2)) {
1268
+ async function runCli(cli, argv = scriptArgs()) {
1246
1269
  const version = cli.version ?? packageVersion();
1247
1270
  if (argv[0] === COMPLETE)
1248
1271
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1269,7 +1292,7 @@ function commandPath(scope, argv) {
1269
1292
  }
1270
1293
  return path.length === 0 ? undefined : path.join(" ");
1271
1294
  }
1272
- async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
1295
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1273
1296
  if (argv[0] === COMPLETE)
1274
1297
  return printCandidates(leafCandidates(run, argv.slice(1)));
1275
1298
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1321,7 +1344,7 @@ function parseSize(text, bareUnit = 1) {
1321
1344
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1322
1345
  }
1323
1346
  // ../kit/src/watch.ts
1324
- import process14 from "process";
1347
+ import process15 from "process";
1325
1348
  import { format } from "util";
1326
1349
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1327
1350
  var DEFAULT_SECONDS = 2;
@@ -1343,7 +1366,7 @@ function withoutWatch(args) {
1343
1366
  }
1344
1367
  return rest;
1345
1368
  }
1346
- async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1369
+ async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1347
1370
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1348
1371
  if (!takesControlCodes(stream))
1349
1372
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1351,12 +1374,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1351
1374
  for (let round = 0;round < rounds; round++) {
1352
1375
  const held = [];
1353
1376
  const { log, info } = console;
1354
- const write = process14.stdout.write.bind(process14.stdout);
1377
+ const write = process15.stdout.write.bind(process15.stdout);
1355
1378
  const hold = (...parts) => void held.push(`${format(...parts)}
1356
1379
  `);
1357
1380
  console.log = hold;
1358
1381
  console.info = hold;
1359
- process14.stdout.write = (text) => {
1382
+ process15.stdout.write = (text) => {
1360
1383
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1361
1384
  return true;
1362
1385
  };
@@ -1365,7 +1388,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1365
1388
  } finally {
1366
1389
  console.log = log;
1367
1390
  console.info = info;
1368
- process14.stdout.write = write;
1391
+ process15.stdout.write = write;
1369
1392
  }
1370
1393
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1371
1394
  await sleep(interval);
@@ -1374,8 +1397,8 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1374
1397
  }
1375
1398
  // ../kit/src/workspace-root.ts
1376
1399
  import { homedir as homedir4 } from "os";
1377
- import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
1378
- import process15 from "process";
1400
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1401
+ import process16 from "process";
1379
1402
  function expandHome(path, home) {
1380
1403
  if (path === "~")
1381
1404
  return home;
@@ -1385,18 +1408,18 @@ function configured(env, home) {
1385
1408
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1386
1409
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1387
1410
  }
1388
- function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
1411
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1389
1412
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1390
- return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1413
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1391
1414
  }
1392
1415
  // src/audit.ts
1393
- import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
1416
+ import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
1394
1417
  import { readdir } from "fs/promises";
1395
- import { join as join8, relative, resolve as resolve4 } from "path";
1396
- import process17 from "process";
1418
+ import { join as join8, relative, resolve as resolve5 } from "path";
1419
+ import process18 from "process";
1397
1420
 
1398
1421
  // src/report.ts
1399
- import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
1422
+ import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
1400
1423
  import { join as join7 } from "path";
1401
1424
  var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
1402
1425
  var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
@@ -1480,7 +1503,7 @@ function reachedFrom(graph, direct, targets) {
1480
1503
  }
1481
1504
  function readManifest(path) {
1482
1505
  try {
1483
- return existsSync4(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
1506
+ return existsSync4(path) ? JSON.parse(readFileSync5(path, "utf8")) : {};
1484
1507
  } catch {
1485
1508
  return {};
1486
1509
  }
@@ -1585,7 +1608,7 @@ async function audited(path, shown, level, ignore) {
1585
1608
  }
1586
1609
  function lockText(path) {
1587
1610
  try {
1588
- return readFileSync5(join8(path, "bun.lock"), "utf8");
1611
+ return readFileSync6(join8(path, "bun.lock"), "utf8");
1589
1612
  } catch {
1590
1613
  return "";
1591
1614
  }
@@ -1605,7 +1628,7 @@ function failure(ran) {
1605
1628
  `).at(-1) ?? `exit ${ran.code}`;
1606
1629
  }
1607
1630
  function tint(severity) {
1608
- const colors = paint(process17.stdout);
1631
+ const colors = paint(process18.stdout);
1609
1632
  if (severity === "critical" || severity === "high")
1610
1633
  return colors.red;
1611
1634
  return severity === "moderate" ? colors.yellow : colors.dim;
@@ -1622,7 +1645,7 @@ function rows(findings) {
1622
1645
  }
1623
1646
  async function audit(args) {
1624
1647
  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"] });
1625
- const root = resolve4(positionals[0] ?? ".");
1648
+ const root = resolve5(positionals[0] ?? ".");
1626
1649
  if (!existsSync5(root) || !statSync2(root).isDirectory())
1627
1650
  fail(`no folder ${root}`);
1628
1651
  const level = oneOf(values.level, "level", SEVERITIES);
@@ -1640,8 +1663,8 @@ async function audit(args) {
1640
1663
  return kept.some((each) => each.findings.length > 0) ? 1 : 0;
1641
1664
  }
1642
1665
  function show(audits, total) {
1643
- const label = role("label", process17.stdout);
1644
- const path = role("path", process17.stdout);
1666
+ const label = role("label", process18.stdout);
1667
+ const path = role("path", process18.stdout);
1645
1668
  const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
1646
1669
  if (flagged.length === 0) {
1647
1670
  console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
@@ -1661,4 +1684,4 @@ function show(audits, total) {
1661
1684
  }
1662
1685
 
1663
1686
  // src/audit-cli.ts
1664
- process18.exitCode = await runMain({ name: "audit", run: audit });
1687
+ process19.exitCode = await runMain({ name: "audit", run: audit });