-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug: --deps mode shows 0 dependencies for TypeScript/React projects
Problem
When running codemap --deps on a TypeScript/React project, it shows 0 internal dependencies even when files clearly import from each other.
Example output:
4 files · 14 functions · 0 deps ❌
Root Cause
Three issues in the ast-grep rules:
- Missing
.tsxsupport: ast-grep treats.tsxaslanguage: tsx, nottypescript - Missing
.jsxsupport: ast-grep treats.jsxaslanguage: jsx, notjavascript - Pattern matching misses
import type: Current rules use pattern matching which doesn't catch TypeScript type imports
Reproduction
Any TypeScript/React project with internal imports:
// src/app.tsx
import type React from 'react'
import {useAuth} from '@/hooks/useAuth'
import './app.scss'$ codemap --deps
# Shows 0 deps ❌Solution
I've tested these fixes locally and they work:
1. Add scanner/sg-rules/tsx.yml
id: tsx-imports
language: tsx
rule:
kind: import_statement
---
id: tsx-functions
language: tsx
rule:
any:
- kind: function_declaration
- kind: method_definition
- kind: arrow_function2. Add scanner/sg-rules/jsx.yml
id: jsx-imports
language: jsx
rule:
kind: import_statement
---
id: jsx-functions
language: jsx
rule:
any:
- kind: function_declaration
- kind: method_definition
- kind: arrow_function3. Update scanner/sg-rules/typescript.yml
id: ts-imports
language: typescript
rule:
kind: import_statement # Changed from pattern matching
---
id: ts-functions
language: typescript
rule:
any:
- kind: function_declaration
- kind: method_definition
- kind: arrow_function4. Update scanner/astgrep.go
func detectLangFromRuleID(ruleID string) string {
parts := strings.Split(ruleID, "-")
if len(parts) > 0 {
switch parts[0] {
case "tsx":
return "typescript" // Add
case "jsx":
return "javascript" // Add
// ... existing cases
}
}
return ""
}Results
Same project after fixes:
Src ════════════════════════════════════════
app ───▶ src/hooks/useAuth
RouteGuard ───▶ src/contexts/AuthContext
api ───▶ src/client/supabase
HUBS: src/db/api (4←)
18 files · 37 functions · 11 deps ✅
| Metric | Before | After | Change |
|---|---|---|---|
| Files | 4 | 18 | +350% |
| Functions | 14 | 37 | +164% |
| Dependencies | 0 | 11 | Fixed! |
Impact
Affects all TypeScript and React projects using --deps mode.
Testing
Tested on:
- ✅ macOS & Ubuntu 22.04
- ✅ TypeScript/React (Taro framework)
- ✅ Mixed .ts/.tsx files
- ✅ Path aliases (
@/*) - ✅ ast-grep 0.40.5
Environment
- codemap: 3.2.0
- ast-grep: 0.40.5
- Platform: macOS/Linux
- Project: TypeScript + React
PR
I have working code ready. Let me know if you'd like me to submit a PR with:
- ✅ All fixes
- ✅ Test coverage
- ✅ Documentation updates
Why kind: import_statement is better:
- Catches all import variants (including
import type) - More reliable than pattern matching
- Future-proof for new syntax
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working