(path: string, relativeTo?: string)
| 445 | * Set the current working directory |
| 446 | */ |
| 447 | export function setCwd(path: string, relativeTo?: string): void { |
| 448 | const resolved = isAbsolute(path) |
| 449 | ? path |
| 450 | : resolve(relativeTo || getFsImplementation().cwd(), path) |
| 451 | // Resolve symlinks to match the behavior of pwd -P. |
| 452 | // realpathSync throws ENOENT if the path doesn't exist - convert to a |
| 453 | // friendlier error message instead of a separate existsSync pre-check (TOCTOU). |
| 454 | let physicalPath: string |
| 455 | try { |
| 456 | physicalPath = getFsImplementation().realpathSync(resolved) |
| 457 | } catch (e) { |
| 458 | if (isENOENT(e)) { |
| 459 | throw new Error(`Path "${resolved}" does not exist`) |
| 460 | } |
| 461 | throw e |
| 462 | } |
| 463 | |
| 464 | setCwdState(physicalPath) |
| 465 | if (process.env.NODE_ENV !== 'test') { |
| 466 | try { |
| 467 | logEvent('tengu_shell_set_cwd', { |
| 468 | success: true, |
| 469 | }) |
| 470 | } catch (_error) { |
| 471 | // Ignore logging errors to prevent test failures |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 |
no test coverage detected