Skip to content

Commit

Permalink
feat(core): return task results from imperative task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Aug 26, 2024
1 parent ec53f31 commit a1b567b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/nx/src/tasks-runner/init-tasks-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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<string, TaskResult>;
}> => {
performance.mark('code-loading:end');

// TODO: This polyfills the outputs if someone doesn't pass a task with outputs. Remove this in Nx 20
Expand Down Expand Up @@ -60,6 +65,7 @@ export async function initTasksRunner(nxArgs: NxArgs) {
return {
status,
taskGraph,
taskResults: lifeCycle.getTaskResults(),
};
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, TaskResult>;

constructor(private readonly tasks: Task[]) {}

Expand Down Expand Up @@ -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') {
Expand All @@ -78,4 +77,8 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle {
const args = getPrintableCommandArgsForTask(task);
output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput);
}

getTaskResults() {
return this.taskResults;
}
}

0 comments on commit a1b567b

Please sign in to comment.