nx 23.2.1 → 23.3.0-beta.1

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 (149) hide show
  1. package/dist/src/command-line/format/format.js +2 -18
  2. package/dist/src/command-line/graph/graph.js +42 -3
  3. package/dist/src/command-line/init/implementation/format.js +2 -3
  4. package/dist/src/command-line/migrate/agentic/definitions.js +75 -19
  5. package/dist/src/command-line/migrate/agentic/format-command.d.ts +14 -0
  6. package/dist/src/command-line/migrate/agentic/format-command.js +44 -0
  7. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +3 -3
  8. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +3 -3
  9. package/dist/src/command-line/migrate/agentic/handoff.d.ts +27 -17
  10. package/dist/src/command-line/migrate/agentic/handoff.js +107 -24
  11. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +21 -0
  12. package/dist/src/command-line/migrate/agentic/instruction-files.js +36 -0
  13. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +16 -0
  14. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +70 -0
  15. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +4 -3
  16. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +25 -1
  17. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +57 -34
  18. package/dist/src/command-line/migrate/agentic/run-step.js +28 -4
  19. package/dist/src/command-line/migrate/agentic/runner.d.ts +17 -8
  20. package/dist/src/command-line/migrate/agentic/runner.js +110 -55
  21. package/dist/src/command-line/migrate/agentic/types.d.ts +23 -8
  22. package/dist/src/command-line/migrate/agentic/types.js +10 -7
  23. package/dist/src/command-line/migrate/migrate-commits.d.ts +1 -0
  24. package/dist/src/command-line/migrate/migrate-commits.js +9 -0
  25. package/dist/src/command-line/migrate/migrate-output.d.ts +3 -7
  26. package/dist/src/command-line/migrate/migrate-output.js +3 -7
  27. package/dist/src/command-line/migrate/migrate.js +21 -8
  28. package/dist/src/command-line/migrate/run/agent-output.d.ts +10 -0
  29. package/dist/src/command-line/migrate/run/agent-output.js +16 -2
  30. package/dist/src/command-line/migrate/run/agent-work-payload.d.ts +37 -0
  31. package/dist/src/command-line/migrate/run/agent-work-payload.js +142 -0
  32. package/dist/src/command-line/migrate/run/atomic-write.d.ts +8 -0
  33. package/dist/src/command-line/migrate/run/atomic-write.js +17 -0
  34. package/dist/src/command-line/migrate/run/index.d.ts +1 -1
  35. package/dist/src/command-line/migrate/run/issues.d.ts +106 -0
  36. package/dist/src/command-line/migrate/run/issues.js +980 -0
  37. package/dist/src/command-line/migrate/run/orchestrator.d.ts +1 -0
  38. package/dist/src/command-line/migrate/run/orchestrator.js +662 -105
  39. package/dist/src/command-line/migrate/run/run-state.d.ts +43 -8
  40. package/dist/src/command-line/migrate/run/run-state.js +184 -20
  41. package/dist/src/command-line/migrate/run/runbook.d.ts +17 -0
  42. package/dist/src/command-line/migrate/run/runbook.js +97 -0
  43. package/dist/src/command-line/migrate/run/state-lock.d.ts +2 -2
  44. package/dist/src/command-line/migrate/run/state-lock.js +2 -2
  45. package/dist/src/command-line/migrate/run/state-machine.d.ts +5 -1
  46. package/dist/src/command-line/migrate/run/state-machine.js +27 -1
  47. package/dist/src/command-line/migrate/run/worker.js +206 -56
  48. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +5 -1
  49. package/dist/src/command-line/release/publish.js +11 -4
  50. package/dist/src/command-line/release/utils/remote-release-clients/github.js +3 -3
  51. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +3 -3
  52. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +2 -0
  53. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +35 -0
  54. package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  55. package/dist/src/command-line/yargs-utils/shared-options.js +22 -4
  56. package/dist/src/config/workspace-json-project-json.d.ts +2 -0
  57. package/dist/src/core/graph/main.js +1 -1
  58. package/dist/src/daemon/client/client.d.ts +4 -2
  59. package/dist/src/daemon/client/client.js +20 -11
  60. package/dist/src/daemon/message-types/run-tasks-execution-hooks.d.ts +3 -2
  61. package/dist/src/daemon/server/handle-hash-tasks.d.ts +8 -2
  62. package/dist/src/daemon/server/handle-hash-tasks.js +16 -3
  63. package/dist/src/daemon/server/handle-outputs-changes.d.ts +2 -2
  64. package/dist/src/daemon/server/handle-outputs-changes.js +21 -6
  65. package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +3 -2
  66. package/dist/src/daemon/server/outputs-tracking.d.ts +6 -0
  67. package/dist/src/daemon/server/outputs-tracking.js +18 -0
  68. package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +22 -7
  69. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +99 -69
  70. package/dist/src/daemon/server/restart-checks.d.ts +22 -0
  71. package/dist/src/daemon/server/restart-checks.js +77 -0
  72. package/dist/src/daemon/server/server.js +28 -18
  73. package/dist/src/daemon/server/shutdown-utils.d.ts +0 -5
  74. package/dist/src/daemon/server/shutdown-utils.js +3 -26
  75. package/dist/src/hasher/hash-task.js +20 -16
  76. package/dist/src/hasher/native-task-hasher-impl.d.ts +8 -0
  77. package/dist/src/hasher/native-task-hasher-impl.js +46 -3
  78. package/dist/src/hasher/task-hasher.d.ts +9 -0
  79. package/dist/src/hasher/task-hasher.js +14 -0
  80. package/dist/src/native/index.d.ts +202 -21
  81. package/dist/src/native/index.js +3 -3
  82. package/dist/src/native/native-bindings.js +3 -1
  83. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  84. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  85. package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -1
  86. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +2 -0
  87. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +22 -0
  88. package/dist/src/plugins/js/utils/register.js +2 -1
  89. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +2 -1
  90. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +3 -2
  91. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +5 -1
  92. package/dist/src/project-graph/plugins/loaded-nx-plugin.d.ts +3 -2
  93. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +5 -1
  94. package/dist/src/project-graph/plugins/task-results-stub.d.ts +50 -0
  95. package/dist/src/project-graph/plugins/task-results-stub.js +111 -0
  96. package/dist/src/project-graph/plugins/tasks-execution-hooks.d.ts +3 -2
  97. package/dist/src/project-graph/plugins/tasks-execution-hooks.js +2 -1
  98. package/dist/src/project-graph/project-graph.js +2 -0
  99. package/dist/src/tasks-runner/batch/run-batch.js +15 -0
  100. package/dist/src/tasks-runner/cache.d.ts +35 -0
  101. package/dist/src/tasks-runner/cache.js +40 -0
  102. package/dist/src/tasks-runner/create-task-graph.js +1 -0
  103. package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
  104. package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
  105. package/dist/src/tasks-runner/forked-process-task-runner.js +8 -7
  106. package/dist/src/tasks-runner/init-tasks-runner.js +5 -1
  107. package/dist/src/tasks-runner/is-tui-enabled.js +4 -3
  108. package/dist/src/tasks-runner/life-cycle.d.ts +7 -0
  109. package/dist/src/tasks-runner/life-cycle.js +7 -0
  110. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.d.ts +35 -0
  111. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +146 -0
  112. package/dist/src/tasks-runner/prune-task-graph.d.ts +17 -0
  113. package/dist/src/tasks-runner/prune-task-graph.js +45 -0
  114. package/dist/src/tasks-runner/run-command.js +14 -3
  115. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +93 -19
  116. package/dist/src/tasks-runner/running-tasks/batch-process.js +184 -88
  117. package/dist/src/tasks-runner/task-orchestrator.d.ts +64 -2
  118. package/dist/src/tasks-runner/task-orchestrator.js +232 -46
  119. package/dist/src/tasks-runner/terminal-output-path.d.ts +11 -0
  120. package/dist/src/tasks-runner/terminal-output-path.js +18 -0
  121. package/dist/src/tasks-runner/utils.js +5 -2
  122. package/dist/src/utils/ab-testing.d.ts +3 -0
  123. package/dist/src/utils/ab-testing.js +11 -3
  124. package/dist/src/utils/chunkify.d.ts +1 -7
  125. package/dist/src/utils/chunkify.js +2 -8
  126. package/dist/src/utils/command-line-utils.d.ts +19 -0
  127. package/dist/src/utils/command-line-utils.js +10 -3
  128. package/dist/src/utils/formatters/index.d.ts +6 -0
  129. package/dist/src/utils/formatters/index.js +5 -0
  130. package/dist/src/utils/formatters/prettier.d.ts +0 -8
  131. package/dist/src/utils/formatters/prettier.js +4 -26
  132. package/dist/src/utils/installed-nx-version.js +2 -48
  133. package/dist/src/utils/min-release-age/packument.js +1 -1
  134. package/dist/src/utils/output.d.ts +22 -3
  135. package/dist/src/utils/output.js +28 -5
  136. package/dist/src/utils/package-json.d.ts +25 -0
  137. package/dist/src/utils/package-json.js +41 -6
  138. package/dist/src/utils/package-manager.d.ts +6 -0
  139. package/dist/src/utils/package-manager.js +10 -0
  140. package/dist/src/utils/provenance.js +20 -4
  141. package/dist/src/utils/workspace-context.d.ts +47 -3
  142. package/dist/src/utils/workspace-context.js +162 -10
  143. package/package.json +12 -12
  144. package/schemas/nx-schema.json +4 -0
  145. package/schemas/project-schema.json +4 -0
  146. package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +0 -9
  147. package/dist/src/daemon/server/file-watching/route-workspace-changes.js +0 -76
  148. package/dist/src/daemon/server/watcher.d.ts +0 -18
  149. package/dist/src/daemon/server/watcher.js +0 -126
@@ -3,7 +3,8 @@ import { FileData, ProjectGraph } from '../../config/project-graph';
3
3
  import { Task, TaskGraph } from '../../config/task-graph';
4
4
  import { Hash } from '../../hasher/task-hasher';
5
5
  import { NxWorkspaceFiles, TaskRun, TaskTarget } from '../../native';
6
- import { PostTasksExecutionContext, PreTasksExecutionContext } from '../../project-graph/plugins/public-api';
6
+ import { PreTasksExecutionContext } from '../../project-graph/plugins/public-api';
7
+ import type { MaybeStubbedPostTasksExecutionContext } from '../../project-graph/plugins/task-results-stub';
7
8
  import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration/source-maps';
8
9
  import type { FlushSyncGeneratorChangesResult, SyncGeneratorRunResult } from '../../utils/sync-generators';
9
10
  import { type ConfigureAiAgentsStatusResponse } from '../message-types/configure-ai-agents';
@@ -57,6 +58,7 @@ export declare class DaemonClient {
57
58
  }>;
58
59
  getAllFileData(): Promise<FileData[]>;
59
60
  hashTasks(runnerOptions: any, tasks: Task[], taskGraph: TaskGraph, perTaskEnvs: Record<string, NodeJS.ProcessEnv>, cwd: string, collectInputs?: boolean): Promise<Hash[]>;
61
+ hashTasksUpfront(runnerOptions: any, tasks: Task[], taskGraph: TaskGraph, perTaskEnvs: Record<string, NodeJS.ProcessEnv>, cwd: string, collectInputs?: boolean): Promise<Record<string, Hash>>;
60
62
  registerFileWatcher(config: {
61
63
  watchProjects: string[] | 'all';
62
64
  includeGlobalWorkspaceFiles?: boolean;
@@ -100,7 +102,7 @@ export declare class DaemonClient {
100
102
  }>;
101
103
  updateWorkspaceContext(createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): Promise<void>;
102
104
  runPreTasksExecution(context: PreTasksExecutionContext): Promise<NodeJS.ProcessEnv[]>;
103
- runPostTasksExecution(context: PostTasksExecutionContext): Promise<void>;
105
+ runPostTasksExecution(context: MaybeStubbedPostTasksExecutionContext): Promise<void>;
104
106
  getNxConsoleStatus(): Promise<NxConsoleStatusResponse>;
105
107
  setNxConsolePreferenceAndInstall(preference: boolean): Promise<SetNxConsolePreferenceAndInstallResponse>;
106
108
  getConfigureAiAgentsStatus(): Promise<ConfigureAiAgentsStatusResponse>;
@@ -11,6 +11,7 @@ const path_1 = require("path");
11
11
  const perf_hooks_1 = require("perf_hooks");
12
12
  const configuration_1 = require("../../config/configuration");
13
13
  const nx_json_1 = require("../../config/nx-json");
14
+ const prune_task_graph_1 = require("../../tasks-runner/prune-task-graph");
14
15
  const native_1 = require("../../native");
15
16
  const error_types_1 = require("../../project-graph/error-types");
16
17
  const typescript_1 = require("../../plugins/js/utils/typescript");
@@ -74,6 +75,14 @@ exports.WatcherFailedError = WatcherFailedError;
74
75
  * re-dialing once this many land back to back without a message in between.
75
76
  */
76
77
  const MAX_CONSECUTIVE_FRAMING_FAILURES = 3;
78
+ // Task results get written back onto these task objects as the run
79
+ // progresses — hash/hashDetails/timestamps by hashing and the orchestrator,
80
+ // terminalOutput by the Nx Cloud life cycle (untyped) — so a later message
81
+ // would otherwise re-ship every earlier result.
82
+ function withoutTaskResults(tasks, taskGraph) {
83
+ const pruned = (0, prune_task_graph_1.pruneTaskGraph)(taskGraph);
84
+ return { tasks: tasks.map((t) => pruned.tasks[t.id]), taskGraph: pruned };
85
+ }
77
86
  class DaemonClient {
78
87
  constructor() {
79
88
  // Tracks the spinner owned by the in-flight request so streamed
@@ -201,21 +210,21 @@ class DaemonClient {
201
210
  return await this.sendToDaemonViaQueue({ type: 'REQUEST_FILE_DATA' });
202
211
  }
203
212
  hashTasks(runnerOptions, tasks, taskGraph, perTaskEnvs, cwd, collectInputs) {
204
- // Task results get written back onto these task objects as the run
205
- // progresses — hash/hashDetails/timestamps by hashing and the
206
- // orchestrator, terminalOutput by the Nx Cloud life cycle (untyped) —
207
- // so a later message would otherwise re-ship every earlier result.
208
- const trimmedTasks = {};
209
- for (const [id, t] of Object.entries(taskGraph.tasks)) {
210
- const { hash, hashDetails, startTime, endTime, terminalOutput, ...strippedTask } = t;
211
- trimmedTasks[id] = strippedTask;
212
- }
213
213
  return this.sendToDaemonViaQueue({
214
214
  type: 'HASH_TASKS',
215
215
  runnerOptions,
216
216
  perTaskEnvs,
217
- tasks: tasks.map((t) => trimmedTasks[t.id]),
218
- taskGraph: { ...taskGraph, tasks: trimmedTasks },
217
+ ...withoutTaskResults(tasks, taskGraph),
218
+ cwd,
219
+ collectInputs,
220
+ });
221
+ }
222
+ hashTasksUpfront(runnerOptions, tasks, taskGraph, perTaskEnvs, cwd, collectInputs) {
223
+ return this.sendToDaemonViaQueue({
224
+ type: 'HASH_TASKS_UPFRONT',
225
+ runnerOptions,
226
+ perTaskEnvs,
227
+ ...withoutTaskResults(tasks, taskGraph),
219
228
  cwd,
220
229
  collectInputs,
221
230
  });
@@ -1,4 +1,5 @@
1
- import type { PostTasksExecutionContext, PreTasksExecutionContext } from '../../project-graph/plugins';
1
+ import type { PreTasksExecutionContext } from '../../project-graph/plugins';
2
+ import type { MaybeStubbedPostTasksExecutionContext } from '../../project-graph/plugins/task-results-stub';
2
3
  export declare const PRE_TASKS_EXECUTION: 'PRE_TASKS_EXECUTION';
3
4
  export declare const POST_TASKS_EXECUTION: 'POST_TASKS_EXECUTION';
4
5
  export type HandlePreTasksExecutionMessage = {
@@ -7,7 +8,7 @@ export type HandlePreTasksExecutionMessage = {
7
8
  };
8
9
  export type HandlePostTasksExecutionMessage = {
9
10
  type: typeof POST_TASKS_EXECUTION;
10
- context: PostTasksExecutionContext;
11
+ context: MaybeStubbedPostTasksExecutionContext;
11
12
  };
12
13
  export declare function isHandlePreTasksExecutionMessage(message: unknown): message is HandlePreTasksExecutionMessage;
13
14
  export declare function isHandlePostTasksExecutionMessage(message: unknown): message is HandlePostTasksExecutionMessage;
@@ -1,12 +1,18 @@
1
1
  import { Task, TaskGraph } from '../../config/task-graph';
2
- export declare function handleHashTasks(payload: {
2
+ interface HashTasksPayload {
3
3
  runnerOptions: any;
4
4
  tasks: Task[];
5
5
  taskGraph: TaskGraph;
6
6
  perTaskEnvs: Record<string, NodeJS.ProcessEnv>;
7
7
  cwd: string;
8
8
  collectInputs?: boolean;
9
- }): Promise<{
9
+ }
10
+ export declare function handleHashTasks(payload: HashTasksPayload): Promise<{
10
11
  response: import("../../hasher/task-hasher").Hash[];
11
12
  description: string;
12
13
  }>;
14
+ export declare function handleHashTasksUpfront(payload: HashTasksPayload): Promise<{
15
+ response: Record<string, import("../../hasher/task-hasher").Hash>;
16
+ description: string;
17
+ }>;
18
+ export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleHashTasks = handleHashTasks;
4
+ exports.handleHashTasksUpfront = handleHashTasksUpfront;
4
5
  const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
5
6
  const task_hasher_1 = require("../../hasher/task-hasher");
6
7
  const configuration_1 = require("../../config/configuration");
@@ -10,7 +11,7 @@ const configuration_1 = require("../../config/configuration");
10
11
  */
11
12
  let storedProjectGraph = null;
12
13
  let storedHasher = null;
13
- async function handleHashTasks(payload) {
14
+ async function getHasher(runnerOptions) {
14
15
  const { error, projectGraph, rustReferences } = await (0, project_graph_incremental_recomputation_1.getCachedSerializedProjectGraphPromise)();
15
16
  if (error) {
16
17
  throw error;
@@ -18,11 +19,23 @@ async function handleHashTasks(payload) {
18
19
  const nxJson = (0, configuration_1.readNxJson)();
19
20
  if (projectGraph !== storedProjectGraph) {
20
21
  storedProjectGraph = projectGraph;
21
- storedHasher = new task_hasher_1.InProcessTaskHasher(projectGraph, nxJson, rustReferences, payload.runnerOptions);
22
+ storedHasher = new task_hasher_1.InProcessTaskHasher(projectGraph, nxJson, rustReferences, runnerOptions);
22
23
  }
23
- const response = await storedHasher.hashTasks(payload.tasks, payload.taskGraph, payload.perTaskEnvs, payload.cwd, payload.collectInputs);
24
+ return storedHasher;
25
+ }
26
+ async function handleHashTasks(payload) {
27
+ const hasher = await getHasher(payload.runnerOptions);
28
+ const response = await hasher.hashTasks(payload.tasks, payload.taskGraph, payload.perTaskEnvs, payload.cwd, payload.collectInputs);
24
29
  return {
25
30
  response,
26
31
  description: 'handleHashTasks',
27
32
  };
28
33
  }
34
+ async function handleHashTasksUpfront(payload) {
35
+ const hasher = await getHasher(payload.runnerOptions);
36
+ const response = await hasher.hashTasksUpfront(payload.tasks, payload.taskGraph, payload.perTaskEnvs, payload.cwd, payload.collectInputs);
37
+ return {
38
+ response,
39
+ description: 'handleHashTasksUpfront',
40
+ };
41
+ }
@@ -1,4 +1,4 @@
1
- import type { FileWatcherCallback } from './watcher';
1
+ import { type WatchEventsListener } from '../../utils/workspace-context';
2
2
  /**
3
3
  * The error a native outputs watcher failure delivered, if one has. Such an
4
4
  * error is terminal (the native watch loop exits after delivering it), so the
@@ -7,4 +7,4 @@ import type { FileWatcherCallback } from './watcher';
7
7
  * a workspace watcher error.
8
8
  */
9
9
  export declare function getOutputsWatcherTerminalError(): Error | undefined;
10
- export declare const handleOutputsChanges: FileWatcherCallback;
10
+ export declare const handleOutputsChanges: WatchEventsListener;
@@ -6,6 +6,8 @@ const logger_1 = require("../logger");
6
6
  const dotenv_graph_changes_1 = require("./dotenv-graph-changes");
7
7
  const outputs_tracking_1 = require("./outputs-tracking");
8
8
  const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
9
+ const workspace_root_1 = require("../../utils/workspace-root");
10
+ const workspace_context_1 = require("../../utils/workspace-context");
9
11
  let outputsWatcherError;
10
12
  let outputsWatcherTerminalError;
11
13
  /**
@@ -38,6 +40,15 @@ const handleOutputsChanges = async (err, changeEvents) => {
38
40
  }
39
41
  return;
40
42
  }
43
+ if (changeEvents.some((event) => event.type === 'rescan')) {
44
+ // Dropped events cannot be classified: any recorded output hash and any
45
+ // gitignored dotenv file may have changed unseen. Start the tracker
46
+ // over and invalidate the graph rather than trust either.
47
+ logger_1.serverLogger.watcherLog('The outputs watcher reported dropped events; clearing recorded output hashes and invalidating the graph cache.');
48
+ (0, outputs_tracking_1.clearRecordedOutputsHashes)();
49
+ (0, project_graph_incremental_recomputation_1.invalidateGraphCache)();
50
+ return;
51
+ }
41
52
  // A dotenv change that a task chain loads must refresh the graph so
42
53
  // createNodes re-resolves config reading process.env. This runs above the
43
54
  // outputsWatcherError guard: the two concerns are independent, and a
@@ -47,11 +58,11 @@ const handleOutputsChanges = async (err, changeEvents) => {
47
58
  // would discard that recomputation at commit and force a second one. It is
48
59
  // queued instead of dropped: the two watchers deliver independently, so a
49
60
  // computation already in flight may have read the file before the edit,
50
- // and only the pre-serve replay can prove that. The committed file map
51
- // approximates what the watcher tracks: a file it does not know is either
52
- // gitignored (never reaches the workspace watcher, so it needs the
53
- // invalidation) or created since the last recompute (the watcher handles
54
- // it; the extra invalidation is fail-safe). Its own try/catch so a fault
61
+ // and only the pre-serve replay can prove that. The context answers from
62
+ // the files the watch keeps, so a path it does not hold is gitignored,
63
+ // already deleted, or not yet ingested, and each of those needs the
64
+ // invalidation. A missing context answers with nothing, which invalidates
65
+ // too. Its own try/catch so a fault
55
66
  // here cannot trip the outputs-tracking kill switch below, which belongs
56
67
  // to an unrelated subsystem, and it fails safe by invalidating: a stale
57
68
  // graph on a dotenv edit is the bug this prevents.
@@ -59,7 +70,11 @@ const handleOutputsChanges = async (err, changeEvents) => {
59
70
  const { invalidating, unclassified } = (0, dotenv_graph_changes_1.classifyDotEnvChanges)(changeEvents, project_graph_incremental_recomputation_1.currentProjectGraph);
60
71
  const generation = (0, project_graph_incremental_recomputation_1.getRecomputationGeneration)();
61
72
  (0, dotenv_graph_changes_1.queuePendingDotEnvEvents)(unclassified.map((event) => event.path), generation);
62
- const knownInvalidating = invalidating.filter((path) => (0, project_graph_incremental_recomputation_1.isKnownWorkspaceFile)(path));
73
+ // Skips the napi call, which takes the files mutex and can wait out a
74
+ // re-walk, for the common batch that classifies nothing.
75
+ const knownInvalidating = invalidating.length
76
+ ? (0, workspace_context_1.trackedFilesInContext)(workspace_root_1.workspaceRoot, invalidating)
77
+ : [];
63
78
  (0, dotenv_graph_changes_1.queuePendingDotEnvEvents)(knownInvalidating, generation);
64
79
  if (knownInvalidating.length < invalidating.length) {
65
80
  (0, project_graph_incremental_recomputation_1.invalidateGraphCache)();
@@ -1,4 +1,5 @@
1
- import type { PostTasksExecutionContext, PreTasksExecutionContext } from '../../project-graph/plugins/public-api';
1
+ import type { PreTasksExecutionContext } from '../../project-graph/plugins/public-api';
2
+ import type { MaybeStubbedPostTasksExecutionContext } from '../../project-graph/plugins/task-results-stub';
2
3
  export declare function handleRunPreTasksExecution(context: PreTasksExecutionContext): Promise<{
3
4
  response: NodeJS.ProcessEnv[];
4
5
  description: string;
@@ -8,7 +9,7 @@ export declare function handleRunPreTasksExecution(context: PreTasksExecutionCon
8
9
  error: any;
9
10
  description: string;
10
11
  }>;
11
- export declare function handleRunPostTasksExecution(context: PostTasksExecutionContext): Promise<{
12
+ export declare function handleRunPostTasksExecution(context: MaybeStubbedPostTasksExecutionContext): Promise<{
12
13
  error?: undefined;
13
14
  response: string;
14
15
  description: string;
@@ -20,4 +20,10 @@ export declare function recordOutputsHashBatch(entries: {
20
20
  outputs: string[];
21
21
  hash: string;
22
22
  }[]): void;
23
+ /**
24
+ * One-shot reset for a watcher rescan: recorded hashes may describe outputs
25
+ * whose change events were dropped, so none can be trusted. Unlike
26
+ * `disableOutputsTracking` the tracker keeps running; it just starts over.
27
+ */
28
+ export declare function clearRecordedOutputsHashes(): void;
23
29
  export declare function disableOutputsTracking(): void;
@@ -5,6 +5,7 @@ exports._outputsHashesMatch = _outputsHashesMatch;
5
5
  exports.processFileChangesInOutputs = processFileChangesInOutputs;
6
6
  exports.outputsHashesMatchBatch = outputsHashesMatchBatch;
7
7
  exports.recordOutputsHashBatch = recordOutputsHashBatch;
8
+ exports.clearRecordedOutputsHashes = clearRecordedOutputsHashes;
8
9
  exports.disableOutputsTracking = disableOutputsTracking;
9
10
  const path_1 = require("path");
10
11
  const native_1 = require("../../native");
@@ -115,6 +116,23 @@ function recordOutputsHashBatch(entries) {
115
116
  _recordOutputsHash(expanded, entries[i].hash);
116
117
  }
117
118
  }
119
+ /**
120
+ * One-shot reset for a watcher rescan: recorded hashes may describe outputs
121
+ * whose change events were dropped, so none can be trusted. Unlike
122
+ * `disableOutputsTracking` the tracker keeps running; it just starts over.
123
+ */
124
+ function clearRecordedOutputsHashes() {
125
+ for (const store of [
126
+ dirsContainingOutputs,
127
+ recordedHashes,
128
+ timestamps,
129
+ numberOfExpandedOutputs,
130
+ ]) {
131
+ for (const key of Object.keys(store)) {
132
+ delete store[key];
133
+ }
134
+ }
135
+ }
118
136
  function disableOutputsTracking() {
119
137
  disabled = true;
120
138
  }
@@ -1,6 +1,7 @@
1
1
  import { Socket } from 'net';
2
2
  import { FileMap, ProjectGraph } from '../../config/project-graph';
3
3
  import { NxWorkspaceFilesExternals } from '../../native';
4
+ import type { ChangeBatch } from '../../native';
4
5
  import { FileMapCache } from '../../project-graph/nx-deps-cache';
5
6
  import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration/source-maps';
6
7
  interface SerializedProjectGraph {
@@ -20,7 +21,28 @@ export declare let currentProjectFileMapCache: FileMapCache | undefined;
20
21
  export declare let currentProjectGraph: ProjectGraph | undefined;
21
22
  export declare let currentSourceMaps: ConfigurationSourceMaps | undefined;
22
23
  export declare function getCachedSerializedProjectGraphPromise(socket?: Socket): Promise<SerializedProjectGraph>;
24
+ /**
25
+ * Takes in changes the workspace context handed out: restarts the daemon if
26
+ * an ignore file changed, otherwise schedules the recomputation.
27
+ */
28
+ export declare function routeAppliedChanges(batch: ChangeBatch): void;
29
+ /**
30
+ * Applies everything the workspace watcher has seen and routes what changed.
31
+ * Call before serving a cached project graph, so a change the watcher already
32
+ * saw is never missed.
33
+ */
34
+ export declare function flushPendingWorkspaceChanges(): Promise<void>;
35
+ /**
36
+ * Applies changes a caller learned of on its own to the workspace context,
37
+ * then schedules the recomputation as for a batch the context applied.
38
+ *
39
+ * The caller is a sync generator, whose writes the watch would report anyway;
40
+ * this makes them visible before the generator returns rather than by the next
41
+ * settle. Whether that guarantee is still needed is NXC-4996.
42
+ */
23
43
  export declare function scheduleProjectGraphRecomputation(createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): void;
44
+ /** Computes the first project graph, unless one is already on its way. */
45
+ export declare function scheduleInitialProjectGraphComputation(): void;
24
46
  export declare function registerProjectGraphRecomputationListener(listener: (projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps, error: Error | null) => void): void;
25
47
  /**
26
48
  * Discards the cached graph when a graph input outside the file watcher's view
@@ -37,11 +59,4 @@ export declare function invalidateGraphCache(): void;
37
59
  * event arrived.
38
60
  */
39
61
  export declare function getRecomputationGeneration(): number;
40
- /**
41
- * Whether the ignore-filtered workspace file map knows `path`. The workspace
42
- * watcher applies the same ignore rules, so a change to a known file also
43
- * reaches scheduleProjectGraphRecomputation; an unknown file is either
44
- * ignored, or created since the last recompute committed.
45
- */
46
- export declare function isKnownWorkspaceFile(path: string): boolean;
47
62
  export {};
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.currentSourceMaps = exports.currentProjectGraph = exports.currentProjectFileMapCache = exports.fileMapWithFiles = void 0;
4
4
  exports.getCachedSerializedProjectGraphPromise = getCachedSerializedProjectGraphPromise;
5
+ exports.routeAppliedChanges = routeAppliedChanges;
6
+ exports.flushPendingWorkspaceChanges = flushPendingWorkspaceChanges;
5
7
  exports.scheduleProjectGraphRecomputation = scheduleProjectGraphRecomputation;
8
+ exports.scheduleInitialProjectGraphComputation = scheduleInitialProjectGraphComputation;
6
9
  exports.registerProjectGraphRecomputationListener = registerProjectGraphRecomputationListener;
7
10
  exports.invalidateGraphCache = invalidateGraphCache;
8
11
  exports.getRecomputationGeneration = getRecomputationGeneration;
9
- exports.isKnownWorkspaceFile = isKnownWorkspaceFile;
10
12
  const perf_hooks_1 = require("perf_hooks");
11
13
  const nx_json_1 = require("../../config/nx-json");
12
14
  const file_hasher_1 = require("../../hasher/file-hasher");
@@ -25,7 +27,7 @@ const dotenv_graph_changes_1 = require("./dotenv-graph-changes");
25
27
  const file_change_events_1 = require("./file-watching/file-change-events");
26
28
  const file_watcher_sockets_1 = require("./file-watching/file-watcher-sockets");
27
29
  const project_graph_listener_sockets_1 = require("./project-graph-listener-sockets");
28
- const watcher_1 = require("./watcher");
30
+ const restart_checks_1 = require("./restart-checks");
29
31
  const logger_1 = require("../logger");
30
32
  let cachedSerializedProjectGraphPromise;
31
33
  // Maps file path to a version counter that increments on each modification.
@@ -136,7 +138,7 @@ async function getCachedSerializedProjectGraphPromise(socket) {
136
138
  // that already arrived in the watcher's accumulator but hasn't
137
139
  // flushed past IDLE_WINDOW yet would be invisible to the staleness
138
140
  // check below — the daemon would return a stale graph.
139
- await (0, watcher_1.flushPendingWorkspaceChanges)();
141
+ await flushPendingWorkspaceChanges();
140
142
  await resetInternalStateIfNxDepsMissing();
141
143
  // Yield one macrotask boundary so any TSFN-queued watcher callbacks
142
144
  // run before we read collected*. Without this, an event that left
@@ -222,38 +224,96 @@ async function getCachedSerializedProjectGraphPromise(socket) {
222
224
  }
223
225
  }
224
226
  }
227
+ const SUMMARY_CAP = 10;
228
+ function summarize(files) {
229
+ if (files.length === 0)
230
+ return '(none)';
231
+ const listed = files.slice(0, SUMMARY_CAP).map((f) => ` - ${f}`);
232
+ if (files.length > SUMMARY_CAP) {
233
+ listed.push(` ... and ${files.length - SUMMARY_CAP} more`);
234
+ }
235
+ return listed.join('\n');
236
+ }
237
+ /**
238
+ * Takes in changes the workspace context handed out: restarts the daemon if
239
+ * an ignore file changed, otherwise schedules the recomputation.
240
+ */
241
+ function routeAppliedChanges(batch) {
242
+ if (!(0, workspace_context_1.isEmptyBatch)(batch)) {
243
+ if ((0, restart_checks_1.restartDaemonIfIgnoreFilesChanged)((0, restart_checks_1.changedPaths)(batch))) {
244
+ return;
245
+ }
246
+ logger_1.serverLogger.watcherLog(`File changes detected (seq ${batch.seq}):\n` +
247
+ `Created:\n${summarize((0, restart_checks_1.fileNames)(batch.createdFiles))}\n` +
248
+ `Updated:\n${summarize((0, restart_checks_1.fileNames)(batch.updatedFiles))}\n` +
249
+ `Deleted:\n${summarize(batch.deletedFiles)}`);
250
+ }
251
+ scheduleAppliedChanges(batch);
252
+ }
253
+ /**
254
+ * Applies everything the workspace watcher has seen and routes what changed.
255
+ * Call before serving a cached project graph, so a change the watcher already
256
+ * saw is never missed.
257
+ */
258
+ async function flushPendingWorkspaceChanges() {
259
+ if (!(0, workspace_context_1.isWatchingWorkspaceContext)())
260
+ return;
261
+ const batch = (0, workspace_context_1.settleWorkspaceContext)(workspace_root_1.workspaceRoot);
262
+ // An empty settle must not reach the routing: it would schedule the first
263
+ // graph computation here rather than where the request handler reports it.
264
+ if ((0, workspace_context_1.isEmptyBatch)(batch)) {
265
+ return;
266
+ }
267
+ routeAppliedChanges(batch);
268
+ }
269
+ /**
270
+ * Applies changes a caller learned of on its own to the workspace context,
271
+ * then schedules the recomputation as for a batch the context applied.
272
+ *
273
+ * The caller is a sync generator, whose writes the watch would report anyway;
274
+ * this makes them visible before the generator returns rather than by the next
275
+ * settle. Whether that guarantee is still needed is NXC-4996.
276
+ */
225
277
  function scheduleProjectGraphRecomputation(createdFiles, updatedFiles, deletedFiles) {
278
+ if (!createdFiles.length && !updatedFiles.length && !deletedFiles.length) {
279
+ return;
280
+ }
281
+ // Hashed once here, not inside the recompute, so a stale retry does not see
282
+ // "no change" after the first pass already updated the context.
283
+ perf_hooks_1.performance.mark('hash-reported-changes-start');
284
+ const batch = (0, workspace_context_1.updateFilesInContext)(workspace_root_1.workspaceRoot, [...createdFiles, ...updatedFiles], deletedFiles);
285
+ perf_hooks_1.performance.mark('hash-reported-changes-end');
286
+ perf_hooks_1.performance.measure('hash reported file changes', 'hash-reported-changes-start', 'hash-reported-changes-end');
287
+ // A watching context hands every applied change out once, from one place.
288
+ routeAppliedChanges((0, workspace_context_1.isWatchingWorkspaceContext)()
289
+ ? (0, workspace_context_1.takeAppliedWorkspaceChanges)(workspace_root_1.workspaceRoot)
290
+ : batch);
291
+ }
292
+ /**
293
+ * Schedules a recomputation for changes the workspace context has applied:
294
+ * no-op rewrites are already dropped, deleted directories expanded, and every
295
+ * created or updated file carries its hash.
296
+ */
297
+ function scheduleAppliedChanges(batch) {
226
298
  ++fileChangeCounter;
227
- // Hash the changed files up front and drop no-op rewrites before they can
228
- // trigger an expensive recompute. Restoring a cached task output, a
229
- // `git checkout` back to the same content, or a formatter that changes
230
- // nothing all rewrite a file (new inode) the watcher reports as changed
231
- // even though the bytes are identical. updateFilesInContext updates the
232
- // workspace context and returns only the files whose content actually
233
- // changed. Hashing here — once per watcher batch — rather than inside the
234
- // recompute keeps it off the stale-retry path, which would otherwise see
235
- // "no change" after the first pass already updated the context hashes.
236
- perf_hooks_1.performance.mark('hash-watched-changes-start');
237
- const changedFileHashes = createdFiles.length > 0 ||
238
- updatedFiles.length > 0 ||
239
- deletedFiles.length > 0
240
- ? ((0, workspace_context_1.updateFilesInContext)(workspace_root_1.workspaceRoot, [...createdFiles, ...updatedFiles], deletedFiles) ?? {})
241
- : {};
242
- perf_hooks_1.performance.mark('hash-watched-changes-end');
243
- perf_hooks_1.performance.measure('hash changed files from watcher', 'hash-watched-changes-start', 'hash-watched-changes-end');
244
- for (const [f, hash] of Object.entries(changedFileHashes)) {
245
- collectedDeletedFiles.delete(f);
246
- collectedUpdatedFiles.set(f, { version: fileChangeCounter, hash });
299
+ const { createdFiles, updatedFiles, deletedFiles } = batch;
300
+ for (const { file, hash } of [...createdFiles, ...updatedFiles]) {
301
+ collectedDeletedFiles.delete(file);
302
+ collectedUpdatedFiles.set(file, { version: fileChangeCounter, hash });
247
303
  }
248
- for (let f of deletedFiles) {
249
- collectedUpdatedFiles.delete(f);
250
- collectedDeletedFiles.set(f, fileChangeCounter);
304
+ for (const file of deletedFiles) {
305
+ collectedUpdatedFiles.delete(file);
306
+ collectedDeletedFiles.set(file, fileChangeCounter);
251
307
  }
252
- // The native watcher already coalesces a burst of events into one batch,
253
- // so socket + listener notifications dispatch immediately.
254
- if (Object.keys(changedFileHashes).length > 0 || deletedFiles.length > 0) {
255
- (0, file_change_events_1.notifyFileChangeListeners)({ createdFiles, updatedFiles, deletedFiles });
256
- (0, file_watcher_sockets_1.notifyFileWatcherSockets)(createdFiles, updatedFiles, deletedFiles);
308
+ if (!(0, workspace_context_1.isEmptyBatch)(batch)) {
309
+ const createdFileNames = (0, restart_checks_1.fileNames)(createdFiles);
310
+ const updatedFileNames = (0, restart_checks_1.fileNames)(updatedFiles);
311
+ (0, file_change_events_1.notifyFileChangeListeners)({
312
+ createdFiles: createdFileNames,
313
+ updatedFiles: updatedFileNames,
314
+ deletedFiles,
315
+ });
316
+ (0, file_watcher_sockets_1.notifyFileWatcherSockets)(createdFileNames, updatedFileNames, deletedFiles);
257
317
  // Bump generation synchronously so any in-flight compute fails its
258
318
  // next isStale() check and chains to the newer one. kickOffRecompute
259
319
  // would also bump on first resume, but only after its first await —
@@ -262,10 +322,14 @@ function scheduleProjectGraphRecomputation(createdFiles, updatedFiles, deletedFi
262
322
  kickOffRecompute();
263
323
  }
264
324
  else {
265
- // First call (initial startup) — no events but we still need a graph.
266
- if (!cachedSerializedProjectGraphPromise) {
267
- kickOffRecompute();
268
- }
325
+ // Nothing changed, but a daemon with no graph yet still needs one.
326
+ scheduleInitialProjectGraphComputation();
327
+ }
328
+ }
329
+ /** Computes the first project graph, unless one is already on its way. */
330
+ function scheduleInitialProjectGraphComputation() {
331
+ if (!cachedSerializedProjectGraphPromise) {
332
+ kickOffRecompute();
269
333
  }
270
334
  }
271
335
  function registerProjectGraphRecomputationListener(listener) {
@@ -337,36 +401,6 @@ function invalidateGraphCache() {
337
401
  function getRecomputationGeneration() {
338
402
  return recomputationGeneration;
339
403
  }
340
- // isKnownWorkspaceFile's membership set, derived lazily from the map object it
341
- // was built from; every `fileMapWithFiles` write clears it, so a replaced map
342
- // generation is not retained through the memo.
343
- let knownWorkspaceFiles;
344
- let knownWorkspaceFilesSource;
345
- /**
346
- * Whether the ignore-filtered workspace file map knows `path`. The workspace
347
- * watcher applies the same ignore rules, so a change to a known file also
348
- * reaches scheduleProjectGraphRecomputation; an unknown file is either
349
- * ignored, or created since the last recompute committed.
350
- */
351
- function isKnownWorkspaceFile(path) {
352
- if (!exports.fileMapWithFiles) {
353
- return false;
354
- }
355
- if (knownWorkspaceFilesSource !== exports.fileMapWithFiles) {
356
- const { projectFileMap, nonProjectFiles } = exports.fileMapWithFiles.fileMap;
357
- knownWorkspaceFiles = new Set();
358
- for (const { file } of nonProjectFiles) {
359
- knownWorkspaceFiles.add(file);
360
- }
361
- for (const files of Object.values(projectFileMap)) {
362
- for (const { file } of files) {
363
- knownWorkspaceFiles.add(file);
364
- }
365
- }
366
- knownWorkspaceFilesSource = exports.fileMapWithFiles;
367
- }
368
- return knownWorkspaceFiles.has(path);
369
- }
370
404
  async function processFilesAndCreateAndSerializeProjectGraph(separatedPlugins) {
371
405
  const plugins = [
372
406
  ...separatedPlugins.specifiedPlugins,
@@ -442,8 +476,6 @@ async function processFilesAndCreateAndSerializeProjectGraph(separatedPlugins) {
442
476
  // chainToLatest above without touching `fileMapWithFiles`, so they
443
477
  // can't clobber a newer compute's write.
444
478
  exports.fileMapWithFiles = fileMapUpdate.fileMap;
445
- knownWorkspaceFiles = undefined;
446
- knownWorkspaceFilesSource = undefined;
447
479
  storedWorkspaceConfigHash = fileMapUpdate.configHash;
448
480
  if (fileMapUpdate.knownExternalNodes) {
449
481
  knownExternalNodes = fileMapUpdate.knownExternalNodes;
@@ -616,8 +648,6 @@ async function resetInternalState() {
616
648
  servedGraphState = null;
617
649
  servedGraphCandidate = null;
618
650
  exports.fileMapWithFiles = undefined;
619
- knownWorkspaceFiles = undefined;
620
- knownWorkspaceFilesSource = undefined;
621
651
  exports.currentProjectFileMapCache = undefined;
622
652
  exports.currentProjectGraph = undefined;
623
653
  exports.currentSourceMaps = undefined;
@@ -0,0 +1,22 @@
1
+ import type { Server, Socket } from 'net';
2
+ import type { ChangeBatch, FileData, WatchEvent } from '../../native';
3
+ export declare function registerDaemonForRestartChecks(server: Server, sockets: Iterable<Socket>): void;
4
+ /**
5
+ * The daemon's own process file, workspace-relative. It lives under the
6
+ * hardcoded-ignored .nx/workspace-data, so the watch admits it explicitly;
7
+ * that is how a daemon learns it has been replaced.
8
+ */
9
+ export declare const relativeServerProcess: string;
10
+ /** The paths out of a list of files and their hashes. */
11
+ export declare function fileNames(files: FileData[]): string[];
12
+ export declare function changedPaths(batch: ChangeBatch): string[];
13
+ /**
14
+ * The watch's ignore rules are fixed when it starts, so an ignore-file edit
15
+ * needs a daemon restart to take effect. True when it stopped the daemon.
16
+ */
17
+ export declare function restartDaemonIfIgnoreFilesChanged(paths: string[]): boolean;
18
+ /**
19
+ * Stops this daemon when the events show another process has written the
20
+ * daemon's process file. True when it stopped the daemon.
21
+ */
22
+ export declare function stopDaemonIfReplaced(events: WatchEvent[]): boolean;