MCPcopy Create free account
hub / github.com/appium/appium / getModuleRootSync

Function getModuleRootSync

packages/support/lib/node.ts:73–92  ·  view source on GitHub ↗
(moduleName: string, filePath: string)

Source from the content-addressed store, hash-verified

71 * @returns Full path to the module root, or null if not found
72 */
73export function getModuleRootSync(moduleName: string, filePath: string): string | null {
74 let currentDir = path.dirname(path.resolve(filePath));
75 let isAtFsRoot = false;
76 while (!isAtFsRoot) {
77 const manifestPath = path.join(currentDir, 'package.json');
78 try {
79 if (
80 _fs.existsSync(manifestPath) &&
81 (JSON.parse(_fs.readFileSync(manifestPath, 'utf8')) as {name?: string}).name === moduleName
82 ) {
83 return currentDir;
84 }
85 } catch {
86 // ignore
87 }
88 currentDir = path.dirname(currentDir);
89 isAtFsRoot = currentDir.length <= path.dirname(currentDir).length;
90 }
91 return null;
92}

Callers

nothing calls this directly

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected