nx 19.6.0-canary.20240809-d3747e0 → 19.6.0-canary.20240813-c72ba9b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. package/bin/post-install.js +8 -0
  2. package/package.json +12 -12
  3. package/schemas/nx-schema.json +55 -4
  4. package/schemas/project-schema.json +7 -0
  5. package/src/adapter/compat.d.ts +1 -1
  6. package/src/adapter/compat.js +1 -0
  7. package/src/command-line/import/command-object.d.ts +2 -0
  8. package/src/command-line/import/command-object.js +38 -0
  9. package/src/command-line/import/import.d.ts +21 -0
  10. package/src/command-line/import/import.js +173 -0
  11. package/src/command-line/import/utils/merge-remote-source.d.ts +2 -0
  12. package/src/command-line/import/utils/merge-remote-source.js +14 -0
  13. package/src/command-line/import/utils/needs-install.d.ts +3 -0
  14. package/src/command-line/import/utils/needs-install.js +31 -0
  15. package/src/command-line/import/utils/prepare-source-repo.d.ts +2 -0
  16. package/src/command-line/import/utils/prepare-source-repo.js +104 -0
  17. package/src/command-line/init/init-v2.d.ts +7 -0
  18. package/src/command-line/init/init-v2.js +49 -16
  19. package/src/command-line/nx-commands.js +33 -28
  20. package/src/command-line/release/changelog.js +9 -9
  21. package/src/command-line/release/command-object.d.ts +12 -3
  22. package/src/command-line/release/command-object.js +16 -1
  23. package/src/command-line/release/config/config.js +4 -2
  24. package/src/command-line/release/config/filter-release-groups.d.ts +2 -2
  25. package/src/command-line/release/config/filter-release-groups.js +1 -1
  26. package/src/command-line/release/config/version-plans.d.ts +1 -1
  27. package/src/command-line/release/config/version-plans.js +12 -12
  28. package/src/command-line/release/plan-check.d.ts +4 -0
  29. package/src/command-line/release/plan-check.js +225 -0
  30. package/src/command-line/release/plan.js +1 -1
  31. package/src/command-line/release/release.js +3 -3
  32. package/src/command-line/release/version.js +1 -1
  33. package/src/command-line/sync/command-object.d.ts +6 -0
  34. package/src/command-line/sync/command-object.js +25 -0
  35. package/src/command-line/sync/sync.d.ts +6 -0
  36. package/src/command-line/sync/sync.js +30 -0
  37. package/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  38. package/src/config/nx-json.d.ts +32 -2
  39. package/src/config/workspace-json-project-json.d.ts +5 -0
  40. package/src/core/graph/main.js +1 -1
  41. package/src/daemon/cache.d.ts +1 -0
  42. package/src/daemon/cache.js +25 -18
  43. package/src/daemon/client/client.d.ts +5 -0
  44. package/src/daemon/client/client.js +42 -1
  45. package/src/daemon/message-types/flush-sync-generator-changes-to-disk.d.ts +6 -0
  46. package/src/daemon/message-types/flush-sync-generator-changes-to-disk.js +11 -0
  47. package/src/daemon/message-types/force-shutdown.d.ts +5 -0
  48. package/src/daemon/message-types/force-shutdown.js +11 -0
  49. package/src/daemon/message-types/get-registered-sync-generators.d.ts +5 -0
  50. package/src/daemon/message-types/get-registered-sync-generators.js +11 -0
  51. package/src/daemon/message-types/get-sync-generator-changes.d.ts +6 -0
  52. package/src/daemon/message-types/get-sync-generator-changes.js +11 -0
  53. package/src/daemon/message-types/update-workspace-context.d.ts +8 -0
  54. package/src/daemon/message-types/update-workspace-context.js +11 -0
  55. package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.d.ts +2 -0
  56. package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.js +11 -0
  57. package/src/daemon/server/handle-force-shutdown.d.ts +5 -0
  58. package/src/daemon/server/handle-force-shutdown.js +18 -0
  59. package/src/daemon/server/handle-get-registered-sync-generators.d.ts +2 -0
  60. package/src/daemon/server/handle-get-registered-sync-generators.js +11 -0
  61. package/src/daemon/server/handle-get-sync-generator-changes.d.ts +2 -0
  62. package/src/daemon/server/handle-get-sync-generator-changes.js +17 -0
  63. package/src/daemon/server/handle-request-shutdown.js +2 -0
  64. package/src/daemon/server/handle-update-workspace-context.d.ts +2 -0
  65. package/src/daemon/server/handle-update-workspace-context.js +11 -0
  66. package/src/daemon/server/project-graph-incremental-recomputation.d.ts +1 -0
  67. package/src/daemon/server/project-graph-incremental-recomputation.js +19 -2
  68. package/src/daemon/server/server.d.ts +1 -0
  69. package/src/daemon/server/server.js +39 -0
  70. package/src/daemon/server/shutdown-utils.d.ts +2 -1
  71. package/src/daemon/server/shutdown-utils.js +11 -4
  72. package/src/daemon/server/sync-generators.d.ts +6 -0
  73. package/src/daemon/server/sync-generators.js +202 -0
  74. package/src/daemon/server/watcher.js +3 -0
  75. package/src/daemon/socket-utils.js +18 -5
  76. package/src/daemon/tmp-dir.js +2 -1
  77. package/src/native/nx.wasm32-wasi.wasm +0 -0
  78. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +1 -1
  79. package/src/nx-cloud/models/onboarding-status.d.ts +1 -0
  80. package/src/nx-cloud/models/onboarding-status.js +2 -0
  81. package/src/nx-cloud/utilities/is-workspace-claimed.d.ts +1 -0
  82. package/src/nx-cloud/utilities/is-workspace-claimed.js +24 -0
  83. package/src/nx-cloud/utilities/onboarding.d.ts +5 -0
  84. package/src/nx-cloud/utilities/onboarding.js +28 -0
  85. package/src/project-graph/plugins/internal-api.js +16 -5
  86. package/src/project-graph/plugins/isolation/messaging.d.ts +5 -1
  87. package/src/project-graph/plugins/isolation/messaging.js +1 -0
  88. package/src/project-graph/plugins/isolation/plugin-pool.js +4 -6
  89. package/src/project-graph/plugins/isolation/plugin-worker.js +15 -0
  90. package/src/project-graph/utils/project-configuration-utils.js +5 -2
  91. package/src/tasks-runner/run-command.d.ts +1 -1
  92. package/src/tasks-runner/run-command.js +120 -2
  93. package/src/utils/command-line-utils.d.ts +1 -0
  94. package/src/utils/command-line-utils.js +6 -3
  95. package/src/utils/git-utils.d.ts +35 -0
  96. package/src/utils/git-utils.js +111 -0
  97. package/src/utils/package-manager.js +1 -1
  98. package/src/utils/plugins/output.js +1 -1
  99. package/src/utils/squash.d.ts +1 -0
  100. package/src/utils/squash.js +12 -0
  101. package/src/utils/sync-generators.d.ts +22 -0
  102. package/src/utils/sync-generators.js +161 -0
  103. package/src/utils/workspace-context.d.ts +1 -0
  104. package/src/utils/workspace-context.js +16 -0
  105. package/src/daemon/message-types/update-context-files.d.ts +0 -7
  106. package/src/daemon/message-types/update-context-files.js +0 -11
@@ -5,5 +5,6 @@ export declare const serverProcessJsonPath: string;
5
5
  export declare function readDaemonProcessJsonCache(): Promise<DaemonProcessJson | null>;
6
6
  export declare function deleteDaemonJsonProcessCache(): void;
7
7
  export declare function writeDaemonJsonProcessCache(daemonJson: DaemonProcessJson): Promise<void>;
8
+ export declare function waitForDaemonToExitAndCleanupProcessJson(): Promise<void>;
8
9
  export declare function safelyCleanUpExistingProcess(): Promise<void>;
9
10
  export declare function getDaemonProcessIdSync(): number | null;
@@ -4,6 +4,7 @@ exports.serverProcessJsonPath = void 0;
4
4
  exports.readDaemonProcessJsonCache = readDaemonProcessJsonCache;
5
5
  exports.deleteDaemonJsonProcessCache = deleteDaemonJsonProcessCache;
6
6
  exports.writeDaemonJsonProcessCache = writeDaemonJsonProcessCache;
7
+ exports.waitForDaemonToExitAndCleanupProcessJson = waitForDaemonToExitAndCleanupProcessJson;
7
8
  exports.safelyCleanUpExistingProcess = safelyCleanUpExistingProcess;
8
9
  exports.getDaemonProcessIdSync = getDaemonProcessIdSync;
9
10
  const fs_extra_1 = require("fs-extra");
@@ -27,33 +28,39 @@ function deleteDaemonJsonProcessCache() {
27
28
  async function writeDaemonJsonProcessCache(daemonJson) {
28
29
  await (0, fs_extra_1.writeJson)(exports.serverProcessJsonPath, daemonJson);
29
30
  }
31
+ async function waitForDaemonToExitAndCleanupProcessJson() {
32
+ const daemonProcessJson = await readDaemonProcessJsonCache();
33
+ if (daemonProcessJson && daemonProcessJson.processId) {
34
+ await new Promise((resolve, reject) => {
35
+ let count = 0;
36
+ const interval = setInterval(() => {
37
+ try {
38
+ // sending a signal 0 to a process checks if the process is running instead of actually killing it
39
+ process.kill(daemonProcessJson.processId, 0);
40
+ }
41
+ catch (e) {
42
+ clearInterval(interval);
43
+ resolve();
44
+ }
45
+ if ((count += 1) > 200) {
46
+ clearInterval(interval);
47
+ reject(`Daemon process ${daemonProcessJson.processId} didn't exit after 2 seconds.`);
48
+ }
49
+ }, 10);
50
+ });
51
+ deleteDaemonJsonProcessCache();
52
+ }
53
+ }
30
54
  async function safelyCleanUpExistingProcess() {
31
55
  const daemonProcessJson = await readDaemonProcessJsonCache();
32
56
  if (daemonProcessJson && daemonProcessJson.processId) {
33
57
  try {
34
58
  process.kill(daemonProcessJson.processId);
35
59
  // we wait for the process to actually shut down before returning
36
- await new Promise((resolve, reject) => {
37
- let count = 0;
38
- const interval = setInterval(() => {
39
- try {
40
- // sending a signal 0 to a process checks if the process is running instead of actually killing it
41
- process.kill(daemonProcessJson.processId, 0);
42
- }
43
- catch (e) {
44
- clearInterval(interval);
45
- resolve();
46
- }
47
- if ((count += 1) > 200) {
48
- clearInterval(interval);
49
- reject(`Daemon process ${daemonProcessJson.processId} didn't exit after 2 seconds.`);
50
- }
51
- }, 10);
52
- });
60
+ await waitForDaemonToExitAndCleanupProcessJson();
53
61
  }
54
62
  catch { }
55
63
  }
56
- deleteDaemonJsonProcessCache();
57
64
  }
58
65
  // Must be sync for the help output use case
59
66
  function getDaemonProcessIdSync() {
@@ -5,6 +5,7 @@ import { Task, TaskGraph } from '../../config/task-graph';
5
5
  import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration-utils';
6
6
  import { NxWorkspaceFiles } from '../../native';
7
7
  import { TaskRun } from '../../utils/task-history';
8
+ import type { SyncGeneratorChangesResult } from '../../utils/sync-generators';
8
9
  export type UnregisterCallback = () => void;
9
10
  export type ChangedFile = {
10
11
  path: string;
@@ -54,6 +55,10 @@ export declare class DaemonClient {
54
55
  [hash: string]: TaskRun[];
55
56
  }>;
56
57
  writeTaskRunsToHistory(taskRuns: TaskRun[]): Promise<void>;
58
+ getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorChangesResult[]>;
59
+ flushSyncGeneratorChangesToDisk(generators: string[]): Promise<void>;
60
+ getRegisteredSyncGenerators(): Promise<string[]>;
61
+ updateWorkspaceContext(createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): Promise<void>;
57
62
  isServerAvailable(): Promise<boolean>;
58
63
  private sendToDaemonViaQueue;
59
64
  private setUpConnection;
@@ -25,6 +25,11 @@ const get_nx_workspace_files_1 = require("../message-types/get-nx-workspace-file
25
25
  const get_context_file_data_1 = require("../message-types/get-context-file-data");
26
26
  const get_files_in_directory_1 = require("../message-types/get-files-in-directory");
27
27
  const hash_glob_1 = require("../message-types/hash-glob");
28
+ const force_shutdown_1 = require("../message-types/force-shutdown");
29
+ const get_sync_generator_changes_1 = require("../message-types/get-sync-generator-changes");
30
+ const get_registered_sync_generators_1 = require("../message-types/get-registered-sync-generators");
31
+ const update_workspace_context_1 = require("../message-types/update-workspace-context");
32
+ const flush_sync_generator_changes_to_disk_1 = require("../message-types/flush-sync-generator-changes-to-disk");
28
33
  const DAEMON_ENV_SETTINGS = {
29
34
  NX_PROJECT_GLOB_CACHE: 'false',
30
35
  NX_CACHE_PROJECTS_CONFIG: 'false',
@@ -244,6 +249,35 @@ class DaemonClient {
244
249
  };
245
250
  return this.sendMessageToDaemon(message);
246
251
  }
252
+ getSyncGeneratorChanges(generators) {
253
+ const message = {
254
+ type: get_sync_generator_changes_1.GET_SYNC_GENERATOR_CHANGES,
255
+ generators,
256
+ };
257
+ return this.sendToDaemonViaQueue(message);
258
+ }
259
+ flushSyncGeneratorChangesToDisk(generators) {
260
+ const message = {
261
+ type: flush_sync_generator_changes_to_disk_1.FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK,
262
+ generators,
263
+ };
264
+ return this.sendToDaemonViaQueue(message);
265
+ }
266
+ getRegisteredSyncGenerators() {
267
+ const message = {
268
+ type: get_registered_sync_generators_1.GET_REGISTERED_SYNC_GENERATORS,
269
+ };
270
+ return this.sendToDaemonViaQueue(message);
271
+ }
272
+ updateWorkspaceContext(createdFiles, updatedFiles, deletedFiles) {
273
+ const message = {
274
+ type: update_workspace_context_1.UPDATE_WORKSPACE_CONTEXT,
275
+ createdFiles,
276
+ updatedFiles,
277
+ deletedFiles,
278
+ };
279
+ return this.sendToDaemonViaQueue(message);
280
+ }
247
281
  async isServerAvailable() {
248
282
  return new Promise((resolve) => {
249
283
  try {
@@ -322,12 +356,18 @@ class DaemonClient {
322
356
  else if (this._daemonStatus == DaemonStatus.CONNECTING) {
323
357
  await this._waitForDaemonReady;
324
358
  }
359
+ // An open promise isn't enough to keep the event loop
360
+ // alive, so we set a timeout here and clear it when we hear
361
+ // back
362
+ const keepAlive = setTimeout(() => { }, 10 * 60 * 1000);
325
363
  return new Promise((resolve, reject) => {
326
364
  perf_hooks_1.performance.mark('sendMessageToDaemon-start');
327
365
  this.currentMessage = message;
328
366
  this.currentResolve = resolve;
329
367
  this.currentReject = reject;
330
368
  this.socketMessenger.sendMessage(message);
369
+ }).finally(() => {
370
+ clearTimeout(keepAlive);
331
371
  });
332
372
  }
333
373
  handleMessage(serializedResult) {
@@ -398,7 +438,8 @@ class DaemonClient {
398
438
  }
399
439
  async stop() {
400
440
  try {
401
- await (0, cache_1.safelyCleanUpExistingProcess)();
441
+ await this.sendMessageToDaemon({ type: force_shutdown_1.FORCE_SHUTDOWN });
442
+ await (0, cache_1.waitForDaemonToExitAndCleanupProcessJson)();
402
443
  }
403
444
  catch (err) {
404
445
  output_1.output.error({
@@ -0,0 +1,6 @@
1
+ export declare const FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK: "CLEAR_CACHED_SYNC_GENERATOR_CHANGES";
2
+ export type HandleFlushSyncGeneratorChangesToDiskMessage = {
3
+ type: typeof FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK;
4
+ generators: string[];
5
+ };
6
+ export declare function isHandleFlushSyncGeneratorChangesToDiskMessage(message: unknown): message is HandleFlushSyncGeneratorChangesToDiskMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK = void 0;
4
+ exports.isHandleFlushSyncGeneratorChangesToDiskMessage = isHandleFlushSyncGeneratorChangesToDiskMessage;
5
+ exports.FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK = 'CLEAR_CACHED_SYNC_GENERATOR_CHANGES';
6
+ function isHandleFlushSyncGeneratorChangesToDiskMessage(message) {
7
+ return (typeof message === 'object' &&
8
+ message !== null &&
9
+ 'type' in message &&
10
+ message['type'] === exports.FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK);
11
+ }
@@ -0,0 +1,5 @@
1
+ export declare const FORCE_SHUTDOWN: "FORCE_SHUTDOWN";
2
+ export type HandleForceShutdownMessage = {
3
+ type: typeof FORCE_SHUTDOWN;
4
+ };
5
+ export declare function isHandleForceShutdownMessage(message: unknown): message is HandleForceShutdownMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORCE_SHUTDOWN = void 0;
4
+ exports.isHandleForceShutdownMessage = isHandleForceShutdownMessage;
5
+ exports.FORCE_SHUTDOWN = 'FORCE_SHUTDOWN';
6
+ function isHandleForceShutdownMessage(message) {
7
+ return (typeof message === 'object' &&
8
+ message !== null &&
9
+ 'type' in message &&
10
+ message['type'] === exports.FORCE_SHUTDOWN);
11
+ }
@@ -0,0 +1,5 @@
1
+ export declare const GET_REGISTERED_SYNC_GENERATORS: "GET_REGISTERED_SYNC_GENERATORS";
2
+ export type HandleGetRegisteredSyncGeneratorsMessage = {
3
+ type: typeof GET_REGISTERED_SYNC_GENERATORS;
4
+ };
5
+ export declare function isHandleGetRegisteredSyncGeneratorsMessage(message: unknown): message is HandleGetRegisteredSyncGeneratorsMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET_REGISTERED_SYNC_GENERATORS = void 0;
4
+ exports.isHandleGetRegisteredSyncGeneratorsMessage = isHandleGetRegisteredSyncGeneratorsMessage;
5
+ exports.GET_REGISTERED_SYNC_GENERATORS = 'GET_REGISTERED_SYNC_GENERATORS';
6
+ function isHandleGetRegisteredSyncGeneratorsMessage(message) {
7
+ return (typeof message === 'object' &&
8
+ message !== null &&
9
+ 'type' in message &&
10
+ message['type'] === exports.GET_REGISTERED_SYNC_GENERATORS);
11
+ }
@@ -0,0 +1,6 @@
1
+ export declare const GET_SYNC_GENERATOR_CHANGES: "GET_SYNC_GENERATOR_CHANGES";
2
+ export type HandleGetSyncGeneratorChangesMessage = {
3
+ type: typeof GET_SYNC_GENERATOR_CHANGES;
4
+ generators: string[];
5
+ };
6
+ export declare function isHandleGetSyncGeneratorChangesMessage(message: unknown): message is HandleGetSyncGeneratorChangesMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET_SYNC_GENERATOR_CHANGES = void 0;
4
+ exports.isHandleGetSyncGeneratorChangesMessage = isHandleGetSyncGeneratorChangesMessage;
5
+ exports.GET_SYNC_GENERATOR_CHANGES = 'GET_SYNC_GENERATOR_CHANGES';
6
+ function isHandleGetSyncGeneratorChangesMessage(message) {
7
+ return (typeof message === 'object' &&
8
+ message !== null &&
9
+ 'type' in message &&
10
+ message['type'] === exports.GET_SYNC_GENERATOR_CHANGES);
11
+ }
@@ -0,0 +1,8 @@
1
+ export declare const UPDATE_WORKSPACE_CONTEXT: "UPDATE_WORKSPACE_CONTEXT";
2
+ export type HandleUpdateWorkspaceContextMessage = {
3
+ type: typeof UPDATE_WORKSPACE_CONTEXT;
4
+ createdFiles: string[];
5
+ updatedFiles: string[];
6
+ deletedFiles: string[];
7
+ };
8
+ export declare function isHandleUpdateWorkspaceContextMessage(message: unknown): message is HandleUpdateWorkspaceContextMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UPDATE_WORKSPACE_CONTEXT = void 0;
4
+ exports.isHandleUpdateWorkspaceContextMessage = isHandleUpdateWorkspaceContextMessage;
5
+ exports.UPDATE_WORKSPACE_CONTEXT = 'UPDATE_WORKSPACE_CONTEXT';
6
+ function isHandleUpdateWorkspaceContextMessage(message) {
7
+ return (typeof message === 'object' &&
8
+ message !== null &&
9
+ 'type' in message &&
10
+ message['type'] === exports.UPDATE_WORKSPACE_CONTEXT);
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { HandlerResult } from './server';
2
+ export declare function handleFlushSyncGeneratorChangesToDisk(generators: string[]): Promise<HandlerResult>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleFlushSyncGeneratorChangesToDisk = handleFlushSyncGeneratorChangesToDisk;
4
+ const sync_generators_1 = require("./sync-generators");
5
+ async function handleFlushSyncGeneratorChangesToDisk(generators) {
6
+ await (0, sync_generators_1.flushSyncGeneratorChangesToDisk)(generators);
7
+ return {
8
+ response: '{}',
9
+ description: 'handleFlushSyncGeneratorChangesToDisk',
10
+ };
11
+ }
@@ -0,0 +1,5 @@
1
+ import { Server } from 'net';
2
+ export declare function handleForceShutdown(server: Server): Promise<{
3
+ description: string;
4
+ response: string;
5
+ }>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleForceShutdown = handleForceShutdown;
4
+ const shutdown_utils_1 = require("./shutdown-utils");
5
+ const server_1 = require("./server");
6
+ async function handleForceShutdown(server) {
7
+ setTimeout(async () => {
8
+ await (0, shutdown_utils_1.handleServerProcessTermination)({
9
+ server,
10
+ reason: 'Request to shutdown',
11
+ sockets: server_1.openSockets,
12
+ });
13
+ });
14
+ return {
15
+ description: 'Shutdown initiated',
16
+ response: '{}',
17
+ };
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { HandlerResult } from './server';
2
+ export declare function handleGetRegisteredSyncGenerators(): Promise<HandlerResult>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleGetRegisteredSyncGenerators = handleGetRegisteredSyncGenerators;
4
+ const sync_generators_1 = require("./sync-generators");
5
+ async function handleGetRegisteredSyncGenerators() {
6
+ const syncGenerators = await (0, sync_generators_1.getCachedRegisteredSyncGenerators)();
7
+ return {
8
+ response: JSON.stringify(syncGenerators),
9
+ description: 'handleGetSyncGeneratorChanges',
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { HandlerResult } from './server';
2
+ export declare function handleGetSyncGeneratorChanges(generators: string[]): Promise<HandlerResult>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleGetSyncGeneratorChanges = handleGetSyncGeneratorChanges;
4
+ const sync_generators_1 = require("./sync-generators");
5
+ async function handleGetSyncGeneratorChanges(generators) {
6
+ const changes = await (0, sync_generators_1.getCachedSyncGeneratorChanges)(generators);
7
+ // strip out the content of the changes and any potential callback
8
+ const result = changes.map((change) => ({
9
+ generatorName: change.generatorName,
10
+ changes: change.changes.map((c) => ({ ...c, content: null })),
11
+ outOfSyncMessage: change.outOfSyncMessage,
12
+ }));
13
+ return {
14
+ response: JSON.stringify(result),
15
+ description: 'handleGetSyncGeneratorChanges',
16
+ };
17
+ }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleRequestShutdown = handleRequestShutdown;
4
4
  const shutdown_utils_1 = require("./shutdown-utils");
5
+ const server_1 = require("./server");
5
6
  async function handleRequestShutdown(server, numberOfConnections) {
6
7
  // 1 connection is the client asking to shut down
7
8
  if (numberOfConnections > 1) {
@@ -15,6 +16,7 @@ async function handleRequestShutdown(server, numberOfConnections) {
15
16
  await (0, shutdown_utils_1.handleServerProcessTermination)({
16
17
  server,
17
18
  reason: 'Request to shutdown',
19
+ sockets: server_1.openSockets,
18
20
  });
19
21
  }, 0);
20
22
  return {
@@ -0,0 +1,2 @@
1
+ import type { HandlerResult } from './server';
2
+ export declare function handleUpdateWorkspaceContext(createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): Promise<HandlerResult>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleUpdateWorkspaceContext = handleUpdateWorkspaceContext;
4
+ const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
5
+ async function handleUpdateWorkspaceContext(createdFiles, updatedFiles, deletedFiles) {
6
+ (0, project_graph_incremental_recomputation_1.addUpdatedAndDeletedFiles)(createdFiles, updatedFiles, deletedFiles);
7
+ return {
8
+ response: '{}',
9
+ description: 'handleUpdateContextFiles',
10
+ };
11
+ }
@@ -20,4 +20,5 @@ export declare let currentProjectFileMapCache: FileMapCache | undefined;
20
20
  export declare let currentProjectGraph: ProjectGraph | undefined;
21
21
  export declare function getCachedSerializedProjectGraphPromise(): Promise<SerializedProjectGraph>;
22
22
  export declare function addUpdatedAndDeletedFiles(createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): void;
23
+ export declare function registerProjectGraphRecomputationListener(listener: (projectGraph: ProjectGraph) => void): void;
23
24
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.currentProjectGraph = exports.currentProjectFileMapCache = exports.fileMapWithFiles = void 0;
4
4
  exports.getCachedSerializedProjectGraphPromise = getCachedSerializedProjectGraphPromise;
5
5
  exports.addUpdatedAndDeletedFiles = addUpdatedAndDeletedFiles;
6
+ exports.registerProjectGraphRecomputationListener = registerProjectGraphRecomputationListener;
6
7
  const perf_hooks_1 = require("perf_hooks");
7
8
  const nx_json_1 = require("../../config/nx-json");
8
9
  const file_hasher_1 = require("../../hasher/file-hasher");
@@ -20,14 +21,17 @@ const error_types_1 = require("../../project-graph/error-types");
20
21
  let cachedSerializedProjectGraphPromise;
21
22
  const collectedUpdatedFiles = new Set();
22
23
  const collectedDeletedFiles = new Set();
24
+ const projectGraphRecomputationListeners = new Set();
23
25
  let storedWorkspaceConfigHash;
24
26
  let waitPeriod = 100;
25
27
  let scheduledTimeoutId;
26
28
  let knownExternalNodes = {};
27
29
  async function getCachedSerializedProjectGraphPromise() {
28
30
  try {
31
+ let wasScheduled = false;
29
32
  // recomputing it now on demand. we can ignore the scheduled timeout
30
33
  if (scheduledTimeoutId) {
34
+ wasScheduled = true;
31
35
  clearTimeout(scheduledTimeoutId);
32
36
  scheduledTimeoutId = undefined;
33
37
  }
@@ -45,7 +49,11 @@ async function getCachedSerializedProjectGraphPromise() {
45
49
  cachedSerializedProjectGraphPromise =
46
50
  processFilesAndCreateAndSerializeProjectGraph(plugins);
47
51
  }
48
- return await cachedSerializedProjectGraphPromise;
52
+ const result = await cachedSerializedProjectGraphPromise;
53
+ if (wasScheduled) {
54
+ notifyProjectGraphRecomputationListeners(result.projectGraph);
55
+ }
56
+ return result;
49
57
  }
50
58
  catch (e) {
51
59
  return {
@@ -83,13 +91,17 @@ function addUpdatedAndDeletedFiles(createdFiles, updatedFiles, deletedFiles) {
83
91
  }
84
92
  cachedSerializedProjectGraphPromise =
85
93
  processFilesAndCreateAndSerializeProjectGraph(await (0, plugins_1.getPlugins)());
86
- await cachedSerializedProjectGraphPromise;
94
+ const { projectGraph } = await cachedSerializedProjectGraphPromise;
87
95
  if (createdFiles.length > 0) {
88
96
  (0, file_watcher_sockets_1.notifyFileWatcherSockets)(createdFiles, null, null);
89
97
  }
98
+ notifyProjectGraphRecomputationListeners(projectGraph);
90
99
  }, waitPeriod);
91
100
  }
92
101
  }
102
+ function registerProjectGraphRecomputationListener(listener) {
103
+ projectGraphRecomputationListeners.add(listener);
104
+ }
93
105
  function computeWorkspaceConfigHash(projectsConfigurations) {
94
106
  const projectConfigurationStrings = Object.entries(projectsConfigurations)
95
107
  .sort(([projectNameA], [projectNameB]) => projectNameA.localeCompare(projectNameB))
@@ -281,3 +293,8 @@ async function resetInternalStateIfNxDepsMissing() {
281
293
  await resetInternalState();
282
294
  }
283
295
  }
296
+ function notifyProjectGraphRecomputationListeners(projectGraph) {
297
+ for (const listener of projectGraphRecomputationListeners) {
298
+ listener(projectGraph);
299
+ }
300
+ }
@@ -4,5 +4,6 @@ export type HandlerResult = {
4
4
  error?: any;
5
5
  response?: string;
6
6
  };
7
+ export declare const openSockets: Set<Socket>;
7
8
  export declare function handleResult(socket: Socket, type: string, hrFn: () => Promise<HandlerResult>): Promise<void>;
8
9
  export declare function startServer(): Promise<Server>;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openSockets = void 0;
3
4
  exports.handleResult = handleResult;
4
5
  exports.startServer = startServer;
5
6
  const fs_1 = require("fs");
@@ -39,13 +40,26 @@ const handle_hash_glob_1 = require("./handle-hash-glob");
39
40
  const task_history_1 = require("../message-types/task-history");
40
41
  const handle_get_task_history_1 = require("./handle-get-task-history");
41
42
  const handle_write_task_runs_to_history_1 = require("./handle-write-task-runs-to-history");
43
+ const force_shutdown_1 = require("../message-types/force-shutdown");
44
+ const handle_force_shutdown_1 = require("./handle-force-shutdown");
45
+ const get_sync_generator_changes_1 = require("../message-types/get-sync-generator-changes");
46
+ const handle_get_sync_generator_changes_1 = require("./handle-get-sync-generator-changes");
47
+ const sync_generators_1 = require("./sync-generators");
48
+ const get_registered_sync_generators_1 = require("../message-types/get-registered-sync-generators");
49
+ const handle_get_registered_sync_generators_1 = require("./handle-get-registered-sync-generators");
50
+ const update_workspace_context_1 = require("../message-types/update-workspace-context");
51
+ const handle_update_workspace_context_1 = require("./handle-update-workspace-context");
52
+ const flush_sync_generator_changes_to_disk_1 = require("../message-types/flush-sync-generator-changes-to-disk");
53
+ const handle_flush_sync_generator_changes_to_disk_1 = require("./handle-flush-sync-generator-changes-to-disk");
42
54
  let performanceObserver;
43
55
  let workspaceWatcherError;
44
56
  let outputsWatcherError;
45
57
  global.NX_DAEMON = true;
46
58
  let numberOfOpenConnections = 0;
59
+ exports.openSockets = new Set();
47
60
  const server = (0, net_1.createServer)(async (socket) => {
48
61
  numberOfOpenConnections += 1;
62
+ exports.openSockets.add(socket);
49
63
  logger_1.serverLogger.log(`Established a connection. Number of open connections: ${numberOfOpenConnections}`);
50
64
  (0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
51
65
  if (!performanceObserver) {
@@ -64,6 +78,7 @@ const server = (0, net_1.createServer)(async (socket) => {
64
78
  });
65
79
  socket.on('close', () => {
66
80
  numberOfOpenConnections -= 1;
81
+ exports.openSockets.delete(socket);
67
82
  logger_1.serverLogger.log(`Closed a connection. Number of open connections: ${numberOfOpenConnections}`);
68
83
  (0, file_watcher_sockets_1.removeRegisteredFileWatcherSocket)(socket);
69
84
  });
@@ -131,6 +146,21 @@ async function handleMessage(socket, data) {
131
146
  else if ((0, task_history_1.isHandleWriteTaskRunsToHistoryMessage)(payload)) {
132
147
  await handleResult(socket, 'WRITE_TASK_RUNS_TO_HISTORY', () => (0, handle_write_task_runs_to_history_1.handleWriteTaskRunsToHistory)(payload.taskRuns));
133
148
  }
149
+ else if ((0, force_shutdown_1.isHandleForceShutdownMessage)(payload)) {
150
+ await handleResult(socket, 'FORCE_SHUTDOWN', () => (0, handle_force_shutdown_1.handleForceShutdown)(server));
151
+ }
152
+ else if ((0, get_sync_generator_changes_1.isHandleGetSyncGeneratorChangesMessage)(payload)) {
153
+ await handleResult(socket, get_sync_generator_changes_1.GET_SYNC_GENERATOR_CHANGES, () => (0, handle_get_sync_generator_changes_1.handleGetSyncGeneratorChanges)(payload.generators));
154
+ }
155
+ else if ((0, flush_sync_generator_changes_to_disk_1.isHandleFlushSyncGeneratorChangesToDiskMessage)(payload)) {
156
+ await handleResult(socket, flush_sync_generator_changes_to_disk_1.FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK, () => (0, handle_flush_sync_generator_changes_to_disk_1.handleFlushSyncGeneratorChangesToDisk)(payload.generators));
157
+ }
158
+ else if ((0, get_registered_sync_generators_1.isHandleGetRegisteredSyncGeneratorsMessage)(payload)) {
159
+ await handleResult(socket, get_registered_sync_generators_1.GET_REGISTERED_SYNC_GENERATORS, () => (0, handle_get_registered_sync_generators_1.handleGetRegisteredSyncGenerators)());
160
+ }
161
+ else if ((0, update_workspace_context_1.isHandleUpdateWorkspaceContextMessage)(payload)) {
162
+ await handleResult(socket, update_workspace_context_1.UPDATE_WORKSPACE_CONTEXT, () => (0, handle_update_workspace_context_1.handleUpdateWorkspaceContext)(payload.createdFiles, payload.updatedFiles, payload.deletedFiles));
163
+ }
134
164
  else {
135
165
  await (0, shutdown_utils_1.respondWithErrorAndExit)(socket, `Invalid payload from the client`, new Error(`Unsupported payload sent to daemon server: ${unparsedPayload}`));
136
166
  }
@@ -157,6 +187,7 @@ function handleInactivityTimeout() {
157
187
  (0, shutdown_utils_1.handleServerProcessTermination)({
158
188
  server,
159
189
  reason: `${shutdown_utils_1.SERVER_INACTIVITY_TIMEOUT_MS}ms of inactivity`,
190
+ sockets: exports.openSockets,
160
191
  });
161
192
  }
162
193
  }
@@ -165,14 +196,17 @@ function registerProcessTerminationListeners() {
165
196
  .on('SIGINT', () => (0, shutdown_utils_1.handleServerProcessTermination)({
166
197
  server,
167
198
  reason: 'received process SIGINT',
199
+ sockets: exports.openSockets,
168
200
  }))
169
201
  .on('SIGTERM', () => (0, shutdown_utils_1.handleServerProcessTermination)({
170
202
  server,
171
203
  reason: 'received process SIGTERM',
204
+ sockets: exports.openSockets,
172
205
  }))
173
206
  .on('SIGHUP', () => (0, shutdown_utils_1.handleServerProcessTermination)({
174
207
  server,
175
208
  reason: 'received process SIGHUP',
209
+ sockets: exports.openSockets,
176
210
  }));
177
211
  }
178
212
  let existingLockHash;
@@ -235,6 +269,7 @@ const handleWorkspaceChanges = async (err, changeEvents) => {
235
269
  await (0, shutdown_utils_1.handleServerProcessTermination)({
236
270
  server,
237
271
  reason: outdatedReason,
272
+ sockets: exports.openSockets,
238
273
  });
239
274
  return;
240
275
  }
@@ -325,6 +360,10 @@ async function startServer() {
325
360
  if (!(0, shutdown_utils_1.getOutputWatcherInstance)()) {
326
361
  (0, shutdown_utils_1.storeOutputWatcherInstance)(await (0, watcher_1.watchOutputFiles)(handleOutputsChanges));
327
362
  }
363
+ // listen for project graph recomputation events to collect and schedule sync generators
364
+ (0, project_graph_incremental_recomputation_1.registerProjectGraphRecomputationListener)(sync_generators_1.collectAndScheduleSyncGenerators);
365
+ // trigger an initial project graph recomputation
366
+ (0, project_graph_incremental_recomputation_1.addUpdatedAndDeletedFiles)([], [], []);
328
367
  return resolve(server);
329
368
  }
330
369
  catch (err) {
@@ -8,8 +8,9 @@ export declare function getOutputWatcherInstance(): Watcher;
8
8
  interface HandleServerProcessTerminationParams {
9
9
  server: Server;
10
10
  reason: string;
11
+ sockets: Iterable<Socket>;
11
12
  }
12
- export declare function handleServerProcessTermination({ server, reason, }: HandleServerProcessTerminationParams): Promise<void>;
13
+ export declare function handleServerProcessTermination({ server, reason, sockets, }: HandleServerProcessTerminationParams): Promise<void>;
13
14
  export declare function resetInactivityTimeout(cb: () => void): void;
14
15
  export declare function respondToClient(socket: Socket, response: string, description: string): Promise<unknown>;
15
16
  export declare function respondWithErrorAndExit(socket: Socket, description: string, error: Error): Promise<void>;
@@ -30,11 +30,16 @@ function storeOutputWatcherInstance(instance) {
30
30
  function getOutputWatcherInstance() {
31
31
  return outputWatcherInstance;
32
32
  }
33
- async function handleServerProcessTermination({ server, reason, }) {
33
+ async function handleServerProcessTermination({ server, reason, sockets, }) {
34
34
  try {
35
- server.close();
36
- (0, cache_1.deleteDaemonJsonProcessCache)();
37
- (0, plugins_1.cleanupPlugins)();
35
+ await new Promise((res) => {
36
+ server.close(() => {
37
+ res(null);
38
+ });
39
+ for (const socket of sockets) {
40
+ socket.destroy();
41
+ }
42
+ });
38
43
  if (watcherInstance) {
39
44
  await watcherInstance.stop();
40
45
  logger_1.serverLogger.watcherLog(`Stopping the watcher for ${workspace_root_1.workspaceRoot} (sources)`);
@@ -43,6 +48,8 @@ async function handleServerProcessTermination({ server, reason, }) {
43
48
  await outputWatcherInstance.stop();
44
49
  logger_1.serverLogger.watcherLog(`Stopping the watcher for ${workspace_root_1.workspaceRoot} (outputs)`);
45
50
  }
51
+ (0, cache_1.deleteDaemonJsonProcessCache)();
52
+ (0, plugins_1.cleanupPlugins)();
46
53
  logger_1.serverLogger.log(`Server stopped because: "${reason}"`);
47
54
  }
48
55
  finally {
@@ -0,0 +1,6 @@
1
+ import type { ProjectGraph } from '../../config/project-graph';
2
+ import { type SyncGeneratorChangesResult } from '../../utils/sync-generators';
3
+ export declare function getCachedSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorChangesResult[]>;
4
+ export declare function flushSyncGeneratorChangesToDisk(generators: string[]): Promise<void>;
5
+ export declare function collectAndScheduleSyncGenerators(projectGraph: ProjectGraph): void;
6
+ export declare function getCachedRegisteredSyncGenerators(): Promise<string[]>;