Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/config/src/env/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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<string, { sources: string[]; value: string }>,
): Record<string, string> {
return Object.entries(cachedEnv).reduce((prev, [key, { sources, value }]) => {
if (sources.includes('internal')) {
prev[key] = value
}
return prev
}, {} as Record<string, string>)
}

const getDeployUrls = function ({
siteInfo: {
name = DEFAULT_SITE_NAME,
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const resolveConfig = async function (opts) {
deployId,
buildId,
context,
cachedEnv: parsedCachedConfig?.env || {},
})

// @todo Remove in the next major version.
Expand Down