@kaynooo/cli-code 0.7.1 → 0.7.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 CHANGED
@@ -37,6 +37,6 @@ hotspots --since '3 months ago' --limit 10
37
37
  ## hotspots
38
38
 
39
39
  - `hotspots [dir]` ranks the source files by complexity times churn, so the files both hard to read and often edited come first: rank, score, churn, recent, complexity, lines, file and the file's most complex declaration. The files are the ones git keeps (`.gitignore` honoured).
40
- - 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 so the bin needs no dependency and reads any language the same way.
40
+ - 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.
41
41
  - `--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.
42
42
  - Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
package/dist/hotspots.js CHANGED
@@ -943,10 +943,10 @@ var {Glob } = globalThis.Bun;
943
943
  var SESSION_FILES = new Glob("*.json");
944
944
  var ACCOUNT_DIRS = new Glob("*/sessions");
945
945
  // package.json
946
- var version = "0.7.1";
946
+ var version = "0.7.2";
947
947
 
948
948
  // src/churn.ts
949
- var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
949
+ var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|kay|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
950
950
  var TESTS = /(?:^|\/)(?:tests?|__tests__|spec|e2e|__mocks__|fixtures)\/|\.(?:test|spec|bench)\.[^/]+$|(?:^|\/)test_[^/]+$|_test\.(?:go|py)$/;
951
951
  var GENERATED = /(?:^|\/)(?:dist|build|out|generated|\.nuxt|\.output|\.next)\/|\.min\.[cm]?js$|\.d\.ts$|\.(?:generated|gen)\.[^/]+$|\.pb\.go$|\.snap$/;
952
952
  var LEADING_NEWLINE = /^\n/;
@@ -1028,6 +1028,13 @@ async function readText(path) {
1028
1028
  var CONTAINER = /^(?:(?:export|default|declare|abstract|final|readonly|public|pub|private|protected|internal|sealed|data|open)\s+)*(?:class|impl|trait|interface|namespace|module|object|mod|struct|enum)\b/;
1029
1029
  var CLOSER = /^[\s)\]};]*$|^\s*(?:\/\/|\/\*|\*|#)/;
1030
1030
  var LONGEST_NAME2 = 60;
1031
+ var MARKUP_BLOCK = /^<(template|style)\b[\s\S]*?\n<\/\1>/gm;
1032
+ var KAY_FILE = /^---\n([\s\S]*?\n)---(?:\n|$)([\s\S]*)$/;
1033
+ function blanked(text) {
1034
+ return `
1035
+ `.repeat(text.split(`
1036
+ `).length - 1);
1037
+ }
1031
1038
  function indentOf(line) {
1032
1039
  return line.length - line.trimStart().length;
1033
1040
  }
@@ -1056,8 +1063,11 @@ function unitsAt(lines, from, to, indent) {
1056
1063
  `)) }];
1057
1064
  });
1058
1065
  }
1059
- function worstUnit(text) {
1060
- const lines = text.split(`
1066
+ function worstUnit(text, path = "") {
1067
+ const code = path.endsWith(".kay") ? text.replace(KAY_FILE, (_, script, template) => `
1068
+ ${script}
1069
+ ${blanked(template)}`) : text.replace(MARKUP_BLOCK, blanked);
1070
+ const lines = code.split(`
1061
1071
  `);
1062
1072
  const top = unitsAt(lines, 0, lines.length, 0);
1063
1073
  return top.reduce((worst, unit) => worst === undefined || unit.complexity > worst.complexity ? unit : worst, undefined);
@@ -1106,7 +1116,7 @@ async function main(args) {
1106
1116
  if (text === undefined || values.all !== true && isGenerated(text))
1107
1117
  continue;
1108
1118
  const complexity = complexityOf(text);
1109
- const worst = worstUnit(text);
1119
+ const worst = worstUnit(text, path);
1110
1120
  ranked.push({ path, score: Math.round(complexity * touched.weight), churn: touched.commits, recent: Math.round(touched.weight * 10) / 10, complexity, worst: worst === undefined ? undefined : { name: worst.name, line: worst.line, complexity: worst.complexity }, lines: text.split(`
1111
1121
  `).length - (text.endsWith(`
1112
1122
  `) ? 1 : 0) });
package/dist/peek.js CHANGED
@@ -944,7 +944,7 @@ var {Glob } = globalThis.Bun;
944
944
  var SESSION_FILES = new Glob("*.json");
945
945
  var ACCOUNT_DIRS = new Glob("*/sessions");
946
946
  // package.json
947
- var version = "0.7.1";
947
+ var version = "0.7.2";
948
948
 
949
949
  // src/files.ts
950
950
  import { existsSync, readdirSync, statSync } from "fs";
package/dist/todo-scan.js CHANGED
@@ -943,7 +943,7 @@ var {Glob } = globalThis.Bun;
943
943
  var SESSION_FILES = new Glob("*.json");
944
944
  var ACCOUNT_DIRS = new Glob("*/sessions");
945
945
  // package.json
946
- var version = "0.7.1";
946
+ var version = "0.7.2";
947
947
 
948
948
  // src/files.ts
949
949
  import { existsSync, readdirSync, statSync } from "fs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-code",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.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",