( cwd: string, path: string, errorSuffix = '' )
| 9 | * A helper function to validate the `rootDirectory` input. |
| 10 | */ |
| 11 | export async function validateRootDirectory( |
| 12 | cwd: string, |
| 13 | path: string, |
| 14 | errorSuffix = '' |
| 15 | ) { |
| 16 | const pathStat = await lstat(path).catch(() => null); |
| 17 | const suffix = errorSuffix ? ` ${errorSuffix}` : ''; |
| 18 | |
| 19 | if (!pathStat) { |
| 20 | output.error( |
| 21 | `The provided path ${chalk.cyan( |
| 22 | `“${toHumanPath(path)}”` |
| 23 | )} does not exist.${suffix}` |
| 24 | ); |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | if (!pathStat.isDirectory()) { |
| 29 | output.error( |
| 30 | `The provided path ${chalk.cyan( |
| 31 | `“${toHumanPath(path)}”` |
| 32 | )} is a file, but expected a directory.${suffix}` |
| 33 | ); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | if (!path.startsWith(cwd)) { |
| 38 | output.error( |
| 39 | `The provided path ${chalk.cyan( |
| 40 | `“${toHumanPath(path)}”` |
| 41 | )} is outside of the project.${suffix}` |
| 42 | ); |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | export default async function validatePaths( |
| 50 | client: Client, |
no test coverage detected