@shvmgyl15/tsgraph 0.1.0 → 0.2.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.
Files changed (55) hide show
  1. package/dist/changes/index.test.js +2 -6
  2. package/dist/changes/index.test.js.map +1 -1
  3. package/dist/cli/index.js +184 -4
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/git/index.test.js +4 -6
  6. package/dist/git/index.test.js.map +1 -1
  7. package/dist/opencode/index.js +1 -1
  8. package/dist/opencode/index.js.map +1 -1
  9. package/dist/opencode/index.test.js +2 -2
  10. package/dist/opencode/index.test.js.map +1 -1
  11. package/dist/search/index.d.ts.map +1 -1
  12. package/dist/search/index.js +12 -4
  13. package/dist/search/index.js.map +1 -1
  14. package/package.json +16 -1
  15. package/AGENTS.md +0 -64
  16. package/TODOS.md +0 -61
  17. package/opencode.json +0 -24
  18. package/src/analysis/analysis.test.ts +0 -405
  19. package/src/analysis/complexity.ts +0 -107
  20. package/src/analysis/coupling.ts +0 -106
  21. package/src/analysis/hotspot.ts +0 -52
  22. package/src/analysis/index.ts +0 -17
  23. package/src/boundaries/index.test.ts +0 -335
  24. package/src/boundaries/index.ts +0 -137
  25. package/src/changes/index.test.ts +0 -114
  26. package/src/changes/index.ts +0 -95
  27. package/src/cli/index.ts +0 -736
  28. package/src/git/index.test.ts +0 -92
  29. package/src/git/index.ts +0 -86
  30. package/src/graph/types.test.ts +0 -383
  31. package/src/graph/types.ts +0 -353
  32. package/src/mcp/mcp.test.ts +0 -176
  33. package/src/mcp/server.ts +0 -217
  34. package/src/nextjs/index.ts +0 -23
  35. package/src/nextjs/nextjs.test.ts +0 -233
  36. package/src/nextjs/pages.ts +0 -43
  37. package/src/nextjs/react.ts +0 -100
  38. package/src/nextjs/router.ts +0 -102
  39. package/src/nextjs/routes.ts +0 -69
  40. package/src/opencode/index.test.ts +0 -90
  41. package/src/opencode/index.ts +0 -83
  42. package/src/parser/index.ts +0 -339
  43. package/src/parser/parser.test.ts +0 -282
  44. package/src/plan/index.test.ts +0 -162
  45. package/src/plan/index.ts +0 -161
  46. package/src/report/index.ts +0 -128
  47. package/src/scanner/index.ts +0 -97
  48. package/src/scanner/scanner.test.ts +0 -135
  49. package/src/search/index.ts +0 -163
  50. package/src/search/search.test.ts +0 -512
  51. package/src/traversal/index.ts +0 -5
  52. package/src/traversal/traversal.test.ts +0 -266
  53. package/src/traversal/traversal.ts +0 -185
  54. package/tsconfig.json +0 -20
  55. package/vitest.config.ts +0 -7
@@ -1,114 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- makeGraph,
4
- makeFileNode,
5
- makeSymbolNode,
6
- makeImportEdge,
7
- } from "../graph/types.js";
8
- import { getChanges, getStale } from "./index.js";
9
- import path from "node:path";
10
- import fs from "node:fs";
11
- import os from "node:os";
12
- import { execSync } from "node:child_process";
13
-
14
- function createGitRepo(): string {
15
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tsgraph-changes-"));
16
- execSync("git init", { cwd: dir, stdio: "pipe" });
17
- execSync('git config user.email "test@test.com"', { cwd: dir, stdio: "pipe" });
18
- execSync('git config user.name "Test"', { cwd: dir, stdio: "pipe" });
19
- return dir;
20
- }
21
-
22
- function writeFile(root: string, relPath: string, content: string) {
23
- const fullPath = path.join(root, relPath);
24
- fs.mkdirSync(path.dirname(fullPath), { recursive: true });
25
- fs.writeFileSync(fullPath, content, "utf-8");
26
- }
27
-
28
- describe("getChanges", () => {
29
- it("returns empty result if not a git repo", () => {
30
- const graph = makeGraph({ files: [], symbols: [], imports: [] });
31
- const result = getChanges(graph, "/tmp/nonexistent");
32
- expect(result.totalFiles).toBe(0);
33
- expect(result.totalSymbols).toBe(0);
34
- });
35
-
36
- it("finds changed files with symbols from a git diff", () => {
37
- const dir = createGitRepo();
38
- writeFile(dir, "src/index.ts", 'export const x = 1;\n');
39
- execSync("git add . && git commit -m 'initial'", { cwd: dir, stdio: "pipe" });
40
- writeFile(dir, "src/lib/util.ts", 'export const util = 2;\n');
41
- execSync("git add . && git commit -m 'add util'", { cwd: dir, stdio: "pipe" });
42
-
43
- const graph = makeGraph({
44
- files: [
45
- makeFileNode({ path: "src/index.ts", packageName: "app" }),
46
- makeFileNode({ path: "src/lib/util.ts", packageName: "app" }),
47
- ],
48
- symbols: [
49
- makeSymbolNode({
50
- name: "x",
51
- kind: "const",
52
- file: "src/index.ts",
53
- packageName: "app",
54
- line: 1,
55
- endLine: 1,
56
- isExported: true,
57
- }),
58
- makeSymbolNode({
59
- name: "util",
60
- kind: "const",
61
- file: "src/lib/util.ts",
62
- packageName: "app",
63
- line: 1,
64
- endLine: 1,
65
- isExported: true,
66
- }),
67
- ],
68
- imports: [],
69
- });
70
-
71
- const result = getChanges(graph, dir, "HEAD~1");
72
- expect(result.totalFiles).toBeGreaterThanOrEqual(1);
73
- expect(result.totalSymbols).toBeGreaterThanOrEqual(1);
74
- const utilFile = result.files.find((f) => f.path === "src/lib/util.ts");
75
- expect(utilFile).toBeTruthy();
76
- fs.rmSync(dir, { recursive: true });
77
- });
78
- });
79
-
80
- describe("getStale", () => {
81
- it("returns empty result if not a git repo", () => {
82
- const graph = makeGraph({ files: [], symbols: [], imports: [] });
83
- const result = getStale(graph, "/tmp/nonexistent");
84
- expect(result.totalFiles).toBe(0);
85
- });
86
-
87
- it("returns files without recent commits", () => {
88
- const dir = createGitRepo();
89
- writeFile(dir, "src/old.ts", 'export const old = 1;\n');
90
- execSync("git add . && git commit -m 'initial'", { cwd: dir, stdio: "pipe" });
91
-
92
- const graph = makeGraph({
93
- files: [
94
- makeFileNode({ path: "src/old.ts", packageName: "app" }),
95
- ],
96
- symbols: [
97
- makeSymbolNode({
98
- name: "old",
99
- kind: "const",
100
- file: "src/old.ts",
101
- packageName: "app",
102
- line: 1,
103
- endLine: 1,
104
- isExported: true,
105
- }),
106
- ],
107
- imports: [],
108
- });
109
-
110
- const result = getStale(graph, dir, 0);
111
- expect(result.totalFiles).toBe(0);
112
- fs.rmSync(dir, { recursive: true });
113
- });
114
- });
@@ -1,95 +0,0 @@
1
- import type { Graph, SymbolNode, FileNode } from "../graph/types.js";
2
- import {
3
- getDiffFiles,
4
- getStaleFiles,
5
- isGitRepo,
6
- } from "../git/index.js";
7
- import type { ChangedFile } from "../git/index.js";
8
-
9
- export interface ChangedSymbolInfo {
10
- symbol: SymbolNode;
11
- file: string;
12
- status: ChangedFile["status"];
13
- }
14
-
15
- export interface ChangeResult {
16
- files: {
17
- path: string;
18
- status: ChangedFile["status"];
19
- symbolCount: number;
20
- }[];
21
- symbols: ChangedSymbolInfo[];
22
- totalFiles: number;
23
- totalSymbols: number;
24
- }
25
-
26
- export interface StaleResult {
27
- files: {
28
- path: string;
29
- symbolCount: number;
30
- symbolNames: string[];
31
- }[];
32
- totalFiles: number;
33
- }
34
-
35
- function symbolsInFile(graph: Graph, filePath: string): SymbolNode[] {
36
- return graph.symbols.filter((s) => s.file === filePath);
37
- }
38
-
39
- export function getChanges(
40
- graph: Graph,
41
- rootDir: string,
42
- base: string = "main",
43
- ): ChangeResult {
44
- if (!isGitRepo(rootDir)) {
45
- return { files: [], symbols: [], totalFiles: 0, totalSymbols: 0 };
46
- }
47
-
48
- const changed = getDiffFiles(rootDir, base);
49
- const files: ChangeResult["files"] = [];
50
- const symbols: ChangedSymbolInfo[] = [];
51
-
52
- for (const c of changed) {
53
- const graphFile = graph.files.find((f) => f.path === c.path);
54
- if (!graphFile) {
55
- files.push({ path: c.path, status: c.status, symbolCount: 0 });
56
- continue;
57
- }
58
- const fileSymbols = symbolsInFile(graph, c.path);
59
- files.push({
60
- path: c.path,
61
- status: c.status,
62
- symbolCount: fileSymbols.length,
63
- });
64
- for (const sym of fileSymbols) {
65
- symbols.push({ symbol: sym, file: c.path, status: c.status });
66
- }
67
- }
68
-
69
- return { files, symbols, totalFiles: files.length, totalSymbols: symbols.length };
70
- }
71
-
72
- export function getStale(
73
- graph: Graph,
74
- rootDir: string,
75
- days: number = 90,
76
- ): StaleResult {
77
- if (!isGitRepo(rootDir)) {
78
- return { files: [], totalFiles: 0 };
79
- }
80
-
81
- const stalePaths = getStaleFiles(rootDir, days);
82
- const files: StaleResult["files"] = [];
83
-
84
- for (const p of stalePaths) {
85
- const syms = symbolsInFile(graph, p);
86
- if (syms.length === 0) continue;
87
- files.push({
88
- path: p,
89
- symbolCount: syms.length,
90
- symbolNames: syms.map((s) => s.name),
91
- });
92
- }
93
-
94
- return { files, totalFiles: files.length };
95
- }