@kaynooo/cli-pkg 0.15.1 → 0.16.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 +389 -59
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -591,33 +591,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
591
591
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
592
592
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
593
593
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
594
|
-
const
|
|
594
|
+
const choices = option.choices?.join("|");
|
|
595
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
596
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
595
597
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
596
598
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
597
|
-
|
|
599
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
600
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
598
601
|
});
|
|
599
602
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
600
603
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
601
604
|
}
|
|
602
|
-
var OPTIONAL, USAGE_PREFIX, FULL_STOP;
|
|
605
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
|
|
603
606
|
var init_help = __esm(() => {
|
|
604
607
|
init_mode();
|
|
605
608
|
init_style();
|
|
606
|
-
OPTIONAL =
|
|
609
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
607
610
|
USAGE_PREFIX = /^usage:\s*/i;
|
|
608
611
|
FULL_STOP = /\.$/;
|
|
609
612
|
});
|
|
610
613
|
|
|
611
614
|
// ../kit/src/text.ts
|
|
612
615
|
function distance(a, b) {
|
|
613
|
-
|
|
614
|
-
|
|
616
|
+
const left = [...a];
|
|
617
|
+
const right = [...b];
|
|
618
|
+
let before = [];
|
|
619
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
620
|
+
for (const [i, x] of left.entries()) {
|
|
615
621
|
const current = [i + 1];
|
|
616
|
-
for (const [j,
|
|
617
|
-
|
|
622
|
+
for (const [j, y] of right.entries()) {
|
|
623
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
624
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
625
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
626
|
+
current.push(cost);
|
|
627
|
+
}
|
|
628
|
+
before = previous;
|
|
618
629
|
previous = current;
|
|
619
630
|
}
|
|
620
|
-
return previous[
|
|
631
|
+
return previous[right.length] ?? 0;
|
|
621
632
|
}
|
|
622
633
|
function closest(name, names) {
|
|
623
634
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -626,10 +637,7 @@ function closest(name, names) {
|
|
|
626
637
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
627
638
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
628
639
|
}
|
|
629
|
-
var
|
|
630
|
-
var init_text2 = __esm(() => {
|
|
631
|
-
ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
632
|
-
});
|
|
640
|
+
var init_text2 = () => {};
|
|
633
641
|
|
|
634
642
|
// ../kit/src/input.ts
|
|
635
643
|
import { fstatSync } from "fs";
|
|
@@ -894,7 +902,7 @@ var init_args = __esm(() => {
|
|
|
894
902
|
};
|
|
895
903
|
completion = { active: false };
|
|
896
904
|
OUTPUT_OPTIONS = {
|
|
897
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
905
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
898
906
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
899
907
|
};
|
|
900
908
|
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
@@ -1219,6 +1227,87 @@ var init_ci = __esm(() => {
|
|
|
1219
1227
|
init_tool();
|
|
1220
1228
|
});
|
|
1221
1229
|
|
|
1230
|
+
// ../kit/src/completions.ts
|
|
1231
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1232
|
+
if (shell === "fish")
|
|
1233
|
+
return `${header}
|
|
1234
|
+
${FISH_FUNCTION}
|
|
1235
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1236
|
+
`).join("")}`;
|
|
1237
|
+
if (shell === "bash")
|
|
1238
|
+
return `${header}
|
|
1239
|
+
${BASH_FUNCTION}
|
|
1240
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1241
|
+
`;
|
|
1242
|
+
return `${header}
|
|
1243
|
+
${ZSH_FUNCTION}
|
|
1244
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1245
|
+
`;
|
|
1246
|
+
}
|
|
1247
|
+
var COMPLETION_SHELLS, FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1248
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1249
|
+
set -l current (commandline -ct)
|
|
1250
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1251
|
+
if test "$line" = __files__
|
|
1252
|
+
__fish_complete_path $current
|
|
1253
|
+
else
|
|
1254
|
+
echo $line
|
|
1255
|
+
end
|
|
1256
|
+
end
|
|
1257
|
+
end`, BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1258
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1259
|
+
local -a lines
|
|
1260
|
+
COMPREPLY=()
|
|
1261
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1262
|
+
for line in "\${lines[@]}"; do
|
|
1263
|
+
if [[ $line == __files__ ]]; then
|
|
1264
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1265
|
+
else
|
|
1266
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1267
|
+
fi
|
|
1268
|
+
done
|
|
1269
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1270
|
+
}`, ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1271
|
+
local line
|
|
1272
|
+
local -a described plain
|
|
1273
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1274
|
+
if [[ $line == __files__ ]]; then
|
|
1275
|
+
_files
|
|
1276
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1277
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1278
|
+
else
|
|
1279
|
+
plain+=("$line")
|
|
1280
|
+
fi
|
|
1281
|
+
done
|
|
1282
|
+
(( \${#described} )) && _describe -V value described
|
|
1283
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1284
|
+
return 0
|
|
1285
|
+
}`;
|
|
1286
|
+
var init_completions = __esm(() => {
|
|
1287
|
+
COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1288
|
+
});
|
|
1289
|
+
|
|
1290
|
+
// ../kit/src/notify.ts
|
|
1291
|
+
import process14 from "process";
|
|
1292
|
+
function base64(text) {
|
|
1293
|
+
return Buffer.from(text).toString("base64");
|
|
1294
|
+
}
|
|
1295
|
+
function notification(title, body, env = process14.env) {
|
|
1296
|
+
const id = `kit${process14.pid}`;
|
|
1297
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1298
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1299
|
+
}
|
|
1300
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1301
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1302
|
+
return;
|
|
1303
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1304
|
+
}
|
|
1305
|
+
var NOTIFY_AFTER_MS = 1e4, CANCELLED = 130;
|
|
1306
|
+
var init_notify = __esm(() => {
|
|
1307
|
+
init_format();
|
|
1308
|
+
init_mode();
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1222
1311
|
// ../kit/src/logs.ts
|
|
1223
1312
|
var DAY_MS, CLI_FOLDER = "kaynooo-cli";
|
|
1224
1313
|
var init_logs = __esm(() => {
|
|
@@ -1229,18 +1318,18 @@ var init_logs = __esm(() => {
|
|
|
1229
1318
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1230
1319
|
import { homedir as homedir3 } from "os";
|
|
1231
1320
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1232
|
-
import
|
|
1321
|
+
import process15 from "process";
|
|
1233
1322
|
function noteUsageError(message) {
|
|
1234
1323
|
usageError = message;
|
|
1235
1324
|
}
|
|
1236
|
-
function stateHome(env =
|
|
1325
|
+
function stateHome(env = process15.env) {
|
|
1237
1326
|
const dir = env.XDG_STATE_HOME;
|
|
1238
1327
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1239
1328
|
}
|
|
1240
|
-
function usagePath(env =
|
|
1329
|
+
function usagePath(env = process15.env) {
|
|
1241
1330
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1242
1331
|
}
|
|
1243
|
-
function usageRecorded(env =
|
|
1332
|
+
function usageRecorded(env = process15.env) {
|
|
1244
1333
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1245
1334
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1246
1335
|
}
|
|
@@ -1254,7 +1343,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1254
1343
|
usageError = undefined;
|
|
1255
1344
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1256
1345
|
}
|
|
1257
|
-
function recordUsage(entry, env =
|
|
1346
|
+
function recordUsage(entry, env = process15.env) {
|
|
1258
1347
|
if (!usageRecorded(env))
|
|
1259
1348
|
return;
|
|
1260
1349
|
try {
|
|
@@ -1274,7 +1363,7 @@ var init_usage = __esm(() => {
|
|
|
1274
1363
|
// ../kit/src/cli.ts
|
|
1275
1364
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1276
1365
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1277
|
-
import
|
|
1366
|
+
import process16 from "process";
|
|
1278
1367
|
async function commandRows(all, colors) {
|
|
1279
1368
|
const commands = shown(all);
|
|
1280
1369
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1348,8 +1437,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1348
1437
|
`);
|
|
1349
1438
|
}
|
|
1350
1439
|
function printError(prefix, message, hint, cause) {
|
|
1351
|
-
const colors = paint(
|
|
1352
|
-
const styled = takesControlCodes(
|
|
1440
|
+
const colors = paint(process16.stderr);
|
|
1441
|
+
const styled = takesControlCodes(process16.stderr);
|
|
1353
1442
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1354
1443
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1355
1444
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1392,11 +1481,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1392
1481
|
}
|
|
1393
1482
|
}
|
|
1394
1483
|
if (name === undefined && level.path.length > 1) {
|
|
1395
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1484
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stderr));
|
|
1396
1485
|
return 2;
|
|
1397
1486
|
}
|
|
1398
1487
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1399
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1488
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stdout));
|
|
1400
1489
|
return 0;
|
|
1401
1490
|
}
|
|
1402
1491
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1505,6 +1594,18 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1505
1594
|
}
|
|
1506
1595
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1507
1596
|
}
|
|
1597
|
+
function flagValue([flag = "", ...rest]) {
|
|
1598
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1599
|
+
}
|
|
1600
|
+
function printCompletionScript(name, args) {
|
|
1601
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1602
|
+
if (shell === undefined || args.length !== 1) {
|
|
1603
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1604
|
+
return 2;
|
|
1605
|
+
}
|
|
1606
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1607
|
+
return 0;
|
|
1608
|
+
}
|
|
1508
1609
|
async function printCandidates(found) {
|
|
1509
1610
|
for (const line of await found)
|
|
1510
1611
|
console.log(line);
|
|
@@ -1529,10 +1630,15 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1529
1630
|
const version = cli.version ?? packageVersion();
|
|
1530
1631
|
if (argv[0] === COMPLETE)
|
|
1531
1632
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1633
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1634
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1635
|
+
const started = performance.now();
|
|
1532
1636
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1637
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1638
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1533
1639
|
if (cli.usage !== false) {
|
|
1534
1640
|
try {
|
|
1535
|
-
recordUsage(usageEntry(cli.name,
|
|
1641
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1536
1642
|
} catch {}
|
|
1537
1643
|
}
|
|
1538
1644
|
return code;
|
|
@@ -1552,10 +1658,12 @@ function commandPath(scope, argv) {
|
|
|
1552
1658
|
}
|
|
1553
1659
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1554
1660
|
}
|
|
1555
|
-
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
|
|
1661
|
+
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__", COMPLETIONS = "--completions";
|
|
1556
1662
|
var init_cli = __esm(() => {
|
|
1557
1663
|
init_args();
|
|
1558
1664
|
init_argv();
|
|
1665
|
+
init_completions();
|
|
1666
|
+
init_notify();
|
|
1559
1667
|
init_style();
|
|
1560
1668
|
init_text2();
|
|
1561
1669
|
init_usage();
|
|
@@ -1563,8 +1671,17 @@ var init_cli = __esm(() => {
|
|
|
1563
1671
|
...OUTPUT_OPTIONS,
|
|
1564
1672
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1565
1673
|
};
|
|
1566
|
-
TOP_OPTIONS = {
|
|
1674
|
+
TOP_OPTIONS = {
|
|
1675
|
+
...LEVEL_OPTIONS,
|
|
1676
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1677
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1678
|
+
};
|
|
1679
|
+
});
|
|
1680
|
+
// ../kit/src/excerpt.ts
|
|
1681
|
+
var init_excerpt = __esm(() => {
|
|
1682
|
+
init_text2();
|
|
1567
1683
|
});
|
|
1684
|
+
|
|
1568
1685
|
// ../kit/src/folders.ts
|
|
1569
1686
|
function ignoredFolders(extra = [], where = {}) {
|
|
1570
1687
|
const configured = readUserConfig("config", where).ignore;
|
|
@@ -1656,7 +1773,7 @@ var init_watch = __esm(() => {
|
|
|
1656
1773
|
// ../kit/src/workspace-root.ts
|
|
1657
1774
|
import { homedir as homedir4 } from "os";
|
|
1658
1775
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1659
|
-
import
|
|
1776
|
+
import process17 from "process";
|
|
1660
1777
|
function expandHome(path, home) {
|
|
1661
1778
|
if (path === "~")
|
|
1662
1779
|
return home;
|
|
@@ -1666,7 +1783,7 @@ function configured(env, home) {
|
|
|
1666
1783
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1667
1784
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1668
1785
|
}
|
|
1669
|
-
function workspaceRoot({ given, env =
|
|
1786
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1670
1787
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1671
1788
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1672
1789
|
}
|
|
@@ -1676,12 +1793,14 @@ var init_workspace_root = __esm(() => {
|
|
|
1676
1793
|
|
|
1677
1794
|
// ../kit/src/index.ts
|
|
1678
1795
|
var init_src = __esm(() => {
|
|
1796
|
+
init_excerpt();
|
|
1679
1797
|
init_advisory();
|
|
1680
1798
|
init_args();
|
|
1681
1799
|
init_argv();
|
|
1682
1800
|
init_chart();
|
|
1683
1801
|
init_ci();
|
|
1684
1802
|
init_cli();
|
|
1803
|
+
init_completions();
|
|
1685
1804
|
init_config();
|
|
1686
1805
|
init_folders();
|
|
1687
1806
|
init_format();
|
|
@@ -2462,6 +2581,24 @@ function safeRelease(packument, now, minAgeDays) {
|
|
|
2462
2581
|
const version = old.sort(Bun.semver.order).at(-1);
|
|
2463
2582
|
return version === undefined ? undefined : { version, published: packument.time?.[version] };
|
|
2464
2583
|
}
|
|
2584
|
+
function previousRelease(packument, version) {
|
|
2585
|
+
const below = Object.keys(packument.versions ?? {}).filter((each) => (isStable(each) || !isStable(version)) && Bun.semver.order(each, version) < 0).sort(Bun.semver.order).at(-1);
|
|
2586
|
+
return below === undefined ? undefined : packument.versions?.[below];
|
|
2587
|
+
}
|
|
2588
|
+
function publisherWarnings(packument, version) {
|
|
2589
|
+
const current = packument.versions?.[version];
|
|
2590
|
+
const previous = previousRelease(packument, version);
|
|
2591
|
+
const warnings = [];
|
|
2592
|
+
if (current === undefined || previous === undefined)
|
|
2593
|
+
return warnings;
|
|
2594
|
+
const by = current._npmUser?.name;
|
|
2595
|
+
const before = previous._npmUser?.name;
|
|
2596
|
+
if (by !== undefined && before !== undefined && by !== before)
|
|
2597
|
+
warnings.push(`${version} was published by ${by}, ${previous.version} by ${before}`);
|
|
2598
|
+
if (previous.dist?.attestations !== undefined && current.dist?.attestations === undefined)
|
|
2599
|
+
warnings.push(`${version} has no provenance attestation, ${previous.version} had one`);
|
|
2600
|
+
return warnings;
|
|
2601
|
+
}
|
|
2465
2602
|
function analyze(input) {
|
|
2466
2603
|
const { spec, packument, registry, now = Date.now(), minAgeDays = DEFAULT_MIN_AGE_DAYS } = input;
|
|
2467
2604
|
const report = { name: spec.name, registry, exists: packument !== undefined, requested: spec.request, installScripts: {}, nearMisses: nearMisses(spec.name), advisories: input.advisories ?? [], fixes: [], warnings: [], blocked: false, downloads: input.downloads };
|
|
@@ -2507,6 +2644,7 @@ function analyze(input) {
|
|
|
2507
2644
|
report.warnings.push(`${version} runs ${scripts.join(", ")} at install`);
|
|
2508
2645
|
if (report.deprecated !== undefined)
|
|
2509
2646
|
report.warnings.push(`${version} is deprecated: ${report.deprecated}`);
|
|
2647
|
+
report.warnings.push(...publisherWarnings(packument, version));
|
|
2510
2648
|
if (input.licenses !== undefined) {
|
|
2511
2649
|
const isMissing = report.license === undefined || report.license === "";
|
|
2512
2650
|
if (isMissing) {
|
|
@@ -2543,7 +2681,7 @@ var init_analyze = __esm(() => {
|
|
|
2543
2681
|
// src/config.ts
|
|
2544
2682
|
import { homedir as homedir5 } from "os";
|
|
2545
2683
|
import { dirname as dirname5, join as join7 } from "path";
|
|
2546
|
-
import
|
|
2684
|
+
import process19 from "process";
|
|
2547
2685
|
function expand2(value, env) {
|
|
2548
2686
|
let missing = false;
|
|
2549
2687
|
const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
|
|
@@ -2632,7 +2770,7 @@ async function readIfThere(path) {
|
|
|
2632
2770
|
const file = Bun.file(path);
|
|
2633
2771
|
return await file.exists() ? file.text() : undefined;
|
|
2634
2772
|
}
|
|
2635
|
-
async function loadConfigs(cwd =
|
|
2773
|
+
async function loadConfigs(cwd = process19.cwd(), env = process19.env, home = homedir5()) {
|
|
2636
2774
|
const directories = [];
|
|
2637
2775
|
for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
|
|
2638
2776
|
directories.push(dir);
|
|
@@ -2665,7 +2803,7 @@ function parseSettings(text) {
|
|
|
2665
2803
|
settings.concurrency = raw.concurrency;
|
|
2666
2804
|
return settings;
|
|
2667
2805
|
}
|
|
2668
|
-
async function loadSettings(cwd =
|
|
2806
|
+
async function loadSettings(cwd = process19.cwd(), home) {
|
|
2669
2807
|
const files = [];
|
|
2670
2808
|
for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
|
|
2671
2809
|
files.push(join7(dir, SETTINGS_FILE));
|
|
@@ -2964,7 +3102,7 @@ ${usage2}` : `${values.from} has no registry dependency to check`);
|
|
|
2964
3102
|
}
|
|
2965
3103
|
var usage2 = `pkg [check] <name>[@version]... | --from <package.json> | -
|
|
2966
3104
|
|
|
2967
|
-
Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts
|
|
3105
|
+
Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts, a near miss of a popular name, and a warning when the version's publisher differs from the previous release's or its provenance attestation is gone.
|
|
2968
3106
|
|
|
2969
3107
|
Names come from the arguments, from the dependencies of a package.json with --from (each checked as \`name@range\`, so it resolves what an install would; dev and optional ones included, peer ranges and local or remote sources left out), or from stdin, separated by spaces or lines, when \`-\` is given or nothing else is and stdin is piped.
|
|
2970
3108
|
|
|
@@ -3056,7 +3194,7 @@ __export(exports_audit, {
|
|
|
3056
3194
|
audit: () => audit
|
|
3057
3195
|
});
|
|
3058
3196
|
import { join as join9, resolve as resolve6 } from "path";
|
|
3059
|
-
import
|
|
3197
|
+
import process20 from "process";
|
|
3060
3198
|
function hasFinding(audited) {
|
|
3061
3199
|
return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
|
|
3062
3200
|
}
|
|
@@ -3096,7 +3234,7 @@ async function auditPackages(packages, context) {
|
|
|
3096
3234
|
});
|
|
3097
3235
|
return { audited, unavailable };
|
|
3098
3236
|
}
|
|
3099
|
-
function renderAudit(findings, total, stream =
|
|
3237
|
+
function renderAudit(findings, total, stream = process20.stdout, env = process20.env) {
|
|
3100
3238
|
const id = role("id", stream, env);
|
|
3101
3239
|
const label = role("label", stream, env);
|
|
3102
3240
|
const warning = role("warn", stream, env);
|
|
@@ -3114,10 +3252,8 @@ function renderAudit(findings, total, stream = process19.stdout, env = process19
|
|
|
3114
3252
|
}
|
|
3115
3253
|
async function audit(args) {
|
|
3116
3254
|
const { values, positionals: [asked] } = parse(args, usage3, options2, { positionals: ["[dir]"], exits: EXITS2 });
|
|
3117
|
-
const level = values
|
|
3118
|
-
|
|
3119
|
-
fail(`--level takes ${SEVERITIES.join(", ")}, not ${level}`);
|
|
3120
|
-
const dir = resolve6(asked ?? process19.cwd());
|
|
3255
|
+
const { level } = values;
|
|
3256
|
+
const dir = resolve6(asked ?? process20.cwd());
|
|
3121
3257
|
const lock = Bun.file(join9(dir, "bun.lock"));
|
|
3122
3258
|
if (!await lock.exists())
|
|
3123
3259
|
fail(`no bun.lock in ${dir}`);
|
|
@@ -3146,7 +3282,7 @@ async function audit(args) {
|
|
|
3146
3282
|
}
|
|
3147
3283
|
var usage3 = `pkg audit [dir]
|
|
3148
3284
|
|
|
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.
|
|
3285
|
+
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 changed publisher or lost attestation, 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.
|
|
3150
3286
|
Findings are grouped per package, each registry package looked up once per run.
|
|
3151
3287
|
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;
|
|
3152
3288
|
var init_audit = __esm(() => {
|
|
@@ -3160,7 +3296,7 @@ var init_audit = __esm(() => {
|
|
|
3160
3296
|
options2 = {
|
|
3161
3297
|
json: jsonOption("[{name, version, license, blocked, warnings, advisories}] for the packages with a finding"),
|
|
3162
3298
|
"min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
|
|
3163
|
-
level: { type: "string", description: "lowest advisory severity listed and failing
|
|
3299
|
+
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "lowest advisory severity listed and failing (moderate)" },
|
|
3164
3300
|
prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
|
|
3165
3301
|
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
|
|
3166
3302
|
};
|
|
@@ -3245,6 +3381,134 @@ var init_outdated = __esm(() => {
|
|
|
3245
3381
|
};
|
|
3246
3382
|
});
|
|
3247
3383
|
|
|
3384
|
+
// ../kit/src/answers.ts
|
|
3385
|
+
var init_answers = __esm(() => {
|
|
3386
|
+
init_folders();
|
|
3387
|
+
});
|
|
3388
|
+
|
|
3389
|
+
// ../kit/src/job.ts
|
|
3390
|
+
import process21 from "process";
|
|
3391
|
+
function stopJob() {
|
|
3392
|
+
process21.kill(0, "SIGTSTP");
|
|
3393
|
+
}
|
|
3394
|
+
var init_job = () => {};
|
|
3395
|
+
|
|
3396
|
+
// ../kit/src/picker/line.ts
|
|
3397
|
+
function isEditKey(key) {
|
|
3398
|
+
return EDIT_KEYS.has(key);
|
|
3399
|
+
}
|
|
3400
|
+
function endsKills(key) {
|
|
3401
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
3402
|
+
}
|
|
3403
|
+
function isWord(char) {
|
|
3404
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
3405
|
+
}
|
|
3406
|
+
function wordStart(chars, from) {
|
|
3407
|
+
let at = from;
|
|
3408
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
3409
|
+
at--;
|
|
3410
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
3411
|
+
at--;
|
|
3412
|
+
return at;
|
|
3413
|
+
}
|
|
3414
|
+
function wordEnd(chars, from) {
|
|
3415
|
+
let at = from;
|
|
3416
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
3417
|
+
at++;
|
|
3418
|
+
while (at < chars.length && isWord(chars[at]))
|
|
3419
|
+
at++;
|
|
3420
|
+
return at;
|
|
3421
|
+
}
|
|
3422
|
+
function spacedStart(chars, from) {
|
|
3423
|
+
let at = from;
|
|
3424
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
3425
|
+
at--;
|
|
3426
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
3427
|
+
at--;
|
|
3428
|
+
return at;
|
|
3429
|
+
}
|
|
3430
|
+
function cut(chars, from, to) {
|
|
3431
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
3432
|
+
}
|
|
3433
|
+
function insert(chars, at, text) {
|
|
3434
|
+
const typed = [...text];
|
|
3435
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
3436
|
+
}
|
|
3437
|
+
function editLine(line, key) {
|
|
3438
|
+
const { killed = "", chained = false } = line;
|
|
3439
|
+
const chars = [...line.text];
|
|
3440
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
3441
|
+
const edited = edit(chars, at, key, killed);
|
|
3442
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
3443
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
3444
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
3445
|
+
if (taken === "")
|
|
3446
|
+
return { ...edited, killed, chained };
|
|
3447
|
+
if (!chained)
|
|
3448
|
+
return { ...edited, killed: taken, chained: true };
|
|
3449
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
3450
|
+
}
|
|
3451
|
+
function edit(chars, at, key, killed) {
|
|
3452
|
+
const text = chars.join("");
|
|
3453
|
+
if (typeof key === "object")
|
|
3454
|
+
return insert(chars, at, key.text);
|
|
3455
|
+
switch (key) {
|
|
3456
|
+
case "left":
|
|
3457
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
3458
|
+
case "right":
|
|
3459
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
3460
|
+
case "wordleft":
|
|
3461
|
+
return { text, caret: wordStart(chars, at) };
|
|
3462
|
+
case "wordright":
|
|
3463
|
+
return { text, caret: wordEnd(chars, at) };
|
|
3464
|
+
case "linestart":
|
|
3465
|
+
return { text, caret: 0 };
|
|
3466
|
+
case "lineend":
|
|
3467
|
+
return { text, caret: chars.length };
|
|
3468
|
+
case "erase":
|
|
3469
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
3470
|
+
case "delete":
|
|
3471
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
3472
|
+
case "word":
|
|
3473
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
3474
|
+
case "killword":
|
|
3475
|
+
return cut(chars, wordStart(chars, at), at);
|
|
3476
|
+
case "killnext":
|
|
3477
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
3478
|
+
case "clear":
|
|
3479
|
+
return cut(chars, 0, at);
|
|
3480
|
+
case "killend":
|
|
3481
|
+
return cut(chars, at, chars.length);
|
|
3482
|
+
case "yank":
|
|
3483
|
+
return insert(chars, at, killed);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
function visible({ text, caret }, room) {
|
|
3487
|
+
const chars = [...text];
|
|
3488
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
3489
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
3490
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
3491
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
3492
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
3493
|
+
let start = at;
|
|
3494
|
+
let end = at + 1;
|
|
3495
|
+
while (start > 0 && fits(start - 1, end))
|
|
3496
|
+
start--;
|
|
3497
|
+
while (end < cells.length && fits(start, end + 1))
|
|
3498
|
+
end++;
|
|
3499
|
+
const left = start > 0 ? "\u2026" : "";
|
|
3500
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
3501
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
3502
|
+
}
|
|
3503
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
3504
|
+
var init_line = __esm(() => {
|
|
3505
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
3506
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
3507
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
3508
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
3509
|
+
SPACE = /\s/;
|
|
3510
|
+
});
|
|
3511
|
+
|
|
3248
3512
|
// ../kit/src/picker/score.ts
|
|
3249
3513
|
var BOUNDARY_AFTER, NONE;
|
|
3250
3514
|
var init_score = __esm(() => {
|
|
@@ -3278,6 +3542,8 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
3278
3542
|
}
|
|
3279
3543
|
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
3280
3544
|
var init_state = __esm(() => {
|
|
3545
|
+
init_text2();
|
|
3546
|
+
init_line();
|
|
3281
3547
|
init_score();
|
|
3282
3548
|
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
3283
3549
|
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
@@ -3301,10 +3567,29 @@ var init_state = __esm(() => {
|
|
|
3301
3567
|
"\n": "enter",
|
|
3302
3568
|
"\x03": "cancel",
|
|
3303
3569
|
"\x1B": "cancel",
|
|
3570
|
+
"\x1B[D": "left",
|
|
3571
|
+
"\x1BOD": "left",
|
|
3572
|
+
"\x1B[C": "right",
|
|
3573
|
+
"\x1BOC": "right",
|
|
3574
|
+
"\x1B[1;5D": "wordleft",
|
|
3575
|
+
"\x1B[1;3D": "wordleft",
|
|
3576
|
+
"\x1Bb": "wordleft",
|
|
3577
|
+
"\x1B[1;5C": "wordright",
|
|
3578
|
+
"\x1B[1;3C": "wordright",
|
|
3579
|
+
"\x1Bf": "wordright",
|
|
3580
|
+
"\x01": "linestart",
|
|
3581
|
+
"\x05": "lineend",
|
|
3304
3582
|
"\x7F": "erase",
|
|
3305
|
-
"\
|
|
3583
|
+
"\x1B[3~": "delete",
|
|
3584
|
+
"\b": "killword",
|
|
3585
|
+
"\x1B\x7F": "killword",
|
|
3586
|
+
"\x1B[3;5~": "killnext",
|
|
3587
|
+
"\x1Bd": "killnext",
|
|
3306
3588
|
"\x15": "clear",
|
|
3589
|
+
"\v": "killend",
|
|
3307
3590
|
"\x17": "word",
|
|
3591
|
+
"\x19": "yank",
|
|
3592
|
+
"\x1A": "suspend",
|
|
3308
3593
|
"\t": "tab",
|
|
3309
3594
|
"\x1F": "help",
|
|
3310
3595
|
"\x1BOP": "help",
|
|
@@ -3312,10 +3597,31 @@ var init_state = __esm(() => {
|
|
|
3312
3597
|
};
|
|
3313
3598
|
});
|
|
3314
3599
|
|
|
3600
|
+
// ../kit/src/redraw.ts
|
|
3601
|
+
function overwrite(lines, columns) {
|
|
3602
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
3603
|
+
`);
|
|
3604
|
+
}
|
|
3605
|
+
function rowsTaken(lines, columns) {
|
|
3606
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
3607
|
+
}
|
|
3608
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
3609
|
+
var init_redraw = __esm(() => {
|
|
3610
|
+
init_format();
|
|
3611
|
+
});
|
|
3612
|
+
|
|
3315
3613
|
// ../kit/src/prompt.ts
|
|
3316
|
-
import
|
|
3614
|
+
import process22 from "process";
|
|
3317
3615
|
function readKeys(input, paste = { active: false }) {
|
|
3318
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
3616
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
3617
|
+
}
|
|
3618
|
+
function roomAfter(question, columns) {
|
|
3619
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
3620
|
+
}
|
|
3621
|
+
function withCaret(colors, line, room, dim = false) {
|
|
3622
|
+
const { before, at, after } = visible(line, room);
|
|
3623
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
3624
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
3319
3625
|
}
|
|
3320
3626
|
function flip(checked, value) {
|
|
3321
3627
|
const next = new Set(checked);
|
|
@@ -3327,7 +3633,7 @@ async function checklist(question, choices, { initial = new Set, min = 0, toggle
|
|
|
3327
3633
|
const list = new List(choices, 0);
|
|
3328
3634
|
let checked = initial;
|
|
3329
3635
|
let invalid;
|
|
3330
|
-
const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.
|
|
3636
|
+
const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.typed(colors, rows.columns, question), "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) => {
|
|
3331
3637
|
if (key === "cancel")
|
|
3332
3638
|
return key;
|
|
3333
3639
|
invalid = undefined;
|
|
@@ -3365,7 +3671,7 @@ async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
|
3365
3671
|
|
|
3366
3672
|
class List {
|
|
3367
3673
|
choices;
|
|
3368
|
-
|
|
3674
|
+
line = { text: "", caret: 0 };
|
|
3369
3675
|
matches;
|
|
3370
3676
|
cursor;
|
|
3371
3677
|
top = 0;
|
|
@@ -3380,6 +3686,8 @@ class List {
|
|
|
3380
3686
|
return this.matches[this.cursor];
|
|
3381
3687
|
}
|
|
3382
3688
|
press(key) {
|
|
3689
|
+
if (this.line.chained === true && endsKills(key))
|
|
3690
|
+
this.line = { ...this.line, chained: false };
|
|
3383
3691
|
if (key === "up" || key === "down") {
|
|
3384
3692
|
if (this.matches.length > 0)
|
|
3385
3693
|
this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
|
|
@@ -3391,15 +3699,19 @@ class List {
|
|
|
3391
3699
|
this.cursor = Math.max(0, Math.min(last, to));
|
|
3392
3700
|
return;
|
|
3393
3701
|
}
|
|
3394
|
-
if (key
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3702
|
+
if (typeof key !== "object" && !isEditKey(key))
|
|
3703
|
+
return;
|
|
3704
|
+
const edited = editLine(this.line, key);
|
|
3705
|
+
if (edited.text !== this.line.text)
|
|
3706
|
+
this.filter(edited.text);
|
|
3707
|
+
this.line = edited;
|
|
3708
|
+
}
|
|
3709
|
+
typed(colors, columns, question) {
|
|
3710
|
+
return this.line.text === "" ? "" : withCaret(colors, this.line, roomAfter(question, columns));
|
|
3398
3711
|
}
|
|
3399
3712
|
filter(query) {
|
|
3400
3713
|
const words = query.toLowerCase().split(WORDS2).filter((word) => word !== "");
|
|
3401
3714
|
const current = this.current();
|
|
3402
|
-
this.query = query;
|
|
3403
3715
|
this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
|
|
3404
3716
|
this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
|
|
3405
3717
|
this.top = 0;
|
|
@@ -3427,7 +3739,7 @@ function asking(colors, question, typed, keys) {
|
|
|
3427
3739
|
function answer(colors, question, state, picked) {
|
|
3428
3740
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
3429
3741
|
}
|
|
3430
|
-
async function ask(question, { hint, terminal =
|
|
3742
|
+
async function ask(question, { hint, terminal = process22 }, render, press) {
|
|
3431
3743
|
const { stdin, stderr } = terminal;
|
|
3432
3744
|
if (!isInteractive(terminal))
|
|
3433
3745
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -3437,12 +3749,22 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
3437
3749
|
const columns = () => stderr.columns || 80;
|
|
3438
3750
|
const draw = (state, last = false) => {
|
|
3439
3751
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
3440
|
-
|
|
3441
|
-
|
|
3752
|
+
const rows = rowsTaken(frame, columns());
|
|
3753
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
3442
3754
|
current = state;
|
|
3443
3755
|
};
|
|
3444
3756
|
const redraw = () => draw(current);
|
|
3445
3757
|
const paste = { active: false };
|
|
3758
|
+
const stop = terminal.stop ?? (terminal === process22 ? stopJob : undefined);
|
|
3759
|
+
const suspend = () => {
|
|
3760
|
+
if (stop === undefined)
|
|
3761
|
+
return;
|
|
3762
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
3763
|
+
stdin.setRawMode(false);
|
|
3764
|
+
stop();
|
|
3765
|
+
stdin.setRawMode(true);
|
|
3766
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
3767
|
+
};
|
|
3446
3768
|
try {
|
|
3447
3769
|
stderr.on?.("resize", redraw);
|
|
3448
3770
|
stdin.setRawMode(true);
|
|
@@ -3452,6 +3774,10 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
3452
3774
|
return await new Promise((resolve) => {
|
|
3453
3775
|
function onData(data) {
|
|
3454
3776
|
for (const key of readKeys(data.toString(), paste)) {
|
|
3777
|
+
if (key === "suspend") {
|
|
3778
|
+
suspend();
|
|
3779
|
+
continue;
|
|
3780
|
+
}
|
|
3455
3781
|
const pressed = press(key);
|
|
3456
3782
|
if (pressed !== undefined) {
|
|
3457
3783
|
settle(pressed);
|
|
@@ -3483,13 +3809,17 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
3483
3809
|
}
|
|
3484
3810
|
var WORDS2, MAX_ROWS = 10, PROMPT_KEYS;
|
|
3485
3811
|
var init_prompt = __esm(() => {
|
|
3812
|
+
init_answers();
|
|
3486
3813
|
init_args();
|
|
3487
3814
|
init_format();
|
|
3815
|
+
init_job();
|
|
3488
3816
|
init_mode();
|
|
3817
|
+
init_line();
|
|
3489
3818
|
init_state();
|
|
3819
|
+
init_redraw();
|
|
3490
3820
|
init_style();
|
|
3491
3821
|
WORDS2 = /\s+/;
|
|
3492
|
-
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "
|
|
3822
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
3493
3823
|
});
|
|
3494
3824
|
|
|
3495
3825
|
// src/excluded.ts
|
|
@@ -3850,7 +4180,7 @@ var exports_manager = {};
|
|
|
3850
4180
|
__export(exports_manager, {
|
|
3851
4181
|
manager: () => manager
|
|
3852
4182
|
});
|
|
3853
|
-
import
|
|
4183
|
+
import process23 from "process";
|
|
3854
4184
|
function manager(args) {
|
|
3855
4185
|
const { values, positionals } = parse(args, usage7, options6, {
|
|
3856
4186
|
exits: EXITS6,
|
|
@@ -3860,7 +4190,7 @@ function manager(args) {
|
|
|
3860
4190
|
examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
|
|
3861
4191
|
});
|
|
3862
4192
|
const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
|
|
3863
|
-
const found = detectManager(
|
|
4193
|
+
const found = detectManager(process23.cwd());
|
|
3864
4194
|
const command = commandFor(action, found);
|
|
3865
4195
|
if (values.json === true)
|
|
3866
4196
|
printJson({ manager: found, action, command });
|
|
@@ -3882,8 +4212,8 @@ var init_manager2 = __esm(() => {
|
|
|
3882
4212
|
|
|
3883
4213
|
// src/cli.ts
|
|
3884
4214
|
init_src();
|
|
3885
|
-
import
|
|
3886
|
-
|
|
4215
|
+
import process24 from "process";
|
|
4216
|
+
process24.exitCode = await runCli({
|
|
3887
4217
|
name: "pkg",
|
|
3888
4218
|
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
3889
4219
|
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.16.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.
|
|
36
|
+
"@kaynooo/cli-kit": "0.41.0"
|
|
37
37
|
}
|
|
38
38
|
}
|