MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / locate

Function locate

javascript/selenium-webdriver/testing/index.js:655–710  ·  view source on GitHub ↗
(fileLike)

Source from the content-addressed store, hash-verified

653}
654
655function locate(fileLike) {
656 if (fs.existsSync(fileLike)) {
657 return fileLike
658 }
659
660 if (!runfiles) {
661 throw new Error('Unable to find ' + fileLike)
662 }
663
664 try {
665 return runfiles.resolve(fileLike)
666 } catch {
667 // Fall through
668 }
669
670 // Is the item in the workspace?
671 try {
672 return runfiles.resolveWorkspaceRelative(fileLike)
673 } catch {
674 // Fall through
675 }
676
677 // Find the repo mapping file
678 let repoMappingFile
679 try {
680 repoMappingFile = runfiles.resolve('_repo_mapping')
681 } catch {
682 throw new Error('Unable to locate (no repo mapping file): ' + fileLike)
683 }
684 const lines = fs.readFileSync(repoMappingFile, { encoding: 'utf8' }).split('\n')
685
686 // Build a map of "repo we declared we need" to "path"
687 const mapping = {}
688 for (const line of lines) {
689 if (line.startsWith(',')) {
690 const parts = line.split(',', 3)
691 mapping[parts[1]] = parts[2]
692 }
693 }
694
695 // Get the first segment of the path
696 const pathSegments = fileLike.split('/')
697 if (!pathSegments.length) {
698 throw new Error('Unable to locate ' + fileLike)
699 }
700
701 pathSegments[0] = mapping[pathSegments[0]] ? mapping[pathSegments[0]] : '_main'
702
703 try {
704 return runfiles.resolve(path.join(...pathSegments))
705 } catch {
706 // Fall through
707 }
708
709 throw new Error('Unable to find ' + fileLike)
710}
711
712// PUBLIC API

Callers 13

addon_test.jsFile · 0.85
options_test.jsFile · 0.85
zip_test.jsFile · 0.85
options_test.jsFile · 0.85
index.jsFile · 0.85
initFunction · 0.85
builderMethod · 0.85
bazelJavaFunction · 0.85

Calls 2

splitMethod · 0.80
resolveMethod · 0.45

Tested by

no test coverage detected