MCPcopy Create free account
hub / github.com/Snapchat/Valdi / findModuleDir

Function findModuleDir

npm_modules/cli/src/preview/previewGenerator.ts:266–279  ·  view source on GitHub ↗
(componentFilePath: string)

Source from the content-addressed store, hash-verified

264
265/** Walk up from a component file to find the directory containing its module BUILD.bazel */
266export function findModuleDir(componentFilePath: string): string {
267 let dir = path.dirname(componentFilePath);
268 while (dir !== path.dirname(dir)) {
269 const buildFile = path.join(dir, 'BUILD.bazel');
270 if (fs.existsSync(buildFile)) {
271 const content = fs.readFileSync(buildFile, 'utf8');
272 if (/valdi_module\s*\(/.test(content)) {
273 return dir;
274 }
275 }
276 dir = path.dirname(dir);
277 }
278 throw new Error(`Could not find a BUILD.bazel with valdi_module() above ${componentFilePath}`);
279}
280
281/** Extract the module name (first segment) from an import path like "widgets/src/..." */
282export function getModuleNameFromImport(importPath: string): string {

Callers 3

valdiPreviewFunction · 0.90
generateTsconfigFunction · 0.85

Calls 3

readFileSyncMethod · 0.80
joinMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected