(fileLike)
| 548 | } |
| 549 | |
| 550 | function locate(fileLike) { |
| 551 | if (fs.existsSync(fileLike)) { |
| 552 | return fileLike |
| 553 | } |
| 554 | |
| 555 | if (!runfiles) { |
| 556 | throw new Error('Unable to find ' + fileLike) |
| 557 | } |
| 558 | |
| 559 | try { |
| 560 | return runfiles.resolve(fileLike) |
| 561 | } catch { |
| 562 | // Fall through |
| 563 | } |
| 564 | |
| 565 | // Is the item in the workspace? |
| 566 | try { |
| 567 | return runfiles.resolveWorkspaceRelative(fileLike) |
| 568 | } catch { |
| 569 | // Fall through |
| 570 | } |
| 571 | |
| 572 | // Find the repo mapping file |
| 573 | let repoMappingFile |
| 574 | try { |
| 575 | repoMappingFile = runfiles.resolve('_repo_mapping') |
| 576 | } catch { |
| 577 | throw new Error('Unable to locate (no repo mapping file): ' + fileLike) |
| 578 | } |
| 579 | const lines = fs.readFileSync(repoMappingFile, { encoding: 'utf8' }).split('\n') |
| 580 | |
| 581 | // Build a map of "repo we declared we need" to "path" |
| 582 | const mapping = {} |
| 583 | for (const line of lines) { |
| 584 | if (line.startsWith(',')) { |
| 585 | const parts = line.split(',', 3) |
| 586 | mapping[parts[1]] = parts[2] |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Get the first segment of the path |
| 591 | const pathSegments = fileLike.split('/') |
| 592 | if (!pathSegments.length) { |
| 593 | throw new Error('Unable to locate ' + fileLike) |
| 594 | } |
| 595 | |
| 596 | pathSegments[0] = mapping[pathSegments[0]] ? mapping[pathSegments[0]] : '_main' |
| 597 | |
| 598 | try { |
| 599 | return runfiles.resolve(path.join(...pathSegments)) |
| 600 | } catch { |
| 601 | // Fall through |
| 602 | } |
| 603 | |
| 604 | throw new Error('Unable to find ' + fileLike) |
| 605 | } |
| 606 | |
| 607 | // PUBLIC API |
no test coverage detected