nx 21.0.0-beta.3 → 21.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/package.json +11 -11
  2. package/src/command-line/migrate/migrate-ui-api.d.ts +56 -0
  3. package/src/command-line/migrate/migrate-ui-api.js +188 -0
  4. package/src/command-line/migrate/migrate.d.ts +17 -0
  5. package/src/command-line/migrate/migrate.js +106 -63
  6. package/src/config/misc-interfaces.d.ts +10 -0
  7. package/src/core/graph/main.js +1 -1
  8. package/src/core/graph/styles.css +1 -1
  9. package/src/native/index.d.ts +2 -1
  10. package/src/native/nx.wasm32-wasi.wasm +0 -0
  11. package/src/tasks-runner/default-tasks-runner.js +1 -1
  12. package/src/tasks-runner/init-tasks-runner.js +2 -1
  13. package/src/tasks-runner/is-tui-enabled.d.ts +1 -1
  14. package/src/tasks-runner/is-tui-enabled.js +12 -6
  15. package/src/tasks-runner/life-cycle.d.ts +2 -2
  16. package/src/tasks-runner/life-cycle.js +2 -2
  17. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +2 -1
  18. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +13 -6
  19. package/src/tasks-runner/run-command.d.ts +2 -1
  20. package/src/tasks-runner/run-command.js +14 -6
  21. package/src/tasks-runner/running-tasks/running-task.d.ts +2 -0
  22. package/src/tasks-runner/running-tasks/shared-running-task.d.ts +14 -0
  23. package/src/tasks-runner/running-tasks/shared-running-task.js +30 -0
  24. package/src/tasks-runner/task-orchestrator.d.ts +6 -3
  25. package/src/tasks-runner/task-orchestrator.js +51 -23
  26. package/src/tasks-runner/tasks-runner.d.ts +1 -0
  27. package/src/tasks-runner/tasks-schedule.d.ts +1 -0
  28. package/src/tasks-runner/tasks-schedule.js +9 -0
  29. package/src/utils/git-utils.d.ts +1 -1
  30. package/src/utils/git-utils.js +8 -3
@@ -7,9 +7,11 @@ import { NxArgs } from '../utils/command-line-utils';
7
7
  import { DefaultTasksRunnerOptions } from './default-tasks-runner';
8
8
  import { RunningTask } from './running-tasks/running-task';
9
9
  import { TaskStatus } from './tasks-runner';
10
+ import { SharedRunningTask } from './running-tasks/shared-running-task';
10
11
  export declare class TaskOrchestrator {
11
12
  private readonly hasher;
12
13
  private readonly initiatingProject;
14
+ private readonly initiatingTasks;
13
15
  private readonly projectGraph;
14
16
  private readonly taskGraph;
15
17
  private readonly nxJson;
@@ -26,6 +28,7 @@ export declare class TaskOrchestrator {
26
28
  private tasksSchedule;
27
29
  private batchEnv;
28
30
  private reverseTaskDeps;
31
+ private initializingTaskIds;
29
32
  private processedTasks;
30
33
  private processedBatches;
31
34
  private completedTasks;
@@ -33,8 +36,7 @@ export declare class TaskOrchestrator {
33
36
  private groups;
34
37
  private bailed;
35
38
  private runningContinuousTasks;
36
- private cleaningUp;
37
- constructor(hasher: TaskHasher, initiatingProject: string | undefined, projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: NxArgs & DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string, taskGraphForHashing?: TaskGraph);
39
+ constructor(hasher: TaskHasher, initiatingProject: string | undefined, initiatingTasks: Task[], projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: NxArgs & DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string, taskGraphForHashing?: TaskGraph);
38
40
  init(): Promise<void>;
39
41
  run(): Promise<{
40
42
  [id: string]: TaskStatus;
@@ -55,7 +57,7 @@ export declare class TaskOrchestrator {
55
57
  }>;
56
58
  private runTask;
57
59
  private runTaskInForkedProcess;
58
- startContinuousTask(task: Task, groupId: number): Promise<RunningTask>;
60
+ startContinuousTask(task: Task, groupId: number): Promise<RunningTask | SharedRunningTask>;
59
61
  private preRunSteps;
60
62
  private postRunSteps;
61
63
  private scheduleNextTasksAndReleaseThreads;
@@ -67,5 +69,6 @@ export declare class TaskOrchestrator {
67
69
  private shouldCopyOutputsFromCache;
68
70
  private recordOutputsHash;
69
71
  private cleanup;
72
+ private cleanUpUnneededContinuousTasks;
70
73
  }
71
74
  export declare function getThreadCount(options: NxArgs & DefaultTasksRunnerOptions, taskGraph: TaskGraph): number;
@@ -21,11 +21,13 @@ const noop_child_process_1 = require("./running-tasks/noop-child-process");
21
21
  const task_env_1 = require("./task-env");
22
22
  const tasks_schedule_1 = require("./tasks-schedule");
23
23
  const utils_1 = require("./utils");
24
+ const shared_running_task_1 = require("./running-tasks/shared-running-task");
24
25
  class TaskOrchestrator {
25
26
  // endregion internal state
26
- constructor(hasher, initiatingProject, projectGraph, taskGraph, nxJson, options, bail, daemon, outputStyle, taskGraphForHashing = taskGraph) {
27
+ constructor(hasher, initiatingProject, initiatingTasks, projectGraph, taskGraph, nxJson, options, bail, daemon, outputStyle, taskGraphForHashing = taskGraph) {
27
28
  this.hasher = hasher;
28
29
  this.initiatingProject = initiatingProject;
30
+ this.initiatingTasks = initiatingTasks;
29
31
  this.projectGraph = projectGraph;
30
32
  this.taskGraph = taskGraph;
31
33
  this.nxJson = nxJson;
@@ -43,6 +45,7 @@ class TaskOrchestrator {
43
45
  // region internal state
44
46
  this.batchEnv = (0, task_env_1.getEnvVariablesForBatchProcess)(this.options.skipNxCache, this.options.captureStderr);
45
47
  this.reverseTaskDeps = (0, utils_1.calculateReverseDeps)(this.taskGraph);
48
+ this.initializingTaskIds = new Set(this.initiatingTasks.map((t) => t.id));
46
49
  this.processedTasks = new Map();
47
50
  this.processedBatches = new Map();
48
51
  this.completedTasks = {};
@@ -50,7 +53,6 @@ class TaskOrchestrator {
50
53
  this.groups = [];
51
54
  this.bailed = false;
52
55
  this.runningContinuousTasks = new Map();
53
- this.cleaningUp = false;
54
56
  }
55
57
  async init() {
56
58
  // Init the ForkedProcessTaskRunner, TasksSchedule, and Cache
@@ -75,12 +77,16 @@ class TaskOrchestrator {
75
77
  }
76
78
  await Promise.race([
77
79
  Promise.all(threads),
78
- new Promise((resolve) => {
79
- this.options.lifeCycle.registerForcedShutdownCallback(() => {
80
- // The user force quit the TUI with ctrl+c, so proceed onto cleanup
81
- resolve(undefined);
82
- });
83
- }),
80
+ ...(this.tuiEnabled
81
+ ? [
82
+ new Promise((resolve) => {
83
+ this.options.lifeCycle.registerForcedShutdownCallback(() => {
84
+ // The user force quit the TUI with ctrl+c, so proceed onto cleanup
85
+ resolve(undefined);
86
+ });
87
+ }),
88
+ ]
89
+ : []),
84
90
  ]);
85
91
  perf_hooks_1.performance.mark('task-execution:end');
86
92
  perf_hooks_1.performance.measure('task-execution', 'task-execution:start', 'task-execution:end');
@@ -393,15 +399,19 @@ class TaskOrchestrator {
393
399
  if (this.tuiEnabled) {
394
400
  this.options.lifeCycle.setTaskStatus(task.id, 8 /* NativeTaskStatus.Shared */);
395
401
  }
402
+ const runningTask = new shared_running_task_1.SharedRunningTask(this.runningTasksService, task.id);
403
+ this.runningContinuousTasks.set(task.id, runningTask);
404
+ runningTask.onExit(() => {
405
+ this.runningContinuousTasks.delete(task.id);
406
+ });
396
407
  // task is already running by another process, we schedule the next tasks
397
408
  // and release the threads
398
409
  await this.scheduleNextTasksAndReleaseThreads();
399
- // wait for the running task to finish
400
- do {
401
- console.log(`Waiting for ${task.id} in another nx process`);
402
- await new Promise((resolve) => setTimeout(resolve, 100));
403
- } while (this.runningTasksService.getRunningTasks([task.id]).length);
404
- return;
410
+ if (this.initializingTaskIds.has(task.id)) {
411
+ // Hold the thread forever
412
+ await new Promise(() => { });
413
+ }
414
+ return runningTask;
405
415
  }
406
416
  const taskSpecificEnv = await this.processedTasks.get(task.id);
407
417
  await this.preRunSteps([task], { groupId });
@@ -421,14 +431,12 @@ class TaskOrchestrator {
421
431
  this.runningContinuousTasks.set(task.id, childProcess);
422
432
  childProcess.onExit(() => {
423
433
  this.runningTasksService.removeRunningTask(task.id);
434
+ this.runningContinuousTasks.delete(task.id);
424
435
  });
425
- if (this.initiatingProject === task.target.project &&
426
- this.options.targets.length === 1 &&
427
- this.options.targets[0] === task.target.target) {
428
- await childProcess.getResults();
429
- }
430
- else {
431
- await this.scheduleNextTasksAndReleaseThreads();
436
+ await this.scheduleNextTasksAndReleaseThreads();
437
+ if (this.initializingTaskIds.has(task.id)) {
438
+ // Hold the thread forever
439
+ await new Promise(() => { });
432
440
  }
433
441
  return childProcess;
434
442
  }
@@ -501,6 +509,7 @@ class TaskOrchestrator {
501
509
  }
502
510
  complete(taskResults) {
503
511
  this.tasksSchedule.complete(taskResults.map(({ taskId }) => taskId));
512
+ this.cleanUpUnneededContinuousTasks();
504
513
  for (const { taskId, status } of taskResults) {
505
514
  if (this.completedTasks[taskId] === undefined) {
506
515
  this.completedTasks[taskId] = status;
@@ -567,10 +576,10 @@ class TaskOrchestrator {
567
576
  }
568
577
  // endregion utils
569
578
  async cleanup() {
570
- this.cleaningUp = true;
571
579
  await Promise.all(Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
572
580
  try {
573
- return t.kill();
581
+ await t.kill();
582
+ this.options.lifeCycle.setTaskStatus(taskId, 9 /* NativeTaskStatus.Stopped */);
574
583
  }
575
584
  catch (e) {
576
585
  console.error(`Unable to terminate ${taskId}\nError:`, e);
@@ -580,6 +589,25 @@ class TaskOrchestrator {
580
589
  }
581
590
  }));
582
591
  }
592
+ cleanUpUnneededContinuousTasks() {
593
+ const incompleteTasks = this.tasksSchedule.getIncompleteTasks();
594
+ const neededContinuousTasks = new Set(this.initializingTaskIds);
595
+ for (const task of incompleteTasks) {
596
+ const continuousDependencies = this.taskGraph.continuousDependencies[task.id];
597
+ for (const continuousDependency of continuousDependencies) {
598
+ neededContinuousTasks.add(continuousDependency);
599
+ }
600
+ }
601
+ for (const taskId of this.runningContinuousTasks.keys()) {
602
+ if (!neededContinuousTasks.has(taskId)) {
603
+ const runningTask = this.runningContinuousTasks.get(taskId);
604
+ if (runningTask) {
605
+ runningTask.kill();
606
+ this.options.lifeCycle.setTaskStatus(taskId, 9 /* NativeTaskStatus.Stopped */);
607
+ }
608
+ }
609
+ }
610
+ }
583
611
  }
584
612
  exports.TaskOrchestrator = TaskOrchestrator;
585
613
  function getThreadCount(options, taskGraph) {
@@ -12,6 +12,7 @@ export type TaskStatus = 'success' | 'failure' | 'skipped' | 'local-cache-kept-e
12
12
  export type TasksRunner<T = unknown> = (tasks: Task[], options: T, context?: {
13
13
  target?: string;
14
14
  initiatingProject?: string | null;
15
+ initiatingTasks: Task[];
15
16
  projectGraph: ProjectGraph;
16
17
  nxJson: NxJsonConfiguration;
17
18
  nxArgs: NxArgs;
@@ -31,6 +31,7 @@ export declare class TasksSchedule {
31
31
  };
32
32
  nextTask(): Task;
33
33
  nextBatch(): Batch;
34
+ getIncompleteTasks(): Task[];
34
35
  private scheduleTasks;
35
36
  private scheduleTask;
36
37
  private scheduleBatches;
@@ -68,6 +68,15 @@ class TasksSchedule {
68
68
  ? this.scheduledBatches.shift()
69
69
  : null;
70
70
  }
71
+ getIncompleteTasks() {
72
+ const incompleteTasks = [];
73
+ for (const taskId in this.taskGraph.tasks) {
74
+ if (!this.completedTasks.has(taskId)) {
75
+ incompleteTasks.push(this.taskGraph.tasks[taskId]);
76
+ }
77
+ }
78
+ return incompleteTasks;
79
+ }
71
80
  async scheduleTasks() {
72
81
  if (this.options.batch || process.env.NX_BATCH_MODE === 'true') {
73
82
  await this.scheduleBatches();
@@ -38,4 +38,4 @@ export declare class GitRepository {
38
38
  export declare function getGithubSlugOrNull(): string | null;
39
39
  export declare function extractUserAndRepoFromGitHubUrl(gitRemotes: string): string | null;
40
40
  export declare function commitChanges(commitMessage: string, directory?: string): string | null;
41
- export declare function getLatestCommitSha(): string | null;
41
+ export declare function getLatestCommitSha(directory?: string): string | null;
@@ -222,7 +222,11 @@ function parseGitHubUrl(url) {
222
222
  }
223
223
  function commitChanges(commitMessage, directory) {
224
224
  try {
225
- (0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe' });
225
+ (0, child_process_1.execSync)('git add -A', {
226
+ encoding: 'utf8',
227
+ stdio: 'pipe',
228
+ cwd: directory,
229
+ });
226
230
  (0, child_process_1.execSync)('git commit --no-verify -F -', {
227
231
  encoding: 'utf8',
228
232
  stdio: 'pipe',
@@ -243,14 +247,15 @@ function commitChanges(commitMessage, directory) {
243
247
  throw new Error(`Error committing changes:\n${err.stderr}`);
244
248
  }
245
249
  }
246
- return getLatestCommitSha();
250
+ return getLatestCommitSha(directory);
247
251
  }
248
- function getLatestCommitSha() {
252
+ function getLatestCommitSha(directory) {
249
253
  try {
250
254
  return (0, child_process_1.execSync)('git rev-parse HEAD', {
251
255
  encoding: 'utf8',
252
256
  stdio: 'pipe',
253
257
  windowsHide: false,
258
+ cwd: directory,
254
259
  }).trim();
255
260
  }
256
261
  catch {