fix(js): stabilize unresolved local import target ids (#2457)

This commit is contained in:
rohit-jsfreaky
2026-08-12 14:20:21 +01:00
committed by safishamsi
parent c285a94d45
commit 8be72ef7bf
2 changed files with 29 additions and 0 deletions
+6
View File
@@ -413,6 +413,12 @@ def _import_js(node, source: bytes, file_nid: str, stem: str, edges: list, str_p
resolved = _resolve_js_import_target(raw, str_path)
if resolved is not None:
tgt_nid, resolved_path = resolved
# `_resolve_js_import_path` returns the attempted path when no
# local file exists. Static ES imports must treat that as unresolved
# rather than minting a checkout-specific target ID (#2457).
if resolved_path is not None and not resolved_path.is_file():
tgt_nid = _make_id("ref", raw)
resolved_path = None
edge = {
"source": file_nid,
"target": tgt_nid,
+23
View File
@@ -1017,6 +1017,29 @@ def test_tsconfig_alias_none_exist_creates_no_false_edge(tmp_path: Path):
assert not _has_edge(result, "src/routes/page.ts", "src/lib/utils.ts")
def test_unresolved_relative_import_uses_stable_ref_target(tmp_path: Path):
"""A missing local module must not leak the checkout path into graph IDs (#2457)."""
importer = _write(
tmp_path / "src/consumer.ts",
"import { getFoo } from './generated/api'\n"
"export function run(): number { return getFoo() }\n",
)
result = _extract_for([importer], tmp_path)
source = _file_node_id(Path("src/consumer.ts"))
imports_from = [
edge["target"]
for edge in result["edges"]
if edge["source"] == source and edge["relation"] == "imports_from"
]
assert imports_from == [_make_id("ref", "./generated/api")]
assert not any(
edge["source"] == source and edge["relation"] == "imports"
for edge in result["edges"]
)
# ── #927: wildcard tsconfig path patterns ────────────────────────────────────