nx 24.0.0-beta.2 → 24.0.0-beta.4

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 (158) hide show
  1. package/dist/bin/post-install.js +5 -3
  2. package/dist/src/adapter/ngcli-adapter.js +1 -2
  3. package/dist/src/command-line/add/add.d.ts +2 -0
  4. package/dist/src/command-line/add/add.js +23 -5
  5. package/dist/src/command-line/affected/affected.js +2 -2
  6. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +21 -62
  7. package/dist/src/command-line/migrate/agentic/definitions.d.ts +1 -3
  8. package/dist/src/command-line/migrate/agentic/definitions.js +5 -97
  9. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +7 -41
  10. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +9 -48
  11. package/dist/src/command-line/migrate/agentic/handoff.d.ts +1 -43
  12. package/dist/src/command-line/migrate/agentic/handoff.js +3 -119
  13. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +0 -21
  14. package/dist/src/command-line/migrate/agentic/instruction-files.js +6 -27
  15. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +19 -1
  16. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +63 -36
  17. package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +1 -0
  18. package/dist/src/command-line/migrate/agentic/master/spawn-master.js +7 -5
  19. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +2 -2
  20. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +2 -2
  21. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +1 -12
  22. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +8 -17
  23. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +0 -15
  24. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +3 -100
  25. package/dist/src/command-line/migrate/agentic/select.d.ts +12 -6
  26. package/dist/src/command-line/migrate/agentic/select.js +35 -5
  27. package/dist/src/command-line/migrate/agentic/types.d.ts +9 -68
  28. package/dist/src/command-line/migrate/agentic/types.js +5 -5
  29. package/dist/src/command-line/migrate/command-object.js +3 -3
  30. package/dist/src/command-line/migrate/execute-migration.d.ts +4 -4
  31. package/dist/src/command-line/migrate/execute-migration.js +7 -5
  32. package/dist/src/command-line/migrate/migrate-analytics.d.ts +12 -1
  33. package/dist/src/command-line/migrate/migrate-analytics.js +26 -0
  34. package/dist/src/command-line/migrate/migrate-commits.d.ts +9 -10
  35. package/dist/src/command-line/migrate/migrate-commits.js +25 -18
  36. package/dist/src/command-line/migrate/migrate-output.d.ts +1 -6
  37. package/dist/src/command-line/migrate/migrate-output.js +1 -10
  38. package/dist/src/command-line/migrate/migrate.d.ts +3 -0
  39. package/dist/src/command-line/migrate/migrate.js +77 -44
  40. package/dist/src/command-line/migrate/run/agent-output.d.ts +1 -0
  41. package/dist/src/command-line/migrate/run/agent-output.js +4 -0
  42. package/dist/src/command-line/migrate/run/broker.js +1 -1
  43. package/dist/src/command-line/migrate/run/give-up.d.ts +4 -3
  44. package/dist/src/command-line/migrate/run/give-up.js +8 -5
  45. package/dist/src/command-line/migrate/run/index.d.ts +2 -1
  46. package/dist/src/command-line/migrate/run/index.js +5 -1
  47. package/dist/src/command-line/migrate/run/issues.js +7 -2
  48. package/dist/src/command-line/migrate/run/orchestrator.d.ts +40 -4
  49. package/dist/src/command-line/migrate/run/orchestrator.js +233 -92
  50. package/dist/src/command-line/migrate/run/run-state.d.ts +4 -1
  51. package/dist/src/command-line/migrate/run/run-state.js +20 -2
  52. package/dist/src/command-line/migrate/run/runbook.d.ts +1 -0
  53. package/dist/src/command-line/migrate/run/runbook.js +99 -21
  54. package/dist/src/command-line/migrate/run/state-lock.d.ts +29 -4
  55. package/dist/src/command-line/migrate/run/state-lock.js +102 -10
  56. package/dist/src/command-line/migrate/run/util.d.ts +4 -2
  57. package/dist/src/command-line/migrate/run/util.js +23 -2
  58. package/dist/src/command-line/migrate/run/worker.d.ts +1 -1
  59. package/dist/src/command-line/migrate/run/worker.js +252 -250
  60. package/dist/src/command-line/release/changelog.js +9 -6
  61. package/dist/src/command-line/release/config/config.d.ts +1 -0
  62. package/dist/src/command-line/release/config/config.js +48 -9
  63. package/dist/src/command-line/release/release.js +2 -2
  64. package/dist/src/command-line/release/utils/git.js +8 -7
  65. package/dist/src/command-line/release/utils/interpolate-release-config.d.ts +6 -0
  66. package/dist/src/command-line/release/utils/interpolate-release-config.js +39 -0
  67. package/dist/src/command-line/release/utils/release-graph.d.ts +5 -0
  68. package/dist/src/command-line/release/utils/release-graph.js +1 -0
  69. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +2 -2
  70. package/dist/src/command-line/release/utils/shared.js +10 -10
  71. package/dist/src/command-line/release/utils/version-plan-utils.d.ts +3 -12
  72. package/dist/src/command-line/release/utils/version-plan-utils.js +33 -55
  73. package/dist/src/command-line/release/version/version-actions.js +2 -1
  74. package/dist/src/command-line/release/version.js +5 -2
  75. package/dist/src/command-line/show/projects.js +5 -3
  76. package/dist/src/command-line/yargs-utils/shared-options.js +1 -1
  77. package/dist/src/config/misc-interfaces.d.ts +6 -0
  78. package/dist/src/config/nx-json.d.ts +8 -5
  79. package/dist/src/config/workspace-json-project-json.d.ts +23 -12
  80. package/dist/src/core/graph/main.js +1 -1
  81. package/dist/src/core/graph/runtime.js +1 -1
  82. package/dist/src/core/graph/styles.css +1 -1
  83. package/dist/src/core/graph/styles.js +1 -1
  84. package/dist/src/devkit-exports.d.ts +8 -0
  85. package/dist/src/devkit-exports.js +12 -1
  86. package/dist/src/devkit-internals.d.ts +2 -1
  87. package/dist/src/devkit-internals.js +7 -3
  88. package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -2
  89. package/dist/src/executors/run-commands/run-commands.impl.js +20 -10
  90. package/dist/src/executors/run-commands/running-tasks.d.ts +12 -3
  91. package/dist/src/executors/run-commands/running-tasks.js +22 -18
  92. package/dist/src/hasher/check-task-files.js +1 -4
  93. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +1 -2
  94. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +6 -11
  95. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +2 -2
  96. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.d.ts +4 -0
  97. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.js +15 -0
  98. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.md +30 -0
  99. package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +7 -6
  100. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.d.ts +3 -0
  101. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.js +130 -0
  102. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md +62 -0
  103. package/dist/src/native/index.d.ts +11 -5
  104. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  105. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  106. package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -3
  107. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +2 -2
  108. package/dist/src/plugins/js/lock-file/pruned-output.js +4 -4
  109. package/dist/src/project-graph/affected/affected-tasks.d.ts +6 -5
  110. package/dist/src/project-graph/affected/affected-tasks.js +16 -6
  111. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +49 -6
  112. package/dist/src/project-graph/utils/project-configuration/target-merging.js +1 -1
  113. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +7 -133
  114. package/dist/src/project-graph/utils/project-configuration-utils.js +2 -2
  115. package/dist/src/tasks-runner/pseudo-ipc.d.ts +1 -0
  116. package/dist/src/tasks-runner/pseudo-ipc.js +4 -0
  117. package/dist/src/tasks-runner/readiness/probes.d.ts +6 -1
  118. package/dist/src/tasks-runner/readiness/probes.js +41 -2
  119. package/dist/src/tasks-runner/readiness/ready-signal-server.d.ts +18 -0
  120. package/dist/src/tasks-runner/readiness/ready-signal-server.js +71 -0
  121. package/dist/src/tasks-runner/readiness/ready-signal.d.ts +25 -0
  122. package/dist/src/tasks-runner/readiness/ready-signal.js +70 -0
  123. package/dist/src/tasks-runner/readiness/ready-when.d.ts +35 -10
  124. package/dist/src/tasks-runner/readiness/ready-when.js +197 -42
  125. package/dist/src/tasks-runner/readiness/startup-host.d.ts +1 -0
  126. package/dist/src/tasks-runner/readiness/startup-host.js +32 -0
  127. package/dist/src/tasks-runner/task-env.js +11 -0
  128. package/dist/src/tasks-runner/task-orchestrator.d.ts +8 -0
  129. package/dist/src/tasks-runner/task-orchestrator.js +152 -42
  130. package/dist/src/tasks-runner/tokens.d.ts +54 -0
  131. package/dist/src/tasks-runner/tokens.js +161 -0
  132. package/dist/src/tasks-runner/utils.d.ts +15 -1
  133. package/dist/src/tasks-runner/utils.js +79 -33
  134. package/dist/src/ultracache/config.d.ts +3 -3
  135. package/dist/src/ultracache/config.js +4 -4
  136. package/dist/src/utils/acknowledge-build-scripts.d.ts +34 -1
  137. package/dist/src/utils/acknowledge-build-scripts.js +171 -32
  138. package/dist/src/utils/long-running-target.d.ts +1 -3
  139. package/dist/src/utils/long-running-target.js +1 -3
  140. package/migrations.json +13 -6
  141. package/package.json +11 -11
  142. package/schemas/migrations-schema.json +11 -0
  143. package/schemas/nx-schema.json +24 -13
  144. package/schemas/project-schema.json +15 -9
  145. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +0 -56
  146. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +0 -67
  147. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +0 -49
  148. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +0 -53
  149. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +0 -26
  150. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +0 -27
  151. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +0 -70
  152. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +0 -113
  153. package/dist/src/command-line/migrate/agentic/run-step.d.ts +0 -68
  154. package/dist/src/command-line/migrate/agentic/run-step.js +0 -148
  155. package/dist/src/command-line/migrate/agentic/runner.d.ts +0 -21
  156. package/dist/src/command-line/migrate/agentic/runner.js +0 -262
  157. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +0 -9
  158. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +0 -18
@@ -11,6 +11,7 @@ exports.normalizeTargetDependencyWithStringProjects = normalizeTargetDependencyW
11
11
  exports.validateOutputs = validateOutputs;
12
12
  exports.transformLegacyOutputs = transformLegacyOutputs;
13
13
  exports.getOutputsForTargetAndConfiguration = getOutputsForTargetAndConfiguration;
14
+ exports.interpolateOutput = interpolateOutput;
14
15
  exports.interpolate = interpolate;
15
16
  exports.getTargetConfigurationForTask = getTargetConfigurationForTask;
16
17
  exports.getExecutorNameForTask = getExecutorNameForTask;
@@ -46,6 +47,7 @@ const serialize_overrides_into_command_line_1 = require("../utils/serialize-over
46
47
  const split_target_1 = require("../utils/split-target");
47
48
  const workspace_root_1 = require("../utils/workspace-root");
48
49
  const is_tui_enabled_1 = require("./is-tui-enabled");
50
+ const tokens_1 = require("./tokens");
49
51
  function getDependencyConfigs({ project, target }, extraTargetDependencies, projectGraph, allTargetNames) {
50
52
  return (projectGraph.nodes[project].data?.targets[target]?.dependsOn ??
51
53
  // This is passed into `run-command` from programmatic invocations
@@ -214,18 +216,10 @@ function getOutputsForTargetAndConfiguration(taskTargetOrTask, overridesOrNode,
214
216
  validateOutputs(targetConfiguration.outputs);
215
217
  const result = new Set();
216
218
  for (const output of targetConfiguration.outputs) {
217
- // A leading `!` is negation, not part of the path: strip it so
218
- // `{workspaceRoot}` still sits where interpolate requires it.
219
- const isNegated = output.startsWith('!');
220
- const interpolatedOutput = interpolate(isNegated ? output.substring(1) : output, {
221
- projectRoot: node.data.root,
222
- projectName: node.name,
223
- project: { ...node.data, name: node.name }, // this is legacy
224
- options,
225
- });
219
+ const interpolatedOutput = interpolateOutput(output, node, options);
226
220
  if (!!interpolatedOutput &&
227
221
  !interpolatedOutput.match(/{(projectRoot|workspaceRoot|(options.*))}/)) {
228
- result.add(isNegated ? `!${interpolatedOutput}` : interpolatedOutput);
222
+ result.add(output.startsWith('!') ? `!${interpolatedOutput}` : interpolatedOutput);
229
223
  }
230
224
  }
231
225
  return Array.from(result);
@@ -249,37 +243,89 @@ function getOutputsForTargetAndConfiguration(taskTargetOrTask, overridesOrNode,
249
243
  }
250
244
  }
251
245
  /**
252
- * Matches portions of a string which need to be interpolated.
253
- * Matches anything within curly braces, excluding the braces.
246
+ * Resolves the tokens in a configured output, without its leading `!`. A token
247
+ * with no value stays as written.
254
248
  */
255
- const replacementRegex = /{([\s\S]+?)}/g;
256
- function interpolate(template, data) {
257
- // Path is absolute or doesn't need interpolation
258
- if (template.startsWith('/') || !replacementRegex.test(template)) {
249
+ function interpolateOutput(output, node, options) {
250
+ // A leading `!` is negation, not part of the path: strip it so
251
+ // `{workspaceRoot}` still sits where interpolate requires it.
252
+ return interpolate(output.startsWith('!') ? output.substring(1) : output, {
253
+ projectRoot: node.data.root,
254
+ projectName: node.name,
255
+ project: { ...node.data, name: node.name }, // this is legacy
256
+ options,
257
+ });
258
+ }
259
+ /**
260
+ * Resolves Nx tokens in a path, where each token names a key of `data`
261
+ * (`{projectRoot}/dist`, `{options.outputPath ?? dist/{projectRoot}}`).
262
+ * Paths starting with `/` are returned as written. A token with no value
263
+ * stays as written. `env.` is text, unless `envNotAllowed` is given: then it
264
+ * throws with that message.
265
+ */
266
+ function interpolate(template, data, options) {
267
+ if (!/{[\s\S]+?}/.test(template)) {
268
+ return template;
269
+ }
270
+ const scope = {
271
+ isToken: (name) => name === 'env' || Object.hasOwn(data, name),
272
+ read: (name, path) => (0, tokens_1.readPath)(data[name], path),
273
+ env: options?.envNotAllowed
274
+ ? { reject: () => new Error(options.envNotAllowed(template)) }
275
+ : undefined,
276
+ noValue: (token) => token,
277
+ };
278
+ if (template.startsWith('/')) {
279
+ if (options?.envNotAllowed) {
280
+ (0, tokens_1.parseTokens)(template, scope);
281
+ }
259
282
  return template;
260
283
  }
261
- if (template.includes('{workspaceRoot}', 1)) {
284
+ const nodes = (0, tokens_1.parseTokens)(template, scope);
285
+ if (!isWorkspaceRootOnlyAtStart(nodes, true)) {
262
286
  throw new Error(`Output '${template}' is invalid. {workspaceRoot} can only be used at the beginning of the expression.`);
263
287
  }
264
- const parts = template.split('/').map((s) => _interpolate(s, data));
265
- return (0, posix_1.join)(...parts).replace('{workspaceRoot}/', '');
288
+ return joinSegments(nodes, data, scope).replace('{workspaceRoot}/', '');
289
+ }
290
+ // A fallback's literal only ever replaces its whole token, so a token at the
291
+ // start can fall back to `{workspaceRoot}/...`
292
+ function isWorkspaceRootOnlyAtStart(nodes, atStart) {
293
+ return nodes.every((node, i) => {
294
+ const nodeAtStart = atStart && i === 0;
295
+ if (node.kind === 'text') {
296
+ return !node.text.includes('{workspaceRoot}', nodeAtStart ? 1 : 0);
297
+ }
298
+ return node.parts.every((part) => part.kind === 'literal'
299
+ ? isWorkspaceRootOnlyAtStart(part.nodes, nodeAtStart)
300
+ : part.name !== 'workspaceRoot' || nodeAtStart);
301
+ });
266
302
  }
267
- function _interpolate(template, data) {
268
- let res = template;
269
- if (data.projectRoot == '.') {
270
- res = res.replace('{projectRoot}', '');
271
- }
272
- return res.replace(replacementRegex, (match) => {
273
- let value = data;
274
- let path = match.slice(1, -1).trim().split('.');
275
- for (let idx = 0; idx < path.length; idx++) {
276
- if (!value[path[idx]]) {
277
- return match;
303
+ // Joining the `/`-separated segments normalizes a root project's
304
+ // `{projectRoot}` away, wherever it sits
305
+ function joinSegments(nodes, data, scope) {
306
+ const segments = [''];
307
+ const append = (nodes, isLiteral) => {
308
+ for (const [i, node] of nodes.entries()) {
309
+ if (node.kind === 'text') {
310
+ // A literal keeps its leading `/` on the segment, as an option value
311
+ // does, so an absolute fallback stays absolute
312
+ const root = isLiteral && i === 0 && node.text.startsWith('/') ? '/' : '';
313
+ const [first, ...rest] = node.text.substring(root.length).split('/');
314
+ segments[segments.length - 1] += root + first;
315
+ segments.push(...rest);
316
+ }
317
+ else {
318
+ // Resolved before indexing `segments`: a fallback literal appends to it
319
+ const value = data.projectRoot == '.' && node.raw === '{projectRoot}'
320
+ ? ''
321
+ : (0, tokens_1.resolveToken)(node, scope, (literal) => append(literal, true));
322
+ segments[segments.length - 1] += value;
278
323
  }
279
- value = value[path[idx]];
280
324
  }
281
- return value;
282
- });
325
+ return '';
326
+ };
327
+ append(nodes, false);
328
+ return (0, posix_1.join)(...segments);
283
329
  }
284
330
  function getTargetConfigurationForTask(task, projectGraph) {
285
331
  const node = projectGraph.nodes[task.target.project];
@@ -12,9 +12,9 @@ export interface UltracacheEnv {
12
12
  hasNxCloudToken?: boolean;
13
13
  }
14
14
  /**
15
- * Off unless a CI run opts in with `NX_CLOUD_USE_ULTRACACHE=true` in a
16
- * workspace that uses Nx Cloud, since there is nothing to fetch from otherwise.
17
- * `env` defaults to this process's.
15
+ * On for CI runs in a workspace that uses Nx Cloud, since there is nothing to
16
+ * fetch from otherwise. Nx Cloud's workspace setting decides whether the fetch
17
+ * returns any; `NX_CLOUD_USE_ULTRACACHE=false` skips it. `env` defaults to this process's.
18
18
  */
19
19
  export declare function isUltracacheConfigurationFetchEnabled(nxJson: NxJsonConfiguration, runnerOptions?: UltracacheCloudOptions, env?: UltracacheEnv): boolean;
20
20
  /** The subset of this run's environment the decision reads. */
@@ -5,15 +5,15 @@ exports.ultracacheEnv = ultracacheEnv;
5
5
  const is_ci_1 = require("../utils/is-ci");
6
6
  const nx_cloud_utils_1 = require("../utils/nx-cloud-utils");
7
7
  /**
8
- * Off unless a CI run opts in with `NX_CLOUD_USE_ULTRACACHE=true` in a
9
- * workspace that uses Nx Cloud, since there is nothing to fetch from otherwise.
10
- * `env` defaults to this process's.
8
+ * On for CI runs in a workspace that uses Nx Cloud, since there is nothing to
9
+ * fetch from otherwise. Nx Cloud's workspace setting decides whether the fetch
10
+ * returns any; `NX_CLOUD_USE_ULTRACACHE=false` skips it. `env` defaults to this process's.
11
11
  */
12
12
  function isUltracacheConfigurationFetchEnabled(nxJson, runnerOptions = {}, env = ultracacheEnv()) {
13
13
  if (env.NX_NO_CLOUD === 'true' ||
14
14
  nxJson.neverConnectToCloud ||
15
15
  runnerOptions.cloud === false ||
16
- env.NX_CLOUD_USE_ULTRACACHE !== 'true' ||
16
+ env.NX_CLOUD_USE_ULTRACACHE === 'false' ||
17
17
  !(0, is_ci_1.isCI)()) {
18
18
  return false;
19
19
  }
@@ -9,5 +9,38 @@ import type { PackageManager } from './package-manager';
9
9
  * that introduces such a dependency records the decision up front. Other
10
10
  * package managers run build scripts unconditionally, so this is a no-op for
11
11
  * them.
12
+ *
13
+ * @param treeOrRoot The workspace tree, or its root on disk.
14
+ * @param packageManager The workspace package manager.
15
+ * @param entries Package name to decision: `true` runs the package's build
16
+ * scripts, `false` skips them. Entries the user already decided are kept.
17
+ * @param directory Workspace root relative to the tree root, for generators
18
+ * that scaffold a workspace into a subdirectory.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * acknowledgeBuildScripts(tree, detectPackageManager(tree.root), {
23
+ * esbuild: false,
24
+ * cypress: true,
25
+ * });
26
+ * ```
27
+ */
28
+ export declare function acknowledgeBuildScripts(treeOrRoot: Tree | string, packageManager: PackageManager, entries: Record<string, boolean>, directory?: string): void;
29
+ /**
30
+ * Records the build-script decisions a package declares for its own
31
+ * dependency tree, so the install that first pulls the package in can stay
32
+ * strict. A package declares them in the `pnpm.allowBuilds` field of its
33
+ * package.json, the same shape pnpm reads from a workspace root; pnpm ignores
34
+ * the field on dependencies, so it is read from the registry here.
35
+ *
36
+ * A declared `false` is recorded as is: it only skips a script. A declared
37
+ * `true` would let a publisher authorize code execution in the workspace, so
38
+ * it is a request: in a terminal the owner picks which to allow, elsewhere
39
+ * every request is recorded as `false`. Decisions the owner already recorded
40
+ * are kept either way, and everything recorded is printed.
41
+ *
42
+ * Resolves to whether the package declared any decision. Nothing is recorded
43
+ * for package managers other than pnpm, pnpm < 11, packages that declare
44
+ * nothing, and specs the registry cannot answer, such as a tarball path.
12
45
  */
13
- export declare function acknowledgeBuildScripts(treeOrRoot: Tree | string, packageManager: PackageManager, entries: Record<string, boolean>): void;
46
+ export declare function acknowledgeDeclaredBuildScripts(treeOrRoot: Tree | string, packageManager: PackageManager, packageName: string, version: string, directory?: string): Promise<boolean>;
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.acknowledgeBuildScripts = acknowledgeBuildScripts;
4
+ exports.acknowledgeDeclaredBuildScripts = acknowledgeDeclaredBuildScripts;
4
5
  const fs_1 = require("fs");
5
6
  const path_1 = require("path");
6
7
  const yaml_1 = require("yaml");
7
8
  const semver_1 = require("semver");
8
9
  const package_manager_1 = require("./package-manager");
9
10
  const fileutils_1 = require("./fileutils");
11
+ const is_ci_1 = require("./is-ci");
10
12
  const json_1 = require("./json");
13
+ const output_1 = require("./output");
14
+ const prompt_helpers_1 = require("./prompt-helpers");
11
15
  const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
12
16
  /**
13
17
  * Records build-script decisions for dependencies that are about to be
@@ -18,67 +22,202 @@ const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
18
22
  * that introduces such a dependency records the decision up front. Other
19
23
  * package managers run build scripts unconditionally, so this is a no-op for
20
24
  * them.
25
+ *
26
+ * @param treeOrRoot The workspace tree, or its root on disk.
27
+ * @param packageManager The workspace package manager.
28
+ * @param entries Package name to decision: `true` runs the package's build
29
+ * scripts, `false` skips them. Entries the user already decided are kept.
30
+ * @param directory Workspace root relative to the tree root, for generators
31
+ * that scaffold a workspace into a subdirectory.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * acknowledgeBuildScripts(tree, detectPackageManager(tree.root), {
36
+ * esbuild: false,
37
+ * cypress: true,
38
+ * });
39
+ * ```
21
40
  */
22
- function acknowledgeBuildScripts(treeOrRoot, packageManager, entries) {
41
+ function acknowledgeBuildScripts(treeOrRoot, packageManager, entries, directory = '') {
23
42
  if (packageManager !== 'pnpm') {
24
43
  return;
25
44
  }
26
- acknowledgePnpmBuildScripts(treeOrRoot, entries);
45
+ const host = createHost(treeOrRoot, directory);
46
+ const pnpmVersion = getPnpmVersion(host);
47
+ if (!pnpmVersion || !(0, semver_1.gte)(pnpmVersion, '11.0.0')) {
48
+ return;
49
+ }
50
+ acknowledgePnpmBuildScripts(host, entries);
27
51
  }
28
52
  /**
29
- * Records `allowBuilds` decisions in pnpm-workspace.yaml, creating the file
30
- * when missing (mirroring `pnpm approve-builds` in single-package repos).
53
+ * Records the build-script decisions a package declares for its own
54
+ * dependency tree, so the install that first pulls the package in can stay
55
+ * strict. A package declares them in the `pnpm.allowBuilds` field of its
56
+ * package.json, the same shape pnpm reads from a workspace root; pnpm ignores
57
+ * the field on dependencies, so it is read from the registry here.
31
58
  *
32
- * Comment-preserving. Existing entries are never overwritten, so user
33
- * decisions always win. No-op for pnpm < 11, which warns instead of erroring
34
- * and does not read `allowBuilds`.
59
+ * A declared `false` is recorded as is: it only skips a script. A declared
60
+ * `true` would let a publisher authorize code execution in the workspace, so
61
+ * it is a request: in a terminal the owner picks which to allow, elsewhere
62
+ * every request is recorded as `false`. Decisions the owner already recorded
63
+ * are kept either way, and everything recorded is printed.
64
+ *
65
+ * Resolves to whether the package declared any decision. Nothing is recorded
66
+ * for package managers other than pnpm, pnpm < 11, packages that declare
67
+ * nothing, and specs the registry cannot answer, such as a tarball path.
35
68
  */
36
- function acknowledgePnpmBuildScripts(treeOrRoot, entries) {
37
- const host = createHost(treeOrRoot);
69
+ async function acknowledgeDeclaredBuildScripts(treeOrRoot, packageManager, packageName, version, directory = '') {
70
+ if (packageManager !== 'pnpm') {
71
+ return false;
72
+ }
73
+ const host = createHost(treeOrRoot, directory);
38
74
  const pnpmVersion = getPnpmVersion(host);
39
75
  if (!pnpmVersion || !(0, semver_1.gte)(pnpmVersion, '11.0.0')) {
40
- return;
76
+ return false;
41
77
  }
42
- const parsed = (0, yaml_1.parseDocument)(host.exists(PNPM_WORKSPACE_FILE) ? host.read(PNPM_WORKSPACE_FILE) : '');
43
- // A file that doesn't parse cleanly or whose root isn't a mapping is
44
- // malformed for pnpm; leave it alone rather than crashing or replacing the
45
- // user's content. pnpm's own error on the file is the actionable signal.
46
- // Empty and comment-only files have no contents at all; setIn creates the
47
- // mapping for them while keeping whatever comments they carry.
48
- if (parsed.errors.length > 0 ||
49
- (parsed.contents != null && !(parsed.contents instanceof yaml_1.YAMLMap))) {
50
- return;
78
+ const declared = await readDeclaredBuildScripts(packageName, version);
79
+ if (Object.keys(declared).length === 0) {
80
+ return false;
81
+ }
82
+ const decided = readRecordedDecisions(host);
83
+ const requests = Object.keys(declared).filter((pkg) => declared[pkg] && !(pkg in decided));
84
+ const prompted = requests.length > 0 && canPrompt();
85
+ const allowed = prompted
86
+ ? await (0, prompt_helpers_1.multiselectPrompt)({
87
+ message: `${packageName}@${version} asks to run the install scripts of these packages. Which ones do you allow?`,
88
+ choices: requests,
89
+ required: false,
90
+ })
91
+ : [];
92
+ const entries = { ...declared };
93
+ for (const pkg of requests) {
94
+ entries[pkg] = allowed.includes(pkg);
51
95
  }
52
- let changed = false;
96
+ const recorded = acknowledgePnpmBuildScripts(host, entries);
97
+ if (Object.keys(recorded).length > 0) {
98
+ const blocked = requests.filter((pkg) => !entries[pkg] && pkg in recorded);
99
+ output_1.output.note({
100
+ title: `Recorded the build-script decisions ${packageName}@${version} declares in ${PNPM_WORKSPACE_FILE}`,
101
+ bodyLines: [
102
+ ...Object.entries(recorded).map(([pkg, value]) => blocked.includes(pkg)
103
+ ? `${pkg}: false (the package asked to run it)`
104
+ : `${pkg}: ${value}`),
105
+ ...(blocked.length > 0
106
+ ? [
107
+ `To run a blocked script, set its entry to true in ${PNPM_WORKSPACE_FILE} and run "pnpm rebuild <package>".`,
108
+ ]
109
+ : []),
110
+ ],
111
+ });
112
+ }
113
+ return true;
114
+ }
115
+ function canPrompt() {
116
+ return (process.env.NX_INTERACTIVE !== 'false' &&
117
+ !(0, is_ci_1.isCI)() &&
118
+ !!process.stdout.isTTY &&
119
+ !!process.stdin.isTTY);
120
+ }
121
+ async function readDeclaredBuildScripts(packageName, version) {
122
+ let declared;
123
+ try {
124
+ const output = await (0, package_manager_1.packageRegistryView)(packageName, version, [
125
+ 'pnpm.allowBuilds',
126
+ '--json',
127
+ ]);
128
+ declared = output ? JSON.parse(output) : undefined;
129
+ }
130
+ catch {
131
+ return {};
132
+ }
133
+ // A range matches several versions; the view lists them lowest first.
134
+ if (Array.isArray(declared)) {
135
+ declared = declared[declared.length - 1];
136
+ }
137
+ if (declared == null || typeof declared !== 'object') {
138
+ return {};
139
+ }
140
+ return Object.fromEntries(Object.entries(declared).filter((entry) => typeof entry[1] === 'boolean'));
141
+ }
142
+ /**
143
+ * Records `allowBuilds` decisions in pnpm-workspace.yaml, creating the file
144
+ * when missing (mirroring `pnpm approve-builds` in single-package repos).
145
+ * Returns the entries it wrote.
146
+ *
147
+ * Comment-preserving. Existing entries are never overwritten, so user
148
+ * decisions always win. pnpm < 11 warns instead of erroring and does not read
149
+ * `allowBuilds`, so callers gate on the version first.
150
+ */
151
+ function acknowledgePnpmBuildScripts(host, entries) {
152
+ const parsed = parseWorkspaceFile(host);
153
+ if (!parsed) {
154
+ return {};
155
+ }
156
+ const recorded = {};
53
157
  for (const [pkg, allowed] of Object.entries(entries)) {
54
158
  // Only a real boolean is a user decision. pnpm's non-strict installs stub
55
159
  // undecided packages with a placeholder string ("set this to true or
56
160
  // false"), which would fail the next strict install if left in place.
57
161
  if (typeof parsed.getIn(['allowBuilds', pkg]) !== 'boolean') {
58
162
  parsed.setIn(['allowBuilds', pkg], allowed);
59
- changed = true;
163
+ recorded[pkg] = allowed;
60
164
  }
61
165
  }
62
- if (changed) {
166
+ if (Object.keys(recorded).length > 0) {
63
167
  host.write(PNPM_WORKSPACE_FILE, parsed.toString());
64
168
  }
169
+ return recorded;
170
+ }
171
+ /**
172
+ * Parses pnpm-workspace.yaml, or null when pnpm itself would reject it. A file
173
+ * that doesn't parse cleanly or whose root isn't a mapping is left alone
174
+ * rather than crashed on or replaced; pnpm's own error on the file is the
175
+ * actionable signal. Empty and comment-only files have no contents at all;
176
+ * setIn creates the mapping for them while keeping whatever comments they
177
+ * carry.
178
+ */
179
+ function parseWorkspaceFile(host) {
180
+ const parsed = (0, yaml_1.parseDocument)(host.exists(PNPM_WORKSPACE_FILE) ? host.read(PNPM_WORKSPACE_FILE) : '');
181
+ if (parsed.errors.length > 0 ||
182
+ (parsed.contents != null && !(parsed.contents instanceof yaml_1.YAMLMap))) {
183
+ return null;
184
+ }
185
+ return parsed;
186
+ }
187
+ /** The `allowBuilds` entries that carry a real decision, not a placeholder. */
188
+ function readRecordedDecisions(host) {
189
+ const allowBuilds = parseWorkspaceFile(host)?.get('allowBuilds');
190
+ if (!(allowBuilds instanceof yaml_1.YAMLMap)) {
191
+ return {};
192
+ }
193
+ const decisions = {};
194
+ for (const pair of allowBuilds.items) {
195
+ const value = (0, yaml_1.isScalar)(pair.value) ? pair.value.value : pair.value;
196
+ if (typeof value === 'boolean') {
197
+ decisions[String((0, yaml_1.isScalar)(pair.key) ? pair.key.value : pair.key)] = value;
198
+ }
199
+ }
200
+ return decisions;
65
201
  }
66
- function createHost(treeOrRoot) {
202
+ function createHost(treeOrRoot, directory) {
67
203
  if (typeof treeOrRoot === 'string') {
204
+ const root = (0, path_1.join)(treeOrRoot, directory);
68
205
  return {
69
- root: treeOrRoot,
70
- exists: (p) => (0, fs_1.existsSync)((0, path_1.join)(treeOrRoot, p)),
71
- read: (p) => (0, fs_1.readFileSync)((0, path_1.join)(treeOrRoot, p), 'utf-8'),
72
- write: (p, c) => (0, fs_1.writeFileSync)((0, path_1.join)(treeOrRoot, p), c),
73
- readJson: (p) => (0, fileutils_1.readJsonFile)((0, path_1.join)(treeOrRoot, p)),
206
+ root,
207
+ exists: (p) => (0, fs_1.existsSync)((0, path_1.join)(root, p)),
208
+ read: (p) => (0, fs_1.readFileSync)((0, path_1.join)(root, p), 'utf-8'),
209
+ write: (p, c) => (0, fs_1.writeFileSync)((0, path_1.join)(root, p), c),
210
+ readJson: (p) => (0, fileutils_1.readJsonFile)((0, path_1.join)(root, p)),
74
211
  };
75
212
  }
213
+ // The directory may not exist on disk yet (a workspace being scaffolded
214
+ // into it), so the package manager is probed from the tree root.
76
215
  return {
77
216
  root: treeOrRoot.root,
78
- exists: (p) => treeOrRoot.exists(p),
79
- read: (p) => treeOrRoot.read(p, 'utf-8'),
80
- write: (p, c) => treeOrRoot.write(p, c),
81
- readJson: (p) => (0, json_1.parseJson)(treeOrRoot.read(p, 'utf-8')),
217
+ exists: (p) => treeOrRoot.exists((0, path_1.join)(directory, p)),
218
+ read: (p) => treeOrRoot.read((0, path_1.join)(directory, p), 'utf-8'),
219
+ write: (p, c) => treeOrRoot.write((0, path_1.join)(directory, p), c),
220
+ readJson: (p) => (0, json_1.parseJson)(treeOrRoot.read((0, path_1.join)(directory, p), 'utf-8')),
82
221
  };
83
222
  }
84
223
  function getPnpmVersion(host) {
@@ -1,7 +1,5 @@
1
1
  /**
2
- * Target names the pre-23 `longRunningTask` guard excluded from caching. Shared
3
- * between that guard and the deprecated target-name cache fallback so the two
4
- * cannot drift apart.
2
+ * Target names the pre-23 `longRunningTask` guard excluded from caching.
5
3
  *
6
4
  * The copy in `migrations/update-23-2-0/set-cache-on-executor-target-defaults.ts`
7
5
  * deliberately does not use this: a migration's decision has to freeze at the
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLongRunningTargetName = isLongRunningTargetName;
4
4
  /**
5
- * Target names the pre-23 `longRunningTask` guard excluded from caching. Shared
6
- * between that guard and the deprecated target-name cache fallback so the two
7
- * cannot drift apart.
5
+ * Target names the pre-23 `longRunningTask` guard excluded from caching.
8
6
  *
9
7
  * The copy in `migrations/update-23-2-0/set-cache-on-executor-target-defaults.ts`
10
8
  * deliberately does not use this: a migration's decision has to freeze at the
package/migrations.json CHANGED
@@ -175,11 +175,6 @@
175
175
  "implementation": "./dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore",
176
176
  "documentation": "./dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.md"
177
177
  },
178
- "23-0-0-consolidate-release-tag-config": {
179
- "version": "23.0.0-beta.16",
180
- "description": "Consolidates any remaining legacy releaseTag* flat properties into the nested releaseTag object. The flat properties were removed in Nx 23.",
181
- "implementation": "./dist/src/migrations/update-23-0-0/consolidate-release-tag-config"
182
- },
183
178
  "23-0-0-add-migrate-runs-to-git-ignore": {
184
179
  "version": "23.0.0-beta.18",
185
180
  "description": "Adds .nx/migrate-runs to .gitignore",
@@ -187,7 +182,7 @@
187
182
  },
188
183
  "23-2-0-set-cache-on-executor-target-defaults": {
189
184
  "version": "23.2.0-beta.8",
190
- "description": "Sets \"cache\" on some executor-based target defaults whose caching was previously enabled by a target name default, maintaining compatibility with how cacheability resolved before Nx 23. Keys the migration cannot decide are left alone and keep working through a deprecated runtime fallback.",
185
+ "description": "Sets \"cache\" on some executor-based target defaults whose caching was previously enabled by a target name default, maintaining compatibility with how cacheability resolved before Nx 23. Keys the migration cannot decide are left alone, and the targets resolving through them need \"cache\" set by hand.",
191
186
  "implementation": "./dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults",
192
187
  "documentation": "./dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md"
193
188
  },
@@ -197,6 +192,18 @@
197
192
  "implementation": "./dist/src/migrations/update-24-0-0/find-custom-hashers",
198
193
  "prompt": "./dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md",
199
194
  "documentation": "./dist/src/migrations/update-24-0-0/find-custom-hashers.md"
195
+ },
196
+ "24-0-0-enable-legacy-affected": {
197
+ "version": "24.0.0-beta.3",
198
+ "description": "Sets affected.legacy to true in nx.json so nx affected keeps selecting whole projects. Nx 24 selects individual affected tasks by default.",
199
+ "implementation": "./dist/src/migrations/update-24-0-0/enable-legacy-affected",
200
+ "documentation": "./dist/src/migrations/update-24-0-0/enable-legacy-affected.md"
201
+ },
202
+ "24-0-0-rename-ultracache-ignore-options": {
203
+ "version": "24.0.0-beta.3",
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
+ "implementation": "./dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options",
206
+ "documentation": "./dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md"
200
207
  }
201
208
  }
202
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "24.0.0-beta.2",
3
+ "version": "24.0.0-beta.4",
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.",
@@ -150,16 +150,16 @@
150
150
  }
151
151
  },
152
152
  "optionalDependencies": {
153
- "@nx/nx-darwin-arm64": "24.0.0-beta.2",
154
- "@nx/nx-darwin-x64": "24.0.0-beta.2",
155
- "@nx/nx-freebsd-x64": "24.0.0-beta.2",
156
- "@nx/nx-linux-arm-gnueabihf": "24.0.0-beta.2",
157
- "@nx/nx-linux-arm64-gnu": "24.0.0-beta.2",
158
- "@nx/nx-linux-arm64-musl": "24.0.0-beta.2",
159
- "@nx/nx-linux-x64-gnu": "24.0.0-beta.2",
160
- "@nx/nx-linux-x64-musl": "24.0.0-beta.2",
161
- "@nx/nx-win32-arm64-msvc": "24.0.0-beta.2",
162
- "@nx/nx-win32-x64-msvc": "24.0.0-beta.2"
153
+ "@nx/nx-darwin-arm64": "24.0.0-beta.4",
154
+ "@nx/nx-darwin-x64": "24.0.0-beta.4",
155
+ "@nx/nx-freebsd-x64": "24.0.0-beta.4",
156
+ "@nx/nx-linux-arm-gnueabihf": "24.0.0-beta.4",
157
+ "@nx/nx-linux-arm64-gnu": "24.0.0-beta.4",
158
+ "@nx/nx-linux-arm64-musl": "24.0.0-beta.4",
159
+ "@nx/nx-linux-x64-gnu": "24.0.0-beta.4",
160
+ "@nx/nx-linux-x64-musl": "24.0.0-beta.4",
161
+ "@nx/nx-win32-arm64-msvc": "24.0.0-beta.4",
162
+ "@nx/nx-win32-x64-msvc": "24.0.0-beta.4"
163
163
  },
164
164
  "nx-migrations": {
165
165
  "migrations": "./migrations.json",
@@ -85,9 +85,20 @@
85
85
  "x-repair-skip": {
86
86
  "type": "boolean",
87
87
  "description": "Exclude this migration when users run `nx repair`."
88
+ },
89
+ "optionalUpdate": {
90
+ "type": "boolean",
91
+ "description": "Marks a migration that applies an optional dependency update, such as a major version bump that also rewrites code. `nx migrate --include=required` skips it, and `nx migrate --include=optional` runs it whenever `requires` is met. Requires `requires`, set to the versions the migration updates from."
88
92
  }
89
93
  },
90
94
  "required": ["version"],
95
+ "if": {
96
+ "properties": { "optionalUpdate": { "const": true } },
97
+ "required": ["optionalUpdate"]
98
+ },
99
+ "then": {
100
+ "required": ["requires"]
101
+ },
91
102
  "anyOf": [
92
103
  {
93
104
  "required": ["implementation"]