@kaynooo/cli-proc 0.8.1 → 0.8.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.
Files changed (2) hide show
  1. package/dist/proc-cli.js +70 -29
  2. package/package.json +3 -3
package/dist/proc-cli.js CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
- // @bun
1
+ #!/bin/sh
2
+ // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
3
3
  var __esm = (fn, res, err) => () => {
4
4
  if (fn)
5
5
  try {
@@ -162,11 +162,14 @@ var init_config = __esm(() => {
162
162
 
163
163
  // ../kit/src/user-config.ts
164
164
  import { homedir } from "os";
165
- import { join as join2 } from "path";
165
+ import { isAbsolute, join as join2 } from "path";
166
166
  import process4 from "process";
167
+ function xdgFolder(value, fallback) {
168
+ return value !== undefined && isAbsolute(value) ? value : fallback;
169
+ }
167
170
  function configBase(where = {}) {
168
171
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
169
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
172
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
170
173
  }
171
174
  function userConfigPath(bin, where = {}) {
172
175
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
@@ -620,21 +623,32 @@ function wholeNumber(value, name, fallback, min = 1) {
620
623
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
621
624
  return number;
622
625
  }
626
+ function durationMs(text, unit) {
627
+ if (BARE_DURATION.test(text))
628
+ return Number(text) * UNIT_MS[unit];
629
+ if (!DURATION.test(text))
630
+ return 0;
631
+ let ms = 0;
632
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
633
+ ms += Number(amount) * UNIT_MS[part];
634
+ return ms;
635
+ }
623
636
  function duration(value, name, fallback, unit = "s") {
624
637
  if (value === undefined)
625
638
  return fallback;
626
- const match = DURATION.exec(value.trim());
627
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
639
+ const ms = durationMs(value.trim(), unit);
628
640
  if (ms < 1)
629
641
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
630
642
  return ms;
631
643
  }
632
- var WHOLE, DURATION, UNIT_MS;
644
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
633
645
  var init_input = __esm(() => {
634
646
  init_args();
635
647
  WHOLE = /^\d+$/;
636
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
637
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
648
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
649
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
650
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
651
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
638
652
  });
639
653
 
640
654
  // ../kit/src/args.ts
@@ -1156,6 +1170,7 @@ init_format2();
1156
1170
  import { constants } from "os";
1157
1171
  import process11 from "process";
1158
1172
  var KILL_GRACE_MS = 2000;
1173
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
1159
1174
  function exitCodeOf(code, signal) {
1160
1175
  if (code !== null)
1161
1176
  return code;
@@ -1206,12 +1221,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
1206
1221
  stop();
1207
1222
  continue;
1208
1223
  }
1224
+ if (state.truncated)
1225
+ continue;
1226
+ let kept = data;
1209
1227
  if (state.kept + data.length > maxBytes) {
1228
+ let cut = maxBytes - state.kept;
1229
+ while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
1230
+ cut--;
1231
+ kept = data.subarray(0, cut);
1210
1232
  state.truncated = true;
1211
- continue;
1212
1233
  }
1213
- state.kept += data.length;
1214
- chunks.push({ stream: name, data });
1234
+ state.kept += kept.length;
1235
+ if (kept.length > 0)
1236
+ chunks.push({ stream: name, data: kept });
1215
1237
  }
1216
1238
  };
1217
1239
  try {
@@ -1228,6 +1250,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
1228
1250
  const joined = () => Buffer.concat(chunks.map(({ data }) => data));
1229
1251
  let output;
1230
1252
  let text;
1253
+ let stdout;
1231
1254
  return {
1232
1255
  code: exitCodeOf(proc.exitCode, proc.signalCode),
1233
1256
  chunks,
@@ -1238,6 +1261,9 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
1238
1261
  },
1239
1262
  get text() {
1240
1263
  return text ??= (output ??= joined()).toString();
1264
+ },
1265
+ get stdout() {
1266
+ return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
1241
1267
  }
1242
1268
  };
1243
1269
  }
@@ -1387,14 +1413,16 @@ init_text2();
1387
1413
  // ../kit/src/usage.ts
1388
1414
  import { appendFileSync, mkdirSync } from "fs";
1389
1415
  import { homedir as homedir3 } from "os";
1390
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1416
+ import { dirname as dirname2, join as join4 } from "path";
1391
1417
  import process14 from "process";
1392
1418
 
1393
1419
  // ../kit/src/logs.ts
1420
+ init_user_config();
1394
1421
  var DAY_MS = 24 * 60 * 60 * 1000;
1395
1422
  var CLI_FOLDER = "kaynooo-cli";
1396
1423
 
1397
1424
  // ../kit/src/usage.ts
1425
+ init_user_config();
1398
1426
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
1399
1427
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
1400
1428
  var LONGEST_NAME = 40;
@@ -1403,8 +1431,7 @@ function noteUsageError(message) {
1403
1431
  usageError = message;
1404
1432
  }
1405
1433
  function stateHome(env = process14.env) {
1406
- const dir = env.XDG_STATE_HOME;
1407
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1434
+ return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
1408
1435
  }
1409
1436
  function usagePath(env = process14.env) {
1410
1437
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
@@ -1478,6 +1505,10 @@ function takeOutputFlags(argv) {
1478
1505
  async function resolveSummary(summary) {
1479
1506
  return typeof summary === "string" ? summary : summary();
1480
1507
  }
1508
+ function lookup({ commands, aliases }, word) {
1509
+ const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
1510
+ return Object.hasOwn(commands, name) ? commands[name] : undefined;
1511
+ }
1481
1512
  function scopeOf(commands, extra, aliases) {
1482
1513
  return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
1483
1514
  }
@@ -1572,12 +1603,12 @@ async function dispatch(level, typed, { version, redact }) {
1572
1603
  console.log(version);
1573
1604
  return 0;
1574
1605
  }
1575
- let command = level.commands[level.aliases?.[name] ?? name];
1606
+ let command = lookup(level, name);
1576
1607
  let rest = args;
1577
1608
  let ran = name;
1578
1609
  if (command === undefined && level.lazy.length > 0) {
1579
1610
  level = await expand(level, [...level.path.slice(1), ...argv]);
1580
- command = level.commands[level.aliases?.[name] ?? name];
1611
+ command = lookup(level, name);
1581
1612
  }
1582
1613
  if (command === undefined && level.defaultCommand !== undefined) {
1583
1614
  command = level.commands[level.defaultCommand];
@@ -1657,18 +1688,19 @@ async function leafCandidates(run, words) {
1657
1688
  async function candidates(scope, defaultCommand, words, before = []) {
1658
1689
  const [word = "", ...rest] = words;
1659
1690
  const listing = rest.length === 0 && !word.startsWith("-");
1660
- let { commands, aliases } = scope;
1661
- let command = commands[aliases?.[word] ?? word];
1691
+ let { commands } = scope;
1692
+ let command = lookup(scope, word);
1662
1693
  if (listing || command === undefined) {
1663
- ({ commands, aliases } = await expand(scope, [...before, ...words]));
1664
- command = commands[aliases?.[word] ?? word];
1694
+ const expanded = await expand(scope, [...before, ...words]);
1695
+ commands = expanded.commands;
1696
+ command = lookup(expanded, word);
1665
1697
  }
1666
1698
  if (listing) {
1667
1699
  const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
1668
1700
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
1669
1701
  const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
1670
1702
  const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
1671
- return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
1703
+ return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
1672
1704
  }
1673
1705
  if (command === undefined) {
1674
1706
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
@@ -1733,8 +1765,7 @@ function commandPath(scope, argv) {
1733
1765
  const path = [];
1734
1766
  let level = scope;
1735
1767
  for (const word of argv.filter((each) => !each.startsWith("-"))) {
1736
- const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
1737
- const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
1768
+ const command = lookup(level, word);
1738
1769
  if (command === undefined)
1739
1770
  break;
1740
1771
  path.push(word);
@@ -1767,25 +1798,35 @@ init_mode();
1767
1798
  init_style();
1768
1799
  init_text2();
1769
1800
  // ../kit/src/secrets.ts
1770
- var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
1801
+ var SECRET_PART = /token|secret|passw|passphrase|credential|private|dsn|apikey|accesskey|authorization|sess(?:ion)?id|connectionstring|key$/i;
1771
1802
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1772
1803
  var WORD_BREAKS = /[^a-zA-Z\d]+|(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/;
1804
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
1805
+ function isSecretWord(word) {
1806
+ const lower = word.toLowerCase();
1807
+ return SECRET_WORDS.has(lower) || lower.endsWith("pass") && !NOT_PASSWORDS.has(lower);
1808
+ }
1773
1809
  function isSecretName(name) {
1774
- return SECRET_PART.test(name) || name.split(WORD_BREAKS).some((word) => SECRET_WORDS.has(word.toLowerCase()));
1810
+ return SECRET_PART.test(name) || name.split(WORD_BREAKS).some(isSecretWord);
1775
1811
  }
1776
1812
  // ../kit/src/sessions.ts
1777
1813
  var {Glob } = globalThis.Bun;
1778
1814
  var SESSION_FILES = new Glob("*.json");
1779
1815
  var ACCOUNT_DIRS = new Glob("*/sessions");
1780
1816
  // ../kit/src/size.ts
1781
- var SIZE = /^(\d+(?:\.\d+)?)\s*([kmgt]?)i?b?$/i;
1817
+ var SIZE = /^(\d+(?:\.\d+)?)\s*(?:([kmgt])i?b?|(b))?$/i;
1782
1818
  var POWERS = { "": 0, k: 1, m: 2, g: 3, t: 4 };
1783
1819
  function parseSize(text, bareUnit = 1) {
1784
1820
  const match = SIZE.exec(text.trim());
1785
1821
  if (match === null)
1786
1822
  return;
1787
- const suffix = match[2].toLowerCase();
1788
- return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1823
+ const suffix = match[2]?.toLowerCase();
1824
+ let unit = bareUnit;
1825
+ if (match[3] !== undefined)
1826
+ unit = 1;
1827
+ else if (suffix !== undefined)
1828
+ unit = 1024 ** POWERS[suffix];
1829
+ return Math.round(Number(match[1]) * unit);
1789
1830
  }
1790
1831
 
1791
1832
  // ../kit/src/index.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-proc",
3
3
  "type": "module",
4
- "version": "0.8.1",
4
+ "version": "0.8.2",
5
5
  "description": "proc: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -25,10 +25,10 @@
25
25
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
26
26
  },
27
27
  "scripts": {
28
- "build": "$npm_execpath build src/proc-cli.ts --target bun --outdir dist",
28
+ "build": "$npm_execpath build src/proc-cli.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
29
29
  "proc": "$npm_execpath src/proc-cli.ts"
30
30
  },
31
31
  "devDependencies": {
32
- "@kaynooo/cli-kit": "0.46.0"
32
+ "@kaynooo/cli-kit": "0.46.4"
33
33
  }
34
34
  }