@kaynooo/cli-code 0.17.1 → 0.17.3
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 +186 -52
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -162,11 +162,14 @@ var init_config = __esm(() => {
|
|
|
162
162
|
// ../kit/src/user-config.ts
|
|
163
163
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
164
164
|
import { homedir } from "os";
|
|
165
|
-
import { join as join2 } from "path";
|
|
165
|
+
import { isAbsolute, join as join2 } from "path";
|
|
166
166
|
import process4 from "process";
|
|
167
|
+
function xdgFolder(value, fallback) {
|
|
168
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
169
|
+
}
|
|
167
170
|
function configBase(where = {}) {
|
|
168
171
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
169
|
-
return xdg
|
|
172
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
170
173
|
}
|
|
171
174
|
function userConfigPath(bin, where = {}) {
|
|
172
175
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -691,11 +694,20 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
691
694
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
692
695
|
return number;
|
|
693
696
|
}
|
|
697
|
+
function durationMs(text, unit) {
|
|
698
|
+
if (BARE_DURATION.test(text))
|
|
699
|
+
return Number(text) * UNIT_MS[unit];
|
|
700
|
+
if (!DURATION.test(text))
|
|
701
|
+
return 0;
|
|
702
|
+
let ms = 0;
|
|
703
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
704
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
705
|
+
return ms;
|
|
706
|
+
}
|
|
694
707
|
function duration(value, name, fallback, unit = "s") {
|
|
695
708
|
if (value === undefined)
|
|
696
709
|
return fallback;
|
|
697
|
-
const
|
|
698
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
710
|
+
const ms = durationMs(value.trim(), unit);
|
|
699
711
|
if (ms < 1)
|
|
700
712
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
701
713
|
return ms;
|
|
@@ -704,12 +716,14 @@ function isStdinPiped() {
|
|
|
704
716
|
const stat = fstatSync(0);
|
|
705
717
|
return stat.isFIFO() || stat.isFile();
|
|
706
718
|
}
|
|
707
|
-
var WHOLE, DURATION, UNIT_MS;
|
|
719
|
+
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
708
720
|
var init_input = __esm(() => {
|
|
709
721
|
init_args();
|
|
710
722
|
WHOLE = /^\d+$/;
|
|
711
|
-
|
|
712
|
-
|
|
723
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
724
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
725
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
726
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
713
727
|
});
|
|
714
728
|
|
|
715
729
|
// ../kit/src/args.ts
|
|
@@ -1001,10 +1015,12 @@ init_format();
|
|
|
1001
1015
|
import process12 from "process";
|
|
1002
1016
|
|
|
1003
1017
|
// ../kit/src/process.ts
|
|
1018
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1004
1019
|
import { constants } from "os";
|
|
1005
1020
|
import process11 from "process";
|
|
1006
1021
|
var KILL_GRACE_MS = 2000;
|
|
1007
1022
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1023
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
1008
1024
|
function exitCodeOf(code, signal) {
|
|
1009
1025
|
if (code !== null)
|
|
1010
1026
|
return code;
|
|
@@ -1012,6 +1028,21 @@ function exitCodeOf(code, signal) {
|
|
|
1012
1028
|
return 128 + signal;
|
|
1013
1029
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1014
1030
|
}
|
|
1031
|
+
function groupsOf(pid) {
|
|
1032
|
+
try {
|
|
1033
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
1034
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1035
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
1036
|
+
} catch {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function heardTheTerminal(child) {
|
|
1041
|
+
if (child.pid === undefined)
|
|
1042
|
+
return false;
|
|
1043
|
+
const own = groupsOf("self");
|
|
1044
|
+
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
1045
|
+
}
|
|
1015
1046
|
function holdSignals(cleanup) {
|
|
1016
1047
|
let received;
|
|
1017
1048
|
let child;
|
|
@@ -1030,7 +1061,8 @@ function holdSignals(cleanup) {
|
|
|
1030
1061
|
function onSignal(signal) {
|
|
1031
1062
|
received = signal;
|
|
1032
1063
|
if (child !== undefined) {
|
|
1033
|
-
|
|
1064
|
+
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1065
|
+
child.kill(signal);
|
|
1034
1066
|
return;
|
|
1035
1067
|
}
|
|
1036
1068
|
if (cleanup === undefined)
|
|
@@ -1086,12 +1118,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
|
|
|
1086
1118
|
stop();
|
|
1087
1119
|
continue;
|
|
1088
1120
|
}
|
|
1121
|
+
if (state.truncated)
|
|
1122
|
+
continue;
|
|
1123
|
+
let kept = data;
|
|
1089
1124
|
if (state.kept + data.length > maxBytes) {
|
|
1125
|
+
let cut = maxBytes - state.kept;
|
|
1126
|
+
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1127
|
+
cut--;
|
|
1128
|
+
kept = data.subarray(0, cut);
|
|
1090
1129
|
state.truncated = true;
|
|
1091
|
-
continue;
|
|
1092
1130
|
}
|
|
1093
|
-
state.kept +=
|
|
1094
|
-
|
|
1131
|
+
state.kept += kept.length;
|
|
1132
|
+
if (kept.length > 0)
|
|
1133
|
+
chunks.push({ stream: name, data: kept });
|
|
1095
1134
|
}
|
|
1096
1135
|
};
|
|
1097
1136
|
try {
|
|
@@ -1108,6 +1147,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
|
|
|
1108
1147
|
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1109
1148
|
let output;
|
|
1110
1149
|
let text;
|
|
1150
|
+
let stdout;
|
|
1111
1151
|
return {
|
|
1112
1152
|
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1113
1153
|
chunks,
|
|
@@ -1118,6 +1158,9 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
|
|
|
1118
1158
|
},
|
|
1119
1159
|
get text() {
|
|
1120
1160
|
return text ??= (output ??= joined()).toString();
|
|
1161
|
+
},
|
|
1162
|
+
get stdout() {
|
|
1163
|
+
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1121
1164
|
}
|
|
1122
1165
|
};
|
|
1123
1166
|
}
|
|
@@ -1348,7 +1391,7 @@ init_style();
|
|
|
1348
1391
|
init_format();
|
|
1349
1392
|
// ../kit/src/cli.ts
|
|
1350
1393
|
init_args();
|
|
1351
|
-
import { readFileSync as
|
|
1394
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1352
1395
|
import { dirname as dirname3, join as join5 } from "path";
|
|
1353
1396
|
import process16 from "process";
|
|
1354
1397
|
|
|
@@ -1478,14 +1521,16 @@ init_text2();
|
|
|
1478
1521
|
// ../kit/src/usage.ts
|
|
1479
1522
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1480
1523
|
import { homedir as homedir3 } from "os";
|
|
1481
|
-
import { dirname as dirname2,
|
|
1524
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
1482
1525
|
import process15 from "process";
|
|
1483
1526
|
|
|
1484
1527
|
// ../kit/src/logs.ts
|
|
1528
|
+
init_user_config();
|
|
1485
1529
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1486
1530
|
var CLI_FOLDER = "kaynooo-cli";
|
|
1487
1531
|
|
|
1488
1532
|
// ../kit/src/usage.ts
|
|
1533
|
+
init_user_config();
|
|
1489
1534
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1490
1535
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1491
1536
|
var LONGEST_NAME = 40;
|
|
@@ -1494,8 +1539,7 @@ function noteUsageError(message) {
|
|
|
1494
1539
|
usageError = message;
|
|
1495
1540
|
}
|
|
1496
1541
|
function stateHome(env = process15.env) {
|
|
1497
|
-
|
|
1498
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1542
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
1499
1543
|
}
|
|
1500
1544
|
function usagePath(env = process15.env) {
|
|
1501
1545
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
@@ -1569,6 +1613,10 @@ function takeOutputFlags(argv) {
|
|
|
1569
1613
|
async function resolveSummary(summary) {
|
|
1570
1614
|
return typeof summary === "string" ? summary : summary();
|
|
1571
1615
|
}
|
|
1616
|
+
function lookup({ commands, aliases }, word) {
|
|
1617
|
+
const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
|
|
1618
|
+
return Object.hasOwn(commands, name) ? commands[name] : undefined;
|
|
1619
|
+
}
|
|
1572
1620
|
function scopeOf(commands, extra, aliases) {
|
|
1573
1621
|
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1574
1622
|
}
|
|
@@ -1663,12 +1711,12 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1663
1711
|
console.log(version);
|
|
1664
1712
|
return 0;
|
|
1665
1713
|
}
|
|
1666
|
-
let command = level
|
|
1714
|
+
let command = lookup(level, name);
|
|
1667
1715
|
let rest = args;
|
|
1668
1716
|
let ran = name;
|
|
1669
1717
|
if (command === undefined && level.lazy.length > 0) {
|
|
1670
1718
|
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1671
|
-
command = level
|
|
1719
|
+
command = lookup(level, name);
|
|
1672
1720
|
}
|
|
1673
1721
|
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1674
1722
|
command = level.commands[level.defaultCommand];
|
|
@@ -1748,18 +1796,19 @@ async function leafCandidates(run, words) {
|
|
|
1748
1796
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1749
1797
|
const [word = "", ...rest] = words;
|
|
1750
1798
|
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1751
|
-
let { commands
|
|
1752
|
-
let command =
|
|
1799
|
+
let { commands } = scope;
|
|
1800
|
+
let command = lookup(scope, word);
|
|
1753
1801
|
if (listing || command === undefined) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1802
|
+
const expanded = await expand(scope, [...before, ...words]);
|
|
1803
|
+
commands = expanded.commands;
|
|
1804
|
+
command = lookup(expanded, word);
|
|
1756
1805
|
}
|
|
1757
1806
|
if (listing) {
|
|
1758
1807
|
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1759
1808
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1760
1809
|
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
1761
1810
|
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
1762
|
-
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line)
|
|
1811
|
+
return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
|
|
1763
1812
|
}
|
|
1764
1813
|
if (command === undefined) {
|
|
1765
1814
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
@@ -1792,7 +1841,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1792
1841
|
} catch {}
|
|
1793
1842
|
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1794
1843
|
try {
|
|
1795
|
-
const { version } = JSON.parse(
|
|
1844
|
+
const { version } = JSON.parse(readFileSync5(join5(dir, "package.json"), "utf8"));
|
|
1796
1845
|
if (typeof version === "string")
|
|
1797
1846
|
return version;
|
|
1798
1847
|
} catch {}
|
|
@@ -1824,8 +1873,7 @@ function commandPath(scope, argv) {
|
|
|
1824
1873
|
const path = [];
|
|
1825
1874
|
let level = scope;
|
|
1826
1875
|
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1827
|
-
const
|
|
1828
|
-
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
1876
|
+
const command = lookup(level, word);
|
|
1829
1877
|
if (command === undefined)
|
|
1830
1878
|
break;
|
|
1831
1879
|
path.push(word);
|
|
@@ -1879,6 +1927,7 @@ init_style();
|
|
|
1879
1927
|
init_text2();
|
|
1880
1928
|
// ../kit/src/secrets.ts
|
|
1881
1929
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1930
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1882
1931
|
// ../kit/src/sessions.ts
|
|
1883
1932
|
var {Glob } = globalThis.Bun;
|
|
1884
1933
|
var SESSION_FILES = new Glob("*.json");
|
|
@@ -1912,7 +1961,7 @@ var COMMIT_START = 1;
|
|
|
1912
1961
|
var LOG_FORMAT = ["--no-renames", "--numstat", "--format=%x01%ct%x02%ae", "-z"];
|
|
1913
1962
|
var GENERATED_HEADER = /@generated|generated by|do not edit/i;
|
|
1914
1963
|
var DECISION = /\b(?:if|elif|elsif|for|foreach|while|until|case|when|catch|except|rescue|match|guard|and|or)\b|&&|\|\||\?\?|\s\?(?![,):.?])/g;
|
|
1915
|
-
var COMMENT_OR_STRING = /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|^[ \t]*#[^\n]*)|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/gm;
|
|
1964
|
+
var COMMENT_OR_STRING = /(\/\*[\s\S]*?\*\/|\/\/[^\n]*|^[ \t]*#[^\n]*)|"""[\s\S]*?"""|'''[\s\S]*?'''|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/gm;
|
|
1916
1965
|
function isCandidate(path) {
|
|
1917
1966
|
return SOURCE.test(path) && !TESTS.test(path) && !GENERATED.test(path);
|
|
1918
1967
|
}
|
|
@@ -2162,7 +2211,7 @@ var MODIFIERS = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?
|
|
|
2162
2211
|
var MEMBER = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?[#\w$]+\s*(?:<[^>]*>\s*)?\(`);
|
|
2163
2212
|
var RECEIVER = /^(?:\([^)]*\)\s*)?/;
|
|
2164
2213
|
var STAR = /^\*?\s*/;
|
|
2165
|
-
var HOLDS_MEMBERS = /\b(?:class|interface|trait|impl|
|
|
2214
|
+
var HOLDS_MEMBERS = /\b(?:(?:class|interface|trait|struct|enum)\s|impl[\s<]|(?:record|extension|protocol|object)\s+[A-Z]|companion\s+object\b)/;
|
|
2166
2215
|
var CALL_KEYWORDS = /^(?:if|for|while|switch|catch|return|await|throw|new|else|do|try|super|typeof)\b/;
|
|
2167
2216
|
var LEADING = /^(?:\/\/|\/\*|\*|#(?!!)|@)/;
|
|
2168
2217
|
var LOCAL_BINDING = /^(?:const|let|var)\s/;
|
|
@@ -2173,6 +2222,12 @@ var INDENTED = /\.(?:py|yml|yaml)$/i;
|
|
|
2173
2222
|
var INDENT = /^\s*/;
|
|
2174
2223
|
var CONTINUES = /(?:[=(,[{:?|&+\-*/<>]|=>)$/;
|
|
2175
2224
|
var BODY_OPENER = /\s*\{\s*$/;
|
|
2225
|
+
var PROPERTY_FUNCTION = /^[#\w$]+\s*(?:[?!]?:[^=]*)?[:=]\s*(?:async\s+)?(?:function\b|(?:<[^>]*>\s*)?(?:\([^)]*\)|[\w$]+)\s*(?::[^=]+)?=>|(?:<[^>]*>\s*)?\($)/;
|
|
2226
|
+
var OBJECT_POSITION = /(?:[=(,[:?]|\|\||&&|\breturn|\bdefault)\s*$|\bnew\s+[\w$.]+(?:<[^>]*>)?\s*\([^()]*\)\s*$/;
|
|
2227
|
+
var CASE_LABEL = /(?:^|[\s;{])(?:case\b.*|default\s*):\s*$/;
|
|
2228
|
+
var REGEX_BEFORE = /(?:^|[(,=:[!&|?{};]|\b(?:return|typeof|case|throw|yield|await|in|of))\s*$/;
|
|
2229
|
+
var RUST_CHAR = /^'(?:\\(?:u\{[\da-f]{1,6}\}|x[\da-f]{2}|.)|[^'\\])'/i;
|
|
2230
|
+
var RUST = /\.rs$/i;
|
|
2176
2231
|
var LONGEST_DEFINITION = 400;
|
|
2177
2232
|
var LONGEST_SIGNATURE = 160;
|
|
2178
2233
|
function indentOf2(line) {
|
|
@@ -2181,20 +2236,47 @@ function indentOf2(line) {
|
|
|
2181
2236
|
function escaped(name) {
|
|
2182
2237
|
return name.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
2183
2238
|
}
|
|
2184
|
-
function declares(line, name) {
|
|
2239
|
+
function declares(line, name, inMembers = true) {
|
|
2185
2240
|
const text = line.trim();
|
|
2186
2241
|
const word = new RegExp(String.raw`^${escaped(name)}\b`);
|
|
2187
2242
|
if (DECLARATION.test(text)) {
|
|
2188
2243
|
const rest = text.replace(DECLARATION, "").replace(RECEIVER, "");
|
|
2189
2244
|
return word.test(rest.replace(STAR, ""));
|
|
2190
2245
|
}
|
|
2191
|
-
|
|
2246
|
+
if (!inMembers || line === text || CALL_KEYWORDS.test(text))
|
|
2247
|
+
return false;
|
|
2248
|
+
const named = text.replace(MODIFIERS, "");
|
|
2249
|
+
return word.test(named) && (MEMBER.test(text) && (text.endsWith("{") || text.endsWith(":")) || PROPERTY_FUNCTION.test(named));
|
|
2250
|
+
}
|
|
2251
|
+
function regexEnd(line, start) {
|
|
2252
|
+
let inClass = false;
|
|
2253
|
+
for (let i = start + 1;i < line.length; i++) {
|
|
2254
|
+
const char = line[i];
|
|
2255
|
+
if (char === "\\")
|
|
2256
|
+
i++;
|
|
2257
|
+
else if (char === "[")
|
|
2258
|
+
inClass = true;
|
|
2259
|
+
else if (char === "]")
|
|
2260
|
+
inClass = false;
|
|
2261
|
+
else if (char === "/" && !inClass)
|
|
2262
|
+
return i;
|
|
2263
|
+
}
|
|
2264
|
+
return -1;
|
|
2192
2265
|
}
|
|
2193
|
-
function
|
|
2194
|
-
let braces = 0;
|
|
2195
|
-
let parens = 0;
|
|
2266
|
+
function codeChars(line, quote, rust, each) {
|
|
2196
2267
|
for (let i = 0;i < line.length; i++) {
|
|
2197
2268
|
const char = line[i] ?? "";
|
|
2269
|
+
if (quote.open === "/*") {
|
|
2270
|
+
if (rust && char === "/" && line[i + 1] === "*") {
|
|
2271
|
+
quote.depth++;
|
|
2272
|
+
i++;
|
|
2273
|
+
} else if (char === "*" && line[i + 1] === "/") {
|
|
2274
|
+
quote.depth--;
|
|
2275
|
+
quote.open = quote.depth === 0 ? "" : "/*";
|
|
2276
|
+
i++;
|
|
2277
|
+
}
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2198
2280
|
if (quote.open !== "") {
|
|
2199
2281
|
if (char === "\\")
|
|
2200
2282
|
i++;
|
|
@@ -2204,9 +2286,30 @@ function depthChange(line, quote) {
|
|
|
2204
2286
|
}
|
|
2205
2287
|
if (char === "/" && line[i + 1] === "/")
|
|
2206
2288
|
break;
|
|
2207
|
-
if (char ===
|
|
2289
|
+
if (char === "/" && line[i + 1] === "*") {
|
|
2290
|
+
quote.open = "/*";
|
|
2291
|
+
quote.depth = 1;
|
|
2292
|
+
i++;
|
|
2293
|
+
continue;
|
|
2294
|
+
}
|
|
2295
|
+
const regex = char === "/" && !rust && REGEX_BEFORE.test(line.slice(0, i)) ? regexEnd(line, i) : -1;
|
|
2296
|
+
if (regex !== -1)
|
|
2297
|
+
i = regex;
|
|
2298
|
+
else if (rust && char === "'")
|
|
2299
|
+
i += (RUST_CHAR.exec(line.slice(i))?.[0].length ?? 1) - 1;
|
|
2300
|
+
else if (char === '"' || char === "'" || char === "`")
|
|
2208
2301
|
quote.open = char;
|
|
2209
|
-
else
|
|
2302
|
+
else
|
|
2303
|
+
each(char, i);
|
|
2304
|
+
}
|
|
2305
|
+
if (quote.open !== "`" && quote.open !== "/*")
|
|
2306
|
+
quote.open = "";
|
|
2307
|
+
}
|
|
2308
|
+
function depthChange(line, quote, rust) {
|
|
2309
|
+
let braces = 0;
|
|
2310
|
+
let parens = 0;
|
|
2311
|
+
codeChars(line, quote, rust, (char) => {
|
|
2312
|
+
if (char === "{")
|
|
2210
2313
|
braces++;
|
|
2211
2314
|
else if (char === "}")
|
|
2212
2315
|
braces--;
|
|
@@ -2214,11 +2317,36 @@ function depthChange(line, quote) {
|
|
|
2214
2317
|
parens++;
|
|
2215
2318
|
else if (char === ")" || char === "]")
|
|
2216
2319
|
parens--;
|
|
2217
|
-
}
|
|
2218
|
-
if (quote.open !== "`")
|
|
2219
|
-
quote.open = "";
|
|
2320
|
+
});
|
|
2220
2321
|
return { braces, parens };
|
|
2221
2322
|
}
|
|
2323
|
+
function memberLines(lines, path) {
|
|
2324
|
+
const everywhere = lines.map(() => true);
|
|
2325
|
+
if (INDENTED.test(path))
|
|
2326
|
+
return everywhere;
|
|
2327
|
+
const quote = { open: "", depth: 0 };
|
|
2328
|
+
const rust = RUST.test(path);
|
|
2329
|
+
const open = [];
|
|
2330
|
+
let previous = "";
|
|
2331
|
+
let lost = false;
|
|
2332
|
+
const members = lines.map((line) => {
|
|
2333
|
+
const inMembers = open.at(-1) === true;
|
|
2334
|
+
codeChars(line, quote, rust, (char, index) => {
|
|
2335
|
+
if (char === "}") {
|
|
2336
|
+
lost ||= open.pop() === undefined;
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
if (char !== "{")
|
|
2340
|
+
return;
|
|
2341
|
+
const before = (line.slice(0, index).trim() === "" ? previous : line.slice(0, index)).trimEnd();
|
|
2342
|
+
open.push(HOLDS_MEMBERS.test(before) || OBJECT_POSITION.test(before) && !CASE_LABEL.test(before));
|
|
2343
|
+
});
|
|
2344
|
+
if (line.trim() !== "")
|
|
2345
|
+
previous = line;
|
|
2346
|
+
return inMembers;
|
|
2347
|
+
});
|
|
2348
|
+
return lost || open.length > 0 || quote.open !== "" ? everywhere : members;
|
|
2349
|
+
}
|
|
2222
2350
|
function endOf(lines, start, path) {
|
|
2223
2351
|
const last = Math.min(lines.length - 1, start + LONGEST_DEFINITION - 1);
|
|
2224
2352
|
if (INDENTED.test(path)) {
|
|
@@ -2233,13 +2361,14 @@ function endOf(lines, start, path) {
|
|
|
2233
2361
|
}
|
|
2234
2362
|
return end;
|
|
2235
2363
|
}
|
|
2236
|
-
const quote = { open: "" };
|
|
2364
|
+
const quote = { open: "", depth: 0 };
|
|
2365
|
+
const rust = RUST.test(path);
|
|
2237
2366
|
let braces = 0;
|
|
2238
2367
|
let parens = 0;
|
|
2239
2368
|
let opened = false;
|
|
2240
2369
|
for (let i = start;i <= last; i++) {
|
|
2241
2370
|
const line = lines[i] ?? "";
|
|
2242
|
-
const change = depthChange(line, quote);
|
|
2371
|
+
const change = depthChange(line, quote, rust);
|
|
2243
2372
|
opened ||= change.braces > 0 || line.includes("{");
|
|
2244
2373
|
braces += change.braces;
|
|
2245
2374
|
parens += change.parens;
|
|
@@ -2257,9 +2386,10 @@ function leadingStart(lines, start) {
|
|
|
2257
2386
|
function definitions(text, path, name) {
|
|
2258
2387
|
const lines = text.split(`
|
|
2259
2388
|
`);
|
|
2389
|
+
const members = memberLines(lines, path);
|
|
2260
2390
|
const spans = [];
|
|
2261
2391
|
for (let i = 0;i < lines.length; i++) {
|
|
2262
|
-
if (!declares(lines[i] ?? "", name))
|
|
2392
|
+
if (!declares(lines[i] ?? "", name, members[i]))
|
|
2263
2393
|
continue;
|
|
2264
2394
|
const end = endOf(lines, i, path);
|
|
2265
2395
|
spans.push({ path, from: leadingStart(lines, i) + 1, to: end + 1 });
|
|
@@ -2555,13 +2685,20 @@ var MARKUP = /\.(?:md|mdx|markdown|html?|xml)$/i;
|
|
|
2555
2685
|
var MARKUP_COMMENT = /<!--/;
|
|
2556
2686
|
var CLOSERS = /\s*(?:\*\/|-->)\s*$/;
|
|
2557
2687
|
var MARKER = /^(?:@|\[)?(TODO|FIXME|HACK|XXX)\b/;
|
|
2558
|
-
var QUOTES = ["'", '"', "`"];
|
|
2688
|
+
var QUOTES = new Set(["'", '"', "`"]);
|
|
2559
2689
|
var ESCAPE2 = /\\./g;
|
|
2560
2690
|
var AFTER_FIRST_LINE = /\n[\s\S]*/;
|
|
2561
2691
|
var REF = /(?<![\w./-])(\w[\w.-]*\/(?!\.+#)[\w.][\w.-]*)#(\d+)\b/g;
|
|
2692
|
+
var FILE_ANCHOR = /\.(?:md|mdx|markdown|txt|rst|adoc|html?)$/i;
|
|
2562
2693
|
function isQuoted(line, index) {
|
|
2563
|
-
|
|
2564
|
-
|
|
2694
|
+
let open;
|
|
2695
|
+
for (const char of line.slice(0, index).replaceAll(ESCAPE2, "")) {
|
|
2696
|
+
if (open === undefined && QUOTES.has(char))
|
|
2697
|
+
open = char;
|
|
2698
|
+
else if (char === open)
|
|
2699
|
+
open = undefined;
|
|
2700
|
+
}
|
|
2701
|
+
return open !== undefined;
|
|
2565
2702
|
}
|
|
2566
2703
|
var BLAME_HEADER = /^[0-9a-f]{40} \d+ (\d+)/;
|
|
2567
2704
|
var DAY_S = 86400;
|
|
@@ -2573,7 +2710,7 @@ async function commitTimes(path, cwd) {
|
|
|
2573
2710
|
const bySha = new Map;
|
|
2574
2711
|
let sha = "";
|
|
2575
2712
|
let line = 0;
|
|
2576
|
-
for (const row of
|
|
2713
|
+
for (const row of blamed.stdout.split(`
|
|
2577
2714
|
`)) {
|
|
2578
2715
|
const header = BLAME_HEADER.exec(row);
|
|
2579
2716
|
if (header !== null) {
|
|
@@ -2607,15 +2744,12 @@ function marksIn(text, path) {
|
|
|
2607
2744
|
continue;
|
|
2608
2745
|
const body = line.slice(opener.index + opener[0].length).replace(CLOSERS, "").trim();
|
|
2609
2746
|
const marker = MARKER.exec(body)?.[1];
|
|
2610
|
-
const refs = [...body.matchAll(REF)].map((found) => ({ repo: found[1] ?? "", number: Number(found[2]) }));
|
|
2747
|
+
const refs = [...body.matchAll(REF)].filter((found) => !FILE_ANCHOR.test(found[1] ?? "")).map((found) => ({ repo: found[1] ?? "", number: Number(found[2]) }));
|
|
2611
2748
|
if (marker !== undefined || refs.length > 0)
|
|
2612
2749
|
marks.push({ path, line: i + 1, kind: marker ?? "ref", text: body, refs });
|
|
2613
2750
|
}
|
|
2614
2751
|
return marks;
|
|
2615
2752
|
}
|
|
2616
|
-
function stdoutOf(chunks) {
|
|
2617
|
-
return Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
2618
|
-
}
|
|
2619
2753
|
function refKey(ref) {
|
|
2620
2754
|
return `${ref.repo}#${ref.number}`;
|
|
2621
2755
|
}
|
|
@@ -2624,7 +2758,7 @@ async function lookUpOnGitHub(repo, numbers, cwd) {
|
|
|
2624
2758
|
for (const ran of await Promise.all(numbers.map(async (number) => ({ number, ran: await runCommand(["gh", "api", `repos/${repo}/issues/${number}`, "--jq", ".state"], { cwd }) })))) {
|
|
2625
2759
|
if (ran.ran.code !== 0)
|
|
2626
2760
|
return ran.ran.text.trim().replace(AFTER_FIRST_LINE, "");
|
|
2627
|
-
states.set(refKey({ repo, number: Number(ran.number) }),
|
|
2761
|
+
states.set(refKey({ repo, number: Number(ran.number) }), ran.ran.stdout.trim());
|
|
2628
2762
|
}
|
|
2629
2763
|
return states;
|
|
2630
2764
|
}
|
|
@@ -2644,7 +2778,7 @@ async function lookUp(refs, cwd) {
|
|
|
2644
2778
|
}
|
|
2645
2779
|
continue;
|
|
2646
2780
|
}
|
|
2647
|
-
const parsed = JSON.parse(
|
|
2781
|
+
const parsed = JSON.parse(ran.stdout);
|
|
2648
2782
|
for (const issue of Array.isArray(parsed) ? parsed : [parsed])
|
|
2649
2783
|
lookup.states.set(refKey({ repo, number: issue.number }), issue.state);
|
|
2650
2784
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-code",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.3",
|
|
5
5
|
"description": "src: source read by spans, symbols and outlines in one call, the TODO and issue-reference comments of a repository with stale ones flagged, and the files ranked by complexity times git churn.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "$npm_execpath build src/cli.ts --target bun --outdir dist",
|
|
36
|
+
"build": "$npm_execpath build src/cli.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
|
|
37
37
|
"src": "$npm_execpath src/cli.ts"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@kaynooo/utils": "3.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@kaynooo/cli-kit": "0.
|
|
43
|
+
"@kaynooo/cli-kit": "0.46.4"
|
|
44
44
|
}
|
|
45
45
|
}
|