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
|
@@ -14,6 +14,7 @@ const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
|
|
|
14
14
|
const task_env_1 = require("../../tasks-runner/task-env");
|
|
15
15
|
const tokens_1 = require("../../tasks-runner/tokens");
|
|
16
16
|
const task_io_service_1 = require("../../tasks-runner/task-io-service");
|
|
17
|
+
const child_process_2 = require("../../utils/child-process");
|
|
17
18
|
const exit_codes_1 = require("../../utils/exit-codes");
|
|
18
19
|
const output_1 = require("../../utils/output");
|
|
19
20
|
/**
|
|
@@ -110,6 +111,12 @@ class ParallelRunningTasks {
|
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
childProcess.onExit((code, terminalOutput) => {
|
|
114
|
+
// A failed command reports only once its output is read, so
|
|
115
|
+
// readyWhen text a sibling prints meanwhile must not hide it.
|
|
116
|
+
if (code === 0 &&
|
|
117
|
+
this.childProcesses.some((p) => p !== childProcess && p.exitedWithFailure)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
113
120
|
res({
|
|
114
121
|
childProcess,
|
|
115
122
|
result: { code, terminalOutput },
|
|
@@ -137,9 +144,14 @@ class ParallelRunningTasks {
|
|
|
137
144
|
}
|
|
138
145
|
else {
|
|
139
146
|
const runningProcesses = new Set();
|
|
140
|
-
let
|
|
141
|
-
let failureDetails = null;
|
|
147
|
+
let failedProcess = null;
|
|
142
148
|
const terminalOutputs = new Map();
|
|
149
|
+
const failFast = (childProcess) => {
|
|
150
|
+
if (failedProcess)
|
|
151
|
+
return;
|
|
152
|
+
failedProcess = childProcess;
|
|
153
|
+
this.terminateRemainingProcesses(runningProcesses, childProcess);
|
|
154
|
+
};
|
|
143
155
|
await Promise.allSettled(this.childProcesses.map(async (childProcess) => {
|
|
144
156
|
runningProcesses.add(childProcess);
|
|
145
157
|
childProcess.onOutput((terminalOutput) => {
|
|
@@ -147,20 +159,20 @@ class ParallelRunningTasks {
|
|
|
147
159
|
cb(terminalOutput);
|
|
148
160
|
}
|
|
149
161
|
});
|
|
162
|
+
// Results wait for the output to drain, which a descendant holding
|
|
163
|
+
// the pipes can stretch to a second.
|
|
164
|
+
childProcess.onFailedExit(() => failFast(childProcess));
|
|
150
165
|
const { code, terminalOutput } = await childProcess.getResults();
|
|
151
166
|
terminalOutputs.set(childProcess, terminalOutput);
|
|
152
|
-
if (code !== 0
|
|
153
|
-
|
|
154
|
-
failureDetails = { childProcess, code, terminalOutput };
|
|
155
|
-
// Immediately terminate all other running processes
|
|
156
|
-
this.terminateRemainingProcesses(runningProcesses, childProcess);
|
|
167
|
+
if (code !== 0) {
|
|
168
|
+
failFast(childProcess);
|
|
157
169
|
}
|
|
158
170
|
runningProcesses.delete(childProcess);
|
|
159
171
|
}));
|
|
160
172
|
let terminalOutput = Array.from(terminalOutputs.values()).join('\r\n');
|
|
161
|
-
if (
|
|
173
|
+
if (failedProcess) {
|
|
162
174
|
// Add failure message
|
|
163
|
-
const warning = commandExitedNonZeroWarning(
|
|
175
|
+
const warning = commandExitedNonZeroWarning(failedProcess.command);
|
|
164
176
|
terminalOutput += warning;
|
|
165
177
|
streamChunk(warning, this.streamOutput, process.stderr);
|
|
166
178
|
this.emitExit(1, terminalOutput);
|
|
@@ -189,6 +201,9 @@ class SeriallyRunningTasks {
|
|
|
189
201
|
this.exitCallbacks = [];
|
|
190
202
|
this.code = 0;
|
|
191
203
|
this.outputCallbacks = [];
|
|
204
|
+
// A command can be killed after it exits, while its output drains. The
|
|
205
|
+
// signal then reaches no process, so this is what stops the next command.
|
|
206
|
+
this.killSignal = null;
|
|
192
207
|
// Memoized exit so late getResults()/onExit() callers don't hang.
|
|
193
208
|
this.exited = false;
|
|
194
209
|
this.exitTerminalOutput = '';
|
|
@@ -253,10 +268,15 @@ class SeriallyRunningTasks {
|
|
|
253
268
|
throw new Error('Not implemented');
|
|
254
269
|
}
|
|
255
270
|
kill(signal) {
|
|
271
|
+
this.killSignal = signal ?? 'SIGTERM';
|
|
256
272
|
return this.currentProcess?.kill(signal);
|
|
257
273
|
}
|
|
258
274
|
async run(options, context) {
|
|
259
275
|
for (const c of options.commands) {
|
|
276
|
+
if (this.killSignal) {
|
|
277
|
+
this.code = (0, exit_codes_1.signalToCode)(this.killSignal);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
260
280
|
const childProcess = await this.createProcess(c, options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, this.task, options.usePty, options.streamOutput, options.tty, options.envFile, this.baseEnv);
|
|
261
281
|
this.currentProcess = childProcess;
|
|
262
282
|
childProcess.onOutput((output, isCommandHeader) => {
|
|
@@ -349,7 +369,10 @@ class RunningNodeProcess {
|
|
|
349
369
|
this.terminalOutputChunks = [];
|
|
350
370
|
this.exitCallbacks = [];
|
|
351
371
|
this.outputCallbacks = [];
|
|
372
|
+
this.failedExitCallbacks = [];
|
|
352
373
|
this.killPromise = null;
|
|
374
|
+
// Set at 'exit', while the output may still be unread.
|
|
375
|
+
this.exitedWithFailure = false;
|
|
353
376
|
// Memoized exit so late getResults()/onExit() callers don't hang.
|
|
354
377
|
this.exited = false;
|
|
355
378
|
this.exitCode = 0;
|
|
@@ -367,6 +390,7 @@ class RunningNodeProcess {
|
|
|
367
390
|
windowsHide: true,
|
|
368
391
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
369
392
|
});
|
|
393
|
+
this.stdioClosed = (0, child_process_2.whenStdioClosed)(this.childProcess);
|
|
370
394
|
this.closedPromise = new Promise((resolve) => {
|
|
371
395
|
this.childProcess.on('close', resolve);
|
|
372
396
|
});
|
|
@@ -402,6 +426,10 @@ class RunningNodeProcess {
|
|
|
402
426
|
}
|
|
403
427
|
this.exitCallbacks.push(cb);
|
|
404
428
|
}
|
|
429
|
+
/** Runs at a non-zero 'exit', before the rest of the output is read. */
|
|
430
|
+
onFailedExit(cb) {
|
|
431
|
+
this.failedExitCallbacks.push(cb);
|
|
432
|
+
}
|
|
405
433
|
send(message) {
|
|
406
434
|
this.childProcess.send(message);
|
|
407
435
|
}
|
|
@@ -424,10 +452,15 @@ class RunningNodeProcess {
|
|
|
424
452
|
return this.killPromise;
|
|
425
453
|
if (!this.childProcess.pid)
|
|
426
454
|
return Promise.resolve();
|
|
455
|
+
// An exited child's pid is free for reuse, so signalling it could reach an
|
|
456
|
+
// unrelated process.
|
|
457
|
+
const signalled = (0, child_process_2.hasExited)(this.childProcess)
|
|
458
|
+
? Promise.resolve()
|
|
459
|
+
: (0, native_1.killProcessTreeGraceful)(this.childProcess.pid, signal);
|
|
427
460
|
// Cache the promise so concurrent callers (e.g. cleanup() after a
|
|
428
461
|
// fire-and-forget kill from cleanUpUnneededContinuousTasks) await the
|
|
429
462
|
// same in-progress operation instead of no-oping.
|
|
430
|
-
this.killPromise =
|
|
463
|
+
this.killPromise = signalled.then(() =>
|
|
431
464
|
// Wait for stdio drain and close events before the orchestrator
|
|
432
465
|
// tears down the event loop via process.exit().
|
|
433
466
|
Promise.race([
|
|
@@ -451,9 +484,10 @@ class RunningNodeProcess {
|
|
|
451
484
|
addListeners(commandConfig) {
|
|
452
485
|
this.childProcess.stdout.setEncoding('utf8');
|
|
453
486
|
this.childProcess.stderr.setEncoding('utf8');
|
|
487
|
+
const exitedWithFailure = () => this.exitedWithFailure;
|
|
454
488
|
// Separate matchers, so a ready string never spans stdout and stderr
|
|
455
|
-
const stdoutReady = readyWhenMatcher(this.readyWhenStatus);
|
|
456
|
-
const stderrReady = readyWhenMatcher(this.readyWhenStatus);
|
|
489
|
+
const stdoutReady = readyWhenMatcher(this.readyWhenStatus, exitedWithFailure);
|
|
490
|
+
const stderrReady = readyWhenMatcher(this.readyWhenStatus, exitedWithFailure);
|
|
457
491
|
this.childProcess.stdout.on('data', (data) => {
|
|
458
492
|
const output = addColorAndPrefix(data, commandConfig);
|
|
459
493
|
this.terminalOutputChunks.push(output);
|
|
@@ -485,11 +519,19 @@ class RunningNodeProcess {
|
|
|
485
519
|
untrackRunningNodeProcess(this);
|
|
486
520
|
this.emitExit(1, terminalOutput);
|
|
487
521
|
});
|
|
488
|
-
this.childProcess.on('exit', (code, signal) => {
|
|
522
|
+
this.childProcess.on('exit', async (code, signal) => {
|
|
489
523
|
if (code === null) {
|
|
490
524
|
code = (0, exit_codes_1.signalToCode)(signal);
|
|
491
525
|
}
|
|
492
526
|
untrackRunningNodeProcess(this);
|
|
527
|
+
this.exitedWithFailure = code !== 0;
|
|
528
|
+
if (this.exitedWithFailure) {
|
|
529
|
+
for (const cb of this.failedExitCallbacks) {
|
|
530
|
+
cb();
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// The last stdout and stderr chunks can still be unread at 'exit'.
|
|
534
|
+
await this.stdioClosed;
|
|
493
535
|
if (code === 0 &&
|
|
494
536
|
this.readyWhenStatus.length &&
|
|
495
537
|
!isReady(this.readyWhenStatus)) {
|
|
@@ -591,23 +633,33 @@ function isReady(readyWhenStatus) {
|
|
|
591
633
|
// The output as printed, kept across chunks, matches strings that hold escape
|
|
592
634
|
// sequences. LogMatcher, absent from the WASM binding, matches text with
|
|
593
635
|
// escapes inside it.
|
|
594
|
-
function readyWhenMatcher(readyWhenStatus) {
|
|
636
|
+
function readyWhenMatcher(readyWhenStatus, exitedWithFailure) {
|
|
595
637
|
const matchers = readyWhenStatus.map((status) => ({
|
|
596
638
|
status,
|
|
597
639
|
matcher: native_1.IS_WASM ? null : new native_1.LogMatcher([status.stringToMatch]),
|
|
598
640
|
tail: '',
|
|
641
|
+
matched: false,
|
|
599
642
|
}));
|
|
600
643
|
return (chunk) => {
|
|
644
|
+
// The status is shared, so only a chunk with this command's own match
|
|
645
|
+
// reports ready. Once ready, only a failed command can change the result.
|
|
646
|
+
if (isReady(readyWhenStatus) && !exitedWithFailure())
|
|
647
|
+
return false;
|
|
648
|
+
let matchedNow = false;
|
|
601
649
|
for (const entry of matchers) {
|
|
602
650
|
const { status, matcher } = entry;
|
|
603
|
-
if (
|
|
651
|
+
if (entry.matched)
|
|
604
652
|
continue;
|
|
605
653
|
const printed = entry.tail + chunk;
|
|
606
|
-
|
|
654
|
+
entry.matched =
|
|
607
655
|
printed.includes(status.stringToMatch) || !!matcher?.feed(chunk);
|
|
608
656
|
entry.tail = printed.slice(Math.max(0, printed.length - status.stringToMatch.length + 1));
|
|
657
|
+
if (entry.matched) {
|
|
658
|
+
status.found = true;
|
|
659
|
+
matchedNow = true;
|
|
660
|
+
}
|
|
609
661
|
}
|
|
610
|
-
return isReady(readyWhenStatus);
|
|
662
|
+
return matchedNow && isReady(readyWhenStatus);
|
|
611
663
|
};
|
|
612
664
|
}
|
|
613
665
|
function loadEnvVarsFile(path, env = {}) {
|
|
@@ -6,6 +6,7 @@ const child_process_1 = require("child_process");
|
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const native_1 = require("../../native");
|
|
8
8
|
const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
|
|
9
|
+
const child_process_2 = require("../../utils/child-process");
|
|
9
10
|
const package_manager_1 = require("../../utils/package-manager");
|
|
10
11
|
async function default_1(options, context) {
|
|
11
12
|
const pm = (0, package_manager_1.getPackageManagerCommand)();
|
|
@@ -40,13 +41,16 @@ function nodeProcess(command, cwd, env) {
|
|
|
40
41
|
env,
|
|
41
42
|
windowsHide: true,
|
|
42
43
|
});
|
|
44
|
+
const stdioClosed = (0, child_process_2.whenStdioClosed)(cp);
|
|
43
45
|
// Forward stdout/stderr to parent process
|
|
44
46
|
cp.stdout.pipe(process.stdout);
|
|
45
47
|
cp.stderr.pipe(process.stderr);
|
|
46
48
|
cp.on('error', (error) => {
|
|
47
49
|
rej(error);
|
|
48
50
|
});
|
|
49
|
-
cp.on('exit', (code) => {
|
|
51
|
+
cp.on('exit', async (code) => {
|
|
52
|
+
// The last stdout and stderr chunks can still be unread at 'exit'.
|
|
53
|
+
await stdioClosed;
|
|
50
54
|
if (code === 0) {
|
|
51
55
|
res();
|
|
52
56
|
}
|
|
@@ -55,9 +59,13 @@ function nodeProcess(command, cwd, env) {
|
|
|
55
59
|
}
|
|
56
60
|
});
|
|
57
61
|
const exitHandler = (signal) => {
|
|
58
|
-
|
|
62
|
+
// An exited child's pid is free for reuse, and its exit code decides
|
|
63
|
+
// the result, also when the kill is what made it exit.
|
|
64
|
+
if (cp && cp.pid && !cp.killed && !(0, child_process_2.hasExited)(cp)) {
|
|
59
65
|
(0, native_1.killProcessTreeGraceful)(cp.pid, signal).finally(() => {
|
|
60
|
-
|
|
66
|
+
if (!(0, child_process_2.hasExited)(cp)) {
|
|
67
|
+
res();
|
|
68
|
+
}
|
|
61
69
|
});
|
|
62
70
|
}
|
|
63
71
|
};
|
|
@@ -869,7 +869,7 @@ export declare function getTransformableOutputs(outputs: Array<string>): Array<s
|
|
|
869
869
|
*/
|
|
870
870
|
export declare function getUltracacheDeferredTaskIds(configurations: UltracacheConfigurations, taskGraph: TaskGraph): Array<string>
|
|
871
871
|
|
|
872
|
-
/** The eligibility report, for the run summary. */
|
|
872
|
+
/** The eligibility report, for the run summary and the skipped task report. */
|
|
873
873
|
export declare function getUltracacheReport(configurations: UltracacheConfigurations, tasks: Record<string, TaskUltracacheSettings | null>, options?: UltracacheEligibilityOptions | undefined | null): UltracacheReport
|
|
874
874
|
|
|
875
875
|
/**
|
package/dist/src/native/index.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const { join, basename } = require('path');
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
chmodSync,
|
|
4
|
+
copyFileSync,
|
|
5
|
+
lstatSync,
|
|
6
|
+
renameSync,
|
|
7
|
+
statSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
} = require('fs');
|
|
3
10
|
const { createHash } = require('crypto');
|
|
4
11
|
const Module = require('module');
|
|
5
12
|
const { nxVersion } = require('../utils/versions');
|
|
@@ -69,6 +76,25 @@ function statsOrNull(path) {
|
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
|
79
|
+
function lstatsOrNull(path) {
|
|
80
|
+
try {
|
|
81
|
+
return lstatSync(path);
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// A trusted entry is one only the current user could have written.
|
|
88
|
+
function isTrustedCacheEntry(stats) {
|
|
89
|
+
if (!stats?.isFile()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (typeof process.getuid !== 'function') {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return stats.uid === process.getuid() && (stats.mode & 0o022) === 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
72
98
|
function removeIfPresent(path) {
|
|
73
99
|
try {
|
|
74
100
|
unlinkSync(path);
|
|
@@ -122,13 +148,14 @@ Module._load = function (request, parent, isMain) {
|
|
|
122
148
|
const tmpFile = join(nativeFileCacheLocation, cacheKey + '-' + fileName);
|
|
123
149
|
const sourceStats = statSync(nativeLocation);
|
|
124
150
|
const expectedFileSize = sourceStats.size;
|
|
125
|
-
const existingFileStats =
|
|
151
|
+
const existingFileStats = lstatsOrNull(tmpFile);
|
|
126
152
|
|
|
127
153
|
// Size alone does not detect a rebuilt binding: a small Rust edit routinely
|
|
128
154
|
// produces a byte-identical size. The copy is taken after the build, so a
|
|
129
155
|
// cache entry older than the source means the source was rebuilt since.
|
|
130
156
|
const isFresh =
|
|
131
|
-
existingFileStats
|
|
157
|
+
isTrustedCacheEntry(existingFileStats) &&
|
|
158
|
+
existingFileStats.size === expectedFileSize &&
|
|
132
159
|
existingFileStats.mtimeMs >= sourceStats.mtimeMs;
|
|
133
160
|
|
|
134
161
|
const loadFromCache = () => {
|
|
@@ -159,6 +186,7 @@ Module._load = function (request, parent, isMain) {
|
|
|
159
186
|
// First copy to a unique location for each process
|
|
160
187
|
try {
|
|
161
188
|
copyFileSync(nativeLocation, tmpTmpFile);
|
|
189
|
+
chmodSync(tmpTmpFile, sourceStats.mode & 0o755);
|
|
162
190
|
} catch (e) {
|
|
163
191
|
// Permission errors won't heal on retry, and a throwing copy can still
|
|
164
192
|
// have left a partial file behind.
|
|
@@ -4,7 +4,6 @@ exports.NATIVE_CACHE_ROOT = void 0;
|
|
|
4
4
|
exports.getNativeFileCacheLocationToDelete = getNativeFileCacheLocationToDelete;
|
|
5
5
|
exports.ensureSecureNativeFileCacheLocation = ensureSecureNativeFileCacheLocation;
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
const nx_tmp_dir_1 = require("../utils/nx-tmp-dir");
|
|
9
8
|
const versions_1 = require("../utils/versions");
|
|
10
9
|
const owned_private_dir_1 = require("../utils/owned-private-dir");
|
|
@@ -29,8 +28,12 @@ function getNativeFileCacheLocationToDelete() {
|
|
|
29
28
|
if (configured !== undefined) {
|
|
30
29
|
// Checked for ownership before it is handed to a recursive delete: being
|
|
31
30
|
// configured does not make it ours. Weaker than the load path below, which
|
|
32
|
-
// also enforces mode and validates the version directory.
|
|
33
|
-
|
|
31
|
+
// also enforces mode and validates the version directory. The leaf's
|
|
32
|
+
// `lstat` resolves through every level above it, so those are judged too.
|
|
33
|
+
return (0, owned_private_dir_1.isSafeAncestry)((0, path_1.dirname)(configured)).status === 'ok' &&
|
|
34
|
+
(0, owned_private_dir_1.isOwnedRealDirectory)(configured)
|
|
35
|
+
? configured
|
|
36
|
+
: null;
|
|
34
37
|
}
|
|
35
38
|
return (0, owned_private_dir_1.isSafeSharedRoot)(nx_tmp_dir_1.NX_TMP_DIR).status === 'ok' &&
|
|
36
39
|
(0, owned_private_dir_1.isOwnedRealDirectory)(nx_tmp_dir_1.NX_USER_TMP_DIR) &&
|
|
@@ -57,7 +60,10 @@ cacheRoot = exports.NATIVE_CACHE_ROOT) {
|
|
|
57
60
|
// Held to the same 0700 bar as the default location: a `.node` is loaded
|
|
58
61
|
// out of here. Unlike NX_SOCKET_DIR it is not additionally refused for
|
|
59
62
|
// naming one of Nx's own roots, which is the only case that throws.
|
|
60
|
-
(0,
|
|
63
|
+
const parents = (0, owned_private_dir_1.ensureSafeAncestry)((0, path_1.dirname)(dir));
|
|
64
|
+
if (parents.status !== 'ok') {
|
|
65
|
+
throw new owned_private_dir_1.DirectoryRefusedError(parents.refusal);
|
|
66
|
+
}
|
|
61
67
|
const established = (0, owned_private_dir_1.ensureOwnedPrivateDir)(dir);
|
|
62
68
|
if (established.status !== 'ok') {
|
|
63
69
|
// The guard's own reason rather than a fixed sentence: `not-created
|
|
Binary file
|
|
Binary file
|
|
@@ -57,7 +57,11 @@ function toRustProjectGraph(graph) {
|
|
|
57
57
|
executor: targetConfig.executor,
|
|
58
58
|
inputs: targetConfig.inputs,
|
|
59
59
|
outputs: targetConfig.outputs,
|
|
60
|
-
options: JSON.stringify(targetConfig.
|
|
60
|
+
options: JSON.stringify(targetConfig.executor === 'nx:run-script' &&
|
|
61
|
+
typeof targetConfig.metadata?.scriptContent === 'string' &&
|
|
62
|
+
targetConfig.metadata.scriptContent !== ''
|
|
63
|
+
? [targetConfig.options, targetConfig.metadata.scriptContent]
|
|
64
|
+
: targetConfig.options),
|
|
61
65
|
configurations: JSON.stringify(targetConfig.configurations),
|
|
62
66
|
parallelism: targetConfig.parallelism,
|
|
63
67
|
};
|
|
@@ -37,6 +37,11 @@ export declare function verifyOrUpdateNxCloudClient(options?: {
|
|
|
37
37
|
nxCloudClient: NxCloudClient;
|
|
38
38
|
version: string;
|
|
39
39
|
} | null>;
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Null outside a workspace when there is no home directory apart from the
|
|
42
|
+
* shared temp dir, since the bundle would then be `require`d from, and resolve
|
|
43
|
+
* its own imports through, directories other users can write.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getBundleInstallDefaultLocation(): string | null;
|
|
41
46
|
export declare function downloadAndExtractClientBundle(httpClient: HttpClient, version: string, url: string): Promise<CloudBundleInstall>;
|
|
42
47
|
export {};
|
|
@@ -9,12 +9,13 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const zlib_1 = require("zlib");
|
|
10
10
|
const stream_1 = require("stream");
|
|
11
11
|
const path_1 = require("path");
|
|
12
|
-
const os_1 = require("os");
|
|
13
12
|
const nx_cloud_http_client_1 = require("./utilities/nx-cloud-http-client");
|
|
14
13
|
const http_client_1 = require("../utils/http-client");
|
|
15
14
|
const debug_logger_1 = require("./debug-logger");
|
|
16
15
|
const tar = tslib_1.__importStar(require("tar-stream"));
|
|
17
16
|
const cache_directory_1 = require("../utils/cache-directory");
|
|
17
|
+
const nx_tmp_dir_1 = require("../utils/nx-tmp-dir");
|
|
18
|
+
const owned_private_dir_1 = require("../utils/owned-private-dir");
|
|
18
19
|
const is_ci_1 = require("../utils/is-ci");
|
|
19
20
|
const crypto_1 = require("crypto");
|
|
20
21
|
const native_1 = require("../native");
|
|
@@ -93,17 +94,24 @@ async function verifyOrUpdateNxCloudClient(options) {
|
|
|
93
94
|
nxCloudClient: require(currentBundle.fullPath),
|
|
94
95
|
};
|
|
95
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Null outside a workspace when there is no home directory apart from the
|
|
99
|
+
* shared temp dir, since the bundle would then be `require`d from, and resolve
|
|
100
|
+
* its own imports through, directories other users can write.
|
|
101
|
+
*/
|
|
96
102
|
function getBundleInstallDefaultLocation() {
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
// NX_CLOUD_API URL so different cloud instances don't conflict.
|
|
103
|
+
// Outside a workspace, keep the bundle out of the current directory and key
|
|
104
|
+
// it by NX_CLOUD_API so different cloud instances don't conflict.
|
|
100
105
|
if (!(0, fs_1.existsSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'nx.json'))) {
|
|
106
|
+
if (!nx_tmp_dir_1.NX_HOME_TMP_DIR || !(0, nx_tmp_dir_1.homeDirIsDistinctFromSharedTmp)()) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
101
109
|
const apiUrl = process.env.NX_CLOUD_API || 'https://cloud.nx.app';
|
|
102
110
|
const apiHash = (0, crypto_1.createHash)('sha256')
|
|
103
111
|
.update(apiUrl)
|
|
104
112
|
.digest('hex')
|
|
105
113
|
.slice(0, 16);
|
|
106
|
-
return (0, path_1.join)(
|
|
114
|
+
return (0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, 'cloud-client', apiHash);
|
|
107
115
|
}
|
|
108
116
|
const legacyPath = (0, path_1.join)(workspace_root_1.workspaceRoot, 'node_modules', '.cache', 'nx', 'cloud');
|
|
109
117
|
// this legacy path is used when the nx-cloud package is installed.
|
|
@@ -116,29 +124,48 @@ function getBundleInstallDefaultLocation() {
|
|
|
116
124
|
return (0, path_1.join)((0, is_ci_1.isCI)() ? (0, cache_directory_1.cacheDirectoryForWorkspace)(workspace_root_1.workspaceRoot) : cache_directory_1.cacheDir, 'cloud');
|
|
117
125
|
}
|
|
118
126
|
const runnerBundleInstallDirectory = getBundleInstallDefaultLocation();
|
|
127
|
+
const inWorkspace = (0, fs_1.existsSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'nx.json'));
|
|
119
128
|
// Control files live outside the install directory. Released nx versions load
|
|
120
129
|
// any directory there as a bundle, so they would `require` a state directory
|
|
121
130
|
// placed inside it.
|
|
122
|
-
const stateDirectory =
|
|
131
|
+
const stateDirectory = inWorkspace
|
|
123
132
|
? (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'nx-cloud')
|
|
124
|
-
: `${runnerBundleInstallDirectory}-state`;
|
|
133
|
+
: runnerBundleInstallDirectory && `${runnerBundleInstallDirectory}-state`;
|
|
125
134
|
function ensureStateDirectory() {
|
|
126
135
|
(0, fs_1.mkdirSync)(stateDirectory, { recursive: true });
|
|
127
136
|
}
|
|
128
|
-
|
|
137
|
+
function ensureInstallDirectories() {
|
|
138
|
+
if (inWorkspace) {
|
|
139
|
+
(0, fs_1.mkdirSync)(runnerBundleInstallDirectory, { recursive: true });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!runnerBundleInstallDirectory) {
|
|
143
|
+
throw new Error('The Nx Cloud client cannot be installed outside a workspace without a home directory separate from the shared temp directory.');
|
|
144
|
+
}
|
|
145
|
+
for (const dir of [
|
|
146
|
+
nx_tmp_dir_1.NX_HOME_TMP_DIR,
|
|
147
|
+
(0, path_1.dirname)(runnerBundleInstallDirectory),
|
|
148
|
+
runnerBundleInstallDirectory,
|
|
149
|
+
stateDirectory,
|
|
150
|
+
]) {
|
|
151
|
+
const result = (0, owned_private_dir_1.ensureOwnedPrivateDir)(dir);
|
|
152
|
+
if (result.status === 'refused') {
|
|
153
|
+
throw new owned_private_dir_1.DirectoryRefusedError(result.refusal);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const downloadLockFilePath = stateDirectory && (0, path_1.join)(stateDirectory, 'download.lock');
|
|
129
158
|
// The record lives beside the lockfile rather than inside it. Windows
|
|
130
159
|
// byte-range locks are mandatory and handle-scoped, so writing to a file this
|
|
131
160
|
// process holds an exclusive lock on fails with ERROR_LOCK_VIOLATION. It also
|
|
132
161
|
// matches the convention elsewhere in nx: project-graph.lock and run.json.lock
|
|
133
162
|
// are never written to.
|
|
134
|
-
const downloadRecordFilePath = (0, path_1.join)(stateDirectory, 'download.record');
|
|
163
|
+
const downloadRecordFilePath = stateDirectory && (0, path_1.join)(stateDirectory, 'download.record');
|
|
135
164
|
// A version names a directory that is created and later deleted, so a value
|
|
136
165
|
// from the server must not be able to escape the install directory.
|
|
137
166
|
const VALID_BUNDLE_VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
138
167
|
function getLatestInstalledRunnerBundle() {
|
|
139
|
-
|
|
140
|
-
(0, fs_1.mkdirSync)(runnerBundleInstallDirectory, { recursive: true });
|
|
141
|
-
}
|
|
168
|
+
ensureInstallDirectories();
|
|
142
169
|
try {
|
|
143
170
|
const installedBundles = (0, fs_1.readdirSync)(runnerBundleInstallDirectory)
|
|
144
171
|
.filter((potentialDirectory) => {
|
|
@@ -4,7 +4,6 @@ exports.getPnpmLockfileNodes = getPnpmLockfileNodes;
|
|
|
4
4
|
exports.getPnpmLockfileDependencies = getPnpmLockfileDependencies;
|
|
5
5
|
exports.stringifyPnpmLockfile = stringifyPnpmLockfile;
|
|
6
6
|
const pnpm_normalizer_1 = require("./utils/pnpm-normalizer");
|
|
7
|
-
const package_json_1 = require("./utils/package-json");
|
|
8
7
|
const object_sort_1 = require("../../../utils/object-sort");
|
|
9
8
|
const project_graph_builder_1 = require("../../../project-graph/project-graph-builder");
|
|
10
9
|
const project_graph_1 = require("../../../config/project-graph");
|
|
@@ -325,24 +324,7 @@ function getNodes(data, isV5) {
|
|
|
325
324
|
}
|
|
326
325
|
}
|
|
327
326
|
}
|
|
328
|
-
|
|
329
|
-
// Pre-build packageName -> key index for O(1) lookup instead of O(n) find() per package
|
|
330
|
-
const hoistedKeysByPackage = new Map();
|
|
331
|
-
for (const key of Object.keys(hoistedDeps)) {
|
|
332
|
-
if (key.startsWith('/')) {
|
|
333
|
-
// Extract package name from key format: /{packageName}/{version}... or /@scope/name/{version}...
|
|
334
|
-
const withoutSlash = key.slice(1);
|
|
335
|
-
const slashIndex = withoutSlash.startsWith('@')
|
|
336
|
-
? withoutSlash.indexOf('/', withoutSlash.indexOf('/') + 1)
|
|
337
|
-
: withoutSlash.indexOf('/');
|
|
338
|
-
if (slashIndex > 0) {
|
|
339
|
-
const pkgName = withoutSlash.slice(0, slashIndex);
|
|
340
|
-
if (!hoistedKeysByPackage.has(pkgName)) {
|
|
341
|
-
hoistedKeysByPackage.set(pkgName, key);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
327
|
+
(0, pnpm_normalizer_1.assertPnpmModulesManifest)();
|
|
346
328
|
const results = {};
|
|
347
329
|
for (const [packageName, versionMap] of nodes.entries()) {
|
|
348
330
|
let hoistedNode;
|
|
@@ -350,8 +332,8 @@ function getNodes(data, isV5) {
|
|
|
350
332
|
hoistedNode = versionMap.values().next().value;
|
|
351
333
|
}
|
|
352
334
|
else {
|
|
353
|
-
const hoistedVersion = getHoistedVersion(packageName,
|
|
354
|
-
hoistedNode = versionMap.get(hoistedVersion);
|
|
335
|
+
const hoistedVersion = getHoistedVersion(packageName, versionMap, data.importers['.'], isV5);
|
|
336
|
+
hoistedNode = hoistedVersion ? versionMap.get(hoistedVersion) : undefined;
|
|
355
337
|
}
|
|
356
338
|
if (hoistedNode) {
|
|
357
339
|
hoistedNode.name = `npm:${packageName}`;
|
|
@@ -410,21 +392,27 @@ function getNodes(data, isV5) {
|
|
|
410
392
|
}
|
|
411
393
|
return { nodes: results, keyMap };
|
|
412
394
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
395
|
+
// The version that gets the bare `npm:<name>` node when a package has several
|
|
396
|
+
// versions: the one the root importer declares, read from the lockfile. Other
|
|
397
|
+
// packages get no bare node, so an `externalDependencies` input hashes every
|
|
398
|
+
// version. The versions that node_modules and `.modules.yaml` hoist depend on
|
|
399
|
+
// the install history and the platform, and the node names decide task hashes
|
|
400
|
+
// and pruned lockfiles.
|
|
401
|
+
function getHoistedVersion(packageName, versionMap, rootImporter, isV5) {
|
|
402
|
+
for (const depType of [
|
|
403
|
+
'dependencies',
|
|
404
|
+
'devDependencies',
|
|
405
|
+
'optionalDependencies',
|
|
406
|
+
]) {
|
|
407
|
+
const rawVersion = rootImporter?.[depType]?.[packageName];
|
|
408
|
+
const version = typeof rawVersion === 'string'
|
|
409
|
+
? parseBaseVersion(rawVersion, isV5)
|
|
410
|
+
: undefined;
|
|
411
|
+
if (version && versionMap.has(version)) {
|
|
412
|
+
return version;
|
|
425
413
|
}
|
|
426
414
|
}
|
|
427
|
-
return
|
|
415
|
+
return undefined;
|
|
428
416
|
}
|
|
429
417
|
function getDependencies(data, keyMap, isV5, ctx) {
|
|
430
418
|
const results = [];
|
|
@@ -14,6 +14,13 @@ export declare function pruneProjectGraph(graph: ProjectGraph, prunedPackageJson
|
|
|
14
14
|
* so the two never match by string.
|
|
15
15
|
*/
|
|
16
16
|
export declare function isLocalPathSpecifier(versionExpr: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The pnpm parser gives the bare `npm:<name>` to an outside `link:` when no
|
|
19
|
+
* registry version holds it. Such a node says nothing about which registry
|
|
20
|
+
* version a project resolves, so lookups that fall back to registry versions
|
|
21
|
+
* skip it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isLinkNode(node: ProjectGraphExternalNode): boolean;
|
|
17
24
|
/**
|
|
18
25
|
* The external node for a `file:`/`link:` local-path dependency.
|
|
19
26
|
*
|