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

Function mountTarget

src/resolution/frameworks/express.ts:619–629  ·  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

617 * in the same file. `x.default` / `x.router` count as `x`.
618 */
619function mountTarget(expr: string, safe: string, file: string, lang: 'typescript' | 'javascript', context: ResolutionContext): string | null {
620 const inline = /^require\s*\(\s*(['"])([^'"]+)\1\s*\)(?:\.\w+)?$/.exec(expr);
621 if (inline) return resolveImportPath(inline[2]!, file, lang, context);
622 const ident = /^([A-Za-z_$][\w$]*)(?:\.(?:default|router|routes))?$/.exec(expr);
623 if (!ident) return null;
624 const name = ident[1]!;
625 const mapping = context.getImportMappings(file, lang).find((im) => im.localName === name);
626 if (mapping) return resolveImportPath(mapping.source, file, lang, context);
627 const required = new RegExp(`\\b(?:const|let|var)\\s+${name.replace(/\$/g, '\\$')}\\s*=\\s*require\\s*\\(\\s*(['"])([^'"]+)\\1\\s*\\)`).exec(safe);
628 return required ? resolveImportPath(required[2]!, file, lang, context) : null;
629}
630
631/**
632 * 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