nx 24.0.5 → 24.1.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/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/adapter/ngcli-adapter.js +7 -20
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +0 -1
- package/dist/src/command-line/generate/generate.js +12 -23
- package/dist/src/command-line/graph/graph.js +1 -7
- package/dist/src/command-line/import/utils/prepare-source-repo.js +0 -3
- package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +2 -2
- package/dist/src/command-line/init/init-v2.js +2 -2
- package/dist/src/command-line/migrate/migrate.js +4 -6
- package/dist/src/command-line/migrate/prompt-files.js +5 -5
- package/dist/src/command-line/migrate/run/orchestrator.js +2 -3
- package/dist/src/command-line/migrate/run/worker.js +7 -5
- package/dist/src/command-line/migrate/run-migration-process.js +3 -2
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +1 -1
- package/dist/src/command-line/release/changelog.js +8 -39
- package/dist/src/command-line/release/config/use-legacy-versioning.js +1 -1
- package/dist/src/command-line/release/utils/diff.js +0 -14
- package/dist/src/command-line/release/utils/git.js +1 -1
- package/dist/src/command-line/reset/reset.js +13 -1
- package/dist/src/command-line/run/executor-utils.js +1 -1
- package/dist/src/command-line/show/show-target/utils.js +1 -1
- package/dist/src/command-line/watch/watch.js +1 -1
- package/dist/src/commands-runner/get-command-projects.js +0 -3
- package/dist/src/config/misc-interfaces.d.ts +0 -1
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.css +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/daemon-environment.d.ts +5 -3
- package/dist/src/daemon/client/daemon-environment.js +15 -3
- package/dist/src/devkit-internals.js +1 -1
- 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/hasher/hash-task.js +4 -4
- package/dist/src/hasher/task-hasher.js +2 -2
- package/dist/src/native/index.js +31 -3
- 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/nx-cloud/utilities/environment.js +0 -17
- package/dist/src/plugins/js/lock-file/bun-parser.js +0 -2
- package/dist/src/plugins/js/lock-file/npm-parser.js +1 -2
- 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 +31 -13
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +7 -1
- package/dist/src/plugins/js/utils/get-workspace-packages-from-graph.js +1 -1
- package/dist/src/plugins/js/utils/register.js +1 -1
- package/dist/src/project-graph/affected/affected-tasks.js +1 -1
- package/dist/src/tasks-runner/run-command.js +6 -7
- 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.js +1 -1
- package/dist/src/tasks-runner/utils.js +1 -12
- package/dist/src/ultracache/overrides.js +1 -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/code-frames.js +0 -1
- package/dist/src/utils/compile-cache.d.ts +6 -8
- package/dist/src/utils/compile-cache.js +23 -16
- package/dist/src/utils/db-connection.js +6 -4
- package/dist/src/utils/min-release-age/behavior/pnpm.js +9 -9
- package/dist/src/utils/min-release-age/behavior/yarn.js +2 -2
- 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/package-json.js +40 -20
- package/dist/src/utils/package-manager.d.ts +15 -0
- package/dist/src/utils/package-manager.js +184 -2
- package/dist/src/utils/plugins/output.js +0 -2
- package/package.json +12 -12
|
@@ -14,6 +14,7 @@ const path_1 = require("path");
|
|
|
14
14
|
const task_hasher_1 = require("../../../hasher/task-hasher");
|
|
15
15
|
const output_1 = require("../../../utils/output");
|
|
16
16
|
const project_graph_pruning_1 = require("../lock-file/project-graph-pruning");
|
|
17
|
+
const logger_1 = require("../../../utils/logger");
|
|
17
18
|
/**
|
|
18
19
|
* Creates a package.json in the output directory for support to install dependencies within containers.
|
|
19
20
|
*
|
|
@@ -28,7 +29,7 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
28
29
|
const npmDeps = findProjectsNpmDependencies(projectNode, graph, options.target, rootPackageJson, {
|
|
29
30
|
helperDependencies: options.helperDependencies,
|
|
30
31
|
isProduction: options.isProduction,
|
|
31
|
-
}, fileMap);
|
|
32
|
+
}, fileMap, root);
|
|
32
33
|
// default package.json if one does not exist
|
|
33
34
|
let packageJson = {
|
|
34
35
|
name: projectName,
|
|
@@ -211,7 +212,7 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
211
212
|
// endregion Overrides/Resolutions
|
|
212
213
|
return packageJson;
|
|
213
214
|
}
|
|
214
|
-
function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson, options, fileMap) {
|
|
215
|
+
function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson, options, fileMap, root = workspace_root_1.workspaceRoot) {
|
|
215
216
|
if (fileMap == null) {
|
|
216
217
|
fileMap = (0, nx_deps_cache_1.readFileMapCache)()?.fileMap?.projectFileMap || {};
|
|
217
218
|
}
|
|
@@ -231,7 +232,7 @@ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson
|
|
|
231
232
|
}
|
|
232
233
|
seen.add(node.name);
|
|
233
234
|
npmDeps.dependencies[node.data.packageName] = node.data.version;
|
|
234
|
-
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen);
|
|
235
|
+
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
|
|
235
236
|
});
|
|
236
237
|
// if it's production, we want to ignore all found devDependencies
|
|
237
238
|
const ignoredDependencies = options.isProduction && rootPackageJson.devDependencies
|
|
@@ -240,10 +241,10 @@ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson
|
|
|
240
241
|
...Object.keys(rootPackageJson.devDependencies),
|
|
241
242
|
]
|
|
242
243
|
: options.ignoredDependencies || [];
|
|
243
|
-
findAllNpmDeps(fileMap, projectNode, graph, npmDeps, seen, ignoredDependencies, dependencyInputs, selfInputs, false);
|
|
244
|
+
findAllNpmDeps(fileMap, projectNode, graph, npmDeps, seen, root, ignoredDependencies, dependencyInputs, selfInputs, false);
|
|
244
245
|
return npmDeps;
|
|
245
246
|
}
|
|
246
|
-
function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, ignoredDependencies, dependencyPatterns, rootPatterns, isTransitiveDependency = false) {
|
|
247
|
+
function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, root, ignoredDependencies, dependencyPatterns, rootPatterns, isTransitiveDependency = false) {
|
|
247
248
|
if (seen.has(projectNode.name))
|
|
248
249
|
return;
|
|
249
250
|
seen.add(projectNode.name);
|
|
@@ -271,10 +272,10 @@ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, ignor
|
|
|
271
272
|
continue;
|
|
272
273
|
}
|
|
273
274
|
npmDeps.dependencies[node.data.packageName] = node.data.version;
|
|
274
|
-
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen);
|
|
275
|
+
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
|
|
275
276
|
}
|
|
276
277
|
else if (graph.nodes[dep]) {
|
|
277
|
-
findAllNpmDeps(projectFileMap, graph.nodes[dep], graph, npmDeps, seen, ignoredDependencies, dependencyPatterns, undefined, true);
|
|
278
|
+
findAllNpmDeps(projectFileMap, graph.nodes[dep], graph, npmDeps, seen, root, ignoredDependencies, dependencyPatterns, undefined, true);
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
}
|
|
@@ -294,14 +295,14 @@ function findHelperDependencyNode(graph, projectName, dep) {
|
|
|
294
295
|
? graph.externalNodes[projectDependency.target]
|
|
295
296
|
: (0, project_graph_pruning_1.findNodeMatchingVersion)(graph, packageName, '*');
|
|
296
297
|
}
|
|
297
|
-
function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen) {
|
|
298
|
+
function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen, root) {
|
|
298
299
|
const npmPackage = graph.externalNodes[projectName];
|
|
299
300
|
if (!npmPackage) {
|
|
300
301
|
return npmDeps;
|
|
301
302
|
}
|
|
302
303
|
const packageName = npmPackage.data.packageName;
|
|
303
304
|
try {
|
|
304
|
-
const packageJson =
|
|
305
|
+
const packageJson = readDependencyPackageJson(packageName, root);
|
|
305
306
|
if (!packageJson.peerDependencies) {
|
|
306
307
|
return npmDeps;
|
|
307
308
|
}
|
|
@@ -310,22 +311,39 @@ function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen) {
|
|
|
310
311
|
.map((dependency) => graph.externalNodes[dependency])
|
|
311
312
|
.filter(Boolean)
|
|
312
313
|
.forEach((node) => {
|
|
314
|
+
const isOptional = packageJson.peerDependenciesMeta?.[node.data.packageName]?.optional;
|
|
313
315
|
if (!seen.has(node.name)) {
|
|
314
316
|
seen.add(node.name);
|
|
315
317
|
npmDeps.peerDependencies[node.data.packageName] = node.data.version;
|
|
316
|
-
if (
|
|
317
|
-
packageJson.peerDependenciesMeta[node.data.packageName] &&
|
|
318
|
-
packageJson.peerDependenciesMeta[node.data.packageName].optional) {
|
|
318
|
+
if (isOptional) {
|
|
319
319
|
npmDeps.peerDependenciesMeta[node.data.packageName] = {
|
|
320
320
|
optional: true,
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
|
-
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen);
|
|
323
|
+
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
|
|
324
|
+
}
|
|
325
|
+
else if (!isOptional) {
|
|
326
|
+
// A peer stays optional only while every host declaring it says so.
|
|
327
|
+
delete npmDeps.peerDependenciesMeta[node.data.packageName];
|
|
324
328
|
}
|
|
325
329
|
});
|
|
326
330
|
return npmDeps;
|
|
327
331
|
}
|
|
328
332
|
catch (e) {
|
|
333
|
+
logger_1.logger.verbose(`Could not read the package.json of ${packageName}, so its peer dependencies were not collected: ${e.message}`);
|
|
329
334
|
return npmDeps;
|
|
330
335
|
}
|
|
331
336
|
}
|
|
337
|
+
// Watch builds collect peers on every compilation, so read each manifest once.
|
|
338
|
+
const dependencyPackageJsonCache = new Map();
|
|
339
|
+
function readDependencyPackageJson(packageName, root) {
|
|
340
|
+
const cacheKey = `${root}\0${packageName}`;
|
|
341
|
+
let packageJson = dependencyPackageJsonCache.get(cacheKey);
|
|
342
|
+
if (!packageJson) {
|
|
343
|
+
// nx's own location first: under pnpm it reaches the hidden hoisted
|
|
344
|
+
// .pnpm/node_modules, which the workspace root does not.
|
|
345
|
+
({ packageJson } = (0, package_json_1.readModulePackageJson)(packageName, [__dirname, root]));
|
|
346
|
+
dependencyPackageJsonCache.set(cacheKey, packageJson);
|
|
347
|
+
}
|
|
348
|
+
return packageJson;
|
|
349
|
+
}
|
|
@@ -19,9 +19,15 @@ const typescript_1 = require("../../utils/typescript");
|
|
|
19
19
|
const defaultNpmResolutionCache = new Map();
|
|
20
20
|
const defaultPackageJsonResolutionCache = new Map();
|
|
21
21
|
const experimentalNodeModules = new Set(['node:sqlite']);
|
|
22
|
+
// Node's isBuiltin is false for Bun's runtime modules (`bun`, `bun:*`).
|
|
23
|
+
function isBunModuleImport(importExpr) {
|
|
24
|
+
return importExpr === 'bun' || importExpr.startsWith('bun:');
|
|
25
|
+
}
|
|
22
26
|
function isBuiltinModuleImport(importExpr) {
|
|
23
27
|
const packageName = (0, get_package_name_from_import_path_1.getPackageNameFromImportPath)(importExpr);
|
|
24
|
-
return (0, node_module_1.isBuiltin)(packageName) ||
|
|
28
|
+
return ((0, node_module_1.isBuiltin)(packageName) ||
|
|
29
|
+
experimentalNodeModules.has(packageName) ||
|
|
30
|
+
isBunModuleImport(importExpr));
|
|
25
31
|
}
|
|
26
32
|
// TypeScript matches the `${configDir}` template case-insensitively and only as a
|
|
27
33
|
// prefix (commandLineParser.ts `startsWithConfigDirTemplate`).
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getWorkspacePackagesFromGraph = getWorkspacePackagesFromGraph;
|
|
4
4
|
function getWorkspacePackagesFromGraph(graph) {
|
|
5
5
|
const workspacePackages = new Map();
|
|
6
|
-
for (const [
|
|
6
|
+
for (const [, project] of Object.entries(graph.nodes)) {
|
|
7
7
|
const pkgName = project.data?.metadata?.js?.packageName;
|
|
8
8
|
if (pkgName) {
|
|
9
9
|
workspacePackages.set(pkgName, project);
|
|
@@ -176,7 +176,7 @@ async function matchAffectedTasks(projectGraph, nxJson, planningContext, request
|
|
|
176
176
|
const dependencies = dependencyChanges(projectGraph, touchedFiles, nxJson, packageJson);
|
|
177
177
|
const namedProjects = new Set(dependencies.projects);
|
|
178
178
|
const projects = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects;
|
|
179
|
-
// TODO(v25): remove custom hasher support.
|
|
179
|
+
// TODO(v25): remove custom hasher support (NXC-5052).
|
|
180
180
|
const customHashed = new Set(taskIds.filter((id) => hasCustomHasher(taskGraph.tasks[id], projects)));
|
|
181
181
|
const options = {
|
|
182
182
|
projectGlobPatterns: await (0, affected_projects_1.getProjectGlobPatterns)(nxJson),
|
|
@@ -187,7 +187,7 @@ async function getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, pr
|
|
|
187
187
|
/**
|
|
188
188
|
* Patch stdout.write and stderr.write methods to pass Nx Cloud client logs to the TUI via the lifecycle
|
|
189
189
|
*/
|
|
190
|
-
const createPatchedLogWrite = (
|
|
190
|
+
const createPatchedLogWrite = (isError) => {
|
|
191
191
|
// @ts-ignore
|
|
192
192
|
return (chunk, encoding, callback) => {
|
|
193
193
|
if (isError) {
|
|
@@ -200,7 +200,6 @@ async function getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, pr
|
|
|
200
200
|
? chunk.toString(encoding)
|
|
201
201
|
: chunk.toString());
|
|
202
202
|
}
|
|
203
|
-
// Check if the log came from the Nx Cloud client, otherwise invoke the original write method
|
|
204
203
|
const stackTrace = new Error().stack;
|
|
205
204
|
const isNxCloudLog = stackTrace.includes(nxCloudClientDir);
|
|
206
205
|
if (isNxCloudLog) {
|
|
@@ -231,8 +230,8 @@ async function getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, pr
|
|
|
231
230
|
// No-op the Nx Cloud client logs
|
|
232
231
|
};
|
|
233
232
|
};
|
|
234
|
-
process.stdout.write = createPatchedLogWrite(
|
|
235
|
-
process.stderr.write = createPatchedLogWrite(
|
|
233
|
+
process.stdout.write = createPatchedLogWrite(false);
|
|
234
|
+
process.stderr.write = createPatchedLogWrite(true);
|
|
236
235
|
// The cloud client calls console.log when NX_VERBOSE_LOGGING is set to true
|
|
237
236
|
console.log = createPatchedConsoleMethod(originalConsoleLog);
|
|
238
237
|
console.error = createPatchedConsoleMethod(originalConsoleError);
|
|
@@ -278,8 +277,8 @@ async function getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, pr
|
|
|
278
277
|
renderIsDone: Promise.resolve(),
|
|
279
278
|
};
|
|
280
279
|
}
|
|
281
|
-
|
|
282
|
-
const useDynamicOutput = shouldUseDynamicLifeCycle(tasks,
|
|
280
|
+
getRunner(nxArgs, nxJson);
|
|
281
|
+
const useDynamicOutput = shouldUseDynamicLifeCycle(tasks, nxArgs.specifiedOutputStyle);
|
|
283
282
|
if (isRunOne) {
|
|
284
283
|
if (useDynamicOutput) {
|
|
285
284
|
return await (0, dynamic_run_one_terminal_output_life_cycle_1.createRunOneDynamicOutputRenderer)({
|
|
@@ -826,7 +825,7 @@ async function convertObservableToPromise(obs) {
|
|
|
826
825
|
});
|
|
827
826
|
});
|
|
828
827
|
}
|
|
829
|
-
function shouldUseDynamicLifeCycle(tasks,
|
|
828
|
+
function shouldUseDynamicLifeCycle(tasks, outputStyle) {
|
|
830
829
|
if (process.env.NX_BATCH_MODE === 'true' ||
|
|
831
830
|
process.env.NX_VERBOSE_LOGGING === 'true' ||
|
|
832
831
|
process.env.NX_TASKS_RUNNER_DYNAMIC_OUTPUT === 'false') {
|
|
@@ -77,6 +77,7 @@ export declare class BatchProcess {
|
|
|
77
77
|
* summary is still pointing at.
|
|
78
78
|
*/
|
|
79
79
|
private readonly captureNonce;
|
|
80
|
+
private readonly stdioClosed;
|
|
80
81
|
constructor(childProcess: ChildProcess, executorName: string,
|
|
81
82
|
/**
|
|
82
83
|
* Whether the worker's output is written to the terminal as it streams.
|
|
@@ -128,8 +129,8 @@ export declare class BatchProcess {
|
|
|
128
129
|
* batch as one fold, so output no task claimed is not lost.
|
|
129
130
|
*
|
|
130
131
|
* Not valid to read before `flushCapturedOutput`; that flush ends the stream,
|
|
131
|
-
* so a chunk arriving afterwards - a worker
|
|
132
|
-
*
|
|
132
|
+
* so a chunk arriving afterwards - a worker can still write after the
|
|
133
|
+
* results message `getResults()` settles on - is dropped rather than appended.
|
|
133
134
|
*/
|
|
134
135
|
getCapturedOutputPath(): string | undefined;
|
|
135
136
|
/** Releases the capture file. Safe to call more than once. */
|
|
@@ -6,6 +6,7 @@ const crypto_1 = require("crypto");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const native_1 = require("../../native");
|
|
8
8
|
const cache_1 = require("../cache");
|
|
9
|
+
const child_process_1 = require("../../utils/child-process");
|
|
9
10
|
const exit_codes_1 = require("../../utils/exit-codes");
|
|
10
11
|
const output_1 = require("../../utils/output");
|
|
11
12
|
const batch_messages_1 = require("../batch/batch-messages");
|
|
@@ -68,6 +69,7 @@ class BatchProcess {
|
|
|
68
69
|
* summary is still pointing at.
|
|
69
70
|
*/
|
|
70
71
|
this.captureNonce = (0, crypto_1.randomBytes)(4).toString('hex');
|
|
72
|
+
this.stdioClosed = (0, child_process_1.whenStdioClosed)(this.childProcess);
|
|
71
73
|
this.childProcess.on('message', (message) => {
|
|
72
74
|
switch (message.type) {
|
|
73
75
|
case batch_messages_1.BatchMessageType.CompleteTask: {
|
|
@@ -294,8 +296,8 @@ class BatchProcess {
|
|
|
294
296
|
* batch as one fold, so output no task claimed is not lost.
|
|
295
297
|
*
|
|
296
298
|
* Not valid to read before `flushCapturedOutput`; that flush ends the stream,
|
|
297
|
-
* so a chunk arriving afterwards - a worker
|
|
298
|
-
*
|
|
299
|
+
* so a chunk arriving afterwards - a worker can still write after the
|
|
300
|
+
* results message `getResults()` settles on - is dropped rather than appended.
|
|
299
301
|
*/
|
|
300
302
|
getCapturedOutputPath() {
|
|
301
303
|
return this.capturedOutputPath;
|
|
@@ -341,7 +343,9 @@ class BatchProcess {
|
|
|
341
343
|
new Promise((_, rej) => {
|
|
342
344
|
this.onExit((code) => {
|
|
343
345
|
if (code !== 0) {
|
|
344
|
-
|
|
346
|
+
// A rejection makes the caller flush the capture, which drops
|
|
347
|
+
// whatever the crashed worker wrote that has not been read yet.
|
|
348
|
+
this.stdioClosed.then(() => rej(new Error(`"${this.executorName}" exited unexpectedly with code: ${code}`)));
|
|
345
349
|
}
|
|
346
350
|
});
|
|
347
351
|
}),
|
|
@@ -371,7 +371,7 @@ class TaskOrchestrator {
|
|
|
371
371
|
// Use a separate groupId space (parallel..parallel+N) so continuous tasks
|
|
372
372
|
// don't consume discrete group slots
|
|
373
373
|
const groupId = this.options.parallel + this.continuousTasksStarted++;
|
|
374
|
-
|
|
374
|
+
await this.startContinuousTask(task, groupId);
|
|
375
375
|
if (this.initializingTaskIds.has(task.id)) {
|
|
376
376
|
await this.continuousTaskExitHandled.get(task.id);
|
|
377
377
|
}
|
|
@@ -147,17 +147,6 @@ function normalizeTargetDependencyWithStringProjects(dependencyConfig) {
|
|
|
147
147
|
}
|
|
148
148
|
return dependencyConfig;
|
|
149
149
|
}
|
|
150
|
-
class InvalidOutputsError extends Error {
|
|
151
|
-
constructor(outputs, invalidOutputs) {
|
|
152
|
-
super(InvalidOutputsError.createMessage(invalidOutputs));
|
|
153
|
-
this.outputs = outputs;
|
|
154
|
-
this.invalidOutputs = invalidOutputs;
|
|
155
|
-
}
|
|
156
|
-
static createMessage(invalidOutputs) {
|
|
157
|
-
const invalidOutputsList = '\n - ' + Array.from(invalidOutputs).join('\n - ');
|
|
158
|
-
return `The following outputs are invalid:${invalidOutputsList}\nPlease run "nx repair" to repair your configuration`;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
150
|
function assertOutputsAreValidType(outputs) {
|
|
162
151
|
if (!Array.isArray(outputs)) {
|
|
163
152
|
throw new Error("The 'outputs' field must be an array");
|
|
@@ -379,7 +368,7 @@ function getExecutorForTask(task, projects) {
|
|
|
379
368
|
const [nodeModule, executorName] = (0, executor_utils_1.parseExecutor)(executor);
|
|
380
369
|
return (0, executor_utils_1.getExecutorInformation)(nodeModule, executorName, workspace_root_1.workspaceRoot, projects);
|
|
381
370
|
}
|
|
382
|
-
// TODO(v25): remove custom hasher support.
|
|
371
|
+
// TODO(v25): remove custom hasher support (NXC-5052).
|
|
383
372
|
function getCustomHasher(task, projects) {
|
|
384
373
|
const factory = getExecutorForTask(task, projects).hasherFactory;
|
|
385
374
|
if (!factory) {
|
|
@@ -19,7 +19,7 @@ function customHasherTaskIds(projectGraph, taskGraph) {
|
|
|
19
19
|
return memoized;
|
|
20
20
|
}
|
|
21
21
|
const projects = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects;
|
|
22
|
-
// TODO(v25): remove custom hasher support.
|
|
22
|
+
// TODO(v25): remove custom hasher support (NXC-5052).
|
|
23
23
|
const ids = Object.values(taskGraph.tasks)
|
|
24
24
|
.filter((task) => {
|
|
25
25
|
try {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare class UntrustedDataDirectoryError extends Error {
|
|
2
|
+
constructor(kind: string, dir: string, reason: string);
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* `readNxJson` rather than a raw read, so a `cacheDirectory` reached through
|
|
3
6
|
* `extends` counts. It throws on malformed JSON, which must not take the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.workspaceDataDirectory = exports.cacheDir = void 0;
|
|
3
|
+
exports.workspaceDataDirectory = exports.cacheDir = exports.UntrustedDataDirectoryError = void 0;
|
|
4
4
|
exports.readCacheDirectoryProperty = readCacheDirectoryProperty;
|
|
5
5
|
exports.resetSharedRootCacheForTesting = resetSharedRootCacheForTesting;
|
|
6
6
|
exports.resolveSharedDataLocation = resolveSharedDataLocation;
|
|
@@ -16,6 +16,102 @@ const nx_tmp_dir_1 = require("./nx-tmp-dir");
|
|
|
16
16
|
const owned_private_dir_1 = require("./owned-private-dir");
|
|
17
17
|
const workspace_id_1 = require("./workspace-id");
|
|
18
18
|
const workspace_root_1 = require("./workspace-root");
|
|
19
|
+
const S_ISVTX = 0o1000;
|
|
20
|
+
const trustedConfiguredDirs = new Set();
|
|
21
|
+
class UntrustedDataDirectoryError extends Error {
|
|
22
|
+
constructor(kind, dir, reason) {
|
|
23
|
+
super(`The configured Nx ${kind} directory ${dir} is not safe to use: ${reason}. ` +
|
|
24
|
+
`Nx restores task outputs and reads cached configuration from this directory, so it must only be modifiable by you, root, or the owner of the workspace. ` +
|
|
25
|
+
`Point it at a directory you own instead, or set NX_ALLOW_INSECURE_DIRECTORIES=true to use it anyway.`);
|
|
26
|
+
this.name = 'UntrustedDataDirectoryError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.UntrustedDataDirectoryError = UntrustedDataDirectoryError;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a configured data directory and refuses it if a user other than us,
|
|
32
|
+
* root, or the workspace owner could replace its contents. Paths inside the
|
|
33
|
+
* workspace are trusted like the workspace. Group write is an explicit grant.
|
|
34
|
+
*/
|
|
35
|
+
function ensureTrustedConfiguredDir(dir, root, kind) {
|
|
36
|
+
const key = `${dir}\0${root}`;
|
|
37
|
+
if (typeof process.getuid !== 'function' || trustedConfiguredDirs.has(key)) {
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
40
|
+
// Claim a missing directory under a shared parent before another user can.
|
|
41
|
+
if (!isWithin((0, path_1.resolve)(dir), (0, path_1.resolve)(root)) && nearestExistingIsShared(dir)) {
|
|
42
|
+
try {
|
|
43
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true, mode: 0o775 });
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
}
|
|
47
|
+
const trusted = new Set([process.getuid(), 0]);
|
|
48
|
+
try {
|
|
49
|
+
trusted.add((0, fs_1.statSync)(root).uid);
|
|
50
|
+
}
|
|
51
|
+
catch { }
|
|
52
|
+
// The path as written catches a symlink a peer could repoint; the canonical
|
|
53
|
+
// path catches the directories the symlinks lead to.
|
|
54
|
+
for (const [leaf, stop] of [
|
|
55
|
+
[(0, path_1.resolve)(dir), (0, path_1.resolve)(root)],
|
|
56
|
+
[(0, owned_private_dir_1.canonicalDir)(dir), (0, owned_private_dir_1.canonicalDir)(root)],
|
|
57
|
+
]) {
|
|
58
|
+
if (isWithin(leaf, stop)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
for (let p = leaf; p !== stop; p = (0, path_1.dirname)(p)) {
|
|
62
|
+
const reason = untrustedReason(p, p === leaf, trusted);
|
|
63
|
+
if (reason) {
|
|
64
|
+
if (process.env.NX_ALLOW_INSECURE_DIRECTORIES !== 'true') {
|
|
65
|
+
throw new UntrustedDataDirectoryError(kind, dir, reason);
|
|
66
|
+
}
|
|
67
|
+
console.warn(`NX_ALLOW_INSECURE_DIRECTORIES is set, so Nx is using the ${kind} directory ${dir} although ${reason}.`);
|
|
68
|
+
trustedConfiguredDirs.add(key);
|
|
69
|
+
return dir;
|
|
70
|
+
}
|
|
71
|
+
if ((0, path_1.dirname)(p) === p) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
trustedConfiguredDirs.add(key);
|
|
77
|
+
return dir;
|
|
78
|
+
}
|
|
79
|
+
function nearestExistingIsShared(dir) {
|
|
80
|
+
for (let p = (0, path_1.resolve)(dir);; p = (0, path_1.dirname)(p)) {
|
|
81
|
+
try {
|
|
82
|
+
return ((0, fs_1.statSync)(p).mode & 0o002) !== 0;
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
if ((0, path_1.dirname)(p) === p) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isWithin(path, root) {
|
|
91
|
+
const rel = (0, path_1.relative)(root, path);
|
|
92
|
+
return !rel.startsWith('..') && !(0, path_1.isAbsolute)(rel);
|
|
93
|
+
}
|
|
94
|
+
function untrustedReason(path, isLeaf, trusted) {
|
|
95
|
+
let stats;
|
|
96
|
+
try {
|
|
97
|
+
stats = (0, fs_1.lstatSync)(path);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (!trusted.has(stats.uid)) {
|
|
103
|
+
return `${path} is owned by uid ${stats.uid}`;
|
|
104
|
+
}
|
|
105
|
+
if (!stats.isDirectory() || !(stats.mode & 0o002)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if (isLeaf) {
|
|
109
|
+
return `${path} is writable by other users`;
|
|
110
|
+
}
|
|
111
|
+
return stats.mode & S_ISVTX
|
|
112
|
+
? undefined
|
|
113
|
+
: `${path} is writable by other users and not sticky`;
|
|
114
|
+
}
|
|
19
115
|
function absolutePath(root, path) {
|
|
20
116
|
if ((0, path_1.isAbsolute)(path)) {
|
|
21
117
|
return path;
|
|
@@ -30,7 +126,7 @@ function cacheDirectory(root, cacheDirectory) {
|
|
|
30
126
|
cacheDirectory = cacheDirFromEnv;
|
|
31
127
|
}
|
|
32
128
|
if (cacheDirectory) {
|
|
33
|
-
return absolutePath(root, cacheDirectory);
|
|
129
|
+
return ensureTrustedConfiguredDir(absolutePath(root, cacheDirectory), root, 'cache');
|
|
34
130
|
}
|
|
35
131
|
else {
|
|
36
132
|
return defaultCacheDirectory(root);
|
|
@@ -81,30 +177,12 @@ const SHARED_SEGMENT = {
|
|
|
81
177
|
'workspace-data': 'databases',
|
|
82
178
|
};
|
|
83
179
|
const SHARED_DATA_KINDS = Object.keys(SHARED_SEGMENT);
|
|
84
|
-
/**
|
|
85
|
-
* Whether `~/.nx` is somewhere other than the shared container.
|
|
86
|
-
*
|
|
87
|
-
* `homedir()` honours `$HOME`, so with `HOME=/tmp` the two are one path -- and
|
|
88
|
-
* that container is deliberately world-writable (`1777`) so peers can each
|
|
89
|
-
* create their own subtree under it. Build outputs and the graph DB get
|
|
90
|
-
* replayed into the workspace and supply target commands, so they cannot live
|
|
91
|
-
* anywhere a peer can replace them.
|
|
92
|
-
*
|
|
93
|
-
* `daemon/tmp-dir.ts` makes the same check for the socket tier. It cannot be
|
|
94
|
-
* shared from there: that module imports this one.
|
|
95
|
-
*/
|
|
96
|
-
function homeDirIsDistinctFromSharedTmp() {
|
|
97
|
-
if (!nx_tmp_dir_1.NX_HOME_TMP_DIR) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
const home = (0, owned_private_dir_1.canonicalDir)(nx_tmp_dir_1.NX_HOME_TMP_DIR);
|
|
101
|
-
return ![nx_tmp_dir_1.NX_TMP_DIR, nx_tmp_dir_1.NX_USER_TMP_DIR].some((shared) => (0, owned_private_dir_1.canonicalDir)(shared) === home);
|
|
102
|
-
}
|
|
103
180
|
/** Memoizes the verdict below, per repository. */
|
|
104
181
|
const sharedRootUsable = new Map();
|
|
105
182
|
/** The establish verdict is cached per process; tests need it cleared. */
|
|
106
183
|
function resetSharedRootCacheForTesting() {
|
|
107
184
|
sharedRootUsable.clear();
|
|
185
|
+
trustedConfiguredDirs.clear();
|
|
108
186
|
workspaceIds.clear();
|
|
109
187
|
resolvedLocations.clear();
|
|
110
188
|
}
|
|
@@ -116,7 +194,7 @@ function resetSharedRootCacheForTesting() {
|
|
|
116
194
|
* it never wrote. One answer serves both.
|
|
117
195
|
*/
|
|
118
196
|
function establishUserRoot(workspaceId) {
|
|
119
|
-
if (!nx_tmp_dir_1.NX_HOME_TMP_DIR || !homeDirIsDistinctFromSharedTmp()) {
|
|
197
|
+
if (!nx_tmp_dir_1.NX_HOME_TMP_DIR || !(0, nx_tmp_dir_1.homeDirIsDistinctFromSharedTmp)()) {
|
|
120
198
|
return { kind: 'not-a-directory', dir: nx_tmp_dir_1.NX_HOME_TMP_DIR ?? '~/.nx' };
|
|
121
199
|
}
|
|
122
200
|
const repoRoot = (0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, sharedDirName(workspaceId));
|
|
@@ -331,7 +409,9 @@ function cacheDirectoryForWorkspace(root) {
|
|
|
331
409
|
*/
|
|
332
410
|
exports.workspaceDataDirectory = workspaceDataDirectoryForWorkspace(workspace_root_1.workspaceRoot);
|
|
333
411
|
function workspaceDataDirectoryForWorkspace(workspaceRoot) {
|
|
334
|
-
|
|
335
|
-
process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY
|
|
336
|
-
|
|
412
|
+
const configured = process.env.NX_WORKSPACE_DATA_DIRECTORY ??
|
|
413
|
+
process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY;
|
|
414
|
+
return configured !== undefined
|
|
415
|
+
? ensureTrustedConfiguredDir(absolutePath(workspaceRoot, configured), workspaceRoot, 'workspace data')
|
|
416
|
+
: defaultWorkspaceDataDirectory(workspaceRoot);
|
|
337
417
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExecOptions, type ExecSyncOptions, type SpawnSyncOptions } from 'child_process';
|
|
1
|
+
import { type ChildProcess as NodeChildProcess, type ExecOptions, type ExecSyncOptions, type SpawnSyncOptions } from 'child_process';
|
|
2
2
|
import { PackageManagerCommands } from './package-manager';
|
|
3
3
|
import { ChildProcess } from '../native';
|
|
4
4
|
export declare function getRunNxBaseCommand(packageManagerCommand?: PackageManagerCommands, cwd?: string): string;
|
|
@@ -41,6 +41,13 @@ export declare function runNxAsync(cmd: string, options?: ExecOptions & {
|
|
|
41
41
|
silent?: boolean;
|
|
42
42
|
packageManagerCommand?: PackageManagerCommands;
|
|
43
43
|
}): Promise<void>;
|
|
44
|
+
export declare function hasExited(child: NodeChildProcess): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Settles once `child`'s stdio has closed, which Node reports after 'exit'.
|
|
47
|
+
* Call it at spawn time: a 'close' emitted before the call is missed. Gives up
|
|
48
|
+
* 1s after 'exit', since a descendant can keep the pipes open indefinitely.
|
|
49
|
+
*/
|
|
50
|
+
export declare function whenStdioClosed(child: NodeChildProcess): Promise<void>;
|
|
44
51
|
export declare class PseudoTtyProcess {
|
|
45
52
|
private childProcess;
|
|
46
53
|
isAlive: boolean;
|
|
@@ -7,6 +7,8 @@ exports.readInstalledNxBin = readInstalledNxBin;
|
|
|
7
7
|
exports.runNxArgvSync = runNxArgvSync;
|
|
8
8
|
exports.runNxSync = runNxSync;
|
|
9
9
|
exports.runNxAsync = runNxAsync;
|
|
10
|
+
exports.hasExited = hasExited;
|
|
11
|
+
exports.whenStdioClosed = whenStdioClosed;
|
|
10
12
|
const child_process_1 = require("child_process");
|
|
11
13
|
const fs_1 = require("fs");
|
|
12
14
|
const path_1 = require("path");
|
|
@@ -160,6 +162,28 @@ async function runNxAsync(cmd, options) {
|
|
|
160
162
|
}
|
|
161
163
|
});
|
|
162
164
|
}
|
|
165
|
+
function hasExited(child) {
|
|
166
|
+
return child.exitCode !== null || child.signalCode !== null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Settles once `child`'s stdio has closed, which Node reports after 'exit'.
|
|
170
|
+
* Call it at spawn time: a 'close' emitted before the call is missed. Gives up
|
|
171
|
+
* 1s after 'exit', since a descendant can keep the pipes open indefinitely.
|
|
172
|
+
*/
|
|
173
|
+
function whenStdioClosed(child) {
|
|
174
|
+
return new Promise((resolve) => {
|
|
175
|
+
let timeout;
|
|
176
|
+
child.once('close', () => {
|
|
177
|
+
clearTimeout(timeout);
|
|
178
|
+
resolve();
|
|
179
|
+
});
|
|
180
|
+
child.once('exit', () => {
|
|
181
|
+
// Node runs expired timers before it reads the pipes, so a blocked event
|
|
182
|
+
// loop would otherwise give up on output that is already there.
|
|
183
|
+
timeout = setTimeout(() => setImmediate(resolve), 1000);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
163
187
|
class PseudoTtyProcess {
|
|
164
188
|
constructor(childProcess) {
|
|
165
189
|
this.childProcess = childProcess;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Enables V8's on-disk bytecode cache for the current process.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The cache lives in the current user's owner-only Nx tmp directory, because
|
|
5
|
+
* Node's default location is a shared `os.tmpdir()` path whose contents are
|
|
6
|
+
* loaded regardless of who created them. If that directory cannot be
|
|
7
|
+
* established securely, the cache stays off. Node's env vars still apply:
|
|
8
|
+
* - `NODE_COMPILE_CACHE=<dir>` — the user's chosen directory wins.
|
|
7
9
|
* - `NODE_DISABLE_COMPILE_CACHE=1` — disable entirely.
|
|
8
10
|
*
|
|
9
|
-
* The default location lives under the OS temp dir keyed by V8 version, so
|
|
10
|
-
* the cache is shared across workspaces and self-invalidates on Node
|
|
11
|
-
* upgrades — no nx-specific cleanup needed.
|
|
12
|
-
*
|
|
13
11
|
* Called at the entry point of every long-lived nx process (main CLI,
|
|
14
12
|
* daemon, plugin workers) via `enable-compile-cache.ts`, which side-effects
|
|
15
13
|
* this on import.
|
|
@@ -21,4 +19,4 @@
|
|
|
21
19
|
* Errors are swallowed — the compile cache is a pure performance
|
|
22
20
|
* optimization and must never break the CLI.
|
|
23
21
|
*/
|
|
24
|
-
export declare function enableCompileCache(
|
|
22
|
+
export declare function enableCompileCache(impl?: unknown, cacheDir?: string): boolean;
|