MCPcopy
hub / github.com/jonaskello/tsconfig-paths / getPathsToTry

Function getPathsToTry

src/try-path.ts:18–56  ·  view source on GitHub ↗
(
  extensions: ReadonlyArray<string>,
  absolutePathMappings: ReadonlyArray<MappingEntry>,
  requestedModule: string
)

Source from the content-addressed store, hash-verified

16 * 4. Check for files named as request ending in "index" with any of the extensions.
17 */
18export function getPathsToTry(
19 extensions: ReadonlyArray<string>,
20 absolutePathMappings: ReadonlyArray<MappingEntry>,
21 requestedModule: string
22): ReadonlyArray<TryPath> | undefined {
23 if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") {
24 return undefined;
25 }
26
27 const pathsToTry: Array<TryPath> = [];
28 for (const entry of absolutePathMappings) {
29 const starMatch =
30 entry.pattern === requestedModule
31 ? ""
32 : matchStar(entry.pattern, requestedModule);
33 if (starMatch !== undefined) {
34 for (const physicalPathPattern of entry.paths) {
35 const physicalPath = physicalPathPattern.replace("*", starMatch);
36 pathsToTry.push({ type: "file", path: physicalPath });
37 pathsToTry.push(
38 ...extensions.map(
39 (e) => ({ type: "extension", path: physicalPath + e } as TryPath)
40 )
41 );
42 pathsToTry.push({
43 type: "package",
44 path: path.join(physicalPath, "/package.json"),
45 });
46 const indexPath = path.join(physicalPath, "/index");
47 pathsToTry.push(
48 ...extensions.map(
49 (e) => ({ type: "index", path: indexPath + e } as TryPath)
50 )
51 );
52 }
53 }
54 }
55 return pathsToTry.length === 0 ? undefined : pathsToTry;
56}
57
58// Not sure why we don't just return the full found path?
59export function getStrippedPath(tryPath: TryPath): string {

Callers 1

try-path.test.tsFile · 0.90

Calls 1

matchStarFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…