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
@@ -29,14 +29,14 @@ function getYarnLockfileNodes(lockFileContent, lockFileHash, packageJson) {
29
29
  const isBerry = !!__metadata;
30
30
  // yarn classic splits keys when parsing so we need to stich them back together
31
31
  const groupedDependencies = groupDependencies(dependencies, isBerry);
32
- return getNodes(groupedDependencies, packageJson, keyMap, isBerry);
32
+ return getNodes(groupedDependencies, packageJson, isBerry);
33
33
  }
34
34
  function getYarnLockfileDependencies(lockFileContent, lockFileHash, ctx) {
35
35
  const { __metadata, ...dependencies } = parseLockFile(lockFileContent, lockFileHash);
36
36
  const isBerry = !!__metadata;
37
37
  // yarn classic splits keys when parsing so we need to stich them back together
38
38
  const groupedDependencies = groupDependencies(dependencies, isBerry);
39
- return getDependencies(groupedDependencies, keyMap, ctx);
39
+ return getDependencies(groupedDependencies, ctx);
40
40
  }
41
41
  function getPackageNameKeyPairs(keys) {
42
42
  const result = new Map();
@@ -51,7 +51,7 @@ function getPackageNameKeyPairs(keys) {
51
51
  });
52
52
  return result;
53
53
  }
54
- function getNodes(dependencies, packageJson, keyMap, isBerry) {
54
+ function getNodes(dependencies, packageJson, isBerry) {
55
55
  const nodes = new Map();
56
56
  const combinedDeps = {
57
57
  ...packageJson.dependencies,
@@ -68,7 +68,7 @@ function getNodes(dependencies, packageJson, keyMap, isBerry) {
68
68
  nameKeyPairs.forEach((keySet, packageName) => {
69
69
  const keysArray = Array.from(keySet);
70
70
  // use key relevant to the package name
71
- const version = findVersion(packageName, keysArray[0], snapshot, isBerry);
71
+ const [version, isAlias] = findVersion(packageName, keysArray[0], snapshot, isBerry);
72
72
  // use keys linked to the extracted package name
73
73
  keysArray.forEach((key) => {
74
74
  // we don't need to keep duplicates, we can just track the keys
@@ -79,7 +79,7 @@ function getNodes(dependencies, packageJson, keyMap, isBerry) {
79
79
  }
80
80
  const node = {
81
81
  type: 'npm',
82
- name: version
82
+ name: version && !isAlias
83
83
  ? `npm:${packageName}@${version}`
84
84
  : `npm:${packageName}`,
85
85
  data: {
@@ -151,7 +151,7 @@ function findVersion(packageName, key, snapshot, isBerry) {
151
151
  ? snapshot.resolution && !snapshot.resolution.startsWith(`${packageName}@`)
152
152
  : versionRange.startsWith('npm:');
153
153
  if (isAlias) {
154
- return versionRange;
154
+ return [versionRange, true];
155
155
  }
156
156
  // check for berry tarball packages
157
157
  if (isBerry &&
@@ -159,13 +159,13 @@ function findVersion(packageName, key, snapshot, isBerry) {
159
159
  // different registry would yield suffix following '::' which we don't need
160
160
  snapshot.resolution.split('::')[0] !==
161
161
  `${packageName}@npm:${snapshot.version}`) {
162
- return snapshot.resolution.slice(packageName.length + 1);
162
+ return [snapshot.resolution.slice(packageName.length + 1)];
163
163
  }
164
164
  if (!isBerry && isTarballPackage(versionRange, snapshot)) {
165
- return snapshot.resolved;
165
+ return [snapshot.resolved];
166
166
  }
167
167
  // otherwise it's a standard version
168
- return snapshot.version;
168
+ return [snapshot.version];
169
169
  }
170
170
  // check if snapshot represents tarball package
171
171
  function isTarballPackage(versionRange, snapshot) {
@@ -193,7 +193,7 @@ function getHoistedVersion(packageName) {
193
193
  return version;
194
194
  }
195
195
  }
196
- function getDependencies(dependencies, keyMap, ctx) {
196
+ function getDependencies(dependencies, ctx) {
197
197
  const projectGraphDependencies = [];
198
198
  Object.keys(dependencies).forEach((keys) => {
199
199
  const snapshot = dependencies[keys];
@@ -203,8 +203,26 @@ function getDependencies(dependencies, keyMap, ctx) {
203
203
  [snapshot.dependencies, snapshot.optionalDependencies].forEach((section) => {
204
204
  if (section) {
205
205
  Object.entries(section).forEach(([name, versionRange]) => {
206
- const target = keyMap.get(`${name}@npm:${versionRange}`) ||
206
+ let target = keyMap.get(`${name}@npm:${versionRange}`) ||
207
207
  keyMap.get(`${name}@${versionRange}`);
208
+ if (!target) {
209
+ const shortRange = versionRange.replace(/^npm:/, '');
210
+ // for range like 'npm:*' the above will not be a match
211
+ if (shortRange === '*') {
212
+ const foundKey = Array.from(keyMap.keys()).find((k) => k.startsWith(`${name}@`));
213
+ if (foundKey) {
214
+ target = keyMap.get(foundKey);
215
+ }
216
+ }
217
+ else if (shortRange.includes('||')) {
218
+ // when range is a union of ranges, we need to treat it as an array
219
+ const ranges = shortRange.split('||').map((r) => r.trim());
220
+ target = Object.values(keyMap).find((n) => {
221
+ return (n.data.packageName === name &&
222
+ ranges.some((r) => (0, semver_1.satisfies)(n.data.version, r)));
223
+ })?.[1];
224
+ }
225
+ }
208
226
  if (target) {
209
227
  const dep = {
210
228
  source: node.name,
@@ -271,11 +289,11 @@ function addPackageVersion(packageName, version, collection, isBerry) {
271
289
  collection.set(packageName, new Set());
272
290
  }
273
291
  collection.get(packageName).add(`${packageName}@${version}`);
274
- if (isBerry && !version.startsWith('npm:')) {
292
+ if (isBerry && !version.startsWith('npm:') && !version.startsWith('patch:')) {
275
293
  collection.get(packageName).add(`${packageName}@npm:${version}`);
276
294
  }
277
295
  }
278
- function mapSnapshots(dependencies, nodes, packageJson, isBerry) {
296
+ function mapSnapshots(rootDependencies, nodes, packageJson, isBerry) {
279
297
  // map snapshot to set of keys (e.g. `eslint@^7.0.0, eslint@npm:^7.0.0`)
280
298
  const snapshotMap = new Map();
281
299
  // track all existing dependencies's keys
@@ -286,8 +304,11 @@ function mapSnapshots(dependencies, nodes, packageJson, isBerry) {
286
304
  ...packageJson.optionalDependencies,
287
305
  ...packageJson.peerDependencies,
288
306
  };
307
+ const resolutions = {
308
+ ...packageJson.resolutions,
309
+ };
289
310
  // yarn classic splits keys when parsing so we need to stich them back together
290
- const groupedDependencies = groupDependencies(dependencies, isBerry);
311
+ const groupedDependencies = groupDependencies(rootDependencies, isBerry);
291
312
  // collect snapshots and their matching keys
292
313
  Object.values(nodes).forEach((node) => {
293
314
  const foundOriginalKeys = findOriginalKeys(groupedDependencies, node);
@@ -311,9 +332,19 @@ function mapSnapshots(dependencies, nodes, packageJson, isBerry) {
311
332
  snapshotMap.get(snapshot).add(requestedKey);
312
333
  }
313
334
  }
335
+ const requestedResolutionsVersion = getPackageJsonVersion(resolutions, node);
336
+ if (requestedResolutionsVersion) {
337
+ addPackageVersion(node.data.packageName, requestedResolutionsVersion, existingKeys, isBerry);
338
+ const requestedKey = isBerry
339
+ ? reverseMapBerryKey(node, requestedResolutionsVersion, snapshot)
340
+ : `${node.data.packageName}@${requestedResolutionsVersion}`;
341
+ if (!snapshotMap.get(snapshot).has(requestedKey)) {
342
+ snapshotMap.get(snapshot).add(requestedKey);
343
+ }
344
+ }
314
345
  if (isBerry) {
315
346
  // look for patched versions
316
- const patch = findPatchedKeys(groupedDependencies, node);
347
+ const patch = findPatchedKeys(groupedDependencies, node, resolutions[node.data.packageName]);
317
348
  if (patch) {
318
349
  const [matchedKeys, snapshot] = patch;
319
350
  snapshotMap.set(snapshot, new Set(matchedKeys));
@@ -321,7 +352,7 @@ function mapSnapshots(dependencies, nodes, packageJson, isBerry) {
321
352
  }
322
353
  });
323
354
  // remove keys that match version ranges that have been pruned away
324
- snapshotMap.forEach((snapshotValue, snapshotKey) => {
355
+ snapshotMap.forEach((snapshotValue, snapshot) => {
325
356
  for (const key of snapshotValue.values()) {
326
357
  const packageName = key.slice(0, key.indexOf('@', 1));
327
358
  let normalizedKey = key;
@@ -353,8 +384,8 @@ function mapSnapshots(dependencies, nodes, packageJson, isBerry) {
353
384
  }
354
385
  function reverseMapBerryKey(node, version, snapshot) {
355
386
  // alias packages already have version
356
- if (version.startsWith('npm:')) {
357
- `${node.data.packageName}@${version}`;
387
+ if (version.startsWith('npm:') || version.startsWith('patch:')) {
388
+ return `${node.data.packageName}@${version}`;
358
389
  }
359
390
  // check for berry tarball packages
360
391
  if (snapshot.resolution &&
@@ -363,15 +394,28 @@ function reverseMapBerryKey(node, version, snapshot) {
363
394
  }
364
395
  return `${node.data.packageName}@npm:${version}`;
365
396
  }
366
- function getPackageJsonVersion(combinedDependencies, node) {
397
+ function getPackageJsonVersion(dependencies, node) {
367
398
  const { packageName, version } = node.data;
368
- if (combinedDependencies[packageName]) {
369
- if (combinedDependencies[packageName] === version ||
370
- (0, semver_1.satisfies)(version, combinedDependencies[packageName])) {
371
- return combinedDependencies[packageName];
399
+ if (dependencies[packageName]) {
400
+ const patchRegex = new RegExp(`^patch:${packageName}@(.*)|#.*$`);
401
+ // extract the version from the patch or use the full version
402
+ const versionRange = dependencies[packageName].match(patchRegex)?.[1] ||
403
+ dependencies[packageName];
404
+ if (versionRange === version || (0, semver_1.satisfies)(version, versionRange)) {
405
+ return dependencies[packageName];
372
406
  }
373
407
  }
374
408
  }
409
+ function isStandardPackage(snapshot, version) {
410
+ return snapshot.version === version;
411
+ }
412
+ function isBerryAlias(snapshot, version) {
413
+ return snapshot.resolution && `npm:${snapshot.resolution}` === version;
414
+ }
415
+ function isClassicAlias(node, keys) {
416
+ return (node.data.version.startsWith('npm:') &&
417
+ keys.some((k) => k === `${node.data.packageName}@${node.data.version}`));
418
+ }
375
419
  function findOriginalKeys(dependencies, node) {
376
420
  for (const keyExpr of Object.keys(dependencies)) {
377
421
  const snapshot = dependencies[keyExpr];
@@ -379,18 +423,9 @@ function findOriginalKeys(dependencies, node) {
379
423
  if (!keys.some((k) => k.startsWith(`${node.data.packageName}@`))) {
380
424
  continue;
381
425
  }
382
- // standard package
383
- if (snapshot.version === node.data.version) {
384
- return [keys, snapshot];
385
- }
386
- // berry alias package
387
- if (snapshot.resolution &&
388
- `npm:${snapshot.resolution}` === node.data.version) {
389
- return [keys, snapshot];
390
- }
391
- // classic alias
392
- if (node.data.version.startsWith('npm:') &&
393
- keys.some((k) => k === `${node.data.packageName}@${node.data.version}`)) {
426
+ if (isStandardPackage(snapshot, node.data.version) ||
427
+ isBerryAlias(snapshot, node.data.version) ||
428
+ isClassicAlias(node, keys)) {
394
429
  return [keys, snapshot];
395
430
  }
396
431
  // tarball package
@@ -400,16 +435,27 @@ function findOriginalKeys(dependencies, node) {
400
435
  }
401
436
  }
402
437
  }
403
- function findPatchedKeys(dependencies, node) {
438
+ function findPatchedKeys(dependencies, node, resolutionVersion) {
404
439
  for (const keyExpr of Object.keys(dependencies)) {
405
440
  const snapshot = dependencies[keyExpr];
406
441
  const keys = keyExpr.split(', ');
407
442
  if (!keys[0].startsWith(`${node.data.packageName}@patch:`)) {
408
443
  continue;
409
444
  }
410
- // local patches are currently not supported
411
- if (keys[0].includes('.yarn/patches')) {
412
- continue;
445
+ if (keyExpr.includes('.yarn/patches')) {
446
+ if (!resolutionVersion) {
447
+ continue;
448
+ }
449
+ const key = `${node.data.packageName}@${resolutionVersion}`;
450
+ // local patches can have different location from than the root lock file
451
+ // use the one from local package.json as the source of truth as long as the rest of the patch matches
452
+ // this obviously doesn't cover the case of patch over a patch, but that's a super rare case and one can argue one can just join those two patches
453
+ if (key.split('::locator')[0] !== keyExpr.split('::locator')[0]) {
454
+ continue;
455
+ }
456
+ else {
457
+ return [[key], { ...snapshot, resolution: key }];
458
+ }
413
459
  }
414
460
  if (snapshot.version === node.data.version) {
415
461
  return [keys, snapshot];
@@ -19,6 +19,7 @@ const getTouchedProjectsFromLockFile = (fileChanges, projectGraphNodes) => {
19
19
  'pnpm-lock.yaml',
20
20
  'pnpm-lock.yml',
21
21
  'bun.lockb',
22
+ 'bun.lock',
22
23
  ];
23
24
  if (fileChanges.some((f) => lockFiles.includes(f.file))) {
24
25
  return Object.values(projectGraphNodes).map((p) => p.name);
@@ -38,7 +38,7 @@ function buildExplicitTypeScriptDependencies(ctx, targetProjectLocator) {
38
38
  if (isVuePluginInstalled()) {
39
39
  moduleExtensions.push('.vue');
40
40
  }
41
- for (const [project, fileData] of Object.entries(ctx.fileMap.projectFileMap)) {
41
+ for (const [project, fileData] of Object.entries(ctx.filesToProcess.projectFileMap)) {
42
42
  filesToProcess[project] ??= [];
43
43
  for (const { file } of fileData) {
44
44
  if (moduleExtensions.some((ext) => file.endsWith(ext))) {
@@ -5,6 +5,11 @@ import type { ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../..
5
5
  * resolved external node name from the project graph.
6
6
  */
7
7
  type NpmResolutionCache = Map<string, string | null>;
8
+ type PathPattern = {
9
+ pattern: string;
10
+ prefix: string;
11
+ suffix: string;
12
+ };
8
13
  export declare function isBuiltinModuleImport(importExpr: string): boolean;
9
14
  export declare class TargetProjectLocator {
10
15
  private readonly nodes;
@@ -14,6 +19,7 @@ export declare class TargetProjectLocator {
14
19
  private npmProjects;
15
20
  private tsConfig;
16
21
  private paths;
22
+ private parsedPathPatterns;
17
23
  private typescriptResolutionCache;
18
24
  private packagesMetadata;
19
25
  constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache);
@@ -36,11 +42,14 @@ export declare class TargetProjectLocator {
36
42
  /**
37
43
  * Return file paths matching the import relative to the repo root
38
44
  * @param normalizedImportExpr
39
- * @returns
45
+ * @deprecated Use `findMatchingPaths` instead. It will be removed in Nx v22.
40
46
  */
41
47
  findPaths(normalizedImportExpr: string): string[] | undefined;
48
+ findMatchingPaths(importExpr: string): [pattern: string | PathPattern, paths: string[]] | undefined;
42
49
  findImportInWorkspaceProjects(importPath: string): string | null;
43
50
  findDependencyInWorkspaceProjects(dep: string): string | null;
51
+ private isPatternMatch;
52
+ private parsePaths;
44
53
  private resolveImportWithTypescript;
45
54
  private resolveImportWithRequire;
46
55
  private findProjectOfResolvedModule;
@@ -49,6 +49,9 @@ class TargetProjectLocator {
49
49
  }
50
50
  return acc;
51
51
  }, {});
52
+ if (this.tsConfig.config?.compilerOptions?.paths) {
53
+ this.parsePaths(this.tsConfig.config.compilerOptions.paths);
54
+ }
52
55
  }
53
56
  /**
54
57
  * Resolve any workspace or external project that matches the given import expression,
@@ -63,14 +66,15 @@ class TargetProjectLocator {
63
66
  return this.findProjectOfResolvedModule(resolvedModule);
64
67
  }
65
68
  // find project using tsconfig paths
66
- const results = this.findPaths(importExpr);
69
+ const results = this.findMatchingPaths(importExpr);
67
70
  if (results) {
68
71
  const [path, paths] = results;
72
+ const matchedStar = typeof path === 'string'
73
+ ? undefined
74
+ : importExpr.substring(path.prefix.length, importExpr.length - path.suffix.length);
69
75
  for (let p of paths) {
70
- const r = p.endsWith('/*')
71
- ? (0, node_path_1.join)((0, node_path_1.dirname)(p), (0, node_path_1.relative)(path.replace(/\*$/, ''), importExpr))
72
- : p;
73
- const maybeResolvedProject = this.findProjectOfResolvedModule(r);
76
+ const path = matchedStar ? p.replace('*', matchedStar) : p;
77
+ const maybeResolvedProject = this.findProjectOfResolvedModule(path);
74
78
  if (maybeResolvedProject) {
75
79
  return maybeResolvedProject;
76
80
  }
@@ -172,7 +176,7 @@ class TargetProjectLocator {
172
176
  /**
173
177
  * Return file paths matching the import relative to the repo root
174
178
  * @param normalizedImportExpr
175
- * @returns
179
+ * @deprecated Use `findMatchingPaths` instead. It will be removed in Nx v22.
176
180
  */
177
181
  findPaths(normalizedImportExpr) {
178
182
  if (!this.paths) {
@@ -189,6 +193,29 @@ class TargetProjectLocator {
189
193
  }
190
194
  return undefined;
191
195
  }
196
+ findMatchingPaths(importExpr) {
197
+ if (!this.parsedPathPatterns) {
198
+ return undefined;
199
+ }
200
+ const { matchableStrings, patterns } = this.parsedPathPatterns;
201
+ if (matchableStrings.has(importExpr)) {
202
+ return [importExpr, this.paths[importExpr]];
203
+ }
204
+ // https://github.com/microsoft/TypeScript/blob/29e6d6689dfb422e4f1395546c1917d07e1f664d/src/compiler/core.ts#L2410
205
+ let matchedValue;
206
+ let longestMatchPrefixLength = -1;
207
+ for (let i = 0; i < patterns.length; i++) {
208
+ const pattern = patterns[i];
209
+ if (pattern.prefix.length > longestMatchPrefixLength &&
210
+ this.isPatternMatch(pattern, importExpr)) {
211
+ longestMatchPrefixLength = pattern.prefix.length;
212
+ matchedValue = pattern;
213
+ }
214
+ }
215
+ return matchedValue
216
+ ? [matchedValue, this.paths[matchedValue.pattern]]
217
+ : undefined;
218
+ }
192
219
  findImportInWorkspaceProjects(importPath) {
193
220
  this.packagesMetadata ??= (0, packages_1.getWorkspacePackagesMetadata)(this.nodes);
194
221
  if (this.packagesMetadata.entryPointsToProjectMap[importPath]) {
@@ -201,6 +228,32 @@ class TargetProjectLocator {
201
228
  this.packagesMetadata ??= (0, packages_1.getWorkspacePackagesMetadata)(this.nodes);
202
229
  return this.packagesMetadata.packageToProjectMap[dep]?.name;
203
230
  }
231
+ isPatternMatch({ prefix, suffix }, candidate) {
232
+ return (candidate.length >= prefix.length + suffix.length &&
233
+ candidate.startsWith(prefix) &&
234
+ candidate.endsWith(suffix));
235
+ }
236
+ parsePaths(paths) {
237
+ this.parsedPathPatterns = {
238
+ matchableStrings: new Set(),
239
+ patterns: [],
240
+ };
241
+ for (const key of Object.keys(paths)) {
242
+ const parts = key.split('*');
243
+ if (parts.length > 2) {
244
+ continue;
245
+ }
246
+ if (parts.length === 1) {
247
+ this.parsedPathPatterns.matchableStrings.add(key);
248
+ continue;
249
+ }
250
+ this.parsedPathPatterns.patterns.push({
251
+ pattern: key,
252
+ prefix: parts[0],
253
+ suffix: parts[1],
254
+ });
255
+ }
256
+ }
204
257
  resolveImportWithTypescript(normalizedImportExpr, filePath) {
205
258
  let resolvedModule;
206
259
  if (this.typescriptResolutionCache.has(normalizedImportExpr)) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWorkspacePackagesMetadata = getWorkspacePackagesMetadata;
4
4
  exports.matchImportToWildcardEntryPointsToProjectMap = matchImportToWildcardEntryPointsToProjectMap;
5
- const minimatch_1 = require("minimatch");
6
5
  const posix_1 = require("node:path/posix");
7
6
  function getWorkspacePackagesMetadata(projects) {
8
7
  const entryPointsToProjectMap = {};
@@ -63,10 +62,30 @@ function getWorkspacePackagesMetadata(projects) {
63
62
  packageToProjectMap,
64
63
  };
65
64
  }
65
+ // adapted from PACKAGE_IMPORTS_EXPORTS_RESOLVE at
66
+ // https://nodejs.org/docs/latest-v22.x/api/esm.html#resolution-algorithm-specification
66
67
  function matchImportToWildcardEntryPointsToProjectMap(wildcardEntryPointsToProjectMap, importPath) {
67
68
  if (!Object.keys(wildcardEntryPointsToProjectMap).length) {
68
69
  return null;
69
70
  }
70
- const matchingPair = Object.entries(wildcardEntryPointsToProjectMap).find(([key]) => (0, minimatch_1.minimatch)(importPath, key));
71
- return matchingPair?.[1];
71
+ const entryPoint = Object.keys(wildcardEntryPointsToProjectMap).find((key) => {
72
+ const segments = key.split('*');
73
+ if (segments.length > 2) {
74
+ return false;
75
+ }
76
+ const patternBase = segments[0];
77
+ if (patternBase === importPath) {
78
+ return false;
79
+ }
80
+ if (!importPath.startsWith(patternBase)) {
81
+ return false;
82
+ }
83
+ const patternTrailer = segments[1];
84
+ if (patternTrailer?.length > 0 &&
85
+ (!importPath.endsWith(patternTrailer) || importPath.length < key.length)) {
86
+ return false;
87
+ }
88
+ return true;
89
+ });
90
+ return entryPoint ? wildcardEntryPointsToProjectMap[entryPoint] : null;
72
91
  }
@@ -161,6 +161,7 @@ function getTranspiler(compilerOptions, tsConfigRaw) {
161
161
  // use NodeJs module resolution until support for TS 4.x is dropped and then
162
162
  // we can switch to Node10
163
163
  compilerOptions.moduleResolution = ts.ModuleResolutionKind.NodeJs;
164
+ compilerOptions.customConditions = null;
164
165
  compilerOptions.target = ts.ScriptTarget.ES2021;
165
166
  compilerOptions.inlineSourceMap = true;
166
167
  compilerOptions.skipLibCheck = true;
@@ -23,11 +23,11 @@ function readTsConfigOptions(tsConfigPath) {
23
23
  tsModule = require('typescript');
24
24
  }
25
25
  const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
26
- // we don't need to scan the files, we only care about options
26
+ // We only care about options, so we don't need to scan source files, and thus
27
+ // `readDirectory` is stubbed for performance.
27
28
  const host = {
29
+ ...tsModule.sys,
28
30
  readDirectory: () => [],
29
- readFile: () => '',
30
- fileExists: tsModule.sys.fileExists,
31
31
  };
32
32
  return tsModule.parseJsonConfigFileContent(readResult.config, host, (0, path_1.dirname)(tsConfigPath)).options;
33
33
  }
@@ -1,5 +1,5 @@
1
1
  import { NxJsonConfiguration } from '../../config/nx-json';
2
- import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
+ import type { ProjectConfiguration } from '../../config/workspace-json-project-json';
3
3
  import { PackageJson } from '../../utils/package-json';
4
4
  import { CreateNodesV2 } from '../../project-graph/plugins';
5
5
  import { PackageJsonConfigurationCache } from '../../../plugins/package-json';
@@ -86,6 +86,9 @@ function createNodeFromPackageJson(pkgJsonPath, workspaceRoot, cache, isInPackag
86
86
  ...json,
87
87
  root: projectRoot,
88
88
  isInPackageManagerWorkspaces,
89
+ // change this to bust the cache when making changes that result in different
90
+ // results for the same hash
91
+ bust: 1,
89
92
  });
90
93
  const cached = cache[hash];
91
94
  if (cached) {
@@ -126,10 +129,9 @@ function buildProjectConfigurationFromPackageJson(packageJson, workspaceRoot, pa
126
129
  let name = packageJson.name ?? (0, to_project_name_1.toProjectName)(normalizedPath);
127
130
  const projectConfiguration = {
128
131
  root: projectRoot,
129
- sourceRoot: projectRoot,
130
132
  name,
131
133
  ...packageJson.nx,
132
- targets: (0, package_json_1.readTargetsFromPackageJson)(packageJson, nxJson),
134
+ targets: (0, package_json_1.readTargetsFromPackageJson)(packageJson, nxJson, projectRoot, workspaceRoot),
133
135
  tags: (0, package_json_1.getTagsFromPackageJson)(packageJson),
134
136
  metadata: (0, package_json_1.getMetadataFromPackageJson)(packageJson, isInPackageManagerWorkspaces),
135
137
  };
@@ -20,8 +20,8 @@ const getTouchedProjectsFromProjectGlobChanges = async (touchedFiles, projectGra
20
20
  'package.json',
21
21
  ]);
22
22
  }
23
- const plugins = await (0, get_plugins_1.getPlugins)();
24
- return (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.configurationGlobs)(plugins));
23
+ const plugins = (await (0, get_plugins_1.getPlugins)()).filter((p) => !!p.createNodes);
24
+ return (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.getGlobPatternsOfPlugins)(plugins));
25
25
  })();
26
26
  const touchedProjects = new Set();
27
27
  for (const touchedFile of touchedFiles) {
@@ -153,10 +153,37 @@ function isProjectWithNoNameError(e) {
153
153
  }
154
154
  class ProjectConfigurationsError extends Error {
155
155
  constructor(errors, partialProjectConfigurationsResult) {
156
- super('Failed to create project configurations');
156
+ const messageFragments = ['Failed to create project configurations.'];
157
+ const mergeNodesErrors = [];
158
+ const unknownErrors = [];
159
+ for (const e of errors) {
160
+ if (
161
+ // Known error type, but unlikely to be caused by the user
162
+ isMergeNodesError(e)) {
163
+ mergeNodesErrors.push(e);
164
+ }
165
+ else if (
166
+ // Known errors that are self-explanatory
167
+ !isAggregateCreateNodesError(e) &&
168
+ !isProjectsWithNoNameError(e) &&
169
+ !isMultipleProjectsWithSameNameError(e)) {
170
+ unknownErrors.push(e);
171
+ }
172
+ }
173
+ if (mergeNodesErrors.length > 0) {
174
+ messageFragments.push(`This type of error most likely points to an issue within Nx. Please report it.`);
175
+ }
176
+ if (unknownErrors.length > 0) {
177
+ messageFragments.push(`If the error cause is not obvious from the below error messages, running "nx reset" may fix it. Please report the issue if you keep seeing it.`);
178
+ }
179
+ super(messageFragments.join(' '));
157
180
  this.errors = errors;
158
181
  this.partialProjectConfigurationsResult = partialProjectConfigurationsResult;
159
182
  this.name = this.constructor.name;
183
+ this.errors = errors;
184
+ this.stack = errors
185
+ .map((error) => indentString(formatErrorStackAndCause(error), 2))
186
+ .join('\n');
160
187
  }
161
188
  }
162
189
  exports.ProjectConfigurationsError = ProjectConfigurationsError;
@@ -216,7 +243,10 @@ class AggregateCreateNodesError extends Error {
216
243
  exports.AggregateCreateNodesError = AggregateCreateNodesError;
217
244
  function formatAggregateCreateNodesError(error, pluginName) {
218
245
  const errorBodyLines = [
219
- `${error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'} occurred while processing files for the ${pluginName} plugin.`,
246
+ `${error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'} occurred while processing files for the ${pluginName} plugin${error.pluginIndex
247
+ ? ` (Defined at nx.json#plugins[${error.pluginIndex}])`
248
+ : ''}`,
249
+ `.`,
220
250
  ];
221
251
  const errorStackLines = [];
222
252
  const innerErrors = error.errors;
@@ -1,5 +1,4 @@
1
- import { FileData } from '../config/project-graph';
2
- import { ProjectsConfigurations } from '../config/workspace-json-project-json';
1
+ import type { FileData } from '../config/project-graph';
3
2
  import type { NxArgs } from '../utils/command-line-utils';
4
3
  export interface Change {
5
4
  type: string;
@@ -17,14 +16,6 @@ export declare function isWholeFileChange(change: Change): change is WholeFileCh
17
16
  export declare function isDeletedFileChange(change: Change): change is DeletedFileChange;
18
17
  export declare function calculateFileChanges(files: string[], allWorkspaceFiles: FileData[], nxArgs?: NxArgs, readFileAtRevision?: (f: string, r: void | string) => string, ignore?: ReturnType<typeof ignore>): FileChange[];
19
18
  export declare const TEN_MEGABYTES: number;
20
- /**
21
- * TODO(v21): Remove this function
22
- * @deprecated To get projects use {@link retrieveProjectConfigurations} instead. This will be removed in v21.
23
- */
24
- export declare function readWorkspaceConfig(opts: {
25
- format: 'angularCli' | 'nx';
26
- path?: string;
27
- }): ProjectsConfigurations;
28
19
  export declare function defaultFileRead(filePath: string): string | null;
29
20
  export declare function readPackageJson(root?: string): any;
30
21
  export { FileData };