From b9f33c8e64d4de18854e6b5cbacfdf53a377c967 Mon Sep 17 00:00:00 2001 From: Max Kless Date: Thu, 25 Jul 2024 17:24:06 +0200 Subject: [PATCH] fix(core): always load task envs from workspace root instead of relative to cwd --- packages/nx/src/tasks-runner/task-env.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/tasks-runner/task-env.ts b/packages/nx/src/tasks-runner/task-env.ts index 67d85afac0197..cbc7b4775ed5b 100644 --- a/packages/nx/src/tasks-runner/task-env.ts +++ b/packages/nx/src/tasks-runner/task-env.ts @@ -2,6 +2,7 @@ import { Task } from '../config/task-graph'; import { config as loadDotEnvFile } from 'dotenv'; import { expand } from 'dotenv-expand'; import { workspaceRoot } from '../utils/workspace-root'; +import { join } from 'node:path'; export function getEnvVariablesForBatchProcess( skipNxCache: boolean, @@ -221,14 +222,14 @@ function loadDotEnvFilesForTask( ) { const dotEnvFiles = getEnvFilesForTask(task); for (const file of dotEnvFiles) { - loadAndExpandDotEnvFile(file, environmentVariables); + loadAndExpandDotEnvFile(join(workspaceRoot, file), environmentVariables); } return environmentVariables; } function unloadDotEnvFiles(environmentVariables: NodeJS.ProcessEnv) { for (const file of ['.env', '.local.env', '.env.local']) { - unloadDotEnvFile(file, environmentVariables); + unloadDotEnvFile(join(workspaceRoot, file), environmentVariables); } return environmentVariables; }