From 4e1c0a48546045166c196e46338325d2d898c173 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 11 Apr 2024 15:26:48 -0400 Subject: [PATCH] feat(core): load root .env files on daemon --- packages/nx/src/daemon/client/client.ts | 3 +-- packages/nx/src/utils/dotenv.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 packages/nx/src/utils/dotenv.ts diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index 7e54b14af59c6d..a2c6771853009f 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -29,7 +29,6 @@ import { DaemonProjectGraphError } from '../daemon-project-graph-error'; import { ProjectGraphError } from '../../project-graph/project-graph'; const DAEMON_ENV_SETTINGS = { - ...process.env, NX_PROJECT_GLOB_CACHE: 'false', NX_CACHE_PROJECTS_CONFIG: 'false', }; @@ -402,7 +401,7 @@ export class DaemonClient { detached: true, windowsHide: true, shell: false, - env: DAEMON_ENV_SETTINGS, + env: { ...process.env, ...DAEMON_ENV_SETTINGS }, } ); backgroundProcess.unref(); diff --git a/packages/nx/src/utils/dotenv.ts b/packages/nx/src/utils/dotenv.ts new file mode 100644 index 00000000000000..9876e150f983cd --- /dev/null +++ b/packages/nx/src/utils/dotenv.ts @@ -0,0 +1,17 @@ +import { config } from 'dotenv'; +import { expand } from 'dotenv-expand'; + +/** + * This loads dotenv files from: + * - .env + * - .local.env + * - .env.local + */ +export function loadRootDotEnvFiles() { + for (const file of ['.local.env', '.env.local', '.env']) { + const myEnv = config({ + path: file, + }); + expand(myEnv); + } +}