nx 23.3.0 → 24.0.0-beta.0
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/README.md +3 -6
- package/dist/src/adapter/ngcli-adapter.js +1 -0
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +0 -12
- package/dist/src/command-line/graph/graph.js +3 -5
- package/dist/src/command-line/init/command-object.js +0 -12
- package/dist/src/command-line/init/init-v2.js +0 -2
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +17 -12
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +5 -6
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +5 -6
- package/dist/src/command-line/run/executor-utils.js +1 -0
- package/dist/src/command-line/run/run-one.d.ts +20 -1
- package/dist/src/command-line/run/run-one.js +153 -5
- package/dist/src/command-line/show/show-target/utils.js +1 -0
- package/dist/src/command-line/watch/command-object.js +3 -22
- package/dist/src/command-line/watch/watch.d.ts +0 -7
- package/dist/src/command-line/watch/watch.js +1 -1
- package/dist/src/config/misc-interfaces.d.ts +12 -0
- package/dist/src/config/workspace-json-project-json.d.ts +5 -0
- package/dist/src/daemon/client/client.d.ts +9 -0
- package/dist/src/daemon/client/client.js +89 -37
- package/dist/src/daemon/server/shutdown-utils.js +0 -3
- package/dist/src/daemon/socket-utils.d.ts +9 -4
- package/dist/src/daemon/socket-utils.js +12 -49
- package/dist/src/daemon/tmp-dir.d.ts +19 -14
- package/dist/src/daemon/tmp-dir.js +142 -354
- package/dist/src/devkit-internals.d.ts +1 -1
- package/dist/src/devkit-internals.js +1 -0
- package/dist/src/hasher/file-hasher.js +9 -7
- package/dist/src/hasher/hash-task.js +4 -0
- package/dist/src/hasher/native-task-hasher-impl.js +1 -1
- package/dist/src/migrations/update-24-0-0/find-custom-hashers.d.ts +3 -0
- package/dist/src/migrations/update-24-0-0/find-custom-hashers.js +100 -0
- package/dist/src/migrations/update-24-0-0/find-custom-hashers.md +63 -0
- package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +145 -0
- package/dist/src/native/index.d.ts +127 -8
- package/dist/src/native/native-bindings.js +5 -0
- package/dist/src/native/nx.wasi-browser.js +1 -0
- package/dist/src/native/nx.wasi.cjs +1 -0
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/update-manager.d.ts +7 -0
- package/dist/src/nx-cloud/update-manager.js +237 -50
- package/dist/src/project-graph/affected/affected-tasks.js +1 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +7 -0
- package/dist/src/tasks-runner/create-task-graph.d.ts +10 -0
- package/dist/src/tasks-runner/create-task-graph.js +37 -2
- package/dist/src/tasks-runner/task-env.d.ts +10 -0
- package/dist/src/tasks-runner/task-env.js +26 -5
- package/dist/src/tasks-runner/task-orchestrator.d.ts +10 -4
- package/dist/src/tasks-runner/task-orchestrator.js +87 -53
- package/dist/src/tasks-runner/utils.d.ts +20 -5
- package/dist/src/tasks-runner/utils.js +80 -29
- package/dist/src/ultracache/overrides.js +4 -0
- package/dist/src/utils/owned-private-dir.d.ts +1 -17
- package/dist/src/utils/owned-private-dir.js +10 -62
- package/dist/src/utils/perf-hooks.d.ts +1 -0
- package/dist/src/utils/plugins/core-plugins.js +1 -1
- package/dist/src/utils/string-similarity.d.ts +38 -0
- package/dist/src/utils/string-similarity.js +108 -0
- package/migrations.json +7 -0
- package/package.json +11 -20
- package/readme-template.md +3 -3
- package/schemas/nx-schema.json +5 -0
- package/schemas/project-schema.json +5 -0
- package/dist/src/tasks-runner/legacy-depends-on-warning.d.ts +0 -18
- package/dist/src/tasks-runner/legacy-depends-on-warning.js +0 -109
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NxCloudClientUnavailableError = exports.NxCloudEnterpriseOutdatedError = void 0;
|
|
4
4
|
exports.verifyOrUpdateNxCloudClient = verifyOrUpdateNxCloudClient;
|
|
5
5
|
exports.getBundleInstallDefaultLocation = getBundleInstallDefaultLocation;
|
|
6
|
+
exports.downloadAndExtractClientBundle = downloadAndExtractClientBundle;
|
|
6
7
|
const tslib_1 = require("tslib");
|
|
7
8
|
const fs_1 = require("fs");
|
|
8
9
|
const zlib_1 = require("zlib");
|
|
@@ -16,6 +17,7 @@ const tar = tslib_1.__importStar(require("tar-stream"));
|
|
|
16
17
|
const cache_directory_1 = require("../utils/cache-directory");
|
|
17
18
|
const is_ci_1 = require("../utils/is-ci");
|
|
18
19
|
const crypto_1 = require("crypto");
|
|
20
|
+
const native_1 = require("../native");
|
|
19
21
|
const workspace_root_1 = require("../utils/workspace-root");
|
|
20
22
|
class NxCloudEnterpriseOutdatedError extends Error {
|
|
21
23
|
constructor(url) {
|
|
@@ -74,13 +76,13 @@ async function verifyOrUpdateNxCloudClient(options) {
|
|
|
74
76
|
if (version === 'NX_ENTERPRISE_OUTDATED_IMAGE') {
|
|
75
77
|
throw new NxCloudEnterpriseOutdatedError(apiUrl);
|
|
76
78
|
}
|
|
77
|
-
const
|
|
78
|
-
(0, debug_logger_1.debugLog)('Done: ', fullPath);
|
|
79
|
-
const nxCloudClient = require(fullPath);
|
|
79
|
+
const installedBundle = await downloadAndExtractClientBundle(httpClient, version, url);
|
|
80
|
+
(0, debug_logger_1.debugLog)('Done: ', installedBundle.fullPath);
|
|
81
|
+
const nxCloudClient = require(installedBundle.fullPath);
|
|
80
82
|
if (nxCloudClient.commands === undefined) {
|
|
81
83
|
throw new NxCloudEnterpriseOutdatedError(apiUrl);
|
|
82
84
|
}
|
|
83
|
-
return { version, nxCloudClient };
|
|
85
|
+
return { version: installedBundle.version, nxCloudClient };
|
|
84
86
|
}
|
|
85
87
|
if (currentBundle === null) {
|
|
86
88
|
throw new NxCloudClientUnavailableError();
|
|
@@ -114,6 +116,25 @@ function getBundleInstallDefaultLocation() {
|
|
|
114
116
|
return (0, path_1.join)((0, is_ci_1.isCI)() ? (0, cache_directory_1.cacheDirectoryForWorkspace)(workspace_root_1.workspaceRoot) : cache_directory_1.cacheDir, 'cloud');
|
|
115
117
|
}
|
|
116
118
|
const runnerBundleInstallDirectory = getBundleInstallDefaultLocation();
|
|
119
|
+
// Control files live outside the install directory. Released nx versions load
|
|
120
|
+
// any directory there as a bundle, so they would `require` a state directory
|
|
121
|
+
// placed inside it.
|
|
122
|
+
const stateDirectory = (0, fs_1.existsSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'nx.json'))
|
|
123
|
+
? (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'nx-cloud')
|
|
124
|
+
: `${runnerBundleInstallDirectory}-state`;
|
|
125
|
+
function ensureStateDirectory() {
|
|
126
|
+
(0, fs_1.mkdirSync)(stateDirectory, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
const downloadLockFilePath = (0, path_1.join)(stateDirectory, 'download.lock');
|
|
129
|
+
// The record lives beside the lockfile rather than inside it. Windows
|
|
130
|
+
// byte-range locks are mandatory and handle-scoped, so writing to a file this
|
|
131
|
+
// process holds an exclusive lock on fails with ERROR_LOCK_VIOLATION. It also
|
|
132
|
+
// matches the convention elsewhere in nx: project-graph.lock and run.json.lock
|
|
133
|
+
// are never written to.
|
|
134
|
+
const downloadRecordFilePath = (0, path_1.join)(stateDirectory, 'download.record');
|
|
135
|
+
// A version names a directory that is created and later deleted, so a value
|
|
136
|
+
// from the server must not be able to escape the install directory.
|
|
137
|
+
const VALID_BUNDLE_VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
117
138
|
function getLatestInstalledRunnerBundle() {
|
|
118
139
|
if (!(0, fs_1.existsSync)(runnerBundleInstallDirectory)) {
|
|
119
140
|
(0, fs_1.mkdirSync)(runnerBundleInstallDirectory, { recursive: true });
|
|
@@ -121,7 +142,9 @@ function getLatestInstalledRunnerBundle() {
|
|
|
121
142
|
try {
|
|
122
143
|
const installedBundles = (0, fs_1.readdirSync)(runnerBundleInstallDirectory)
|
|
123
144
|
.filter((potentialDirectory) => {
|
|
124
|
-
|
|
145
|
+
// '.tmp-*' directories are in-progress or crashed downloads
|
|
146
|
+
return (!potentialDirectory.startsWith('.') &&
|
|
147
|
+
(0, fs_1.statSync)((0, path_1.join)(runnerBundleInstallDirectory, potentialDirectory)).isDirectory());
|
|
125
148
|
})
|
|
126
149
|
.map((fileOrDirectory) => ({
|
|
127
150
|
version: fileOrDirectory,
|
|
@@ -131,7 +154,13 @@ function getLatestInstalledRunnerBundle() {
|
|
|
131
154
|
// No installed bundles
|
|
132
155
|
return null;
|
|
133
156
|
}
|
|
134
|
-
|
|
157
|
+
// A contended install can leave several bundles on disk. The record names
|
|
158
|
+
// the directory an install last completed in, which is the one to run.
|
|
159
|
+
// Without a record the directory name is all there is to go on and is read
|
|
160
|
+
// as the version, which is right for a bundle an older nx installed and
|
|
161
|
+
// otherwise yields a version the server rejects, costing one more
|
|
162
|
+
// download.
|
|
163
|
+
return recordedBundle() ?? installedBundles[0];
|
|
135
164
|
}
|
|
136
165
|
catch (e) {
|
|
137
166
|
console.log('Could not read runner bundle path:', e.message);
|
|
@@ -170,7 +199,7 @@ async function verifyCurrentBundle(httpClient, currentBundle) {
|
|
|
170
199
|
});
|
|
171
200
|
}
|
|
172
201
|
function getLatestBundleVerificationTimestamp() {
|
|
173
|
-
const lockfilePath = (0, path_1.join)(
|
|
202
|
+
const lockfilePath = (0, path_1.join)(stateDirectory, 'verify.lock');
|
|
174
203
|
if ((0, fs_1.existsSync)(lockfilePath)) {
|
|
175
204
|
const timestampAsString = (0, fs_1.readFileSync)(lockfilePath, 'utf-8');
|
|
176
205
|
let timestampAsNumber;
|
|
@@ -185,7 +214,8 @@ function getLatestBundleVerificationTimestamp() {
|
|
|
185
214
|
return null;
|
|
186
215
|
}
|
|
187
216
|
function writeBundleVerificationLock() {
|
|
188
|
-
const lockfilePath = (0, path_1.join)(
|
|
217
|
+
const lockfilePath = (0, path_1.join)(stateDirectory, 'verify.lock');
|
|
218
|
+
ensureStateDirectory();
|
|
189
219
|
(0, fs_1.writeFileSync)(lockfilePath, new Date().getTime().toString(), 'utf-8');
|
|
190
220
|
}
|
|
191
221
|
function getBundleContentHash(bundle) {
|
|
@@ -211,7 +241,118 @@ function hashDirectory(dir) {
|
|
|
211
241
|
const combinedHashes = hashes.sort().join('');
|
|
212
242
|
return (0, crypto_1.createHash)('sha256').update(combinedHashes).digest('hex');
|
|
213
243
|
}
|
|
214
|
-
async function downloadAndExtractClientBundle(httpClient,
|
|
244
|
+
async function downloadAndExtractClientBundle(httpClient, version, url) {
|
|
245
|
+
// Parallel nx processes race to install bundles, possibly at different
|
|
246
|
+
// versions. The first to take the lock downloads; the rest wait and adopt
|
|
247
|
+
// its bundle when an install completed during the wait at the version the
|
|
248
|
+
// server asked them for. Otherwise they download their own as a contended
|
|
249
|
+
// install, which publishes its own directory and skips cleanup, so the
|
|
250
|
+
// holder's bundle stays on disk for the process running from it - at the
|
|
251
|
+
// same version as well as a different one. The flock is released by the
|
|
252
|
+
// kernel if the holder dies, so no stale-lock cleanup is needed. Under WASM
|
|
253
|
+
// the lock is unavailable and downloads run unserialized.
|
|
254
|
+
if (!VALID_BUNDLE_VERSION.test(version)) {
|
|
255
|
+
throw new Error(`Invalid Nx Cloud client bundle version: ${version}`);
|
|
256
|
+
}
|
|
257
|
+
const recordBeforeContending = readDownloadRecord();
|
|
258
|
+
const lock = !native_1.IS_WASM ? new native_1.FileLock(downloadLockFilePath) : null;
|
|
259
|
+
let locked = lock?.locked;
|
|
260
|
+
let contended = false;
|
|
261
|
+
while (locked) {
|
|
262
|
+
(0, debug_logger_1.debugLog)('Another process is downloading the client bundle, waiting for it to complete');
|
|
263
|
+
await lock.wait();
|
|
264
|
+
// The holder may be running from a bundle whose record predates this call,
|
|
265
|
+
// so the wait alone makes the install contended.
|
|
266
|
+
contended = true;
|
|
267
|
+
const installedBundle = bundleInstalledSince(recordBeforeContending);
|
|
268
|
+
if (installedBundle) {
|
|
269
|
+
if (installedBundle.version === version) {
|
|
270
|
+
(0, debug_logger_1.debugLog)('Using client bundle downloaded by another process: ', installedBundle.version);
|
|
271
|
+
return installedBundle;
|
|
272
|
+
}
|
|
273
|
+
(0, debug_logger_1.debugLog)('Another process installed a different bundle: ', installedBundle.version);
|
|
274
|
+
}
|
|
275
|
+
// The other process failed or installed an older version, so this process
|
|
276
|
+
// still needs to download.
|
|
277
|
+
locked = lock.check();
|
|
278
|
+
}
|
|
279
|
+
lock?.lock();
|
|
280
|
+
try {
|
|
281
|
+
// A process that acquired the lock between the check above and lock() may
|
|
282
|
+
// have completed an install already.
|
|
283
|
+
const installedBundle = bundleInstalledSince(recordBeforeContending);
|
|
284
|
+
if (installedBundle) {
|
|
285
|
+
if (installedBundle.version === version) {
|
|
286
|
+
(0, debug_logger_1.debugLog)('Using client bundle downloaded by another process: ', installedBundle.version);
|
|
287
|
+
return installedBundle;
|
|
288
|
+
}
|
|
289
|
+
// A different version means that process is running from a bundle this
|
|
290
|
+
// one must not delete.
|
|
291
|
+
contended = true;
|
|
292
|
+
(0, debug_logger_1.debugLog)('Another process installed a different bundle: ', installedBundle.version);
|
|
293
|
+
}
|
|
294
|
+
const fullPath = await downloadAndExtractBundle(httpClient, version, url, contended);
|
|
295
|
+
return { version, fullPath };
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
lock?.unlock();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Records "<serverVersion> <directoryName>", written only once an install has
|
|
302
|
+
// COMPLETED. The directory is recorded separately because it cannot be derived
|
|
303
|
+
// from the version - every install publishes its own (see
|
|
304
|
+
// downloadAndExtractBundle), so several directories can carry the same
|
|
305
|
+
// version. That also makes every record distinct, so a waiter can tell "an
|
|
306
|
+
// install finished while I waited" from "this record is left over from a past
|
|
307
|
+
// run" by comparing the record it read before contending. Timestamps cannot
|
|
308
|
+
// answer that: filesystem mtime granularity is coarser than the race window.
|
|
309
|
+
function readDownloadRecord() {
|
|
310
|
+
try {
|
|
311
|
+
return (0, fs_1.readFileSync)(downloadRecordFilePath, 'utf-8').trim();
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
return '';
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function writeDownloadRecord(version, directoryName) {
|
|
318
|
+
ensureStateDirectory();
|
|
319
|
+
(0, fs_1.writeFileSync)(downloadRecordFilePath, `${version} ${directoryName}`, 'utf-8');
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The bundle the record names, if it is still on disk. A record whose second
|
|
323
|
+
* field does not name a live directory resolves to null and leaves selection
|
|
324
|
+
* on its fallback, which is what a one-field record or anything else
|
|
325
|
+
* unexpected in the file has to do.
|
|
326
|
+
*/
|
|
327
|
+
function recordedBundle() {
|
|
328
|
+
const [version, directoryName] = readDownloadRecord().split(' ');
|
|
329
|
+
if (!version ||
|
|
330
|
+
!directoryName ||
|
|
331
|
+
!VALID_BUNDLE_VERSION.test(version) ||
|
|
332
|
+
!VALID_BUNDLE_VERSION.test(directoryName)) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const fullPath = (0, path_1.join)(runnerBundleInstallDirectory, directoryName);
|
|
336
|
+
return (0, fs_1.existsSync)(fullPath) ? { version, fullPath } : null;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The bundle an install completed during this call, or null. Requires the
|
|
340
|
+
* record to have changed since `recordBefore` was read: a directory existing
|
|
341
|
+
* proves only that some earlier run left one there, and an install
|
|
342
|
+
* interrupted on a released nx leaves exactly that.
|
|
343
|
+
*/
|
|
344
|
+
function bundleInstalledSince(recordBefore) {
|
|
345
|
+
return readDownloadRecord() === recordBefore ? null : recordedBundle();
|
|
346
|
+
}
|
|
347
|
+
async function downloadAndExtractBundle(httpClient, version, url, contended) {
|
|
348
|
+
// Every install publishes its own directory. Two processes can be asked for
|
|
349
|
+
// the same version while one of them is already running from a completed
|
|
350
|
+
// install of it, so replacing <installDir>/<version> in place would delete
|
|
351
|
+
// that bundle out from under it - and a holder loading its client in the gap
|
|
352
|
+
// fails with MODULE_NOT_FOUND, which drops the task runner to running
|
|
353
|
+
// without Nx Cloud. A directory nothing else has seen cannot be in use.
|
|
354
|
+
const bundleDirectoryName = `${version}-${(0, crypto_1.randomUUID)()}`;
|
|
355
|
+
const bundleExtractLocation = (0, path_1.join)(runnerBundleInstallDirectory, bundleDirectoryName);
|
|
215
356
|
let resp;
|
|
216
357
|
try {
|
|
217
358
|
resp = await httpClient.get(url, {
|
|
@@ -222,53 +363,99 @@ async function downloadAndExtractClientBundle(httpClient, runnerBundleInstallDir
|
|
|
222
363
|
console.error('Error while updating Nx Cloud client bundle');
|
|
223
364
|
throw e;
|
|
224
365
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
(0,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
else if (headers.type === 'file') {
|
|
241
|
-
const outputFilePath = (0, path_1.join)(bundleExtractLocation, headers.name);
|
|
242
|
-
const writeStream = (0, fs_1.createWriteStream)(outputFilePath);
|
|
243
|
-
// Surface disk errors through the pipeline instead of crashing
|
|
244
|
-
writeStream.on('error', (e) => extract.destroy(e));
|
|
245
|
-
stream.pipe(writeStream);
|
|
246
|
-
// Continue the tar stream after the write stream closes
|
|
247
|
-
writeStream.on('close', () => {
|
|
366
|
+
// Extract into a temp directory and rename into place afterwards, so a
|
|
367
|
+
// failed or interrupted download never leaves a partial bundle at the
|
|
368
|
+
// path other processes require it from.
|
|
369
|
+
const tempExtractLocation = (0, path_1.join)(runnerBundleInstallDirectory, `.tmp-${version}-${process.pid}`);
|
|
370
|
+
(0, fs_1.mkdirSync)(tempExtractLocation, { recursive: true });
|
|
371
|
+
try {
|
|
372
|
+
await new Promise((res, rej) => {
|
|
373
|
+
const extract = tar.extract();
|
|
374
|
+
extract.on('entry', function (headers, stream, next) {
|
|
375
|
+
if (headers.type === 'directory') {
|
|
376
|
+
const directoryPath = (0, path_1.join)(tempExtractLocation, headers.name);
|
|
377
|
+
if (!(0, fs_1.existsSync)(directoryPath)) {
|
|
378
|
+
(0, fs_1.mkdirSync)(directoryPath, { recursive: true });
|
|
379
|
+
}
|
|
248
380
|
next();
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
381
|
+
stream.resume();
|
|
382
|
+
}
|
|
383
|
+
else if (headers.type === 'file') {
|
|
384
|
+
const outputFilePath = (0, path_1.join)(tempExtractLocation, headers.name);
|
|
385
|
+
const writeStream = (0, fs_1.createWriteStream)(outputFilePath);
|
|
386
|
+
// Surface disk errors through the pipeline instead of crashing
|
|
387
|
+
writeStream.on('error', (e) => extract.destroy(e));
|
|
388
|
+
stream.pipe(writeStream);
|
|
389
|
+
// Continue the tar stream after the write stream closes
|
|
390
|
+
writeStream.on('close', () => {
|
|
391
|
+
next();
|
|
392
|
+
});
|
|
393
|
+
stream.resume();
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
// Skipping the entry would publish an incomplete bundle.
|
|
397
|
+
extract.destroy(new Error(`Unsupported ${headers.type} entry in Nx Cloud client bundle: ${headers.name}`));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
extract.on('finish', function () {
|
|
401
|
+
res();
|
|
402
|
+
});
|
|
403
|
+
// pipeline propagates download/gunzip errors that .pipe() would leave
|
|
404
|
+
// uncaught
|
|
405
|
+
(0, stream_1.pipeline)(resp.data, (0, zlib_1.createGunzip)(), extract, (e) => {
|
|
406
|
+
if (e)
|
|
407
|
+
rej(e);
|
|
408
|
+
});
|
|
263
409
|
});
|
|
264
|
-
|
|
410
|
+
(0, fs_1.renameSync)(tempExtractLocation, bundleExtractLocation);
|
|
411
|
+
// Recorded only now: the record is the signal that a bundle at this
|
|
412
|
+
// version was installed by this process, which is what lets a waiter
|
|
413
|
+
// adopt it instead of downloading again, and it carries the directory
|
|
414
|
+
// that selection has to load from.
|
|
415
|
+
writeDownloadRecord(version, bundleDirectoryName);
|
|
416
|
+
}
|
|
417
|
+
catch (e) {
|
|
418
|
+
(0, fs_1.rmSync)(tempExtractLocation, { recursive: true, force: true });
|
|
419
|
+
throw e;
|
|
420
|
+
}
|
|
421
|
+
// On a contended install another process may be running from any bundle on
|
|
422
|
+
// disk, now including one at this same version, so nothing here can be shown
|
|
423
|
+
// to be unused and collection waits for a later uncontended install. Repeat
|
|
424
|
+
// contention accumulates directories until one of those runs. Bounding that
|
|
425
|
+
// means knowing which bundles are still loaded, which nothing on disk
|
|
426
|
+
// records today.
|
|
427
|
+
if (!contended) {
|
|
428
|
+
removeOldClientBundles(bundleDirectoryName);
|
|
429
|
+
}
|
|
430
|
+
writeBundleVerificationLock();
|
|
431
|
+
return bundleExtractLocation;
|
|
265
432
|
}
|
|
266
|
-
function removeOldClientBundles(
|
|
433
|
+
function removeOldClientBundles(currentInstallDirectoryName) {
|
|
267
434
|
const filesAndFolders = (0, fs_1.readdirSync)(runnerBundleInstallDirectory);
|
|
268
435
|
for (let fileOrFolder of filesAndFolders) {
|
|
436
|
+
// A '.tmp-*' left by a crashed extract is reclaimed here, which is safe
|
|
437
|
+
// only because this runs after our own was renamed away and the download
|
|
438
|
+
// lock means no other process is extracting. Under WASM there is no lock,
|
|
439
|
+
// so a concurrent extract may still own that directory: leaving it costs
|
|
440
|
+
// disk, deleting it would fail that process's install.
|
|
441
|
+
if (fileOrFolder === currentInstallDirectoryName ||
|
|
442
|
+
(native_1.IS_WASM && fileOrFolder.startsWith('.tmp-'))) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
269
445
|
const fileOrFolderPath = (0, path_1.join)(runnerBundleInstallDirectory, fileOrFolder);
|
|
270
|
-
|
|
271
|
-
|
|
446
|
+
// Another process's cleanup can remove an entry between the readdir above
|
|
447
|
+
// and these calls, so both tolerate it already being gone.
|
|
448
|
+
let isBundle;
|
|
449
|
+
try {
|
|
450
|
+
// Only directories are bundles. Files here, like the verify.lock a
|
|
451
|
+
// released nx writes, are left alone.
|
|
452
|
+
isBundle = (0, fs_1.statSync)(fileOrFolderPath).isDirectory();
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (isBundle) {
|
|
458
|
+
(0, fs_1.rmSync)(fileOrFolderPath, { recursive: true, force: true });
|
|
272
459
|
}
|
|
273
460
|
}
|
|
274
461
|
}
|
|
@@ -148,6 +148,7 @@ async function selectAffectedTasks(projectGraph, nxJson, planningContext, reques
|
|
|
148
148
|
const dependencies = dependencyChanges(projectGraph, touchedFiles, nxJson, packageJson);
|
|
149
149
|
const namedProjects = new Set(dependencies.projects);
|
|
150
150
|
const projects = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects;
|
|
151
|
+
// TODO(v25): remove custom hasher support.
|
|
151
152
|
const customHashed = new Set(taskIds.filter((id) => hasCustomHasher(taskGraph.tasks[id], projects)));
|
|
152
153
|
const options = {
|
|
153
154
|
projectGlobPatterns: await (0, affected_projects_1.getProjectGlobPatterns)(nxJson),
|
|
@@ -351,6 +351,13 @@ class IsolatedPlugin {
|
|
|
351
351
|
this.shutdown();
|
|
352
352
|
}
|
|
353
353
|
async setWorkerEnv(env) {
|
|
354
|
+
// A restart may have spawned under the previous client env but not yet
|
|
355
|
+
// finished loading. Wait for that worker so it receives the update too.
|
|
356
|
+
// Do not start a stopped worker solely to forward env: its next spawn
|
|
357
|
+
// will inherit the daemon's already-updated environment.
|
|
358
|
+
if (!this._alive && this._connectPromise) {
|
|
359
|
+
await this._connectPromise;
|
|
360
|
+
}
|
|
354
361
|
if (!this._alive) {
|
|
355
362
|
return;
|
|
356
363
|
}
|
|
@@ -25,6 +25,8 @@ export declare class ProcessTasks {
|
|
|
25
25
|
readonly continuousDependencies: {
|
|
26
26
|
[k: string]: string[];
|
|
27
27
|
};
|
|
28
|
+
private readonly continuousEdgesWithoutInputs;
|
|
29
|
+
private readonly continuousEdgesWithInputs;
|
|
28
30
|
readonly dependencyOverrides: DependencyOverrides;
|
|
29
31
|
private readonly allTargetNames;
|
|
30
32
|
constructor(extraTargetDependencies: TargetDependencies, projectGraph: ProjectGraph, recordDependencyOverrides?: boolean);
|
|
@@ -33,6 +35,14 @@ export declare class ProcessTasks {
|
|
|
33
35
|
private processTasksForMultipleProjects;
|
|
34
36
|
private processTasksForSingleProject;
|
|
35
37
|
private processTasksForDependencies;
|
|
38
|
+
private addContinuousEdge;
|
|
39
|
+
/**
|
|
40
|
+
* Continuous edges every `dependsOn` path into which has `inputs: false`.
|
|
41
|
+
* Undefined when there are none, so graphs without the option are unchanged.
|
|
42
|
+
*/
|
|
43
|
+
continuousDependenciesWithoutInputs(): {
|
|
44
|
+
[k: string]: string[];
|
|
45
|
+
} | undefined;
|
|
36
46
|
private recordEdge;
|
|
37
47
|
private createDummyTask;
|
|
38
48
|
createTask(id: string, project: ProjectGraphProjectNode, target: string, resolvedConfiguration: string | undefined, overrides: Record<string, unknown>): Task;
|
|
@@ -20,6 +20,11 @@ class ProcessTasks {
|
|
|
20
20
|
this.tasks = {};
|
|
21
21
|
this.dependencies = {};
|
|
22
22
|
this.continuousDependencies = {};
|
|
23
|
+
// `from\0to` continuous edges by whether their `dependsOn` entry has
|
|
24
|
+
// `inputs: false`. Keyed from the creator's target, like `recordEdge`, so
|
|
25
|
+
// an edge through a dummy task names the real task.
|
|
26
|
+
this.continuousEdgesWithoutInputs = new Set();
|
|
27
|
+
this.continuousEdgesWithInputs = new Set();
|
|
23
28
|
this.dependencyOverrides = {};
|
|
24
29
|
const allTargetNames = new Set();
|
|
25
30
|
for (const projectName in projectGraph.nodes) {
|
|
@@ -132,7 +137,7 @@ class ProcessTasks {
|
|
|
132
137
|
if (task.id !== selfTaskId) {
|
|
133
138
|
this.recordEdge(task, selfTaskId, taskOverrides);
|
|
134
139
|
if (this.tasks[selfTaskId].continuous) {
|
|
135
|
-
this.
|
|
140
|
+
this.addContinuousEdge(task, selfTaskId, dependencyConfig);
|
|
136
141
|
}
|
|
137
142
|
else {
|
|
138
143
|
this.dependencies[task.id].push(selfTaskId);
|
|
@@ -156,7 +161,7 @@ class ProcessTasks {
|
|
|
156
161
|
if (task.id !== depTargetId) {
|
|
157
162
|
this.recordEdge(task, depTargetId, taskOverrides);
|
|
158
163
|
if (depTargetConfiguration.continuous) {
|
|
159
|
-
this.
|
|
164
|
+
this.addContinuousEdge(task, depTargetId, dependencyConfig);
|
|
160
165
|
}
|
|
161
166
|
else {
|
|
162
167
|
this.dependencies[task.id].push(depTargetId);
|
|
@@ -186,6 +191,32 @@ class ProcessTasks {
|
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
}
|
|
194
|
+
addContinuousEdge(task, dependencyId, dependencyConfig) {
|
|
195
|
+
this.continuousDependencies[task.id].push(dependencyId);
|
|
196
|
+
const { project, target, configuration } = task.target;
|
|
197
|
+
const edge = `${(0, utils_1.createTaskId)(project, target, configuration)}\0${dependencyId}`;
|
|
198
|
+
(dependencyConfig.inputs === false
|
|
199
|
+
? this.continuousEdgesWithoutInputs
|
|
200
|
+
: this.continuousEdgesWithInputs).add(edge);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Continuous edges every `dependsOn` path into which has `inputs: false`.
|
|
204
|
+
* Undefined when there are none, so graphs without the option are unchanged.
|
|
205
|
+
*/
|
|
206
|
+
continuousDependenciesWithoutInputs() {
|
|
207
|
+
let without;
|
|
208
|
+
for (const [taskId, deps] of Object.entries(this.continuousDependencies)) {
|
|
209
|
+
const excluded = deps.filter((dep) => {
|
|
210
|
+
const edge = `${taskId}\0${dep}`;
|
|
211
|
+
return (this.continuousEdgesWithoutInputs.has(edge) &&
|
|
212
|
+
!this.continuousEdgesWithInputs.has(edge));
|
|
213
|
+
});
|
|
214
|
+
if (excluded.length > 0) {
|
|
215
|
+
(without ??= {})[taskId] = excluded;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return without;
|
|
219
|
+
}
|
|
189
220
|
recordEdge(task, dependencyId, overrides) {
|
|
190
221
|
if (!this.recordDependencyOverrides) {
|
|
191
222
|
return;
|
|
@@ -276,11 +307,15 @@ function filterTaskGraphToSelection(projectGraph, taskGraph, dependencyOverrides
|
|
|
276
307
|
}
|
|
277
308
|
function buildTaskGraph(p, projectNames, targets, configuration, overrides, excludeTaskDependencies) {
|
|
278
309
|
const roots = p.processTasks(projectNames, targets, configuration, overrides, excludeTaskDependencies);
|
|
310
|
+
const continuousDependenciesWithoutInputs = p.continuousDependenciesWithoutInputs();
|
|
279
311
|
return {
|
|
280
312
|
roots,
|
|
281
313
|
tasks: p.tasks,
|
|
282
314
|
dependencies: p.dependencies,
|
|
283
315
|
continuousDependencies: p.continuousDependencies,
|
|
316
|
+
...(continuousDependenciesWithoutInputs
|
|
317
|
+
? { continuousDependenciesWithoutInputs }
|
|
318
|
+
: {}),
|
|
284
319
|
};
|
|
285
320
|
}
|
|
286
321
|
function interpolateOverrides(args, projectName, project) {
|
|
@@ -37,6 +37,16 @@ export declare function getTaskSpecificEnv(task: Task, graph: ProjectGraph): Nod
|
|
|
37
37
|
*/
|
|
38
38
|
export declare function getGraphTimeDotEnvForTask(projectRoot: string, target: string, configuration?: string, nonAtomizedTarget?: string, baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
39
39
|
export declare function getEnvVariablesForTask(task: Task, taskSpecificEnv: NodeJS.ProcessEnv, forceColor: string, skipNxCache: boolean, captureStderr: boolean, outputPath: string, streamOutput: boolean): NodeJS.ProcessEnv;
|
|
40
|
+
/**
|
|
41
|
+
* Pids of the nx processes this one is nested inside, outermost first. Empty
|
|
42
|
+
* for a root invocation.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getInvocationAncestorPids(): number[];
|
|
45
|
+
/**
|
|
46
|
+
* Pid of the outermost nx process in this tree, which is this process when it
|
|
47
|
+
* is the root.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getInvocationRootPid(): number;
|
|
40
50
|
/**
|
|
41
51
|
* This function loads one or more .env files and expands the variables in them.
|
|
42
52
|
* When multiple files are provided, all files are loaded first, then variable
|
|
@@ -5,6 +5,8 @@ exports.getEnvVariablesForBatchProcess = getEnvVariablesForBatchProcess;
|
|
|
5
5
|
exports.getTaskSpecificEnv = getTaskSpecificEnv;
|
|
6
6
|
exports.getGraphTimeDotEnvForTask = getGraphTimeDotEnvForTask;
|
|
7
7
|
exports.getEnvVariablesForTask = getEnvVariablesForTask;
|
|
8
|
+
exports.getInvocationAncestorPids = getInvocationAncestorPids;
|
|
9
|
+
exports.getInvocationRootPid = getInvocationRootPid;
|
|
8
10
|
exports.loadAndExpandDotEnvFile = loadAndExpandDotEnvFile;
|
|
9
11
|
exports.unloadDotEnvFile = unloadDotEnvFile;
|
|
10
12
|
exports.getEnvFilesForTask = getEnvFilesForTask;
|
|
@@ -128,6 +130,10 @@ function getNxEnvVariablesForForkedProcess(forceColor, skipNxCache, captureStder
|
|
|
128
130
|
FORCE_COLOR: forceColor,
|
|
129
131
|
NX_WORKSPACE_ROOT: workspace_root_1.workspaceRoot,
|
|
130
132
|
NX_SKIP_NX_CACHE: skipNxCache ? 'true' : undefined,
|
|
133
|
+
// pids of the forked process's ancestor nx processes, outermost first.
|
|
134
|
+
// Only an ancestor re-invoking a task is a loop — sibling nx processes
|
|
135
|
+
// running the same task are legitimate.
|
|
136
|
+
NX_INVOCATION_ANCESTOR_PIDS: appendAncestorPid(process.env.NX_INVOCATION_ANCESTOR_PIDS),
|
|
131
137
|
};
|
|
132
138
|
if (outputPath) {
|
|
133
139
|
env.NX_TERMINAL_OUTPUT_PATH = outputPath;
|
|
@@ -140,6 +146,26 @@ function getNxEnvVariablesForForkedProcess(forceColor, skipNxCache, captureStder
|
|
|
140
146
|
}
|
|
141
147
|
return env;
|
|
142
148
|
}
|
|
149
|
+
function appendAncestorPid(inherited) {
|
|
150
|
+
return inherited ? `${inherited},${process.pid}` : String(process.pid);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Pids of the nx processes this one is nested inside, outermost first. Empty
|
|
154
|
+
* for a root invocation.
|
|
155
|
+
*/
|
|
156
|
+
function getInvocationAncestorPids() {
|
|
157
|
+
return (process.env.NX_INVOCATION_ANCESTOR_PIDS ?? '')
|
|
158
|
+
.split(',')
|
|
159
|
+
.map((pid) => Number(pid))
|
|
160
|
+
.filter((pid) => Number.isInteger(pid) && pid > 0);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Pid of the outermost nx process in this tree, which is this process when it
|
|
164
|
+
* is the root.
|
|
165
|
+
*/
|
|
166
|
+
function getInvocationRootPid() {
|
|
167
|
+
return getInvocationAncestorPids()[0] ?? process.pid;
|
|
168
|
+
}
|
|
143
169
|
function getNxEnvVariablesForTask(task, forceColor, skipNxCache, captureStderr, outputPath, streamOutput) {
|
|
144
170
|
const env = {
|
|
145
171
|
NX_TASK_TARGET_PROJECT: task.target.project,
|
|
@@ -153,16 +179,11 @@ function getNxEnvVariablesForTask(task, forceColor, skipNxCache, captureStderr,
|
|
|
153
179
|
if (task.target.target === 'test') {
|
|
154
180
|
env.NX_TERMINAL_CAPTURE_STDERR = 'true';
|
|
155
181
|
}
|
|
156
|
-
// Pass the root Nx process PID to nested processes for DB-based loop detection.
|
|
157
|
-
// The root PID is used as a key in the task_invocations table to track which tasks
|
|
158
|
-
// have been invoked across nested Nx processes.
|
|
159
182
|
return {
|
|
160
183
|
...getNxEnvVariablesForForkedProcess(forceColor, skipNxCache, captureStderr, outputPath, streamOutput),
|
|
161
184
|
...env,
|
|
162
185
|
// Ensure the TUI does not get spawned within the TUI if ever tasks invoke Nx again
|
|
163
186
|
NX_TUI: 'false',
|
|
164
|
-
// tracks the root PID for child nx tasks, used to verify nx is infinitely recursing through the same tasks
|
|
165
|
-
NX_INVOCATION_ROOT_PID: process.env.NX_INVOCATION_ROOT_PID ?? String(process.pid),
|
|
166
187
|
};
|
|
167
188
|
}
|
|
168
189
|
/**
|
|
@@ -94,12 +94,18 @@ export declare class TaskOrchestrator {
|
|
|
94
94
|
private processTask;
|
|
95
95
|
processAllScheduledTasks(): void;
|
|
96
96
|
/**
|
|
97
|
-
* Registers a task invocation and checks for loops across nested Nx
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
97
|
+
* Registers a task invocation and checks for loops across nested Nx
|
|
98
|
+
* processes. registerTask() returns the invocation chain only when an
|
|
99
|
+
* *ancestor* Nx process is already running this task — a genuine loop.
|
|
100
|
+
* Sibling processes running the same task are legitimate and register
|
|
101
|
+
* without complaint.
|
|
102
|
+
*
|
|
103
|
+
* The overrides hash rides along with the task id so the tracker can tell an
|
|
104
|
+
* ancestor re-invoking a task with different arguments from one repeating
|
|
105
|
+
* the same invocation.
|
|
101
106
|
*/
|
|
102
107
|
private detectTaskInvocationLoop;
|
|
108
|
+
private releaseTaskInvocation;
|
|
103
109
|
private applyCachedResults;
|
|
104
110
|
/**
|
|
105
111
|
* Batch cache lookup + filter to successful entries. Handles both
|