mirror of
https://github.com/safishamsi/graphify.git
synced 2026-09-21 13:05:41 +00:00
fix(js): stabilize unresolved local import target ids (#2457)
This commit is contained in:
committed by
safishamsi
parent
c285a94d45
commit
8be72ef7bf
@@ -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,
|
||||
|
||||
@@ -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 ────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user