@syke1/mcp-server 1.3.8 → 1.3.9

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/graph.js CHANGED
@@ -38,6 +38,7 @@ exports.getGraph = getGraph;
38
38
  exports.refreshGraph = refreshGraph;
39
39
  const path = __importStar(require("path"));
40
40
  const plugin_1 = require("./languages/plugin");
41
+ const typescript_1 = require("./languages/typescript");
41
42
  let cachedGraph = null;
42
43
  function buildGraph(projectRoot, packageName) {
43
44
  const detectedPlugins = (0, plugin_1.detectLanguages)(projectRoot);
@@ -103,5 +104,6 @@ function getGraph(projectRoot, packageName) {
103
104
  }
104
105
  function refreshGraph(projectRoot, packageName) {
105
106
  cachedGraph = null;
107
+ (0, typescript_1.clearAliasCache)();
106
108
  return buildGraph(projectRoot, packageName);
107
109
  }
@@ -1,2 +1,4 @@
1
1
  import { LanguagePlugin } from "./plugin";
2
+ /** Clear cached aliases (call on project switch / graph refresh) */
3
+ export declare function clearAliasCache(): void;
2
4
  export declare const typescriptPlugin: LanguagePlugin;
@@ -34,12 +34,53 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.typescriptPlugin = void 0;
37
+ exports.clearAliasCache = clearAliasCache;
37
38
  const fs = __importStar(require("fs"));
38
39
  const path = __importStar(require("path"));
39
40
  const plugin_1 = require("./plugin");
40
41
  const TS_IMPORT_RE = /(?:import|export)\s+.*?from\s+['"](.+?)['"]/;
41
42
  const TS_SIDE_EFFECT_RE = /^import\s+['"](.+?)['"]/;
42
43
  const JS_REQUIRE_RE = /(?:const|let|var)\s+\w+\s*=\s*require\s*\(\s*['"](.+?)['"]\s*\)/;
44
+ const aliasCache = new Map(); // projectRoot → aliases
45
+ function loadPathAliases(projectRoot) {
46
+ if (aliasCache.has(projectRoot))
47
+ return aliasCache.get(projectRoot);
48
+ const aliases = [];
49
+ try {
50
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
51
+ if (!fs.existsSync(tsconfigPath)) {
52
+ aliasCache.set(projectRoot, aliases);
53
+ return aliases;
54
+ }
55
+ // Strip single-line comments (// ...) and trailing commas for lenient parsing
56
+ const raw = fs.readFileSync(tsconfigPath, "utf-8")
57
+ .replace(/\/\/.*$/gm, "")
58
+ .replace(/,\s*([\]}])/g, "$1");
59
+ const tsconfig = JSON.parse(raw);
60
+ const paths = tsconfig?.compilerOptions?.paths;
61
+ const baseUrl = tsconfig?.compilerOptions?.baseUrl || ".";
62
+ if (!paths) {
63
+ aliasCache.set(projectRoot, aliases);
64
+ return aliases;
65
+ }
66
+ const baseDir = path.resolve(projectRoot, baseUrl);
67
+ for (const [pattern, targets] of Object.entries(paths)) {
68
+ // Pattern like "@/*" → prefix "@/", target "./src/*" → baseDir + "src"
69
+ const prefix = pattern.endsWith("/*") ? pattern.slice(0, -1) : pattern;
70
+ const resolvedTargets = [];
71
+ for (const target of targets) {
72
+ const stripped = target.endsWith("/*") ? target.slice(0, -1) : target;
73
+ resolvedTargets.push(path.resolve(baseDir, stripped));
74
+ }
75
+ aliases.push({ prefix, targets: resolvedTargets });
76
+ }
77
+ }
78
+ catch (_) {
79
+ // Ignore parse errors
80
+ }
81
+ aliasCache.set(projectRoot, aliases);
82
+ return aliases;
83
+ }
43
84
  function resolveTsImport(fromDir, importPath) {
44
85
  const base = path.resolve(fromDir, importPath);
45
86
  const candidates = [
@@ -49,6 +90,7 @@ function resolveTsImport(fromDir, importPath) {
49
90
  base + ".js",
50
91
  base + ".jsx",
51
92
  path.join(base, "index.ts"),
93
+ path.join(base, "index.tsx"),
52
94
  path.join(base, "index.js"),
53
95
  ];
54
96
  for (const candidate of candidates) {
@@ -58,6 +100,24 @@ function resolveTsImport(fromDir, importPath) {
58
100
  }
59
101
  return null;
60
102
  }
103
+ /** Clear cached aliases (call on project switch / graph refresh) */
104
+ function clearAliasCache() {
105
+ aliasCache.clear();
106
+ }
107
+ function resolveAliasImport(importPath, projectRoot) {
108
+ const aliases = loadPathAliases(projectRoot);
109
+ for (const alias of aliases) {
110
+ if (importPath.startsWith(alias.prefix)) {
111
+ const rest = importPath.slice(alias.prefix.length);
112
+ for (const targetDir of alias.targets) {
113
+ const resolved = resolveTsImport(targetDir, "./" + rest);
114
+ if (resolved)
115
+ return resolved;
116
+ }
117
+ }
118
+ }
119
+ return null;
120
+ }
61
121
  exports.typescriptPlugin = {
62
122
  id: "typescript",
63
123
  name: "TypeScript",
@@ -82,7 +142,7 @@ exports.typescriptPlugin = {
82
142
  discoverFiles(dir) {
83
143
  return (0, plugin_1.discoverAllFiles)(dir, [".ts", ".tsx", ".js", ".jsx"]).filter(f => !f.endsWith(".d.ts"));
84
144
  },
85
- parseImports(filePath, _projectRoot, _sourceDir) {
145
+ parseImports(filePath, projectRoot, _sourceDir) {
86
146
  let content;
87
147
  try {
88
148
  content = fs.readFileSync(filePath, "utf-8");
@@ -100,11 +160,19 @@ exports.typescriptPlugin = {
100
160
  importPath = match[1];
101
161
  if (!importPath)
102
162
  continue;
103
- if (!importPath.startsWith("."))
104
- continue;
105
- const resolved = resolveTsImport(fileDir, importPath);
106
- if (resolved)
107
- imports.push(resolved);
163
+ // Skip bare package imports (e.g. "react", "next/link", "firebase/app")
164
+ if (importPath.startsWith(".")) {
165
+ // Relative import
166
+ const resolved = resolveTsImport(fileDir, importPath);
167
+ if (resolved)
168
+ imports.push(resolved);
169
+ }
170
+ else {
171
+ // Try path alias resolution (e.g. @/components/Sidebar → projectRoot/components/Sidebar)
172
+ const resolved = resolveAliasImport(importPath, projectRoot);
173
+ if (resolved)
174
+ imports.push(resolved);
175
+ }
108
176
  }
109
177
  return imports;
110
178
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syke1/mcp-server",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "mcpName": "io.github.khalomsky/syke",
5
5
  "description": "AI code impact analysis MCP server — dependency graphs, cascade detection, and a mandatory build gate for AI coding agents",
6
6
  "main": "dist/index.js",