(fromPath: string, toPath: string)
| 320 | * Returns true if the `toPath` is a subdirectory of `fromPath`. |
| 321 | */ |
| 322 | export function isSubdir(fromPath: string, toPath: string) { |
| 323 | const resolvedFrom = path.resolve(fromPath) |
| 324 | const resolvedTo = path.resolve(toPath) |
| 325 | |
| 326 | if (process.platform === 'win32') { |
| 327 | const fromDrive = path.parse(resolvedFrom).root.toLowerCase() |
| 328 | const toDrive = path.parse(resolvedTo).root.toLowerCase() |
| 329 | if (fromDrive !== toDrive) { |
| 330 | return false |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return !path.relative(resolvedFrom, resolvedTo).startsWith('..') |
| 335 | } |
| 336 | |
| 337 | export function isValidProjectRoot(dir: string): boolean { |
| 338 | return !isSubdir(dir, os.homedir()) |
no test coverage detected