(fileLike)
| 674 | } |
| 675 | |
| 676 | function locate(fileLike) { |
| 677 | if (fs.existsSync(fileLike)) { |
| 678 | return fileLike |
| 679 | } |
| 680 | |
| 681 | if (!runfiles) { |
| 682 | throw new Error('Unable to find ' + fileLike) |
| 683 | } |
| 684 | |
| 685 | try { |
| 686 | return runfiles.resolve(fileLike) |
| 687 | } catch { |
| 688 | // Fall through |
| 689 | } |
| 690 | |
| 691 | // Is the item in the workspace? |
| 692 | try { |
| 693 | return runfiles.resolveWorkspaceRelative(fileLike) |
| 694 | } catch { |
| 695 | // Fall through |
| 696 | } |
| 697 | |
| 698 | // Find the repo mapping file |
| 699 | let repoMappingFile |
| 700 | try { |
| 701 | repoMappingFile = runfiles.resolve('_repo_mapping') |
| 702 | } catch { |
| 703 | throw new Error('Unable to locate (no repo mapping file): ' + fileLike) |
| 704 | } |
| 705 | const lines = fs.readFileSync(repoMappingFile, { encoding: 'utf8' }).split('\n') |
| 706 | |
| 707 | // Build a map of "repo we declared we need" to "path" |
| 708 | const mapping = {} |
| 709 | for (const line of lines) { |
| 710 | if (line.startsWith(',')) { |
| 711 | const parts = line.split(',', 3) |
| 712 | mapping[parts[1]] = parts[2] |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | // Get the first segment of the path |
| 717 | const pathSegments = fileLike.split('/') |
| 718 | if (!pathSegments.length) { |
| 719 | throw new Error('Unable to locate ' + fileLike) |
| 720 | } |
| 721 | |
| 722 | pathSegments[0] = mapping[pathSegments[0]] ? mapping[pathSegments[0]] : '_main' |
| 723 | |
| 724 | try { |
| 725 | return runfiles.resolve(path.join(...pathSegments)) |
| 726 | } catch { |
| 727 | // Fall through |
| 728 | } |
| 729 | |
| 730 | throw new Error('Unable to find ' + fileLike) |
| 731 | } |
| 732 | |
| 733 | // PUBLIC API |
no test coverage detected