@kaynooo/cli-pkg 0.10.0 → 0.12.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 +351 -13
- 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"]);
|
|
@@ -1664,6 +1667,12 @@ var init_cli = __esm(() => {
|
|
|
1664
1667
|
};
|
|
1665
1668
|
TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1666
1669
|
});
|
|
1670
|
+
// ../kit/src/folders.ts
|
|
1671
|
+
var SKIPPED_FOLDERS;
|
|
1672
|
+
var init_folders = __esm(() => {
|
|
1673
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1674
|
+
});
|
|
1675
|
+
|
|
1667
1676
|
// ../kit/src/git.ts
|
|
1668
1677
|
var init_git = __esm(() => {
|
|
1669
1678
|
init_args();
|
|
@@ -1726,6 +1735,13 @@ var init_sessions = __esm(() => {
|
|
|
1726
1735
|
// ../kit/src/size.ts
|
|
1727
1736
|
var init_size = () => {};
|
|
1728
1737
|
|
|
1738
|
+
// ../kit/src/watch.ts
|
|
1739
|
+
var init_watch = __esm(() => {
|
|
1740
|
+
init_args();
|
|
1741
|
+
init_input();
|
|
1742
|
+
init_style();
|
|
1743
|
+
});
|
|
1744
|
+
|
|
1729
1745
|
// ../kit/src/workspace-root.ts
|
|
1730
1746
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1731
1747
|
import { homedir as homedir4 } from "os";
|
|
@@ -1764,6 +1780,7 @@ var init_src = __esm(() => {
|
|
|
1764
1780
|
init_ci();
|
|
1765
1781
|
init_cli();
|
|
1766
1782
|
init_config();
|
|
1783
|
+
init_folders();
|
|
1767
1784
|
init_format();
|
|
1768
1785
|
init_git();
|
|
1769
1786
|
init_limit();
|
|
@@ -1779,6 +1796,7 @@ var init_src = __esm(() => {
|
|
|
1779
1796
|
init_tool();
|
|
1780
1797
|
init_usage();
|
|
1781
1798
|
init_user_config();
|
|
1799
|
+
init_watch();
|
|
1782
1800
|
init_workspace_root();
|
|
1783
1801
|
});
|
|
1784
1802
|
|
|
@@ -2868,7 +2886,7 @@ function packageFiles(dir, depth, found) {
|
|
|
2868
2886
|
for (const entry of entries) {
|
|
2869
2887
|
if (entry.isFile() && entry.name === "package.json")
|
|
2870
2888
|
found.push(join8(dir, entry.name));
|
|
2871
|
-
else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !
|
|
2889
|
+
else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !SKIPPED_FOLDERS.has(entry.name))
|
|
2872
2890
|
packageFiles(join8(dir, entry.name), depth + 1, found);
|
|
2873
2891
|
}
|
|
2874
2892
|
return found;
|
|
@@ -2948,12 +2966,11 @@ function registryDependencies(text) {
|
|
|
2948
2966
|
}
|
|
2949
2967
|
return REGISTRY_KINDS.flatMap((kind) => Object.entries(manifest?.[kind] ?? {}).flatMap(([name, spec]) => typeof spec === "string" && !LOCAL_SPEC.test(spec) ? [{ name, kind, spec }] : []));
|
|
2950
2968
|
}
|
|
2951
|
-
var KINDS,
|
|
2969
|
+
var KINDS, MAX_DEPTH = 5, LOCAL_SPEC, ALIAS, MIN_SIMILAR = 3, KIND_FLAGS, RANGE_PREFIX, REGISTRY_KINDS;
|
|
2952
2970
|
var init_consumers = __esm(() => {
|
|
2953
2971
|
init_src();
|
|
2954
2972
|
init_pin();
|
|
2955
2973
|
KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
2956
|
-
SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
2957
2974
|
LOCAL_SPEC = /[:/]/;
|
|
2958
2975
|
ALIAS = /^npm:(@[^@/]+\/[^@/]+|[^@/]+)@(.+)$/;
|
|
2959
2976
|
KIND_FLAGS = { dependencies: [], devDependencies: ["--dev"], optionalDependencies: ["--optional"], peerDependencies: ["--peer"] };
|
|
@@ -3311,14 +3328,296 @@ var init_outdated = __esm(() => {
|
|
|
3311
3328
|
};
|
|
3312
3329
|
});
|
|
3313
3330
|
|
|
3331
|
+
// ../kit/src/picker/score.ts
|
|
3332
|
+
var BOUNDARY_AFTER, NONE;
|
|
3333
|
+
var init_score = __esm(() => {
|
|
3334
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
3335
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
3336
|
+
});
|
|
3337
|
+
|
|
3338
|
+
// ../kit/src/picker/state.ts
|
|
3339
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
3340
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
3341
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
3342
|
+
const named = codes.get(sequence);
|
|
3343
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
3344
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
3345
|
+
paste.active = sequence === PASTE_START;
|
|
3346
|
+
return [];
|
|
3347
|
+
}
|
|
3348
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
3349
|
+
`))
|
|
3350
|
+
return [];
|
|
3351
|
+
if (key !== undefined)
|
|
3352
|
+
return [key];
|
|
3353
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
3354
|
+
});
|
|
3355
|
+
}
|
|
3356
|
+
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, KEYS;
|
|
3357
|
+
var init_state = __esm(() => {
|
|
3358
|
+
init_score();
|
|
3359
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
3360
|
+
KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
3361
|
+
KEYS = {
|
|
3362
|
+
"\x1B[A": "up",
|
|
3363
|
+
"\x1BOA": "up",
|
|
3364
|
+
"\x10": "up",
|
|
3365
|
+
"\x1B[B": "down",
|
|
3366
|
+
"\x1BOB": "down",
|
|
3367
|
+
"\x0E": "down",
|
|
3368
|
+
"\x1B[5~": "pageup",
|
|
3369
|
+
"\x1B[6~": "pagedown",
|
|
3370
|
+
"\x1B[H": "home",
|
|
3371
|
+
"\x1B[1~": "home",
|
|
3372
|
+
"\x1BOH": "home",
|
|
3373
|
+
"\x1B[F": "end",
|
|
3374
|
+
"\x1B[4~": "end",
|
|
3375
|
+
"\x1BOF": "end",
|
|
3376
|
+
"\r": "enter",
|
|
3377
|
+
"\n": "enter",
|
|
3378
|
+
"\x03": "cancel",
|
|
3379
|
+
"\x1B": "cancel",
|
|
3380
|
+
"\x7F": "erase",
|
|
3381
|
+
"\b": "erase",
|
|
3382
|
+
"\x15": "clear",
|
|
3383
|
+
"\x17": "word",
|
|
3384
|
+
"\t": "tab",
|
|
3385
|
+
"\x1F": "help",
|
|
3386
|
+
"\x1BOP": "help",
|
|
3387
|
+
"\x1B[11~": "help"
|
|
3388
|
+
};
|
|
3389
|
+
});
|
|
3390
|
+
|
|
3391
|
+
// ../kit/src/prompt.ts
|
|
3392
|
+
import process19 from "process";
|
|
3393
|
+
function readKeys(input, paste = { active: false }) {
|
|
3394
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
3395
|
+
}
|
|
3396
|
+
function flip(checked, value) {
|
|
3397
|
+
const next = new Set(checked);
|
|
3398
|
+
if (!next.delete(value))
|
|
3399
|
+
next.add(value);
|
|
3400
|
+
return next;
|
|
3401
|
+
}
|
|
3402
|
+
async function checklist(question, choices, { initial = new Set, min = 0, toggle = flip, ...settings } = {}) {
|
|
3403
|
+
const list = new List(choices, 0);
|
|
3404
|
+
let checked = initial;
|
|
3405
|
+
let invalid;
|
|
3406
|
+
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) => {
|
|
3407
|
+
if (key === "cancel")
|
|
3408
|
+
return key;
|
|
3409
|
+
invalid = undefined;
|
|
3410
|
+
if (key === "enter") {
|
|
3411
|
+
invalid = checked.size < min ? `pick at least ${min}` : undefined;
|
|
3412
|
+
return invalid === undefined ? "enter" : undefined;
|
|
3413
|
+
}
|
|
3414
|
+
const current = list.current();
|
|
3415
|
+
if (typeof key === "object" && key.text === " ") {
|
|
3416
|
+
if (current !== undefined)
|
|
3417
|
+
checked = toggle(checked, current.value);
|
|
3418
|
+
return;
|
|
3419
|
+
}
|
|
3420
|
+
list.press(key);
|
|
3421
|
+
return;
|
|
3422
|
+
});
|
|
3423
|
+
return accepted ? checked : undefined;
|
|
3424
|
+
}
|
|
3425
|
+
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
3426
|
+
let answered = fallback;
|
|
3427
|
+
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
3428
|
+
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
3429
|
+
if (key === "cancel")
|
|
3430
|
+
return "cancel";
|
|
3431
|
+
if (key === "enter")
|
|
3432
|
+
return answered === undefined ? undefined : "enter";
|
|
3433
|
+
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
3434
|
+
if (letter !== "y" && letter !== "n")
|
|
3435
|
+
return;
|
|
3436
|
+
answered = letter === "y";
|
|
3437
|
+
return "enter";
|
|
3438
|
+
});
|
|
3439
|
+
return accepted ? answered : undefined;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
class List {
|
|
3443
|
+
choices;
|
|
3444
|
+
query = "";
|
|
3445
|
+
matches;
|
|
3446
|
+
cursor;
|
|
3447
|
+
top = 0;
|
|
3448
|
+
width;
|
|
3449
|
+
constructor(choices, initial) {
|
|
3450
|
+
this.choices = choices;
|
|
3451
|
+
this.matches = choices;
|
|
3452
|
+
this.cursor = Math.min(Math.max(initial, 0), choices.length - 1);
|
|
3453
|
+
this.width = Math.max(0, ...choices.map((choice) => choice.label.length));
|
|
3454
|
+
}
|
|
3455
|
+
current() {
|
|
3456
|
+
return this.matches[this.cursor];
|
|
3457
|
+
}
|
|
3458
|
+
press(key) {
|
|
3459
|
+
if (key === "up" || key === "down") {
|
|
3460
|
+
if (this.matches.length > 0)
|
|
3461
|
+
this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
|
|
3462
|
+
return;
|
|
3463
|
+
}
|
|
3464
|
+
if (key === "home" || key === "end" || key === "pageup" || key === "pagedown") {
|
|
3465
|
+
const last = this.matches.length - 1;
|
|
3466
|
+
const to = { home: 0, end: last, pageup: this.cursor - MAX_ROWS, pagedown: this.cursor + MAX_ROWS }[key];
|
|
3467
|
+
this.cursor = Math.max(0, Math.min(last, to));
|
|
3468
|
+
return;
|
|
3469
|
+
}
|
|
3470
|
+
if (key === "erase")
|
|
3471
|
+
this.filter([...this.query].slice(0, -1).join(""));
|
|
3472
|
+
else if (typeof key === "object")
|
|
3473
|
+
this.filter(this.query + key.text);
|
|
3474
|
+
}
|
|
3475
|
+
filter(query) {
|
|
3476
|
+
const words = query.toLowerCase().split(WORDS2).filter((word) => word !== "");
|
|
3477
|
+
const current = this.current();
|
|
3478
|
+
this.query = query;
|
|
3479
|
+
this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
|
|
3480
|
+
this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
|
|
3481
|
+
this.top = 0;
|
|
3482
|
+
}
|
|
3483
|
+
rows(colors, { columns, rows }, marker) {
|
|
3484
|
+
if (this.matches.length === 0)
|
|
3485
|
+
return [colors.dim(" no match")];
|
|
3486
|
+
const height = Math.max(1, Math.min(MAX_ROWS, rows - 3, this.matches.length));
|
|
3487
|
+
this.top = Math.min(Math.max(this.top, this.cursor - height + 1), this.cursor);
|
|
3488
|
+
const shown = this.matches.slice(this.top, this.top + height).map((choice, index) => {
|
|
3489
|
+
const here = this.top + index === this.cursor;
|
|
3490
|
+
const mark = marker(choice);
|
|
3491
|
+
const head = `${here ? "\u276F" : " "} ${mark}`;
|
|
3492
|
+
const label = choice.label.padEnd(this.width);
|
|
3493
|
+
const room = columns - 5 - (mark === "" ? 0 : 2) - this.width;
|
|
3494
|
+
return `${here ? colors.cyan(head) : head}${here ? colors.cyan(label) : label} ${colors.dim(truncate(choice.hint, Math.max(room, 0)))}`;
|
|
3495
|
+
});
|
|
3496
|
+
const below = this.matches.length - this.top - height;
|
|
3497
|
+
return [...this.top > 0 ? [colors.dim(` \u2026 ${this.top} more`)] : [], ...shown, ...below > 0 ? [colors.dim(` \u2026 ${below} more`)] : []];
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
function asking(colors, question, typed, keys) {
|
|
3501
|
+
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
3502
|
+
}
|
|
3503
|
+
function answer(colors, question, state, picked) {
|
|
3504
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
3505
|
+
}
|
|
3506
|
+
async function ask(question, { hint, terminal = process19 }, render, press) {
|
|
3507
|
+
const { stdin, stderr } = terminal;
|
|
3508
|
+
if (!isInteractive(terminal))
|
|
3509
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
3510
|
+
const colors = paint(stderr);
|
|
3511
|
+
let drawn = [];
|
|
3512
|
+
let current = "asking";
|
|
3513
|
+
let outcome;
|
|
3514
|
+
const columns = () => stderr.columns || 80;
|
|
3515
|
+
const draw = (state) => {
|
|
3516
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
3517
|
+
const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
|
|
3518
|
+
stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
|
|
3519
|
+
`)}`);
|
|
3520
|
+
drawn = frame;
|
|
3521
|
+
current = state;
|
|
3522
|
+
};
|
|
3523
|
+
const redraw = () => draw(current);
|
|
3524
|
+
const paste = { active: false };
|
|
3525
|
+
try {
|
|
3526
|
+
stderr.on?.("resize", redraw);
|
|
3527
|
+
stdin.setRawMode(true);
|
|
3528
|
+
stdin.resume();
|
|
3529
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
3530
|
+
draw("asking");
|
|
3531
|
+
return await new Promise((resolve) => {
|
|
3532
|
+
function onData(data) {
|
|
3533
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
3534
|
+
const pressed = press(key);
|
|
3535
|
+
if (pressed !== undefined) {
|
|
3536
|
+
settle(pressed);
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
draw("asking");
|
|
3541
|
+
}
|
|
3542
|
+
function onEnd() {
|
|
3543
|
+
settle("cancel");
|
|
3544
|
+
}
|
|
3545
|
+
function settle(settled) {
|
|
3546
|
+
outcome = settled;
|
|
3547
|
+
stdin.off("data", onData);
|
|
3548
|
+
stdin.off("end", onEnd);
|
|
3549
|
+
resolve(settled === "enter");
|
|
3550
|
+
}
|
|
3551
|
+
stdin.on("data", onData);
|
|
3552
|
+
stdin.on("end", onEnd);
|
|
3553
|
+
});
|
|
3554
|
+
} finally {
|
|
3555
|
+
stderr.off?.("resize", redraw);
|
|
3556
|
+
draw(outcome ?? "cancel");
|
|
3557
|
+
stderr.write(`
|
|
3558
|
+
\x1B[?25h\x1B[?2004l`);
|
|
3559
|
+
stdin.setRawMode(false);
|
|
3560
|
+
stdin.pause();
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
var WORDS2, MAX_ROWS = 10, PROMPT_KEYS;
|
|
3564
|
+
var init_prompt = __esm(() => {
|
|
3565
|
+
init_args();
|
|
3566
|
+
init_format();
|
|
3567
|
+
init_mode();
|
|
3568
|
+
init_state();
|
|
3569
|
+
init_style();
|
|
3570
|
+
WORDS2 = /\s+/;
|
|
3571
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
3572
|
+
});
|
|
3573
|
+
|
|
3574
|
+
// src/excluded.ts
|
|
3575
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "fs";
|
|
3576
|
+
import { dirname as dirname7 } from "path";
|
|
3577
|
+
function excludedPath(home) {
|
|
3578
|
+
return userConfigPath("pkg-excluded", { home });
|
|
3579
|
+
}
|
|
3580
|
+
function loadExcluded(home) {
|
|
3581
|
+
const path = excludedPath(home);
|
|
3582
|
+
if (!existsSync7(path))
|
|
3583
|
+
return {};
|
|
3584
|
+
try {
|
|
3585
|
+
const raw = JSON.parse(readFileSync5(path, "utf8"));
|
|
3586
|
+
const excluded = {};
|
|
3587
|
+
for (const [name, dirs] of Object.entries(raw)) {
|
|
3588
|
+
if (Array.isArray(dirs))
|
|
3589
|
+
excluded[name] = dirs.filter((dir) => typeof dir === "string");
|
|
3590
|
+
}
|
|
3591
|
+
return excluded;
|
|
3592
|
+
} catch {
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
function saveExcluded(name, dirs, home) {
|
|
3597
|
+
const path = excludedPath(home);
|
|
3598
|
+
const excluded = loadExcluded(home);
|
|
3599
|
+
if (excluded === undefined)
|
|
3600
|
+
return;
|
|
3601
|
+
if (dirs.length === 0)
|
|
3602
|
+
delete excluded[name];
|
|
3603
|
+
else
|
|
3604
|
+
excluded[name] = [...dirs].toSorted();
|
|
3605
|
+
mkdirSync3(dirname7(path), { recursive: true });
|
|
3606
|
+
writeFileSync2(path, `${JSON.stringify(excluded, null, 2)}
|
|
3607
|
+
`);
|
|
3608
|
+
}
|
|
3609
|
+
var init_excluded = __esm(() => {
|
|
3610
|
+
init_src();
|
|
3611
|
+
});
|
|
3612
|
+
|
|
3314
3613
|
// src/commands/bump.ts
|
|
3315
3614
|
var exports_bump = {};
|
|
3316
3615
|
__export(exports_bump, {
|
|
3317
3616
|
ROOT_OPTION: () => ROOT_OPTION,
|
|
3318
3617
|
bump: () => bump
|
|
3319
3618
|
});
|
|
3320
|
-
import { existsSync as
|
|
3321
|
-
import { basename, dirname as
|
|
3619
|
+
import { existsSync as existsSync8 } from "fs";
|
|
3620
|
+
import { basename, dirname as dirname8, join as join11, relative as relative2 } from "path";
|
|
3322
3621
|
async function lookup(name, registry, fetcher) {
|
|
3323
3622
|
try {
|
|
3324
3623
|
return { packument: await fetchPackument(name, registry, fetcher) };
|
|
@@ -3378,11 +3677,11 @@ async function vet(name, version, settings) {
|
|
|
3378
3677
|
return false;
|
|
3379
3678
|
}
|
|
3380
3679
|
function lockfileOf(dir, root) {
|
|
3381
|
-
for (let at = dir;; at =
|
|
3382
|
-
const found = ["bun.lock", "bun.lockb"].find((file) =>
|
|
3680
|
+
for (let at = dir;; at = dirname8(at)) {
|
|
3681
|
+
const found = ["bun.lock", "bun.lockb"].find((file) => existsSync8(join11(at, file)));
|
|
3383
3682
|
if (found !== undefined)
|
|
3384
3683
|
return relative2(dir, join11(at, found));
|
|
3385
|
-
if (at === root || at ===
|
|
3684
|
+
if (at === root || at === dirname8(at))
|
|
3386
3685
|
return;
|
|
3387
3686
|
}
|
|
3388
3687
|
}
|
|
@@ -3409,9 +3708,10 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3409
3708
|
const everyone = findConsumers(name, settings.root);
|
|
3410
3709
|
const isOnly = matcher(settings.only ?? []);
|
|
3411
3710
|
const isExcept = matcher(settings.except ?? []);
|
|
3412
|
-
const
|
|
3711
|
+
const declined = new Set(settings.declined ?? []);
|
|
3712
|
+
const found = everyone.filter((each) => (settings.only === undefined || settings.only.length === 0 || isOnly(each.dir)) && !isExcept(each.dir) && !declined.has(each.dir));
|
|
3413
3713
|
const consumers = found.filter((each) => !isLocal(each));
|
|
3414
|
-
const left = everyone.length - found.length;
|
|
3714
|
+
const left = everyone.length - found.length - declined.size;
|
|
3415
3715
|
const local = found.length - consumers.length;
|
|
3416
3716
|
const run = settings.run ?? (async (argv, cwd) => runCommand(argv, { cwd }));
|
|
3417
3717
|
const committed = [];
|
|
@@ -3424,6 +3724,8 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3424
3724
|
} else if (left > 0) {
|
|
3425
3725
|
note(`${left} folder${left === 1 ? "" : "s"} left out by --only or --except`);
|
|
3426
3726
|
}
|
|
3727
|
+
if (declined.size > 0)
|
|
3728
|
+
note(`${declined.size} folder${declined.size === 1 ? "" : "s"} left out by your choice`);
|
|
3427
3729
|
if (local > 0)
|
|
3428
3730
|
note(`${local} non-registry dependenc${local === 1 ? "y" : "ies"} (workspace:, file:, git, URL, alias, catalog:)`, "left as they are");
|
|
3429
3731
|
for (const consumer of consumers) {
|
|
@@ -3470,6 +3772,26 @@ async function bumpConsumers(name, version, settings) {
|
|
|
3470
3772
|
note("summary", `${committed.length} bumped and committed, ${failing.length} bumped and failing${failing.length > 0 ? ` (${failing.join(", ")})` : ""}, ${skipped.length + local} skipped`);
|
|
3471
3773
|
return isClean;
|
|
3472
3774
|
}
|
|
3775
|
+
function plannedBumps(name, version, settings) {
|
|
3776
|
+
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}` }));
|
|
3777
|
+
}
|
|
3778
|
+
async function choosePlan(name, version, settings, chooser = terminalChooser, home) {
|
|
3779
|
+
const plans = plannedBumps(name, version, settings);
|
|
3780
|
+
if (plans.length === 0)
|
|
3781
|
+
return;
|
|
3782
|
+
const excluded = new Set(loadExcluded(home)?.[name] ?? []);
|
|
3783
|
+
const picked = await chooser.pick(name, plans, excluded);
|
|
3784
|
+
if (picked === undefined)
|
|
3785
|
+
return { chosen: [], declined: plans.map((plan) => plan.dir) };
|
|
3786
|
+
const chosen = plans.filter((plan) => picked.has(plan.dir));
|
|
3787
|
+
for (const plan of chosen)
|
|
3788
|
+
note("plan", plan.line);
|
|
3789
|
+
if (chosen.length === 0 || await chooser.confirm(`bump ${name} to ${version} in ${chosen.length} folder${chosen.length === 1 ? "" : "s"}?`) !== true)
|
|
3790
|
+
return { chosen: [], declined: plans.map((plan) => plan.dir) };
|
|
3791
|
+
const declined = plans.filter((plan) => !picked.has(plan.dir)).map((plan) => plan.dir);
|
|
3792
|
+
saveExcluded(name, [...excluded].filter((dir) => !plans.some((plan) => plan.dir === dir)).concat(declined), home);
|
|
3793
|
+
return { chosen: chosen.map((plan) => plan.dir), declined };
|
|
3794
|
+
}
|
|
3473
3795
|
async function bump(args) {
|
|
3474
3796
|
const { values, positionals: [name, asked] } = parse(args, usage5, options4, { positionals: ["<name>", "[version]"] });
|
|
3475
3797
|
const settings = {
|
|
@@ -3487,6 +3809,14 @@ async function bump(args) {
|
|
|
3487
3809
|
const version = await servedVersion(name, asked, settings);
|
|
3488
3810
|
if (!await vet(name, version, settings))
|
|
3489
3811
|
return 1;
|
|
3812
|
+
if (settings.isDryRun !== true && values.yes !== true && isInteractive() && (settings.only?.length ?? 0) === 0 && (settings.except?.length ?? 0) === 0) {
|
|
3813
|
+
const plan = await choosePlan(name, version, settings);
|
|
3814
|
+
if (plan?.chosen.length === 0) {
|
|
3815
|
+
note("nothing to bump", "none chosen or not confirmed");
|
|
3816
|
+
return 0;
|
|
3817
|
+
}
|
|
3818
|
+
settings.declined = plan?.declined;
|
|
3819
|
+
}
|
|
3490
3820
|
return await bumpConsumers(name, version, settings) ? 0 : 1;
|
|
3491
3821
|
}
|
|
3492
3822
|
var usage5 = `pkg bump <name> [version]
|
|
@@ -3495,14 +3825,17 @@ Waits until the registry serves the version (the latest when none is given, an e
|
|
|
3495
3825
|
A version the vetting blocks is refused before any folder is touched, unless --force is given.
|
|
3496
3826
|
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
3827
|
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.
|
|
3828
|
+
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
3829
|
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
3830
|
|
|
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;
|
|
3831
|
+
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
3832
|
var init_bump = __esm(() => {
|
|
3502
3833
|
init_src();
|
|
3503
3834
|
init_progress();
|
|
3835
|
+
init_prompt();
|
|
3504
3836
|
init_config2();
|
|
3505
3837
|
init_consumers();
|
|
3838
|
+
init_excluded();
|
|
3506
3839
|
init_registry();
|
|
3507
3840
|
init_semver();
|
|
3508
3841
|
init_check();
|
|
@@ -3514,9 +3847,14 @@ var init_bump = __esm(() => {
|
|
|
3514
3847
|
only: { type: "string", multiple: true, description: "bump only the folders matching this name or glob, repeatable" },
|
|
3515
3848
|
except: { type: "string", multiple: true, description: "leave the folders matching this name or glob alone, repeatable" },
|
|
3516
3849
|
"dry-run": { type: "boolean", description: "print what would run, changing nothing" },
|
|
3850
|
+
yes: { type: "boolean", short: "y", description: "on a terminal, bump every consumer without the checklist and the confirmation" },
|
|
3517
3851
|
force: { type: "boolean", description: "bump even when the version is blocked by the vetting" },
|
|
3518
3852
|
"min-age": { type: "string", description: "days a version must be old (0: a bump adopts a release on purpose, often one just made)" }
|
|
3519
3853
|
};
|
|
3854
|
+
terminalChooser = {
|
|
3855
|
+
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" }),
|
|
3856
|
+
confirm: async (question) => confirm(question, { default: true })
|
|
3857
|
+
};
|
|
3520
3858
|
});
|
|
3521
3859
|
|
|
3522
3860
|
// src/commands/consumers.ts
|
|
@@ -3557,8 +3895,8 @@ var init_consumers2 = __esm(() => {
|
|
|
3557
3895
|
|
|
3558
3896
|
// src/cli.ts
|
|
3559
3897
|
init_src();
|
|
3560
|
-
import
|
|
3561
|
-
|
|
3898
|
+
import process20 from "process";
|
|
3899
|
+
process20.exitCode = await runCli({
|
|
3562
3900
|
name: "pkg",
|
|
3563
3901
|
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
3564
3902
|
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.12.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.27.0"
|
|
34
34
|
}
|
|
35
35
|
}
|