nx 24.0.0-beta.2 → 24.0.0-beta.4

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 (158) hide show
  1. package/dist/bin/post-install.js +5 -3
  2. package/dist/src/adapter/ngcli-adapter.js +1 -2
  3. package/dist/src/command-line/add/add.d.ts +2 -0
  4. package/dist/src/command-line/add/add.js +23 -5
  5. package/dist/src/command-line/affected/affected.js +2 -2
  6. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +21 -62
  7. package/dist/src/command-line/migrate/agentic/definitions.d.ts +1 -3
  8. package/dist/src/command-line/migrate/agentic/definitions.js +5 -97
  9. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +7 -41
  10. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +9 -48
  11. package/dist/src/command-line/migrate/agentic/handoff.d.ts +1 -43
  12. package/dist/src/command-line/migrate/agentic/handoff.js +3 -119
  13. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +0 -21
  14. package/dist/src/command-line/migrate/agentic/instruction-files.js +6 -27
  15. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +19 -1
  16. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +63 -36
  17. package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +1 -0
  18. package/dist/src/command-line/migrate/agentic/master/spawn-master.js +7 -5
  19. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +2 -2
  20. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +2 -2
  21. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +1 -12
  22. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +8 -17
  23. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +0 -15
  24. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +3 -100
  25. package/dist/src/command-line/migrate/agentic/select.d.ts +12 -6
  26. package/dist/src/command-line/migrate/agentic/select.js +35 -5
  27. package/dist/src/command-line/migrate/agentic/types.d.ts +9 -68
  28. package/dist/src/command-line/migrate/agentic/types.js +5 -5
  29. package/dist/src/command-line/migrate/command-object.js +3 -3
  30. package/dist/src/command-line/migrate/execute-migration.d.ts +4 -4
  31. package/dist/src/command-line/migrate/execute-migration.js +7 -5
  32. package/dist/src/command-line/migrate/migrate-analytics.d.ts +12 -1
  33. package/dist/src/command-line/migrate/migrate-analytics.js +26 -0
  34. package/dist/src/command-line/migrate/migrate-commits.d.ts +9 -10
  35. package/dist/src/command-line/migrate/migrate-commits.js +25 -18
  36. package/dist/src/command-line/migrate/migrate-output.d.ts +1 -6
  37. package/dist/src/command-line/migrate/migrate-output.js +1 -10
  38. package/dist/src/command-line/migrate/migrate.d.ts +3 -0
  39. package/dist/src/command-line/migrate/migrate.js +77 -44
  40. package/dist/src/command-line/migrate/run/agent-output.d.ts +1 -0
  41. package/dist/src/command-line/migrate/run/agent-output.js +4 -0
  42. package/dist/src/command-line/migrate/run/broker.js +1 -1
  43. package/dist/src/command-line/migrate/run/give-up.d.ts +4 -3
  44. package/dist/src/command-line/migrate/run/give-up.js +8 -5
  45. package/dist/src/command-line/migrate/run/index.d.ts +2 -1
  46. package/dist/src/command-line/migrate/run/index.js +5 -1
  47. package/dist/src/command-line/migrate/run/issues.js +7 -2
  48. package/dist/src/command-line/migrate/run/orchestrator.d.ts +40 -4
  49. package/dist/src/command-line/migrate/run/orchestrator.js +233 -92
  50. package/dist/src/command-line/migrate/run/run-state.d.ts +4 -1
  51. package/dist/src/command-line/migrate/run/run-state.js +20 -2
  52. package/dist/src/command-line/migrate/run/runbook.d.ts +1 -0
  53. package/dist/src/command-line/migrate/run/runbook.js +99 -21
  54. package/dist/src/command-line/migrate/run/state-lock.d.ts +29 -4
  55. package/dist/src/command-line/migrate/run/state-lock.js +102 -10
  56. package/dist/src/command-line/migrate/run/util.d.ts +4 -2
  57. package/dist/src/command-line/migrate/run/util.js +23 -2
  58. package/dist/src/command-line/migrate/run/worker.d.ts +1 -1
  59. package/dist/src/command-line/migrate/run/worker.js +252 -250
  60. package/dist/src/command-line/release/changelog.js +9 -6
  61. package/dist/src/command-line/release/config/config.d.ts +1 -0
  62. package/dist/src/command-line/release/config/config.js +48 -9
  63. package/dist/src/command-line/release/release.js +2 -2
  64. package/dist/src/command-line/release/utils/git.js +8 -7
  65. package/dist/src/command-line/release/utils/interpolate-release-config.d.ts +6 -0
  66. package/dist/src/command-line/release/utils/interpolate-release-config.js +39 -0
  67. package/dist/src/command-line/release/utils/release-graph.d.ts +5 -0
  68. package/dist/src/command-line/release/utils/release-graph.js +1 -0
  69. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +2 -2
  70. package/dist/src/command-line/release/utils/shared.js +10 -10
  71. package/dist/src/command-line/release/utils/version-plan-utils.d.ts +3 -12
  72. package/dist/src/command-line/release/utils/version-plan-utils.js +33 -55
  73. package/dist/src/command-line/release/version/version-actions.js +2 -1
  74. package/dist/src/command-line/release/version.js +5 -2
  75. package/dist/src/command-line/show/projects.js +5 -3
  76. package/dist/src/command-line/yargs-utils/shared-options.js +1 -1
  77. package/dist/src/config/misc-interfaces.d.ts +6 -0
  78. package/dist/src/config/nx-json.d.ts +8 -5
  79. package/dist/src/config/workspace-json-project-json.d.ts +23 -12
  80. package/dist/src/core/graph/main.js +1 -1
  81. package/dist/src/core/graph/runtime.js +1 -1
  82. package/dist/src/core/graph/styles.css +1 -1
  83. package/dist/src/core/graph/styles.js +1 -1
  84. package/dist/src/devkit-exports.d.ts +8 -0
  85. package/dist/src/devkit-exports.js +12 -1
  86. package/dist/src/devkit-internals.d.ts +2 -1
  87. package/dist/src/devkit-internals.js +7 -3
  88. package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -2
  89. package/dist/src/executors/run-commands/run-commands.impl.js +20 -10
  90. package/dist/src/executors/run-commands/running-tasks.d.ts +12 -3
  91. package/dist/src/executors/run-commands/running-tasks.js +22 -18
  92. package/dist/src/hasher/check-task-files.js +1 -4
  93. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +1 -2
  94. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +6 -11
  95. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +2 -2
  96. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.d.ts +4 -0
  97. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.js +15 -0
  98. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.md +30 -0
  99. package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +7 -6
  100. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.d.ts +3 -0
  101. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.js +130 -0
  102. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md +62 -0
  103. package/dist/src/native/index.d.ts +11 -5
  104. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  105. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  106. package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -3
  107. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +2 -2
  108. package/dist/src/plugins/js/lock-file/pruned-output.js +4 -4
  109. package/dist/src/project-graph/affected/affected-tasks.d.ts +6 -5
  110. package/dist/src/project-graph/affected/affected-tasks.js +16 -6
  111. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +49 -6
  112. package/dist/src/project-graph/utils/project-configuration/target-merging.js +1 -1
  113. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +7 -133
  114. package/dist/src/project-graph/utils/project-configuration-utils.js +2 -2
  115. package/dist/src/tasks-runner/pseudo-ipc.d.ts +1 -0
  116. package/dist/src/tasks-runner/pseudo-ipc.js +4 -0
  117. package/dist/src/tasks-runner/readiness/probes.d.ts +6 -1
  118. package/dist/src/tasks-runner/readiness/probes.js +41 -2
  119. package/dist/src/tasks-runner/readiness/ready-signal-server.d.ts +18 -0
  120. package/dist/src/tasks-runner/readiness/ready-signal-server.js +71 -0
  121. package/dist/src/tasks-runner/readiness/ready-signal.d.ts +25 -0
  122. package/dist/src/tasks-runner/readiness/ready-signal.js +70 -0
  123. package/dist/src/tasks-runner/readiness/ready-when.d.ts +35 -10
  124. package/dist/src/tasks-runner/readiness/ready-when.js +197 -42
  125. package/dist/src/tasks-runner/readiness/startup-host.d.ts +1 -0
  126. package/dist/src/tasks-runner/readiness/startup-host.js +32 -0
  127. package/dist/src/tasks-runner/task-env.js +11 -0
  128. package/dist/src/tasks-runner/task-orchestrator.d.ts +8 -0
  129. package/dist/src/tasks-runner/task-orchestrator.js +152 -42
  130. package/dist/src/tasks-runner/tokens.d.ts +54 -0
  131. package/dist/src/tasks-runner/tokens.js +161 -0
  132. package/dist/src/tasks-runner/utils.d.ts +15 -1
  133. package/dist/src/tasks-runner/utils.js +79 -33
  134. package/dist/src/ultracache/config.d.ts +3 -3
  135. package/dist/src/ultracache/config.js +4 -4
  136. package/dist/src/utils/acknowledge-build-scripts.d.ts +34 -1
  137. package/dist/src/utils/acknowledge-build-scripts.js +171 -32
  138. package/dist/src/utils/long-running-target.d.ts +1 -3
  139. package/dist/src/utils/long-running-target.js +1 -3
  140. package/migrations.json +13 -6
  141. package/package.json +11 -11
  142. package/schemas/migrations-schema.json +11 -0
  143. package/schemas/nx-schema.json +24 -13
  144. package/schemas/project-schema.json +15 -9
  145. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +0 -56
  146. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +0 -67
  147. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +0 -49
  148. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +0 -53
  149. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +0 -26
  150. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +0 -27
  151. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +0 -70
  152. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +0 -113
  153. package/dist/src/command-line/migrate/agentic/run-step.d.ts +0 -68
  154. package/dist/src/command-line/migrate/agentic/run-step.js +0 -148
  155. package/dist/src/command-line/migrate/agentic/runner.d.ts +0 -21
  156. package/dist/src/command-line/migrate/agentic/runner.js +0 -262
  157. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +0 -9
  158. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +0 -18
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadySignalServer = void 0;
4
+ const socket_utils_1 = require("../../daemon/socket-utils");
5
+ const pseudo_ipc_1 = require("../pseudo-ipc");
6
+ const ready_signal_1 = require("./ready-signal");
7
+ let id = 0;
8
+ /**
9
+ * Receives the readiness signals of the producers this process starts. It
10
+ * does not depend on the pseudo terminal, which Windows and non-TTY runs lack.
11
+ */
12
+ class ReadySignalServer {
13
+ constructor() {
14
+ this.path = (0, socket_utils_1.getForkedProcessOsSocketPath)(`${process.pid}-ready-${id++}`);
15
+ this.server = new pseudo_ipc_1.PseudoIPCServer(this.path);
16
+ this.listeners = new Map();
17
+ // A producer can signal before its probe subscribes. Only tasks given the
18
+ // socket are buffered for.
19
+ this.early = new Map();
20
+ this.issued = new Set();
21
+ }
22
+ async env(taskId) {
23
+ this.started ??= this.server.init().then(() => {
24
+ this.server.onMessageFromChildren((message) => {
25
+ if (isReadySignalMessage(message))
26
+ this.dispatch(message);
27
+ });
28
+ });
29
+ await this.started;
30
+ this.issued.add(taskId);
31
+ return {
32
+ [ready_signal_1.READY_SIGNAL_SOCKET_ENV]: this.path,
33
+ [ready_signal_1.READY_SIGNAL_TASK_ENV]: taskId,
34
+ };
35
+ }
36
+ subscribe(taskId, listener) {
37
+ this.listeners.set(taskId, listener);
38
+ for (const message of this.early.get(taskId) ?? []) {
39
+ listener(message);
40
+ }
41
+ this.early.delete(taskId);
42
+ return () => {
43
+ if (this.listeners.get(taskId) === listener) {
44
+ this.listeners.delete(taskId);
45
+ }
46
+ };
47
+ }
48
+ close() {
49
+ if (this.started) {
50
+ this.server.close();
51
+ }
52
+ }
53
+ dispatch(message) {
54
+ const listener = this.listeners.get(message.taskId);
55
+ if (listener) {
56
+ listener(message);
57
+ }
58
+ else if (this.issued.has(message.taskId)) {
59
+ const early = this.early.get(message.taskId) ?? [];
60
+ early.push(message);
61
+ this.early.set(message.taskId, early);
62
+ }
63
+ }
64
+ }
65
+ exports.ReadySignalServer = ReadySignalServer;
66
+ function isReadySignalMessage(message) {
67
+ if (typeof message !== 'object' || message === null)
68
+ return false;
69
+ const { type, taskId } = message;
70
+ return type === 'nx-ready-signal:ready' && typeof taskId === 'string';
71
+ }
@@ -0,0 +1,25 @@
1
+ export declare const READY_SIGNAL_SOCKET_ENV = "NX_READY_SIGNAL_SOCKET";
2
+ export declare const READY_SIGNAL_TASK_ENV = "NX_READY_SIGNAL_TASK";
3
+ export declare const READY_URL_ENV = "NX_READY_URL";
4
+ export type ReadySignalMessage = {
5
+ type: 'nx-ready-signal:ready';
6
+ taskId: string;
7
+ url?: string;
8
+ };
9
+ /**
10
+ * Tells Nx that the task running this process is ready, for a target whose
11
+ * readyWhen is `signal`. Only the first call counts. `url` is passed on to the
12
+ * tasks that waited, as NX_READY_URL.
13
+ */
14
+ export declare function signalTaskReady(details?: {
15
+ url?: string;
16
+ }): boolean;
17
+ /**
18
+ * `configured` moved to the address the server reported, for a task that
19
+ * waited for a signal: its protocol and port, and its host unless `configured`
20
+ * names localhost and the server listens on loopback. Keeps the path and
21
+ * query. Returns `configured` when no address was reported, and the reported
22
+ * address when `configured` is missing or not a URL.
23
+ */
24
+ export declare function getReadyUrl(configured: string): string;
25
+ export declare function getReadyUrl(configured?: string): string | undefined;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.READY_URL_ENV = exports.READY_SIGNAL_TASK_ENV = exports.READY_SIGNAL_SOCKET_ENV = void 0;
4
+ exports.signalTaskReady = signalTaskReady;
5
+ exports.getReadyUrl = getReadyUrl;
6
+ // Set on the env of a producer whose readyWhen is `signal`
7
+ exports.READY_SIGNAL_SOCKET_ENV = 'NX_READY_SIGNAL_SOCKET';
8
+ exports.READY_SIGNAL_TASK_ENV = 'NX_READY_SIGNAL_TASK';
9
+ // Set on the env of a task that waited for a producer that signalled its url
10
+ exports.READY_URL_ENV = 'NX_READY_URL';
11
+ let client;
12
+ let readySent = false;
13
+ function connect() {
14
+ const path = process.env[exports.READY_SIGNAL_SOCKET_ENV];
15
+ const taskId = process.env[exports.READY_SIGNAL_TASK_ENV];
16
+ if (!path || !taskId) {
17
+ return null;
18
+ }
19
+ // Required lazily to keep this module light for the task env code
20
+ const { PseudoIPCClient } = require('../pseudo-ipc');
21
+ // A failed connection must not crash the server it reports on, nor keep
22
+ // its process alive
23
+ client ??= new PseudoIPCClient(path)
24
+ .onMessageFromParent(taskId, () => { }, () => { }, () => { })
25
+ .unref();
26
+ return { client, taskId };
27
+ }
28
+ /**
29
+ * Tells Nx that the task running this process is ready, for a target whose
30
+ * readyWhen is `signal`. Only the first call counts. `url` is passed on to the
31
+ * tasks that waited, as NX_READY_URL.
32
+ */
33
+ function signalTaskReady(details = {}) {
34
+ const connection = connect();
35
+ if (!connection || readySent) {
36
+ return false;
37
+ }
38
+ readySent = true;
39
+ connection.client.sendMessageToParent({
40
+ type: 'nx-ready-signal:ready',
41
+ taskId: connection.taskId,
42
+ ...(details.url ? { url: details.url } : {}),
43
+ });
44
+ return true;
45
+ }
46
+ function getReadyUrl(configured) {
47
+ const ready = process.env[exports.READY_URL_ENV];
48
+ if (!ready || !URL.canParse(ready)) {
49
+ return configured;
50
+ }
51
+ if (!configured || !URL.canParse(configured)) {
52
+ return ready;
53
+ }
54
+ const url = new URL(configured);
55
+ const reported = new URL(ready);
56
+ url.protocol = reported.protocol;
57
+ url.port = reported.port;
58
+ // A localhost name reaches either loopback address; an IP literal only its own
59
+ if (!isLocalhostName(url.hostname) || !isLoopback(reported.hostname)) {
60
+ url.hostname = reported.hostname;
61
+ }
62
+ return url.toString();
63
+ }
64
+ function isLocalhostName(hostname) {
65
+ return hostname === 'localhost' || hostname.endsWith('.localhost');
66
+ }
67
+ function isLoopback(hostname) {
68
+ const host = hostname.replace(/^\[|\]$/g, '');
69
+ return isLocalhostName(host) || host === '::1' || /^127\./.test(host);
70
+ }
@@ -1,38 +1,63 @@
1
1
  import type { ProjectGraph } from '../../config/project-graph';
2
2
  import type { Task, TaskGraph } from '../../config/task-graph';
3
3
  import type { ProjectConfiguration, ReadyWhen } from '../../config/workspace-json-project-json';
4
- export type NormalizedReadyWhen = {
4
+ export declare const DEFAULT_READY_TIMEOUT = 60000;
5
+ type ReadyWhenProbe<Deferred> = {
5
6
  timeout: number;
6
7
  interval?: number;
7
8
  } & ({
8
9
  kind: 'url';
9
- url: string;
10
+ url: string | Deferred;
10
11
  } | {
11
12
  kind: 'port';
12
- port: number;
13
- host?: string;
13
+ port: number | Deferred;
14
+ host?: string | Deferred;
14
15
  } | {
15
16
  kind: 'command';
16
- command: string;
17
+ command: string | Deferred;
18
+ env?: Record<string, string>;
17
19
  } | {
18
20
  kind: 'logMatches';
19
- logMatches: string[];
21
+ logMatches: (string | Deferred)[];
22
+ } | {
23
+ kind: 'signal';
20
24
  });
25
+ export type NormalizedReadyWhen = ReadyWhenProbe<never>;
26
+ export interface ReadyWhenWait {
27
+ timeout: number;
28
+ description: string;
29
+ }
21
30
  export interface ReadyWhenData {
22
31
  workspaceRoot: string;
23
32
  projectRoot: string;
24
33
  projectName: string;
25
34
  options: Record<string, unknown>;
35
+ env: () => NodeJS.ProcessEnv;
26
36
  }
27
- export declare function normalizeReadyWhen(readyWhen: ReadyWhen, taskId: string, data: ReadyWhenData): NormalizedReadyWhen;
28
- export declare function readinessTimeoutError(taskId: string, readyWhen: NormalizedReadyWhen): Error;
37
+ export declare function normalizeReadyWhen(readyWhen: ReadyWhen, taskId: string, data: ReadyWhenData): NormalizedReadyWhen | null;
38
+ /**
39
+ * Checks a producer's probe without the env the producer runs with. A value
40
+ * that reads that env is left to getReadyWhen in the process that runs the
41
+ * producer, and every other value is checked the way getReadyWhen checks it.
42
+ */
43
+ export declare function checkReadyWhen(readyWhen: ReadyWhen, taskId: string, data: Omit<ReadyWhenData, 'env'>): ReadyWhenWait;
44
+ export declare function readinessTimeoutError(taskId: string, readyWhen: NormalizedReadyWhen | ReadyWhenWait): Error;
29
45
  export declare class ProducerFailedError extends Error {
30
46
  constructor(taskId: string);
31
47
  }
32
48
  export declare class NotReadyError extends Error {
33
49
  }
50
+ export declare class InvalidReadyWhenError extends Error {
51
+ }
34
52
  export declare function notReadyError(taskId: string, reason: 'exited' | 'was stopped' | 'failed'): Error;
35
- export declare function getReadyWhenConfig(task: Task, projectGraph: ProjectGraph): ReadyWhen | undefined;
36
- export declare function getReadyWhen(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string): NormalizedReadyWhen | null;
53
+ export declare function getReadyWhenConfig(task: Task, projectGraph: ProjectGraph): ReadyWhen | null | undefined;
54
+ /**
55
+ * The probe of a producer this process starts with `taskEnv`. Env tokens read
56
+ * `taskEnv`, or for run-commands the env its command runs with
57
+ */
58
+ export declare function getReadyWhen(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string, taskEnv: NodeJS.ProcessEnv): NormalizedReadyWhen | null;
59
+ export declare const TASK_OPTIONS_ENV = "NX_TASK_OPTIONS";
60
+ export declare function getReadyWhenWait(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string): ReadyWhenWait | null;
37
61
  export declare function getReadyProducerIds(task: Task, taskGraph: TaskGraph): string[];
38
62
  export declare function getReadyDependencies(taskGraph: TaskGraph, projectGraph: ProjectGraph): Record<string, string[]>;
63
+ export {};
@@ -1,48 +1,111 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotReadyError = exports.ProducerFailedError = void 0;
3
+ exports.TASK_OPTIONS_ENV = exports.InvalidReadyWhenError = exports.NotReadyError = exports.ProducerFailedError = exports.DEFAULT_READY_TIMEOUT = void 0;
4
4
  exports.normalizeReadyWhen = normalizeReadyWhen;
5
+ exports.checkReadyWhen = checkReadyWhen;
5
6
  exports.readinessTimeoutError = readinessTimeoutError;
6
7
  exports.notReadyError = notReadyError;
7
8
  exports.getReadyWhenConfig = getReadyWhenConfig;
8
9
  exports.getReadyWhen = getReadyWhen;
10
+ exports.getReadyWhenWait = getReadyWhenWait;
9
11
  exports.getReadyProducerIds = getReadyProducerIds;
10
12
  exports.getReadyDependencies = getReadyDependencies;
11
13
  const path_1 = require("path");
12
14
  const params_1 = require("../../utils/params");
15
+ const tokens_1 = require("../tokens");
13
16
  const utils_1 = require("../utils");
14
- const DEFAULT_READY_TIMEOUT = 60_000;
17
+ exports.DEFAULT_READY_TIMEOUT = 60_000;
15
18
  // Node timers take at most a signed 32-bit count of milliseconds
16
19
  const MAX_DURATION = 2_147_483_647;
17
- const PROBE_KEYS = ['url', 'port', 'command', 'logMatches'];
18
- // The placeholders `outputs` resolve, matched by name so that braces a shell
19
- // command needs (`{{.State.Health.Status}}`, `${VAR}`, `{a,b}`) stay literal
20
- const PLACEHOLDER = /{(workspaceRoot|projectRoot|projectName|options\.[^}]+)}/g;
20
+ const PROBE_KEYS = ['url', 'port', 'command', 'logMatches', 'signal'];
21
+ class EnvUnknownHere extends Error {
22
+ }
23
+ // A value that reads the producer's env. It keeps its written form, and
24
+ // getReadyWhen checks it in the process that runs the producer
25
+ class EnvDeferred {
26
+ constructor(written) {
27
+ this.written = written;
28
+ }
29
+ toString() {
30
+ return this.written;
31
+ }
32
+ }
33
+ // `options` and `env` are tokens only with a path, so shell text such as
34
+ // `${options}` stays as written
35
+ const PATHLESS_TOKENS = new Set([
36
+ 'workspaceRoot',
37
+ 'projectRoot',
38
+ 'projectName',
39
+ ]);
21
40
  function normalizeReadyWhen(readyWhen, taskId, data) {
22
- const invalid = (reason) => new Error(`Task "${taskId}" has an invalid "readyWhen": ${reason}.`);
41
+ const probe = resolveReadyWhen(readyWhen, taskId, data);
42
+ // Only checkReadyWhen's env throws EnvUnknownHere, so nothing is deferred
43
+ return probe.kind === 'serverPicksPort'
44
+ ? null
45
+ : probe;
46
+ }
47
+ function resolveReadyWhen(readyWhen, taskId, data) {
48
+ const invalid = (reason) => new InvalidReadyWhenError(`Task "${taskId}" has an invalid "readyWhen": ${reason}.`);
23
49
  if (typeof readyWhen !== 'object' || readyWhen === null) {
24
50
  throw invalid('expected an object');
25
51
  }
26
52
  const config = readyWhen;
27
- const resolve = (value) => typeof value === 'string'
28
- ? value.replace(PLACEHOLDER, (match, name) => {
29
- let resolved = data;
30
- for (const key of name.split('.')) {
31
- resolved = resolved?.[key];
32
- }
33
- if (resolved == null) {
34
- throw invalid(`"${match}" has no value`);
53
+ const scope = {
54
+ isToken: (name, path) => path === undefined
55
+ ? PATHLESS_TOKENS.has(name)
56
+ : name === 'options' || name === 'env',
57
+ read: (name, path) => (0, tokens_1.readPath)(data[name], path),
58
+ env: { read: data.env },
59
+ noValue: (token) => {
60
+ throw invalid(`"${token}" has no value`);
61
+ },
62
+ toText: (value, token) => {
63
+ if (!['string', 'number', 'boolean'].includes(typeof value)) {
64
+ throw invalid(`"${token}" is not a string or a number`);
35
65
  }
36
- if (!['string', 'number', 'boolean'].includes(typeof resolved)) {
37
- throw invalid(`"${match}" is not a string or a number`);
66
+ return String(value);
67
+ },
68
+ };
69
+ // A flag passed without a value parses as `true`, and no host or port is a
70
+ // boolean
71
+ const hostScope = {
72
+ ...scope,
73
+ isUnset: (value) => typeof value === 'boolean',
74
+ };
75
+ // The Rspack dev server reads an empty port option as 0. An empty env var
76
+ // stays unset.
77
+ const portScope = {
78
+ ...hostScope,
79
+ read: (name, path) => {
80
+ const value = scope.read(name, path);
81
+ return value === '' ? 0 : value;
82
+ },
83
+ };
84
+ const resolve = (value, tokenScope = scope) => {
85
+ if (typeof value !== 'string') {
86
+ return value;
87
+ }
88
+ let nodes;
89
+ try {
90
+ nodes = (0, tokens_1.parseTokens)(value, tokenScope);
91
+ }
92
+ catch (e) {
93
+ throw invalid(e.message);
94
+ }
95
+ try {
96
+ return (0, tokens_1.renderTokens)(nodes, tokenScope);
97
+ }
98
+ catch (e) {
99
+ if (e instanceof EnvUnknownHere) {
100
+ return new EnvDeferred(value);
38
101
  }
39
- return String(resolved);
40
- })
41
- : value;
102
+ throw e;
103
+ }
104
+ };
42
105
  // Braces are never valid in a host or port once resolved, so a leftover is
43
106
  // a typo. A url keeps them: they are legal in its path and query.
44
- const resolveWithoutBraces = (key) => {
45
- const value = resolve(config[key]);
107
+ const resolveWithoutBraces = (key, tokenScope) => {
108
+ const value = resolve(config[key], tokenScope);
46
109
  if (typeof value === 'string' && /[{}]/.test(value)) {
47
110
  throw invalid(`"${key}" contains an unknown placeholder`);
48
111
  }
@@ -52,7 +115,7 @@ function normalizeReadyWhen(readyWhen, taskId, data) {
52
115
  if (present.length !== 1) {
53
116
  throw invalid(`expected exactly one of ${PROBE_KEYS.map((k) => `"${k}"`).join(', ')}`);
54
117
  }
55
- const timeout = config.timeout ?? DEFAULT_READY_TIMEOUT;
118
+ const timeout = config.timeout ?? exports.DEFAULT_READY_TIMEOUT;
56
119
  if (!isDuration(timeout)) {
57
120
  throw invalid(`"timeout" must be an integer from 1 to ${MAX_DURATION}`);
58
121
  }
@@ -66,31 +129,41 @@ function normalizeReadyWhen(readyWhen, taskId, data) {
66
129
  switch (present[0]) {
67
130
  case 'url': {
68
131
  const url = resolve(config.url);
69
- if (typeof url !== 'string' || !isHttpUrl(url)) {
132
+ if (!(url instanceof EnvDeferred) &&
133
+ (typeof url !== 'string' || !isHttpUrl(url))) {
70
134
  throw invalid('"url" must be an http or https URL');
71
135
  }
72
136
  return { kind: 'url', url, ...shared };
73
137
  }
74
138
  case 'port': {
75
- let port = resolveWithoutBraces('port');
139
+ let port = resolveWithoutBraces('port', portScope);
76
140
  if (typeof port === 'string' && /^\d+$/.test(port)) {
77
141
  port = Number(port);
78
142
  }
79
- if (!isPositiveInteger(port) || port > 65535) {
80
- throw invalid('"port" must be an integer from 1 to 65535');
143
+ if (port !== 0 &&
144
+ port !== 'auto' &&
145
+ !(port instanceof EnvDeferred) &&
146
+ (!isPositiveInteger(port) || port > 65535)) {
147
+ throw invalid('"port" must be an integer from 0 to 65535, or "auto"');
81
148
  }
82
- const host = resolveWithoutBraces('host');
149
+ const host = resolveWithoutBraces('host', hostScope);
83
150
  if (host == null) {
84
- return { kind: 'port', port, ...shared };
151
+ return port === 0 || port === 'auto'
152
+ ? { kind: 'serverPicksPort', port, ...shared }
153
+ : { kind: 'port', port, ...shared };
85
154
  }
86
- if (typeof host !== 'string' || !host) {
155
+ if (!(host instanceof EnvDeferred) &&
156
+ (typeof host !== 'string' || !host)) {
87
157
  throw invalid('"host" must be a non-empty string');
88
158
  }
89
- return { kind: 'port', port, host, ...shared };
159
+ return port === 0 || port === 'auto'
160
+ ? { kind: 'serverPicksPort', port, host, ...shared }
161
+ : { kind: 'port', port, host, ...shared };
90
162
  }
91
163
  case 'command': {
92
164
  const command = resolve(config.command);
93
- if (typeof command !== 'string' || !command) {
165
+ if (!(command instanceof EnvDeferred) &&
166
+ (typeof command !== 'string' || !command)) {
94
167
  throw invalid('"command" must be a non-empty string');
95
168
  }
96
169
  return { kind: 'command', command, ...shared };
@@ -98,17 +171,45 @@ function normalizeReadyWhen(readyWhen, taskId, data) {
98
171
  case 'logMatches': {
99
172
  const logMatches = (Array.isArray(config.logMatches)
100
173
  ? config.logMatches
101
- : [config.logMatches]).map(resolve);
174
+ : [config.logMatches]).map((match) => resolve(match));
102
175
  if (logMatches.length === 0 ||
103
- !logMatches.every((m) => typeof m === 'string' && !!m)) {
176
+ !logMatches.every((m) => m instanceof EnvDeferred || (typeof m === 'string' && !!m))) {
104
177
  throw invalid('"logMatches" must be a non-empty string or an array of them');
105
178
  }
106
179
  return { kind: 'logMatches', logMatches, ...shared };
107
180
  }
181
+ case 'signal': {
182
+ if (config.signal !== true) {
183
+ throw invalid('"signal" must be true');
184
+ }
185
+ if (config.interval != null) {
186
+ throw invalid('"interval" is not used by "signal"');
187
+ }
188
+ return { kind: 'signal', timeout };
189
+ }
108
190
  }
109
191
  }
192
+ /**
193
+ * Checks a producer's probe without the env the producer runs with. A value
194
+ * that reads that env is left to getReadyWhen in the process that runs the
195
+ * producer, and every other value is checked the way getReadyWhen checks it.
196
+ */
197
+ function checkReadyWhen(readyWhen, taskId, data) {
198
+ const probe = resolveReadyWhen(readyWhen, taskId, {
199
+ ...data,
200
+ env: () => {
201
+ throw new EnvUnknownHere();
202
+ },
203
+ });
204
+ return {
205
+ timeout: probe.timeout,
206
+ description: describeReadyWhen(probe),
207
+ };
208
+ }
110
209
  function readinessTimeoutError(taskId, readyWhen) {
111
- return new Error(`Task "${taskId}" did not become ready within ${readyWhen.timeout}ms (readyWhen: ${describeReadyWhen(readyWhen)}).`);
210
+ const description = 'kind' in readyWhen ? describeReadyWhen(readyWhen) : readyWhen.description;
211
+ return new Error(`Task "${taskId}" did not become ready within ${readyWhen.timeout}ms (readyWhen: ${description}). ` +
212
+ 'To change the check, set "readyWhen" on the target or in "targetDefaults" in nx.json, or set it to null to turn it off.');
112
213
  }
113
214
  // The row carries only the status; the owner reports the reason
114
215
  class ProducerFailedError extends Error {
@@ -121,6 +222,9 @@ exports.ProducerFailedError = ProducerFailedError;
121
222
  class NotReadyError extends Error {
122
223
  }
123
224
  exports.NotReadyError = NotReadyError;
225
+ class InvalidReadyWhenError extends Error {
226
+ }
227
+ exports.InvalidReadyWhenError = InvalidReadyWhenError;
124
228
  function notReadyError(taskId, reason) {
125
229
  return new NotReadyError(`Task "${taskId}" ${reason} before it became ready.`);
126
230
  }
@@ -129,6 +233,7 @@ function describeReadyWhen(readyWhen) {
129
233
  case 'url':
130
234
  return `url ${readyWhen.url}`;
131
235
  case 'port':
236
+ case 'serverPicksPort':
132
237
  return readyWhen.host
133
238
  ? `port ${readyWhen.host}:${readyWhen.port}`
134
239
  : `port ${readyWhen.port}`;
@@ -136,6 +241,8 @@ function describeReadyWhen(readyWhen) {
136
241
  return `command "${readyWhen.command}"`;
137
242
  case 'logMatches':
138
243
  return `logMatches ${readyWhen.logMatches.map((m) => `"${m}"`).join(', ')}`;
244
+ case 'signal':
245
+ return 'signal';
139
246
  }
140
247
  }
141
248
  // Raw config: scheduling must not throw on an invalid value, the producer's
@@ -146,9 +253,52 @@ function getReadyWhenConfig(task, projectGraph) {
146
253
  }
147
254
  return projectGraph.nodes[task.target.project]?.data?.targets?.[task.target.target]?.readyWhen;
148
255
  }
256
+ /**
257
+ * The probe of a producer this process starts with `taskEnv`. Env tokens read
258
+ * `taskEnv`, or for run-commands the env its command runs with
259
+ */
260
+ function getReadyWhen(task, projectGraph, projects, workspaceRoot, taskEnv) {
261
+ const inputs = getReadyWhenInputs(task, projectGraph, projects, workspaceRoot);
262
+ if (!inputs) {
263
+ return null;
264
+ }
265
+ const { readyWhen, executor, data } = inputs;
266
+ const { options } = data;
267
+ let commandEnv;
268
+ const env = () => {
269
+ if (executor !== 'nx:run-commands') {
270
+ return taskEnv;
271
+ }
272
+ if (commandEnv) {
273
+ return commandEnv;
274
+ }
275
+ // Required lazily, so loading run-command.ts doesn't also load the
276
+ // run-commands executor
277
+ const { calculateCwd, processEnv } = require('../../executors/run-commands/running-tasks');
278
+ commandEnv = processEnv(options.color, calculateCwd(options.cwd, {
279
+ root: workspaceRoot,
280
+ }), (options.env ?? {}), options.envFile, taskEnv);
281
+ return commandEnv;
282
+ };
283
+ const probe = normalizeReadyWhen(readyWhen, task.id, { ...data, env });
284
+ if (probe?.kind === 'command') {
285
+ probe.env = {
286
+ ...Object.fromEntries(Object.entries(env()).filter(([, value]) => value !== undefined)),
287
+ [exports.TASK_OPTIONS_ENV]: JSON.stringify(options),
288
+ };
289
+ }
290
+ return probe;
291
+ }
292
+ // A command check reads the options its producer runs with from this variable
293
+ exports.TASK_OPTIONS_ENV = 'NX_TASK_OPTIONS';
294
+ // The probe of a producer another process may run
295
+ function getReadyWhenWait(task, projectGraph, projects, workspaceRoot) {
296
+ const inputs = getReadyWhenInputs(task, projectGraph, projects, workspaceRoot);
297
+ return inputs && checkReadyWhen(inputs.readyWhen, task.id, inputs.data);
298
+ }
149
299
  // Placeholders resolve against the options the executor receives: aliases,
150
300
  // schema defaults and the spelling of command-line overrides applied
151
- function getReadyWhen(task, projectGraph, projects, workspaceRoot) {
301
+ function getReadyWhenInputs(task, projectGraph, projects, workspaceRoot) {
152
302
  const readyWhen = getReadyWhenConfig(task, projectGraph);
153
303
  if (readyWhen == null) {
154
304
  return null;
@@ -156,12 +306,17 @@ function getReadyWhen(task, projectGraph, projects, workspaceRoot) {
156
306
  const node = projectGraph.nodes[task.target.project];
157
307
  const target = node.data.targets[task.target.target];
158
308
  const { schema } = (0, utils_1.getExecutorForTask)(task, projects);
159
- return normalizeReadyWhen(readyWhen, task.id, {
160
- workspaceRoot,
161
- projectRoot: node.data.root,
162
- projectName: node.name,
163
- options: (0, params_1.combineOptionsForExecutor)(task.overrides, task.target.configuration ?? target.defaultConfiguration, target, schema, task.target.project, (0, path_1.relative)(task.projectRoot ?? workspaceRoot, process.cwd()), process.env.NX_VERBOSE_LOGGING === 'true'),
164
- });
309
+ const options = (0, params_1.combineOptionsForExecutor)(task.overrides, task.target.configuration ?? target.defaultConfiguration, target, schema, task.target.project, (0, path_1.relative)(task.projectRoot ?? workspaceRoot, process.cwd()), process.env.NX_VERBOSE_LOGGING === 'true');
310
+ return {
311
+ readyWhen,
312
+ executor: target.executor,
313
+ data: {
314
+ workspaceRoot,
315
+ projectRoot: node.data.root,
316
+ projectName: node.name,
317
+ options,
318
+ },
319
+ };
165
320
  }
166
321
  function getReadyProducerIds(task, taskGraph) {
167
322
  return (taskGraph.continuousDependencies[task.id] ?? [])
@@ -0,0 +1 @@
1
+ export declare function resolveStartupHost(host: string | undefined): string | undefined;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveStartupHost = resolveStartupHost;
4
+ const net_1 = require("net");
5
+ const os_1 = require("os");
6
+ // webpack-dev-server and the Rspack dev server resolve these hosts when they
7
+ // start (`Server.getHostname`). A wildcard fallback means loopback to the probe.
8
+ function resolveStartupHost(host) {
9
+ switch (host) {
10
+ case 'local-ip':
11
+ return findIp('IPv4') ?? findIp('IPv6') ?? '0.0.0.0';
12
+ case 'local-ipv4':
13
+ return findIp('IPv4') ?? '0.0.0.0';
14
+ case 'local-ipv6':
15
+ return findIp('IPv6') ?? '::';
16
+ default:
17
+ return host;
18
+ }
19
+ }
20
+ // The IPv6 ranges `Server.findIp` accepts: unique local, IPv4-mapped, loopback
21
+ const FIND_IP_V6_RANGES = new net_1.BlockList();
22
+ FIND_IP_V6_RANGES.addSubnet('fc00::', 7, 'ipv6');
23
+ FIND_IP_V6_RANGES.addSubnet('::ffff:0:0', 96, 'ipv6');
24
+ FIND_IP_V6_RANGES.addAddress('::1', 'ipv6');
25
+ function findIp(family) {
26
+ return Object.values((0, os_1.networkInterfaces)())
27
+ .flatMap((addresses) => addresses ?? [])
28
+ .find(({ address, family: addressFamily, internal }) => address &&
29
+ addressFamily === family &&
30
+ !internal &&
31
+ (family === 'IPv4' || FIND_IP_V6_RANGES.check(address, 'ipv6')))?.address;
32
+ }
@@ -10,6 +10,7 @@ exports.getInvocationRootPid = getInvocationRootPid;
10
10
  exports.loadAndExpandDotEnvFile = loadAndExpandDotEnvFile;
11
11
  exports.unloadDotEnvFile = unloadDotEnvFile;
12
12
  exports.getEnvFilesForTask = getEnvFilesForTask;
13
+ const ready_signal_1 = require("./readiness/ready-signal");
13
14
  const dotenv_1 = require("dotenv");
14
15
  const dotenv_expand_1 = require("dotenv-expand");
15
16
  const node_path_1 = require("node:path");
@@ -41,6 +42,11 @@ function getEnvVariablesForBatchProcess(skipNxCache, captureStderr) {
41
42
  };
42
43
  // NX_ORIGINAL_FORCE_COLOR is an internal signal and should not leak into child processes
43
44
  delete res.NX_ORIGINAL_FORCE_COLOR;
45
+ // The orchestrator sets these for the one task they are meant for, so an
46
+ // Nx run inside that task must not pass them on
47
+ delete res[ready_signal_1.READY_SIGNAL_SOCKET_ENV];
48
+ delete res[ready_signal_1.READY_SIGNAL_TASK_ENV];
49
+ delete res[ready_signal_1.READY_URL_ENV];
44
50
  return res;
45
51
  }
46
52
  // The orchestrator now calls this eagerly during the coordinator pre-hash
@@ -123,6 +129,11 @@ function getEnvVariablesForTask(task, taskSpecificEnv, forceColor, skipNxCache,
123
129
  // NX_ORIGINAL_FORCE_COLOR is an internal signal used by getForceColorForChild()
124
130
  // and should not leak into child processes
125
131
  delete res.NX_ORIGINAL_FORCE_COLOR;
132
+ // The orchestrator sets these for the one task they are meant for, so an
133
+ // Nx run inside that task must not pass them on
134
+ delete res[ready_signal_1.READY_SIGNAL_SOCKET_ENV];
135
+ delete res[ready_signal_1.READY_SIGNAL_TASK_ENV];
136
+ delete res[ready_signal_1.READY_URL_ENV];
126
137
  return res;
127
138
  }
128
139
  function getNxEnvVariablesForForkedProcess(forceColor, skipNxCache, captureStderr, outputPath, streamOutput) {