@kaynooo/cli-pkg 0.13.2 → 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.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/dist/cli.js +170 -75
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -67,6 +67,16 @@ pkg bump @kaynooo/cli-kit 0.8.0 --dry-run
67
67
 
68
68
  The metadata comes from the registry the name is installed from. A `@scope/` name follows `@scope:registry=` in the nearest `.npmrc` or `[install.scopes]` in the nearest `bunfig.toml`, walking up from the current directory and ending at the home directory, and a scope key wins over a nearer plain `registry=`, as it does for npm; the token (`_authToken`, or `token` in bunfig, with `${VAR}` or `$VAR` expanded) is sent to that registry only, matched on a path boundary, over https (or http to localhost) only, and never printed. Environment variables are expanded in tokens only, never in a registry address. Every request has a 10 s deadline. Downloads come from the npmjs.org API, so they show `-` for any other registry. A registry that does not return publish times (Forgejo's does not) leaves the age unchecked, which `pkg` says in a warning.
69
69
 
70
+ ## The folder's package manager
71
+
72
+ ```sh
73
+ pkg manager dev
74
+ ```
75
+
76
+ `pkg manager <install|dev|remove|update|exec>` prints the command the manager of this folder runs for the action, such as `bun add -d`, `composer require --dev` or `pnpm dlx`. The manager is the one whose lockfile (`bun.lock`, `bun.lockb`, `yarn.lock`, `pnpm-lock.yaml`, `package-lock.json`, `uv.lock`) or `composer.json` is nearest, here or in a parent folder, bun when none is found. `--json` prints `{manager, action, command}`.
77
+
78
+ A shell abbreviation can call it through a small function, in fish `function __nd; pkg manager dev; end` then `abbr -a nd --function __nd`.
79
+
70
80
  ## Maintenance
71
81
 
72
82
  - `bun run popular` regenerates `src/popular.json`, the 500 most downloaded names from the [npm-high-impact](https://www.npmjs.com/package/npm-high-impact) list.
package/dist/cli.js CHANGED
@@ -900,6 +900,32 @@ var init_args = __esm(() => {
900
900
  UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
901
901
  });
902
902
 
903
+ // ../kit/src/argv.ts
904
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
905
+ import { resolve as resolve3 } from "path";
906
+ import process11 from "process";
907
+ function commandLine() {
908
+ try {
909
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
910
+ } catch {
911
+ return;
912
+ }
913
+ }
914
+ function realPath(word) {
915
+ try {
916
+ return realpathSync(resolve3(word));
917
+ } catch {
918
+ return;
919
+ }
920
+ }
921
+ function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
922
+ const target = script === undefined ? undefined : realPath(script) ?? script;
923
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
924
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
925
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
926
+ }
927
+ var init_argv = () => {};
928
+
903
929
  // ../kit/src/chart.ts
904
930
  var init_chart = __esm(() => {
905
931
  init_format();
@@ -910,7 +936,7 @@ var init_chart = __esm(() => {
910
936
 
911
937
  // ../kit/src/process.ts
912
938
  import { constants } from "os";
913
- import process11 from "process";
939
+ import process12 from "process";
914
940
  function exitCodeOf(code, signal) {
915
941
  if (code !== null)
916
942
  return code;
@@ -930,7 +956,7 @@ function holdSignals(cleanup) {
930
956
  },
931
957
  release: () => {
932
958
  for (const signal of SIGNALS)
933
- process11.off(signal, onSignal);
959
+ process12.off(signal, onSignal);
934
960
  }
935
961
  };
936
962
  function onSignal(signal) {
@@ -943,10 +969,10 @@ function holdSignals(cleanup) {
943
969
  return;
944
970
  held.release();
945
971
  cleanup(signal);
946
- process11.kill(process11.pid, signal);
972
+ process12.kill(process12.pid, signal);
947
973
  }
948
974
  for (const signal of SIGNALS)
949
- process11.on(signal, onSignal);
975
+ process12.on(signal, onSignal);
950
976
  return held;
951
977
  }
952
978
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -960,7 +986,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
960
986
  return;
961
987
  try {
962
988
  if (grouped)
963
- process11.kill(-proc.pid, killing);
989
+ process12.kill(-proc.pid, killing);
964
990
  else
965
991
  proc.kill(killing);
966
992
  } catch {}
@@ -1033,8 +1059,8 @@ var init_process = __esm(() => {
1033
1059
  });
1034
1060
 
1035
1061
  // ../kit/src/progress.ts
1036
- import process12 from "process";
1037
- function liveRegion(render, stream = process12.stderr, env = process12.env) {
1062
+ import process13 from "process";
1063
+ function liveRegion(render, stream = process13.stderr, env = process13.env) {
1038
1064
  if (!takesControlCodes(stream, env))
1039
1065
  return { redraw: () => {
1040
1066
  return;
@@ -1044,13 +1070,15 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1044
1070
  } };
1045
1071
  const write = stream.write.bind(stream);
1046
1072
  let frame = 0;
1047
- let drawn = [];
1048
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1049
- const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
1073
+ let drawn = false;
1074
+ const columns = () => {
1075
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
1076
+ return now === undefined || now === 0 ? 80 : now;
1077
+ };
1050
1078
  const clear = () => {
1051
- if (drawn.length > 0)
1052
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1053
- drawn = [];
1079
+ if (drawn)
1080
+ write(CLEAR_BELOW);
1081
+ drawn = false;
1054
1082
  };
1055
1083
  const draw = () => {
1056
1084
  const width = columns() - 1;
@@ -1060,9 +1088,9 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1060
1088
  clear();
1061
1089
  return;
1062
1090
  }
1063
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1064
- `)}`);
1065
- drawn = lines.map((line) => Bun.stringWidth(line));
1091
+ write(`${CLEAR_BELOW}${lines.join(`
1092
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
1093
+ drawn = true;
1066
1094
  };
1067
1095
  const timer = setInterval(draw, FRAME_MS);
1068
1096
  stream.on?.("resize", draw);
@@ -1079,11 +1107,11 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1079
1107
  clear();
1080
1108
  restore();
1081
1109
  release();
1082
- process12.off("exit", onExit);
1110
+ process13.off("exit", onExit);
1083
1111
  signals.release();
1084
1112
  }
1085
1113
  timer.unref();
1086
- process12.on("exit", onExit);
1114
+ process13.on("exit", onExit);
1087
1115
  return {
1088
1116
  redraw: draw,
1089
1117
  print: (text) => {
@@ -1122,14 +1150,14 @@ function cutToWidth(line, width) {
1122
1150
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1123
1151
  }
1124
1152
  function swallowInput() {
1125
- const input = process12.stdin;
1153
+ const input = process13.stdin;
1126
1154
  if (!input.isTTY)
1127
1155
  return () => {
1128
1156
  return;
1129
1157
  };
1130
1158
  const onData = (data) => {
1131
1159
  if (data.includes(CTRL_C))
1132
- process12.kill(process12.pid, "SIGINT");
1160
+ process13.kill(process13.pid, "SIGINT");
1133
1161
  };
1134
1162
  input.setRawMode(true);
1135
1163
  input.on("data", onData);
@@ -1145,7 +1173,7 @@ function swallowInput() {
1145
1173
  };
1146
1174
  }
1147
1175
  function interceptOutput(clear) {
1148
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1176
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process13.stdout, "write"], [process13.stderr, "write"]];
1149
1177
  const wrapped = targets.map(([target, name]) => {
1150
1178
  const original = Reflect.get(target, name);
1151
1179
  const wrapper = (...args) => {
@@ -1162,7 +1190,7 @@ function interceptOutput(clear) {
1162
1190
  }
1163
1191
  };
1164
1192
  }
1165
- var FRAMES, FRAME_MS = 200, CLEAR_LINE = "\r\x1B[2K", LINE_UP = "\x1B[1A\x1B[2K", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
1193
+ var FRAMES, FRAME_MS = 200, CLEAR_BELOW = "\r\x1B[J", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
1166
1194
  var init_progress = __esm(() => {
1167
1195
  init_format();
1168
1196
  init_process();
@@ -1201,18 +1229,18 @@ var init_logs = __esm(() => {
1201
1229
  import { appendFileSync, mkdirSync } from "fs";
1202
1230
  import { homedir as homedir3 } from "os";
1203
1231
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1204
- import process13 from "process";
1232
+ import process14 from "process";
1205
1233
  function noteUsageError(message) {
1206
1234
  usageError = message;
1207
1235
  }
1208
- function stateHome(env = process13.env) {
1236
+ function stateHome(env = process14.env) {
1209
1237
  const dir = env.XDG_STATE_HOME;
1210
1238
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1211
1239
  }
1212
- function usagePath(env = process13.env) {
1240
+ function usagePath(env = process14.env) {
1213
1241
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1214
1242
  }
1215
- function usageRecorded(env = process13.env) {
1243
+ function usageRecorded(env = process14.env) {
1216
1244
  const off = env.KAYNOOO_CLI_NO_USAGE;
1217
1245
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1218
1246
  }
@@ -1226,7 +1254,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1226
1254
  usageError = undefined;
1227
1255
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1228
1256
  }
1229
- function recordUsage(entry, env = process13.env) {
1257
+ function recordUsage(entry, env = process14.env) {
1230
1258
  if (!usageRecorded(env))
1231
1259
  return;
1232
1260
  try {
@@ -1244,9 +1272,9 @@ var init_usage = __esm(() => {
1244
1272
  });
1245
1273
 
1246
1274
  // ../kit/src/cli.ts
1247
- import { readFileSync as readFileSync3, realpathSync } from "fs";
1275
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1248
1276
  import { dirname as dirname3, join as join5 } from "path";
1249
- import process14 from "process";
1277
+ import process15 from "process";
1250
1278
  async function commandRows(all, colors) {
1251
1279
  const commands = shown(all);
1252
1280
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1321,8 +1349,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1321
1349
  `);
1322
1350
  }
1323
1351
  function printError(prefix, message, hint, cause) {
1324
- const colors = paint(process14.stderr);
1325
- const styled = takesControlCodes(process14.stderr);
1352
+ const colors = paint(process15.stderr);
1353
+ const styled = takesControlCodes(process15.stderr);
1326
1354
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1327
1355
  const under = (label, text, tint) => text === undefined ? "" : `
1328
1356
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1365,11 +1393,11 @@ async function dispatch(level, typed, { version, redact }) {
1365
1393
  }
1366
1394
  }
1367
1395
  if (name === undefined && level.path.length > 1) {
1368
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1396
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
1369
1397
  return 2;
1370
1398
  }
1371
1399
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1372
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1400
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
1373
1401
  return 0;
1374
1402
  }
1375
1403
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1423,24 +1451,24 @@ function candidateLine(candidate) {
1423
1451
  }
1424
1452
  function positionalBeingTyped(before, { options, positionals }) {
1425
1453
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1426
- let index = 0;
1454
+ const typed = [];
1427
1455
  let at = 0;
1428
1456
  while (at < before.length) {
1429
1457
  const word = before[at];
1430
1458
  if (word === "--") {
1431
- index += before.length - at - 1;
1459
+ typed.push(...before.slice(at + 1));
1432
1460
  break;
1433
1461
  }
1434
1462
  if (!word.startsWith("-"))
1435
- index++;
1463
+ typed.push(word);
1436
1464
  else if (takesValue(word))
1437
1465
  at++;
1438
1466
  at++;
1439
1467
  }
1440
1468
  const last = positionals.at(-1);
1441
- if (index < positionals.length)
1442
- return positionals[index];
1443
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1469
+ if (typed.length < positionals.length)
1470
+ return { name: positionals[typed.length], typed };
1471
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1444
1472
  }
1445
1473
  async function leafCandidates(run, words) {
1446
1474
  const completing = await completingOf(run);
@@ -1448,12 +1476,12 @@ async function leafCandidates(run, words) {
1448
1476
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1449
1477
  const flag = words.at(-2);
1450
1478
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1479
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1451
1480
  if (option?.type === "string") {
1452
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1481
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1453
1482
  return values === undefined ? [FILES] : values.map(candidateLine);
1454
1483
  }
1455
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1456
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1484
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1457
1485
  return values === undefined ? [FILES] : values.map(candidateLine);
1458
1486
  }
1459
1487
  async function candidates(scope, defaultCommand, words, before = []) {
@@ -1484,9 +1512,9 @@ async function printCandidates(found) {
1484
1512
  return 0;
1485
1513
  }
1486
1514
  function packageVersion(entry = Bun.main) {
1487
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1515
+ for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1488
1516
  try {
1489
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1517
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1490
1518
  if (typeof version === "string")
1491
1519
  return version;
1492
1520
  } catch {}
@@ -1494,7 +1522,7 @@ function packageVersion(entry = Bun.main) {
1494
1522
  return "0.0.0";
1495
1523
  }
1496
1524
  }
1497
- async function runCli(cli, argv = process14.argv.slice(2)) {
1525
+ async function runCli(cli, argv = scriptArgs()) {
1498
1526
  const version = cli.version ?? packageVersion();
1499
1527
  if (argv[0] === COMPLETE)
1500
1528
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1524,6 +1552,7 @@ function commandPath(scope, argv) {
1524
1552
  var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
1525
1553
  var init_cli = __esm(() => {
1526
1554
  init_args();
1555
+ init_argv();
1527
1556
  init_style();
1528
1557
  init_text2();
1529
1558
  init_usage();
@@ -1623,8 +1652,8 @@ var init_watch = __esm(() => {
1623
1652
 
1624
1653
  // ../kit/src/workspace-root.ts
1625
1654
  import { homedir as homedir4 } from "os";
1626
- import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
1627
- import process15 from "process";
1655
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1656
+ import process16 from "process";
1628
1657
  function expandHome(path, home) {
1629
1658
  if (path === "~")
1630
1659
  return home;
@@ -1634,9 +1663,9 @@ function configured(env, home) {
1634
1663
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1635
1664
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1636
1665
  }
1637
- function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
1666
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1638
1667
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1639
- return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1668
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1640
1669
  }
1641
1670
  var init_workspace_root = __esm(() => {
1642
1671
  init_user_config();
@@ -1646,6 +1675,7 @@ var init_workspace_root = __esm(() => {
1646
1675
  var init_src = __esm(() => {
1647
1676
  init_advisory();
1648
1677
  init_args();
1678
+ init_argv();
1649
1679
  init_chart();
1650
1680
  init_ci();
1651
1681
  init_cli();
@@ -2395,7 +2425,7 @@ function parseSpec(text) {
2395
2425
  function isStable(version) {
2396
2426
  return !version.includes("-");
2397
2427
  }
2398
- function resolve4(packument, request) {
2428
+ function resolve5(packument, request) {
2399
2429
  const tags = packument["dist-tags"] ?? {};
2400
2430
  const versions = Object.keys(packument.versions ?? {});
2401
2431
  const wanted = request === undefined || request === "" ? "latest" : request;
@@ -2440,7 +2470,7 @@ function analyze(input) {
2440
2470
  return report;
2441
2471
  }
2442
2472
  const latest = packument["dist-tags"]?.latest;
2443
- const version = resolve4(packument, spec.request);
2473
+ const version = resolve5(packument, spec.request);
2444
2474
  const entry = version === undefined ? undefined : packument.versions?.[version];
2445
2475
  report.description = packument.description;
2446
2476
  report.license = licenseOf(entry?.license) ?? licenseOf(packument.license);
@@ -2510,7 +2540,7 @@ var init_analyze = __esm(() => {
2510
2540
  // src/config.ts
2511
2541
  import { homedir as homedir5 } from "os";
2512
2542
  import { dirname as dirname5, join as join7 } from "path";
2513
- import process17 from "process";
2543
+ import process18 from "process";
2514
2544
  function expand2(value, env) {
2515
2545
  let missing = false;
2516
2546
  const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
@@ -2599,7 +2629,7 @@ async function readIfThere(path) {
2599
2629
  const file = Bun.file(path);
2600
2630
  return await file.exists() ? file.text() : undefined;
2601
2631
  }
2602
- async function loadConfigs(cwd = process17.cwd(), env = process17.env, home = homedir5()) {
2632
+ async function loadConfigs(cwd = process18.cwd(), env = process18.env, home = homedir5()) {
2603
2633
  const directories = [];
2604
2634
  for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
2605
2635
  directories.push(dir);
@@ -2632,7 +2662,7 @@ function parseSettings(text) {
2632
2662
  settings.concurrency = raw.concurrency;
2633
2663
  return settings;
2634
2664
  }
2635
- async function loadSettings(cwd = process17.cwd(), home) {
2665
+ async function loadSettings(cwd = process18.cwd(), home) {
2636
2666
  const files = [];
2637
2667
  for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
2638
2668
  files.push(join7(dir, SETTINGS_FILE));
@@ -2749,7 +2779,7 @@ var init_pin = __esm(() => {
2749
2779
  });
2750
2780
 
2751
2781
  // src/consumers.ts
2752
- import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync4 } from "fs";
2782
+ import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
2753
2783
  import { dirname as dirname6, join as join8, relative } from "path";
2754
2784
  function packageFiles(dir, depth, found, ignored = ignoredFolders()) {
2755
2785
  let entries;
@@ -2777,7 +2807,7 @@ function managerFor(dir, root) {
2777
2807
  }
2778
2808
  function readManifest(path) {
2779
2809
  try {
2780
- return JSON.parse(readFileSync4(path, "utf8"));
2810
+ return JSON.parse(readFileSync5(path, "utf8"));
2781
2811
  } catch {
2782
2812
  return;
2783
2813
  }
@@ -3020,8 +3050,8 @@ var exports_audit = {};
3020
3050
  __export(exports_audit, {
3021
3051
  audit: () => audit
3022
3052
  });
3023
- import { join as join9, resolve as resolve5 } from "path";
3024
- import process18 from "process";
3053
+ import { join as join9, resolve as resolve6 } from "path";
3054
+ import process19 from "process";
3025
3055
  function hasFinding(audited) {
3026
3056
  return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
3027
3057
  }
@@ -3077,7 +3107,7 @@ async function audit(args) {
3077
3107
  const level = values.level ?? "moderate";
3078
3108
  if (!isSeverity(level))
3079
3109
  fail(`--level takes ${SEVERITIES.join(", ")}, not ${level}`);
3080
- const dir = resolve5(asked ?? process18.cwd());
3110
+ const dir = resolve6(asked ?? process19.cwd());
3081
3111
  const lock = Bun.file(join9(dir, "bun.lock"));
3082
3112
  if (!await lock.exists())
3083
3113
  fail(`no bun.lock in ${dir}`);
@@ -3132,7 +3162,7 @@ __export(exports_outdated, {
3132
3162
  outdatedCommand: () => outdatedCommand
3133
3163
  });
3134
3164
  import { existsSync as existsSync5 } from "fs";
3135
- import { join as join10, resolve as resolve6 } from "path";
3165
+ import { join as join10, resolve as resolve7 } from "path";
3136
3166
  function currentOf(name, spec, locked) {
3137
3167
  const pinned = locked.filter((each) => each.name === name && Bun.semver.satisfies(each.version, spec)).map((each) => each.version).sort(Bun.semver.order).at(-1);
3138
3168
  const written = FIRST_VERSION.exec(spec)?.[0];
@@ -3165,7 +3195,7 @@ async function outdated(manifest, context) {
3165
3195
  }
3166
3196
  async function outdatedCommand(args) {
3167
3197
  const { values, positionals: [dir = "."] } = parse(args, usage4, options3, { positionals: ["[dir]"], exits: EXITS3 });
3168
- const folder = resolve6(dir);
3198
+ const folder = resolve7(dir);
3169
3199
  const manifest = Bun.file(join10(folder, "package.json"));
3170
3200
  if (!await manifest.exists())
3171
3201
  fail(`no package.json in ${folder}`);
@@ -3272,7 +3302,7 @@ var init_state = __esm(() => {
3272
3302
  });
3273
3303
 
3274
3304
  // ../kit/src/prompt.ts
3275
- import process19 from "process";
3305
+ import process20 from "process";
3276
3306
  function readKeys(input, paste = { active: false }) {
3277
3307
  return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
3278
3308
  }
@@ -3386,21 +3416,18 @@ function asking(colors, question, typed, keys) {
3386
3416
  function answer(colors, question, state, picked) {
3387
3417
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
3388
3418
  }
3389
- async function ask(question, { hint, terminal = process19 }, render, press) {
3419
+ async function ask(question, { hint, terminal = process20 }, render, press) {
3390
3420
  const { stdin, stderr } = terminal;
3391
3421
  if (!isInteractive(terminal))
3392
3422
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
3393
3423
  const colors = paint(stderr);
3394
- let drawn = [];
3395
3424
  let current = "asking";
3396
3425
  let outcome;
3397
3426
  const columns = () => stderr.columns || 80;
3398
- const draw = (state) => {
3427
+ const draw = (state, last = false) => {
3399
3428
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
3400
- const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
3401
- stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
3402
- `)}`);
3403
- drawn = frame;
3429
+ stderr.write(`\r\x1B[0J${frame.join(`
3430
+ `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
3404
3431
  current = state;
3405
3432
  };
3406
3433
  const redraw = () => draw(current);
@@ -3436,7 +3463,7 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
3436
3463
  });
3437
3464
  } finally {
3438
3465
  stderr.off?.("resize", redraw);
3439
- draw(outcome ?? "cancel");
3466
+ draw(outcome ?? "cancel", true);
3440
3467
  stderr.write(`
3441
3468
  \x1B[?25h\x1B[?2004l`);
3442
3469
  stdin.setRawMode(false);
@@ -3455,7 +3482,7 @@ var init_prompt = __esm(() => {
3455
3482
  });
3456
3483
 
3457
3484
  // src/excluded.ts
3458
- import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
3485
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync } from "fs";
3459
3486
  import { dirname as dirname7 } from "path";
3460
3487
  function excludedPath(home) {
3461
3488
  return userConfigPath("pkg-excluded", { home });
@@ -3465,7 +3492,7 @@ function loadExcluded(home) {
3465
3492
  if (!existsSync6(path))
3466
3493
  return {};
3467
3494
  try {
3468
- const raw = JSON.parse(readFileSync5(path, "utf8"));
3495
+ const raw = JSON.parse(readFileSync6(path, "utf8"));
3469
3496
  const excluded = {};
3470
3497
  for (const [name, dirs] of Object.entries(raw)) {
3471
3498
  if (Array.isArray(dirs))
@@ -3777,10 +3804,77 @@ var init_consumers2 = __esm(() => {
3777
3804
  };
3778
3805
  });
3779
3806
 
3807
+ // src/manager.ts
3808
+ import { existsSync as existsSync8 } from "fs";
3809
+ import { dirname as dirname9, join as join12 } from "path";
3810
+ function detectManager(from) {
3811
+ let dir = from;
3812
+ while (true) {
3813
+ const found = LOCKFILES2.find(([file]) => existsSync8(join12(dir, file)));
3814
+ if (found !== undefined)
3815
+ return found[1];
3816
+ const parent = dirname9(dir);
3817
+ if (parent === dir)
3818
+ return "bun";
3819
+ dir = parent;
3820
+ }
3821
+ }
3822
+ function commandFor(action, manager) {
3823
+ const { fallback, ...own } = COMMANDS[action];
3824
+ return own[manager] ?? fallback(manager);
3825
+ }
3826
+ var ACTIONS2, LOCKFILES2, COMMANDS;
3827
+ var init_manager = __esm(() => {
3828
+ ACTIONS2 = ["install", "dev", "remove", "update", "exec"];
3829
+ LOCKFILES2 = [["bun.lock", "bun"], ["bun.lockb", "bun"], ["yarn.lock", "yarn"], ["pnpm-lock.yaml", "pnpm"], ["package-lock.json", "npm"], ["composer.json", "composer"], ["uv.lock", "uv"]];
3830
+ COMMANDS = {
3831
+ install: { yarn: "yarn add", uv: "uv sync", fallback: (manager) => `${manager} install` },
3832
+ dev: { bun: "bun add -d", yarn: "yarn add -D", pnpm: "pnpm add -D", composer: "composer require --dev", uv: "uv add --dev", fallback: () => "npm install -D" },
3833
+ remove: { npm: "npm uninstall", fallback: (manager) => `${manager} remove` },
3834
+ update: { yarn: "yarn upgrade", uv: "uv lock --upgrade", fallback: (manager) => `${manager} update` },
3835
+ exec: { bun: "bunx", pnpm: "pnpm dlx", yarn: "yarn dlx", composer: "composer exec", uv: "uvx", fallback: () => "npx" }
3836
+ };
3837
+ });
3838
+
3839
+ // src/commands/manager.ts
3840
+ var exports_manager = {};
3841
+ __export(exports_manager, {
3842
+ manager: () => manager
3843
+ });
3844
+ import process21 from "process";
3845
+ function manager(args) {
3846
+ const { values, positionals } = parse(args, usage7, options6, {
3847
+ positionals: ["<action>"],
3848
+ candidates: { "<action>": () => [...ACTIONS2] },
3849
+ replaces: "telling bun, yarn, pnpm, npm, composer and uv apart by their lockfile before typing an add, remove or dlx",
3850
+ examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
3851
+ });
3852
+ const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
3853
+ const found = detectManager(process21.cwd());
3854
+ const command = commandFor(action, found);
3855
+ if (values.json === true)
3856
+ printJson({ manager: found, action, command });
3857
+ else
3858
+ console.log(command);
3859
+ return 0;
3860
+ }
3861
+ var usage7 = `pkg manager <install|dev|remove|update|exec>
3862
+
3863
+ Prints the command the package manager of this folder runs for the action: install is the add or install of a package, dev adds one as a dev dependency, remove drops one, update upgrades them and exec runs a package's bin without installing it. The manager is the one whose lockfile (bun.lock, bun.lockb, yarn.lock, pnpm-lock.yaml, package-lock.json, uv.lock) or composer.json is nearest, here or in a parent folder, bun when none is found.
3864
+
3865
+ Exits 0 when it printed the command, 2 on a usage error.`, options6;
3866
+ var init_manager2 = __esm(() => {
3867
+ init_src();
3868
+ init_manager();
3869
+ options6 = {
3870
+ json: jsonOption("{manager, action, command}")
3871
+ };
3872
+ });
3873
+
3780
3874
  // src/cli.ts
3781
3875
  init_src();
3782
- import process20 from "process";
3783
- process20.exitCode = await runCli({
3876
+ import process22 from "process";
3877
+ process22.exitCode = await runCli({
3784
3878
  name: "pkg",
3785
3879
  about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
3786
3880
  replaces: "bun add on trust, and a bun info and sleep loop then a bun add per consumer",
@@ -3791,6 +3885,7 @@ process20.exitCode = await runCli({
3791
3885
  audit: { summary: "check every package a bun.lock pins, with its known advisories", run: async (args) => (await Promise.resolve().then(() => (init_audit(), exports_audit))).audit(args) },
3792
3886
  outdated: { summary: "list the dependencies of this folder that have a newer version safe to take", run: async (args) => (await Promise.resolve().then(() => (init_outdated(), exports_outdated))).outdatedCommand(args) },
3793
3887
  bump: { summary: "wait for a release on the registry, then bun add it in every consumer", run: async (args) => (await Promise.resolve().then(() => (init_bump(), exports_bump))).bump(args) },
3794
- consumers: { summary: "list the folders depending on a package, with the version each asks for", run: async (args) => (await Promise.resolve().then(() => (init_consumers2(), exports_consumers))).consumers(args) }
3888
+ consumers: { summary: "list the folders depending on a package, with the version each asks for", run: async (args) => (await Promise.resolve().then(() => (init_consumers2(), exports_consumers))).consumers(args) },
3889
+ manager: { summary: "the command this folder's package manager runs to install, remove, update or exec", run: async (args) => (await Promise.resolve().then(() => (init_manager2(), exports_manager))).manager(args) }
3795
3890
  }
3796
3891
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pkg",
3
3
  "type": "module",
4
- "version": "0.13.2",
4
+ "version": "0.14.0",
5
5
  "description": "pkg: check an npm package before it is added, for a guessed name, a version under two weeks old and install scripts.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "@kaynooo/utils": "3.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@kaynooo/cli-kit": "0.36.1"
36
+ "@kaynooo/cli-kit": "0.38.1"
37
37
  }
38
38
  }