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