nx 21.0.0-beta.4 → 21.0.0-beta.6

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 (32) 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/forked-process-task-runner.js +3 -0
  13. package/src/tasks-runner/init-tasks-runner.js +2 -1
  14. package/src/tasks-runner/is-tui-enabled.d.ts +1 -1
  15. package/src/tasks-runner/is-tui-enabled.js +12 -6
  16. package/src/tasks-runner/life-cycle.d.ts +2 -2
  17. package/src/tasks-runner/life-cycle.js +2 -2
  18. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +2 -1
  19. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +16 -10
  20. package/src/tasks-runner/run-command.d.ts +2 -1
  21. package/src/tasks-runner/run-command.js +14 -6
  22. package/src/tasks-runner/running-tasks/node-child-process.js +4 -11
  23. package/src/tasks-runner/running-tasks/running-task.d.ts +2 -0
  24. package/src/tasks-runner/running-tasks/shared-running-task.d.ts +14 -0
  25. package/src/tasks-runner/running-tasks/shared-running-task.js +30 -0
  26. package/src/tasks-runner/task-orchestrator.d.ts +6 -3
  27. package/src/tasks-runner/task-orchestrator.js +57 -17
  28. package/src/tasks-runner/tasks-runner.d.ts +1 -0
  29. package/src/tasks-runner/tasks-schedule.d.ts +1 -0
  30. package/src/tasks-runner/tasks-schedule.js +9 -0
  31. package/src/utils/git-utils.d.ts +1 -1
  32. package/src/utils/git-utils.js +8 -3
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedRunningTask = void 0;
4
+ class SharedRunningTask {
5
+ constructor(runningTasksService, taskId) {
6
+ this.runningTasksService = runningTasksService;
7
+ this.exitCallbacks = [];
8
+ this.waitForTaskToFinish(taskId).then(() => {
9
+ // notify exit callbacks
10
+ this.exitCallbacks.forEach((cb) => cb(0));
11
+ });
12
+ }
13
+ async getResults() {
14
+ throw new Error('Results cannot be retrieved from a shared task');
15
+ }
16
+ kill() {
17
+ this.exitCallbacks.forEach((cb) => cb(0));
18
+ }
19
+ onExit(cb) {
20
+ this.exitCallbacks.push(cb);
21
+ }
22
+ async waitForTaskToFinish(taskId) {
23
+ console.log(`Waiting for ${taskId} in another nx process`);
24
+ // wait for the running task to finish
25
+ do {
26
+ await new Promise((resolve) => setTimeout(resolve, 100));
27
+ } while (this.runningTasksService.getRunningTasks([taskId]).length);
28
+ }
29
+ }
30
+ exports.SharedRunningTask = SharedRunningTask;
@@ -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,27 @@ 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
+ await new Promise((res) => {
412
+ runningTask.onExit((code) => {
413
+ if (!this.tuiEnabled) {
414
+ if (code > 128) {
415
+ process.exit(code);
416
+ }
417
+ }
418
+ res();
419
+ });
420
+ });
421
+ }
422
+ return runningTask;
409
423
  }
410
424
  const taskSpecificEnv = await this.processedTasks.get(task.id);
411
425
  await this.preRunSteps([task], { groupId });
@@ -425,14 +439,20 @@ class TaskOrchestrator {
425
439
  this.runningContinuousTasks.set(task.id, childProcess);
426
440
  childProcess.onExit(() => {
427
441
  this.runningTasksService.removeRunningTask(task.id);
442
+ this.runningContinuousTasks.delete(task.id);
428
443
  });
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();
444
+ await this.scheduleNextTasksAndReleaseThreads();
445
+ if (this.initializingTaskIds.has(task.id)) {
446
+ await new Promise((res) => {
447
+ childProcess.onExit((code) => {
448
+ if (!this.tuiEnabled) {
449
+ if (code > 128) {
450
+ process.exit(code);
451
+ }
452
+ }
453
+ res();
454
+ });
455
+ });
436
456
  }
437
457
  return childProcess;
438
458
  }
@@ -505,6 +525,7 @@ class TaskOrchestrator {
505
525
  }
506
526
  complete(taskResults) {
507
527
  this.tasksSchedule.complete(taskResults.map(({ taskId }) => taskId));
528
+ this.cleanUpUnneededContinuousTasks();
508
529
  for (const { taskId, status } of taskResults) {
509
530
  if (this.completedTasks[taskId] === undefined) {
510
531
  this.completedTasks[taskId] = status;
@@ -571,10 +592,10 @@ class TaskOrchestrator {
571
592
  }
572
593
  // endregion utils
573
594
  async cleanup() {
574
- this.cleaningUp = true;
575
595
  await Promise.all(Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
576
596
  try {
577
- return t.kill();
597
+ await t.kill();
598
+ this.options.lifeCycle.setTaskStatus(taskId, 9 /* NativeTaskStatus.Stopped */);
578
599
  }
579
600
  catch (e) {
580
601
  console.error(`Unable to terminate ${taskId}\nError:`, e);
@@ -584,6 +605,25 @@ class TaskOrchestrator {
584
605
  }
585
606
  }));
586
607
  }
608
+ cleanUpUnneededContinuousTasks() {
609
+ const incompleteTasks = this.tasksSchedule.getIncompleteTasks();
610
+ const neededContinuousTasks = new Set(this.initializingTaskIds);
611
+ for (const task of incompleteTasks) {
612
+ const continuousDependencies = this.taskGraph.continuousDependencies[task.id];
613
+ for (const continuousDependency of continuousDependencies) {
614
+ neededContinuousTasks.add(continuousDependency);
615
+ }
616
+ }
617
+ for (const taskId of this.runningContinuousTasks.keys()) {
618
+ if (!neededContinuousTasks.has(taskId)) {
619
+ const runningTask = this.runningContinuousTasks.get(taskId);
620
+ if (runningTask) {
621
+ runningTask.kill();
622
+ this.options.lifeCycle.setTaskStatus(taskId, 9 /* NativeTaskStatus.Stopped */);
623
+ }
624
+ }
625
+ }
626
+ }
587
627
  }
588
628
  exports.TaskOrchestrator = TaskOrchestrator;
589
629
  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 {