diff --git a/packages/nx/src/tasks-runner/init-tasks-runner.ts b/packages/nx/src/tasks-runner/init-tasks-runner.ts index b656a35135..2060225040 100644 --- a/packages/nx/src/tasks-runner/init-tasks-runner.ts +++ b/packages/nx/src/tasks-runner/init-tasks-runner.ts @@ -1,3 +1,4 @@ +import type { NxJsonConfiguration } from '../config/nx-json'; import { readNxJson } from '../config/nx-json'; import { NxArgs } from '../utils/command-line-utils'; import { createProjectGraphAsync } from '../project-graph/project-graph'; @@ -6,6 +7,7 @@ import { constructLifeCycles, getRunner, invokeTasksRunner, + setEnvVarsBasedOnArgs, } from './run-command'; import { InvokeRunnerTerminalOutputLifeCycle } from './life-cycles/invoke-runner-terminal-output-life-cycle'; import { performance } from 'perf_hooks'; @@ -15,7 +17,6 @@ import { CompositeLifeCycle, LifeCycle, TaskResult } from './life-cycle'; import { TaskOrchestrator } from './task-orchestrator'; import { createTaskHasher } from '../hasher/create-task-hasher'; import type { ProjectGraph } from '../config/project-graph'; -import type { NxJsonConfiguration } from '../config/nx-json'; import { daemonClient } from '../daemon/client/client'; import { RunningTask } from './running-tasks/running-task'; import { TaskResultsLifeCycle } from './life-cycles/task-results-life-cycle'; @@ -133,6 +134,13 @@ async function createOrchestrator( }, {} as any), }; + const nxArgs = { + ...options, + parallel: tasks.length, + lifeCycle: compositedLifeCycle, + }; + setEnvVarsBasedOnArgs(nxArgs, true); + const orchestrator = new TaskOrchestrator( hasher, null, @@ -140,7 +148,7 @@ async function createOrchestrator( projectGraph, taskGraph, nxJson, - { ...options, parallel: tasks.length, lifeCycle: compositedLifeCycle }, + nxArgs, false, daemonClient, undefined, @@ -149,7 +157,7 @@ async function createOrchestrator( await orchestrator.init(); - await Promise.all(tasks.map((task) => orchestrator.processTask(task.id))); + orchestrator.processTasks(tasks.map((task) => task.id)); return orchestrator; } diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index ba249eeba8..b1f9e8bb4c 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -802,7 +802,10 @@ async function confirmRunningTasksWithSyncFailures(): Promise { } } -function setEnvVarsBasedOnArgs(nxArgs: NxArgs, loadDotEnvFiles: boolean) { +export function setEnvVarsBasedOnArgs( + nxArgs: NxArgs, + loadDotEnvFiles: boolean +) { if ( nxArgs.outputStyle == 'stream' || process.env.NX_BATCH_MODE === 'true' || diff --git a/packages/nx/src/tasks-runner/task-orchestrator.ts b/packages/nx/src/tasks-runner/task-orchestrator.ts index bf3579d0bd..387ae8e9d0 100644 --- a/packages/nx/src/tasks-runner/task-orchestrator.ts +++ b/packages/nx/src/tasks-runner/task-orchestrator.ts @@ -199,8 +199,17 @@ export class TaskOrchestrator { ); } + processTasks(taskIds: string[]) { + for (const taskId of taskIds) { + // Task is already handled or being handled + if (!this.processedTasks.has(taskId)) { + this.processedTasks.set(taskId, this.processTask(taskId)); + } + } + } + // region Processing Scheduled Tasks - async processTask(taskId: string): Promise { + private async processTask(taskId: string): Promise { const task = this.taskGraph.tasks[taskId]; const taskSpecificEnv = getTaskSpecificEnv(task); @@ -245,12 +254,7 @@ export class TaskOrchestrator { for (const batch of scheduledBatches) { this.processedBatches.set(batch, this.processScheduledBatch(batch)); } - for (const taskId of scheduledTasks) { - // Task is already handled or being handled - if (!this.processedTasks.has(taskId)) { - this.processedTasks.set(taskId, this.processTask(taskId)); - } - } + this.processTasks(scheduledTasks); } // endregion Processing Scheduled Tasks