nx 19.8.0 → 19.8.2

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 (86) hide show
  1. package/.eslintrc.json +11 -2
  2. package/bin/nx.js +10 -2
  3. package/package.json +12 -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 +2 -1
  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/daemon/cache.d.ts +1 -2
  43. package/src/daemon/cache.js +12 -21
  44. package/src/daemon/client/client.d.ts +4 -1
  45. package/src/daemon/client/client.js +9 -8
  46. package/src/daemon/client/generate-help-output.js +1 -0
  47. package/src/daemon/server/sync-generators.d.ts +4 -1
  48. package/src/daemon/server/sync-generators.js +33 -15
  49. package/src/daemon/tmp-dir.js +6 -7
  50. package/src/executors/run-commands/run-commands.impl.js +1 -0
  51. package/src/executors/run-script/run-script.impl.js +1 -0
  52. package/src/generators/tree.d.ts +1 -1
  53. package/src/generators/tree.js +11 -11
  54. package/src/native/index.d.ts +1 -1
  55. package/src/native/nx.wasm32-wasi.wasm +0 -0
  56. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +1 -1
  57. package/src/plugins/js/index.js +1 -2
  58. package/src/project-graph/file-utils.js +1 -0
  59. package/src/project-graph/nx-deps-cache.js +5 -6
  60. package/src/tasks-runner/cache.d.ts +3 -1
  61. package/src/tasks-runner/cache.js +29 -29
  62. package/src/tasks-runner/default-tasks-runner.js +1 -1
  63. package/src/tasks-runner/life-cycles/formatting-utils.d.ts +1 -1
  64. package/src/tasks-runner/life-cycles/formatting-utils.js +27 -15
  65. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +3 -0
  66. package/src/tasks-runner/remove-old-cache-records.js +2 -3
  67. package/src/tasks-runner/task-orchestrator.d.ts +3 -1
  68. package/src/tasks-runner/task-orchestrator.js +3 -2
  69. package/src/tasks-runner/tasks-schedule.js +1 -1
  70. package/src/utils/ab-testing.js +4 -1
  71. package/src/utils/child-process.js +5 -3
  72. package/src/utils/command-line-utils.js +7 -1
  73. package/src/utils/default-base.js +5 -2
  74. package/src/utils/fileutils.d.ts +9 -1
  75. package/src/utils/fileutils.js +29 -12
  76. package/src/utils/git-utils.index-filter.js +2 -1
  77. package/src/utils/git-utils.js +4 -0
  78. package/src/utils/git-utils.tree-filter.js +3 -1
  79. package/src/utils/ignore.js +2 -2
  80. package/src/utils/package-manager.js +2 -2
  81. package/src/utils/powerpack.d.ts +1 -1
  82. package/src/utils/powerpack.js +3 -8
  83. package/src/utils/sync-generators.d.ts +13 -3
  84. package/src/utils/sync-generators.js +99 -25
  85. package/src/utils/task-history.d.ts +2 -2
  86. package/src/utils/task-history.js +4 -1
@@ -16,6 +16,7 @@ function runNxSync(cmd, options) {
16
16
  else {
17
17
  options ??= {};
18
18
  options.cwd ??= process.cwd();
19
+ options.windowsHide ??= true;
19
20
  const offsetFromRoot = (0, path_1.relative)(options.cwd, (0, workspace_root_1.workspaceRootInner)(options.cwd, null));
20
21
  if (process.platform === 'win32') {
21
22
  baseCmd = '.\\' + (0, path_1.join)(`${offsetFromRoot}`, 'nx.bat');
@@ -34,6 +35,7 @@ async function runNxAsync(cmd, options) {
34
35
  else {
35
36
  options ??= {};
36
37
  options.cwd ??= process.cwd();
38
+ options.windowsHide ??= true;
37
39
  const offsetFromRoot = (0, path_1.relative)(options.cwd, (0, workspace_root_1.workspaceRootInner)(options.cwd, null));
38
40
  if (process.platform === 'win32') {
39
41
  baseCmd = '.\\' + (0, path_1.join)(`${offsetFromRoot}`, 'nx.bat');
@@ -46,13 +48,13 @@ async function runNxAsync(cmd, options) {
46
48
  if (options?.silent) {
47
49
  delete options.silent;
48
50
  }
49
- await new Promise((resolve, reject) => {
51
+ return new Promise((resolve, reject) => {
50
52
  const child = (0, child_process_1.exec)(`${baseCmd} ${cmd}`, options, (error, stdout, stderr) => {
51
53
  if (error) {
52
- reject(error);
54
+ reject(stderr || stdout || error.message);
53
55
  }
54
56
  else {
55
- resolve(stdout);
57
+ resolve();
56
58
  }
57
59
  });
58
60
  if (!silent) {
@@ -222,6 +222,7 @@ function getMergeBase(base, head = 'HEAD') {
222
222
  maxBuffer: file_utils_1.TEN_MEGABYTES,
223
223
  cwd: workspace_root_1.workspaceRoot,
224
224
  stdio: 'pipe',
225
+ windowsHide: true,
225
226
  })
226
227
  .toString()
227
228
  .trim();
@@ -232,6 +233,7 @@ function getMergeBase(base, head = 'HEAD') {
232
233
  maxBuffer: file_utils_1.TEN_MEGABYTES,
233
234
  cwd: workspace_root_1.workspaceRoot,
234
235
  stdio: 'pipe',
236
+ windowsHide: true,
235
237
  })
236
238
  .toString()
237
239
  .trim();
@@ -245,7 +247,11 @@ function getFilesUsingBaseAndHead(base, head) {
245
247
  return parseGitOutput(`git diff --name-only --no-renames --relative "${base}" "${head}"`);
246
248
  }
247
249
  function parseGitOutput(command) {
248
- return (0, child_process_1.execSync)(command, { maxBuffer: file_utils_1.TEN_MEGABYTES, cwd: workspace_root_1.workspaceRoot })
250
+ return (0, child_process_1.execSync)(command, {
251
+ maxBuffer: file_utils_1.TEN_MEGABYTES,
252
+ cwd: workspace_root_1.workspaceRoot,
253
+ windowsHide: true,
254
+ })
249
255
  .toString('utf-8')
250
256
  .split('\n')
251
257
  .map((a) => a.trim())
@@ -5,8 +5,11 @@ const child_process_1 = require("child_process");
5
5
  function deduceDefaultBase() {
6
6
  const nxDefaultBase = 'main';
7
7
  try {
8
- return ((0, child_process_1.execSync)('git config --get init.defaultBranch').toString().trim() ||
9
- nxDefaultBase);
8
+ return ((0, child_process_1.execSync)('git config --get init.defaultBranch', {
9
+ windowsHide: true,
10
+ })
11
+ .toString()
12
+ .trim() || nxDefaultBase);
10
13
  }
11
14
  catch {
12
15
  return nxDefaultBase;
@@ -1,5 +1,5 @@
1
1
  import type { JsonParseOptions, JsonSerializeOptions } from './json';
2
- import { PathLike } from 'fs';
2
+ import { PathLike } from 'node:fs';
3
3
  export interface JsonReadOptions extends JsonParseOptions {
4
4
  /**
5
5
  * mutable field recording whether JSON ends with new line
@@ -43,6 +43,14 @@ export declare function readYamlFile<T extends object = any>(path: string, optio
43
43
  * @param options JSON serialize options
44
44
  */
45
45
  export declare function writeJsonFile<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): void;
46
+ /**
47
+ * Serializes the given data to JSON and writes it to a file asynchronously.
48
+ *
49
+ * @param path A path to a file.
50
+ * @param data data which should be serialized to JSON and written to the file
51
+ * @param options JSON serialize options
52
+ */
53
+ export declare function writeJsonFileAsync<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): Promise<void>;
46
54
  /**
47
55
  * Check if a directory exists
48
56
  * @param path Path to directory
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readJsonFile = readJsonFile;
4
4
  exports.readYamlFile = readYamlFile;
5
5
  exports.writeJsonFile = writeJsonFile;
6
+ exports.writeJsonFileAsync = writeJsonFileAsync;
6
7
  exports.directoryExists = directoryExists;
7
8
  exports.fileExists = fileExists;
8
9
  exports.createDirectory = createDirectory;
@@ -10,7 +11,8 @@ exports.isRelativePath = isRelativePath;
10
11
  exports.extractFileFromTarball = extractFileFromTarball;
11
12
  exports.readFileIfExisting = readFileIfExisting;
12
13
  const json_1 = require("./json");
13
- const fs_1 = require("fs");
14
+ const node_fs_1 = require("node:fs");
15
+ const promises_1 = require("node:fs/promises");
14
16
  const path_1 = require("path");
15
17
  const tar = require("tar-stream");
16
18
  const zlib_1 = require("zlib");
@@ -22,7 +24,7 @@ const zlib_1 = require("zlib");
22
24
  * @returns Object the JSON content of the file represents
23
25
  */
24
26
  function readJsonFile(path, options) {
25
- const content = (0, fs_1.readFileSync)(path, 'utf-8');
27
+ const content = (0, node_fs_1.readFileSync)(path, 'utf-8');
26
28
  if (options) {
27
29
  options.endsWithNewline = content.charCodeAt(content.length - 1) === 10;
28
30
  }
@@ -41,7 +43,7 @@ function readJsonFile(path, options) {
41
43
  * @returns
42
44
  */
43
45
  function readYamlFile(path, options) {
44
- const content = (0, fs_1.readFileSync)(path, 'utf-8');
46
+ const content = (0, node_fs_1.readFileSync)(path, 'utf-8');
45
47
  const { load } = require('@zkochan/js-yaml');
46
48
  return load(content, { ...options, filename: path });
47
49
  }
@@ -53,12 +55,27 @@ function readYamlFile(path, options) {
53
55
  * @param options JSON serialize options
54
56
  */
55
57
  function writeJsonFile(path, data, options) {
56
- (0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
58
+ (0, node_fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
57
59
  const serializedJson = (0, json_1.serializeJson)(data, options);
58
60
  const content = options?.appendNewLine
59
61
  ? `${serializedJson}\n`
60
62
  : serializedJson;
61
- (0, fs_1.writeFileSync)(path, content, { encoding: 'utf-8' });
63
+ (0, node_fs_1.writeFileSync)(path, content, { encoding: 'utf-8' });
64
+ }
65
+ /**
66
+ * Serializes the given data to JSON and writes it to a file asynchronously.
67
+ *
68
+ * @param path A path to a file.
69
+ * @param data data which should be serialized to JSON and written to the file
70
+ * @param options JSON serialize options
71
+ */
72
+ async function writeJsonFileAsync(path, data, options) {
73
+ await (0, promises_1.mkdir)((0, path_1.dirname)(path), { recursive: true });
74
+ const serializedJson = (0, json_1.serializeJson)(data, options);
75
+ const content = options?.appendNewLine
76
+ ? `${serializedJson}\n`
77
+ : serializedJson;
78
+ await (0, promises_1.writeFile)(path, content, { encoding: 'utf-8' });
62
79
  }
63
80
  /**
64
81
  * Check if a directory exists
@@ -66,7 +83,7 @@ function writeJsonFile(path, data, options) {
66
83
  */
67
84
  function directoryExists(path) {
68
85
  try {
69
- return (0, fs_1.statSync)(path).isDirectory();
86
+ return (0, node_fs_1.statSync)(path).isDirectory();
70
87
  }
71
88
  catch {
72
89
  return false;
@@ -78,14 +95,14 @@ function directoryExists(path) {
78
95
  */
79
96
  function fileExists(path) {
80
97
  try {
81
- return (0, fs_1.statSync)(path).isFile();
98
+ return (0, node_fs_1.statSync)(path).isFile();
82
99
  }
83
100
  catch {
84
101
  return false;
85
102
  }
86
103
  }
87
104
  function createDirectory(path) {
88
- (0, fs_1.mkdirSync)(path, { recursive: true });
105
+ (0, node_fs_1.mkdirSync)(path, { recursive: true });
89
106
  }
90
107
  function isRelativePath(path) {
91
108
  return (path === '.' ||
@@ -102,9 +119,9 @@ function isRelativePath(path) {
102
119
  */
103
120
  async function extractFileFromTarball(tarballPath, file, destinationFilePath) {
104
121
  return new Promise((resolve, reject) => {
105
- (0, fs_1.mkdirSync)((0, path_1.dirname)(destinationFilePath), { recursive: true });
122
+ (0, node_fs_1.mkdirSync)((0, path_1.dirname)(destinationFilePath), { recursive: true });
106
123
  var tarExtractStream = tar.extract();
107
- const destinationFileStream = (0, fs_1.createWriteStream)(destinationFilePath);
124
+ const destinationFileStream = (0, node_fs_1.createWriteStream)(destinationFilePath);
108
125
  let isFileExtracted = false;
109
126
  tarExtractStream.on('entry', function (header, stream, next) {
110
127
  if (header.name === file) {
@@ -126,9 +143,9 @@ async function extractFileFromTarball(tarballPath, file, destinationFilePath) {
126
143
  reject();
127
144
  }
128
145
  });
129
- (0, fs_1.createReadStream)(tarballPath).pipe((0, zlib_1.createGunzip)()).pipe(tarExtractStream);
146
+ (0, node_fs_1.createReadStream)(tarballPath).pipe((0, zlib_1.createGunzip)()).pipe(tarExtractStream);
130
147
  });
131
148
  }
132
149
  function readFileIfExisting(path) {
133
- return (0, fs_1.existsSync)(path) ? (0, fs_1.readFileSync)(path, 'utf-8') : '';
150
+ return (0, node_fs_1.existsSync)(path) ? (0, node_fs_1.readFileSync)(path, 'utf-8') : '';
134
151
  }
@@ -9,9 +9,10 @@ try {
9
9
  const { execSync } = require('child_process');
10
10
  // NOTE: Using env vars because Windows PowerShell has its own handling of quotes (") messes up quotes in args, even if escaped.
11
11
  const src = process.env.NX_IMPORT_SOURCE;
12
- execSync('git read-tree --empty', { stdio: 'inherit' });
12
+ execSync('git read-tree --empty', { stdio: 'inherit', windowsHide: true });
13
13
  execSync(`git reset ${process.env.GIT_COMMIT} -- "${src}"`, {
14
14
  stdio: 'inherit',
15
+ windowsHide: true,
15
16
  });
16
17
  }
17
18
  catch (error) {
@@ -36,6 +36,7 @@ class GitRepository {
36
36
  getGitRootPath(cwd) {
37
37
  return (0, child_process_1.execSync)('git rev-parse --show-toplevel', {
38
38
  cwd,
39
+ windowsHide: true,
39
40
  })
40
41
  .toString()
41
42
  .trim();
@@ -176,6 +177,7 @@ function getGithubSlugOrNull() {
176
177
  try {
177
178
  const gitRemote = (0, child_process_1.execSync)('git remote -v', {
178
179
  stdio: 'pipe',
180
+ windowsHide: true,
179
181
  }).toString();
180
182
  // If there are no remotes, we default to github
181
183
  if (!gitRemote || gitRemote.length === 0) {
@@ -226,6 +228,7 @@ function commitChanges(commitMessage, directory) {
226
228
  stdio: 'pipe',
227
229
  input: commitMessage,
228
230
  cwd: directory,
231
+ windowsHide: true,
229
232
  });
230
233
  }
231
234
  catch (err) {
@@ -247,6 +250,7 @@ function getLatestCommitSha() {
247
250
  return (0, child_process_1.execSync)('git rev-parse HEAD', {
248
251
  encoding: 'utf8',
249
252
  stdio: 'pipe',
253
+ windowsHide: true,
250
254
  }).trim();
251
255
  }
252
256
  catch {
@@ -14,7 +14,9 @@ try {
14
14
  // NOTE: Using env vars because Windows PowerShell has its own handling of quotes (") messes up quotes in args, even if escaped.
15
15
  const src = process.env.NX_IMPORT_SOURCE;
16
16
  const dest = process.env.NX_IMPORT_DESTINATION;
17
- const files = execSync(`git ls-files -z ${src}`)
17
+ const files = execSync(`git ls-files -z ${src}`, {
18
+ windowsHide: true,
19
+ })
18
20
  .toString()
19
21
  .trim()
20
22
  .split('\x00')
@@ -4,7 +4,7 @@ exports.ALWAYS_IGNORE = void 0;
4
4
  exports.getIgnoredGlobs = getIgnoredGlobs;
5
5
  exports.getAlwaysIgnore = getAlwaysIgnore;
6
6
  exports.getIgnoreObject = getIgnoreObject;
7
- const fs_extra_1 = require("fs-extra");
7
+ const node_fs_1 = require("node:fs");
8
8
  const ignore_1 = require("ignore");
9
9
  const fileutils_1 = require("./fileutils");
10
10
  const path_1 = require("./path");
@@ -48,7 +48,7 @@ function getIgnoreObject(root = workspace_root_1.workspaceRoot) {
48
48
  function getIgnoredGlobsFromFile(file, root) {
49
49
  try {
50
50
  const results = [];
51
- const contents = (0, fs_extra_1.readFileSync)(file, 'utf-8');
51
+ const contents = (0, node_fs_1.readFileSync)(file, 'utf-8');
52
52
  const lines = contents.split('\n');
53
53
  for (const line of lines) {
54
54
  const trimmed = line.trim();
@@ -15,7 +15,7 @@ exports.packageRegistryView = packageRegistryView;
15
15
  exports.packageRegistryPack = packageRegistryPack;
16
16
  const child_process_1 = require("child_process");
17
17
  const fs_1 = require("fs");
18
- const fs_extra_1 = require("fs-extra");
18
+ const promises_1 = require("node:fs/promises");
19
19
  const path_1 = require("path");
20
20
  const semver_1 = require("semver");
21
21
  const tmp_1 = require("tmp");
@@ -301,7 +301,7 @@ function createTempNpmDirectory() {
301
301
  copyPackageManagerConfigurationFiles(workspace_root_1.workspaceRoot, dir);
302
302
  const cleanup = async () => {
303
303
  try {
304
- await (0, fs_extra_1.remove)(dir);
304
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
305
305
  }
306
306
  catch {
307
307
  // It's okay if this fails, the OS will clean it up eventually
@@ -1,5 +1,5 @@
1
1
  export declare function printPowerpackLicense(): Promise<void>;
2
- export declare function getPowerpackLicenseInformation(): Promise<any>;
2
+ export declare function getPowerpackLicenseInformation(): Promise<import("@nx/powerpack-license").PowerpackLicense>;
3
3
  export declare class NxPowerpackNotInstalledError extends Error {
4
4
  constructor(e: Error);
5
5
  }
@@ -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
  }