nx 23.2.0-beta.7 → 23.2.0-beta.9

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 (188) hide show
  1. package/dist/bin/init-local.js +3 -5
  2. package/dist/release/changelog-renderer/index.js +4 -5
  3. package/dist/src/adapter/ngcli-adapter.js +60 -1
  4. package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +2 -2
  5. package/dist/src/command-line/completion/command-object.js +7 -12
  6. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +17 -23
  7. package/dist/src/command-line/format/format.js +84 -101
  8. package/dist/src/command-line/generate/generate.js +35 -35
  9. package/dist/src/command-line/import/import.js +30 -40
  10. package/dist/src/command-line/init/ai-agent-prompts.js +5 -11
  11. package/dist/src/command-line/init/command-object.js +4 -2
  12. package/dist/src/command-line/init/configure-plugins.js +4 -1
  13. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +12 -32
  14. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +17 -21
  15. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +8 -21
  16. package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +3 -17
  17. package/dist/src/command-line/init/implementation/angular/index.js +10 -15
  18. package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +2 -0
  19. package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +8 -2
  20. package/dist/src/command-line/init/implementation/check-compatible-with-plugins.js +2 -0
  21. package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +5 -0
  22. package/dist/src/command-line/init/implementation/format.d.ts +18 -0
  23. package/dist/src/command-line/init/implementation/format.js +114 -0
  24. package/dist/src/command-line/init/implementation/utils.js +8 -0
  25. package/dist/src/command-line/init/init-v1.js +15 -18
  26. package/dist/src/command-line/init/init-v2.js +37 -56
  27. package/dist/src/command-line/migrate/agentic/definitions.js +35 -8
  28. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +22 -3
  29. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +13 -10
  30. package/dist/src/command-line/migrate/agentic/handoff.d.ts +3 -1
  31. package/dist/src/command-line/migrate/agentic/handoff.js +4 -2
  32. package/dist/src/command-line/migrate/agentic/run-step.js +1 -0
  33. package/dist/src/command-line/migrate/agentic/runner.js +24 -24
  34. package/dist/src/command-line/migrate/agentic/select.js +20 -30
  35. package/dist/src/command-line/migrate/agentic/types.d.ts +19 -3
  36. package/dist/src/command-line/migrate/agentic/types.js +13 -4
  37. package/dist/src/command-line/migrate/command-object.d.ts +3 -0
  38. package/dist/src/command-line/migrate/command-object.js +13 -0
  39. package/dist/src/command-line/migrate/execute-migration.d.ts +14 -0
  40. package/dist/src/command-line/migrate/execute-migration.js +30 -9
  41. package/dist/src/command-line/migrate/migrate-analytics.d.ts +28 -0
  42. package/dist/src/command-line/migrate/migrate-analytics.js +51 -1
  43. package/dist/src/command-line/migrate/migrate-commits.d.ts +8 -2
  44. package/dist/src/command-line/migrate/migrate-commits.js +66 -19
  45. package/dist/src/command-line/migrate/migrate-config.d.ts +4 -2
  46. package/dist/src/command-line/migrate/migrate-config.js +12 -4
  47. package/dist/src/command-line/migrate/migrate.d.ts +13 -2
  48. package/dist/src/command-line/migrate/migrate.js +243 -80
  49. package/dist/src/command-line/migrate/multi-major.js +7 -10
  50. package/dist/src/command-line/migrate/resolve-package-version.js +4 -8
  51. package/dist/src/command-line/migrate/run/agent-output.d.ts +20 -0
  52. package/dist/src/command-line/migrate/run/agent-output.js +65 -0
  53. package/dist/src/command-line/migrate/run/index.d.ts +7 -0
  54. package/dist/src/command-line/migrate/run/index.js +19 -1
  55. package/dist/src/command-line/migrate/run/orchestrator.d.ts +20 -0
  56. package/dist/src/command-line/migrate/run/orchestrator.js +1200 -0
  57. package/dist/src/command-line/migrate/run/run-id.d.ts +16 -0
  58. package/dist/src/command-line/migrate/run/run-id.js +56 -0
  59. package/dist/src/command-line/migrate/run/run-state.d.ts +157 -0
  60. package/dist/src/command-line/migrate/run/run-state.js +438 -0
  61. package/dist/src/command-line/migrate/run/state-lock.d.ts +25 -0
  62. package/dist/src/command-line/migrate/run/state-lock.js +76 -0
  63. package/dist/src/command-line/migrate/run/state-machine.d.ts +84 -0
  64. package/dist/src/command-line/migrate/run/state-machine.js +315 -0
  65. package/dist/src/command-line/migrate/run/util.d.ts +58 -0
  66. package/dist/src/command-line/migrate/run/util.js +139 -7
  67. package/dist/src/command-line/migrate/run/worker.d.ts +1 -0
  68. package/dist/src/command-line/migrate/run/worker.js +308 -45
  69. package/dist/src/command-line/migrate/safe-prompt.d.ts +14 -26
  70. package/dist/src/command-line/migrate/safe-prompt.js +32 -43
  71. package/dist/src/command-line/migrate/step-actions.d.ts +5 -0
  72. package/dist/src/command-line/migrate/step-actions.js +12 -0
  73. package/dist/src/command-line/migrate/text.d.ts +18 -0
  74. package/dist/src/command-line/migrate/text.js +26 -0
  75. package/dist/src/command-line/migrate/version-skew-guard.d.ts +6 -4
  76. package/dist/src/command-line/migrate/version-skew-guard.js +34 -14
  77. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +16 -20
  78. package/dist/src/command-line/release/changelog.js +6 -17
  79. package/dist/src/command-line/release/plan.js +15 -28
  80. package/dist/src/command-line/release/release.js +6 -17
  81. package/dist/src/command-line/release/utils/remote-release-clients/github.js +16 -22
  82. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +13 -22
  83. package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
  84. package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
  85. package/dist/src/command-line/release/version.js +2 -2
  86. package/dist/src/core/graph/main.js +1 -1
  87. package/dist/src/daemon/client/client.js +11 -2
  88. package/dist/src/devkit-internals.d.ts +7 -2
  89. package/dist/src/devkit-internals.js +22 -6
  90. package/dist/src/generators/internal-utils/{format-changed-files-with-prettier-if-available.d.ts → format-changed-files.d.ts} +6 -6
  91. package/dist/src/generators/internal-utils/format-changed-files.js +163 -0
  92. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.d.ts +15 -0
  93. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.js +21 -3
  94. package/dist/src/migrations/update-15-0-0/prefix-outputs.js +2 -2
  95. package/dist/src/migrations/update-16-0-0/remove-nrwl-cli.js +2 -2
  96. package/dist/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +2 -2
  97. package/dist/src/migrations/update-16-0-0/update-nx-cloud-runner.js +2 -2
  98. package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +2 -2
  99. package/dist/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +2 -2
  100. package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +2 -2
  101. package/dist/src/migrations/update-17-2-0/move-default-base.js +2 -2
  102. package/dist/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +2 -2
  103. package/dist/src/migrations/update-19-2-4/set-project-name.js +2 -2
  104. package/dist/src/migrations/update-20-0-0/move-use-daemon-process.js +2 -2
  105. package/dist/src/migrations/update-20-0-1/use-legacy-cache.js +2 -2
  106. package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.js +2 -2
  107. package/dist/src/migrations/update-21-0-0/release-version-config-changes.js +2 -2
  108. package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.js +2 -2
  109. package/dist/src/migrations/update-21-0-0/remove-legacy-cache.js +2 -2
  110. package/dist/src/migrations/update-22-0-0/consolidate-release-tag-config.js +2 -2
  111. package/dist/src/migrations/update-22-0-0/release-version-config-changes.js +2 -2
  112. package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.js +2 -2
  113. package/dist/src/migrations/update-22-6-0/add-claude-settings-local-to-git-ignore.js +2 -2
  114. package/dist/src/migrations/update-22-6-0/add-claude-worktrees-to-git-ignore.js +2 -2
  115. package/dist/src/migrations/update-22-7-0/add-polygraph-to-git-ignore.js +2 -2
  116. package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +2 -2
  117. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
  118. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
  119. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
  120. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  121. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  122. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +3 -3
  123. package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
  124. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +128 -2
  125. package/dist/src/tasks-runner/run-command.js +17 -32
  126. package/dist/src/tasks-runner/task-env.js +5 -2
  127. package/dist/src/tasks-runner/utils.js +2 -6
  128. package/dist/src/utils/analytics-prompt.js +4 -7
  129. package/dist/src/utils/chunkify.d.ts +7 -1
  130. package/dist/src/utils/chunkify.js +10 -3
  131. package/dist/src/utils/exit-codes.d.ts +9 -0
  132. package/dist/src/utils/exit-codes.js +19 -0
  133. package/dist/src/utils/fileutils.d.ts +5 -0
  134. package/dist/src/utils/fileutils.js +7 -2
  135. package/dist/src/utils/formatters/index.d.ts +13 -0
  136. package/dist/src/utils/formatters/index.js +74 -0
  137. package/dist/src/utils/formatters/oxfmt.d.ts +32 -0
  138. package/dist/src/utils/formatters/oxfmt.js +764 -0
  139. package/dist/src/utils/formatters/prettier.d.ts +26 -0
  140. package/dist/src/utils/formatters/prettier.js +201 -0
  141. package/dist/src/utils/formatters/shared.d.ts +5 -0
  142. package/dist/src/utils/formatters/shared.js +8 -0
  143. package/dist/src/utils/git-utils.d.ts +33 -2
  144. package/dist/src/utils/git-utils.js +156 -8
  145. package/dist/src/utils/ignore.d.ts +47 -5
  146. package/dist/src/utils/ignore.js +93 -11
  147. package/dist/src/utils/long-running-target.d.ts +10 -0
  148. package/dist/src/utils/long-running-target.js +19 -0
  149. package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
  150. package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
  151. package/dist/src/utils/min-release-age/packument.js +1 -1
  152. package/dist/src/utils/nx-console-prompt.js +3 -6
  153. package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
  154. package/dist/src/utils/package-manager-config/bunfig.js +49 -0
  155. package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
  156. package/dist/src/utils/package-manager-config/npmrc.js +124 -0
  157. package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
  158. package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
  159. package/dist/src/utils/package-manager.d.ts +21 -2
  160. package/dist/src/utils/package-manager.js +244 -47
  161. package/dist/src/utils/params.d.ts +7 -1
  162. package/dist/src/utils/params.js +64 -6
  163. package/dist/src/utils/prompt-helpers.d.ts +53 -0
  164. package/dist/src/utils/prompt-helpers.js +111 -0
  165. package/dist/src/utils/provenance.js +6 -14
  166. package/dist/src/utils/registry-config/bun.d.ts +2 -0
  167. package/dist/src/utils/registry-config/bun.js +257 -0
  168. package/dist/src/utils/registry-config/index.d.ts +13 -0
  169. package/dist/src/utils/registry-config/index.js +102 -0
  170. package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
  171. package/dist/src/utils/registry-config/pnpm.js +1551 -0
  172. package/dist/src/utils/registry-config/utils.d.ts +195 -0
  173. package/dist/src/utils/registry-config/utils.js +496 -0
  174. package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
  175. package/dist/src/utils/registry-config/yarn-berry.js +612 -0
  176. package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
  177. package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
  178. package/dist/src/utils/safe-spawn.d.ts +24 -0
  179. package/dist/src/utils/safe-spawn.js +104 -0
  180. package/dist/src/utils/write-formatted-json-file.d.ts +3 -2
  181. package/dist/src/utils/write-formatted-json-file.js +5 -4
  182. package/migrations.json +6 -0
  183. package/package.json +17 -13
  184. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +0 -88
  185. package/dist/src/utils/is-using-prettier.d.ts +0 -3
  186. package/dist/src/utils/is-using-prettier.js +0 -62
  187. package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
  188. package/dist/src/utils/min-release-age/npmrc.js +0 -45
@@ -6,7 +6,7 @@ const perf_hooks_1 = require("perf_hooks");
6
6
  const nx_commands_1 = require("../src/command-line/nx-commands");
7
7
  const strip_indents_1 = require("../src/utils/strip-indents");
8
8
  const client_1 = require("../src/daemon/client/client");
9
- const enquirer_1 = require("enquirer");
9
+ const prompt_helpers_1 = require("../src/utils/prompt-helpers");
10
10
  const output_1 = require("../src/utils/output");
11
11
  const analytics_1 = require("../src/analytics");
12
12
  /**
@@ -136,11 +136,9 @@ async function ensureNxConsoleInstalledViaDaemon() {
136
136
  ],
137
137
  });
138
138
  try {
139
- const { shouldInstallNxConsole } = await (0, enquirer_1.prompt)({
140
- type: 'confirm',
141
- name: 'shouldInstallNxConsole',
139
+ const shouldInstallNxConsole = await (0, prompt_helpers_1.confirmationPrompt)({
142
140
  message: 'Install Nx Console? (you can uninstall anytime)',
143
- initial: true,
141
+ onCancel: () => false,
144
142
  });
145
143
  // Set preference and install if user said yes
146
144
  const result = await client_1.daemonClient.setNxConsolePreferenceAndInstall(shouldInstallNxConsole);
@@ -215,12 +215,11 @@ class DefaultChangelogRenderer {
215
215
  if (!name || name.includes('[bot]')) {
216
216
  continue;
217
217
  }
218
- if (_authors.has(name)) {
219
- const entry = _authors.get(name);
220
- entry.email.add(author.email);
218
+ if (!_authors.has(name)) {
219
+ _authors.set(name, { email: new Set() });
221
220
  }
222
- else {
223
- _authors.set(name, { email: new Set([author.email]) });
221
+ if (author.email) {
222
+ _authors.get(name).email.add(author.email);
224
223
  }
225
224
  }
226
225
  }
@@ -31,6 +31,7 @@ const executor_utils_1 = require("../command-line/run/executor-utils");
31
31
  const plugins_1 = require("../project-graph/plugins");
32
32
  const schema_utils_1 = require("../config/schema-utils");
33
33
  const handle_import_1 = require("../utils/handle-import");
34
+ const prompt_helpers_1 = require("../utils/prompt-helpers");
34
35
  const target_merging_1 = require("../project-graph/utils/project-configuration/target-merging");
35
36
  function getProjectGraph() {
36
37
  try {
@@ -653,8 +654,66 @@ function createPromptProvider() {
653
654
  return { ...question, type: definition.type };
654
655
  }
655
656
  });
656
- return require('enquirer').prompt(questions);
657
+ // Angular hands over a whole form at once; clack asks one question at a
658
+ // time, so they are run in order and the answers reassembled.
659
+ return (async () => {
660
+ const answers = {};
661
+ for (const question of questions) {
662
+ answers[question.name] = await askSchematicQuestion(question);
663
+ }
664
+ return answers;
665
+ })();
657
666
  };
667
+ async function askSchematicQuestion(question) {
668
+ const validate = question.validate
669
+ ? (value) => {
670
+ const result = question.validate(value);
671
+ if (result === true)
672
+ return undefined;
673
+ return typeof result === 'string' ? result : 'Invalid value';
674
+ }
675
+ : undefined;
676
+ const choices = (question.choices ?? []).map((c) => typeof c === 'string' ? { value: c } : { value: c.name, label: c.message });
677
+ switch (question.type) {
678
+ case 'confirm':
679
+ return (0, prompt_helpers_1.confirmationPrompt)({
680
+ message: question.message,
681
+ initial: question.initial !== false,
682
+ });
683
+ case 'select':
684
+ return (0, prompt_helpers_1.selectPrompt)({
685
+ message: question.message,
686
+ choices,
687
+ initial: question.initial,
688
+ });
689
+ case 'multiselect':
690
+ return (0, prompt_helpers_1.multiselectPrompt)({
691
+ message: question.message,
692
+ choices,
693
+ initialValues: question.initial,
694
+ });
695
+ case 'numeral': {
696
+ // No numeric prompt; the answer is parsed back so callers still get a
697
+ // number rather than the typed string.
698
+ const answer = await (0, prompt_helpers_1.textPrompt)({
699
+ message: question.message,
700
+ initialValue: question.initial === undefined
701
+ ? undefined
702
+ : String(question.initial),
703
+ validate: (value) => value !== '' && !Number.isNaN(Number(value))
704
+ ? validate?.(value)
705
+ : 'Please enter a number',
706
+ });
707
+ return Number(answer);
708
+ }
709
+ default:
710
+ return (0, prompt_helpers_1.textPrompt)({
711
+ message: question.message,
712
+ initialValue: question.initial,
713
+ validate,
714
+ });
715
+ }
716
+ }
658
717
  }
659
718
  async function runMigration(root, packageName, migrationName, projects, isVerbose, projectGraph) {
660
719
  const logger = (0, exports.getLogger)(isVerbose);
@@ -7,7 +7,7 @@ const fs_1 = require("fs");
7
7
  const path_1 = require("path");
8
8
  const semver_1 = require("semver");
9
9
  const smol_toml_1 = tslib_1.__importDefault(require("smol-toml"));
10
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
10
+ const format_changed_files_1 = require("../../generators/internal-utils/format-changed-files");
11
11
  const generate_files_1 = require("../../generators/utils/generate-files");
12
12
  const json_1 = require("../../generators/utils/json");
13
13
  const native_1 = require("../../native");
@@ -234,7 +234,7 @@ async function setupAiAgentsGeneratorImpl(tree, options) {
234
234
  (0, ignore_1.addEntryToGitIgnore)(tree, (0, path_1.join)(options.directory, '.gitignore'), '.nx/polygraph');
235
235
  (0, ignore_1.addEntryToGitIgnore)(tree, (0, path_1.join)(options.directory, '.gitignore'), '.claude/worktrees');
236
236
  (0, ignore_1.addEntryToGitIgnore)(tree, (0, path_1.join)(options.directory, '.gitignore'), '.claude/settings.local.json');
237
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
237
+ await (0, format_changed_files_1.formatChangedFiles)(tree);
238
238
  // we use the check variable to determine if we should actually make changes or just report what would be changed
239
239
  return async (check = false) => {
240
240
  const messages = [];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.yargsCompletionCommand = void 0;
4
- const enquirer_1 = require("enquirer");
4
+ const prompt_helpers_1 = require("../../utils/prompt-helpers");
5
5
  const fs_1 = require("fs");
6
6
  const os_1 = require("os");
7
7
  const path_1 = require("path");
@@ -69,18 +69,13 @@ async function pickShellsInteractively() {
69
69
  process.exit(1);
70
70
  }
71
71
  const detected = detectAvailableShells();
72
- const answer = (await (0, enquirer_1.prompt)({
73
- type: 'multiselect',
74
- name: 'shells',
72
+ return await (0, prompt_helpers_1.multiselectPrompt)({
75
73
  message: 'Install nx completion for which shell(s)?',
76
- choices: SHELL_CHOICES.map((name) => ({
77
- name,
78
- value: name,
79
- // Pre-check shells we can detect on this machine.
80
- enabled: detected.has(name),
81
- })),
82
- }));
83
- return answer.shells ?? [];
74
+ choices: SHELL_CHOICES,
75
+ // Pre-select shells we can detect on this machine.
76
+ initialValues: SHELL_CHOICES.filter((name) => detected.has(name)),
77
+ onCancel: () => [],
78
+ });
84
79
  }
85
80
  /** Best-effort detect-which-shells-the-user-has. Pre-checks the multiselect.
86
81
  * Signals: $SHELL basename, presence of conventional rc files, $PSModulePath
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configureAiAgentsHandler = configureAiAgentsHandler;
4
4
  exports.configureAiAgentsHandlerImpl = configureAiAgentsHandlerImpl;
5
5
  const tslib_1 = require("tslib");
6
- const enquirer_1 = require("enquirer");
6
+ const prompt_helpers_1 = require("../../utils/prompt-helpers");
7
7
  const node_fs_1 = require("node:fs");
8
8
  const node_path_1 = require("node:path");
9
9
  const pc = tslib_1.__importStar(require("picocolors"));
@@ -63,8 +63,10 @@ async function configureAiAgentsHandler(args, inner = false) {
63
63
  await resetDaemonAgentStatus();
64
64
  }
65
65
  async function configureAiAgentsHandlerImpl(options) {
66
- // Node 24 has stricter readline behavior, and enquirer is not checking for closed state
67
- // when invoking operations, thus you get an ERR_USE_AFTER_CLOSE error.
66
+ // Node 24's stricter readline throws ERR_USE_AFTER_CLOSE when a prompt
67
+ // library operates on a closed interface. Added for enquirer, which nx no
68
+ // longer uses; verify against Node 24 before removing.
69
+ // TODO(v24): drop if @clack/prompts proves not to need it.
68
70
  process.on('uncaughtException', (error) => {
69
71
  if (error &&
70
72
  typeof error === 'object' &&
@@ -158,7 +160,7 @@ async function configureAiAgentsHandlerImpl(options) {
158
160
  ...partiallyConfiguredAgents,
159
161
  ...outOfDateAgents,
160
162
  ...nonConfiguredAgents,
161
- ].map((a) => getAgentChoiceForPrompt(a).message),
163
+ ].map((a) => getAgentChoiceForPrompt(a).label),
162
164
  });
163
165
  process.exit(1);
164
166
  }
@@ -239,26 +241,22 @@ async function configureAiAgentsHandlerImpl(options) {
239
241
  }
240
242
  // Interactive mode (or non-interactive with explicit --agents)
241
243
  const allAgentChoices = [];
242
- const preselectedIndices = [];
243
- let currentIndex = 0;
244
+ const preselectedAgents = [];
244
245
  // Partially configured agents first (highest priority)
245
246
  partiallyConfiguredAgents.forEach((a) => {
246
247
  allAgentChoices.push(getAgentChoiceForPrompt(a));
247
- preselectedIndices.push(currentIndex);
248
- currentIndex++;
248
+ preselectedAgents.push(a.name);
249
249
  });
250
250
  // Outdated agents second
251
251
  for (const a of fullyConfiguredAgents) {
252
252
  if (a.outdated) {
253
253
  allAgentChoices.push(getAgentChoiceForPrompt(a));
254
- preselectedIndices.push(currentIndex);
255
- currentIndex++;
254
+ preselectedAgents.push(a.name);
256
255
  }
257
256
  }
258
257
  // Non-configured agents last
259
258
  nonConfiguredAgents.forEach((a) => {
260
259
  allAgentChoices.push(getAgentChoiceForPrompt(a));
261
- currentIndex++;
262
260
  });
263
261
  if (allAgentChoices.length === 0) {
264
262
  output_1.output.success({
@@ -270,18 +268,13 @@ async function configureAiAgentsHandlerImpl(options) {
270
268
  let selectedAgents;
271
269
  if (options.interactive !== false) {
272
270
  try {
273
- selectedAgents = (await (0, enquirer_1.prompt)({
274
- type: 'multiselect',
275
- name: 'agents',
271
+ selectedAgents = await (0, prompt_helpers_1.multiselectPrompt)({
276
272
  message: 'Which AI agents would you like to configure? (space to select, enter to confirm)',
277
273
  choices: allAgentChoices,
278
- initial: preselectedIndices,
274
+ initialValues: preselectedAgents,
279
275
  required: true,
280
- footer: function () {
281
- const focused = this.focused;
282
- return pc.dim(` ${getAgentFooterDescription(focused.agentConfiguration)}`);
283
- },
284
- })).agents;
276
+ onCancel: () => process.exit(1),
277
+ });
285
278
  }
286
279
  catch {
287
280
  process.exit(1);
@@ -289,7 +282,7 @@ async function configureAiAgentsHandlerImpl(options) {
289
282
  }
290
283
  else {
291
284
  // non-interactive with explicit --agents: configure all requested
292
- selectedAgents = allAgentChoices.map((a) => a.name);
285
+ selectedAgents = allAgentChoices.map((a) => a.value);
293
286
  }
294
287
  if (selectedAgents?.length === 0) {
295
288
  output_1.output.log({
@@ -388,10 +381,11 @@ function getAgentChoiceForPrompt(agent) {
388
381
  const partiallyConfigured = agent.mcp !== agent.rules;
389
382
  const needsUpdate = partiallyConfigured || agent.outdated;
390
383
  return {
391
- name: agent.name,
392
- message: needsUpdate
384
+ value: agent.name,
385
+ label: needsUpdate
393
386
  ? `${agent.displayName} (update available)`
394
387
  : agent.displayName,
388
+ hint: getAgentFooterDescription(agent),
395
389
  agentConfiguration: agent,
396
390
  };
397
391
  }
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.format = format;
4
4
  const tslib_1 = require("tslib");
5
- const node_child_process_1 = require("node:child_process");
6
5
  const path = tslib_1.__importStar(require("node:path"));
7
- const semver_1 = require("semver");
8
6
  const configuration_1 = require("../../config/configuration");
9
7
  const typescript_1 = require("../../plugins/js/utils/typescript");
10
8
  const affected_project_graph_1 = require("../../project-graph/affected/affected-project-graph");
@@ -13,59 +11,81 @@ const project_graph_1 = require("../../project-graph/project-graph");
13
11
  const chunkify_1 = require("../../utils/chunkify");
14
12
  const command_line_utils_1 = require("../../utils/command-line-utils");
15
13
  const fileutils_1 = require("../../utils/fileutils");
16
- const handle_import_1 = require("../../utils/handle-import");
14
+ const formatters_1 = require("../../utils/formatters");
15
+ const oxfmt_1 = require("../../utils/formatters/oxfmt");
16
+ const prettier_1 = require("../../utils/formatters/prettier");
17
17
  const ignore_1 = require("../../utils/ignore");
18
18
  const object_sort_1 = require("../../utils/object-sort");
19
19
  const output_1 = require("../../utils/output");
20
- const package_json_1 = require("../../utils/package-json");
21
20
  const workspace_root_1 = require("../../utils/workspace-root");
21
+ /**
22
+ * A table, not a `switch`: this lookup sits inside a `try` whose `catch`
23
+ * reports "configured but not installed", and a `never` arm would throw into
24
+ * that catch and be misreported. A missing member is a compile error here.
25
+ */
26
+ const resolveFormatterBin = {
27
+ oxfmt: oxfmt_1.getOxfmtBinPath,
28
+ prettier: prettier_1.getPrettierPath,
29
+ };
22
30
  async function format(command, args) {
23
- let prettier;
31
+ const formatterType = (0, formatters_1.detectFormatter)(workspace_root_1.workspaceRoot);
32
+ if (!formatterType) {
33
+ output_1.output.warn({
34
+ title: 'No formatter configured.',
35
+ bodyLines: ['Install oxfmt or prettier to enable formatting.'],
36
+ });
37
+ return;
38
+ }
39
+ // Detection reads configuration only, so a workspace can be configured for a
40
+ // formatter that is not installed - a fresh clone, `--omit=dev` CI, a pruned
41
+ // node_modules. Resolving now turns a raw MODULE_NOT_FOUND into something
42
+ // actionable.
24
43
  try {
25
- prettier = await (0, handle_import_1.handleImport)('prettier');
44
+ resolveFormatterBin[formatterType]();
26
45
  }
27
46
  catch {
28
47
  output_1.output.error({
29
- title: 'Prettier is not installed.',
48
+ title: `${formatterType} is configured for this workspace but is not installed.`,
30
49
  bodyLines: [
31
- `Please install "prettier" and try again, or don't run the "nx format:${command}" command.`,
50
+ `Install "${formatterType}" and try again, or remove its configuration to disable "nx format:${command}".`,
32
51
  ],
33
52
  });
34
53
  process.exit(1);
35
54
  }
36
55
  const { nxArgs } = (0, command_line_utils_1.splitArgsIntoNxArgsAndOverrides)(args, 'affected', { printWarnings: false }, (0, configuration_1.readNxJson)());
37
- const patterns = (await getPatterns(prettier, { ...args, ...nxArgs })).map((p) => {
38
- // On non-Windows, escape $ to prevent shell variable interpolation
39
- // (the shell consumes one \, so \\$ becomes \$ which the shell treats as literal $)
40
- // On Windows (cmd.exe), $ is not a special character, so escaping it would
41
- // cause prettier to look for a file with a literal \$ in the name
42
- // prettier-ignore
43
- const escaped = process.platform !== 'win32' ? p.replace(/\$/g, '\\\$') : p;
44
- return `"${escaped}"`;
56
+ // Patterns are kept raw here. Prettier is invoked through a shell so it
57
+ // quotes them at the call site; oxfmt is invoked with execFile and needs
58
+ // the unquoted paths.
59
+ const patterns = await getPatterns(formatterType, {
60
+ ...args,
61
+ ...nxArgs,
45
62
  });
46
- // Chunkify the patterns array to prevent crashing the windows terminal
47
- const chunkList = (0, chunkify_1.chunkify)(patterns);
63
+ // Chunkify the patterns array to prevent crashing the windows terminal.
64
+ // The prettier path quotes each pattern on its way to the shell, so size the
65
+ // chunks against that; oxfmt goes through execFile and gets them raw.
66
+ const chunkList = (0, chunkify_1.chunkify)(patterns, undefined, formatterType === 'prettier'
67
+ ? (pattern) => (0, prettier_1.quoteForShell)(pattern).length
68
+ : undefined);
48
69
  switch (command) {
49
70
  case 'write':
50
71
  if (nxArgs.sortRootTsconfigPaths) {
51
72
  sortTsConfig();
52
73
  }
53
74
  addRootConfigFiles(chunkList, nxArgs);
54
- chunkList.forEach((chunk) => write(prettier, chunk));
75
+ chunkList.forEach((chunk) => write(formatterType, chunk));
55
76
  break;
56
77
  case 'check': {
57
78
  const filesWithDifferentFormatting = [];
58
79
  for (const chunk of chunkList) {
59
- const files = await check(chunk);
80
+ const files = await check(formatterType, chunk);
60
81
  filesWithDifferentFormatting.push(...files);
61
82
  }
62
83
  if (filesWithDifferentFormatting.length > 0) {
63
84
  if (nxArgs.verbose) {
64
85
  output_1.output.error({
65
- title: 'The following files are not formatted correctly based on your Prettier configuration',
86
+ title: 'The following files are not formatted correctly',
66
87
  bodyLines: [
67
88
  '- Run "nx format:write" and commit the resulting diff to fix these files.',
68
- '- Please note, Prettier does not support a native way to diff the output of its check logic (https://github.com/prettier/prettier/issues/6885).',
69
89
  '',
70
90
  ...filesWithDifferentFormatting,
71
91
  ],
@@ -80,7 +100,7 @@ async function format(command, args) {
80
100
  }
81
101
  }
82
102
  }
83
- async function getPatterns(prettier, args) {
103
+ async function getPatterns(formatterType, args) {
84
104
  const allFilesPattern = ['.'];
85
105
  if (args.all) {
86
106
  return allFilesPattern;
@@ -91,16 +111,16 @@ async function getPatterns(prettier, args) {
91
111
  return getPatternsFromProjects(args.projects, graph);
92
112
  }
93
113
  const p = (0, command_line_utils_1.parseFiles)(args);
94
- const supportedExtensions = new Set((await prettier.getSupportInfo()).languages
95
- .flatMap((language) => language.extensions)
96
- .filter((extension) => !!extension)
97
- // Prettier supports ".swcrc" as a file instead of an extension
98
- // So we add ".swcrc" as a supported extension manually
99
- // which allows it to be considered for calculating "patterns"
100
- .concat('.swcrc'));
101
- const patterns = p.files
114
+ // Deleted files still show up in the changed-file set, and neither
115
+ // formatter should be handed a path that is no longer there.
116
+ let patterns = p.files
102
117
  .map((f) => path.relative(workspace_root_1.workspaceRoot, f))
103
- .filter((f) => (0, fileutils_1.fileExists)(f) && supportedExtensions.has(path.extname(f)));
118
+ .filter((f) => (0, fileutils_1.fileExists)(f));
119
+ if (formatterType === 'prettier') {
120
+ // oxfmt needs no equivalent filter - it silently skips file types it
121
+ // does not handle, and its base args keep an all-skipped run green.
122
+ patterns = await (0, prettier_1.filterToPrettierSupportedFiles)(patterns);
123
+ }
104
124
  // exclude patterns in .nxignore or .gitignore
105
125
  const nonIgnoredPatterns = (0, ignore_1.getIgnoreObject)().filter(patterns);
106
126
  if (args.libsAndApps) {
@@ -130,13 +150,10 @@ function addRootConfigFiles(chunkList, nxArgs) {
130
150
  }
131
151
  const chunk = [];
132
152
  const addToChunkIfNeeded = (file) => {
133
- if (chunkList.every((c) => !c.includes(`"${file}"`))) {
153
+ if (chunkList.every((c) => !c.includes(file))) {
134
154
  chunk.push(file);
135
155
  }
136
156
  };
137
- // if (workspaceJsonPath) {
138
- // addToChunkIfNeeded(workspaceJsonPath);
139
- // }
140
157
  ['nx.json', (0, typescript_1.getRootTsConfigFileName)()]
141
158
  .filter(Boolean)
142
159
  .forEach(addToChunkIfNeeded);
@@ -147,49 +164,43 @@ function addRootConfigFiles(chunkList, nxArgs) {
147
164
  function getPatternsFromProjects(projects, projectGraph) {
148
165
  return (0, command_line_utils_1.getProjectRoots)(projects, projectGraph);
149
166
  }
150
- function write(prettier, patterns) {
151
- if (patterns.length > 0) {
152
- const [swcrcPatterns, regularPatterns] = patterns.reduce((result, pattern) => {
153
- result[pattern.includes('.swcrc') ? 0 : 1].push(pattern);
154
- return result;
155
- }, [[], []]);
156
- const prettierPath = getPrettierPath();
157
- const listDifferentArg = shouldUseListDifferent(prettier.version)
158
- ? '--list-different '
159
- : '';
160
- (0, node_child_process_1.execSync)(`node "${prettierPath}" --write ${listDifferentArg}${regularPatterns.join(' ')}`, {
161
- stdio: [0, 1, 2],
162
- windowsHide: true,
163
- });
164
- if (swcrcPatterns.length > 0) {
165
- (0, node_child_process_1.execSync)(`node "${prettierPath}" --write ${listDifferentArg}${swcrcPatterns.join(' ')} --parser json`, {
166
- stdio: [0, 1, 2],
167
- windowsHide: true,
168
- });
167
+ function write(formatterType, patterns) {
168
+ if (patterns.length === 0) {
169
+ return;
170
+ }
171
+ switch (formatterType) {
172
+ case 'oxfmt':
173
+ (0, oxfmt_1.writeWithOxfmt)(patterns);
174
+ break;
175
+ case 'prettier':
176
+ (0, prettier_1.writeWithPrettier)(patterns);
177
+ break;
178
+ default: {
179
+ // Without this, an unhandled formatter makes `nx format:write` exit 0
180
+ // having formatted nothing, while `check()` throws - the two halves of
181
+ // the same command disagreeing.
182
+ const unhandled = formatterType;
183
+ throw new Error(`Unhandled formatter: ${unhandled}`);
169
184
  }
170
185
  }
171
186
  }
172
- async function check(patterns) {
187
+ async function check(formatterType, patterns) {
173
188
  if (patterns.length === 0) {
174
189
  return [];
175
190
  }
176
- const prettierPath = getPrettierPath();
177
- return new Promise((resolve, reject) => {
178
- (0, node_child_process_1.exec)(`node "${prettierPath}" --list-different ${patterns.join(' ')}`, { encoding: 'utf-8', windowsHide: true }, (error, stdout) => {
179
- if (error) {
180
- // The command failed because Prettier threw an error.
181
- if (stdout.length === 0) {
182
- reject(error);
183
- }
184
- // The command failed so there are files with different formatting. Prettier writes them to stdout, newline separated.
185
- resolve(stdout.trim().split('\n'));
186
- }
187
- else {
188
- // The command succeeded so there are no files with different formatting
189
- resolve([]);
190
- }
191
- });
192
- });
191
+ switch (formatterType) {
192
+ case 'oxfmt':
193
+ return (0, oxfmt_1.checkWithOxfmt)(patterns);
194
+ case 'prettier':
195
+ return (0, prettier_1.checkWithPrettier)(patterns);
196
+ default: {
197
+ // `strict: false` does not make a missing case an error on its own, but
198
+ // it does reject this assignment - so adding a formatter fails to compile
199
+ // here instead of returning undefined into a caller that spreads it.
200
+ const unhandled = formatterType;
201
+ throw new Error(`Unhandled formatter: ${unhandled}`);
202
+ }
203
+ }
193
204
  }
194
205
  function sortTsConfig() {
195
206
  try {
@@ -203,31 +214,3 @@ function sortTsConfig() {
203
214
  // catch noop
204
215
  }
205
216
  }
206
- let prettierPath;
207
- function getPrettierPath() {
208
- if (prettierPath) {
209
- return prettierPath;
210
- }
211
- const { packageJson, path: packageJsonPath } = (0, package_json_1.readModulePackageJson)('prettier');
212
- const bin = packageJson.bin;
213
- const binPath = typeof bin === 'string' ? bin : bin?.['prettier'];
214
- if (!binPath) {
215
- throw new Error(`Could not find prettier binary in ${packageJsonPath}`);
216
- }
217
- prettierPath = path.resolve(path.dirname(packageJsonPath), binPath);
218
- return prettierPath;
219
- }
220
- let useListDifferent;
221
- /**
222
- * Determines if --list-different should be used with --write.
223
- * Prettier 4+ and 3.6.x with experimental CLI don't support combining these flags.
224
- */
225
- function shouldUseListDifferent(prettierVersion) {
226
- if (useListDifferent !== undefined) {
227
- return useListDifferent;
228
- }
229
- const prettierMajor = (0, semver_1.major)(prettierVersion);
230
- const isExperimentalCli = process.env.PRETTIER_EXPERIMENTAL_CLI === '1';
231
- useListDifferent = prettierMajor < 4 && !isExperimentalCli;
232
- return useListDifferent;
233
- }
@@ -6,7 +6,7 @@ exports.printGenHelp = printGenHelp;
6
6
  exports.generate = generate;
7
7
  const tslib_1 = require("tslib");
8
8
  const pc = tslib_1.__importStar(require("picocolors"));
9
- const enquirer_1 = require("enquirer");
9
+ const prompt_helpers_1 = require("../../utils/prompt-helpers");
10
10
  const path_1 = require("path");
11
11
  const configuration_1 = require("../../config/configuration");
12
12
  const tree_1 = require("../../generators/tree");
@@ -91,42 +91,42 @@ async function promptForCollection(generatorName, interactive, projectsConfigura
91
91
  throwInvalidInvocation(Array.from(choicesMap));
92
92
  }
93
93
  else if (interactive && choices.length > 1) {
94
- const noneOfTheAbove = `\nNone of the above`;
94
+ const noneOfTheAbove = `None of the above`;
95
+ // Blank line before the last entry. The newline has to trail the choice
96
+ // *before* the gap: a leading one would land between the following
97
+ // choice's radio marker and its text, splitting that row in two.
98
+ const beforeGap = choices.length - 1;
95
99
  choices.push(noneOfTheAbove);
96
- let { generator, customCollection } = await (0, enquirer_1.prompt)([
97
- {
98
- name: 'generator',
99
- message: `Which generator would you like to use?`,
100
- type: 'autocomplete',
101
- // enquirer's typings are incorrect here... It supports (string | Choice)[], but is typed as (string[] | Choice[])
102
- choices: choices,
103
- },
104
- {
105
- name: 'customCollection',
106
- type: 'input',
107
- message: `Which collection would you like to use?`,
108
- skip: function () {
109
- // Skip this question if the user did not answer None of the above
110
- return this.state.answers.generator !== noneOfTheAbove;
111
- },
112
- validate: function (value) {
113
- if (this.skipped) {
114
- return true;
115
- }
116
- try {
117
- (0, generator_utils_1.getGeneratorInformation)(value, generatorName, workspace_root_1.workspaceRoot, projectsConfiguration.projects);
118
- return true;
119
- }
120
- catch {
121
- logger_1.logger.error(`\nCould not find ${value}:${generatorName}`);
122
- return false;
123
- }
124
- },
100
+ const generator = await (0, prompt_helpers_1.selectPrompt)({
101
+ message: `Which generator would you like to use?`,
102
+ // Local-plugin entries carry a separate display label; the rest are
103
+ // plain collection names. Only the label takes the newline, so the
104
+ // value still resolves as a collection name.
105
+ choices: choices.map((c, i) => {
106
+ const choice = typeof c === 'string'
107
+ ? { value: c, label: c }
108
+ : { value: c.value, label: c.message };
109
+ return i === beforeGap && !choice.label.endsWith('\n')
110
+ ? { ...choice, label: `${choice.label}\n` }
111
+ : choice;
112
+ }),
113
+ });
114
+ if (generator !== noneOfTheAbove) {
115
+ return generator;
116
+ }
117
+ const customCollection = await (0, prompt_helpers_1.textPrompt)({
118
+ message: `Which collection would you like to use?`,
119
+ validate: (value) => {
120
+ try {
121
+ (0, generator_utils_1.getGeneratorInformation)(value, generatorName, workspace_root_1.workspaceRoot, projectsConfiguration.projects);
122
+ return undefined;
123
+ }
124
+ catch {
125
+ return `Could not find ${value}:${generatorName}`;
126
+ }
125
127
  },
126
- ]);
127
- return customCollection
128
- ? `${customCollection}:${generatorName}`
129
- : generator;
128
+ });
129
+ return `${customCollection}:${generatorName}`;
130
130
  }
131
131
  else if (deprecatedChoices.size > 0) {
132
132
  throw new Error([