( extensions: ReadonlyArray<string>, absolutePathMappings: ReadonlyArray<MappingEntry>, requestedModule: string )
| 16 | * 4. Check for files named as request ending in "index" with any of the extensions. |
| 17 | */ |
| 18 | export 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? |
| 59 | export function getStrippedPath(tryPath: TryPath): string { |
no test coverage detected
searching dependent graphs…