(input: ResolveProjectDirInput)
| 42 | * --dir wins; otherwise the git toplevel of cwd (falling back to cwd itself). |
| 43 | */ |
| 44 | export async function resolveProjectDir(input: ResolveProjectDirInput): Promise<string> { |
| 45 | if (input.explicitDir != null) { |
| 46 | const explicitDir = path.resolve(input.cwd, input.explicitDir); |
| 47 | await ensureDirectory(explicitDir); |
| 48 | return explicitDir; |
| 49 | } |
| 50 | |
| 51 | const cwd = path.resolve(input.cwd); |
| 52 | await ensureDirectory(cwd); |
| 53 | const gitRoot = await findGitRoot(cwd); |
| 54 | return gitRoot ?? cwd; |
| 55 | } |
| 56 | |
| 57 | async function ensureDirectory(dirPath: string): Promise<void> { |
| 58 | const stats = await fs.stat(dirPath); |
no test coverage detected