diff --git a/packages/func/src/executors/start/executor.ts b/packages/func/src/executors/start/executor.ts index 86179a2..cdff836 100644 --- a/packages/func/src/executors/start/executor.ts +++ b/packages/func/src/executors/start/executor.ts @@ -1,11 +1,25 @@ -import { Executor } from '@nx/devkit'; +import { Executor, readJsonFile } from '@nx/devkit'; import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; +import { fileExists } from 'nx/src/utils/fileutils'; import treeKill from 'tree-kill'; import { color } from '../../common'; import { build, watch } from '../common'; import { FuncLogger } from './func-logger'; import { StartExecutorSchema } from './schema'; +const loadProcessEnvWithoutOverrides = (projectCwd: string) => { + const localProcessEnvCopy = { ...process.env }; + const localSettingsJsonPath = `${projectCwd}/local.settings.json`; + if (!fileExists(localSettingsJsonPath)) return localProcessEnvCopy; + + const localSettingsConfig = readJsonFile<{ Values: Record }>(localSettingsJsonPath).Values; + if (!localSettingsConfig) return localProcessEnvCopy; + + Object.keys(localSettingsConfig).forEach(key => delete localProcessEnvCopy[key]); + + return localProcessEnvCopy; +}; + const executor: Executor = async (options, context) => { const { port, disableWatch, additionalFlags } = options; const { workspace, projectName, isVerbose, target } = context; @@ -20,7 +34,8 @@ const executor: Executor = async (options, context) => { if (isVerbose) console.log(`Running ${target.executor} command: func ${params.join(' ')}.`); const cwd = workspace?.projects[projectName].root; - spawned = spawn('func', params, { cwd, detached: false, shell: true }); + const noOverridesEnvVars = loadProcessEnvWithoutOverrides(cwd); + spawned = spawn('func', params, { cwd, detached: false, shell: true, env: noOverridesEnvVars }); spawned.stdout.on('data', data => logger.logData(data?.toString())); spawned.stderr.on('data', data => logger.logError(data?.toString()));