@kaynooo/cli-pkg 0.13.3 → 0.15.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 +10 -0
- package/dist/cli.js +181 -69
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -67,6 +67,16 @@ pkg bump @kaynooo/cli-kit 0.8.0 --dry-run
|
|
|
67
67
|
|
|
68
68
|
The metadata comes from the registry the name is installed from. A `@scope/` name follows `@scope:registry=` in the nearest `.npmrc` or `[install.scopes]` in the nearest `bunfig.toml`, walking up from the current directory and ending at the home directory, and a scope key wins over a nearer plain `registry=`, as it does for npm; the token (`_authToken`, or `token` in bunfig, with `${VAR}` or `$VAR` expanded) is sent to that registry only, matched on a path boundary, over https (or http to localhost) only, and never printed. Environment variables are expanded in tokens only, never in a registry address. Every request has a 10 s deadline. Downloads come from the npmjs.org API, so they show `-` for any other registry. A registry that does not return publish times (Forgejo's does not) leaves the age unchecked, which `pkg` says in a warning.
|
|
69
69
|
|
|
70
|
+
## The folder's package manager
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
pkg manager dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`pkg manager <install|dev|remove|update|exec>` prints the command the manager of this folder runs for the action, such as `bun add -d`, `composer require --dev` or `pnpm dlx`. 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. `--json` prints `{manager, action, command}`.
|
|
77
|
+
|
|
78
|
+
A shell abbreviation can call it through a small function, in fish `function __nd; pkg manager dev; end` then `abbr -a nd --function __nd`.
|
|
79
|
+
|
|
70
80
|
## Maintenance
|
|
71
81
|
|
|
72
82
|
- `bun run popular` regenerates `src/popular.json`, the 500 most downloaded names from the [npm-high-impact](https://www.npmjs.com/package/npm-high-impact) list.
|
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();
|
|
@@ -900,6 +904,32 @@ var init_args = __esm(() => {
|
|
|
900
904
|
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
901
905
|
});
|
|
902
906
|
|
|
907
|
+
// ../kit/src/argv.ts
|
|
908
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
909
|
+
import { resolve as resolve3 } from "path";
|
|
910
|
+
import process11 from "process";
|
|
911
|
+
function commandLine() {
|
|
912
|
+
try {
|
|
913
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
914
|
+
} catch {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
function realPath(word) {
|
|
919
|
+
try {
|
|
920
|
+
return realpathSync(resolve3(word));
|
|
921
|
+
} catch {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
926
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
927
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
928
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
929
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
930
|
+
}
|
|
931
|
+
var init_argv = () => {};
|
|
932
|
+
|
|
903
933
|
// ../kit/src/chart.ts
|
|
904
934
|
var init_chart = __esm(() => {
|
|
905
935
|
init_format();
|
|
@@ -910,7 +940,7 @@ var init_chart = __esm(() => {
|
|
|
910
940
|
|
|
911
941
|
// ../kit/src/process.ts
|
|
912
942
|
import { constants } from "os";
|
|
913
|
-
import
|
|
943
|
+
import process12 from "process";
|
|
914
944
|
function exitCodeOf(code, signal) {
|
|
915
945
|
if (code !== null)
|
|
916
946
|
return code;
|
|
@@ -930,7 +960,7 @@ function holdSignals(cleanup) {
|
|
|
930
960
|
},
|
|
931
961
|
release: () => {
|
|
932
962
|
for (const signal of SIGNALS)
|
|
933
|
-
|
|
963
|
+
process12.off(signal, onSignal);
|
|
934
964
|
}
|
|
935
965
|
};
|
|
936
966
|
function onSignal(signal) {
|
|
@@ -943,10 +973,10 @@ function holdSignals(cleanup) {
|
|
|
943
973
|
return;
|
|
944
974
|
held.release();
|
|
945
975
|
cleanup(signal);
|
|
946
|
-
|
|
976
|
+
process12.kill(process12.pid, signal);
|
|
947
977
|
}
|
|
948
978
|
for (const signal of SIGNALS)
|
|
949
|
-
|
|
979
|
+
process12.on(signal, onSignal);
|
|
950
980
|
return held;
|
|
951
981
|
}
|
|
952
982
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -960,7 +990,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
960
990
|
return;
|
|
961
991
|
try {
|
|
962
992
|
if (grouped)
|
|
963
|
-
|
|
993
|
+
process12.kill(-proc.pid, killing);
|
|
964
994
|
else
|
|
965
995
|
proc.kill(killing);
|
|
966
996
|
} catch {}
|
|
@@ -1033,8 +1063,8 @@ var init_process = __esm(() => {
|
|
|
1033
1063
|
});
|
|
1034
1064
|
|
|
1035
1065
|
// ../kit/src/progress.ts
|
|
1036
|
-
import
|
|
1037
|
-
function liveRegion(render, stream =
|
|
1066
|
+
import process13 from "process";
|
|
1067
|
+
function liveRegion(render, stream = process13.stderr, env = process13.env) {
|
|
1038
1068
|
if (!takesControlCodes(stream, env))
|
|
1039
1069
|
return { redraw: () => {
|
|
1040
1070
|
return;
|
|
@@ -1081,11 +1111,11 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1081
1111
|
clear();
|
|
1082
1112
|
restore();
|
|
1083
1113
|
release();
|
|
1084
|
-
|
|
1114
|
+
process13.off("exit", onExit);
|
|
1085
1115
|
signals.release();
|
|
1086
1116
|
}
|
|
1087
1117
|
timer.unref();
|
|
1088
|
-
|
|
1118
|
+
process13.on("exit", onExit);
|
|
1089
1119
|
return {
|
|
1090
1120
|
redraw: draw,
|
|
1091
1121
|
print: (text) => {
|
|
@@ -1124,14 +1154,14 @@ function cutToWidth(line, width) {
|
|
|
1124
1154
|
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1125
1155
|
}
|
|
1126
1156
|
function swallowInput() {
|
|
1127
|
-
const input =
|
|
1157
|
+
const input = process13.stdin;
|
|
1128
1158
|
if (!input.isTTY)
|
|
1129
1159
|
return () => {
|
|
1130
1160
|
return;
|
|
1131
1161
|
};
|
|
1132
1162
|
const onData = (data) => {
|
|
1133
1163
|
if (data.includes(CTRL_C))
|
|
1134
|
-
|
|
1164
|
+
process13.kill(process13.pid, "SIGINT");
|
|
1135
1165
|
};
|
|
1136
1166
|
input.setRawMode(true);
|
|
1137
1167
|
input.on("data", onData);
|
|
@@ -1147,7 +1177,7 @@ function swallowInput() {
|
|
|
1147
1177
|
};
|
|
1148
1178
|
}
|
|
1149
1179
|
function interceptOutput(clear) {
|
|
1150
|
-
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [
|
|
1180
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process13.stdout, "write"], [process13.stderr, "write"]];
|
|
1151
1181
|
const wrapped = targets.map(([target, name]) => {
|
|
1152
1182
|
const original = Reflect.get(target, name);
|
|
1153
1183
|
const wrapper = (...args) => {
|
|
@@ -1203,18 +1233,18 @@ var init_logs = __esm(() => {
|
|
|
1203
1233
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1204
1234
|
import { homedir as homedir3 } from "os";
|
|
1205
1235
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1206
|
-
import
|
|
1236
|
+
import process14 from "process";
|
|
1207
1237
|
function noteUsageError(message) {
|
|
1208
1238
|
usageError = message;
|
|
1209
1239
|
}
|
|
1210
|
-
function stateHome(env =
|
|
1240
|
+
function stateHome(env = process14.env) {
|
|
1211
1241
|
const dir = env.XDG_STATE_HOME;
|
|
1212
1242
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1213
1243
|
}
|
|
1214
|
-
function usagePath(env =
|
|
1244
|
+
function usagePath(env = process14.env) {
|
|
1215
1245
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1216
1246
|
}
|
|
1217
|
-
function usageRecorded(env =
|
|
1247
|
+
function usageRecorded(env = process14.env) {
|
|
1218
1248
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1219
1249
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1220
1250
|
}
|
|
@@ -1228,7 +1258,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1228
1258
|
usageError = undefined;
|
|
1229
1259
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1230
1260
|
}
|
|
1231
|
-
function recordUsage(entry, env =
|
|
1261
|
+
function recordUsage(entry, env = process14.env) {
|
|
1232
1262
|
if (!usageRecorded(env))
|
|
1233
1263
|
return;
|
|
1234
1264
|
try {
|
|
@@ -1246,9 +1276,9 @@ var init_usage = __esm(() => {
|
|
|
1246
1276
|
});
|
|
1247
1277
|
|
|
1248
1278
|
// ../kit/src/cli.ts
|
|
1249
|
-
import { readFileSync as
|
|
1279
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1250
1280
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1251
|
-
import
|
|
1281
|
+
import process15 from "process";
|
|
1252
1282
|
async function commandRows(all, colors) {
|
|
1253
1283
|
const commands = shown(all);
|
|
1254
1284
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1323,8 +1353,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1323
1353
|
`);
|
|
1324
1354
|
}
|
|
1325
1355
|
function printError(prefix, message, hint, cause) {
|
|
1326
|
-
const colors = paint(
|
|
1327
|
-
const styled = takesControlCodes(
|
|
1356
|
+
const colors = paint(process15.stderr);
|
|
1357
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1328
1358
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1329
1359
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1330
1360
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1367,11 +1397,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1367
1397
|
}
|
|
1368
1398
|
}
|
|
1369
1399
|
if (name === undefined && level.path.length > 1) {
|
|
1370
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1400
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1371
1401
|
return 2;
|
|
1372
1402
|
}
|
|
1373
1403
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1374
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1404
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1375
1405
|
return 0;
|
|
1376
1406
|
}
|
|
1377
1407
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1425,24 +1455,24 @@ function candidateLine(candidate) {
|
|
|
1425
1455
|
}
|
|
1426
1456
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1427
1457
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1428
|
-
|
|
1458
|
+
const typed = [];
|
|
1429
1459
|
let at = 0;
|
|
1430
1460
|
while (at < before.length) {
|
|
1431
1461
|
const word = before[at];
|
|
1432
1462
|
if (word === "--") {
|
|
1433
|
-
|
|
1463
|
+
typed.push(...before.slice(at + 1));
|
|
1434
1464
|
break;
|
|
1435
1465
|
}
|
|
1436
1466
|
if (!word.startsWith("-"))
|
|
1437
|
-
|
|
1467
|
+
typed.push(word);
|
|
1438
1468
|
else if (takesValue(word))
|
|
1439
1469
|
at++;
|
|
1440
1470
|
at++;
|
|
1441
1471
|
}
|
|
1442
1472
|
const last = positionals.at(-1);
|
|
1443
|
-
if (
|
|
1444
|
-
return positionals[
|
|
1445
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1473
|
+
if (typed.length < positionals.length)
|
|
1474
|
+
return { name: positionals[typed.length], typed };
|
|
1475
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1446
1476
|
}
|
|
1447
1477
|
async function leafCandidates(run, words) {
|
|
1448
1478
|
const completing = await completingOf(run);
|
|
@@ -1450,12 +1480,12 @@ async function leafCandidates(run, words) {
|
|
|
1450
1480
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1451
1481
|
const flag = words.at(-2);
|
|
1452
1482
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1483
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1453
1484
|
if (option?.type === "string") {
|
|
1454
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1485
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1455
1486
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1456
1487
|
}
|
|
1457
|
-
const
|
|
1458
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1488
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1459
1489
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1460
1490
|
}
|
|
1461
1491
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1486,9 +1516,13 @@ async function printCandidates(found) {
|
|
|
1486
1516
|
return 0;
|
|
1487
1517
|
}
|
|
1488
1518
|
function packageVersion(entry = Bun.main) {
|
|
1489
|
-
|
|
1519
|
+
let resolved = entry;
|
|
1520
|
+
try {
|
|
1521
|
+
resolved = realpathSync2(entry);
|
|
1522
|
+
} catch {}
|
|
1523
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1490
1524
|
try {
|
|
1491
|
-
const { version } = JSON.parse(
|
|
1525
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1492
1526
|
if (typeof version === "string")
|
|
1493
1527
|
return version;
|
|
1494
1528
|
} catch {}
|
|
@@ -1496,7 +1530,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1496
1530
|
return "0.0.0";
|
|
1497
1531
|
}
|
|
1498
1532
|
}
|
|
1499
|
-
async function runCli(cli, argv =
|
|
1533
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1500
1534
|
const version = cli.version ?? packageVersion();
|
|
1501
1535
|
if (argv[0] === COMPLETE)
|
|
1502
1536
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1526,6 +1560,7 @@ function commandPath(scope, argv) {
|
|
|
1526
1560
|
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
|
|
1527
1561
|
var init_cli = __esm(() => {
|
|
1528
1562
|
init_args();
|
|
1563
|
+
init_argv();
|
|
1529
1564
|
init_style();
|
|
1530
1565
|
init_text2();
|
|
1531
1566
|
init_usage();
|
|
@@ -1625,8 +1660,8 @@ var init_watch = __esm(() => {
|
|
|
1625
1660
|
|
|
1626
1661
|
// ../kit/src/workspace-root.ts
|
|
1627
1662
|
import { homedir as homedir4 } from "os";
|
|
1628
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1629
|
-
import
|
|
1663
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1664
|
+
import process16 from "process";
|
|
1630
1665
|
function expandHome(path, home) {
|
|
1631
1666
|
if (path === "~")
|
|
1632
1667
|
return home;
|
|
@@ -1636,9 +1671,9 @@ function configured(env, home) {
|
|
|
1636
1671
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1637
1672
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1638
1673
|
}
|
|
1639
|
-
function workspaceRoot({ given, env =
|
|
1674
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1640
1675
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1641
|
-
return
|
|
1676
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1642
1677
|
}
|
|
1643
1678
|
var init_workspace_root = __esm(() => {
|
|
1644
1679
|
init_user_config();
|
|
@@ -1648,6 +1683,7 @@ var init_workspace_root = __esm(() => {
|
|
|
1648
1683
|
var init_src = __esm(() => {
|
|
1649
1684
|
init_advisory();
|
|
1650
1685
|
init_args();
|
|
1686
|
+
init_argv();
|
|
1651
1687
|
init_chart();
|
|
1652
1688
|
init_ci();
|
|
1653
1689
|
init_cli();
|
|
@@ -2397,7 +2433,7 @@ function parseSpec(text) {
|
|
|
2397
2433
|
function isStable(version) {
|
|
2398
2434
|
return !version.includes("-");
|
|
2399
2435
|
}
|
|
2400
|
-
function
|
|
2436
|
+
function resolve5(packument, request) {
|
|
2401
2437
|
const tags = packument["dist-tags"] ?? {};
|
|
2402
2438
|
const versions = Object.keys(packument.versions ?? {});
|
|
2403
2439
|
const wanted = request === undefined || request === "" ? "latest" : request;
|
|
@@ -2442,7 +2478,7 @@ function analyze(input) {
|
|
|
2442
2478
|
return report;
|
|
2443
2479
|
}
|
|
2444
2480
|
const latest = packument["dist-tags"]?.latest;
|
|
2445
|
-
const version =
|
|
2481
|
+
const version = resolve5(packument, spec.request);
|
|
2446
2482
|
const entry = version === undefined ? undefined : packument.versions?.[version];
|
|
2447
2483
|
report.description = packument.description;
|
|
2448
2484
|
report.license = licenseOf(entry?.license) ?? licenseOf(packument.license);
|
|
@@ -2512,7 +2548,7 @@ var init_analyze = __esm(() => {
|
|
|
2512
2548
|
// src/config.ts
|
|
2513
2549
|
import { homedir as homedir5 } from "os";
|
|
2514
2550
|
import { dirname as dirname5, join as join7 } from "path";
|
|
2515
|
-
import
|
|
2551
|
+
import process18 from "process";
|
|
2516
2552
|
function expand2(value, env) {
|
|
2517
2553
|
let missing = false;
|
|
2518
2554
|
const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
|
|
@@ -2601,7 +2637,7 @@ async function readIfThere(path) {
|
|
|
2601
2637
|
const file = Bun.file(path);
|
|
2602
2638
|
return await file.exists() ? file.text() : undefined;
|
|
2603
2639
|
}
|
|
2604
|
-
async function loadConfigs(cwd =
|
|
2640
|
+
async function loadConfigs(cwd = process18.cwd(), env = process18.env, home = homedir5()) {
|
|
2605
2641
|
const directories = [];
|
|
2606
2642
|
for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
|
|
2607
2643
|
directories.push(dir);
|
|
@@ -2634,7 +2670,7 @@ function parseSettings(text) {
|
|
|
2634
2670
|
settings.concurrency = raw.concurrency;
|
|
2635
2671
|
return settings;
|
|
2636
2672
|
}
|
|
2637
|
-
async function loadSettings(cwd =
|
|
2673
|
+
async function loadSettings(cwd = process18.cwd(), home) {
|
|
2638
2674
|
const files = [];
|
|
2639
2675
|
for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
|
|
2640
2676
|
files.push(join7(dir, SETTINGS_FILE));
|
|
@@ -2751,7 +2787,7 @@ var init_pin = __esm(() => {
|
|
|
2751
2787
|
});
|
|
2752
2788
|
|
|
2753
2789
|
// src/consumers.ts
|
|
2754
|
-
import { existsSync as existsSync4, readdirSync, readFileSync as
|
|
2790
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
2755
2791
|
import { dirname as dirname6, join as join8, relative } from "path";
|
|
2756
2792
|
function packageFiles(dir, depth, found, ignored = ignoredFolders()) {
|
|
2757
2793
|
let entries;
|
|
@@ -2779,7 +2815,7 @@ function managerFor(dir, root) {
|
|
|
2779
2815
|
}
|
|
2780
2816
|
function readManifest(path) {
|
|
2781
2817
|
try {
|
|
2782
|
-
return JSON.parse(
|
|
2818
|
+
return JSON.parse(readFileSync5(path, "utf8"));
|
|
2783
2819
|
} catch {
|
|
2784
2820
|
return;
|
|
2785
2821
|
}
|
|
@@ -2883,9 +2919,11 @@ async function checkPackage(text, context) {
|
|
|
2883
2919
|
function when(release, now) {
|
|
2884
2920
|
return release?.published === undefined ? "" : `, published ${formatAge(release.published, now)} (${release.published.slice(0, 10)})`;
|
|
2885
2921
|
}
|
|
2886
|
-
function render(report, now = Date.now()) {
|
|
2922
|
+
function render(report, now = Date.now(), stream = process.stdout, env = process.env) {
|
|
2923
|
+
const id = role("id", stream, env);
|
|
2924
|
+
const warn = role("warn", stream, env);
|
|
2887
2925
|
if (!report.exists)
|
|
2888
|
-
return [report.name, ...report.warnings.map((warning) => ` warning: ${warning}`)].join(`
|
|
2926
|
+
return [id(report.name), ...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)].join(`
|
|
2889
2927
|
`);
|
|
2890
2928
|
const asked = report.requested === undefined ? "" : ` (asked for ${report.requested})`;
|
|
2891
2929
|
const rows = [
|
|
@@ -2898,9 +2936,9 @@ function render(report, now = Date.now()) {
|
|
|
2898
2936
|
...Object.entries(report.installScripts).map(([name, command]) => [name, command])
|
|
2899
2937
|
];
|
|
2900
2938
|
return [
|
|
2901
|
-
`${report.name}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
2939
|
+
`${id(report.name)}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
2902
2940
|
table(rows.map(([key, value]) => [` ${key}`, value ?? ""])),
|
|
2903
|
-
...report.warnings.map((warning) => ` warning: ${warning}`)
|
|
2941
|
+
...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)
|
|
2904
2942
|
].join(`
|
|
2905
2943
|
`);
|
|
2906
2944
|
}
|
|
@@ -3022,8 +3060,8 @@ var exports_audit = {};
|
|
|
3022
3060
|
__export(exports_audit, {
|
|
3023
3061
|
audit: () => audit
|
|
3024
3062
|
});
|
|
3025
|
-
import { join as join9, resolve as
|
|
3026
|
-
import
|
|
3063
|
+
import { join as join9, resolve as resolve6 } from "path";
|
|
3064
|
+
import process19 from "process";
|
|
3027
3065
|
function hasFinding(audited) {
|
|
3028
3066
|
return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
|
|
3029
3067
|
}
|
|
@@ -3063,14 +3101,19 @@ async function auditPackages(packages, context) {
|
|
|
3063
3101
|
});
|
|
3064
3102
|
return { audited, unavailable };
|
|
3065
3103
|
}
|
|
3066
|
-
function renderAudit(findings, total) {
|
|
3104
|
+
function renderAudit(findings, total, stream = process19.stdout, env = process19.env) {
|
|
3105
|
+
const id = role("id", stream, env);
|
|
3106
|
+
const label = role("label", stream, env);
|
|
3107
|
+
const warning = role("warn", stream, env);
|
|
3108
|
+
const problem = role("problem", stream, env);
|
|
3109
|
+
const blocking = findings.filter((each) => each.blocked).length;
|
|
3067
3110
|
const blocks = findings.map(({ name, version, warnings, advisories }) => [
|
|
3068
|
-
`${name}@${version}
|
|
3069
|
-
...warnings.map((
|
|
3070
|
-
...advisories.map((each) => ` ${each.ghsa ?? each.id} ${each.severity}: ${each.title}${each.fixed === undefined ? "" : ` (fixed in ${each.fixed})`}`)
|
|
3111
|
+
id(`${name}@${version}`),
|
|
3112
|
+
...warnings.map((each) => ` ${warning("warning:")} ${each}`),
|
|
3113
|
+
...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})`)}`}`)
|
|
3071
3114
|
].join(`
|
|
3072
3115
|
`));
|
|
3073
|
-
return [...blocks, `${findings.length} of ${total} packages with a finding, ${
|
|
3116
|
+
return [...blocks, `${findings.length} of ${total} packages with a finding, ${(blocking === 0 ? label : problem)(`${blocking} blocking`)}`].join(`
|
|
3074
3117
|
|
|
3075
3118
|
`);
|
|
3076
3119
|
}
|
|
@@ -3079,7 +3122,7 @@ async function audit(args) {
|
|
|
3079
3122
|
const level = values.level ?? "moderate";
|
|
3080
3123
|
if (!isSeverity(level))
|
|
3081
3124
|
fail(`--level takes ${SEVERITIES.join(", ")}, not ${level}`);
|
|
3082
|
-
const dir =
|
|
3125
|
+
const dir = resolve6(asked ?? process19.cwd());
|
|
3083
3126
|
const lock = Bun.file(join9(dir, "bun.lock"));
|
|
3084
3127
|
if (!await lock.exists())
|
|
3085
3128
|
fail(`no bun.lock in ${dir}`);
|
|
@@ -3110,7 +3153,7 @@ var usage3 = `pkg audit [dir]
|
|
|
3110
3153
|
|
|
3111
3154
|
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.
|
|
3112
3155
|
Findings are grouped per package, each registry package looked up once per run.
|
|
3113
|
-
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;
|
|
3156
|
+
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;
|
|
3114
3157
|
var init_audit = __esm(() => {
|
|
3115
3158
|
init_src();
|
|
3116
3159
|
init_advisories();
|
|
@@ -3126,6 +3169,7 @@ var init_audit = __esm(() => {
|
|
|
3126
3169
|
prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
|
|
3127
3170
|
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
|
|
3128
3171
|
};
|
|
3172
|
+
HIGH_SEVERITIES = new Set(["high", "critical"]);
|
|
3129
3173
|
});
|
|
3130
3174
|
|
|
3131
3175
|
// src/commands/outdated.ts
|
|
@@ -3134,7 +3178,7 @@ __export(exports_outdated, {
|
|
|
3134
3178
|
outdatedCommand: () => outdatedCommand
|
|
3135
3179
|
});
|
|
3136
3180
|
import { existsSync as existsSync5 } from "fs";
|
|
3137
|
-
import { join as join10, resolve as
|
|
3181
|
+
import { join as join10, resolve as resolve7 } from "path";
|
|
3138
3182
|
function currentOf(name, spec, locked) {
|
|
3139
3183
|
const pinned = locked.filter((each) => each.name === name && Bun.semver.satisfies(each.version, spec)).map((each) => each.version).sort(Bun.semver.order).at(-1);
|
|
3140
3184
|
const written = FIRST_VERSION.exec(spec)?.[0];
|
|
@@ -3167,7 +3211,7 @@ async function outdated(manifest, context) {
|
|
|
3167
3211
|
}
|
|
3168
3212
|
async function outdatedCommand(args) {
|
|
3169
3213
|
const { values, positionals: [dir = "."] } = parse(args, usage4, options3, { positionals: ["[dir]"], exits: EXITS3 });
|
|
3170
|
-
const folder =
|
|
3214
|
+
const folder = resolve7(dir);
|
|
3171
3215
|
const manifest = Bun.file(join10(folder, "package.json"));
|
|
3172
3216
|
if (!await manifest.exists())
|
|
3173
3217
|
fail(`no package.json in ${folder}`);
|
|
@@ -3179,7 +3223,7 @@ async function outdatedCommand(args) {
|
|
|
3179
3223
|
if (values.json === true)
|
|
3180
3224
|
printJson(shown);
|
|
3181
3225
|
else if (shown.length === 0)
|
|
3182
|
-
console.log("nothing outdated: every dependency is on its safe version");
|
|
3226
|
+
console.log(role("ok", process.stdout)("nothing outdated: every dependency is on its safe version"));
|
|
3183
3227
|
else
|
|
3184
3228
|
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(`
|
|
3185
3229
|
`));
|
|
@@ -3274,7 +3318,7 @@ var init_state = __esm(() => {
|
|
|
3274
3318
|
});
|
|
3275
3319
|
|
|
3276
3320
|
// ../kit/src/prompt.ts
|
|
3277
|
-
import
|
|
3321
|
+
import process20 from "process";
|
|
3278
3322
|
function readKeys(input, paste = { active: false }) {
|
|
3279
3323
|
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
3280
3324
|
}
|
|
@@ -3388,7 +3432,7 @@ function asking(colors, question, typed, keys) {
|
|
|
3388
3432
|
function answer(colors, question, state, picked) {
|
|
3389
3433
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
3390
3434
|
}
|
|
3391
|
-
async function ask(question, { hint, terminal =
|
|
3435
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
3392
3436
|
const { stdin, stderr } = terminal;
|
|
3393
3437
|
if (!isInteractive(terminal))
|
|
3394
3438
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -3454,7 +3498,7 @@ var init_prompt = __esm(() => {
|
|
|
3454
3498
|
});
|
|
3455
3499
|
|
|
3456
3500
|
// src/excluded.ts
|
|
3457
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as
|
|
3501
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync } from "fs";
|
|
3458
3502
|
import { dirname as dirname7 } from "path";
|
|
3459
3503
|
function excludedPath(home) {
|
|
3460
3504
|
return userConfigPath("pkg-excluded", { home });
|
|
@@ -3464,7 +3508,7 @@ function loadExcluded(home) {
|
|
|
3464
3508
|
if (!existsSync6(path))
|
|
3465
3509
|
return {};
|
|
3466
3510
|
try {
|
|
3467
|
-
const raw = JSON.parse(
|
|
3511
|
+
const raw = JSON.parse(readFileSync6(path, "utf8"));
|
|
3468
3512
|
const excluded = {};
|
|
3469
3513
|
for (const [name, dirs] of Object.entries(raw)) {
|
|
3470
3514
|
if (Array.isArray(dirs))
|
|
@@ -3776,10 +3820,77 @@ var init_consumers2 = __esm(() => {
|
|
|
3776
3820
|
};
|
|
3777
3821
|
});
|
|
3778
3822
|
|
|
3823
|
+
// src/manager.ts
|
|
3824
|
+
import { existsSync as existsSync8 } from "fs";
|
|
3825
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
3826
|
+
function detectManager(from) {
|
|
3827
|
+
let dir = from;
|
|
3828
|
+
while (true) {
|
|
3829
|
+
const found = LOCKFILES2.find(([file]) => existsSync8(join12(dir, file)));
|
|
3830
|
+
if (found !== undefined)
|
|
3831
|
+
return found[1];
|
|
3832
|
+
const parent = dirname9(dir);
|
|
3833
|
+
if (parent === dir)
|
|
3834
|
+
return "bun";
|
|
3835
|
+
dir = parent;
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
function commandFor(action, manager) {
|
|
3839
|
+
const { fallback, ...own } = COMMANDS[action];
|
|
3840
|
+
return own[manager] ?? fallback(manager);
|
|
3841
|
+
}
|
|
3842
|
+
var ACTIONS2, LOCKFILES2, COMMANDS;
|
|
3843
|
+
var init_manager = __esm(() => {
|
|
3844
|
+
ACTIONS2 = ["install", "dev", "remove", "update", "exec"];
|
|
3845
|
+
LOCKFILES2 = [["bun.lock", "bun"], ["bun.lockb", "bun"], ["yarn.lock", "yarn"], ["pnpm-lock.yaml", "pnpm"], ["package-lock.json", "npm"], ["composer.json", "composer"], ["uv.lock", "uv"]];
|
|
3846
|
+
COMMANDS = {
|
|
3847
|
+
install: { yarn: "yarn add", uv: "uv sync", fallback: (manager) => `${manager} install` },
|
|
3848
|
+
dev: { bun: "bun add -d", yarn: "yarn add -D", pnpm: "pnpm add -D", composer: "composer require --dev", uv: "uv add --dev", fallback: () => "npm install -D" },
|
|
3849
|
+
remove: { npm: "npm uninstall", fallback: (manager) => `${manager} remove` },
|
|
3850
|
+
update: { yarn: "yarn upgrade", uv: "uv lock --upgrade", fallback: (manager) => `${manager} update` },
|
|
3851
|
+
exec: { bun: "bunx", pnpm: "pnpm dlx", yarn: "yarn dlx", composer: "composer exec", uv: "uvx", fallback: () => "npx" }
|
|
3852
|
+
};
|
|
3853
|
+
});
|
|
3854
|
+
|
|
3855
|
+
// src/commands/manager.ts
|
|
3856
|
+
var exports_manager = {};
|
|
3857
|
+
__export(exports_manager, {
|
|
3858
|
+
manager: () => manager
|
|
3859
|
+
});
|
|
3860
|
+
import process21 from "process";
|
|
3861
|
+
function manager(args) {
|
|
3862
|
+
const { values, positionals } = parse(args, usage7, options6, {
|
|
3863
|
+
positionals: ["<action>"],
|
|
3864
|
+
candidates: { "<action>": () => [...ACTIONS2] },
|
|
3865
|
+
replaces: "telling bun, yarn, pnpm, npm, composer and uv apart by their lockfile before typing an add, remove or dlx",
|
|
3866
|
+
examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
|
|
3867
|
+
});
|
|
3868
|
+
const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
|
|
3869
|
+
const found = detectManager(process21.cwd());
|
|
3870
|
+
const command = commandFor(action, found);
|
|
3871
|
+
if (values.json === true)
|
|
3872
|
+
printJson({ manager: found, action, command });
|
|
3873
|
+
else
|
|
3874
|
+
console.log(command);
|
|
3875
|
+
return 0;
|
|
3876
|
+
}
|
|
3877
|
+
var usage7 = `pkg manager <install|dev|remove|update|exec>
|
|
3878
|
+
|
|
3879
|
+
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.
|
|
3880
|
+
|
|
3881
|
+
Exits 0 when it printed the command, 2 on a usage error.`, options6;
|
|
3882
|
+
var init_manager2 = __esm(() => {
|
|
3883
|
+
init_src();
|
|
3884
|
+
init_manager();
|
|
3885
|
+
options6 = {
|
|
3886
|
+
json: jsonOption("{manager, action, command}")
|
|
3887
|
+
};
|
|
3888
|
+
});
|
|
3889
|
+
|
|
3779
3890
|
// src/cli.ts
|
|
3780
3891
|
init_src();
|
|
3781
|
-
import
|
|
3782
|
-
|
|
3892
|
+
import process22 from "process";
|
|
3893
|
+
process22.exitCode = await runCli({
|
|
3783
3894
|
name: "pkg",
|
|
3784
3895
|
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
3785
3896
|
replaces: "bun add on trust, and a bun info and sleep loop then a bun add per consumer",
|
|
@@ -3790,6 +3901,7 @@ process20.exitCode = await runCli({
|
|
|
3790
3901
|
audit: { summary: "check every package a bun.lock pins, with its known advisories", run: async (args) => (await Promise.resolve().then(() => (init_audit(), exports_audit))).audit(args) },
|
|
3791
3902
|
outdated: { summary: "list the dependencies of this folder that have a newer version safe to take", run: async (args) => (await Promise.resolve().then(() => (init_outdated(), exports_outdated))).outdatedCommand(args) },
|
|
3792
3903
|
bump: { summary: "wait for a release on the registry, then bun add it in every consumer", run: async (args) => (await Promise.resolve().then(() => (init_bump(), exports_bump))).bump(args) },
|
|
3793
|
-
consumers: { summary: "list the folders depending on a package, with the version each asks for", run: async (args) => (await Promise.resolve().then(() => (init_consumers2(), exports_consumers))).consumers(args) }
|
|
3904
|
+
consumers: { summary: "list the folders depending on a package, with the version each asks for", run: async (args) => (await Promise.resolve().then(() => (init_consumers2(), exports_consumers))).consumers(args) },
|
|
3905
|
+
manager: { summary: "the command this folder's package manager runs to install, remove, update or exec", run: async (args) => (await Promise.resolve().then(() => (init_manager2(), exports_manager))).manager(args) }
|
|
3794
3906
|
}
|
|
3795
3907
|
});
|
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.0",
|
|
5
5
|
"description": "pkg: check an npm package before it is added, for a guessed name, a version under two weeks old and install scripts.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"@kaynooo/utils": "3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@kaynooo/cli-kit": "0.
|
|
36
|
+
"@kaynooo/cli-kit": "0.38.2"
|
|
37
37
|
}
|
|
38
38
|
}
|