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

Function resolveImportPathUncached

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

Source from the content-addressed store, hash-verified

433}
434
435function resolveImportPathUncached(
436 importPath: string,
437 fromFile: string,
438 language: Language,
439 context: ResolutionContext
440): string | null {
441 // COBOL COPY/EXEC SQL INCLUDE names a copybook member, not a path — the
442 // compiler searches a library, so we match against indexed file basenames.
443 // Must run before isExternalImport: a bare member name would otherwise be
444 // misclassified as an external package.
445 if (language === 'cobol') {
446 return resolveCobolCopybook(importPath, fromFile, context);
447 }
448
449 // Skip external/npm packages — but pass the context so the
450 // bare-specifier heuristic can consult the project's tsconfig
451 // alias map first (custom prefixes like `@components/*` would
452 // otherwise be misclassified as npm). What still looks like a package
453 // may name a file through the importing app's own config.
454 if (isExternalImport(importPath, language, context, { fromFile })) {
455 return resolveFromOwnConfig(importPath, fromFile, language, context);
456 }
457
458 // Python names modules, not paths: one resolver answers relative and
459 // absolute specifiers alike, so every caller gets the same answer.
460 if (language === 'python') {
461 return resolvePythonModule(importPath, fromFile, context);
462 }
463
464 const projectRoot = context.getProjectRoot();
465 const fromDir = path.dirname(path.join(projectRoot, fromFile));
466
467 // Handle relative imports
468 if (importPath.startsWith('.')) {
469 return resolveRelativeImport(importPath, fromDir, language, context);
470 }
471
472 // Handle absolute/aliased imports (like @/ or src/)
473 const aliased = resolveAliasedImport(importPath, projectRoot, language, context, fromFile);
474 if (aliased) return aliased;
475
476 // C/C++ include directory search: when neither relative nor aliased
477 // resolution found a match, search -I directories from
478 // compile_commands.json or heuristic probing.
479 if (language === 'c' || language === 'cpp') {
480 return resolveCppIncludePath(importPath, language, context);
481 }
482
483 return null;
484}
485
486/**
487 * COBOL copybook lookup: `COPY CVACT01Y` (or `EXEC SQL INCLUDE X`) names a

Callers 1

resolveImportPathFunction · 0.85

Calls 9

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

Tested by

no test coverage detected