-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
default-tasks-runner.ts
109 lines (96 loc) · 2.95 KB
/
default-tasks-runner.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { TasksRunner, TaskStatus } from './tasks-runner';
import { TaskOrchestrator } from './task-orchestrator';
import { performance } from 'perf_hooks';
import { TaskGraphCreator } from './task-graph-creator';
import { Hasher } from '../hasher/hasher';
import { LifeCycle } from './life-cycle';
import { ProjectGraph } from '../config/project-graph';
import { NxJsonConfiguration } from '../config/nx-json';
import { Task } from '../config/task-graph';
import { NxArgs } from '../utils/command-line-utils';
export interface RemoteCache {
retrieve: (hash: string, cacheDirectory: string) => Promise<boolean>;
store: (hash: string, cacheDirectory: string) => Promise<boolean>;
}
export interface DefaultTasksRunnerOptions {
parallel?: number;
cacheableOperations?: string[];
cacheableTargets?: string[];
runtimeCacheInputs?: string[];
cacheDirectory?: string;
remoteCache?: RemoteCache;
lifeCycle: LifeCycle;
captureStderr?: boolean;
skipNxCache?: boolean;
}
export const defaultTasksRunner: TasksRunner<
DefaultTasksRunnerOptions
> = async (
tasks: Task[],
options: DefaultTasksRunnerOptions,
context: {
target: string;
initiatingProject?: string;
projectGraph: ProjectGraph;
nxJson: NxJsonConfiguration;
nxArgs: NxArgs;
}
): Promise<{ [id: string]: TaskStatus }> => {
if (
(options as any)['parallel'] === 'false' ||
(options as any)['parallel'] === false
) {
(options as any)['parallel'] = 1;
} else if (
(options as any)['parallel'] === 'true' ||
(options as any)['parallel'] === true ||
(options as any)['parallel'] === undefined
) {
(options as any)['parallel'] = Number((options as any)['maxParallel'] || 3);
}
options.lifeCycle.startCommand();
try {
return await runAllTasks(tasks, options, context);
} catch (e) {
console.error('Unexpected error:');
console.error(e);
process.exit(1);
} finally {
options.lifeCycle.endCommand();
}
};
async function runAllTasks(
tasks: Task[],
options: DefaultTasksRunnerOptions,
context: {
initiatingProject?: string;
projectGraph: ProjectGraph;
nxJson: NxJsonConfiguration;
nxArgs: NxArgs;
}
): Promise<{ [id: string]: TaskStatus }> {
const defaultTargetDependencies = context.nxJson.targetDependencies ?? {};
const taskGraphCreator = new TaskGraphCreator(
context.projectGraph,
defaultTargetDependencies
);
const taskGraph = taskGraphCreator.createTaskGraph(tasks);
performance.mark('task-graph-created');
performance.measure('nx-prep-work', 'init-local', 'task-graph-created');
performance.measure(
'graph-creation',
'command-execution-begins',
'task-graph-created'
);
const hasher = new Hasher(context.projectGraph, context.nxJson, options);
const orchestrator = new TaskOrchestrator(
hasher,
context.initiatingProject,
context.projectGraph,
taskGraph,
options,
context.nxArgs?.nxBail
);
return orchestrator.run();
}
export default defaultTasksRunner;