(options: {
cwd?: string;
configPath?: string;
})
| 3 | import { dirname, resolve } from "path"; |
| 4 | |
| 5 | export function detectProjectRoot(options: { |
| 6 | cwd?: string; |
| 7 | configPath?: string; |
| 8 | }): string | undefined { |
| 9 | let projectRootDir = options.cwd || process.cwd(); |
| 10 | if (options.configPath) { |
| 11 | const fullPath = resolve(projectRootDir, options.configPath); |
| 12 | if (!fileExistsSync(fullPath)) { |
| 13 | throw new FirebaseError(`Could not load config file ${options.configPath}.`, { |
| 14 | exit: 1, |
| 15 | status: 404, |
| 16 | }); |
| 17 | } |
| 18 | |
| 19 | return dirname(fullPath); |
| 20 | } |
| 21 | |
| 22 | while (!fileExistsSync(resolve(projectRootDir, "./firebase.json"))) { |
| 23 | const parentDir = dirname(projectRootDir); |
| 24 | if (parentDir === projectRootDir) { |
| 25 | return undefined; |
| 26 | } |
| 27 | projectRootDir = parentDir; |
| 28 | } |
| 29 | return projectRootDir; |
| 30 | } |
no test coverage detected
searching dependent graphs…