-
-
Notifications
You must be signed in to change notification settings - Fork 260
fix(config): expand leading ~ in config paths (supersedes #301) #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40f017c
Add shared expandHomePrefix utility
cameroncooke 34bef5a
Expand ~ in resolveEffectiveDerivedDataPath
cameroncooke da13af6
Expand ~ in project-config path normalization
cameroncooke 83c9f9c
Expand ~ in build-utils path resolution
cameroncooke f98824a
Add changelog entry for tilde expansion in config paths
cameroncooke 1535672
refactor(utils): unify path resolution helpers in src/utils/path.ts
cameroncooke c83368a
fix(path): normalize traversal segments in resolvePathFromCwd
cameroncooke 8f66e41
refactor(path): drop Windows tilde branch and consolidate helpers
cameroncooke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import path from 'node:path'; | ||
| import { homedir } from 'node:os'; | ||
| import { createMockExecutor } from '../../test-utils/mock-executors.ts'; | ||
| import { resolveAppPathFromBuildSettings } from '../app-path-resolver.ts'; | ||
| import { XcodePlatform } from '../../types/common.ts'; | ||
|
|
||
| describe('resolveAppPathFromBuildSettings', () => { | ||
| it('expands tilde-prefixed projectPath when invoking xcodebuild', async () => { | ||
| let capturedCommand: string[] | undefined; | ||
|
|
||
| const mockExecutor = createMockExecutor({ | ||
| success: true, | ||
| output: | ||
| 'BUILT_PRODUCTS_DIR = /Build/Products/Debug-iphonesimulator\nFULL_PRODUCT_NAME = App.app\n', | ||
| exitCode: 0, | ||
| onExecute: (command) => { | ||
| capturedCommand = command; | ||
| }, | ||
| }); | ||
|
|
||
| await resolveAppPathFromBuildSettings( | ||
| { | ||
| projectPath: '~/Code/App.xcodeproj', | ||
| scheme: 'App', | ||
| platform: XcodePlatform.iOSSimulator, | ||
| }, | ||
| mockExecutor, | ||
| ); | ||
|
|
||
| const expected = path.join(homedir(), 'Code/App.xcodeproj'); | ||
| expect(capturedCommand).toBeDefined(); | ||
| expect(capturedCommand).toContain(expected); | ||
| expect(capturedCommand).not.toContain('~/Code/App.xcodeproj'); | ||
| }); | ||
|
|
||
| it('expands tilde-prefixed workspacePath when invoking xcodebuild', async () => { | ||
| let capturedCommand: string[] | undefined; | ||
|
|
||
| const mockExecutor = createMockExecutor({ | ||
| success: true, | ||
| output: | ||
| 'BUILT_PRODUCTS_DIR = /Build/Products/Debug-iphonesimulator\nFULL_PRODUCT_NAME = App.app\n', | ||
| exitCode: 0, | ||
| onExecute: (command) => { | ||
| capturedCommand = command; | ||
| }, | ||
| }); | ||
|
|
||
| await resolveAppPathFromBuildSettings( | ||
| { | ||
| workspacePath: '~/Code/App.xcworkspace', | ||
| scheme: 'App', | ||
| platform: XcodePlatform.iOSSimulator, | ||
| }, | ||
| mockExecutor, | ||
| ); | ||
|
|
||
| const expected = path.join(homedir(), 'Code/App.xcworkspace'); | ||
| expect(capturedCommand).toBeDefined(); | ||
| expect(capturedCommand).toContain(expected); | ||
| }); | ||
|
|
||
| it('leaves absolute paths unchanged', async () => { | ||
| let capturedCommand: string[] | undefined; | ||
|
|
||
| const mockExecutor = createMockExecutor({ | ||
| success: true, | ||
| output: | ||
| 'BUILT_PRODUCTS_DIR = /Build/Products/Debug-iphonesimulator\nFULL_PRODUCT_NAME = App.app\n', | ||
| exitCode: 0, | ||
| onExecute: (command) => { | ||
| capturedCommand = command; | ||
| }, | ||
| }); | ||
|
|
||
| await resolveAppPathFromBuildSettings( | ||
| { | ||
| projectPath: '/abs/path/App.xcodeproj', | ||
| scheme: 'App', | ||
| platform: XcodePlatform.iOSSimulator, | ||
| }, | ||
| mockExecutor, | ||
| ); | ||
|
|
||
| expect(capturedCommand).toContain('/abs/path/App.xcodeproj'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import path from 'node:path'; | ||
| import { homedir } from 'node:os'; | ||
| import { resolveEffectiveDerivedDataPath } from '../derived-data-path.ts'; | ||
| import { DERIVED_DATA_DIR } from '../log-paths.ts'; | ||
|
|
||
| describe('resolveEffectiveDerivedDataPath', () => { | ||
| it('returns the default derived data dir when input is undefined', () => { | ||
| expect(resolveEffectiveDerivedDataPath(undefined)).toBe(DERIVED_DATA_DIR); | ||
| }); | ||
|
|
||
| it('returns the default derived data dir when input is empty', () => { | ||
| expect(resolveEffectiveDerivedDataPath('')).toBe(DERIVED_DATA_DIR); | ||
| }); | ||
|
|
||
| it('returns the default derived data dir when input is whitespace', () => { | ||
| expect(resolveEffectiveDerivedDataPath(' ')).toBe(DERIVED_DATA_DIR); | ||
| }); | ||
|
|
||
| it('returns absolute paths unchanged', () => { | ||
| expect(resolveEffectiveDerivedDataPath('/abs/path/dd')).toBe('/abs/path/dd'); | ||
| }); | ||
|
|
||
| it('resolves relative paths against the current working directory', () => { | ||
| expect(resolveEffectiveDerivedDataPath('.derivedData/e2e')).toBe( | ||
| path.resolve(process.cwd(), '.derivedData/e2e'), | ||
| ); | ||
| }); | ||
|
|
||
| it('expands a bare ~ input to the home directory', () => { | ||
| expect(resolveEffectiveDerivedDataPath('~')).toBe(homedir()); | ||
| }); | ||
|
|
||
| it('expands a ~/-prefixed input under the home directory', () => { | ||
| expect(resolveEffectiveDerivedDataPath('~/.foo/derivedData')).toBe( | ||
| path.join(homedir(), '.foo/derivedData'), | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import path from 'node:path'; | ||
| import { homedir } from 'node:os'; | ||
| import { expandHomePrefix, resolvePathFromCwd } from '../path.ts'; | ||
|
|
||
| describe('expandHomePrefix', () => { | ||
| it('expands a bare ~ to the home directory', () => { | ||
| expect(expandHomePrefix('~')).toBe(homedir()); | ||
| }); | ||
|
|
||
| it('expands a leading ~/ to the home directory', () => { | ||
| expect(expandHomePrefix('~/foo/bar')).toBe(path.join(homedir(), 'foo/bar')); | ||
| }); | ||
|
|
||
| it('returns absolute paths unchanged', () => { | ||
| expect(expandHomePrefix('/absolute/path')).toBe('/absolute/path'); | ||
| }); | ||
|
|
||
| it('returns relative paths unchanged', () => { | ||
| expect(expandHomePrefix('relative/path')).toBe('relative/path'); | ||
| }); | ||
|
|
||
| it('does not expand ~user style prefixes', () => { | ||
| expect(expandHomePrefix('~other/foo')).toBe('~other/foo'); | ||
| }); | ||
|
|
||
| it('does not expand ~ embedded later in the path', () => { | ||
| expect(expandHomePrefix('foo/~/bar')).toBe('foo/~/bar'); | ||
| }); | ||
|
|
||
| it('does not expand a leading ~ followed by whitespace', () => { | ||
| expect(expandHomePrefix(' ~/foo')).toBe(' ~/foo'); | ||
| }); | ||
|
|
||
| it('preserves multi-byte characters in the expanded segment', () => { | ||
| expect(expandHomePrefix('~/日本語/файл')).toBe(path.join(homedir(), '日本語/файл')); | ||
| }); | ||
|
|
||
| it('returns an empty string unchanged', () => { | ||
| expect(expandHomePrefix('')).toBe(''); | ||
| }); | ||
| }); | ||
|
|
||
| describe('resolvePathFromCwd', () => { | ||
| it('expands a bare ~ to the home directory', () => { | ||
| expect(resolvePathFromCwd('~')).toBe(homedir()); | ||
| }); | ||
|
|
||
| it('expands a leading ~/ under the home directory', () => { | ||
| expect(resolvePathFromCwd('~/.foo/derivedData')).toBe(path.join(homedir(), '.foo/derivedData')); | ||
| }); | ||
|
|
||
| it('returns absolute paths unchanged', () => { | ||
| expect(resolvePathFromCwd('/abs/path')).toBe('/abs/path'); | ||
| }); | ||
|
|
||
| it('resolves relative paths against process.cwd() by default', () => { | ||
| expect(resolvePathFromCwd('rel/path')).toBe(path.resolve(process.cwd(), 'rel/path')); | ||
| }); | ||
|
|
||
| it('resolves relative paths against an explicit cwd when provided', () => { | ||
| expect(resolvePathFromCwd('rel/path', '/some/base')).toBe( | ||
| path.resolve('/some/base', 'rel/path'), | ||
| ); | ||
| }); | ||
|
|
||
| it('does not resolve absolute paths against an explicit cwd', () => { | ||
| expect(resolvePathFromCwd('/abs/path', '/some/base')).toBe('/abs/path'); | ||
| }); | ||
|
|
||
| it('does not expand ~user style prefixes', () => { | ||
| expect(resolvePathFromCwd('~other/foo')).toBe(path.resolve(process.cwd(), '~other/foo')); | ||
| }); | ||
|
|
||
| it('normalizes traversal segments in absolute paths', () => { | ||
| expect(resolvePathFromCwd('/foo/..')).toBe('/'); | ||
| }); | ||
|
|
||
| it('normalizes interior traversal segments in absolute paths', () => { | ||
| expect(resolvePathFromCwd('/a/b/../c')).toBe('/a/c'); | ||
| }); | ||
|
|
||
| it('returns undefined when pathValue is undefined', () => { | ||
| expect(resolvePathFromCwd(undefined)).toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.