Skip to content

Commit

Permalink
fix(core): pass env options to nx:run-commands properly
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Mar 27, 2024
1 parent e576383 commit 29d1012
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ describe('Nx Running Tests', () => {
expect(output).toContain(app);
});
});

it('should pass env option to nx:run-commands executor', () => {
const myapp = uniq('myapp');
runCLI(`generate @nx/js:lib ${myapp}`);

updateJson(`libs/${myapp}/project.json`, (c) => {
c.targets['echo'] = {
executor: 'nx:run-commands',
options: {
command: 'node -e "console.log(process.env.ONE)"',
env: {
ONE: 'TWO',
},
},
};
return c;
});

const output = runCLI(`echo ${myapp}`);
console.log('OUTPUT', output);
expect(output).toContain('TWO');
});
});

describe('Nx Bail', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/nx/src/tasks-runner/task-orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class TaskOrchestrator {
const temporaryOutputPath = this.cache.temporaryOutputPath(task);
const streamOutput = shouldStreamOutput(task, this.initiatingProject);

const env = pipeOutput
let env = pipeOutput
? getEnvVariablesForTask(
task,
taskSpecificEnv,
Expand Down Expand Up @@ -403,6 +403,12 @@ export class TaskOrchestrator {
relative(task.projectRoot ?? workspaceRoot, process.cwd()),
process.env.NX_VERBOSE_LOGGING === 'true'
);
if (combinedOptions.env) {
env = {
...env,
...combinedOptions.env,
};
}
if (streamOutput) {
const args = getPrintableCommandArgsForTask(task);
output.logCommand(args.join(' '));
Expand Down

0 comments on commit 29d1012

Please sign in to comment.