diff --git a/packages/config/src/env/main.ts b/packages/config/src/env/main.ts index 548f7b8970..ea73911eaf 100644 --- a/packages/config/src/env/main.ts +++ b/packages/config/src/env/main.ts @@ -24,11 +24,13 @@ export const getEnv = async function ({ deployId, buildId, context, + cachedEnv, }) { if (mode === 'buildbot') { return {} } + const internalEnv = getInternalEnv(cachedEnv) const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context }) const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, @@ -46,6 +48,7 @@ export const getEnv = async function ({ { key: 'addons', values: addonsEnv }, { key: 'account', values: accountEnv }, { key: 'general', values: generalEnv }, + { key: 'internal', values: internalEnv }, ] // A hash mapping names of environment variables to objects containing the following properties: @@ -119,6 +122,22 @@ const getGeneralEnv = async function ({ }) } +/** + * Retrieve internal environment variables (needed for the CLI). + * Based on the cached environment, it returns the internal environment variables. + * Internal environment variables are those that are set by the CLI and are not retrieved by Envelope or the API. + */ +const getInternalEnv = function ( + cachedEnv: Record, +): Record { + return Object.entries(cachedEnv).reduce((prev, [key, { sources, value }]) => { + if (sources.includes('internal')) { + prev[key] = value + } + return prev + }, {} as Record) +} + const getDeployUrls = function ({ siteInfo: { name = DEFAULT_SITE_NAME, diff --git a/packages/config/src/main.ts b/packages/config/src/main.ts index 9a05eada13..a42dd9e7a8 100644 --- a/packages/config/src/main.ts +++ b/packages/config/src/main.ts @@ -118,6 +118,7 @@ export const resolveConfig = async function (opts) { deployId, buildId, context, + cachedEnv: parsedCachedConfig?.env || {}, }) // @todo Remove in the next major version.