From a0f33c1f8152cbb8a846d13b9e914bbc5965b93f Mon Sep 17 00:00:00 2001 From: David Berlin <47757213+davbree@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:37:11 +0300 Subject: [PATCH] feat: add flag to skip env var fetching (#6723) --- src/commands/base-command.ts | 11 +++++++++-- src/commands/dev/dev.ts | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/base-command.ts b/src/commands/base-command.ts index 32631b4d0de..592f464b755 100644 --- a/src/commands/base-command.ts +++ b/src/commands/base-command.ts @@ -596,7 +596,11 @@ export default class BaseCommand extends Command { token, ...apiUrlOpts, }) - const { buildDir, config, configPath, env, repositoryRoot, siteInfo } = cachedConfig + const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig + let { env } = cachedConfig + if (flags.offlineEnv) { + env = {} + } env.NETLIFY_CLI_VERSION = { sources: ['internal'], value: version } const normalizedConfig = normalizeConfig(config) @@ -661,7 +665,10 @@ export default class BaseCommand extends Command { // Configuration from netlify.[toml/yml] config: normalizedConfig, // Used to avoid calling @netlify/config again - cachedConfig, + cachedConfig: { + ...cachedConfig, + env, + }, // global cli config globalConfig, // state of current site dir diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 8dba0743eb3..2d79832f92b 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -118,7 +118,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => { env[BLOBS_CONTEXT_VARIABLE] = { sources: ['internal'], value: encodeBlobsContext(blobsContext) } - if (!options.offline) { + if (!options.offline && !options.offlineEnv) { env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo }) log(`${NETLIFYDEVLOG} Injecting environment variable values for ${chalk.yellow('all scopes')}`) } @@ -275,6 +275,9 @@ export const createDevCommand = (program: BaseCommand) => { .option('-d ,--dir ', 'dir with static files') .option('-f ,--functions ', 'specify a functions folder to serve') .option('-o ,--offline', 'disables any features that require network access') + .addOption( + new Option('--offline-env', 'disables fetching environment variables from the Netlify API').hideHelp(true), + ) .addOption( new Option( '--internal-disable-edge-functions',