nx 21.0.0-beta.4 → 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 +41 -17
  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
@@ -397,15 +399,19 @@ class TaskOrchestrator {
397
399
  if (this.tuiEnabled) {
398
400
  this.options.lifeCycle.setTaskStatus(task.id, 8 /* NativeTaskStatus.Shared */);
399
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
+ });
400
407
  // task is already running by another process, we schedule the next tasks
401
408
  // and release the threads
402
409
  await this.scheduleNextTasksAndReleaseThreads();
403
- // wait for the running task to finish
404
- do {
405
- console.log(`Waiting for ${task.id} in another nx process`);
406
- await new Promise((resolve) => setTimeout(resolve, 100));
407
- } while (this.runningTasksService.getRunningTasks([task.id]).length);
408
- return;
410
+ if (this.initializingTaskIds.has(task.id)) {
411
+ // Hold the thread forever
412
+ await new Promise(() => { });
413
+ }
414
+ return runningTask;
409
415
  }
410
416
  const taskSpecificEnv = await this.processedTasks.get(task.id);
411
417
  await this.preRunSteps([task], { groupId });
@@ -425,14 +431,12 @@ class TaskOrchestrator {
425
431
  this.runningContinuousTasks.set(task.id, childProcess);
426
432
  childProcess.onExit(() => {
427
433
  this.runningTasksService.removeRunningTask(task.id);
434
+ this.runningContinuousTasks.delete(task.id);
428
435
  });
429
- if (this.initiatingProject === task.target.project &&
430
- this.options.targets.length === 1 &&
431
- this.options.targets[0] === task.target.target) {
432
- await childProcess.getResults();
433
- }
434
- else {
435
- await this.scheduleNextTasksAndReleaseThreads();
436
+ await this.scheduleNextTasksAndReleaseThreads();
437
+ if (this.initializingTaskIds.has(task.id)) {
438
+ // Hold the thread forever
439
+ await new Promise(() => { });
436
440
  }
437
441
  return childProcess;
438
442
  }
@@ -505,6 +509,7 @@ class TaskOrchestrator {
505
509
  }
506
510
  complete(taskResults) {
507
511
  this.tasksSchedule.complete(taskResults.map(({ taskId }) => taskId));
512
+ this.cleanUpUnneededContinuousTasks();
508
513
  for (const { taskId, status } of taskResults) {
509
514
  if (this.completedTasks[taskId] === undefined) {
510
515
  this.completedTasks[taskId] = status;
@@ -571,10 +576,10 @@ class TaskOrchestrator {
571
576
  }
572
577
  // endregion utils
573
578
  async cleanup() {
574
- this.cleaningUp = true;
575
579
  await Promise.all(Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
576
580
  try {
577
- return t.kill();
581
+ await t.kill();
582
+ this.options.lifeCycle.setTaskStatus(taskId, 9 /* NativeTaskStatus.Stopped */);
578
583
  }
579
584
  catch (e) {
580
585
  console.error(`Unable to terminate ${taskId}\nError:`, e);
@@ -584,6 +589,25 @@ class TaskOrchestrator {
584
589
  }
585
590
  }));
586
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
+ }
587
611
  }
588
612
  exports.TaskOrchestrator = TaskOrchestrator;
589
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 {