nx 19.7.1 → 19.7.3
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +12 -12
- package/src/command-line/add/add.js +2 -2
- package/src/command-line/affected/command-object.js +6 -6
- package/src/command-line/deprecated/command-objects.js +3 -3
- package/src/command-line/generate/generate.js +2 -1
- package/src/command-line/import/command-object.js +8 -6
- package/src/command-line/import/import.d.ts +1 -1
- package/src/command-line/import/import.js +42 -27
- package/src/command-line/login/login.js +2 -2
- package/src/command-line/logout/logout.js +2 -2
- package/src/command-line/migrate/migrate.js +2 -2
- package/src/command-line/new/new.js +2 -1
- package/src/command-line/release/changelog.js +2 -2
- package/src/command-line/release/plan-check.js +2 -2
- package/src/command-line/release/plan.js +2 -2
- package/src/command-line/release/publish.js +2 -2
- package/src/command-line/release/release.js +2 -2
- package/src/command-line/release/utils/git.js +4 -2
- package/src/command-line/release/version.js +2 -1
- package/src/command-line/repair/repair.js +2 -2
- package/src/command-line/run/command-object.js +3 -3
- package/src/command-line/run/run.js +3 -2
- package/src/command-line/run-many/command-object.js +2 -2
- package/src/command-line/show/command-object.js +3 -3
- package/src/command-line/sync/sync.js +69 -11
- package/src/daemon/client/client.d.ts +3 -3
- package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.js +2 -2
- package/src/daemon/server/handle-get-sync-generator-changes.js +8 -6
- package/src/daemon/server/sync-generators.d.ts +4 -4
- package/src/daemon/server/sync-generators.js +11 -2
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +0 -1
- package/src/nx-cloud/utilities/get-cloud-options.d.ts +1 -0
- package/src/nx-cloud/utilities/get-cloud-options.js +4 -0
- package/src/nx-cloud/utilities/is-workspace-claimed.d.ts +1 -1
- package/src/nx-cloud/utilities/is-workspace-claimed.js +6 -5
- package/src/nx-cloud/utilities/onboarding.js +2 -2
- package/src/plugins/package-json/create-nodes.js +1 -1
- package/src/project-graph/error-types.d.ts +1 -1
- package/src/project-graph/error-types.js +19 -5
- package/src/tasks-runner/run-command.js +139 -29
- package/src/utils/handle-errors.d.ts +1 -0
- package/src/utils/handle-errors.js +71 -0
- package/src/utils/nx-cloud-utils.d.ts +0 -1
- package/src/utils/nx-cloud-utils.js +0 -10
- package/src/utils/package-json.d.ts +2 -1
- package/src/utils/package-json.js +14 -3
- package/src/utils/params.d.ts +0 -1
- package/src/utils/params.js +0 -50
- package/src/utils/plugins/plugin-capabilities.js +4 -1
- package/src/utils/sync-generators.d.ts +35 -6
- package/src/utils/sync-generators.js +144 -47
@@ -7,7 +7,10 @@ exports.runSyncGenerator = runSyncGenerator;
|
|
7
7
|
exports.collectEnabledTaskSyncGeneratorsFromProjectGraph = collectEnabledTaskSyncGeneratorsFromProjectGraph;
|
8
8
|
exports.collectEnabledTaskSyncGeneratorsFromTaskGraph = collectEnabledTaskSyncGeneratorsFromTaskGraph;
|
9
9
|
exports.collectRegisteredGlobalSyncGenerators = collectRegisteredGlobalSyncGenerators;
|
10
|
-
exports.
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
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
|
218
|
+
const generatorFailures = [];
|
164
219
|
for (const result of results) {
|
165
|
-
if (result
|
166
|
-
|
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
|
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
|
}
|