From ecca8a3edb2666187ad1c6f76591f830f33e0a6f Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Fri, 12 Jul 2024 16:14:33 +0200 Subject: [PATCH 1/2] fix: leverage the internal config inside the getEnv as well the internal config is set through the cached config by the CLI --- packages/config/src/env/main.ts | 19 +++++++++++++++++++ packages/config/src/main.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/packages/config/src/env/main.ts b/packages/config/src/env/main.ts index 548f7b8970..ed81003b15 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 the 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..29ac7786f9 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. From b78341658e7d8a4ce0f39875006e69e99bcc1a87 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Fri, 12 Jul 2024 16:24:10 +0200 Subject: [PATCH 2/2] chore: fix typo --- packages/config/src/env/main.ts | 2 +- packages/config/src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/config/src/env/main.ts b/packages/config/src/env/main.ts index ed81003b15..ea73911eaf 100644 --- a/packages/config/src/env/main.ts +++ b/packages/config/src/env/main.ts @@ -125,7 +125,7 @@ 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 the envelope or the API. + * 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, diff --git a/packages/config/src/main.ts b/packages/config/src/main.ts index 29ac7786f9..a42dd9e7a8 100644 --- a/packages/config/src/main.ts +++ b/packages/config/src/main.ts @@ -118,7 +118,7 @@ export const resolveConfig = async function (opts) { deployId, buildId, context, - cachedEnv: parsedCachedConfig.env, + cachedEnv: parsedCachedConfig?.env || {}, }) // @todo Remove in the next major version.