@rayburst/cli 0.3.3 → 0.3.5
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
|
|
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:
|
|
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, externalNodeMap) {
|
|
583
617
|
let totalEdgesCreated = 0;
|
|
584
618
|
try {
|
|
585
619
|
const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
|
|
@@ -621,16 +655,66 @@ 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
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
componentPaths
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
`
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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 routerProviderExternalId = "external::@tanstack/react-router::RouterProvider";
|
|
666
|
+
const routerProviderNode = externalNodeMap.get(routerProviderExternalId);
|
|
667
|
+
if (routerProviderNode) {
|
|
668
|
+
const providerToRouterEdgeId = `e-${routerProviderNode.id}-${routerNode.id}`;
|
|
669
|
+
if (!edges.find((e) => e.id === providerToRouterEdgeId)) {
|
|
670
|
+
edges.push({
|
|
671
|
+
id: providerToRouterEdgeId,
|
|
672
|
+
source: routerProviderNode.id,
|
|
673
|
+
target: routerNode.id,
|
|
674
|
+
type: "floating",
|
|
675
|
+
label: "router prop"
|
|
676
|
+
});
|
|
677
|
+
totalEdgesCreated++;
|
|
678
|
+
console.log(`[DEBUG] Created edge: RouterProvider -> Router`);
|
|
679
|
+
}
|
|
680
|
+
} else {
|
|
681
|
+
console.warn("[DEBUG] RouterProvider external node not found, falling back to App -> Router edge");
|
|
682
|
+
const appToRouterEdgeId = `e-${sourceNode.id}-${routerNode.id}`;
|
|
683
|
+
if (!edges.find((e) => e.id === appToRouterEdgeId)) {
|
|
684
|
+
edges.push({
|
|
685
|
+
id: appToRouterEdgeId,
|
|
686
|
+
source: sourceNode.id,
|
|
687
|
+
target: routerNode.id,
|
|
688
|
+
type: "floating",
|
|
689
|
+
label: "router prop"
|
|
690
|
+
});
|
|
691
|
+
totalEdgesCreated++;
|
|
692
|
+
console.log(`[DEBUG] Created edge: App -> Router (fallback)`);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const routerToRoutesEdges = createConfigBasedEdges(
|
|
696
|
+
routerNode,
|
|
697
|
+
componentPaths,
|
|
698
|
+
nodeMap,
|
|
699
|
+
edges,
|
|
700
|
+
"route",
|
|
701
|
+
true
|
|
702
|
+
// Use route path labels
|
|
703
|
+
);
|
|
704
|
+
console.log(`[DEBUG] Created ${routerToRoutesEdges} edges from Router to routes`);
|
|
705
|
+
totalEdgesCreated += routerToRoutesEdges;
|
|
706
|
+
} else {
|
|
707
|
+
console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
|
|
708
|
+
const edgesCreated = createConfigBasedEdges(
|
|
709
|
+
sourceNode,
|
|
710
|
+
componentPaths,
|
|
711
|
+
nodeMap,
|
|
712
|
+
edges,
|
|
713
|
+
`config:${propName}`
|
|
714
|
+
);
|
|
715
|
+
console.log(`[DEBUG] Edges created: ${edgesCreated}`);
|
|
716
|
+
totalEdgesCreated += edgesCreated;
|
|
717
|
+
}
|
|
634
718
|
}
|
|
635
719
|
}
|
|
636
720
|
}
|
|
@@ -704,7 +788,7 @@ async function analyzeProject(projectPath, projectId, onLog) {
|
|
|
704
788
|
log(` Analyzing config-based components...`);
|
|
705
789
|
let totalConfigEdges = 0;
|
|
706
790
|
for (const sourceFile of sourceFiles) {
|
|
707
|
-
const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project);
|
|
791
|
+
const configEdges = detectConfigBasedComponents(sourceFile, nodes, nodeMap, edges, projectPath, project, gitHash, externalNodeMap);
|
|
708
792
|
totalConfigEdges += configEdges;
|
|
709
793
|
}
|
|
710
794
|
if (totalConfigEdges > 0) {
|
package/dist/index.js
CHANGED
package/dist/vite-plugin.js
CHANGED