(projectRoot: string)
| 257 | * The returned string is a human phrase that slots into "… looks like {reason}". |
| 258 | */ |
| 259 | export function unsafeIndexRootReason(projectRoot: string): string | null { |
| 260 | const resolve = (p: string): string => { |
| 261 | try { |
| 262 | return fs.realpathSync(path.resolve(p)); |
| 263 | } catch { |
| 264 | return path.resolve(p); |
| 265 | } |
| 266 | }; |
| 267 | const resolved = resolve(projectRoot); |
| 268 | |
| 269 | // Filesystem root: `/` on POSIX, a drive root like `C:\` on Windows. |
| 270 | if (path.parse(resolved).root === resolved) { |
| 271 | return 'the filesystem root'; |
| 272 | } |
| 273 | |
| 274 | const home = resolve(os.homedir()); |
| 275 | // Case-insensitive on macOS/Windows (case-preserving but case-insensitive FS). |
| 276 | const norm = (p: string): string => |
| 277 | process.platform === 'darwin' || process.platform === 'win32' ? p.toLowerCase() : p; |
| 278 | const r = norm(resolved); |
| 279 | const h = norm(home); |
| 280 | |
| 281 | if (r === h) { |
| 282 | return 'your home directory'; |
| 283 | } |
| 284 | // An ancestor of home (e.g. `/Users`, `/home`) — even broader than home. |
| 285 | if (h.startsWith(r + path.sep)) { |
| 286 | return 'a parent of your home directory'; |
| 287 | } |
| 288 | return null; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * `dev:ino` for a path, or null if it can't be stat'd or the platform doesn't |
no test coverage detected