nx 24.0.6 → 24.1.0-beta.1

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.
Files changed (120) hide show
  1. package/dist/bin/init-local.js +2 -4
  2. package/dist/bin/nx-cloud.js +2 -1
  3. package/dist/bin/nx.js +12 -14
  4. package/dist/bin/run-executor.js +5 -0
  5. package/dist/src/adapter/compat.d.ts +1 -1
  6. package/dist/src/adapter/compat.js +1 -0
  7. package/dist/src/adapter/ngcli-adapter.js +7 -20
  8. package/dist/src/command-line/completion/scripts/bash.sh +9 -2
  9. package/dist/src/command-line/completion/scripts/fish.fish +10 -2
  10. package/dist/src/command-line/completion/scripts/zsh.zsh +8 -2
  11. package/dist/src/command-line/completion/scripts.js +18 -8
  12. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +0 -1
  13. package/dist/src/command-line/conformance/command-object.d.ts +3 -0
  14. package/dist/src/command-line/conformance/command-object.js +66 -0
  15. package/dist/src/command-line/generate/generate.js +14 -27
  16. package/dist/src/command-line/generate/generator-utils.d.ts +1 -0
  17. package/dist/src/command-line/generate/generator-utils.js +9 -0
  18. package/dist/src/command-line/graph/graph.js +1 -7
  19. package/dist/src/command-line/import/import.js +26 -2
  20. package/dist/src/command-line/import/utils/ai-output.d.ts +9 -1
  21. package/dist/src/command-line/import/utils/ai-output.js +20 -1
  22. package/dist/src/command-line/import/utils/prepare-source-repo.js +0 -3
  23. package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +2 -2
  24. package/dist/src/command-line/init/init-v2.js +2 -2
  25. package/dist/src/command-line/migrate/migrate.js +1 -4
  26. package/dist/src/command-line/migrate/prompt-files.js +5 -5
  27. package/dist/src/command-line/migrate/run/orchestrator.js +2 -3
  28. package/dist/src/command-line/migrate/run/worker.js +7 -5
  29. package/dist/src/command-line/migrate/run-migration-process.js +3 -2
  30. package/dist/src/command-line/nx-commands.d.ts +1 -1
  31. package/dist/src/command-line/nx-commands.js +82 -132
  32. package/dist/src/command-line/release/changelog.js +8 -39
  33. package/dist/src/command-line/release/command-object.d.ts +1 -0
  34. package/dist/src/command-line/release/command-object.js +4 -0
  35. package/dist/src/command-line/release/config/use-legacy-versioning.js +1 -1
  36. package/dist/src/command-line/release/release.js +6 -4
  37. package/dist/src/command-line/release/utils/diff.js +0 -14
  38. package/dist/src/command-line/release/utils/git.js +1 -1
  39. package/dist/src/command-line/release/utils/resolve-nx-json-error-message.js +2 -24
  40. package/dist/src/command-line/report/report.js +1 -1
  41. package/dist/src/command-line/run/executor-utils.js +1 -1
  42. package/dist/src/command-line/show/show-target/utils.js +1 -1
  43. package/dist/src/command-line/watch/watch.js +1 -1
  44. package/dist/src/commands-runner/get-command-projects.js +0 -3
  45. package/dist/src/config/misc-interfaces.d.ts +0 -1
  46. package/dist/src/config/nx-json.d.ts +117 -0
  47. package/dist/src/config/workspace-json-project-json.d.ts +6 -7
  48. package/dist/src/core/graph/main.js +1 -1
  49. package/dist/src/core/graph/styles.css +1 -1
  50. package/dist/src/core/graph/styles.js +1 -1
  51. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +13 -20
  52. package/dist/src/devkit-exports.d.ts +1 -1
  53. package/dist/src/devkit-internals.d.ts +11 -4
  54. package/dist/src/devkit-internals.js +27 -5
  55. package/dist/src/executors/run-commands/run-commands.impl.d.ts +1 -1
  56. package/dist/src/executors/run-commands/run-commands.impl.js +35 -13
  57. package/dist/src/hasher/hash-task.js +4 -4
  58. package/dist/src/hasher/task-hasher.js +2 -2
  59. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.d.ts +4 -0
  60. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.js +117 -0
  61. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.md +38 -0
  62. package/dist/src/native/index.d.ts +6 -4
  63. package/dist/src/native/index.js +5 -0
  64. package/dist/src/native/native-bindings.js +1 -0
  65. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  66. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  67. package/dist/src/native/transform-objects.d.ts +2 -0
  68. package/dist/src/native/transform-objects.js +15 -0
  69. package/dist/src/nx-cloud/utilities/environment.js +0 -17
  70. package/dist/src/plugins/js/lock-file/bun-parser.d.ts +1 -2
  71. package/dist/src/plugins/js/lock-file/bun-parser.js +5 -5
  72. package/dist/src/plugins/js/lock-file/lock-file-names.d.ts +6 -0
  73. package/dist/src/plugins/js/lock-file/lock-file-names.js +16 -0
  74. package/dist/src/plugins/js/lock-file/lock-file.d.ts +1 -2
  75. package/dist/src/plugins/js/lock-file/lock-file.js +24 -31
  76. package/dist/src/plugins/js/lock-file/npm-parser.js +1 -2
  77. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +50 -2
  78. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +5 -0
  79. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +75 -13
  80. package/dist/src/plugins/js/utils/get-workspace-packages-from-graph.js +1 -1
  81. package/dist/src/plugins/js/utils/register.js +13 -6
  82. package/dist/src/project-graph/affected/affected-tasks.js +1 -1
  83. package/dist/src/project-graph/build-project-graph.js +5 -2
  84. package/dist/src/project-graph/nx-deps-cache.d.ts +3 -2
  85. package/dist/src/project-graph/nx-deps-cache.js +8 -2
  86. package/dist/src/project-graph/utils/project-graph-paths.d.ts +8 -0
  87. package/dist/src/project-graph/utils/project-graph-paths.js +170 -0
  88. package/dist/src/tasks-runner/batch/run-batch.js +3 -13
  89. package/dist/src/tasks-runner/cache.js +19 -18
  90. package/dist/src/tasks-runner/run-command.js +12 -10
  91. package/dist/src/tasks-runner/task-orchestrator.d.ts +1 -0
  92. package/dist/src/tasks-runner/task-orchestrator.js +14 -3
  93. package/dist/src/tasks-runner/utils.js +1 -12
  94. package/dist/src/ultracache/overrides.js +1 -1
  95. package/dist/src/utils/child-process.js +2 -1
  96. package/dist/src/utils/code-frames.js +0 -1
  97. package/dist/src/utils/db-connection.js +6 -4
  98. package/dist/src/utils/find-workspace-root.js +2 -4
  99. package/dist/src/utils/git-utils.d.ts +5 -0
  100. package/dist/src/utils/git-utils.js +23 -1
  101. package/dist/src/utils/handle-import.js +6 -0
  102. package/dist/src/utils/installation-directory.d.ts +16 -0
  103. package/dist/src/utils/installation-directory.js +96 -2
  104. package/dist/src/utils/json.d.ts +7 -0
  105. package/dist/src/utils/json.js +27 -0
  106. package/dist/src/utils/min-release-age/behavior/pnpm.js +9 -9
  107. package/dist/src/utils/min-release-age/behavior/yarn.js +2 -2
  108. package/dist/src/utils/nx-key.js +11 -8
  109. package/dist/src/utils/output.d.ts +5 -0
  110. package/dist/src/utils/output.js +11 -4
  111. package/dist/src/utils/owned-private-dir.d.ts +10 -0
  112. package/dist/src/utils/owned-private-dir.js +28 -0
  113. package/dist/src/utils/plugins/output.js +0 -2
  114. package/dist/src/utils/require-nx-key.js +6 -4
  115. package/dist/src/utils/workspace-root.d.ts +12 -0
  116. package/dist/src/utils/workspace-root.js +56 -7
  117. package/migrations.json +6 -0
  118. package/package.json +14 -12
  119. package/schemas/nx-schema.json +75 -9
  120. package/schemas/project-schema.json +5 -0
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNxInstallationPath = getNxInstallationPath;
4
4
  exports.getNxRequirePaths = getNxRequirePaths;
5
5
  exports.resolveFromWorkspace = resolveFromWorkspace;
6
+ exports.installationRootsOf = installationRootsOf;
7
+ exports.resolveInstalledPackage = resolveInstalledPackage;
8
+ exports.resolveNxBinFrom = resolveNxBinFrom;
9
+ const module_1 = require("module");
6
10
  const path_1 = require("path");
7
11
  const workspace_root_1 = require("./workspace-root");
8
12
  function getNxInstallationPath(root = workspace_root_1.workspaceRoot) {
@@ -19,7 +23,97 @@ function getNxRequirePaths(root = workspace_root_1.workspaceRoot) {
19
23
  * see what the workspace installs.
20
24
  */
21
25
  function resolveFromWorkspace(specifier, root = workspace_root_1.workspaceRoot) {
22
- return require.resolve(specifier, {
23
- paths: [...getNxRequirePaths(root), __dirname],
26
+ return resolveInstalledPackage(specifier, [...getNxRequirePaths(root), __dirname], root);
27
+ }
28
+ const nodeModulesSegment = `${path_1.sep}node_modules${path_1.sep}`;
29
+ let nxInstallationRoots;
30
+ /**
31
+ * The directories whose `node_modules` hold this nx and its own dependencies,
32
+ * e.g. the workspace, a global prefix, or the nx repo when run from source.
33
+ */
34
+ function getNxInstallationRoots() {
35
+ nxInstallationRoots ??= installationRootsOf([
36
+ __dirname,
37
+ require.resolve('yargs'),
38
+ ]);
39
+ return nxInstallationRoots;
40
+ }
41
+ /**
42
+ * The directory holding the outermost `node_modules` of each path. The
43
+ * separator is kept so `/node_modules` yields `/`, not an empty path.
44
+ */
45
+ function installationRootsOf(paths) {
46
+ return paths
47
+ .filter((path) => path.includes(nodeModulesSegment))
48
+ .map((path) => (0, path_1.resolve)(path.slice(0, path.indexOf(nodeModulesSegment) + 1)));
49
+ }
50
+ function normalize(path) {
51
+ const resolved = (0, path_1.resolve)(path);
52
+ return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
53
+ }
54
+ function isInside(path, dir) {
55
+ return path === dir || path.startsWith(dir.endsWith(path_1.sep) ? dir : dir + path_1.sep);
56
+ }
57
+ /**
58
+ * `require.resolve(specifier, { paths })` limited to `node_modules`
59
+ * directories inside `root`, the workspace, or this nx installation.
60
+ */
61
+ function resolveInstalledPackage(specifier, paths, root = workspace_root_1.workspaceRoot) {
62
+ if (process.versions.pnp ||
63
+ specifier.startsWith('.') ||
64
+ (0, path_1.isAbsolute)(specifier)) {
65
+ return require.resolve(specifier, { paths });
66
+ }
67
+ const trustedRoots = [root, workspace_root_1.workspaceRoot, ...getNxInstallationRoots()].map(normalize);
68
+ const lookupPaths = new Set();
69
+ for (const start of paths) {
70
+ let dir = (0, path_1.resolve)(start);
71
+ while (trustedRoots.some((r) => isInside(normalize(dir), r))) {
72
+ if ((0, path_1.basename)(dir) !== 'node_modules') {
73
+ lookupPaths.add((0, path_1.join)(dir, 'node_modules'));
74
+ }
75
+ if ((0, path_1.dirname)(dir) === dir) {
76
+ break;
77
+ }
78
+ dir = (0, path_1.dirname)(dir);
79
+ }
80
+ }
81
+ const Module = require('node:module');
82
+ const resolved = Module._findPath(specifier, [
83
+ ...lookupPaths,
84
+ ]);
85
+ if (!resolved) {
86
+ throw Object.assign(new Error(`Cannot find module '${specifier}'`), {
87
+ code: 'MODULE_NOT_FOUND',
88
+ });
89
+ }
90
+ return resolved;
91
+ }
92
+ /**
93
+ * Resolves `nx/bin/nx.js` from the first `node_modules` Node searches from `dir`
94
+ * that holds it, refusing it when it fails `isTrustedNxInstall` for the
95
+ * workspace at `root`.
96
+ */
97
+ function resolveNxBinFrom(dir, root = dir) {
98
+ // createRequire avoids nx's own exports field answering by self-reference.
99
+ const dirRequire = (0, module_1.createRequire)((0, path_1.join)(dir, 'package.json'));
100
+ if (process.versions.pnp) {
101
+ return dirRequire.resolve('nx/bin/nx.js');
102
+ }
103
+ const Module = require('node:module');
104
+ for (const nodeModules of dirRequire.resolve.paths('nx') ?? []) {
105
+ const nxBin = Module._findPath('nx/bin/nx.js', [
106
+ nodeModules,
107
+ ]);
108
+ if (!nxBin) {
109
+ continue;
110
+ }
111
+ if (!(0, workspace_root_1.isTrustedNxInstall)(nodeModules, root)) {
112
+ throw new Error(`Refusing the nx installed in ${nodeModules}`);
113
+ }
114
+ return nxBin;
115
+ }
116
+ throw Object.assign(new Error(`Cannot find module 'nx/bin/nx.js'`), {
117
+ code: 'MODULE_NOT_FOUND',
24
118
  });
25
119
  }
@@ -42,3 +42,10 @@ export declare function parseJson<T extends object = any>(input: string, options
42
42
  * @returns the formatted JSON representation of the object
43
43
  */
44
44
  export declare function serializeJson<T extends object = object>(input: T, options?: JsonSerializeOptions): string;
45
+ /**
46
+ * Returns the 1-based lines spanned by `characterCount` characters starting at `startOffset`.
47
+ */
48
+ export declare function computeJsonLineNumbers(inputText: string, startOffset: number, characterCount: number): {
49
+ startLine: number;
50
+ endLine: number;
51
+ };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripJsonComments = void 0;
4
4
  exports.parseJson = parseJson;
5
5
  exports.serializeJson = serializeJson;
6
+ exports.computeJsonLineNumbers = computeJsonLineNumbers;
6
7
  const jsonc_parser_1 = require("jsonc-parser");
7
8
  Object.defineProperty(exports, "stripJsonComments", { enumerable: true, get: function () { return jsonc_parser_1.stripComments; } });
8
9
  const lines_and_columns_1 = require("lines-and-columns");
@@ -60,3 +61,29 @@ function formatParseError(input, parseError) {
60
61
  function serializeJson(input, options) {
61
62
  return JSON.stringify(input, null, options?.spaces ?? 2);
62
63
  }
64
+ /**
65
+ * Returns the 1-based lines spanned by `characterCount` characters starting at `startOffset`.
66
+ */
67
+ function computeJsonLineNumbers(inputText, startOffset, characterCount) {
68
+ const lines = inputText.split('\n');
69
+ let totalChars = 0;
70
+ let startLine = 0;
71
+ let endLine = 0;
72
+ for (let i = 0; i < lines.length; i++) {
73
+ totalChars += lines[i].length + 1; // +1 for '\n' character
74
+ if (!startLine && totalChars >= startOffset) {
75
+ startLine = i + 1; // +1 because arrays are 0-based
76
+ }
77
+ if (totalChars >= startOffset + characterCount) {
78
+ endLine = i + 1; // +1 because arrays are 0-based
79
+ break;
80
+ }
81
+ }
82
+ if (!startLine) {
83
+ throw new Error('Start offset exceeds the text length');
84
+ }
85
+ if (!endLine) {
86
+ throw new Error('Character count exceeds the text length after start offset');
87
+ }
88
+ return { startLine, endLine };
89
+ }
@@ -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, policy);
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, behavior)) {
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, behavior)) {
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, behavior));
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, behavior);
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, behavior) {
418
- return metadata.versions.filter((v) => mature(metadata, policy, v, behavior));
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, behavior) {
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, policy) {
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, preapproved)) {
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, preapproved) {
104
+ function isDefaultLockfileMigrationEscape(root, pmVersion, gateMinutes) {
105
105
  if ((0, semver_1.lt)(pmVersion, '4.15.0')) {
106
106
  return false;
107
107
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NxKeyNotInstalledError = void 0;
4
4
  exports.createNxKeyLicenseeInformation = createNxKeyLicenseeInformation;
5
5
  exports.getNxKeyInformation = getNxKeyInformation;
6
+ const url_1 = require("url");
6
7
  const installation_directory_1 = require("./installation-directory");
7
8
  const package_manager_1 = require("./package-manager");
8
9
  const workspace_root_1 = require("./workspace-root");
@@ -20,24 +21,26 @@ function createNxKeyLicenseeInformation(nxKey) {
20
21
  // is just the filesystem lookup and is microseconds when the package is absent.
21
22
  // Only treat MODULE_NOT_FOUND as "not installed" so unrelated errors (permission,
22
23
  // corrupt package.json, etc.) still surface instead of being silently hidden.
23
- function packageInstalled(name) {
24
+ function resolveInstalled(name) {
24
25
  try {
25
- require.resolve(name, { paths: (0, installation_directory_1.getNxRequirePaths)() });
26
- return true;
26
+ return (0, url_1.pathToFileURL)((0, installation_directory_1.resolveInstalledPackage)(name, (0, installation_directory_1.getNxRequirePaths)()))
27
+ .href;
27
28
  }
28
29
  catch (e) {
29
30
  if (e?.code === 'MODULE_NOT_FOUND')
30
- return false;
31
+ return null;
31
32
  throw e;
32
33
  }
33
34
  }
34
35
  async function getNxKeyInformation() {
35
- if (packageInstalled('@nx/key')) {
36
- const { getNxKeyInformationAsync } = await import('@nx/key');
36
+ const nxKeyUrl = resolveInstalled('@nx/key');
37
+ if (nxKeyUrl) {
38
+ const { getNxKeyInformationAsync } = await import(nxKeyUrl);
37
39
  return getNxKeyInformationAsync(workspace_root_1.workspaceRoot);
38
40
  }
39
- if (packageInstalled('@nx/powerpack-license')) {
40
- const { getPowerpackLicenseInformation, getPowerpackLicenseInformationAsync, } = await import('@nx/powerpack-license');
41
+ const powerpackLicenseUrl = resolveInstalled('@nx/powerpack-license');
42
+ if (powerpackLicenseUrl) {
43
+ const { getPowerpackLicenseInformation, getPowerpackLicenseInformationAsync, } = await import(powerpackLicenseUrl);
41
44
  return (getPowerpackLicenseInformationAsync ?? getPowerpackLicenseInformation)(workspace_root_1.workspaceRoot);
42
45
  }
43
46
  throw new NxKeyNotInstalledError(new Error('MODULE_NOT_FOUND'));
@@ -246,6 +246,11 @@ declare class CLIOutput {
246
246
  log({ title, bodyLines, color }: CLIWarnMessageConfig & {
247
247
  color?: string;
248
248
  }): void;
249
+ /**
250
+ * Waits until everything written to stdout and stderr so far has reached the
251
+ * pipe. Writes to a pipe are asynchronous and `process.exit` does not wait
252
+ * for them.
253
+ */
249
254
  drain(): Promise<void>;
250
255
  }
251
256
  export declare const output: CLIOutput;
@@ -558,15 +558,22 @@ class CLIOutput {
558
558
  this.writeOptionalOutputBody(bodyLines);
559
559
  this.addNewline();
560
560
  }
561
+ /**
562
+ * Waits until everything written to stdout and stderr so far has reached the
563
+ * pipe. Writes to a pipe are asynchronous and `process.exit` does not wait
564
+ * for them.
565
+ */
561
566
  drain() {
562
- return new Promise((resolve) => {
563
- if (process.stdout.writableNeedDrain) {
564
- process.stdout.once('drain', resolve);
567
+ const flush = (stream) => new Promise((resolve) => {
568
+ if (stream.writableLength === 0) {
569
+ resolve();
565
570
  }
566
571
  else {
567
- resolve();
572
+ // The callback runs once every write queued before it is flushed.
573
+ stream.write('', () => resolve());
568
574
  }
569
575
  });
576
+ return Promise.all([flush(process.stdout), flush(process.stderr)]).then(() => undefined);
570
577
  }
571
578
  }
572
579
  exports.output = new CLIOutput();
@@ -135,6 +135,16 @@ export declare function isOwnedPrivateDir(dir: string): GuardResult<OwnedPrivate
135
135
  export declare function ensureSafeAncestry(dir: string): GuardResult<string>;
136
136
  /** `ensureSafeAncestry` without creating anything, for the delete path. */
137
137
  export declare function isSafeAncestry(dir: string): GuardResult<string>;
138
+ /**
139
+ * Whether the entry `name` of `dir` can be acted on by a walk up from the cwd.
140
+ * In a world-writable directory (`/tmp`) anyone can create it, so it must be
141
+ * ours or root's. Elsewhere ownership is not checked, so checkouts owned by
142
+ * another uid keep working. `lstat` judges a symlink by who made it.
143
+ *
144
+ * Anyone can hard-link a file they do not own, so a non-directory entry with
145
+ * more than one link proves nothing about who placed it.
146
+ */
147
+ export declare function isTrustedAncestorEntry(dir: string, name: string): boolean;
138
148
  /** The path segment separating one user's Nx runtime state from another's. */
139
149
  export declare function getUserSegment(): string;
140
150
  /**
@@ -9,6 +9,7 @@ exports.isOwnedRealDirectory = isOwnedRealDirectory;
9
9
  exports.isOwnedPrivateDir = isOwnedPrivateDir;
10
10
  exports.ensureSafeAncestry = ensureSafeAncestry;
11
11
  exports.isSafeAncestry = isSafeAncestry;
12
+ exports.isTrustedAncestorEntry = isTrustedAncestorEntry;
12
13
  exports.getUserSegment = getUserSegment;
13
14
  exports.ensureOwnedPrivateDir = ensureOwnedPrivateDir;
14
15
  /**
@@ -386,6 +387,33 @@ function isSafeAncestry(dir) {
386
387
  const refusal = walkAncestry(dir, false);
387
388
  return refusal ? deny(refusal) : allow(dir);
388
389
  }
390
+ /**
391
+ * Whether the entry `name` of `dir` can be acted on by a walk up from the cwd.
392
+ * In a world-writable directory (`/tmp`) anyone can create it, so it must be
393
+ * ours or root's. Elsewhere ownership is not checked, so checkouts owned by
394
+ * another uid keep working. `lstat` judges a symlink by who made it.
395
+ *
396
+ * Anyone can hard-link a file they do not own, so a non-directory entry with
397
+ * more than one link proves nothing about who placed it.
398
+ */
399
+ function isTrustedAncestorEntry(dir, name) {
400
+ if (typeof process.getuid !== 'function') {
401
+ return true;
402
+ }
403
+ try {
404
+ if (!((0, node_fs_1.statSync)(dir).mode & 0o002)) {
405
+ return true;
406
+ }
407
+ const entry = (0, node_fs_1.lstatSync)((0, node_path_1.join)(dir, name));
408
+ if (!entry.isDirectory() && entry.nlink !== 1) {
409
+ return false;
410
+ }
411
+ return entry.uid === process.getuid() || entry.uid === 0;
412
+ }
413
+ catch {
414
+ return false;
415
+ }
416
+ }
389
417
  /** The path segment separating one user's Nx runtime state from another's. */
390
418
  function getUserSegment() {
391
419
  try {
@@ -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 = [];
@@ -4,16 +4,18 @@ exports.requireNxKey = requireNxKey;
4
4
  const child_process_1 = require("child_process");
5
5
  const package_manager_1 = require("./package-manager");
6
6
  const handle_import_1 = require("./handle-import");
7
+ const installation_directory_1 = require("./installation-directory");
8
+ async function importNxKey() {
9
+ return (0, handle_import_1.handleImport)((0, installation_directory_1.resolveFromWorkspace)('@nx/key'));
10
+ }
7
11
  async function requireNxKey() {
8
- // @ts-ignore
9
- return (0, handle_import_1.handleImport)('@nx/key').catch(async (e) => {
12
+ return importNxKey().catch(async (e) => {
10
13
  if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
11
14
  try {
12
15
  (0, child_process_1.execSync)(`${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/key@latest`, {
13
16
  windowsHide: true,
14
17
  });
15
- // @ts-ignore
16
- return await (0, handle_import_1.handleImport)('@nx/key');
18
+ return await importNxKey();
17
19
  }
18
20
  catch (e) {
19
21
  throw new Error('Failed to install @nx/key. Please install @nx/key and try again.');
@@ -4,3 +4,15 @@
4
4
  export declare let workspaceRoot: string;
5
5
  export declare function setWorkspaceRoot(root: string): void;
6
6
  export declare function workspaceRootInner(dir: string, candidateRoot: string | null): string;
7
+ /**
8
+ * Whether a workspace marker found by walking up from the cwd may be used.
9
+ * `NX_WORKSPACE_ROOT_PATH` vouches for its own entries.
10
+ */
11
+ export declare function isTrustedWorkspaceEntry(dir: string, name: string): boolean;
12
+ /**
13
+ * Whether the nx installed in `nodeModules` may be used for the workspace at
14
+ * `root`. Each directory from `nodeModules` up to `root` is judged, or only
15
+ * `nodeModules` when it sits above `root`. `NX_WORKSPACE_ROOT_PATH` vouches
16
+ * for everything inside it.
17
+ */
18
+ export declare function isTrustedNxInstall(nodeModules: string, root: string): boolean;
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.workspaceRoot = void 0;
4
4
  exports.setWorkspaceRoot = setWorkspaceRoot;
5
5
  exports.workspaceRootInner = workspaceRootInner;
6
+ exports.isTrustedWorkspaceEntry = isTrustedWorkspaceEntry;
7
+ exports.isTrustedNxInstall = isTrustedNxInstall;
6
8
  const tslib_1 = require("tslib");
7
9
  const path = tslib_1.__importStar(require("path"));
8
10
  const fileutils_1 = require("./fileutils");
11
+ const owned_private_dir_1 = require("./owned-private-dir");
12
+ const warnedUntrusted = new Set();
9
13
  /**
10
14
  * The root of the workspace
11
15
  */
@@ -19,22 +23,67 @@ function workspaceRootInner(dir, candidateRoot) {
19
23
  return process.env.NX_WORKSPACE_ROOT_PATH;
20
24
  if (path.dirname(dir) === dir)
21
25
  return candidateRoot;
22
- const matches = [
23
- path.join(dir, 'nx.json'),
24
- path.join(dir, 'nx'),
25
- path.join(dir, 'nx.bat'),
26
- ];
27
- if (matches.some((x) => (0, fileutils_1.fileExists)(x))) {
26
+ const matches = ['nx.json', 'nx', 'nx.bat'];
27
+ if (matches.some((x) => (0, fileutils_1.fileExists)(path.join(dir, x)) && isTrustedWorkspaceEntry(dir, x))) {
28
28
  return dir;
29
29
  // This handles the case where we have a workspace which uses npm / yarn / pnpm
30
30
  // workspaces, and has a project which contains Nx in its dependency tree.
31
31
  // e.g. packages/my-lib/package.json contains @nx/devkit, which references Nx and is
32
32
  // thus located in //packages/my-lib/node_modules/nx/package.json
33
33
  }
34
- else if ((0, fileutils_1.fileExists)(path.join(dir, 'node_modules', 'nx', 'package.json'))) {
34
+ else if ((0, fileutils_1.fileExists)(path.join(dir, 'node_modules', 'nx', 'package.json')) &&
35
+ isTrustedNxInstall(path.join(dir, 'node_modules'), dir)) {
35
36
  return workspaceRootInner(path.dirname(dir), dir);
36
37
  }
37
38
  else {
38
39
  return workspaceRootInner(path.dirname(dir), candidateRoot);
39
40
  }
40
41
  }
42
+ /**
43
+ * Whether a workspace marker found by walking up from the cwd may be used.
44
+ * `NX_WORKSPACE_ROOT_PATH` vouches for its own entries.
45
+ */
46
+ function isTrustedWorkspaceEntry(dir, name) {
47
+ const explicitRoot = process.env.NX_WORKSPACE_ROOT_PATH;
48
+ if ((explicitRoot && path.resolve(explicitRoot) === path.resolve(dir)) ||
49
+ (0, owned_private_dir_1.isTrustedAncestorEntry)(dir, name)) {
50
+ return true;
51
+ }
52
+ const entry = path.join(dir, name);
53
+ warnUntrusted(entry, entry, `Set NX_WORKSPACE_ROOT_PATH=${dir} to use it anyway.`);
54
+ return false;
55
+ }
56
+ /**
57
+ * Whether the nx installed in `nodeModules` may be used for the workspace at
58
+ * `root`. Each directory from `nodeModules` up to `root` is judged, or only
59
+ * `nodeModules` when it sits above `root`. `NX_WORKSPACE_ROOT_PATH` vouches
60
+ * for everything inside it.
61
+ */
62
+ function isTrustedNxInstall(nodeModules, root) {
63
+ const explicitRoot = process.env.NX_WORKSPACE_ROOT_PATH;
64
+ const top = path.resolve(root);
65
+ let entry = path.resolve(nodeModules);
66
+ do {
67
+ const dir = path.dirname(entry);
68
+ if (!(explicitRoot && isInside(dir, path.resolve(explicitRoot))) &&
69
+ !(0, owned_private_dir_1.isTrustedAncestorEntry)(dir, path.basename(entry))) {
70
+ warnUntrusted(`the nx installed in ${nodeModules}`, entry, isInside(path.resolve(nodeModules), top)
71
+ ? `Set NX_WORKSPACE_ROOT_PATH=${root} to use it anyway.`
72
+ : 'Install nx in the workspace to use it.');
73
+ return false;
74
+ }
75
+ entry = dir;
76
+ } while (!isInside(top, entry));
77
+ return true;
78
+ }
79
+ function isInside(p, dir) {
80
+ return (p === dir || p.startsWith(dir.endsWith(path.sep) ? dir : dir + path.sep));
81
+ }
82
+ function warnUntrusted(subject, entry, remedy) {
83
+ if (warnedUntrusted.has(subject)) {
84
+ return;
85
+ }
86
+ warnedUntrusted.add(subject);
87
+ const where = subject === entry ? 'it is' : `${entry} is`;
88
+ console.warn(`NX Ignoring ${subject} because ${where} in a world-writable directory and may have been placed there by another user. ${remedy}`);
89
+ }
package/migrations.json CHANGED
@@ -204,6 +204,12 @@
204
204
  "description": "Renames the ultracache target options \"ignoredReads\" and \"ignoredWrites\" to \"ignoreReads\" and \"ignoreWrites\", and renames .nx/workflows/sandboxing-config.yaml to ultracache-config.yaml with its \"exclude-reads\" and \"exclude-writes\" keys renamed to \"ignore-reads\" and \"ignore-writes\".",
205
205
  "implementation": "./dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options",
206
206
  "documentation": "./dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md"
207
+ },
208
+ "24-1-0-replace-powerpack-conformance": {
209
+ "version": "24.1.0-beta.0",
210
+ "description": "Replaces @nx/powerpack-conformance with @nx/conformance, which nx conformance now loads. Rewrites its rule specifiers, executors and imports, points ensure-owners at @nx/owners, and adds esbuild for the bundle-rules executor.",
211
+ "implementation": "./dist/src/migrations/update-24-1-0/replace-powerpack-conformance",
212
+ "documentation": "./dist/src/migrations/update-24-1-0/replace-powerpack-conformance.md"
207
213
  }
208
214
  }
209
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "24.0.6",
3
+ "version": "24.1.0-beta.1",
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.1",
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.6",
154
- "@nx/nx-darwin-x64": "24.0.6",
155
- "@nx/nx-freebsd-x64": "24.0.6",
156
- "@nx/nx-linux-arm-gnueabihf": "24.0.6",
157
- "@nx/nx-linux-arm64-gnu": "24.0.6",
158
- "@nx/nx-linux-arm64-musl": "24.0.6",
159
- "@nx/nx-linux-x64-gnu": "24.0.6",
160
- "@nx/nx-linux-x64-musl": "24.0.6",
161
- "@nx/nx-win32-arm64-msvc": "24.0.6",
162
- "@nx/nx-win32-x64-msvc": "24.0.6"
153
+ "@nx/nx-darwin-arm64": "24.1.0-beta.1",
154
+ "@nx/nx-darwin-x64": "24.1.0-beta.1",
155
+ "@nx/nx-freebsd-x64": "24.1.0-beta.1",
156
+ "@nx/nx-linux-arm-gnueabihf": "24.1.0-beta.1",
157
+ "@nx/nx-linux-arm64-gnu": "24.1.0-beta.1",
158
+ "@nx/nx-linux-arm64-musl": "24.1.0-beta.1",
159
+ "@nx/nx-linux-x64-gnu": "24.1.0-beta.1",
160
+ "@nx/nx-linux-x64-musl": "24.1.0-beta.1",
161
+ "@nx/nx-win32-arm64-msvc": "24.1.0-beta.1",
162
+ "@nx/nx-win32-x64-msvc": "24.1.0-beta.1"
163
163
  },
164
164
  "nx-migrations": {
165
165
  "migrations": "./migrations.json",
@@ -204,6 +204,8 @@
204
204
  "@nx/web",
205
205
  "@nx/webpack",
206
206
  "@nx/docker",
207
+ "@nx/conformance",
208
+ "@nx/owners",
207
209
  "create-nx-workspace",
208
210
  {
209
211
  "package": "nx-cloud",