nx 21.0.0-canary.20250206-8bd0bcd → 21.0.0-canary.20250418-8619c1d

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 (219) hide show
  1. package/.eslintrc.json +5 -1
  2. package/package.json +13 -12
  3. package/release/index.d.ts +1 -1
  4. package/release/index.js +2 -1
  5. package/schemas/nx-schema.json +186 -35
  6. package/src/adapter/compat.d.ts +1 -1
  7. package/src/adapter/compat.js +3 -0
  8. package/src/command-line/add/add.js +6 -16
  9. package/src/command-line/affected/command-object.js +6 -6
  10. package/src/command-line/examples.js +0 -4
  11. package/src/command-line/exec/command-object.js +1 -1
  12. package/src/command-line/generate/generator-utils.js +8 -3
  13. package/src/command-line/graph/graph.js +2 -0
  14. package/src/command-line/import/import.js +1 -1
  15. package/src/command-line/init/command-object.js +18 -6
  16. package/src/command-line/init/configure-plugins.d.ts +6 -7
  17. package/src/command-line/init/configure-plugins.js +47 -35
  18. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  19. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  20. package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
  21. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  22. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  23. package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
  24. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  25. package/src/command-line/init/implementation/react/index.js +32 -185
  26. package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
  27. package/src/command-line/init/implementation/utils.d.ts +4 -1
  28. package/src/command-line/init/implementation/utils.js +108 -44
  29. package/src/command-line/init/init-v1.js +1 -1
  30. package/src/command-line/init/init-v2.d.ts +1 -0
  31. package/src/command-line/init/init-v2.js +68 -38
  32. package/src/command-line/migrate/migrate-ui-api.d.ts +56 -0
  33. package/src/command-line/migrate/migrate-ui-api.js +188 -0
  34. package/src/command-line/migrate/migrate.d.ts +17 -0
  35. package/src/command-line/migrate/migrate.js +106 -63
  36. package/src/command-line/nx-commands.js +19 -5
  37. package/src/command-line/register/command-object.d.ts +6 -0
  38. package/src/command-line/{activate-powerpack → register}/command-object.js +9 -9
  39. package/src/command-line/register/register.d.ts +2 -0
  40. package/src/command-line/register/register.js +9 -0
  41. package/src/command-line/release/changelog.js +18 -15
  42. package/src/command-line/release/command-object.d.ts +2 -0
  43. package/src/command-line/release/command-object.js +9 -0
  44. package/src/command-line/release/config/config.d.ts +8 -7
  45. package/src/command-line/release/config/config.js +129 -42
  46. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  47. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  48. package/src/command-line/release/index.d.ts +4 -0
  49. package/src/command-line/release/index.js +6 -1
  50. package/src/command-line/release/plan-check.js +6 -3
  51. package/src/command-line/release/plan.js +7 -3
  52. package/src/command-line/release/publish.js +7 -3
  53. package/src/command-line/release/release.js +8 -3
  54. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  55. package/src/command-line/release/utils/git.d.ts +3 -2
  56. package/src/command-line/release/utils/git.js +65 -9
  57. package/src/command-line/release/utils/github.js +3 -1
  58. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  59. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  60. package/src/command-line/release/utils/semver.d.ts +8 -0
  61. package/src/command-line/release/utils/semver.js +8 -0
  62. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  63. package/src/command-line/release/utils/shared-legacy.js +2 -0
  64. package/src/command-line/release/utils/shared.d.ts +11 -17
  65. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  66. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  67. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  68. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  69. package/src/command-line/release/version/project-logger.d.ts +8 -0
  70. package/src/command-line/release/version/project-logger.js +45 -0
  71. package/src/command-line/release/version/release-group-processor.d.ts +251 -0
  72. package/src/command-line/release/version/release-group-processor.js +1040 -0
  73. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  74. package/src/command-line/release/version/resolve-current-version.js +241 -0
  75. package/src/command-line/release/version/test-utils.d.ts +95 -0
  76. package/src/command-line/release/version/test-utils.js +416 -0
  77. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  78. package/src/command-line/release/version/topological-sort.js +41 -0
  79. package/src/command-line/release/version/version-actions.d.ts +170 -0
  80. package/src/command-line/release/version/version-actions.js +183 -0
  81. package/src/command-line/release/version-legacy.d.ts +46 -0
  82. package/src/command-line/release/version-legacy.js +453 -0
  83. package/src/command-line/release/version.d.ts +0 -40
  84. package/src/command-line/release/version.js +80 -262
  85. package/src/command-line/report/report.d.ts +7 -3
  86. package/src/command-line/report/report.js +52 -18
  87. package/src/command-line/run/command-object.js +2 -2
  88. package/src/command-line/run/run.js +1 -1
  89. package/src/command-line/run-many/command-object.js +2 -2
  90. package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
  91. package/src/command-line/yargs-utils/shared-options.js +20 -0
  92. package/src/commands-runner/get-command-projects.js +17 -2
  93. package/src/config/misc-interfaces.d.ts +10 -0
  94. package/src/config/nx-json.d.ts +153 -15
  95. package/src/config/project-graph.d.ts +4 -2
  96. package/src/config/project-graph.js +8 -0
  97. package/src/config/task-graph.d.ts +5 -0
  98. package/src/config/workspace-json-project-json.d.ts +6 -2
  99. package/src/core/graph/main.js +1 -1
  100. package/src/core/graph/runtime.js +1 -1
  101. package/src/core/graph/styles.css +2 -2
  102. package/src/core/graph/styles.js +1 -1
  103. package/src/daemon/client/client.d.ts +2 -0
  104. package/src/daemon/client/client.js +15 -0
  105. package/src/daemon/message-types/glob.d.ts +7 -0
  106. package/src/daemon/message-types/glob.js +9 -1
  107. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  108. package/src/daemon/message-types/hash-glob.js +9 -1
  109. package/src/daemon/server/handle-glob.d.ts +1 -0
  110. package/src/daemon/server/handle-glob.js +8 -0
  111. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  112. package/src/daemon/server/handle-hash-glob.js +8 -0
  113. package/src/daemon/server/logger.js +2 -1
  114. package/src/daemon/server/server.js +7 -0
  115. package/src/devkit-internals.d.ts +2 -1
  116. package/src/devkit-internals.js +4 -1
  117. package/src/executors/run-commands/run-commands.impl.d.ts +18 -17
  118. package/src/executors/run-commands/run-commands.impl.js +25 -292
  119. package/src/executors/run-commands/running-tasks.d.ts +40 -0
  120. package/src/executors/run-commands/running-tasks.js +386 -0
  121. package/src/executors/run-script/run-script.impl.js +4 -3
  122. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
  123. package/src/generators/testing-utils/create-tree.js +5 -1
  124. package/src/native/index.d.ts +94 -19
  125. package/src/native/index.js +16 -2
  126. package/src/native/native-bindings.js +6 -0
  127. package/src/native/nx.wasi-browser.js +20 -19
  128. package/src/native/nx.wasi.cjs +20 -19
  129. package/src/native/nx.wasm32-wasi.wasm +0 -0
  130. package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
  131. package/src/plugins/js/lock-file/lock-file.js +28 -13
  132. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  133. package/src/plugins/js/lock-file/utils/package-json.js +2 -1
  134. package/src/plugins/js/lock-file/yarn-parser.js +85 -39
  135. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  136. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  137. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  138. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  139. package/src/plugins/js/utils/packages.js +22 -3
  140. package/src/plugins/js/utils/register.js +1 -0
  141. package/src/plugins/js/utils/typescript.js +3 -3
  142. package/src/plugins/package-json/create-nodes.d.ts +1 -1
  143. package/src/plugins/package-json/create-nodes.js +3 -1
  144. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  145. package/src/project-graph/error-types.js +32 -2
  146. package/src/project-graph/plugins/get-plugins.js +2 -1
  147. package/src/project-graph/plugins/in-process-loader.js +1 -1
  148. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  149. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  150. package/src/project-graph/plugins/utils.d.ts +2 -2
  151. package/src/project-graph/plugins/utils.js +2 -2
  152. package/src/project-graph/project-graph.js +1 -1
  153. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  154. package/src/project-graph/utils/project-configuration-utils.js +25 -11
  155. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  156. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  157. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  158. package/src/tasks-runner/batch/run-batch.js +2 -3
  159. package/src/tasks-runner/cache.d.ts +20 -6
  160. package/src/tasks-runner/cache.js +104 -20
  161. package/src/tasks-runner/create-task-graph.d.ts +4 -1
  162. package/src/tasks-runner/create-task-graph.js +48 -16
  163. package/src/tasks-runner/default-tasks-runner.js +4 -13
  164. package/src/tasks-runner/forked-process-task-runner.d.ts +13 -14
  165. package/src/tasks-runner/forked-process-task-runner.js +160 -303
  166. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  167. package/src/tasks-runner/init-tasks-runner.js +59 -2
  168. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  169. package/src/tasks-runner/is-tui-enabled.js +64 -0
  170. package/src/tasks-runner/life-cycle.d.ts +10 -3
  171. package/src/tasks-runner/life-cycle.js +23 -2
  172. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +7 -2
  173. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +6 -1
  174. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +17 -0
  175. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +221 -0
  176. package/src/tasks-runner/pseudo-terminal.d.ts +17 -8
  177. package/src/tasks-runner/pseudo-terminal.js +63 -47
  178. package/src/tasks-runner/run-command.d.ts +1 -0
  179. package/src/tasks-runner/run-command.js +180 -23
  180. package/src/tasks-runner/running-tasks/batch-process.d.ts +14 -0
  181. package/src/tasks-runner/running-tasks/batch-process.js +70 -0
  182. package/src/tasks-runner/running-tasks/node-child-process.d.ts +36 -0
  183. package/src/tasks-runner/running-tasks/node-child-process.js +184 -0
  184. package/src/tasks-runner/running-tasks/noop-child-process.d.ts +15 -0
  185. package/src/tasks-runner/running-tasks/noop-child-process.js +19 -0
  186. package/src/tasks-runner/running-tasks/running-task.d.ts +8 -0
  187. package/src/tasks-runner/running-tasks/running-task.js +6 -0
  188. package/src/tasks-runner/task-env.d.ts +1 -4
  189. package/src/tasks-runner/task-env.js +2 -0
  190. package/src/tasks-runner/task-orchestrator.d.ts +25 -7
  191. package/src/tasks-runner/task-orchestrator.js +237 -95
  192. package/src/tasks-runner/tasks-schedule.js +5 -1
  193. package/src/tasks-runner/utils.d.ts +2 -10
  194. package/src/tasks-runner/utils.js +27 -15
  195. package/src/utils/child-process.d.ts +4 -0
  196. package/src/utils/child-process.js +23 -30
  197. package/src/utils/command-line-utils.d.ts +1 -1
  198. package/src/utils/find-matching-projects.js +2 -2
  199. package/src/utils/git-utils.d.ts +1 -1
  200. package/src/utils/git-utils.js +8 -3
  201. package/src/utils/handle-errors.js +15 -0
  202. package/src/utils/is-ci.js +4 -1
  203. package/src/utils/is-using-prettier.d.ts +3 -0
  204. package/src/utils/is-using-prettier.js +62 -0
  205. package/src/utils/nx-key.d.ts +7 -0
  206. package/src/utils/nx-key.js +52 -0
  207. package/src/utils/package-manager.js +2 -2
  208. package/src/utils/path.js +1 -1
  209. package/src/utils/require-nx-key.d.ts +1 -0
  210. package/src/utils/require-nx-key.js +22 -0
  211. package/src/utils/workspace-context.d.ts +2 -0
  212. package/src/utils/workspace-context.js +16 -0
  213. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  214. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  215. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  216. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  217. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  218. package/src/utils/powerpack.d.ts +0 -5
  219. package/src/utils/powerpack.js +0 -33
@@ -1,17 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initTasksRunner = initTasksRunner;
4
- const configuration_1 = require("../config/configuration");
4
+ exports.runDiscreteTasks = runDiscreteTasks;
5
+ exports.runContinuousTasks = runContinuousTasks;
6
+ const nx_json_1 = require("../config/nx-json");
5
7
  const project_graph_1 = require("../project-graph/project-graph");
6
8
  const run_command_1 = require("./run-command");
7
9
  const invoke_runner_terminal_output_life_cycle_1 = require("./life-cycles/invoke-runner-terminal-output-life-cycle");
8
10
  const perf_hooks_1 = require("perf_hooks");
9
11
  const utils_1 = require("./utils");
10
12
  const dotenv_1 = require("../utils/dotenv");
13
+ const life_cycle_1 = require("./life-cycle");
14
+ const task_orchestrator_1 = require("./task-orchestrator");
15
+ const create_task_hasher_1 = require("../hasher/create-task-hasher");
16
+ const client_1 = require("../daemon/client/client");
17
+ const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
18
+ /**
19
+ * This function is deprecated. Do not use this
20
+ * @deprecated This function is deprecated. Do not use this
21
+ */
11
22
  async function initTasksRunner(nxArgs) {
12
23
  perf_hooks_1.performance.mark('init-local');
13
24
  (0, dotenv_1.loadRootEnvFiles)();
14
- const nxJson = (0, configuration_1.readNxJson)();
25
+ const nxJson = (0, nx_json_1.readNxJson)();
15
26
  if (nxArgs.verbose) {
16
27
  process.env.NX_VERBOSE_LOGGING = 'true';
17
28
  }
@@ -36,6 +47,10 @@ async function initTasksRunner(nxArgs) {
36
47
  acc[task.id] = [];
37
48
  return acc;
38
49
  }, {}),
50
+ continuousDependencies: opts.tasks.reduce((acc, task) => {
51
+ acc[task.id] = [];
52
+ return acc;
53
+ }, {}),
39
54
  };
40
55
  const taskResults = await (0, run_command_1.invokeTasksRunner)({
41
56
  tasks: opts.tasks,
@@ -57,3 +72,45 @@ async function initTasksRunner(nxArgs) {
57
72
  },
58
73
  };
59
74
  }
75
+ async function createOrchestrator(tasks, projectGraph, taskGraphForHashing, nxJson, lifeCycle) {
76
+ (0, dotenv_1.loadRootEnvFiles)();
77
+ const invokeRunnerTerminalLifecycle = new invoke_runner_terminal_output_life_cycle_1.InvokeRunnerTerminalOutputLifeCycle(tasks);
78
+ const taskResultsLifecycle = new task_results_life_cycle_1.TaskResultsLifeCycle();
79
+ const compositedLifeCycle = new life_cycle_1.CompositeLifeCycle([
80
+ ...(0, run_command_1.constructLifeCycles)(invokeRunnerTerminalLifecycle),
81
+ taskResultsLifecycle,
82
+ lifeCycle,
83
+ ]);
84
+ const { runnerOptions: options } = (0, run_command_1.getRunner)({}, nxJson);
85
+ let hasher = (0, create_task_hasher_1.createTaskHasher)(projectGraph, nxJson, options);
86
+ const taskGraph = {
87
+ roots: tasks.map((task) => task.id),
88
+ tasks: tasks.reduce((acc, task) => {
89
+ acc[task.id] = task;
90
+ return acc;
91
+ }, {}),
92
+ dependencies: tasks.reduce((acc, task) => {
93
+ acc[task.id] = [];
94
+ return acc;
95
+ }, {}),
96
+ continuousDependencies: tasks.reduce((acc, task) => {
97
+ acc[task.id] = [];
98
+ return acc;
99
+ }, {}),
100
+ };
101
+ const orchestrator = new task_orchestrator_1.TaskOrchestrator(hasher, null, projectGraph, taskGraph, nxJson, { ...options, parallel: tasks.length, lifeCycle: compositedLifeCycle }, false, client_1.daemonClient, undefined, taskGraphForHashing);
102
+ await orchestrator.init();
103
+ await Promise.all(tasks.map((task) => orchestrator.processTask(task.id)));
104
+ return orchestrator;
105
+ }
106
+ async function runDiscreteTasks(tasks, projectGraph, taskGraphForHashing, nxJson, lifeCycle) {
107
+ const orchestrator = await createOrchestrator(tasks, projectGraph, taskGraphForHashing, nxJson, lifeCycle);
108
+ return tasks.map((task, index) => orchestrator.applyFromCacheOrRunTask(true, task, index));
109
+ }
110
+ async function runContinuousTasks(tasks, projectGraph, taskGraphForHashing, nxJson, lifeCycle) {
111
+ const orchestrator = await createOrchestrator(tasks, projectGraph, taskGraphForHashing, nxJson, lifeCycle);
112
+ return tasks.reduce((current, task, index) => {
113
+ current[task.id] = orchestrator.startContinuousTask(task, index);
114
+ return current;
115
+ }, {});
116
+ }
@@ -0,0 +1,2 @@
1
+ import type { NxJsonConfiguration } from '../config/nx-json';
2
+ export declare function isTuiEnabled(nxJson?: NxJsonConfiguration, skipCapableCheck?: boolean): any;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTuiEnabled = isTuiEnabled;
4
+ const devkit_internals_1 = require("../devkit-internals");
5
+ const is_ci_1 = require("../utils/is-ci");
6
+ let tuiEnabled = undefined;
7
+ function isTuiEnabled(nxJson, skipCapableCheck = false) {
8
+ if (tuiEnabled !== undefined) {
9
+ return tuiEnabled;
10
+ }
11
+ // If the current terminal/environment is not capable of displaying the TUI, we don't run it
12
+ const isWindows = process.platform === 'win32';
13
+ const isCapable = skipCapableCheck || (process.stderr.isTTY && isUnicodeSupported());
14
+ if (!isCapable) {
15
+ tuiEnabled = false;
16
+ process.env.NX_TUI = 'false';
17
+ return tuiEnabled;
18
+ }
19
+ // The environment variable takes precedence over the nx.json config
20
+ if (typeof process.env.NX_TUI === 'string') {
21
+ tuiEnabled = process.env.NX_TUI === 'true';
22
+ return tuiEnabled;
23
+ }
24
+ // Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled
25
+ // TODO(@JamesHenry): Remove this check once Windows issues are fixed.
26
+ if ((0, is_ci_1.isCI)() || isWindows) {
27
+ tuiEnabled = false;
28
+ process.env.NX_TUI = 'false';
29
+ return tuiEnabled;
30
+ }
31
+ // Only read from disk if nx.json config is not already provided (and we have not been able to determine tuiEnabled based on the above checks)
32
+ if (!nxJson) {
33
+ nxJson = (0, devkit_internals_1.readNxJsonFromDisk)();
34
+ }
35
+ // Respect user config
36
+ if (typeof nxJson.tui?.enabled === 'boolean') {
37
+ tuiEnabled = Boolean(nxJson.tui?.enabled);
38
+ }
39
+ else {
40
+ // Default to enabling the TUI if the system is capable of displaying it
41
+ tuiEnabled = true;
42
+ }
43
+ // Also set the environment variable for consistency and ease of checking on the rust side, for example
44
+ process.env.NX_TUI = tuiEnabled.toString();
45
+ return tuiEnabled;
46
+ }
47
+ // Credit to https://github.com/sindresorhus/is-unicode-supported/blob/e0373335038856c63034c8eef6ac43ee3827a601/index.js
48
+ function isUnicodeSupported() {
49
+ const { env } = process;
50
+ const { TERM, TERM_PROGRAM } = env;
51
+ if (process.platform !== 'win32') {
52
+ return TERM !== 'linux'; // Linux console (kernel)
53
+ }
54
+ return (Boolean(env.WT_SESSION) || // Windows Terminal
55
+ Boolean(env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
56
+ env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
57
+ TERM_PROGRAM === 'Terminus-Sublime' ||
58
+ TERM_PROGRAM === 'vscode' ||
59
+ TERM === 'xterm-256color' ||
60
+ TERM === 'alacritty' ||
61
+ TERM === 'rxvt-unicode' ||
62
+ TERM === 'rxvt-unicode-256color' ||
63
+ env.TERMINAL_EMULATOR === 'JetBrains-JediTerm');
64
+ }
@@ -1,5 +1,6 @@
1
- import { TaskStatus } from './tasks-runner';
2
1
  import { Task } from '../config/task-graph';
2
+ import { ExternalObject, TaskStatus as NativeTaskStatus } from '../native';
3
+ import { TaskStatus } from './tasks-runner';
3
4
  /**
4
5
  * The result of a completed {@link Task}
5
6
  */
@@ -17,7 +18,7 @@ export interface TaskMetadata {
17
18
  groupId: number;
18
19
  }
19
20
  export interface LifeCycle {
20
- startCommand?(): void | Promise<void>;
21
+ startCommand?(parallel?: number): void | Promise<void>;
21
22
  endCommand?(): void | Promise<void>;
22
23
  scheduleTask?(task: Task): void | Promise<void>;
23
24
  /**
@@ -35,11 +36,14 @@ export interface LifeCycle {
35
36
  startTasks?(task: Task[], metadata: TaskMetadata): void | Promise<void>;
36
37
  endTasks?(taskResults: TaskResult[], metadata: TaskMetadata): void | Promise<void>;
37
38
  printTaskTerminalOutput?(task: Task, status: TaskStatus, output: string): void;
39
+ registerRunningTask?(taskId: string, parserAndWriter: ExternalObject<[any, any]>): Promise<void>;
40
+ setTaskStatus?(taskId: string, status: NativeTaskStatus): void;
41
+ registerForcedShutdownCallback?(callback: () => void): void;
38
42
  }
39
43
  export declare class CompositeLifeCycle implements LifeCycle {
40
44
  private readonly lifeCycles;
41
45
  constructor(lifeCycles: LifeCycle[]);
42
- startCommand(): Promise<void>;
46
+ startCommand(parallel?: number): Promise<void>;
43
47
  endCommand(): Promise<void>;
44
48
  scheduleTask(task: Task): Promise<void>;
45
49
  startTask(task: Task): void;
@@ -47,4 +51,7 @@ export declare class CompositeLifeCycle implements LifeCycle {
47
51
  startTasks(tasks: Task[], metadata: TaskMetadata): Promise<void>;
48
52
  endTasks(taskResults: TaskResult[], metadata: TaskMetadata): Promise<void>;
49
53
  printTaskTerminalOutput(task: Task, status: TaskStatus, output: string): void;
54
+ registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[any, any]>): Promise<void>;
55
+ setTaskStatus(taskId: string, status: NativeTaskStatus): void;
56
+ registerForcedShutdownCallback(callback: () => void): void;
50
57
  }
@@ -5,10 +5,10 @@ class CompositeLifeCycle {
5
5
  constructor(lifeCycles) {
6
6
  this.lifeCycles = lifeCycles;
7
7
  }
8
- async startCommand() {
8
+ async startCommand(parallel) {
9
9
  for (let l of this.lifeCycles) {
10
10
  if (l.startCommand) {
11
- await l.startCommand();
11
+ await l.startCommand(parallel);
12
12
  }
13
13
  }
14
14
  }
@@ -67,5 +67,26 @@ class CompositeLifeCycle {
67
67
  }
68
68
  }
69
69
  }
70
+ async registerRunningTask(taskId, parserAndWriter) {
71
+ for (let l of this.lifeCycles) {
72
+ if (l.registerRunningTask) {
73
+ await l.registerRunningTask(taskId, parserAndWriter);
74
+ }
75
+ }
76
+ }
77
+ setTaskStatus(taskId, status) {
78
+ for (let l of this.lifeCycles) {
79
+ if (l.setTaskStatus) {
80
+ l.setTaskStatus(taskId, status);
81
+ }
82
+ }
83
+ }
84
+ registerForcedShutdownCallback(callback) {
85
+ for (let l of this.lifeCycles) {
86
+ if (l.registerForcedShutdownCallback) {
87
+ l.registerForcedShutdownCallback(callback);
88
+ }
89
+ }
90
+ }
70
91
  }
71
92
  exports.CompositeLifeCycle = CompositeLifeCycle;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LegacyTaskHistoryLifeCycle = void 0;
4
- const serialize_target_1 = require("../../utils/serialize-target");
5
- const output_1 = require("../../utils/output");
6
4
  const legacy_task_history_1 = require("../../utils/legacy-task-history");
5
+ const output_1 = require("../../utils/output");
6
+ const serialize_target_1 = require("../../utils/serialize-target");
7
+ const is_tui_enabled_1 = require("../is-tui-enabled");
7
8
  class LegacyTaskHistoryLifeCycle {
8
9
  constructor() {
9
10
  this.startTimings = {};
@@ -38,6 +39,10 @@ class LegacyTaskHistoryLifeCycle {
38
39
  flakyTasks.push((0, serialize_target_1.serializeTarget)(history[hash][0].project, history[hash][0].target, history[hash][0].configuration));
39
40
  }
40
41
  }
42
+ // Do not directly print output when using the TUI
43
+ if ((0, is_tui_enabled_1.isTuiEnabled)()) {
44
+ return;
45
+ }
41
46
  if (flakyTasks.length > 0) {
42
47
  output_1.output.warn({
43
48
  title: `Nx detected ${flakyTasks.length === 1 ? 'a flaky task' : ' flaky tasks'}`,
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskHistoryLifeCycle = void 0;
4
- const serialize_target_1 = require("../../utils/serialize-target");
5
4
  const output_1 = require("../../utils/output");
5
+ const serialize_target_1 = require("../../utils/serialize-target");
6
6
  const task_history_1 = require("../../utils/task-history");
7
+ const is_tui_enabled_1 = require("../is-tui-enabled");
7
8
  class TaskHistoryLifeCycle {
8
9
  constructor() {
9
10
  this.startTimings = {};
@@ -36,6 +37,10 @@ class TaskHistoryLifeCycle {
36
37
  }
37
38
  await this.taskHistory.recordTaskRuns(entries.map(([_, v]) => v));
38
39
  const flakyTasks = await this.taskHistory.getFlakyTasks(entries.map(([hash]) => hash));
40
+ // Do not directly print output when using the TUI
41
+ if ((0, is_tui_enabled_1.isTuiEnabled)()) {
42
+ return;
43
+ }
39
44
  if (flakyTasks.length > 0) {
40
45
  output_1.output.warn({
41
46
  title: `Nx detected ${flakyTasks.length === 1 ? 'a flaky task' : ' flaky tasks'}`,
@@ -0,0 +1,17 @@
1
+ import { Task } from '../../config/task-graph';
2
+ import type { LifeCycle } from '../life-cycle';
3
+ export declare function getTuiTerminalSummaryLifeCycle({ projectNames, tasks, args, overrides, initiatingProject, resolveRenderIsDonePromise, }: {
4
+ projectNames: string[];
5
+ tasks: Task[];
6
+ args: {
7
+ targets?: string[];
8
+ configuration?: string;
9
+ parallel?: number;
10
+ };
11
+ overrides: Record<string, unknown>;
12
+ initiatingProject: string;
13
+ resolveRenderIsDonePromise: (value: void) => void;
14
+ }): {
15
+ lifeCycle: Partial<LifeCycle>;
16
+ printSummary: () => void;
17
+ };
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTuiTerminalSummaryLifeCycle = getTuiTerminalSummaryLifeCycle;
4
+ const node_os_1 = require("node:os");
5
+ const output_1 = require("../../utils/output");
6
+ const formatting_utils_1 = require("./formatting-utils");
7
+ const pretty_time_1 = require("./pretty-time");
8
+ const view_logs_utils_1 = require("./view-logs-utils");
9
+ const figures = require("figures");
10
+ const LEFT_PAD = ` `;
11
+ const SPACER = ` `;
12
+ const EXTENDED_LEFT_PAD = ` `;
13
+ function getTuiTerminalSummaryLifeCycle({ projectNames, tasks, args, overrides, initiatingProject, resolveRenderIsDonePromise, }) {
14
+ const lifeCycle = {};
15
+ const start = process.hrtime();
16
+ const targets = args.targets;
17
+ const totalTasks = tasks.length;
18
+ let totalCachedTasks = 0;
19
+ let totalSuccessfulTasks = 0;
20
+ let totalFailedTasks = 0;
21
+ let totalCompletedTasks = 0;
22
+ let timeTakenText;
23
+ const failedTasks = new Set();
24
+ const inProgressTasks = new Set();
25
+ const tasksToTerminalOutputs = {};
26
+ const taskIdsInOrderOfCompletion = [];
27
+ lifeCycle.startTasks = (tasks) => {
28
+ for (let t of tasks) {
29
+ inProgressTasks.add(t.id);
30
+ }
31
+ };
32
+ lifeCycle.printTaskTerminalOutput = (task, taskStatus, terminalOutput) => {
33
+ tasksToTerminalOutputs[task.id] = { terminalOutput, taskStatus };
34
+ taskIdsInOrderOfCompletion.push(task.id);
35
+ };
36
+ lifeCycle.endTasks = (taskResults) => {
37
+ for (let t of taskResults) {
38
+ totalCompletedTasks++;
39
+ inProgressTasks.delete(t.task.id);
40
+ switch (t.status) {
41
+ case 'remote-cache':
42
+ case 'local-cache':
43
+ case 'local-cache-kept-existing':
44
+ totalCachedTasks++;
45
+ totalSuccessfulTasks++;
46
+ break;
47
+ case 'success':
48
+ totalSuccessfulTasks++;
49
+ break;
50
+ case 'failure':
51
+ totalFailedTasks++;
52
+ failedTasks.add(t.task.id);
53
+ break;
54
+ }
55
+ }
56
+ };
57
+ lifeCycle.endCommand = () => {
58
+ timeTakenText = (0, pretty_time_1.prettyTime)(process.hrtime(start));
59
+ resolveRenderIsDonePromise();
60
+ };
61
+ const printSummary = () => {
62
+ const isRunOne = initiatingProject && targets?.length === 1;
63
+ // Handles when the user interrupts the process
64
+ timeTakenText ??= (0, pretty_time_1.prettyTime)(process.hrtime(start));
65
+ if (totalTasks === 0) {
66
+ console.log(`\n${output_1.output.applyNxPrefix('gray', 'No tasks were run')}\n`);
67
+ return;
68
+ }
69
+ if (isRunOne) {
70
+ printRunOneSummary();
71
+ }
72
+ else {
73
+ printRunManySummary();
74
+ }
75
+ };
76
+ const printRunOneSummary = () => {
77
+ let lines = [];
78
+ const failure = totalSuccessfulTasks !== totalTasks;
79
+ // Prints task outputs in the order they were completed
80
+ // above the summary, since run-one should print all task results.
81
+ for (const taskId of taskIdsInOrderOfCompletion) {
82
+ const { terminalOutput, taskStatus } = tasksToTerminalOutputs[taskId];
83
+ output_1.output.logCommandOutput(taskId, taskStatus, terminalOutput);
84
+ }
85
+ lines.push(...output_1.output.getVerticalSeparatorLines(failure ? 'red' : 'green'));
86
+ if (!failure) {
87
+ const text = `Successfully ran ${(0, formatting_utils_1.formatTargetsAndProjects)([initiatingProject], targets, tasks)}`;
88
+ const taskOverridesLines = [];
89
+ if (Object.keys(overrides).length > 0) {
90
+ taskOverridesLines.push('');
91
+ taskOverridesLines.push(`${EXTENDED_LEFT_PAD}${output_1.output.dim.green('With additional flags:')}`);
92
+ Object.entries(overrides)
93
+ .map(([flag, value]) => output_1.output.dim.green((0, formatting_utils_1.formatFlags)(EXTENDED_LEFT_PAD, flag, value)))
94
+ .forEach((arg) => taskOverridesLines.push(arg));
95
+ }
96
+ lines.push(output_1.output.applyNxPrefix('green', output_1.output.colors.green(text) + output_1.output.dim(` (${timeTakenText})`)), ...taskOverridesLines);
97
+ if (totalCachedTasks > 0) {
98
+ lines.push(output_1.output.dim(`${node_os_1.EOL}Nx read the output from the cache instead of running the command for ${totalCachedTasks} out of ${totalTasks} tasks.`));
99
+ }
100
+ lines = [output_1.output.colors.green(lines.join(node_os_1.EOL))];
101
+ }
102
+ else if (totalCompletedTasks === totalTasks) {
103
+ let text = `Ran target ${output_1.output.bold(targets[0])} for project ${output_1.output.bold(initiatingProject)}`;
104
+ if (tasks.length > 1) {
105
+ text += ` and ${output_1.output.bold(tasks.length - 1)} task(s) they depend on`;
106
+ }
107
+ const taskOverridesLines = [];
108
+ if (Object.keys(overrides).length > 0) {
109
+ taskOverridesLines.push('');
110
+ taskOverridesLines.push(`${EXTENDED_LEFT_PAD}${output_1.output.dim.red('With additional flags:')}`);
111
+ Object.entries(overrides)
112
+ .map(([flag, value]) => output_1.output.dim.red((0, formatting_utils_1.formatFlags)(EXTENDED_LEFT_PAD, flag, value)))
113
+ .forEach((arg) => taskOverridesLines.push(arg));
114
+ }
115
+ const viewLogs = (0, view_logs_utils_1.viewLogsFooterRows)(totalFailedTasks);
116
+ lines = [
117
+ output_1.output.colors.red([
118
+ output_1.output.applyNxPrefix('red', output_1.output.colors.red(text) + output_1.output.dim(` (${timeTakenText})`)),
119
+ ...taskOverridesLines,
120
+ '',
121
+ `${LEFT_PAD}${output_1.output.colors.red(figures.cross)}${SPACER}${totalFailedTasks}${`/${totalCompletedTasks}`} failed`,
122
+ `${LEFT_PAD}${output_1.output.dim(figures.tick)}${SPACER}${totalSuccessfulTasks}${`/${totalCompletedTasks}`} succeeded ${output_1.output.dim(`[${totalCachedTasks} read from cache]`)}`,
123
+ ...viewLogs,
124
+ ]),
125
+ ];
126
+ }
127
+ else {
128
+ lines = [
129
+ ...output_1.output.getVerticalSeparatorLines('red'),
130
+ output_1.output.applyNxPrefix('red', output_1.output.colors.red(`Cancelled running target ${output_1.output.bold(targets[0])} for project ${output_1.output.bold(initiatingProject)}`) + output_1.output.dim(` (${timeTakenText})`)),
131
+ ];
132
+ }
133
+ // adds some vertical space after the summary to avoid bunching against terminal
134
+ lines.push('');
135
+ console.log(lines.join(node_os_1.EOL));
136
+ };
137
+ const printRunManySummary = () => {
138
+ console.log('');
139
+ const lines = [];
140
+ const failure = totalSuccessfulTasks !== totalTasks;
141
+ for (const taskId of taskIdsInOrderOfCompletion) {
142
+ const { terminalOutput, taskStatus } = tasksToTerminalOutputs[taskId];
143
+ if (taskStatus === 'failure') {
144
+ output_1.output.logCommandOutput(taskId, taskStatus, terminalOutput);
145
+ lines.push(`${LEFT_PAD}${output_1.output.colors.red(figures.cross)}${SPACER}${output_1.output.colors.gray('nx run ')}${taskId}`);
146
+ }
147
+ else {
148
+ lines.push(`${LEFT_PAD}${output_1.output.colors.green(figures.tick)}${SPACER}${output_1.output.colors.gray('nx run ')}${taskId}`);
149
+ }
150
+ }
151
+ lines.push(...output_1.output.getVerticalSeparatorLines(failure ? 'red' : 'green'));
152
+ if (totalSuccessfulTasks === totalTasks) {
153
+ const successSummaryRows = [];
154
+ const text = `Successfully ran ${(0, formatting_utils_1.formatTargetsAndProjects)(projectNames, targets, tasks)}`;
155
+ const taskOverridesRows = [];
156
+ if (Object.keys(overrides).length > 0) {
157
+ taskOverridesRows.push('');
158
+ taskOverridesRows.push(`${EXTENDED_LEFT_PAD}${output_1.output.dim.green('With additional flags:')}`);
159
+ Object.entries(overrides)
160
+ .map(([flag, value]) => output_1.output.dim.green((0, formatting_utils_1.formatFlags)(EXTENDED_LEFT_PAD, flag, value)))
161
+ .forEach((arg) => taskOverridesRows.push(arg));
162
+ }
163
+ successSummaryRows.push(...[
164
+ output_1.output.applyNxPrefix('green', output_1.output.colors.green(text) + output_1.output.dim.white(` (${timeTakenText})`)),
165
+ ...taskOverridesRows,
166
+ ]);
167
+ if (totalCachedTasks > 0) {
168
+ successSummaryRows.push(output_1.output.dim(`${node_os_1.EOL}Nx read the output from the cache instead of running the command for ${totalCachedTasks} out of ${totalTasks} tasks.`));
169
+ }
170
+ lines.push(successSummaryRows.join(node_os_1.EOL));
171
+ }
172
+ else {
173
+ const text = `${inProgressTasks.size ? 'Cancelled while running' : 'Ran'} ${(0, formatting_utils_1.formatTargetsAndProjects)(projectNames, targets, tasks)}`;
174
+ const taskOverridesRows = [];
175
+ if (Object.keys(overrides).length > 0) {
176
+ taskOverridesRows.push('');
177
+ taskOverridesRows.push(`${EXTENDED_LEFT_PAD}${output_1.output.dim.red('With additional flags:')}`);
178
+ Object.entries(overrides)
179
+ .map(([flag, value]) => output_1.output.dim.red((0, formatting_utils_1.formatFlags)(EXTENDED_LEFT_PAD, flag, value)))
180
+ .forEach((arg) => taskOverridesRows.push(arg));
181
+ }
182
+ const numFailedToPrint = 5;
183
+ const failedTasksForPrinting = Array.from(failedTasks).slice(0, numFailedToPrint);
184
+ const failureSummaryRows = [
185
+ output_1.output.applyNxPrefix('red', output_1.output.colors.red(text) + output_1.output.dim.white(` (${timeTakenText})`)),
186
+ ...taskOverridesRows,
187
+ '',
188
+ ];
189
+ if (totalCompletedTasks > 0) {
190
+ if (totalSuccessfulTasks > 0) {
191
+ failureSummaryRows.push(output_1.output.dim(`${LEFT_PAD}${output_1.output.dim(figures.tick)}${SPACER}${totalSuccessfulTasks}${`/${totalCompletedTasks}`} succeeded ${output_1.output.dim(`[${totalCachedTasks} read from cache]`)}`), '');
192
+ }
193
+ if (totalFailedTasks > 0) {
194
+ failureSummaryRows.push(`${LEFT_PAD}${output_1.output.colors.red(figures.cross)}${SPACER}${totalFailedTasks}${`/${totalCompletedTasks}`} targets failed, including the following:`, '', `${failedTasksForPrinting
195
+ .map((t) => `${EXTENDED_LEFT_PAD}${output_1.output.colors.red('-')} ${output_1.output.formatCommand(t.toString())}`)
196
+ .join('\n')}`, '');
197
+ if (failedTasks.size > numFailedToPrint) {
198
+ failureSummaryRows.push(output_1.output.dim(`${EXTENDED_LEFT_PAD}...and ${failedTasks.size - numFailedToPrint} more...`));
199
+ }
200
+ }
201
+ if (totalCompletedTasks !== totalTasks) {
202
+ const remainingTasks = totalTasks - totalCompletedTasks;
203
+ if (inProgressTasks.size) {
204
+ failureSummaryRows.push(`${LEFT_PAD}${output_1.output.colors.red(figures.ellipsis)}${SPACER}${inProgressTasks.size}${`/${totalTasks}`} targets were in progress, including the following:`, '', `${Array.from(inProgressTasks)
205
+ .map((t) => `${EXTENDED_LEFT_PAD}${output_1.output.colors.red('-')} ${output_1.output.formatCommand(t.toString())}`)
206
+ .join(node_os_1.EOL)}`, '');
207
+ }
208
+ if (remainingTasks - inProgressTasks.size > 0) {
209
+ failureSummaryRows.push(output_1.output.dim(`${LEFT_PAD}${output_1.output.colors.red(figures.ellipsis)}${SPACER}${remainingTasks - inProgressTasks.size}${`/${totalTasks}`} targets had not started.`), '');
210
+ }
211
+ }
212
+ failureSummaryRows.push(...(0, view_logs_utils_1.viewLogsFooterRows)(failedTasks.size));
213
+ lines.push(output_1.output.colors.red(failureSummaryRows.join(node_os_1.EOL)));
214
+ }
215
+ }
216
+ // adds some vertical space after the summary to avoid bunching against terminal
217
+ lines.push('');
218
+ console.log(lines.join(node_os_1.EOL));
219
+ };
220
+ return { lifeCycle, printSummary };
221
+ }
@@ -1,7 +1,8 @@
1
+ import { Serializable } from 'child_process';
1
2
  import { ChildProcess, RustPseudoTerminal } from '../native';
2
3
  import { PseudoIPCServer } from './pseudo-ipc';
3
- import { Serializable } from 'child_process';
4
- export declare function getPseudoTerminal(skipSupportCheck?: boolean): PseudoTerminal;
4
+ import { RunningTask } from './running-tasks/running-task';
5
+ export declare function createPseudoTerminal(skipSupportCheck?: boolean): PseudoTerminal;
5
6
  export declare class PseudoTerminal {
6
7
  private rustPseudoTerminal;
7
8
  private pseudoIPCPath;
@@ -10,6 +11,7 @@ export declare class PseudoTerminal {
10
11
  static isSupported(): boolean;
11
12
  constructor(rustPseudoTerminal: RustPseudoTerminal);
12
13
  init(): Promise<void>;
14
+ shutdown(): void;
13
15
  runCommand(command: string, { cwd, execArgv, jsEnv, quiet, tty, }?: {
14
16
  cwd?: string;
15
17
  execArgv?: string[];
@@ -25,21 +27,28 @@ export declare class PseudoTerminal {
25
27
  }): Promise<PseudoTtyProcessWithSend>;
26
28
  sendMessageToChildren(message: Serializable): void;
27
29
  onMessageFromChildren(callback: (message: Serializable) => void): void;
28
- private setupProcessListeners;
29
- private shutdownPseudoIPC;
30
30
  }
31
- export declare class PseudoTtyProcess {
31
+ export declare class PseudoTtyProcess implements RunningTask {
32
+ rustPseudoTerminal: RustPseudoTerminal;
32
33
  private childProcess;
33
34
  isAlive: boolean;
34
- exitCallbacks: any[];
35
- constructor(childProcess: ChildProcess);
35
+ private exitCallbacks;
36
+ private outputCallbacks;
37
+ private terminalOutput;
38
+ constructor(rustPseudoTerminal: RustPseudoTerminal, childProcess: ChildProcess);
39
+ getResults(): Promise<{
40
+ code: number;
41
+ terminalOutput: string;
42
+ }>;
36
43
  onExit(callback: (code: number) => void): void;
37
44
  onOutput(callback: (message: string) => void): void;
38
45
  kill(): void;
46
+ getParserAndWriter(): import("../native").ExternalObject<[ParserArc, WriterArc]>;
39
47
  }
40
48
  export declare class PseudoTtyProcessWithSend extends PseudoTtyProcess {
49
+ rustPseudoTerminal: RustPseudoTerminal;
41
50
  private id;
42
51
  private pseudoIpc;
43
- constructor(_childProcess: ChildProcess, id: string, pseudoIpc: PseudoIPCServer);
52
+ constructor(rustPseudoTerminal: RustPseudoTerminal, _childProcess: ChildProcess, id: string, pseudoIpc: PseudoIPCServer);
44
53
  send(message: Serializable): void;
45
54
  }