From a1b567b3458ced366699ab3da5e013a0d81c58d6 Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Mon, 26 Aug 2024 15:24:11 -0400 Subject: [PATCH] feat(core): return task results from imperative task runner --- packages/nx/src/tasks-runner/init-tasks-runner.ts | 8 +++++++- .../invoke-runner-terminal-output-life-cycle.ts | 13 ++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/nx/src/tasks-runner/init-tasks-runner.ts b/packages/nx/src/tasks-runner/init-tasks-runner.ts index 6fcdddfabc0e88..86b9e7838f2727 100644 --- a/packages/nx/src/tasks-runner/init-tasks-runner.ts +++ b/packages/nx/src/tasks-runner/init-tasks-runner.ts @@ -8,6 +8,7 @@ import { InvokeRunnerTerminalOutputLifeCycle } from './life-cycles/invoke-runner import { performance } from 'perf_hooks'; import { getOutputs } from './utils'; import { loadRootEnvFiles } from '../utils/dotenv'; +import { TaskResult } from './life-cycle'; export async function initTasksRunner(nxArgs: NxArgs) { performance.mark('init-local'); @@ -22,7 +23,11 @@ export async function initTasksRunner(nxArgs: NxArgs) { invoke: async (opts: { tasks: Task[]; parallel: number; - }): Promise<{ status: number; taskGraph: TaskGraph }> => { + }): Promise<{ + status: number; + taskGraph: TaskGraph; + taskResults: Record; + }> => { performance.mark('code-loading:end'); // TODO: This polyfills the outputs if someone doesn't pass a task with outputs. Remove this in Nx 20 @@ -60,6 +65,7 @@ export async function initTasksRunner(nxArgs: NxArgs) { return { status, taskGraph, + taskResults: lifeCycle.getTaskResults(), }; }, }; diff --git a/packages/nx/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.ts b/packages/nx/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.ts index c859a1228f856c..6247ae39b628bb 100644 --- a/packages/nx/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.ts +++ b/packages/nx/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.ts @@ -1,13 +1,13 @@ import { output } from '../../utils/output'; import { TaskStatus } from '../tasks-runner'; import { getPrintableCommandArgsForTask } from '../utils'; -import type { LifeCycle } from '../life-cycle'; +import type { LifeCycle, TaskResult } from '../life-cycle'; import { Task } from '../../config/task-graph'; -import { formatFlags, formatTargetsAndProjects } from './formatting-utils'; export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle { failedTasks = [] as Task[]; cachedTasks = [] as Task[]; + private taskResults = {} as Record; constructor(private readonly tasks: Task[]) {} @@ -54,10 +54,9 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle { } } - endTasks( - taskResults: { task: Task; status: TaskStatus; code: number }[] - ): void { + endTasks(taskResults: TaskResult[]): void { for (let t of taskResults) { + this.taskResults[t.task.id] = t; if (t.status === 'failure') { this.failedTasks.push(t.task); } else if (t.status === 'local-cache') { @@ -78,4 +77,8 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle { const args = getPrintableCommandArgsForTask(task); output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput); } + + getTaskResults() { + return this.taskResults; + } }