nx 21.0.0-canary.20250205-45d5140 → 21.0.0-canary.20250416-caa26a7

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 (215) 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.js +21 -18
  33. package/src/command-line/nx-commands.js +19 -5
  34. package/src/command-line/register/command-object.d.ts +6 -0
  35. package/src/command-line/{activate-powerpack → register}/command-object.js +9 -9
  36. package/src/command-line/register/register.d.ts +2 -0
  37. package/src/command-line/register/register.js +9 -0
  38. package/src/command-line/release/changelog.js +18 -15
  39. package/src/command-line/release/command-object.d.ts +2 -0
  40. package/src/command-line/release/command-object.js +9 -0
  41. package/src/command-line/release/config/config.d.ts +8 -7
  42. package/src/command-line/release/config/config.js +129 -42
  43. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  44. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  45. package/src/command-line/release/index.d.ts +4 -0
  46. package/src/command-line/release/index.js +6 -1
  47. package/src/command-line/release/plan-check.js +6 -3
  48. package/src/command-line/release/plan.js +7 -3
  49. package/src/command-line/release/publish.js +7 -3
  50. package/src/command-line/release/release.js +8 -3
  51. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  52. package/src/command-line/release/utils/git.d.ts +3 -2
  53. package/src/command-line/release/utils/git.js +65 -9
  54. package/src/command-line/release/utils/github.js +3 -1
  55. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  56. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  57. package/src/command-line/release/utils/semver.d.ts +8 -0
  58. package/src/command-line/release/utils/semver.js +8 -0
  59. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  60. package/src/command-line/release/utils/shared-legacy.js +2 -0
  61. package/src/command-line/release/utils/shared.d.ts +11 -17
  62. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  63. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  64. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  65. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  66. package/src/command-line/release/version/project-logger.d.ts +8 -0
  67. package/src/command-line/release/version/project-logger.js +45 -0
  68. package/src/command-line/release/version/release-group-processor.d.ts +251 -0
  69. package/src/command-line/release/version/release-group-processor.js +1040 -0
  70. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  71. package/src/command-line/release/version/resolve-current-version.js +241 -0
  72. package/src/command-line/release/version/test-utils.d.ts +95 -0
  73. package/src/command-line/release/version/test-utils.js +416 -0
  74. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  75. package/src/command-line/release/version/topological-sort.js +41 -0
  76. package/src/command-line/release/version/version-actions.d.ts +170 -0
  77. package/src/command-line/release/version/version-actions.js +183 -0
  78. package/src/command-line/release/version-legacy.d.ts +46 -0
  79. package/src/command-line/release/version-legacy.js +453 -0
  80. package/src/command-line/release/version.d.ts +0 -40
  81. package/src/command-line/release/version.js +80 -262
  82. package/src/command-line/report/report.d.ts +7 -3
  83. package/src/command-line/report/report.js +52 -18
  84. package/src/command-line/run/command-object.js +2 -2
  85. package/src/command-line/run/run.js +1 -1
  86. package/src/command-line/run-many/command-object.js +2 -2
  87. package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
  88. package/src/command-line/yargs-utils/shared-options.js +20 -0
  89. package/src/commands-runner/get-command-projects.js +17 -2
  90. package/src/config/nx-json.d.ts +153 -15
  91. package/src/config/project-graph.d.ts +4 -2
  92. package/src/config/project-graph.js +8 -0
  93. package/src/config/task-graph.d.ts +5 -0
  94. package/src/config/workspace-json-project-json.d.ts +6 -2
  95. package/src/core/graph/main.js +1 -1
  96. package/src/core/graph/runtime.js +1 -1
  97. package/src/core/graph/styles.css +2 -2
  98. package/src/core/graph/styles.js +1 -1
  99. package/src/daemon/client/client.d.ts +2 -0
  100. package/src/daemon/client/client.js +15 -0
  101. package/src/daemon/message-types/glob.d.ts +7 -0
  102. package/src/daemon/message-types/glob.js +9 -1
  103. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  104. package/src/daemon/message-types/hash-glob.js +9 -1
  105. package/src/daemon/server/handle-glob.d.ts +1 -0
  106. package/src/daemon/server/handle-glob.js +8 -0
  107. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  108. package/src/daemon/server/handle-hash-glob.js +8 -0
  109. package/src/daemon/server/logger.js +2 -1
  110. package/src/daemon/server/server.js +7 -0
  111. package/src/devkit-internals.d.ts +2 -1
  112. package/src/devkit-internals.js +4 -1
  113. package/src/executors/run-commands/run-commands.impl.d.ts +18 -17
  114. package/src/executors/run-commands/run-commands.impl.js +25 -292
  115. package/src/executors/run-commands/running-tasks.d.ts +40 -0
  116. package/src/executors/run-commands/running-tasks.js +386 -0
  117. package/src/executors/run-script/run-script.impl.js +4 -3
  118. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
  119. package/src/generators/testing-utils/create-tree.js +5 -1
  120. package/src/native/index.d.ts +94 -19
  121. package/src/native/index.js +16 -2
  122. package/src/native/native-bindings.js +6 -0
  123. package/src/native/nx.wasi-browser.js +20 -19
  124. package/src/native/nx.wasi.cjs +20 -19
  125. package/src/native/nx.wasm32-wasi.wasm +0 -0
  126. package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
  127. package/src/plugins/js/lock-file/lock-file.js +28 -13
  128. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  129. package/src/plugins/js/lock-file/utils/package-json.js +2 -1
  130. package/src/plugins/js/lock-file/yarn-parser.js +85 -39
  131. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  132. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  133. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  134. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  135. package/src/plugins/js/utils/packages.js +22 -3
  136. package/src/plugins/js/utils/register.js +1 -0
  137. package/src/plugins/js/utils/typescript.js +3 -3
  138. package/src/plugins/package-json/create-nodes.d.ts +1 -1
  139. package/src/plugins/package-json/create-nodes.js +3 -1
  140. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  141. package/src/project-graph/error-types.js +32 -2
  142. package/src/project-graph/nx-deps-cache.js +7 -2
  143. package/src/project-graph/plugins/get-plugins.js +2 -1
  144. package/src/project-graph/plugins/in-process-loader.js +1 -1
  145. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  146. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  147. package/src/project-graph/plugins/loaded-nx-plugin.js +3 -7
  148. package/src/project-graph/plugins/utils.d.ts +2 -2
  149. package/src/project-graph/plugins/utils.js +2 -2
  150. package/src/project-graph/project-graph.js +5 -2
  151. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  152. package/src/project-graph/utils/project-configuration-utils.js +25 -11
  153. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  154. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  155. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  156. package/src/tasks-runner/batch/run-batch.js +2 -3
  157. package/src/tasks-runner/cache.d.ts +20 -6
  158. package/src/tasks-runner/cache.js +104 -20
  159. package/src/tasks-runner/create-task-graph.d.ts +4 -1
  160. package/src/tasks-runner/create-task-graph.js +48 -16
  161. package/src/tasks-runner/default-tasks-runner.js +4 -13
  162. package/src/tasks-runner/forked-process-task-runner.d.ts +13 -14
  163. package/src/tasks-runner/forked-process-task-runner.js +160 -303
  164. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  165. package/src/tasks-runner/init-tasks-runner.js +59 -2
  166. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  167. package/src/tasks-runner/is-tui-enabled.js +58 -0
  168. package/src/tasks-runner/life-cycle.d.ts +10 -3
  169. package/src/tasks-runner/life-cycle.js +23 -2
  170. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +7 -2
  171. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +6 -1
  172. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +17 -0
  173. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +221 -0
  174. package/src/tasks-runner/pseudo-terminal.d.ts +17 -8
  175. package/src/tasks-runner/pseudo-terminal.js +63 -47
  176. package/src/tasks-runner/run-command.d.ts +1 -0
  177. package/src/tasks-runner/run-command.js +180 -23
  178. package/src/tasks-runner/running-tasks/batch-process.d.ts +14 -0
  179. package/src/tasks-runner/running-tasks/batch-process.js +70 -0
  180. package/src/tasks-runner/running-tasks/node-child-process.d.ts +36 -0
  181. package/src/tasks-runner/running-tasks/node-child-process.js +184 -0
  182. package/src/tasks-runner/running-tasks/noop-child-process.d.ts +15 -0
  183. package/src/tasks-runner/running-tasks/noop-child-process.js +19 -0
  184. package/src/tasks-runner/running-tasks/running-task.d.ts +8 -0
  185. package/src/tasks-runner/running-tasks/running-task.js +6 -0
  186. package/src/tasks-runner/task-env.d.ts +1 -4
  187. package/src/tasks-runner/task-env.js +2 -0
  188. package/src/tasks-runner/task-orchestrator.d.ts +25 -7
  189. package/src/tasks-runner/task-orchestrator.js +237 -95
  190. package/src/tasks-runner/tasks-schedule.js +5 -1
  191. package/src/tasks-runner/utils.d.ts +2 -10
  192. package/src/tasks-runner/utils.js +27 -15
  193. package/src/utils/child-process.d.ts +4 -0
  194. package/src/utils/child-process.js +23 -30
  195. package/src/utils/command-line-utils.d.ts +1 -1
  196. package/src/utils/find-matching-projects.js +2 -2
  197. package/src/utils/handle-errors.js +15 -0
  198. package/src/utils/is-ci.js +4 -1
  199. package/src/utils/is-using-prettier.d.ts +3 -0
  200. package/src/utils/is-using-prettier.js +62 -0
  201. package/src/utils/nx-key.d.ts +7 -0
  202. package/src/utils/nx-key.js +52 -0
  203. package/src/utils/package-manager.js +2 -2
  204. package/src/utils/path.js +1 -1
  205. package/src/utils/require-nx-key.d.ts +1 -0
  206. package/src/utils/require-nx-key.js +22 -0
  207. package/src/utils/workspace-context.d.ts +2 -0
  208. package/src/utils/workspace-context.js +16 -0
  209. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  210. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  211. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  212. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  213. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  214. package/src/utils/powerpack.d.ts +0 -5
  215. package/src/utils/powerpack.js +0 -33
@@ -0,0 +1,386 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeriallyRunningTasks = exports.ParallelRunningTasks = void 0;
4
+ exports.runSingleCommandWithPseudoTerminal = runSingleCommandWithPseudoTerminal;
5
+ const chalk = require("chalk");
6
+ const child_process_1 = require("child_process");
7
+ const npm_run_path_1 = require("npm-run-path");
8
+ const path_1 = require("path");
9
+ const treeKill = require("tree-kill");
10
+ const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
11
+ const task_env_1 = require("../../tasks-runner/task-env");
12
+ const exit_codes_1 = require("../../utils/exit-codes");
13
+ const run_commands_impl_1 = require("./run-commands.impl");
14
+ class ParallelRunningTasks {
15
+ constructor(options, context, tuiEnabled) {
16
+ this.tuiEnabled = tuiEnabled;
17
+ this.exitCallbacks = [];
18
+ this.childProcesses = options.commands.map((commandConfig) => new RunningNodeProcess(commandConfig, options.color, calculateCwd(options.cwd, context), options.env ?? {}, options.readyWhenStatus, options.streamOutput, options.envFile));
19
+ this.readyWhenStatus = options.readyWhenStatus;
20
+ this.streamOutput = options.streamOutput;
21
+ this.run();
22
+ }
23
+ async getResults() {
24
+ return new Promise((res) => {
25
+ this.onExit((code, terminalOutput) => {
26
+ res({ code, terminalOutput });
27
+ });
28
+ });
29
+ }
30
+ onExit(cb) {
31
+ this.exitCallbacks.push(cb);
32
+ }
33
+ send(message) {
34
+ for (const childProcess of this.childProcesses) {
35
+ childProcess.send(message);
36
+ }
37
+ }
38
+ async kill(signal) {
39
+ await Promise.all(this.childProcesses.map(async (p) => {
40
+ try {
41
+ return p.kill();
42
+ }
43
+ catch (e) {
44
+ console.error(`Unable to terminate "${p.command}"\nError:`, e);
45
+ }
46
+ }));
47
+ }
48
+ async run() {
49
+ if (this.readyWhenStatus.length) {
50
+ let { childProcess, result: { code, terminalOutput }, } = await Promise.race(this.childProcesses.map((childProcess) => new Promise((res) => {
51
+ childProcess.onExit((code, terminalOutput) => {
52
+ res({
53
+ childProcess,
54
+ result: { code, terminalOutput },
55
+ });
56
+ });
57
+ })));
58
+ if (code !== 0) {
59
+ const output = `Warning: command "${childProcess.command}" exited with non-zero status code`;
60
+ terminalOutput += output;
61
+ if (this.streamOutput) {
62
+ process.stderr.write(output);
63
+ }
64
+ }
65
+ for (const cb of this.exitCallbacks) {
66
+ cb(code, terminalOutput);
67
+ }
68
+ }
69
+ else {
70
+ const results = await Promise.all(this.childProcesses.map((childProcess) => childProcess.getResults().then((result) => ({
71
+ childProcess,
72
+ result,
73
+ }))));
74
+ let terminalOutput = results
75
+ .map((r) => r.result.terminalOutput)
76
+ .join('\r\n');
77
+ const failed = results.filter((result) => result.result.code !== 0);
78
+ if (failed.length > 0) {
79
+ const output = failed
80
+ .map((failedResult) => `Warning: command "${failedResult.childProcess.command}" exited with non-zero status code`)
81
+ .join('\r\n');
82
+ terminalOutput += output;
83
+ if (this.streamOutput) {
84
+ process.stderr.write(output);
85
+ }
86
+ for (const cb of this.exitCallbacks) {
87
+ cb(1, terminalOutput);
88
+ }
89
+ }
90
+ else {
91
+ for (const cb of this.exitCallbacks) {
92
+ cb(0, terminalOutput);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ exports.ParallelRunningTasks = ParallelRunningTasks;
99
+ class SeriallyRunningTasks {
100
+ constructor(options, context, tuiEnabled) {
101
+ this.tuiEnabled = tuiEnabled;
102
+ this.terminalOutput = '';
103
+ this.currentProcess = null;
104
+ this.exitCallbacks = [];
105
+ this.code = 0;
106
+ this.run(options, context)
107
+ .catch((e) => {
108
+ this.error = e;
109
+ })
110
+ .finally(() => {
111
+ for (const cb of this.exitCallbacks) {
112
+ cb(this.code, this.terminalOutput);
113
+ }
114
+ });
115
+ }
116
+ getResults() {
117
+ return new Promise((res, rej) => {
118
+ this.onExit((code) => {
119
+ if (this.error) {
120
+ rej(this.error);
121
+ }
122
+ else {
123
+ res({ code, terminalOutput: this.terminalOutput });
124
+ }
125
+ });
126
+ });
127
+ }
128
+ onExit(cb) {
129
+ this.exitCallbacks.push(cb);
130
+ }
131
+ send(message) {
132
+ throw new Error('Not implemented');
133
+ }
134
+ kill(signal) {
135
+ return this.currentProcess.kill(signal);
136
+ }
137
+ async run(options, context) {
138
+ for (const c of options.commands) {
139
+ const childProcess = await this.createProcess(c, options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, options.usePty, options.streamOutput, options.tty, options.envFile);
140
+ this.currentProcess = childProcess;
141
+ let { code, terminalOutput } = await childProcess.getResults();
142
+ this.terminalOutput += terminalOutput;
143
+ this.code = code;
144
+ if (code !== 0) {
145
+ const output = `Warning: command "${c.command}" exited with non-zero status code`;
146
+ terminalOutput += output;
147
+ if (options.streamOutput) {
148
+ process.stderr.write(output);
149
+ }
150
+ this.terminalOutput += terminalOutput;
151
+ // Stop running commands
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ async createProcess(commandConfig, color, cwd, env, usePty = true, streamOutput = true, tty, envFile) {
157
+ // The rust runCommand is always a tty, so it will not look nice in parallel and if we need prefixes
158
+ // currently does not work properly in windows
159
+ if (process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
160
+ !commandConfig.prefix &&
161
+ usePty &&
162
+ pseudo_terminal_1.PseudoTerminal.isSupported()) {
163
+ const pseudoTerminal = (0, pseudo_terminal_1.createPseudoTerminal)();
164
+ registerProcessListener(this, pseudoTerminal);
165
+ return createProcessWithPseudoTty(pseudoTerminal, commandConfig, color, cwd, env, streamOutput, tty, envFile);
166
+ }
167
+ return new RunningNodeProcess(commandConfig, color, cwd, env, [], streamOutput, envFile);
168
+ }
169
+ }
170
+ exports.SeriallyRunningTasks = SeriallyRunningTasks;
171
+ class RunningNodeProcess {
172
+ constructor(commandConfig, color, cwd, env, readyWhenStatus, streamOutput = true, envFile) {
173
+ this.readyWhenStatus = readyWhenStatus;
174
+ this.terminalOutput = '';
175
+ this.exitCallbacks = [];
176
+ env = processEnv(color, cwd, env, envFile);
177
+ this.command = commandConfig.command;
178
+ this.terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
179
+ if (streamOutput) {
180
+ process.stdout.write(this.terminalOutput);
181
+ }
182
+ this.childProcess = (0, child_process_1.exec)(commandConfig.command, {
183
+ maxBuffer: run_commands_impl_1.LARGE_BUFFER,
184
+ env,
185
+ cwd,
186
+ windowsHide: false,
187
+ });
188
+ this.addListeners(commandConfig, streamOutput);
189
+ }
190
+ getResults() {
191
+ return new Promise((res) => {
192
+ this.onExit((code, terminalOutput) => {
193
+ res({ code, terminalOutput });
194
+ });
195
+ });
196
+ }
197
+ onExit(cb) {
198
+ this.exitCallbacks.push(cb);
199
+ }
200
+ send(message) {
201
+ this.childProcess.send(message);
202
+ }
203
+ kill(signal) {
204
+ return new Promise((res, rej) => {
205
+ treeKill(this.childProcess.pid, signal, (err) => {
206
+ if (err) {
207
+ rej(err);
208
+ }
209
+ else {
210
+ res();
211
+ }
212
+ });
213
+ });
214
+ }
215
+ addListeners(commandConfig, streamOutput) {
216
+ this.childProcess.stdout.on('data', (data) => {
217
+ const output = addColorAndPrefix(data, commandConfig);
218
+ this.terminalOutput += output;
219
+ if (streamOutput) {
220
+ process.stdout.write(output);
221
+ }
222
+ if (this.readyWhenStatus.length &&
223
+ isReady(this.readyWhenStatus, data.toString())) {
224
+ for (const cb of this.exitCallbacks) {
225
+ cb(0, this.terminalOutput);
226
+ }
227
+ }
228
+ });
229
+ this.childProcess.stderr.on('data', (err) => {
230
+ const output = addColorAndPrefix(err, commandConfig);
231
+ this.terminalOutput += output;
232
+ if (streamOutput) {
233
+ process.stderr.write(output);
234
+ }
235
+ if (this.readyWhenStatus.length &&
236
+ isReady(this.readyWhenStatus, err.toString())) {
237
+ for (const cb of this.exitCallbacks) {
238
+ cb(1, this.terminalOutput);
239
+ }
240
+ }
241
+ });
242
+ this.childProcess.on('error', (err) => {
243
+ const output = addColorAndPrefix(err.toString(), commandConfig);
244
+ this.terminalOutput += output;
245
+ if (streamOutput) {
246
+ process.stderr.write(output);
247
+ }
248
+ for (const cb of this.exitCallbacks) {
249
+ cb(1, this.terminalOutput);
250
+ }
251
+ });
252
+ this.childProcess.on('exit', (code) => {
253
+ if (!this.readyWhenStatus.length || isReady(this.readyWhenStatus)) {
254
+ for (const cb of this.exitCallbacks) {
255
+ cb(code, this.terminalOutput);
256
+ }
257
+ }
258
+ });
259
+ }
260
+ }
261
+ async function runSingleCommandWithPseudoTerminal(normalized, context) {
262
+ const pseudoTerminal = (0, pseudo_terminal_1.createPseudoTerminal)();
263
+ const pseudoTtyProcess = await createProcessWithPseudoTty(pseudoTerminal, normalized.commands[0], normalized.color, calculateCwd(normalized.cwd, context), normalized.env, normalized.streamOutput, pseudoTerminal ? normalized.isTTY : false, normalized.envFile);
264
+ registerProcessListener(pseudoTtyProcess, pseudoTerminal);
265
+ return pseudoTtyProcess;
266
+ }
267
+ async function createProcessWithPseudoTty(pseudoTerminal, commandConfig, color, cwd, env, streamOutput = true, tty, envFile) {
268
+ return pseudoTerminal.runCommand(commandConfig.command, {
269
+ cwd,
270
+ jsEnv: processEnv(color, cwd, env, envFile),
271
+ quiet: !streamOutput,
272
+ tty,
273
+ });
274
+ }
275
+ function addColorAndPrefix(out, config) {
276
+ if (config.prefix) {
277
+ out = out
278
+ .split('\n')
279
+ .map((l) => {
280
+ let prefixText = config.prefix;
281
+ if (config.prefixColor && chalk[config.prefixColor]) {
282
+ prefixText = chalk[config.prefixColor](prefixText);
283
+ }
284
+ prefixText = chalk.bold(prefixText);
285
+ return l.trim().length > 0 ? `${prefixText} ${l}` : l;
286
+ })
287
+ .join('\n');
288
+ }
289
+ if (config.color && chalk[config.color]) {
290
+ out = chalk[config.color](out);
291
+ }
292
+ if (config.bgColor && chalk[config.bgColor]) {
293
+ out = chalk[config.bgColor](out);
294
+ }
295
+ return out;
296
+ }
297
+ function calculateCwd(cwd, context) {
298
+ if (!cwd)
299
+ return context.root;
300
+ if ((0, path_1.isAbsolute)(cwd))
301
+ return cwd;
302
+ return (0, path_1.join)(context.root, cwd);
303
+ }
304
+ /**
305
+ * Env variables are processed in the following order:
306
+ * - env option from executor options
307
+ * - env file from envFile option if provided
308
+ * - local env variables
309
+ */
310
+ function processEnv(color, cwd, envOptionFromExecutor, envFile) {
311
+ let localEnv = (0, npm_run_path_1.env)({ cwd: cwd ?? process.cwd() });
312
+ localEnv = {
313
+ ...process.env,
314
+ ...localEnv,
315
+ };
316
+ if (process.env.NX_LOAD_DOT_ENV_FILES !== 'false' && envFile) {
317
+ loadEnvVarsFile(envFile, localEnv);
318
+ }
319
+ let res = {
320
+ ...localEnv,
321
+ ...envOptionFromExecutor,
322
+ };
323
+ // need to override PATH to make sure we are using the local node_modules
324
+ if (localEnv.PATH)
325
+ res.PATH = localEnv.PATH; // UNIX-like
326
+ if (localEnv.Path)
327
+ res.Path = localEnv.Path; // Windows
328
+ if (color) {
329
+ res.FORCE_COLOR = `${color}`;
330
+ }
331
+ return res;
332
+ }
333
+ function isReady(readyWhenStatus = [], data) {
334
+ if (data) {
335
+ for (const readyWhenElement of readyWhenStatus) {
336
+ if (data.toString().indexOf(readyWhenElement.stringToMatch) > -1) {
337
+ readyWhenElement.found = true;
338
+ break;
339
+ }
340
+ }
341
+ }
342
+ return readyWhenStatus.every((readyWhenElement) => readyWhenElement.found);
343
+ }
344
+ function loadEnvVarsFile(path, env = {}) {
345
+ (0, task_env_1.unloadDotEnvFile)(path, env);
346
+ const result = (0, task_env_1.loadAndExpandDotEnvFile)(path, env);
347
+ if (result.error) {
348
+ throw result.error;
349
+ }
350
+ }
351
+ let registered = false;
352
+ function registerProcessListener(runningTask, pseudoTerminal) {
353
+ if (registered) {
354
+ return;
355
+ }
356
+ registered = true;
357
+ // When the nx process gets a message, it will be sent into the task's process
358
+ process.on('message', (message) => {
359
+ // this.publisher.publish(message.toString());
360
+ if (pseudoTerminal) {
361
+ pseudoTerminal.sendMessageToChildren(message);
362
+ }
363
+ if ('send' in runningTask) {
364
+ runningTask.send(message);
365
+ }
366
+ });
367
+ // Terminate any task processes on exit
368
+ process.on('exit', () => {
369
+ runningTask.kill();
370
+ });
371
+ process.on('SIGINT', () => {
372
+ runningTask.kill('SIGTERM');
373
+ // we exit here because we don't need to write anything to cache.
374
+ process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
375
+ });
376
+ process.on('SIGTERM', () => {
377
+ runningTask.kill('SIGTERM');
378
+ // no exit here because we expect child processes to terminate which
379
+ // will store results to the cache and will terminate this process
380
+ });
381
+ process.on('SIGHUP', () => {
382
+ runningTask.kill('SIGTERM');
383
+ // no exit here because we expect child processes to terminate which
384
+ // will store results to the cache and will terminate this process
385
+ });
386
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
- const path = require("path");
5
- const package_manager_1 = require("../../utils/package-manager");
6
4
  const child_process_1 = require("child_process");
5
+ const path = require("path");
7
6
  const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
7
+ const package_manager_1 = require("../../utils/package-manager");
8
8
  async function default_1(options, context) {
9
9
  const pm = (0, package_manager_1.getPackageManagerCommand)();
10
10
  try {
@@ -39,7 +39,8 @@ function nodeProcess(command, cwd, env) {
39
39
  });
40
40
  }
41
41
  async function ptyProcess(command, cwd, env) {
42
- const terminal = (0, pseudo_terminal_1.getPseudoTerminal)();
42
+ const terminal = (0, pseudo_terminal_1.createPseudoTerminal)();
43
+ await terminal.init();
43
44
  return new Promise((res, rej) => {
44
45
  const cp = terminal.runCommand(command, { cwd, jsEnv: env });
45
46
  cp.onExit((code) => {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatChangedFilesWithPrettierIfAvailable = formatChangedFilesWithPrettierIfAvailable;
4
4
  exports.formatFilesWithPrettierIfAvailable = formatFilesWithPrettierIfAvailable;
5
5
  const path = require("path");
6
+ const is_using_prettier_1 = require("../../utils/is-using-prettier");
6
7
  /**
7
8
  * Formats all the created or updated files using Prettier
8
9
  * @param tree - the file system tree
@@ -19,6 +20,13 @@ async function formatFilesWithPrettierIfAvailable(files, root, options) {
19
20
  let prettier;
20
21
  try {
21
22
  prettier = await Promise.resolve().then(() => require('prettier'));
23
+ /**
24
+ * Even after we discovered prettier in node_modules, we need to be sure that the user is intentionally using prettier
25
+ * before proceeding to format with it.
26
+ */
27
+ if (!(0, is_using_prettier_1.isUsingPrettier)(root)) {
28
+ return results;
29
+ }
22
30
  }
23
31
  catch { }
24
32
  if (!prettier) {
@@ -6,5 +6,9 @@ const tree_1 = require("../tree");
6
6
  * Creates a host for testing.
7
7
  */
8
8
  function createTree() {
9
- return new tree_1.FsTree('/virtual', false);
9
+ const tree = new tree_1.FsTree('/virtual', false);
10
+ // Allow prettier formatting to be applied to the tree for backwards compatibility within v20
11
+ // TODO: Decouple formatFiles and other formatting utilities from prettier to avoid this
12
+ tree.write('.prettierrc', '{}');
13
+ return tree;
10
14
  }
@@ -7,10 +7,27 @@ export declare class ExternalObject<T> {
7
7
  [K: symbol]: T
8
8
  }
9
9
  }
10
+ export declare class AppLifeCycle {
11
+ constructor(tasks: Array<Task>, pinnedTasks: Array<string>, tuiCliArgs: TuiCliArgs, tuiConfig: TuiConfig, titleText: string)
12
+ startCommand(threadCount?: number | undefined | null): void
13
+ scheduleTask(task: Task): void
14
+ startTasks(tasks: Array<Task>, metadata: object): void
15
+ printTaskTerminalOutput(task: Task, status: string, output: string): void
16
+ endTasks(taskResults: Array<TaskResult>, metadata: object): void
17
+ endCommand(): void
18
+ __init(doneCallback: () => any): void
19
+ registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[ParserArc, WriterArc]>): void
20
+ setTaskStatus(taskId: string, status: TaskStatus): void
21
+ registerForcedShutdownCallback(forcedShutdownCallback: () => any): void
22
+ __setCloudMessage(message: string): Promise<void>
23
+ }
24
+
10
25
  export declare class ChildProcess {
26
+ getParserAndWriter(): ExternalObject<[ParserArc, WriterArc]>
11
27
  kill(): void
12
28
  onExit(callback: (message: string) => void): void
13
29
  onOutput(callback: (message: string) => void): void
30
+ cleanup(): void
14
31
  }
15
32
 
16
33
  export declare class FileLock {
@@ -25,7 +42,13 @@ export declare class FileLock {
25
42
  export declare class HashPlanner {
26
43
  constructor(nxJson: NxJson, projectGraph: ExternalObject<ProjectGraph>)
27
44
  getPlans(taskIds: Array<string>, taskGraph: TaskGraph): Record<string, string[]>
28
- getPlansReference(taskIds: Array<string>, taskGraph: TaskGraph): JsExternal
45
+ getPlansReference(taskIds: Array<string>, taskGraph: TaskGraph): ExternalObject<Record<string, Array<HashInstruction>>>
46
+ }
47
+
48
+ export declare class HttpRemoteCache {
49
+ constructor()
50
+ retrieve(hash: string, cacheDirectory: string): Promise<CachedResult | null>
51
+ store(hash: string, cacheDirectory: string, terminalOutput: string, code: number): Promise<boolean>
29
52
  }
30
53
 
31
54
  export declare class ImportResult {
@@ -37,12 +60,13 @@ export declare class ImportResult {
37
60
 
38
61
  export declare class NxCache {
39
62
  cacheDirectory: string
40
- constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<NxDbConnection>, linkTaskDetails?: boolean | undefined | null)
63
+ constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<NxDbConnection>, linkTaskDetails?: boolean | undefined | null, maxCacheSize?: number | undefined | null)
41
64
  get(hash: string): CachedResult | null
42
65
  put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
43
- applyRemoteCacheResults(hash: string, result: CachedResult): void
66
+ applyRemoteCacheResults(hash: string, result: CachedResult, outputs?: Array<string> | undefined | null): void
44
67
  getTaskOutputsPath(hash: string): string
45
- copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): void
68
+ getCacheSize(): number
69
+ copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): number
46
70
  removeOldCacheRecords(): void
47
71
  checkCacheFsInSync(): boolean
48
72
  }
@@ -54,6 +78,13 @@ export declare class NxTaskHistory {
54
78
  getEstimatedTaskTimings(targets: Array<TaskTarget>): Record<string, number>
55
79
  }
56
80
 
81
+ export declare class RunningTasksService {
82
+ constructor(db: ExternalObject<NxDbConnection>)
83
+ getRunningTasks(ids: Array<string>): Array<string>
84
+ addRunningTask(taskId: string): void
85
+ removeRunningTask(taskId: string): void
86
+ }
87
+
57
88
  export declare class RustPseudoTerminal {
58
89
  constructor()
59
90
  runCommand(command: string, commandDir?: string | undefined | null, jsEnv?: Record<string, string> | undefined | null, execArgv?: Array<string> | undefined | null, quiet?: boolean | undefined | null, tty?: boolean | undefined | null): ChildProcess
@@ -93,6 +124,14 @@ export declare class WorkspaceContext {
93
124
  constructor(workspaceRoot: string, cacheDir: string)
94
125
  getWorkspaceFiles(projectRootMap: Record<string, string>): NxWorkspaceFiles
95
126
  glob(globs: Array<string>, exclude?: Array<string> | undefined | null): Array<string>
127
+ /**
128
+ * Performs multiple glob pattern matches against workspace files in parallel
129
+ * @returns An array of arrays, where each inner array contains the file paths
130
+ * that matched the corresponding glob pattern in the input. The outer array maintains the same order
131
+ * as the input globs.
132
+ */
133
+ multiGlob(globs: Array<string>, exclude?: Array<string> | undefined | null): Array<Array<string>>
134
+ hashFilesMatchingGlobs(globGroups: Array<Array<string>>): Array<string>
96
135
  hashFilesMatchingGlob(globs: Array<string>, exclude?: Array<string> | undefined | null): string
97
136
  incrementalUpdate(updatedFiles: Array<string>, deletedFiles: Array<string>): Record<string, string>
98
137
  updateProjectFiles(projectRootMappings: ProjectRootMappings, projectFiles: ExternalObject<ProjectFiles>, globalFiles: ExternalObject<Array<FileData>>, updatedFiles: Record<string, string>, deletedFiles: Array<string>): UpdatedWorkspaceFiles
@@ -102,15 +141,16 @@ export declare class WorkspaceContext {
102
141
 
103
142
  export interface CachedResult {
104
143
  code: number
105
- terminalOutput: string
144
+ terminalOutput?: string
106
145
  outputsPath: string
146
+ size?: number
107
147
  }
108
148
 
109
- export declare export function closeDbConnection(connection: ExternalObject<NxDbConnection>): void
149
+ export declare export declare function closeDbConnection(connection: ExternalObject<NxDbConnection>): void
110
150
 
111
- export declare export function connectToNxDb(cacheDir: string, nxVersion: string, dbName?: string | undefined | null): ExternalObject<NxDbConnection>
151
+ export declare export declare function connectToNxDb(cacheDir: string, nxVersion: string, dbName?: string | undefined | null): ExternalObject<NxDbConnection>
112
152
 
113
- export declare export function copy(src: string, dest: string): void
153
+ export declare export declare function copy(src: string, dest: string): number
114
154
 
115
155
  export interface DepsOutputsInput {
116
156
  dependentTasksOutputFiles: string
@@ -127,7 +167,7 @@ export declare const enum EventType {
127
167
  create = 'create'
128
168
  }
129
169
 
130
- export declare export function expandOutputs(directory: string, entries: Array<string>): Array<string>
170
+ export declare export declare function expandOutputs(directory: string, entries: Array<string>): Array<string>
131
171
 
132
172
  export interface ExternalDependenciesInput {
133
173
  externalDependencies: Array<string>
@@ -153,19 +193,21 @@ export interface FileSetInput {
153
193
  fileset: string
154
194
  }
155
195
 
156
- export declare export function findImports(projectFileMap: Record<string, Array<string>>): Array<ImportResult>
196
+ export declare export declare function findImports(projectFileMap: Record<string, Array<string>>): Array<ImportResult>
197
+
198
+ export declare export declare function getBinaryTarget(): string
157
199
 
158
- export declare export function getBinaryTarget(): string
200
+ export declare export declare function getDefaultMaxCacheSize(cachePath: string): number
159
201
 
160
202
  /**
161
203
  * Expands the given outputs into a list of existing files.
162
204
  * This is used when hashing outputs
163
205
  */
164
- export declare export function getFilesForOutputs(directory: string, entries: Array<string>): Array<string>
206
+ export declare export declare function getFilesForOutputs(directory: string, entries: Array<string>): Array<string>
165
207
 
166
- export declare export function getTransformableOutputs(outputs: Array<string>): Array<string>
208
+ export declare export declare function getTransformableOutputs(outputs: Array<string>): Array<string>
167
209
 
168
- export declare export function hashArray(input: Array<string>): string
210
+ export declare export declare function hashArray(input: Array<string | undefined | null>): string
169
211
 
170
212
  export interface HashDetails {
171
213
  value: string
@@ -183,7 +225,7 @@ export interface HasherOptions {
183
225
  selectivelyHashTsConfig: boolean
184
226
  }
185
227
 
186
- export declare export function hashFile(file: string): string | null
228
+ export declare export declare function hashFile(file: string): string | null
187
229
 
188
230
  export interface InputsInput {
189
231
  input: string
@@ -223,7 +265,9 @@ export interface ProjectGraph {
223
265
  externalNodes: Record<string, ExternalNode>
224
266
  }
225
267
 
226
- export declare export function remove(src: string): void
268
+ export declare export declare function remove(src: string): void
269
+
270
+ export declare export declare function restoreTerminal(): void
227
271
 
228
272
  export interface RuntimeInput {
229
273
  runtime: string
@@ -243,6 +287,9 @@ export interface Task {
243
287
  target: TaskTarget
244
288
  outputs: Array<string>
245
289
  projectRoot?: string
290
+ startTime?: number
291
+ endTime?: number
292
+ continuous?: boolean
246
293
  }
247
294
 
248
295
  export interface TaskGraph {
@@ -251,6 +298,13 @@ export interface TaskGraph {
251
298
  dependencies: Record<string, Array<string>>
252
299
  }
253
300
 
301
+ export interface TaskResult {
302
+ task: Task
303
+ status: string
304
+ code: number
305
+ terminalOutput?: string
306
+ }
307
+
254
308
  export interface TaskRun {
255
309
  hash: string
256
310
  status: string
@@ -259,26 +313,47 @@ export interface TaskRun {
259
313
  end: number
260
314
  }
261
315
 
316
+ export declare const enum TaskStatus {
317
+ Success = 0,
318
+ Failure = 1,
319
+ Skipped = 2,
320
+ LocalCacheKeptExisting = 3,
321
+ LocalCache = 4,
322
+ RemoteCache = 5,
323
+ NotStarted = 6,
324
+ InProgress = 7,
325
+ Shared = 8
326
+ }
327
+
262
328
  export interface TaskTarget {
263
329
  project: string
264
330
  target: string
265
331
  configuration?: string
266
332
  }
267
333
 
268
- export declare export function testOnlyTransferFileMap(projectFiles: Record<string, Array<FileData>>, nonProjectFiles: Array<FileData>): NxWorkspaceFilesExternals
334
+ export declare export declare function testOnlyTransferFileMap(projectFiles: Record<string, Array<FileData>>, nonProjectFiles: Array<FileData>): NxWorkspaceFilesExternals
269
335
 
270
336
  /**
271
337
  * Transfer the project graph from the JS world to the Rust world, so that we can pass the project graph via memory quicker
272
338
  * This wont be needed once the project graph is created in Rust
273
339
  */
274
- export declare export function transferProjectGraph(projectGraph: ProjectGraph): ExternalObject<ProjectGraph>
340
+ export declare export declare function transferProjectGraph(projectGraph: ProjectGraph): ExternalObject<ProjectGraph>
341
+
342
+ export interface TuiCliArgs {
343
+ targets?: string[] | undefined
344
+ tuiAutoExit?: boolean | number | undefined
345
+ }
346
+
347
+ export interface TuiConfig {
348
+ autoExit?: boolean | number | undefined
349
+ }
275
350
 
276
351
  export interface UpdatedWorkspaceFiles {
277
352
  fileMap: FileMap
278
353
  externalReferences: NxWorkspaceFilesExternals
279
354
  }
280
355
 
281
- export declare export function validateOutputs(outputs: Array<string>): void
356
+ export declare export declare function validateOutputs(outputs: Array<string>): void
282
357
 
283
358
  export interface WatchEvent {
284
359
  path: string