@kaynooo/cli-env 0.13.2 → 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/dist/ev.js +558 -65
- package/dist/redact.js +124 -35
- package/package.json +2 -2
- package/src/commands/edit.ts +11 -8
- package/src/dotenv.ts +12 -1
- package/src/mask.ts +37 -6
package/dist/ev.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ev.ts
|
|
5
|
-
import
|
|
5
|
+
import process22 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -45,6 +45,9 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
45
45
|
return "terminal";
|
|
46
46
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
47
47
|
}
|
|
48
|
+
function isInteractive(streams = process2) {
|
|
49
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
// ../kit/src/style.ts
|
|
50
53
|
import process6 from "process";
|
|
@@ -374,6 +377,23 @@ var STATUS_WORDS = {
|
|
|
374
377
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
378
|
|
|
376
379
|
// ../kit/src/format.ts
|
|
380
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
381
|
+
function formatSeconds(total) {
|
|
382
|
+
let rest = Math.max(0, Math.round(total));
|
|
383
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
384
|
+
const amount = Math.floor(rest / size);
|
|
385
|
+
rest -= amount * size;
|
|
386
|
+
return `${amount}${unit}`;
|
|
387
|
+
});
|
|
388
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
389
|
+
if (first === -1)
|
|
390
|
+
return "0s";
|
|
391
|
+
const next = amounts[first + 1];
|
|
392
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
393
|
+
}
|
|
394
|
+
function formatDuration(ms) {
|
|
395
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
396
|
+
}
|
|
377
397
|
function upTo(text, separator) {
|
|
378
398
|
const end = text.indexOf(separator);
|
|
379
399
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -434,7 +454,7 @@ function printJson(value) {
|
|
|
434
454
|
|
|
435
455
|
// ../kit/src/help.ts
|
|
436
456
|
import process8 from "process";
|
|
437
|
-
var OPTIONAL =
|
|
457
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
438
458
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
439
459
|
var FULL_STOP = /\.$/;
|
|
440
460
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -473,29 +493,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
473
493
|
return [];
|
|
474
494
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
475
495
|
}
|
|
496
|
+
var MAX_INLINE_CHOICES = 24;
|
|
476
497
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
477
498
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
478
499
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
479
|
-
const
|
|
500
|
+
const choices = option.choices?.join("|");
|
|
501
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
502
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
480
503
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
481
504
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
482
|
-
|
|
505
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
506
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
483
507
|
});
|
|
484
508
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
485
509
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
486
510
|
}
|
|
487
511
|
|
|
488
512
|
// ../kit/src/text.ts
|
|
489
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
490
513
|
function distance(a, b) {
|
|
491
|
-
|
|
492
|
-
|
|
514
|
+
const left = [...a];
|
|
515
|
+
const right = [...b];
|
|
516
|
+
let before = [];
|
|
517
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
518
|
+
for (const [i, x] of left.entries()) {
|
|
493
519
|
const current = [i + 1];
|
|
494
|
-
for (const [j,
|
|
495
|
-
|
|
520
|
+
for (const [j, y] of right.entries()) {
|
|
521
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
522
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
523
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
524
|
+
current.push(cost);
|
|
525
|
+
}
|
|
526
|
+
before = previous;
|
|
496
527
|
previous = current;
|
|
497
528
|
}
|
|
498
|
-
return previous[
|
|
529
|
+
return previous[right.length] ?? 0;
|
|
499
530
|
}
|
|
500
531
|
function closest(name, names) {
|
|
501
532
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -767,13 +798,31 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
767
798
|
// ../kit/src/cli.ts
|
|
768
799
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
769
800
|
import { dirname as dirname3, join as join5 } from "path";
|
|
770
|
-
import
|
|
801
|
+
import process14 from "process";
|
|
802
|
+
|
|
803
|
+
// ../kit/src/notify.ts
|
|
804
|
+
import process12 from "process";
|
|
805
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
806
|
+
var CANCELLED = 130;
|
|
807
|
+
function base64(text) {
|
|
808
|
+
return Buffer.from(text).toString("base64");
|
|
809
|
+
}
|
|
810
|
+
function notification(title, body, env = process12.env) {
|
|
811
|
+
const id = `kit${process12.pid}`;
|
|
812
|
+
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\\`];
|
|
813
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
814
|
+
}
|
|
815
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
816
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
817
|
+
return;
|
|
818
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
819
|
+
}
|
|
771
820
|
|
|
772
821
|
// ../kit/src/usage.ts
|
|
773
822
|
import { appendFileSync, mkdirSync } from "fs";
|
|
774
823
|
import { homedir as homedir3 } from "os";
|
|
775
824
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
776
|
-
import
|
|
825
|
+
import process13 from "process";
|
|
777
826
|
|
|
778
827
|
// ../kit/src/logs.ts
|
|
779
828
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -787,14 +836,14 @@ var usageError;
|
|
|
787
836
|
function noteUsageError(message) {
|
|
788
837
|
usageError = message;
|
|
789
838
|
}
|
|
790
|
-
function stateHome(env =
|
|
839
|
+
function stateHome(env = process13.env) {
|
|
791
840
|
const dir = env.XDG_STATE_HOME;
|
|
792
841
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
793
842
|
}
|
|
794
|
-
function usagePath(env =
|
|
843
|
+
function usagePath(env = process13.env) {
|
|
795
844
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
796
845
|
}
|
|
797
|
-
function usageRecorded(env =
|
|
846
|
+
function usageRecorded(env = process13.env) {
|
|
798
847
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
799
848
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
800
849
|
}
|
|
@@ -808,7 +857,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
808
857
|
usageError = undefined;
|
|
809
858
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
810
859
|
}
|
|
811
|
-
function recordUsage(entry, env =
|
|
860
|
+
function recordUsage(entry, env = process13.env) {
|
|
812
861
|
if (!usageRecorded(env))
|
|
813
862
|
return;
|
|
814
863
|
try {
|
|
@@ -898,8 +947,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
898
947
|
`);
|
|
899
948
|
}
|
|
900
949
|
function printError(prefix, message, hint, cause) {
|
|
901
|
-
const colors = paint(
|
|
902
|
-
const styled = takesControlCodes(
|
|
950
|
+
const colors = paint(process14.stderr);
|
|
951
|
+
const styled = takesControlCodes(process14.stderr);
|
|
903
952
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
904
953
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
905
954
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -942,11 +991,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
942
991
|
}
|
|
943
992
|
}
|
|
944
993
|
if (name === undefined && level.path.length > 1) {
|
|
945
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
994
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
946
995
|
return 2;
|
|
947
996
|
}
|
|
948
997
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
949
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
998
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
950
999
|
return 0;
|
|
951
1000
|
}
|
|
952
1001
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1081,10 +1130,13 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1081
1130
|
const version = cli.version ?? packageVersion();
|
|
1082
1131
|
if (argv[0] === COMPLETE)
|
|
1083
1132
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1133
|
+
const started = performance.now();
|
|
1084
1134
|
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 });
|
|
1135
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1136
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1085
1137
|
if (cli.usage !== false) {
|
|
1086
1138
|
try {
|
|
1087
|
-
recordUsage(usageEntry(cli.name,
|
|
1139
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1088
1140
|
} catch {}
|
|
1089
1141
|
}
|
|
1090
1142
|
return code;
|
|
@@ -1112,11 +1164,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1112
1164
|
return 0;
|
|
1113
1165
|
}
|
|
1114
1166
|
let code;
|
|
1167
|
+
const started = performance.now();
|
|
1115
1168
|
try {
|
|
1116
1169
|
code = await run(argv);
|
|
1117
1170
|
} catch (error) {
|
|
1118
1171
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1119
1172
|
}
|
|
1173
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1120
1174
|
if (usage !== false) {
|
|
1121
1175
|
try {
|
|
1122
1176
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1134,12 +1188,18 @@ async function compose(args, { flags = [], ...options } = {}) {
|
|
|
1134
1188
|
return captureOutput(["docker", "compose", ...flags, ...args], options);
|
|
1135
1189
|
}
|
|
1136
1190
|
// ../kit/src/folders.ts
|
|
1191
|
+
import { homedir as homedir4 } from "os";
|
|
1192
|
+
import { join as join6 } from "path";
|
|
1193
|
+
import process15 from "process";
|
|
1137
1194
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1138
1195
|
function ignoredFolders(extra = [], where = {}) {
|
|
1139
1196
|
const configured = readUserConfig("config", where).ignore;
|
|
1140
1197
|
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1141
1198
|
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1142
1199
|
}
|
|
1200
|
+
function cacheFolder({ home = homedir4(), env = process15.env } = {}) {
|
|
1201
|
+
return env.XDG_CACHE_HOME ?? join6(home, ".cache");
|
|
1202
|
+
}
|
|
1143
1203
|
// ../kit/src/secrets.ts
|
|
1144
1204
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1145
1205
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1154,7 +1214,7 @@ var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
|
1154
1214
|
// src/commands/audit.ts
|
|
1155
1215
|
import { stat as stat4 } from "fs/promises";
|
|
1156
1216
|
import { relative, resolve as resolve4 } from "path";
|
|
1157
|
-
import
|
|
1217
|
+
import process17 from "process";
|
|
1158
1218
|
|
|
1159
1219
|
// ../kit/src/shell.ts
|
|
1160
1220
|
var SEPARATORS = new Set([`
|
|
@@ -1205,12 +1265,12 @@ function shellQuote(word) {
|
|
|
1205
1265
|
|
|
1206
1266
|
// src/audit.ts
|
|
1207
1267
|
import { readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
1208
|
-
import { dirname as dirname5, join as
|
|
1268
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1209
1269
|
var {$ } = globalThis.Bun;
|
|
1210
1270
|
|
|
1211
1271
|
// src/files.ts
|
|
1212
1272
|
import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from "fs/promises";
|
|
1213
|
-
import { basename, dirname as dirname4, join as
|
|
1273
|
+
import { basename, dirname as dirname4, join as join7 } from "path";
|
|
1214
1274
|
|
|
1215
1275
|
// src/dotenv.ts
|
|
1216
1276
|
var ASSIGNMENT = /^\s*(?:export\s+)?([A-Z_][\w.-]*)\s*=(.*)$/i;
|
|
@@ -1268,7 +1328,8 @@ function parseDotenv(text) {
|
|
|
1268
1328
|
let body = start.slice(1);
|
|
1269
1329
|
let raw = line;
|
|
1270
1330
|
let end = closingQuote(body, quote);
|
|
1271
|
-
|
|
1331
|
+
const first = index;
|
|
1332
|
+
while (end === -1 && index + 1 < physical.length && !ASSIGNMENT.test(physical[index + 1] ?? "")) {
|
|
1272
1333
|
index++;
|
|
1273
1334
|
body += `
|
|
1274
1335
|
${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
@@ -1276,6 +1337,11 @@ ${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
|
1276
1337
|
${physical[index] ?? ""}`;
|
|
1277
1338
|
end = closingQuote(body, quote);
|
|
1278
1339
|
}
|
|
1340
|
+
if (end === -1 && index + 1 < physical.length) {
|
|
1341
|
+
index = first;
|
|
1342
|
+
lines.push({ raw: line, key, value: unescapeDollar(start.replace(INLINE_COMMENT, "").trim()), unterminated: true });
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1279
1345
|
const inner = end === -1 ? body : body.slice(0, end);
|
|
1280
1346
|
lines.push({ raw, key, value: quote === '"' ? unescapeDouble(inner) : unescapeDollar(inner) });
|
|
1281
1347
|
}
|
|
@@ -1341,9 +1407,30 @@ var ESCAPE2 = /[.*+?^${}()|[\]\\]/g;
|
|
|
1341
1407
|
function isPlaceholder(value) {
|
|
1342
1408
|
return PLACEHOLDER.test(value) || PLAIN_VALUE.test(value);
|
|
1343
1409
|
}
|
|
1410
|
+
var STRONG_NAME = "password|passwd|secret|api[_-]?key|access[_-]?key|private[_-]?key|account[_-]?key|shared[_-]?access[_-]?key";
|
|
1411
|
+
var WEAK_NAME = "token|credentials?|auth";
|
|
1412
|
+
var PLAIN_WORD = /^[a-z]+$/i;
|
|
1413
|
+
var AFTER_COLON = /:\s*$/;
|
|
1414
|
+
var DIGIT = /\d/;
|
|
1415
|
+
var KEY_VALUE_GAP = "\\s*[:=]\\s*";
|
|
1416
|
+
function isProse(value, before) {
|
|
1417
|
+
return isPlaceholder(value) || AFTER_COLON.test(before) && PLAIN_WORD.test(value);
|
|
1418
|
+
}
|
|
1419
|
+
function isWeak(value, before) {
|
|
1420
|
+
return isProse(value, before) || !(DIGIT.test(value) || value.length >= 16);
|
|
1421
|
+
}
|
|
1422
|
+
function keyed(names, value) {
|
|
1423
|
+
return new RegExp(`(?<![\\w-])["']?(?:[\\w-]{0,30}[_-])?(?:${names})(?:[_-][\\w-]{0,30})?["']?${KEY_VALUE_GAP}${value}`, "dgi");
|
|
1424
|
+
}
|
|
1344
1425
|
var TOKEN_FORMATS = [
|
|
1345
1426
|
{ kind: "GitHub token", pattern: /\b(?:gh[pousr]_|github_pat_)\w{20,}/dg },
|
|
1346
|
-
{ kind: "GitLab token", pattern: /\
|
|
1427
|
+
{ kind: "GitLab token", pattern: /\bgl(?:pat|rt|dt|ptt)-[\w-]{20,}/dg },
|
|
1428
|
+
{ kind: "Hugging Face token", pattern: /\bhf_[A-Za-z]{30,}/dg },
|
|
1429
|
+
{ kind: "webhook secret", pattern: /\bwhsec_\w{20,}/dg },
|
|
1430
|
+
{ kind: "DigitalOcean token", pattern: /\bdop_v1_\w{20,}/dg },
|
|
1431
|
+
{ kind: "Shopify token", pattern: /\bshp(?:at|ca|pa|ss)_\w{20,}/dg },
|
|
1432
|
+
{ kind: "password", pattern: /\bmysql(?:dump|admin)?\s+(?:\S+\s+)*?-p([^\s"'|;&-]\S{3,})/dg },
|
|
1433
|
+
{ kind: "password", pattern: /\bsshpass\s+(?:-[a-oq-z]\s+)*-p\s*([^\s"'|;&]{4,})/dg },
|
|
1347
1434
|
{ kind: "API key", pattern: /\bsk-[\w-]{20,}/dg },
|
|
1348
1435
|
{ kind: "Slack token", pattern: /\bx(?:ox[abprs]|app)-[\w-]{10,}/dg },
|
|
1349
1436
|
{ kind: "JWT", pattern: /\beyJ[\w-]+\.[\w-]+\.[\w-]+/dg },
|
|
@@ -1354,8 +1441,10 @@ var TOKEN_FORMATS = [
|
|
|
1354
1441
|
{ kind: "SendGrid key", pattern: /\bSG\.[\w-]{16,}\.[\w-]{16,}/dg },
|
|
1355
1442
|
{ kind: "Authorization header", pattern: /\bAuthorization["']?\s*[:=]\s*["']?(?:Bearer|Basic|Token|Digest)\s+([^\s"',;]{8,})/dgi, skip: isPlaceholder },
|
|
1356
1443
|
{ kind: "Bearer token", pattern: /\bBearer\s+((?=[\w.~+/=-]*\d)[\w.~+/=-]{20,})/dg },
|
|
1357
|
-
{ kind: "password", pattern:
|
|
1358
|
-
{ kind: "password", pattern:
|
|
1444
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `([^\\s"'&;,]{4,})`), skip: isProse },
|
|
1445
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `([^\\s"'&;,]{4,})`), skip: isWeak },
|
|
1446
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isPlaceholder },
|
|
1447
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isWeak }
|
|
1359
1448
|
];
|
|
1360
1449
|
var PEM_BEGIN = /-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
1361
1450
|
var PEM_END = /-----END [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
@@ -1460,7 +1549,7 @@ function findSecrets(line, known) {
|
|
|
1460
1549
|
if (start === undefined || end === undefined)
|
|
1461
1550
|
continue;
|
|
1462
1551
|
const value = line.slice(start, end);
|
|
1463
|
-
if (!skip?.(value))
|
|
1552
|
+
if (!skip?.(value, line.slice(0, start)))
|
|
1464
1553
|
found.push({ start, end, kind, mask: hint(value) });
|
|
1465
1554
|
}
|
|
1466
1555
|
}
|
|
@@ -1522,7 +1611,7 @@ async function envFiles(folder = process.cwd()) {
|
|
|
1522
1611
|
const found = await readdir(folder, { withFileTypes: true });
|
|
1523
1612
|
const names = [];
|
|
1524
1613
|
for (const entry of found) {
|
|
1525
|
-
if (ENV_FILE.test(entry.name) && await isFileEntry(entry,
|
|
1614
|
+
if (ENV_FILE.test(entry.name) && await isFileEntry(entry, join7(folder, entry.name)))
|
|
1526
1615
|
names.push(entry.name);
|
|
1527
1616
|
}
|
|
1528
1617
|
return names.sort();
|
|
@@ -1546,7 +1635,7 @@ async function writeAtomic(path, text) {
|
|
|
1546
1635
|
if (error.code !== "ENOENT")
|
|
1547
1636
|
throw error;
|
|
1548
1637
|
}
|
|
1549
|
-
const temp =
|
|
1638
|
+
const temp = join7(dirname4(target), `.${basename(target)}.${process.pid}.${crypto.randomUUID()}.tmp`);
|
|
1550
1639
|
try {
|
|
1551
1640
|
await writeFile(temp, text, { mode: 384, flag: "wx" });
|
|
1552
1641
|
if (owner !== undefined)
|
|
@@ -1602,7 +1691,7 @@ async function acquire(path) {
|
|
|
1602
1691
|
try {
|
|
1603
1692
|
real = await realpath(path);
|
|
1604
1693
|
} catch {}
|
|
1605
|
-
const lock =
|
|
1694
|
+
const lock = join7(dirname4(real), `.${basename(real)}.lock`);
|
|
1606
1695
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
1607
1696
|
while (true) {
|
|
1608
1697
|
try {
|
|
@@ -1637,7 +1726,7 @@ async function envFilesBelow(folder, depth = 0) {
|
|
|
1637
1726
|
return found;
|
|
1638
1727
|
}
|
|
1639
1728
|
for (const entry of children) {
|
|
1640
|
-
const path =
|
|
1729
|
+
const path = join7(folder, entry.name);
|
|
1641
1730
|
if (entry.isDirectory() && depth < KNOWN_DEPTH && !SKIPPED.has(entry.name))
|
|
1642
1731
|
found.push(...await envFilesBelow(path, depth + 1));
|
|
1643
1732
|
else if (ENV_FILE.test(entry.name) && await isFileEntry(entry, path))
|
|
@@ -1728,7 +1817,7 @@ async function* candidates2(root, unread, depth = 0) {
|
|
|
1728
1817
|
return;
|
|
1729
1818
|
}
|
|
1730
1819
|
for (const entry of found) {
|
|
1731
|
-
const path =
|
|
1820
|
+
const path = join8(root, entry.name);
|
|
1732
1821
|
if (entry.isDirectory() && depth < MAX_DEPTH && !SKIPPED.has(entry.name))
|
|
1733
1822
|
yield* candidates2(path, unread, depth + 1);
|
|
1734
1823
|
else if (!TEMPLATE.test(entry.name) && (ENV_FILE.test(entry.name) || COMPOSE_FILE.test(entry.name)) && await isFileEntry(entry, path))
|
|
@@ -1760,7 +1849,7 @@ async function audit(roots) {
|
|
|
1760
1849
|
|
|
1761
1850
|
// src/fix.ts
|
|
1762
1851
|
import { chmod as chmod2, chown as chown2, lstat, rm as rm2, stat as stat3 } from "fs/promises";
|
|
1763
|
-
import { dirname as dirname6, join as
|
|
1852
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1764
1853
|
var MAP_ENTRY = /^(\s*)(["']?)([A-Z0-9_]+)\2(\s*:)(.*)$/;
|
|
1765
1854
|
var LIST_ENTRY = /^(\s*-[ \t]*)(["']?)([A-Z0-9_]+)=(.*)$/;
|
|
1766
1855
|
var TRAILING = /^\s*(?:#.*)?$/;
|
|
@@ -1853,7 +1942,7 @@ async function shutOthersOut(path, group = false) {
|
|
|
1853
1942
|
}
|
|
1854
1943
|
}
|
|
1855
1944
|
async function fixCompose(path, group = false) {
|
|
1856
|
-
const env =
|
|
1945
|
+
const env = join9(dirname6(path), ".env");
|
|
1857
1946
|
const compose = await Bun.file(path).text();
|
|
1858
1947
|
const envBefore = await Bun.file(env).exists() ? await Bun.file(env).text() : undefined;
|
|
1859
1948
|
const dotenv = parseDotenv(envBefore ?? "");
|
|
@@ -1971,12 +2060,12 @@ async function isFolder(path) {
|
|
|
1971
2060
|
}
|
|
1972
2061
|
}
|
|
1973
2062
|
function shown2(path) {
|
|
1974
|
-
return path.startsWith(`${
|
|
2063
|
+
return path.startsWith(`${process17.cwd()}/`) ? relative(process17.cwd(), path) : path;
|
|
1975
2064
|
}
|
|
1976
2065
|
async function fixAll(exposed, json) {
|
|
1977
2066
|
const fixed = [];
|
|
1978
2067
|
let left = false;
|
|
1979
|
-
const tint = role("path",
|
|
2068
|
+
const tint = role("path", process17.stdout);
|
|
1980
2069
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1981
2070
|
const fix = secrets === undefined ? undefined : await fixCompose(path, group === true);
|
|
1982
2071
|
const open = fix?.open ?? (readable && !await shutOthersOut(path, group === true) ? [path] : []);
|
|
@@ -2028,8 +2117,8 @@ async function audit2(args) {
|
|
|
2028
2117
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
2029
2118
|
return 0;
|
|
2030
2119
|
}
|
|
2031
|
-
const uid =
|
|
2032
|
-
const tint = role("path",
|
|
2120
|
+
const uid = process17.getuid?.();
|
|
2121
|
+
const tint = role("path", process17.stdout);
|
|
2033
2122
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
2034
2123
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
2035
2124
|
const problems = [
|
|
@@ -2045,7 +2134,7 @@ async function audit2(args) {
|
|
|
2045
2134
|
}
|
|
2046
2135
|
|
|
2047
2136
|
// src/commands/compare.ts
|
|
2048
|
-
import
|
|
2137
|
+
import process18 from "process";
|
|
2049
2138
|
var diffUsage = `ev diff <a> <b>
|
|
2050
2139
|
|
|
2051
2140
|
Names the keys set in one file and not the other, never their values.
|
|
@@ -2077,8 +2166,8 @@ ${diffUsage}`);
|
|
|
2077
2166
|
printJson({ a, b, onlyA, onlyB });
|
|
2078
2167
|
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2079
2168
|
}
|
|
2080
|
-
const path = role("path",
|
|
2081
|
-
const value = role("value",
|
|
2169
|
+
const path = role("path", process18.stdout);
|
|
2170
|
+
const value = role("value", process18.stdout);
|
|
2082
2171
|
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2083
2172
|
if (lines.length === 0)
|
|
2084
2173
|
return 0;
|
|
@@ -2099,13 +2188,417 @@ async function missing(args) {
|
|
|
2099
2188
|
}
|
|
2100
2189
|
if (absent.length === 0)
|
|
2101
2190
|
return 0;
|
|
2102
|
-
const path = role("path",
|
|
2103
|
-
const value = role("value",
|
|
2191
|
+
const path = role("path", process18.stdout);
|
|
2192
|
+
const value = role("value", process18.stdout);
|
|
2104
2193
|
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2105
2194
|
`));
|
|
2106
2195
|
return 1;
|
|
2107
2196
|
}
|
|
2108
2197
|
|
|
2198
|
+
// ../kit/src/prompt.ts
|
|
2199
|
+
import process20 from "process";
|
|
2200
|
+
|
|
2201
|
+
// ../kit/src/answers.ts
|
|
2202
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
2203
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
2204
|
+
var KEPT = 50;
|
|
2205
|
+
function answersFile() {
|
|
2206
|
+
return join10(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2207
|
+
}
|
|
2208
|
+
function stored() {
|
|
2209
|
+
try {
|
|
2210
|
+
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
2211
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
2212
|
+
return {};
|
|
2213
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2214
|
+
} catch {
|
|
2215
|
+
return {};
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
function earlierAnswers(key) {
|
|
2219
|
+
return stored()[key] ?? [];
|
|
2220
|
+
}
|
|
2221
|
+
function rememberAnswer(key, answer) {
|
|
2222
|
+
const all = stored();
|
|
2223
|
+
const file = answersFile();
|
|
2224
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2225
|
+
try {
|
|
2226
|
+
mkdirSync2(dirname7(file), { recursive: true });
|
|
2227
|
+
writeFileSync(file, JSON.stringify(all));
|
|
2228
|
+
} catch {}
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// ../kit/src/job.ts
|
|
2232
|
+
import process19 from "process";
|
|
2233
|
+
function stopJob() {
|
|
2234
|
+
process19.kill(0, "SIGTSTP");
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
// ../kit/src/picker/line.ts
|
|
2238
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2239
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2240
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2241
|
+
function isEditKey(key) {
|
|
2242
|
+
return EDIT_KEYS.has(key);
|
|
2243
|
+
}
|
|
2244
|
+
function endsKills(key) {
|
|
2245
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
2246
|
+
}
|
|
2247
|
+
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
2248
|
+
var SPACE = /\s/;
|
|
2249
|
+
function isWord(char) {
|
|
2250
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
2251
|
+
}
|
|
2252
|
+
function wordStart(chars, from) {
|
|
2253
|
+
let at = from;
|
|
2254
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
2255
|
+
at--;
|
|
2256
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
2257
|
+
at--;
|
|
2258
|
+
return at;
|
|
2259
|
+
}
|
|
2260
|
+
function wordEnd(chars, from) {
|
|
2261
|
+
let at = from;
|
|
2262
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
2263
|
+
at++;
|
|
2264
|
+
while (at < chars.length && isWord(chars[at]))
|
|
2265
|
+
at++;
|
|
2266
|
+
return at;
|
|
2267
|
+
}
|
|
2268
|
+
function spacedStart(chars, from) {
|
|
2269
|
+
let at = from;
|
|
2270
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
2271
|
+
at--;
|
|
2272
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
2273
|
+
at--;
|
|
2274
|
+
return at;
|
|
2275
|
+
}
|
|
2276
|
+
function cut(chars, from, to) {
|
|
2277
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
2278
|
+
}
|
|
2279
|
+
function insert(chars, at, text) {
|
|
2280
|
+
const typed = [...text];
|
|
2281
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
2282
|
+
}
|
|
2283
|
+
function editLine(line, key) {
|
|
2284
|
+
const { killed = "", chained = false } = line;
|
|
2285
|
+
const chars = [...line.text];
|
|
2286
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
2287
|
+
const edited = edit(chars, at, key, killed);
|
|
2288
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
2289
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
2290
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
2291
|
+
if (taken === "")
|
|
2292
|
+
return { ...edited, killed, chained };
|
|
2293
|
+
if (!chained)
|
|
2294
|
+
return { ...edited, killed: taken, chained: true };
|
|
2295
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
2296
|
+
}
|
|
2297
|
+
function edit(chars, at, key, killed) {
|
|
2298
|
+
const text = chars.join("");
|
|
2299
|
+
if (typeof key === "object")
|
|
2300
|
+
return insert(chars, at, key.text);
|
|
2301
|
+
switch (key) {
|
|
2302
|
+
case "left":
|
|
2303
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
2304
|
+
case "right":
|
|
2305
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
2306
|
+
case "wordleft":
|
|
2307
|
+
return { text, caret: wordStart(chars, at) };
|
|
2308
|
+
case "wordright":
|
|
2309
|
+
return { text, caret: wordEnd(chars, at) };
|
|
2310
|
+
case "linestart":
|
|
2311
|
+
return { text, caret: 0 };
|
|
2312
|
+
case "lineend":
|
|
2313
|
+
return { text, caret: chars.length };
|
|
2314
|
+
case "erase":
|
|
2315
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
2316
|
+
case "delete":
|
|
2317
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
2318
|
+
case "word":
|
|
2319
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
2320
|
+
case "killword":
|
|
2321
|
+
return cut(chars, wordStart(chars, at), at);
|
|
2322
|
+
case "killnext":
|
|
2323
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
2324
|
+
case "clear":
|
|
2325
|
+
return cut(chars, 0, at);
|
|
2326
|
+
case "killend":
|
|
2327
|
+
return cut(chars, at, chars.length);
|
|
2328
|
+
case "yank":
|
|
2329
|
+
return insert(chars, at, killed);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
function visible({ text, caret }, room) {
|
|
2333
|
+
const chars = [...text];
|
|
2334
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
2335
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
2336
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
2337
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
2338
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
2339
|
+
let start = at;
|
|
2340
|
+
let end = at + 1;
|
|
2341
|
+
while (start > 0 && fits(start - 1, end))
|
|
2342
|
+
start--;
|
|
2343
|
+
while (end < cells.length && fits(start, end + 1))
|
|
2344
|
+
end++;
|
|
2345
|
+
const left = start > 0 ? "\u2026" : "";
|
|
2346
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
2347
|
+
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) };
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
// ../kit/src/picker/score.ts
|
|
2351
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2352
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
2353
|
+
|
|
2354
|
+
// ../kit/src/picker/state.ts
|
|
2355
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2356
|
+
var PASTE_START = "\x1B[200~";
|
|
2357
|
+
var PASTE_END = "\x1B[201~";
|
|
2358
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2359
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
2360
|
+
var WHEEL_LINES = 3;
|
|
2361
|
+
var KEYS = {
|
|
2362
|
+
"\x1B[A": "up",
|
|
2363
|
+
"\x1BOA": "up",
|
|
2364
|
+
"\x10": "up",
|
|
2365
|
+
"\x1B[B": "down",
|
|
2366
|
+
"\x1BOB": "down",
|
|
2367
|
+
"\x0E": "down",
|
|
2368
|
+
"\x1B[5~": "pageup",
|
|
2369
|
+
"\x1B[6~": "pagedown",
|
|
2370
|
+
"\x1B[H": "home",
|
|
2371
|
+
"\x1B[1~": "home",
|
|
2372
|
+
"\x1BOH": "home",
|
|
2373
|
+
"\x1B[F": "end",
|
|
2374
|
+
"\x1B[4~": "end",
|
|
2375
|
+
"\x1BOF": "end",
|
|
2376
|
+
"\r": "enter",
|
|
2377
|
+
"\n": "enter",
|
|
2378
|
+
"\x03": "cancel",
|
|
2379
|
+
"\x1B": "cancel",
|
|
2380
|
+
"\x1B[D": "left",
|
|
2381
|
+
"\x1BOD": "left",
|
|
2382
|
+
"\x1B[C": "right",
|
|
2383
|
+
"\x1BOC": "right",
|
|
2384
|
+
"\x1B[1;5D": "wordleft",
|
|
2385
|
+
"\x1B[1;3D": "wordleft",
|
|
2386
|
+
"\x1Bb": "wordleft",
|
|
2387
|
+
"\x1B[1;5C": "wordright",
|
|
2388
|
+
"\x1B[1;3C": "wordright",
|
|
2389
|
+
"\x1Bf": "wordright",
|
|
2390
|
+
"\x01": "linestart",
|
|
2391
|
+
"\x05": "lineend",
|
|
2392
|
+
"\x7F": "erase",
|
|
2393
|
+
"\x1B[3~": "delete",
|
|
2394
|
+
"\b": "killword",
|
|
2395
|
+
"\x1B\x7F": "killword",
|
|
2396
|
+
"\x1B[3;5~": "killnext",
|
|
2397
|
+
"\x1Bd": "killnext",
|
|
2398
|
+
"\x15": "clear",
|
|
2399
|
+
"\v": "killend",
|
|
2400
|
+
"\x17": "word",
|
|
2401
|
+
"\x19": "yank",
|
|
2402
|
+
"\x1A": "suspend",
|
|
2403
|
+
"\t": "tab",
|
|
2404
|
+
"\x1F": "help",
|
|
2405
|
+
"\x1BOP": "help",
|
|
2406
|
+
"\x1B[11~": "help"
|
|
2407
|
+
};
|
|
2408
|
+
function repeat(value, count) {
|
|
2409
|
+
return Array.from({ length: count }).fill(value);
|
|
2410
|
+
}
|
|
2411
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2412
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2413
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2414
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2415
|
+
if (wheel !== undefined)
|
|
2416
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
2417
|
+
const named = codes.get(sequence);
|
|
2418
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2419
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2420
|
+
paste.active = sequence === PASTE_START;
|
|
2421
|
+
return [];
|
|
2422
|
+
}
|
|
2423
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
2424
|
+
`))
|
|
2425
|
+
return [];
|
|
2426
|
+
if (key !== undefined)
|
|
2427
|
+
return [key];
|
|
2428
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
// ../kit/src/redraw.ts
|
|
2433
|
+
var SYNC_START = "\x1B[?2026h";
|
|
2434
|
+
var SYNC_END = "\x1B[?2026l";
|
|
2435
|
+
function overwrite(lines, columns) {
|
|
2436
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2437
|
+
`);
|
|
2438
|
+
}
|
|
2439
|
+
function rowsTaken(lines, columns) {
|
|
2440
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
// ../kit/src/prompt.ts
|
|
2444
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2445
|
+
var MAX_LISTED = 12;
|
|
2446
|
+
function readKeys(input, paste = { active: false }) {
|
|
2447
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2448
|
+
}
|
|
2449
|
+
function roomAfter(question, columns) {
|
|
2450
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2451
|
+
}
|
|
2452
|
+
function withCaret(colors, line, room, dim = false) {
|
|
2453
|
+
const { before, at, after } = visible(line, room);
|
|
2454
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
2455
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2456
|
+
}
|
|
2457
|
+
function sharedStart(texts) {
|
|
2458
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
2459
|
+
let length = first.length;
|
|
2460
|
+
for (const chars of rest) {
|
|
2461
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
2462
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
2463
|
+
}
|
|
2464
|
+
return first.slice(0, length).join("");
|
|
2465
|
+
}
|
|
2466
|
+
function listed2(colors, found, columns) {
|
|
2467
|
+
const shared = sharedStart(found);
|
|
2468
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
2469
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
2470
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
2471
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
2472
|
+
}
|
|
2473
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2474
|
+
let line = { text: "", caret: 0 };
|
|
2475
|
+
let invalid;
|
|
2476
|
+
let completions = [];
|
|
2477
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
2478
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2479
|
+
let recalled = -1;
|
|
2480
|
+
let draft = line;
|
|
2481
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
2482
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
2483
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
2484
|
+
if (state !== "asking")
|
|
2485
|
+
return [answer(colors, question, state, shown())];
|
|
2486
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2487
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
2488
|
+
}, (key) => {
|
|
2489
|
+
if (key === "cancel")
|
|
2490
|
+
return "cancel";
|
|
2491
|
+
invalid = undefined;
|
|
2492
|
+
completions = [];
|
|
2493
|
+
if (line.chained === true && endsKills(key))
|
|
2494
|
+
line = { ...line, chained: false };
|
|
2495
|
+
if (key === "tab") {
|
|
2496
|
+
const chars = [...line.text];
|
|
2497
|
+
const before = chars.slice(0, line.caret).join("");
|
|
2498
|
+
const found = complete?.(before) ?? [];
|
|
2499
|
+
const filled = sharedStart(found);
|
|
2500
|
+
if ([...filled].length > [...before].length)
|
|
2501
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2502
|
+
else
|
|
2503
|
+
completions = found;
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
if (key === "enter") {
|
|
2507
|
+
invalid = validate?.(taken());
|
|
2508
|
+
return invalid === undefined ? "enter" : undefined;
|
|
2509
|
+
}
|
|
2510
|
+
if (key === "up" || key === "down") {
|
|
2511
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2512
|
+
if (recalled === -1)
|
|
2513
|
+
draft = line;
|
|
2514
|
+
recalled = to;
|
|
2515
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2516
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2520
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
2521
|
+
line = editLine(line, edit);
|
|
2522
|
+
return;
|
|
2523
|
+
});
|
|
2524
|
+
if (!accepted)
|
|
2525
|
+
return;
|
|
2526
|
+
if (remembered !== undefined && taken() !== "")
|
|
2527
|
+
rememberAnswer(remembered, taken());
|
|
2528
|
+
return taken();
|
|
2529
|
+
}
|
|
2530
|
+
function answer(colors, question, state, picked) {
|
|
2531
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2532
|
+
}
|
|
2533
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
2534
|
+
const { stdin, stderr } = terminal;
|
|
2535
|
+
if (!isInteractive(terminal))
|
|
2536
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2537
|
+
const colors = paint(stderr);
|
|
2538
|
+
let current = "asking";
|
|
2539
|
+
let outcome;
|
|
2540
|
+
const columns = () => stderr.columns || 80;
|
|
2541
|
+
const draw = (state, last = false) => {
|
|
2542
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2543
|
+
const rows = rowsTaken(frame, columns());
|
|
2544
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2545
|
+
current = state;
|
|
2546
|
+
};
|
|
2547
|
+
const redraw = () => draw(current);
|
|
2548
|
+
const paste = { active: false };
|
|
2549
|
+
const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
|
|
2550
|
+
const suspend = () => {
|
|
2551
|
+
if (stop === undefined)
|
|
2552
|
+
return;
|
|
2553
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2554
|
+
stdin.setRawMode(false);
|
|
2555
|
+
stop();
|
|
2556
|
+
stdin.setRawMode(true);
|
|
2557
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2558
|
+
};
|
|
2559
|
+
try {
|
|
2560
|
+
stderr.on?.("resize", redraw);
|
|
2561
|
+
stdin.setRawMode(true);
|
|
2562
|
+
stdin.resume();
|
|
2563
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2564
|
+
draw("asking");
|
|
2565
|
+
return await new Promise((resolve) => {
|
|
2566
|
+
function onData(data) {
|
|
2567
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
2568
|
+
if (key === "suspend") {
|
|
2569
|
+
suspend();
|
|
2570
|
+
continue;
|
|
2571
|
+
}
|
|
2572
|
+
const pressed = press(key);
|
|
2573
|
+
if (pressed !== undefined) {
|
|
2574
|
+
settle(pressed);
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
draw("asking");
|
|
2579
|
+
}
|
|
2580
|
+
function onEnd() {
|
|
2581
|
+
settle("cancel");
|
|
2582
|
+
}
|
|
2583
|
+
function settle(settled) {
|
|
2584
|
+
outcome = settled;
|
|
2585
|
+
stdin.off("data", onData);
|
|
2586
|
+
stdin.off("end", onEnd);
|
|
2587
|
+
resolve(settled === "enter");
|
|
2588
|
+
}
|
|
2589
|
+
stdin.on("data", onData);
|
|
2590
|
+
stdin.on("end", onEnd);
|
|
2591
|
+
});
|
|
2592
|
+
} finally {
|
|
2593
|
+
stderr.off?.("resize", redraw);
|
|
2594
|
+
draw(outcome ?? "cancel", true);
|
|
2595
|
+
stderr.write(`
|
|
2596
|
+
\x1B[?25h\x1B[?2004l`);
|
|
2597
|
+
stdin.setRawMode(false);
|
|
2598
|
+
stdin.pause();
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2109
2602
|
// src/commands/edit.ts
|
|
2110
2603
|
var DEFAULT_FILE = ".env";
|
|
2111
2604
|
var TRAILING_NEWLINE = /\r?\n$/;
|
|
@@ -2113,8 +2606,8 @@ var KEY_NAME = /^[A-Z_][\w.-]*$/i;
|
|
|
2113
2606
|
var QUIET = { quiet: { type: "boolean", short: "q", description: "print nothing on success" } };
|
|
2114
2607
|
var setUsage = `ev set KEY [file] [--quiet]
|
|
2115
2608
|
|
|
2116
|
-
Sets KEY in the file (.env by default, created when missing), replacing its line in place or appending one. The value is read from stdin, or from -F <file>, so it never appears in a command line; --empty sets it to an empty value.`;
|
|
2117
|
-
var SET_EXITS = [[0, "it wrote the key"], [1, "it could not"], [2, "a usage error"]];
|
|
2609
|
+
Sets KEY in the file (.env by default, created when missing), replacing its line in place or appending one. The value is read from stdin, or from -F <file>, so it never appears in a command line; on a terminal with nothing piped it is asked for, masked as it is typed. --empty sets it to an empty value.`;
|
|
2610
|
+
var SET_EXITS = [[0, "it wrote the key"], [1, "it could not"], [2, "a usage error"], [130, "the prompt was cancelled"]];
|
|
2118
2611
|
var unsetUsage = `ev unset KEY [file] [--quiet]
|
|
2119
2612
|
|
|
2120
2613
|
Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are.`;
|
|
@@ -2127,11 +2620,11 @@ var cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY] [--quiet]
|
|
|
2127
2620
|
|
|
2128
2621
|
Copies KEY's value from one file to another without printing it, replacing the key's line in the target in place or appending one, and prints the masked result as ev set does. --as stores the copy under another key.`;
|
|
2129
2622
|
var CP_EXITS = [[0, "it copied the key"], [1, "the source lacks it"], [2, "a usage error"]];
|
|
2130
|
-
async function readValue(from) {
|
|
2131
|
-
const
|
|
2132
|
-
if (
|
|
2623
|
+
async function readValue(key, from) {
|
|
2624
|
+
const value = from === undefined && isInteractive() ? await input2(`value of ${key}`, { mask: true }) ?? fail("cancelled, nothing was written", 130) : await readInput(from ?? "-", { noStdin: "pipe the value on stdin or give -F <file>, it is never taken from the command line" });
|
|
2625
|
+
if (value === "")
|
|
2133
2626
|
fail("the value is empty, nothing was written: --empty sets an empty value");
|
|
2134
|
-
return
|
|
2627
|
+
return value.replace(TRAILING_NEWLINE, "");
|
|
2135
2628
|
}
|
|
2136
2629
|
function checkKey(key) {
|
|
2137
2630
|
if (!KEY_NAME.test(key))
|
|
@@ -2154,7 +2647,7 @@ ${setUsage}`);
|
|
|
2154
2647
|
if (parsed.values.empty === true && parsed.values.file !== undefined)
|
|
2155
2648
|
fail("--empty and -F exclude each other");
|
|
2156
2649
|
checkKey(key);
|
|
2157
|
-
const value = parsed.values.empty === true ? "" : await readValue(parsed.values.file);
|
|
2650
|
+
const value = parsed.values.empty === true ? "" : await readValue(key, parsed.values.file);
|
|
2158
2651
|
const file = await withLocks([target], async () => {
|
|
2159
2652
|
const current = await readOrEmpty(target);
|
|
2160
2653
|
setLine(current, key, value);
|
|
@@ -2246,11 +2739,11 @@ ${cpUsage}`);
|
|
|
2246
2739
|
|
|
2247
2740
|
// src/commands/pins.ts
|
|
2248
2741
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
2249
|
-
import { join as
|
|
2742
|
+
import { join as join12, resolve as resolve5 } from "path";
|
|
2250
2743
|
|
|
2251
2744
|
// src/pins.ts
|
|
2252
2745
|
import { readdir as readdir3, readFile } from "fs/promises";
|
|
2253
|
-
import { join as
|
|
2746
|
+
import { join as join11, relative as relative2 } from "path";
|
|
2254
2747
|
var OPTIONAL2 = /^\s*([A-Z][A-Z0-9_]*)\s*:\s*s\.Optional\(/gm;
|
|
2255
2748
|
var REACHING = /(?:URL|URI|TOKEN|KEY|SECRET|PASSWORD|DSN|_HOST)(?:_FILE)?$/;
|
|
2256
2749
|
var SELF = /(?:^|_)(?:PUBLIC|SITE|BASE|APP)_URL$/;
|
|
@@ -2279,7 +2772,7 @@ async function walk(folder, keep) {
|
|
|
2279
2772
|
for (const entry of entries) {
|
|
2280
2773
|
if (SKIPPED.has(entry.name))
|
|
2281
2774
|
continue;
|
|
2282
|
-
const path =
|
|
2775
|
+
const path = join11(folder, entry.name);
|
|
2283
2776
|
if (entry.isDirectory())
|
|
2284
2777
|
found.push(...await walk(path, keep));
|
|
2285
2778
|
else if (entry.isFile() && keep(entry.name))
|
|
@@ -2290,7 +2783,7 @@ async function walk(folder, keep) {
|
|
|
2290
2783
|
async function testFiles(folder) {
|
|
2291
2784
|
const found = [];
|
|
2292
2785
|
for (const root of TEST_ROOTS) {
|
|
2293
|
-
found.push(...await walk(
|
|
2786
|
+
found.push(...await walk(join11(folder, root), (name) => TEST_FILE.test(name)));
|
|
2294
2787
|
}
|
|
2295
2788
|
return found;
|
|
2296
2789
|
}
|
|
@@ -2358,7 +2851,7 @@ function reachesOutside(name) {
|
|
|
2358
2851
|
}
|
|
2359
2852
|
async function schemaFile(folder) {
|
|
2360
2853
|
for (const candidate of SCHEMA_CANDIDATES) {
|
|
2361
|
-
const path =
|
|
2854
|
+
const path = join11(folder, candidate);
|
|
2362
2855
|
if (await exists(path) && (await readFile(path, "utf8")).includes("defineEnv("))
|
|
2363
2856
|
return path;
|
|
2364
2857
|
}
|
|
@@ -2369,7 +2862,7 @@ async function testEnvKeys(folder) {
|
|
|
2369
2862
|
for (const entry of await readdir3(folder, { withFileTypes: true })) {
|
|
2370
2863
|
if (!entry.isFile() || !ENV_TEST.test(entry.name))
|
|
2371
2864
|
continue;
|
|
2372
|
-
for (const line of parseDotenv(await readFile(
|
|
2865
|
+
for (const line of parseDotenv(await readFile(join11(folder, entry.name), "utf8")).lines) {
|
|
2373
2866
|
if (line.key !== undefined)
|
|
2374
2867
|
keys.add(line.key);
|
|
2375
2868
|
}
|
|
@@ -2377,7 +2870,7 @@ async function testEnvKeys(folder) {
|
|
|
2377
2870
|
return keys;
|
|
2378
2871
|
}
|
|
2379
2872
|
async function pinningPreload(folder) {
|
|
2380
|
-
const path =
|
|
2873
|
+
const path = join11(folder, "bunfig.toml");
|
|
2381
2874
|
if (!await exists(path))
|
|
2382
2875
|
return;
|
|
2383
2876
|
let config;
|
|
@@ -2388,7 +2881,7 @@ async function pinningPreload(folder) {
|
|
|
2388
2881
|
}
|
|
2389
2882
|
const preloads = [config.test?.preload, config.preload].flat().filter((entry) => typeof entry === "string" && entry.startsWith("."));
|
|
2390
2883
|
for (const preload of preloads) {
|
|
2391
|
-
const file =
|
|
2884
|
+
const file = join11(folder, preload);
|
|
2392
2885
|
if (!await exists(file))
|
|
2393
2886
|
continue;
|
|
2394
2887
|
const source = await readFile(file, "utf8");
|
|
@@ -2450,7 +2943,7 @@ async function apps(dir, except) {
|
|
|
2450
2943
|
for (const entry of (await readdir4(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2451
2944
|
if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
|
|
2452
2945
|
continue;
|
|
2453
|
-
const app = await checkApp(
|
|
2946
|
+
const app = await checkApp(join12(dir, entry.name), except);
|
|
2454
2947
|
if (app !== undefined)
|
|
2455
2948
|
found.push(app);
|
|
2456
2949
|
}
|
|
@@ -2638,7 +3131,7 @@ ${showUsage}`);
|
|
|
2638
3131
|
}
|
|
2639
3132
|
|
|
2640
3133
|
// src/commands/redact.ts
|
|
2641
|
-
import
|
|
3134
|
+
import process21 from "process";
|
|
2642
3135
|
|
|
2643
3136
|
// src/redactor.ts
|
|
2644
3137
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -2777,13 +3270,13 @@ async function redact(args) {
|
|
|
2777
3270
|
const redactor = new Redactor(known);
|
|
2778
3271
|
const decoder = new TextDecoder;
|
|
2779
3272
|
for await (const chunk of Bun.stdin.stream())
|
|
2780
|
-
|
|
2781
|
-
|
|
3273
|
+
process21.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
3274
|
+
process21.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
2782
3275
|
return 0;
|
|
2783
3276
|
}
|
|
2784
3277
|
|
|
2785
3278
|
// src/ev.ts
|
|
2786
|
-
|
|
3279
|
+
process22.exitCode = await runCli({
|
|
2787
3280
|
name: "ev",
|
|
2788
3281
|
about: ".env files listed and edited with secrets masked",
|
|
2789
3282
|
replaces: "cat .env, grep on env files and editing them by hand",
|