@autodev/codebase 1.0.0 → 1.0.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.
package/dist/index.js CHANGED
@@ -45454,7 +45454,7 @@ function parseMarkdown(content) {
45454
45454
  }
45455
45455
 
45456
45456
  // Private constant
45457
- const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4;
45457
+ const DEFAULT_MIN_COMPONENT_LINES_VALUE = 2;
45458
45458
  // Getter function for MIN_COMPONENT_LINES (for easier testing)
45459
45459
  let currentMinComponentLines = DEFAULT_MIN_COMPONENT_LINES_VALUE;
45460
45460
  /**
@@ -61829,8 +61829,6 @@ class BaseAnalyzer {
61829
61829
  // ═══════════════════════════════════════════════════════
61830
61830
  async analyze() {
61831
61831
  try {
61832
- // 0. Create module node for tracking top-level calls
61833
- this.createModuleNode();
61834
61832
  const tree = this.parser.parse(this.content);
61835
61833
  const root = tree.rootNode;
61836
61834
  // 1. Extract imports first (for resolution)
@@ -61898,8 +61896,8 @@ class BaseAnalyzer {
61898
61896
  if (calleeInfo) {
61899
61897
  // 使用 CallInfo 进行过滤判断
61900
61898
  if (!this.shouldFilterCall(node, calleeInfo)) {
61901
- // Use currentFunc if inside a function, otherwise use module node ID
61902
- const caller = currentFunc || this.getModuleNodeId();
61899
+ // Use currentFunc if inside a function, otherwise ensure module node exists
61900
+ const caller = currentFunc || this.ensureModuleNode();
61903
61901
  // 根据调用类型决定如何传递 callee 参数
61904
61902
  if (calleeInfo.isGlobalCall) {
61905
61903
  // 全局直接调用(如 setTimeout):尝试用 importMap 解析
@@ -62011,6 +62009,24 @@ class BaseAnalyzer {
62011
62009
  getModuleNodeId() {
62012
62010
  return this.getModulePath();
62013
62011
  }
62012
+ /**
62013
+ * Ensure module node exists, creating it lazily if needed.
62014
+ * Returns the module node ID.
62015
+ *
62016
+ * This method is called when a top-level call is detected.
62017
+ * By creating module nodes on-demand, we avoid creating nodes for files
62018
+ * that don't have any top-level calls, reducing graph noise.
62019
+ */
62020
+ ensureModuleNode() {
62021
+ const moduleId = this.getModuleNodeId();
62022
+ // If module node already exists, return its ID
62023
+ if (this.nodes.has(moduleId)) {
62024
+ return moduleId;
62025
+ }
62026
+ // Otherwise, create the module node now
62027
+ this.createModuleNode();
62028
+ return moduleId;
62029
+ }
62014
62030
  addEdge(caller, calleeName, line) {
62015
62031
  let resolved;
62016
62032
  // 1. 尝试直接匹配(命名导入:import { foo } from './module')
@@ -63360,14 +63376,15 @@ function buildCalleeTree(nodes, rootNode, visited, currentDepth, maxDepth) {
63360
63376
  const depNode = nodes.get(depId);
63361
63377
  if (!depNode)
63362
63378
  continue;
63379
+ const childDepth = currentDepth + 1;
63363
63380
  const treeNode = {
63364
63381
  id: depNode.id,
63365
63382
  name: depNode.name,
63366
63383
  filePath: depNode.filePath,
63367
63384
  line: depNode.startLine,
63368
63385
  endLine: depNode.endLine,
63369
- depth: currentDepth,
63370
- children: buildCalleeTree(nodes, depNode, visited, currentDepth + 1, maxDepth)
63386
+ depth: childDepth,
63387
+ children: buildCalleeTree(nodes, depNode, visited, childDepth, maxDepth)
63371
63388
  };
63372
63389
  children.push(treeNode);
63373
63390
  }
@@ -63385,14 +63402,15 @@ function buildCallerTree(nodes, targetNodeId, visited, currentDepth, maxDepth) {
63385
63402
  // Find all nodes that depend on the target node
63386
63403
  for (const node of nodes.values()) {
63387
63404
  if (node.dependsOn.has(targetNodeId)) {
63405
+ const childDepth = currentDepth + 1;
63388
63406
  const treeNode = {
63389
63407
  id: node.id,
63390
63408
  name: node.name,
63391
63409
  filePath: node.filePath,
63392
63410
  line: node.startLine,
63393
63411
  endLine: node.endLine,
63394
- depth: currentDepth,
63395
- children: buildCallerTree(nodes, node.id, visited, currentDepth + 1, maxDepth)
63412
+ depth: childDepth,
63413
+ children: buildCallerTree(nodes, node.id, visited, childDepth, maxDepth)
63396
63414
  };
63397
63415
  children.push(treeNode);
63398
63416
  }
@@ -63455,7 +63473,7 @@ function findDirectConnections(matchedNodes, adj) {
63455
63473
  /**
63456
63474
  * BFS to find shortest path between two nodes
63457
63475
  */
63458
- function findShortestPath(adj, startId, endId, maxLength = 10) {
63476
+ function findShortestPath(adj, startId, endId, maxLength) {
63459
63477
  if (startId === endId) {
63460
63478
  return [startId];
63461
63479
  }
@@ -63482,13 +63500,13 @@ function findShortestPath(adj, startId, endId, maxLength = 10) {
63482
63500
  /**
63483
63501
  * Find all chains connecting queried nodes
63484
63502
  */
63485
- function findChains(matchedNodes, adj) {
63503
+ function findChains(matchedNodes, adj, maxDepth) {
63486
63504
  const chains = [];
63487
63505
  const n = matchedNodes.length;
63488
63506
  // Find paths between all pairs
63489
63507
  for (let i = 0; i < n; i++) {
63490
63508
  for (let j = i + 1; j < n; j++) {
63491
- const path = findShortestPath(adj, matchedNodes[i].id, matchedNodes[j].id);
63509
+ const path = findShortestPath(adj, matchedNodes[i].id, matchedNodes[j].id, maxDepth);
63492
63510
  if (path && path.length > 1) {
63493
63511
  chains.push({
63494
63512
  path,
@@ -63505,9 +63523,10 @@ function findChains(matchedNodes, adj) {
63505
63523
  *
63506
63524
  * @param nodes - Node map
63507
63525
  * @param query - Comma-separated function names/patterns
63526
+ * @param maxDepth - Maximum depth for path finding
63508
63527
  * @returns Connection analysis result
63509
63528
  */
63510
- function analyzeConnections(nodes, query) {
63529
+ function analyzeConnections(nodes, query, maxDepth) {
63511
63530
  // Find matching nodes
63512
63531
  const matchedNodes = findMatchingNodes(nodes, query);
63513
63532
  if (matchedNodes.length === 0) {
@@ -63524,7 +63543,7 @@ function analyzeConnections(nodes, query) {
63524
63543
  // Find direct connections
63525
63544
  const directConnections = findDirectConnections(matchedNodes);
63526
63545
  // Find chains
63527
- const chains = findChains(matchedNodes, adj);
63546
+ const chains = findChains(matchedNodes, adj, maxDepth);
63528
63547
  // Collect all involved nodes
63529
63548
  const involvedIds = new Set();
63530
63549
  for (const conn of directConnections) {