ucn 3.1.4 → 3.1.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.

Potentially problematic release.


This version of ucn might be problematic. Click here for more details.

package/cli/index.js CHANGED
@@ -960,7 +960,8 @@ function runProjectCommand(rootDir, command, arg) {
960
960
 
961
961
  case 'graph': {
962
962
  requireArg(arg, 'Usage: ucn . graph <file>');
963
- const graphResult = index.graph(arg, { direction: 'both', maxDepth: flags.depth ?? 5 });
963
+ const graphDepth = flags.depth ?? 2; // Default to 2 for cleaner output
964
+ const graphResult = index.graph(arg, { direction: 'both', maxDepth: graphDepth });
964
965
  if (graphResult.nodes.length === 0) {
965
966
  console.log(`File not found: ${arg}`);
966
967
  } else {
@@ -970,7 +971,7 @@ function runProjectCommand(rootDir, command, arg) {
970
971
  nodes: r.nodes.map(n => ({ file: n.relativePath, depth: n.depth })),
971
972
  edges: r.edges.map(e => ({ from: path.relative(index.root, e.from), to: path.relative(index.root, e.to) }))
972
973
  }, null, 2),
973
- r => { printGraph(r, index.root); }
974
+ r => { printGraph(r, index.root, graphDepth); }
974
975
  );
975
976
  }
976
977
  break;
@@ -1801,12 +1802,15 @@ function printStats(stats) {
1801
1802
  }
1802
1803
  }
1803
1804
 
1804
- function printGraph(graph, root) {
1805
+ function printGraph(graph, root, maxDepth = 2) {
1805
1806
  const rootRelPath = path.relative(root, graph.root);
1806
1807
  console.log(`Dependency graph for ${rootRelPath}`);
1807
1808
  console.log('═'.repeat(60));
1808
1809
 
1809
1810
  const printed = new Set();
1811
+ const maxChildren = 8; // Limit children per node
1812
+ let truncatedNodes = 0;
1813
+ let depthLimited = false;
1810
1814
 
1811
1815
  function printNode(file, indent = 0) {
1812
1816
  const fileEntry = graph.nodes.find(n => n.file === file);
@@ -1819,15 +1823,43 @@ function printGraph(graph, root) {
1819
1823
  }
1820
1824
  printed.add(file);
1821
1825
 
1826
+ // Depth limiting
1827
+ if (indent > maxDepth) {
1828
+ depthLimited = true;
1829
+ console.log(`${prefix}${relPath} ...`);
1830
+ return;
1831
+ }
1832
+
1822
1833
  console.log(`${prefix}${relPath}`);
1823
1834
 
1824
1835
  const edges = graph.edges.filter(e => e.from === file);
1825
- for (const edge of edges) {
1836
+
1837
+ // Limit children
1838
+ const displayEdges = edges.slice(0, maxChildren);
1839
+ const hiddenCount = edges.length - displayEdges.length;
1840
+
1841
+ for (const edge of displayEdges) {
1826
1842
  printNode(edge.to, indent + 1);
1827
1843
  }
1844
+
1845
+ if (hiddenCount > 0) {
1846
+ truncatedNodes += hiddenCount;
1847
+ console.log(`${' '.repeat(indent)}└── ... and ${hiddenCount} more`);
1848
+ }
1828
1849
  }
1829
1850
 
1830
1851
  printNode(graph.root);
1852
+
1853
+ // Print helpful note about expanding
1854
+ if (depthLimited || truncatedNodes > 0) {
1855
+ console.log('\n' + '─'.repeat(60));
1856
+ if (depthLimited) {
1857
+ console.log(`Depth limited to ${maxDepth}. Use --depth=N for deeper graph.`);
1858
+ }
1859
+ if (truncatedNodes > 0) {
1860
+ console.log(`${truncatedNodes} nodes hidden. Graph has ${graph.nodes.length} total files.`);
1861
+ }
1862
+ }
1831
1863
  }
1832
1864
 
1833
1865
  function printSearchResults(results, term) {
package/core/discovery.js CHANGED
@@ -332,31 +332,51 @@ function findProjectRoot(startDir) {
332
332
 
333
333
  /**
334
334
  * Auto-detect the glob pattern for a project based on its type
335
+ * Checks both project root and immediate subdirectories for config files
335
336
  */
336
337
  function detectProjectPattern(projectRoot) {
337
338
  const extensions = [];
338
339
 
339
- if (fs.existsSync(path.join(projectRoot, 'package.json'))) {
340
- extensions.push('js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs');
341
- }
340
+ // Helper to check for config files in a directory
341
+ const checkDir = (dir) => {
342
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
343
+ extensions.push('js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs');
344
+ }
342
345
 
343
- if (fs.existsSync(path.join(projectRoot, 'pyproject.toml')) ||
344
- fs.existsSync(path.join(projectRoot, 'setup.py')) ||
345
- fs.existsSync(path.join(projectRoot, 'requirements.txt'))) {
346
- extensions.push('py');
347
- }
346
+ if (fs.existsSync(path.join(dir, 'pyproject.toml')) ||
347
+ fs.existsSync(path.join(dir, 'setup.py')) ||
348
+ fs.existsSync(path.join(dir, 'requirements.txt'))) {
349
+ extensions.push('py');
350
+ }
348
351
 
349
- if (fs.existsSync(path.join(projectRoot, 'go.mod'))) {
350
- extensions.push('go');
351
- }
352
+ if (fs.existsSync(path.join(dir, 'go.mod'))) {
353
+ extensions.push('go');
354
+ }
352
355
 
353
- if (fs.existsSync(path.join(projectRoot, 'Cargo.toml'))) {
354
- extensions.push('rs');
355
- }
356
+ if (fs.existsSync(path.join(dir, 'Cargo.toml'))) {
357
+ extensions.push('rs');
358
+ }
356
359
 
357
- if (fs.existsSync(path.join(projectRoot, 'pom.xml')) ||
358
- fs.existsSync(path.join(projectRoot, 'build.gradle'))) {
359
- extensions.push('java', 'kt');
360
+ if (fs.existsSync(path.join(dir, 'pom.xml')) ||
361
+ fs.existsSync(path.join(dir, 'build.gradle'))) {
362
+ extensions.push('java', 'kt');
363
+ }
364
+ };
365
+
366
+ // Check project root
367
+ checkDir(projectRoot);
368
+
369
+ // Also check immediate subdirectories for multi-language projects (e.g., web/, frontend/, server/)
370
+ try {
371
+ const entries = fs.readdirSync(projectRoot, { withFileTypes: true });
372
+ for (const entry of entries) {
373
+ if (entry.isDirectory() && !entry.name.startsWith('.') &&
374
+ !EXCLUDED_DIRS.has(entry.name)) {
375
+ checkDir(path.join(projectRoot, entry.name));
376
+ }
377
+ }
378
+ } catch (e) {
379
+ // Ignore errors reading directory
360
380
  }
361
381
 
362
382
  if (extensions.length > 0) {
@@ -812,6 +812,50 @@ function findCallsInCode(code, parser) {
812
812
  return true;
813
813
  }
814
814
 
815
+ // Handle JSX component usage: <Component /> or <Component>...</Component>
816
+ // Only track PascalCase names (React components), not lowercase (HTML elements)
817
+ if (node.type === 'jsx_self_closing_element' || node.type === 'jsx_opening_element') {
818
+ // First named child is the element name
819
+ for (let i = 0; i < node.namedChildCount; i++) {
820
+ const child = node.namedChild(i);
821
+ if (child.type === 'identifier') {
822
+ const name = child.text;
823
+ // React components start with uppercase
824
+ if (name && /^[A-Z]/.test(name)) {
825
+ const enclosingFunction = getCurrentEnclosingFunction();
826
+ calls.push({
827
+ name: name,
828
+ line: node.startPosition.row + 1,
829
+ isMethod: false,
830
+ isJsxComponent: true,
831
+ enclosingFunction
832
+ });
833
+ }
834
+ break;
835
+ }
836
+ // Handle namespaced components: <Foo.Bar />
837
+ if (child.type === 'member_expression' || child.type === 'nested_identifier') {
838
+ const text = child.text;
839
+ // Get the last part after the dot
840
+ const parts = text.split('.');
841
+ const componentName = parts[parts.length - 1];
842
+ if (componentName && /^[A-Z]/.test(componentName)) {
843
+ const enclosingFunction = getCurrentEnclosingFunction();
844
+ calls.push({
845
+ name: componentName,
846
+ line: node.startPosition.row + 1,
847
+ isMethod: true,
848
+ receiver: parts.slice(0, -1).join('.'),
849
+ isJsxComponent: true,
850
+ enclosingFunction
851
+ });
852
+ }
853
+ break;
854
+ }
855
+ }
856
+ return true;
857
+ }
858
+
815
859
  return true;
816
860
  }, {
817
861
  onLeave: (node) => {
@@ -1338,6 +1382,10 @@ function findUsagesInCode(code, name, parser) {
1338
1382
  usageType = 'reference';
1339
1383
  }
1340
1384
  }
1385
+ // JSX component usage: <Component /> or <Component>...</Component>
1386
+ else if (parent.type === 'jsx_self_closing_element' || parent.type === 'jsx_opening_element') {
1387
+ usageType = 'call'; // Treat JSX component usage as a "call"
1388
+ }
1341
1389
  }
1342
1390
 
1343
1391
  usages.push({ line, column, usageType });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ucn",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Code navigation built by AI, for AI. Reduces context usage when working with large codebases.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -4547,6 +4547,38 @@ func (s *ServiceB) helper() {}
4547
4547
  }
4548
4548
  });
4549
4549
 
4550
+ it('should detect JSX component usage as calls', () => {
4551
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ucn-jsx-'));
4552
+ try {
4553
+ fs.writeFileSync(path.join(tmpDir, 'package.json'), `{"name": "test"}`);
4554
+
4555
+ fs.writeFileSync(path.join(tmpDir, 'Page.tsx'), `
4556
+ function EnvironmentsPage() {
4557
+ return <div>Hello</div>;
4558
+ }
4559
+
4560
+ function App() {
4561
+ return <EnvironmentsPage />;
4562
+ }
4563
+
4564
+ export { App, EnvironmentsPage };
4565
+ `);
4566
+
4567
+ const index = new ProjectIndex(tmpDir);
4568
+ index.build('**/*.tsx', { quiet: true });
4569
+
4570
+ const usages = index.usages('EnvironmentsPage', { codeOnly: true });
4571
+ const calls = usages.filter(u => u.usageType === 'call' && !u.isDefinition);
4572
+
4573
+ // Should find JSX usage as a call
4574
+ assert.ok(calls.length >= 1, 'Should find at least 1 JSX component usage');
4575
+ assert.ok(calls.some(c => c.content && c.content.includes('<EnvironmentsPage')),
4576
+ 'Should detect <EnvironmentsPage /> as a call');
4577
+ } finally {
4578
+ fs.rmSync(tmpDir, { recursive: true, force: true });
4579
+ }
4580
+ });
4581
+
4550
4582
  it('should detect Rust method calls in usages', () => {
4551
4583
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ucn-rust-method-'));
4552
4584
  try {