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

Function getAbsoluteMappingEntries

src/mapping-entry.ts:22–50  ·  view source on GitHub ↗
(
  absoluteBaseUrl: string,
  paths: Paths,
  addMatchAll: boolean
)

Source from the content-addressed store, hash-verified

20 * @param addMatchAll
21 */
22export function getAbsoluteMappingEntries(
23 absoluteBaseUrl: string,
24 paths: Paths,
25 addMatchAll: boolean
26): ReadonlyArray<MappingEntry> {
27 // Resolve all paths to absolute form once here, and sort them by
28 // longest prefix once here, this saves time on each request later.
29 // We need to put them in an array to preserve the sorting order.
30 const sortedKeys = sortByLongestPrefix(Object.keys(paths));
31 const absolutePaths: Array<MappingEntry> = [];
32 for (const key of sortedKeys) {
33 absolutePaths.push({
34 pattern: key,
35 paths: paths[key].map((pathToResolve) =>
36 path.resolve(absoluteBaseUrl, pathToResolve)
37 ),
38 });
39 }
40 // If there is no match-all path specified in the paths section of tsconfig, then try to match
41 // all paths relative to baseUrl, this is how typescript works.
42 if (!paths["*"] && addMatchAll) {
43 absolutePaths.push({
44 pattern: "*",
45 paths: [`${absoluteBaseUrl.replace(/\/$/, "")}/*`],
46 });
47 }
48
49 return absolutePaths;
50}
51
52/**
53 * Sort path patterns.

Callers 1

Calls 1

sortByLongestPrefixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…