nx 17.0.3 → 17.0.5

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 (320) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/bin/init-local.js +10 -60
  4. package/bin/nx-cloud.js +6 -0
  5. package/bin/nx.js +1 -9
  6. package/bin/post-install.js +5 -1
  7. package/bin/run-executor.js +1 -1
  8. package/migrations.json +18 -0
  9. package/package.json +21 -18
  10. package/plugins/package-json.js +1 -1
  11. package/{changelog-renderer → release/changelog-renderer}/index.d.ts +18 -3
  12. package/{changelog-renderer → release/changelog-renderer}/index.js +78 -34
  13. package/release/index.d.ts +4 -0
  14. package/release/index.js +11 -0
  15. package/schemas/nx-schema.json +203 -19
  16. package/schemas/project-schema.json +20 -0
  17. package/src/adapter/angular-json.js +28 -18
  18. package/src/adapter/compat.d.ts +2 -2
  19. package/src/adapter/compat.js +6 -1
  20. package/src/adapter/ngcli-adapter.d.ts +16 -4
  21. package/src/adapter/ngcli-adapter.js +85 -28
  22. package/src/command-line/add/add.d.ts +2 -0
  23. package/src/command-line/add/add.js +169 -0
  24. package/src/command-line/add/command-object.d.ts +7 -0
  25. package/src/command-line/add/command-object.js +24 -0
  26. package/src/command-line/affected/affected.js +0 -3
  27. package/src/command-line/affected/command-object.d.ts +4 -4
  28. package/src/command-line/affected/command-object.js +53 -26
  29. package/src/command-line/affected/print-affected.js +10 -1
  30. package/src/command-line/connect/command-object.d.ts +1 -2
  31. package/src/command-line/connect/command-object.js +3 -7
  32. package/src/command-line/connect/connect-to-nx-cloud.d.ts +4 -5
  33. package/src/command-line/connect/connect-to-nx-cloud.js +43 -31
  34. package/src/command-line/connect/view-logs.js +5 -21
  35. package/src/command-line/examples.js +18 -0
  36. package/src/command-line/exec/command-object.js +2 -1
  37. package/src/command-line/exec/exec.d.ts +1 -1
  38. package/src/command-line/exec/exec.js +78 -35
  39. package/src/command-line/format/format.js +13 -4
  40. package/src/command-line/generate/generate.js +9 -9
  41. package/src/command-line/generate/generator-utils.d.ts +3 -2
  42. package/src/command-line/generate/generator-utils.js +5 -5
  43. package/src/command-line/graph/graph.d.ts +1 -1
  44. package/src/command-line/graph/graph.js +82 -37
  45. package/src/command-line/init/command-object.js +70 -43
  46. package/src/command-line/init/implementation/add-nx-to-monorepo.d.ts +4 -2
  47. package/src/command-line/init/implementation/add-nx-to-monorepo.js +11 -2
  48. package/src/command-line/init/implementation/add-nx-to-nest.d.ts +1 -1
  49. package/src/command-line/init/implementation/add-nx-to-nest.js +9 -6
  50. package/src/command-line/init/implementation/add-nx-to-npm-repo.d.ts +4 -2
  51. package/src/command-line/init/implementation/add-nx-to-npm-repo.js +14 -4
  52. package/src/command-line/init/implementation/angular/index.js +4 -1
  53. package/src/command-line/init/implementation/angular/legacy-angular-versions.js +10 -5
  54. package/src/command-line/init/implementation/angular/standalone-workspace.js +1 -1
  55. package/src/command-line/init/implementation/angular/types.d.ts +1 -1
  56. package/src/command-line/init/implementation/dot-nx/nxw.js +47 -16
  57. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  58. package/src/command-line/init/implementation/react/index.js +4 -2
  59. package/src/command-line/init/implementation/react/rename-js-to-jsx.js +4 -2
  60. package/src/command-line/init/implementation/utils.d.ts +5 -5
  61. package/src/command-line/init/implementation/utils.js +46 -44
  62. package/src/command-line/init/{init.js → init-v1.js} +5 -13
  63. package/src/command-line/init/init-v2.d.ts +7 -0
  64. package/src/command-line/init/init-v2.js +201 -0
  65. package/src/command-line/list/list.js +6 -5
  66. package/src/command-line/migrate/command-object.js +19 -4
  67. package/src/command-line/migrate/migrate.js +21 -17
  68. package/src/command-line/new/new.js +1 -1
  69. package/src/command-line/nx-commands.js +4 -1
  70. package/src/command-line/release/changelog.d.ts +22 -1
  71. package/src/command-line/release/changelog.js +459 -257
  72. package/src/command-line/release/command-object.d.ts +29 -7
  73. package/src/command-line/release/command-object.js +120 -20
  74. package/src/command-line/release/config/config.d.ts +26 -21
  75. package/src/command-line/release/config/config.js +416 -59
  76. package/src/command-line/release/config/conventional-commits.d.ts +2 -0
  77. package/src/command-line/release/config/conventional-commits.js +98 -0
  78. package/src/command-line/release/config/filter-release-groups.d.ts +1 -2
  79. package/src/command-line/release/config/filter-release-groups.js +38 -1
  80. package/src/command-line/release/index.d.ts +16 -0
  81. package/src/command-line/release/index.js +23 -0
  82. package/src/command-line/release/publish.d.ts +7 -3
  83. package/src/command-line/release/publish.js +89 -37
  84. package/src/command-line/release/release.d.ts +4 -0
  85. package/src/command-line/release/release.js +176 -0
  86. package/src/command-line/release/utils/batch-projects-by-generator-config.d.ts +7 -0
  87. package/src/command-line/release/utils/batch-projects-by-generator-config.js +37 -0
  88. package/src/command-line/release/utils/exec-command.d.ts +1 -0
  89. package/src/command-line/release/utils/exec-command.js +34 -0
  90. package/src/command-line/release/utils/git.d.ts +34 -1
  91. package/src/command-line/release/utils/git.js +238 -34
  92. package/src/command-line/release/utils/github.d.ts +5 -5
  93. package/src/command-line/release/utils/github.js +155 -8
  94. package/src/command-line/release/utils/markdown.js +6 -1
  95. package/src/command-line/release/utils/print-changes.d.ts +1 -1
  96. package/src/command-line/release/utils/print-changes.js +3 -3
  97. package/src/command-line/release/utils/resolve-nx-json-error-message.js +4 -1
  98. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +4 -0
  99. package/src/command-line/release/utils/resolve-semver-specifier.js +58 -0
  100. package/src/command-line/release/utils/semver.d.ts +8 -0
  101. package/src/command-line/release/utils/semver.js +30 -1
  102. package/src/command-line/release/utils/shared.d.ts +39 -0
  103. package/src/command-line/release/utils/shared.js +213 -0
  104. package/src/command-line/release/version.d.ts +37 -3
  105. package/src/command-line/release/version.js +312 -117
  106. package/src/command-line/repair/repair.js +13 -9
  107. package/src/command-line/report/report.d.ts +3 -0
  108. package/src/command-line/report/report.js +22 -5
  109. package/src/command-line/run/command-object.d.ts +4 -0
  110. package/src/command-line/run/command-object.js +18 -2
  111. package/src/command-line/run/executor-utils.d.ts +2 -1
  112. package/src/command-line/run/executor-utils.js +4 -4
  113. package/src/command-line/run/run-one.js +3 -6
  114. package/src/command-line/run/run.js +34 -9
  115. package/src/command-line/run-many/command-object.js +4 -1
  116. package/src/command-line/run-many/run-many.js +0 -3
  117. package/src/command-line/show/command-object.d.ts +3 -0
  118. package/src/command-line/show/command-object.js +29 -2
  119. package/src/command-line/show/show.js +9 -0
  120. package/src/command-line/yargs-utils/shared-options.d.ts +4 -1
  121. package/src/command-line/yargs-utils/shared-options.js +23 -9
  122. package/src/commands-runner/command-graph.d.ts +13 -0
  123. package/src/commands-runner/command-graph.js +2 -0
  124. package/src/commands-runner/create-command-graph.d.ts +4 -0
  125. package/src/commands-runner/create-command-graph.js +44 -0
  126. package/src/commands-runner/get-command-projects.d.ts +3 -0
  127. package/src/commands-runner/get-command-projects.js +19 -0
  128. package/src/config/nx-json.d.ts +160 -25
  129. package/src/config/project-graph.d.ts +3 -3
  130. package/src/config/workspace-json-project-json.d.ts +23 -1
  131. package/src/config/workspaces.d.ts +1 -1
  132. package/src/config/workspaces.js +4 -6
  133. package/src/core/graph/3rdpartylicenses.txt +144 -74
  134. package/src/core/graph/environment.js +1 -1
  135. package/src/core/graph/index.html +4 -6
  136. package/src/core/graph/main.js +1 -1
  137. package/src/core/graph/runtime.js +1 -1
  138. package/src/core/graph/styles.css +3 -3
  139. package/src/core/graph/styles.js +1 -1
  140. package/src/daemon/client/client.d.ts +5 -1
  141. package/src/daemon/client/client.js +27 -8
  142. package/src/daemon/client/{socket-messenger.d.ts → daemon-socket-messenger.d.ts} +1 -1
  143. package/src/daemon/client/{socket-messenger.js → daemon-socket-messenger.js} +3 -3
  144. package/src/daemon/daemon-project-graph-error.d.ts +8 -0
  145. package/src/daemon/daemon-project-graph-error.js +13 -0
  146. package/src/daemon/server/handle-hash-tasks.js +12 -2
  147. package/src/daemon/server/handle-request-project-graph.js +1 -1
  148. package/src/daemon/server/project-graph-incremental-recomputation.d.ts +14 -13
  149. package/src/daemon/server/project-graph-incremental-recomputation.js +98 -33
  150. package/src/daemon/server/shutdown-utils.js +2 -4
  151. package/src/daemon/server/watcher.js +0 -3
  152. package/src/daemon/socket-utils.d.ts +2 -1
  153. package/src/daemon/socket-utils.js +15 -4
  154. package/src/daemon/tmp-dir.d.ts +1 -0
  155. package/src/daemon/tmp-dir.js +4 -4
  156. package/src/devkit-exports.d.ts +2 -2
  157. package/src/devkit-exports.js +3 -2
  158. package/src/devkit-internals.d.ts +3 -0
  159. package/src/devkit-internals.js +7 -1
  160. package/src/executors/noop/schema.json +1 -1
  161. package/src/executors/run-commands/run-commands.impl.d.ts +10 -2
  162. package/src/executors/run-commands/run-commands.impl.js +152 -48
  163. package/src/executors/run-commands/schema.json +11 -1
  164. package/src/executors/run-script/run-script.impl.js +43 -11
  165. package/src/executors/utils/convert-nx-executor.js +1 -1
  166. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +3 -1
  167. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +4 -2
  168. package/src/generators/testing-utils/create-tree-with-empty-workspace.js +0 -6
  169. package/src/generators/tree.d.ts +1 -0
  170. package/src/generators/utils/glob.js +2 -2
  171. package/src/generators/utils/project-configuration.js +28 -9
  172. package/src/hasher/create-task-hasher.d.ts +4 -0
  173. package/src/hasher/create-task-hasher.js +16 -0
  174. package/src/hasher/hash-task.js +9 -3
  175. package/src/hasher/native-task-hasher-impl.d.ts +19 -0
  176. package/src/hasher/native-task-hasher-impl.js +37 -0
  177. package/src/hasher/node-task-hasher-impl.d.ts +49 -0
  178. package/src/hasher/node-task-hasher-impl.js +431 -0
  179. package/src/hasher/task-hasher.d.ts +33 -21
  180. package/src/hasher/task-hasher.js +30 -428
  181. package/src/migrations/update-15-0-0/migrate-to-inputs.js +5 -5
  182. package/src/migrations/update-15-1-0/set-project-names.js +2 -1
  183. package/src/migrations/update-15-8-2/update-nxw.js +2 -6
  184. package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +3 -3
  185. package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +49 -13
  186. package/src/migrations/update-17-2-0/move-default-base.d.ts +5 -0
  187. package/src/migrations/update-17-2-0/move-default-base.js +21 -0
  188. package/src/migrations/update-17-3-0/nx-release-path.d.ts +3 -0
  189. package/src/migrations/update-17-3-0/nx-release-path.js +48 -0
  190. package/src/migrations/update-17-3-0/update-nxw.d.ts +2 -0
  191. package/src/migrations/update-17-3-0/update-nxw.js +7 -0
  192. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +2 -0
  193. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +9 -0
  194. package/src/native/index.d.ts +65 -15
  195. package/src/native/index.js +6 -2
  196. package/src/native/transform-objects.js +2 -0
  197. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts +1 -0
  198. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +13 -12
  199. package/src/nx-cloud/generators/connect-to-nx-cloud/schema.json +6 -1
  200. package/src/nx-cloud/update-manager.js +2 -1
  201. package/src/plugins/js/index.d.ts +1 -1
  202. package/src/plugins/js/index.js +3 -3
  203. package/src/plugins/js/lock-file/lock-file.d.ts +2 -2
  204. package/src/plugins/js/lock-file/lock-file.js +15 -3
  205. package/src/plugins/js/package-json/create-package-json.js +1 -1
  206. package/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +1 -1
  207. package/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +1 -1
  208. package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +1 -1
  209. package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.js +1 -1
  210. package/src/plugins/js/utils/register.d.ts +1 -1
  211. package/src/plugins/js/utils/register.js +28 -8
  212. package/src/plugins/js/versions.d.ts +1 -1
  213. package/src/plugins/js/versions.js +1 -1
  214. package/{plugins/package-json-workspaces.d.ts → src/plugins/package-json-workspaces/create-nodes.d.ts} +4 -4
  215. package/{plugins/package-json-workspaces.js → src/plugins/package-json-workspaces/create-nodes.js} +34 -12
  216. package/src/plugins/package-json-workspaces/index.d.ts +1 -0
  217. package/src/plugins/package-json-workspaces/index.js +4 -0
  218. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -0
  219. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +47 -0
  220. package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -5
  221. package/src/plugins/project-json/build-nodes/project-json.js +6 -44
  222. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +66 -0
  223. package/src/plugins/target-defaults/target-defaults-plugin.js +182 -0
  224. package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
  225. package/src/project-graph/affected/locators/workspace-projects.d.ts +0 -2
  226. package/src/project-graph/affected/locators/workspace-projects.js +16 -29
  227. package/src/project-graph/build-project-graph.d.ts +20 -1
  228. package/src/project-graph/build-project-graph.js +91 -33
  229. package/src/project-graph/file-map-utils.d.ts +9 -5
  230. package/src/project-graph/file-map-utils.js +16 -63
  231. package/src/project-graph/file-utils.d.ts +1 -1
  232. package/src/project-graph/file-utils.js +44 -2
  233. package/src/project-graph/nx-deps-cache.js +1 -1
  234. package/src/project-graph/project-graph-builder.d.ts +1 -1
  235. package/src/project-graph/project-graph-builder.js +1 -1
  236. package/src/project-graph/project-graph.d.ts +32 -1
  237. package/src/project-graph/project-graph.js +147 -23
  238. package/src/project-graph/utils/build-all-workspace-files.d.ts +2 -0
  239. package/src/project-graph/utils/build-all-workspace-files.js +15 -0
  240. package/src/project-graph/utils/normalize-project-nodes.d.ts +2 -3
  241. package/src/project-graph/utils/normalize-project-nodes.js +7 -33
  242. package/src/project-graph/utils/project-configuration-utils.d.ts +66 -4
  243. package/src/project-graph/utils/project-configuration-utils.js +509 -62
  244. package/src/project-graph/utils/retrieve-workspace-files.d.ts +12 -31
  245. package/src/project-graph/utils/retrieve-workspace-files.js +27 -90
  246. package/src/tasks-runner/batch/run-batch.js +3 -3
  247. package/src/tasks-runner/cache.js +6 -3
  248. package/src/tasks-runner/create-task-graph.js +1 -1
  249. package/src/tasks-runner/fork.d.ts +1 -0
  250. package/src/tasks-runner/fork.js +23 -0
  251. package/src/tasks-runner/forked-process-task-runner.d.ts +13 -5
  252. package/src/tasks-runner/forked-process-task-runner.js +112 -21
  253. package/src/tasks-runner/init-tasks-runner.js +1 -1
  254. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +28 -28
  255. package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +19 -22
  256. package/src/tasks-runner/life-cycles/empty-terminal-output-life-cycle.js +1 -3
  257. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +1 -3
  258. package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +2 -4
  259. package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +1 -0
  260. package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +11 -5
  261. package/src/tasks-runner/life-cycles/view-logs-utils.js +1 -1
  262. package/src/tasks-runner/pseudo-ipc.d.ts +49 -0
  263. package/src/tasks-runner/pseudo-ipc.js +140 -0
  264. package/src/tasks-runner/pseudo-terminal.d.ts +43 -0
  265. package/src/tasks-runner/pseudo-terminal.js +159 -0
  266. package/src/tasks-runner/run-command.d.ts +1 -1
  267. package/src/tasks-runner/run-command.js +13 -19
  268. package/src/tasks-runner/task-env.js +1 -2
  269. package/src/tasks-runner/task-graph-utils.d.ts +7 -3
  270. package/src/tasks-runner/task-graph-utils.js +15 -15
  271. package/src/tasks-runner/task-orchestrator.js +68 -12
  272. package/src/tasks-runner/tasks-schedule.js +3 -3
  273. package/src/tasks-runner/utils.d.ts +16 -7
  274. package/src/tasks-runner/utils.js +30 -16
  275. package/src/utils/ab-testing.d.ts +36 -2
  276. package/src/utils/ab-testing.js +34 -16
  277. package/src/utils/assert-workspace-validity.js +1 -1
  278. package/src/utils/cache-directory.d.ts +1 -0
  279. package/src/utils/cache-directory.js +5 -1
  280. package/src/utils/child-process.d.ts +15 -1
  281. package/src/utils/child-process.js +91 -1
  282. package/src/utils/command-line-utils.js +2 -1
  283. package/src/utils/exit-codes.d.ts +6 -0
  284. package/src/utils/exit-codes.js +20 -0
  285. package/src/utils/fileutils.d.ts +1 -0
  286. package/src/utils/find-matching-projects.js +5 -5
  287. package/src/utils/find-workspace-root.js +1 -0
  288. package/src/utils/ignore.js +8 -1
  289. package/src/utils/json-diff.d.ts +1 -0
  290. package/src/utils/json-diff.js +2 -1
  291. package/src/utils/json.js +3 -1
  292. package/src/utils/logger.js +1 -1
  293. package/src/utils/nx-cloud-utils.d.ts +1 -1
  294. package/src/utils/nx-cloud-utils.js +9 -4
  295. package/src/utils/nx-plugin.d.ts +32 -15
  296. package/src/utils/nx-plugin.deprecated.d.ts +10 -5
  297. package/src/utils/nx-plugin.deprecated.js +23 -0
  298. package/src/utils/nx-plugin.js +71 -80
  299. package/src/utils/output.d.ts +4 -2
  300. package/src/utils/output.js +44 -9
  301. package/src/utils/package-json.d.ts +4 -4
  302. package/src/utils/package-json.js +18 -12
  303. package/src/utils/package-manager.d.ts +7 -0
  304. package/src/utils/package-manager.js +24 -4
  305. package/src/utils/params.d.ts +12 -4
  306. package/src/utils/params.js +37 -4
  307. package/src/utils/plugins/core-plugins.js +8 -0
  308. package/src/utils/plugins/installed-plugins.d.ts +2 -1
  309. package/src/utils/plugins/installed-plugins.js +2 -2
  310. package/src/utils/plugins/local-plugins.js +1 -1
  311. package/src/utils/plugins/plugin-capabilities.d.ts +3 -2
  312. package/src/utils/plugins/plugin-capabilities.js +7 -7
  313. package/src/utils/typescript.js +1 -1
  314. package/src/utils/update-nxw.d.ts +2 -0
  315. package/src/utils/update-nxw.js +12 -0
  316. package/src/utils/workspace-configuration-check.js +1 -1
  317. package/src/utils/workspace-context.d.ts +6 -4
  318. package/src/utils/workspace-context.js +19 -9
  319. package/src/core/graph/polyfills.js +0 -1
  320. /package/src/command-line/init/{init.d.ts → init-v1.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printChanges = exports.printDiff = void 0;
3
+ exports.printAndFlushChanges = exports.printDiff = void 0;
4
4
  const chalk = require("chalk");
5
5
  const jest_diff_1 = require("jest-diff");
6
6
  const node_fs_1 = require("node:fs");
@@ -27,7 +27,7 @@ function printDiff(before, after, contextLines = 1, noDiffMessage = NO_DIFF_MESS
27
27
  console.log('');
28
28
  }
29
29
  exports.printDiff = printDiff;
30
- function printChanges(tree, isDryRun, diffContextLines = 1, shouldPrintDryRunMessage = true, noDiffMessage, changePredicate) {
30
+ function printAndFlushChanges(tree, isDryRun, diffContextLines = 1, shouldPrintDryRunMessage = true, noDiffMessage, changePredicate) {
31
31
  changePredicate = changePredicate || (() => true);
32
32
  const changes = tree.listChanges();
33
33
  console.log('');
@@ -57,4 +57,4 @@ function printChanges(tree, isDryRun, diffContextLines = 1, shouldPrintDryRunMes
57
57
  devkit_exports_1.logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
58
58
  }
59
59
  }
60
- exports.printChanges = printChanges;
60
+ exports.printAndFlushChanges = printAndFlushChanges;
@@ -8,7 +8,10 @@ async function resolveNxJsonConfigErrorMessage(propPath) {
8
8
  const errorLines = await getJsonConfigLinesForErrorMessage((0, node_fs_1.readFileSync)((0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, 'nx.json'), 'utf-8'), propPath);
9
9
  let nxJsonMessage = `The relevant config is defined here: ${(0, node_path_1.relative)(process.cwd(), (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, 'nx.json'))}`;
10
10
  if (errorLines) {
11
- nxJsonMessage += `, lines ${errorLines.startLine}-${errorLines.endLine}`;
11
+ nxJsonMessage +=
12
+ errorLines.startLine === errorLines.endLine
13
+ ? `, line ${errorLines.startLine}`
14
+ : `, lines ${errorLines.startLine}-${errorLines.endLine}`;
12
15
  }
13
16
  return nxJsonMessage;
14
17
  }
@@ -0,0 +1,4 @@
1
+ import { ProjectGraph } from '../../../config/project-graph';
2
+ import { NxReleaseConfig } from '../config/config';
3
+ export declare function resolveSemverSpecifierFromConventionalCommits(from: string, projectGraph: ProjectGraph, projectNames: string[], conventionalCommitsConfig: NxReleaseConfig['conventionalCommits']): Promise<string | null>;
4
+ export declare function resolveSemverSpecifierFromPrompt(selectionMessage: string, customVersionMessage: string): Promise<string>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSemverSpecifierFromPrompt = exports.resolveSemverSpecifierFromConventionalCommits = void 0;
4
+ const enquirer_1 = require("enquirer");
5
+ const semver_1 = require("semver");
6
+ const git_1 = require("./git");
7
+ const semver_2 = require("./semver");
8
+ const shared_1 = require("./shared");
9
+ async function resolveSemverSpecifierFromConventionalCommits(from, projectGraph, projectNames, conventionalCommitsConfig) {
10
+ const commits = await (0, git_1.getGitDiff)(from);
11
+ const parsedCommits = (0, git_1.parseCommits)(commits);
12
+ const relevantCommits = await (0, shared_1.getCommitsRelevantToProjects)(projectGraph, parsedCommits, projectNames);
13
+ return (0, semver_2.determineSemverChange)(relevantCommits, conventionalCommitsConfig);
14
+ }
15
+ exports.resolveSemverSpecifierFromConventionalCommits = resolveSemverSpecifierFromConventionalCommits;
16
+ async function resolveSemverSpecifierFromPrompt(selectionMessage, customVersionMessage) {
17
+ try {
18
+ const reply = await (0, enquirer_1.prompt)([
19
+ {
20
+ name: 'specifier',
21
+ message: selectionMessage,
22
+ type: 'select',
23
+ choices: [
24
+ ...semver_1.RELEASE_TYPES.map((t) => ({ name: t, message: t })),
25
+ {
26
+ name: 'custom',
27
+ message: 'Custom exact version',
28
+ },
29
+ ],
30
+ },
31
+ ]);
32
+ if (reply.specifier !== 'custom') {
33
+ return reply.specifier;
34
+ }
35
+ else {
36
+ const reply = await (0, enquirer_1.prompt)([
37
+ {
38
+ name: 'specifier',
39
+ message: customVersionMessage,
40
+ type: 'input',
41
+ validate: (input) => {
42
+ if ((0, semver_1.valid)(input)) {
43
+ return true;
44
+ }
45
+ return 'Please enter a valid semver version';
46
+ },
47
+ },
48
+ ]);
49
+ return reply.specifier;
50
+ }
51
+ }
52
+ catch {
53
+ // TODO: log the error to the user?
54
+ // We need to catch the error from enquirer prompt, otherwise yargs will print its help
55
+ process.exit(1);
56
+ }
57
+ }
58
+ exports.resolveSemverSpecifierFromPrompt = resolveSemverSpecifierFromPrompt;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Special thanks to changelogen for the original inspiration for many of these utilities:
3
+ * https://github.com/unjs/changelogen
4
+ */
1
5
  import { ReleaseType } from 'semver';
6
+ import { NxReleaseConfig } from '../config/config';
7
+ import { GitCommit } from './git';
2
8
  export declare function isRelativeVersionKeyword(val: string): val is ReleaseType;
9
+ export declare function isValidSemverSpecifier(specifier: string): boolean;
10
+ export declare function determineSemverChange(commits: GitCommit[], config: NxReleaseConfig['conventionalCommits']): 'patch' | 'minor' | 'major' | null;
3
11
  export declare function deriveNewSemverVersion(currentSemverVersion: string, semverSpecifier: string, preid?: string): string;
@@ -1,11 +1,40 @@
1
1
  "use strict";
2
+ /**
3
+ * Special thanks to changelogen for the original inspiration for many of these utilities:
4
+ * https://github.com/unjs/changelogen
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deriveNewSemverVersion = exports.isRelativeVersionKeyword = void 0;
7
+ exports.deriveNewSemverVersion = exports.determineSemverChange = exports.isValidSemverSpecifier = exports.isRelativeVersionKeyword = void 0;
4
8
  const semver_1 = require("semver");
5
9
  function isRelativeVersionKeyword(val) {
6
10
  return semver_1.RELEASE_TYPES.includes(val);
7
11
  }
8
12
  exports.isRelativeVersionKeyword = isRelativeVersionKeyword;
13
+ function isValidSemverSpecifier(specifier) {
14
+ return (specifier && !!((0, semver_1.valid)(specifier) || isRelativeVersionKeyword(specifier)));
15
+ }
16
+ exports.isValidSemverSpecifier = isValidSemverSpecifier;
17
+ // https://github.com/unjs/changelogen/blob/main/src/semver.ts
18
+ function determineSemverChange(commits, config) {
19
+ let [hasMajor, hasMinor, hasPatch] = [false, false, false];
20
+ for (const commit of commits) {
21
+ const semverType = config.types[commit.type]?.semverBump;
22
+ if (semverType === 'major' || commit.isBreaking) {
23
+ hasMajor = true;
24
+ }
25
+ else if (semverType === 'minor') {
26
+ hasMinor = true;
27
+ }
28
+ else if (semverType === 'patch') {
29
+ hasPatch = true;
30
+ }
31
+ else if (semverType === 'none' || !semverType) {
32
+ // do not report a change
33
+ }
34
+ }
35
+ return hasMajor ? 'major' : hasMinor ? 'minor' : hasPatch ? 'patch' : null;
36
+ }
37
+ exports.determineSemverChange = determineSemverChange;
9
38
  function deriveNewSemverVersion(currentSemverVersion, semverSpecifier, preid) {
10
39
  if (!(0, semver_1.valid)(currentSemverVersion)) {
11
40
  throw new Error(`Invalid semver version "${currentSemverVersion}" provided.`);
@@ -0,0 +1,39 @@
1
+ import { ProjectGraph } from '../../../config/project-graph';
2
+ import { Tree } from '../../../generators/tree';
3
+ import type { ReleaseGroupWithName } from '../config/filter-release-groups';
4
+ import { GitCommit } from './git';
5
+ export declare const noDiffInChangelogMessage: string;
6
+ export type ReleaseVersionGeneratorResult = {
7
+ data: VersionData;
8
+ callback: (tree: Tree, opts: {
9
+ dryRun?: boolean;
10
+ verbose?: boolean;
11
+ generatorOptions?: Record<string, unknown>;
12
+ }) => Promise<string[]>;
13
+ };
14
+ export type VersionData = Record<string, {
15
+ /**
16
+ * newVersion will be null in the case that no changes are detected for the project,
17
+ * e.g. when using conventional commits
18
+ */
19
+ newVersion: string | null;
20
+ currentVersion: string;
21
+ dependentProjects: any[];
22
+ }>;
23
+ export declare class ReleaseVersion {
24
+ rawVersion: string;
25
+ gitTag: string;
26
+ isPrerelease: boolean;
27
+ constructor({ version, // short form version string with no prefixes or patterns, e.g. 1.0.0
28
+ releaseTagPattern, // full pattern to interpolate, e.g. "v{version}" or "{projectName}@{version}"
29
+ projectName, }: {
30
+ version: string;
31
+ releaseTagPattern: string;
32
+ projectName?: string;
33
+ });
34
+ }
35
+ export declare function commitChanges(changedFiles: string[], isDryRun: boolean, isVerbose: boolean, gitCommitMessages: string[], gitCommitArgs?: string): Promise<void>;
36
+ export declare function createCommitMessageValues(releaseGroups: ReleaseGroupWithName[], releaseGroupToFilteredProjects: Map<ReleaseGroupWithName, Set<string>>, versionData: VersionData, commitMessage: string): string[];
37
+ export declare function createGitTagValues(releaseGroups: ReleaseGroupWithName[], releaseGroupToFilteredProjects: Map<ReleaseGroupWithName, Set<string>>, versionData: VersionData): string[];
38
+ export declare function handleDuplicateGitTags(gitTagValues: string[]): void;
39
+ export declare function getCommitsRelevantToProjects(projectGraph: ProjectGraph, commits: GitCommit[], projects: string[]): Promise<GitCommit[]>;
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommitsRelevantToProjects = exports.handleDuplicateGitTags = exports.createGitTagValues = exports.createCommitMessageValues = exports.commitChanges = exports.ReleaseVersion = exports.noDiffInChangelogMessage = void 0;
4
+ const chalk = require("chalk");
5
+ const semver_1 = require("semver");
6
+ const file_map_utils_1 = require("../../../project-graph/file-map-utils");
7
+ const utils_1 = require("../../../tasks-runner/utils");
8
+ const output_1 = require("../../../utils/output");
9
+ const git_1 = require("./git");
10
+ exports.noDiffInChangelogMessage = chalk.yellow(`NOTE: There was no diff detected for the changelog entry. Maybe you intended to pass alternative git references via --from and --to?`);
11
+ function isPrerelease(version) {
12
+ // prerelease returns an array of matching prerelease "components", or null if the version is not a prerelease
13
+ return (0, semver_1.prerelease)(version) !== null;
14
+ }
15
+ class ReleaseVersion {
16
+ constructor({ version, // short form version string with no prefixes or patterns, e.g. 1.0.0
17
+ releaseTagPattern, // full pattern to interpolate, e.g. "v{version}" or "{projectName}@{version}"
18
+ projectName, // optional project name to interpolate into the releaseTagPattern
19
+ }) {
20
+ this.rawVersion = version;
21
+ this.gitTag = (0, utils_1.interpolate)(releaseTagPattern, {
22
+ version,
23
+ projectName,
24
+ });
25
+ this.isPrerelease = isPrerelease(version);
26
+ }
27
+ }
28
+ exports.ReleaseVersion = ReleaseVersion;
29
+ async function commitChanges(changedFiles, isDryRun, isVerbose, gitCommitMessages, gitCommitArgs) {
30
+ if (!changedFiles.length) {
31
+ throw new Error('Error: No changed files to commit');
32
+ }
33
+ output_1.output.logSingleLine(`Committing changes with git`);
34
+ await (0, git_1.gitAdd)({
35
+ changedFiles,
36
+ dryRun: isDryRun,
37
+ verbose: isVerbose,
38
+ });
39
+ // The extra logs need something breathing room
40
+ if (isVerbose) {
41
+ console.log('');
42
+ }
43
+ await (0, git_1.gitCommit)({
44
+ messages: gitCommitMessages,
45
+ additionalArgs: gitCommitArgs,
46
+ dryRun: isDryRun,
47
+ verbose: isVerbose,
48
+ });
49
+ }
50
+ exports.commitChanges = commitChanges;
51
+ function createCommitMessageValues(releaseGroups, releaseGroupToFilteredProjects, versionData, commitMessage) {
52
+ const commitMessageValues = [commitMessage];
53
+ if (releaseGroups.length === 0) {
54
+ return commitMessageValues;
55
+ }
56
+ // If we have exactly one release group, with a fixed relationship, then interpolate {version} as the new version for the release group
57
+ if (releaseGroups.length === 1 &&
58
+ releaseGroups[0].projectsRelationship === 'fixed') {
59
+ const releaseGroup = releaseGroups[0];
60
+ const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
61
+ const projectVersionData = versionData[releaseGroupProjectNames[0]]; // all at the same version, so we can just pick the first one
62
+ const releaseVersion = new ReleaseVersion({
63
+ version: projectVersionData.newVersion,
64
+ releaseTagPattern: releaseGroup.releaseTagPattern,
65
+ });
66
+ commitMessageValues[0] = (0, utils_1.interpolate)(commitMessageValues[0], {
67
+ version: releaseVersion.rawVersion,
68
+ }).trim();
69
+ return commitMessageValues;
70
+ }
71
+ /**
72
+ * There is another special case for interpolation: if, after all filtering, we have a single independent release group with a single project,
73
+ * and the user has provided {projectName} within the custom message.
74
+ * In this case we will directly interpolate both {version} and {projectName} within the commit message.
75
+ */
76
+ if (releaseGroups.length === 1 &&
77
+ releaseGroups[0].projectsRelationship === 'independent' &&
78
+ commitMessage.includes('{projectName}')) {
79
+ const releaseGroup = releaseGroups[0];
80
+ const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
81
+ if (releaseGroupProjectNames.length === 1) {
82
+ const projectVersionData = versionData[releaseGroupProjectNames[0]];
83
+ const releaseVersion = new ReleaseVersion({
84
+ version: projectVersionData.newVersion,
85
+ releaseTagPattern: releaseGroup.releaseTagPattern,
86
+ projectName: releaseGroupProjectNames[0],
87
+ });
88
+ commitMessageValues[0] = (0, utils_1.interpolate)(commitMessageValues[0], {
89
+ version: releaseVersion.rawVersion,
90
+ projectName: releaseGroupProjectNames[0],
91
+ }).trim();
92
+ return commitMessageValues;
93
+ }
94
+ }
95
+ /**
96
+ * At this point we have multiple release groups for a single commit, we will not interpolate an overall {version} or {projectName} because that won't be
97
+ * appropriate (for any {version} or {projectName} value within the string, we will replace it with an empty string so that it doesn't end up in the final output).
98
+ *
99
+ * Instead for fixed groups we will add one bullet point the release group, and for independent groups we will add one bullet point per project.
100
+ */
101
+ commitMessageValues[0] = stripPlaceholders(commitMessageValues[0], [
102
+ // for cleanest possible final result try and replace the common pattern of a v prefix in front of the version first
103
+ 'v{version}',
104
+ '{version}',
105
+ '{projectName}',
106
+ ]);
107
+ for (const releaseGroup of releaseGroups) {
108
+ const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
109
+ // One entry per project for independent groups
110
+ if (releaseGroup.projectsRelationship === 'independent') {
111
+ for (const project of releaseGroupProjectNames) {
112
+ const projectVersionData = versionData[project];
113
+ if (projectVersionData.newVersion !== null) {
114
+ const releaseVersion = new ReleaseVersion({
115
+ version: projectVersionData.newVersion,
116
+ releaseTagPattern: releaseGroup.releaseTagPattern,
117
+ projectName: project,
118
+ });
119
+ commitMessageValues.push(`- project: ${project} ${releaseVersion.rawVersion}`);
120
+ }
121
+ }
122
+ continue;
123
+ }
124
+ // One entry for the whole group for fixed groups
125
+ const projectVersionData = versionData[releaseGroupProjectNames[0]]; // all at the same version, so we can just pick the first one
126
+ const releaseVersion = new ReleaseVersion({
127
+ version: projectVersionData.newVersion,
128
+ releaseTagPattern: releaseGroup.releaseTagPattern,
129
+ });
130
+ commitMessageValues.push(`- release-group: ${releaseGroup.name} ${releaseVersion.rawVersion}`);
131
+ }
132
+ return commitMessageValues;
133
+ }
134
+ exports.createCommitMessageValues = createCommitMessageValues;
135
+ function stripPlaceholders(str, placeholders) {
136
+ for (const placeholder of placeholders) {
137
+ // for cleanest possible final result try and replace relevant spacing around placeholders first
138
+ str = str
139
+ .replace(` ${placeholder}`, '')
140
+ .replace(`${placeholder} `, '')
141
+ .replace(placeholder, '')
142
+ .trim();
143
+ }
144
+ return str;
145
+ }
146
+ function createGitTagValues(releaseGroups, releaseGroupToFilteredProjects, versionData) {
147
+ const tags = [];
148
+ for (const releaseGroup of releaseGroups) {
149
+ const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
150
+ // For independent groups we want one tag per project, not one for the overall group
151
+ if (releaseGroup.projectsRelationship === 'independent') {
152
+ for (const project of releaseGroupProjectNames) {
153
+ const projectVersionData = versionData[project];
154
+ if (projectVersionData.newVersion !== null) {
155
+ tags.push((0, utils_1.interpolate)(releaseGroup.releaseTagPattern, {
156
+ version: projectVersionData.newVersion,
157
+ projectName: project,
158
+ }));
159
+ }
160
+ }
161
+ continue;
162
+ }
163
+ // For fixed groups we want one tag for the overall group
164
+ const projectVersionData = versionData[releaseGroupProjectNames[0]]; // all at the same version, so we can just pick the first one
165
+ tags.push((0, utils_1.interpolate)(releaseGroup.releaseTagPattern, {
166
+ version: projectVersionData.newVersion,
167
+ }));
168
+ }
169
+ return tags;
170
+ }
171
+ exports.createGitTagValues = createGitTagValues;
172
+ function findDuplicates(arr) {
173
+ const seen = new Set();
174
+ const duplicates = new Set();
175
+ for (const item of arr) {
176
+ if (seen.has(item)) {
177
+ duplicates.add(item);
178
+ }
179
+ else {
180
+ seen.add(item);
181
+ }
182
+ }
183
+ return Array.from(duplicates);
184
+ }
185
+ function handleDuplicateGitTags(gitTagValues) {
186
+ // If any of the gitTagValues are identical we should hard error upfront to avoid an awkward git error later
187
+ const duplicateGitTagValues = findDuplicates(gitTagValues);
188
+ if (duplicateGitTagValues.length) {
189
+ output_1.output.error({
190
+ title: `Your current configuration would generate the following duplicate git tags:`,
191
+ bodyLines: [
192
+ ...duplicateGitTagValues.map((v) => `- ${v}`),
193
+ '',
194
+ `Please ensure that for "independent" release groups the {projectName} placeholder is used so that all dynamically created project tags are unique.`,
195
+ ],
196
+ });
197
+ process.exit(1);
198
+ }
199
+ }
200
+ exports.handleDuplicateGitTags = handleDuplicateGitTags;
201
+ async function getCommitsRelevantToProjects(projectGraph, commits, projects) {
202
+ const { fileMap } = await (0, file_map_utils_1.createFileMapUsingProjectGraph)(projectGraph);
203
+ const filesInReleaseGroup = new Set(projects.reduce((files, p) => [...files, ...fileMap.projectFileMap[p].map((f) => f.file)], []));
204
+ /**
205
+ * The relevant commits are those that either:
206
+ * - touch project files which are contained within the list of projects directly
207
+ * - touch non-project files and the commit is not scoped
208
+ */
209
+ return commits.filter((c) => c.affectedFiles.some((f) => filesInReleaseGroup.has(f) ||
210
+ (!c.scope &&
211
+ fileMap.nonProjectFiles.some((nonProjectFile) => nonProjectFile.file === f))));
212
+ }
213
+ exports.getCommitsRelevantToProjects = getCommitsRelevantToProjects;
@@ -1,13 +1,47 @@
1
1
  import { ProjectGraph, ProjectGraphProjectNode } from '../../config/project-graph';
2
2
  import { VersionOptions } from './command-object';
3
+ import { NxReleaseConfig } from './config/config';
4
+ import { ReleaseGroupWithName } from './config/filter-release-groups';
5
+ import { VersionData } from './utils/shared';
3
6
  export { deriveNewSemverVersion } from './utils/semver';
7
+ export type { ReleaseVersionGeneratorResult, VersionData, } from './utils/shared';
8
+ export declare const validReleaseVersionPrefixes: readonly ["auto", "", "~", "^", "="];
4
9
  export interface ReleaseVersionGeneratorSchema {
5
10
  projects: ProjectGraphProjectNode[];
11
+ releaseGroup: ReleaseGroupWithName;
6
12
  projectGraph: ProjectGraph;
7
- specifier: string;
13
+ specifier?: string;
14
+ specifierSource?: 'prompt' | 'conventional-commits';
8
15
  preid?: string;
9
16
  packageRoot?: string;
10
- currentVersionResolver?: 'registry' | 'disk';
17
+ currentVersionResolver?: 'registry' | 'disk' | 'git-tag';
11
18
  currentVersionResolverMetadata?: Record<string, unknown>;
19
+ fallbackCurrentVersionResolver?: 'disk';
20
+ firstRelease?: boolean;
21
+ versionPrefix?: typeof validReleaseVersionPrefixes[number];
22
+ skipLockFileUpdate?: boolean;
23
+ installArgs?: string;
24
+ installIgnoreScripts?: boolean;
25
+ conventionalCommitsConfig?: NxReleaseConfig['conventionalCommits'];
12
26
  }
13
- export declare function versionHandler(args: VersionOptions): Promise<void>;
27
+ export interface NxReleaseVersionResult {
28
+ /**
29
+ * In one specific (and very common) case, an overall workspace version is relevant, for example when there is
30
+ * only a single release group in which all projects have a fixed relationship to each other. In this case, the
31
+ * overall workspace version is the same as the version of the release group (and every project within it). This
32
+ * version could be a `string`, or it could be `null` if using conventional commits and no changes were detected.
33
+ *
34
+ * In all other cases (independent versioning, multiple release groups etc), the overall workspace version is
35
+ * not applicable and will be `undefined` here. If a user attempts to use this value later when it is `undefined`
36
+ * (for example in the changelog command), we will throw an appropriate error.
37
+ */
38
+ workspaceVersion: (string | null) | undefined;
39
+ projectsVersionData: VersionData;
40
+ }
41
+ export declare const releaseVersionCLIHandler: (args: VersionOptions) => Promise<any>;
42
+ /**
43
+ * NOTE: This function is also exported for programmatic usage and forms part of the public API
44
+ * of Nx. We intentionally do not wrap the implementation with handleErrors because users need
45
+ * to have control over their own error handling when using the API.
46
+ */
47
+ export declare function releaseVersion(args: VersionOptions): Promise<NxReleaseVersionResult>;