nx 24.0.0-beta.3 → 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.
- package/dist/src/command-line/migrate/execute-migration.d.ts +4 -4
- package/dist/src/command-line/migrate/execute-migration.js +7 -5
- package/dist/src/command-line/migrate/migrate.d.ts +3 -0
- package/dist/src/command-line/migrate/migrate.js +61 -17
- package/dist/src/config/misc-interfaces.d.ts +6 -0
- package/dist/src/config/workspace-json-project-json.d.ts +12 -4
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/runtime.js +1 -1
- package/dist/src/core/graph/styles.css +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/devkit-exports.d.ts +4 -0
- package/dist/src/devkit-exports.js +7 -1
- package/dist/src/devkit-internals.d.ts +1 -0
- package/dist/src/devkit-internals.js +3 -0
- package/dist/src/native/index.d.ts +8 -2
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +49 -6
- package/dist/src/tasks-runner/pseudo-ipc.d.ts +1 -0
- package/dist/src/tasks-runner/pseudo-ipc.js +4 -0
- package/dist/src/tasks-runner/readiness/probes.d.ts +6 -1
- package/dist/src/tasks-runner/readiness/probes.js +40 -30
- package/dist/src/tasks-runner/readiness/ready-signal-server.d.ts +18 -0
- package/dist/src/tasks-runner/readiness/ready-signal-server.js +71 -0
- package/dist/src/tasks-runner/readiness/ready-signal.d.ts +25 -0
- package/dist/src/tasks-runner/readiness/ready-signal.js +70 -0
- package/dist/src/tasks-runner/readiness/ready-when.d.ts +4 -0
- package/dist/src/tasks-runner/readiness/ready-when.js +37 -19
- package/dist/src/tasks-runner/readiness/startup-host.d.ts +1 -0
- package/dist/src/tasks-runner/readiness/startup-host.js +32 -0
- package/dist/src/tasks-runner/task-env.js +11 -0
- package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -0
- package/dist/src/tasks-runner/task-orchestrator.js +41 -6
- package/dist/src/ultracache/config.d.ts +3 -3
- package/dist/src/ultracache/config.js +4 -4
- package/package.json +11 -11
- package/schemas/migrations-schema.json +11 -0
- package/schemas/nx-schema.json +8 -3
- package/schemas/project-schema.json +8 -3
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { RunningTask } from '../running-tasks/running-task';
|
|
2
|
+
import type { ReadySignalServer } from './ready-signal-server';
|
|
2
3
|
import { type NormalizedReadyWhen } from './ready-when';
|
|
3
4
|
export interface ReadinessProbeContext {
|
|
4
5
|
taskId: string;
|
|
5
6
|
runningTask: RunningTask;
|
|
6
7
|
cwd: string;
|
|
7
8
|
signal: AbortSignal;
|
|
9
|
+
readySignal?: ReadySignalServer;
|
|
8
10
|
}
|
|
9
|
-
export
|
|
11
|
+
export interface Readiness {
|
|
12
|
+
url?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function waitForReadiness(readyWhen: NormalizedReadyWhen, context: ReadinessProbeContext): Promise<Readiness>;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitForReadiness = waitForReadiness;
|
|
4
|
-
const net_1 = require("net");
|
|
5
|
-
const os_1 = require("os");
|
|
6
4
|
const native_1 = require("../../native");
|
|
5
|
+
const startup_host_1 = require("./startup-host");
|
|
7
6
|
const ready_when_1 = require("./ready-when");
|
|
8
7
|
// Never rejects for a transient probe error: every failure is retried until
|
|
9
8
|
// the deadline.
|
|
10
9
|
async function waitForReadiness(readyWhen, context) {
|
|
10
|
+
if (readyWhen.kind === 'signal') {
|
|
11
|
+
return waitForSignal(readyWhen, context);
|
|
12
|
+
}
|
|
13
|
+
await waitForCheck(readyWhen, context);
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
async function waitForCheck(readyWhen, context) {
|
|
11
17
|
if (native_1.IS_WASM) {
|
|
12
18
|
throw new Error(`The WASM build of Nx does not support "readyWhen", so "${context.taskId}" cannot be probed for readiness.`);
|
|
13
19
|
}
|
|
@@ -20,8 +26,8 @@ async function waitForReadiness(readyWhen, context) {
|
|
|
20
26
|
...(readyWhen.kind === 'url'
|
|
21
27
|
? { url: readyWhen.url }
|
|
22
28
|
: readyWhen.kind === 'port'
|
|
23
|
-
? { port: readyWhen.port, host: resolveStartupHost(readyWhen.host) }
|
|
24
|
-
: { command: readyWhen.command }),
|
|
29
|
+
? { port: readyWhen.port, host: (0, startup_host_1.resolveStartupHost)(readyWhen.host) }
|
|
30
|
+
: { command: readyWhen.command, env: readyWhen.env }),
|
|
25
31
|
}, context.cwd);
|
|
26
32
|
const cancel = () => probe.cancel();
|
|
27
33
|
context.signal.addEventListener('abort', cancel);
|
|
@@ -41,32 +47,36 @@ async function waitForReadiness(readyWhen, context) {
|
|
|
41
47
|
: (0, ready_when_1.readinessTimeoutError)(context.taskId, readyWhen);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
// Ready on the producer's `ready` message, which a message sent before the
|
|
51
|
+
// check started counts as
|
|
52
|
+
function waitForSignal(readyWhen, context) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
let unsubscribe = () => { };
|
|
55
|
+
let settled = false;
|
|
56
|
+
const settle = (error, readiness) => {
|
|
57
|
+
if (settled)
|
|
58
|
+
return;
|
|
59
|
+
settled = true;
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
unsubscribe();
|
|
62
|
+
context.signal.removeEventListener('abort', onAbort);
|
|
63
|
+
error ? reject(error) : resolve(readiness);
|
|
64
|
+
};
|
|
65
|
+
const onAbort = () => settle((0, ready_when_1.notReadyError)(context.taskId, 'exited'));
|
|
66
|
+
const timer = setTimeout(() => settle((0, ready_when_1.readinessTimeoutError)(context.taskId, readyWhen)), readyWhen.timeout);
|
|
67
|
+
timer.unref();
|
|
68
|
+
context.signal.addEventListener('abort', onAbort);
|
|
69
|
+
if (context.signal.aborted) {
|
|
70
|
+
onAbort();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const stop = context.readySignal?.subscribe(context.taskId, (message) => settle(null, message.url ? { url: message.url } : {}));
|
|
74
|
+
if (settled) {
|
|
75
|
+
stop?.();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
unsubscribe = stop ?? unsubscribe;
|
|
79
|
+
});
|
|
70
80
|
}
|
|
71
81
|
function waitForLogMatch(readyWhen, context) {
|
|
72
82
|
return new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReadySignalMessage } from './ready-signal';
|
|
2
|
+
export type ReadySignalListener = (message: ReadySignalMessage) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Receives the readiness signals of the producers this process starts. It
|
|
5
|
+
* does not depend on the pseudo terminal, which Windows and non-TTY runs lack.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReadySignalServer {
|
|
8
|
+
private readonly path;
|
|
9
|
+
private readonly server;
|
|
10
|
+
private started;
|
|
11
|
+
private listeners;
|
|
12
|
+
private early;
|
|
13
|
+
private issued;
|
|
14
|
+
env(taskId: string): Promise<NodeJS.ProcessEnv>;
|
|
15
|
+
subscribe(taskId: string, listener: ReadySignalListener): () => void;
|
|
16
|
+
close(): void;
|
|
17
|
+
private dispatch;
|
|
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
|
+
}
|
|
@@ -15,9 +15,12 @@ type ReadyWhenProbe<Deferred> = {
|
|
|
15
15
|
} | {
|
|
16
16
|
kind: 'command';
|
|
17
17
|
command: string | Deferred;
|
|
18
|
+
env?: Record<string, string>;
|
|
18
19
|
} | {
|
|
19
20
|
kind: 'logMatches';
|
|
20
21
|
logMatches: (string | Deferred)[];
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'signal';
|
|
21
24
|
});
|
|
22
25
|
export type NormalizedReadyWhen = ReadyWhenProbe<never>;
|
|
23
26
|
export interface ReadyWhenWait {
|
|
@@ -53,6 +56,7 @@ export declare function getReadyWhenConfig(task: Task, projectGraph: ProjectGrap
|
|
|
53
56
|
* `taskEnv`, or for run-commands the env its command runs with
|
|
54
57
|
*/
|
|
55
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";
|
|
56
60
|
export declare function getReadyWhenWait(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string): ReadyWhenWait | null;
|
|
57
61
|
export declare function getReadyProducerIds(task: Task, taskGraph: TaskGraph): string[];
|
|
58
62
|
export declare function getReadyDependencies(taskGraph: TaskGraph, projectGraph: ProjectGraph): Record<string, string[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidReadyWhenError = exports.NotReadyError = exports.ProducerFailedError = exports.DEFAULT_READY_TIMEOUT = 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
5
|
exports.checkReadyWhen = checkReadyWhen;
|
|
6
6
|
exports.readinessTimeoutError = readinessTimeoutError;
|
|
@@ -17,7 +17,7 @@ const utils_1 = require("../utils");
|
|
|
17
17
|
exports.DEFAULT_READY_TIMEOUT = 60_000;
|
|
18
18
|
// Node timers take at most a signed 32-bit count of milliseconds
|
|
19
19
|
const MAX_DURATION = 2_147_483_647;
|
|
20
|
-
const PROBE_KEYS = ['url', 'port', 'command', 'logMatches'];
|
|
20
|
+
const PROBE_KEYS = ['url', 'port', 'command', 'logMatches', 'signal'];
|
|
21
21
|
class EnvUnknownHere extends Error {
|
|
22
22
|
}
|
|
23
23
|
// A value that reads the producer's env. It keeps its written form, and
|
|
@@ -178,6 +178,15 @@ function resolveReadyWhen(readyWhen, taskId, data) {
|
|
|
178
178
|
}
|
|
179
179
|
return { kind: 'logMatches', logMatches, ...shared };
|
|
180
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
|
+
}
|
|
181
190
|
}
|
|
182
191
|
}
|
|
183
192
|
/**
|
|
@@ -232,6 +241,8 @@ function describeReadyWhen(readyWhen) {
|
|
|
232
241
|
return `command "${readyWhen.command}"`;
|
|
233
242
|
case 'logMatches':
|
|
234
243
|
return `logMatches ${readyWhen.logMatches.map((m) => `"${m}"`).join(', ')}`;
|
|
244
|
+
case 'signal':
|
|
245
|
+
return 'signal';
|
|
235
246
|
}
|
|
236
247
|
}
|
|
237
248
|
// Raw config: scheduling must not throw on an invalid value, the producer's
|
|
@@ -254,25 +265,32 @@ function getReadyWhen(task, projectGraph, projects, workspaceRoot, taskEnv) {
|
|
|
254
265
|
const { readyWhen, executor, data } = inputs;
|
|
255
266
|
const { options } = data;
|
|
256
267
|
let commandEnv;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
if (commandEnv) {
|
|
264
|
-
return commandEnv;
|
|
265
|
-
}
|
|
266
|
-
// Required lazily, so loading run-command.ts doesn't also load the
|
|
267
|
-
// run-commands executor
|
|
268
|
-
const { calculateCwd, processEnv } = require('../../executors/run-commands/running-tasks');
|
|
269
|
-
commandEnv = processEnv(options.color, calculateCwd(options.cwd, {
|
|
270
|
-
root: workspaceRoot,
|
|
271
|
-
}), (options.env ?? {}), options.envFile, taskEnv);
|
|
268
|
+
const env = () => {
|
|
269
|
+
if (executor !== 'nx:run-commands') {
|
|
270
|
+
return taskEnv;
|
|
271
|
+
}
|
|
272
|
+
if (commandEnv) {
|
|
272
273
|
return commandEnv;
|
|
273
|
-
}
|
|
274
|
-
|
|
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;
|
|
275
291
|
}
|
|
292
|
+
// A command check reads the options its producer runs with from this variable
|
|
293
|
+
exports.TASK_OPTIONS_ENV = 'NX_TASK_OPTIONS';
|
|
276
294
|
// The probe of a producer another process may run
|
|
277
295
|
function getReadyWhenWait(task, projectGraph, projects, workspaceRoot) {
|
|
278
296
|
const inputs = getReadyWhenInputs(task, projectGraph, projects, workspaceRoot);
|
|
@@ -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) {
|
|
@@ -67,6 +67,8 @@ export declare class TaskOrchestrator {
|
|
|
67
67
|
private readinessFailures;
|
|
68
68
|
private readinessFailureReasons;
|
|
69
69
|
private readinessSettled;
|
|
70
|
+
private readySignal;
|
|
71
|
+
private readyUrls;
|
|
70
72
|
private waitingLogged;
|
|
71
73
|
private cleanupPromise;
|
|
72
74
|
private signalHandlers;
|
|
@@ -275,6 +277,7 @@ export declare class TaskOrchestrator {
|
|
|
275
277
|
private getReadinessCheck;
|
|
276
278
|
private warnUncheckedReadiness;
|
|
277
279
|
private waitForReadyDependencies;
|
|
280
|
+
private getReadyUrlEnv;
|
|
278
281
|
private onReadinessHold;
|
|
279
282
|
private pollReadinessRow;
|
|
280
283
|
private startReadinessProbe;
|
|
@@ -283,6 +286,7 @@ export declare class TaskOrchestrator {
|
|
|
283
286
|
private skipWaiter;
|
|
284
287
|
private recordReadiness;
|
|
285
288
|
private publishReadiness;
|
|
289
|
+
private readReadyUrl;
|
|
286
290
|
private readinessOf;
|
|
287
291
|
private armReadiness;
|
|
288
292
|
private abortReadiness;
|
|
@@ -23,6 +23,8 @@ const forked_process_task_runner_1 = require("./forked-process-task-runner");
|
|
|
23
23
|
const is_tui_enabled_1 = require("./is-tui-enabled");
|
|
24
24
|
const pseudo_terminal_1 = require("./pseudo-terminal");
|
|
25
25
|
const probes_1 = require("./readiness/probes");
|
|
26
|
+
const ready_signal_1 = require("./readiness/ready-signal");
|
|
27
|
+
const ready_signal_server_1 = require("./readiness/ready-signal-server");
|
|
26
28
|
const ready_when_1 = require("./readiness/ready-when");
|
|
27
29
|
const noop_child_process_1 = require("./running-tasks/noop-child-process");
|
|
28
30
|
const output_prefix_1 = require("./running-tasks/output-prefix");
|
|
@@ -161,6 +163,8 @@ class TaskOrchestrator {
|
|
|
161
163
|
this.readinessFailures = new Map();
|
|
162
164
|
this.readinessFailureReasons = new Map();
|
|
163
165
|
this.readinessSettled = false;
|
|
166
|
+
// The url each producer reported with its readiness signal
|
|
167
|
+
this.readyUrls = new Map();
|
|
164
168
|
this.waitingLogged = new Set();
|
|
165
169
|
this.cleanupPromise = null;
|
|
166
170
|
this.signalHandlers = [];
|
|
@@ -1111,6 +1115,7 @@ class TaskOrchestrator {
|
|
|
1111
1115
|
const env = pipeOutput
|
|
1112
1116
|
? (0, task_env_1.getEnvVariablesForTask)(task, taskSpecificEnv, (0, task_env_1.getForceColorForChild)(), this.options.skipNxCache, this.options.captureStderr, null, null)
|
|
1113
1117
|
: (0, task_env_1.getEnvVariablesForTask)(task, taskSpecificEnv, undefined, this.options.skipNxCache, this.options.captureStderr, temporaryOutputPath, streamOutput);
|
|
1118
|
+
Object.assign(env, this.getReadyUrlEnv(task));
|
|
1114
1119
|
let resolveDiscreteExit;
|
|
1115
1120
|
const discreteExitHandled = new Promise((r) => (resolveDiscreteExit = r));
|
|
1116
1121
|
this.discreteTaskExitHandled.set(task.id, discreteExitHandled);
|
|
@@ -1375,7 +1380,12 @@ class TaskOrchestrator {
|
|
|
1375
1380
|
? (0, task_env_1.getEnvVariablesForTask)(task, taskSpecificEnv, (0, task_env_1.getForceColorForChild)(), this.options.skipNxCache, this.options.captureStderr, null, null)
|
|
1376
1381
|
: (0, task_env_1.getEnvVariablesForTask)(task, taskSpecificEnv, undefined, this.options.skipNxCache, this.options.captureStderr, temporaryOutputPath, streamOutput);
|
|
1377
1382
|
({ readyWhen, uncheckedReason, readyOnStart } = this.getReadinessCheck(task, () => this.getReadyWhen(task, env)));
|
|
1383
|
+
if (readyWhen?.kind === 'signal') {
|
|
1384
|
+
this.readySignal ??= new ready_signal_server_1.ReadySignalServer();
|
|
1385
|
+
Object.assign(env, await this.readySignal.env(task.id));
|
|
1386
|
+
}
|
|
1378
1387
|
await this.waitForReadyDependencies(task);
|
|
1388
|
+
Object.assign(env, this.getReadyUrlEnv(task));
|
|
1379
1389
|
}
|
|
1380
1390
|
catch (e) {
|
|
1381
1391
|
this.runningTasksService?.removeRunningTask(task.id);
|
|
@@ -1517,6 +1527,13 @@ class TaskOrchestrator {
|
|
|
1517
1527
|
}
|
|
1518
1528
|
}
|
|
1519
1529
|
}
|
|
1530
|
+
// A waiter learns the url of the one ready producer that reported it
|
|
1531
|
+
getReadyUrlEnv(task) {
|
|
1532
|
+
const urls = (0, ready_when_1.getReadyProducerIds)(task, this.fullTaskGraph)
|
|
1533
|
+
.map((id) => this.readyUrls.get(id))
|
|
1534
|
+
.filter(Boolean);
|
|
1535
|
+
return urls.length === 1 ? { [ready_signal_1.READY_URL_ENV]: urls[0] } : {};
|
|
1536
|
+
}
|
|
1520
1537
|
onReadinessHold(producerId) {
|
|
1521
1538
|
if (!this.waitingLogged.has(producerId) &&
|
|
1522
1539
|
!this.tuiEnabled &&
|
|
@@ -1550,6 +1567,7 @@ class TaskOrchestrator {
|
|
|
1550
1567
|
this.options.lifeCycle.setTaskReadiness?.(producer.id, status);
|
|
1551
1568
|
}
|
|
1552
1569
|
if (status === 1 /* TaskReadiness.Ready */) {
|
|
1570
|
+
this.readReadyUrl(producer.id);
|
|
1553
1571
|
return true;
|
|
1554
1572
|
}
|
|
1555
1573
|
if (status === 2 /* TaskReadiness.Failed */) {
|
|
@@ -1569,10 +1587,13 @@ class TaskOrchestrator {
|
|
|
1569
1587
|
runningTask,
|
|
1570
1588
|
cwd: workspace_root_1.workspaceRoot,
|
|
1571
1589
|
signal: state.abort.signal,
|
|
1572
|
-
|
|
1590
|
+
readySignal: this.readySignal,
|
|
1591
|
+
}).then(({ url }) => {
|
|
1573
1592
|
if (state.abort.signal.aborted)
|
|
1574
1593
|
return;
|
|
1575
|
-
|
|
1594
|
+
if (url)
|
|
1595
|
+
this.readyUrls.set(task.id, url);
|
|
1596
|
+
this.recordReadiness(task, 1 /* TaskReadiness.Ready */, url);
|
|
1576
1597
|
state.resolve();
|
|
1577
1598
|
}, (e) => {
|
|
1578
1599
|
if (state.abort.signal.aborted)
|
|
@@ -1621,14 +1642,14 @@ class TaskOrchestrator {
|
|
|
1621
1642
|
await this.complete([{ task, status: 'skipped' }], groupId);
|
|
1622
1643
|
}
|
|
1623
1644
|
}
|
|
1624
|
-
recordReadiness(task, status) {
|
|
1645
|
+
recordReadiness(task, status, url) {
|
|
1625
1646
|
this.options.lifeCycle.setTaskReadiness?.(task.id, status);
|
|
1626
|
-
this.publishReadiness(task, status);
|
|
1647
|
+
this.publishReadiness(task, status, url);
|
|
1627
1648
|
}
|
|
1628
1649
|
// Only other processes read the row, so a failed write must not fail this one
|
|
1629
|
-
publishReadiness(task, status) {
|
|
1650
|
+
publishReadiness(task, status, url) {
|
|
1630
1651
|
try {
|
|
1631
|
-
this.runningTasksService?.setTaskReadiness(task.id, status);
|
|
1652
|
+
this.runningTasksService?.setTaskReadiness(task.id, status, url ?? null);
|
|
1632
1653
|
}
|
|
1633
1654
|
catch (e) {
|
|
1634
1655
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
@@ -1636,6 +1657,19 @@ class TaskOrchestrator {
|
|
|
1636
1657
|
}
|
|
1637
1658
|
}
|
|
1638
1659
|
}
|
|
1660
|
+
// The url a producer another process runs reported with its readiness
|
|
1661
|
+
readReadyUrl(producerId) {
|
|
1662
|
+
try {
|
|
1663
|
+
const url = this.runningTasksService?.getTaskReadyUrl(producerId);
|
|
1664
|
+
if (url)
|
|
1665
|
+
this.readyUrls.set(producerId, url);
|
|
1666
|
+
}
|
|
1667
|
+
catch (e) {
|
|
1668
|
+
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
1669
|
+
console.error(`Failed to read the url of "${producerId}":`, e);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1639
1673
|
readinessOf(taskId) {
|
|
1640
1674
|
return this.readiness.get(taskId) ?? this.armReadiness(taskId);
|
|
1641
1675
|
}
|
|
@@ -2065,6 +2099,7 @@ class TaskOrchestrator {
|
|
|
2065
2099
|
async performCleanup() {
|
|
2066
2100
|
// Waiters must not sit out a probe once the run is stopping
|
|
2067
2101
|
this.abortAllReadiness();
|
|
2102
|
+
this.readySignal?.close();
|
|
2068
2103
|
// Mark all running tasks for intentional stop
|
|
2069
2104
|
const reason = this.stopRequested ? 'interrupted' : 'fulfilled';
|
|
2070
2105
|
for (const entry of this.runningContinuousTasks.values()) {
|
|
@@ -12,9 +12,9 @@ export interface UltracacheEnv {
|
|
|
12
12
|
hasNxCloudToken?: boolean;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `env` defaults to this process's.
|
|
15
|
+
* On for CI runs in a workspace that uses Nx Cloud, since there is nothing to
|
|
16
|
+
* fetch from otherwise. Nx Cloud's workspace setting decides whether the fetch
|
|
17
|
+
* returns any; `NX_CLOUD_USE_ULTRACACHE=false` skips it. `env` defaults to this process's.
|
|
18
18
|
*/
|
|
19
19
|
export declare function isUltracacheConfigurationFetchEnabled(nxJson: NxJsonConfiguration, runnerOptions?: UltracacheCloudOptions, env?: UltracacheEnv): boolean;
|
|
20
20
|
/** The subset of this run's environment the decision reads. */
|