nx 21.0.0-beta.0 → 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 (242) 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 +134 -101
  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/nx-deps-cache.js +7 -2
  154. package/src/project-graph/plugins/get-plugins.js +2 -1
  155. package/src/project-graph/plugins/in-process-loader.js +1 -1
  156. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  157. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  158. package/src/project-graph/plugins/loaded-nx-plugin.js +3 -7
  159. package/src/project-graph/plugins/public-api.d.ts +1 -1
  160. package/src/project-graph/plugins/utils.d.ts +2 -2
  161. package/src/project-graph/plugins/utils.js +2 -2
  162. package/src/project-graph/project-graph.js +5 -2
  163. package/src/project-graph/utils/project-configuration-utils.d.ts +3 -3
  164. package/src/project-graph/utils/project-configuration-utils.js +54 -21
  165. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  166. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  167. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  168. package/src/tasks-runner/batch/run-batch.js +3 -4
  169. package/src/tasks-runner/cache.d.ts +20 -6
  170. package/src/tasks-runner/cache.js +104 -20
  171. package/src/tasks-runner/create-task-graph.d.ts +0 -1
  172. package/src/tasks-runner/create-task-graph.js +11 -11
  173. package/src/tasks-runner/default-tasks-runner.js +5 -14
  174. package/src/tasks-runner/forked-process-task-runner.d.ts +8 -3
  175. package/src/tasks-runner/forked-process-task-runner.js +59 -46
  176. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  177. package/src/tasks-runner/init-tasks-runner.js +62 -2
  178. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  179. package/src/tasks-runner/is-tui-enabled.js +64 -0
  180. package/src/tasks-runner/life-cycle.d.ts +14 -3
  181. package/src/tasks-runner/life-cycle.js +37 -2
  182. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.d.ts +2 -0
  183. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +15 -7
  184. package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts +5 -0
  185. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +35 -5
  186. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +18 -0
  187. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +229 -0
  188. package/src/tasks-runner/pseudo-terminal.d.ts +10 -7
  189. package/src/tasks-runner/pseudo-terminal.js +37 -35
  190. package/src/tasks-runner/run-command.d.ts +4 -1
  191. package/src/tasks-runner/run-command.js +220 -42
  192. package/src/tasks-runner/running-tasks/node-child-process.js +4 -11
  193. package/src/tasks-runner/running-tasks/running-task.d.ts +3 -0
  194. package/src/tasks-runner/running-tasks/shared-running-task.d.ts +14 -0
  195. package/src/tasks-runner/running-tasks/shared-running-task.js +30 -0
  196. package/src/tasks-runner/task-env.d.ts +1 -4
  197. package/src/tasks-runner/task-env.js +2 -0
  198. package/src/tasks-runner/task-orchestrator.d.ts +26 -10
  199. package/src/tasks-runner/task-orchestrator.js +212 -57
  200. package/src/tasks-runner/tasks-runner.d.ts +1 -0
  201. package/src/tasks-runner/tasks-schedule.d.ts +1 -0
  202. package/src/tasks-runner/tasks-schedule.js +9 -0
  203. package/src/tasks-runner/utils.d.ts +2 -2
  204. package/src/tasks-runner/utils.js +18 -12
  205. package/src/utils/child-process.d.ts +4 -0
  206. package/src/utils/child-process.js +23 -30
  207. package/src/utils/command-line-utils.d.ts +1 -1
  208. package/src/utils/find-matching-projects.js +2 -2
  209. package/src/utils/git-utils.d.ts +1 -1
  210. package/src/utils/git-utils.js +8 -3
  211. package/src/utils/handle-errors.js +15 -0
  212. package/src/utils/is-ci.js +4 -1
  213. package/src/utils/is-using-prettier.d.ts +3 -0
  214. package/src/utils/is-using-prettier.js +62 -0
  215. package/src/utils/nx-key.d.ts +7 -0
  216. package/src/utils/nx-key.js +52 -0
  217. package/src/utils/package-json.d.ts +1 -1
  218. package/src/utils/package-json.js +16 -2
  219. package/src/utils/package-manager.js +2 -2
  220. package/src/utils/path.js +1 -1
  221. package/src/utils/require-nx-key.d.ts +1 -0
  222. package/src/utils/require-nx-key.js +22 -0
  223. package/src/utils/workspace-context.d.ts +2 -0
  224. package/src/utils/workspace-context.js +16 -0
  225. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  226. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  227. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  228. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  229. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  230. package/src/migrations/update-17-0-0/move-cache-directory.d.ts +0 -2
  231. package/src/migrations/update-17-0-0/move-cache-directory.js +0 -35
  232. package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +0 -72
  233. package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.d.ts +0 -2
  234. package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +0 -122
  235. package/src/migrations/update-17-2-0/move-default-base.d.ts +0 -5
  236. package/src/migrations/update-17-2-0/move-default-base.js +0 -21
  237. package/src/migrations/update-17-3-0/nx-release-path.d.ts +0 -3
  238. package/src/migrations/update-17-3-0/nx-release-path.js +0 -47
  239. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +0 -2
  240. package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +0 -11
  241. package/src/utils/powerpack.d.ts +0 -5
  242. package/src/utils/powerpack.js +0 -33
@@ -0,0 +1,32 @@
1
+ import type { ProjectGraphProjectNode } from '../../../config/project-graph';
2
+ import type { Tree } from '../../../generators/tree';
3
+ import type { ReleaseGroupWithName } from '../config/filter-release-groups';
4
+ import { getLatestGitTagForPattern } from '../utils/git';
5
+ import { ProjectLogger } from './project-logger';
6
+ import type { FinalConfigForProject } from './release-group-processor';
7
+ import { VersionActions } from './version-actions';
8
+ export declare function resolveCurrentVersion(tree: Tree, projectGraphNode: ProjectGraphProjectNode, releaseGroup: ReleaseGroupWithName, versionActions: VersionActions, logger: ProjectLogger, cachedCurrentVersionsPerFixedReleaseGroup: Map<string, // release group name
9
+ {
10
+ currentVersion: string;
11
+ originatingProjectName: string;
12
+ logText: string;
13
+ }>, finalConfigForProject: FinalConfigForProject, releaseTagPattern: string, latestMatchingGitTag?: Awaited<ReturnType<typeof getLatestGitTagForPattern>>): Promise<string | null>;
14
+ /**
15
+ * Attempt to resolve the current version from the manifest file on disk.
16
+ *
17
+ * Not all VersionActions implementations support a manifest file, in which case the logic will handle either thrown errors
18
+ * or null values being returned from the readCurrentVersionFromSourceManifest method and throw a clear user-facing error.
19
+ */
20
+ export declare function resolveCurrentVersionFromDisk(tree: Tree, projectGraphNode: ProjectGraphProjectNode, versionActions: VersionActions, logger: ProjectLogger): Promise<string>;
21
+ export declare function resolveCurrentVersionFromRegistry(tree: Tree, projectGraphNode: ProjectGraphProjectNode, releaseGroup: ReleaseGroupWithName, versionActions: VersionActions, logger: ProjectLogger, cachedCurrentVersionsPerFixedReleaseGroup: Map<string, // release group name
22
+ {
23
+ currentVersion: string;
24
+ originatingProjectName: string;
25
+ logText?: string;
26
+ }>, finalConfigForProject: FinalConfigForProject): Promise<string>;
27
+ export declare function resolveCurrentVersionFromGitTag(tree: Tree, projectGraphNode: ProjectGraphProjectNode, releaseGroup: ReleaseGroupWithName, versionActions: VersionActions, logger: ProjectLogger, cachedCurrentVersionsPerFixedReleaseGroup: Map<string, // release group name
28
+ {
29
+ currentVersion: string;
30
+ originatingProjectName: string;
31
+ logText: string;
32
+ }>, finalConfigForProject: FinalConfigForProject, releaseTagPattern: string, latestMatchingGitTag?: Awaited<ReturnType<typeof getLatestGitTagForPattern>>): Promise<string>;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveCurrentVersion = resolveCurrentVersion;
4
+ exports.resolveCurrentVersionFromDisk = resolveCurrentVersionFromDisk;
5
+ exports.resolveCurrentVersionFromRegistry = resolveCurrentVersionFromRegistry;
6
+ exports.resolveCurrentVersionFromGitTag = resolveCurrentVersionFromGitTag;
7
+ const chalk = require("chalk");
8
+ const enquirer_1 = require("enquirer");
9
+ const ora = require("ora");
10
+ async function resolveCurrentVersion(tree, projectGraphNode, releaseGroup, versionActions, logger, cachedCurrentVersionsPerFixedReleaseGroup, finalConfigForProject, releaseTagPattern, latestMatchingGitTag) {
11
+ switch (finalConfigForProject.currentVersionResolver) {
12
+ case 'none':
13
+ return null;
14
+ case 'disk': {
15
+ return resolveCurrentVersionFromDisk(tree, projectGraphNode, versionActions, logger);
16
+ }
17
+ case 'registry': {
18
+ return resolveCurrentVersionFromRegistry(tree, projectGraphNode, releaseGroup, versionActions, logger, cachedCurrentVersionsPerFixedReleaseGroup, finalConfigForProject);
19
+ }
20
+ case 'git-tag': {
21
+ return resolveCurrentVersionFromGitTag(tree, projectGraphNode, releaseGroup, versionActions, logger, cachedCurrentVersionsPerFixedReleaseGroup, finalConfigForProject, releaseTagPattern, latestMatchingGitTag);
22
+ }
23
+ default:
24
+ throw new Error(`Invalid value for "currentVersionResolver": ${finalConfigForProject.currentVersionResolver}`);
25
+ }
26
+ }
27
+ /**
28
+ * Attempt to resolve the current version from the manifest file on disk.
29
+ *
30
+ * Not all VersionActions implementations support a manifest file, in which case the logic will handle either thrown errors
31
+ * or null values being returned from the readCurrentVersionFromSourceManifest method and throw a clear user-facing error.
32
+ */
33
+ async function resolveCurrentVersionFromDisk(tree, projectGraphNode, versionActions, logger) {
34
+ if (!versionActions.validManifestFilenames?.length) {
35
+ throw new Error(`For project "${projectGraphNode.name}", the "currentVersionResolver" is set to "disk" but it is using "versionActions" of type "${versionActions.constructor.name}". This is invalid because "${versionActions.constructor.name}" does not support a manifest file. You should use a different "currentVersionResolver" or use a different "versionActions" implementation that supports a manifest file`);
36
+ }
37
+ const nullVersionError = new Error(`For project "${projectGraphNode.name}", the "currentVersionResolver" is set to "disk" and it is using "versionActions" of type "${versionActions.constructor.name}" which failed to resolve the current version from the manifest file on disk`);
38
+ try {
39
+ const res = await versionActions.readCurrentVersionFromSourceManifest(tree);
40
+ if (!res) {
41
+ throw nullVersionError;
42
+ }
43
+ const { currentVersion, manifestPath } = res;
44
+ logger.buffer(`📄 Resolved the current version as ${currentVersion} from manifest: ${manifestPath}`);
45
+ return currentVersion;
46
+ }
47
+ catch (err) {
48
+ if (err === nullVersionError) {
49
+ throw err;
50
+ }
51
+ throw new Error(`The project "${projectGraphNode.name}" does not have a ${versionActions.validManifestFilenames.join(' or ')} file available in ./${projectGraphNode.data.root}.
52
+
53
+ To fix this you will either need to add a ${versionActions.validManifestFilenames.join(' or ')} file at that location, or configure "release" within your nx.json to use a different "currentVersionResolver" or "versionActions" implementation that supports this setup`);
54
+ }
55
+ }
56
+ async function resolveCurrentVersionFromRegistry(tree, projectGraphNode, releaseGroup, versionActions, logger, cachedCurrentVersionsPerFixedReleaseGroup, finalConfigForProject) {
57
+ /**
58
+ * In the case of fixed release groups that are configured to resolve the current version from a registry,
59
+ * it would be a waste of time and resources to make requests to the registry, or resolve one of the fallbacks,
60
+ * for each individual project, therefore we maintain a cache of the current version for each applicable release group here.
61
+ */
62
+ const cached = cachedCurrentVersionsPerFixedReleaseGroup.get(releaseGroup.name);
63
+ if (cached) {
64
+ const logText = cached.logText ? ` ${cached.logText}` : '';
65
+ logger.buffer(`🔄 Reusing the current version ${cached.currentVersion} already resolved for ${cached.originatingProjectName}${logText}`);
66
+ return cached.currentVersion;
67
+ }
68
+ let registryTxt = '';
69
+ const spinner = ora(`Resolving the current version for ${projectGraphNode.name} from the configured registry...`);
70
+ spinner.color = 'cyan';
71
+ spinner.start();
72
+ try {
73
+ const res = await versionActions.readCurrentVersionFromRegistry(tree, finalConfigForProject.currentVersionResolverMetadata);
74
+ if (!res) {
75
+ // Not a user-facing error
76
+ throw new Error('Registry not applicable for this version actions implementation');
77
+ }
78
+ const { currentVersion, logText } = res;
79
+ spinner.stop();
80
+ registryTxt = logText?.length > 0 ? `: ${logText}` : '';
81
+ if (!currentVersion) {
82
+ // Not a user-facing error
83
+ throw new Error('No version found in the registry');
84
+ }
85
+ logger.buffer(`🔍 Resolved the current version as ${currentVersion} from the remote registry${registryTxt}`);
86
+ // Write to the cache if the release group is fixed
87
+ if (releaseGroup.projectsRelationship === 'fixed') {
88
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
89
+ currentVersion,
90
+ originatingProjectName: projectGraphNode.name,
91
+ logText: `from the registry${registryTxt}`,
92
+ });
93
+ }
94
+ return currentVersion;
95
+ }
96
+ catch {
97
+ spinner.stop();
98
+ if (finalConfigForProject.fallbackCurrentVersionResolver === 'disk') {
99
+ if (!versionActions.validManifestFilenames?.length) {
100
+ throw new Error(`For project "${projectGraphNode.name}", the "currentVersionResolver" is set to "registry" with a "fallbackCurrentVersionResolver" of "disk" but it is using "versionActions" of type "${versionActions.constructor.name}". This is invalid because "${versionActions.constructor.name}" does not support a manifest file. You should use a different "fallbackCurrentVersionResolver" or use a different "versionActions" implementation that supports a manifest file`);
101
+ }
102
+ const fromDiskRes = await versionActions.readCurrentVersionFromSourceManifest(tree);
103
+ // Fallback on disk is available, return it directly
104
+ if (fromDiskRes && fromDiskRes.currentVersion) {
105
+ logger.buffer(`⚠️ Unable to resolve the current version from the registry${registryTxt}. Falling back to the version ${fromDiskRes.currentVersion} in manifest: ${fromDiskRes.manifestPath}`);
106
+ // Write to the cache if the release group is fixed
107
+ if (releaseGroup.projectsRelationship === 'fixed') {
108
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
109
+ currentVersion: fromDiskRes.currentVersion,
110
+ originatingProjectName: projectGraphNode.name,
111
+ logText: `from the disk fallback`,
112
+ });
113
+ }
114
+ return fromDiskRes.currentVersion;
115
+ }
116
+ }
117
+ // At this point the fallback on disk is also not available/configured, allow one final interactive fallback, but only when using version-plans or conventional-commits
118
+ if (finalConfigForProject.specifierSource === 'prompt') {
119
+ throw new Error(`Unable to resolve the current version from the registry${registryTxt}. Please ensure that the package exists in the registry in order to use the "registry" currentVersionResolver. Alternatively, you can use the --first-release option or set "release.version.fallbackCurrentVersionResolver" to "disk" in order to fallback to the version on disk when the registry lookup fails.`);
120
+ }
121
+ const currentVersionFromPromptFallback = await handleNoAvailableDiskFallback({
122
+ logger,
123
+ projectName: projectGraphNode.name,
124
+ versionActions,
125
+ specifierSource: finalConfigForProject.specifierSource,
126
+ currentVersionSourceMessage: `from the registry${registryTxt}`,
127
+ resolutionSuggestion: `you should publish an initial version to the registry`,
128
+ });
129
+ // Write to the cache if the release group is fixed
130
+ if (releaseGroup.projectsRelationship === 'fixed') {
131
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
132
+ currentVersion: currentVersionFromPromptFallback,
133
+ originatingProjectName: projectGraphNode.name,
134
+ logText: `from the prompt fallback`,
135
+ });
136
+ }
137
+ return currentVersionFromPromptFallback;
138
+ }
139
+ }
140
+ async function resolveCurrentVersionFromGitTag(tree, projectGraphNode, releaseGroup, versionActions, logger, cachedCurrentVersionsPerFixedReleaseGroup, finalConfigForProject, releaseTagPattern, latestMatchingGitTag) {
141
+ /**
142
+ * In the case of fixed release groups that are configured to resolve the current version from a git tag,
143
+ * it would be a waste of time and resources to figure out the git tag, or resolve one of the fallbacks,
144
+ * for each individual project, therefore we maintain a cache of the current version for each applicable release group here.
145
+ */
146
+ const cached = cachedCurrentVersionsPerFixedReleaseGroup.get(releaseGroup.name);
147
+ if (cached) {
148
+ const logText = cached.logText ? ` ${cached.logText}` : '';
149
+ logger.buffer(`🔄 Reusing the current version ${cached.currentVersion} already resolved for ${cached.originatingProjectName}${logText}`);
150
+ return cached.currentVersion;
151
+ }
152
+ // The latest matching git tag was found in release-group-processor and has an extracted version, return it directly
153
+ if (latestMatchingGitTag && latestMatchingGitTag.extractedVersion) {
154
+ const currentVersion = latestMatchingGitTag.extractedVersion;
155
+ logger.buffer(`🏷️ Resolved the current version as ${currentVersion} from git tag "${latestMatchingGitTag.tag}", based on releaseTagPattern "${releaseTagPattern}"`);
156
+ // Write to the cache if the release group is fixed
157
+ if (releaseGroup.projectsRelationship === 'fixed') {
158
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
159
+ currentVersion,
160
+ originatingProjectName: projectGraphNode.name,
161
+ logText: `from git tag "${latestMatchingGitTag.tag}"`,
162
+ });
163
+ }
164
+ return currentVersion;
165
+ }
166
+ const noMatchingGitTagsError = new Error(`No git tags matching pattern "${releaseTagPattern}" for project "${projectGraphNode.name}" were found. You will need to create an initial matching tag to use as a base for determining the next version. Alternatively, you can use the --first-release option or set "release.version.fallbackCurrentVersionResolver" to "disk" in order to fallback to the version on disk when no matching git tags are found.`);
167
+ if (finalConfigForProject.fallbackCurrentVersionResolver !== 'disk') {
168
+ throw noMatchingGitTagsError;
169
+ }
170
+ const fromDiskRes = await versionActions.readCurrentVersionFromSourceManifest(tree);
171
+ // Fallback on disk is available, return it directly
172
+ if (fromDiskRes && fromDiskRes.currentVersion) {
173
+ logger.buffer(`⚠️ Unable to resolve the current version from git tags using pattern "${releaseTagPattern}". Falling back to the version ${fromDiskRes.currentVersion} in manifest: ${fromDiskRes.manifestPath}`);
174
+ // Write to the cache if the release group is fixed
175
+ if (releaseGroup.projectsRelationship === 'fixed') {
176
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
177
+ currentVersion: fromDiskRes.currentVersion,
178
+ originatingProjectName: projectGraphNode.name,
179
+ logText: `from the disk fallback`,
180
+ });
181
+ }
182
+ return fromDiskRes.currentVersion;
183
+ }
184
+ // At this point the fallback on disk is also not available/configured, allow one final interactive fallback, but only when using version-plans or conventional-commits
185
+ if (finalConfigForProject.specifierSource === 'prompt') {
186
+ throw noMatchingGitTagsError;
187
+ }
188
+ const currentVersionFromPromptFallback = await handleNoAvailableDiskFallback({
189
+ logger,
190
+ projectName: projectGraphNode.name,
191
+ versionActions,
192
+ specifierSource: finalConfigForProject.specifierSource,
193
+ currentVersionSourceMessage: `from git tag using pattern "${releaseTagPattern}"`,
194
+ resolutionSuggestion: `you should set an initial git tag on a relevant commit`,
195
+ });
196
+ // Write to the cache if the release group is fixed
197
+ if (releaseGroup.projectsRelationship === 'fixed') {
198
+ cachedCurrentVersionsPerFixedReleaseGroup.set(releaseGroup.name, {
199
+ currentVersion: currentVersionFromPromptFallback,
200
+ originatingProjectName: projectGraphNode.name,
201
+ logText: `from the prompt fallback`,
202
+ });
203
+ }
204
+ return currentVersionFromPromptFallback;
205
+ }
206
+ /**
207
+ * Allow users to be unblocked when locally running releases for the very first time with certain combinations that require an initial
208
+ * version in order to function (e.g. a relative semver bump derived via conventional-commits or version-plans) by providing an interactive
209
+ * prompt to let them opt into using 0.0.0 as the implied current version.
210
+ */
211
+ async function handleNoAvailableDiskFallback({ logger, projectName, versionActions, specifierSource, currentVersionSourceMessage, resolutionSuggestion, }) {
212
+ if (!versionActions.validManifestFilenames?.length) {
213
+ throw new Error(`Unable to resolve the current version ${currentVersionSourceMessage} and there is no version on disk to fall back to. This is invalid with ${specifierSource} because the new version is determined by relatively bumping the current version. To resolve this, ${resolutionSuggestion}, or set use a versionActions implementation that supports a manifest file`);
214
+ }
215
+ const validManifestFilenames = versionActions.validManifestFilenames.join(' or ');
216
+ const unresolvableCurrentVersionError = new Error(`Unable to resolve the current version ${currentVersionSourceMessage} and there is no version on disk to fall back to. This is invalid with ${specifierSource} because the new version is determined by relatively bumping the current version. To resolve this, ${resolutionSuggestion}, or set an appropriate version in a supported manifest file such as ${validManifestFilenames}`);
217
+ if (process.env.CI === 'true') {
218
+ // We can't prompt in CI, so error immediately
219
+ throw unresolvableCurrentVersionError;
220
+ }
221
+ try {
222
+ const reply = await (0, enquirer_1.prompt)([
223
+ {
224
+ name: 'useZero',
225
+ message: `\n${chalk.yellow(`Warning: Unable to resolve the current version for "${projectName}" ${currentVersionSourceMessage} and there is no version on disk to fall back to. This is invalid with ${specifierSource} because the new version is determined by relatively bumping the current version.\n\nTo resolve this, ${resolutionSuggestion}, or set an appropriate version in a supported manifest file such as ${validManifestFilenames}`)}. \n\nAlternatively, would you like to continue now by using 0.0.0 as the current version?`,
226
+ type: 'confirm',
227
+ initial: false,
228
+ },
229
+ ]);
230
+ if (!reply.useZero) {
231
+ // Throw any error to skip the fallback to 0.0.0, may as well use the one we already have
232
+ throw unresolvableCurrentVersionError;
233
+ }
234
+ const currentVersion = '0.0.0';
235
+ logger.buffer(`⚠ Forcibly resolved the current version as "${currentVersion}" based on your response to the prompt above`);
236
+ return currentVersion;
237
+ }
238
+ catch {
239
+ throw unresolvableCurrentVersionError;
240
+ }
241
+ }
@@ -0,0 +1,93 @@
1
+ import type { NxJsonConfiguration, NxReleaseVersionConfiguration } from '../../../config/nx-json';
2
+ import type { ProjectGraph } from '../../../config/project-graph';
3
+ import type { Tree } from '../../../generators/tree';
4
+ import { NxReleaseConfig } from '../config/config';
5
+ import { FinalConfigForProject } from './release-group-processor';
6
+ import { VersionActions } from './version-actions';
7
+ export declare function createNxReleaseConfigAndPopulateWorkspace(tree: Tree, graphDefinition: string, additionalNxReleaseConfig: Exclude<NxJsonConfiguration['release'], 'groups'>, mockResolveCurrentVersion?: any, filters?: {
8
+ projects?: string[];
9
+ groups?: string[];
10
+ }): Promise<{
11
+ projectGraph: ProjectGraph;
12
+ nxReleaseConfig: NxReleaseConfig;
13
+ releaseGroups: import("../config/filter-release-groups").ReleaseGroupWithName[];
14
+ releaseGroupToFilteredProjects: Map<import("../config/filter-release-groups").ReleaseGroupWithName, Set<string>>;
15
+ filters: {
16
+ projects?: string[];
17
+ groups?: string[];
18
+ };
19
+ }>;
20
+ /**
21
+ * A non-production grade rust implementation to prove out loading multiple different versionActions in various setups
22
+ */
23
+ interface CargoToml {
24
+ workspace?: {
25
+ members: string[];
26
+ };
27
+ package: {
28
+ name: string;
29
+ version: string;
30
+ };
31
+ dependencies?: Record<string, string | {
32
+ version: string;
33
+ features?: string[];
34
+ optional?: boolean;
35
+ }>;
36
+ 'dev-dependencies'?: Record<string, string | {
37
+ version: string;
38
+ features: string[];
39
+ }>;
40
+ [key: string]: any;
41
+ }
42
+ export declare class ExampleRustVersionActions extends VersionActions {
43
+ validManifestFilenames: string[];
44
+ private parseCargoToml;
45
+ static stringifyCargoToml(cargoToml: CargoToml): string;
46
+ static modifyCargoTable(toml: CargoToml, section: string, key: string, value: string | object | Array<any> | (() => any)): void;
47
+ readCurrentVersionFromSourceManifest(tree: Tree): Promise<{
48
+ currentVersion: string;
49
+ manifestPath: string;
50
+ }>;
51
+ readCurrentVersionFromRegistry(tree: Tree, _currentVersionResolverMetadata: NxReleaseVersionConfiguration['currentVersionResolverMetadata']): Promise<{
52
+ currentVersion: string;
53
+ logText: string;
54
+ }>;
55
+ updateProjectVersion(tree: Tree, newVersion: string): Promise<string[]>;
56
+ readCurrentVersionOfDependency(tree: Tree, _projectGraph: ProjectGraph, dependencyProjectName: string): Promise<{
57
+ currentVersion: string;
58
+ dependencyCollection: string;
59
+ }>;
60
+ updateProjectDependencies(tree: Tree, _projectGraph: ProjectGraph, dependenciesToUpdate: Record<string, string>): Promise<string[]>;
61
+ }
62
+ export declare class ExampleNonSemverVersionActions extends VersionActions {
63
+ validManifestFilenames: any;
64
+ readCurrentVersionFromSourceManifest(): Promise<any>;
65
+ readCurrentVersionFromRegistry(): Promise<any>;
66
+ readCurrentVersionOfDependency(): Promise<{
67
+ currentVersion: any;
68
+ dependencyCollection: any;
69
+ }>;
70
+ updateProjectVersion(tree: any, newVersion: any): Promise<any[]>;
71
+ updateProjectDependencies(): Promise<any[]>;
72
+ calculateNewVersion(currentVersion: string | null, newVersionInput: string, newVersionInputReason: string, newVersionInputReasonData: Record<string, unknown>, preid: string): Promise<{
73
+ newVersion: string;
74
+ logText: string;
75
+ }>;
76
+ }
77
+ export declare function parseGraphDefinition(definition: string): {
78
+ projects: any;
79
+ };
80
+ export declare function mockResolveVersionActionsForProjectImplementation(tree: Tree, releaseGroup: any, projectGraphNode: any, finalConfigForProject: FinalConfigForProject): Promise<{
81
+ versionActionsPath: string;
82
+ versionActions: ExampleRustVersionActions;
83
+ afterAllProjectsVersioned?: undefined;
84
+ } | {
85
+ versionActionsPath: string;
86
+ versionActions: ExampleNonSemverVersionActions;
87
+ afterAllProjectsVersioned?: undefined;
88
+ } | {
89
+ versionActionsPath: string;
90
+ versionActions: VersionActions;
91
+ afterAllProjectsVersioned: any;
92
+ }>;
93
+ export {};