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,29 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PseudoTtyProcessWithSend = exports.PseudoTtyProcess = exports.PseudoTerminal = void 0;
4
- exports.getPseudoTerminal = getPseudoTerminal;
4
+ exports.createPseudoTerminal = createPseudoTerminal;
5
+ const os = require("os");
6
+ const socket_utils_1 = require("../daemon/socket-utils");
5
7
  const native_1 = require("../native");
6
8
  const pseudo_ipc_1 = require("./pseudo-ipc");
7
- const socket_utils_1 = require("../daemon/socket-utils");
8
- const os = require("os");
9
- let pseudoTerminal;
10
- function getPseudoTerminal(skipSupportCheck = false) {
9
+ // Register single event listeners for all pseudo-terminal instances
10
+ const pseudoTerminalShutdownCallbacks = [];
11
+ process.on('SIGINT', () => {
12
+ pseudoTerminalShutdownCallbacks.forEach((cb) => cb());
13
+ });
14
+ process.on('SIGTERM', () => {
15
+ pseudoTerminalShutdownCallbacks.forEach((cb) => cb());
16
+ });
17
+ process.on('SIGHUP', () => {
18
+ pseudoTerminalShutdownCallbacks.forEach((cb) => cb());
19
+ });
20
+ process.on('exit', () => {
21
+ pseudoTerminalShutdownCallbacks.forEach((cb) => cb());
22
+ });
23
+ function createPseudoTerminal(skipSupportCheck = false) {
11
24
  if (!skipSupportCheck && !PseudoTerminal.isSupported()) {
12
25
  throw new Error('Pseudo terminal is not supported on this platform.');
13
26
  }
14
- pseudoTerminal ??= new PseudoTerminal(new native_1.RustPseudoTerminal());
27
+ const pseudoTerminal = new PseudoTerminal(new native_1.RustPseudoTerminal());
28
+ pseudoTerminalShutdownCallbacks.push(pseudoTerminal.shutdown.bind(pseudoTerminal));
15
29
  return pseudoTerminal;
16
30
  }
31
+ let id = 0;
17
32
  class PseudoTerminal {
18
33
  static isSupported() {
19
34
  return process.stdout.isTTY && supportedPtyPlatform();
20
35
  }
21
36
  constructor(rustPseudoTerminal) {
22
37
  this.rustPseudoTerminal = rustPseudoTerminal;
23
- this.pseudoIPCPath = (0, socket_utils_1.getForkedProcessOsSocketPath)(process.pid.toString());
38
+ this.pseudoIPCPath = (0, socket_utils_1.getForkedProcessOsSocketPath)(process.pid.toString() + '-' + id++);
24
39
  this.pseudoIPC = new pseudo_ipc_1.PseudoIPCServer(this.pseudoIPCPath);
25
40
  this.initialized = false;
26
- this.setupProcessListeners();
27
41
  }
28
42
  async init() {
29
43
  if (this.initialized) {
@@ -32,14 +46,19 @@ class PseudoTerminal {
32
46
  await this.pseudoIPC.init();
33
47
  this.initialized = true;
34
48
  }
49
+ shutdown() {
50
+ if (this.initialized) {
51
+ this.pseudoIPC.close();
52
+ }
53
+ }
35
54
  runCommand(command, { cwd, execArgv, jsEnv, quiet, tty, } = {}) {
36
- return new PseudoTtyProcess(this.rustPseudoTerminal.runCommand(command, cwd, jsEnv, execArgv, quiet, tty));
55
+ return new PseudoTtyProcess(this.rustPseudoTerminal, this.rustPseudoTerminal.runCommand(command, cwd, jsEnv, execArgv, quiet, tty));
37
56
  }
38
57
  async fork(id, script, { cwd, execArgv, jsEnv, quiet, }) {
39
58
  if (!this.initialized) {
40
59
  throw new Error('Call init() before forking processes');
41
60
  }
42
- const cp = new PseudoTtyProcessWithSend(this.rustPseudoTerminal.fork(id, script, this.pseudoIPCPath, cwd, jsEnv, execArgv, quiet), id, this.pseudoIPC);
61
+ const cp = new PseudoTtyProcessWithSend(this.rustPseudoTerminal, this.rustPseudoTerminal.fork(id, script, this.pseudoIPCPath, cwd, jsEnv, execArgv, quiet), id, this.pseudoIPC);
43
62
  await this.pseudoIPC.waitForChildReady(id);
44
63
  return cp;
45
64
  }
@@ -49,66 +68,63 @@ class PseudoTerminal {
49
68
  onMessageFromChildren(callback) {
50
69
  this.pseudoIPC.onMessageFromChildren(callback);
51
70
  }
52
- setupProcessListeners() {
53
- const shutdown = () => {
54
- this.shutdownPseudoIPC();
55
- };
56
- process.on('SIGINT', () => {
57
- this.shutdownPseudoIPC();
58
- });
59
- process.on('SIGTERM', () => {
60
- this.shutdownPseudoIPC();
61
- });
62
- process.on('SIGHUP', () => {
63
- this.shutdownPseudoIPC();
64
- });
65
- process.on('exit', () => {
66
- this.shutdownPseudoIPC();
67
- });
68
- }
69
- shutdownPseudoIPC() {
70
- if (this.initialized) {
71
- this.pseudoIPC.close();
72
- }
73
- }
74
71
  }
75
72
  exports.PseudoTerminal = PseudoTerminal;
76
73
  class PseudoTtyProcess {
77
- constructor(childProcess) {
74
+ constructor(rustPseudoTerminal, childProcess) {
75
+ this.rustPseudoTerminal = rustPseudoTerminal;
78
76
  this.childProcess = childProcess;
79
77
  this.isAlive = true;
80
78
  this.exitCallbacks = [];
79
+ this.outputCallbacks = [];
80
+ this.terminalOutput = '';
81
+ childProcess.onOutput((output) => {
82
+ this.terminalOutput += output;
83
+ this.outputCallbacks.forEach((cb) => cb(output));
84
+ });
81
85
  childProcess.onExit((message) => {
82
86
  this.isAlive = false;
83
- const exitCode = messageToCode(message);
84
- this.exitCallbacks.forEach((cb) => cb(exitCode));
87
+ const code = messageToCode(message);
88
+ childProcess.cleanup();
89
+ this.exitCallbacks.forEach((cb) => cb(code));
90
+ });
91
+ }
92
+ async getResults() {
93
+ return new Promise((res) => {
94
+ this.onExit((code) => {
95
+ res({ code, terminalOutput: this.terminalOutput });
96
+ });
85
97
  });
86
98
  }
87
99
  onExit(callback) {
88
100
  this.exitCallbacks.push(callback);
89
101
  }
90
102
  onOutput(callback) {
91
- this.childProcess.onOutput(callback);
103
+ this.outputCallbacks.push(callback);
92
104
  }
93
105
  kill() {
94
- try {
95
- this.childProcess.kill();
96
- }
97
- catch {
98
- // when the child process completes before we explicitly call kill, this will throw
99
- // do nothing
100
- }
101
- finally {
102
- if (this.isAlive == true) {
106
+ if (this.isAlive) {
107
+ try {
108
+ this.childProcess.kill();
109
+ }
110
+ catch {
111
+ // when the child process completes before we explicitly call kill, this will throw
112
+ // do nothing
113
+ }
114
+ finally {
103
115
  this.isAlive = false;
104
116
  }
105
117
  }
106
118
  }
119
+ getParserAndWriter() {
120
+ return this.childProcess.getParserAndWriter();
121
+ }
107
122
  }
108
123
  exports.PseudoTtyProcess = PseudoTtyProcess;
109
124
  class PseudoTtyProcessWithSend extends PseudoTtyProcess {
110
- constructor(_childProcess, id, pseudoIpc) {
111
- super(_childProcess);
125
+ constructor(rustPseudoTerminal, _childProcess, id, pseudoIpc) {
126
+ super(rustPseudoTerminal, _childProcess);
127
+ this.rustPseudoTerminal = rustPseudoTerminal;
112
128
  this.id = id;
113
129
  this.pseudoIpc = pseudoIpc;
114
130
  }
@@ -29,6 +29,7 @@ export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, life
29
29
  }): Promise<{
30
30
  [id: string]: TaskResult;
31
31
  }>;
32
+ export declare function constructLifeCycles(lifeCycle: LifeCycle): LifeCycle[];
32
33
  export declare function getRunner(nxArgs: NxArgs, nxJson: NxJsonConfiguration): {
33
34
  tasksRunner: TasksRunner;
34
35
  runnerOptions: any;
@@ -3,25 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommand = runCommand;
4
4
  exports.runCommandForTasks = runCommandForTasks;
5
5
  exports.invokeTasksRunner = invokeTasksRunner;
6
+ exports.constructLifeCycles = constructLifeCycles;
6
7
  exports.getRunner = getRunner;
7
8
  exports.getRunnerOptions = getRunnerOptions;
8
9
  const enquirer_1 = require("enquirer");
10
+ const node_path_1 = require("node:path");
11
+ const node_util_1 = require("node:util");
9
12
  const ora = require("ora");
10
- const path_1 = require("path");
11
13
  const nx_json_1 = require("../config/nx-json");
12
14
  const client_1 = require("../daemon/client/client");
13
15
  const create_task_hasher_1 = require("../hasher/create-task-hasher");
14
16
  const hash_task_1 = require("../hasher/hash-task");
15
17
  const native_1 = require("../native");
18
+ const tasks_execution_hooks_1 = require("../project-graph/plugins/tasks-execution-hooks");
16
19
  const project_graph_1 = require("../project-graph/project-graph");
17
20
  const fileutils_1 = require("../utils/fileutils");
21
+ const handle_errors_1 = require("../utils/handle-errors");
18
22
  const is_ci_1 = require("../utils/is-ci");
19
23
  const nx_cloud_utils_1 = require("../utils/nx-cloud-utils");
24
+ const nx_key_1 = require("../utils/nx-key");
20
25
  const output_1 = require("../utils/output");
21
- const handle_errors_1 = require("../utils/handle-errors");
22
26
  const sync_generators_1 = require("../utils/sync-generators");
23
27
  const workspace_root_1 = require("../utils/workspace-root");
24
28
  const create_task_graph_1 = require("./create-task-graph");
29
+ const is_tui_enabled_1 = require("./is-tui-enabled");
25
30
  const life_cycle_1 = require("./life-cycle");
26
31
  const dynamic_run_many_terminal_output_life_cycle_1 = require("./life-cycles/dynamic-run-many-terminal-output-life-cycle");
27
32
  const dynamic_run_one_terminal_output_life_cycle_1 = require("./life-cycles/dynamic-run-one-terminal-output-life-cycle");
@@ -31,19 +36,172 @@ const store_run_information_life_cycle_1 = require("./life-cycles/store-run-info
31
36
  const task_history_life_cycle_1 = require("./life-cycles/task-history-life-cycle");
32
37
  const task_history_life_cycle_old_1 = require("./life-cycles/task-history-life-cycle-old");
33
38
  const task_profiling_life_cycle_1 = require("./life-cycles/task-profiling-life-cycle");
34
- const task_timings_life_cycle_1 = require("./life-cycles/task-timings-life-cycle");
35
39
  const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
40
+ const task_timings_life_cycle_1 = require("./life-cycles/task-timings-life-cycle");
41
+ const tui_summary_life_cycle_1 = require("./life-cycles/tui-summary-life-cycle");
36
42
  const task_graph_utils_1 = require("./task-graph-utils");
37
43
  const utils_1 = require("./utils");
38
44
  const chalk = require("chalk");
39
- const powerpack_1 = require("../utils/powerpack");
40
- const tasks_execution_hooks_1 = require("../project-graph/plugins/tasks-execution-hooks");
41
- async function getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides) {
45
+ const originalStdoutWrite = process.stdout.write.bind(process.stdout);
46
+ const originalStderrWrite = process.stderr.write.bind(process.stderr);
47
+ const originalConsoleLog = console.log.bind(console);
48
+ const originalConsoleError = console.error.bind(console);
49
+ async function getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, taskGraph, nxArgs, nxJson, overrides) {
50
+ const overridesWithoutHidden = { ...overrides };
51
+ delete overridesWithoutHidden['__overrides_unparsed__'];
52
+ if ((0, is_tui_enabled_1.isTuiEnabled)(nxJson)) {
53
+ const interceptedNxCloudLogs = [];
54
+ const createPatchedConsoleMethod = (originalMethod) => {
55
+ return (...args) => {
56
+ // Check if the log came from the Nx Cloud client, otherwise invoke the original write method
57
+ const stackTrace = new Error().stack;
58
+ const isNxCloudLog = stackTrace.includes((0, node_path_1.join)(workspace_root_1.workspaceRoot, '.nx', 'cache', 'cloud'));
59
+ if (!isNxCloudLog) {
60
+ return originalMethod(...args);
61
+ }
62
+ // No-op the Nx Cloud client logs
63
+ };
64
+ };
65
+ // The cloud client calls console.log when NX_VERBOSE_LOGGING is set to true
66
+ console.log = createPatchedConsoleMethod(originalConsoleLog);
67
+ console.error = createPatchedConsoleMethod(originalConsoleError);
68
+ const patchedWrite = (_chunk, _encoding, callback) => {
69
+ // Preserve original behavior around callback and return value, just in case
70
+ if (callback) {
71
+ callback();
72
+ }
73
+ return true;
74
+ };
75
+ process.stdout.write = patchedWrite;
76
+ process.stderr.write = patchedWrite;
77
+ const { AppLifeCycle, restoreTerminal } = await Promise.resolve().then(() => require('../native'));
78
+ let appLifeCycle;
79
+ const isRunOne = initiatingProject != null;
80
+ const pinnedTasks = [];
81
+ const taskText = tasks.length === 1 ? 'task' : 'tasks';
82
+ const projectText = projectNames.length === 1 ? 'project' : 'projects';
83
+ let titleText = '';
84
+ if (isRunOne) {
85
+ const mainTaskId = (0, create_task_graph_1.createTaskId)(initiatingProject, nxArgs.targets[0], nxArgs.configuration);
86
+ pinnedTasks.push(mainTaskId);
87
+ const mainContinuousDependencies = taskGraph.continuousDependencies[mainTaskId];
88
+ if (mainContinuousDependencies.length > 0) {
89
+ pinnedTasks.push(mainContinuousDependencies[0]);
90
+ }
91
+ const [project, target] = mainTaskId.split(':');
92
+ titleText = `${target} ${project}`;
93
+ if (tasks.length > 1) {
94
+ titleText += `, and ${tasks.length - 1} requisite ${taskText}`;
95
+ }
96
+ }
97
+ else {
98
+ titleText =
99
+ nxArgs.targets.join(', ') +
100
+ ` for ${projectNames.length} ${projectText}`;
101
+ if (tasks.length > projectNames.length) {
102
+ titleText += `, and ${tasks.length - projectNames.length} requisite ${taskText}`;
103
+ }
104
+ }
105
+ let resolveRenderIsDonePromise;
106
+ // Default renderIsDone that will be overridden if the TUI is used
107
+ let renderIsDone = new Promise((resolve) => (resolveRenderIsDonePromise = resolve));
108
+ const { lifeCycle: tsLifeCycle, printSummary } = (0, tui_summary_life_cycle_1.getTuiTerminalSummaryLifeCycle)({
109
+ projectNames,
110
+ tasks,
111
+ args: nxArgs,
112
+ overrides: overridesWithoutHidden,
113
+ initiatingProject,
114
+ resolveRenderIsDonePromise,
115
+ });
116
+ if (tasks.length === 0) {
117
+ renderIsDone = renderIsDone.then(() => {
118
+ // Revert the patched methods
119
+ process.stdout.write = originalStdoutWrite;
120
+ process.stderr.write = originalStderrWrite;
121
+ console.log = originalConsoleLog;
122
+ console.error = originalConsoleError;
123
+ printSummary();
124
+ });
125
+ }
126
+ const lifeCycles = [tsLifeCycle];
127
+ // Only run the TUI if there are tasks to run
128
+ if (tasks.length > 0) {
129
+ appLifeCycle = new AppLifeCycle(tasks, pinnedTasks, nxArgs ?? {}, nxJson.tui ?? {}, titleText);
130
+ lifeCycles.unshift(appLifeCycle);
131
+ /**
132
+ * Patch stdout.write and stderr.write methods to pass Nx Cloud client logs to the TUI via the lifecycle
133
+ */
134
+ const createPatchedLogWrite = (originalWrite) => {
135
+ // @ts-ignore
136
+ return (chunk, encoding, callback) => {
137
+ // Check if the log came from the Nx Cloud client, otherwise invoke the original write method
138
+ const stackTrace = new Error().stack;
139
+ const isNxCloudLog = stackTrace.includes((0, node_path_1.join)(workspace_root_1.workspaceRoot, '.nx', 'cache', 'cloud'));
140
+ if (isNxCloudLog) {
141
+ interceptedNxCloudLogs.push(chunk);
142
+ // Do not bother to store logs with only whitespace characters, they aren't relevant for the TUI
143
+ const trimmedChunk = chunk.toString().trim();
144
+ if (trimmedChunk.length) {
145
+ // Remove ANSI escape codes, the TUI will control the formatting
146
+ appLifeCycle?.__setCloudMessage((0, node_util_1.stripVTControlCharacters)(trimmedChunk));
147
+ }
148
+ }
149
+ // Preserve original behavior around callback and return value, just in case
150
+ if (callback) {
151
+ callback();
152
+ }
153
+ return true;
154
+ };
155
+ };
156
+ const createPatchedConsoleMethod = (originalMethod) => {
157
+ return (...args) => {
158
+ // Check if the log came from the Nx Cloud client, otherwise invoke the original write method
159
+ const stackTrace = new Error().stack;
160
+ const isNxCloudLog = stackTrace.includes((0, node_path_1.join)(workspace_root_1.workspaceRoot, '.nx', 'cache', 'cloud'));
161
+ if (!isNxCloudLog) {
162
+ return originalMethod(...args);
163
+ }
164
+ // No-op the Nx Cloud client logs
165
+ };
166
+ };
167
+ process.stdout.write = createPatchedLogWrite(originalStdoutWrite);
168
+ process.stderr.write = createPatchedLogWrite(originalStderrWrite);
169
+ // The cloud client calls console.log when NX_VERBOSE_LOGGING is set to true
170
+ console.log = createPatchedConsoleMethod(originalConsoleLog);
171
+ console.error = createPatchedConsoleMethod(originalConsoleError);
172
+ renderIsDone = new Promise((resolve) => {
173
+ appLifeCycle.__init(() => {
174
+ resolve();
175
+ });
176
+ })
177
+ .then(() => {
178
+ restoreTerminal();
179
+ })
180
+ .finally(() => {
181
+ // Revert the patched methods
182
+ process.stdout.write = originalStdoutWrite;
183
+ process.stderr.write = originalStderrWrite;
184
+ console.log = originalConsoleLog;
185
+ console.error = originalConsoleError;
186
+ printSummary();
187
+ // Print the intercepted Nx Cloud logs
188
+ for (const log of interceptedNxCloudLogs) {
189
+ const logString = log.toString().trimStart();
190
+ process.stdout.write(logString);
191
+ if (logString) {
192
+ process.stdout.write('\n');
193
+ }
194
+ }
195
+ });
196
+ }
197
+ return {
198
+ lifeCycle: new life_cycle_1.CompositeLifeCycle(lifeCycles),
199
+ renderIsDone,
200
+ };
201
+ }
42
202
  const { runnerOptions } = getRunner(nxArgs, nxJson);
43
203
  const isRunOne = initiatingProject != null;
44
204
  const useDynamicOutput = shouldUseDynamicLifeCycle(tasks, runnerOptions, nxArgs.outputStyle);
45
- const overridesWithoutHidden = { ...overrides };
46
- delete overridesWithoutHidden['__overrides_unparsed__'];
47
205
  if (isRunOne) {
48
206
  if (useDynamicOutput) {
49
207
  return await (0, dynamic_run_one_terminal_output_life_cycle_1.createRunOneDynamicOutputRenderer)({
@@ -129,7 +287,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
129
287
  const projectNames = projectsToRun.map((t) => t.name);
130
288
  const { projectGraph, taskGraph } = await ensureWorkspaceIsInSyncAndGetGraphs(currentProjectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions);
131
289
  const tasks = Object.values(taskGraph.tasks);
132
- const { lifeCycle, renderIsDone } = await getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides);
290
+ const { lifeCycle, renderIsDone } = await getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, taskGraph, nxArgs, nxJson, overrides);
133
291
  const taskResults = await invokeTasksRunner({
134
292
  tasks,
135
293
  projectGraph,
@@ -141,12 +299,12 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
141
299
  initiatingProject,
142
300
  });
143
301
  await renderIsDone;
144
- await (0, powerpack_1.printPowerpackLicense)();
302
+ await (0, nx_key_1.printNxKey)();
145
303
  return taskResults;
146
304
  }
147
305
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
148
306
  let taskGraph = createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies ?? {}, projectNames, nxArgs, overrides, extraOptions);
149
- if (nxArgs.skipSync) {
307
+ if (nxArgs.skipSync || (0, is_ci_1.isCI)()) {
150
308
  return { projectGraph, taskGraph };
151
309
  }
152
310
  // collect unique syncGenerators from the tasks
@@ -166,9 +324,8 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
166
324
  const outOfSyncTitle = 'The workspace is out of sync';
167
325
  const resultBodyLines = (0, sync_generators_1.getSyncGeneratorSuccessResultsMessageLines)(results);
168
326
  const fixMessage = 'Make sure to run `nx sync` to apply the identified changes or set `sync.applyChanges` to `true` in your `nx.json` to apply them automatically when running tasks in interactive environments.';
169
- const willErrorOnCiMessage = 'This will result in an error in CI.';
170
- if ((0, is_ci_1.isCI)() || !process.stdout.isTTY) {
171
- // If the user is running in CI or is running in a non-TTY environment we
327
+ if (!process.stdout.isTTY) {
328
+ // If the user is running a non-TTY environment we
172
329
  // throw an error to stop the execution of the tasks.
173
330
  if (areAllResultsFailures) {
174
331
  output_1.output.error({
@@ -216,7 +373,6 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
216
373
  ...resultBodyLines,
217
374
  '',
218
375
  'Your workspace is set to not apply the identified changes automatically (`sync.applyChanges` is set to `false` in your `nx.json`).',
219
- willErrorOnCiMessage,
220
376
  fixMessage,
221
377
  ],
222
378
  });
@@ -235,10 +391,12 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, project
235
391
  title: outOfSyncTitle,
236
392
  bodyLines: [
237
393
  ...resultBodyLines,
238
- '',
239
- nxJson.sync?.applyChanges === true
240
- ? 'Proceeding to sync the identified changes automatically (`sync.applyChanges` is set to `true` in your `nx.json`).'
241
- : willErrorOnCiMessage,
394
+ ...(nxJson.sync?.applyChanges === true
395
+ ? [
396
+ '',
397
+ 'Proceeding to sync the identified changes automatically (`sync.applyChanges` is set to `true` in your `nx.json`).',
398
+ ]
399
+ : []),
242
400
  ],
243
401
  });
244
402
  const applyChanges = nxJson.sync?.applyChanges === true ||
@@ -535,10 +693,9 @@ function getRunner(nxArgs, nxJson) {
535
693
  try {
536
694
  if (isCustomRunnerPath(modulePath)) {
537
695
  output_1.output.warn({
538
- title: `Custom task runners will no longer be supported in Nx 21.`,
696
+ title: `Custom task runners will be replaced by a new API starting with Nx 21.`,
539
697
  bodyLines: [
540
- `Use Nx Cloud or the Nx Powerpack caches instead.`,
541
- `For more information, see https://nx.dev/nx-enterprise/powerpack/custom-caching`,
698
+ `For more information, see https://nx.dev/deprecated/custom-tasks-runner`,
542
699
  ],
543
700
  });
544
701
  }
@@ -557,7 +714,7 @@ function getTasksRunnerPath(runner, nxJson) {
557
714
  let modulePath = nxJson.tasksRunnerOptions?.[runner]?.runner;
558
715
  if (modulePath) {
559
716
  if ((0, fileutils_1.isRelativePath)(modulePath)) {
560
- return (0, path_1.join)(workspace_root_1.workspaceRoot, modulePath);
717
+ return (0, node_path_1.join)(workspace_root_1.workspaceRoot, modulePath);
561
718
  }
562
719
  return modulePath;
563
720
  }
@@ -0,0 +1,14 @@
1
+ import { BatchResults } from '../batch/batch-messages';
2
+ import { ChildProcess, Serializable } from 'child_process';
3
+ export declare class BatchProcess {
4
+ private childProcess;
5
+ private executorName;
6
+ private exitCallbacks;
7
+ private resultsCallbacks;
8
+ constructor(childProcess: ChildProcess, executorName: string);
9
+ onExit(cb: (code: number) => void): void;
10
+ onResults(cb: (results: BatchResults) => void): void;
11
+ getResults(): Promise<BatchResults>;
12
+ send(message: Serializable): void;
13
+ kill(signal?: NodeJS.Signals | number): void;
14
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BatchProcess = void 0;
4
+ const batch_messages_1 = require("../batch/batch-messages");
5
+ const exit_codes_1 = require("../../utils/exit-codes");
6
+ class BatchProcess {
7
+ constructor(childProcess, executorName) {
8
+ this.childProcess = childProcess;
9
+ this.executorName = executorName;
10
+ this.exitCallbacks = [];
11
+ this.resultsCallbacks = [];
12
+ this.childProcess.on('message', (message) => {
13
+ switch (message.type) {
14
+ case batch_messages_1.BatchMessageType.CompleteBatchExecution: {
15
+ for (const cb of this.resultsCallbacks) {
16
+ cb(message.results);
17
+ }
18
+ break;
19
+ }
20
+ case batch_messages_1.BatchMessageType.RunTasks: {
21
+ break;
22
+ }
23
+ default: {
24
+ // Re-emit any non-batch messages from the task process
25
+ if (process.send) {
26
+ process.send(message);
27
+ }
28
+ }
29
+ }
30
+ });
31
+ this.childProcess.once('exit', (code, signal) => {
32
+ if (code === null)
33
+ code = (0, exit_codes_1.signalToCode)(signal);
34
+ for (const cb of this.exitCallbacks) {
35
+ cb(code);
36
+ }
37
+ });
38
+ }
39
+ onExit(cb) {
40
+ this.exitCallbacks.push(cb);
41
+ }
42
+ onResults(cb) {
43
+ this.resultsCallbacks.push(cb);
44
+ }
45
+ async getResults() {
46
+ return Promise.race([
47
+ new Promise((_, rej) => {
48
+ this.onExit((code) => {
49
+ if (code !== 0) {
50
+ rej(new Error(`"${this.executorName}" exited unexpectedly with code: ${code}`));
51
+ }
52
+ });
53
+ }),
54
+ new Promise((res) => {
55
+ this.onResults(res);
56
+ }),
57
+ ]);
58
+ }
59
+ send(message) {
60
+ if (this.childProcess.connected) {
61
+ this.childProcess.send(message);
62
+ }
63
+ }
64
+ kill(signal) {
65
+ if (this.childProcess.connected) {
66
+ this.childProcess.kill(signal);
67
+ }
68
+ }
69
+ }
70
+ exports.BatchProcess = BatchProcess;
@@ -0,0 +1,36 @@
1
+ import { ChildProcess, Serializable } from 'child_process';
2
+ import { RunningTask } from './running-task';
3
+ export declare class NodeChildProcessWithNonDirectOutput implements RunningTask {
4
+ private childProcess;
5
+ private terminalOutput;
6
+ private exitCallbacks;
7
+ constructor(childProcess: ChildProcess, { streamOutput, prefix }: {
8
+ streamOutput: boolean;
9
+ prefix: string;
10
+ });
11
+ onExit(cb: (code: number, terminalOutput: string) => void): void;
12
+ getResults(): Promise<{
13
+ code: number;
14
+ terminalOutput: string;
15
+ }>;
16
+ send(message: Serializable): void;
17
+ kill(signal?: NodeJS.Signals | number): void;
18
+ }
19
+ export declare class NodeChildProcessWithDirectOutput implements RunningTask {
20
+ private childProcess;
21
+ private temporaryOutputPath;
22
+ private terminalOutput;
23
+ private exitCallbacks;
24
+ private exited;
25
+ private exitCode;
26
+ constructor(childProcess: ChildProcess, temporaryOutputPath: string);
27
+ send(message: Serializable): void;
28
+ onExit(cb: (code: number, signal: NodeJS.Signals) => void): void;
29
+ getResults(): Promise<{
30
+ code: number;
31
+ terminalOutput: string;
32
+ }>;
33
+ waitForExit(): Promise<void>;
34
+ getTerminalOutput(): string;
35
+ kill(signal?: NodeJS.Signals | number): void;
36
+ }