MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveImportPathUncached

Function resolveImportPathUncached

src/resolution/import-resolver.ts:133–175  ·  view source on GitHub ↗
(
  importPath: string,
  fromFile: string,
  language: Language,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

131}
132
133function resolveImportPathUncached(
134 importPath: string,
135 fromFile: string,
136 language: Language,
137 context: ResolutionContext
138): string | null {
139 // COBOL COPY/EXEC SQL INCLUDE names a copybook member, not a path — the
140 // compiler searches a library, so we match against indexed file basenames.
141 // Must run before isExternalImport: a bare member name would otherwise be
142 // misclassified as an external package.
143 if (language === 'cobol') {
144 return resolveCobolCopybook(importPath, fromFile, context);
145 }
146
147 // Skip external/npm packages — but pass the context so the
148 // bare-specifier heuristic can consult the project's tsconfig
149 // alias map first (custom prefixes like `@components/*` would
150 // otherwise be misclassified as npm).
151 if (isExternalImport(importPath, language, context)) {
152 return null;
153 }
154
155 const projectRoot = context.getProjectRoot();
156 const fromDir = path.dirname(path.join(projectRoot, fromFile));
157
158 // Handle relative imports
159 if (importPath.startsWith('.')) {
160 return resolveRelativeImport(importPath, fromDir, language, context);
161 }
162
163 // Handle absolute/aliased imports (like @/ or src/)
164 const aliased = resolveAliasedImport(importPath, projectRoot, language, context);
165 if (aliased) return aliased;
166
167 // C/C++ include directory search: when neither relative nor aliased
168 // resolution found a match, search -I directories from
169 // compile_commands.json or heuristic probing.
170 if (language === 'c' || language === 'cpp') {
171 return resolveCppIncludePath(importPath, language, context);
172 }
173
174 return null;
175}
176
177/**
178 * COBOL copybook lookup: `COPY CVACT01Y` (or `EXEC SQL INCLUDE X`) names a

Callers 1

resolveImportPathFunction · 0.85

Calls 7

resolveCobolCopybookFunction · 0.85
isExternalImportFunction · 0.85
resolveRelativeImportFunction · 0.85
resolveAliasedImportFunction · 0.85
resolveCppIncludePathFunction · 0.85
getProjectRootMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected