nx 18.2.0-canary.20240321-2a4c57d → 18.2.0-canary.20240322-61cb63d

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildProjectGraphUsingProjectFileMap = exports.getFileMap = void 0;
3
+ exports.CreateDependenciesError = exports.ProcessProjectGraphError = exports.ProcessDependenciesError = exports.buildProjectGraphUsingProjectFileMap = exports.getFileMap = void 0;
4
4
  const workspace_root_1 = require("../utils/workspace-root");
5
5
  const path_1 = require("path");
6
6
  const perf_hooks_1 = require("perf_hooks");
@@ -39,7 +39,7 @@ function getFileMap() {
39
39
  }
40
40
  }
41
41
  exports.getFileMap = getFileMap;
42
- async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache, shouldWriteCache) {
42
+ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache) {
43
43
  storedFileMap = fileMap;
44
44
  storedAllWorkspaceFiles = allWorkspaceFiles;
45
45
  storedRustReferences = rustReferences;
@@ -65,11 +65,8 @@ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fil
65
65
  };
66
66
  }
67
67
  const context = createContext(projects, nxJson, externalNodes, fileMap, filesToProcess);
68
- let projectGraph = await buildProjectGraphUsingContext(nxJson, externalNodes, context, cachedFileData, projectGraphVersion);
68
+ let projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion);
69
69
  const projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig);
70
- if (shouldWriteCache) {
71
- (0, nx_deps_cache_1.writeCache)(projectFileMapCache, projectGraph);
72
- }
73
70
  return {
74
71
  projectGraph,
75
72
  projectFileMapCache,
@@ -92,7 +89,7 @@ function readCombinedDeps() {
92
89
  ...installationPackageJson.devDependencies,
93
90
  };
94
91
  }
95
- async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, cachedFileData, projectGraphVersion) {
92
+ async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFileData, projectGraphVersion) {
96
93
  perf_hooks_1.performance.mark('build project graph:start');
97
94
  const builder = new project_graph_builder_1.ProjectGraphBuilder(null, ctx.fileMap.projectFileMap);
98
95
  builder.setVersion(projectGraphVersion);
@@ -101,8 +98,21 @@ async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, ca
101
98
  }
102
99
  await (0, normalize_project_nodes_1.normalizeProjectNodes)(ctx, builder);
103
100
  const initProjectGraph = builder.getUpdatedProjectGraph();
104
- const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
105
- const updatedBuilder = new project_graph_builder_1.ProjectGraphBuilder(r, ctx.fileMap.projectFileMap);
101
+ let updatedGraph;
102
+ let error;
103
+ try {
104
+ updatedGraph = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
105
+ }
106
+ catch (e) {
107
+ if (e instanceof CreateDependenciesError) {
108
+ updatedGraph = e.partialProjectGraph;
109
+ error = e;
110
+ }
111
+ else {
112
+ throw e;
113
+ }
114
+ }
115
+ const updatedBuilder = new project_graph_builder_1.ProjectGraphBuilder(updatedGraph, ctx.fileMap.projectFileMap);
106
116
  for (const proj of Object.keys(cachedFileData.projectFileMap)) {
107
117
  for (const f of ctx.fileMap.projectFileMap[proj] || []) {
108
118
  const cached = cachedFileData.projectFileMap[proj][f.file];
@@ -121,7 +131,12 @@ async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, ca
121
131
  const finalGraph = updatedBuilder.getUpdatedProjectGraph();
122
132
  perf_hooks_1.performance.mark('build project graph:end');
123
133
  perf_hooks_1.performance.measure('build project graph', 'build project graph:start', 'build project graph:end');
124
- return finalGraph;
134
+ if (!error) {
135
+ return finalGraph;
136
+ }
137
+ else {
138
+ throw new CreateDependenciesError(error.errors, finalGraph);
139
+ }
125
140
  }
126
141
  function createContext(projects, nxJson, externalNodes, fileMap, filesToProcess) {
127
142
  const clonedProjects = Object.keys(projects).reduce((map, projectName) => {
@@ -142,6 +157,7 @@ function createContext(projects, nxJson, externalNodes, fileMap, filesToProcess)
142
157
  async function updateProjectGraphWithPlugins(context, initProjectGraph) {
143
158
  const plugins = await (0, nx_plugin_1.loadNxPlugins)(context.nxJsonConfiguration?.plugins, (0, installation_directory_1.getNxRequirePaths)(), context.workspaceRoot, context.projects);
144
159
  let graph = initProjectGraph;
160
+ const errors = [];
145
161
  for (const { plugin } of plugins) {
146
162
  try {
147
163
  if ((0, nx_plugin_1.isNxPluginV1)(plugin) &&
@@ -173,12 +189,9 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph) {
173
189
  }
174
190
  }
175
191
  catch (e) {
176
- let message = `Failed to process the project graph with "${plugin.name}".`;
177
- if (e instanceof Error) {
178
- e.message = message + '\n' + e.message;
179
- throw e;
180
- }
181
- throw new Error(message);
192
+ errors.push(new ProcessProjectGraphError(plugin.name, {
193
+ cause: e,
194
+ }));
182
195
  }
183
196
  }
184
197
  const builder = new project_graph_builder_1.ProjectGraphBuilder(graph, context.fileMap.projectFileMap, context.fileMap.nonProjectFiles);
@@ -193,19 +206,53 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph) {
193
206
  builder.addDependency(dep.source, dep.target, dep.type, 'sourceFile' in dep ? dep.sourceFile : null);
194
207
  }
195
208
  }
196
- catch (e) {
197
- let message = `Failed to process project dependencies with "${plugin.name}".`;
198
- if (e instanceof Error) {
199
- e.message = message + '\n' + e.message;
200
- throw e;
201
- }
202
- throw new Error(message);
209
+ catch (cause) {
210
+ errors.push(new ProcessDependenciesError(plugin.name, {
211
+ cause,
212
+ }));
203
213
  }
204
214
  perf_hooks_1.performance.mark(`${plugin.name}:createDependencies - end`);
205
215
  perf_hooks_1.performance.measure(`${plugin.name}:createDependencies`, `${plugin.name}:createDependencies - start`, `${plugin.name}:createDependencies - end`);
206
216
  }));
207
- return builder.getUpdatedProjectGraph();
217
+ const result = builder.getUpdatedProjectGraph();
218
+ if (errors.length === 0) {
219
+ return result;
220
+ }
221
+ else {
222
+ throw new CreateDependenciesError(errors, result);
223
+ }
224
+ }
225
+ class ProcessDependenciesError extends Error {
226
+ constructor(pluginName, { cause }) {
227
+ super(`The "${pluginName}" plugin threw an error while creating dependencies:`, {
228
+ cause,
229
+ });
230
+ this.pluginName = pluginName;
231
+ this.name = this.constructor.name;
232
+ this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
233
+ }
234
+ }
235
+ exports.ProcessDependenciesError = ProcessDependenciesError;
236
+ class ProcessProjectGraphError extends Error {
237
+ constructor(pluginName, { cause }) {
238
+ super(`The "${pluginName}" plugin threw an error while processing the project graph:`, {
239
+ cause,
240
+ });
241
+ this.pluginName = pluginName;
242
+ this.name = this.constructor.name;
243
+ this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
244
+ }
245
+ }
246
+ exports.ProcessProjectGraphError = ProcessProjectGraphError;
247
+ class CreateDependenciesError extends Error {
248
+ constructor(errors, partialProjectGraph) {
249
+ super('Failed to create dependencies. See above for errors');
250
+ this.errors = errors;
251
+ this.partialProjectGraph = partialProjectGraph;
252
+ this.name = this.constructor.name;
253
+ }
208
254
  }
255
+ exports.CreateDependenciesError = CreateDependenciesError;
209
256
  function readRootTsConfig() {
210
257
  try {
211
258
  const tsConfigPath = (0, typescript_1.getRootTsConfigPath)();
@@ -1,5 +1,8 @@
1
+ import { ProcessDependenciesError, ProcessProjectGraphError } from './build-project-graph';
1
2
  import { ProjectGraph } from '../config/project-graph';
2
3
  import { ProjectConfiguration, ProjectsConfigurations } from '../config/workspace-json-project-json';
4
+ import { ConfigurationSourceMaps, CreateNodesError, MergeNodesError } from './utils/project-configuration-utils';
5
+ import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error';
3
6
  /**
4
7
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
5
8
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -12,8 +15,26 @@ export declare function readCachedProjectConfiguration(projectName: string): Pro
12
15
  export declare function readProjectsConfigurationFromProjectGraph(projectGraph: ProjectGraph): ProjectsConfigurations;
13
16
  export declare function buildProjectGraphAndSourceMapsWithoutDaemon(): Promise<{
14
17
  projectGraph: ProjectGraph;
15
- sourceMaps: import("./utils/project-configuration-utils").ConfigurationSourceMaps;
18
+ sourceMaps: ConfigurationSourceMaps;
16
19
  }>;
20
+ export declare class ProjectGraphError extends Error {
21
+ #private;
22
+ constructor(errors: Array<CreateNodesError | MergeNodesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
23
+ /**
24
+ * The daemon cannot throw errors which contain methods as they are not serializable.
25
+ *
26
+ * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
27
+ */
28
+ static fromDaemonProjectGraphError(e: DaemonProjectGraphError): ProjectGraphError;
29
+ /**
30
+ * This gets the partial project graph despite the errors which occured.
31
+ * This partial project graph may be missing nodes, properties of nodes, or dependencies.
32
+ * This is useful mostly for visualization/debugging. It should not be used for running tasks.
33
+ */
34
+ getPartialProjectGraph(): ProjectGraph;
35
+ getPartialSourcemaps(): ConfigurationSourceMaps;
36
+ getErrors(): (ProcessDependenciesError | ProcessProjectGraphError | CreateNodesError)[];
37
+ }
17
38
  /**
18
39
  * Computes and returns a ProjectGraph.
19
40
  *
@@ -44,5 +65,5 @@ export declare function createProjectGraphAndSourceMapsAsync(opts?: {
44
65
  resetDaemonClient?: boolean;
45
66
  }): Promise<{
46
67
  projectGraph: ProjectGraph;
47
- sourceMaps: import("./utils/project-configuration-utils").ConfigurationSourceMaps;
68
+ sourceMaps: ConfigurationSourceMaps;
48
69
  }>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
+ var _ProjectGraphError_errors, _ProjectGraphError_partialProjectGraph, _ProjectGraphError_partialSourceMaps;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
4
+ exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.ProjectGraphError = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
5
+ const tslib_1 = require("tslib");
4
6
  const nx_deps_cache_1 = require("./nx-deps-cache");
5
7
  const build_project_graph_1 = require("./build-project-graph");
6
8
  const output_1 = require("../utils/output");
@@ -13,6 +15,7 @@ const perf_hooks_1 = require("perf_hooks");
13
15
  const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
14
16
  const nx_json_1 = require("../config/nx-json");
15
17
  const nx_plugin_1 = require("../utils/nx-plugin");
18
+ const project_configuration_utils_1 = require("./utils/project-configuration-utils");
16
19
  /**
17
20
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
18
21
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -70,29 +73,127 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
70
73
  global.NX_GRAPH_CREATION = true;
71
74
  const nxJson = (0, nx_json_1.readNxJson)();
72
75
  perf_hooks_1.performance.mark('retrieve-project-configurations:start');
73
- const { projects, externalNodes, sourceMaps, projectRootMap } = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
76
+ let configurationResult;
77
+ let projectConfigurationsError;
78
+ try {
79
+ configurationResult = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
80
+ }
81
+ catch (e) {
82
+ if (e instanceof project_configuration_utils_1.ProjectConfigurationsError) {
83
+ projectConfigurationsError = e;
84
+ configurationResult = e.partialProjectConfigurationsResult;
85
+ }
86
+ else {
87
+ throw e;
88
+ }
89
+ }
90
+ const { projects, externalNodes, sourceMaps, projectRootMap } = configurationResult;
74
91
  perf_hooks_1.performance.mark('retrieve-project-configurations:end');
75
92
  perf_hooks_1.performance.mark('retrieve-workspace-files:start');
76
93
  const { allWorkspaceFiles, fileMap, rustReferences } = await (0, retrieve_workspace_files_1.retrieveWorkspaceFiles)(workspace_root_1.workspaceRoot, projectRootMap);
77
94
  perf_hooks_1.performance.mark('retrieve-workspace-files:end');
78
95
  const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
79
96
  perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
80
- const projectGraph = (await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, cacheEnabled)).projectGraph;
97
+ let createDependenciesError;
98
+ let projectGraphResult;
99
+ try {
100
+ projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null);
101
+ }
102
+ catch (e) {
103
+ if (e instanceof build_project_graph_1.CreateDependenciesError) {
104
+ projectGraphResult = {
105
+ projectGraph: e.partialProjectGraph,
106
+ projectFileMapCache: null,
107
+ };
108
+ createDependenciesError = e;
109
+ }
110
+ else {
111
+ throw e;
112
+ }
113
+ }
114
+ const { projectGraph, projectFileMapCache } = projectGraphResult;
81
115
  perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:end');
82
116
  (0, nx_plugin_1.unregisterPluginTSTranspiler)();
83
117
  delete global.NX_GRAPH_CREATION;
84
- return { projectGraph, sourceMaps };
118
+ const errors = [
119
+ ...(projectConfigurationsError?.errors ?? []),
120
+ ...(createDependenciesError?.errors ?? []),
121
+ ];
122
+ if (errors.length > 0) {
123
+ throw new ProjectGraphError(errors, projectGraph, sourceMaps);
124
+ }
125
+ else {
126
+ if (cacheEnabled) {
127
+ (0, nx_deps_cache_1.writeCache)(projectFileMapCache, projectGraph);
128
+ }
129
+ return { projectGraph, sourceMaps };
130
+ }
85
131
  }
86
132
  exports.buildProjectGraphAndSourceMapsWithoutDaemon = buildProjectGraphAndSourceMapsWithoutDaemon;
133
+ class ProjectGraphError extends Error {
134
+ constructor(errors, partialProjectGraph, partialSourceMaps) {
135
+ super(`Failed to process project graph.`);
136
+ _ProjectGraphError_errors.set(this, void 0);
137
+ _ProjectGraphError_partialProjectGraph.set(this, void 0);
138
+ _ProjectGraphError_partialSourceMaps.set(this, void 0);
139
+ this.name = this.constructor.name;
140
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_errors, errors, "f");
141
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialProjectGraph, partialProjectGraph, "f");
142
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialSourceMaps, partialSourceMaps, "f");
143
+ this.stack = `${this.message}\n ${errors
144
+ .map((error) => error.stack.split('\n').join('\n '))
145
+ .join('\n')}`;
146
+ }
147
+ /**
148
+ * The daemon cannot throw errors which contain methods as they are not serializable.
149
+ *
150
+ * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
151
+ */
152
+ static fromDaemonProjectGraphError(e) {
153
+ return new ProjectGraphError(e.errors, e.projectGraph, e.sourceMaps);
154
+ }
155
+ /**
156
+ * This gets the partial project graph despite the errors which occured.
157
+ * This partial project graph may be missing nodes, properties of nodes, or dependencies.
158
+ * This is useful mostly for visualization/debugging. It should not be used for running tasks.
159
+ */
160
+ getPartialProjectGraph() {
161
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialProjectGraph, "f");
162
+ }
163
+ getPartialSourcemaps() {
164
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialSourceMaps, "f");
165
+ }
166
+ getErrors() {
167
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_errors, "f");
168
+ }
169
+ }
170
+ exports.ProjectGraphError = ProjectGraphError;
171
+ _ProjectGraphError_errors = new WeakMap(), _ProjectGraphError_partialProjectGraph = new WeakMap(), _ProjectGraphError_partialSourceMaps = new WeakMap();
87
172
  function handleProjectGraphError(opts, e) {
88
173
  if (opts.exitOnError) {
89
- const lines = e.message.split('\n');
90
- output_1.output.error({
91
- title: lines[0],
92
- bodyLines: lines.slice(1),
93
- });
94
- if (process.env.NX_VERBOSE_LOGGING === 'true') {
95
- console.error(e);
174
+ const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
175
+ if (e instanceof ProjectGraphError) {
176
+ let title = e.message;
177
+ if (isVerbose) {
178
+ title += ' See errors below.';
179
+ }
180
+ const bodyLines = isVerbose
181
+ ? [e.stack]
182
+ : ['Pass --verbose to see the stacktraces.'];
183
+ output_1.output.error({
184
+ title,
185
+ bodyLines: bodyLines,
186
+ });
187
+ }
188
+ else {
189
+ const lines = e.message.split('\n');
190
+ output_1.output.error({
191
+ title: lines[0],
192
+ bodyLines: lines.slice(1),
193
+ });
194
+ if (isVerbose) {
195
+ console.error(e);
196
+ }
96
197
  }
97
198
  process.exit(1);
98
199
  }
@@ -151,9 +252,6 @@ async function createProjectGraphAndSourceMapsAsync(opts = {
151
252
  else {
152
253
  try {
153
254
  const projectGraphAndSourceMaps = await client_1.daemonClient.getProjectGraphAndSourceMaps();
154
- if (opts.resetDaemonClient) {
155
- client_1.daemonClient.reset();
156
- }
157
255
  perf_hooks_1.performance.mark('create-project-graph-async:end');
158
256
  perf_hooks_1.performance.measure('create-project-graph-async', 'create-project-graph-async:start', 'create-project-graph-async:end');
159
257
  return projectGraphAndSourceMaps;
@@ -186,6 +284,11 @@ async function createProjectGraphAndSourceMapsAsync(opts = {
186
284
  }
187
285
  handleProjectGraphError(opts, e);
188
286
  }
287
+ finally {
288
+ if (opts.resetDaemonClient) {
289
+ client_1.daemonClient.reset();
290
+ }
291
+ }
189
292
  }
190
293
  }
191
294
  exports.createProjectGraphAndSourceMapsAsync = createProjectGraphAndSourceMapsAsync;
@@ -13,20 +13,43 @@ export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Map
13
13
  export type ConfigurationResult = {
14
14
  projects: Record<string, ProjectConfiguration>;
15
15
  externalNodes: Record<string, ProjectGraphExternalNode>;
16
- rootMap: Record<string, string>;
16
+ projectRootMap: Record<string, string>;
17
17
  sourceMaps: ConfigurationSourceMaps;
18
18
  };
19
19
  /**
20
20
  * Transforms a list of project paths into a map of project configurations.
21
21
  *
22
+ * @param root The workspace root
22
23
  * @param nxJson The NxJson configuration
23
24
  * @param workspaceFiles A list of non-ignored workspace files
24
25
  * @param plugins The plugins that should be used to infer project configuration
25
- * @param root The workspace root
26
26
  */
27
- export declare function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson: NxJsonConfiguration, workspaceFiles: string[], // making this parameter allows devkit to pick up newly created projects
28
- plugins: LoadedNxPlugin[], root?: string): Promise<ConfigurationResult>;
27
+ export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, workspaceFiles: string[], // making this parameter allows devkit to pick up newly created projects
28
+ plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
29
29
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Map<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
30
+ export declare class ProjectConfigurationsError extends Error {
31
+ readonly errors: Array<MergeNodesError | CreateNodesError>;
32
+ readonly partialProjectConfigurationsResult: ConfigurationResult;
33
+ constructor(errors: Array<MergeNodesError | CreateNodesError>, partialProjectConfigurationsResult: ConfigurationResult);
34
+ }
35
+ export declare class CreateNodesError extends Error {
36
+ file: string;
37
+ pluginName: string;
38
+ constructor({ file, pluginName, error, }: {
39
+ file: string;
40
+ pluginName: string;
41
+ error: Error;
42
+ });
43
+ }
44
+ export declare class MergeNodesError extends Error {
45
+ file: string;
46
+ pluginName: string;
47
+ constructor({ file, pluginName, error, }: {
48
+ file: string;
49
+ pluginName: string;
50
+ error: Error;
51
+ });
52
+ }
30
53
  /**
31
54
  * Merges two targets.
32
55
  *
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.readProjectConfigurationsFromRootMap = exports.buildProjectsConfigurationsFromProjectPathsAndPlugins = exports.mergeProjectConfigurationIntoRootMap = void 0;
3
+ exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.MergeNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeProjectConfigurationIntoRootMap = void 0;
4
4
  const logger_1 = require("../../utils/logger");
5
5
  const fileutils_1 = require("../../utils/fileutils");
6
6
  const workspace_root_1 = require("../../utils/workspace-root");
7
7
  const target_defaults_plugin_1 = require("../../plugins/target-defaults/target-defaults-plugin");
8
8
  const minimatch_1 = require("minimatch");
9
9
  const path_1 = require("path");
10
+ const perf_hooks_1 = require("perf_hooks");
10
11
  function mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInformation,
11
12
  // This function is used when reading project configuration
12
13
  // in generators, where we don't want to do this.
@@ -208,25 +209,27 @@ exports.mergeProjectConfigurationIntoRootMap = mergeProjectConfigurationIntoRoot
208
209
  /**
209
210
  * Transforms a list of project paths into a map of project configurations.
210
211
  *
212
+ * @param root The workspace root
211
213
  * @param nxJson The NxJson configuration
212
214
  * @param workspaceFiles A list of non-ignored workspace files
213
215
  * @param plugins The plugins that should be used to infer project configuration
214
- * @param root The workspace root
215
216
  */
216
- function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson, workspaceFiles, // making this parameter allows devkit to pick up newly created projects
217
- plugins, root = workspace_root_1.workspaceRoot) {
217
+ function createProjectConfigurations(root = workspace_root_1.workspaceRoot, nxJson, workspaceFiles, // making this parameter allows devkit to pick up newly created projects
218
+ plugins) {
219
+ perf_hooks_1.performance.mark('build-project-configs:start');
218
220
  const results = [];
221
+ const errors = [];
219
222
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
220
223
  for (const { plugin, options } of plugins) {
221
224
  const [pattern, createNodes] = plugin.createNodes ?? [];
222
225
  const pluginResults = [];
223
- performance.mark(`${plugin.name}:createNodes - start`);
226
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes - start`);
224
227
  if (!pattern) {
225
228
  continue;
226
229
  }
227
230
  const matchingConfigFiles = workspaceFiles.filter(minimatch_1.minimatch.filter(pattern, { dot: true }));
228
231
  for (const file of matchingConfigFiles) {
229
- performance.mark(`${plugin.name}:createNodes:${file} - start`);
232
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - start`);
230
233
  try {
231
234
  let r = createNodes(file, options, {
232
235
  nxJsonConfiguration: nxJson,
@@ -235,19 +238,26 @@ plugins, root = workspace_root_1.workspaceRoot) {
235
238
  });
236
239
  if (r instanceof Promise) {
237
240
  pluginResults.push(r
238
- .catch((e) => {
239
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
240
- throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
241
+ .catch((error) => {
242
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
243
+ errors.push(new CreateNodesError({
244
+ file,
245
+ pluginName: plugin.name,
246
+ error,
247
+ }));
248
+ return {
249
+ projects: {},
250
+ };
241
251
  })
242
252
  .then((r) => {
243
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
244
- performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
253
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
254
+ perf_hooks_1.performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
245
255
  return { ...r, file, pluginName: plugin.name };
246
256
  }));
247
257
  }
248
258
  else {
249
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
250
- performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
259
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
260
+ perf_hooks_1.performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
251
261
  pluginResults.push({
252
262
  ...r,
253
263
  file,
@@ -255,19 +265,22 @@ plugins, root = workspace_root_1.workspaceRoot) {
255
265
  });
256
266
  }
257
267
  }
258
- catch (e) {
259
- throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
268
+ catch (error) {
269
+ errors.push(new CreateNodesError({
270
+ file,
271
+ pluginName: plugin.name,
272
+ error,
273
+ }));
260
274
  }
261
275
  }
262
- // If there are no promises (counter undefined) or all promises have resolved (counter === 0)
263
276
  results.push(Promise.all(pluginResults).then((results) => {
264
- performance.mark(`${plugin.name}:createNodes - end`);
265
- performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
277
+ perf_hooks_1.performance.mark(`${plugin.name}:createNodes - end`);
278
+ perf_hooks_1.performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
266
279
  return results;
267
280
  }));
268
281
  }
269
282
  return Promise.all(results).then((results) => {
270
- performance.mark('createNodes:merge - start');
283
+ perf_hooks_1.performance.mark('createNodes:merge - start');
271
284
  const projectRootMap = new Map();
272
285
  const externalNodes = {};
273
286
  const configurationSourceMaps = {};
@@ -285,25 +298,41 @@ plugins, root = workspace_root_1.workspaceRoot) {
285
298
  try {
286
299
  mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInfo);
287
300
  }
288
- catch (e) {
289
- throw new CreateNodesError(`Unable to merge project information for "${project.root}" from ${result.file} using plugin ${result.pluginName}.`, e);
301
+ catch (error) {
302
+ errors.push(new MergeNodesError({
303
+ file,
304
+ pluginName,
305
+ error,
306
+ }));
290
307
  }
291
308
  }
292
309
  Object.assign(externalNodes, pluginExternalNodes);
293
310
  }
294
311
  const projects = readProjectConfigurationsFromRootMap(projectRootMap);
295
312
  const rootMap = createRootMap(projectRootMap);
296
- performance.mark('createNodes:merge - end');
297
- performance.measure('createNodes:merge', 'createNodes:merge - start', 'createNodes:merge - end');
298
- return {
299
- projects,
300
- externalNodes,
301
- rootMap,
302
- sourceMaps: configurationSourceMaps,
303
- };
313
+ perf_hooks_1.performance.mark('createNodes:merge - end');
314
+ perf_hooks_1.performance.measure('createNodes:merge', 'createNodes:merge - start', 'createNodes:merge - end');
315
+ perf_hooks_1.performance.mark('build-project-configs:end');
316
+ perf_hooks_1.performance.measure('build-project-configs', 'build-project-configs:start', 'build-project-configs:end');
317
+ if (errors.length === 0) {
318
+ return {
319
+ projects,
320
+ externalNodes,
321
+ projectRootMap: rootMap,
322
+ sourceMaps: configurationSourceMaps,
323
+ };
324
+ }
325
+ else {
326
+ throw new ProjectConfigurationsError(errors, {
327
+ projects,
328
+ externalNodes,
329
+ projectRootMap: rootMap,
330
+ sourceMaps: configurationSourceMaps,
331
+ });
332
+ }
304
333
  });
305
334
  }
306
- exports.buildProjectsConfigurationsFromProjectPathsAndPlugins = buildProjectsConfigurationsFromProjectPathsAndPlugins;
335
+ exports.createProjectConfigurations = createProjectConfigurations;
307
336
  function readProjectConfigurationsFromRootMap(projectRootMap) {
308
337
  const projects = {};
309
338
  // If there are projects that have the same name, that is an error.
@@ -346,20 +375,37 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
346
375
  return projects;
347
376
  }
348
377
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
378
+ class ProjectConfigurationsError extends Error {
379
+ constructor(errors, partialProjectConfigurationsResult) {
380
+ super('Failed to create project configurations');
381
+ this.errors = errors;
382
+ this.partialProjectConfigurationsResult = partialProjectConfigurationsResult;
383
+ this.name = this.constructor.name;
384
+ }
385
+ }
386
+ exports.ProjectConfigurationsError = ProjectConfigurationsError;
349
387
  class CreateNodesError extends Error {
350
- constructor(msg, cause) {
351
- const message = `${msg} ${!cause
352
- ? ''
353
- : cause instanceof Error
354
- ? `\n\n\t Inner Error: ${cause.stack}`
355
- : cause}`;
356
- // These errors are thrown during a JS callback which is invoked via rust.
357
- // The errors messaging gets lost in the rust -> js -> rust transition, but
358
- // logging the error here will ensure that it is visible in the console.
359
- console.error(message);
360
- super(message, { cause });
388
+ constructor({ file, pluginName, error, }) {
389
+ const msg = `The "${pluginName}" plugin threw an error while creating nodes from ${file}:`;
390
+ super(msg, { cause: error });
391
+ this.name = this.constructor.name;
392
+ this.file = file;
393
+ this.pluginName = pluginName;
394
+ this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
395
+ }
396
+ }
397
+ exports.CreateNodesError = CreateNodesError;
398
+ class MergeNodesError extends Error {
399
+ constructor({ file, pluginName, error, }) {
400
+ const msg = `The nodes created from ${file} by the "${pluginName}" could not be merged into the project graph:`;
401
+ super(msg, { cause: error });
402
+ this.name = this.constructor.name;
403
+ this.file = file;
404
+ this.pluginName = pluginName;
405
+ this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
361
406
  }
362
407
  }
408
+ exports.MergeNodesError = MergeNodesError;
363
409
  /**
364
410
  * Merges two targets.
365
411
  *