Resolve NodeNext TypeScript `.js` imports to TypeScript source files

Đang mở Phù hợp với người mới
#100 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, typescript

Hướng nghiên cứu

Bắt đầu trong CoderMind/scripts/rpg/dep_graph.py, tại các khoảng resolver và invoke-resolution được trích dẫn trong issue, sau đó đọc test invoke TypeScript không có phần mở rộng trong CoderMind/tests/test_multilingual_dep_graph.py. Thêm một test theo kiểu NodeNext sử dụng repro a.ts và b.ts được cung cấp; được xem là hoàn tất khi import .js được resolve tới b.ts và cả cạnh import xuyên tệp lẫn cạnh invoke đều tồn tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In a NodeNext/ESM TypeScript repo, relative imports such as import { b } from "./b.js" (the TypeScript-mandated form) remain unresolved, so the graph misses cross-file import and invoke edges. The resolver tries only the literal path when a specifier has an extension, so ./b.js is never tried as b.ts (resolver: https://github.com/microsoft/RPG-ZeroRepo/blob/f0947723cc07fe10fb0d6b14c8aa837847f57b0d/CoderMind/scripts/rpg/dep_graph.py#L2154-L2172 and invoke resolution: https://github.com/microsoft/RPG-ZeroRepo/blob/f0947723cc07fe10fb0d6b14c8aa837847f57b0d/CoderMind/scripts/rpg/dep_graph.py#L2225-L2239).

Minimal resolver-derived repro (not run):

repo/
  tsconfig.json
  src/a.ts
  src/b.ts

tsconfig.json: {"compilerOptions":{"module":"NodeNext","moduleResolution":"NodeNext"}}
src/a.ts: import { b } from "./b.js"; export function a() { return b(); }
src/b.ts: export function b() { return 1; }

Expected: import and invoke edges from src/a.ts to src/b.ts and from src/a.ts:a to src/b.ts:b. Actual: unresolved import and no cross-file invoke edge, as derived from reading the resolver, not from a run.

Suggested change:

         if extension:
             candidates.append(raw_path)
+            if extension in {".js", ".jsx", ".mjs", ".cjs"}:
+                stem = raw_path[:-len(extension)]
+                candidates.extend(
+                    f"{stem}{ext}" for ext in (".ts", ".tsx", ".mts", ".cts")
+                )

Please add a NodeNext-style test next to the existing extensionless TypeScript invoke test (https://github.com/microsoft/RPG-ZeroRepo/blob/f0947723cc07fe10fb0d6b14c8aa837847f57b0d/CoderMind/tests/test_multilingual_dep_graph.py#L156-L199). The audit report counted 241 relative .js imports as unresolved in the inspected repo. I can open a PR with the small resolver fix and test if useful.

This issue was AI-generated at the human operator's direction and reviewed by the operator before submission.

Ngôn ngữ chính
Python
Star
556
Fork
44
Merge trung bình
5 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/RPG-ZeroRepo

Tất cả issue của microsoft/RPG-ZeroRepo

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.