nx 20.0.0-beta.1 → 20.0.0-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/.eslintrc.json +11 -2
  2. package/bin/nx.js +10 -2
  3. package/package.json +14 -13
  4. package/schemas/nx-schema.json +26 -21
  5. package/src/adapter/compat.d.ts +1 -1
  6. package/src/adapter/compat.js +1 -0
  7. package/src/command-line/activate-powerpack/activate-powerpack.js +3 -1
  8. package/src/command-line/add/add.js +4 -2
  9. package/src/command-line/connect/view-logs.js +1 -0
  10. package/src/command-line/exec/exec.js +6 -1
  11. package/src/command-line/format/format.js +3 -1
  12. package/src/command-line/graph/graph.js +10 -9
  13. package/src/command-line/init/implementation/add-nx-to-nest.js +5 -5
  14. package/src/command-line/init/implementation/angular/integrated-workspace.js +4 -1
  15. package/src/command-line/init/implementation/angular/legacy-angular-versions.js +5 -2
  16. package/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +3 -1
  17. package/src/command-line/init/implementation/dot-nx/nxw.js +1 -0
  18. package/src/command-line/init/implementation/react/check-for-uncommitted-changes.js +3 -1
  19. package/src/command-line/init/implementation/react/clean-up-files.js +7 -7
  20. package/src/command-line/init/implementation/react/index.js +36 -17
  21. package/src/command-line/init/implementation/react/rename-js-to-jsx.js +3 -3
  22. package/src/command-line/init/implementation/utils.js +5 -1
  23. package/src/command-line/init/init-v1.js +1 -0
  24. package/src/command-line/init/init-v2.js +1 -0
  25. package/src/command-line/migrate/command-object.js +4 -0
  26. package/src/command-line/migrate/migrate.js +1 -1
  27. package/src/command-line/release/changelog.js +1 -2
  28. package/src/command-line/release/config/version-plans.js +9 -8
  29. package/src/command-line/release/plan.js +6 -5
  30. package/src/command-line/release/release.js +2 -2
  31. package/src/command-line/release/utils/exec-command.js +1 -0
  32. package/src/command-line/release/utils/github.js +1 -0
  33. package/src/command-line/release/utils/launch-editor.js +6 -1
  34. package/src/command-line/release/version.js +6 -3
  35. package/src/command-line/report/report.d.ts +3 -1
  36. package/src/command-line/report/report.js +17 -2
  37. package/src/command-line/reset/reset.js +4 -4
  38. package/src/command-line/run/run.js +1 -0
  39. package/src/command-line/sync/sync.js +5 -4
  40. package/src/command-line/watch/watch.js +1 -0
  41. package/src/config/nx-json.d.ts +4 -0
  42. package/src/core/graph/main.js +1 -1
  43. package/src/core/graph/styles.css +1 -1
  44. package/src/core/graph/styles.js +1 -1
  45. package/src/daemon/cache.d.ts +1 -2
  46. package/src/daemon/cache.js +12 -21
  47. package/src/daemon/client/client.d.ts +4 -1
  48. package/src/daemon/client/client.js +9 -8
  49. package/src/daemon/client/generate-help-output.js +1 -0
  50. package/src/daemon/server/sync-generators.d.ts +4 -1
  51. package/src/daemon/server/sync-generators.js +33 -15
  52. package/src/daemon/tmp-dir.js +6 -7
  53. package/src/executors/run-commands/run-commands.impl.js +1 -0
  54. package/src/executors/run-script/run-script.impl.js +1 -0
  55. package/src/generators/tree.d.ts +1 -1
  56. package/src/generators/tree.js +11 -11
  57. package/src/native/nx.wasm32-wasi.wasm +0 -0
  58. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +1 -1
  59. package/src/plugins/js/index.js +1 -2
  60. package/src/project-graph/file-utils.js +1 -0
  61. package/src/project-graph/nx-deps-cache.js +5 -6
  62. package/src/tasks-runner/cache.d.ts +3 -1
  63. package/src/tasks-runner/cache.js +29 -29
  64. package/src/tasks-runner/default-tasks-runner.js +1 -1
  65. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +5 -0
  66. package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +7 -0
  67. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +3 -0
  68. package/src/tasks-runner/remove-old-cache-records.js +2 -3
  69. package/src/tasks-runner/task-orchestrator.d.ts +3 -1
  70. package/src/tasks-runner/task-orchestrator.js +3 -2
  71. package/src/tasks-runner/tasks-schedule.js +1 -1
  72. package/src/utils/ab-testing.js +4 -1
  73. package/src/utils/child-process.js +5 -3
  74. package/src/utils/command-line-utils.js +7 -1
  75. package/src/utils/default-base.js +5 -2
  76. package/src/utils/fileutils.d.ts +9 -1
  77. package/src/utils/fileutils.js +29 -12
  78. package/src/utils/git-utils.index-filter.js +2 -1
  79. package/src/utils/git-utils.js +4 -0
  80. package/src/utils/git-utils.tree-filter.js +3 -1
  81. package/src/utils/ignore.js +2 -2
  82. package/src/utils/package-manager.js +2 -2
  83. package/src/utils/plugins/core-plugins.js +4 -0
  84. package/src/utils/powerpack.d.ts +1 -1
  85. package/src/utils/powerpack.js +3 -8
  86. package/src/utils/sync-generators.d.ts +13 -3
  87. package/src/utils/sync-generators.js +99 -25
  88. package/src/utils/task-history.d.ts +2 -2
  89. package/src/utils/task-history.js +4 -1
@@ -9,22 +9,17 @@ const workspace_root_1 = require("./workspace-root");
9
9
  async function printPowerpackLicense() {
10
10
  try {
11
11
  const { organizationName, seatCount, workspaceCount } = await getPowerpackLicenseInformation();
12
- logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? '' : 's'} in ${workspaceCount} workspace${workspaceCount > 1 ? '' : 's'}`);
12
+ logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? '' : 's'} in ${workspaceCount === 9999 ? 'an unlimited number of' : workspaceCount} workspace${workspaceCount > 1 ? '' : 's'}`);
13
13
  }
14
14
  catch { }
15
15
  }
16
16
  async function getPowerpackLicenseInformation() {
17
17
  try {
18
- const { getPowerpackLicenseInformation } = (await Promise.resolve().then(() => require(
19
- // @ts-ignore
20
- '@nx/powerpack-license'
21
- // TODO(@FrozenPandaz): Provide the right type here.
22
- )));
23
- // )) as typeof import('@nx/powerpack-license');
18
+ const { getPowerpackLicenseInformation } = (await Promise.resolve().then(() => require('@nx/powerpack-license')));
24
19
  return getPowerpackLicenseInformation(workspace_root_1.workspaceRoot);
25
20
  }
26
21
  catch (e) {
27
- if ('code' in e && e.code === 'ERR_MODULE_NOT_FOUND') {
22
+ if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
28
23
  throw new NxPowerpackNotInstalledError(e);
29
24
  }
30
25
  throw e;
@@ -18,6 +18,8 @@ export type SyncGeneratorRunSuccessResult = {
18
18
  type SerializableSimpleError = {
19
19
  message: string;
20
20
  stack: string | undefined;
21
+ title?: string;
22
+ bodyLines?: string[];
21
23
  };
22
24
  export type SyncGeneratorRunErrorResult = {
23
25
  generatorName: string;
@@ -36,16 +38,24 @@ type FlushSyncGeneratorChangesFailure = {
36
38
  generalFailure?: SerializableSimpleError;
37
39
  };
38
40
  export type FlushSyncGeneratorChangesResult = FlushSyncGeneratorChangesSuccess | FlushSyncGeneratorChangesFailure;
41
+ export declare class SyncError extends Error {
42
+ title: string;
43
+ bodyLines?: string[];
44
+ constructor(title: string, bodyLines?: string[]);
45
+ }
39
46
  export declare function getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorRunResult[]>;
40
47
  export declare function flushSyncGeneratorChanges(results: SyncGeneratorRunResult[]): Promise<FlushSyncGeneratorChangesResult>;
41
- export declare function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Promise<string[]>;
48
+ export declare function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Promise<{
49
+ globalGenerators: string[];
50
+ taskGenerators: string[];
51
+ }>;
42
52
  export declare function runSyncGenerator(tree: Tree, generatorSpecifier: string, projects: Record<string, ProjectConfiguration>): Promise<SyncGeneratorRunResult>;
43
53
  export declare function collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
44
54
  export declare function collectEnabledTaskSyncGeneratorsFromTaskGraph(taskGraph: TaskGraph, projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
45
55
  export declare function collectRegisteredGlobalSyncGenerators(nxJson?: NxJsonConfiguration<string[] | "*">): Set<string>;
46
56
  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[];
57
+ export declare function getFailedSyncGeneratorsFixMessageLines(results: SyncGeneratorRunResult[], verbose: boolean, globalGeneratorSet?: Set<string>): string[];
58
+ export declare function getFlushFailureMessageLines(result: FlushSyncGeneratorChangesFailure, verbose: boolean, globalGeneratorSet?: Set<string>): string[];
49
59
  export declare function processSyncGeneratorResultErrors(results: SyncGeneratorRunResult[]): {
50
60
  failedGeneratorsCount: number;
51
61
  areAllResultsFailures: boolean;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyncError = void 0;
3
4
  exports.getSyncGeneratorChanges = getSyncGeneratorChanges;
4
5
  exports.flushSyncGeneratorChanges = flushSyncGeneratorChanges;
5
6
  exports.collectAllRegisteredSyncGenerators = collectAllRegisteredSyncGenerators;
@@ -22,6 +23,15 @@ const project_graph_1 = require("../project-graph/project-graph");
22
23
  const workspace_context_1 = require("./workspace-context");
23
24
  const workspace_root_1 = require("./workspace-root");
24
25
  const chalk = require("chalk");
26
+ class SyncError extends Error {
27
+ constructor(title, bodyLines) {
28
+ super(title);
29
+ this.title = title;
30
+ this.bodyLines = bodyLines;
31
+ this.name = this.constructor.name;
32
+ }
33
+ }
34
+ exports.SyncError = SyncError;
25
35
  async function getSyncGeneratorChanges(generators) {
26
36
  perf_hooks_1.performance.mark('get-sync-generators-changes:start');
27
37
  let results;
@@ -43,10 +53,12 @@ async function flushSyncGeneratorChanges(results) {
43
53
  }
44
54
  async function collectAllRegisteredSyncGenerators(projectGraph, nxJson) {
45
55
  if (!client_1.daemonClient.enabled()) {
46
- return [
47
- ...collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph, nxJson),
48
- ...collectRegisteredGlobalSyncGenerators(),
49
- ];
56
+ return {
57
+ globalGenerators: [...collectRegisteredGlobalSyncGenerators()],
58
+ taskGenerators: [
59
+ ...collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph, nxJson),
60
+ ],
61
+ };
50
62
  }
51
63
  return await client_1.daemonClient.getRegisteredSyncGenerators();
52
64
  }
@@ -75,7 +87,7 @@ async function runSyncGenerator(tree, generatorSpecifier, projects) {
75
87
  catch (e) {
76
88
  return {
77
89
  generatorName: generatorSpecifier,
78
- error: { message: e.message, stack: e.stack },
90
+ error: toSerializableError(e),
79
91
  };
80
92
  }
81
93
  }
@@ -140,28 +152,48 @@ function getSyncGeneratorSuccessResultsMessageLines(results) {
140
152
  }
141
153
  return messageLines;
142
154
  }
143
- function getFailedSyncGeneratorsFixMessageLines(results, verbose) {
155
+ function getFailedSyncGeneratorsFixMessageLines(results, verbose, globalGeneratorSet = new Set()) {
144
156
  const messageLines = [];
145
- const generators = [];
157
+ const globalGenerators = [];
158
+ const taskGenerators = [];
159
+ let isFirst = true;
146
160
  for (const result of results) {
147
161
  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);
162
+ if (!isFirst) {
163
+ messageLines.push('');
164
+ }
165
+ isFirst = false;
166
+ messageLines.push(`The ${chalk.bold(result.generatorName)} sync generator reported the following error:`, '', errorToString(result.error, verbose));
167
+ if (globalGeneratorSet.has(result.generatorName)) {
168
+ globalGenerators.push(result.generatorName);
169
+ }
170
+ else {
171
+ taskGenerators.push(result.generatorName);
172
+ }
151
173
  }
152
174
  }
153
- messageLines.push(...getFailedSyncGeneratorsMessageLines(generators, verbose));
175
+ messageLines.push(...getFailedSyncGeneratorsMessageLines(taskGenerators, globalGenerators, verbose));
154
176
  return messageLines;
155
177
  }
156
- function getFlushFailureMessageLines(result, verbose) {
178
+ function getFlushFailureMessageLines(result, verbose, globalGeneratorSet = new Set()) {
157
179
  const messageLines = [];
158
- const generators = [];
180
+ const globalGenerators = [];
181
+ const taskGenerators = [];
182
+ let isFirst = true;
159
183
  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);
184
+ if (!isFirst) {
185
+ messageLines.push('');
186
+ }
187
+ isFirst = false;
188
+ messageLines.push(`The ${chalk.bold(failure.generator)} sync generator failed to apply its changes with the following error:`, '', errorToString(failure.error, verbose));
189
+ if (globalGeneratorSet.has(failure.generator)) {
190
+ globalGenerators.push(failure.generator);
191
+ }
192
+ else {
193
+ taskGenerators.push(failure.generator);
194
+ }
163
195
  }
164
- messageLines.push(...getFailedSyncGeneratorsMessageLines(generators, verbose));
196
+ messageLines.push(...getFailedSyncGeneratorsMessageLines(taskGenerators, globalGenerators, verbose));
165
197
  if (result.generalFailure) {
166
198
  if (messageLines.length > 0) {
167
199
  messageLines.push('');
@@ -242,7 +274,7 @@ async function flushSyncGeneratorChangesToDisk(results) {
242
274
  catch (e) {
243
275
  generatorFailures.push({
244
276
  generator: result.generatorName,
245
- error: { message: e.message, stack: e.stack },
277
+ error: toSerializableError(e),
246
278
  });
247
279
  }
248
280
  }
@@ -255,25 +287,67 @@ async function flushSyncGeneratorChangesToDisk(results) {
255
287
  catch (e) {
256
288
  return {
257
289
  generatorFailures,
258
- generalFailure: { message: e.message, stack: e.stack },
290
+ generalFailure: toSerializableError(e),
259
291
  };
260
292
  }
261
293
  return generatorFailures.length > 0
262
294
  ? { generatorFailures }
263
295
  : { success: true };
264
296
  }
265
- function getFailedSyncGeneratorsMessageLines(generators, verbose) {
297
+ function getFailedSyncGeneratorsMessageLines(taskGenerators, globalGenerators, verbose) {
266
298
  const messageLines = [];
267
- if (generators.length === 1) {
299
+ if (taskGenerators.length + globalGenerators.length === 1) {
268
300
  messageLines.push('', verbose
269
301
  ? '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\`.`);
302
+ : 'Please check the error above and address the issue. You can provide the `--verbose` flag to get more details.');
303
+ if (taskGenerators.length === 1) {
304
+ messageLines.push(`If needed, you can disable the failing sync generator by setting \`sync.disabledTaskSyncGenerators: ["${taskGenerators[0]}"]\` in your \`nx.json\`.`);
305
+ }
306
+ else {
307
+ messageLines.push(`If needed, you can remove the failing global sync generator "${globalGenerators[0]}" from the \`sync.globalGenerators\` array in your \`nx.json\`.`);
308
+ }
271
309
  }
272
- else if (generators.length > 1) {
273
- const generatorsString = generators.map((g) => `"${g}"`).join(', ');
310
+ else if (taskGenerators.length + globalGenerators.length > 1) {
274
311
  messageLines.push('', verbose
275
312
  ? '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\`.`);
313
+ : 'Please check the errors above and address the issues. You can provide the `--verbose` flag to get more details.');
314
+ if (taskGenerators.length > 0) {
315
+ const generatorsString = taskGenerators.map((g) => `"${g}"`).join(', ');
316
+ messageLines.push(`If needed, you can disable the failing task sync generators by setting \`sync.disabledTaskSyncGenerators: [${generatorsString}]\` in your \`nx.json\`.`);
317
+ }
318
+ if (globalGenerators.length > 0) {
319
+ const lastGenerator = globalGenerators.pop();
320
+ const generatorsString = globalGenerators.length > 0
321
+ ? `${globalGenerators
322
+ .map((g) => `"${g}"`)
323
+ .join(', ')} and "${lastGenerator}"`
324
+ : `"${lastGenerator}"`;
325
+ messageLines.push(`If needed, you can remove the failing global sync generators ${generatorsString} from the \`sync.globalGenerators\` array in your \`nx.json\`.`);
326
+ }
277
327
  }
278
328
  return messageLines;
279
329
  }
330
+ function errorToString(error, verbose) {
331
+ if (error.title) {
332
+ let message = ` ${chalk.red(error.title)}`;
333
+ if (error.bodyLines?.length) {
334
+ message += `
335
+
336
+ ${error.bodyLines
337
+ .map((bodyLine) => `${bodyLine.split('\n').join('\n ')}`)
338
+ .join('\n ')}`;
339
+ return message;
340
+ }
341
+ }
342
+ return ` ${chalk.red(error.message)}${verbose && error.stack ? '\n ' + error.stack : ''}`;
343
+ }
344
+ function toSerializableError(error) {
345
+ return error instanceof SyncError
346
+ ? {
347
+ title: error.title,
348
+ bodyLines: error.bodyLines,
349
+ message: error.message,
350
+ stack: error.stack,
351
+ }
352
+ : { message: error.message, stack: error.stack };
353
+ }
@@ -12,6 +12,6 @@ export declare class TaskHistory {
12
12
  }
13
13
  /**
14
14
  * This function returns the singleton instance of TaskHistory
15
- * @returns singleton instance of TaskHistory
15
+ * @returns singleton instance of TaskHistory, null if database is disabled or WASM is not enabled
16
16
  */
17
- export declare function getTaskHistory(): TaskHistory;
17
+ export declare function getTaskHistory(): TaskHistory | null;
@@ -38,9 +38,12 @@ exports.TaskHistory = TaskHistory;
38
38
  let taskHistory;
39
39
  /**
40
40
  * This function returns the singleton instance of TaskHistory
41
- * @returns singleton instance of TaskHistory
41
+ * @returns singleton instance of TaskHistory, null if database is disabled or WASM is not enabled
42
42
  */
43
43
  function getTaskHistory() {
44
+ if (process.env.NX_DISABLE_DB === 'true' || !native_1.IS_WASM) {
45
+ return null;
46
+ }
44
47
  if (!taskHistory) {
45
48
  taskHistory = new TaskHistory();
46
49
  }