@rayburst/cli 0.2.9 → 0.3.0

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,34 @@ 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
  }
390
494
  if (isImportDeclaration(propertyNode)) {
391
495
  const sourceFile = getImportSourceFile(propertyNode);
392
496
  if (sourceFile) {
393
- return extractComponentPathsFromImports(sourceFile, projectPath);
497
+ const filePath = sourceFile.getFilePath();
498
+ const relativePath = filePath.replace(projectPath + "/", "");
499
+ console.log(`[DEBUG traceConfigToComponentPaths] Found routeTree file: ${relativePath}`);
500
+ const routeFilePaths = extractComponentPathsFromImports(sourceFile, projectPath);
501
+ console.log(`[DEBUG traceConfigToComponentPaths] Found ${routeFilePaths.length} route files`);
502
+ const allComponentPaths = [];
503
+ for (const routePath of routeFilePaths) {
504
+ const routeSourceFile = project.getSourceFile(projectPath + "/" + routePath);
505
+ if (!routeSourceFile) {
506
+ console.log(`[DEBUG traceConfigToComponentPaths] Could not load route file: ${routePath}`);
507
+ continue;
508
+ }
509
+ console.log(`[DEBUG traceConfigToComponentPaths] Extracting components from route: ${routePath}`);
510
+ const componentPaths = extractComponentsFromRouteFile(routeSourceFile, projectPath);
511
+ console.log(`[DEBUG traceConfigToComponentPaths] Found ${componentPaths.length} components in ${routePath}`);
512
+ allComponentPaths.push(...componentPaths);
513
+ }
514
+ return [...routeFilePaths, ...allComponentPaths];
394
515
  }
395
516
  }
396
517
  if (isObjectLiteralExpression(propertyNode)) {
@@ -415,7 +536,7 @@ function traceConfigToComponentPaths(configObject, propertyName, projectPath) {
415
536
  }
416
537
  return [];
417
538
  }
418
- function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath) {
539
+ function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project) {
419
540
  let totalEdgesCreated = 0;
420
541
  try {
421
542
  const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
@@ -454,7 +575,7 @@ function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath) {
454
575
  const commonPropNames = ["router", "config", "routes", "navigation"];
455
576
  for (const propName of commonPropNames) {
456
577
  console.log(`[DEBUG] Checking prop: ${propName}`);
457
- const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath);
578
+ const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath, project);
458
579
  console.log(`[DEBUG] Component paths found: ${componentPaths.length}`);
459
580
  if (componentPaths.length > 0) {
460
581
  console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
@@ -540,7 +661,7 @@ async function analyzeProject(projectPath, projectId, onLog) {
540
661
  log(` Analyzing config-based components...`);
541
662
  let totalConfigEdges = 0;
542
663
  for (const sourceFile of sourceFiles) {
543
- const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath);
664
+ const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project);
544
665
  totalConfigEdges += configEdges;
545
666
  }
546
667
  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-7HEX7KJS.js";
12
+ } from "./chunk-L6EQILHI.js";
13
13
  export {
14
14
  addGitignoreEntry,
15
15
  analyzeProject,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  rayburstPlugin
3
- } from "./chunk-7HEX7KJS.js";
3
+ } from "./chunk-L6EQILHI.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.2.9",
3
+ "version": "0.3.0",
4
4
  "description": "Rayburst - Automatic code analysis for TypeScript/JavaScript projects via Vite plugin",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",