Skip to content

feat: add .mjs/.astro extension support and fix IMPORTS_FROM path resolution#58

Closed
zoneghost7 wants to merge 1 commit intotirth8205:mainfrom
WalkingWithGiants:feat/mjs-astro-import-resolution
Closed

feat: add .mjs/.astro extension support and fix IMPORTS_FROM path resolution#58
zoneghost7 wants to merge 1 commit intotirth8205:mainfrom
WalkingWithGiants:feat/mjs-astro-import-resolution

Conversation

@zoneghost7
Copy link

Summary

Two changes to parser.py:

1. Extension mappings for .mjs and .astro files

  • .mjsjavascript: Standard ES module files (.mjs) are widely used for test suites (*.test.mjs), configs (astro.config.mjs, rollup.config.mjs), and any project preferring explicit ESM. These were silently skipped during parsing. Since .mjs is standard JavaScript with ES module semantics, mapping to javascript is correct.

  • .astrotypescript: Astro framework files have TypeScript frontmatter between --- fences followed by an HTML template section. Tree-sitter's TypeScript grammar parses the frontmatter cleanly — extracting imports, function definitions, and call expressions — while silently skipping the template section (no parse errors). This gives useful graph coverage (imports, functions, calls) for Astro projects without requiring a dedicated Astro grammar.

2. Fix IMPORTS_FROM edge path resolution

Problem: IMPORTS_FROM edges store the raw import string as target_qualified (e.g., ../../lib/data-service). However, query patterns like importers_of and find_dependents look up edges by absolute file path. This mismatch causes:

  • importers_of returns zero results for every file — the query searches for /abs/path/to/file.ts but the database contains ../../lib/data-service
  • find_dependents() in incremental.py fails to identify downstream files during incremental rebuilds — editing a core library file won't trigger re-parsing of its importers
  • Blast radius analysis misses all IMPORTS_FROM traversal paths, only finding connections via CALLS edges

Root cause: _resolve_module_to_file() is called when creating CALLS edges (via _resolve_call_target) but is never called for IMPORTS_FROM edges.

Fix: Call _resolve_module_to_file() when creating IMPORTS_FROM edges (lines 601-607). If resolution succeeds, store the absolute path; if it fails (node built-ins like node:fs, external packages like react, virtual modules like astro:content), fall back to the raw string. This is the same graceful-fallback pattern used for CALLS edges.

Before:

importers_of('src/lib/data-service.ts') → 0 results
find_dependents('/abs/path/data-service.ts') → 0 files

After:

importers_of('src/lib/data-service.ts') → WorkLayout.astro, [slug].astro
find_dependents('/abs/path/data-service.ts') → 2 files

Edge cases handled

Import type Resolution Stored as
Relative: ../../lib/utils Resolves via _resolve_module_to_file Absolute path
Relative with ext: ./Component.astro Resolves (exact match) Absolute path
Index barrel: ./utils (dir with index.ts) Resolves (index file) Absolute path
Node built-in: node:fs Returns None → fallback node:fs (raw)
External package: react Returns None → fallback react (raw)
Virtual module: astro:content Returns None → fallback astro:content (raw)
Missing file: ./deleted Returns None → fallback ./deleted (raw)

Test plan

  • Full rebuild on a TypeScript/JavaScript project with .mjs test files — verify .mjs files appear in graph stats
  • Full rebuild on an Astro project — verify .astro files are parsed, imports and functions extracted, no errors
  • importers_of query returns correct results for files with relative imports
  • find_dependents correctly identifies downstream files
  • Blast radius for a library file includes files connected via IMPORTS_FROM edges
  • External/unresolvable imports (node:fs, react, etc.) stored as raw strings (no regression)
  • Incremental rebuild after editing a file correctly re-parses its dependents

🤖 Generated with Claude Code

…olution

Extension mappings:
- Add ".mjs": "javascript" — standard ES module files (test suites,
  configs like astro.config.mjs) were silently skipped during parsing.
- Add ".astro": "typescript" — Astro framework files have TypeScript
  frontmatter between --- fences. The TypeScript tree-sitter grammar
  parses the frontmatter cleanly, extracting imports and function
  definitions while silently skipping the HTML template section.

Import resolution fix:
- IMPORTS_FROM edges previously stored raw import strings (e.g.,
  "../../lib/data-service") as the target_qualified value. Query
  patterns like importers_of and find_dependents look up edges by
  absolute file path, so they returned zero results for all
  IMPORTS_FROM edges.
- The fix calls _resolve_module_to_file (already used for CALLS edge
  resolution) when creating IMPORTS_FROM edges. Relative imports are
  resolved to absolute paths; unresolvable imports (node built-ins,
  external packages, virtual modules) fall back to the raw string.
- This fixes: importers_of queries, find_dependents for incremental
  rebuilds, and blast radius traversal of import edges.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tirth8205 added a commit that referenced this pull request Mar 26, 2026
Adds .mjs extension mapping to JavaScript and .astro extension mapping
to TypeScript for import path resolution.

Co-Authored-By: zoneghost7 <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tirth8205 added a commit that referenced this pull request Mar 26, 2026
…nfigurable embeddings, MiniMax, Perl)

* feat: integrate PR #43 — R language support

Adds R language parsing with function extraction (both <- and = assignment),
S4/R5 class detection via setClass/setRefClass, library/require/source
imports, namespace-qualified calls (dplyr::filter), and testthat test detection.

Co-Authored-By: michael-denyer <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #54 — Vitest/Jest test detection

Adds describe/it/test block parsing for JS/TS test files, producing
synthetic Test nodes with description labels. Supports modifier suffixes
(describe.only, it.skip, test.each) and nested describe/it containment.

Co-Authored-By: JF10R <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #53 — tsconfig path alias resolution

Adds TsconfigResolver module that resolves TypeScript path aliases
(e.g., @/ -> src/) from tsconfig.json compilerOptions.paths. Also
resolves import targets to absolute file paths in IMPORTS_FROM edges.

Co-Authored-By: JF10R <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #58 — .mjs/.astro support

Adds .mjs extension mapping to JavaScript and .astro extension mapping
to TypeScript for import path resolution.

Co-Authored-By: zoneghost7 <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #55 — configurable embedding model

Adds CRG_EMBEDDING_MODEL env var and model parameter to embedding
functions, allowing users to specify any sentence-transformers compatible
model. Changing the model re-embeds all nodes automatically.

Co-Authored-By: eugenepro2 <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #45 — MiniMax embedding provider

Adds MiniMaxEmbeddingProvider using the embo-01 model (1536 dimensions)
with support for distinct task types (db/query), batching, and retry logic.

Co-Authored-By: octo-patch <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #62 — Perl support

Adds Perl language parsing with package detection, subroutine extraction,
use/require imports, and function call tracking. Includes test fixture
and comprehensive test class.

Co-Authored-By: potatogim <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: michael-denyer <noreply@github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tirth8205
Copy link
Owner

Integrated into main via PR #68. Thank you for the contribution! 🎉

@tirth8205 tirth8205 closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants