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

Function resolveImportPathUncached

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

Source from the content-addressed store, hash-verified

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