@kaynooo/cli-pkg 0.13.3 → 0.14.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 +154 -58
- 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
|
@@ -900,6 +900,32 @@ var init_args = __esm(() => {
|
|
|
900
900
|
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
901
901
|
});
|
|
902
902
|
|
|
903
|
+
// ../kit/src/argv.ts
|
|
904
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
905
|
+
import { resolve as resolve3 } from "path";
|
|
906
|
+
import process11 from "process";
|
|
907
|
+
function commandLine() {
|
|
908
|
+
try {
|
|
909
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
910
|
+
} catch {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
function realPath(word) {
|
|
915
|
+
try {
|
|
916
|
+
return realpathSync(resolve3(word));
|
|
917
|
+
} catch {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
922
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
923
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
924
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
925
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
926
|
+
}
|
|
927
|
+
var init_argv = () => {};
|
|
928
|
+
|
|
903
929
|
// ../kit/src/chart.ts
|
|
904
930
|
var init_chart = __esm(() => {
|
|
905
931
|
init_format();
|
|
@@ -910,7 +936,7 @@ var init_chart = __esm(() => {
|
|
|
910
936
|
|
|
911
937
|
// ../kit/src/process.ts
|
|
912
938
|
import { constants } from "os";
|
|
913
|
-
import
|
|
939
|
+
import process12 from "process";
|
|
914
940
|
function exitCodeOf(code, signal) {
|
|
915
941
|
if (code !== null)
|
|
916
942
|
return code;
|
|
@@ -930,7 +956,7 @@ function holdSignals(cleanup) {
|
|
|
930
956
|
},
|
|
931
957
|
release: () => {
|
|
932
958
|
for (const signal of SIGNALS)
|
|
933
|
-
|
|
959
|
+
process12.off(signal, onSignal);
|
|
934
960
|
}
|
|
935
961
|
};
|
|
936
962
|
function onSignal(signal) {
|
|
@@ -943,10 +969,10 @@ function holdSignals(cleanup) {
|
|
|
943
969
|
return;
|
|
944
970
|
held.release();
|
|
945
971
|
cleanup(signal);
|
|
946
|
-
|
|
972
|
+
process12.kill(process12.pid, signal);
|
|
947
973
|
}
|
|
948
974
|
for (const signal of SIGNALS)
|
|
949
|
-
|
|
975
|
+
process12.on(signal, onSignal);
|
|
950
976
|
return held;
|
|
951
977
|
}
|
|
952
978
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -960,7 +986,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
960
986
|
return;
|
|
961
987
|
try {
|
|
962
988
|
if (grouped)
|
|
963
|
-
|
|
989
|
+
process12.kill(-proc.pid, killing);
|
|
964
990
|
else
|
|
965
991
|
proc.kill(killing);
|
|
966
992
|
} catch {}
|
|
@@ -1033,8 +1059,8 @@ var init_process = __esm(() => {
|
|
|
1033
1059
|
});
|
|
1034
1060
|
|
|
1035
1061
|
// ../kit/src/progress.ts
|
|
1036
|
-
import
|
|
1037
|
-
function liveRegion(render, stream =
|
|
1062
|
+
import process13 from "process";
|
|
1063
|
+
function liveRegion(render, stream = process13.stderr, env = process13.env) {
|
|
1038
1064
|
if (!takesControlCodes(stream, env))
|
|
1039
1065
|
return { redraw: () => {
|
|
1040
1066
|
return;
|
|
@@ -1081,11 +1107,11 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1081
1107
|
clear();
|
|
1082
1108
|
restore();
|
|
1083
1109
|
release();
|
|
1084
|
-
|
|
1110
|
+
process13.off("exit", onExit);
|
|
1085
1111
|
signals.release();
|
|
1086
1112
|
}
|
|
1087
1113
|
timer.unref();
|
|
1088
|
-
|
|
1114
|
+
process13.on("exit", onExit);
|
|
1089
1115
|
return {
|
|
1090
1116
|
redraw: draw,
|
|
1091
1117
|
print: (text) => {
|
|
@@ -1124,14 +1150,14 @@ function cutToWidth(line, width) {
|
|
|
1124
1150
|
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1125
1151
|
}
|
|
1126
1152
|
function swallowInput() {
|
|
1127
|
-
const input =
|
|
1153
|
+
const input = process13.stdin;
|
|
1128
1154
|
if (!input.isTTY)
|
|
1129
1155
|
return () => {
|
|
1130
1156
|
return;
|
|
1131
1157
|
};
|
|
1132
1158
|
const onData = (data) => {
|
|
1133
1159
|
if (data.includes(CTRL_C))
|
|
1134
|
-
|
|
1160
|
+
process13.kill(process13.pid, "SIGINT");
|
|
1135
1161
|
};
|
|
1136
1162
|
input.setRawMode(true);
|
|
1137
1163
|
input.on("data", onData);
|
|
@@ -1147,7 +1173,7 @@ function swallowInput() {
|
|
|
1147
1173
|
};
|
|
1148
1174
|
}
|
|
1149
1175
|
function interceptOutput(clear) {
|
|
1150
|
-
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [
|
|
1176
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process13.stdout, "write"], [process13.stderr, "write"]];
|
|
1151
1177
|
const wrapped = targets.map(([target, name]) => {
|
|
1152
1178
|
const original = Reflect.get(target, name);
|
|
1153
1179
|
const wrapper = (...args) => {
|
|
@@ -1203,18 +1229,18 @@ var init_logs = __esm(() => {
|
|
|
1203
1229
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1204
1230
|
import { homedir as homedir3 } from "os";
|
|
1205
1231
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1206
|
-
import
|
|
1232
|
+
import process14 from "process";
|
|
1207
1233
|
function noteUsageError(message) {
|
|
1208
1234
|
usageError = message;
|
|
1209
1235
|
}
|
|
1210
|
-
function stateHome(env =
|
|
1236
|
+
function stateHome(env = process14.env) {
|
|
1211
1237
|
const dir = env.XDG_STATE_HOME;
|
|
1212
1238
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1213
1239
|
}
|
|
1214
|
-
function usagePath(env =
|
|
1240
|
+
function usagePath(env = process14.env) {
|
|
1215
1241
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1216
1242
|
}
|
|
1217
|
-
function usageRecorded(env =
|
|
1243
|
+
function usageRecorded(env = process14.env) {
|
|
1218
1244
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1219
1245
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1220
1246
|
}
|
|
@@ -1228,7 +1254,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1228
1254
|
usageError = undefined;
|
|
1229
1255
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1230
1256
|
}
|
|
1231
|
-
function recordUsage(entry, env =
|
|
1257
|
+
function recordUsage(entry, env = process14.env) {
|
|
1232
1258
|
if (!usageRecorded(env))
|
|
1233
1259
|
return;
|
|
1234
1260
|
try {
|
|
@@ -1246,9 +1272,9 @@ var init_usage = __esm(() => {
|
|
|
1246
1272
|
});
|
|
1247
1273
|
|
|
1248
1274
|
// ../kit/src/cli.ts
|
|
1249
|
-
import { readFileSync as
|
|
1275
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1250
1276
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1251
|
-
import
|
|
1277
|
+
import process15 from "process";
|
|
1252
1278
|
async function commandRows(all, colors) {
|
|
1253
1279
|
const commands = shown(all);
|
|
1254
1280
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1323,8 +1349,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1323
1349
|
`);
|
|
1324
1350
|
}
|
|
1325
1351
|
function printError(prefix, message, hint, cause) {
|
|
1326
|
-
const colors = paint(
|
|
1327
|
-
const styled = takesControlCodes(
|
|
1352
|
+
const colors = paint(process15.stderr);
|
|
1353
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1328
1354
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1329
1355
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1330
1356
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1367,11 +1393,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1367
1393
|
}
|
|
1368
1394
|
}
|
|
1369
1395
|
if (name === undefined && level.path.length > 1) {
|
|
1370
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1396
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1371
1397
|
return 2;
|
|
1372
1398
|
}
|
|
1373
1399
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1374
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1400
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1375
1401
|
return 0;
|
|
1376
1402
|
}
|
|
1377
1403
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1425,24 +1451,24 @@ function candidateLine(candidate) {
|
|
|
1425
1451
|
}
|
|
1426
1452
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1427
1453
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1428
|
-
|
|
1454
|
+
const typed = [];
|
|
1429
1455
|
let at = 0;
|
|
1430
1456
|
while (at < before.length) {
|
|
1431
1457
|
const word = before[at];
|
|
1432
1458
|
if (word === "--") {
|
|
1433
|
-
|
|
1459
|
+
typed.push(...before.slice(at + 1));
|
|
1434
1460
|
break;
|
|
1435
1461
|
}
|
|
1436
1462
|
if (!word.startsWith("-"))
|
|
1437
|
-
|
|
1463
|
+
typed.push(word);
|
|
1438
1464
|
else if (takesValue(word))
|
|
1439
1465
|
at++;
|
|
1440
1466
|
at++;
|
|
1441
1467
|
}
|
|
1442
1468
|
const last = positionals.at(-1);
|
|
1443
|
-
if (
|
|
1444
|
-
return positionals[
|
|
1445
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1469
|
+
if (typed.length < positionals.length)
|
|
1470
|
+
return { name: positionals[typed.length], typed };
|
|
1471
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1446
1472
|
}
|
|
1447
1473
|
async function leafCandidates(run, words) {
|
|
1448
1474
|
const completing = await completingOf(run);
|
|
@@ -1450,12 +1476,12 @@ async function leafCandidates(run, words) {
|
|
|
1450
1476
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1451
1477
|
const flag = words.at(-2);
|
|
1452
1478
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1479
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1453
1480
|
if (option?.type === "string") {
|
|
1454
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1481
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1455
1482
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1456
1483
|
}
|
|
1457
|
-
const
|
|
1458
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1484
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1459
1485
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1460
1486
|
}
|
|
1461
1487
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1486,9 +1512,9 @@ async function printCandidates(found) {
|
|
|
1486
1512
|
return 0;
|
|
1487
1513
|
}
|
|
1488
1514
|
function packageVersion(entry = Bun.main) {
|
|
1489
|
-
for (let dir = dirname3(
|
|
1515
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
1490
1516
|
try {
|
|
1491
|
-
const { version } = JSON.parse(
|
|
1517
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1492
1518
|
if (typeof version === "string")
|
|
1493
1519
|
return version;
|
|
1494
1520
|
} catch {}
|
|
@@ -1496,7 +1522,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1496
1522
|
return "0.0.0";
|
|
1497
1523
|
}
|
|
1498
1524
|
}
|
|
1499
|
-
async function runCli(cli, argv =
|
|
1525
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1500
1526
|
const version = cli.version ?? packageVersion();
|
|
1501
1527
|
if (argv[0] === COMPLETE)
|
|
1502
1528
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1526,6 +1552,7 @@ function commandPath(scope, argv) {
|
|
|
1526
1552
|
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
|
|
1527
1553
|
var init_cli = __esm(() => {
|
|
1528
1554
|
init_args();
|
|
1555
|
+
init_argv();
|
|
1529
1556
|
init_style();
|
|
1530
1557
|
init_text2();
|
|
1531
1558
|
init_usage();
|
|
@@ -1625,8 +1652,8 @@ var init_watch = __esm(() => {
|
|
|
1625
1652
|
|
|
1626
1653
|
// ../kit/src/workspace-root.ts
|
|
1627
1654
|
import { homedir as homedir4 } from "os";
|
|
1628
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1629
|
-
import
|
|
1655
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1656
|
+
import process16 from "process";
|
|
1630
1657
|
function expandHome(path, home) {
|
|
1631
1658
|
if (path === "~")
|
|
1632
1659
|
return home;
|
|
@@ -1636,9 +1663,9 @@ function configured(env, home) {
|
|
|
1636
1663
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1637
1664
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1638
1665
|
}
|
|
1639
|
-
function workspaceRoot({ given, env =
|
|
1666
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1640
1667
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1641
|
-
return
|
|
1668
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1642
1669
|
}
|
|
1643
1670
|
var init_workspace_root = __esm(() => {
|
|
1644
1671
|
init_user_config();
|
|
@@ -1648,6 +1675,7 @@ var init_workspace_root = __esm(() => {
|
|
|
1648
1675
|
var init_src = __esm(() => {
|
|
1649
1676
|
init_advisory();
|
|
1650
1677
|
init_args();
|
|
1678
|
+
init_argv();
|
|
1651
1679
|
init_chart();
|
|
1652
1680
|
init_ci();
|
|
1653
1681
|
init_cli();
|
|
@@ -2397,7 +2425,7 @@ function parseSpec(text) {
|
|
|
2397
2425
|
function isStable(version) {
|
|
2398
2426
|
return !version.includes("-");
|
|
2399
2427
|
}
|
|
2400
|
-
function
|
|
2428
|
+
function resolve5(packument, request) {
|
|
2401
2429
|
const tags = packument["dist-tags"] ?? {};
|
|
2402
2430
|
const versions = Object.keys(packument.versions ?? {});
|
|
2403
2431
|
const wanted = request === undefined || request === "" ? "latest" : request;
|
|
@@ -2442,7 +2470,7 @@ function analyze(input) {
|
|
|
2442
2470
|
return report;
|
|
2443
2471
|
}
|
|
2444
2472
|
const latest = packument["dist-tags"]?.latest;
|
|
2445
|
-
const version =
|
|
2473
|
+
const version = resolve5(packument, spec.request);
|
|
2446
2474
|
const entry = version === undefined ? undefined : packument.versions?.[version];
|
|
2447
2475
|
report.description = packument.description;
|
|
2448
2476
|
report.license = licenseOf(entry?.license) ?? licenseOf(packument.license);
|
|
@@ -2512,7 +2540,7 @@ var init_analyze = __esm(() => {
|
|
|
2512
2540
|
// src/config.ts
|
|
2513
2541
|
import { homedir as homedir5 } from "os";
|
|
2514
2542
|
import { dirname as dirname5, join as join7 } from "path";
|
|
2515
|
-
import
|
|
2543
|
+
import process18 from "process";
|
|
2516
2544
|
function expand2(value, env) {
|
|
2517
2545
|
let missing = false;
|
|
2518
2546
|
const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
|
|
@@ -2601,7 +2629,7 @@ async function readIfThere(path) {
|
|
|
2601
2629
|
const file = Bun.file(path);
|
|
2602
2630
|
return await file.exists() ? file.text() : undefined;
|
|
2603
2631
|
}
|
|
2604
|
-
async function loadConfigs(cwd =
|
|
2632
|
+
async function loadConfigs(cwd = process18.cwd(), env = process18.env, home = homedir5()) {
|
|
2605
2633
|
const directories = [];
|
|
2606
2634
|
for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
|
|
2607
2635
|
directories.push(dir);
|
|
@@ -2634,7 +2662,7 @@ function parseSettings(text) {
|
|
|
2634
2662
|
settings.concurrency = raw.concurrency;
|
|
2635
2663
|
return settings;
|
|
2636
2664
|
}
|
|
2637
|
-
async function loadSettings(cwd =
|
|
2665
|
+
async function loadSettings(cwd = process18.cwd(), home) {
|
|
2638
2666
|
const files = [];
|
|
2639
2667
|
for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
|
|
2640
2668
|
files.push(join7(dir, SETTINGS_FILE));
|
|
@@ -2751,7 +2779,7 @@ var init_pin = __esm(() => {
|
|
|
2751
2779
|
});
|
|
2752
2780
|
|
|
2753
2781
|
// src/consumers.ts
|
|
2754
|
-
import { existsSync as existsSync4, readdirSync, readFileSync as
|
|
2782
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
2755
2783
|
import { dirname as dirname6, join as join8, relative } from "path";
|
|
2756
2784
|
function packageFiles(dir, depth, found, ignored = ignoredFolders()) {
|
|
2757
2785
|
let entries;
|
|
@@ -2779,7 +2807,7 @@ function managerFor(dir, root) {
|
|
|
2779
2807
|
}
|
|
2780
2808
|
function readManifest(path) {
|
|
2781
2809
|
try {
|
|
2782
|
-
return JSON.parse(
|
|
2810
|
+
return JSON.parse(readFileSync5(path, "utf8"));
|
|
2783
2811
|
} catch {
|
|
2784
2812
|
return;
|
|
2785
2813
|
}
|
|
@@ -3022,8 +3050,8 @@ var exports_audit = {};
|
|
|
3022
3050
|
__export(exports_audit, {
|
|
3023
3051
|
audit: () => audit
|
|
3024
3052
|
});
|
|
3025
|
-
import { join as join9, resolve as
|
|
3026
|
-
import
|
|
3053
|
+
import { join as join9, resolve as resolve6 } from "path";
|
|
3054
|
+
import process19 from "process";
|
|
3027
3055
|
function hasFinding(audited) {
|
|
3028
3056
|
return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
|
|
3029
3057
|
}
|
|
@@ -3079,7 +3107,7 @@ async function audit(args) {
|
|
|
3079
3107
|
const level = values.level ?? "moderate";
|
|
3080
3108
|
if (!isSeverity(level))
|
|
3081
3109
|
fail(`--level takes ${SEVERITIES.join(", ")}, not ${level}`);
|
|
3082
|
-
const dir =
|
|
3110
|
+
const dir = resolve6(asked ?? process19.cwd());
|
|
3083
3111
|
const lock = Bun.file(join9(dir, "bun.lock"));
|
|
3084
3112
|
if (!await lock.exists())
|
|
3085
3113
|
fail(`no bun.lock in ${dir}`);
|
|
@@ -3134,7 +3162,7 @@ __export(exports_outdated, {
|
|
|
3134
3162
|
outdatedCommand: () => outdatedCommand
|
|
3135
3163
|
});
|
|
3136
3164
|
import { existsSync as existsSync5 } from "fs";
|
|
3137
|
-
import { join as join10, resolve as
|
|
3165
|
+
import { join as join10, resolve as resolve7 } from "path";
|
|
3138
3166
|
function currentOf(name, spec, locked) {
|
|
3139
3167
|
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
3168
|
const written = FIRST_VERSION.exec(spec)?.[0];
|
|
@@ -3167,7 +3195,7 @@ async function outdated(manifest, context) {
|
|
|
3167
3195
|
}
|
|
3168
3196
|
async function outdatedCommand(args) {
|
|
3169
3197
|
const { values, positionals: [dir = "."] } = parse(args, usage4, options3, { positionals: ["[dir]"], exits: EXITS3 });
|
|
3170
|
-
const folder =
|
|
3198
|
+
const folder = resolve7(dir);
|
|
3171
3199
|
const manifest = Bun.file(join10(folder, "package.json"));
|
|
3172
3200
|
if (!await manifest.exists())
|
|
3173
3201
|
fail(`no package.json in ${folder}`);
|
|
@@ -3274,7 +3302,7 @@ var init_state = __esm(() => {
|
|
|
3274
3302
|
});
|
|
3275
3303
|
|
|
3276
3304
|
// ../kit/src/prompt.ts
|
|
3277
|
-
import
|
|
3305
|
+
import process20 from "process";
|
|
3278
3306
|
function readKeys(input, paste = { active: false }) {
|
|
3279
3307
|
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
3280
3308
|
}
|
|
@@ -3388,7 +3416,7 @@ function asking(colors, question, typed, keys) {
|
|
|
3388
3416
|
function answer(colors, question, state, picked) {
|
|
3389
3417
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
3390
3418
|
}
|
|
3391
|
-
async function ask(question, { hint, terminal =
|
|
3419
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
3392
3420
|
const { stdin, stderr } = terminal;
|
|
3393
3421
|
if (!isInteractive(terminal))
|
|
3394
3422
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -3454,7 +3482,7 @@ var init_prompt = __esm(() => {
|
|
|
3454
3482
|
});
|
|
3455
3483
|
|
|
3456
3484
|
// src/excluded.ts
|
|
3457
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as
|
|
3485
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync } from "fs";
|
|
3458
3486
|
import { dirname as dirname7 } from "path";
|
|
3459
3487
|
function excludedPath(home) {
|
|
3460
3488
|
return userConfigPath("pkg-excluded", { home });
|
|
@@ -3464,7 +3492,7 @@ function loadExcluded(home) {
|
|
|
3464
3492
|
if (!existsSync6(path))
|
|
3465
3493
|
return {};
|
|
3466
3494
|
try {
|
|
3467
|
-
const raw = JSON.parse(
|
|
3495
|
+
const raw = JSON.parse(readFileSync6(path, "utf8"));
|
|
3468
3496
|
const excluded = {};
|
|
3469
3497
|
for (const [name, dirs] of Object.entries(raw)) {
|
|
3470
3498
|
if (Array.isArray(dirs))
|
|
@@ -3776,10 +3804,77 @@ var init_consumers2 = __esm(() => {
|
|
|
3776
3804
|
};
|
|
3777
3805
|
});
|
|
3778
3806
|
|
|
3807
|
+
// src/manager.ts
|
|
3808
|
+
import { existsSync as existsSync8 } from "fs";
|
|
3809
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
3810
|
+
function detectManager(from) {
|
|
3811
|
+
let dir = from;
|
|
3812
|
+
while (true) {
|
|
3813
|
+
const found = LOCKFILES2.find(([file]) => existsSync8(join12(dir, file)));
|
|
3814
|
+
if (found !== undefined)
|
|
3815
|
+
return found[1];
|
|
3816
|
+
const parent = dirname9(dir);
|
|
3817
|
+
if (parent === dir)
|
|
3818
|
+
return "bun";
|
|
3819
|
+
dir = parent;
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
function commandFor(action, manager) {
|
|
3823
|
+
const { fallback, ...own } = COMMANDS[action];
|
|
3824
|
+
return own[manager] ?? fallback(manager);
|
|
3825
|
+
}
|
|
3826
|
+
var ACTIONS2, LOCKFILES2, COMMANDS;
|
|
3827
|
+
var init_manager = __esm(() => {
|
|
3828
|
+
ACTIONS2 = ["install", "dev", "remove", "update", "exec"];
|
|
3829
|
+
LOCKFILES2 = [["bun.lock", "bun"], ["bun.lockb", "bun"], ["yarn.lock", "yarn"], ["pnpm-lock.yaml", "pnpm"], ["package-lock.json", "npm"], ["composer.json", "composer"], ["uv.lock", "uv"]];
|
|
3830
|
+
COMMANDS = {
|
|
3831
|
+
install: { yarn: "yarn add", uv: "uv sync", fallback: (manager) => `${manager} install` },
|
|
3832
|
+
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" },
|
|
3833
|
+
remove: { npm: "npm uninstall", fallback: (manager) => `${manager} remove` },
|
|
3834
|
+
update: { yarn: "yarn upgrade", uv: "uv lock --upgrade", fallback: (manager) => `${manager} update` },
|
|
3835
|
+
exec: { bun: "bunx", pnpm: "pnpm dlx", yarn: "yarn dlx", composer: "composer exec", uv: "uvx", fallback: () => "npx" }
|
|
3836
|
+
};
|
|
3837
|
+
});
|
|
3838
|
+
|
|
3839
|
+
// src/commands/manager.ts
|
|
3840
|
+
var exports_manager = {};
|
|
3841
|
+
__export(exports_manager, {
|
|
3842
|
+
manager: () => manager
|
|
3843
|
+
});
|
|
3844
|
+
import process21 from "process";
|
|
3845
|
+
function manager(args) {
|
|
3846
|
+
const { values, positionals } = parse(args, usage7, options6, {
|
|
3847
|
+
positionals: ["<action>"],
|
|
3848
|
+
candidates: { "<action>": () => [...ACTIONS2] },
|
|
3849
|
+
replaces: "telling bun, yarn, pnpm, npm, composer and uv apart by their lockfile before typing an add, remove or dlx",
|
|
3850
|
+
examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
|
|
3851
|
+
});
|
|
3852
|
+
const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
|
|
3853
|
+
const found = detectManager(process21.cwd());
|
|
3854
|
+
const command = commandFor(action, found);
|
|
3855
|
+
if (values.json === true)
|
|
3856
|
+
printJson({ manager: found, action, command });
|
|
3857
|
+
else
|
|
3858
|
+
console.log(command);
|
|
3859
|
+
return 0;
|
|
3860
|
+
}
|
|
3861
|
+
var usage7 = `pkg manager <install|dev|remove|update|exec>
|
|
3862
|
+
|
|
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;
|
|
3866
|
+
var init_manager2 = __esm(() => {
|
|
3867
|
+
init_src();
|
|
3868
|
+
init_manager();
|
|
3869
|
+
options6 = {
|
|
3870
|
+
json: jsonOption("{manager, action, command}")
|
|
3871
|
+
};
|
|
3872
|
+
});
|
|
3873
|
+
|
|
3779
3874
|
// src/cli.ts
|
|
3780
3875
|
init_src();
|
|
3781
|
-
import
|
|
3782
|
-
|
|
3876
|
+
import process22 from "process";
|
|
3877
|
+
process22.exitCode = await runCli({
|
|
3783
3878
|
name: "pkg",
|
|
3784
3879
|
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
3785
3880
|
replaces: "bun add on trust, and a bun info and sleep loop then a bun add per consumer",
|
|
@@ -3790,6 +3885,7 @@ process20.exitCode = await runCli({
|
|
|
3790
3885
|
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
3886
|
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
3887
|
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) }
|
|
3888
|
+
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) },
|
|
3889
|
+
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
3890
|
}
|
|
3795
3891
|
});
|
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.14.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.1"
|
|
37
37
|
}
|
|
38
38
|
}
|