@kaynooo/cli-pkg 0.10.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.
- package/README.md +1 -1
- package/dist/cli.js +342 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ pkg bump @kaynooo/cli-kit 0.8.0 --dry-run
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
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.
|
|
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. 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.
|
|
60
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.
|
|
61
61
|
- `pkg <name>` alone still runs `pkg check`.
|
|
62
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"]);
|
|
@@ -1726,6 +1729,13 @@ var init_sessions = __esm(() => {
|
|
|
1726
1729
|
// ../kit/src/size.ts
|
|
1727
1730
|
var init_size = () => {};
|
|
1728
1731
|
|
|
1732
|
+
// ../kit/src/watch.ts
|
|
1733
|
+
var init_watch = __esm(() => {
|
|
1734
|
+
init_args();
|
|
1735
|
+
init_input();
|
|
1736
|
+
init_style();
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1729
1739
|
// ../kit/src/workspace-root.ts
|
|
1730
1740
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1731
1741
|
import { homedir as homedir4 } from "os";
|
|
@@ -1779,6 +1789,7 @@ var init_src = __esm(() => {
|
|
|
1779
1789
|
init_tool();
|
|
1780
1790
|
init_usage();
|
|
1781
1791
|
init_user_config();
|
|
1792
|
+
init_watch();
|
|
1782
1793
|
init_workspace_root();
|
|
1783
1794
|
});
|
|
1784
1795
|
|
|
@@ -3311,14 +3322,296 @@ var init_outdated = __esm(() => {
|
|
|
3311
3322
|
};
|
|
3312
3323
|
});
|
|
3313
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
|
+
|
|
3314
3607
|
// src/commands/bump.ts
|
|
3315
3608
|
var exports_bump = {};
|
|
3316
3609
|
__export(exports_bump, {
|
|
3317
3610
|
ROOT_OPTION: () => ROOT_OPTION,
|
|
3318
3611
|
bump: () => bump
|
|
3319
3612
|
});
|
|
3320
|
-
import { existsSync as
|
|
3321
|
-
import { basename, dirname as
|
|
3613
|
+
import { existsSync as existsSync8 } from "fs";
|
|
3614
|
+
import { basename, dirname as dirname8, join as join11, relative as relative2 } from "path";
|
|
3322
3615
|
async function lookup(name, registry, fetcher) {
|
|
3323
3616
|
try {
|
|
3324
3617
|
return { packument: await fetchPackument(name, registry, fetcher) };
|
|
@@ -3378,11 +3671,11 @@ async function vet(name, version, settings) {
|
|
|
3378
3671
|
return false;
|
|
3379
3672
|
}
|
|
3380
3673
|
function lockfileOf(dir, root) {
|
|
3381
|
-
for (let at = dir;; at =
|
|
3382
|
-
const found = ["bun.lock", "bun.lockb"].find((file) =>
|
|
3674
|
+
for (let at = dir;; at = dirname8(at)) {
|
|
3675
|
+
const found = ["bun.lock", "bun.lockb"].find((file) => existsSync8(join11(at, file)));
|
|
3383
3676
|
if (found !== undefined)
|
|
3384
3677
|
return relative2(dir, join11(at, found));
|
|
3385
|
-
if (at === root || at ===
|
|
3678
|
+
if (at === root || at === dirname8(at))
|
|
3386
3679
|
return;
|
|
3387
3680
|
}
|
|
3388
3681
|
}
|
|
@@ -3409,9 +3702,10 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3409
3702
|
const everyone = findConsumers(name, settings.root);
|
|
3410
3703
|
const isOnly = matcher(settings.only ?? []);
|
|
3411
3704
|
const isExcept = matcher(settings.except ?? []);
|
|
3412
|
-
const
|
|
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));
|
|
3413
3707
|
const consumers = found.filter((each) => !isLocal(each));
|
|
3414
|
-
const left = everyone.length - found.length;
|
|
3708
|
+
const left = everyone.length - found.length - declined.size;
|
|
3415
3709
|
const local = found.length - consumers.length;
|
|
3416
3710
|
const run = settings.run ?? (async (argv, cwd) => runCommand(argv, { cwd }));
|
|
3417
3711
|
const committed = [];
|
|
@@ -3424,6 +3718,8 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3424
3718
|
} else if (left > 0) {
|
|
3425
3719
|
note(`${left} folder${left === 1 ? "" : "s"} left out by --only or --except`);
|
|
3426
3720
|
}
|
|
3721
|
+
if (declined.size > 0)
|
|
3722
|
+
note(`${declined.size} folder${declined.size === 1 ? "" : "s"} left out by your choice`);
|
|
3427
3723
|
if (local > 0)
|
|
3428
3724
|
note(`${local} non-registry dependenc${local === 1 ? "y" : "ies"} (workspace:, file:, git, URL, alias, catalog:)`, "left as they are");
|
|
3429
3725
|
for (const consumer of consumers) {
|
|
@@ -3470,6 +3766,26 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3470
3766
|
note("summary", `${committed.length} bumped and committed, ${failing.length} bumped and failing${failing.length > 0 ? ` (${failing.join(", ")})` : ""}, ${skipped.length + local} skipped`);
|
|
3471
3767
|
return isClean;
|
|
3472
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
|
+
}
|
|
3473
3789
|
async function bump(args) {
|
|
3474
3790
|
const { values, positionals: [name, asked] } = parse(args, usage5, options4, { positionals: ["<name>", "[version]"] });
|
|
3475
3791
|
const settings = {
|
|
@@ -3487,6 +3803,14 @@ async function bump(args) {
|
|
|
3487
3803
|
const version = await servedVersion(name, asked, settings);
|
|
3488
3804
|
if (!await vet(name, version, settings))
|
|
3489
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
|
+
}
|
|
3490
3814
|
return await bumpConsumers(name, version, settings) ? 0 : 1;
|
|
3491
3815
|
}
|
|
3492
3816
|
var usage5 = `pkg bump <name> [version]
|
|
@@ -3495,14 +3819,17 @@ Waits until the registry serves the version (the latest when none is given, an e
|
|
|
3495
3819
|
A version the vetting blocks is refused before any folder is touched, unless --force is given.
|
|
3496
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).
|
|
3497
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.
|
|
3498
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.
|
|
3499
3824
|
|
|
3500
|
-
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;
|
|
3501
3826
|
var init_bump = __esm(() => {
|
|
3502
3827
|
init_src();
|
|
3503
3828
|
init_progress();
|
|
3829
|
+
init_prompt();
|
|
3504
3830
|
init_config2();
|
|
3505
3831
|
init_consumers();
|
|
3832
|
+
init_excluded();
|
|
3506
3833
|
init_registry();
|
|
3507
3834
|
init_semver();
|
|
3508
3835
|
init_check();
|
|
@@ -3514,9 +3841,14 @@ var init_bump = __esm(() => {
|
|
|
3514
3841
|
only: { type: "string", multiple: true, description: "bump only the folders matching this name or glob, repeatable" },
|
|
3515
3842
|
except: { type: "string", multiple: true, description: "leave the folders matching this name or glob alone, repeatable" },
|
|
3516
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" },
|
|
3517
3845
|
force: { type: "boolean", description: "bump even when the version is blocked by the vetting" },
|
|
3518
3846
|
"min-age": { type: "string", description: "days a version must be old (0: a bump adopts a release on purpose, often one just made)" }
|
|
3519
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
|
+
};
|
|
3520
3852
|
});
|
|
3521
3853
|
|
|
3522
3854
|
// src/commands/consumers.ts
|
|
@@ -3557,8 +3889,8 @@ var init_consumers2 = __esm(() => {
|
|
|
3557
3889
|
|
|
3558
3890
|
// src/cli.ts
|
|
3559
3891
|
init_src();
|
|
3560
|
-
import
|
|
3561
|
-
|
|
3892
|
+
import process20 from "process";
|
|
3893
|
+
process20.exitCode = await runCli({
|
|
3562
3894
|
name: "pkg",
|
|
3563
3895
|
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
3564
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.
|
|
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.
|
|
33
|
+
"@kaynooo/cli-kit": "0.26.0"
|
|
34
34
|
}
|
|
35
35
|
}
|