@rayburst/cli 0.3.3 → 0.3.4

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.
@@ -410,10 +410,44 @@ function findNodesInFile(filePath, nodeMap) {
410
410
  }
411
411
  return nodes;
412
412
  }
413
- function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edgeType = "config") {
413
+ function createRouterDecisionNode(sourceFilePath, gitHash, routeCount) {
414
+ return {
415
+ id: `${sourceFilePath}::RouterDecision::${gitHash}`,
416
+ type: "switch",
417
+ position: { x: 600, y: 400 },
418
+ data: {
419
+ label: "Router (TanStack)",
420
+ description: `URL-based routing decision tree with ${routeCount} routes`,
421
+ switchExpression: "window.location.pathname",
422
+ cases: `${routeCount} route${routeCount !== 1 ? "s" : ""}`
423
+ }
424
+ };
425
+ }
426
+ function extractRoutePathFromFile(routeFilePath) {
427
+ let path5 = routeFilePath.replace(/^src\/routes\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/route$/, "").replace(/\/index$/, "");
428
+ if (path5 === "/__root") {
429
+ return "/";
430
+ }
431
+ path5 = path5.replace(/\/\$([^/]+)/g, (_, param) => `/:${param}`);
432
+ if (path5 === "" || path5 === "/") {
433
+ return "/";
434
+ }
435
+ return path5;
436
+ }
437
+ function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edgeType = "config", useRoutePathLabels = false) {
414
438
  let edgesCreated = 0;
415
439
  for (const targetFilePath of targetFilePaths) {
416
440
  const targetNodes = findNodesInFile(targetFilePath, nodeMap);
441
+ const routePath = useRoutePathLabels ? extractRoutePathFromFile(targetFilePath) : null;
442
+ let edgeLabel = edgeType;
443
+ if (useRoutePathLabels && routePath) {
444
+ const isDynamic = routePath.includes(":");
445
+ if (isDynamic) {
446
+ edgeLabel = `path matches "${routePath}"`;
447
+ } else {
448
+ edgeLabel = `path === "${routePath}"`;
449
+ }
450
+ }
417
451
  for (const targetNode of targetNodes) {
418
452
  if (targetNode.type !== "component") {
419
453
  continue;
@@ -430,7 +464,7 @@ function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edg
430
464
  source: sourceNode.id,
431
465
  target: targetNode.id,
432
466
  type: "floating",
433
- label: edgeType
467
+ label: edgeLabel
434
468
  });
435
469
  edgesCreated++;
436
470
  }
@@ -579,7 +613,7 @@ function traceConfigToComponentPaths(configObject, propertyName, projectPath, pr
579
613
  }
580
614
  return [];
581
615
  }
582
- function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project) {
616
+ function detectConfigBasedComponents(sourceFile, nodes, nodeMap, edges, projectPath, project, gitHash) {
583
617
  let totalEdgesCreated = 0;
584
618
  try {
585
619
  const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
@@ -621,16 +655,48 @@ function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, pr
621
655
  const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath, project);
622
656
  console.log(`[DEBUG] Component paths found: ${componentPaths.length}`);
623
657
  if (componentPaths.length > 0) {
624
- console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
625
- const edgesCreated = createConfigBasedEdges(
626
- sourceNode,
627
- componentPaths,
628
- nodeMap,
629
- edges,
630
- `config:${propName}`
631
- );
632
- console.log(`[DEBUG] Edges created: ${edgesCreated}`);
633
- totalEdgesCreated += edgesCreated;
658
+ if (propName === "router") {
659
+ console.log(`[DEBUG] Creating router decision node for ${componentPaths.length} routes`);
660
+ const relativePath = sourceFile.getFilePath().replace(projectPath + "/", "");
661
+ const routerNode = createRouterDecisionNode(relativePath, gitHash, componentPaths.length);
662
+ nodes.push(routerNode);
663
+ nodeMap.set(routerNode.id, routerNode);
664
+ console.log(`[DEBUG] Created router node: ${routerNode.id}`);
665
+ const appToRouterEdgeId = `e-${sourceNode.id}-${routerNode.id}`;
666
+ if (!edges.find((e) => e.id === appToRouterEdgeId)) {
667
+ edges.push({
668
+ id: appToRouterEdgeId,
669
+ source: sourceNode.id,
670
+ target: routerNode.id,
671
+ type: "floating",
672
+ label: "router prop"
673
+ });
674
+ totalEdgesCreated++;
675
+ console.log(`[DEBUG] Created edge: App -> Router`);
676
+ }
677
+ const routerToRoutesEdges = createConfigBasedEdges(
678
+ routerNode,
679
+ componentPaths,
680
+ nodeMap,
681
+ edges,
682
+ "route",
683
+ true
684
+ // Use route path labels
685
+ );
686
+ console.log(`[DEBUG] Created ${routerToRoutesEdges} edges from Router to routes`);
687
+ totalEdgesCreated += routerToRoutesEdges;
688
+ } else {
689
+ console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
690
+ const edgesCreated = createConfigBasedEdges(
691
+ sourceNode,
692
+ componentPaths,
693
+ nodeMap,
694
+ edges,
695
+ `config:${propName}`
696
+ );
697
+ console.log(`[DEBUG] Edges created: ${edgesCreated}`);
698
+ totalEdgesCreated += edgesCreated;
699
+ }
634
700
  }
635
701
  }
636
702
  }
@@ -704,7 +770,7 @@ async function analyzeProject(projectPath, projectId, onLog) {
704
770
  log(` Analyzing config-based components...`);
705
771
  let totalConfigEdges = 0;
706
772
  for (const sourceFile of sourceFiles) {
707
- const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project);
773
+ const configEdges = detectConfigBasedComponents(sourceFile, nodes, nodeMap, edges, projectPath, project, gitHash);
708
774
  totalConfigEdges += configEdges;
709
775
  }
710
776
  if (totalConfigEdges > 0) {
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  readLocalMeta,
10
10
  writeLocalAnalysis,
11
11
  writeLocalMeta
12
- } from "./chunk-5LBWVFGJ.js";
12
+ } from "./chunk-3IJUZFQ6.js";
13
13
  export {
14
14
  addGitignoreEntry,
15
15
  analyzeProject,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  rayburstPlugin
3
- } from "./chunk-5LBWVFGJ.js";
3
+ } from "./chunk-3IJUZFQ6.js";
4
4
  export {
5
5
  rayburstPlugin
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayburst/cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Rayburst - Automatic code analysis for TypeScript/JavaScript projects via Vite plugin",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",