@kaynooo/cli-pkg 0.15.1 → 0.16.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 (2) hide show
  1. package/dist/cli.js +304 -52
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -591,33 +591,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
591
591
  function optionRows(options, colors = paint(process8.stdout)) {
592
592
  const rows = Object.entries(options).map(([name, option]) => {
593
593
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
594
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
594
+ const choices = option.choices?.join("|");
595
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
596
+ const named = inline ? `<${choices}>` : "<value>";
595
597
  const placeholder = option.optional === undefined ? named : `[${named}]`;
596
598
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
597
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
599
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
600
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
598
601
  });
599
602
  const width = Math.max(0, ...rows.map((row) => row.width));
600
603
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
601
604
  }
602
- var OPTIONAL, USAGE_PREFIX, FULL_STOP;
605
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
603
606
  var init_help = __esm(() => {
604
607
  init_mode();
605
608
  init_style();
606
- OPTIONAL = /\[[^\]]+\]/g;
609
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
607
610
  USAGE_PREFIX = /^usage:\s*/i;
608
611
  FULL_STOP = /\.$/;
609
612
  });
610
613
 
611
614
  // ../kit/src/text.ts
612
615
  function distance(a, b) {
613
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
614
- for (const [i, left] of [...a].entries()) {
616
+ const left = [...a];
617
+ const right = [...b];
618
+ let before = [];
619
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
620
+ for (const [i, x] of left.entries()) {
615
621
  const current = [i + 1];
616
- for (const [j, right] of [...b].entries())
617
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
622
+ for (const [j, y] of right.entries()) {
623
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
624
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
625
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
626
+ current.push(cost);
627
+ }
628
+ before = previous;
618
629
  previous = current;
619
630
  }
620
- return previous[b.length] ?? 0;
631
+ return previous[right.length] ?? 0;
621
632
  }
622
633
  function closest(name, names) {
623
634
  const started = names.find((known) => known.startsWith(name));
@@ -626,10 +637,7 @@ function closest(name, names) {
626
637
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
627
638
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
628
639
  }
629
- var ANSI;
630
- var init_text2 = __esm(() => {
631
- ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
632
- });
640
+ var init_text2 = () => {};
633
641
 
634
642
  // ../kit/src/input.ts
635
643
  import { fstatSync } from "fs";
@@ -1219,6 +1227,27 @@ var init_ci = __esm(() => {
1219
1227
  init_tool();
1220
1228
  });
1221
1229
 
1230
+ // ../kit/src/notify.ts
1231
+ import process14 from "process";
1232
+ function base64(text) {
1233
+ return Buffer.from(text).toString("base64");
1234
+ }
1235
+ function notification(title, body, env = process14.env) {
1236
+ const id = `kit${process14.pid}`;
1237
+ const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1238
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1239
+ }
1240
+ function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
1241
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1242
+ return;
1243
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1244
+ }
1245
+ var NOTIFY_AFTER_MS = 1e4, CANCELLED = 130;
1246
+ var init_notify = __esm(() => {
1247
+ init_format();
1248
+ init_mode();
1249
+ });
1250
+
1222
1251
  // ../kit/src/logs.ts
1223
1252
  var DAY_MS, CLI_FOLDER = "kaynooo-cli";
1224
1253
  var init_logs = __esm(() => {
@@ -1229,18 +1258,18 @@ var init_logs = __esm(() => {
1229
1258
  import { appendFileSync, mkdirSync } from "fs";
1230
1259
  import { homedir as homedir3 } from "os";
1231
1260
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1232
- import process14 from "process";
1261
+ import process15 from "process";
1233
1262
  function noteUsageError(message) {
1234
1263
  usageError = message;
1235
1264
  }
1236
- function stateHome(env = process14.env) {
1265
+ function stateHome(env = process15.env) {
1237
1266
  const dir = env.XDG_STATE_HOME;
1238
1267
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1239
1268
  }
1240
- function usagePath(env = process14.env) {
1269
+ function usagePath(env = process15.env) {
1241
1270
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1242
1271
  }
1243
- function usageRecorded(env = process14.env) {
1272
+ function usageRecorded(env = process15.env) {
1244
1273
  const off = env.KAYNOOO_CLI_NO_USAGE;
1245
1274
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1246
1275
  }
@@ -1254,7 +1283,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1254
1283
  usageError = undefined;
1255
1284
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1256
1285
  }
1257
- function recordUsage(entry, env = process14.env) {
1286
+ function recordUsage(entry, env = process15.env) {
1258
1287
  if (!usageRecorded(env))
1259
1288
  return;
1260
1289
  try {
@@ -1274,7 +1303,7 @@ var init_usage = __esm(() => {
1274
1303
  // ../kit/src/cli.ts
1275
1304
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1276
1305
  import { dirname as dirname3, join as join5 } from "path";
1277
- import process15 from "process";
1306
+ import process16 from "process";
1278
1307
  async function commandRows(all, colors) {
1279
1308
  const commands = shown(all);
1280
1309
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1348,8 +1377,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1348
1377
  `);
1349
1378
  }
1350
1379
  function printError(prefix, message, hint, cause) {
1351
- const colors = paint(process15.stderr);
1352
- const styled = takesControlCodes(process15.stderr);
1380
+ const colors = paint(process16.stderr);
1381
+ const styled = takesControlCodes(process16.stderr);
1353
1382
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1354
1383
  const under = (label, text, tint) => text === undefined ? "" : `
1355
1384
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1392,11 +1421,11 @@ async function dispatch(level, typed, { version, redact }) {
1392
1421
  }
1393
1422
  }
1394
1423
  if (name === undefined && level.path.length > 1) {
1395
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
1424
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stderr));
1396
1425
  return 2;
1397
1426
  }
1398
1427
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1399
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
1428
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stdout));
1400
1429
  return 0;
1401
1430
  }
1402
1431
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1529,10 +1558,13 @@ async function runCli(cli, argv = scriptArgs()) {
1529
1558
  const version = cli.version ?? packageVersion();
1530
1559
  if (argv[0] === COMPLETE)
1531
1560
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1561
+ const started = performance.now();
1532
1562
  const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
1563
+ const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
1564
+ notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1533
1565
  if (cli.usage !== false) {
1534
1566
  try {
1535
- recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
1567
+ recordUsage(usageEntry(cli.name, command, argv, code));
1536
1568
  } catch {}
1537
1569
  }
1538
1570
  return code;
@@ -1556,6 +1588,7 @@ var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
1556
1588
  var init_cli = __esm(() => {
1557
1589
  init_args();
1558
1590
  init_argv();
1591
+ init_notify();
1559
1592
  init_style();
1560
1593
  init_text2();
1561
1594
  init_usage();
@@ -1565,6 +1598,11 @@ var init_cli = __esm(() => {
1565
1598
  };
1566
1599
  TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1567
1600
  });
1601
+ // ../kit/src/excerpt.ts
1602
+ var init_excerpt = __esm(() => {
1603
+ init_text2();
1604
+ });
1605
+
1568
1606
  // ../kit/src/folders.ts
1569
1607
  function ignoredFolders(extra = [], where = {}) {
1570
1608
  const configured = readUserConfig("config", where).ignore;
@@ -1656,7 +1694,7 @@ var init_watch = __esm(() => {
1656
1694
  // ../kit/src/workspace-root.ts
1657
1695
  import { homedir as homedir4 } from "os";
1658
1696
  import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1659
- import process16 from "process";
1697
+ import process17 from "process";
1660
1698
  function expandHome(path, home) {
1661
1699
  if (path === "~")
1662
1700
  return home;
@@ -1666,7 +1704,7 @@ function configured(env, home) {
1666
1704
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1667
1705
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1668
1706
  }
1669
- function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1707
+ function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
1670
1708
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1671
1709
  return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1672
1710
  }
@@ -1676,6 +1714,7 @@ var init_workspace_root = __esm(() => {
1676
1714
 
1677
1715
  // ../kit/src/index.ts
1678
1716
  var init_src = __esm(() => {
1717
+ init_excerpt();
1679
1718
  init_advisory();
1680
1719
  init_args();
1681
1720
  init_argv();
@@ -2462,6 +2501,24 @@ function safeRelease(packument, now, minAgeDays) {
2462
2501
  const version = old.sort(Bun.semver.order).at(-1);
2463
2502
  return version === undefined ? undefined : { version, published: packument.time?.[version] };
2464
2503
  }
2504
+ function previousRelease(packument, version) {
2505
+ const below = Object.keys(packument.versions ?? {}).filter((each) => (isStable(each) || !isStable(version)) && Bun.semver.order(each, version) < 0).sort(Bun.semver.order).at(-1);
2506
+ return below === undefined ? undefined : packument.versions?.[below];
2507
+ }
2508
+ function publisherWarnings(packument, version) {
2509
+ const current = packument.versions?.[version];
2510
+ const previous = previousRelease(packument, version);
2511
+ const warnings = [];
2512
+ if (current === undefined || previous === undefined)
2513
+ return warnings;
2514
+ const by = current._npmUser?.name;
2515
+ const before = previous._npmUser?.name;
2516
+ if (by !== undefined && before !== undefined && by !== before)
2517
+ warnings.push(`${version} was published by ${by}, ${previous.version} by ${before}`);
2518
+ if (previous.dist?.attestations !== undefined && current.dist?.attestations === undefined)
2519
+ warnings.push(`${version} has no provenance attestation, ${previous.version} had one`);
2520
+ return warnings;
2521
+ }
2465
2522
  function analyze(input) {
2466
2523
  const { spec, packument, registry, now = Date.now(), minAgeDays = DEFAULT_MIN_AGE_DAYS } = input;
2467
2524
  const report = { name: spec.name, registry, exists: packument !== undefined, requested: spec.request, installScripts: {}, nearMisses: nearMisses(spec.name), advisories: input.advisories ?? [], fixes: [], warnings: [], blocked: false, downloads: input.downloads };
@@ -2507,6 +2564,7 @@ function analyze(input) {
2507
2564
  report.warnings.push(`${version} runs ${scripts.join(", ")} at install`);
2508
2565
  if (report.deprecated !== undefined)
2509
2566
  report.warnings.push(`${version} is deprecated: ${report.deprecated}`);
2567
+ report.warnings.push(...publisherWarnings(packument, version));
2510
2568
  if (input.licenses !== undefined) {
2511
2569
  const isMissing = report.license === undefined || report.license === "";
2512
2570
  if (isMissing) {
@@ -2543,7 +2601,7 @@ var init_analyze = __esm(() => {
2543
2601
  // src/config.ts
2544
2602
  import { homedir as homedir5 } from "os";
2545
2603
  import { dirname as dirname5, join as join7 } from "path";
2546
- import process18 from "process";
2604
+ import process19 from "process";
2547
2605
  function expand2(value, env) {
2548
2606
  let missing = false;
2549
2607
  const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
@@ -2632,7 +2690,7 @@ async function readIfThere(path) {
2632
2690
  const file = Bun.file(path);
2633
2691
  return await file.exists() ? file.text() : undefined;
2634
2692
  }
2635
- async function loadConfigs(cwd = process18.cwd(), env = process18.env, home = homedir5()) {
2693
+ async function loadConfigs(cwd = process19.cwd(), env = process19.env, home = homedir5()) {
2636
2694
  const directories = [];
2637
2695
  for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
2638
2696
  directories.push(dir);
@@ -2665,7 +2723,7 @@ function parseSettings(text) {
2665
2723
  settings.concurrency = raw.concurrency;
2666
2724
  return settings;
2667
2725
  }
2668
- async function loadSettings(cwd = process18.cwd(), home) {
2726
+ async function loadSettings(cwd = process19.cwd(), home) {
2669
2727
  const files = [];
2670
2728
  for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
2671
2729
  files.push(join7(dir, SETTINGS_FILE));
@@ -2964,7 +3022,7 @@ ${usage2}` : `${values.from} has no registry dependency to check`);
2964
3022
  }
2965
3023
  var usage2 = `pkg [check] <name>[@version]... | --from <package.json> | -
2966
3024
 
2967
- Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts and a near miss of a popular name.
3025
+ Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts, a near miss of a popular name, and a warning when the version's publisher differs from the previous release's or its provenance attestation is gone.
2968
3026
 
2969
3027
  Names come from the arguments, from the dependencies of a package.json with --from (each checked as \`name@range\`, so it resolves what an install would; dev and optional ones included, peer ranges and local or remote sources left out), or from stdin, separated by spaces or lines, when \`-\` is given or nothing else is and stdin is piped.
2970
3028
 
@@ -3056,7 +3114,7 @@ __export(exports_audit, {
3056
3114
  audit: () => audit
3057
3115
  });
3058
3116
  import { join as join9, resolve as resolve6 } from "path";
3059
- import process19 from "process";
3117
+ import process20 from "process";
3060
3118
  function hasFinding(audited) {
3061
3119
  return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
3062
3120
  }
@@ -3096,7 +3154,7 @@ async function auditPackages(packages, context) {
3096
3154
  });
3097
3155
  return { audited, unavailable };
3098
3156
  }
3099
- function renderAudit(findings, total, stream = process19.stdout, env = process19.env) {
3157
+ function renderAudit(findings, total, stream = process20.stdout, env = process20.env) {
3100
3158
  const id = role("id", stream, env);
3101
3159
  const label = role("label", stream, env);
3102
3160
  const warning = role("warn", stream, env);
@@ -3117,7 +3175,7 @@ async function audit(args) {
3117
3175
  const level = values.level ?? "moderate";
3118
3176
  if (!isSeverity(level))
3119
3177
  fail(`--level takes ${SEVERITIES.join(", ")}, not ${level}`);
3120
- const dir = resolve6(asked ?? process19.cwd());
3178
+ const dir = resolve6(asked ?? process20.cwd());
3121
3179
  const lock = Bun.file(join9(dir, "bun.lock"));
3122
3180
  if (!await lock.exists())
3123
3181
  fail(`no bun.lock in ${dir}`);
@@ -3146,7 +3204,7 @@ async function audit(args) {
3146
3204
  }
3147
3205
  var usage3 = `pkg audit [dir]
3148
3206
 
3149
- Reads the bun.lock in the folder (the current one by default) and runs on every registry package it pins the checks \`pkg check\` runs before an add: age, install scripts, a deprecated version, a near miss of a popular name, and the licence allowlist of the pkg config. It also lists the known advisories of each version, with the GHSA, the severity and the fixed version, from the registry's bulk advisory endpoint, the one \`bun audit\` reads.
3207
+ Reads the bun.lock in the folder (the current one by default) and runs on every registry package it pins the checks \`pkg check\` runs before an add: age, install scripts, a deprecated version, a changed publisher or lost attestation, a near miss of a popular name, and the licence allowlist of the pkg config. It also lists the known advisories of each version, with the GHSA, the severity and the fixed version, from the registry's bulk advisory endpoint, the one \`bun audit\` reads.
3150
3208
  Findings are grouped per package, each registry package looked up once per run.
3151
3209
  Reach for it to vet one repository in depth; \`audit\` sweeps many repositories for advisories only, and shares --level, --prod and --ignore.`, EXITS2, options2, BATCH = 8, HIGH_SEVERITIES;
3152
3210
  var init_audit = __esm(() => {
@@ -3245,6 +3303,134 @@ var init_outdated = __esm(() => {
3245
3303
  };
3246
3304
  });
3247
3305
 
3306
+ // ../kit/src/answers.ts
3307
+ var init_answers = __esm(() => {
3308
+ init_folders();
3309
+ });
3310
+
3311
+ // ../kit/src/job.ts
3312
+ import process21 from "process";
3313
+ function stopJob() {
3314
+ process21.kill(0, "SIGTSTP");
3315
+ }
3316
+ var init_job = () => {};
3317
+
3318
+ // ../kit/src/picker/line.ts
3319
+ function isEditKey(key) {
3320
+ return EDIT_KEYS.has(key);
3321
+ }
3322
+ function endsKills(key) {
3323
+ return typeof key !== "object" && !isEditKey(key);
3324
+ }
3325
+ function isWord(char) {
3326
+ return char !== undefined && WORD_CHARACTER.test(char);
3327
+ }
3328
+ function wordStart(chars, from) {
3329
+ let at = from;
3330
+ while (at > 0 && !isWord(chars[at - 1]))
3331
+ at--;
3332
+ while (at > 0 && isWord(chars[at - 1]))
3333
+ at--;
3334
+ return at;
3335
+ }
3336
+ function wordEnd(chars, from) {
3337
+ let at = from;
3338
+ while (at < chars.length && !isWord(chars[at]))
3339
+ at++;
3340
+ while (at < chars.length && isWord(chars[at]))
3341
+ at++;
3342
+ return at;
3343
+ }
3344
+ function spacedStart(chars, from) {
3345
+ let at = from;
3346
+ while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
3347
+ at--;
3348
+ while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
3349
+ at--;
3350
+ return at;
3351
+ }
3352
+ function cut(chars, from, to) {
3353
+ return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
3354
+ }
3355
+ function insert(chars, at, text) {
3356
+ const typed = [...text];
3357
+ return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
3358
+ }
3359
+ function editLine(line, key) {
3360
+ const { killed = "", chained = false } = line;
3361
+ const chars = [...line.text];
3362
+ const at = Math.min(Math.max(line.caret, 0), chars.length);
3363
+ const edited = edit(chars, at, key, killed);
3364
+ if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
3365
+ return line.killed === undefined ? edited : { ...edited, killed };
3366
+ const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
3367
+ if (taken === "")
3368
+ return { ...edited, killed, chained };
3369
+ if (!chained)
3370
+ return { ...edited, killed: taken, chained: true };
3371
+ return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
3372
+ }
3373
+ function edit(chars, at, key, killed) {
3374
+ const text = chars.join("");
3375
+ if (typeof key === "object")
3376
+ return insert(chars, at, key.text);
3377
+ switch (key) {
3378
+ case "left":
3379
+ return { text, caret: Math.max(at - 1, 0) };
3380
+ case "right":
3381
+ return { text, caret: Math.min(at + 1, chars.length) };
3382
+ case "wordleft":
3383
+ return { text, caret: wordStart(chars, at) };
3384
+ case "wordright":
3385
+ return { text, caret: wordEnd(chars, at) };
3386
+ case "linestart":
3387
+ return { text, caret: 0 };
3388
+ case "lineend":
3389
+ return { text, caret: chars.length };
3390
+ case "erase":
3391
+ return cut(chars, Math.max(at - 1, 0), at);
3392
+ case "delete":
3393
+ return cut(chars, at, Math.min(at + 1, chars.length));
3394
+ case "word":
3395
+ return cut(chars, spacedStart(chars, at), at);
3396
+ case "killword":
3397
+ return cut(chars, wordStart(chars, at), at);
3398
+ case "killnext":
3399
+ return cut(chars, at, wordEnd(chars, at));
3400
+ case "clear":
3401
+ return cut(chars, 0, at);
3402
+ case "killend":
3403
+ return cut(chars, at, chars.length);
3404
+ case "yank":
3405
+ return insert(chars, at, killed);
3406
+ }
3407
+ }
3408
+ function visible({ text, caret }, room) {
3409
+ const chars = [...text];
3410
+ const at = Math.min(Math.max(caret, 0), chars.length);
3411
+ const cells = at === chars.length ? [...chars, " "] : chars;
3412
+ const widths = cells.map((char) => Bun.stringWidth(char));
3413
+ const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
3414
+ const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
3415
+ let start = at;
3416
+ let end = at + 1;
3417
+ while (start > 0 && fits(start - 1, end))
3418
+ start--;
3419
+ while (end < cells.length && fits(start, end + 1))
3420
+ end++;
3421
+ const left = start > 0 ? "\u2026" : "";
3422
+ const right = end < cells.length ? "\u2026" : "";
3423
+ return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
3424
+ }
3425
+ var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
3426
+ var init_line = __esm(() => {
3427
+ EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
3428
+ BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
3429
+ FORWARD_KILLS = new Set(["killnext", "killend"]);
3430
+ WORD_CHARACTER = /[\p{L}\p{N}_]/u;
3431
+ SPACE = /\s/;
3432
+ });
3433
+
3248
3434
  // ../kit/src/picker/score.ts
3249
3435
  var BOUNDARY_AFTER, NONE;
3250
3436
  var init_score = __esm(() => {
@@ -3278,6 +3464,8 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
3278
3464
  }
3279
3465
  var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
3280
3466
  var init_state = __esm(() => {
3467
+ init_text2();
3468
+ init_line();
3281
3469
  init_score();
3282
3470
  IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
3283
3471
  KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
@@ -3301,10 +3489,29 @@ var init_state = __esm(() => {
3301
3489
  "\n": "enter",
3302
3490
  "\x03": "cancel",
3303
3491
  "\x1B": "cancel",
3492
+ "\x1B[D": "left",
3493
+ "\x1BOD": "left",
3494
+ "\x1B[C": "right",
3495
+ "\x1BOC": "right",
3496
+ "\x1B[1;5D": "wordleft",
3497
+ "\x1B[1;3D": "wordleft",
3498
+ "\x1Bb": "wordleft",
3499
+ "\x1B[1;5C": "wordright",
3500
+ "\x1B[1;3C": "wordright",
3501
+ "\x1Bf": "wordright",
3502
+ "\x01": "linestart",
3503
+ "\x05": "lineend",
3304
3504
  "\x7F": "erase",
3305
- "\b": "erase",
3505
+ "\x1B[3~": "delete",
3506
+ "\b": "killword",
3507
+ "\x1B\x7F": "killword",
3508
+ "\x1B[3;5~": "killnext",
3509
+ "\x1Bd": "killnext",
3306
3510
  "\x15": "clear",
3511
+ "\v": "killend",
3307
3512
  "\x17": "word",
3513
+ "\x19": "yank",
3514
+ "\x1A": "suspend",
3308
3515
  "\t": "tab",
3309
3516
  "\x1F": "help",
3310
3517
  "\x1BOP": "help",
@@ -3312,10 +3519,31 @@ var init_state = __esm(() => {
3312
3519
  };
3313
3520
  });
3314
3521
 
3522
+ // ../kit/src/redraw.ts
3523
+ function overwrite(lines, columns) {
3524
+ return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
3525
+ `);
3526
+ }
3527
+ function rowsTaken(lines, columns) {
3528
+ return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
3529
+ }
3530
+ var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
3531
+ var init_redraw = __esm(() => {
3532
+ init_format();
3533
+ });
3534
+
3315
3535
  // ../kit/src/prompt.ts
3316
- import process20 from "process";
3536
+ import process22 from "process";
3317
3537
  function readKeys(input, paste = { active: false }) {
3318
- return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
3538
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
3539
+ }
3540
+ function roomAfter(question, columns) {
3541
+ return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
3542
+ }
3543
+ function withCaret(colors, line, room, dim = false) {
3544
+ const { before, at, after } = visible(line, room);
3545
+ const tone = dim ? colors.dim : (text) => text;
3546
+ return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
3319
3547
  }
3320
3548
  function flip(checked, value) {
3321
3549
  const next = new Set(checked);
@@ -3327,7 +3555,7 @@ async function checklist(question, choices, { initial = new Set, min = 0, toggle
3327
3555
  const list = new List(choices, 0);
3328
3556
  let checked = initial;
3329
3557
  let invalid;
3330
- const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.query, "type to filter, space toggles, enter accepts"), ...list.rows(colors, rows, (choice) => checked.has(choice.value) ? `${colors.cyan("\u25C9")} ` : `${colors.dim("\u25EF")} `), ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]] : [answer(colors, question, state, choices.filter((choice) => checked.has(choice.value)).map((choice) => choice.label).join(", ") || "none")], (key) => {
3558
+ const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.typed(colors, rows.columns, question), "type to filter, space toggles, enter accepts"), ...list.rows(colors, rows, (choice) => checked.has(choice.value) ? `${colors.cyan("\u25C9")} ` : `${colors.dim("\u25EF")} `), ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]] : [answer(colors, question, state, choices.filter((choice) => checked.has(choice.value)).map((choice) => choice.label).join(", ") || "none")], (key) => {
3331
3559
  if (key === "cancel")
3332
3560
  return key;
3333
3561
  invalid = undefined;
@@ -3365,7 +3593,7 @@ async function confirm(question, { default: fallback, ...settings } = {}) {
3365
3593
 
3366
3594
  class List {
3367
3595
  choices;
3368
- query = "";
3596
+ line = { text: "", caret: 0 };
3369
3597
  matches;
3370
3598
  cursor;
3371
3599
  top = 0;
@@ -3380,6 +3608,8 @@ class List {
3380
3608
  return this.matches[this.cursor];
3381
3609
  }
3382
3610
  press(key) {
3611
+ if (this.line.chained === true && endsKills(key))
3612
+ this.line = { ...this.line, chained: false };
3383
3613
  if (key === "up" || key === "down") {
3384
3614
  if (this.matches.length > 0)
3385
3615
  this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
@@ -3391,15 +3621,19 @@ class List {
3391
3621
  this.cursor = Math.max(0, Math.min(last, to));
3392
3622
  return;
3393
3623
  }
3394
- if (key === "erase")
3395
- this.filter([...this.query].slice(0, -1).join(""));
3396
- else if (typeof key === "object")
3397
- this.filter(this.query + key.text);
3624
+ if (typeof key !== "object" && !isEditKey(key))
3625
+ return;
3626
+ const edited = editLine(this.line, key);
3627
+ if (edited.text !== this.line.text)
3628
+ this.filter(edited.text);
3629
+ this.line = edited;
3630
+ }
3631
+ typed(colors, columns, question) {
3632
+ return this.line.text === "" ? "" : withCaret(colors, this.line, roomAfter(question, columns));
3398
3633
  }
3399
3634
  filter(query) {
3400
3635
  const words = query.toLowerCase().split(WORDS2).filter((word) => word !== "");
3401
3636
  const current = this.current();
3402
- this.query = query;
3403
3637
  this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
3404
3638
  this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
3405
3639
  this.top = 0;
@@ -3427,7 +3661,7 @@ function asking(colors, question, typed, keys) {
3427
3661
  function answer(colors, question, state, picked) {
3428
3662
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
3429
3663
  }
3430
- async function ask(question, { hint, terminal = process20 }, render, press) {
3664
+ async function ask(question, { hint, terminal = process22 }, render, press) {
3431
3665
  const { stdin, stderr } = terminal;
3432
3666
  if (!isInteractive(terminal))
3433
3667
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
@@ -3437,12 +3671,22 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
3437
3671
  const columns = () => stderr.columns || 80;
3438
3672
  const draw = (state, last = false) => {
3439
3673
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
3440
- stderr.write(`\r\x1B[0J${frame.join(`
3441
- `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
3674
+ const rows = rowsTaken(frame, columns());
3675
+ stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
3442
3676
  current = state;
3443
3677
  };
3444
3678
  const redraw = () => draw(current);
3445
3679
  const paste = { active: false };
3680
+ const stop = terminal.stop ?? (terminal === process22 ? stopJob : undefined);
3681
+ const suspend = () => {
3682
+ if (stop === undefined)
3683
+ return;
3684
+ stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
3685
+ stdin.setRawMode(false);
3686
+ stop();
3687
+ stdin.setRawMode(true);
3688
+ stderr.write("\x1B[?25l\x1B[?2004h");
3689
+ };
3446
3690
  try {
3447
3691
  stderr.on?.("resize", redraw);
3448
3692
  stdin.setRawMode(true);
@@ -3452,6 +3696,10 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
3452
3696
  return await new Promise((resolve) => {
3453
3697
  function onData(data) {
3454
3698
  for (const key of readKeys(data.toString(), paste)) {
3699
+ if (key === "suspend") {
3700
+ suspend();
3701
+ continue;
3702
+ }
3455
3703
  const pressed = press(key);
3456
3704
  if (pressed !== undefined) {
3457
3705
  settle(pressed);
@@ -3483,13 +3731,17 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
3483
3731
  }
3484
3732
  var WORDS2, MAX_ROWS = 10, PROMPT_KEYS;
3485
3733
  var init_prompt = __esm(() => {
3734
+ init_answers();
3486
3735
  init_args();
3487
3736
  init_format();
3737
+ init_job();
3488
3738
  init_mode();
3739
+ init_line();
3489
3740
  init_state();
3741
+ init_redraw();
3490
3742
  init_style();
3491
3743
  WORDS2 = /\s+/;
3492
- PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
3744
+ PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
3493
3745
  });
3494
3746
 
3495
3747
  // src/excluded.ts
@@ -3850,7 +4102,7 @@ var exports_manager = {};
3850
4102
  __export(exports_manager, {
3851
4103
  manager: () => manager
3852
4104
  });
3853
- import process21 from "process";
4105
+ import process23 from "process";
3854
4106
  function manager(args) {
3855
4107
  const { values, positionals } = parse(args, usage7, options6, {
3856
4108
  exits: EXITS6,
@@ -3860,7 +4112,7 @@ function manager(args) {
3860
4112
  examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
3861
4113
  });
3862
4114
  const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
3863
- const found = detectManager(process21.cwd());
4115
+ const found = detectManager(process23.cwd());
3864
4116
  const command = commandFor(action, found);
3865
4117
  if (values.json === true)
3866
4118
  printJson({ manager: found, action, command });
@@ -3882,8 +4134,8 @@ var init_manager2 = __esm(() => {
3882
4134
 
3883
4135
  // src/cli.ts
3884
4136
  init_src();
3885
- import process22 from "process";
3886
- process22.exitCode = await runCli({
4137
+ import process24 from "process";
4138
+ process24.exitCode = await runCli({
3887
4139
  name: "pkg",
3888
4140
  about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
3889
4141
  replaces: "bun add on trust, and a bun info and sleep loop then a bun add per consumer",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pkg",
3
3
  "type": "module",
4
- "version": "0.15.1",
4
+ "version": "0.16.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.38.3"
36
+ "@kaynooo/cli-kit": "0.40.0"
37
37
  }
38
38
  }