-
Notifications
You must be signed in to change notification settings - Fork 160
[eas-build] warn when creating a production build from Expo Go #3073
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
Open
vonovak
wants to merge
2
commits into
main
Choose a base branch
from
vonovak/_eas-build_discourage_expo_go_for_production
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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 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
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
86 changes: 86 additions & 0 deletions
86
packages/eas-cli/src/project/__tests__/discourageExpoGoForProd-test.ts
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 { Platform, Workflow } from '@expo/eas-build-job'; | ||
| import getenv from 'getenv'; | ||
| import resolveFrom from 'resolve-from'; | ||
|
|
||
| import type { ProfileData } from '../../utils/profiles'; | ||
| import { resolveVcsClient } from '../../vcs'; | ||
| import { detectExpoGoProdBuildAsync } from '../discourageExpoGoForProdAsync'; | ||
|
|
||
| jest.mock('getenv'); | ||
| jest.mock('resolve-from'); | ||
| jest.mock('../workflow', () => ({ | ||
| resolveWorkflowPerPlatformAsync: jest.fn(), | ||
| })); | ||
|
|
||
| const mockResolveWorkflowPerPlatformAsync = jest.mocked( | ||
| require('../workflow').resolveWorkflowPerPlatformAsync | ||
| ); | ||
|
|
||
| const projectDir = '/app'; | ||
| const vcsClient = resolveVcsClient(); | ||
|
|
||
| const createMockBuildProfile = (profileName: string): ProfileData<'build'> => ({ | ||
| profileName, | ||
| platform: Platform.ANDROID, | ||
| profile: {} as any, | ||
| }); | ||
|
|
||
| describe(detectExpoGoProdBuildAsync, () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| jest.mocked(getenv.boolish).mockReturnValue(false); | ||
| jest.mocked(resolveFrom).mockImplementation(() => { | ||
| // expo-dev-client is not installed | ||
| throw new Error('Module not found'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('should return false', () => { | ||
| it.each([ | ||
| ['non-production profiles', [createMockBuildProfile('development')]], | ||
| ['undefined buildProfiles', undefined], | ||
| ['empty buildProfiles', []], | ||
| ])('should return false for %s', async (_, buildProfiles) => { | ||
| const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); | ||
|
|
||
| expect(result).toBe(false); | ||
| expect(mockResolveWorkflowPerPlatformAsync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('when expo-dev-client is installed - that signals a development build', async () => { | ||
| jest.mocked(resolveFrom).mockReturnValue('/path/to/expo-dev-client/package.json'); | ||
| const buildProfiles = [createMockBuildProfile('production')]; | ||
|
|
||
| const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); | ||
|
|
||
| expect(result).toBe(false); | ||
| expect(mockResolveWorkflowPerPlatformAsync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('when either platform is "generic" - likely a bare RN project', async () => { | ||
| mockResolveWorkflowPerPlatformAsync.mockResolvedValue({ | ||
| android: Workflow.GENERIC, | ||
| ios: Workflow.GENERIC, | ||
| }); | ||
| const buildProfiles = [createMockBuildProfile('production')]; | ||
|
|
||
| const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); | ||
|
|
||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('should return true', () => { | ||
| it('when production profile is used, there are no native directories (or are gitignored) AND expo-dev-client is not installed', async () => { | ||
| mockResolveWorkflowPerPlatformAsync.mockResolvedValue({ | ||
| android: Workflow.MANAGED, | ||
| ios: Workflow.MANAGED, | ||
| }); | ||
| const buildProfiles = [createMockBuildProfile('production')]; | ||
|
|
||
| const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); | ||
|
|
||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
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,73 @@ | ||
| import { Workflow } from '@expo/eas-build-job'; | ||
| import chalk from 'chalk'; | ||
| import getenv from 'getenv'; | ||
|
|
||
| import { resolveWorkflowPerPlatformAsync } from './workflow'; | ||
| import { isExpoDevClientInstalled } from '../build/utils/devClient'; | ||
| import Log, { learnMore } from '../log'; | ||
| import type { ProfileData } from '../utils/profiles'; | ||
| import type { Client } from '../vcs/vcs'; | ||
|
|
||
| const suppressionEnvVarName = 'EAS_BUILD_NO_EXPO_GO_WARNING'; | ||
|
|
||
| export async function discourageExpoGoForProdAsync( | ||
| buildProfiles: ProfileData<'build'>[] | undefined, | ||
| projectDir: string, | ||
| vcsClient: Client | ||
| ): Promise<void> { | ||
| try { | ||
| const isExpoGoProdBuild = await detectExpoGoProdBuildAsync( | ||
| buildProfiles, | ||
| projectDir, | ||
| vcsClient | ||
| ); | ||
| if (!isExpoGoProdBuild) { | ||
| return; | ||
| } | ||
| Log.newLine(); | ||
| Log.warn( | ||
| `⚠️ It appears you're trying to build an app based on Expo Go for production. Expo Go is not a suitable environment for production apps.` | ||
| ); | ||
| Log.warn( | ||
| learnMore('https://docs.expo.dev/develop/development-builds/expo-go-to-dev-build/', { | ||
| learnMoreMessage: 'Learn more about converting from Expo Go to a development build', | ||
| dim: false, | ||
| }) | ||
| ); | ||
| Log.warn( | ||
| chalk.dim(`To suppress this warning, set ${chalk.bold(`${suppressionEnvVarName}=true`)}.`) | ||
| ); | ||
| Log.newLine(); | ||
| } catch (err) { | ||
| Log.warn('Error detecting whether Expo Go is used:', err); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only show this is debug, ideally log this to sentry also so we can get some info on when/how this happens |
||
| } | ||
| } | ||
|
|
||
| export async function detectExpoGoProdBuildAsync( | ||
| buildProfiles: ProfileData<'build'>[] | undefined, | ||
| projectDir: string, | ||
| vcsClient: Client | ||
| ): Promise<boolean> { | ||
| const shouldSuppressWarning = getenv.boolish(suppressionEnvVarName, false); | ||
|
|
||
| const isProductionBuild = buildProfiles?.map(it => it.profileName).includes('production'); | ||
| if (shouldSuppressWarning || !isProductionBuild) { | ||
| return false; | ||
| } | ||
|
|
||
| const hasExpoDevClient = isExpoDevClientInstalled(projectDir); | ||
| if (hasExpoDevClient) { | ||
| return false; | ||
| } | ||
|
|
||
| return await checkIfManagedWorkflowAsync(projectDir, vcsClient); | ||
| } | ||
|
|
||
| async function checkIfManagedWorkflowAsync( | ||
| projectDir: string, | ||
| vcsClient: Client | ||
| ): Promise<boolean> { | ||
| const workflows = await resolveWorkflowPerPlatformAsync(projectDir, vcsClient); | ||
|
|
||
| return workflows.android === Workflow.MANAGED && workflows.ios === Workflow.MANAGED; | ||
| } | ||
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.
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.
i'll think about how to improve the wording on this and get back to you, let's hold off on merging for now
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.
fyi page:
Expo Go is meant for learning and prototyping. Learn more.
Behavior of production builds may differ significantly from the Expo Go app, because it is a precompiled sandbox app and your customizations that will apply to production apps and development will likely not be testable in Expo Go.
For example, if you add a library with native code that is not in the Expo SDK, that will not be available in Expo Go. If that library does not actually compile due to an error or incompatibility, you will only discover this when you run a production build. Additionally, most fields in your app.json do not have any impact on your app when it runs in Expo Go, but they will apply when you run a production or development build. Examples of such properties are:
scheme,splash(only the app icon is used in Expo Go), anyplugins,edgeToEdgeEnabled,predictiveBackGestureEnabled, and so on.Development builds provide a reliable and flexible development environment, and behave more predictably and similar to production builds. This makes it easier to catch potential issues during development.
Learn more about converting from Expo Go to a development build.