diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d4bc734c..8bbde2b161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages. ### 🎉 New features +- Load `.env` variables even when `--environment` is specified for `deploy` command. Conflicts will be highlighted by a warning message. ([#2783](https://github.com/expo/eas-cli/pull/2783) by [@kitten](https://github.com/kitten)) + ### 🐛 Bug fixes - Show `eas deploy` upload error messages. ([#2771](https://github.com/expo/eas-cli/pull/2771) by [@kadikraman](https://github.com/kadikraman)) diff --git a/packages/eas-cli/src/commands/worker/deploy.ts b/packages/eas-cli/src/commands/worker/deploy.ts index 2f905845f6..dc3c1adecc 100644 --- a/packages/eas-cli/src/commands/worker/deploy.ts +++ b/packages/eas-cli/src/commands/worker/deploy.ts @@ -253,7 +253,7 @@ export default class WorkerDeploy extends EasCommand { let progress = ora('Preparing project').start(); try { - const manifest = await WorkerAssets.createManifestAsync( + const manifestResult = await WorkerAssets.createManifestAsync( { environment: flags.environment, projectDir, @@ -261,13 +261,20 @@ export default class WorkerDeploy extends EasCommand { }, graphqlClient ); + if (manifestResult.conflictingVariableNames?.length) { + Log.warn( + '> The following environment variables were loaded both from local .env files as well as EAS environment variables, ' + + ' and will be set to the EAS environment variable values instead: ' + + manifestResult.conflictingVariableNames.join(' ') + ); + } assetMap = await WorkerAssets.createAssetMapAsync( projectDist.type === 'server' ? projectDist.clientPath : projectDist.path ); tarPath = await WorkerAssets.packFilesIterableAsync( emitWorkerTarballAsync({ assetMap, - manifest, + manifest: manifestResult.manifest, }) ); diff --git a/packages/eas-cli/src/worker/assets.ts b/packages/eas-cli/src/worker/assets.ts index 31a56a5d85..2536df2bbe 100644 --- a/packages/eas-cli/src/worker/assets.ts +++ b/packages/eas-cli/src/worker/assets.ts @@ -98,6 +98,11 @@ export interface Manifest { env: Record; } +export interface CreateManifestResult { + conflictingVariableNames: string[] | undefined; + manifest: Manifest; +} + interface CreateManifestParams { projectId: string; projectDir: string; @@ -108,23 +113,34 @@ interface CreateManifestParams { export async function createManifestAsync( params: CreateManifestParams, graphqlClient: ExpoGraphqlClient -): Promise { - let env: Record; +): Promise { + // NOTE: This is required for the .env resolution + process.env.NODE_ENV = 'production'; + // Resolve .env file variables + const env: Record = getEnv(params.projectDir).env; + // Maybe load EAS Environment Variables (based on `--environment` arg) + let conflictingVariableNames: string[] | undefined; if (params.environment) { - env = Object.fromEntries( - ( - await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, { - appId: params.projectId, - environment: params.environment, - }) - ).map(variable => [variable.name, variable.value ?? undefined]) + const loadedVariables = await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync( + graphqlClient, + { + appId: params.projectId, + environment: params.environment, + } ); - } else { - // NOTE: This is required for the .env resolution - process.env.NODE_ENV = 'production'; - env = getEnv(params.projectDir).env; + // Load EAS Env vars into `env` object, keeping track of conflicts + conflictingVariableNames = []; + for (const variable of loadedVariables) { + if (variable.value != null) { + if (env[variable.name] != null) { + conflictingVariableNames.push(variable.name); + } + env[variable.name] = variable.value; + } + } } - return { env }; + const manifest: Manifest = { env }; + return { conflictingVariableNames, manifest }; } interface WorkerFileEntry {