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

Function resolveImportPathUncached

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

Source from the content-addressed store, hash-verified

452}
453
454function resolveImportPathUncached(
455 importPath: string,
456 fromFile: string,
457 language: Language,
458 context: ResolutionContext
459): string | null {
460 // COBOL COPY/EXEC SQL INCLUDE names a copybook member, not a path — the
461 // compiler searches a library, so we match against indexed file basenames.
462 // Must run before isExternalImport: a bare member name would otherwise be
463 // misclassified as an external package.
464 if (language === 'cobol') {
465 return resolveCobolCopybook(importPath, fromFile, context);
466 }
467
468 // Skip external/npm packages — but pass the context so the
469 // bare-specifier heuristic can consult the project's tsconfig
470 // alias map first (custom prefixes like `@components/*` would
471 // otherwise be misclassified as npm). What still looks like a package
472 // may name a file through the importing app's own config.
473 if (isExternalImport(importPath, language, context, { fromFile })) {
474 return resolveFromOwnConfig(importPath, fromFile, language, context);
475 }
476
477 // Python names modules, not paths: one resolver answers relative and
478 // absolute specifiers alike, so every caller gets the same answer.
479 if (language === 'python') {
480 return resolvePythonModule(importPath, fromFile, context);
481 }
482
483 const projectRoot = context.getProjectRoot();
484 const fromDir = path.dirname(path.join(projectRoot, fromFile));
485
486 // Handle relative imports
487 if (importPath.startsWith('.')) {
488 return resolveRelativeImport(importPath, fromDir, language, context);
489 }
490
491 // Handle absolute/aliased imports (like @/ or src/)
492 const aliased = resolveAliasedImport(importPath, projectRoot, language, context, fromFile);
493 if (aliased) return aliased;
494
495 // C/C++ include directory search: when neither relative nor aliased
496 // resolution found a match, search -I directories from
497 // compile_commands.json or heuristic probing.
498 if (language === 'c' || language === 'cpp') {
499 return resolveCppIncludePath(importPath, language, context);
500 }
501
502 return null;
503}
504
505/**
506 * 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