nx 21.0.0-beta.1 → 21.0.0-beta.3

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 (200) hide show
  1. package/.eslintrc.json +5 -1
  2. package/package.json +12 -12
  3. package/release/index.d.ts +1 -1
  4. package/release/index.js +2 -1
  5. package/schemas/nx-schema.json +186 -35
  6. package/src/adapter/compat.d.ts +1 -1
  7. package/src/adapter/compat.js +3 -0
  8. package/src/command-line/add/add.js +6 -16
  9. package/src/command-line/affected/command-object.js +6 -6
  10. package/src/command-line/examples.js +0 -4
  11. package/src/command-line/exec/command-object.js +1 -1
  12. package/src/command-line/generate/generator-utils.js +8 -3
  13. package/src/command-line/import/import.js +1 -1
  14. package/src/command-line/init/command-object.js +18 -6
  15. package/src/command-line/init/configure-plugins.d.ts +6 -7
  16. package/src/command-line/init/configure-plugins.js +47 -35
  17. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  18. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  19. package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
  20. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  21. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  22. package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
  23. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  24. package/src/command-line/init/implementation/react/index.js +32 -185
  25. package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
  26. package/src/command-line/init/implementation/utils.d.ts +4 -1
  27. package/src/command-line/init/implementation/utils.js +108 -44
  28. package/src/command-line/init/init-v1.js +1 -1
  29. package/src/command-line/init/init-v2.d.ts +1 -0
  30. package/src/command-line/init/init-v2.js +68 -38
  31. package/src/command-line/nx-commands.js +19 -5
  32. package/src/command-line/register/command-object.d.ts +6 -0
  33. package/src/command-line/{activate-powerpack → register}/command-object.js +9 -9
  34. package/src/command-line/register/register.d.ts +2 -0
  35. package/src/command-line/register/register.js +9 -0
  36. package/src/command-line/release/changelog.js +18 -15
  37. package/src/command-line/release/command-object.d.ts +2 -0
  38. package/src/command-line/release/command-object.js +9 -0
  39. package/src/command-line/release/config/config.d.ts +8 -7
  40. package/src/command-line/release/config/config.js +129 -42
  41. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  42. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  43. package/src/command-line/release/index.d.ts +4 -0
  44. package/src/command-line/release/index.js +6 -1
  45. package/src/command-line/release/plan-check.js +6 -3
  46. package/src/command-line/release/plan.js +7 -3
  47. package/src/command-line/release/publish.js +7 -3
  48. package/src/command-line/release/release.js +8 -3
  49. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  50. package/src/command-line/release/utils/git.d.ts +3 -2
  51. package/src/command-line/release/utils/git.js +65 -9
  52. package/src/command-line/release/utils/github.js +3 -1
  53. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  54. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  55. package/src/command-line/release/utils/semver.d.ts +8 -0
  56. package/src/command-line/release/utils/semver.js +8 -0
  57. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  58. package/src/command-line/release/utils/shared-legacy.js +2 -0
  59. package/src/command-line/release/utils/shared.d.ts +11 -17
  60. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  61. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  62. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  63. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  64. package/src/command-line/release/version/project-logger.d.ts +8 -0
  65. package/src/command-line/release/version/project-logger.js +45 -0
  66. package/src/command-line/release/version/release-group-processor.d.ts +251 -0
  67. package/src/command-line/release/version/release-group-processor.js +1040 -0
  68. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  69. package/src/command-line/release/version/resolve-current-version.js +241 -0
  70. package/src/command-line/release/version/test-utils.d.ts +95 -0
  71. package/src/command-line/release/version/test-utils.js +416 -0
  72. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  73. package/src/command-line/release/version/topological-sort.js +41 -0
  74. package/src/command-line/release/version/version-actions.d.ts +170 -0
  75. package/src/command-line/release/version/version-actions.js +183 -0
  76. package/src/command-line/release/version-legacy.d.ts +46 -0
  77. package/src/command-line/release/version-legacy.js +453 -0
  78. package/src/command-line/release/version.d.ts +0 -40
  79. package/src/command-line/release/version.js +80 -262
  80. package/src/command-line/report/report.d.ts +7 -3
  81. package/src/command-line/report/report.js +52 -18
  82. package/src/command-line/run/command-object.js +2 -2
  83. package/src/command-line/run/run.js +1 -1
  84. package/src/command-line/run-many/command-object.js +2 -2
  85. package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
  86. package/src/command-line/yargs-utils/shared-options.js +20 -0
  87. package/src/config/nx-json.d.ts +153 -15
  88. package/src/config/project-graph.d.ts +4 -2
  89. package/src/config/project-graph.js +8 -0
  90. package/src/config/workspace-json-project-json.d.ts +2 -2
  91. package/src/core/graph/main.js +1 -1
  92. package/src/core/graph/runtime.js +1 -1
  93. package/src/core/graph/styles.css +2 -2
  94. package/src/core/graph/styles.js +1 -1
  95. package/src/daemon/client/client.d.ts +2 -0
  96. package/src/daemon/client/client.js +15 -0
  97. package/src/daemon/message-types/glob.d.ts +7 -0
  98. package/src/daemon/message-types/glob.js +9 -1
  99. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  100. package/src/daemon/message-types/hash-glob.js +9 -1
  101. package/src/daemon/server/handle-glob.d.ts +1 -0
  102. package/src/daemon/server/handle-glob.js +8 -0
  103. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  104. package/src/daemon/server/handle-hash-glob.js +8 -0
  105. package/src/daemon/server/logger.js +2 -1
  106. package/src/daemon/server/server.js +7 -0
  107. package/src/devkit-internals.d.ts +2 -1
  108. package/src/devkit-internals.js +4 -1
  109. package/src/executors/run-commands/run-commands.impl.d.ts +3 -5
  110. package/src/executors/run-commands/run-commands.impl.js +14 -42
  111. package/src/executors/run-commands/running-tasks.d.ts +7 -5
  112. package/src/executors/run-commands/running-tasks.js +64 -27
  113. package/src/executors/run-script/run-script.impl.js +4 -3
  114. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
  115. package/src/generators/testing-utils/create-tree.js +5 -1
  116. package/src/native/index.d.ts +93 -19
  117. package/src/native/index.js +16 -2
  118. package/src/native/native-bindings.js +6 -0
  119. package/src/native/nx.wasi-browser.js +20 -19
  120. package/src/native/nx.wasi.cjs +20 -19
  121. package/src/native/nx.wasm32-wasi.wasm +0 -0
  122. package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
  123. package/src/plugins/js/lock-file/lock-file.js +28 -13
  124. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  125. package/src/plugins/js/lock-file/utils/package-json.js +2 -1
  126. package/src/plugins/js/lock-file/yarn-parser.js +85 -39
  127. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  128. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  129. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  130. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  131. package/src/plugins/js/utils/packages.js +22 -3
  132. package/src/plugins/js/utils/register.js +1 -0
  133. package/src/plugins/js/utils/typescript.js +3 -3
  134. package/src/plugins/package-json/create-nodes.d.ts +1 -1
  135. package/src/plugins/package-json/create-nodes.js +3 -1
  136. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  137. package/src/project-graph/error-types.js +32 -2
  138. package/src/project-graph/plugins/get-plugins.js +2 -1
  139. package/src/project-graph/plugins/in-process-loader.js +1 -1
  140. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  141. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  142. package/src/project-graph/plugins/utils.d.ts +2 -2
  143. package/src/project-graph/plugins/utils.js +2 -2
  144. package/src/project-graph/project-graph.js +1 -1
  145. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  146. package/src/project-graph/utils/project-configuration-utils.js +25 -11
  147. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  148. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  149. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  150. package/src/tasks-runner/batch/run-batch.js +2 -3
  151. package/src/tasks-runner/cache.d.ts +20 -6
  152. package/src/tasks-runner/cache.js +104 -20
  153. package/src/tasks-runner/create-task-graph.d.ts +1 -1
  154. package/src/tasks-runner/create-task-graph.js +12 -11
  155. package/src/tasks-runner/default-tasks-runner.js +4 -13
  156. package/src/tasks-runner/forked-process-task-runner.d.ts +8 -3
  157. package/src/tasks-runner/forked-process-task-runner.js +56 -46
  158. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  159. package/src/tasks-runner/init-tasks-runner.js +55 -2
  160. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  161. package/src/tasks-runner/is-tui-enabled.js +58 -0
  162. package/src/tasks-runner/life-cycle.d.ts +10 -3
  163. package/src/tasks-runner/life-cycle.js +23 -2
  164. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +7 -2
  165. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +6 -1
  166. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +17 -0
  167. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +221 -0
  168. package/src/tasks-runner/pseudo-terminal.d.ts +10 -7
  169. package/src/tasks-runner/pseudo-terminal.js +37 -35
  170. package/src/tasks-runner/run-command.d.ts +1 -0
  171. package/src/tasks-runner/run-command.js +180 -23
  172. package/src/tasks-runner/task-env.d.ts +1 -4
  173. package/src/tasks-runner/task-env.js +2 -0
  174. package/src/tasks-runner/task-orchestrator.d.ts +21 -9
  175. package/src/tasks-runner/task-orchestrator.js +127 -44
  176. package/src/tasks-runner/utils.d.ts +2 -2
  177. package/src/tasks-runner/utils.js +15 -11
  178. package/src/utils/child-process.d.ts +4 -0
  179. package/src/utils/child-process.js +23 -30
  180. package/src/utils/command-line-utils.d.ts +1 -1
  181. package/src/utils/find-matching-projects.js +2 -2
  182. package/src/utils/handle-errors.js +15 -0
  183. package/src/utils/is-ci.js +4 -1
  184. package/src/utils/is-using-prettier.d.ts +3 -0
  185. package/src/utils/is-using-prettier.js +62 -0
  186. package/src/utils/nx-key.d.ts +7 -0
  187. package/src/utils/nx-key.js +52 -0
  188. package/src/utils/package-manager.js +2 -2
  189. package/src/utils/path.js +1 -1
  190. package/src/utils/require-nx-key.d.ts +1 -0
  191. package/src/utils/require-nx-key.js +22 -0
  192. package/src/utils/workspace-context.d.ts +2 -0
  193. package/src/utils/workspace-context.js +16 -0
  194. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  195. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  196. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  197. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  198. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  199. package/src/utils/powerpack.d.ts +0 -5
  200. package/src/utils/powerpack.js +0 -33
@@ -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;
@@ -108,12 +108,13 @@ async function loadSpecifiedNxPlugins(plugins, root = workspace_root_1.workspace
108
108
  plugins ??= [];
109
109
  const cleanupFunctions = [];
110
110
  const ret = [
111
- await Promise.all(plugins.map(async (plugin) => {
111
+ await Promise.all(plugins.map(async (plugin, index) => {
112
112
  const pluginPath = typeof plugin === 'string' ? plugin : plugin.plugin;
113
113
  performance.mark(`Load Nx Plugin: ${pluginPath} - start`);
114
114
  const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
115
115
  cleanupFunctions.push(cleanup);
116
116
  const res = await loadedPluginPromise;
117
+ res.index = index;
117
118
  performance.mark(`Load Nx Plugin: ${pluginPath} - end`);
118
119
  performance.measure(`Load Nx Plugin: ${pluginPath}`, `Load Nx Plugin: ${pluginPath} - start`, `Load Nx Plugin: ${pluginPath} - end`);
119
120
  return res;
@@ -25,7 +25,7 @@ function readPluginPackageJson(pluginName, projects, paths = (0, installation_di
25
25
  const localPluginPath = (0, resolve_plugin_1.resolveLocalNxPlugin)(pluginName, projects);
26
26
  if (localPluginPath) {
27
27
  const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
28
- if ((0, transpiler_1.pluginTranspilerIsRegistered)()) {
28
+ if (!(0, transpiler_1.pluginTranspilerIsRegistered)()) {
29
29
  (0, transpiler_1.registerPluginTSTranspiler)();
30
30
  }
31
31
  return {
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_perf_hooks_1 = require("node:perf_hooks");
4
+ node_perf_hooks_1.performance.mark(`plugin worker ${process.pid} code loading -- start`);
3
5
  const messaging_1 = require("./messaging");
4
6
  const serializable_error_1 = require("../../../utils/serializable-error");
5
7
  const consume_messages_from_socket_1 = require("../../../utils/consume-messages-from-socket");
@@ -8,6 +10,8 @@ const fs_1 = require("fs");
8
10
  if (process.env.NX_PERF_LOGGING === 'true') {
9
11
  require('../../../utils/perf-logging');
10
12
  }
13
+ node_perf_hooks_1.performance.mark(`plugin worker ${process.pid} code loading -- end`);
14
+ node_perf_hooks_1.performance.measure(`plugin worker ${process.pid} code loading`, `plugin worker ${process.pid} code loading -- start`, `plugin worker ${process.pid} code loading -- end`);
11
15
  global.NX_GRAPH_CREATION = true;
12
16
  global.NX_PLUGIN_WORKER = true;
13
17
  let connected = false;
@@ -182,12 +186,14 @@ const server = (0, net_1.createServer)((socket) => {
182
186
  });
183
187
  });
184
188
  server.listen(socketPath);
185
- setTimeout(() => {
186
- if (!connected) {
187
- console.error('The plugin worker is exiting as it was not connected to within 5 seconds.');
188
- process.exit(1);
189
- }
190
- }, 5000).unref();
189
+ if (process.env.NX_PLUGIN_NO_TIMEOUTS !== 'true') {
190
+ setTimeout(() => {
191
+ if (!connected) {
192
+ console.error('The plugin worker is exiting as it was not connected to within 5 seconds.');
193
+ process.exit(1);
194
+ }
195
+ }, 5000).unref();
196
+ }
191
197
  const exitHandler = (exitCode) => () => {
192
198
  server.close();
193
199
  try {
@@ -1,8 +1,9 @@
1
1
  import type { ProjectGraph } from '../../config/project-graph';
2
- import type { PluginConfiguration } from '../../config/nx-json';
2
+ import { type PluginConfiguration } from '../../config/nx-json';
3
3
  import type { RawProjectGraphDependency } from '../project-graph-builder';
4
4
  import type { CreateDependenciesContext, CreateMetadataContext, CreateNodesContextV2, CreateNodesResult, NxPluginV2, PostTasksExecutionContext, PreTasksExecutionContext, ProjectsMetadata } from './public-api';
5
5
  export declare class LoadedNxPlugin {
6
+ index?: number;
6
7
  readonly name: string;
7
8
  readonly createNodes?: [
8
9
  filePattern: string,
@@ -1,2 +1,2 @@
1
- import { CreateNodesContextV2, CreateNodesFunction, CreateNodesResult } from './public-api';
2
- export declare function createNodesFromFiles<T = unknown>(createNodes: CreateNodesFunction<T>, configFiles: readonly string[], options: T, context: CreateNodesContextV2): Promise<[file: string, value: CreateNodesResult][]>;
1
+ import { CreateNodesContext, CreateNodesContextV2, CreateNodesResult } from './public-api';
2
+ export declare function createNodesFromFiles<T = unknown>(createNodes: (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext, idx: number) => CreateNodesResult | Promise<CreateNodesResult>, configFiles: readonly string[], options: T, context: CreateNodesContextV2): Promise<[file: string, value: CreateNodesResult][]>;
@@ -5,12 +5,12 @@ const error_types_1 = require("../error-types");
5
5
  async function createNodesFromFiles(createNodes, configFiles, options, context) {
6
6
  const results = [];
7
7
  const errors = [];
8
- await Promise.all(configFiles.map(async (file) => {
8
+ await Promise.all(configFiles.map(async (file, idx) => {
9
9
  try {
10
10
  const value = await createNodes(file, options, {
11
11
  ...context,
12
12
  configFiles,
13
- });
13
+ }, idx);
14
14
  if (value) {
15
15
  results.push([file, value]);
16
16
  }
@@ -280,7 +280,7 @@ async function createProjectGraphAndSourceMapsAsync(opts = {
280
280
  handleProjectGraphError(opts, e);
281
281
  }
282
282
  finally {
283
- lock.unlock();
283
+ lock?.unlock();
284
284
  }
285
285
  }
286
286
  else {
@@ -35,7 +35,7 @@ export type ConfigurationResult = {
35
35
  * @param workspaceFiles A list of non-ignored workspace files
36
36
  * @param plugins The plugins that should be used to infer project configuration
37
37
  */
38
- export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
38
+ export declare function createProjectConfigurationsWithPlugins(root: string, nxJson: NxJsonConfiguration, projectFiles: string[][], // making this parameter allows devkit to pick up newly created projects
39
39
  plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
40
40
  export declare function findMatchingConfigFiles(projectFiles: string[], pattern: string, include: string[], exclude: string[]): string[];
41
41
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeProjectConfigurationIntoRootMap = mergeProjectConfigurationIntoRootMap;
4
4
  exports.mergeMetadata = mergeMetadata;
5
- exports.createProjectConfigurations = createProjectConfigurations;
5
+ exports.createProjectConfigurationsWithPlugins = createProjectConfigurationsWithPlugins;
6
6
  exports.findMatchingConfigFiles = findMatchingConfigFiles;
7
7
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
8
8
  exports.validateProject = validateProject;
@@ -138,8 +138,20 @@ skipTargetNormalization) {
138
138
  const normalizedTarget = skipTargetNormalization
139
139
  ? target
140
140
  : resolveCommandSyntacticSugar(target, project.root);
141
- const mergedTarget = mergeTargetConfigurations(normalizedTarget, matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
142
- updatedProjectConfiguration.targets[targetName] = mergedTarget;
141
+ let matchingTargets = [];
142
+ if ((0, globs_1.isGlobPattern)(targetName)) {
143
+ // find all targets matching the glob pattern
144
+ // this will map atomized targets to the glob pattern same as it does for targetDefaults
145
+ matchingTargets = Object.keys(updatedProjectConfiguration.targets).filter((key) => (0, minimatch_1.minimatch)(key, targetName));
146
+ }
147
+ // If no matching targets were found, we can assume that the target name is not (meant to be) a glob pattern
148
+ if (!matchingTargets.length) {
149
+ matchingTargets = [targetName];
150
+ }
151
+ for (const matchingTargetName of matchingTargets) {
152
+ const mergedTarget = mergeTargetConfigurations(normalizedTarget, matchingProject.targets?.[matchingTargetName], sourceMap, sourceInformation, `targets.${matchingTargetName}`);
153
+ updatedProjectConfiguration.targets[matchingTargetName] = mergedTarget;
154
+ }
143
155
  }
144
156
  }
145
157
  projectRootMap[updatedProjectConfiguration.root] =
@@ -222,7 +234,7 @@ function mergeMetadata(sourceMap, sourceInformation, baseSourceMapPath, metadata
222
234
  * @param workspaceFiles A list of non-ignored workspace files
223
235
  * @param plugins The plugins that should be used to infer project configuration
224
236
  */
225
- async function createProjectConfigurations(root = workspace_root_1.workspaceRoot, nxJson, projectFiles, // making this parameter allows devkit to pick up newly created projects
237
+ async function createProjectConfigurationsWithPlugins(root = workspace_root_1.workspaceRoot, nxJson, projectFiles, // making this parameter allows devkit to pick up newly created projects
226
238
  plugins) {
227
239
  perf_hooks_1.performance.mark('build-project-configs:start');
228
240
  let spinner;
@@ -248,12 +260,12 @@ plugins) {
248
260
  const results = [];
249
261
  const errors = [];
250
262
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
251
- for (const [index, { createNodes: createNodesTuple, include, exclude, name: pluginName },] of plugins.entries()) {
263
+ for (const [index, { index: pluginIndex, createNodes: createNodesTuple, include, exclude, name: pluginName, },] of plugins.entries()) {
252
264
  const [pattern, createNodes] = createNodesTuple ?? [];
253
265
  if (!pattern) {
254
266
  continue;
255
267
  }
256
- const matchingConfigFiles = findMatchingConfigFiles(projectFiles, pattern, include, exclude);
268
+ const matchingConfigFiles = findMatchingConfigFiles(projectFiles[index], pattern, include, exclude);
257
269
  inProgressPlugins.add(pluginName);
258
270
  let r = createNodes(matchingConfigFiles, {
259
271
  nxJsonConfiguration: nxJson,
@@ -265,8 +277,10 @@ plugins) {
265
277
  e
266
278
  : // This represents a single plugin erroring out with a hard error.
267
279
  new error_types_1.AggregateCreateNodesError([[null, e]], []);
280
+ if (pluginIndex !== undefined) {
281
+ error.pluginIndex = pluginIndex;
282
+ }
268
283
  (0, error_types_1.formatAggregateCreateNodesError)(error, pluginName);
269
- error.pluginIndex = index;
270
284
  // This represents a single plugin erroring out with a hard error.
271
285
  errors.push(error);
272
286
  // The plugin didn't return partial results, so we return an empty array.
@@ -289,7 +303,7 @@ plugins) {
289
303
  externalNodes,
290
304
  projectRootMap: rootMap,
291
305
  sourceMaps: configurationSourceMaps,
292
- matchingProjectFiles: projectFiles,
306
+ matchingProjectFiles: projectFiles.flat(),
293
307
  };
294
308
  }
295
309
  else {
@@ -298,7 +312,7 @@ plugins) {
298
312
  externalNodes,
299
313
  projectRootMap: rootMap,
300
314
  sourceMaps: configurationSourceMaps,
301
- matchingProjectFiles: projectFiles,
315
+ matchingProjectFiles: projectFiles.flat(),
302
316
  });
303
317
  }
304
318
  });
@@ -309,7 +323,7 @@ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
309
323
  const externalNodes = {};
310
324
  const configurationSourceMaps = {};
311
325
  for (const result of results.flat()) {
312
- const [pluginName, file, nodes, index] = result;
326
+ const [pluginName, file, nodes, pluginIndex] = result;
313
327
  const { projects: projectNodes, externalNodes: pluginExternalNodes } = nodes;
314
328
  const sourceInfo = [file, pluginName];
315
329
  for (const node in projectNodes) {
@@ -329,7 +343,7 @@ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
329
343
  file,
330
344
  pluginName,
331
345
  error,
332
- pluginIndex: index,
346
+ pluginIndex,
333
347
  }));
334
348
  }
335
349
  }
@@ -23,4 +23,4 @@ export declare function retrieveProjectConfigurations(plugins: LoadedNxPlugin[],
23
23
  export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
24
24
  export declare function retrieveProjectConfigurationPaths(root: string, plugins: Array<LoadedNxPlugin>): Promise<string[]>;
25
25
  export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
26
- export declare function configurationGlobs(plugins: Array<LoadedNxPlugin>): string[];
26
+ export declare function getGlobPatternsOfPlugins(plugins: Array<LoadedNxPlugin>): string[];
@@ -5,7 +5,7 @@ exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
5
5
  exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
6
6
  exports.retrieveProjectConfigurationPaths = retrieveProjectConfigurationPaths;
7
7
  exports.retrieveProjectConfigurationsWithoutPluginInference = retrieveProjectConfigurationsWithoutPluginInference;
8
- exports.configurationGlobs = configurationGlobs;
8
+ exports.getGlobPatternsOfPlugins = getGlobPatternsOfPlugins;
9
9
  const perf_hooks_1 = require("perf_hooks");
10
10
  const angular_json_1 = require("../../adapter/angular-json");
11
11
  const nx_json_1 = require("../../config/nx-json");
@@ -41,9 +41,10 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
41
41
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
42
42
  */
43
43
  async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
44
- const globPatterns = configurationGlobs(plugins);
45
- const workspaceFiles = await (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
46
- return (0, project_configuration_utils_1.createProjectConfigurations)(workspaceRoot, nxJson, workspaceFiles, plugins);
44
+ const pluginsWithCreateNodes = plugins.filter((p) => !!p.createNodes);
45
+ const globPatterns = getGlobPatternsOfPlugins(pluginsWithCreateNodes);
46
+ const pluginConfigFiles = await (0, workspace_context_1.multiGlobWithWorkspaceContext)(workspaceRoot, globPatterns);
47
+ return (0, project_configuration_utils_1.createProjectConfigurationsWithPlugins)(workspaceRoot, nxJson, pluginConfigFiles, pluginsWithCreateNodes);
47
48
  }
48
49
  async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
49
50
  const pluginsToLoad = nxJson?.plugins ?? [];
@@ -56,31 +57,26 @@ async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, n
56
57
  const res = await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
57
58
  return res;
58
59
  }
59
- function retrieveProjectConfigurationPaths(root, plugins) {
60
- const projectGlobPatterns = configurationGlobs(plugins);
61
- return (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns);
60
+ async function retrieveProjectConfigurationPaths(root, plugins) {
61
+ const projectGlobPatterns = getGlobPatternsOfPlugins(plugins);
62
+ const pluginConfigFiles = await (0, workspace_context_1.multiGlobWithWorkspaceContext)(root, projectGlobPatterns);
63
+ return pluginConfigFiles.flat();
62
64
  }
63
65
  const projectsWithoutPluginCache = new Map();
64
66
  // TODO: This function is called way too often, it should be optimized without this cache
65
67
  async function retrieveProjectConfigurationsWithoutPluginInference(root) {
66
68
  const nxJson = (0, nx_json_1.readNxJson)(root);
67
69
  const plugins = await (0, get_plugins_1.getOnlyDefaultPlugins)(); // only load default plugins
68
- const projectGlobPatterns = await retrieveProjectConfigurationPaths(root, plugins);
70
+ const projectGlobPatterns = getGlobPatternsOfPlugins(plugins);
69
71
  const cacheKey = root + ',' + projectGlobPatterns.join(',');
70
72
  if (projectsWithoutPluginCache.has(cacheKey)) {
71
73
  return projectsWithoutPluginCache.get(cacheKey);
72
74
  }
73
- const projectFiles = (await (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns)) ?? [];
74
- const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, plugins);
75
+ const projectFiles = (await (0, workspace_context_1.multiGlobWithWorkspaceContext)(root, projectGlobPatterns)) ?? [];
76
+ const { projects } = await (0, project_configuration_utils_1.createProjectConfigurationsWithPlugins)(root, nxJson, projectFiles, plugins);
75
77
  projectsWithoutPluginCache.set(cacheKey, projects);
76
78
  return projects;
77
79
  }
78
- function configurationGlobs(plugins) {
79
- const globPatterns = [];
80
- for (const plugin of plugins) {
81
- if ('createNodes' in plugin && plugin.createNodes) {
82
- globPatterns.push(plugin.createNodes[0]);
83
- }
84
- }
85
- return globPatterns;
80
+ function getGlobPatternsOfPlugins(plugins) {
81
+ return plugins.map((p) => p.createNodes[0]);
86
82
  }
@@ -1,5 +1,6 @@
1
1
  import type { TaskResult } from '../../config/misc-interfaces';
2
2
  import type { TaskGraph } from '../../config/task-graph';
3
+ import type { ProjectGraph } from '../../config/project-graph';
3
4
  export declare enum BatchMessageType {
4
5
  RunTasks = 0,
5
6
  CompleteTask = 1,
@@ -18,6 +19,7 @@ export interface BatchTaskResult {
18
19
  export interface RunTasksMessage {
19
20
  type: BatchMessageType.RunTasks;
20
21
  executorName: string;
22
+ projectGraph: ProjectGraph;
21
23
  batchTaskGraph: TaskGraph;
22
24
  fullTaskGraph: TaskGraph;
23
25
  }
@@ -11,9 +11,8 @@ function getBatchExecutor(executorName, projects) {
11
11
  const [nodeModule, exportName] = executorName.split(':');
12
12
  return (0, executor_utils_1.getExecutorInformation)(nodeModule, exportName, workspace_root_1.workspaceRoot, projects);
13
13
  }
14
- async function runTasks(executorName, batchTaskGraph, fullTaskGraph) {
14
+ async function runTasks(executorName, projectGraph, batchTaskGraph, fullTaskGraph) {
15
15
  const input = {};
16
- const projectGraph = await (0, project_graph_1.createProjectGraphAsync)();
17
16
  const projectsConfigurations = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
18
17
  const nxJsonConfiguration = (0, configuration_1.readNxJson)();
19
18
  const batchExecutor = getBatchExecutor(executorName, projectsConfigurations.projects);
@@ -66,7 +65,7 @@ async function runTasks(executorName, batchTaskGraph, fullTaskGraph) {
66
65
  process.on('message', async (message) => {
67
66
  switch (message.type) {
68
67
  case batch_messages_1.BatchMessageType.RunTasks: {
69
- const results = await runTasks(message.executorName, message.batchTaskGraph, message.fullTaskGraph);
68
+ const results = await runTasks(message.executorName, message.projectGraph, message.batchTaskGraph, message.fullTaskGraph);
70
69
  process.send({
71
70
  type: batch_messages_1.BatchMessageType.CompleteBatchExecution,
72
71
  results,
@@ -15,6 +15,7 @@ export declare function dbCacheEnabled(nxJson?: NxJsonConfiguration): boolean;
15
15
  export declare function getCache(options: DefaultTasksRunnerOptions): DbCache | Cache;
16
16
  export declare class DbCache {
17
17
  private readonly options;
18
+ private nxJson;
18
19
  private cache;
19
20
  private remoteCache;
20
21
  private remoteCachePromise;
@@ -25,18 +26,20 @@ export declare class DbCache {
25
26
  });
26
27
  init(): Promise<void>;
27
28
  get(task: Task): Promise<CachedResult | null>;
29
+ getUsedCacheSpace(): number;
28
30
  private applyRemoteCacheResults;
29
31
  put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
30
- copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<void>;
32
+ copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<number>;
31
33
  removeOldCacheRecords(): void;
32
34
  temporaryOutputPath(task: Task): string;
33
35
  private getRemoteCache;
34
36
  private _getRemoteCache;
35
- private getPowerpackS3Cache;
36
- private getPowerpackSharedCache;
37
- private getPowerpackGcsCache;
38
- private getPowerpackAzureCache;
39
- private getPowerpackCache;
37
+ private getS3Cache;
38
+ private getSharedCache;
39
+ private getGcsCache;
40
+ private getAzureCache;
41
+ private getHttpCache;
42
+ private resolveRemoteCache;
40
43
  private resolvePackage;
41
44
  private assertCacheIsValid;
42
45
  }
@@ -66,3 +69,14 @@ export declare class Cache {
66
69
  private createCacheDir;
67
70
  private createTerminalOutputsDir;
68
71
  }
72
+ /**
73
+ * Converts a string representation of a max cache size to a number.
74
+ *
75
+ * e.g. '1GB' -> 1024 * 1024 * 1024
76
+ * '1MB' -> 1024 * 1024
77
+ * '1KB' -> 1024
78
+ *
79
+ * @param maxCacheSize Max cache size as specified in nx.json
80
+ */
81
+ export declare function parseMaxCacheSize(maxCacheSize: string | number): number | undefined;
82
+ export declare function formatCacheSize(maxCacheSize: number, decimals?: number): string;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cache = exports.DbCache = void 0;
4
4
  exports.dbCacheEnabled = dbCacheEnabled;
5
5
  exports.getCache = getCache;
6
+ exports.parseMaxCacheSize = parseMaxCacheSize;
7
+ exports.formatCacheSize = formatCacheSize;
6
8
  const workspace_root_1 = require("../utils/workspace-root");
7
9
  const path_1 = require("path");
8
10
  const perf_hooks_1 = require("perf_hooks");
@@ -68,7 +70,10 @@ function getCache(options) {
68
70
  class DbCache {
69
71
  constructor(options) {
70
72
  this.options = options;
71
- this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)());
73
+ this.nxJson = (0, nx_json_1.readNxJson)();
74
+ this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)(), undefined, this.nxJson.maxCacheSize !== undefined
75
+ ? parseMaxCacheSize(this.nxJson.maxCacheSize)
76
+ : (0, native_1.getDefaultMaxCacheSize)(cache_directory_1.cacheDir));
72
77
  this.isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
73
78
  }
74
79
  async init() {
@@ -83,6 +88,7 @@ class DbCache {
83
88
  if (res) {
84
89
  return {
85
90
  ...res,
91
+ terminalOutput: res.terminalOutput ?? '',
86
92
  remote: false,
87
93
  };
88
94
  }
@@ -91,9 +97,10 @@ class DbCache {
91
97
  // attempt remote cache
92
98
  const res = await this.remoteCache.retrieve(task.hash, this.cache.cacheDirectory);
93
99
  if (res) {
94
- this.applyRemoteCacheResults(task.hash, res);
100
+ this.applyRemoteCacheResults(task.hash, res, task.outputs);
95
101
  return {
96
102
  ...res,
103
+ terminalOutput: res.terminalOutput ?? '',
97
104
  remote: true,
98
105
  };
99
106
  }
@@ -105,8 +112,11 @@ class DbCache {
105
112
  return null;
106
113
  }
107
114
  }
108
- applyRemoteCacheResults(hash, res) {
109
- return this.cache.applyRemoteCacheResults(hash, res);
115
+ getUsedCacheSpace() {
116
+ return this.cache.getCacheSize();
117
+ }
118
+ applyRemoteCacheResults(hash, res, outputs) {
119
+ return this.cache.applyRemoteCacheResults(hash, res, outputs);
110
120
  }
111
121
  async put(task, terminalOutput, outputs, code) {
112
122
  return tryAndRetry(async () => {
@@ -155,26 +165,49 @@ class DbCache {
155
165
  }
156
166
  }
157
167
  else {
158
- return ((await this.getPowerpackS3Cache()) ??
159
- (await this.getPowerpackSharedCache()) ??
160
- (await this.getPowerpackGcsCache()) ??
161
- (await this.getPowerpackAzureCache()) ??
168
+ return ((await this.getS3Cache()) ??
169
+ (await this.getSharedCache()) ??
170
+ (await this.getGcsCache()) ??
171
+ (await this.getAzureCache()) ??
172
+ this.getHttpCache() ??
162
173
  null);
163
174
  }
164
175
  }
165
- getPowerpackS3Cache() {
166
- return this.getPowerpackCache('@nx/powerpack-s3-cache');
167
- }
168
- getPowerpackSharedCache() {
169
- return this.getPowerpackCache('@nx/powerpack-shared-fs-cache');
170
- }
171
- getPowerpackGcsCache() {
172
- return this.getPowerpackCache('@nx/powerpack-gcs-cache');
173
- }
174
- getPowerpackAzureCache() {
175
- return this.getPowerpackCache('@nx/powerpack-azure-cache');
176
+ async getS3Cache() {
177
+ const cache = await this.resolveRemoteCache('@nx/s3-cache');
178
+ if (cache)
179
+ return cache;
180
+ return this.resolveRemoteCache('@nx/powerpack-s3-cache');
181
+ }
182
+ async getSharedCache() {
183
+ const cache = await this.resolveRemoteCache('@nx/shared-fs-cache');
184
+ if (cache)
185
+ return cache;
186
+ return this.resolveRemoteCache('@nx/powerpack-shared-fs-cache');
187
+ }
188
+ async getGcsCache() {
189
+ const cache = await this.resolveRemoteCache('@nx/gcs-cache');
190
+ if (cache)
191
+ return cache;
192
+ return this.resolveRemoteCache('@nx/powerpack-gcs-cache');
193
+ }
194
+ async getAzureCache() {
195
+ const cache = await this.resolveRemoteCache('@nx/azure-cache');
196
+ if (cache)
197
+ return cache;
198
+ return this.resolveRemoteCache('@nx/powerpack-azure-cache');
199
+ }
200
+ getHttpCache() {
201
+ if (process.env.NX_SELF_HOSTED_REMOTE_CACHE_SERVER) {
202
+ if (native_1.IS_WASM) {
203
+ logger_1.logger.warn('The HTTP remote cache is not yet supported in the wasm build of Nx.');
204
+ return null;
205
+ }
206
+ return new native_1.HttpRemoteCache();
207
+ }
208
+ return null;
176
209
  }
177
- async getPowerpackCache(pkg) {
210
+ async resolveRemoteCache(pkg) {
178
211
  let getRemoteCache = null;
179
212
  try {
180
213
  getRemoteCache = (await Promise.resolve(`${this.resolvePackage(pkg)}`).then(s => require(s))).getRemoteCache;
@@ -455,3 +488,54 @@ function tryAndRetry(fn) {
455
488
  };
456
489
  return _try();
457
490
  }
491
+ /**
492
+ * Converts a string representation of a max cache size to a number.
493
+ *
494
+ * e.g. '1GB' -> 1024 * 1024 * 1024
495
+ * '1MB' -> 1024 * 1024
496
+ * '1KB' -> 1024
497
+ *
498
+ * @param maxCacheSize Max cache size as specified in nx.json
499
+ */
500
+ function parseMaxCacheSize(maxCacheSize) {
501
+ if (maxCacheSize === null || maxCacheSize === undefined) {
502
+ return undefined;
503
+ }
504
+ let regexResult = maxCacheSize
505
+ // Covers folks who accidentally specify as a number rather than a string
506
+ .toString()
507
+ // Match a number followed by an optional unit (KB, MB, GB), with optional whitespace between the number and unit
508
+ .match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
509
+ if (!regexResult) {
510
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize}. Must be a number followed by an optional unit (KB, MB, GB)`);
511
+ }
512
+ let sizeString = regexResult.groups.size;
513
+ let unit = regexResult.groups.unit;
514
+ if ([...sizeString].filter((c) => c === '.').length > 1) {
515
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize} (multiple decimal points in size)`);
516
+ }
517
+ let size = parseFloat(sizeString);
518
+ if (isNaN(size)) {
519
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize} (${sizeString} is not a number)`);
520
+ }
521
+ switch (unit) {
522
+ case 'KB':
523
+ return size * 1024;
524
+ case 'MB':
525
+ return size * 1024 * 1024;
526
+ case 'GB':
527
+ return size * 1024 * 1024 * 1024;
528
+ default:
529
+ return size;
530
+ }
531
+ }
532
+ function formatCacheSize(maxCacheSize, decimals = 2) {
533
+ const exponents = ['B', 'KB', 'MB', 'GB'];
534
+ let exponent = 0;
535
+ let size = maxCacheSize;
536
+ while (size >= 1024 && exponent < exponents.length - 1) {
537
+ size /= 1024;
538
+ exponent++;
539
+ }
540
+ return `${size.toFixed(decimals)} ${exponents[exponent]}`;
541
+ }
@@ -24,7 +24,6 @@ export declare class ProcessTasks {
24
24
  private createDummyTask;
25
25
  createTask(id: string, project: ProjectGraphProjectNode, target: string, resolvedConfiguration: string | undefined, overrides: Object): Task;
26
26
  resolveConfiguration(project: ProjectGraphProjectNode, target: string, configuration: string | undefined): string;
27
- getId(project: string, target: string, configuration: string | undefined): string;
28
27
  }
29
28
  export declare function createTaskGraph(projectGraph: ProjectGraph, extraTargetDependencies: TargetDependencies, projectNames: string[], targets: string[], configuration: string | undefined, overrides: Object, excludeTaskDependencies?: boolean): TaskGraph;
30
29
  export declare function mapTargetDefaultsToDependencies(defaults: TargetDefaults | undefined): TargetDependencies;
@@ -41,3 +40,4 @@ export declare function filterDummyTasks(dependencies: {
41
40
  export declare function getNonDummyDeps(currentTask: string, dependencies: {
42
41
  [k: string]: string[];
43
42
  }, cycles?: Set<string>, seen?: Set<string>): string[];
43
+ export declare function createTaskId(project: string, target: string, configuration: string | undefined): string;