typegraph-mcp 0.9.46 → 0.9.48

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/benchmark.js CHANGED
@@ -11,6 +11,30 @@ import * as fs from "fs";
11
11
  import { createRequire } from "module";
12
12
  var log = (...args) => console.error("[typegraph/tsserver]", ...args);
13
13
  var REQUEST_TIMEOUT_MS = 1e4;
14
+ function readPackageVersion(packagePath) {
15
+ const pkg = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
16
+ return pkg.version ?? "unknown";
17
+ }
18
+ function resolveTsServer(projectRoot2) {
19
+ const projectRequire = createRequire(path.resolve(projectRoot2, "package.json"));
20
+ let projectVersion;
21
+ try {
22
+ const packagePath2 = projectRequire.resolve("typescript/package.json");
23
+ projectVersion = readPackageVersion(packagePath2);
24
+ const serverPath2 = projectRequire.resolve("typescript/lib/tsserver.js");
25
+ return { path: serverPath2, version: projectVersion, source: "project" };
26
+ } catch {
27
+ }
28
+ const toolRequire = createRequire(import.meta.url);
29
+ const packagePath = toolRequire.resolve("typescript/package.json");
30
+ const serverPath = toolRequire.resolve("typescript/lib/tsserver.js");
31
+ return {
32
+ path: serverPath,
33
+ version: readPackageVersion(packagePath),
34
+ source: "typegraph",
35
+ projectVersion
36
+ };
37
+ }
14
38
  var TsServerClient = class {
15
39
  constructor(projectRoot2, tsconfigPath2 = "./tsconfig.json") {
16
40
  this.projectRoot = projectRoot2;
@@ -47,9 +71,12 @@ var TsServerClient = class {
47
71
  // ─── Lifecycle ──────────────────────────────────────────────────────────
48
72
  async start() {
49
73
  if (this.child) return;
50
- const require2 = createRequire(path.resolve(this.projectRoot, "package.json"));
51
- const tsserverPath = require2.resolve("typescript/lib/tsserver.js");
52
- log(`Spawning tsserver: ${tsserverPath}`);
74
+ const resolution = resolveTsServer(this.projectRoot);
75
+ const tsserverPath = resolution.path;
76
+ const fallbackNote = resolution.projectVersion ? `; project TypeScript ${resolution.projectVersion} has no legacy tsserver` : "";
77
+ log(
78
+ `Spawning tsserver: ${tsserverPath} (TypeScript ${resolution.version}, ${resolution.source}${fallbackNote})`
79
+ );
53
80
  log(`Project root: ${this.projectRoot}`);
54
81
  log(`tsconfig: ${this.tsconfigPath}`);
55
82
  this.child = spawn("node", [tsserverPath, "--disableAutomaticTypingAcquisition"], {
@@ -78,12 +105,9 @@ var TsServerClient = class {
78
105
  }
79
106
  });
80
107
  const warmStart = performance.now();
81
- const tsconfigAbs = this.resolvePath(this.tsconfigPath);
82
- if (fs.existsSync(tsconfigAbs)) {
83
- await this.sendRequest("compilerOptionsForInferredProjects", {
84
- options: { allowJs: true, checkJs: false }
85
- });
86
- }
108
+ await this.sendRequest("compilerOptionsForInferredProjects", {
109
+ options: { allowJs: true, checkJs: false }
110
+ });
87
111
  this.ready = true;
88
112
  log(`Ready [${(performance.now() - warmStart).toFixed(0)}ms configure]`);
89
113
  }
@@ -327,8 +351,19 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
327
351
  "coverage"
328
352
  ]);
329
353
  var SKIP_FILES = /* @__PURE__ */ new Set(["routeTree.gen.ts"]);
330
- function discoverFiles(rootDir) {
354
+ function normalizeExcludedPaths(rootDir, excludedPaths) {
355
+ return excludedPaths.map(
356
+ (excludedPath) => path2.resolve(rootDir, excludedPath)
357
+ );
358
+ }
359
+ function isExcluded(filePath, excludedPaths) {
360
+ return excludedPaths.some(
361
+ (excludedPath) => filePath === excludedPath || filePath.startsWith(excludedPath + path2.sep)
362
+ );
363
+ }
364
+ function discoverFiles(rootDir, excludedPaths = []) {
331
365
  const files = [];
366
+ const normalizedExclusions = normalizeExcludedPaths(rootDir, excludedPaths);
332
367
  function walk(dir) {
333
368
  let entries;
334
369
  try {
@@ -340,7 +375,9 @@ function discoverFiles(rootDir) {
340
375
  if (entry.isDirectory()) {
341
376
  if (SKIP_DIRS.has(entry.name)) continue;
342
377
  if (entry.name.startsWith(".") && dir !== rootDir) continue;
343
- walk(path2.join(dir, entry.name));
378
+ const childDir = path2.join(dir, entry.name);
379
+ if (isExcluded(childDir, normalizedExclusions)) continue;
380
+ walk(childDir);
344
381
  } else if (entry.isFile()) {
345
382
  const name = entry.name;
346
383
  if (SKIP_FILES.has(name)) continue;
@@ -441,11 +478,9 @@ function resolveProjectImport(resolver, fromDir, specifier, projectRoot2) {
441
478
  return null;
442
479
  }
443
480
  function createResolver(projectRoot2, tsconfigPath2) {
481
+ const configFile = path2.resolve(projectRoot2, tsconfigPath2);
444
482
  return new ResolverFactory({
445
- tsconfig: {
446
- configFile: path2.resolve(projectRoot2, tsconfigPath2),
447
- references: "auto"
448
- },
483
+ ...fs2.existsSync(configFile) ? { tsconfig: { configFile, references: "auto" } } : {},
449
484
  extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"],
450
485
  extensionAlias: {
451
486
  ".js": [".ts", ".tsx", ".js"],
@@ -511,10 +546,10 @@ function buildReverseMap(forward) {
511
546
  }
512
547
  return reverse;
513
548
  }
514
- async function buildGraph(projectRoot2, tsconfigPath2) {
549
+ async function buildGraph(projectRoot2, tsconfigPath2, excludedPaths = []) {
515
550
  const startTime = performance.now();
516
551
  const resolver = createResolver(projectRoot2, tsconfigPath2);
517
- const fileList = discoverFiles(projectRoot2);
552
+ const fileList = discoverFiles(projectRoot2, excludedPaths);
518
553
  log2(`Discovered ${fileList.length} source files`);
519
554
  const { forward, parseFailures } = buildForwardEdges(fileList, resolver, projectRoot2);
520
555
  const reverse = buildReverseMap(forward);
@@ -1267,14 +1302,16 @@ async function benchmarkAccuracy(client, graph) {
1267
1302
  return scenarios;
1268
1303
  }
1269
1304
  async function main(config) {
1270
- ({ projectRoot, tsconfigPath } = config ?? resolveConfig(import.meta.dirname));
1305
+ const resolvedConfig = config ?? resolveConfig(import.meta.dirname);
1306
+ ({ projectRoot, tsconfigPath } = resolvedConfig);
1307
+ const excludedPaths = resolvedConfig.toolIsEmbedded && resolvedConfig.toolDir ? [resolvedConfig.toolDir] : [];
1271
1308
  console.log("");
1272
1309
  console.log("typegraph-mcp Benchmark");
1273
1310
  console.log("=======================");
1274
1311
  console.log(`Project: ${projectRoot}`);
1275
1312
  console.log("");
1276
1313
  const graphStart = performance.now();
1277
- const { graph } = await buildGraph(projectRoot, tsconfigPath);
1314
+ const { graph } = await buildGraph(projectRoot, tsconfigPath, excludedPaths);
1278
1315
  const graphMs = performance.now() - graphStart;
1279
1316
  const edgeCount = [...graph.forward.values()].reduce((s, e) => s + e.length, 0);
1280
1317
  console.log(`Module graph: ${graph.files.size} files, ${edgeCount} edges [${graphMs.toFixed(0)}ms]`);