Skip to main content

Module path_resolver

Module path_resolver 

Source
Expand description

Path resolution for import statements across languages

This module provides utilities for resolving relative and absolute import paths to canonical module identifiers, ensuring that import edges in the graph point to the correct target nodes.

§Problem

Without proper path resolution, relative imports collapse together:

  • src/foo/index.js importing "./utils" → points to "./utils"
  • src/bar/index.js importing "./utils" → points to same "./utils"

These refer to different files but create the same module node.

§Solution

This module resolves import paths to canonical forms:

  • Relative paths (./utils, ../lib/helper) → absolute paths
  • Normalize path separators (handle both / and \)
  • Handle . and .. components
  • Preserve absolute paths and package imports as-is

§Example

use sqry_core::graph::path_resolver::resolve_import_path;
use std::path::Path;

// Relative import from src/components/Button.js
let source_file = Path::new("src/components/Button.js");
let import_path = "./Icon";
let resolved = resolve_import_path(source_file, import_path).unwrap();
assert_eq!(resolved, "src/components/Icon");

// Parent directory import
let import_path = "../utils/helpers";
let resolved = resolve_import_path(source_file, import_path).unwrap();
assert_eq!(resolved, "src/utils/helpers");

// Package imports are preserved
let resolved = resolve_import_path(source_file, "react").unwrap();
assert_eq!(resolved, "react");

Functions§

normalize_path
Normalize a path by removing . and .. components
resolve_import_path
Resolve an import path to a canonical module identifier
resolve_python_import
Resolve a Python module import path