refactor: centralize path resolution into shared/paths.ts (#2422)

Move all filesystem path helpers (getUserHome, getSpawnDir, getHistoryPath,
getSpawnCloudConfigPath, getCacheDir, getCacheFile, getUpdateFailedPath,
getSshDir, getTmpDir) into a single shared/paths.ts module. This eliminates
scattered homedir()/process.env.HOME patterns across 8+ files and provides
a single import source for all path resolution.

- Create packages/cli/src/shared/paths.ts with 9 exported functions
- Update 17 source files to import from paths.ts
- Add re-exports in ui.ts and history.ts for backward compatibility
- Remove direct homedir() imports from gcp, sprite, local, ssh-keys, etc.
- Add comprehensive unit tests in paths.test.ts
- Bump CLI version to 0.15.34

Co-authored-by: lab <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
A 2026-03-10 00:48:03 -07:00 committed by GitHub
parent 769aa69b31
commit de76599b39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 229 additions and 99 deletions

View file

@ -7,6 +7,7 @@ import { mkdirSync, readFileSync } from "node:fs";
import { handleBillingError, isBillingError, showNonBillingError } from "../shared/billing-guidance";
import { getPackagesForTier, NODE_INSTALL_CMD, needsBun, needsNode } from "../shared/cloud-init";
import { parseJsonObj } from "../shared/parse";
import { getSpawnCloudConfigPath } from "../shared/paths";
import {
killWithTimeout,
SSH_BASE_OPTS,
@ -19,7 +20,6 @@ import { ensureSshKeys, getSshFingerprint, getSshKeyOpts } from "../shared/ssh-k
import { getErrorMessage, isNumber, isString, toObjectArray, toRecord } from "../shared/type-guards";
import {
getServerNameFromEnv,
getSpawnCloudConfigPath,
jsonEscape,
loadApiToken,
logError,