nx 24.0.4 → 24.0.6
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/bin/nx.js +2 -8
- package/dist/bin/workspace-env.d.ts +7 -0
- package/dist/bin/workspace-env.js +20 -0
- package/dist/src/command-line/affected/affected.js +1 -0
- package/dist/src/command-line/migrate/migrate.js +23 -7
- package/dist/src/command-line/migrate/prompt-files.d.ts +4 -2
- package/dist/src/command-line/migrate/prompt-files.js +26 -5
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +1 -1
- package/dist/src/command-line/release/changelog.js +15 -12
- package/dist/src/command-line/reset/reset.js +13 -1
- package/dist/src/daemon/client/client.js +8 -7
- package/dist/src/daemon/client/daemon-environment.d.ts +43 -11
- package/dist/src/daemon/client/daemon-environment.js +139 -8
- package/dist/src/daemon/server/handle-client-env.d.ts +11 -1
- package/dist/src/daemon/server/handle-client-env.js +96 -5
- package/dist/src/daemon/server/handle-configure-ai-agents.js +2 -1
- package/dist/src/daemon/server/latest-nx.js +2 -1
- package/dist/src/daemon/server/server.js +1 -1
- package/dist/src/daemon/socket-utils.d.ts +9 -1
- package/dist/src/daemon/socket-utils.js +25 -0
- package/dist/src/executors/run-commands/running-tasks.d.ts +1 -0
- package/dist/src/executors/run-commands/running-tasks.js +69 -17
- package/dist/src/executors/run-script/run-script.impl.js +11 -3
- package/dist/src/native/index.d.ts +1 -1
- package/dist/src/native/index.js +31 -3
- package/dist/src/native/native-file-cache-location.js +10 -4
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/native/transform-objects.js +5 -1
- package/dist/src/nx-cloud/update-manager.d.ts +6 -1
- package/dist/src/nx-cloud/update-manager.js +39 -12
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +22 -34
- package/dist/src/plugins/js/lock-file/project-graph-pruning.d.ts +7 -0
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +31 -5
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +1 -1
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +6 -5
- package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -1
- package/dist/src/plugins/js/package-json/create-package-json.js +53 -16
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +7 -1
- package/dist/src/project-graph/affected/affected-tasks.js +29 -1
- package/dist/src/project-graph/plugins/get-plugins.d.ts +2 -0
- package/dist/src/project-graph/plugins/get-plugins.js +17 -2
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +4 -2
- package/dist/src/tasks-runner/fork.js +4 -2
- package/dist/src/tasks-runner/run-command.d.ts +4 -1
- package/dist/src/tasks-runner/run-command.js +6 -4
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +3 -2
- package/dist/src/tasks-runner/running-tasks/batch-process.js +7 -3
- package/dist/src/tasks-runner/task-orchestrator.d.ts +1 -0
- package/dist/src/tasks-runner/task-orchestrator.js +12 -3
- package/dist/src/tasks-runner/tasks-runner.d.ts +5 -0
- package/dist/src/ultracache/overrides.d.ts +1 -1
- package/dist/src/ultracache/overrides.js +1 -1
- package/dist/src/ultracache/report.d.ts +1 -1
- package/dist/src/ultracache/report.js +4 -1
- package/dist/src/utils/cache-directory.d.ts +3 -0
- package/dist/src/utils/cache-directory.js +105 -25
- package/dist/src/utils/child-process.d.ts +8 -1
- package/dist/src/utils/child-process.js +24 -0
- package/dist/src/utils/compile-cache.d.ts +6 -8
- package/dist/src/utils/compile-cache.js +23 -16
- package/dist/src/utils/min-release-age/packument.d.ts +2 -1
- package/dist/src/utils/min-release-age/packument.js +5 -3
- package/dist/src/utils/nx-tmp-dir.d.ts +14 -2
- package/dist/src/utils/nx-tmp-dir.js +26 -2
- package/dist/src/utils/owned-private-dir.d.ts +22 -0
- package/dist/src/utils/owned-private-dir.js +148 -0
- package/dist/src/utils/package-json.d.ts +8 -1
- package/dist/src/utils/package-json.js +77 -34
- package/dist/src/utils/package-manager.d.ts +25 -0
- package/dist/src/utils/package-manager.js +244 -9
- package/dist/src/utils/path.d.ts +4 -0
- package/dist/src/utils/path.js +8 -0
- package/dist/src/utils/redact-url-credentials.js +3 -2
- package/dist/src/utils/wait-for-socket-connection.d.ts +2 -0
- package/dist/src/utils/wait-for-socket-connection.js +3 -3
- package/package.json +11 -11
- package/schemas/migrations-schema.json +1 -1
|
@@ -8,7 +8,18 @@ exports.getAppliedDaemonClientEnv = getAppliedDaemonClientEnv;
|
|
|
8
8
|
exports.applyDaemonEnvFromClient = applyDaemonEnvFromClient;
|
|
9
9
|
exports.normalizeDaemonEnvironmentForGraph = normalizeDaemonEnvironmentForGraph;
|
|
10
10
|
exports.getChangedEnvKeys = getChangedEnvKeys;
|
|
11
|
+
exports.hasBerryBinFolders = hasBerryBinFolders;
|
|
12
|
+
exports.withoutBerryBinFoldersOnPath = withoutBerryBinFoldersOnPath;
|
|
13
|
+
exports.withoutBerryBinFolders = withoutBerryBinFolders;
|
|
14
|
+
exports.withTrustedBerryBinFolders = withTrustedBerryBinFolders;
|
|
15
|
+
exports.withLiveBerryBinFolders = withLiveBerryBinFolders;
|
|
16
|
+
exports.setLiveClientBerryEnv = setLiveClientBerryEnv;
|
|
17
|
+
exports.getLiveClientBerryEnv = getLiveClientBerryEnv;
|
|
18
|
+
exports.adoptBerryBinFoldersOnPath = adoptBerryBinFoldersOnPath;
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
11
21
|
const file_hasher_1 = require("../../hasher/file-hasher");
|
|
22
|
+
const owned_private_dir_1 = require("../../utils/owned-private-dir");
|
|
12
23
|
const DAEMON_ENV_REQUIRED_SETTINGS = {
|
|
13
24
|
NX_PROJECT_GLOB_CACHE: 'false',
|
|
14
25
|
NX_CACHE_PROJECTS_CONFIG: 'false',
|
|
@@ -57,6 +68,9 @@ const DAEMON_ENV_VARS_EXCLUSIONS = new Set([
|
|
|
57
68
|
// to the next client's connection. Pinned at daemon spawn instead; see
|
|
58
69
|
// getDaemonSpawnEnv.
|
|
59
70
|
'NX_MAX_MESSAGE_SIZE',
|
|
71
|
+
// Read when the daemon resolves its cache directories at startup. Pinned at
|
|
72
|
+
// spawn instead, so one client's opt-out never reaches later clients.
|
|
73
|
+
'NX_ALLOW_INSECURE_DIRECTORIES',
|
|
60
74
|
// Nx UI/logging vars (don't affect graph structure)
|
|
61
75
|
'NX_TUI',
|
|
62
76
|
'NX_TUI_AUTO_EXIT',
|
|
@@ -300,12 +314,14 @@ function getDaemonClientEnvGeneration() {
|
|
|
300
314
|
* the pin, a root without markers under an ancestor that has them
|
|
301
315
|
* resolves to the ancestor and the daemon publishes its socket under the
|
|
302
316
|
* wrong workspace.
|
|
303
|
-
* - NX_MAX_MESSAGE_SIZE: excluded from
|
|
304
|
-
* here holds for the daemon's whole
|
|
305
|
-
* daemon restart (`nx reset`).
|
|
317
|
+
* - NX_MAX_MESSAGE_SIZE and NX_ALLOW_INSECURE_DIRECTORIES: excluded from
|
|
318
|
+
* reflection (see above), so the value here holds for the daemon's whole
|
|
319
|
+
* lifetime. Changing either therefore needs a daemon restart (`nx reset`).
|
|
320
|
+
* - TMPDIR: without it, os.tmpdir() in the daemon and every process it
|
|
321
|
+
* starts falls back to the shared /tmp instead of the user's own.
|
|
306
322
|
*/
|
|
307
323
|
function getDaemonSpawnEnv() {
|
|
308
|
-
const env = getDaemonEnv();
|
|
324
|
+
const env = withoutBerryBinFoldersOnPath(getDaemonEnv());
|
|
309
325
|
if (process.env.ELECTRON_RUN_AS_NODE !== undefined) {
|
|
310
326
|
env.ELECTRON_RUN_AS_NODE = process.env.ELECTRON_RUN_AS_NODE;
|
|
311
327
|
}
|
|
@@ -315,6 +331,13 @@ function getDaemonSpawnEnv() {
|
|
|
315
331
|
if (process.env.NX_MAX_MESSAGE_SIZE !== undefined) {
|
|
316
332
|
env.NX_MAX_MESSAGE_SIZE = process.env.NX_MAX_MESSAGE_SIZE;
|
|
317
333
|
}
|
|
334
|
+
if (process.env.TMPDIR !== undefined) {
|
|
335
|
+
env.TMPDIR = process.env.TMPDIR;
|
|
336
|
+
}
|
|
337
|
+
if (process.env.NX_ALLOW_INSECURE_DIRECTORIES !== undefined) {
|
|
338
|
+
env.NX_ALLOW_INSECURE_DIRECTORIES =
|
|
339
|
+
process.env.NX_ALLOW_INSECURE_DIRECTORIES;
|
|
340
|
+
}
|
|
318
341
|
return env;
|
|
319
342
|
}
|
|
320
343
|
/**
|
|
@@ -381,10 +404,10 @@ function applyDaemonEnvFromClient(newEnv) {
|
|
|
381
404
|
const BERRY_BIN_FOLDER_GRAPH_IDENTITY = '<YARN_BERRY_BIN_FOLDER>';
|
|
382
405
|
/**
|
|
383
406
|
* Yarn Berry creates a fresh BERRY_BIN_FOLDER for every invocation and puts it
|
|
384
|
-
* first on PATH.
|
|
385
|
-
*
|
|
386
|
-
* two invocations whose environments differ only by it
|
|
387
|
-
* graph. Strips the folder from PATH and pins the var to a sentinel so such
|
|
407
|
+
* first on PATH. Plugin workers, and the daemon's own PATH when it runs plugins
|
|
408
|
+
* itself, get its wrappers only while a connected client carries it. Its random name is not
|
|
409
|
+
* project-graph identity: two invocations whose environments differ only by it
|
|
410
|
+
* would compute the same graph. Strips the folder from PATH and pins the var to a sentinel so such
|
|
388
411
|
* environments compare equal. Returns a copy; never mutates runtime env.
|
|
389
412
|
*/
|
|
390
413
|
function normalizeDaemonEnvironmentForGraph(env, platform = process.platform) {
|
|
@@ -420,3 +443,111 @@ function getChangedEnvKeys(before, after) {
|
|
|
420
443
|
}
|
|
421
444
|
return changedKeys;
|
|
422
445
|
}
|
|
446
|
+
const BERRY_BIN_FOLDER_NAME = /^xfs-[0-9a-f]{8}$/i;
|
|
447
|
+
function isBerryBinFolder(entry) {
|
|
448
|
+
return BERRY_BIN_FOLDER_NAME.test((0, node_path_1.basename)(entry));
|
|
449
|
+
}
|
|
450
|
+
function isTrustedBerryBinFolder(dir) {
|
|
451
|
+
if (!(0, owned_private_dir_1.isOwnedRealDirectory)(dir)) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
if (process.platform === 'win32') {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
try {
|
|
458
|
+
return ((0, node_fs_1.lstatSync)(dir).mode & 0o022) === 0;
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function filterBerryBinFoldersOnPath(env, keep) {
|
|
465
|
+
const filtered = { ...env };
|
|
466
|
+
for (const key of Object.keys(filtered)) {
|
|
467
|
+
if (key.toUpperCase() === 'PATH' && filtered[key]) {
|
|
468
|
+
filtered[key] = filtered[key]
|
|
469
|
+
.split(node_path_1.delimiter)
|
|
470
|
+
.filter((entry) => !isBerryBinFolder(entry) || keep(entry))
|
|
471
|
+
.join(node_path_1.delimiter);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return filtered;
|
|
475
|
+
}
|
|
476
|
+
function hasBerryBinFolders(env) {
|
|
477
|
+
return env.BERRY_BIN_FOLDER !== undefined || hasBerryBinFoldersOnPath(env);
|
|
478
|
+
}
|
|
479
|
+
function hasBerryBinFoldersOnPath(env) {
|
|
480
|
+
return Object.keys(env).some((key) => key.toUpperCase() === 'PATH' &&
|
|
481
|
+
!!env[key]?.split(node_path_1.delimiter).some(isBerryBinFolder));
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Yarn Berry deletes its per-invocation bin folders when the command exits, so
|
|
485
|
+
* a process that can outlive the command must not resolve binaries through
|
|
486
|
+
* them. BERRY_BIN_FOLDER is kept: Yarn only ever writes it, and graph identity
|
|
487
|
+
* is computed from it.
|
|
488
|
+
*/
|
|
489
|
+
function withoutBerryBinFoldersOnPath(env) {
|
|
490
|
+
return filterBerryBinFoldersOnPath(env, () => false);
|
|
491
|
+
}
|
|
492
|
+
function withoutBerryBinFolders(env) {
|
|
493
|
+
const stripped = withoutBerryBinFoldersOnPath(env);
|
|
494
|
+
delete stripped.BERRY_BIN_FOLDER;
|
|
495
|
+
return stripped;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* For work a live client is waiting on: its Yarn command, and so its bin
|
|
499
|
+
* folders, are still alive, but only folders that are ours and closed to other
|
|
500
|
+
* users are kept.
|
|
501
|
+
*/
|
|
502
|
+
function withTrustedBerryBinFolders(env) {
|
|
503
|
+
return withBerryBinFoldersKept(env, isTrustedBerryBinFolder);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Like withTrustedBerryBinFolders, but also drops every bin folder outside
|
|
507
|
+
* `liveFolders`.
|
|
508
|
+
*/
|
|
509
|
+
function withLiveBerryBinFolders(env, liveFolders) {
|
|
510
|
+
return withBerryBinFoldersKept(env, (dir) => liveFolders.has(dir) && isTrustedBerryBinFolder(dir));
|
|
511
|
+
}
|
|
512
|
+
function withBerryBinFoldersKept(env, keep) {
|
|
513
|
+
const kept = filterBerryBinFoldersOnPath(env, keep);
|
|
514
|
+
if (kept.BERRY_BIN_FOLDER && !keep(kept.BERRY_BIN_FOLDER)) {
|
|
515
|
+
delete kept.BERRY_BIN_FOLDER;
|
|
516
|
+
}
|
|
517
|
+
return kept;
|
|
518
|
+
}
|
|
519
|
+
let liveClientBerryEnv = {};
|
|
520
|
+
/**
|
|
521
|
+
* The PATH and BERRY_BIN_FOLDER of the env the daemon applied last, keeping
|
|
522
|
+
* only the bin folders a connected client still carries. The daemon's own PATH
|
|
523
|
+
* lacks the client's bin folders, so workers spawned for that client's request,
|
|
524
|
+
* and a daemon that starts running plugins itself, take them here.
|
|
525
|
+
*/
|
|
526
|
+
function setLiveClientBerryEnv(env) {
|
|
527
|
+
liveClientBerryEnv = {};
|
|
528
|
+
if (!env || !hasBerryBinFolders(env)) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
for (const key of Object.keys(env)) {
|
|
532
|
+
if (key === 'BERRY_BIN_FOLDER' || key.toUpperCase() === 'PATH') {
|
|
533
|
+
liveClientBerryEnv[key] = env[key];
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function getLiveClientBerryEnv() {
|
|
538
|
+
return { ...liveClientBerryEnv };
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Replaces the bin folders on this process's PATH with those on `env`'s PATH,
|
|
542
|
+
* for a daemon that runs plugins itself rather than in workers.
|
|
543
|
+
*/
|
|
544
|
+
function adoptBerryBinFoldersOnPath(env) {
|
|
545
|
+
const source = hasBerryBinFoldersOnPath(env)
|
|
546
|
+
? env
|
|
547
|
+
: withoutBerryBinFoldersOnPath(process.env);
|
|
548
|
+
for (const key of Object.keys(source)) {
|
|
549
|
+
if (key.toUpperCase() === 'PATH') {
|
|
550
|
+
process.env[key] = source[key];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
1
2
|
export declare function _setEnvForwardTimeoutMs(ms: number): void;
|
|
3
|
+
type ClientSocket = EventEmitter & {
|
|
4
|
+
destroyed?: boolean;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Applies an env-carrying client message to the daemon. Must be awaited
|
|
4
8
|
* before dispatching the message's handler: plugin workers key their disk
|
|
5
9
|
* caches on their own process env, so a graph request must not reach a worker
|
|
6
10
|
* whose env still reflects the previous client.
|
|
7
11
|
*/
|
|
8
|
-
export declare function handleClientEnv(env: Record<string, string
|
|
12
|
+
export declare function handleClientEnv(env: Record<string, string>, client?: ClientSocket): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* The daemon's env plus the trusted bin folders a connected client still
|
|
15
|
+
* carries, for a command the daemon starts now on a client's behalf.
|
|
16
|
+
*/
|
|
17
|
+
export declare function envWithLiveBerryBinFolders(): NodeJS.ProcessEnv;
|
|
18
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._setEnvForwardTimeoutMs = _setEnvForwardTimeoutMs;
|
|
4
4
|
exports.handleClientEnv = handleClientEnv;
|
|
5
|
+
exports.envWithLiveBerryBinFolders = envWithLiveBerryBinFolders;
|
|
5
6
|
const get_plugins_1 = require("../../project-graph/plugins/get-plugins");
|
|
6
7
|
const daemon_environment_1 = require("../client/daemon-environment");
|
|
7
8
|
const logger_1 = require("../logger");
|
|
@@ -15,13 +16,16 @@ function _setEnvForwardTimeoutMs(ms) {
|
|
|
15
16
|
envForwardTimeoutMs = ms;
|
|
16
17
|
}
|
|
17
18
|
let inFlightApply;
|
|
19
|
+
// Connected clients that carry Yarn Berry bin folders, by BERRY_BIN_FOLDER.
|
|
20
|
+
const liveBerryClients = new Map();
|
|
21
|
+
let workersHoldBerryFolders = false;
|
|
18
22
|
/**
|
|
19
23
|
* Applies an env-carrying client message to the daemon. Must be awaited
|
|
20
24
|
* before dispatching the message's handler: plugin workers key their disk
|
|
21
25
|
* caches on their own process env, so a graph request must not reach a worker
|
|
22
26
|
* whose env still reflects the previous client.
|
|
23
27
|
*/
|
|
24
|
-
async function handleClientEnv(env) {
|
|
28
|
+
async function handleClientEnv(env, client) {
|
|
25
29
|
// A client whose env matches one an in-flight apply already wrote to
|
|
26
30
|
// process.env sees zero changed keys, yet the graph cache is only discarded
|
|
27
31
|
// once that apply's forwarding completes. Wait for it so such a client
|
|
@@ -29,19 +33,32 @@ async function handleClientEnv(env) {
|
|
|
29
33
|
while (inFlightApply) {
|
|
30
34
|
await inFlightApply;
|
|
31
35
|
}
|
|
36
|
+
trackLiveClient(env, client);
|
|
37
|
+
const keepBerryFolders = isBerryFolderLive(env);
|
|
38
|
+
(0, daemon_environment_1.setLiveClientBerryEnv)(keepBerryFolders ? env : undefined);
|
|
39
|
+
// Yarn Berry's bin folders outlive neither the client nor its request, while
|
|
40
|
+
// the daemon and anything it starts in the background do.
|
|
41
|
+
const daemonEnv = (0, daemon_environment_1.withoutBerryBinFoldersOnPath)(env);
|
|
42
|
+
hostBerryBinFoldersInProcess({});
|
|
32
43
|
const graphEnvBefore = (0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(process.env);
|
|
33
44
|
const previousClientEnv = (0, daemon_environment_1.getAppliedDaemonClientEnv)()?.env;
|
|
34
|
-
const changedEnvKeys = (0, daemon_environment_1.applyDaemonEnvFromClient)(
|
|
45
|
+
const changedEnvKeys = (0, daemon_environment_1.applyDaemonEnvFromClient)(daemonEnv);
|
|
46
|
+
const graphEnvAfter = (0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(process.env);
|
|
47
|
+
hostBerryBinFoldersInProcess(keepBerryFolders ? (0, daemon_environment_1.withTrustedBerryBinFolders)(env) : {});
|
|
35
48
|
if (changedEnvKeys.length === 0) {
|
|
49
|
+
// An unchanged env can still owe workers the folders a disconnect took.
|
|
50
|
+
if (keepBerryFolders && !workersHoldBerryFolders) {
|
|
51
|
+
await runApply(forwardEnvToPluginWorkers(workerEnv(env, true)));
|
|
52
|
+
}
|
|
36
53
|
return;
|
|
37
54
|
}
|
|
38
55
|
// Runtime changes always reach the workers, but only changes that survive
|
|
39
56
|
// graph normalization (e.g. Yarn Berry's per-invocation BERRY_BIN_FOLDER
|
|
40
57
|
// does not) invalidate the computed graph.
|
|
41
58
|
const graphChangedKeys = new Set([
|
|
42
|
-
...(0, daemon_environment_1.getChangedEnvKeys)(graphEnvBefore,
|
|
59
|
+
...(0, daemon_environment_1.getChangedEnvKeys)(graphEnvBefore, graphEnvAfter),
|
|
43
60
|
...(previousClientEnv
|
|
44
|
-
? (0, daemon_environment_1.getChangedEnvKeys)((0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(previousClientEnv), (0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(
|
|
61
|
+
? (0, daemon_environment_1.getChangedEnvKeys)((0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(previousClientEnv), (0, daemon_environment_1.normalizeDaemonEnvironmentForGraph)(daemonEnv))
|
|
45
62
|
: []),
|
|
46
63
|
]);
|
|
47
64
|
if (graphChangedKeys.size > 0) {
|
|
@@ -52,7 +69,9 @@ async function handleClientEnv(env) {
|
|
|
52
69
|
else {
|
|
53
70
|
logger_1.serverLogger.log(`Env variable refresh changed only runtime values (${changedEnvKeys.join(', ')}); graph identity is unchanged, keeping the cached graph.`);
|
|
54
71
|
}
|
|
55
|
-
|
|
72
|
+
await runApply(applyEnvChange(workerEnv(env, keepBerryFolders), graphChangedKeys.size > 0));
|
|
73
|
+
}
|
|
74
|
+
async function runApply(apply) {
|
|
56
75
|
inFlightApply = apply;
|
|
57
76
|
try {
|
|
58
77
|
await apply;
|
|
@@ -63,6 +82,78 @@ async function handleClientEnv(env) {
|
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
}
|
|
85
|
+
function trackLiveClient(env, client) {
|
|
86
|
+
// A socket that closed while this message waited will not emit 'close' again.
|
|
87
|
+
if (!client ||
|
|
88
|
+
client.destroyed ||
|
|
89
|
+
!(0, daemon_environment_1.hasBerryBinFolders)(env) ||
|
|
90
|
+
liveBerryClients.has(client)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
liveBerryClients.set(client, env.BERRY_BIN_FOLDER);
|
|
94
|
+
client.once('close', () => {
|
|
95
|
+
liveBerryClients.delete(client);
|
|
96
|
+
const liveClientEnv = (0, daemon_environment_1.getLiveClientBerryEnv)();
|
|
97
|
+
if (!isBerryFolderLive(liveClientEnv)) {
|
|
98
|
+
(0, daemon_environment_1.setLiveClientBerryEnv)((0, daemon_environment_1.withLiveBerryBinFolders)(liveClientEnv, liveBerryFolders()));
|
|
99
|
+
}
|
|
100
|
+
dropUnownedBerryFolders().catch((e) => {
|
|
101
|
+
logger_1.serverLogger.log(`Failed to drop Yarn Berry bin folders from plugin workers: ${e.message}`);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function isBerryFolderLive(env) {
|
|
106
|
+
return ((0, daemon_environment_1.hasBerryBinFolders)(env) &&
|
|
107
|
+
[...liveBerryClients.values()].includes(env.BERRY_BIN_FOLDER));
|
|
108
|
+
}
|
|
109
|
+
function liveBerryFolders() {
|
|
110
|
+
return new Set([...liveBerryClients.values()].filter((folder) => folder !== undefined));
|
|
111
|
+
}
|
|
112
|
+
// A daemon that runs plugins itself is one more plugin host, so its PATH holds
|
|
113
|
+
// the folders its workers do. The graph is computed without them.
|
|
114
|
+
function hostBerryBinFoldersInProcess(env) {
|
|
115
|
+
if ((0, get_plugins_1.daemonHostsPluginsInProcess)()) {
|
|
116
|
+
(0, daemon_environment_1.adoptBerryBinFoldersOnPath)(env);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The daemon's env plus the trusted bin folders a connected client still
|
|
121
|
+
* carries, for a command the daemon starts now on a client's behalf.
|
|
122
|
+
*/
|
|
123
|
+
function envWithLiveBerryBinFolders() {
|
|
124
|
+
return (0, daemon_environment_1.withLiveBerryBinFolders)({ ...process.env, ...(0, daemon_environment_1.getLiveClientBerryEnv)() }, liveBerryFolders());
|
|
125
|
+
}
|
|
126
|
+
function workerEnv(env, keepBerryFolders) {
|
|
127
|
+
workersHoldBerryFolders = keepBerryFolders;
|
|
128
|
+
return (keepBerryFolders
|
|
129
|
+
? (0, daemon_environment_1.withTrustedBerryBinFolders)(env)
|
|
130
|
+
: (0, daemon_environment_1.withoutBerryBinFolders)(env));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Once no connected client carries the applied env's bin folders, their Yarn
|
|
134
|
+
* command is about to delete them, so plugin workers stop resolving through
|
|
135
|
+
* them. A nested Yarn command's PATH also carries its parent's folder, which
|
|
136
|
+
* stays while the parent's client is connected. A newer client's apply either
|
|
137
|
+
* lands after this forward or, if it ran while this waited, has already
|
|
138
|
+
* forwarded its own env and is left in place.
|
|
139
|
+
*/
|
|
140
|
+
async function dropUnownedBerryFolders() {
|
|
141
|
+
while (inFlightApply) {
|
|
142
|
+
await inFlightApply;
|
|
143
|
+
}
|
|
144
|
+
const appliedEnv = (0, daemon_environment_1.getAppliedDaemonClientEnv)()?.env;
|
|
145
|
+
if (!appliedEnv ||
|
|
146
|
+
!workersHoldBerryFolders ||
|
|
147
|
+
isBerryFolderLive(appliedEnv)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// The applied env's PATH never held the bin folders; the live client env does.
|
|
151
|
+
const keptEnv = (0, daemon_environment_1.withLiveBerryBinFolders)({ ...appliedEnv, ...(0, daemon_environment_1.getLiveClientBerryEnv)() }, liveBerryFolders());
|
|
152
|
+
(0, daemon_environment_1.setLiveClientBerryEnv)(keptEnv);
|
|
153
|
+
hostBerryBinFoldersInProcess(keptEnv);
|
|
154
|
+
workersHoldBerryFolders = (0, daemon_environment_1.hasBerryBinFolders)(keptEnv);
|
|
155
|
+
await runApply(forwardEnvToPluginWorkers(keptEnv));
|
|
156
|
+
}
|
|
66
157
|
async function applyEnvChange(env, invalidateGraph) {
|
|
67
158
|
await forwardEnvToPluginWorkers(env);
|
|
68
159
|
if (!invalidateGraph) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleGetConfigureAiAgentsStatus = handleGetConfigureAiAgentsStatus;
|
|
4
4
|
exports.handleResetConfigureAiAgentsStatus = handleResetConfigureAiAgentsStatus;
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const workspace_root_1 = require("../../utils/workspace-root");
|
|
7
8
|
const latest_nx_1 = require("./latest-nx");
|
|
@@ -79,7 +80,7 @@ async function computeAgentStatuses() {
|
|
|
79
80
|
paths: [tmpPath],
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
|
-
const { getAgentConfigurations, supportedAgents } = await import(modulePath);
|
|
83
|
+
const { getAgentConfigurations, supportedAgents } = await import((0, node_url_1.pathToFileURL)(modulePath).href);
|
|
83
84
|
const { fullyConfiguredAgents, partiallyConfiguredAgents, nonConfiguredAgents, } = await getAgentConfigurations([...supportedAgents], workspace_root_1.workspaceRoot);
|
|
84
85
|
const toStatusInfo = (agent) => ({
|
|
85
86
|
name: agent.name,
|
|
@@ -10,6 +10,7 @@ const package_manager_1 = require("../../utils/package-manager");
|
|
|
10
10
|
const provenance_1 = require("../../utils/provenance");
|
|
11
11
|
const workspace_root_1 = require("../../utils/workspace-root");
|
|
12
12
|
const logger_1 = require("../logger");
|
|
13
|
+
const handle_client_env_1 = require("./handle-client-env");
|
|
13
14
|
// Module-level state - persists across invocations within daemon lifecycle
|
|
14
15
|
let latestNxTmpPath = null;
|
|
15
16
|
let cleanupFn = null;
|
|
@@ -31,7 +32,7 @@ async function getLatestNxTmpPath() {
|
|
|
31
32
|
try {
|
|
32
33
|
logger_1.serverLogger.log('[LATEST-NX]: Pulling latest Nx...');
|
|
33
34
|
const version = await (0, provenance_1.resolveVersionWithProvenance)('nx', 'latest');
|
|
34
|
-
const result = await (0, package_json_1.installPackageToTmpAsync)('nx', version, (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot));
|
|
35
|
+
const result = await (0, package_json_1.installPackageToTmpAsync)('nx', version, (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot), { env: handle_client_env_1.envWithLiveBerryBinFolders });
|
|
35
36
|
latestNxTmpPath = result.tempDir;
|
|
36
37
|
cleanupFn = result.cleanup;
|
|
37
38
|
logger_1.serverLogger.log('[LATEST-NX]: Successfully pulled latest Nx to', latestNxTmpPath);
|
|
@@ -140,7 +140,7 @@ async function handleMessage(socket, data) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
if ((0, daemon_message_1.isDaemonMessage)(payload) && payload.env) {
|
|
143
|
-
await (0, handle_client_env_1.handleClientEnv)(payload.env);
|
|
143
|
+
await (0, handle_client_env_1.handleClientEnv)(payload.env, socket);
|
|
144
144
|
}
|
|
145
145
|
if (payload.type === 'PING') {
|
|
146
146
|
await handleResult(socket, 'PING', () => Promise.resolve({ response: true, description: 'ping' }), mode);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Socket } from 'net';
|
|
2
2
|
export declare const isWindows: boolean;
|
|
3
3
|
/**
|
|
4
4
|
* For IPC with the daemon server we use unix sockets or windows named pipes,
|
|
@@ -15,6 +15,14 @@ export declare const isWindows: boolean;
|
|
|
15
15
|
export declare const getFullOsSocketPath: () => string;
|
|
16
16
|
export declare const getForkedProcessOsSocketPath: (id: string) => string;
|
|
17
17
|
export declare const getPluginOsSocketPath: (id: string) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Dial a recorded daemon socket only if its directory is ours and owner-only,
|
|
20
|
+
* and every level above it passes `isSafeAncestry`. Judging the directory alone
|
|
21
|
+
* lets whoever controls a level above it swap the path before the dial.
|
|
22
|
+
* A refusal fails the socket like any failed connect, with the directory's
|
|
23
|
+
* errno when it cannot be inspected and ENOENT otherwise.
|
|
24
|
+
*/
|
|
25
|
+
export declare function connectToDaemonSocket(socketPath: string, onConnect?: () => void): Socket;
|
|
18
26
|
export declare function killSocketOrPath(): void;
|
|
19
27
|
export declare function serializeResult(error: Error | null, serializedProjectGraph: string | null, serializedSourceMaps: string | null): string | null;
|
|
20
28
|
/**
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPluginOsSocketPath = exports.getForkedProcessOsSocketPath = exports.getFullOsSocketPath = exports.isWindows = void 0;
|
|
4
|
+
exports.connectToDaemonSocket = connectToDaemonSocket;
|
|
4
5
|
exports.killSocketOrPath = killSocketOrPath;
|
|
5
6
|
exports.serializeResult = serializeResult;
|
|
6
7
|
exports.serializeWithFallback = serializeWithFallback;
|
|
7
8
|
exports.serialize = serialize;
|
|
8
9
|
exports.sendMessage = sendMessage;
|
|
9
10
|
const fs_1 = require("fs");
|
|
11
|
+
const net_1 = require("net");
|
|
10
12
|
const os_1 = require("os");
|
|
13
|
+
const path_1 = require("path");
|
|
11
14
|
const tmp_dir_1 = require("./tmp-dir");
|
|
12
15
|
const serializable_error_1 = require("../utils/serializable-error");
|
|
13
16
|
const is_v8_serializer_enabled_1 = require("./is-v8-serializer-enabled");
|
|
14
17
|
const v8_1 = require("v8");
|
|
15
18
|
const consume_messages_from_socket_1 = require("../utils/consume-messages-from-socket");
|
|
19
|
+
const owned_private_dir_1 = require("../utils/owned-private-dir");
|
|
16
20
|
exports.isWindows = (0, os_1.platform)() === 'win32';
|
|
17
21
|
/**
|
|
18
22
|
* For IPC with the daemon server we use unix sockets or windows named pipes,
|
|
@@ -32,6 +36,27 @@ const getForkedProcessOsSocketPath = (id) => (0, tmp_dir_1.getForkedProcessSocke
|
|
|
32
36
|
exports.getForkedProcessOsSocketPath = getForkedProcessOsSocketPath;
|
|
33
37
|
const getPluginOsSocketPath = (id) => (0, tmp_dir_1.getPluginSocketPath)(id);
|
|
34
38
|
exports.getPluginOsSocketPath = getPluginOsSocketPath;
|
|
39
|
+
/**
|
|
40
|
+
* Dial a recorded daemon socket only if its directory is ours and owner-only,
|
|
41
|
+
* and every level above it passes `isSafeAncestry`. Judging the directory alone
|
|
42
|
+
* lets whoever controls a level above it swap the path before the dial.
|
|
43
|
+
* A refusal fails the socket like any failed connect, with the directory's
|
|
44
|
+
* errno when it cannot be inspected and ENOENT otherwise.
|
|
45
|
+
*/
|
|
46
|
+
function connectToDaemonSocket(socketPath, onConnect) {
|
|
47
|
+
// A named pipe has no directory to judge.
|
|
48
|
+
const verdict = exports.isWindows ? undefined : judgeSocketDir((0, path_1.dirname)(socketPath));
|
|
49
|
+
if (verdict?.status === 'refused') {
|
|
50
|
+
const { refusal } = verdict;
|
|
51
|
+
const code = (refusal.kind === 'not-inspectable' && refusal.code) || 'ENOENT';
|
|
52
|
+
return new net_1.Socket().destroy(Object.assign(new Error(`connect ${code} ${socketPath}: ${(0, owned_private_dir_1.describeRefusal)(refusal)}`), { code }));
|
|
53
|
+
}
|
|
54
|
+
return (0, net_1.connect)(socketPath, onConnect);
|
|
55
|
+
}
|
|
56
|
+
function judgeSocketDir(dir) {
|
|
57
|
+
const ancestry = (0, owned_private_dir_1.isSafeAncestry)((0, path_1.dirname)(dir));
|
|
58
|
+
return ancestry.status === 'refused' ? ancestry : (0, owned_private_dir_1.isOwnedPrivateDir)(dir);
|
|
59
|
+
}
|
|
35
60
|
function killSocketOrPath() {
|
|
36
61
|
try {
|
|
37
62
|
(0, fs_1.unlinkSync)((0, exports.getFullOsSocketPath)());
|
|
@@ -36,6 +36,7 @@ export declare class SeriallyRunningTasks implements RunningTask {
|
|
|
36
36
|
private code;
|
|
37
37
|
private error;
|
|
38
38
|
private outputCallbacks;
|
|
39
|
+
private killSignal;
|
|
39
40
|
private exited;
|
|
40
41
|
private exitTerminalOutput;
|
|
41
42
|
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext, tuiEnabled: boolean, task: Pick<Task, 'id' | 'ultracache'>, baseEnv?: NodeJS.ProcessEnv);
|