@kaynooo/cli-pkg 0.14.0 → 0.15.1
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/dist/cli.js +40 -31
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -437,6 +437,10 @@ function warn(text, detail) {
|
|
|
437
437
|
function problem(text, detail) {
|
|
438
438
|
console.error(marked("problem", text, process6.stderr, detail));
|
|
439
439
|
}
|
|
440
|
+
function role(name, stream, env = process6.env) {
|
|
441
|
+
const colors = paint(stream, env);
|
|
442
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
443
|
+
}
|
|
440
444
|
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
441
445
|
var init_style = __esm(() => {
|
|
442
446
|
init_colors();
|
|
@@ -551,18 +555,14 @@ import process8 from "process";
|
|
|
551
555
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
552
556
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
553
557
|
}
|
|
554
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
555
|
-
return [usageLine(usage, colors),
|
|
558
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
559
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
556
560
|
`);
|
|
557
561
|
}
|
|
558
562
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
559
563
|
if (exits.length === 0)
|
|
560
564
|
return [];
|
|
561
|
-
|
|
562
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
563
|
-
}
|
|
564
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
565
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
565
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
566
566
|
}
|
|
567
567
|
function wantsHelpJson(env = process8.env) {
|
|
568
568
|
return env.KIT_HELP === "json";
|
|
@@ -1335,7 +1335,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1335
1335
|
header(colors, summary),
|
|
1336
1336
|
"",
|
|
1337
1337
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1338
|
-
...replacesRows(replaces, colors),
|
|
1339
1338
|
"",
|
|
1340
1339
|
...await commandRows(commands, colors),
|
|
1341
1340
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1512,7 +1511,11 @@ async function printCandidates(found) {
|
|
|
1512
1511
|
return 0;
|
|
1513
1512
|
}
|
|
1514
1513
|
function packageVersion(entry = Bun.main) {
|
|
1515
|
-
|
|
1514
|
+
let resolved = entry;
|
|
1515
|
+
try {
|
|
1516
|
+
resolved = realpathSync2(entry);
|
|
1517
|
+
} catch {}
|
|
1518
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1516
1519
|
try {
|
|
1517
1520
|
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1518
1521
|
if (typeof version === "string")
|
|
@@ -2911,9 +2914,11 @@ async function checkPackage(text, context) {
|
|
|
2911
2914
|
function when(release, now) {
|
|
2912
2915
|
return release?.published === undefined ? "" : `, published ${formatAge(release.published, now)} (${release.published.slice(0, 10)})`;
|
|
2913
2916
|
}
|
|
2914
|
-
function render(report, now = Date.now()) {
|
|
2917
|
+
function render(report, now = Date.now(), stream = process.stdout, env = process.env) {
|
|
2918
|
+
const id = role("id", stream, env);
|
|
2919
|
+
const warn = role("warn", stream, env);
|
|
2915
2920
|
if (!report.exists)
|
|
2916
|
-
return [report.name, ...report.warnings.map((warning) => ` warning: ${warning}`)].join(`
|
|
2921
|
+
return [id(report.name), ...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)].join(`
|
|
2917
2922
|
`);
|
|
2918
2923
|
const asked = report.requested === undefined ? "" : ` (asked for ${report.requested})`;
|
|
2919
2924
|
const rows = [
|
|
@@ -2926,9 +2931,9 @@ function render(report, now = Date.now()) {
|
|
|
2926
2931
|
...Object.entries(report.installScripts).map(([name, command]) => [name, command])
|
|
2927
2932
|
];
|
|
2928
2933
|
return [
|
|
2929
|
-
`${report.name}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
2934
|
+
`${id(report.name)}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
2930
2935
|
table(rows.map(([key, value]) => [` ${key}`, value ?? ""])),
|
|
2931
|
-
...report.warnings.map((warning) => ` warning: ${warning}`)
|
|
2936
|
+
...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)
|
|
2932
2937
|
].join(`
|
|
2933
2938
|
`);
|
|
2934
2939
|
}
|
|
@@ -3091,14 +3096,19 @@ async function auditPackages(packages, context) {
|
|
|
3091
3096
|
});
|
|
3092
3097
|
return { audited, unavailable };
|
|
3093
3098
|
}
|
|
3094
|
-
function renderAudit(findings, total) {
|
|
3099
|
+
function renderAudit(findings, total, stream = process19.stdout, env = process19.env) {
|
|
3100
|
+
const id = role("id", stream, env);
|
|
3101
|
+
const label = role("label", stream, env);
|
|
3102
|
+
const warning = role("warn", stream, env);
|
|
3103
|
+
const problem = role("problem", stream, env);
|
|
3104
|
+
const blocking = findings.filter((each) => each.blocked).length;
|
|
3095
3105
|
const blocks = findings.map(({ name, version, warnings, advisories }) => [
|
|
3096
|
-
`${name}@${version}
|
|
3097
|
-
...warnings.map((
|
|
3098
|
-
...advisories.map((each) => ` ${each.ghsa ?? each.id} ${each.severity}: ${each.title}${each.fixed === undefined ? "" : ` (fixed in ${each.fixed})`}`)
|
|
3106
|
+
id(`${name}@${version}`),
|
|
3107
|
+
...warnings.map((each) => ` ${warning("warning:")} ${each}`),
|
|
3108
|
+
...advisories.map((each) => ` ${label(String(each.ghsa ?? each.id))} ${(HIGH_SEVERITIES.has(each.severity) ? problem : warning)(each.severity)}: ${each.title}${each.fixed === undefined ? "" : ` ${label(`(fixed in ${each.fixed})`)}`}`)
|
|
3099
3109
|
].join(`
|
|
3100
3110
|
`));
|
|
3101
|
-
return [...blocks, `${findings.length} of ${total} packages with a finding, ${
|
|
3111
|
+
return [...blocks, `${findings.length} of ${total} packages with a finding, ${(blocking === 0 ? label : problem)(`${blocking} blocking`)}`].join(`
|
|
3102
3112
|
|
|
3103
3113
|
`);
|
|
3104
3114
|
}
|
|
@@ -3138,7 +3148,7 @@ var usage3 = `pkg audit [dir]
|
|
|
3138
3148
|
|
|
3139
3149
|
Reads the bun.lock in the folder (the current one by default) and runs on every registry package it pins the checks \`pkg check\` runs before an add: age, install scripts, a deprecated version, a near miss of a popular name, and the licence allowlist of the pkg config. It also lists the known advisories of each version, with the GHSA, the severity and the fixed version, from the registry's bulk advisory endpoint, the one \`bun audit\` reads.
|
|
3140
3150
|
Findings are grouped per package, each registry package looked up once per run.
|
|
3141
|
-
Reach for it to vet one repository in depth; \`audit\` sweeps many repositories for advisories only, and shares --level, --prod and --ignore.`, EXITS2, options2, BATCH = 8;
|
|
3151
|
+
Reach for it to vet one repository in depth; \`audit\` sweeps many repositories for advisories only, and shares --level, --prod and --ignore.`, EXITS2, options2, BATCH = 8, HIGH_SEVERITIES;
|
|
3142
3152
|
var init_audit = __esm(() => {
|
|
3143
3153
|
init_src();
|
|
3144
3154
|
init_advisories();
|
|
@@ -3154,6 +3164,7 @@ var init_audit = __esm(() => {
|
|
|
3154
3164
|
prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
|
|
3155
3165
|
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
|
|
3156
3166
|
};
|
|
3167
|
+
HIGH_SEVERITIES = new Set(["high", "critical"]);
|
|
3157
3168
|
});
|
|
3158
3169
|
|
|
3159
3170
|
// src/commands/outdated.ts
|
|
@@ -3207,7 +3218,7 @@ async function outdatedCommand(args) {
|
|
|
3207
3218
|
if (values.json === true)
|
|
3208
3219
|
printJson(shown);
|
|
3209
3220
|
else if (shown.length === 0)
|
|
3210
|
-
console.log("nothing outdated: every dependency is on its safe version");
|
|
3221
|
+
console.log(role("ok", process.stdout)("nothing outdated: every dependency is on its safe version"));
|
|
3211
3222
|
else
|
|
3212
3223
|
console.log([table([["PACKAGE", "KIND", "CURRENT", "SAFE", "CHANGE", "PUBLISHED", "LATEST"], ...shown.map((each) => [each.name, each.kind, each.current, each.safe, each.change, each.published === undefined ? "-" : formatAge(each.published), each.latest ?? ""])], { header: true }), ...footer === undefined ? [] : [footer]].join(`
|
|
3213
3224
|
`));
|
|
@@ -3703,7 +3714,7 @@ async function choosePlan(name, version, settings, chooser = terminalChooser, ho
|
|
|
3703
3714
|
return { chosen: chosen.map((plan) => plan.dir), declined };
|
|
3704
3715
|
}
|
|
3705
3716
|
async function bump(args) {
|
|
3706
|
-
const { values, positionals: [name, asked] } = parse(args, usage5, options4, { positionals: ["<name>", "[version]"] });
|
|
3717
|
+
const { values, positionals: [name, asked] } = parse(args, usage5, options4, { exits: EXITS4, positionals: ["<name>", "[version]"] });
|
|
3707
3718
|
const settings = {
|
|
3708
3719
|
root: workspaceRoot({ given: values.root }),
|
|
3709
3720
|
configs: await loadConfigs(),
|
|
@@ -3736,9 +3747,7 @@ A version the vetting blocks is refused before any folder is touched, unless --f
|
|
|
3736
3747
|
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).
|
|
3737
3748
|
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.
|
|
3738
3749
|
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.
|
|
3739
|
-
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
|
|
3740
|
-
|
|
3741
|
-
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;
|
|
3750
|
+
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.`, EXITS4, ROOT_OPTION, options4, POLL = 5000, terminalChooser;
|
|
3742
3751
|
var init_bump = __esm(() => {
|
|
3743
3752
|
init_src();
|
|
3744
3753
|
init_progress();
|
|
@@ -3750,6 +3759,7 @@ var init_bump = __esm(() => {
|
|
|
3750
3759
|
init_registry();
|
|
3751
3760
|
init_semver();
|
|
3752
3761
|
init_check();
|
|
3762
|
+
EXITS4 = [[0, "every install ran or was left as it is (with --all-consumers, and every check passed and every commit landed)"], [1, "the vetting refuses the version, an install, a check or a commit fails or the registry has no such package"], [2, "the version never shows within the timeout (a registry that cannot be reached is retried until then) or a usage error"]];
|
|
3753
3763
|
ROOT_OPTION = { type: "string", description: "the folder holding the repositories (the workspace of the user config or KAYNOOO_WORKSPACE, ~/Workspace by default)" };
|
|
3754
3764
|
options4 = {
|
|
3755
3765
|
root: ROOT_OPTION,
|
|
@@ -3774,7 +3784,7 @@ __export(exports_consumers, {
|
|
|
3774
3784
|
consumers: () => consumers
|
|
3775
3785
|
});
|
|
3776
3786
|
function consumers(args) {
|
|
3777
|
-
const { values, positionals: [name] } = parse(args, usage6, options5, { positionals: ["<name>"] });
|
|
3787
|
+
const { values, positionals: [name] } = parse(args, usage6, options5, { exits: EXITS5, positionals: ["<name>"] });
|
|
3778
3788
|
const root = workspaceRoot({ given: values.root });
|
|
3779
3789
|
const { shown, footer } = capped(findConsumers(name, root), limitOf(values, CONSUMERS_LIMIT));
|
|
3780
3790
|
if (values.json === true) {
|
|
@@ -3790,13 +3800,12 @@ function consumers(args) {
|
|
|
3790
3800
|
}
|
|
3791
3801
|
var usage6 = `pkg consumers <name>
|
|
3792
3802
|
|
|
3793
|
-
Lists the folders under --root whose package.json depends on the package, by its own name or through an \`npm:\` alias of it (the alias key is shown after the kind): the folder, the kind of dependency, the version it asks for and the manager its lockfile pins, 30 at most with the count of the rest after them (--limit <n>, --full for all; --json is never cut unless --limit is given)
|
|
3794
|
-
|
|
3795
|
-
Exits 0 when it listed them, 2 on a usage error.`, CONSUMERS_LIMIT = 30, options5;
|
|
3803
|
+
Lists the folders under --root whose package.json depends on the package, by its own name or through an \`npm:\` alias of it (the alias key is shown after the kind): the folder, the kind of dependency, the version it asks for and the manager its lockfile pins, 30 at most with the count of the rest after them (--limit <n>, --full for all; --json is never cut unless --limit is given).`, EXITS5, CONSUMERS_LIMIT = 30, options5;
|
|
3796
3804
|
var init_consumers2 = __esm(() => {
|
|
3797
3805
|
init_src();
|
|
3798
3806
|
init_consumers();
|
|
3799
3807
|
init_bump();
|
|
3808
|
+
EXITS5 = [[0, "it listed them"], [2, "a usage error"]];
|
|
3800
3809
|
options5 = {
|
|
3801
3810
|
root: ROOT_OPTION,
|
|
3802
3811
|
...limitOptions(CONSUMERS_LIMIT),
|
|
@@ -3844,6 +3853,7 @@ __export(exports_manager, {
|
|
|
3844
3853
|
import process21 from "process";
|
|
3845
3854
|
function manager(args) {
|
|
3846
3855
|
const { values, positionals } = parse(args, usage7, options6, {
|
|
3856
|
+
exits: EXITS6,
|
|
3847
3857
|
positionals: ["<action>"],
|
|
3848
3858
|
candidates: { "<action>": () => [...ACTIONS2] },
|
|
3849
3859
|
replaces: "telling bun, yarn, pnpm, npm, composer and uv apart by their lockfile before typing an add, remove or dlx",
|
|
@@ -3860,12 +3870,11 @@ function manager(args) {
|
|
|
3860
3870
|
}
|
|
3861
3871
|
var usage7 = `pkg manager <install|dev|remove|update|exec>
|
|
3862
3872
|
|
|
3863
|
-
Prints the command the package manager of this folder runs for the action: install is the add or install of a package, dev adds one as a dev dependency, remove drops one, update upgrades them and exec runs a package's bin without installing it. The manager is the one whose lockfile (bun.lock, bun.lockb, yarn.lock, pnpm-lock.yaml, package-lock.json, uv.lock) or composer.json is nearest, here or in a parent folder, bun when none is found
|
|
3864
|
-
|
|
3865
|
-
Exits 0 when it printed the command, 2 on a usage error.`, options6;
|
|
3873
|
+
Prints the command the package manager of this folder runs for the action: install is the add or install of a package, dev adds one as a dev dependency, remove drops one, update upgrades them and exec runs a package's bin without installing it. The manager is the one whose lockfile (bun.lock, bun.lockb, yarn.lock, pnpm-lock.yaml, package-lock.json, uv.lock) or composer.json is nearest, here or in a parent folder, bun when none is found.`, EXITS6, options6;
|
|
3866
3874
|
var init_manager2 = __esm(() => {
|
|
3867
3875
|
init_src();
|
|
3868
3876
|
init_manager();
|
|
3877
|
+
EXITS6 = [[0, "it printed the command"], [2, "a usage error"]];
|
|
3869
3878
|
options6 = {
|
|
3870
3879
|
json: jsonOption("{manager, action, command}")
|
|
3871
3880
|
};
|
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.15.1",
|
|
5
5
|
"description": "pkg: check an npm package before it is added, for a guessed name, a version under two weeks old and install scripts.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"@kaynooo/utils": "3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@kaynooo/cli-kit": "0.38.
|
|
36
|
+
"@kaynooo/cli-kit": "0.38.3"
|
|
37
37
|
}
|
|
38
38
|
}
|