(componentFilePath: string)
| 264 | |
| 265 | /** Walk up from a component file to find the directory containing its module BUILD.bazel */ |
| 266 | export 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/..." */ |
| 282 | export function getModuleNameFromImport(importPath: string): string { |
no test coverage detected