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

Function mountTarget

src/resolution/frameworks/express.ts:633–643  ·  view source on GitHub ↗

* The file a mount's last argument names: an inline `require('./x')`, an * identifier imported from a project file, or one bound to `require('./x')` * in the same file. `x.default` / `x.router` count as `x`.

(expr: string, safe: string, file: string, lang: 'typescript' | 'javascript', context: ResolutionContext)

Source from the content-addressed store, hash-verified

631 * in the same file. `x.default` / `x.router` count as `x`.
632 */
633function mountTarget(expr: string, safe: string, file: string, lang: 'typescript' | 'javascript', context: ResolutionContext): string | null {
634 const inline = /^require\s*\(\s*(['"])([^'"]+)\1\s*\)(?:\.\w+)?$/.exec(expr);
635 if (inline) return resolveImportPath(inline[2]!, file, lang, context);
636 const ident = /^([A-Za-z_$][\w$]*)(?:\.(?:default|router|routes))?$/.exec(expr);
637 if (!ident) return null;
638 const name = ident[1]!;
639 const mapping = context.getImportMappings(file, lang).find((im) => im.localName === name);
640 if (mapping) return resolveImportPath(mapping.source, file, lang, context);
641 const required = new RegExp(`\\b(?:const|let|var)\\s+${name.replace(/\$/g, '\\$')}\\s*=\\s*require\\s*\\(\\s*(['"])([^'"]+)\\1\\s*\\)`).exec(safe);
642 return required ? resolveImportPath(required[2]!, file, lang, context) : null;
643}
644
645/**
646 * Check if a name looks like middleware

Callers 1

postExtractFunction · 0.85

Calls 3

resolveImportPathFunction · 0.90
getImportMappingsMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected