@kaynooo/cli-code 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +44 -14
- package/dist/hotspots-cli.js +44 -14
- package/dist/peek-cli.js +40 -11
- package/dist/todo-scan-cli.js +40 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ hotspots --since '3 months ago' --limit 10
|
|
|
25
25
|
- `--around <regex> -C <n>` prints the `n` (3) lines on each side of each matching line, spans that touch merged, at most 20 spans (`--limit`, `--full`, the count of the rest after them).
|
|
26
26
|
- Piped into with no file and no mode, it reads the `path:line` opening each line of the input (`errs`, `rg -n`, `grep -n`, a linter's `path:line:col`, tsc's `path(line,col)`) and prints the `-C` (3) lines around each, spans that touch merged and files in the order first named; a path outside the repository or not readable is skipped, and nothing readable exits 1.
|
|
27
27
|
- `--json` prints the spans as `[{path, from, to, lines}]`, `--refs` as `[{path, line, text}]` and `--outline` as `[{path, line, depth, text}]`, the lines never cut; a failure prints as `{"error"}` on stderr.
|
|
28
|
-
- `--def`, `--refs` and `--around` look through the paths given, the files git keeps here by default (`git ls-files` with the untracked files `.gitignore` lets through), and outside a repository a walk leaving dot folders and `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` out; binary files and files over 2 MB are skipped.
|
|
28
|
+
- `--def`, `--refs` and `--around` look through the paths given, the files git keeps here by default (`git ls-files` with the untracked files `.gitignore` lets through), and outside a repository a walk leaving dot folders and `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` and the names in the `ignore` array of `~/.config/kaynooo-cli/config.json` out; binary files and files over 2 MB are skipped.
|
|
29
29
|
- The symbols are found by pattern, not by a type checker: a name declared twice in a file shows twice, and a symbol re-exported under another name is not followed.
|
|
30
30
|
- A path must lie inside the repository (a symlink out of it counts as outside), absolute or relative. Exits 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.
|
|
31
31
|
|
|
@@ -41,3 +41,5 @@ hotspots --since '3 months ago' --limit 10
|
|
|
41
41
|
- Churn is the commits touching the file since `--since` (any date git reads, `6 months ago` by default), counted from one `git log`. The score uses `recent`, the commits weighted by age (half as much every `--half-life`, `90d` by default, `0` to count them alike), and leaves out the commits touching more than `--bulk` files (25), the format and rename sweeps. Complexity is the decision points of the file (`if`, loops, `case`, `catch`, `&&`, `||`, `??`, ternaries, `and`/`or`) plus one, counted with comments and strings blanked; it is computed in-house (js, ts, vue, svelte, astro, kay, php, py, go, rs, rb, java, kt, swift, cs, c, cpp, scala, dart, lua and shell files are ranked) so the bin needs no dependency and reads any language the same way.
|
|
42
42
|
- `--limit <n>` (`-n`) sets how many files are listed (20, the count of the rest after them), `--full` lists all, `--json` is never cut unless `--limit` is given. `--all` keeps test files and generated files (`dist/`, `*.d.ts`, `*.min.js`, snapshots, files whose first lines say generated), `--json` prints `[{rank, path, score, churn, recent, complexity, worst, lines}]`. The most complex declaration is found from the indentation alone (a class is opened into its methods), so it reads any language the same way.
|
|
43
43
|
- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
|
|
44
|
+
|
|
45
|
+
`~/.config/kaynooo-cli/hotspots.json` (`$XDG_CONFIG_HOME/kaynooo-cli/` when set) changes the defaults of `hotspots`: `since` (a date as git reads it, `6 months ago`), `bulk` (25) and `limit` (20, the files listed).
|
package/dist/cli.js
CHANGED
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -873,7 +896,7 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
896
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
897
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
898
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
899
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
877
900
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
901
|
import process12 from "process";
|
|
879
902
|
|
|
@@ -1174,7 +1197,7 @@ async function printCandidates(found) {
|
|
|
1174
1197
|
function packageVersion(entry = Bun.main) {
|
|
1175
1198
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1176
1199
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1200
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1178
1201
|
if (typeof version === "string")
|
|
1179
1202
|
return version;
|
|
1180
1203
|
} catch {}
|
|
@@ -1231,6 +1254,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1254
|
}
|
|
1232
1255
|
// ../kit/src/folders.ts
|
|
1233
1256
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1257
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1258
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1259
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1260
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1261
|
+
}
|
|
1234
1262
|
// ../kit/src/limit.ts
|
|
1235
1263
|
function limitOptions(fallback) {
|
|
1236
1264
|
return {
|
|
@@ -1301,11 +1329,11 @@ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
|
|
|
1301
1329
|
}
|
|
1302
1330
|
|
|
1303
1331
|
// src/files.ts
|
|
1304
|
-
import { existsSync as
|
|
1332
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1305
1333
|
import { join as join6, relative } from "path";
|
|
1306
1334
|
var MAX_BYTES = 2000000;
|
|
1307
1335
|
var SNIFF_BYTES = 8000;
|
|
1308
|
-
function walk(dir, found) {
|
|
1336
|
+
function walk(dir, found, ignored) {
|
|
1309
1337
|
let entries;
|
|
1310
1338
|
try {
|
|
1311
1339
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1313,10 +1341,10 @@ function walk(dir, found) {
|
|
|
1313
1341
|
return found;
|
|
1314
1342
|
}
|
|
1315
1343
|
for (const entry of entries) {
|
|
1316
|
-
if (entry.name.startsWith(".") ||
|
|
1344
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1317
1345
|
continue;
|
|
1318
1346
|
if (entry.isDirectory())
|
|
1319
|
-
walk(join6(dir, entry.name), found);
|
|
1347
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1320
1348
|
else if (entry.isFile())
|
|
1321
1349
|
found.push(join6(dir, entry.name));
|
|
1322
1350
|
}
|
|
@@ -1325,9 +1353,10 @@ function walk(dir, found) {
|
|
|
1325
1353
|
async function listFiles(paths, cwd) {
|
|
1326
1354
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1327
1355
|
if (listed.code === 0)
|
|
1328
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1356
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1329
1357
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1330
|
-
|
|
1358
|
+
const ignored = ignoredFolders();
|
|
1359
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1331
1360
|
}
|
|
1332
1361
|
async function readText(path) {
|
|
1333
1362
|
const file = Bun.file(path);
|
|
@@ -1390,11 +1419,12 @@ ${blanked(template)}`) : text.replace(MARKUP_BLOCK, blanked);
|
|
|
1390
1419
|
}
|
|
1391
1420
|
|
|
1392
1421
|
// src/hotspots.ts
|
|
1393
|
-
var
|
|
1394
|
-
var
|
|
1422
|
+
var SETTINGS = readUserConfig("hotspots");
|
|
1423
|
+
var DEFAULT_SINCE = typeof SETTINGS.since === "string" && SETTINGS.since !== "" ? SETTINGS.since : "6 months ago";
|
|
1424
|
+
var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
|
|
1395
1425
|
var DAY_MS2 = 86400000;
|
|
1396
1426
|
var DEFAULT_HALF_LIFE = "90d";
|
|
1397
|
-
var DEFAULT_COUNT = 20;
|
|
1427
|
+
var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
|
|
1398
1428
|
var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1399
1429
|
|
|
1400
1430
|
Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. Each file also shows its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
|
package/dist/hotspots-cli.js
CHANGED
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -873,7 +896,7 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
896
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
897
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
898
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
899
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
877
900
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
901
|
import process12 from "process";
|
|
879
902
|
|
|
@@ -1174,7 +1197,7 @@ async function printCandidates(found) {
|
|
|
1174
1197
|
function packageVersion(entry = Bun.main) {
|
|
1175
1198
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1176
1199
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1200
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1178
1201
|
if (typeof version === "string")
|
|
1179
1202
|
return version;
|
|
1180
1203
|
} catch {}
|
|
@@ -1231,6 +1254,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1254
|
}
|
|
1232
1255
|
// ../kit/src/folders.ts
|
|
1233
1256
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1257
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1258
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1259
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1260
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1261
|
+
}
|
|
1234
1262
|
// ../kit/src/limit.ts
|
|
1235
1263
|
function limitOptions(fallback) {
|
|
1236
1264
|
return {
|
|
@@ -1301,11 +1329,11 @@ async function churnSince(cwd, since, { bulk, halfLifeMs, now = Date.now() }) {
|
|
|
1301
1329
|
}
|
|
1302
1330
|
|
|
1303
1331
|
// src/files.ts
|
|
1304
|
-
import { existsSync as
|
|
1332
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1305
1333
|
import { join as join6, relative } from "path";
|
|
1306
1334
|
var MAX_BYTES = 2000000;
|
|
1307
1335
|
var SNIFF_BYTES = 8000;
|
|
1308
|
-
function walk(dir, found) {
|
|
1336
|
+
function walk(dir, found, ignored) {
|
|
1309
1337
|
let entries;
|
|
1310
1338
|
try {
|
|
1311
1339
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1313,10 +1341,10 @@ function walk(dir, found) {
|
|
|
1313
1341
|
return found;
|
|
1314
1342
|
}
|
|
1315
1343
|
for (const entry of entries) {
|
|
1316
|
-
if (entry.name.startsWith(".") ||
|
|
1344
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1317
1345
|
continue;
|
|
1318
1346
|
if (entry.isDirectory())
|
|
1319
|
-
walk(join6(dir, entry.name), found);
|
|
1347
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1320
1348
|
else if (entry.isFile())
|
|
1321
1349
|
found.push(join6(dir, entry.name));
|
|
1322
1350
|
}
|
|
@@ -1325,9 +1353,10 @@ function walk(dir, found) {
|
|
|
1325
1353
|
async function listFiles(paths, cwd) {
|
|
1326
1354
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1327
1355
|
if (listed.code === 0)
|
|
1328
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1356
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1329
1357
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1330
|
-
|
|
1358
|
+
const ignored = ignoredFolders();
|
|
1359
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1331
1360
|
}
|
|
1332
1361
|
async function readText(path) {
|
|
1333
1362
|
const file = Bun.file(path);
|
|
@@ -1390,11 +1419,12 @@ ${blanked(template)}`) : text.replace(MARKUP_BLOCK, blanked);
|
|
|
1390
1419
|
}
|
|
1391
1420
|
|
|
1392
1421
|
// src/hotspots.ts
|
|
1393
|
-
var
|
|
1394
|
-
var
|
|
1422
|
+
var SETTINGS = readUserConfig("hotspots");
|
|
1423
|
+
var DEFAULT_SINCE = typeof SETTINGS.since === "string" && SETTINGS.since !== "" ? SETTINGS.since : "6 months ago";
|
|
1424
|
+
var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
|
|
1395
1425
|
var DAY_MS2 = 86400000;
|
|
1396
1426
|
var DEFAULT_HALF_LIFE = "90d";
|
|
1397
|
-
var DEFAULT_COUNT = 20;
|
|
1427
|
+
var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
|
|
1398
1428
|
var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1399
1429
|
|
|
1400
1430
|
Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. Each file also shows its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
|
package/dist/peek-cli.js
CHANGED
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -873,7 +896,7 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
896
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
897
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
898
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
899
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
877
900
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
901
|
import process12 from "process";
|
|
879
902
|
|
|
@@ -1174,7 +1197,7 @@ async function printCandidates(found) {
|
|
|
1174
1197
|
function packageVersion(entry = Bun.main) {
|
|
1175
1198
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1176
1199
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1200
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1178
1201
|
if (typeof version === "string")
|
|
1179
1202
|
return version;
|
|
1180
1203
|
} catch {}
|
|
@@ -1231,6 +1254,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1254
|
}
|
|
1232
1255
|
// ../kit/src/folders.ts
|
|
1233
1256
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1257
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1258
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1259
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1260
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1261
|
+
}
|
|
1234
1262
|
// ../kit/src/limit.ts
|
|
1235
1263
|
function limitOptions(fallback) {
|
|
1236
1264
|
return {
|
|
@@ -1264,11 +1292,11 @@ import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolv
|
|
|
1264
1292
|
import process14 from "process";
|
|
1265
1293
|
|
|
1266
1294
|
// src/files.ts
|
|
1267
|
-
import { existsSync as
|
|
1295
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1268
1296
|
import { join as join6, relative } from "path";
|
|
1269
1297
|
var MAX_BYTES = 2000000;
|
|
1270
1298
|
var SNIFF_BYTES = 8000;
|
|
1271
|
-
function walk(dir, found) {
|
|
1299
|
+
function walk(dir, found, ignored) {
|
|
1272
1300
|
let entries;
|
|
1273
1301
|
try {
|
|
1274
1302
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1276,10 +1304,10 @@ function walk(dir, found) {
|
|
|
1276
1304
|
return found;
|
|
1277
1305
|
}
|
|
1278
1306
|
for (const entry of entries) {
|
|
1279
|
-
if (entry.name.startsWith(".") ||
|
|
1307
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1280
1308
|
continue;
|
|
1281
1309
|
if (entry.isDirectory())
|
|
1282
|
-
walk(join6(dir, entry.name), found);
|
|
1310
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1283
1311
|
else if (entry.isFile())
|
|
1284
1312
|
found.push(join6(dir, entry.name));
|
|
1285
1313
|
}
|
|
@@ -1288,9 +1316,10 @@ function walk(dir, found) {
|
|
|
1288
1316
|
async function listFiles(paths, cwd) {
|
|
1289
1317
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1290
1318
|
if (listed.code === 0)
|
|
1291
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1319
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1292
1320
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1293
|
-
|
|
1321
|
+
const ignored = ignoredFolders();
|
|
1322
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1294
1323
|
}
|
|
1295
1324
|
async function readText(path) {
|
|
1296
1325
|
const file = Bun.file(path);
|
package/dist/todo-scan-cli.js
CHANGED
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -873,7 +896,7 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
896
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
897
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
898
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
899
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
877
900
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
901
|
import process12 from "process";
|
|
879
902
|
|
|
@@ -1174,7 +1197,7 @@ async function printCandidates(found) {
|
|
|
1174
1197
|
function packageVersion(entry = Bun.main) {
|
|
1175
1198
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1176
1199
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1200
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1178
1201
|
if (typeof version === "string")
|
|
1179
1202
|
return version;
|
|
1180
1203
|
} catch {}
|
|
@@ -1231,6 +1254,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1254
|
}
|
|
1232
1255
|
// ../kit/src/folders.ts
|
|
1233
1256
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1257
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1258
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1259
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1260
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1261
|
+
}
|
|
1234
1262
|
// ../kit/src/limit.ts
|
|
1235
1263
|
function limitOptions(fallback) {
|
|
1236
1264
|
return {
|
|
@@ -1263,11 +1291,11 @@ import { join as join7 } from "path";
|
|
|
1263
1291
|
import process14 from "process";
|
|
1264
1292
|
|
|
1265
1293
|
// src/files.ts
|
|
1266
|
-
import { existsSync as
|
|
1294
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1267
1295
|
import { join as join6, relative } from "path";
|
|
1268
1296
|
var MAX_BYTES = 2000000;
|
|
1269
1297
|
var SNIFF_BYTES = 8000;
|
|
1270
|
-
function walk(dir, found) {
|
|
1298
|
+
function walk(dir, found, ignored) {
|
|
1271
1299
|
let entries;
|
|
1272
1300
|
try {
|
|
1273
1301
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1275,10 +1303,10 @@ function walk(dir, found) {
|
|
|
1275
1303
|
return found;
|
|
1276
1304
|
}
|
|
1277
1305
|
for (const entry of entries) {
|
|
1278
|
-
if (entry.name.startsWith(".") ||
|
|
1306
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1279
1307
|
continue;
|
|
1280
1308
|
if (entry.isDirectory())
|
|
1281
|
-
walk(join6(dir, entry.name), found);
|
|
1309
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1282
1310
|
else if (entry.isFile())
|
|
1283
1311
|
found.push(join6(dir, entry.name));
|
|
1284
1312
|
}
|
|
@@ -1287,9 +1315,10 @@ function walk(dir, found) {
|
|
|
1287
1315
|
async function listFiles(paths, cwd) {
|
|
1288
1316
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1289
1317
|
if (listed.code === 0)
|
|
1290
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1318
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1291
1319
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1292
|
-
|
|
1320
|
+
const ignored = ignoredFolders();
|
|
1321
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1293
1322
|
}
|
|
1294
1323
|
async function readText(path) {
|
|
1295
1324
|
const file = Bun.file(path);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-code",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.2",
|
|
5
5
|
"description": "peek, todo-scan and hotspots: 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",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"@kaynooo/utils": "3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@kaynooo/cli-kit": "0.
|
|
49
|
+
"@kaynooo/cli-kit": "0.37.0"
|
|
50
50
|
}
|
|
51
51
|
}
|