nx 19.7.2 → 19.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/package.json +12 -12
  2. package/src/command-line/add/add.js +2 -2
  3. package/src/command-line/affected/command-object.js +6 -6
  4. package/src/command-line/deprecated/command-objects.js +3 -3
  5. package/src/command-line/generate/generate.js +2 -1
  6. package/src/command-line/import/command-object.js +8 -6
  7. package/src/command-line/import/import.d.ts +1 -1
  8. package/src/command-line/import/import.js +42 -27
  9. package/src/command-line/login/login.js +2 -2
  10. package/src/command-line/logout/logout.js +2 -2
  11. package/src/command-line/migrate/migrate.js +2 -2
  12. package/src/command-line/new/new.js +2 -1
  13. package/src/command-line/release/changelog.js +2 -2
  14. package/src/command-line/release/plan-check.js +2 -2
  15. package/src/command-line/release/plan.js +2 -2
  16. package/src/command-line/release/publish.js +2 -2
  17. package/src/command-line/release/release.js +2 -2
  18. package/src/command-line/release/version.js +2 -1
  19. package/src/command-line/repair/repair.js +2 -2
  20. package/src/command-line/run/command-object.js +3 -3
  21. package/src/command-line/run/run.js +3 -2
  22. package/src/command-line/run-many/command-object.js +2 -2
  23. package/src/command-line/show/command-object.js +3 -3
  24. package/src/command-line/sync/sync.js +69 -11
  25. package/src/daemon/client/client.d.ts +3 -3
  26. package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.js +2 -2
  27. package/src/daemon/server/handle-get-sync-generator-changes.js +8 -6
  28. package/src/daemon/server/sync-generators.d.ts +4 -4
  29. package/src/daemon/server/sync-generators.js +11 -2
  30. package/src/native/nx.wasm32-wasi.wasm +0 -0
  31. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +0 -1
  32. package/src/nx-cloud/utilities/get-cloud-options.d.ts +1 -0
  33. package/src/nx-cloud/utilities/get-cloud-options.js +4 -0
  34. package/src/nx-cloud/utilities/is-workspace-claimed.d.ts +1 -1
  35. package/src/nx-cloud/utilities/is-workspace-claimed.js +6 -5
  36. package/src/nx-cloud/utilities/onboarding.js +2 -2
  37. package/src/project-graph/error-types.d.ts +1 -1
  38. package/src/project-graph/error-types.js +19 -5
  39. package/src/tasks-runner/run-command.js +139 -29
  40. package/src/utils/handle-errors.d.ts +1 -0
  41. package/src/utils/handle-errors.js +71 -0
  42. package/src/utils/nx-cloud-utils.d.ts +0 -1
  43. package/src/utils/nx-cloud-utils.js +0 -10
  44. package/src/utils/params.d.ts +0 -1
  45. package/src/utils/params.js +0 -50
  46. package/src/utils/plugins/plugin-capabilities.js +4 -1
  47. package/src/utils/sync-generators.d.ts +35 -6
  48. package/src/utils/sync-generators.js +144 -47
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleErrors = handleErrors;
4
+ const client_1 = require("../daemon/client/client");
5
+ const logger_1 = require("./logger");
6
+ const output_1 = require("./output");
7
+ async function handleErrors(isVerbose, fn) {
8
+ try {
9
+ const result = await fn();
10
+ if (typeof result === 'number') {
11
+ return result;
12
+ }
13
+ return 0;
14
+ }
15
+ catch (err) {
16
+ err ||= new Error('Unknown error caught');
17
+ if (err.constructor.name === 'UnsuccessfulWorkflowExecution') {
18
+ logger_1.logger.error('The generator workflow failed. See above.');
19
+ }
20
+ else if (err.name === 'ProjectGraphError') {
21
+ const projectGraphError = err;
22
+ let title = projectGraphError.message;
23
+ if (projectGraphError.cause &&
24
+ typeof projectGraphError.cause === 'object' &&
25
+ 'message' in projectGraphError.cause) {
26
+ title += ' ' + projectGraphError.cause.message + '.';
27
+ }
28
+ if (isVerbose) {
29
+ title += ' See errors below.';
30
+ }
31
+ const bodyLines = isVerbose
32
+ ? formatErrorStackAndCause(projectGraphError)
33
+ : ['Pass --verbose to see the stacktraces.'];
34
+ output_1.output.error({
35
+ title,
36
+ bodyLines: bodyLines,
37
+ });
38
+ }
39
+ else {
40
+ const lines = (err.message ? err.message : err.toString()).split('\n');
41
+ const bodyLines = lines.slice(1);
42
+ if (isVerbose) {
43
+ bodyLines.push(...formatErrorStackAndCause(err));
44
+ }
45
+ else if (err.stack) {
46
+ bodyLines.push('Pass --verbose to see the stacktrace.');
47
+ }
48
+ output_1.output.error({
49
+ title: lines[0],
50
+ bodyLines,
51
+ });
52
+ }
53
+ if (client_1.daemonClient.enabled()) {
54
+ client_1.daemonClient.reset();
55
+ }
56
+ return 1;
57
+ }
58
+ }
59
+ function formatErrorStackAndCause(error) {
60
+ return [
61
+ error.stack || error.message,
62
+ ...(error.cause && typeof error.cause === 'object'
63
+ ? [
64
+ 'Caused by:',
65
+ 'stack' in error.cause
66
+ ? error.cause.stack.toString()
67
+ : error.cause.toString(),
68
+ ]
69
+ : []),
70
+ ];
71
+ }
@@ -1,4 +1,3 @@
1
1
  import { NxJsonConfiguration } from '../config/nx-json';
2
2
  export declare function isNxCloudUsed(nxJson: NxJsonConfiguration): boolean;
3
3
  export declare function getNxCloudUrl(nxJson: NxJsonConfiguration): string;
4
- export declare function getNxCloudToken(nxJson: NxJsonConfiguration): string;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNxCloudUsed = isNxCloudUsed;
4
4
  exports.getNxCloudUrl = getNxCloudUrl;
5
- exports.getNxCloudToken = getNxCloudToken;
6
5
  function isNxCloudUsed(nxJson) {
7
6
  return (!!process.env.NX_CLOUD_ACCESS_TOKEN ||
8
7
  !!nxJson.nxCloudAccessToken ||
@@ -17,12 +16,3 @@ function getNxCloudUrl(nxJson) {
17
16
  throw new Error('nx-cloud runner not found in nx.json');
18
17
  return cloudRunner?.options?.url ?? nxJson.nxCloudUrl ?? 'https://nx.app';
19
18
  }
20
- function getNxCloudToken(nxJson) {
21
- const cloudRunner = Object.values(nxJson.tasksRunnerOptions ?? {}).find((r) => r.runner == '@nrwl/nx-cloud' || r.runner == 'nx-cloud');
22
- if (!cloudRunner &&
23
- !(nxJson.nxCloudAccessToken || process.env.NX_CLOUD_ACCESS_TOKEN))
24
- throw new Error('nx-cloud runner not found in nx.json');
25
- return (process.env.NX_CLOUD_ACCESS_TOKEN ??
26
- cloudRunner?.options.accessToken ??
27
- nxJson.nxCloudAccessToken);
28
- }
@@ -79,7 +79,6 @@ export type Options = {
79
79
  '--'?: Unmatched[];
80
80
  [k: string]: string | number | boolean | string[] | Unmatched[] | undefined;
81
81
  };
82
- export declare function handleErrors(isVerbose: boolean, fn: Function): Promise<number>;
83
82
  export declare function convertToCamelCase(parsed: {
84
83
  [k: string]: any;
85
84
  }, schema: Schema): Options;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaError = void 0;
4
- exports.handleErrors = handleErrors;
5
4
  exports.convertToCamelCase = convertToCamelCase;
6
5
  exports.coerceTypesInOptions = coerceTypesInOptions;
7
6
  exports.convertAliases = convertAliases;
@@ -15,55 +14,6 @@ exports.warnDeprecations = warnDeprecations;
15
14
  exports.convertSmartDefaultsIntoNamedParams = convertSmartDefaultsIntoNamedParams;
16
15
  exports.getPromptsForSchema = getPromptsForSchema;
17
16
  const logger_1 = require("./logger");
18
- const output_1 = require("./output");
19
- const client_1 = require("../daemon/client/client");
20
- async function handleErrors(isVerbose, fn) {
21
- try {
22
- const result = await fn();
23
- if (typeof result === 'number') {
24
- return result;
25
- }
26
- return 0;
27
- }
28
- catch (err) {
29
- err ||= new Error('Unknown error caught');
30
- if (err.constructor.name === 'UnsuccessfulWorkflowExecution') {
31
- logger_1.logger.error('The generator workflow failed. See above.');
32
- }
33
- else if (err.name === 'ProjectGraphError') {
34
- const projectGraphError = err;
35
- let title = projectGraphError.message;
36
- if (isVerbose) {
37
- title += ' See errors below.';
38
- }
39
- const bodyLines = isVerbose
40
- ? [projectGraphError.stack]
41
- : ['Pass --verbose to see the stacktraces.'];
42
- output_1.output.error({
43
- title,
44
- bodyLines: bodyLines,
45
- });
46
- }
47
- else {
48
- const lines = (err.message ? err.message : err.toString()).split('\n');
49
- const bodyLines = lines.slice(1);
50
- if (err.stack && !isVerbose) {
51
- bodyLines.push('Pass --verbose to see the stacktrace.');
52
- }
53
- output_1.output.error({
54
- title: lines[0],
55
- bodyLines,
56
- });
57
- if (err.stack && isVerbose) {
58
- logger_1.logger.info(err.stack);
59
- }
60
- }
61
- if (client_1.daemonClient.enabled()) {
62
- client_1.daemonClient.reset();
63
- }
64
- return 1;
65
- }
66
- }
67
17
  function camelCase(input) {
68
18
  if (input.indexOf('-') > 1) {
69
19
  return input
@@ -41,10 +41,13 @@ async function getPluginCapabilities(workspaceRoot, pluginName, projects, includ
41
41
  projectGraphExtension: pluginModule &&
42
42
  ('processProjectGraph' in pluginModule ||
43
43
  'createNodes' in pluginModule ||
44
+ 'createNodesV2' in pluginModule ||
45
+ 'createMetadata' in pluginModule ||
44
46
  'createDependencies' in pluginModule),
45
47
  projectInference: pluginModule &&
46
48
  ('projectFilePatterns' in pluginModule ||
47
- 'createNodes' in pluginModule),
49
+ 'createNodes' in pluginModule ||
50
+ 'createNodesV2' in pluginModule),
48
51
  };
49
52
  }
50
53
  catch {
@@ -9,17 +9,46 @@ export type SyncGeneratorResult = void | {
9
9
  outOfSyncMessage?: string;
10
10
  };
11
11
  export type SyncGenerator = (tree: Tree) => SyncGeneratorResult | Promise<SyncGeneratorResult>;
12
- export type SyncGeneratorChangesResult = {
13
- changes: FileChange[];
12
+ export type SyncGeneratorRunSuccessResult = {
14
13
  generatorName: string;
14
+ changes: FileChange[];
15
15
  callback?: GeneratorCallback;
16
16
  outOfSyncMessage?: string;
17
17
  };
18
- export declare function getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorChangesResult[]>;
19
- export declare function flushSyncGeneratorChanges(results: SyncGeneratorChangesResult[]): Promise<void>;
18
+ type SerializableSimpleError = {
19
+ message: string;
20
+ stack: string | undefined;
21
+ };
22
+ export type SyncGeneratorRunErrorResult = {
23
+ generatorName: string;
24
+ error: SerializableSimpleError;
25
+ };
26
+ export type SyncGeneratorRunResult = SyncGeneratorRunSuccessResult | SyncGeneratorRunErrorResult;
27
+ type FlushSyncGeneratorChangesSuccess = {
28
+ success: true;
29
+ };
30
+ type FlushSyncGeneratorFailure = {
31
+ generator: string;
32
+ error: SerializableSimpleError;
33
+ };
34
+ type FlushSyncGeneratorChangesFailure = {
35
+ generatorFailures: FlushSyncGeneratorFailure[];
36
+ generalFailure?: SerializableSimpleError;
37
+ };
38
+ export type FlushSyncGeneratorChangesResult = FlushSyncGeneratorChangesSuccess | FlushSyncGeneratorChangesFailure;
39
+ export declare function getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorRunResult[]>;
40
+ export declare function flushSyncGeneratorChanges(results: SyncGeneratorRunResult[]): Promise<FlushSyncGeneratorChangesResult>;
20
41
  export declare function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Promise<string[]>;
21
- export declare function runSyncGenerator(tree: Tree, generatorSpecifier: string, projects: Record<string, ProjectConfiguration>): Promise<SyncGeneratorChangesResult>;
42
+ export declare function runSyncGenerator(tree: Tree, generatorSpecifier: string, projects: Record<string, ProjectConfiguration>): Promise<SyncGeneratorRunResult>;
22
43
  export declare function collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
23
44
  export declare function collectEnabledTaskSyncGeneratorsFromTaskGraph(taskGraph: TaskGraph, projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
24
45
  export declare function collectRegisteredGlobalSyncGenerators(nxJson?: NxJsonConfiguration<string[] | "*">): Set<string>;
25
- export declare function syncGeneratorResultsToMessageLines(results: SyncGeneratorChangesResult[]): string[];
46
+ export declare function getSyncGeneratorSuccessResultsMessageLines(results: SyncGeneratorRunResult[]): string[];
47
+ export declare function getFailedSyncGeneratorsFixMessageLines(results: SyncGeneratorRunResult[], verbose: boolean): string[];
48
+ export declare function getFlushFailureMessageLines(result: FlushSyncGeneratorChangesFailure, verbose: boolean): string[];
49
+ export declare function processSyncGeneratorResultErrors(results: SyncGeneratorRunResult[]): {
50
+ failedGeneratorsCount: number;
51
+ areAllResultsFailures: boolean;
52
+ anySyncGeneratorsFailed: boolean;
53
+ };
54
+ export {};
@@ -7,7 +7,10 @@ exports.runSyncGenerator = runSyncGenerator;
7
7
  exports.collectEnabledTaskSyncGeneratorsFromProjectGraph = collectEnabledTaskSyncGeneratorsFromProjectGraph;
8
8
  exports.collectEnabledTaskSyncGeneratorsFromTaskGraph = collectEnabledTaskSyncGeneratorsFromTaskGraph;
9
9
  exports.collectRegisteredGlobalSyncGenerators = collectRegisteredGlobalSyncGenerators;
10
- exports.syncGeneratorResultsToMessageLines = syncGeneratorResultsToMessageLines;
10
+ exports.getSyncGeneratorSuccessResultsMessageLines = getSyncGeneratorSuccessResultsMessageLines;
11
+ exports.getFailedSyncGeneratorsFixMessageLines = getFailedSyncGeneratorsFixMessageLines;
12
+ exports.getFlushFailureMessageLines = getFlushFailureMessageLines;
13
+ exports.processSyncGeneratorResultErrors = processSyncGeneratorResultErrors;
11
14
  const perf_hooks_1 = require("perf_hooks");
12
15
  const generate_1 = require("../command-line/generate/generate");
13
16
  const generator_utils_1 = require("../command-line/generate/generator-utils");
@@ -30,15 +33,13 @@ async function getSyncGeneratorChanges(generators) {
30
33
  }
31
34
  perf_hooks_1.performance.mark('get-sync-generators-changes:end');
32
35
  perf_hooks_1.performance.measure('get-sync-generators-changes', 'get-sync-generators-changes:start', 'get-sync-generators-changes:end');
33
- return results.filter((r) => r.changes.length > 0);
36
+ return results.filter((r) => ('error' in r ? true : r.changes.length > 0));
34
37
  }
35
38
  async function flushSyncGeneratorChanges(results) {
36
39
  if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
37
- await flushSyncGeneratorChangesToDisk(results);
38
- }
39
- else {
40
- await client_1.daemonClient.flushSyncGeneratorChangesToDisk(results.map((r) => r.generatorName));
40
+ return await flushSyncGeneratorChangesToDisk(results);
41
41
  }
42
+ return await client_1.daemonClient.flushSyncGeneratorChangesToDisk(results.map((r) => r.generatorName));
42
43
  }
43
44
  async function collectAllRegisteredSyncGenerators(projectGraph, nxJson) {
44
45
  if (!client_1.daemonClient.enabled()) {
@@ -50,25 +51,33 @@ async function collectAllRegisteredSyncGenerators(projectGraph, nxJson) {
50
51
  return await client_1.daemonClient.getRegisteredSyncGenerators();
51
52
  }
52
53
  async function runSyncGenerator(tree, generatorSpecifier, projects) {
53
- perf_hooks_1.performance.mark(`run-sync-generator:${generatorSpecifier}:start`);
54
- const { collection, generator } = (0, generate_1.parseGeneratorString)(generatorSpecifier);
55
- const { implementationFactory } = (0, generator_utils_1.getGeneratorInformation)(collection, generator, workspace_root_1.workspaceRoot, projects);
56
- const implementation = implementationFactory();
57
- const result = await implementation(tree);
58
- let callback;
59
- let outOfSyncMessage;
60
- if (result && typeof result === 'object') {
61
- callback = result.callback;
62
- outOfSyncMessage = result.outOfSyncMessage;
63
- }
64
- perf_hooks_1.performance.mark(`run-sync-generator:${generatorSpecifier}:end`);
65
- perf_hooks_1.performance.measure(`run-sync-generator:${generatorSpecifier}`, `run-sync-generator:${generatorSpecifier}:start`, `run-sync-generator:${generatorSpecifier}:end`);
66
- return {
67
- changes: tree.listChanges(),
68
- generatorName: generatorSpecifier,
69
- callback,
70
- outOfSyncMessage,
71
- };
54
+ try {
55
+ perf_hooks_1.performance.mark(`run-sync-generator:${generatorSpecifier}:start`);
56
+ const { collection, generator } = (0, generate_1.parseGeneratorString)(generatorSpecifier);
57
+ const { implementationFactory } = (0, generator_utils_1.getGeneratorInformation)(collection, generator, workspace_root_1.workspaceRoot, projects);
58
+ const implementation = implementationFactory();
59
+ const result = await implementation(tree);
60
+ let callback;
61
+ let outOfSyncMessage;
62
+ if (result && typeof result === 'object') {
63
+ callback = result.callback;
64
+ outOfSyncMessage = result.outOfSyncMessage;
65
+ }
66
+ perf_hooks_1.performance.mark(`run-sync-generator:${generatorSpecifier}:end`);
67
+ perf_hooks_1.performance.measure(`run-sync-generator:${generatorSpecifier}`, `run-sync-generator:${generatorSpecifier}:start`, `run-sync-generator:${generatorSpecifier}:end`);
68
+ return {
69
+ changes: tree.listChanges(),
70
+ generatorName: generatorSpecifier,
71
+ callback,
72
+ outOfSyncMessage,
73
+ };
74
+ }
75
+ catch (e) {
76
+ return {
77
+ generatorName: generatorSpecifier,
78
+ error: { message: e.message, stack: e.stack },
79
+ };
80
+ }
72
81
  }
73
82
  function collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph, nxJson) {
74
83
  const taskSyncGenerators = new Set();
@@ -118,9 +127,12 @@ function collectRegisteredGlobalSyncGenerators(nxJson = (0, nx_json_1.readNxJson
118
127
  }
119
128
  return globalSyncGenerators;
120
129
  }
121
- function syncGeneratorResultsToMessageLines(results) {
130
+ function getSyncGeneratorSuccessResultsMessageLines(results) {
122
131
  const messageLines = [];
123
132
  for (const result of results) {
133
+ if ('error' in result) {
134
+ continue;
135
+ }
124
136
  messageLines.push(`The ${chalk.bold(result.generatorName)} sync generator identified ${chalk.bold(result.changes.length)} file${result.changes.length === 1 ? '' : 's'} in the workspace that ${result.changes.length === 1 ? 'is' : 'are'} out of sync${result.outOfSyncMessage ? ':' : '.'}`);
125
137
  if (result.outOfSyncMessage) {
126
138
  messageLines.push(result.outOfSyncMessage);
@@ -128,6 +140,65 @@ function syncGeneratorResultsToMessageLines(results) {
128
140
  }
129
141
  return messageLines;
130
142
  }
143
+ function getFailedSyncGeneratorsFixMessageLines(results, verbose) {
144
+ const messageLines = [];
145
+ const generators = [];
146
+ for (const result of results) {
147
+ if ('error' in result) {
148
+ messageLines.push(`The ${chalk.bold(result.generatorName)} sync generator reported the following error:
149
+ ${chalk.bold(result.error.message)}${verbose && result.error.stack ? '\n' + result.error.stack : ''}`);
150
+ generators.push(result.generatorName);
151
+ }
152
+ }
153
+ messageLines.push(...getFailedSyncGeneratorsMessageLines(generators, verbose));
154
+ return messageLines;
155
+ }
156
+ function getFlushFailureMessageLines(result, verbose) {
157
+ const messageLines = [];
158
+ const generators = [];
159
+ for (const failure of result.generatorFailures) {
160
+ messageLines.push(`The ${chalk.bold(failure.generator)} sync generator failed to apply its changes with the following error:
161
+ ${chalk.bold(failure.error.message)}${verbose && failure.error.stack ? '\n' + failure.error.stack : ''}`);
162
+ generators.push(failure.generator);
163
+ }
164
+ messageLines.push(...getFailedSyncGeneratorsMessageLines(generators, verbose));
165
+ if (result.generalFailure) {
166
+ if (messageLines.length > 0) {
167
+ messageLines.push('');
168
+ messageLines.push('Additionally, an unexpected error occurred:');
169
+ }
170
+ else {
171
+ messageLines.push('An unexpected error occurred:');
172
+ }
173
+ messageLines.push(...[
174
+ '',
175
+ result.generalFailure.message,
176
+ ...(verbose && !!result.generalFailure.stack
177
+ ? [`\n${result.generalFailure.stack}`]
178
+ : []),
179
+ '',
180
+ verbose
181
+ ? 'Please report the error at: https://github.com/nrwl/nx/issues/new/choose'
182
+ : 'Please run with `--verbose` and report the error at: https://github.com/nrwl/nx/issues/new/choose',
183
+ ]);
184
+ }
185
+ return messageLines;
186
+ }
187
+ function processSyncGeneratorResultErrors(results) {
188
+ let failedGeneratorsCount = 0;
189
+ for (const result of results) {
190
+ if ('error' in result) {
191
+ failedGeneratorsCount++;
192
+ }
193
+ }
194
+ const areAllResultsFailures = failedGeneratorsCount === results.length;
195
+ const anySyncGeneratorsFailed = failedGeneratorsCount > 0;
196
+ return {
197
+ failedGeneratorsCount,
198
+ areAllResultsFailures,
199
+ anySyncGeneratorsFailed,
200
+ };
201
+ }
131
202
  async function runSyncGenerators(generators) {
132
203
  const tree = new tree_1.FsTree(workspace_root_1.workspaceRoot, false, 'running sync generators');
133
204
  const projectGraph = await (0, project_graph_1.createProjectGraphAsync)();
@@ -141,32 +212,15 @@ async function runSyncGenerators(generators) {
141
212
  }
142
213
  async function flushSyncGeneratorChangesToDisk(results) {
143
214
  perf_hooks_1.performance.mark('flush-sync-generator-changes-to-disk:start');
144
- const { changes, createdFiles, updatedFiles, deletedFiles, callbacks } = processSyncGeneratorResults(results);
145
- // Write changes to disk
146
- (0, tree_1.flushChanges)(workspace_root_1.workspaceRoot, changes);
147
- // Run the callbacks
148
- if (callbacks.length) {
149
- for (const callback of callbacks) {
150
- await callback();
151
- }
152
- }
153
- // Update the context files
154
- await (0, workspace_context_1.updateContextWithChangedFiles)(workspace_root_1.workspaceRoot, createdFiles, updatedFiles, deletedFiles);
155
- perf_hooks_1.performance.mark('flush-sync-generator-changes-to-disk:end');
156
- perf_hooks_1.performance.measure('flush sync generator changes to disk', 'flush-sync-generator-changes-to-disk:start', 'flush-sync-generator-changes-to-disk:end');
157
- }
158
- function processSyncGeneratorResults(results) {
159
- const changes = [];
160
215
  const createdFiles = [];
161
216
  const updatedFiles = [];
162
217
  const deletedFiles = [];
163
- const callbacks = [];
218
+ const generatorFailures = [];
164
219
  for (const result of results) {
165
- if (result.callback) {
166
- callbacks.push(result.callback);
220
+ if ('error' in result) {
221
+ continue;
167
222
  }
168
223
  for (const change of result.changes) {
169
- changes.push(change);
170
224
  if (change.type === 'CREATE') {
171
225
  createdFiles.push(change.path);
172
226
  }
@@ -177,6 +231,49 @@ function processSyncGeneratorResults(results) {
177
231
  deletedFiles.push(change.path);
178
232
  }
179
233
  }
234
+ try {
235
+ // Write changes to disk
236
+ (0, tree_1.flushChanges)(workspace_root_1.workspaceRoot, result.changes);
237
+ // Run the callback
238
+ if (result.callback) {
239
+ await result.callback();
240
+ }
241
+ }
242
+ catch (e) {
243
+ generatorFailures.push({
244
+ generator: result.generatorName,
245
+ error: { message: e.message, stack: e.stack },
246
+ });
247
+ }
248
+ }
249
+ try {
250
+ // Update the context files
251
+ await (0, workspace_context_1.updateContextWithChangedFiles)(workspace_root_1.workspaceRoot, createdFiles, updatedFiles, deletedFiles);
252
+ perf_hooks_1.performance.mark('flush-sync-generator-changes-to-disk:end');
253
+ perf_hooks_1.performance.measure('flush sync generator changes to disk', 'flush-sync-generator-changes-to-disk:start', 'flush-sync-generator-changes-to-disk:end');
254
+ }
255
+ catch (e) {
256
+ return {
257
+ generatorFailures,
258
+ generalFailure: { message: e.message, stack: e.stack },
259
+ };
180
260
  }
181
- return { changes, createdFiles, updatedFiles, deletedFiles, callbacks };
261
+ return generatorFailures.length > 0
262
+ ? { generatorFailures }
263
+ : { success: true };
264
+ }
265
+ function getFailedSyncGeneratorsMessageLines(generators, verbose) {
266
+ const messageLines = [];
267
+ if (generators.length === 1) {
268
+ messageLines.push('', verbose
269
+ ? 'Please check the error above and address the issue.'
270
+ : 'Please check the error above and address the issue. You can provide the `--verbose` flag to get more details.', `If needed, you can disable the failing sync generator by setting \`sync.disabledTaskSyncGenerators: ["${generators[0]}"]\` in your \`nx.json\`.`);
271
+ }
272
+ else if (generators.length > 1) {
273
+ const generatorsString = generators.map((g) => `"${g}"`).join(', ');
274
+ messageLines.push('', verbose
275
+ ? 'Please check the errors above and address the issues.'
276
+ : 'Please check the errors above and address the issues. You can provide the `--verbose` flag to get more details.', `If needed, you can disable the failing sync generators by setting \`sync.disabledTaskSyncGenerators: [${generatorsString}]\` in your \`nx.json\`.`);
277
+ }
278
+ return messageLines;
182
279
  }