nx 24.0.0-beta.2 → 24.0.0-beta.3

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 (137) 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/migrate-analytics.d.ts +12 -1
  31. package/dist/src/command-line/migrate/migrate-analytics.js +26 -0
  32. package/dist/src/command-line/migrate/migrate-commits.d.ts +9 -10
  33. package/dist/src/command-line/migrate/migrate-commits.js +25 -18
  34. package/dist/src/command-line/migrate/migrate-output.d.ts +1 -6
  35. package/dist/src/command-line/migrate/migrate-output.js +1 -10
  36. package/dist/src/command-line/migrate/migrate.js +16 -27
  37. package/dist/src/command-line/migrate/run/agent-output.d.ts +1 -0
  38. package/dist/src/command-line/migrate/run/agent-output.js +4 -0
  39. package/dist/src/command-line/migrate/run/broker.js +1 -1
  40. package/dist/src/command-line/migrate/run/give-up.d.ts +4 -3
  41. package/dist/src/command-line/migrate/run/give-up.js +8 -5
  42. package/dist/src/command-line/migrate/run/index.d.ts +2 -1
  43. package/dist/src/command-line/migrate/run/index.js +5 -1
  44. package/dist/src/command-line/migrate/run/issues.js +7 -2
  45. package/dist/src/command-line/migrate/run/orchestrator.d.ts +40 -4
  46. package/dist/src/command-line/migrate/run/orchestrator.js +233 -92
  47. package/dist/src/command-line/migrate/run/run-state.d.ts +4 -1
  48. package/dist/src/command-line/migrate/run/run-state.js +20 -2
  49. package/dist/src/command-line/migrate/run/runbook.d.ts +1 -0
  50. package/dist/src/command-line/migrate/run/runbook.js +99 -21
  51. package/dist/src/command-line/migrate/run/state-lock.d.ts +29 -4
  52. package/dist/src/command-line/migrate/run/state-lock.js +102 -10
  53. package/dist/src/command-line/migrate/run/util.d.ts +4 -2
  54. package/dist/src/command-line/migrate/run/util.js +23 -2
  55. package/dist/src/command-line/migrate/run/worker.d.ts +1 -1
  56. package/dist/src/command-line/migrate/run/worker.js +252 -250
  57. package/dist/src/command-line/release/changelog.js +9 -6
  58. package/dist/src/command-line/release/config/config.d.ts +1 -0
  59. package/dist/src/command-line/release/config/config.js +48 -9
  60. package/dist/src/command-line/release/release.js +2 -2
  61. package/dist/src/command-line/release/utils/git.js +8 -7
  62. package/dist/src/command-line/release/utils/interpolate-release-config.d.ts +6 -0
  63. package/dist/src/command-line/release/utils/interpolate-release-config.js +39 -0
  64. package/dist/src/command-line/release/utils/release-graph.d.ts +5 -0
  65. package/dist/src/command-line/release/utils/release-graph.js +1 -0
  66. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +2 -2
  67. package/dist/src/command-line/release/utils/shared.js +10 -10
  68. package/dist/src/command-line/release/utils/version-plan-utils.d.ts +3 -12
  69. package/dist/src/command-line/release/utils/version-plan-utils.js +33 -55
  70. package/dist/src/command-line/release/version/version-actions.js +2 -1
  71. package/dist/src/command-line/release/version.js +5 -2
  72. package/dist/src/command-line/show/projects.js +5 -3
  73. package/dist/src/command-line/yargs-utils/shared-options.js +1 -1
  74. package/dist/src/config/nx-json.d.ts +8 -5
  75. package/dist/src/config/workspace-json-project-json.d.ts +12 -9
  76. package/dist/src/core/graph/main.js +1 -1
  77. package/dist/src/devkit-exports.d.ts +4 -0
  78. package/dist/src/devkit-exports.js +6 -1
  79. package/dist/src/devkit-internals.d.ts +1 -1
  80. package/dist/src/devkit-internals.js +4 -3
  81. package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -2
  82. package/dist/src/executors/run-commands/run-commands.impl.js +20 -10
  83. package/dist/src/executors/run-commands/running-tasks.d.ts +12 -3
  84. package/dist/src/executors/run-commands/running-tasks.js +22 -18
  85. package/dist/src/hasher/check-task-files.js +1 -4
  86. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +1 -2
  87. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +6 -11
  88. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +2 -2
  89. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.d.ts +4 -0
  90. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.js +15 -0
  91. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.md +30 -0
  92. package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +7 -6
  93. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.d.ts +3 -0
  94. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.js +130 -0
  95. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md +62 -0
  96. package/dist/src/native/index.d.ts +3 -3
  97. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  98. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  99. package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -3
  100. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +2 -2
  101. package/dist/src/plugins/js/lock-file/pruned-output.js +4 -4
  102. package/dist/src/project-graph/affected/affected-tasks.d.ts +6 -5
  103. package/dist/src/project-graph/affected/affected-tasks.js +16 -6
  104. package/dist/src/project-graph/utils/project-configuration/target-merging.js +1 -1
  105. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +7 -133
  106. package/dist/src/project-graph/utils/project-configuration-utils.js +2 -2
  107. package/dist/src/tasks-runner/readiness/probes.js +30 -1
  108. package/dist/src/tasks-runner/readiness/ready-when.d.ts +31 -10
  109. package/dist/src/tasks-runner/readiness/ready-when.js +178 -41
  110. package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -0
  111. package/dist/src/tasks-runner/task-orchestrator.js +113 -38
  112. package/dist/src/tasks-runner/tokens.d.ts +54 -0
  113. package/dist/src/tasks-runner/tokens.js +161 -0
  114. package/dist/src/tasks-runner/utils.d.ts +15 -1
  115. package/dist/src/tasks-runner/utils.js +79 -33
  116. package/dist/src/utils/acknowledge-build-scripts.d.ts +34 -1
  117. package/dist/src/utils/acknowledge-build-scripts.js +171 -32
  118. package/dist/src/utils/long-running-target.d.ts +1 -3
  119. package/dist/src/utils/long-running-target.js +1 -3
  120. package/migrations.json +13 -6
  121. package/package.json +11 -11
  122. package/schemas/nx-schema.json +17 -11
  123. package/schemas/project-schema.json +8 -7
  124. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +0 -56
  125. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +0 -67
  126. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +0 -49
  127. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +0 -53
  128. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +0 -26
  129. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +0 -27
  130. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +0 -70
  131. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +0 -113
  132. package/dist/src/command-line/migrate/agentic/run-step.d.ts +0 -68
  133. package/dist/src/command-line/migrate/agentic/run-step.js +0 -148
  134. package/dist/src/command-line/migrate/agentic/runner.d.ts +0 -21
  135. package/dist/src/command-line/migrate/agentic/runner.js +0 -262
  136. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +0 -9
  137. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +0 -18
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Nx tokens are `{name}` or `{name.path}`, optionally followed by `??`
3
+ * fallbacks that resolve left to right: `{options.port ?? env.PORT ?? 4200}`.
4
+ * Only the last part can be a literal, and the literal can contain tokens.
5
+ * Braces that don't start with a token are text, so `${VAR}` or
6
+ * `{{.State.Health.Status}}` stay as written.
7
+ */
8
+ export type TokenNode = {
9
+ kind: 'text';
10
+ text: string;
11
+ } | Token;
12
+ export interface Token {
13
+ kind: 'token';
14
+ raw: string;
15
+ parts: TokenPart[];
16
+ }
17
+ export type TokenPart = Reference | {
18
+ kind: 'literal';
19
+ nodes: TokenNode[];
20
+ };
21
+ interface Reference {
22
+ kind: 'reference';
23
+ name: string;
24
+ path: string | undefined;
25
+ }
26
+ export interface TokenScope {
27
+ /** Whether `{name}` or `{name.path}` is a token. An `env.` fallback skips this check */
28
+ isToken(name: string, path: string | undefined): boolean;
29
+ /** The value of `{name}` or `{name.path}` */
30
+ read(name: string, path: string | undefined): unknown;
31
+ /**
32
+ * Where `env.` references read from. When absent, `env.` is not a token, so
33
+ * `{env.X}` stays text and a fallback `env.X` is a literal.
34
+ */
35
+ env?: {
36
+ read: () => NodeJS.ProcessEnv;
37
+ } | {
38
+ reject: () => Error;
39
+ };
40
+ /** The text of a token with no value and no literal fallback */
41
+ noValue(token: string): string;
42
+ /** Whether a value counts as unset, as `undefined`, `null` and `''` always do */
43
+ isUnset?(value: unknown): boolean;
44
+ /** The text of a value; defaults to `String(value)` */
45
+ toText?(value: unknown, token: string): string;
46
+ }
47
+ export declare function parseTokens(template: string, scope: TokenScope): TokenNode[];
48
+ export declare function resolveTokens(template: string, scope: TokenScope): string;
49
+ export declare function renderTokens(nodes: TokenNode[], scope: TokenScope): string;
50
+ export declare function resolveToken(token: Token, scope: TokenScope, renderLiteral: (nodes: TokenNode[]) => string): string;
51
+ /** Walks a dotted path; a missing step yields `undefined` */
52
+ export declare function readPath(value: unknown, path: string | undefined): unknown;
53
+ export declare function readEnv(env: NodeJS.ProcessEnv, name: string): string | undefined;
54
+ export {};
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTokens = parseTokens;
4
+ exports.resolveTokens = resolveTokens;
5
+ exports.renderTokens = renderTokens;
6
+ exports.resolveToken = resolveToken;
7
+ exports.readPath = readPath;
8
+ exports.readEnv = readEnv;
9
+ function parseTokens(template, scope) {
10
+ const nodes = [];
11
+ let text = '';
12
+ let index = 0;
13
+ let open;
14
+ while ((open = template.indexOf('{', index)) !== -1) {
15
+ const close = findClosingBrace(template, open);
16
+ const node = close === -1 ? null : parseToken(template.slice(open, close + 1), scope);
17
+ if (!node) {
18
+ // Not a token, but a token can still sit inside it: `{a,{projectRoot}}`
19
+ text += template.slice(index, open + 1);
20
+ index = open + 1;
21
+ continue;
22
+ }
23
+ text += template.slice(index, open);
24
+ if (text) {
25
+ nodes.push({ kind: 'text', text });
26
+ }
27
+ text = '';
28
+ nodes.push(node);
29
+ index = close + 1;
30
+ }
31
+ text += template.slice(index);
32
+ if (text) {
33
+ nodes.push({ kind: 'text', text });
34
+ }
35
+ return nodes;
36
+ }
37
+ function resolveTokens(template, scope) {
38
+ return renderTokens(parseTokens(template, scope), scope);
39
+ }
40
+ function renderTokens(nodes, scope) {
41
+ return nodes
42
+ .map((node) => node.kind === 'text'
43
+ ? node.text
44
+ : resolveToken(node, scope, (literal) => renderTokens(literal, scope)))
45
+ .join('');
46
+ }
47
+ function resolveToken(token, scope, renderLiteral) {
48
+ for (const part of token.parts) {
49
+ if (part.kind === 'literal') {
50
+ return renderLiteral(part.nodes);
51
+ }
52
+ const value = part.name === 'env' && scope.env && 'read' in scope.env
53
+ ? readEnv(scope.env.read(), part.path)
54
+ : scope.read(part.name, part.path);
55
+ if (value !== undefined &&
56
+ value !== null &&
57
+ value !== '' &&
58
+ !scope.isUnset?.(value)) {
59
+ return scope.toText ? scope.toText(value, token.raw) : String(value);
60
+ }
61
+ }
62
+ return scope.noValue(token.raw);
63
+ }
64
+ /** Walks a dotted path; a missing step yields `undefined` */
65
+ function readPath(value, path) {
66
+ if (path === undefined) {
67
+ return value;
68
+ }
69
+ for (const key of path.split('.')) {
70
+ if (value === undefined ||
71
+ value === null ||
72
+ !Object.hasOwn(value, key)) {
73
+ return undefined;
74
+ }
75
+ value = value[key];
76
+ }
77
+ return value;
78
+ }
79
+ function parseToken(raw, scope) {
80
+ const sources = splitFallbacks(raw.slice(1, -1));
81
+ if (!parseReference(sources[0], scope, true)) {
82
+ return null;
83
+ }
84
+ const parts = sources.map((source, i) => {
85
+ const reference = parseReference(source, scope, i === 0);
86
+ if (reference) {
87
+ return reference;
88
+ }
89
+ if (i < sources.length - 1) {
90
+ throw new Error(`"${raw}" has a fallback after the literal "${source}" that can never be used`);
91
+ }
92
+ return { kind: 'literal', nodes: parseTokens(source, scope) };
93
+ });
94
+ if (scope.env && 'reject' in scope.env && readsEnv(parts)) {
95
+ throw scope.env.reject();
96
+ }
97
+ return { kind: 'token', raw, parts };
98
+ }
99
+ function readsEnv(parts) {
100
+ return parts.some((p) => p.kind === 'reference' && p.name === 'env');
101
+ }
102
+ // The names an env file can define, plus parentheses for Windows names such as
103
+ // `ProgramFiles(x86)`. A glob such as `{env.ts,env.d.ts}` stays text
104
+ const ENV_NAME = /^[\w.()-]+$/;
105
+ function parseReference(source, scope, first) {
106
+ const dot = source.indexOf('.');
107
+ const name = dot === -1 ? source : source.slice(0, dot);
108
+ const path = dot === -1 ? undefined : source.slice(dot + 1);
109
+ const isReference = name === 'env'
110
+ ? scope.env !== undefined &&
111
+ path !== undefined &&
112
+ ENV_NAME.test(path) &&
113
+ (!first || scope.isToken(name, path))
114
+ : scope.isToken(name, path);
115
+ return isReference ? { kind: 'reference', name, path } : null;
116
+ }
117
+ function findClosingBrace(template, open) {
118
+ let depth = 0;
119
+ for (let i = open; i < template.length; i++) {
120
+ if (template[i] === '{') {
121
+ depth++;
122
+ }
123
+ else if (template[i] === '}' && --depth === 0) {
124
+ return i;
125
+ }
126
+ }
127
+ return -1;
128
+ }
129
+ function splitFallbacks(expression) {
130
+ const parts = [];
131
+ let depth = 0;
132
+ let start = 0;
133
+ for (let i = 0; i < expression.length; i++) {
134
+ if (expression[i] === '{') {
135
+ depth++;
136
+ }
137
+ else if (expression[i] === '}') {
138
+ depth--;
139
+ }
140
+ else if (depth === 0 && expression.startsWith('??', i)) {
141
+ parts.push(expression.slice(start, i));
142
+ start = i + 2;
143
+ i++;
144
+ }
145
+ }
146
+ parts.push(expression.slice(start));
147
+ return parts.map((part) => part.trim());
148
+ }
149
+ // Windows env names are case-insensitive, but a copied env object keeps the
150
+ // spelling Windows reported (`Path`, not `PATH`)
151
+ function readEnv(env, name) {
152
+ if (Object.hasOwn(env, name)) {
153
+ return env[name];
154
+ }
155
+ if (process.platform !== 'win32') {
156
+ return undefined;
157
+ }
158
+ const upperName = name.toUpperCase();
159
+ const key = Object.keys(env).find((k) => k.toUpperCase() === upperName);
160
+ return key === undefined ? undefined : env[key];
161
+ }
@@ -28,7 +28,21 @@ export declare function transformLegacyOutputs(projectRoot: string, outputs: str
28
28
  */
29
29
  export declare function getOutputsForTargetAndConfiguration(task: Task, node: ProjectGraphProjectNode): string[];
30
30
  export declare function getOutputsForTargetAndConfiguration(target: Task['target'] | Task, overrides: Task['overrides'] | ProjectGraphProjectNode, node: ProjectGraphProjectNode): string[];
31
- export declare function interpolate(template: string, data: any): string;
31
+ /**
32
+ * Resolves the tokens in a configured output, without its leading `!`. A token
33
+ * with no value stays as written.
34
+ */
35
+ export declare function interpolateOutput(output: string, node: ProjectGraphProjectNode, options: Record<string, unknown>): string;
36
+ /**
37
+ * Resolves Nx tokens in a path, where each token names a key of `data`
38
+ * (`{projectRoot}/dist`, `{options.outputPath ?? dist/{projectRoot}}`).
39
+ * Paths starting with `/` are returned as written. A token with no value
40
+ * stays as written. `env.` is text, unless `envNotAllowed` is given: then it
41
+ * throws with that message.
42
+ */
43
+ export declare function interpolate(template: string, data: any, options?: {
44
+ envNotAllowed?: (template: string) => string;
45
+ }): string;
32
46
  export declare function getTargetConfigurationForTask(task: Task, projectGraph: ProjectGraph): TargetConfiguration | undefined;
33
47
  export declare function getExecutorNameForTask(task: Task, projectGraph: ProjectGraph): string;
34
48
  /**
@@ -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];
@@ -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>;