Skip to content

Commit

Permalink
fix(core): always load task envs from workspace root instead of relat…
Browse files Browse the repository at this point in the history
…ive to cwd
  • Loading branch information
MaxKless committed Jul 25, 2024
1 parent ebb42b7 commit b9f33c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/nx/src/tasks-runner/task-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

0 comments on commit b9f33c8

Please sign in to comment.