nx 18.1.1 → 18.2.0-beta.0

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 (47) hide show
  1. package/package.json +12 -12
  2. package/src/adapter/compat.d.ts +1 -1
  3. package/src/adapter/compat.js +1 -0
  4. package/src/command-line/add/add.js +1 -1
  5. package/src/command-line/affected/command-object.js +49 -22
  6. package/src/command-line/generate/generate.js +3 -3
  7. package/src/command-line/init/init-v2.js +43 -31
  8. package/src/command-line/run/command-object.js +9 -2
  9. package/src/command-line/run/run-one.js +1 -1
  10. package/src/command-line/run/run.js +15 -5
  11. package/src/command-line/run-many/command-object.js +4 -1
  12. package/src/command-line/show/command-object.d.ts +2 -0
  13. package/src/command-line/show/command-object.js +19 -2
  14. package/src/config/workspace-json-project-json.d.ts +4 -0
  15. package/src/core/graph/main.js +1 -1
  16. package/src/core/graph/polyfills.js +1 -1
  17. package/src/daemon/client/client.js +19 -7
  18. package/src/daemon/daemon-project-graph-error.d.ts +8 -0
  19. package/src/daemon/daemon-project-graph-error.js +13 -0
  20. package/src/daemon/server/handle-hash-tasks.js +11 -1
  21. package/src/daemon/server/project-graph-incremental-recomputation.d.ts +1 -0
  22. package/src/daemon/server/project-graph-incremental-recomputation.js +55 -6
  23. package/src/daemon/server/shutdown-utils.js +1 -3
  24. package/src/daemon/socket-utils.js +7 -1
  25. package/src/executors/run-commands/run-commands.impl.js +15 -9
  26. package/src/executors/run-script/run-script.impl.js +1 -1
  27. package/src/plugins/js/index.js +1 -1
  28. package/src/plugins/js/lock-file/lock-file.d.ts +2 -2
  29. package/src/plugins/js/lock-file/lock-file.js +2 -2
  30. package/src/plugins/js/versions.d.ts +1 -1
  31. package/src/plugins/js/versions.js +1 -1
  32. package/src/project-graph/build-project-graph.d.ts +18 -1
  33. package/src/project-graph/build-project-graph.js +71 -24
  34. package/src/project-graph/project-graph.d.ts +23 -2
  35. package/src/project-graph/project-graph.js +117 -14
  36. package/src/project-graph/utils/project-configuration-utils.d.ts +27 -4
  37. package/src/project-graph/utils/project-configuration-utils.js +176 -45
  38. package/src/project-graph/utils/retrieve-workspace-files.d.ts +6 -14
  39. package/src/project-graph/utils/retrieve-workspace-files.js +3 -16
  40. package/src/tasks-runner/forked-process-task-runner.d.ts +2 -1
  41. package/src/tasks-runner/forked-process-task-runner.js +19 -8
  42. package/src/tasks-runner/pseudo-terminal.d.ts +2 -1
  43. package/src/tasks-runner/pseudo-terminal.js +27 -1
  44. package/src/tasks-runner/task-orchestrator.js +4 -22
  45. package/src/utils/output.d.ts +1 -1
  46. package/src/utils/params.d.ts +2 -2
  47. package/src/utils/params.js +14 -0
@@ -18,6 +18,8 @@ const promised_based_queue_1 = require("../../utils/promised-based-queue");
18
18
  const nx_json_1 = require("../../config/nx-json");
19
19
  const daemon_socket_messenger_1 = require("./daemon-socket-messenger");
20
20
  const cache_1 = require("../cache");
21
+ const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
22
+ const project_graph_1 = require("../../project-graph/project-graph");
21
23
  const DAEMON_ENV_SETTINGS = {
22
24
  ...process.env,
23
25
  NX_PROJECT_GLOB_CACHE: 'false',
@@ -90,13 +92,23 @@ class DaemonClient {
90
92
  return this.sendToDaemonViaQueue({ type: 'REQUEST_SHUTDOWN' });
91
93
  }
92
94
  async getProjectGraphAndSourceMaps() {
93
- const response = await this.sendToDaemonViaQueue({
94
- type: 'REQUEST_PROJECT_GRAPH',
95
- });
96
- return {
97
- projectGraph: response.projectGraph,
98
- sourceMaps: response.sourceMaps,
99
- };
95
+ try {
96
+ const response = await this.sendToDaemonViaQueue({
97
+ type: 'REQUEST_PROJECT_GRAPH',
98
+ });
99
+ return {
100
+ projectGraph: response.projectGraph,
101
+ sourceMaps: response.sourceMaps,
102
+ };
103
+ }
104
+ catch (e) {
105
+ if (e.name === daemon_project_graph_error_1.DaemonProjectGraphError.name) {
106
+ throw project_graph_1.ProjectGraphError.fromDaemonProjectGraphError(e);
107
+ }
108
+ else {
109
+ throw e;
110
+ }
111
+ }
100
112
  }
101
113
  async getAllFileData() {
102
114
  return await this.sendToDaemonViaQueue({ type: 'REQUEST_FILE_DATA' });
@@ -0,0 +1,8 @@
1
+ import { ProjectGraph } from '../config/project-graph';
2
+ import { ConfigurationSourceMaps } from '../project-graph/utils/project-configuration-utils';
3
+ export declare class DaemonProjectGraphError extends Error {
4
+ errors: any[];
5
+ readonly projectGraph: ProjectGraph;
6
+ readonly sourceMaps: ConfigurationSourceMaps;
7
+ constructor(errors: any[], projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps);
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DaemonProjectGraphError = void 0;
4
+ class DaemonProjectGraphError extends Error {
5
+ constructor(errors, projectGraph, sourceMaps) {
6
+ super(`The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.`);
7
+ this.errors = errors;
8
+ this.projectGraph = projectGraph;
9
+ this.sourceMaps = sourceMaps;
10
+ this.name = this.constructor.name;
11
+ }
12
+ }
13
+ exports.DaemonProjectGraphError = DaemonProjectGraphError;
@@ -4,6 +4,7 @@ exports.handleHashTasks = void 0;
4
4
  const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
5
5
  const task_hasher_1 = require("../../hasher/task-hasher");
6
6
  const configuration_1 = require("../../config/configuration");
7
+ const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
7
8
  /**
8
9
  * We use this not to recreated hasher for every hash operation
9
10
  * TaskHasher has a cache inside, so keeping it around results in faster performance
@@ -11,7 +12,16 @@ const configuration_1 = require("../../config/configuration");
11
12
  let storedProjectGraph = null;
12
13
  let storedHasher = null;
13
14
  async function handleHashTasks(payload) {
14
- const { projectGraph, allWorkspaceFiles, fileMap, rustReferences } = await (0, project_graph_incremental_recomputation_1.getCachedSerializedProjectGraphPromise)();
15
+ const { error, projectGraph: _graph, allWorkspaceFiles, fileMap, rustReferences, } = await (0, project_graph_incremental_recomputation_1.getCachedSerializedProjectGraphPromise)();
16
+ let projectGraph = _graph;
17
+ if (error) {
18
+ if (error instanceof daemon_project_graph_error_1.DaemonProjectGraphError) {
19
+ projectGraph = error.projectGraph;
20
+ }
21
+ else {
22
+ throw error;
23
+ }
24
+ }
15
25
  const nxJson = (0, configuration_1.readNxJson)();
16
26
  if (projectGraph !== storedProjectGraph) {
17
27
  storedProjectGraph = projectGraph;
@@ -4,6 +4,7 @@ import { NxWorkspaceFilesExternals } from '../../native';
4
4
  interface SerializedProjectGraph {
5
5
  error: Error | null;
6
6
  projectGraph: ProjectGraph | null;
7
+ projectFileMapCache: FileMapCache | null;
7
8
  fileMap: FileMap | null;
8
9
  allWorkspaceFiles: FileData[] | null;
9
10
  serializedProjectGraph: string | null;
@@ -13,6 +13,8 @@ const workspace_context_1 = require("../../utils/workspace-context");
13
13
  const workspace_root_1 = require("../../utils/workspace-root");
14
14
  const file_watcher_sockets_1 = require("./file-watching/file-watcher-sockets");
15
15
  const logger_1 = require("./logger");
16
+ const project_configuration_utils_1 = require("../../project-graph/utils/project-configuration-utils");
17
+ const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
16
18
  let cachedSerializedProjectGraphPromise;
17
19
  const collectedUpdatedFiles = new Set();
18
20
  const collectedDeletedFiles = new Set();
@@ -48,6 +50,7 @@ async function getCachedSerializedProjectGraphPromise() {
48
50
  serializedProjectGraph: null,
49
51
  serializedSourceMaps: null,
50
52
  projectGraph: null,
53
+ projectFileMapCache: null,
51
54
  fileMap: null,
52
55
  allWorkspaceFiles: null,
53
56
  rustReferences: null,
@@ -139,22 +142,66 @@ async function processFilesAndCreateAndSerializeProjectGraph() {
139
142
  const nxJson = (0, nx_json_1.readNxJson)(workspace_root_1.workspaceRoot);
140
143
  // Set this globally to allow plugins to know if they are being called from the project graph creation
141
144
  global.NX_GRAPH_CREATION = true;
142
- const graphNodes = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
145
+ let graphNodes;
146
+ let projectConfigurationsError;
147
+ try {
148
+ graphNodes = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
149
+ }
150
+ catch (e) {
151
+ if (e instanceof project_configuration_utils_1.ProjectConfigurationsError) {
152
+ graphNodes = e.partialProjectConfigurationsResult;
153
+ projectConfigurationsError = e;
154
+ }
155
+ }
143
156
  await processCollectedUpdatedAndDeletedFiles(graphNodes, updatedFileHashes, deletedFiles);
144
- const g = createAndSerializeProjectGraph(graphNodes);
157
+ const g = await createAndSerializeProjectGraph(graphNodes);
145
158
  delete global.NX_GRAPH_CREATION;
146
- return g;
159
+ const errors = [...(projectConfigurationsError?.errors ?? [])];
160
+ if (g.error) {
161
+ if (g.error instanceof build_project_graph_1.CreateDependenciesError) {
162
+ errors.concat(g.error.errors);
163
+ }
164
+ else {
165
+ return {
166
+ error: g.error,
167
+ projectGraph: null,
168
+ projectFileMapCache: null,
169
+ fileMap: null,
170
+ rustReferences: null,
171
+ allWorkspaceFiles: null,
172
+ serializedProjectGraph: null,
173
+ serializedSourceMaps: null,
174
+ };
175
+ }
176
+ }
177
+ if (errors.length > 0) {
178
+ return {
179
+ error: new daemon_project_graph_error_1.DaemonProjectGraphError(errors, g.projectGraph, graphNodes.sourceMaps),
180
+ projectGraph: null,
181
+ projectFileMapCache: null,
182
+ fileMap: null,
183
+ rustReferences: null,
184
+ allWorkspaceFiles: null,
185
+ serializedProjectGraph: null,
186
+ serializedSourceMaps: null,
187
+ };
188
+ }
189
+ else {
190
+ (0, nx_deps_cache_1.writeCache)(g.projectFileMapCache, g.projectGraph);
191
+ return g;
192
+ }
147
193
  }
148
194
  catch (err) {
149
- return Promise.resolve({
195
+ return {
150
196
  error: err,
151
197
  projectGraph: null,
198
+ projectFileMapCache: null,
152
199
  fileMap: null,
153
200
  rustReferences: null,
154
201
  allWorkspaceFiles: null,
155
202
  serializedProjectGraph: null,
156
203
  serializedSourceMaps: null,
157
- });
204
+ };
158
205
  }
159
206
  }
160
207
  function copyFileData(d) {
@@ -176,7 +223,7 @@ async function createAndSerializeProjectGraph({ projects, sourceMaps, }) {
176
223
  const fileMap = copyFileMap(exports.fileMapWithFiles.fileMap);
177
224
  const allWorkspaceFiles = copyFileData(exports.fileMapWithFiles.allWorkspaceFiles);
178
225
  const rustReferences = exports.fileMapWithFiles.rustReferences;
179
- const { projectGraph, projectFileMapCache } = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, knownExternalNodes, fileMap, allWorkspaceFiles, rustReferences, exports.currentProjectFileMapCache || (0, nx_deps_cache_1.readFileMapCache)(), true);
226
+ const { projectGraph, projectFileMapCache } = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, knownExternalNodes, fileMap, allWorkspaceFiles, rustReferences, exports.currentProjectFileMapCache || (0, nx_deps_cache_1.readFileMapCache)());
180
227
  exports.currentProjectFileMapCache = projectFileMapCache;
181
228
  exports.currentProjectGraph = projectGraph;
182
229
  perf_hooks_1.performance.mark('create-project-graph-end');
@@ -189,6 +236,7 @@ async function createAndSerializeProjectGraph({ projects, sourceMaps, }) {
189
236
  return {
190
237
  error: null,
191
238
  projectGraph,
239
+ projectFileMapCache,
192
240
  fileMap,
193
241
  allWorkspaceFiles,
194
242
  serializedProjectGraph,
@@ -201,6 +249,7 @@ async function createAndSerializeProjectGraph({ projects, sourceMaps, }) {
201
249
  return {
202
250
  error: e,
203
251
  projectGraph: null,
252
+ projectFileMapCache: null,
204
253
  fileMap: null,
205
254
  allWorkspaceFiles: null,
206
255
  serializedProjectGraph: null,
@@ -69,9 +69,7 @@ exports.respondToClient = respondToClient;
69
69
  async function respondWithErrorAndExit(socket, description, error) {
70
70
  // print some extra stuff in the error message
71
71
  logger_1.serverLogger.requestLog(`Responding to the client with an error.`, description, error.message);
72
- console.error(error);
73
- error.message = `${error.message}\n\nBecause of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\nIf the error persists, please run "nx reset".`;
72
+ console.error(error.stack);
74
73
  await respondToClient(socket, (0, socket_utils_1.serializeResult)(error, null, null), null);
75
- process.exit(1);
76
74
  }
77
75
  exports.respondWithErrorAndExit = respondWithErrorAndExit;
@@ -5,6 +5,7 @@ const fs_1 = require("fs");
5
5
  const os_1 = require("os");
6
6
  const path_1 = require("path");
7
7
  const tmp_dir_1 = require("./tmp-dir");
8
+ const daemon_project_graph_error_1 = require("./daemon-project-graph-error");
8
9
  exports.isWindows = (0, os_1.platform)() === 'win32';
9
10
  /**
10
11
  * For IPC with the daemon server we use unix sockets or windows named pipes, depending on the user's operating system.
@@ -32,7 +33,12 @@ function serializeError(error) {
32
33
  if (!error) {
33
34
  return null;
34
35
  }
35
- return JSON.stringify(error, Object.getOwnPropertyNames(error));
36
+ if (error instanceof daemon_project_graph_error_1.DaemonProjectGraphError) {
37
+ error.errors = error.errors.map((e) => JSON.parse(serializeError(e)));
38
+ }
39
+ return `{${Object.getOwnPropertyNames(error)
40
+ .map((k) => `"${k}": ${JSON.stringify(error[k])}`)
41
+ .join(',')}}`;
36
42
  }
37
43
  // Prepare a serialized project graph result for sending over IPC from the server to the client
38
44
  function serializeResult(error, serializedProjectGraph, serializedSourceMaps) {
@@ -47,11 +47,10 @@ async function default_1(options, context) {
47
47
  !options.parallel) {
48
48
  throw new Error('ERROR: Bad executor config for run-commands - "prefix", "color" and "bgColor" can only be set when "parallel=true".');
49
49
  }
50
- const terminal = (0, pseudo_terminal_1.getPseudoTerminal)();
51
50
  try {
52
51
  const result = options.parallel
53
- ? await runInParallel(terminal, normalized, context)
54
- : await runSerially(terminal, normalized, context);
52
+ ? await runInParallel(normalized, context)
53
+ : await runSerially(normalized, context);
55
54
  return result;
56
55
  }
57
56
  catch (e) {
@@ -62,8 +61,8 @@ async function default_1(options, context) {
62
61
  }
63
62
  }
64
63
  exports.default = default_1;
65
- async function runInParallel(pseudoTerminal, options, context) {
66
- const procs = options.commands.map((c) => createProcess(pseudoTerminal, c, options.readyWhen, options.color, calculateCwd(options.cwd, context), options.env ?? {}, true, options.usePty, options.streamOutput).then((result) => ({
64
+ async function runInParallel(options, context) {
65
+ const procs = options.commands.map((c) => createProcess(null, c, options.readyWhen, options.color, calculateCwd(options.cwd, context), options.env ?? {}, true, options.usePty, options.streamOutput).then((result) => ({
67
66
  result,
68
67
  command: c.command,
69
68
  })));
@@ -135,7 +134,10 @@ function normalizeOptions(options) {
135
134
  });
136
135
  return options;
137
136
  }
138
- async function runSerially(pseudoTerminal, options, context) {
137
+ async function runSerially(options, context) {
138
+ const pseudoTerminal = pseudo_terminal_1.PseudoTerminal.isSupported()
139
+ ? (0, pseudo_terminal_1.getPseudoTerminal)()
140
+ : null;
139
141
  let terminalOutput = '';
140
142
  for (const c of options.commands) {
141
143
  const result = await createProcess(pseudoTerminal, c, undefined, options.color, calculateCwd(options.cwd, context), options.env ?? {}, false, options.usePty, options.streamOutput);
@@ -155,8 +157,8 @@ async function createProcess(pseudoTerminal, commandConfig, readyWhen, color, cw
155
157
  env = processEnv(color, cwd, env);
156
158
  // The rust runCommand is always a tty, so it will not look nice in parallel and if we need prefixes
157
159
  // currently does not work properly in windows
158
- if (process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
159
- process.stdout.isTTY &&
160
+ if (pseudoTerminal &&
161
+ process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
160
162
  !commandConfig.prefix &&
161
163
  !isParallel &&
162
164
  usePty) {
@@ -265,7 +267,11 @@ function processEnv(color, cwd, env) {
265
267
  ...localEnv,
266
268
  ...env,
267
269
  };
268
- res.PATH = localEnv.PATH; // need to override PATH to make sure we are using the local node_modules
270
+ // need to override PATH to make sure we are using the local node_modules
271
+ if (localEnv.PATH)
272
+ res.PATH = localEnv.PATH; // UNIX-like
273
+ if (localEnv.Path)
274
+ res.Path = localEnv.Path; // Windows
269
275
  if (color) {
270
276
  res.FORCE_COLOR = `${color}`;
271
277
  }
@@ -17,7 +17,7 @@ async function default_1(options, context) {
17
17
  .filter((p) => !p.startsWith(path.join(context.root, 'node_modules')))
18
18
  .join(path.delimiter) ?? '';
19
19
  env.PATH = filteredPath;
20
- if (process.stdout.isTTY) {
20
+ if (pseudo_terminal_1.PseudoTerminal.isSupported()) {
21
21
  await ptyProcess(command, cwd, env);
22
22
  }
23
23
  else {
@@ -39,7 +39,7 @@ exports.createNodes = [
39
39
  externalNodes: nodes,
40
40
  };
41
41
  }
42
- const externalNodes = (0, lock_file_1.getLockFileNodes)(packageManager, lockFileContents, lockFileHash);
42
+ const externalNodes = (0, lock_file_1.getLockFileNodes)(packageManager, lockFileContents, lockFileHash, context);
43
43
  parsedLockFile.externalNodes = externalNodes;
44
44
  return {
45
45
  externalNodes,
@@ -6,12 +6,12 @@ import { PackageManager } from '../../../utils/package-manager';
6
6
  import { ProjectGraph, ProjectGraphExternalNode } from '../../../config/project-graph';
7
7
  import { RawProjectGraphDependency } from '../../../project-graph/project-graph-builder';
8
8
  import { PackageJson } from '../../../utils/package-json';
9
- import { CreateDependenciesContext } from '../../../utils/nx-plugin';
9
+ import { CreateDependenciesContext, CreateNodesContext } from '../../../utils/nx-plugin';
10
10
  export declare const LOCKFILES: string[];
11
11
  /**
12
12
  * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
13
13
  */
14
- export declare function getLockFileNodes(packageManager: PackageManager, contents: string, lockFileHash: string): Record<string, ProjectGraphExternalNode>;
14
+ export declare function getLockFileNodes(packageManager: PackageManager, contents: string, lockFileHash: string, context: CreateNodesContext): Record<string, ProjectGraphExternalNode>;
15
15
  /**
16
16
  * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
17
17
  */
@@ -26,10 +26,10 @@ const PNPM_LOCK_PATH = (0, path_1.join)(workspace_root_1.workspaceRoot, PNPM_LOC
26
26
  /**
27
27
  * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
28
28
  */
29
- function getLockFileNodes(packageManager, contents, lockFileHash) {
29
+ function getLockFileNodes(packageManager, contents, lockFileHash, context) {
30
30
  try {
31
31
  if (packageManager === 'yarn') {
32
- const packageJson = (0, fileutils_1.readJsonFile)('package.json');
32
+ const packageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(context.workspaceRoot, 'package.json'));
33
33
  return (0, yarn_parser_1.getYarnLockfileNodes)(contents, lockFileHash, packageJson);
34
34
  }
35
35
  if (packageManager === 'pnpm') {
@@ -1 +1 @@
1
- export declare const typescriptVersion = "~5.3.2";
1
+ export declare const typescriptVersion = "~5.4.2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typescriptVersion = void 0;
4
- exports.typescriptVersion = '~5.3.2';
4
+ exports.typescriptVersion = '~5.4.2';
@@ -8,7 +8,24 @@ export declare function getFileMap(): {
8
8
  allWorkspaceFiles: FileData[];
9
9
  rustReferences: NxWorkspaceFilesExternals | null;
10
10
  };
11
- export declare function buildProjectGraphUsingProjectFileMap(projects: Record<string, ProjectConfiguration>, externalNodes: Record<string, ProjectGraphExternalNode>, fileMap: FileMap, allWorkspaceFiles: FileData[], rustReferences: NxWorkspaceFilesExternals, fileMapCache: FileMapCache | null, shouldWriteCache: boolean): Promise<{
11
+ export declare function buildProjectGraphUsingProjectFileMap(projects: Record<string, ProjectConfiguration>, externalNodes: Record<string, ProjectGraphExternalNode>, fileMap: FileMap, allWorkspaceFiles: FileData[], rustReferences: NxWorkspaceFilesExternals, fileMapCache: FileMapCache | null): Promise<{
12
12
  projectGraph: ProjectGraph;
13
13
  projectFileMapCache: FileMapCache;
14
14
  }>;
15
+ export declare class ProcessDependenciesError extends Error {
16
+ readonly pluginName: string;
17
+ constructor(pluginName: string, { cause }: {
18
+ cause: any;
19
+ });
20
+ }
21
+ export declare class ProcessProjectGraphError extends Error {
22
+ readonly pluginName: string;
23
+ constructor(pluginName: string, { cause }: {
24
+ cause: any;
25
+ });
26
+ }
27
+ export declare class CreateDependenciesError extends Error {
28
+ readonly errors: Array<ProcessDependenciesError | ProcessProjectGraphError>;
29
+ readonly partialProjectGraph: ProjectGraph;
30
+ constructor(errors: Array<ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph);
31
+ }
@@ -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
  }>;