From 09935cb3e9d6a4cbc65500ab908edf7cb7b286a5 Mon Sep 17 00:00:00 2001 From: Alex Pshul Date: Mon, 14 Oct 2024 20:12:39 -0400 Subject: [PATCH 1/2] Fixed generating flat eslint config file --- packages/func/src/generators/init/generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/func/src/generators/init/generator.ts b/packages/func/src/generators/init/generator.ts index bfcc835..01518b4 100644 --- a/packages/func/src/generators/init/generator.ts +++ b/packages/func/src/generators/init/generator.ts @@ -248,7 +248,7 @@ const setupFlatEslintConfig = (tree: Tree, appRoot: string, fileName: string) => files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], // Override or add rules here rules: {}, - languageOptions: { parserOptions: { project: [${path.posix.join(...projectJsonPath.split(path.sep))}], } }, + languageOptions: { parserOptions: { project: ['${path.posix.join(...projectJsonPath.split(path.sep))}'], } }, }, { files: ['**/*.ts', '**/*.tsx'], From 9fe70818535f835fc7ded8203ad6a3e8a85c38c9 Mon Sep 17 00:00:00 2001 From: Alex Pshul Date: Mon, 14 Oct 2024 21:44:52 -0400 Subject: [PATCH 2/2] Allow overriding env vars from .env files by setting local.settings.json file --- packages/func/src/executors/start/executor.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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()));