( absoluteBaseUrl: string, paths: Paths, addMatchAll: boolean )
| 20 | * @param addMatchAll |
| 21 | */ |
| 22 | export 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. |
no test coverage detected
searching dependent graphs…