@rayburst/cli 0.2.9 → 0.3.1
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.
|
@@ -297,6 +297,109 @@ function extractComponentPathsFromImports(sourceFile, projectPath) {
|
|
|
297
297
|
}
|
|
298
298
|
return componentPaths;
|
|
299
299
|
}
|
|
300
|
+
function extractComponentsFromRouteFile(sourceFile, projectPath) {
|
|
301
|
+
const componentPaths = [];
|
|
302
|
+
try {
|
|
303
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
304
|
+
for (const callExpr of callExpressions) {
|
|
305
|
+
const expr = callExpr.getExpression();
|
|
306
|
+
const functionName = expr.getText();
|
|
307
|
+
if (!functionName.includes("createFileRoute") && !functionName.includes("createRootRoute")) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const args = callExpr.getArguments();
|
|
311
|
+
if (args.length === 0) continue;
|
|
312
|
+
let configObject;
|
|
313
|
+
const parent = callExpr.getParent();
|
|
314
|
+
if (Node.isCallExpression(parent)) {
|
|
315
|
+
const parentArgs = parent.getArguments();
|
|
316
|
+
if (parentArgs.length > 0 && Node.isObjectLiteralExpression(parentArgs[0])) {
|
|
317
|
+
configObject = parentArgs[0];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (!configObject && Node.isObjectLiteralExpression(args[0])) {
|
|
321
|
+
configObject = args[0];
|
|
322
|
+
}
|
|
323
|
+
if (!configObject) continue;
|
|
324
|
+
const properties = extractObjectLiteralProperties(configObject);
|
|
325
|
+
const componentValue = properties.get("component");
|
|
326
|
+
if (!componentValue) continue;
|
|
327
|
+
if (isIdentifier(componentValue)) {
|
|
328
|
+
const componentName = componentValue.getText();
|
|
329
|
+
const decl = traceIdentifierToDeclaration(componentValue);
|
|
330
|
+
if (decl) {
|
|
331
|
+
const importDecl = decl.getFirstAncestorByKind(SyntaxKind.ImportDeclaration);
|
|
332
|
+
if (importDecl) {
|
|
333
|
+
const importedSourceFile = getImportSourceFile(importDecl);
|
|
334
|
+
if (importedSourceFile) {
|
|
335
|
+
const filePath = importedSourceFile.getFilePath();
|
|
336
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
337
|
+
if (!relativePath.includes("node_modules")) {
|
|
338
|
+
componentPaths.push(relativePath);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
const localComponentPaths = findNodesInFile(
|
|
343
|
+
sourceFile.getFilePath().replace(projectPath + "/", ""),
|
|
344
|
+
/* @__PURE__ */ new Map()
|
|
345
|
+
// This won't work without nodeMap, but we'll handle it differently
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} else if (Node.isArrowFunction(componentValue) || Node.isFunctionExpression(componentValue)) {
|
|
350
|
+
const jsxElements = componentValue.getDescendantsOfKind(SyntaxKind.JsxElement);
|
|
351
|
+
const jsxSelfClosing = componentValue.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
|
|
352
|
+
for (const jsxElement of jsxElements) {
|
|
353
|
+
const tagName = jsxElement.getOpeningElement().getTagNameNode().getText();
|
|
354
|
+
const importSource = resolveImportSource(sourceFile, tagName);
|
|
355
|
+
if (importSource && !importSource.startsWith(".") && !importSource.startsWith("/")) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const importDecls = sourceFile.getImportDeclarations();
|
|
359
|
+
for (const importDecl of importDecls) {
|
|
360
|
+
const namedImports = importDecl.getNamedImports();
|
|
361
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
362
|
+
if (namedImports.some((ni) => ni.getName() === tagName) || defaultImport?.getText() === tagName) {
|
|
363
|
+
const importedSourceFile = getImportSourceFile(importDecl);
|
|
364
|
+
if (importedSourceFile) {
|
|
365
|
+
const filePath = importedSourceFile.getFilePath();
|
|
366
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
367
|
+
if (!relativePath.includes("node_modules")) {
|
|
368
|
+
componentPaths.push(relativePath);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const jsxElement of jsxSelfClosing) {
|
|
375
|
+
const tagName = jsxElement.getTagNameNode().getText();
|
|
376
|
+
const importSource = resolveImportSource(sourceFile, tagName);
|
|
377
|
+
if (importSource && !importSource.startsWith(".") && !importSource.startsWith("/")) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const importDecls = sourceFile.getImportDeclarations();
|
|
381
|
+
for (const importDecl of importDecls) {
|
|
382
|
+
const namedImports = importDecl.getNamedImports();
|
|
383
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
384
|
+
if (namedImports.some((ni) => ni.getName() === tagName) || defaultImport?.getText() === tagName) {
|
|
385
|
+
const importedSourceFile = getImportSourceFile(importDecl);
|
|
386
|
+
if (importedSourceFile) {
|
|
387
|
+
const filePath = importedSourceFile.getFilePath();
|
|
388
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
389
|
+
if (!relativePath.includes("node_modules")) {
|
|
390
|
+
componentPaths.push(relativePath);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
} catch (error) {
|
|
399
|
+
console.error("[extractComponentsFromRouteFile] Error:", error);
|
|
400
|
+
}
|
|
401
|
+
return componentPaths;
|
|
402
|
+
}
|
|
300
403
|
function findNodesInFile(filePath, nodeMap) {
|
|
301
404
|
const nodes = [];
|
|
302
405
|
for (const [nodeId, node] of nodeMap.entries()) {
|
|
@@ -331,7 +434,7 @@ function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edg
|
|
|
331
434
|
}
|
|
332
435
|
return edgesCreated;
|
|
333
436
|
}
|
|
334
|
-
function analyzeJsxPropsForComponents(jsxElement, propName, projectPath) {
|
|
437
|
+
function analyzeJsxPropsForComponents(jsxElement, propName, projectPath, project) {
|
|
335
438
|
const componentPaths = [];
|
|
336
439
|
try {
|
|
337
440
|
const jsxAttributes = jsxElement.getChildrenOfKind(SyntaxKind.JsxAttributes)[0];
|
|
@@ -369,7 +472,7 @@ function analyzeJsxPropsForComponents(jsxElement, propName, projectPath) {
|
|
|
369
472
|
const commonPropNames = ["routeTree", "routes", "children", "components"];
|
|
370
473
|
for (const commonPropName of commonPropNames) {
|
|
371
474
|
console.log(`[DEBUG analyzeJsxProps] Checking config property: ${commonPropName}`);
|
|
372
|
-
const paths = traceConfigToComponentPaths(configArg, commonPropName, projectPath);
|
|
475
|
+
const paths = traceConfigToComponentPaths(configArg, commonPropName, projectPath, project);
|
|
373
476
|
console.log(`[DEBUG analyzeJsxProps] Paths found for ${commonPropName}: ${paths.length}`);
|
|
374
477
|
if (paths.length > 0) {
|
|
375
478
|
return paths;
|
|
@@ -381,16 +484,67 @@ function analyzeJsxPropsForComponents(jsxElement, propName, projectPath) {
|
|
|
381
484
|
}
|
|
382
485
|
return componentPaths;
|
|
383
486
|
}
|
|
384
|
-
function traceConfigToComponentPaths(configObject, propertyName, projectPath) {
|
|
487
|
+
function traceConfigToComponentPaths(configObject, propertyName, projectPath, project) {
|
|
385
488
|
try {
|
|
386
489
|
const propertyNode = traceConfigProperty(configObject, propertyName);
|
|
490
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Property node for "${propertyName}": ${propertyNode ? propertyNode.getKindName() : "NULL"}`);
|
|
387
491
|
if (!propertyNode) {
|
|
388
492
|
return [];
|
|
389
493
|
}
|
|
494
|
+
if (propertyNode.getKind() === SyntaxKind.ShorthandPropertyAssignment) {
|
|
495
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Shorthand property found, tracing identifier`);
|
|
496
|
+
const identifier = propertyNode.getChildrenOfKind(SyntaxKind.Identifier)[0];
|
|
497
|
+
if (identifier) {
|
|
498
|
+
const declaration = traceIdentifierToDeclaration(identifier);
|
|
499
|
+
if (declaration) {
|
|
500
|
+
const importDecl = declaration.getFirstAncestorByKind(SyntaxKind.ImportDeclaration);
|
|
501
|
+
if (importDecl) {
|
|
502
|
+
const sourceFile = getImportSourceFile(importDecl);
|
|
503
|
+
if (sourceFile) {
|
|
504
|
+
const filePath = sourceFile.getFilePath();
|
|
505
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
506
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found routeTree file: ${relativePath}`);
|
|
507
|
+
const routeFilePaths = extractComponentPathsFromImports(sourceFile, projectPath);
|
|
508
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found ${routeFilePaths.length} route files`);
|
|
509
|
+
const allComponentPaths = [];
|
|
510
|
+
for (const routePath of routeFilePaths) {
|
|
511
|
+
const routeSourceFile = project.getSourceFile(projectPath + "/" + routePath);
|
|
512
|
+
if (!routeSourceFile) {
|
|
513
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Could not load route file: ${routePath}`);
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Extracting components from route: ${routePath}`);
|
|
517
|
+
const componentPaths = extractComponentsFromRouteFile(routeSourceFile, projectPath);
|
|
518
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found ${componentPaths.length} components in ${routePath}`);
|
|
519
|
+
allComponentPaths.push(...componentPaths);
|
|
520
|
+
}
|
|
521
|
+
return [...routeFilePaths, ...allComponentPaths];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
390
527
|
if (isImportDeclaration(propertyNode)) {
|
|
391
528
|
const sourceFile = getImportSourceFile(propertyNode);
|
|
392
529
|
if (sourceFile) {
|
|
393
|
-
|
|
530
|
+
const filePath = sourceFile.getFilePath();
|
|
531
|
+
const relativePath = filePath.replace(projectPath + "/", "");
|
|
532
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found routeTree file: ${relativePath}`);
|
|
533
|
+
const routeFilePaths = extractComponentPathsFromImports(sourceFile, projectPath);
|
|
534
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found ${routeFilePaths.length} route files`);
|
|
535
|
+
const allComponentPaths = [];
|
|
536
|
+
for (const routePath of routeFilePaths) {
|
|
537
|
+
const routeSourceFile = project.getSourceFile(projectPath + "/" + routePath);
|
|
538
|
+
if (!routeSourceFile) {
|
|
539
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Could not load route file: ${routePath}`);
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Extracting components from route: ${routePath}`);
|
|
543
|
+
const componentPaths = extractComponentsFromRouteFile(routeSourceFile, projectPath);
|
|
544
|
+
console.log(`[DEBUG traceConfigToComponentPaths] Found ${componentPaths.length} components in ${routePath}`);
|
|
545
|
+
allComponentPaths.push(...componentPaths);
|
|
546
|
+
}
|
|
547
|
+
return [...routeFilePaths, ...allComponentPaths];
|
|
394
548
|
}
|
|
395
549
|
}
|
|
396
550
|
if (isObjectLiteralExpression(propertyNode)) {
|
|
@@ -415,7 +569,7 @@ function traceConfigToComponentPaths(configObject, propertyName, projectPath) {
|
|
|
415
569
|
}
|
|
416
570
|
return [];
|
|
417
571
|
}
|
|
418
|
-
function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath) {
|
|
572
|
+
function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project) {
|
|
419
573
|
let totalEdgesCreated = 0;
|
|
420
574
|
try {
|
|
421
575
|
const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
|
|
@@ -454,7 +608,7 @@ function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath) {
|
|
|
454
608
|
const commonPropNames = ["router", "config", "routes", "navigation"];
|
|
455
609
|
for (const propName of commonPropNames) {
|
|
456
610
|
console.log(`[DEBUG] Checking prop: ${propName}`);
|
|
457
|
-
const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath);
|
|
611
|
+
const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath, project);
|
|
458
612
|
console.log(`[DEBUG] Component paths found: ${componentPaths.length}`);
|
|
459
613
|
if (componentPaths.length > 0) {
|
|
460
614
|
console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
|
|
@@ -540,7 +694,7 @@ async function analyzeProject(projectPath, projectId, onLog) {
|
|
|
540
694
|
log(` Analyzing config-based components...`);
|
|
541
695
|
let totalConfigEdges = 0;
|
|
542
696
|
for (const sourceFile of sourceFiles) {
|
|
543
|
-
const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath);
|
|
697
|
+
const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project);
|
|
544
698
|
totalConfigEdges += configEdges;
|
|
545
699
|
}
|
|
546
700
|
if (totalConfigEdges > 0) {
|
package/dist/index.js
CHANGED
package/dist/vite-plugin.js
CHANGED