diff --git a/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts b/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts index 64d707125c..b493f2b842 100644 --- a/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts +++ b/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts @@ -54,7 +54,9 @@ async function resolveEnvVarsAsync({ projectId: string; }): Promise { const environment = - buildProfile.environment?.toUpperCase() ?? process.env.EAS_CURRENT_ENVIRONMENT; + buildProfile.environment?.toUpperCase() ?? + process.env.EAS_CURRENT_ENVIRONMENT ?? + resolveSuggestedEnvironmentForBuildProfileConfiguration(buildProfile); if (!environment || !isEnvironment(environment)) { Log.log( @@ -145,3 +147,27 @@ async function resolveEnvVarsAsync({ return { ...buildProfile.env }; } } + +function resolveSuggestedEnvironmentForBuildProfileConfiguration( + buildProfile: BuildProfile +): EnvironmentVariableEnvironment { + const setEnvironmentMessage = + 'Set the environment using the "environment" field in the build profile configuration if you want to use a specific environment.'; + if (buildProfile.distribution === 'store') { + Log.log( + `We detected that you are building for the "store" distribution. Resolving the environment for environment variables used during the build to "production". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Production; + } else { + if (buildProfile.developmentClient) { + Log.log( + `We detected that you are building the development client. Resolving the environment for environment variables used during the build to "development". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Development; + } + Log.log( + `We detected that you are building for the "internal" distribution. Resolving the environment for environment variables used during the build to "preview". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Preview; + } +}