fix(config): expand leading ~ in config paths (supersedes #301)#370
fix(config): expand leading ~ in config paths (supersedes #301)#370cameroncooke wants to merge 5 commits intomainfrom
Conversation
Move the tilde-expansion logic that previously lived as a private helper inside src/cli/commands/init.ts into a shared src/utils/expand-home.ts module so it can be reused by other call sites that need the same behavior. The shared version handles a bare '~', '~/' on POSIX, and '~\\' for Windows-style separators.
resolveEffectiveDerivedDataPath() previously fed any non-absolute input to path.resolve(process.cwd(), ...), which caused configured derivedDataPath values like '~/.foo/derivedData' to materialize as a literal '~' directory under the current working directory. Run the input through expandHomePrefix() before the absolute/relative check so tilde-prefixed paths resolve under the user's home directory as users expect. Add unit coverage for the absolute, relative, default, and tilde-expansion code paths.
normalizePathValue() resolved relative path values against cwd but left a literal '~' prefix in place, so derivedDataPath, projectPath, workspacePath, axePath, and the iOS/macOS template paths under both sessionDefaults and sessionDefaultsProfiles all leaked unexpanded tilde paths through to consumers. Apply expandHomePrefix() before the absolute/relative check inside normalizePathValue() so all callers (session defaults, profiles, and top-level path keys) benefit from a single expansion. Cover the behavior with unit tests for sessionDefaults, top-level path keys, and sessionDefaultsProfiles.
executeXcodeBuildCommand() resolves projectPath, workspacePath, and the derivedDataPath argument before invoking xcodebuild. The resolvePathFromCwd() helper passed non-absolute values straight to path.resolve(process.cwd(), ...), so callers that supplied a tilde path (for example, direct API callers without project-config normalization) ended up with a literal '~' segment under cwd. Run the input through expandHomePrefix() inside resolvePathFromCwd() so tilde-prefixed projectPath and workspacePath resolve under the home directory. Add a unit test that verifies tilde expansion of projectPath and derivedDataPath flows through to the xcodebuild command line.
commit: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f98824a. Configure here.
| return expanded; | ||
| } | ||
| return path.resolve(process.cwd(), pathValue); | ||
| return path.resolve(process.cwd(), expanded); |
There was a problem hiding this comment.
Tilde expansion missed in duplicate resolvePathFromCwd
Medium Severity
app-path-resolver.ts contains its own resolvePathFromCwd that is functionally identical to the one in build-utils.ts, but was not updated with expandHomePrefix. This means tilde-prefixed paths like ~/Code/App.xcodeproj are correctly expanded when passed to executeXcodeBuildCommand but remain literal ~ when the same params flow into resolveAppPathFromBuildSettings (used by device build/run, get-app-path, and macOS build tools). Within a single tool execution (e.g., build_macos.ts), the same projectPath is now expanded in the build step but not in the app-path resolution step — an inconsistency introduced by this PR.
Reviewed by Cursor Bugbot for commit f98824a. Configure here.
| return expanded; | ||
| } | ||
| return path.resolve(process.cwd(), pathValue); | ||
| return path.resolve(process.cwd(), expanded); |
There was a problem hiding this comment.
Duplicate resolvePathFromCwd not updated with tilde expansion
Medium Severity
app-path-resolver.ts contains a private resolvePathFromCwd that is functionally identical to the one in build-utils.ts, but was not updated with expandHomePrefix. This creates inconsistent behavior: MCP tools like build_run_device and build_run_macos call executeXcodeBuildCommand (which now expands tildes) and then resolveAppPathFromBuildSettings (which does not) with the same raw params. A tilde-prefixed path would build successfully but then fail during app-path resolution.
Reviewed by Cursor Bugbot for commit f98824a. Configure here.


Summary
Expands leading
~(and~//~\on Windows) prefixes in user-supplied config paths so values likederivedDataPath: "~/.foo/derivedData"resolve underhomedir()instead of creating a literal~directory under the project root.Fixes #283. Supersedes #301 by @trmquang93 — the original PR could not be cleanly rebased onto current
main(the targeted code inbuild-utils.tsanddevice/build-settings.tshas been refactored or removed since the PR was opened) and additionally bundled an unrelated #287/#300 commit. Reimplemented from scratch against currentmain, following the spirit of the original PR (single shared utility applied at every entry point).What changed
src/utils/expand-home.ts— single canonicalexpandHomePrefix()helper. Replaces the private duplicate insidesrc/cli/commands/init.ts.resolveEffectiveDerivedDataPath()insrc/utils/derived-data-path.tsnow expands tildes before the absolute/relative check.normalizePathValueinsrc/utils/project-config.tsnow expands tildes before the absolute/relative check. Single point of coverage forprojectPath,workspacePath,derivedDataPath,axePath,iosTemplatePath, andmacosTemplatePathacross bothsessionDefaultsandsessionDefaultsProfiles.resolvePathFromCwdinsrc/utils/build-utils.ts(still used for directprojectPath/workspacePathcallers that bypass project-config normalization) now also expands tildes.[Unreleased] / Fixedcrediting [Feature]: Expand ~ (tilde) in derived data path passed via config #283 and @trmquang93's original Expand tilde (~) in config paths like derivedDataPath #301.Ordering note: in
normalizePathValue,tryFileUrlToPathruns beforeexpandHomePrefix, sofile:URLs are not tilde-mangled.Test plan
npm run build— cleannpm run typecheck— cleannpm run lint— cleannpm run format:check— cleannpm test— 156 files, 1634 tests, all passingtest:snapshotandtest:smoke— skipped (require real device/simulator)Unit tests added at every layer:
src/utils/__tests__/expand-home.test.ts— utility behavior (~,~/...,~\\..., non-tilde absolute, non-tilde relative,~user"do not expand", embedded~, empty-string passthrough).src/utils/__tests__/derived-data-path.test.ts— tilde input resolves underhomedir().src/utils/__tests__/project-config.test.ts— tilde expansion across the path keys covered bynormalizePathValue.src/utils/__tests__/build-utils.test.ts— end-to-end throughexecuteXcodeBuildCommandconfirming bothprojectPathandderivedDataPathare tilde-expanded on the command line.