@kaynooo/cli-pkg 0.9.0 → 0.11.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 +2 -1
  2. package/dist/cli.js +365 -24
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -28,6 +28,7 @@ pkg outdated
28
28
  ```
29
29
 
30
30
  - `licenses` is the allowlist of SPDX ids, compared without regard to case. An expression is allowed when one side of an `OR` is and every term of an `AND` is; a `WITH` exception is ignored. With an allowlist set, `pkg check` refuses a package whose licence is outside it or missing (a legacy `SEE LICENSE IN` or `UNLICENSED` counts as outside), so the `bun add` the guard checks through `pkg check` is refused with it. Without the key the licence is only printed.
31
+ - `minAge` (a whole number of days, 14 when no config sets it) is how old a version must be when `--min-age` is not given, in `check`, `audit` and `outdated`.
31
32
  - `blockSeverity` (`low`, `moderate`, `high` or `critical`, `high` when no config sets it) makes `pkg check` ask the registry for the advisories of the exact `name@version` and refuse it when one is at that severity or above. The request is the one `bun audit` makes: a `POST` of `{"name": ["version"]}` to `<registry>/-/npm/v1/security/advisories/bulk`. A registry without that endpoint (a private one, say) leaves the version unrefused with a warning, while an advisory request that fails (unreachable, a 5xx, not JSON) exits 2, since the advisories could not be read.
32
33
 
33
34
  ## Auditing a lockfile
@@ -55,7 +56,7 @@ pkg bump @kaynooo/cli-kit 0.8.0 --dry-run
55
56
  ```
56
57
 
57
58
  - `pkg consumers <name>` lists every `package.json` under `--root` (the configured workspace folder, `~/Workspace` by default) depending on the package, `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` and dot folders left out and nothing deeper than 5 levels below `--root` (point `--root` at the folder to reach further): the folder, the kind of dependency, the version it asks for and the manager its nearest lockfile pins; `--json` for the rows.
58
- - `pkg bump <name> [version]` waits until the package's registry serves the version (every 5 s, `-t 10m`; the latest when none is given, an exact version otherwise, never a range or a tag), then vets it with the checks of `pkg check` (advisories, licence allowlist) before any folder is touched, and runs `bun add --exact --no-cache <name>@<version>` in each of those folders, one after another, as the same kind of dependency (`--dev`, `--optional`), a line per folder. A version the vetting blocks is refused with its reasons and exit 1; `--force` bumps it anyway. A bump adopts a release on purpose, often one just made, so it checks no minimum age unless `--min-age <days>` asks for one. A dependency declared through an alias of the package (`"kay": "npm:@scope/name@~1.2.0"`) is found and bumped under its own key, keeping its `~` or `^`; `--only <name|glob>` and `--except <name|glob>` (repeatable) narrow the folders, and a package nothing depends on names similar dependencies. A dependency that is not a registry version (`workspace:`, `link:`, `file:`, `git`, a URL, another package's `npm:` alias, `catalog:`), a `peerDependencies` range, a folder already on the version and one whose lockfile pins another manager are left alone and said so; `--dry-run` prints what would run. A transient registry error is retried until the timeout. It exits 1 when the vetting refuses the version, an install fails or the registry has no such package (at once, without waiting), 2 when the version never shows within the timeout.
59
+ - `pkg bump <name> [version]` waits until the package's registry serves the version (every 5 s, `-t 10m`; the latest when none is given, an exact version otherwise, never a range or a tag), then vets it with the checks of `pkg check` (advisories, licence allowlist) before any folder is touched, and runs `bun add --exact --no-cache <name>@<version>` in each of those folders, one after another, as the same kind of dependency (`--dev`, `--optional`), a line per folder. A version the vetting blocks is refused with its reasons and exit 1; `--force` bumps it anyway. A bump adopts a release on purpose, often one just made, so it checks no minimum age unless `--min-age <days>` asks for one. A dependency declared through an alias of the package (`"kay": "npm:@scope/name@~1.2.0"`) is found and bumped under its own key, keeping its `~` or `^`; `--only <name|glob>` and `--except <name|glob>` (repeatable) narrow the folders, and a package nothing depends on names similar dependencies. A dependency that is not a registry version (`workspace:`, `link:`, `file:`, `git`, a URL, another package's `npm:` alias, `catalog:`), a `peerDependencies` range, a folder already on the version and one whose lockfile pins another manager are left alone and said so; `--dry-run` prints what would run. On a terminal with no `--only` or `--except`, a checklist asks which consumers to bump (the ones left out last time unchecked, what is unchecked now remembered in `~/.config/kaynooo-cli/pkg-excluded.json`), then the plan is printed and confirmed; `--yes` skips both, as a pipe does. A transient registry error is retried until the timeout. It exits 1 when the vetting refuses the version, an install fails or the registry has no such package (at once, without waiting), 2 when the version never shows within the timeout.
59
60
  - `pkg bump <name> [version] --all-consumers` leaves alone a folder whose `package.json` or lockfile already has uncommitted changes, so that `gc` never commits them as the bump, and goes on in each folder whose install went through: it runs the folder's own `check` and, only when that passes, commits with `gc 'chore(deps): bump <name> to <version>' -- package.json <lockfile>` (the `bun.lock` or `bun.lockb` nearest the folder, a monorepo's at its root). A folder whose check fails stays uncommitted. It ends on a summary line of the folders bumped and committed, bumped and failing, and skipped, exits 1 when an install, a check or a commit failed, and never pushes. With `--dry-run` it lists the `bun add`, `check` and `gc` each folder would run.
60
61
  - `pkg <name>` alone still runs `pkg check`.
61
62
  - `pkg check --from <package.json>` checks every registry dependency of a manifest (`dependencies`, `devDependencies` and `optionalDependencies`, each as `name@range` so it resolves what an install would; peer ranges and `workspace:`, `link:`, `file:`, git, URL and `npm:` sources left out). Names also come from stdin, separated by spaces or lines, with `-` as the argument or when nothing else names a package and stdin is piped; the three sources add up.
package/dist/cli.js CHANGED
@@ -53,6 +53,9 @@ function outputMode(stream = process2.stdout, env = process2.env) {
53
53
  return "terminal";
54
54
  return isSet(env.CI) ? "ci" : "pipe";
55
55
  }
56
+ function isInteractive(streams = process2) {
57
+ return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
58
+ }
56
59
  var MODES, AGENT_VARIABLES;
57
60
  var init_mode = __esm(() => {
58
61
  MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -1177,25 +1180,28 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1177
1180
  } };
1178
1181
  const write = stream.write.bind(stream);
1179
1182
  let frame = 0;
1180
- let drawn = 0;
1183
+ let drawn = [];
1184
+ const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1185
+ const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
1181
1186
  const clear = () => {
1182
- if (drawn > 0)
1183
- write(`${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}`);
1184
- drawn = 0;
1187
+ if (drawn.length > 0)
1188
+ write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1189
+ drawn = [];
1185
1190
  };
1186
1191
  const draw = () => {
1187
- const width = (stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns) - 1;
1192
+ const width = columns() - 1;
1188
1193
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
1189
1194
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
1190
1195
  if (lines.length === 0) {
1191
1196
  clear();
1192
1197
  return;
1193
1198
  }
1194
- write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}` : CLEAR_LINE}${lines.join(`
1199
+ write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1195
1200
  `)}`);
1196
- drawn = lines.length;
1201
+ drawn = lines.map((line) => Bun.stringWidth(line));
1197
1202
  };
1198
1203
  const timer = setInterval(draw, FRAME_MS);
1204
+ stream.on?.("resize", draw);
1199
1205
  const restore = interceptOutput(clear);
1200
1206
  const release = swallowInput();
1201
1207
  const onExit = () => {
@@ -1205,6 +1211,7 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1205
1211
  const signals = holdSignals(stop);
1206
1212
  function stop() {
1207
1213
  clearInterval(timer);
1214
+ stream.off?.("resize", draw);
1208
1215
  clear();
1209
1216
  restore();
1210
1217
  release();
@@ -1722,6 +1729,13 @@ var init_sessions = __esm(() => {
1722
1729
  // ../kit/src/size.ts
1723
1730
  var init_size = () => {};
1724
1731
 
1732
+ // ../kit/src/watch.ts
1733
+ var init_watch = __esm(() => {
1734
+ init_args();
1735
+ init_input();
1736
+ init_style();
1737
+ });
1738
+
1725
1739
  // ../kit/src/workspace-root.ts
1726
1740
  import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1727
1741
  import { homedir as homedir4 } from "os";
@@ -1775,6 +1789,7 @@ var init_src = __esm(() => {
1775
1789
  init_tool();
1776
1790
  init_usage();
1777
1791
  init_user_config();
1792
+ init_watch();
1778
1793
  init_workspace_root();
1779
1794
  });
1780
1795
 
@@ -2732,6 +2747,8 @@ function parseSettings(text) {
2732
2747
  settings.licenses = raw.licenses;
2733
2748
  if (isSeverity(raw?.blockSeverity))
2734
2749
  settings.blockSeverity = raw.blockSeverity;
2750
+ if (typeof raw?.minAge === "number" && Number.isInteger(raw.minAge) && raw.minAge >= 0)
2751
+ settings.minAge = raw.minAge;
2735
2752
  return settings;
2736
2753
  }
2737
2754
  async function loadSettings(cwd = process17.cwd(), home) {
@@ -2747,6 +2764,7 @@ async function loadSettings(cwd = process17.cwd(), home) {
2747
2764
  const found = readable(file, () => parseSettings(text));
2748
2765
  settings.licenses ??= found.licenses;
2749
2766
  settings.blockSeverity ??= found.blockSeverity;
2767
+ settings.minAge ??= found.minAge;
2750
2768
  }
2751
2769
  return settings;
2752
2770
  }
@@ -3017,7 +3035,8 @@ async function check(args) {
3017
3035
  fail(values.from === undefined ? `a package name is needed
3018
3036
 
3019
3037
  ${usage2}` : `${values.from} has no registry dependency to check`);
3020
- const context = { configs: await loadConfigs(), settings: await loadSettings(), minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0) };
3038
+ const settings = await loadSettings();
3039
+ const context = { configs: await loadConfigs(), settings, minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0) };
3021
3040
  const reports = await Promise.all(positionals.map(async (text) => checkPackage(text, context)));
3022
3041
  if (values.json === true)
3023
3042
  printJson(reports.length === 1 ? reports[0] : reports);
@@ -3044,7 +3063,7 @@ var init_check = __esm(() => {
3044
3063
  EXITS = [[0, "every package passes"], [1, "one is blocked: missing, the version asked for is under the minimum age or has no date, its licence is outside the allowlist or an advisory reaches the threshold"], [2, "it could not check (the registry unreachable, slow or answering badly, a broken .pkgrc.json, bunfig.toml or .npmrc) or a usage error"]];
3045
3064
  options = {
3046
3065
  json: jsonOption(),
3047
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3066
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3048
3067
  from: { type: "string", description: "check the dependencies of this package.json" }
3049
3068
  };
3050
3069
  WORDS = /\s+/;
@@ -3184,10 +3203,11 @@ async function audit(args) {
3184
3203
  const text = await lock.text();
3185
3204
  const production = values.prod === true ? productionPackages(text) : undefined;
3186
3205
  const packages = parseBunLock(text).filter(({ name, version }) => production?.has(`${name}@${version}`) ?? true);
3206
+ const settings = await loadSettings(dir);
3187
3207
  const context = {
3188
3208
  configs: await loadConfigs(dir),
3189
- settings: await loadSettings(dir),
3190
- minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0),
3209
+ settings,
3210
+ minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0),
3191
3211
  level,
3192
3212
  ignore: values.ignore ?? []
3193
3213
  };
@@ -3218,7 +3238,7 @@ var init_audit = __esm(() => {
3218
3238
  EXITS2 = [[0, "nothing blocks"], [1, "a package is missing, too fresh or outside the licence allowlist, or an advisory reaches --level"], [2, "the registry could not be reached or answered badly (a warning says which, and nothing is reported as clean), a usage error or no bun.lock"]];
3219
3239
  options2 = {
3220
3240
  json: jsonOption("[{name, version, license, blocked, warnings, advisories}] for the packages with a finding"),
3221
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3241
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3222
3242
  level: { type: "string", description: "lowest advisory severity listed and failing: low, moderate, high, critical (moderate)" },
3223
3243
  prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
3224
3244
  ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
@@ -3270,7 +3290,7 @@ async function outdatedCommand(args) {
3270
3290
  fail(`no package.json in ${folder}`);
3271
3291
  const lockPath = join10(folder, "bun.lock");
3272
3292
  const locked = existsSync6(lockPath) ? parseBunLock(await Bun.file(lockPath).text()) : [];
3273
- const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0), locked });
3293
+ const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", (await loadSettings(folder)).minAge ?? DEFAULT_MIN_AGE_DAYS, 0), locked });
3274
3294
  const { shown, footer } = capped(rows, limitOf(values, OUTDATED_LIMIT));
3275
3295
  if (values.json === true)
3276
3296
  printJson(shown);
@@ -3296,20 +3316,302 @@ var init_outdated = __esm(() => {
3296
3316
  FIRST_VERSION = /\d+(?:\.\d+){0,2}(?:-[\w.-]+)?/;
3297
3317
  DOT = /[.-]/;
3298
3318
  options3 = {
3299
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3319
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3300
3320
  ...limitOptions(OUTDATED_LIMIT),
3301
3321
  json: jsonOption("[{name, kind, spec, current, safe, change, published, latest?}]")
3302
3322
  };
3303
3323
  });
3304
3324
 
3325
+ // ../kit/src/picker/score.ts
3326
+ var BOUNDARY_AFTER, NONE;
3327
+ var init_score = __esm(() => {
3328
+ BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
3329
+ NONE = Number.NEGATIVE_INFINITY;
3330
+ });
3331
+
3332
+ // ../kit/src/picker/state.ts
3333
+ function parseKeys(input, paste = { active: false }, ctrls = []) {
3334
+ const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
3335
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
3336
+ const named = codes.get(sequence);
3337
+ const key = named === undefined ? KEYS[sequence] : { ctrl: named };
3338
+ if (sequence === PASTE_START || sequence === PASTE_END) {
3339
+ paste.active = sequence === PASTE_START;
3340
+ return [];
3341
+ }
3342
+ if (paste.active && (sequence === "\r" || sequence === `
3343
+ `))
3344
+ return [];
3345
+ if (key !== undefined)
3346
+ return [key];
3347
+ return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
3348
+ });
3349
+ }
3350
+ var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, KEYS;
3351
+ var init_state = __esm(() => {
3352
+ init_score();
3353
+ IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
3354
+ KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
3355
+ KEYS = {
3356
+ "\x1B[A": "up",
3357
+ "\x1BOA": "up",
3358
+ "\x10": "up",
3359
+ "\x1B[B": "down",
3360
+ "\x1BOB": "down",
3361
+ "\x0E": "down",
3362
+ "\x1B[5~": "pageup",
3363
+ "\x1B[6~": "pagedown",
3364
+ "\x1B[H": "home",
3365
+ "\x1B[1~": "home",
3366
+ "\x1BOH": "home",
3367
+ "\x1B[F": "end",
3368
+ "\x1B[4~": "end",
3369
+ "\x1BOF": "end",
3370
+ "\r": "enter",
3371
+ "\n": "enter",
3372
+ "\x03": "cancel",
3373
+ "\x1B": "cancel",
3374
+ "\x7F": "erase",
3375
+ "\b": "erase",
3376
+ "\x15": "clear",
3377
+ "\x17": "word",
3378
+ "\t": "tab",
3379
+ "\x1F": "help",
3380
+ "\x1BOP": "help",
3381
+ "\x1B[11~": "help"
3382
+ };
3383
+ });
3384
+
3385
+ // ../kit/src/prompt.ts
3386
+ import process19 from "process";
3387
+ function readKeys(input, paste = { active: false }) {
3388
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
3389
+ }
3390
+ function flip(checked, value) {
3391
+ const next = new Set(checked);
3392
+ if (!next.delete(value))
3393
+ next.add(value);
3394
+ return next;
3395
+ }
3396
+ async function checklist(question, choices, { initial = new Set, min = 0, toggle = flip, ...settings } = {}) {
3397
+ const list = new List(choices, 0);
3398
+ let checked = initial;
3399
+ let invalid;
3400
+ 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) => {
3401
+ if (key === "cancel")
3402
+ return key;
3403
+ invalid = undefined;
3404
+ if (key === "enter") {
3405
+ invalid = checked.size < min ? `pick at least ${min}` : undefined;
3406
+ return invalid === undefined ? "enter" : undefined;
3407
+ }
3408
+ const current = list.current();
3409
+ if (typeof key === "object" && key.text === " ") {
3410
+ if (current !== undefined)
3411
+ checked = toggle(checked, current.value);
3412
+ return;
3413
+ }
3414
+ list.press(key);
3415
+ return;
3416
+ });
3417
+ return accepted ? checked : undefined;
3418
+ }
3419
+ async function confirm(question, { default: fallback, ...settings } = {}) {
3420
+ let answered = fallback;
3421
+ const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
3422
+ const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
3423
+ if (key === "cancel")
3424
+ return "cancel";
3425
+ if (key === "enter")
3426
+ return answered === undefined ? undefined : "enter";
3427
+ const letter = typeof key === "object" ? key.text.toLowerCase() : "";
3428
+ if (letter !== "y" && letter !== "n")
3429
+ return;
3430
+ answered = letter === "y";
3431
+ return "enter";
3432
+ });
3433
+ return accepted ? answered : undefined;
3434
+ }
3435
+
3436
+ class List {
3437
+ choices;
3438
+ query = "";
3439
+ matches;
3440
+ cursor;
3441
+ top = 0;
3442
+ width;
3443
+ constructor(choices, initial) {
3444
+ this.choices = choices;
3445
+ this.matches = choices;
3446
+ this.cursor = Math.min(Math.max(initial, 0), choices.length - 1);
3447
+ this.width = Math.max(0, ...choices.map((choice) => choice.label.length));
3448
+ }
3449
+ current() {
3450
+ return this.matches[this.cursor];
3451
+ }
3452
+ press(key) {
3453
+ if (key === "up" || key === "down") {
3454
+ if (this.matches.length > 0)
3455
+ this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
3456
+ return;
3457
+ }
3458
+ if (key === "home" || key === "end" || key === "pageup" || key === "pagedown") {
3459
+ const last = this.matches.length - 1;
3460
+ const to = { home: 0, end: last, pageup: this.cursor - MAX_ROWS, pagedown: this.cursor + MAX_ROWS }[key];
3461
+ this.cursor = Math.max(0, Math.min(last, to));
3462
+ return;
3463
+ }
3464
+ if (key === "erase")
3465
+ this.filter([...this.query].slice(0, -1).join(""));
3466
+ else if (typeof key === "object")
3467
+ this.filter(this.query + key.text);
3468
+ }
3469
+ filter(query) {
3470
+ const words = query.toLowerCase().split(WORDS2).filter((word) => word !== "");
3471
+ const current = this.current();
3472
+ this.query = query;
3473
+ this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
3474
+ this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
3475
+ this.top = 0;
3476
+ }
3477
+ rows(colors, { columns, rows }, marker) {
3478
+ if (this.matches.length === 0)
3479
+ return [colors.dim(" no match")];
3480
+ const height = Math.max(1, Math.min(MAX_ROWS, rows - 3, this.matches.length));
3481
+ this.top = Math.min(Math.max(this.top, this.cursor - height + 1), this.cursor);
3482
+ const shown = this.matches.slice(this.top, this.top + height).map((choice, index) => {
3483
+ const here = this.top + index === this.cursor;
3484
+ const mark = marker(choice);
3485
+ const head = `${here ? "\u276F" : " "} ${mark}`;
3486
+ const label = choice.label.padEnd(this.width);
3487
+ const room = columns - 5 - (mark === "" ? 0 : 2) - this.width;
3488
+ return `${here ? colors.cyan(head) : head}${here ? colors.cyan(label) : label} ${colors.dim(truncate(choice.hint, Math.max(room, 0)))}`;
3489
+ });
3490
+ const below = this.matches.length - this.top - height;
3491
+ return [...this.top > 0 ? [colors.dim(` \u2026 ${this.top} more`)] : [], ...shown, ...below > 0 ? [colors.dim(` \u2026 ${below} more`)] : []];
3492
+ }
3493
+ }
3494
+ function asking(colors, question, typed, keys) {
3495
+ return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
3496
+ }
3497
+ function answer(colors, question, state, picked) {
3498
+ return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
3499
+ }
3500
+ async function ask(question, { hint, terminal = process19 }, render, press) {
3501
+ const { stdin, stderr } = terminal;
3502
+ if (!isInteractive(terminal))
3503
+ fail(`cannot ask "${question}" off a terminal`, 2, hint);
3504
+ const colors = paint(stderr);
3505
+ let drawn = [];
3506
+ let current = "asking";
3507
+ let outcome;
3508
+ const columns = () => stderr.columns || 80;
3509
+ const draw = (state) => {
3510
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
3511
+ const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
3512
+ stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
3513
+ `)}`);
3514
+ drawn = frame;
3515
+ current = state;
3516
+ };
3517
+ const redraw = () => draw(current);
3518
+ const paste = { active: false };
3519
+ try {
3520
+ stderr.on?.("resize", redraw);
3521
+ stdin.setRawMode(true);
3522
+ stdin.resume();
3523
+ stderr.write("\x1B[?25l\x1B[?2004h");
3524
+ draw("asking");
3525
+ return await new Promise((resolve) => {
3526
+ function onData(data) {
3527
+ for (const key of readKeys(data.toString(), paste)) {
3528
+ const pressed = press(key);
3529
+ if (pressed !== undefined) {
3530
+ settle(pressed);
3531
+ return;
3532
+ }
3533
+ }
3534
+ draw("asking");
3535
+ }
3536
+ function onEnd() {
3537
+ settle("cancel");
3538
+ }
3539
+ function settle(settled) {
3540
+ outcome = settled;
3541
+ stdin.off("data", onData);
3542
+ stdin.off("end", onEnd);
3543
+ resolve(settled === "enter");
3544
+ }
3545
+ stdin.on("data", onData);
3546
+ stdin.on("end", onEnd);
3547
+ });
3548
+ } finally {
3549
+ stderr.off?.("resize", redraw);
3550
+ draw(outcome ?? "cancel");
3551
+ stderr.write(`
3552
+ \x1B[?25h\x1B[?2004l`);
3553
+ stdin.setRawMode(false);
3554
+ stdin.pause();
3555
+ }
3556
+ }
3557
+ var WORDS2, MAX_ROWS = 10, PROMPT_KEYS;
3558
+ var init_prompt = __esm(() => {
3559
+ init_args();
3560
+ init_format();
3561
+ init_mode();
3562
+ init_state();
3563
+ init_style();
3564
+ WORDS2 = /\s+/;
3565
+ PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
3566
+ });
3567
+
3568
+ // src/excluded.ts
3569
+ import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "fs";
3570
+ import { dirname as dirname7 } from "path";
3571
+ function excludedPath(home) {
3572
+ return userConfigPath("pkg-excluded", { home });
3573
+ }
3574
+ function loadExcluded(home) {
3575
+ const path = excludedPath(home);
3576
+ if (!existsSync7(path))
3577
+ return {};
3578
+ try {
3579
+ const raw = JSON.parse(readFileSync5(path, "utf8"));
3580
+ const excluded = {};
3581
+ for (const [name, dirs] of Object.entries(raw)) {
3582
+ if (Array.isArray(dirs))
3583
+ excluded[name] = dirs.filter((dir) => typeof dir === "string");
3584
+ }
3585
+ return excluded;
3586
+ } catch {
3587
+ return;
3588
+ }
3589
+ }
3590
+ function saveExcluded(name, dirs, home) {
3591
+ const path = excludedPath(home);
3592
+ const excluded = loadExcluded(home);
3593
+ if (excluded === undefined)
3594
+ return;
3595
+ if (dirs.length === 0)
3596
+ delete excluded[name];
3597
+ else
3598
+ excluded[name] = [...dirs].toSorted();
3599
+ mkdirSync3(dirname7(path), { recursive: true });
3600
+ writeFileSync2(path, `${JSON.stringify(excluded, null, 2)}
3601
+ `);
3602
+ }
3603
+ var init_excluded = __esm(() => {
3604
+ init_src();
3605
+ });
3606
+
3305
3607
  // src/commands/bump.ts
3306
3608
  var exports_bump = {};
3307
3609
  __export(exports_bump, {
3308
3610
  ROOT_OPTION: () => ROOT_OPTION,
3309
3611
  bump: () => bump
3310
3612
  });
3311
- import { existsSync as existsSync7 } from "fs";
3312
- import { basename, dirname as dirname7, join as join11, relative as relative2 } from "path";
3613
+ import { existsSync as existsSync8 } from "fs";
3614
+ import { basename, dirname as dirname8, join as join11, relative as relative2 } from "path";
3313
3615
  async function lookup(name, registry, fetcher) {
3314
3616
  try {
3315
3617
  return { packument: await fetchPackument(name, registry, fetcher) };
@@ -3369,11 +3671,11 @@ async function vet(name, version, settings) {
3369
3671
  return false;
3370
3672
  }
3371
3673
  function lockfileOf(dir, root) {
3372
- for (let at = dir;; at = dirname7(at)) {
3373
- const found = ["bun.lock", "bun.lockb"].find((file) => existsSync7(join11(at, file)));
3674
+ for (let at = dir;; at = dirname8(at)) {
3675
+ const found = ["bun.lock", "bun.lockb"].find((file) => existsSync8(join11(at, file)));
3374
3676
  if (found !== undefined)
3375
3677
  return relative2(dir, join11(at, found));
3376
- if (at === root || at === dirname7(at))
3678
+ if (at === root || at === dirname8(at))
3377
3679
  return;
3378
3680
  }
3379
3681
  }
@@ -3400,9 +3702,10 @@ async function bumpConsumers(name, version, settings) {
3400
3702
  const everyone = findConsumers(name, settings.root);
3401
3703
  const isOnly = matcher(settings.only ?? []);
3402
3704
  const isExcept = matcher(settings.except ?? []);
3403
- const found = everyone.filter((each) => (settings.only === undefined || settings.only.length === 0 || isOnly(each.dir)) && !isExcept(each.dir));
3705
+ const declined = new Set(settings.declined ?? []);
3706
+ const found = everyone.filter((each) => (settings.only === undefined || settings.only.length === 0 || isOnly(each.dir)) && !isExcept(each.dir) && !declined.has(each.dir));
3404
3707
  const consumers = found.filter((each) => !isLocal(each));
3405
- const left = everyone.length - found.length;
3708
+ const left = everyone.length - found.length - declined.size;
3406
3709
  const local = found.length - consumers.length;
3407
3710
  const run = settings.run ?? (async (argv, cwd) => runCommand(argv, { cwd }));
3408
3711
  const committed = [];
@@ -3415,6 +3718,8 @@ async function bumpConsumers(name, version, settings) {
3415
3718
  } else if (left > 0) {
3416
3719
  note(`${left} folder${left === 1 ? "" : "s"} left out by --only or --except`);
3417
3720
  }
3721
+ if (declined.size > 0)
3722
+ note(`${declined.size} folder${declined.size === 1 ? "" : "s"} left out by your choice`);
3418
3723
  if (local > 0)
3419
3724
  note(`${local} non-registry dependenc${local === 1 ? "y" : "ies"} (workspace:, file:, git, URL, alias, catalog:)`, "left as they are");
3420
3725
  for (const consumer of consumers) {
@@ -3461,6 +3766,26 @@ async function bumpConsumers(name, version, settings) {
3461
3766
  note("summary", `${committed.length} bumped and committed, ${failing.length} bumped and failing${failing.length > 0 ? ` (${failing.join(", ")})` : ""}, ${skipped.length + local} skipped`);
3462
3767
  return isClean;
3463
3768
  }
3769
+ function plannedBumps(name, version, settings) {
3770
+ return findConsumers(name, settings.root).filter((each) => !isLocal(each) && each.kind !== "peerDependencies" && each.manager === "bun" && (each.alias === undefined ? each.spec : wantedVersion(each).replace(RANGE_PREFIX, "")) !== version).map((each) => ({ dir: each.dir, line: `${each.dir} ${each.spec} -> ${version}` }));
3771
+ }
3772
+ async function choosePlan(name, version, settings, chooser = terminalChooser, home) {
3773
+ const plans = plannedBumps(name, version, settings);
3774
+ if (plans.length === 0)
3775
+ return;
3776
+ const excluded = new Set(loadExcluded(home)?.[name] ?? []);
3777
+ const picked = await chooser.pick(name, plans, excluded);
3778
+ if (picked === undefined)
3779
+ return { chosen: [], declined: plans.map((plan) => plan.dir) };
3780
+ const chosen = plans.filter((plan) => picked.has(plan.dir));
3781
+ for (const plan of chosen)
3782
+ note("plan", plan.line);
3783
+ if (chosen.length === 0 || await chooser.confirm(`bump ${name} to ${version} in ${chosen.length} folder${chosen.length === 1 ? "" : "s"}?`) !== true)
3784
+ return { chosen: [], declined: plans.map((plan) => plan.dir) };
3785
+ const declined = plans.filter((plan) => !picked.has(plan.dir)).map((plan) => plan.dir);
3786
+ saveExcluded(name, [...excluded].filter((dir) => !plans.some((plan) => plan.dir === dir)).concat(declined), home);
3787
+ return { chosen: chosen.map((plan) => plan.dir), declined };
3788
+ }
3464
3789
  async function bump(args) {
3465
3790
  const { values, positionals: [name, asked] } = parse(args, usage5, options4, { positionals: ["<name>", "[version]"] });
3466
3791
  const settings = {
@@ -3478,6 +3803,14 @@ async function bump(args) {
3478
3803
  const version = await servedVersion(name, asked, settings);
3479
3804
  if (!await vet(name, version, settings))
3480
3805
  return 1;
3806
+ if (settings.isDryRun !== true && values.yes !== true && isInteractive() && (settings.only?.length ?? 0) === 0 && (settings.except?.length ?? 0) === 0) {
3807
+ const plan = await choosePlan(name, version, settings);
3808
+ if (plan?.chosen.length === 0) {
3809
+ note("nothing to bump", "none chosen or not confirmed");
3810
+ return 0;
3811
+ }
3812
+ settings.declined = plan?.declined;
3813
+ }
3481
3814
  return await bumpConsumers(name, version, settings) ? 0 : 1;
3482
3815
  }
3483
3816
  var usage5 = `pkg bump <name> [version]
@@ -3486,14 +3819,17 @@ Waits until the registry serves the version (the latest when none is given, an e
3486
3819
  A version the vetting blocks is refused before any folder is touched, unless --force is given.
3487
3820
  A dependency declared through an alias of the package (\`"kay": "npm:@kaynooo/kayjs@~1.77.0"\`) is bumped under its own key, keeping the \`~\` or \`^\` of its range; --only and --except narrow the folders by name or glob (\`app\`, \`kay-*\`, a path relative to --root).
3488
3821
  A dependency that is not a registry version (workspace:, link:, file:, git, a URL, an npm: alias of another package, catalog:), a peer range, a folder already on the version and one whose lockfile pins another manager are left as they are, each said so.
3822
+ On a terminal with no --only or --except, a checklist asks which consumers to bump (those left out last time are unchecked, and what is unchecked is remembered in ~/.config/kaynooo-cli/pkg-excluded.json), then the plan is printed and confirmed; --yes skips both, as a pipe or --dry-run does.
3489
3823
  With --all-consumers a folder whose package.json or lockfile already has uncommitted changes is left alone, and each folder whose install went through then runs its own \`check\` (the check bin) and is committed with \`gc 'chore(deps): bump <name> to <version>' -- package.json <lockfile>\` only when that passes; a failing one is left uncommitted and listed in the summary with the skipped ones, and nothing is ever pushed.
3490
3824
 
3491
- Exits 0 when every install ran or was left as it is (with --all-consumers, and every check passed and every commit landed), 1 when the vetting refuses the version, an install, a check or a commit fails or the registry has no such package, 2 when the version never shows within the timeout (a registry that cannot be reached is retried until then) or on a usage error.`, ROOT_OPTION, options4, POLL = 5000;
3825
+ Exits 0 when every install ran or was left as it is (with --all-consumers, and every check passed and every commit landed), 1 when the vetting refuses the version, an install, a check or a commit fails or the registry has no such package, 2 when the version never shows within the timeout (a registry that cannot be reached is retried until then) or on a usage error.`, ROOT_OPTION, options4, POLL = 5000, terminalChooser;
3492
3826
  var init_bump = __esm(() => {
3493
3827
  init_src();
3494
3828
  init_progress();
3829
+ init_prompt();
3495
3830
  init_config2();
3496
3831
  init_consumers();
3832
+ init_excluded();
3497
3833
  init_registry();
3498
3834
  init_semver();
3499
3835
  init_check();
@@ -3505,9 +3841,14 @@ var init_bump = __esm(() => {
3505
3841
  only: { type: "string", multiple: true, description: "bump only the folders matching this name or glob, repeatable" },
3506
3842
  except: { type: "string", multiple: true, description: "leave the folders matching this name or glob alone, repeatable" },
3507
3843
  "dry-run": { type: "boolean", description: "print what would run, changing nothing" },
3844
+ yes: { type: "boolean", short: "y", description: "on a terminal, bump every consumer without the checklist and the confirmation" },
3508
3845
  force: { type: "boolean", description: "bump even when the version is blocked by the vetting" },
3509
3846
  "min-age": { type: "string", description: "days a version must be old (0: a bump adopts a release on purpose, often one just made)" }
3510
3847
  };
3848
+ terminalChooser = {
3849
+ pick: async (name, plans, excluded) => checklist(`bump ${name} in`, plans.map((plan) => ({ value: plan.dir, label: plan.line, hint: excluded.has(plan.dir) ? "left out last time" : "" })), { initial: new Set(plans.filter((plan) => !excluded.has(plan.dir)).map((plan) => plan.dir)), hint: "pass --yes to bump every consumer" }),
3850
+ confirm: async (question) => confirm(question, { default: true })
3851
+ };
3511
3852
  });
3512
3853
 
3513
3854
  // src/commands/consumers.ts
@@ -3548,8 +3889,8 @@ var init_consumers2 = __esm(() => {
3548
3889
 
3549
3890
  // src/cli.ts
3550
3891
  init_src();
3551
- import process19 from "process";
3552
- process19.exitCode = await runCli({
3892
+ import process20 from "process";
3893
+ process20.exitCode = await runCli({
3553
3894
  name: "pkg",
3554
3895
  about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
3555
3896
  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.9.0",
4
+ "version": "0.11.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",
@@ -30,6 +30,6 @@
30
30
  "record": "$npm_execpath scripts/record.ts"
31
31
  },
32
32
  "devDependencies": {
33
- "@kaynooo/cli-kit": "0.23.0"
33
+ "@kaynooo/cli-kit": "0.26.0"
34
34
  }
35
35
  }