nx 21.0.0-beta.1 → 21.0.0-beta.10

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 (240) hide show
  1. package/.eslintrc.json +5 -1
  2. package/migrations.json +5 -35
  3. package/package.json +12 -12
  4. package/release/index.d.ts +1 -1
  5. package/release/index.js +2 -1
  6. package/schemas/nx-schema.json +182 -35
  7. package/schemas/project-schema.json +5 -0
  8. package/src/adapter/compat.d.ts +1 -1
  9. package/src/adapter/compat.js +3 -0
  10. package/src/command-line/add/add.js +6 -16
  11. package/src/command-line/affected/command-object.js +6 -6
  12. package/src/command-line/examples.js +0 -4
  13. package/src/command-line/exec/command-object.js +1 -1
  14. package/src/command-line/generate/generator-utils.js +8 -3
  15. package/src/command-line/import/import.js +1 -1
  16. package/src/command-line/init/command-object.js +18 -6
  17. package/src/command-line/init/configure-plugins.d.ts +6 -7
  18. package/src/command-line/init/configure-plugins.js +52 -38
  19. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  20. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  21. package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
  22. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  23. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  24. package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
  25. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  26. package/src/command-line/init/implementation/react/index.js +32 -185
  27. package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
  28. package/src/command-line/init/implementation/utils.d.ts +6 -2
  29. package/src/command-line/init/implementation/utils.js +110 -45
  30. package/src/command-line/init/init-v1.js +1 -1
  31. package/src/command-line/init/init-v2.d.ts +1 -0
  32. package/src/command-line/init/init-v2.js +70 -39
  33. package/src/command-line/migrate/migrate-ui-api.d.ts +58 -0
  34. package/src/command-line/migrate/migrate-ui-api.js +227 -0
  35. package/src/command-line/migrate/migrate.d.ts +16 -3
  36. package/src/command-line/migrate/migrate.js +113 -83
  37. package/src/command-line/nx-commands.js +19 -5
  38. package/src/command-line/register/command-object.d.ts +6 -0
  39. package/src/command-line/{activate-powerpack → register}/command-object.js +9 -9
  40. package/src/command-line/register/register.d.ts +2 -0
  41. package/src/command-line/register/register.js +9 -0
  42. package/src/command-line/release/changelog.js +18 -15
  43. package/src/command-line/release/command-object.d.ts +8 -0
  44. package/src/command-line/release/command-object.js +9 -0
  45. package/src/command-line/release/config/config.d.ts +8 -7
  46. package/src/command-line/release/config/config.js +139 -45
  47. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  48. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  49. package/src/command-line/release/index.d.ts +4 -0
  50. package/src/command-line/release/index.js +6 -1
  51. package/src/command-line/release/plan-check.js +6 -3
  52. package/src/command-line/release/plan.js +7 -3
  53. package/src/command-line/release/publish.js +7 -3
  54. package/src/command-line/release/release.js +8 -3
  55. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  56. package/src/command-line/release/utils/git.d.ts +3 -2
  57. package/src/command-line/release/utils/git.js +65 -9
  58. package/src/command-line/release/utils/github.js +3 -1
  59. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  60. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  61. package/src/command-line/release/utils/semver.d.ts +8 -0
  62. package/src/command-line/release/utils/semver.js +8 -0
  63. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  64. package/src/command-line/release/utils/shared-legacy.js +2 -0
  65. package/src/command-line/release/utils/shared.d.ts +11 -17
  66. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  67. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  68. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  69. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  70. package/src/command-line/release/version/project-logger.d.ts +8 -0
  71. package/src/command-line/release/version/project-logger.js +45 -0
  72. package/src/command-line/release/version/release-group-processor.d.ts +252 -0
  73. package/src/command-line/release/version/release-group-processor.js +1057 -0
  74. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  75. package/src/command-line/release/version/resolve-current-version.js +241 -0
  76. package/src/command-line/release/version/test-utils.d.ts +93 -0
  77. package/src/command-line/release/version/test-utils.js +415 -0
  78. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  79. package/src/command-line/release/version/topological-sort.js +41 -0
  80. package/src/command-line/release/version/version-actions.d.ts +171 -0
  81. package/src/command-line/release/version/version-actions.js +195 -0
  82. package/src/command-line/release/version-legacy.d.ts +46 -0
  83. package/src/command-line/release/version-legacy.js +453 -0
  84. package/src/command-line/release/version.d.ts +0 -40
  85. package/src/command-line/release/version.js +84 -262
  86. package/src/command-line/repair/repair.js +0 -1
  87. package/src/command-line/report/report.d.ts +7 -3
  88. package/src/command-line/report/report.js +52 -18
  89. package/src/command-line/run/command-object.js +2 -2
  90. package/src/command-line/run/executor-utils.d.ts +6 -1
  91. package/src/command-line/run/executor-utils.js +10 -1
  92. package/src/command-line/run/run.js +2 -2
  93. package/src/command-line/run-many/command-object.js +2 -2
  94. package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
  95. package/src/command-line/yargs-utils/shared-options.js +20 -0
  96. package/src/config/misc-interfaces.d.ts +11 -1
  97. package/src/config/nx-json.d.ts +160 -16
  98. package/src/config/project-graph.d.ts +4 -2
  99. package/src/config/project-graph.js +8 -0
  100. package/src/config/workspace-json-project-json.d.ts +2 -2
  101. package/src/core/graph/main.js +1 -1
  102. package/src/core/graph/runtime.js +1 -1
  103. package/src/core/graph/styles.css +2 -2
  104. package/src/core/graph/styles.js +1 -1
  105. package/src/daemon/client/client.d.ts +2 -0
  106. package/src/daemon/client/client.js +15 -0
  107. package/src/daemon/message-types/glob.d.ts +7 -0
  108. package/src/daemon/message-types/glob.js +9 -1
  109. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  110. package/src/daemon/message-types/hash-glob.js +9 -1
  111. package/src/daemon/server/handle-glob.d.ts +1 -0
  112. package/src/daemon/server/handle-glob.js +8 -0
  113. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  114. package/src/daemon/server/handle-hash-glob.js +8 -0
  115. package/src/daemon/server/logger.js +2 -1
  116. package/src/daemon/server/server.js +7 -0
  117. package/src/devkit-internals.d.ts +3 -2
  118. package/src/devkit-internals.js +5 -1
  119. package/src/executors/run-commands/run-commands.impl.d.ts +2 -5
  120. package/src/executors/run-commands/run-commands.impl.js +14 -42
  121. package/src/executors/run-commands/running-tasks.d.ts +9 -4
  122. package/src/executors/run-commands/running-tasks.js +103 -30
  123. package/src/executors/run-script/run-script.impl.js +4 -3
  124. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
  125. package/src/generators/testing-utils/create-tree.js +5 -1
  126. package/src/migrations/{update-17-0-0/rm-default-collection-npm-scope.d.ts → update-21-0-0/release-version-config-changes.d.ts} +1 -1
  127. package/src/migrations/update-21-0-0/release-version-config-changes.js +111 -0
  128. package/src/native/index.d.ts +98 -19
  129. package/src/native/index.js +16 -2
  130. package/src/native/native-bindings.js +7 -0
  131. package/src/native/nx.wasi-browser.js +20 -19
  132. package/src/native/nx.wasi.cjs +20 -19
  133. package/src/native/nx.wasm32-wasi.wasm +0 -0
  134. package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
  135. package/src/plugins/js/lock-file/lock-file.js +28 -13
  136. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  137. package/src/plugins/js/lock-file/utils/package-json.js +8 -6
  138. package/src/plugins/js/lock-file/utils/pnpm-normalizer.js +3 -3
  139. package/src/plugins/js/lock-file/yarn-parser.js +85 -39
  140. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  141. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  142. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  143. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  144. package/src/plugins/js/utils/packages.js +22 -3
  145. package/src/plugins/js/utils/register.js +1 -0
  146. package/src/plugins/js/utils/typescript.js +3 -3
  147. package/src/plugins/package-json/create-nodes.d.ts +1 -1
  148. package/src/plugins/package-json/create-nodes.js +4 -2
  149. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  150. package/src/project-graph/error-types.js +32 -2
  151. package/src/project-graph/file-utils.d.ts +1 -10
  152. package/src/project-graph/file-utils.js +2 -77
  153. package/src/project-graph/plugins/get-plugins.js +2 -1
  154. package/src/project-graph/plugins/in-process-loader.js +1 -1
  155. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  156. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  157. package/src/project-graph/plugins/public-api.d.ts +1 -1
  158. package/src/project-graph/plugins/utils.d.ts +2 -2
  159. package/src/project-graph/plugins/utils.js +2 -2
  160. package/src/project-graph/project-graph.js +1 -1
  161. package/src/project-graph/utils/project-configuration-utils.d.ts +3 -3
  162. package/src/project-graph/utils/project-configuration-utils.js +54 -21
  163. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  164. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  165. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  166. package/src/tasks-runner/batch/run-batch.js +3 -4
  167. package/src/tasks-runner/cache.d.ts +20 -6
  168. package/src/tasks-runner/cache.js +104 -20
  169. package/src/tasks-runner/create-task-graph.d.ts +0 -1
  170. package/src/tasks-runner/create-task-graph.js +11 -11
  171. package/src/tasks-runner/default-tasks-runner.js +5 -14
  172. package/src/tasks-runner/forked-process-task-runner.d.ts +8 -3
  173. package/src/tasks-runner/forked-process-task-runner.js +59 -46
  174. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  175. package/src/tasks-runner/init-tasks-runner.js +62 -2
  176. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  177. package/src/tasks-runner/is-tui-enabled.js +64 -0
  178. package/src/tasks-runner/life-cycle.d.ts +14 -3
  179. package/src/tasks-runner/life-cycle.js +37 -2
  180. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.d.ts +2 -0
  181. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +15 -7
  182. package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts +5 -0
  183. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +35 -5
  184. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +18 -0
  185. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +229 -0
  186. package/src/tasks-runner/pseudo-terminal.d.ts +10 -7
  187. package/src/tasks-runner/pseudo-terminal.js +37 -35
  188. package/src/tasks-runner/run-command.d.ts +4 -1
  189. package/src/tasks-runner/run-command.js +220 -42
  190. package/src/tasks-runner/running-tasks/node-child-process.js +4 -11
  191. package/src/tasks-runner/running-tasks/running-task.d.ts +3 -0
  192. package/src/tasks-runner/running-tasks/shared-running-task.d.ts +14 -0
  193. package/src/tasks-runner/running-tasks/shared-running-task.js +30 -0
  194. package/src/tasks-runner/task-env.d.ts +1 -4
  195. package/src/tasks-runner/task-env.js +2 -0
  196. package/src/tasks-runner/task-orchestrator.d.ts +26 -10
  197. package/src/tasks-runner/task-orchestrator.js +212 -57
  198. package/src/tasks-runner/tasks-runner.d.ts +1 -0
  199. package/src/tasks-runner/tasks-schedule.d.ts +1 -0
  200. package/src/tasks-runner/tasks-schedule.js +9 -0
  201. package/src/tasks-runner/utils.d.ts +2 -2
  202. package/src/tasks-runner/utils.js +18 -12
  203. package/src/utils/child-process.d.ts +4 -0
  204. package/src/utils/child-process.js +23 -30
  205. package/src/utils/command-line-utils.d.ts +1 -1
  206. package/src/utils/find-matching-projects.js +2 -2
  207. package/src/utils/git-utils.d.ts +1 -1
  208. package/src/utils/git-utils.js +8 -3
  209. package/src/utils/handle-errors.js +15 -0
  210. package/src/utils/is-ci.js +4 -1
  211. package/src/utils/is-using-prettier.d.ts +3 -0
  212. package/src/utils/is-using-prettier.js +62 -0
  213. package/src/utils/nx-key.d.ts +7 -0
  214. package/src/utils/nx-key.js +52 -0
  215. package/src/utils/package-json.d.ts +1 -1
  216. package/src/utils/package-json.js +16 -2
  217. package/src/utils/package-manager.js +2 -2
  218. package/src/utils/path.js +1 -1
  219. package/src/utils/require-nx-key.d.ts +1 -0
  220. package/src/utils/require-nx-key.js +22 -0
  221. package/src/utils/workspace-context.d.ts +2 -0
  222. package/src/utils/workspace-context.js +16 -0
  223. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  224. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  225. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  226. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  227. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  228. package/src/migrations/update-17-0-0/move-cache-directory.d.ts +0 -2
  229. package/src/migrations/update-17-0-0/move-cache-directory.js +0 -35
  230. package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +0 -72
  231. package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.d.ts +0 -2
  232. package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +0 -122
  233. package/src/migrations/update-17-2-0/move-default-base.d.ts +0 -5
  234. package/src/migrations/update-17-2-0/move-default-base.js +0 -21
  235. package/src/migrations/update-17-3-0/nx-release-path.d.ts +0 -3
  236. package/src/migrations/update-17-3-0/nx-release-path.js +0 -47
  237. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +0 -2
  238. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +0 -11
  239. package/src/utils/powerpack.d.ts +0 -5
  240. package/src/utils/powerpack.js +0 -33
@@ -1,38 +1,43 @@
1
1
  import { Serializable } from 'child_process';
2
- import { RunningTask } from '../../tasks-runner/running-tasks/running-task';
3
2
  import { ExecutorContext } from '../../config/misc-interfaces';
3
+ import { PseudoTtyProcess } from '../../tasks-runner/pseudo-terminal';
4
+ import { RunningTask } from '../../tasks-runner/running-tasks/running-task';
4
5
  import { NormalizedRunCommandsOptions } from './run-commands.impl';
5
- import { PseudoTerminal } from '../../tasks-runner/pseudo-terminal';
6
6
  export declare class ParallelRunningTasks implements RunningTask {
7
7
  private readonly childProcesses;
8
8
  private readyWhenStatus;
9
9
  private readonly streamOutput;
10
10
  private exitCallbacks;
11
+ private outputCallbacks;
11
12
  constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext);
12
13
  getResults(): Promise<{
13
14
  code: number;
14
15
  terminalOutput: string;
15
16
  }>;
17
+ onOutput(cb: (terminalOutput: string) => void): void;
16
18
  onExit(cb: (code: number, terminalOutput: string) => void): void;
17
19
  send(message: Serializable): void;
18
20
  kill(signal?: NodeJS.Signals | number): Promise<void>;
19
21
  private run;
20
22
  }
21
23
  export declare class SeriallyRunningTasks implements RunningTask {
22
- private pseudoTerminal?;
24
+ private readonly tuiEnabled;
23
25
  private terminalOutput;
24
26
  private currentProcess;
25
27
  private exitCallbacks;
26
28
  private code;
27
29
  private error;
28
- constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext, pseudoTerminal?: PseudoTerminal);
30
+ private outputCallbacks;
31
+ constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext, tuiEnabled: boolean);
29
32
  getResults(): Promise<{
30
33
  code: number;
31
34
  terminalOutput: string;
32
35
  }>;
33
36
  onExit(cb: (code: number, terminalOutput: string) => void): void;
37
+ onOutput(cb: (terminalOutput: string) => void): void;
34
38
  send(message: Serializable): void;
35
39
  kill(signal?: NodeJS.Signals | number): void | Promise<void>;
36
40
  private run;
37
41
  private createProcess;
38
42
  }
43
+ export declare function runSingleCommandWithPseudoTerminal(normalized: NormalizedRunCommandsOptions, context: ExecutorContext): Promise<PseudoTtyProcess>;
@@ -1,16 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SeriallyRunningTasks = exports.ParallelRunningTasks = void 0;
4
- const child_process_1 = require("child_process");
5
- const run_commands_impl_1 = require("./run-commands.impl");
6
- const path_1 = require("path");
4
+ exports.runSingleCommandWithPseudoTerminal = runSingleCommandWithPseudoTerminal;
7
5
  const chalk = require("chalk");
6
+ const child_process_1 = require("child_process");
8
7
  const npm_run_path_1 = require("npm-run-path");
9
- const task_env_1 = require("../../tasks-runner/task-env");
8
+ const path_1 = require("path");
10
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");
11
14
  class ParallelRunningTasks {
12
15
  constructor(options, context) {
13
16
  this.exitCallbacks = [];
17
+ this.outputCallbacks = [];
14
18
  this.childProcesses = options.commands.map((commandConfig) => new RunningNodeProcess(commandConfig, options.color, calculateCwd(options.cwd, context), options.env ?? {}, options.readyWhenStatus, options.streamOutput, options.envFile));
15
19
  this.readyWhenStatus = options.readyWhenStatus;
16
20
  this.streamOutput = options.streamOutput;
@@ -23,6 +27,9 @@ class ParallelRunningTasks {
23
27
  });
24
28
  });
25
29
  }
30
+ onOutput(cb) {
31
+ this.outputCallbacks.push(cb);
32
+ }
26
33
  onExit(cb) {
27
34
  this.exitCallbacks.push(cb);
28
35
  }
@@ -44,6 +51,11 @@ class ParallelRunningTasks {
44
51
  async run() {
45
52
  if (this.readyWhenStatus.length) {
46
53
  let { childProcess, result: { code, terminalOutput }, } = await Promise.race(this.childProcesses.map((childProcess) => new Promise((res) => {
54
+ childProcess.onOutput((terminalOutput) => {
55
+ for (const cb of this.outputCallbacks) {
56
+ cb(terminalOutput);
57
+ }
58
+ });
47
59
  childProcess.onExit((code, terminalOutput) => {
48
60
  res({
49
61
  childProcess,
@@ -63,10 +75,18 @@ class ParallelRunningTasks {
63
75
  }
64
76
  }
65
77
  else {
66
- const results = await Promise.all(this.childProcesses.map((childProcess) => childProcess.getResults().then((result) => ({
67
- childProcess,
68
- result,
69
- }))));
78
+ const results = await Promise.all(this.childProcesses.map(async (childProcess) => {
79
+ childProcess.onOutput((terminalOutput) => {
80
+ for (const cb of this.outputCallbacks) {
81
+ cb(terminalOutput);
82
+ }
83
+ });
84
+ const result = await childProcess.getResults();
85
+ return {
86
+ childProcess,
87
+ result,
88
+ };
89
+ }));
70
90
  let terminalOutput = results
71
91
  .map((r) => r.result.terminalOutput)
72
92
  .join('\r\n');
@@ -93,12 +113,13 @@ class ParallelRunningTasks {
93
113
  }
94
114
  exports.ParallelRunningTasks = ParallelRunningTasks;
95
115
  class SeriallyRunningTasks {
96
- constructor(options, context, pseudoTerminal) {
97
- this.pseudoTerminal = pseudoTerminal;
116
+ constructor(options, context, tuiEnabled) {
117
+ this.tuiEnabled = tuiEnabled;
98
118
  this.terminalOutput = '';
99
119
  this.currentProcess = null;
100
120
  this.exitCallbacks = [];
101
121
  this.code = 0;
122
+ this.outputCallbacks = [];
102
123
  this.run(options, context)
103
124
  .catch((e) => {
104
125
  this.error = e;
@@ -124,6 +145,9 @@ class SeriallyRunningTasks {
124
145
  onExit(cb) {
125
146
  this.exitCallbacks.push(cb);
126
147
  }
148
+ onOutput(cb) {
149
+ this.outputCallbacks.push(cb);
150
+ }
127
151
  send(message) {
128
152
  throw new Error('Not implemented');
129
153
  }
@@ -132,8 +156,13 @@ class SeriallyRunningTasks {
132
156
  }
133
157
  async run(options, context) {
134
158
  for (const c of options.commands) {
135
- const childProcess = await this.createProcess(c, [], options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, false, options.usePty, options.streamOutput, options.tty, options.envFile);
159
+ const childProcess = await this.createProcess(c, options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, options.usePty, options.streamOutput, options.tty, options.envFile);
136
160
  this.currentProcess = childProcess;
161
+ childProcess.onOutput((output) => {
162
+ for (const cb of this.outputCallbacks) {
163
+ cb(output);
164
+ }
165
+ });
137
166
  let { code, terminalOutput } = await childProcess.getResults();
138
167
  this.terminalOutput += terminalOutput;
139
168
  this.code = code;
@@ -149,18 +178,18 @@ class SeriallyRunningTasks {
149
178
  }
150
179
  }
151
180
  }
152
- async createProcess(commandConfig, readyWhenStatus = [], color, cwd, env, isParallel, usePty = true, streamOutput = true, tty, envFile) {
181
+ async createProcess(commandConfig, color, cwd, env, usePty = true, streamOutput = true, tty, envFile) {
153
182
  // The rust runCommand is always a tty, so it will not look nice in parallel and if we need prefixes
154
183
  // currently does not work properly in windows
155
- if (this.pseudoTerminal &&
156
- process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
184
+ if (process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
157
185
  !commandConfig.prefix &&
158
- readyWhenStatus.length === 0 &&
159
- !isParallel &&
160
- usePty) {
161
- return createProcessWithPseudoTty(this.pseudoTerminal, commandConfig, color, cwd, env, streamOutput, tty, envFile);
186
+ usePty &&
187
+ pseudo_terminal_1.PseudoTerminal.isSupported()) {
188
+ const pseudoTerminal = (0, pseudo_terminal_1.createPseudoTerminal)();
189
+ registerProcessListener(this, pseudoTerminal);
190
+ return createProcessWithPseudoTty(pseudoTerminal, commandConfig, color, cwd, env, streamOutput, tty, envFile);
162
191
  }
163
- return new RunningNodeProcess(commandConfig, color, cwd, env, readyWhenStatus, streamOutput, envFile);
192
+ return new RunningNodeProcess(commandConfig, color, cwd, env, [], streamOutput, envFile);
164
193
  }
165
194
  }
166
195
  exports.SeriallyRunningTasks = SeriallyRunningTasks;
@@ -169,6 +198,7 @@ class RunningNodeProcess {
169
198
  this.readyWhenStatus = readyWhenStatus;
170
199
  this.terminalOutput = '';
171
200
  this.exitCallbacks = [];
201
+ this.outputCallbacks = [];
172
202
  env = processEnv(color, cwd, env, envFile);
173
203
  this.command = commandConfig.command;
174
204
  this.terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
@@ -190,6 +220,9 @@ class RunningNodeProcess {
190
220
  });
191
221
  });
192
222
  }
223
+ onOutput(cb) {
224
+ this.outputCallbacks.push(cb);
225
+ }
193
226
  onExit(cb) {
194
227
  this.exitCallbacks.push(cb);
195
228
  }
@@ -208,10 +241,16 @@ class RunningNodeProcess {
208
241
  });
209
242
  });
210
243
  }
244
+ triggerOutputListeners(output) {
245
+ for (const cb of this.outputCallbacks) {
246
+ cb(output);
247
+ }
248
+ }
211
249
  addListeners(commandConfig, streamOutput) {
212
250
  this.childProcess.stdout.on('data', (data) => {
213
251
  const output = addColorAndPrefix(data, commandConfig);
214
252
  this.terminalOutput += output;
253
+ this.triggerOutputListeners(output);
215
254
  if (streamOutput) {
216
255
  process.stdout.write(output);
217
256
  }
@@ -225,6 +264,7 @@ class RunningNodeProcess {
225
264
  this.childProcess.stderr.on('data', (err) => {
226
265
  const output = addColorAndPrefix(err, commandConfig);
227
266
  this.terminalOutput += output;
267
+ this.triggerOutputListeners(output);
228
268
  if (streamOutput) {
229
269
  process.stderr.write(output);
230
270
  }
@@ -254,22 +294,19 @@ class RunningNodeProcess {
254
294
  });
255
295
  }
256
296
  }
297
+ async function runSingleCommandWithPseudoTerminal(normalized, context) {
298
+ const pseudoTerminal = (0, pseudo_terminal_1.createPseudoTerminal)();
299
+ const pseudoTtyProcess = await createProcessWithPseudoTty(pseudoTerminal, normalized.commands[0], normalized.color, calculateCwd(normalized.cwd, context), normalized.env, normalized.streamOutput, pseudoTerminal ? normalized.isTTY : false, normalized.envFile);
300
+ registerProcessListener(pseudoTtyProcess, pseudoTerminal);
301
+ return pseudoTtyProcess;
302
+ }
257
303
  async function createProcessWithPseudoTty(pseudoTerminal, commandConfig, color, cwd, env, streamOutput = true, tty, envFile) {
258
- let terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
259
- if (streamOutput) {
260
- process.stdout.write(terminalOutput);
261
- }
262
- env = processEnv(color, cwd, env, envFile);
263
- const childProcess = pseudoTerminal.runCommand(commandConfig.command, {
304
+ return pseudoTerminal.runCommand(commandConfig.command, {
264
305
  cwd,
265
- jsEnv: env,
306
+ jsEnv: processEnv(color, cwd, env, envFile),
266
307
  quiet: !streamOutput,
267
308
  tty,
268
309
  });
269
- childProcess.onOutput((output) => {
270
- terminalOutput += output;
271
- });
272
- return childProcess;
273
310
  }
274
311
  function addColorAndPrefix(out, config) {
275
312
  if (config.prefix) {
@@ -347,3 +384,39 @@ function loadEnvVarsFile(path, env = {}) {
347
384
  throw result.error;
348
385
  }
349
386
  }
387
+ let registered = false;
388
+ function registerProcessListener(runningTask, pseudoTerminal) {
389
+ if (registered) {
390
+ return;
391
+ }
392
+ registered = true;
393
+ // When the nx process gets a message, it will be sent into the task's process
394
+ process.on('message', (message) => {
395
+ // this.publisher.publish(message.toString());
396
+ if (pseudoTerminal) {
397
+ pseudoTerminal.sendMessageToChildren(message);
398
+ }
399
+ if ('send' in runningTask) {
400
+ runningTask.send(message);
401
+ }
402
+ });
403
+ // Terminate any task processes on exit
404
+ process.on('exit', () => {
405
+ runningTask.kill();
406
+ });
407
+ process.on('SIGINT', () => {
408
+ runningTask.kill('SIGTERM');
409
+ // we exit here because we don't need to write anything to cache.
410
+ process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
411
+ });
412
+ process.on('SIGTERM', () => {
413
+ runningTask.kill('SIGTERM');
414
+ // no exit here because we expect child processes to terminate which
415
+ // will store results to the cache and will terminate this process
416
+ });
417
+ process.on('SIGHUP', () => {
418
+ runningTask.kill('SIGTERM');
419
+ // no exit here because we expect child processes to terminate which
420
+ // will store results to the cache and will terminate this process
421
+ });
422
+ }
@@ -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
  }
@@ -1,2 +1,2 @@
1
- import { Tree } from '../../generators/tree';
1
+ import type { Tree } from '../../generators/tree';
2
2
  export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const node_path_1 = require("node:path");
5
+ const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
6
+ const json_1 = require("../../generators/utils/json");
7
+ const nx_json_1 = require("../../generators/utils/nx-json");
8
+ const project_configuration_1 = require("../../generators/utils/project-configuration");
9
+ async function update(tree) {
10
+ const nxJson = (0, nx_json_1.readNxJson)(tree);
11
+ if (!nxJson) {
12
+ return;
13
+ }
14
+ // If the user has explicitly set the useLegacyVersioning property to true, do nothing
15
+ if (nxJson.release?.version?.useLegacyVersioning === true) {
16
+ return;
17
+ }
18
+ function updateProperties(versionConfig) {
19
+ // If the user is using a generator other than the @nx/js one, set useLegacyVersioning to true and nothing else
20
+ if ('generator' in versionConfig &&
21
+ versionConfig.generator !== '@nx/js:release-version') {
22
+ versionConfig.useLegacyVersioning =
23
+ true;
24
+ return;
25
+ }
26
+ // These options used to live inside of generatorOptions, but are now like for like top-level nx core options
27
+ const coreOptionsToPromoteToTopLevel = [
28
+ 'specifierSource',
29
+ 'currentVersionResolver',
30
+ 'currentVersionResolverMetadata',
31
+ 'fallbackCurrentVersionResolver',
32
+ 'versionPrefix',
33
+ 'updateDependents',
34
+ 'logUnchangedProjects',
35
+ ];
36
+ if ('generatorOptions' in versionConfig) {
37
+ for (const option of coreOptionsToPromoteToTopLevel) {
38
+ if (versionConfig.generatorOptions[option]) {
39
+ versionConfig[option] = versionConfig.generatorOptions[option];
40
+ }
41
+ }
42
+ // preserveLocalDependencyProtocols has changed to true by default, so remove it if explicitly true, otherwise set to false explicitly
43
+ if (versionConfig.generatorOptions.preserveLocalDependencyProtocols) {
44
+ delete versionConfig.generatorOptions.preserveLocalDependencyProtocols;
45
+ }
46
+ else {
47
+ versionConfig.preserveLocalDependencyProtocols = false;
48
+ }
49
+ // packageRoot has been replaced by manifestRootsToUpdate
50
+ if (typeof versionConfig.generatorOptions.packageRoot === 'string') {
51
+ versionConfig.manifestRootsToUpdate =
52
+ [versionConfig.generatorOptions.packageRoot];
53
+ delete versionConfig.generatorOptions.packageRoot;
54
+ }
55
+ // These options have been moved to versionActionsOptions
56
+ const versionActionsOptions = [
57
+ 'skipLockFileUpdate',
58
+ 'installArgs',
59
+ 'installIgnoreScripts',
60
+ ];
61
+ for (const option of versionActionsOptions) {
62
+ if (versionConfig.generatorOptions[option]) {
63
+ versionConfig.versionActionsOptions =
64
+ versionConfig
65
+ .versionActionsOptions || {};
66
+ versionConfig.versionActionsOptions[option] =
67
+ versionConfig.generatorOptions[option];
68
+ delete versionConfig.generatorOptions[option];
69
+ }
70
+ }
71
+ delete versionConfig.generatorOptions;
72
+ }
73
+ }
74
+ // nx.json
75
+ if (nxJson.release) {
76
+ // Top level version config
77
+ if (nxJson.release.version) {
78
+ updateProperties(nxJson.release.version);
79
+ }
80
+ // Version config for each group
81
+ if (nxJson.release.groups) {
82
+ for (const group of Object.values(nxJson.release.groups)) {
83
+ if (group.version) {
84
+ updateProperties(group.version);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ // project.json or package.json
90
+ const projects = (0, project_configuration_1.getProjects)(tree);
91
+ for (const project of projects.values()) {
92
+ const projectJsonPath = (0, node_path_1.join)(project.root, 'project.json');
93
+ if (tree.exists(projectJsonPath)) {
94
+ const projectJson = (0, json_1.readJson)(tree, projectJsonPath);
95
+ if (projectJson.release?.version) {
96
+ updateProperties(projectJson.release.version);
97
+ (0, json_1.writeJson)(tree, projectJsonPath, projectJson);
98
+ }
99
+ }
100
+ const packageJsonPath = (0, node_path_1.join)(project.root, 'package.json');
101
+ if (tree.exists(packageJsonPath)) {
102
+ const packageJson = (0, json_1.readJson)(tree, packageJsonPath);
103
+ if (packageJson.nx?.release?.version) {
104
+ updateProperties(packageJson.nx.release.version);
105
+ (0, json_1.writeJson)(tree, packageJsonPath, packageJson);
106
+ }
107
+ }
108
+ }
109
+ (0, nx_json_1.updateNxJson)(tree, nxJson);
110
+ await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
111
+ }