nx 19.0.0-beta.0 → 19.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 (107) hide show
  1. package/.eslintrc.json +1 -1
  2. package/migrations.json +2 -25
  3. package/package.json +12 -12
  4. package/src/command-line/add/add.js +17 -16
  5. package/src/command-line/affected/affected.js +1 -1
  6. package/src/command-line/graph/command-object.js +1 -1
  7. package/src/command-line/graph/graph.d.ts +11 -1
  8. package/src/command-line/graph/graph.js +97 -13
  9. package/src/command-line/init/implementation/react/index.js +1 -1
  10. package/src/command-line/release/changelog.js +1 -1
  11. package/src/command-line/release/command-object.js +2 -2
  12. package/src/command-line/release/publish.js +1 -1
  13. package/src/command-line/report/report.js +1 -1
  14. package/src/command-line/run/run-one.js +1 -1
  15. package/src/command-line/run-many/run-many.js +1 -1
  16. package/src/command-line/show/command-object.js +1 -5
  17. package/src/command-line/yargs-utils/shared-options.d.ts +3 -0
  18. package/src/command-line/yargs-utils/shared-options.js +16 -7
  19. package/src/config/nx-json.d.ts +2 -2
  20. package/src/config/to-project-name.d.ts +5 -0
  21. package/src/config/to-project-name.js +13 -0
  22. package/src/core/graph/index.html +1 -2
  23. package/src/core/graph/main.js +1 -1
  24. package/src/core/graph/runtime.js +1 -1
  25. package/src/core/graph/styles.css +2 -2
  26. package/src/core/graph/styles.js +1 -1
  27. package/src/daemon/client/client.d.ts +2 -2
  28. package/src/daemon/client/client.js +21 -6
  29. package/src/daemon/server/project-graph-incremental-recomputation.js +8 -8
  30. package/src/daemon/server/server.js +1 -4
  31. package/src/daemon/server/shutdown-utils.js +7 -2
  32. package/src/daemon/socket-utils.js +2 -14
  33. package/src/daemon/tmp-dir.js +2 -2
  34. package/src/devkit-exports.d.ts +1 -5
  35. package/src/devkit-exports.js +1 -7
  36. package/src/devkit-internals.d.ts +2 -0
  37. package/src/devkit-internals.js +5 -1
  38. package/src/executors/run-commands/run-commands.impl.d.ts +2 -0
  39. package/src/executors/run-commands/run-commands.impl.js +69 -15
  40. package/src/executors/run-commands/schema.json +19 -2
  41. package/src/executors/utils/convert-nx-executor.js +2 -1
  42. package/src/generators/testing-utils/create-tree-with-empty-workspace.js +7 -0
  43. package/src/generators/utils/project-configuration.js +3 -8
  44. package/src/hasher/task-hasher.d.ts +4 -4
  45. package/src/native/index.d.ts +1 -1
  46. package/src/plugins/js/lock-file/pnpm-parser.js +109 -67
  47. package/src/plugins/package-json-workspaces/create-nodes.d.ts +1 -0
  48. package/src/plugins/package-json-workspaces/create-nodes.js +25 -20
  49. package/src/plugins/project-json/build-nodes/project-json.js +2 -2
  50. package/src/project-graph/affected/locators/workspace-projects.js +3 -1
  51. package/src/project-graph/build-project-graph.d.ts +8 -18
  52. package/src/project-graph/build-project-graph.js +86 -57
  53. package/src/project-graph/error-types.d.ts +35 -3
  54. package/src/project-graph/error-types.js +84 -2
  55. package/src/project-graph/file-utils.d.ts +2 -3
  56. package/src/project-graph/file-utils.js +5 -9
  57. package/src/project-graph/plugins/internal-api.d.ts +3 -2
  58. package/src/project-graph/plugins/internal-api.js +3 -0
  59. package/src/project-graph/plugins/isolation/messaging.d.ts +34 -8
  60. package/src/project-graph/plugins/isolation/messaging.js +27 -10
  61. package/src/project-graph/plugins/isolation/plugin-pool.js +34 -15
  62. package/src/project-graph/plugins/isolation/plugin-worker.js +41 -4
  63. package/src/project-graph/plugins/loader.js +36 -24
  64. package/src/project-graph/plugins/public-api.d.ts +11 -1
  65. package/src/project-graph/plugins/utils.d.ts +2 -2
  66. package/src/project-graph/plugins/utils.js +19 -24
  67. package/src/project-graph/project-graph.d.ts +3 -0
  68. package/src/project-graph/project-graph.js +8 -7
  69. package/src/project-graph/utils/find-project-for-path.js +2 -3
  70. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  71. package/src/project-graph/utils/normalize-project-nodes.js +8 -14
  72. package/src/project-graph/utils/project-configuration-utils.d.ts +23 -6
  73. package/src/project-graph/utils/project-configuration-utils.js +43 -20
  74. package/src/tasks-runner/create-task-graph.js +0 -1
  75. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +5 -1
  76. package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +4 -0
  77. package/src/tasks-runner/pseudo-terminal.d.ts +2 -1
  78. package/src/tasks-runner/pseudo-terminal.js +8 -2
  79. package/src/tasks-runner/run-command.js +4 -4
  80. package/src/tasks-runner/utils.js +17 -0
  81. package/src/utils/assert-workspace-validity.js +2 -1
  82. package/src/utils/command-line-utils.d.ts +1 -1
  83. package/src/utils/nx-plugin.deprecated.d.ts +1 -1
  84. package/src/utils/nx-plugin.deprecated.js +1 -1
  85. package/src/utils/params.js +4 -0
  86. package/src/utils/perf-logging.js +3 -1
  87. package/src/utils/serializable-error.d.ts +4 -0
  88. package/src/utils/serializable-error.js +28 -0
  89. package/src/command-line/repair.d.ts +0 -4
  90. package/src/command-line/repair.js +0 -7
  91. package/src/command-line/run-many.d.ts +0 -4
  92. package/src/command-line/run-many.js +0 -7
  93. package/src/command-line/run-one.d.ts +0 -4
  94. package/src/command-line/run-one.js +0 -7
  95. package/src/command-line/run.d.ts +0 -4
  96. package/src/command-line/run.js +0 -7
  97. package/src/command-line/watch.d.ts +0 -4
  98. package/src/command-line/watch.js +0 -7
  99. package/src/config/workspaces.d.ts +0 -18
  100. package/src/config/workspaces.js +0 -35
  101. package/src/core/graph/3rdpartylicenses.txt +0 -785
  102. package/src/migrations/update-15-1-0/set-project-names.d.ts +0 -2
  103. package/src/migrations/update-15-1-0/set-project-names.js +0 -34
  104. package/src/migrations/update-15-8-2/update-nxw.d.ts +0 -2
  105. package/src/migrations/update-15-8-2/update-nxw.js +0 -7
  106. package/src/utils/typescript.d.ts +0 -1
  107. package/src/utils/typescript.js +0 -5
@@ -32,7 +32,7 @@ function loadRemoteNxPlugin(plugin, root) {
32
32
  ...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
33
33
  ],
34
34
  });
35
- worker.send((0, messaging_1.createMessage)({ type: 'load', payload: { plugin, root } }));
35
+ worker.send({ type: 'load', payload: { plugin, root } });
36
36
  // logger.verbose(`[plugin-worker] started worker: ${worker.pid}`);
37
37
  const pendingPromises = new Map();
38
38
  const exitHandler = createWorkerExitHandler(worker, pendingPromises);
@@ -67,30 +67,29 @@ async function shutdownPluginWorker(worker, pendingPromises) {
67
67
  function createWorkerHandler(worker, pending, onload, onloadError) {
68
68
  let pluginName;
69
69
  return function (message) {
70
- const parsed = JSON.parse(message);
71
- // logger.verbose(
72
- // `[plugin-pool] received message: ${parsed.type} from ${
73
- // pluginName ?? worker.pid
74
- // }`
75
- // );
76
- (0, messaging_1.consumeMessage)(parsed, {
70
+ if (!(0, messaging_1.isPluginWorkerResult)(message)) {
71
+ return;
72
+ }
73
+ return (0, messaging_1.consumeMessage)(message, {
77
74
  'load-result': (result) => {
78
75
  if (result.success) {
79
- const { name, createNodesPattern } = result;
76
+ const { name, createNodesPattern, include, exclude } = result;
80
77
  pluginName = name;
81
78
  pluginNames.set(worker, pluginName);
82
79
  onload({
83
80
  name,
81
+ include,
82
+ exclude,
84
83
  createNodes: createNodesPattern
85
84
  ? [
86
85
  createNodesPattern,
87
86
  (configFiles, ctx) => {
88
87
  const tx = pluginName + ':createNodes:' + performance.now();
89
88
  return registerPendingPromise(tx, pending, () => {
90
- worker.send((0, messaging_1.createMessage)({
89
+ worker.send({
91
90
  type: 'createNodes',
92
91
  payload: { configFiles, context: ctx, tx },
93
- }));
92
+ });
94
93
  });
95
94
  },
96
95
  ]
@@ -99,10 +98,10 @@ function createWorkerHandler(worker, pending, onload, onloadError) {
99
98
  ? (ctx) => {
100
99
  const tx = pluginName + ':createDependencies:' + performance.now();
101
100
  return registerPendingPromise(tx, pending, () => {
102
- worker.send((0, messaging_1.createMessage)({
101
+ worker.send({
103
102
  type: 'createDependencies',
104
103
  payload: { context: ctx, tx },
105
- }));
104
+ });
106
105
  });
107
106
  }
108
107
  : undefined,
@@ -110,10 +109,21 @@ function createWorkerHandler(worker, pending, onload, onloadError) {
110
109
  ? (graph, ctx) => {
111
110
  const tx = pluginName + ':processProjectGraph:' + performance.now();
112
111
  return registerPendingPromise(tx, pending, () => {
113
- worker.send((0, messaging_1.createMessage)({
112
+ worker.send({
114
113
  type: 'processProjectGraph',
115
114
  payload: { graph, ctx, tx },
116
- }));
115
+ });
116
+ });
117
+ }
118
+ : undefined,
119
+ createMetadata: result.hasCreateMetadata
120
+ ? (graph, ctx) => {
121
+ const tx = pluginName + ':createMetadata:' + performance.now();
122
+ return registerPendingPromise(tx, pending, () => {
123
+ worker.send({
124
+ type: 'createMetadata',
125
+ payload: { graph, context: ctx, tx },
126
+ });
117
127
  });
118
128
  }
119
129
  : undefined,
@@ -150,6 +160,15 @@ function createWorkerHandler(worker, pending, onload, onloadError) {
150
160
  rejector(result.error);
151
161
  }
152
162
  },
163
+ createMetadataResult: ({ tx, ...result }) => {
164
+ const { resolver, rejector } = pending.get(tx);
165
+ if (result.success) {
166
+ resolver(result.metadata);
167
+ }
168
+ else if (result.success === false) {
169
+ rejector(result.error);
170
+ }
171
+ },
153
172
  });
154
173
  };
155
174
  }
@@ -2,10 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const messaging_1 = require("./messaging");
4
4
  const loader_1 = require("../loader");
5
+ const serializable_error_1 = require("../../../utils/serializable-error");
6
+ if (process.env.NX_PERF_LOGGING === 'true') {
7
+ require('../../../utils/perf-logging');
8
+ }
5
9
  global.NX_GRAPH_CREATION = true;
6
10
  let plugin;
7
11
  process.on('message', async (message) => {
8
- (0, messaging_1.consumeMessage)(message, {
12
+ if (!(0, messaging_1.isPluginWorkerMessage)(message)) {
13
+ return;
14
+ }
15
+ return (0, messaging_1.consumeMessage)(message, {
9
16
  load: async ({ plugin: pluginConfiguration, root }) => {
10
17
  process.chdir(root);
11
18
  try {
@@ -15,9 +22,12 @@ process.on('message', async (message) => {
15
22
  type: 'load-result',
16
23
  payload: {
17
24
  name: plugin.name,
25
+ include: plugin.include,
26
+ exclude: plugin.exclude,
18
27
  createNodesPattern: plugin.createNodes?.[0],
19
28
  hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
20
29
  hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
30
+ hasCreateMetadata: 'createMetadata' in plugin && !!plugin.createMetadata,
21
31
  success: true,
22
32
  },
23
33
  };
@@ -27,7 +37,7 @@ process.on('message', async (message) => {
27
37
  type: 'load-result',
28
38
  payload: {
29
39
  success: false,
30
- error: `Could not load plugin ${plugin} \n ${e instanceof Error ? e.stack : ''}`,
40
+ error: (0, serializable_error_1.createSerializableError)(e),
31
41
  },
32
42
  };
33
43
  }
@@ -43,7 +53,11 @@ process.on('message', async (message) => {
43
53
  catch (e) {
44
54
  return {
45
55
  type: 'createNodesResult',
46
- payload: { success: false, error: e.stack, tx },
56
+ payload: {
57
+ success: false,
58
+ error: (0, serializable_error_1.createSerializableError)(e),
59
+ tx,
60
+ },
47
61
  };
48
62
  }
49
63
  },
@@ -58,7 +72,11 @@ process.on('message', async (message) => {
58
72
  catch (e) {
59
73
  return {
60
74
  type: 'createDependenciesResult',
61
- payload: { success: false, error: e.stack, tx },
75
+ payload: {
76
+ success: false,
77
+ error: (0, serializable_error_1.createSerializableError)(e),
78
+ tx,
79
+ },
62
80
  };
63
81
  }
64
82
  },
@@ -73,6 +91,25 @@ process.on('message', async (message) => {
73
91
  catch (e) {
74
92
  return {
75
93
  type: 'processProjectGraphResult',
94
+ payload: {
95
+ success: false,
96
+ error: (0, serializable_error_1.createSerializableError)(e),
97
+ tx,
98
+ },
99
+ };
100
+ }
101
+ },
102
+ createMetadata: async ({ graph, context, tx }) => {
103
+ try {
104
+ const result = await plugin.createMetadata(graph, context);
105
+ return {
106
+ type: 'createMetadataResult',
107
+ payload: { metadata: result, success: true, tx },
108
+ };
109
+ }
110
+ catch (e) {
111
+ return {
112
+ type: 'createMetadataResult',
76
113
  payload: { success: false, error: e.stack, tx },
77
114
  };
78
115
  }
@@ -8,16 +8,17 @@ const package_json_1 = require("../../utils/package-json");
8
8
  const fileutils_1 = require("../../utils/fileutils");
9
9
  const workspace_root_1 = require("../../utils/workspace-root");
10
10
  const node_fs_1 = require("node:fs");
11
- const typescript_1 = require("../../utils/typescript");
12
11
  const register_1 = require("../../plugins/js/utils/register");
13
12
  const find_project_for_path_1 = require("../utils/find-project-for-path");
14
13
  const path_1 = require("../../utils/path");
15
14
  const logger_1 = require("../../utils/logger");
16
15
  const node_path_1 = require("node:path");
17
- const path = require("node:path/posix");
18
16
  const retrieve_workspace_files_1 = require("../utils/retrieve-workspace-files");
19
17
  const utils_1 = require("./utils");
20
18
  const internal_api_1 = require("./internal-api");
19
+ const error_types_1 = require("../error-types");
20
+ const path = require("node:path/posix");
21
+ const typescript_1 = require("../../plugins/js/utils/typescript");
21
22
  function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
22
23
  try {
23
24
  const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
@@ -31,6 +32,9 @@ function readPluginPackageJson(pluginName, projects, paths = (0, installation_di
31
32
  const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
32
33
  if (localPluginPath) {
33
34
  const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
35
+ if (!exports.unregisterPluginTSTranspiler) {
36
+ registerPluginTSTranspiler();
37
+ }
34
38
  return {
35
39
  path: localPluginPackageJson,
36
40
  json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
@@ -76,22 +80,27 @@ function registerPluginTSTranspiler() {
76
80
  }
77
81
  exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
78
82
  function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
79
- const plugin = findNxProjectForImportPath(importPath, projects, root);
80
- if (!plugin) {
83
+ const projectConfig = findNxProjectForImportPath(importPath, projects, root);
84
+ if (!projectConfig) {
81
85
  return null;
82
86
  }
83
- const projectConfig = projects[plugin];
84
87
  return { path: path.join(root, projectConfig.root), projectConfig };
85
88
  }
86
89
  function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
87
90
  const tsConfigPaths = readTsConfigPaths(root);
88
91
  const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
89
92
  if (possiblePaths?.length) {
90
- const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
93
+ const projectRootMappings = new Map();
94
+ const projectNameMap = new Map();
95
+ for (const projectRoot in projects) {
96
+ const project = projects[projectRoot];
97
+ projectRootMappings.set(project.root, project.name);
98
+ projectNameMap.set(project.name, project);
99
+ }
91
100
  for (const tsConfigPath of possiblePaths) {
92
101
  const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
93
102
  if (nxProject) {
94
- return nxProject;
103
+ return projectNameMap.get(nxProject);
95
104
  }
96
105
  }
97
106
  logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
@@ -174,26 +183,29 @@ function loadNxPlugin(plugin, root) {
174
183
  }
175
184
  exports.loadNxPlugin = loadNxPlugin;
176
185
  async function loadNxPluginAsync(pluginConfiguration, paths, root) {
177
- try {
178
- require.resolve(typeof pluginConfiguration === 'string'
179
- ? pluginConfiguration
180
- : pluginConfiguration.plugin);
181
- }
182
- catch {
183
- // If a plugin cannot be resolved, we will need projects to resolve it
184
- projectsWithoutInference ??=
185
- await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
186
- }
187
186
  const moduleName = typeof pluginConfiguration === 'string'
188
187
  ? pluginConfiguration
189
188
  : pluginConfiguration.plugin;
190
- performance.mark(`Load Nx Plugin: ${moduleName} - start`);
191
- let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projectsWithoutInference, root);
192
- const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
193
- plugin.name ??= name;
194
- performance.mark(`Load Nx Plugin: ${moduleName} - end`);
195
- performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
196
- return new internal_api_1.LoadedNxPlugin(plugin, pluginConfiguration);
189
+ try {
190
+ try {
191
+ require.resolve(moduleName);
192
+ }
193
+ catch {
194
+ // If a plugin cannot be resolved, we will need projects to resolve it
195
+ projectsWithoutInference ??=
196
+ await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
197
+ }
198
+ performance.mark(`Load Nx Plugin: ${moduleName} - start`);
199
+ let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projectsWithoutInference, root);
200
+ const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
201
+ plugin.name ??= name;
202
+ performance.mark(`Load Nx Plugin: ${moduleName} - end`);
203
+ performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
204
+ return new internal_api_1.LoadedNxPlugin(plugin, pluginConfiguration);
205
+ }
206
+ catch (e) {
207
+ throw new error_types_1.LoadPluginError(moduleName, e);
208
+ }
197
209
  }
198
210
  exports.loadNxPluginAsync = loadNxPluginAsync;
199
211
  async function importPluginModule(pluginPath) {
@@ -12,7 +12,7 @@ export interface CreateNodesContext {
12
12
  /**
13
13
  * The subset of configuration files which match the createNodes pattern
14
14
  */
15
- readonly configFiles: string[];
15
+ readonly configFiles: readonly string[];
16
16
  }
17
17
  /**
18
18
  * A function which parses a configuration file into a set of nodes.
@@ -68,6 +68,12 @@ export interface CreateDependenciesContext {
68
68
  * Use {@link validateDependency} to validate dependencies
69
69
  */
70
70
  export type CreateDependencies<T = unknown> = (options: T | undefined, context: CreateDependenciesContext) => RawProjectGraphDependency[] | Promise<RawProjectGraphDependency[]>;
71
+ export type CreateMetadataContext = {
72
+ readonly nxJsonConfiguration: NxJsonConfiguration;
73
+ readonly workspaceRoot: string;
74
+ };
75
+ export type ProjectsMetadata = Record<string, Pick<ProjectConfiguration, 'metadata'>>;
76
+ export type CreateMetadata<T = unknown> = (graph: ProjectGraph, options: T | undefined, context: CreateMetadataContext) => ProjectsMetadata | Promise<ProjectsMetadata>;
71
77
  /**
72
78
  * A plugin for Nx which creates nodes and dependencies for the {@link ProjectGraph}
73
79
  */
@@ -82,6 +88,10 @@ export type NxPluginV2<TOptions = unknown> = {
82
88
  * Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
83
89
  */
84
90
  createDependencies?: CreateDependencies<TOptions>;
91
+ /**
92
+ * Provides a function to create metadata for the {@link ProjectGraph}
93
+ */
94
+ createMetadata?: CreateMetadata<TOptions>;
85
95
  };
86
96
  /**
87
97
  * A plugin for Nx
@@ -1,7 +1,7 @@
1
1
  import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
2
2
  import type { CreateNodesResultWithContext, LoadedNxPlugin, NormalizedPlugin } from './internal-api';
3
- import type { CreateNodesContext, NxPlugin, NxPluginV2 } from './public-api';
3
+ import { type CreateNodesContext, type NxPlugin, type NxPluginV2 } from './public-api';
4
4
  export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
5
5
  export declare function isNxPluginV1(plugin: NxPlugin | LoadedNxPlugin): plugin is NxPluginV1;
6
6
  export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
7
- export declare function runCreateNodesInParallel(configFiles: string[], plugin: NormalizedPlugin, options: unknown, context: CreateNodesContext): Promise<CreateNodesResultWithContext[]>;
7
+ export declare function runCreateNodesInParallel(configFiles: readonly string[], plugin: NormalizedPlugin, options: unknown, context: CreateNodesContext): Promise<CreateNodesResultWithContext[]>;
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCreateNodesInParallel = exports.normalizeNxPlugin = exports.isNxPluginV1 = exports.isNxPluginV2 = void 0;
4
4
  const node_path_1 = require("node:path");
5
- const workspaces_1 = require("../../config/workspaces");
5
+ const to_project_name_1 = require("../../config/to-project-name");
6
6
  const globs_1 = require("../../utils/globs");
7
7
  const error_types_1 = require("../error-types");
8
+ const perf_hooks_1 = require("perf_hooks");
8
9
  function isNxPluginV2(plugin) {
9
10
  return 'createNodes' in plugin || 'createDependencies' in plugin;
10
11
  }
@@ -27,7 +28,7 @@ function normalizeNxPlugin(plugin) {
27
28
  return {
28
29
  projects: {
29
30
  [root]: {
30
- name: (0, workspaces_1.toProjectName)(configFilePath),
31
+ name: (0, to_project_name_1.toProjectName)(configFilePath),
31
32
  targets: plugin.registerProjectTargets?.(configFilePath),
32
33
  },
33
34
  },
@@ -40,37 +41,31 @@ function normalizeNxPlugin(plugin) {
40
41
  }
41
42
  exports.normalizeNxPlugin = normalizeNxPlugin;
42
43
  async function runCreateNodesInParallel(configFiles, plugin, options, context) {
43
- performance.mark(`${plugin.name}:createNodes - start`);
44
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes - start`);
44
45
  const errors = [];
45
46
  const results = [];
46
- const promises = configFiles.map((file) => {
47
- performance.mark(`${plugin.name}:createNodes:${file} - start`);
48
- // Result is either static or a promise, using Promise.resolve lets us
49
- // handle both cases with same logic
50
- const value = Promise.resolve(plugin.createNodes[1](file, options, context));
51
- return value
52
- .catch((e) => {
53
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
47
+ const promises = configFiles.map(async (file) => {
48
+ try {
49
+ const value = await plugin.createNodes[1](file, options, context);
50
+ if (value) {
51
+ results.push({
52
+ ...value,
53
+ file,
54
+ pluginName: plugin.name,
55
+ });
56
+ }
57
+ }
58
+ catch (e) {
54
59
  errors.push(new error_types_1.CreateNodesError({
55
60
  error: e,
56
61
  pluginName: plugin.name,
57
62
  file,
58
63
  }));
59
- return null;
60
- })
61
- .then((r) => {
62
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
63
- performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
64
- // Existing behavior is to ignore null results of
65
- // createNodes function.
66
- if (r) {
67
- results.push({ ...r, file, pluginName: plugin.name });
68
- }
69
- });
64
+ }
70
65
  });
71
66
  await Promise.all(promises).then(() => {
72
- performance.mark(`${plugin.name}:createNodes - end`);
73
- performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
67
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes - end`);
68
+ perf_hooks_1.performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
74
69
  });
75
70
  if (errors.length > 0) {
76
71
  throw new error_types_1.AggregateCreateNodesError(plugin.name, errors, results);
@@ -14,6 +14,9 @@ export declare function buildProjectGraphAndSourceMapsWithoutDaemon(): Promise<{
14
14
  projectGraph: ProjectGraph;
15
15
  sourceMaps: import("./utils/project-configuration-utils").ConfigurationSourceMaps;
16
16
  }>;
17
+ export declare function handleProjectGraphError(opts: {
18
+ exitOnError: boolean;
19
+ }, e: any): void;
17
20
  /**
18
21
  * Computes and returns a ProjectGraph.
19
22
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
3
+ exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.handleProjectGraphError = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
4
4
  const perf_hooks_1 = require("perf_hooks");
5
5
  const nx_json_1 = require("../config/nx-json");
6
6
  const client_1 = require("../daemon/client/client");
@@ -10,8 +10,8 @@ const output_1 = require("../utils/output");
10
10
  const strip_indents_1 = require("../utils/strip-indents");
11
11
  const workspace_root_1 = require("../utils/workspace-root");
12
12
  const build_project_graph_1 = require("./build-project-graph");
13
- const nx_deps_cache_1 = require("./nx-deps-cache");
14
13
  const error_types_1 = require("./error-types");
14
+ const nx_deps_cache_1 = require("./nx-deps-cache");
15
15
  const internal_api_1 = require("./plugins/internal-api");
16
16
  const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
17
17
  /**
@@ -92,18 +92,18 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
92
92
  perf_hooks_1.performance.mark('retrieve-workspace-files:end');
93
93
  const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
94
94
  perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
95
- let createDependenciesError;
95
+ let projectGraphError;
96
96
  let projectGraphResult;
97
97
  try {
98
- projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, plugins);
98
+ projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, plugins, sourceMaps);
99
99
  }
100
100
  catch (e) {
101
- if (e instanceof build_project_graph_1.CreateDependenciesError) {
101
+ if ((0, error_types_1.isAggregateProjectGraphError)(e)) {
102
102
  projectGraphResult = {
103
103
  projectGraph: e.partialProjectGraph,
104
104
  projectFileMapCache: null,
105
105
  };
106
- createDependenciesError = e;
106
+ projectGraphError = e;
107
107
  }
108
108
  else {
109
109
  throw e;
@@ -117,7 +117,7 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
117
117
  delete global.NX_GRAPH_CREATION;
118
118
  const errors = [
119
119
  ...(projectConfigurationsError?.errors ?? []),
120
- ...(createDependenciesError?.errors ?? []),
120
+ ...(projectGraphError?.errors ?? []),
121
121
  ];
122
122
  if (errors.length > 0) {
123
123
  throw new error_types_1.ProjectGraphError(errors, projectGraph, sourceMaps);
@@ -162,6 +162,7 @@ function handleProjectGraphError(opts, e) {
162
162
  throw e;
163
163
  }
164
164
  }
165
+ exports.handleProjectGraphError = handleProjectGraphError;
165
166
  /**
166
167
  * Computes and returns a ProjectGraph.
167
168
  *
@@ -9,9 +9,8 @@ const path_2 = require("../../utils/path");
9
9
  */
10
10
  function createProjectRootMappingsFromProjectConfigurations(projects) {
11
11
  const projectRootMappings = new Map();
12
- for (const projectName of Object.keys(projects)) {
13
- const root = projects[projectName].root;
14
- projectRootMappings.set(normalizeProjectRoot(root), projectName);
12
+ for (const { name, root } of Object.values(projects)) {
13
+ projectRootMappings.set(normalizeProjectRoot(root), name);
15
14
  }
16
15
  return projectRootMappings;
17
16
  }
@@ -2,7 +2,7 @@ import { ProjectGraphProjectNode } from '../../config/project-graph';
2
2
  import { ProjectGraphBuilder } from '../project-graph-builder';
3
3
  import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
4
4
  import { CreateDependenciesContext } from '../plugins';
5
- export declare function normalizeProjectNodes(ctx: CreateDependenciesContext, builder: ProjectGraphBuilder): Promise<void>;
5
+ export declare function normalizeProjectNodes({ projects }: CreateDependenciesContext, builder: ProjectGraphBuilder): Promise<void>;
6
6
  /**
7
7
  * Apply target defaults and normalization
8
8
  */
@@ -2,16 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeImplicitDependencies = exports.normalizeProjectTargets = exports.normalizeProjectNodes = void 0;
4
4
  const find_matching_projects_1 = require("../../utils/find-matching-projects");
5
- const project_configuration_utils_1 = require("../utils/project-configuration-utils");
6
- async function normalizeProjectNodes(ctx, builder) {
7
- const toAdd = [];
5
+ async function normalizeProjectNodes({ projects }, builder) {
8
6
  // Sorting projects by name to make sure that the order of projects in the graph is deterministic.
9
7
  // This is important to ensure that expanded properties referencing projects (e.g. implicit dependencies)
10
8
  // are also deterministic, and thus don't cause the calculated project configuration hash to shift.
11
- const projects = Object.keys(ctx.projects).sort();
9
+ const sortedProjectNames = Object.keys(projects).sort();
12
10
  // Used for expanding implicit dependencies (e.g. `@proj/*` or `tag:foo`)
13
- const partialProjectGraphNodes = projects.reduce((graph, project) => {
14
- const projectConfiguration = ctx.projects[project];
11
+ const partialProjectGraphNodes = sortedProjectNames.reduce((graph, project) => {
12
+ const projectConfiguration = projects[project];
15
13
  graph[project] = {
16
14
  name: project,
17
15
  type: projectConfiguration.projectType === 'library' ? 'lib' : 'app', // missing fallback to `e2e`
@@ -21,8 +19,9 @@ async function normalizeProjectNodes(ctx, builder) {
21
19
  };
22
20
  return graph;
23
21
  }, {});
24
- for (const key of projects) {
25
- const p = ctx.projects[key];
22
+ const toAdd = [];
23
+ for (const key of sortedProjectNames) {
24
+ const p = projects[key];
26
25
  p.implicitDependencies = normalizeImplicitDependencies(key, p.implicitDependencies, partialProjectGraphNodes);
27
26
  p.targets = normalizeProjectTargets(p, key);
28
27
  // TODO: remove in v16
@@ -31,7 +30,7 @@ async function normalizeProjectNodes(ctx, builder) {
31
30
  ? 'e2e'
32
31
  : 'app'
33
32
  : 'lib';
34
- const tags = ctx.projects?.[key]?.tags || [];
33
+ const tags = p.tags || [];
35
34
  toAdd.push({
36
35
  name: key,
37
36
  type: projectType,
@@ -69,11 +68,6 @@ function normalizeProjectTargets(project, projectName) {
69
68
  delete targets[target];
70
69
  continue;
71
70
  }
72
- targets[target].options = (0, project_configuration_utils_1.resolveNxTokensInOptions)(targets[target].options, project, `${projectName}:${target}`);
73
- targets[target].configurations ??= {};
74
- for (const configuration in targets[target].configurations) {
75
- targets[target].configurations[configuration] = (0, project_configuration_utils_1.resolveNxTokensInOptions)(targets[target].configurations[configuration], project, `${projectName}:${target}:${configuration}`);
76
- }
77
71
  }
78
72
  return targets;
79
73
  }
@@ -1,20 +1,36 @@
1
1
  import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
2
2
  import { ProjectGraphExternalNode } from '../../config/project-graph';
3
- import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
3
+ import { ProjectConfiguration, ProjectMetadata, TargetConfiguration, TargetMetadata } from '../../config/workspace-json-project-json';
4
4
  import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/symbols';
5
5
  import { LoadedNxPlugin } from '../plugins/internal-api';
6
- export type SourceInformation = [file: string, plugin: string];
6
+ export type SourceInformation = [file: string | null, plugin: string];
7
7
  export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
8
- export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Map<string, ProjectConfiguration>, project: ProjectConfiguration & {
8
+ export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration & {
9
9
  targets?: Record<string, TargetConfiguration & {
10
10
  [ONLY_MODIFIES_EXISTING_TARGET]?: boolean;
11
11
  }>;
12
- }, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipCommandNormalization?: boolean): void;
12
+ }, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipTargetNormalization?: boolean): void;
13
+ export declare function mergeMetadata<T = ProjectMetadata | TargetMetadata>(sourceMap: Record<string, [file: string, plugin: string]>, sourceInformation: [file: string, plugin: string], baseSourceMapPath: string, metadata: T, matchingMetadata?: T): T;
13
14
  export type ConfigurationResult = {
14
- projects: Record<string, ProjectConfiguration>;
15
+ /**
16
+ * A map of project configurations, keyed by project root.
17
+ */
18
+ projects: {
19
+ [projectRoot: string]: ProjectConfiguration;
20
+ };
21
+ /**
22
+ * Node Name -> Node info
23
+ */
15
24
  externalNodes: Record<string, ProjectGraphExternalNode>;
25
+ /**
26
+ * Project Root -> Project Name
27
+ */
16
28
  projectRootMap: Record<string, string>;
17
29
  sourceMaps: ConfigurationSourceMaps;
30
+ /**
31
+ * The list of files that were used to create project configurations
32
+ */
33
+ matchingProjectFiles: string[];
18
34
  };
19
35
  /**
20
36
  * Transforms a list of project paths into a map of project configurations.
@@ -26,7 +42,7 @@ export type ConfigurationResult = {
26
42
  */
27
43
  export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
28
44
  plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
29
- export declare function readProjectConfigurationsFromRootMap(projectRootMap: Map<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
45
+ export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
30
46
  /**
31
47
  * Merges two targets.
32
48
  *
@@ -51,3 +67,4 @@ export declare function mergeTargetConfigurations(target: TargetConfiguration, b
51
67
  export declare function isCompatibleTarget(a: TargetConfiguration, b: TargetConfiguration): boolean;
52
68
  export declare function resolveNxTokensInOptions<T extends Object | Array<unknown>>(object: T, project: ProjectConfiguration, key: string): T;
53
69
  export declare function readTargetDefaultsForTarget(targetName: string, targetDefaults: TargetDefaults, executor?: string): TargetDefaults[string];
70
+ export declare function normalizeTarget(target: TargetConfiguration, project: ProjectConfiguration): TargetConfiguration<any>;