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
|
@@ -3,18 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enableCompileCache = enableCompileCache;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const nodeModule = tslib_1.__importStar(require("node:module"));
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const nx_tmp_dir_1 = require("./nx-tmp-dir");
|
|
8
|
+
const owned_private_dir_1 = require("./owned-private-dir");
|
|
9
|
+
const COMPILE_CACHE_DIR = (0, node_path_1.join)(nx_tmp_dir_1.NX_USER_TMP_DIR, 'compile-cache');
|
|
6
10
|
/**
|
|
7
11
|
* Enables V8's on-disk bytecode cache for the current process.
|
|
8
12
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
13
|
+
* The cache lives in the current user's owner-only Nx tmp directory, because
|
|
14
|
+
* Node's default location is a shared `os.tmpdir()` path whose contents are
|
|
15
|
+
* loaded regardless of who created them. If that directory cannot be
|
|
16
|
+
* established securely, the cache stays off. Node's env vars still apply:
|
|
17
|
+
* - `NODE_COMPILE_CACHE=<dir>` — the user's chosen directory wins.
|
|
12
18
|
* - `NODE_DISABLE_COMPILE_CACHE=1` — disable entirely.
|
|
13
19
|
*
|
|
14
|
-
* The default location lives under the OS temp dir keyed by V8 version, so
|
|
15
|
-
* the cache is shared across workspaces and self-invalidates on Node
|
|
16
|
-
* upgrades — no nx-specific cleanup needed.
|
|
17
|
-
*
|
|
18
20
|
* Called at the entry point of every long-lived nx process (main CLI,
|
|
19
21
|
* daemon, plugin workers) via `enable-compile-cache.ts`, which side-effects
|
|
20
22
|
* this on import.
|
|
@@ -27,20 +29,25 @@ const nodeModule = tslib_1.__importStar(require("node:module"));
|
|
|
27
29
|
* optimization and must never break the CLI.
|
|
28
30
|
*/
|
|
29
31
|
function enableCompileCache(
|
|
30
|
-
// Test
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
// read `arguments.length` so callers can *explicitly* pass `undefined`.
|
|
34
|
-
...override) {
|
|
32
|
+
// Test seams: production callers omit both. A non-function `impl` simulates
|
|
33
|
+
// pre-22.8 Node, where `module.enableCompileCache` is missing.
|
|
34
|
+
impl = nodeModule.enableCompileCache, cacheDir = COMPILE_CACHE_DIR) {
|
|
35
35
|
if (process.env.NX_COMPILE_CACHE === 'false')
|
|
36
36
|
return false;
|
|
37
|
-
const impl = override.length === 0
|
|
38
|
-
? nodeModule.enableCompileCache
|
|
39
|
-
: override[0];
|
|
40
37
|
if (typeof impl !== 'function')
|
|
41
38
|
return false;
|
|
42
39
|
try {
|
|
43
|
-
|
|
40
|
+
if (process.env.NODE_COMPILE_CACHE) {
|
|
41
|
+
impl();
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
const userRoot = (0, node_path_1.dirname)(cacheDir);
|
|
45
|
+
if ((0, owned_private_dir_1.ensureSafeSharedRoot)((0, node_path_1.dirname)(userRoot)).status !== 'ok' ||
|
|
46
|
+
(0, owned_private_dir_1.ensureOwnedPrivateDir)(userRoot).status !== 'ok' ||
|
|
47
|
+
(0, owned_private_dir_1.ensureOwnedPrivateDir)(cacheDir).status !== 'ok') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
impl(cacheDir);
|
|
44
51
|
return true;
|
|
45
52
|
}
|
|
46
53
|
catch {
|
|
@@ -24,8 +24,9 @@ function sharedWorkspaceDataDirectory(root) {
|
|
|
24
24
|
}
|
|
25
25
|
function getDbConnection(opts = {}) {
|
|
26
26
|
opts.directory ??= sharedWorkspaceDataDirectory(workspace_root_1.workspaceRoot);
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const dbName = opts.dbName ?? (process.env.NX_DB_NAME || undefined);
|
|
28
|
+
const key = JSON.stringify([opts.directory, dbName]);
|
|
29
|
+
const connection = getEntryOrSet(dbConnectionMap, key, () => (0, native_1.connectToNxDb)(opts.directory, dbName));
|
|
29
30
|
return connection;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -36,8 +37,9 @@ function getDbConnection(opts = {}) {
|
|
|
36
37
|
*/
|
|
37
38
|
function getLocalDbConnection(opts = {}) {
|
|
38
39
|
const directory = (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(workspace_root_1.workspaceRoot);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
40
|
+
const dbName = opts.dbName ?? (process.env.NX_DB_NAME || undefined);
|
|
41
|
+
const key = JSON.stringify([directory, dbName]);
|
|
42
|
+
const connection = getEntryOrSet(dbConnectionMap, key, () => (0, native_1.connectToNxDb)(directory, dbName));
|
|
41
43
|
return connection;
|
|
42
44
|
}
|
|
43
45
|
function removeDbConnections() {
|
|
@@ -343,7 +343,7 @@ function pickPnpmVersion(spec, metadata, policy) {
|
|
|
343
343
|
}
|
|
344
344
|
const wholeMapMissing = metadata.time === null;
|
|
345
345
|
if (wholeMapMissing && behavior.missingTimeMap === 'error') {
|
|
346
|
-
throw missingTime(metadata
|
|
346
|
+
throw missingTime(metadata);
|
|
347
347
|
}
|
|
348
348
|
const type = (0, pick_1.classifySpec)(spec);
|
|
349
349
|
if (type === 'exact') {
|
|
@@ -356,7 +356,7 @@ function pickPnpmVersion(spec, metadata, policy) {
|
|
|
356
356
|
}
|
|
357
357
|
function pickExact(spec, metadata, policy, behavior) {
|
|
358
358
|
const unconstrained = spec;
|
|
359
|
-
if (mature(metadata, policy, spec
|
|
359
|
+
if (mature(metadata, policy, spec)) {
|
|
360
360
|
return { version: spec, unconstrained };
|
|
361
361
|
}
|
|
362
362
|
if (behavior.looseFallback) {
|
|
@@ -371,10 +371,10 @@ function pickTag(spec, metadata, policy, behavior) {
|
|
|
371
371
|
throw violation(metadata, policy, spec, 'tag', []);
|
|
372
372
|
}
|
|
373
373
|
const unconstrained = tagTarget;
|
|
374
|
-
if (mature(metadata, policy, tagTarget
|
|
374
|
+
if (mature(metadata, policy, tagTarget)) {
|
|
375
375
|
return { version: tagTarget, unconstrained };
|
|
376
376
|
}
|
|
377
|
-
const degraded = (0, pick_1.degradeTagToCompliant)(tagTarget, metadata, (v) => mature(metadata, policy, v
|
|
377
|
+
const degraded = (0, pick_1.degradeTagToCompliant)(tagTarget, metadata, (v) => mature(metadata, policy, v));
|
|
378
378
|
if (degraded) {
|
|
379
379
|
return { version: degraded, unconstrained };
|
|
380
380
|
}
|
|
@@ -389,7 +389,7 @@ function pickTag(spec, metadata, policy, behavior) {
|
|
|
389
389
|
throw violation(metadata, policy, spec, 'tag', [tagTarget]);
|
|
390
390
|
}
|
|
391
391
|
function pickRange(spec, metadata, policy, behavior, unconstrained) {
|
|
392
|
-
const matureInRange = matureVersions(metadata, policy
|
|
392
|
+
const matureInRange = matureVersions(metadata, policy);
|
|
393
393
|
const newest = (0, semver_1.maxSatisfying)(matureInRange, spec, {
|
|
394
394
|
includePrerelease: false,
|
|
395
395
|
});
|
|
@@ -414,12 +414,12 @@ function pickRange(spec, metadata, policy, behavior, unconstrained) {
|
|
|
414
414
|
.sort(semver_1.rcompare);
|
|
415
415
|
throw violation(metadata, policy, spec, 'range', blocked);
|
|
416
416
|
}
|
|
417
|
-
function matureVersions(metadata, policy
|
|
418
|
-
return metadata.versions.filter((v) => mature(metadata, policy, v
|
|
417
|
+
function matureVersions(metadata, policy) {
|
|
418
|
+
return metadata.versions.filter((v) => mature(metadata, policy, v));
|
|
419
419
|
}
|
|
420
420
|
// pnpm blocks a version whose individual time entry is missing (treated too
|
|
421
421
|
// new). The whole-map-missing skip case is handled before any pick.
|
|
422
|
-
function mature(metadata, policy, version
|
|
422
|
+
function mature(metadata, policy, version) {
|
|
423
423
|
if (policy.isExcluded(metadata.name, version)) {
|
|
424
424
|
return true;
|
|
425
425
|
}
|
|
@@ -502,7 +502,7 @@ function failOnImmatureDetail(metadata, policy, spec, type, blockedVersions) {
|
|
|
502
502
|
return ('1 version does not meet the minimumReleaseAge constraint:\n' +
|
|
503
503
|
` ${metadata.name}@${resolved} was published at ${publishedIso}, within the minimumReleaseAge cutoff (${cutoffIso})`);
|
|
504
504
|
}
|
|
505
|
-
function missingTime(metadata
|
|
505
|
+
function missingTime(metadata) {
|
|
506
506
|
return new errors_1.MinReleaseAgeViolationError({
|
|
507
507
|
packageManager: 'pnpm',
|
|
508
508
|
packageName: metadata.name,
|
|
@@ -47,7 +47,7 @@ async function readYarnPolicy(root, pmVersion) {
|
|
|
47
47
|
if (gateMinutes <= 0) {
|
|
48
48
|
return { outcome: 'inactive' };
|
|
49
49
|
}
|
|
50
|
-
if (isDefaultLockfileMigrationEscape(root, pmVersion, gateMinutes
|
|
50
|
+
if (isDefaultLockfileMigrationEscape(root, pmVersion, gateMinutes)) {
|
|
51
51
|
return { outcome: 'inactive' };
|
|
52
52
|
}
|
|
53
53
|
const windowMs = gateMinutes * constants_1.MS_PER_MINUTE;
|
|
@@ -101,7 +101,7 @@ function readPreapprovedPackages(root) {
|
|
|
101
101
|
* and that has not explicitly set the gate. A missing lockfile means a fresh
|
|
102
102
|
* project, where the default does apply.
|
|
103
103
|
*/
|
|
104
|
-
function isDefaultLockfileMigrationEscape(root, pmVersion, gateMinutes
|
|
104
|
+
function isDefaultLockfileMigrationEscape(root, pmVersion, gateMinutes) {
|
|
105
105
|
if ((0, semver_1.lt)(pmVersion, '4.15.0')) {
|
|
106
106
|
return false;
|
|
107
107
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stable root for Nx runtime artifacts that need an OS tmp location. On POSIX a
|
|
3
3
|
* literal `/tmp`, not `os.tmpdir()`, which honours `$TMPDIR` — per-user on
|
|
4
|
-
* macOS, rewritten by sandboxes,
|
|
5
|
-
* daemon would disagree. Windows has no `/tmp`, and `%TMP%` is already per-user
|
|
4
|
+
* macOS, rewritten by sandboxes, fixed in the daemon at spawn and never
|
|
5
|
+
* reflected from later clients, so client and daemon would disagree. Windows has no `/tmp`, and `%TMP%` is already per-user
|
|
6
6
|
* and stable, so it keeps `os.tmpdir()`.
|
|
7
7
|
*
|
|
8
8
|
* Consumed by the native binding loader, so keep this file limited to local
|
|
@@ -21,3 +21,15 @@ export declare const NX_TMP_DIR: string;
|
|
|
21
21
|
export declare const NX_USER_TMP_DIR: string;
|
|
22
22
|
/** Runtime root under the user's home, used when the shared container cannot be established. */
|
|
23
23
|
export declare const NX_HOME_TMP_DIR: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the home directory lies outside the shared temp dir.
|
|
26
|
+
*
|
|
27
|
+
* `homedir()` honours `$HOME`, so `HOME=/tmp` or `HOME=/tmp/foo` puts `~/.nx`
|
|
28
|
+
* at or under a directory every user can write to (`1777`). Peers can plant
|
|
29
|
+
* files in its ancestors and, at `HOME=/tmp`, own the `.nx` container itself.
|
|
30
|
+
* Nothing that Nx later executes, installs into, or replays into the workspace
|
|
31
|
+
* can live there.
|
|
32
|
+
*
|
|
33
|
+
* `native/utils/socket_path.rs` makes only the same-path check, for sockets.
|
|
34
|
+
*/
|
|
35
|
+
export declare function homeDirIsDistinctFromSharedTmp(): boolean;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NX_HOME_TMP_DIR = exports.NX_USER_TMP_DIR = exports.NX_TMP_DIR = exports.NX_TMP_DIR_POSIX = void 0;
|
|
4
|
+
exports.homeDirIsDistinctFromSharedTmp = homeDirIsDistinctFromSharedTmp;
|
|
4
5
|
const node_os_1 = require("node:os");
|
|
5
6
|
const node_path_1 = require("node:path");
|
|
6
7
|
const owned_private_dir_1 = require("./owned-private-dir");
|
|
7
8
|
/**
|
|
8
9
|
* Stable root for Nx runtime artifacts that need an OS tmp location. On POSIX a
|
|
9
10
|
* literal `/tmp`, not `os.tmpdir()`, which honours `$TMPDIR` — per-user on
|
|
10
|
-
* macOS, rewritten by sandboxes,
|
|
11
|
-
* daemon would disagree. Windows has no `/tmp`, and `%TMP%` is already per-user
|
|
11
|
+
* macOS, rewritten by sandboxes, fixed in the daemon at spawn and never
|
|
12
|
+
* reflected from later clients, so client and daemon would disagree. Windows has no `/tmp`, and `%TMP%` is already per-user
|
|
12
13
|
* and stable, so it keeps `os.tmpdir()`.
|
|
13
14
|
*
|
|
14
15
|
* Consumed by the native binding loader, so keep this file limited to local
|
|
@@ -43,3 +44,26 @@ function resolveHomeTmpDir() {
|
|
|
43
44
|
return undefined;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether the home directory lies outside the shared temp dir.
|
|
49
|
+
*
|
|
50
|
+
* `homedir()` honours `$HOME`, so `HOME=/tmp` or `HOME=/tmp/foo` puts `~/.nx`
|
|
51
|
+
* at or under a directory every user can write to (`1777`). Peers can plant
|
|
52
|
+
* files in its ancestors and, at `HOME=/tmp`, own the `.nx` container itself.
|
|
53
|
+
* Nothing that Nx later executes, installs into, or replays into the workspace
|
|
54
|
+
* can live there.
|
|
55
|
+
*
|
|
56
|
+
* `native/utils/socket_path.rs` makes only the same-path check, for sockets.
|
|
57
|
+
*/
|
|
58
|
+
function homeDirIsDistinctFromSharedTmp() {
|
|
59
|
+
if (!exports.NX_HOME_TMP_DIR) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const home = (0, owned_private_dir_1.canonicalDir)((0, node_path_1.dirname)(exports.NX_HOME_TMP_DIR));
|
|
63
|
+
const fromSharedTmp = (0, node_path_1.relative)((0, owned_private_dir_1.canonicalDir)((0, node_path_1.dirname)(exports.NX_TMP_DIR)), home);
|
|
64
|
+
const atOrUnderSharedTmp = fromSharedTmp === '' ||
|
|
65
|
+
(fromSharedTmp !== '..' &&
|
|
66
|
+
!fromSharedTmp.startsWith('..' + node_path_1.sep) &&
|
|
67
|
+
!(0, node_path_1.isAbsolute)(fromSharedTmp));
|
|
68
|
+
return !atOrUnderSharedTmp;
|
|
69
|
+
}
|
|
@@ -19,7 +19,6 @@ const fs_1 = require("fs");
|
|
|
19
19
|
const node_module_1 = tslib_1.__importStar(require("node:module"));
|
|
20
20
|
const path_1 = require("path");
|
|
21
21
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
22
|
-
const tmp_1 = require("tmp");
|
|
23
22
|
const which_1 = tslib_1.__importDefault(require("which"));
|
|
24
23
|
const json_1 = require("../generators/utils/json");
|
|
25
24
|
const project_configuration_utils_1 = require("../project-graph/utils/project-configuration-utils");
|
|
@@ -195,30 +194,54 @@ function readModulePackageJsonWithoutFallbacks(moduleSpecifier, requirePaths = (
|
|
|
195
194
|
* @returns package json contents and path
|
|
196
195
|
*/
|
|
197
196
|
function readModulePackageJson(moduleSpecifier, requirePaths = (0, installation_directory_1.getNxRequirePaths)()) {
|
|
198
|
-
let
|
|
199
|
-
let packageJson;
|
|
197
|
+
let exported;
|
|
200
198
|
try {
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
exported = readModulePackageJsonWithoutFallbacks(moduleSpecifier, requirePaths);
|
|
200
|
+
}
|
|
201
|
+
catch { }
|
|
202
|
+
// A wildcard export can map package.json to a nested `{"type": ...}` stub,
|
|
203
|
+
// so a nameless manifest is kept only when the lookup step finds no other.
|
|
204
|
+
if (exported?.packageJson.name) {
|
|
205
|
+
return exported;
|
|
206
|
+
}
|
|
207
|
+
const lookupPathMatch = findPackageJsonInLookupPaths(moduleSpecifier, requirePaths);
|
|
208
|
+
if (lookupPathMatch) {
|
|
209
|
+
return {
|
|
210
|
+
packageJson: (0, fileutils_1.readJsonFile)(lookupPathMatch),
|
|
211
|
+
path: lookupPathMatch,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (exported) {
|
|
215
|
+
return exported;
|
|
203
216
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
217
|
+
const entryPoint = resolveWithoutCachePollution(moduleSpecifier, requirePaths);
|
|
218
|
+
let moduleRootPath = (0, path_1.dirname)(entryPoint);
|
|
219
|
+
let packageJsonPath = (0, path_1.join)(moduleRootPath, 'package.json');
|
|
220
|
+
while (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
221
|
+
moduleRootPath = (0, path_1.dirname)(moduleRootPath);
|
|
207
222
|
packageJsonPath = (0, path_1.join)(moduleRootPath, 'package.json');
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
213
|
-
if (packageJson.name && packageJson.name !== moduleSpecifier) {
|
|
214
|
-
throw new Error(`Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json`);
|
|
215
|
-
}
|
|
223
|
+
}
|
|
224
|
+
const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
225
|
+
if (packageJson.name && packageJson.name !== moduleSpecifier) {
|
|
226
|
+
throw new Error(`Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json`);
|
|
216
227
|
}
|
|
217
228
|
return {
|
|
218
229
|
packageJson,
|
|
219
230
|
path: packageJsonPath,
|
|
220
231
|
};
|
|
221
232
|
}
|
|
233
|
+
function findPackageJsonInLookupPaths(moduleSpecifier, requirePaths) {
|
|
234
|
+
for (const requirePath of requirePaths) {
|
|
235
|
+
const lookupPaths = (0, node_module_1.createRequire)((0, path_1.join)((0, path_1.resolve)(requirePath), 'noop.js')).resolve.paths(moduleSpecifier) ?? [];
|
|
236
|
+
for (const lookupPath of lookupPaths) {
|
|
237
|
+
const candidate = (0, path_1.join)(lookupPath, moduleSpecifier, 'package.json');
|
|
238
|
+
if ((0, fs_1.existsSync)(candidate)) {
|
|
239
|
+
// Resolving gives a symlinked package the same real path Node returns.
|
|
240
|
+
return resolveWithoutCachePollution(candidate, requirePaths);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
222
245
|
/**
|
|
223
246
|
* Resolve `request` via Node's CJS resolver while neutralising both ways
|
|
224
247
|
* `require.resolve(req, { paths })` can lie about the `paths` argument:
|
|
@@ -260,10 +283,7 @@ function resolveWithoutCachePollution(request, requirePaths) {
|
|
|
260
283
|
* This is used by both sync and async installation functions.
|
|
261
284
|
*/
|
|
262
285
|
function preparePackageInstallation(pkg, requiredVersion, packageManager) {
|
|
263
|
-
const { dir: tempDir, cleanup } = (0, package_manager_1.createTempNpmDirectory)
|
|
264
|
-
dir: (0, tmp_1.dirSync)().name,
|
|
265
|
-
cleanup: () => { },
|
|
266
|
-
};
|
|
286
|
+
const { dir: tempDir, cleanup } = (0, package_manager_1.createTempNpmDirectory)();
|
|
267
287
|
console.log(`Fetching ${pkg}...`);
|
|
268
288
|
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
|
269
289
|
generatePackageManagerFiles(tempDir, packageManager);
|
|
@@ -113,6 +113,21 @@ export declare function copyPackageManagerConfigurationFiles(root: string, desti
|
|
|
113
113
|
* files under the Nx installation directory instead.
|
|
114
114
|
*/
|
|
115
115
|
export declare function getPackageManagerConfigRoot(root?: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Creates an empty owner-only directory for a throwaway package install.
|
|
118
|
+
*
|
|
119
|
+
* Package managers and Node read config and modules from every ancestor of
|
|
120
|
+
* the install, so it lives under `~/.nx/tmp`, else under the OS temp dir, and
|
|
121
|
+
* only where that root and all of its ancestors are closed to other users.
|
|
122
|
+
* Throws when neither root qualifies or can be written. The OS does not reap
|
|
123
|
+
* it, so it is removed when the process exits.
|
|
124
|
+
*/
|
|
125
|
+
export declare function createTempInstallDirectory(): string;
|
|
126
|
+
/**
|
|
127
|
+
* Removes this user's throwaway install dirs under `~/.nx/tmp` and the temp
|
|
128
|
+
* dir fallback that are more than a day old. Best effort; creates nothing.
|
|
129
|
+
*/
|
|
130
|
+
export declare function removeStaleTempInstallDirectories(): void;
|
|
116
131
|
/**
|
|
117
132
|
* Creates a temporary directory where you can run package manager commands safely.
|
|
118
133
|
*
|
|
@@ -13,6 +13,8 @@ exports.modifyYarnRcToFitNewDirectory = modifyYarnRcToFitNewDirectory;
|
|
|
13
13
|
exports.modifyPnpmWorkspaceYamlToFitNewDirectory = modifyPnpmWorkspaceYamlToFitNewDirectory;
|
|
14
14
|
exports.copyPackageManagerConfigurationFiles = copyPackageManagerConfigurationFiles;
|
|
15
15
|
exports.getPackageManagerConfigRoot = getPackageManagerConfigRoot;
|
|
16
|
+
exports.createTempInstallDirectory = createTempInstallDirectory;
|
|
17
|
+
exports.removeStaleTempInstallDirectories = removeStaleTempInstallDirectories;
|
|
16
18
|
exports.createTempNpmDirectory = createTempNpmDirectory;
|
|
17
19
|
exports.resolvePackageVersionUsingRegistry = resolvePackageVersionUsingRegistry;
|
|
18
20
|
exports.resolvePackageVersionUsingInstallation = resolvePackageVersionUsingInstallation;
|
|
@@ -38,6 +40,8 @@ const catalog_1 = require("./catalog");
|
|
|
38
40
|
const fileutils_1 = require("./fileutils");
|
|
39
41
|
const installation_directory_1 = require("./installation-directory");
|
|
40
42
|
const logger_1 = require("./logger");
|
|
43
|
+
const nx_tmp_dir_1 = require("./nx-tmp-dir");
|
|
44
|
+
const owned_private_dir_1 = require("./owned-private-dir");
|
|
41
45
|
const package_json_1 = require("./package-json");
|
|
42
46
|
const redact_url_credentials_1 = require("./redact-url-credentials");
|
|
43
47
|
const shell_quoting_1 = require("./shell-quoting");
|
|
@@ -575,6 +579,184 @@ function getPackageManagerConfigRoot(root = workspace_root_1.workspaceRoot) {
|
|
|
575
579
|
return root;
|
|
576
580
|
}
|
|
577
581
|
}
|
|
582
|
+
/**
|
|
583
|
+
* Creates an empty owner-only directory for a throwaway package install.
|
|
584
|
+
*
|
|
585
|
+
* Package managers and Node read config and modules from every ancestor of
|
|
586
|
+
* the install, so it lives under `~/.nx/tmp`, else under the OS temp dir, and
|
|
587
|
+
* only where that root and all of its ancestors are closed to other users.
|
|
588
|
+
* Throws when neither root qualifies or can be written. The OS does not reap
|
|
589
|
+
* it, so it is removed when the process exits.
|
|
590
|
+
*/
|
|
591
|
+
function createTempInstallDirectory() {
|
|
592
|
+
const dir = createInPrivateInstallRoot();
|
|
593
|
+
if (tempInstallDirectories.size === 0) {
|
|
594
|
+
process.once('exit', removeTempInstallDirectories);
|
|
595
|
+
}
|
|
596
|
+
tempInstallDirectories.add(dir);
|
|
597
|
+
return dir;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Removes this user's throwaway install dirs under `~/.nx/tmp` and the temp
|
|
601
|
+
* dir fallback that are more than a day old. Best effort; creates nothing.
|
|
602
|
+
*/
|
|
603
|
+
function removeStaleTempInstallDirectories() {
|
|
604
|
+
if (nx_tmp_dir_1.NX_HOME_TMP_DIR && (0, nx_tmp_dir_1.homeDirIsDistinctFromSharedTmp)()) {
|
|
605
|
+
const root = (0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, 'tmp');
|
|
606
|
+
if ((0, owned_private_dir_1.isOwnedRealDirectory)(nx_tmp_dir_1.NX_HOME_TMP_DIR) && (0, owned_private_dir_1.isOwnedRealDirectory)(root)) {
|
|
607
|
+
removeStaleInstallDirectories(root);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
const fallbackRoot = (0, path_1.join)((0, node_os_1.tmpdir)(), TMPDIR_INSTALL_ROOT);
|
|
611
|
+
if (!privateTreeRefusal((0, node_os_1.tmpdir)()) && (0, owned_private_dir_1.isOwnedRealDirectory)(fallbackRoot)) {
|
|
612
|
+
removeStaleInstallDirectories(fallbackRoot);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
const tempInstallDirectories = new Set();
|
|
616
|
+
function removeTempInstallDirectories() {
|
|
617
|
+
for (const dir of tempInstallDirectories) {
|
|
618
|
+
try {
|
|
619
|
+
(0, fs_1.rmSync)(dir, { recursive: true, force: true });
|
|
620
|
+
}
|
|
621
|
+
catch { }
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const STALE_INSTALL_DIRECTORY_MS = 24 * 60 * 60 * 1000;
|
|
625
|
+
/**
|
|
626
|
+
* Removes install dirs left behind by processes that never reached their exit
|
|
627
|
+
* handler. A day outlasts any realistic install or `nx migrate` run, so a
|
|
628
|
+
* concurrent process's install survives.
|
|
629
|
+
*/
|
|
630
|
+
function removeStaleInstallDirectories(root) {
|
|
631
|
+
let entries;
|
|
632
|
+
try {
|
|
633
|
+
entries = (0, fs_1.readdirSync)(root);
|
|
634
|
+
}
|
|
635
|
+
catch {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const cutoff = Date.now() - STALE_INSTALL_DIRECTORY_MS;
|
|
639
|
+
for (const entry of entries) {
|
|
640
|
+
const path = (0, path_1.join)(root, entry);
|
|
641
|
+
try {
|
|
642
|
+
const stats = (0, fs_1.lstatSync)(path);
|
|
643
|
+
if (stats.isDirectory() &&
|
|
644
|
+
stats.mtimeMs < cutoff &&
|
|
645
|
+
(typeof process.getuid !== 'function' || stats.uid === process.getuid())) {
|
|
646
|
+
(0, fs_1.rmSync)(path, { recursive: true, force: true });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
catch { }
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
const TMPDIR_INSTALL_ROOT = 'nx-installs';
|
|
653
|
+
/**
|
|
654
|
+
* An existing `~/.nx/tmp` can still refuse writes, for example under an agent
|
|
655
|
+
* sandbox, so a failed create there moves on to the OS temp dir.
|
|
656
|
+
*/
|
|
657
|
+
function createInPrivateInstallRoot() {
|
|
658
|
+
let homeRefusal = homeInstallRootRefusal();
|
|
659
|
+
if (!homeRefusal) {
|
|
660
|
+
const root = (0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, 'tmp');
|
|
661
|
+
try {
|
|
662
|
+
return createInstallDirectory(root);
|
|
663
|
+
}
|
|
664
|
+
catch (e) {
|
|
665
|
+
homeRefusal = `${root} is not writable${e?.code ? ` (${e.code})` : ''}`;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const tmp = (0, node_os_1.tmpdir)();
|
|
669
|
+
const fallbackRoot = (0, path_1.join)(tmp, TMPDIR_INSTALL_ROOT);
|
|
670
|
+
let tmpRefusal = privateTreeRefusal(tmp);
|
|
671
|
+
if (!tmpRefusal) {
|
|
672
|
+
const result = (0, owned_private_dir_1.ensureOwnedPrivateDir)(fallbackRoot);
|
|
673
|
+
if (result.status === 'ok') {
|
|
674
|
+
return createInstallDirectory(fallbackRoot);
|
|
675
|
+
}
|
|
676
|
+
tmpRefusal = (0, owned_private_dir_1.describeRefusal)(result.refusal);
|
|
677
|
+
}
|
|
678
|
+
if (process.env.NX_ALLOW_INSECURE_DIRECTORIES === 'true') {
|
|
679
|
+
console.warn(`NX_ALLOW_INSECURE_DIRECTORIES is set, so Nx is installing packages in ${tmp} although ${tmpRefusal}.`);
|
|
680
|
+
return (0, tmp_1.dirSync)({ tmpdir: tmp, prefix: 'nx-install-' }).name;
|
|
681
|
+
}
|
|
682
|
+
throw new PrivateInstallRootError(homeRefusal, tmpRefusal);
|
|
683
|
+
}
|
|
684
|
+
function createInstallDirectory(root) {
|
|
685
|
+
removeStaleInstallDirectories(root);
|
|
686
|
+
return (0, tmp_1.dirSync)({ tmpdir: root }).name;
|
|
687
|
+
}
|
|
688
|
+
function homeInstallRootRefusal() {
|
|
689
|
+
if (!nx_tmp_dir_1.NX_HOME_TMP_DIR || !(0, nx_tmp_dir_1.homeDirIsDistinctFromSharedTmp)()) {
|
|
690
|
+
return 'there is no home directory separate from the shared temp directory';
|
|
691
|
+
}
|
|
692
|
+
for (const dir of [nx_tmp_dir_1.NX_HOME_TMP_DIR, (0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, 'tmp')]) {
|
|
693
|
+
const result = (0, owned_private_dir_1.ensureOwnedPrivateDir)(dir);
|
|
694
|
+
if (result.status === 'refused') {
|
|
695
|
+
return (0, owned_private_dir_1.describeRefusal)(result.refusal);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return privateTreeRefusal((0, path_1.join)(nx_tmp_dir_1.NX_HOME_TMP_DIR, 'tmp'));
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Why `dir` or one of its ancestors could be written by another user, if it
|
|
702
|
+
* could. Each must be a directory owned by us or root without group or other
|
|
703
|
+
* write, sticky or not, and `dir` itself must be ours and not a symlink. Both
|
|
704
|
+
* the path as written and its canonical form are checked, so a symlinked
|
|
705
|
+
* ancestor and the directory it leads to must each qualify.
|
|
706
|
+
*/
|
|
707
|
+
function privateTreeRefusal(dir) {
|
|
708
|
+
if (typeof process.getuid !== 'function') {
|
|
709
|
+
return (0, owned_private_dir_1.isOwnedRealDirectory)(dir)
|
|
710
|
+
? undefined
|
|
711
|
+
: `${dir} is not a real directory`;
|
|
712
|
+
}
|
|
713
|
+
for (const leaf of [(0, path_1.resolve)(dir), (0, owned_private_dir_1.canonicalDir)(dir)]) {
|
|
714
|
+
for (let p = leaf;; p = (0, path_1.dirname)(p)) {
|
|
715
|
+
const refusal = privatePathRefusal(p, p === leaf);
|
|
716
|
+
if (refusal) {
|
|
717
|
+
return refusal;
|
|
718
|
+
}
|
|
719
|
+
if ((0, path_1.dirname)(p) === p) {
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
function privatePathRefusal(path, isLeaf) {
|
|
727
|
+
let stats;
|
|
728
|
+
try {
|
|
729
|
+
stats = (0, fs_1.lstatSync)(path);
|
|
730
|
+
}
|
|
731
|
+
catch (e) {
|
|
732
|
+
return `${path} could not be inspected${e?.code ? ` (${e.code})` : ''}`;
|
|
733
|
+
}
|
|
734
|
+
const uid = process.getuid();
|
|
735
|
+
const trustedOwner = stats.uid === uid || (!isLeaf && stats.uid === 0);
|
|
736
|
+
if (stats.isSymbolicLink() && !isLeaf) {
|
|
737
|
+
return trustedOwner ? undefined : `${path} is owned by uid ${stats.uid}`;
|
|
738
|
+
}
|
|
739
|
+
if (!stats.isDirectory()) {
|
|
740
|
+
return stats.isSymbolicLink()
|
|
741
|
+
? `${path} is a symlink, not a real directory`
|
|
742
|
+
: `${path} is not a directory`;
|
|
743
|
+
}
|
|
744
|
+
if (stats.mode & 0o022) {
|
|
745
|
+
const mode = (stats.mode & 0o7777).toString(8).padStart(4, '0');
|
|
746
|
+
return `${path} is writable by other users (mode ${mode})`;
|
|
747
|
+
}
|
|
748
|
+
return trustedOwner ? undefined : `${path} is owned by uid ${stats.uid}`;
|
|
749
|
+
}
|
|
750
|
+
class PrivateInstallRootError extends Error {
|
|
751
|
+
constructor(homeRefusal, tmpRefusal) {
|
|
752
|
+
super('Nx cannot install packages because it found no directory closed to other users to install into.\n' +
|
|
753
|
+
` ~/.nx/tmp: ${homeRefusal}.\n` +
|
|
754
|
+
` The OS temp directory: ${tmpRefusal}.\n` +
|
|
755
|
+
'Package managers and Node read config and modules from every parent of the install directory, so Nx will not install where another user could write to it or to any of its parents.\n' +
|
|
756
|
+
'Point TMPDIR at a directory only you can write to, or set NX_ALLOW_INSECURE_DIRECTORIES=true to install in the OS temp directory anyway.');
|
|
757
|
+
this.name = 'PrivateInstallRootError';
|
|
758
|
+
}
|
|
759
|
+
}
|
|
578
760
|
/**
|
|
579
761
|
* Creates a temporary directory where you can run package manager commands safely.
|
|
580
762
|
*
|
|
@@ -587,7 +769,7 @@ function getPackageManagerConfigRoot(root = workspace_root_1.workspaceRoot) {
|
|
|
587
769
|
* where no existing configuration files are available to copy.
|
|
588
770
|
*/
|
|
589
771
|
function createTempNpmDirectory(skipCopy = false) {
|
|
590
|
-
const dir = (
|
|
772
|
+
const dir = createTempInstallDirectory();
|
|
591
773
|
// A package.json is needed for pnpm pack and for .npmrc to resolve
|
|
592
774
|
(0, fileutils_1.writeJsonFile)(`${dir}/package.json`, {});
|
|
593
775
|
if (!skipCopy) {
|
|
@@ -598,7 +780,7 @@ function createTempNpmDirectory(skipCopy = false) {
|
|
|
598
780
|
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
599
781
|
}
|
|
600
782
|
catch {
|
|
601
|
-
//
|
|
783
|
+
// The exit handler retries the removal.
|
|
602
784
|
}
|
|
603
785
|
};
|
|
604
786
|
return { dir, cleanup };
|
|
@@ -14,9 +14,7 @@ const package_manager_1 = require("../package-manager");
|
|
|
14
14
|
const workspace_root_1 = require("../workspace-root");
|
|
15
15
|
const core_plugins_1 = require("./core-plugins");
|
|
16
16
|
const plugin_capabilities_1 = require("./plugin-capabilities");
|
|
17
|
-
const package_json_1 = require("../package-json");
|
|
18
17
|
function listPlugins(plugins, title) {
|
|
19
|
-
package_json_1.readModulePackageJson;
|
|
20
18
|
const bodyLines = [];
|
|
21
19
|
for (const [, p] of plugins) {
|
|
22
20
|
const capabilities = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nx",
|
|
3
|
-
"version": "24.0.
|
|
3
|
+
"version": "24.1.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@emnapi/core": "1.4.5",
|
|
54
54
|
"@emnapi/runtime": "1.4.5",
|
|
55
55
|
"@emnapi/wasi-threads": "1.0.4",
|
|
56
|
-
"@jest/diff-sequences": "30.0
|
|
56
|
+
"@jest/diff-sequences": "30.3.0",
|
|
57
57
|
"@napi-rs/wasm-runtime": "0.2.4",
|
|
58
58
|
"@tybys/wasm-util": "0.9.0",
|
|
59
59
|
"@yarnpkg/lockfile": "1.1.0",
|
|
@@ -150,16 +150,16 @@
|
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
152
|
"optionalDependencies": {
|
|
153
|
-
"@nx/nx-darwin-arm64": "24.0.
|
|
154
|
-
"@nx/nx-darwin-x64": "24.0.
|
|
155
|
-
"@nx/nx-freebsd-x64": "24.0.
|
|
156
|
-
"@nx/nx-linux-arm-gnueabihf": "24.0.
|
|
157
|
-
"@nx/nx-linux-arm64-gnu": "24.0.
|
|
158
|
-
"@nx/nx-linux-arm64-musl": "24.0.
|
|
159
|
-
"@nx/nx-linux-x64-gnu": "24.0.
|
|
160
|
-
"@nx/nx-linux-x64-musl": "24.0.
|
|
161
|
-
"@nx/nx-win32-arm64-msvc": "24.0.
|
|
162
|
-
"@nx/nx-win32-x64-msvc": "24.0.
|
|
153
|
+
"@nx/nx-darwin-arm64": "24.1.0-beta.0",
|
|
154
|
+
"@nx/nx-darwin-x64": "24.1.0-beta.0",
|
|
155
|
+
"@nx/nx-freebsd-x64": "24.1.0-beta.0",
|
|
156
|
+
"@nx/nx-linux-arm-gnueabihf": "24.1.0-beta.0",
|
|
157
|
+
"@nx/nx-linux-arm64-gnu": "24.1.0-beta.0",
|
|
158
|
+
"@nx/nx-linux-arm64-musl": "24.1.0-beta.0",
|
|
159
|
+
"@nx/nx-linux-x64-gnu": "24.1.0-beta.0",
|
|
160
|
+
"@nx/nx-linux-x64-musl": "24.1.0-beta.0",
|
|
161
|
+
"@nx/nx-win32-arm64-msvc": "24.1.0-beta.0",
|
|
162
|
+
"@nx/nx-win32-x64-msvc": "24.1.0-beta.0"
|
|
163
163
|
},
|
|
164
164
|
"nx-migrations": {
|
|
165
165
|
"migrations": "./migrations.json",
|