fix(resolve): probe .mts/.cts extensions for extension-less imports - #2564
Merged
Conversation
Discovered while fixing #2299 (the .mjs->.mts/.cjs->.cts emitted-extension remap). A separate, distinct code path -- resolving an extension-less relative specifier like `import './foo'` by probing a fixed list of candidate extensions -- never tried .mts/.cts in either engine, even though both engines otherwise recognize and parse .mts/.cts files (#2073). Adds .mts/.cts to the extension-probing list in resolveImportPathJS (src/domain/graph/resolve.ts) and probe_known_extensions's EXTENSIONS constant (crates/codegraph-core/src/domain/graph/resolve.rs), keeping the two lists in sync per the dual-engine parity requirement. Placed alongside .ts/.tsx to keep TypeScript-family extensions grouped, matching the existing ordering convention. docs check acknowledged -- bug fix only, no new language support, feature, or architectural change to document. Impact: 1 functions changed, 19 affected
Contributor
Contributor
Greptile SummaryThe PR extends extension-less import resolution to recognize
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "fix(resolve): also probe /index.mts and ..." | Re-trigger Greptile |
Contributor
Codegraph Impact Analysis1 functions changed → 19 callers affected across 4 files
|
Follow-up to Greptile review on this same PR: the direct .mts/.cts candidates alone don't cover the directory-index convention (import './dir' -> dir/index.mts), which every other extension already in this list (.ts, .tsx, .js) supports via its own /index.<ext> entry. Adds /index.mts and /index.cts to both engines' extension-probing lists, alongside the existing /index.ts and /index.tsx entries. docs check acknowledged -- bug fix only, no new language support, feature, or architectural change to document. Impact: 1 functions changed, 19 affected
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Discovered while fixing #2299 (the
.mjs→.mts/.cjs→.ctsemitted-extension remap). A separate, distinct code path — resolving an extension-less relative specifier likeimport './foo'by probing a fixed list of candidate extensions — never tries.mts/.ctsin either engine, even though both engines otherwise recognize and parse.mts/.ctsfiles (#2073).resolveImportPathJS(src/domain/graph/resolve.ts) tried['.ts', '.tsx', '.js', '.jsx', '.mjs', '.py', '.pyi', ...index variants]— no.mts/.cts.probe_known_extensions'sEXTENSIONSconstant (crates/codegraph-core/src/domain/graph/resolve.rs) had the identical list, same gap.So
import './foo'resolving to a source filefoo.mts/foo.cts(as opposed to the emitted-specifier formimport './foo.mjs', which #2299 covers) fell through to proximity-based confidence instead of an import-aware match.Fix
Added
.mts/.ctsto both extension lists, in both engines, placed alongside.ts/.tsxto keep TypeScript-family extensions grouped (matching the existing ordering convention where TS extensions precede JS extensions in the list).Test plan
tests/unit/resolve.test.ts: extension-less specifier resolves to.mts, extension-less specifier resolves to.cts— reusing the exact fixture files (src/esm/util.mts,src/cjs/legacy.cts) Import resolution doesn't remap .mjs/.cjs specifiers to .mts/.cts sources #2299's own remap tests already set up, but exercising the extension-probing loop directly (no extension on the specifier at all) rather thanEMIT_EXTENSION_REMAPScrates/codegraph-core/src/domain/graph/resolve.rsmirroring both cases.mts/.ctsfrom each list and confirmed the corresponding new tests fail with the exact pre-fix output (resolves to the bare specifier, no extension); restored and confirmed greencargo test --lib(full suite) — 1096 passed (up from 1094, +2 new)cargo clippy --lib -- -D warnings— cleannpm test(full suite) — 339 files, 5449 passednpx tsc --noEmit— cleannpm run lint— cleanCloses #2464