This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
[xdl] Allow dev client apps to be launched in the iOS simulator #3182
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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,144 @@ | ||
/** | ||
* BundleIdentifier.ts | ||
* | ||
* NOTE: | ||
* The code in this module originates from eas-cli and the canonical version of | ||
* it is in | ||
* https://github.com/expo/eas-cli/blob/6a0a9bbaaad03b053b5930f7d14bde35b4d0a9f0/packages/eas-cli/src/build/ios/bundleIdentifer.ts#L36 | ||
* Any changes to this code should be applied to eas-cli as well! | ||
* | ||
* TODO: move the code for configuring and validating the bundle identifier | ||
* to a shared package that can be used for both eas-cli and expo-cli. | ||
*/ | ||
import { ExpoConfig, getConfigFilePaths, getProjectConfigDescription } from '@expo/config'; | ||
import { IOSConfig } from '@expo/config-plugins'; | ||
import JsonFile from '@expo/json-file'; | ||
import assert from 'assert'; | ||
import chalk from 'chalk'; | ||
import { prompt } from 'prompts'; | ||
|
||
import { logInfo, logWarning } from './project/ProjectUtils'; | ||
|
||
enum BundleIdentiferSource { | ||
XcodeProject, | ||
AppJson, | ||
} | ||
|
||
export async function configureBundleIdentifierAsync( | ||
projectRoot: string, | ||
exp: ExpoConfig | ||
): Promise<string> { | ||
const configDescription = getProjectConfigDescription(projectRoot); | ||
const bundleIdentifierFromPbxproj = IOSConfig.BundleIdentifier.getBundleIdentifierFromPbxproj( | ||
projectRoot | ||
); | ||
const bundleIdentifierFromConfig = IOSConfig.BundleIdentifier.getBundleIdentifier(exp); | ||
if (bundleIdentifierFromPbxproj && bundleIdentifierFromConfig) { | ||
if (bundleIdentifierFromPbxproj === bundleIdentifierFromConfig) { | ||
return bundleIdentifierFromConfig; | ||
} else { | ||
logWarning( | ||
projectRoot, | ||
'expo', | ||
`We detected that your Xcode project is configured with a different bundle identifier than the one defined in ${configDescription}.` | ||
); | ||
const hasBundleIdentifierInStaticConfig = await hasBundleIdentifierInStaticConfigAsync( | ||
projectRoot, | ||
exp | ||
); | ||
if (!hasBundleIdentifierInStaticConfig) { | ||
logInfo( | ||
projectRoot, | ||
'expo', | ||
`If you choose the one defined in ${configDescription} we'll automatically configure your Xcode project with it. | ||
However, if you choose the one defined in the Xcode project you'll have to update ${configDescription} on your own.` | ||
); | ||
} | ||
const { bundleIdentifierSource } = await prompt({ | ||
type: 'select', | ||
name: 'bundleIdentifierSource', | ||
message: 'Which bundle identifier should we use?', | ||
choices: [ | ||
{ | ||
title: `${chalk.bold(bundleIdentifierFromPbxproj)} - In Xcode project`, | ||
value: BundleIdentiferSource.XcodeProject, | ||
}, | ||
{ | ||
title: `${chalk.bold(bundleIdentifierFromConfig)} - In your ${configDescription}`, | ||
value: BundleIdentiferSource.AppJson, | ||
}, | ||
], | ||
}); | ||
if (bundleIdentifierSource === BundleIdentiferSource.XcodeProject) { | ||
IOSConfig.BundleIdentifier.setBundleIdentifierForPbxproj( | ||
projectRoot, | ||
bundleIdentifierFromConfig | ||
); | ||
return bundleIdentifierFromConfig; | ||
} else { | ||
if (hasBundleIdentifierInStaticConfig) { | ||
await updateAppJsonConfigAsync(projectRoot, exp, bundleIdentifierFromPbxproj); | ||
} else { | ||
throw new Error(missingBundleIdentifierMessage(configDescription)); | ||
} | ||
return bundleIdentifierFromPbxproj; | ||
} | ||
} | ||
} else if (bundleIdentifierFromPbxproj && !bundleIdentifierFromConfig) { | ||
if (getConfigFilePaths(projectRoot).staticConfigPath) { | ||
await updateAppJsonConfigAsync(projectRoot, exp, bundleIdentifierFromPbxproj); | ||
return bundleIdentifierFromPbxproj; | ||
} else { | ||
throw new Error(missingBundleIdentifierMessage(configDescription)); | ||
} | ||
} else if (!bundleIdentifierFromPbxproj && bundleIdentifierFromConfig) { | ||
IOSConfig.BundleIdentifier.setBundleIdentifierForPbxproj( | ||
projectRoot, | ||
bundleIdentifierFromConfig | ||
); | ||
return bundleIdentifierFromConfig; | ||
} else { | ||
throw new Error(missingBundleIdentifierMessage(configDescription)); | ||
} | ||
} | ||
|
||
function missingBundleIdentifierMessage(configDescription: string): string { | ||
return `Please define "ios.bundleIdentifier" in ${configDescription}.`; | ||
} | ||
|
||
async function updateAppJsonConfigAsync( | ||
projectDir: string, | ||
exp: ExpoConfig, | ||
newBundleIdentifier: string | ||
): Promise<void> { | ||
const paths = getConfigFilePaths(projectDir); | ||
assert(paths.staticConfigPath, "Can't update dynamic configs"); | ||
|
||
const rawStaticConfig = (await JsonFile.readAsync(paths.staticConfigPath)) as any; | ||
rawStaticConfig.expo = { | ||
...rawStaticConfig.expo, | ||
ios: { ...rawStaticConfig.expo?.ios, bundleIdentifier: newBundleIdentifier }, | ||
}; | ||
await JsonFile.writeAsync(paths.staticConfigPath, rawStaticConfig); | ||
|
||
exp.ios = { ...exp.ios, bundleIdentifier: newBundleIdentifier }; | ||
} | ||
|
||
/** | ||
* Check if static config exists and if ios.bundleIdentifier is defined there. | ||
* It will return false if the value in static config is different than "ios.bundleIdentifier" in ExpoConfig | ||
*/ | ||
async function hasBundleIdentifierInStaticConfigAsync( | ||
projectDir: string, | ||
exp: ExpoConfig | ||
): Promise<boolean> { | ||
if (!exp.ios?.bundleIdentifier) { | ||
return false; | ||
} | ||
const paths = getConfigFilePaths(projectDir); | ||
if (!paths.staticConfigPath) { | ||
return false; | ||
} | ||
const rawStaticConfig = JsonFile.read(paths.staticConfigPath) as any; | ||
return rawStaticConfig?.expo?.ios?.bundleIdentifier === exp.ios.bundleIdentifier; | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a big doc block here to point to the canonical version of this code in eas-cli, so it's clearly documented that this is a copy/paste fork of it