@kaynooo/cli-check 0.18.1 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fix-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/fix-cli.ts
5
- import process19 from "process";
5
+ import process20 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process10 from "process";
8
8
  import { parseArgs } from "util";
@@ -780,9 +780,33 @@ function nearestOption(message, options, allowNegative) {
780
780
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
781
781
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
782
782
  }
783
+ // ../kit/src/argv.ts
784
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
785
+ import { resolve as resolve3 } from "path";
786
+ import process11 from "process";
787
+ function commandLine() {
788
+ try {
789
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
790
+ } catch {
791
+ return;
792
+ }
793
+ }
794
+ function realPath(word) {
795
+ try {
796
+ return realpathSync(resolve3(word));
797
+ } catch {
798
+ return;
799
+ }
800
+ }
801
+ function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
802
+ const target = script === undefined ? undefined : realPath(script) ?? script;
803
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
804
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
805
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
806
+ }
783
807
  // ../kit/src/process.ts
784
808
  import { constants } from "os";
785
- import process11 from "process";
809
+ import process12 from "process";
786
810
  var KILL_GRACE_MS = 2000;
787
811
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
788
812
  function exitCodeOf(code, signal) {
@@ -804,7 +828,7 @@ function holdSignals(cleanup) {
804
828
  },
805
829
  release: () => {
806
830
  for (const signal of SIGNALS)
807
- process11.off(signal, onSignal);
831
+ process12.off(signal, onSignal);
808
832
  }
809
833
  };
810
834
  function onSignal(signal) {
@@ -817,10 +841,10 @@ function holdSignals(cleanup) {
817
841
  return;
818
842
  held.release();
819
843
  cleanup(signal);
820
- process11.kill(process11.pid, signal);
844
+ process12.kill(process12.pid, signal);
821
845
  }
822
846
  for (const signal of SIGNALS)
823
- process11.on(signal, onSignal);
847
+ process12.on(signal, onSignal);
824
848
  return held;
825
849
  }
826
850
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -834,7 +858,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
834
858
  return;
835
859
  try {
836
860
  if (grouped)
837
- process11.kill(-proc.pid, killing);
861
+ process12.kill(-proc.pid, killing);
838
862
  else
839
863
  proc.kill(killing);
840
864
  } catch {}
@@ -908,33 +932,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
908
932
  var RESET_STYLE = `${ESC}[0m`;
909
933
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
910
934
  // ../kit/src/cli.ts
911
- import { readFileSync as readFileSync3, realpathSync } from "fs";
935
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
912
936
  import { dirname as dirname3, join as join6 } from "path";
913
- import process14 from "process";
937
+ import process15 from "process";
914
938
 
915
939
  // ../kit/src/usage.ts
916
940
  import { appendFileSync, mkdirSync } from "fs";
917
941
  import { homedir as homedir4 } from "os";
918
942
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
919
- import process13 from "process";
943
+ import process14 from "process";
920
944
 
921
945
  // ../kit/src/logs.ts
922
946
  import { lstatSync, openSync } from "fs";
923
947
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
924
948
  import { homedir as homedir3, tmpdir } from "os";
925
949
  import { join as join4 } from "path";
926
- import process12 from "process";
950
+ import process13 from "process";
927
951
  var DAY_MS = 24 * 60 * 60 * 1000;
928
952
  var CLI_FOLDER = "kaynooo-cli";
929
953
  function isPrivateDirectory(path) {
930
954
  try {
931
955
  const info = lstatSync(path, { throwIfNoEntry: false });
932
- return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
956
+ return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
933
957
  } catch {
934
958
  return false;
935
959
  }
936
960
  }
937
- async function privateLogDirectory(name, env = process12.env) {
961
+ async function privateLogDirectory(name, env = process13.env) {
938
962
  const runtime = env.XDG_RUNTIME_DIR;
939
963
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
940
964
  const path = join4(base, name);
@@ -974,14 +998,14 @@ var usageError;
974
998
  function noteUsageError(message) {
975
999
  usageError = message;
976
1000
  }
977
- function stateHome(env = process13.env) {
1001
+ function stateHome(env = process14.env) {
978
1002
  const dir = env.XDG_STATE_HOME;
979
1003
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
980
1004
  }
981
- function usagePath(env = process13.env) {
1005
+ function usagePath(env = process14.env) {
982
1006
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
983
1007
  }
984
- function usageRecorded(env = process13.env) {
1008
+ function usageRecorded(env = process14.env) {
985
1009
  const off = env.KAYNOOO_CLI_NO_USAGE;
986
1010
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
987
1011
  }
@@ -995,7 +1019,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
995
1019
  usageError = undefined;
996
1020
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
997
1021
  }
998
- function recordUsage(entry, env = process13.env) {
1022
+ function recordUsage(entry, env = process14.env) {
999
1023
  if (!usageRecorded(env))
1000
1024
  return;
1001
1025
  try {
@@ -1013,8 +1037,8 @@ var LEVEL_OPTIONS = {
1013
1037
  };
1014
1038
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1015
1039
  function printError(prefix, message, hint, cause) {
1016
- const colors = paint(process14.stderr);
1017
- const styled = takesControlCodes(process14.stderr);
1040
+ const colors = paint(process15.stderr);
1041
+ const styled = takesControlCodes(process15.stderr);
1018
1042
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1019
1043
  const under = (label, text, tint) => text === undefined ? "" : `
1020
1044
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1058,24 +1082,24 @@ function candidateLine(candidate) {
1058
1082
  }
1059
1083
  function positionalBeingTyped(before, { options, positionals }) {
1060
1084
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1061
- let index = 0;
1085
+ const typed = [];
1062
1086
  let at = 0;
1063
1087
  while (at < before.length) {
1064
1088
  const word = before[at];
1065
1089
  if (word === "--") {
1066
- index += before.length - at - 1;
1090
+ typed.push(...before.slice(at + 1));
1067
1091
  break;
1068
1092
  }
1069
1093
  if (!word.startsWith("-"))
1070
- index++;
1094
+ typed.push(word);
1071
1095
  else if (takesValue(word))
1072
1096
  at++;
1073
1097
  at++;
1074
1098
  }
1075
1099
  const last = positionals.at(-1);
1076
- if (index < positionals.length)
1077
- return positionals[index];
1078
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1100
+ if (typed.length < positionals.length)
1101
+ return { name: positionals[typed.length], typed };
1102
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1079
1103
  }
1080
1104
  async function leafCandidates(run, words) {
1081
1105
  const completing = await completingOf(run);
@@ -1083,12 +1107,12 @@ async function leafCandidates(run, words) {
1083
1107
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1084
1108
  const flag = words.at(-2);
1085
1109
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1110
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1086
1111
  if (option?.type === "string") {
1087
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1112
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1088
1113
  return values === undefined ? [FILES] : values.map(candidateLine);
1089
1114
  }
1090
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1091
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1115
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1092
1116
  return values === undefined ? [FILES] : values.map(candidateLine);
1093
1117
  }
1094
1118
  async function printCandidates(found) {
@@ -1097,9 +1121,9 @@ async function printCandidates(found) {
1097
1121
  return 0;
1098
1122
  }
1099
1123
  function packageVersion(entry = Bun.main) {
1100
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1124
+ for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1101
1125
  try {
1102
- const { version } = JSON.parse(readFileSync3(join6(dir, "package.json"), "utf8"));
1126
+ const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1103
1127
  if (typeof version === "string")
1104
1128
  return version;
1105
1129
  } catch {}
@@ -1107,7 +1131,7 @@ function packageVersion(entry = Bun.main) {
1107
1131
  return "0.0.0";
1108
1132
  }
1109
1133
  }
1110
- async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1134
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1111
1135
  if (argv[0] === COMPLETE)
1112
1136
  return printCandidates(leafCandidates(run, argv.slice(1)));
1113
1137
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1141,13 +1165,13 @@ var {Glob } = globalThis.Bun;
1141
1165
  var SESSION_FILES = new Glob("*.json");
1142
1166
  var ACCOUNT_DIRS = new Glob("*/sessions");
1143
1167
  // package.json
1144
- var version = "0.18.1";
1168
+ var version = "0.18.2";
1145
1169
 
1146
1170
  // src/fix.ts
1147
1171
  import { existsSync as existsSync5, statSync as statSync2 } from "fs";
1148
1172
  import { rename, writeFile as writeFile2 } from "fs/promises";
1149
1173
  import { join as join11 } from "path";
1150
- import process18 from "process";
1174
+ import process19 from "process";
1151
1175
 
1152
1176
  // src/changes.ts
1153
1177
  import { stat as stat2 } from "fs/promises";
@@ -1175,8 +1199,8 @@ function changedFiles(before, after) {
1175
1199
  // src/compose.ts
1176
1200
  import { existsSync as existsSync4 } from "fs";
1177
1201
  import { homedir as homedir5 } from "os";
1178
- import { basename, dirname as dirname4, join as join8, relative, resolve as resolve3 } from "path";
1179
- import process16 from "process";
1202
+ import { basename, dirname as dirname4, join as join8, relative, resolve as resolve4 } from "path";
1203
+ import process17 from "process";
1180
1204
 
1181
1205
  // ../kit/src/shell.ts
1182
1206
  var SEPARATORS = new Set([`
@@ -1269,7 +1293,7 @@ async function variables(composeDir) {
1269
1293
  if (match !== null && !line.trimStart().startsWith("#"))
1270
1294
  env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
1271
1295
  }
1272
- for (const [key, value] of Object.entries(process16.env)) {
1296
+ for (const [key, value] of Object.entries(process17.env)) {
1273
1297
  if (value !== undefined)
1274
1298
  env[key] = value;
1275
1299
  }
@@ -1291,8 +1315,8 @@ function bindSource(source, composeDir, env) {
1291
1315
  if (path.startsWith("~"))
1292
1316
  return join8(homedir5(), path.slice(1));
1293
1317
  if (path.startsWith("/"))
1294
- return resolve3(path);
1295
- return path.startsWith(".") ? resolve3(composeDir, path) : undefined;
1318
+ return resolve4(path);
1319
+ return path.startsWith(".") ? resolve4(composeDir, path) : undefined;
1296
1320
  }
1297
1321
  function mountsOf(volumes, composeDir, env) {
1298
1322
  if (!Array.isArray(volumes))
@@ -1334,7 +1358,7 @@ async function composeFiles(composeDir, env) {
1334
1358
  const files = [];
1335
1359
  const separator = env.COMPOSE_PATH_SEPARATOR;
1336
1360
  for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
1337
- const file = Bun.file(resolve3(composeDir, name));
1361
+ const file = Bun.file(resolve4(composeDir, name));
1338
1362
  if (!await file.exists())
1339
1363
  fail(`COMPOSE_FILE names ${join8(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
1340
1364
  files.push({ name, text: await file.text() });
@@ -1405,7 +1429,7 @@ async function place(dir, program, { service, host } = {}) {
1405
1429
  fail(`--in ${service}: no compose project mounts ${dir}`);
1406
1430
  return;
1407
1431
  }
1408
- if (Bun.which("docker", { PATH: process16.env.PATH ?? "" }) === null) {
1432
+ if (Bun.which("docker", { PATH: process17.env.PATH ?? "" }) === null) {
1409
1433
  if (service !== undefined)
1410
1434
  fail(`--in ${service}: docker not found`);
1411
1435
  if (!noticed.has(found.composeDir)) {
@@ -1457,7 +1481,7 @@ class Stack {
1457
1481
  }
1458
1482
  static async running(composeDir) {
1459
1483
  try {
1460
- const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process16.env, timeoutMs: PS_TIMEOUT_MS });
1484
+ const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process17.env, timeoutMs: PS_TIMEOUT_MS });
1461
1485
  if (ran.code !== 0)
1462
1486
  return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
1463
1487
  `).at(-1) ?? `exit ${ran.code}`}`;
@@ -1525,6 +1549,7 @@ import { join as join9 } from "path";
1525
1549
  var STEP_NAMES = ["check", "typecheck", "lint", "test"];
1526
1550
  var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
1527
1551
  var JUSTFILES = ["justfile", "Justfile", ".justfile"];
1552
+ var TASK_RUNNERS = new Set(["Justfile", "Makefile"]);
1528
1553
  var MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
1529
1554
  var CS_FIXER_CONFIGS = [".php-cs-fixer.php", ".php-cs-fixer.dist.php"];
1530
1555
  var JUST_TIMEOUT_MS = 1e4;
@@ -1636,8 +1661,9 @@ async function discoverProjects(dir) {
1636
1661
  }
1637
1662
  async function discover(dir) {
1638
1663
  const found = await candidates(dir, "check");
1664
+ const runnerCheck = found.find((candidate) => candidate.name === "check" && TASK_RUNNERS.has(candidate.source));
1639
1665
  return STEP_NAMES.flatMap((name) => {
1640
- const step = found.find((candidate) => candidate.name === name);
1666
+ const step = name === "check" && runnerCheck !== undefined ? runnerCheck : found.find((candidate) => candidate.name === name);
1641
1667
  return step === undefined ? [] : [step];
1642
1668
  });
1643
1669
  }
@@ -1674,7 +1700,7 @@ function pick(steps, only, noun = "step") {
1674
1700
  // src/run.ts
1675
1701
  import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
1676
1702
  import { basename as basename2, join as join10 } from "path";
1677
- import process17 from "process";
1703
+ import process18 from "process";
1678
1704
 
1679
1705
  // src/e2e.ts
1680
1706
  var E2E_NOISE = [
@@ -2309,7 +2335,7 @@ var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
2309
2335
  async function logDirectory(cwd) {
2310
2336
  const root = await privateLogDirectory("check");
2311
2337
  await sweepLogs(root, LOG_MAX_AGE_MS);
2312
- const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process17.pid}`);
2338
+ const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process18.pid}`);
2313
2339
  await mkdir2(path, { mode: 448 });
2314
2340
  return path;
2315
2341
  }
@@ -2335,7 +2361,7 @@ async function lastFailed(cwd) {
2335
2361
  async function saveLog(output) {
2336
2362
  const root = await privateLogDirectory("errs");
2337
2363
  await sweepLogs(root);
2338
- const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process17.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2364
+ const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process18.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
2339
2365
  await writeFile(path, output, { mode: 384, flag: "wx" });
2340
2366
  return path;
2341
2367
  }
@@ -2343,7 +2369,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
2343
2369
  const started = Date.now();
2344
2370
  const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
2345
2371
  cwd,
2346
- env: { ...process17.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2372
+ env: { ...process18.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
2347
2373
  ...timeoutMs === undefined ? {} : { timeoutMs },
2348
2374
  ...held === undefined ? {} : { onStart: (child) => held.forward(child) }
2349
2375
  });
@@ -2359,8 +2385,8 @@ function outcomeJson(name, command, logFile, outcome, service) {
2359
2385
  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) } };
2360
2386
  }
2361
2387
  function printOutcome(name, width, command, logFile, outcome) {
2362
- const colors = paint(process17.stdout);
2363
- const path = role("path", process17.stdout);
2388
+ const colors = paint(process18.stdout);
2389
+ const path = role("path", process18.stdout);
2364
2390
  const took = colors.dim(formatDuration(outcome.ms));
2365
2391
  if (outcome.ok) {
2366
2392
  console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
@@ -2391,7 +2417,7 @@ var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
2391
2417
  var RUFF_SECTION = /^\[tool\.ruff/m;
2392
2418
  var MAX_CHANGED = 30;
2393
2419
  async function replaceFile(path, content) {
2394
- const temporary = `${path}.${process18.pid}.tmp`;
2420
+ const temporary = `${path}.${process19.pid}.tmp`;
2395
2421
  await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
2396
2422
  await rename(temporary, path);
2397
2423
  }
@@ -2463,14 +2489,14 @@ function printChanged(changed) {
2463
2489
  if (changed.length > MAX_CHANGED)
2464
2490
  console.log(` and ${changed.length - MAX_CHANGED} more`);
2465
2491
  }
2466
- async function fix(args, cwd = process18.cwd()) {
2492
+ async function fix(args, cwd = process19.cwd()) {
2467
2493
  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"]] });
2468
2494
  return runFixers(parsed.values, cwd);
2469
2495
  }
2470
2496
  async function runFixers(values, cwd) {
2471
2497
  const parsed = { values };
2472
2498
  const settings = placeSettings(values);
2473
- if (process18.env[RUNNING] !== undefined)
2499
+ if (process19.env[RUNNING] !== undefined)
2474
2500
  fail("a fixer called fix again, which would recurse: give its script another command");
2475
2501
  const found = await fixers(cwd);
2476
2502
  if (found.length === 0)
@@ -2504,7 +2530,7 @@ async function runFixers(values, cwd) {
2504
2530
  break;
2505
2531
  if (missing(fixer)) {
2506
2532
  if (!json)
2507
- console.log(`${paint(process18.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
2533
+ console.log(`${paint(process19.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
2508
2534
  ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
2509
2535
  continue;
2510
2536
  }
@@ -2537,4 +2563,4 @@ async function runFixers(values, cwd) {
2537
2563
  }
2538
2564
 
2539
2565
  // src/fix-cli.ts
2540
- process19.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });
2566
+ process20.exitCode = await runMain({ name: "fix", version, run: async (args) => fix(args) });