@nx/js 24.1.0-beta.1 → 24.1.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 (34) hide show
  1. package/dist/internal.d.ts +2 -1
  2. package/dist/internal.js +8 -5
  3. package/dist/src/executors/copy-workspace-modules/copy-workspace-modules.js +40 -32
  4. package/dist/src/executors/prune-lockfile/prune-lockfile.js +105 -8
  5. package/dist/src/executors/release-publish/release-publish.impl.js +6 -1
  6. package/dist/src/migrations/update-23-2-0/add-pnpm-deploy-output-cache-inputs.d.ts +1 -6
  7. package/dist/src/migrations/update-23-2-0/add-pnpm-deploy-output-cache-inputs.js +4 -224
  8. package/dist/src/migrations/update-23-2-0/add-pnpm-prune-lockfile-cache-config.js +18 -297
  9. package/dist/src/migrations/update-24-1-0/add-bun-deploy-output-cache-inputs.d.ts +8 -0
  10. package/dist/src/migrations/update-24-1-0/add-bun-deploy-output-cache-inputs.js +21 -0
  11. package/dist/src/migrations/update-24-1-0/add-bun-deploy-output-cache-inputs.md +49 -0
  12. package/dist/src/migrations/update-24-1-0/add-bun-prune-lockfile-cache-config.d.ts +2 -0
  13. package/dist/src/migrations/update-24-1-0/add-bun-prune-lockfile-cache-config.js +28 -0
  14. package/dist/src/migrations/update-24-1-0/add-bun-prune-lockfile-cache-config.md +44 -0
  15. package/dist/src/plugins/typescript/plugin.js +58 -5
  16. package/dist/src/plugins/typescript/typecheck-target.d.ts +6 -0
  17. package/dist/src/plugins/typescript/typecheck-target.js +7 -5
  18. package/dist/src/release/version-actions.js +6 -0
  19. package/dist/src/utils/bun-install-settings-inputs.d.ts +20 -0
  20. package/dist/src/utils/bun-install-settings-inputs.js +31 -0
  21. package/dist/src/utils/deploy-output-cache-inputs.d.ts +35 -0
  22. package/dist/src/utils/deploy-output-cache-inputs.js +400 -0
  23. package/dist/src/utils/pnpm-install-settings-inputs.d.ts +0 -6
  24. package/dist/src/utils/pnpm-install-settings-inputs.js +0 -6
  25. package/dist/src/utils/prune-lockfile-cache-config.d.ts +18 -0
  26. package/dist/src/utils/prune-lockfile-cache-config.js +288 -0
  27. package/dist/src/utils/target-defaults-matching.d.ts +3 -0
  28. package/dist/src/utils/target-defaults-matching.js +7 -0
  29. package/dist/src/utils/workspace-module-sections.d.ts +10 -5
  30. package/dist/src/utils/workspace-module-sections.js +15 -6
  31. package/migrations.json +14 -2
  32. package/package.json +20 -12
  33. package/dist/src/utils/pnpm-deploy-output-cache-inputs.d.ts +0 -29
  34. package/dist/src/utils/pnpm-deploy-output-cache-inputs.js +0 -177
@@ -2,304 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = update;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const internal_1 = require("@nx/devkit/internal");
6
5
  const pnpm_install_settings_inputs_1 = require("../../utils/pnpm-install-settings-inputs");
7
- const target_defaults_matching_1 = require("../../utils/target-defaults-matching");
8
- const PRUNE_LOCKFILE_EXECUTOR = '@nx/js:prune-lockfile';
9
- const PNPM_LOCKFILE = 'pnpm-lock.yaml';
10
- // Artifacts the executor emits next to the pruned lockfile; without them in
11
- // `outputs`, a cache replay restores only the manifest and the lockfile.
12
- const PNPM_PRUNE_ARTIFACTS = [
13
- 'pnpm-workspace.yaml',
14
- 'patches',
15
- 'local_path_modules',
16
- ];
17
- // The workspace root files those artifacts are built from. Neither the pnpm
18
- // build approvals nor `supportedArchitectures` are recorded in the lockfile, so
19
- // nothing else in the hash moves when they change. The pnpm major decides
20
- // which emitted file carries them, and the ambient binary supplies it when the
21
- // manifest's `packageManager` field is absent, so the major probe is added
22
- // alongside.
23
- const PNPM_ROOT_SETTINGS_SOURCES = [
24
- '{workspaceRoot}/pnpm-workspace.yaml',
25
- '{workspaceRoot}/package.json',
26
- ];
6
+ const prune_lockfile_cache_config_1 = require("../../utils/prune-lockfile-cache-config");
27
7
  async function update(tree) {
28
- const nxJson = (0, devkit_1.readNxJson)(tree);
29
- const targetDefaults = nxJson?.targetDefaults;
30
- const pruneTargets = [];
31
- const projects = new Map();
32
- const changedProjects = new Set();
33
- for (const [projectName, project] of (0, devkit_1.getProjects)(tree)) {
34
- projects.set(projectName, project);
35
- const projectNode = {
36
- name: projectName,
37
- type: 'lib',
38
- data: { root: project.root, tags: project.tags },
39
- };
40
- for (const [targetName, target] of Object.entries(project.targets ?? {})) {
41
- // The executor may come from a matching targetDefaults entry rather
42
- // than the target itself. A `command` target resolves to nx:run-commands
43
- // before defaults apply, so a default can never make it a prune target.
44
- const executor = target.executor ??
45
- (target.command
46
- ? 'nx:run-commands'
47
- : (0, target_defaults_matching_1.resolveDefaultsExecutor)(targetName, projectName, projectNode, targetDefaults, PRUNE_LOCKFILE_EXECUTOR));
48
- if (executor !== PRUNE_LOCKFILE_EXECUTOR) {
49
- continue;
50
- }
51
- pruneTargets.push({
52
- targetName,
53
- projectName,
54
- projectNode,
55
- matcherExecutor: target.executor,
56
- target,
57
- });
58
- if (appendPnpmPruneOutputs(target)) {
59
- changedProjects.add(projectName);
60
- }
61
- }
62
- }
63
- let defaultsChanged = false;
64
- // runtime applies only the first key that resolves for a target (executor,
65
- // exact name, then longest glob), so anchor each prune target to its
66
- // selected key
67
- const keyedPruneTargets = pruneTargets.map((ref) => ({
68
- ref,
69
- selectedKey: targetDefaults
70
- ? (0, target_defaults_matching_1.selectDefaultsKey)(ref, targetDefaults, PRUNE_LOCKFILE_EXECUTOR)
71
- : null,
72
- }));
73
- if (targetDefaults) {
74
- for (const [key, value] of Object.entries(targetDefaults)) {
75
- // a value may be the plain object form or the filtered array form
76
- for (const config of Array.isArray(value) ? value : [value]) {
77
- if (!appliesToPruneLockfileTargets(key, config, keyedPruneTargets)) {
78
- continue;
79
- }
80
- defaultsChanged = appendPnpmPruneOutputs(config) || defaultsChanged;
81
- }
82
- }
83
- }
84
- // `inputs` is decided separately from `outputs`, because the two can be
85
- // authored on different layers and a target's own `inputs` replaces the
86
- // defaults' array rather than merging with it. The sources are only ever
87
- // appended to an array that already exists, or written with nx's default as
88
- // the base when no layer declares one. The migration never authors a `'...'`
89
- // of its own: whether the entry it would expand against survives depends on
90
- // the document-order identity resets in nx's own merge, and a spread that
91
- // ends up with nothing to expand narrows the target to the two root files.
92
- for (const { ref, selectedKey } of keyedPruneTargets) {
93
- const entries = (0, target_defaults_matching_1.compatibleDefaultsEntries)(ref, selectedKey, targetDefaults);
94
- const defaults = entries.length
95
- ? (0, internal_1.readTargetDefaultsForTarget)(ref.targetName, { [selectedKey]: entries }, ref.matcherExecutor, { projectName: ref.projectName, projectNode: ref.projectNode })
96
- : null;
97
- // The effective outputs, not the target's own array: a target inheriting
98
- // its lockfile entry, or spreading the defaults' outputs into its own, is
99
- // still a pnpm prune target.
100
- const effective = (0, internal_1.mergeTargetConfigurations)(ref.target, defaults ?? {});
101
- if (!declaresPnpmLockfile(effective.outputs)) {
102
- continue;
103
- }
104
- if (ref.target.inputs !== undefined) {
105
- // A target's own array wins outright, so nothing else can carry them.
106
- if (addRootSettingsInputs(ref.target, effective.inputs)) {
107
- changedProjects.add(ref.projectName);
108
- }
109
- continue;
110
- }
111
- // Otherwise they belong to the entry supplying the array the target
112
- // inherits, which is the last matching one declaring `inputs`.
113
- const supplier = (0, target_defaults_matching_1.lastMatchingInputsSupplier)(ref, selectedKey, entries);
114
- if (supplier) {
115
- defaultsChanged =
116
- addRootSettingsInputs(supplier, effective.inputs) || defaultsChanged;
117
- }
118
- else if (addRootSettingsInputs(ref.target, effective.inputs)) {
119
- changedProjects.add(ref.projectName);
120
- }
121
- }
122
- // A workspace configuring its prune targets purely through `targetDefaults`
123
- // has no concrete target to carry the decision above.
124
- if (targetDefaults && pruneTargets.length === 0) {
125
- for (const [key, value] of Object.entries(targetDefaults)) {
126
- const entries = Array.isArray(value) ? value : [value];
127
- // The key qualifies only when it locates the executor without a
128
- // concrete target to resolve against: the key itself, an entry pinning
129
- // it, or an entry filtering on it. Every identity-compatible sibling
130
- // still merges for such a target, an identity-neutral one included.
131
- const compatible = entries.filter(entryIdentityCompatible);
132
- const locatesExecutor = key === PRUNE_LOCKFILE_EXECUTOR ||
133
- compatible.some((config) => config.executor === PRUNE_LOCKFILE_EXECUTOR ||
134
- config.filter?.executor === PRUNE_LOCKFILE_EXECUTOR);
135
- if (!locatesExecutor ||
136
- !compatible.some((config) => declaresPnpmLockfile(config.outputs))) {
137
- continue;
138
- }
139
- // Every compatible entry declaring `inputs` can be the array a future
140
- // target inherits (a later filtered one replaces it for its projects),
141
- // so each carries the sources itself; a sibling's array covers nothing
142
- // unless a `'...'` spread pulls it in, in which case only the strictly
143
- // filter-less earlier entries are the base it expands against: a
144
- // filtered one supplies nothing to the targets its filter excludes,
145
- // an executor filter failing for a target whose executor a sibling
146
- // supplies (earlier entries are updated first, so the base is checked
147
- // with the sources already added).
148
- const suppliers = compatible.filter((config) => config.inputs !== undefined);
149
- for (const [index, config] of compatible.entries()) {
150
- if (config.inputs === undefined) {
151
- continue;
152
- }
153
- const reference = config.inputs.includes('...')
154
- ? [
155
- ...config.inputs,
156
- ...compatible
157
- .slice(0, index)
158
- .filter((earlier) => !earlier.filter)
159
- .flatMap((earlier) => earlier.inputs ?? []),
160
- ]
161
- : config.inputs;
162
- defaultsChanged =
163
- addRootSettingsInputs(config, reference) || defaultsChanged;
164
- }
165
- // Targets no filtered supplier matches fall back to nx's own default
166
- // when no filter-less entry declares an array, so the spelled-out
167
- // default is prepended as its own entry: prepending keeps it from
168
- // replacing a later supplier's array. A prepended carrier must match
169
- // only targets an existing entry already matched, or the key starts
170
- // winning selection for targets that previously fell through to their
171
- // name or glob defaults. That holds under an executor key with a
172
- // filter-less entry (a neutral carrier), and under a name or glob key
173
- // with a filter-less pin (a pinned carrier, which a same-name target of
174
- // another executor cannot inherit). An all-filtered array gets no
175
- // fallback: any carrier would widen the key. The object form has no
176
- // room to prepend; its single filter-less entry carries it instead.
177
- if (!suppliers.some((supplier) => !supplier.filter)) {
178
- const canCarry = key === PRUNE_LOCKFILE_EXECUTOR
179
- ? compatible.some((config) => !config.filter)
180
- : compatible.some((config) => !config.filter && config.executor === PRUNE_LOCKFILE_EXECUTOR);
181
- if (canCarry) {
182
- if (Array.isArray(value)) {
183
- const fallback = key === PRUNE_LOCKFILE_EXECUTOR
184
- ? {}
185
- : { executor: PRUNE_LOCKFILE_EXECUTOR };
186
- addRootSettingsInputs(fallback, []);
187
- value.unshift(fallback);
188
- defaultsChanged = true;
189
- }
190
- else {
191
- defaultsChanged =
192
- addRootSettingsInputs(value, []) || defaultsChanged;
193
- }
194
- }
195
- }
196
- }
197
- }
198
- for (const projectName of changedProjects) {
199
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projects.get(projectName));
200
- }
201
- if (defaultsChanged) {
202
- (0, devkit_1.updateNxJson)(tree, nxJson);
203
- }
8
+ (0, prune_lockfile_cache_config_1.addPruneLockfileCacheConfig)(tree, {
9
+ lockFile: 'pnpm-lock.yaml',
10
+ // Artifacts the executor emits next to the pruned lockfile; without them
11
+ // in `outputs`, a cache replay restores only the manifest and the lockfile.
12
+ artifacts: ['pnpm-workspace.yaml', 'patches', 'local_path_modules'],
13
+ // The workspace root files those artifacts are built from. Neither the
14
+ // pnpm build approvals nor `supportedArchitectures` are recorded in the
15
+ // lockfile, so nothing else in the hash moves when they change. The pnpm
16
+ // major decides which emitted file carries them, and the ambient binary
17
+ // supplies it when the manifest's `packageManager` field is absent, so the
18
+ // major probe is added alongside.
19
+ rootInputs: [
20
+ '{workspaceRoot}/pnpm-workspace.yaml',
21
+ '{workspaceRoot}/package.json',
22
+ pnpm_install_settings_inputs_1.PNPM_MAJOR_RUNTIME_INPUT,
23
+ ],
24
+ });
204
25
  await (0, devkit_1.formatFiles)(tree);
205
26
  }
206
- function declaresPnpmLockfile(outputs) {
207
- return pnpmLockfileEntry(outputs) !== undefined;
208
- }
209
- function pnpmLockfileEntry(outputs) {
210
- return outputs?.find((output) => typeof output === 'string' &&
211
- (output === PNPM_LOCKFILE || output.endsWith(`/${PNPM_LOCKFILE}`)));
212
- }
213
- /**
214
- * Adds the workspace root files the pnpm install settings live in, and the
215
- * pnpm major probe, skipping any the target already hashes: a `'...'` in the
216
- * owner's array can carry one in from the layer below, where a check against
217
- * the owner's own entries cannot see it. An absent `inputs` means nx's own
218
- * default, so that is spelled out before adding to it rather than narrowing
219
- * the configuration to the settings sources alone.
220
- */
221
- function addRootSettingsInputs(config, referenceInputs = []) {
222
- const alreadyHashed = (0, target_defaults_matching_1.namedFilesets)(referenceInputs);
223
- const missing = PNPM_ROOT_SETTINGS_SOURCES.filter((source) => !alreadyHashed.has(source) && !config.inputs?.includes(source));
224
- if (!hasPnpmMajorProbe(referenceInputs) &&
225
- !hasPnpmMajorProbe(config.inputs)) {
226
- missing.push(pnpm_install_settings_inputs_1.PNPM_MAJOR_RUNTIME_INPUT);
227
- }
228
- if (missing.length === 0) {
229
- return false;
230
- }
231
- config.inputs = [...(config.inputs ?? target_defaults_matching_1.DEFAULT_INPUTS), ...missing];
232
- return true;
233
- }
234
- function hasPnpmMajorProbe(inputs) {
235
- return (inputs ?? []).some((existing) => typeof existing === 'object' &&
236
- existing !== null &&
237
- 'runtime' in existing &&
238
- existing.runtime === pnpm_install_settings_inputs_1.PNPM_MAJOR_RUNTIME_INPUT.runtime);
239
- }
240
- /**
241
- * Whether a `targetDefaults` entry applies to `@nx/js:prune-lockfile` targets,
242
- * mirroring nx's runtime matching: the entry's `filter` and merge-time
243
- * payload compatibility are evaluated first, then the entry must sit under a
244
- * prune target's selected key and match its context. Entries locating the
245
- * executor (key, `executor` field, or `filter.executor`) match without a
246
- * concrete target so a defaults-only workspace still gets the update. The
247
- * in-key merge accumulation (identity replacement, outputs replacement, `...`
248
- * spreads) is deliberately not replicated: an entry the merge ends up
249
- * discarding for the prune target may still get the artifacts appended, which
250
- * is additive-only for the target's own replay.
251
- */
252
- function appliesToPruneLockfileTargets(key, config, pruneTargets) {
253
- if (!entryIdentityCompatible(config)) {
254
- return false;
255
- }
256
- const filter = config.filter;
257
- if (pruneTargets.length === 0) {
258
- const locatesExecutor = key === PRUNE_LOCKFILE_EXECUTOR ||
259
- config.executor === PRUNE_LOCKFILE_EXECUTOR ||
260
- filter?.executor === PRUNE_LOCKFILE_EXECUTOR;
261
- return locatesExecutor && !filter?.projects;
262
- }
263
- return pruneTargets.some(({ ref, selectedKey }) => selectedKey === key &&
264
- (0, internal_1.readTargetDefaultsForTarget)(ref.targetName, { [key]: [config] }, ref.matcherExecutor, { projectName: ref.projectName, projectNode: ref.projectNode }) !== null);
265
- }
266
- /**
267
- * Whether a `targetDefaults` entry can merge into an `@nx/js:prune-lockfile`
268
- * target at all: a filter or payload pinning another executor or a command
269
- * identity never does (isCompatibleTarget), and prune-lockfile targets are
270
- * always explicitly configured, never inferred, so a plugin-filtered entry
271
- * never applies either.
272
- */
273
- function entryIdentityCompatible(config) {
274
- const filter = config.filter;
275
- if (filter?.executor && filter.executor !== PRUNE_LOCKFILE_EXECUTOR) {
276
- return false;
277
- }
278
- if (filter?.plugin) {
279
- return false;
280
- }
281
- return !((config.executor && config.executor !== PRUNE_LOCKFILE_EXECUTOR) ||
282
- config.command);
283
- }
284
- /**
285
- * Appends the pnpm prune artifacts next to an existing pnpm-lock.yaml entry,
286
- * reusing that entry's own path spelling. Configurations with no `outputs` or no
287
- * pnpm lockfile entry are left alone: the lockfile entry is what identifies the
288
- * target as pnpm's, and one without `outputs` caches nothing to begin with.
289
- */
290
- function appendPnpmPruneOutputs(config) {
291
- const lockfileEntry = pnpmLockfileEntry(config.outputs);
292
- if (!lockfileEntry) {
293
- return false;
294
- }
295
- const prefix = lockfileEntry.slice(0, -PNPM_LOCKFILE.length);
296
- let changed = false;
297
- for (const artifact of PNPM_PRUNE_ARTIFACTS) {
298
- const entry = `${prefix}${artifact}`;
299
- if (!config.outputs.includes(entry)) {
300
- config.outputs.push(entry);
301
- changed = true;
302
- }
303
- }
304
- return changed;
305
- }
@@ -0,0 +1,8 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ /**
3
+ * Adds the root package.json fields a pruned Bun deploy output is built from
4
+ * to the `inputs` of build targets that emit it. The trust list reaches no
5
+ * package's hash, so without them an untrusted package leaves the task hash
6
+ * unchanged and a cached run replays an output that still trusts it.
7
+ */
8
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const bun_install_settings_inputs_1 = require("../../utils/bun-install-settings-inputs");
6
+ const deploy_output_cache_inputs_1 = require("../../utils/deploy-output-cache-inputs");
7
+ /**
8
+ * Adds the root package.json fields a pruned Bun deploy output is built from
9
+ * to the `inputs` of build targets that emit it. The trust list reaches no
10
+ * package's hash, so without them an untrusted package leaves the task hash
11
+ * unchanged and a cached run replays an output that still trusts it.
12
+ */
13
+ async function update(tree) {
14
+ // A workspace on the binary bun.lockb gets the inputs too: its output
15
+ // carries the trust list once it switches to bun.lock.
16
+ if (!tree.exists('bun.lock') && !tree.exists('bun.lockb')) {
17
+ return;
18
+ }
19
+ await (0, deploy_output_cache_inputs_1.addDeployOutputCacheInputsToBuildTargets)(tree, bun_install_settings_inputs_1.BUN_INSTALL_SETTINGS_INPUTS);
20
+ await (0, devkit_1.formatFiles)(tree);
21
+ }
@@ -0,0 +1,49 @@
1
+ #### Add the Bun install settings fields to the inputs of build targets that emit the pruned deploy output
2
+
3
+ In a Bun workspace on the text `bun.lock`, build executors that generate a deployable `package.json` now also emit a pruned `bun.lock` and the `.patch` files of a `bun patch` workspace next to it. `@nx/esbuild:esbuild` builds do this when `generatePackageJson` is enabled, `@nx/js:tsc` and `@nx/js:swc` builds when `generateLockfile` is, and builds inferred by `@nx/webpack/plugin` or `@nx/rspack/plugin` when `NxAppWebpackPlugin` or `NxAppRspackPlugin` has `generatePackageJson` enabled. The emitted `package.json` carries the root `trustedDependencies` list and the `patchedDependencies` of the patches it ships.
4
+
5
+ Nothing in a build target's default task hash covers the root `trustedDependencies`. Removing a package from that list would replay the previous build from cache and ship an output that still trusts it to run install scripts.
6
+
7
+ The migration adds a `json` input hashing only the `trustedDependencies` and `patchedDependencies` fields of the root `package.json`, so ordinary dependency bumps in the root manifest do not invalidate every build. The patch contents already reach the task hash through the patched packages. Workspaces on the binary `bun.lockb` get the input too. Their deploy output is the `package.json` alone until they switch to the text `bun.lock`, and from then on it carries the trust list.
8
+
9
+ The input is placed with the same rules as the pnpm migration in Nx 23.2 (`update-23-2-0-add-pnpm-deploy-output-cache-inputs`): on the target's own `inputs` when it declares them, otherwise on the `targetDefaults` entry supplying the array it inherits, and otherwise on the target itself with nx's own default spelled out first. An existing whole-file root `package.json` fileset or a `json` input covering both fields counts as already hashing them. Targets inferred by the `@nx/webpack` and `@nx/rspack` plugins declare the input themselves, but a project-level or `targetDefaults` entry that supplies its own `inputs` array without `"..."` replaces the inferred array and discards it; the migration appends the input to that replacing array.
10
+
11
+ #### Sample code changes
12
+
13
+ ##### Before
14
+
15
+ ```json title="apps/app1/project.json"
16
+ {
17
+ "targets": {
18
+ "build": {
19
+ "executor": "@nx/esbuild:esbuild",
20
+ "options": {
21
+ "generatePackageJson": true
22
+ }
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ ##### After
29
+
30
+ ```json title="apps/app1/project.json"
31
+ {
32
+ "targets": {
33
+ "build": {
34
+ "executor": "@nx/esbuild:esbuild",
35
+ "inputs": [
36
+ "default",
37
+ "^default",
38
+ {
39
+ "json": "{workspaceRoot}/package.json",
40
+ "fields": ["trustedDependencies", "patchedDependencies"]
41
+ }
42
+ ],
43
+ "options": {
44
+ "generatePackageJson": true
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const prune_lockfile_cache_config_1 = require("../../utils/prune-lockfile-cache-config");
6
+ // The `bun patch` files and the vendored local-path dependencies the executor
7
+ // emits next to the pruned lockfile; without them in `outputs`, a cache replay
8
+ // restores only the manifest and the lockfile.
9
+ const ARTIFACTS = ['patches', 'local_path_modules'];
10
+ // The root manifest declares the trusted install scripts and the patches the
11
+ // output carries. The trust list reaches no package's hash, so nothing else in
12
+ // the hash moves when a package is untrusted.
13
+ const ROOT_INPUTS = ['{workspaceRoot}/package.json'];
14
+ async function update(tree) {
15
+ (0, prune_lockfile_cache_config_1.addPruneLockfileCacheConfig)(tree, {
16
+ lockFile: 'bun.lock',
17
+ artifacts: ARTIFACTS,
18
+ rootInputs: ROOT_INPUTS,
19
+ });
20
+ // A target generated on the binary bun.lockb declares that file, and the
21
+ // executor writes the text bun.lock once the workspace switches to it.
22
+ (0, prune_lockfile_cache_config_1.addPruneLockfileCacheConfig)(tree, {
23
+ lockFile: 'bun.lockb',
24
+ artifacts: ['bun.lock', ...ARTIFACTS],
25
+ rootInputs: ROOT_INPUTS,
26
+ });
27
+ await (0, devkit_1.formatFiles)(tree);
28
+ }
@@ -0,0 +1,44 @@
1
+ #### Update the cache configuration of `@nx/js:prune-lockfile` targets for the Bun install artifacts
2
+
3
+ In a Bun workspace on the text `bun.lock`, the `@nx/js:prune-lockfile` executor now emits a pruned `bun.lock` next to the pruned `package.json`, the `.patch` files of a `bun patch` workspace under `patches/`, and the non-workspace `file:` and `link:` dependencies the output installs under `local_path_modules/`. The emitted `package.json` carries the root `trustedDependencies` list and the `patchedDependencies` of the patches it ships.
4
+
5
+ Targets generated before this change declare only the manifest and the lockfile in `outputs`, so a cache replay in a clean checkout restores just those two files, and `bun install --frozen-lockfile` in the output fails on the missing patch files or vendored packages. The same targets declare no `inputs`, so nothing in the task hash covers the root `trustedDependencies`. Removing a package from that list would replay the previous run's output from cache and ship a manifest that still trusts it. The patch contents and the vendored package contents already reach the task hash through the packages they belong to.
6
+
7
+ The `patches` and `local_path_modules` paths are appended to whichever `outputs` array declares the `bun.lock` entry, reusing that entry's own path prefix. A target generated on the binary `bun.lockb` declares that file instead. It gets the same paths and a `bun.lock` output next to it, because the executor writes the text lockfile once the workspace switches to it. The root `package.json` is added to the `inputs` the target actually uses: its own `inputs` when it declares them, otherwise the `targetDefaults` entry supplying the array it inherits, and otherwise the target itself with nx's own default spelled out first, so nothing that was hashed stops being hashed. Targets on another package manager's lockfile are left alone, as are paths and inputs already present. Placement follows the same rules as the pnpm migration in Nx 23.2 (`update-23-2-0-add-pnpm-prune-lockfile-cache-config`).
8
+
9
+ #### Sample code changes
10
+
11
+ ##### Before
12
+
13
+ ```json title="apps/app1/project.json"
14
+ {
15
+ "targets": {
16
+ "prune-lockfile": {
17
+ "executor": "@nx/js:prune-lockfile",
18
+ "outputs": [
19
+ "{workspaceRoot}/dist/apps/app1/package.json",
20
+ "{workspaceRoot}/dist/apps/app1/bun.lock"
21
+ ]
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ ##### After
28
+
29
+ ```json title="apps/app1/project.json"
30
+ {
31
+ "targets": {
32
+ "prune-lockfile": {
33
+ "executor": "@nx/js:prune-lockfile",
34
+ "inputs": ["default", "^default", "{workspaceRoot}/package.json"],
35
+ "outputs": [
36
+ "{workspaceRoot}/dist/apps/app1/package.json",
37
+ "{workspaceRoot}/dist/apps/app1/bun.lock",
38
+ "{workspaceRoot}/dist/apps/app1/patches",
39
+ "{workspaceRoot}/dist/apps/app1/local_path_modules"
40
+ ]
41
+ }
42
+ }
43
+ }
44
+ ```
@@ -131,15 +131,35 @@ exports.createNodesV2 = [
131
131
  const packageManager = (0, devkit_1.detectPackageManager)(context.workspaceRoot);
132
132
  const pmc = (0, devkit_1.getPackageManagerCommand)(packageManager);
133
133
  const lockFileName = (0, internal_1.getLockFileName)(packageManager);
134
- const { configFilePaths: validConfigFilePaths, hashes, projectRoots, } = await resolveValidConfigFilesAndHashes(configFilePaths, normalizedOptions, (0, internal_1.hashObject)({ options, isUsingTsSolutionSetup }), context, cache, lockFileName, isUsingTsSolutionSetup);
134
+ // Only the noEmit typecheck target lists its compiler packages as inputs
135
+ const typescriptAliasCandidates = !isUsingTsSolutionSetup && normalizedOptions.typecheck
136
+ ? readRootTypeScriptAliases(context.workspaceRoot)
137
+ : [];
138
+ const lockFile = typescriptAliasCandidates.length
139
+ ? (0, internal_1.readLockFileSnapshot)(context)
140
+ : undefined;
141
+ const { configFilePaths: validConfigFilePaths, hashes, projectRoots, } = await resolveValidConfigFilesAndHashes(configFilePaths, normalizedOptions, (0, internal_1.hashObject)({
142
+ options,
143
+ isUsingTsSolutionSetup,
144
+ typescriptAliasCandidates,
145
+ // Missing when lockfile analysis is off. The per-file hashes read the
146
+ // lockfile separately, so they can't stand in for this read.
147
+ lockFileHash: lockFile?.lockFileHash,
148
+ }), context, cache, lockFileName, isUsingTsSolutionSetup);
135
149
  try {
150
+ const targetsCacheKeys = validConfigFilePaths.map((configFilePath, idx) => `${hashes[idx]}_${configFilePath}`);
151
+ // An input naming a package with no graph node fails the task, and a
152
+ // package manager can leave a declared alias uninstalled. Only targets
153
+ // missing from the cache need the lockfile's nodes.
154
+ const typescriptAliases = lockFile && targetsCacheKeys.some((key) => !targetsCache[key])
155
+ ? typescriptAliasCandidates.filter((name) => lockFile.hasExternalDependency(name))
156
+ : [];
136
157
  return await (0, devkit_1.createNodesFromFiles)((configFilePath, options, context, idx) => {
137
158
  const projectRoot = projectRoots[idx];
138
- const hash = hashes[idx];
139
- const targetsCacheKey = `${hash}_${configFilePath}`;
159
+ const targetsCacheKey = targetsCacheKeys[idx];
140
160
  const absolutePath = (0, node_path_1.join)(context.workspaceRoot, configFilePath);
141
161
  const configContext = getConfigContext(absolutePath, context.workspaceRoot, cache);
142
- targetsCache[targetsCacheKey] ??= buildTscTargets(configContext, options, context, validConfigFilePaths, cache, pmc, isUsingTsSolutionSetup);
162
+ targetsCache[targetsCacheKey] ??= buildTscTargets(configContext, options, context, validConfigFilePaths, cache, pmc, isUsingTsSolutionSetup, typescriptAliases);
143
163
  const { targets } = targetsCache[targetsCacheKey];
144
164
  return {
145
165
  projects: {
@@ -258,7 +278,7 @@ function checkIfConfigFileShouldBeProject(config, cache) {
258
278
  }
259
279
  return true;
260
280
  }
261
- function buildTscTargets(config, options, context, configFiles, cache, pmc, isUsingTsSolutionSetup) {
281
+ function buildTscTargets(config, options, context, configFiles, cache, pmc, isUsingTsSolutionSetup, typescriptAliases) {
262
282
  const targets = {};
263
283
  const namedInputs = (0, internal_1.getNamedInputs)(config.project.root, context);
264
284
  const tsConfig = retrieveTsConfigFromCache(config.absolutePath, context.workspaceRoot, cache);
@@ -281,6 +301,7 @@ function buildTscTargets(config, options, context, configFiles, cache, pmc, isUs
281
301
  pmc,
282
302
  tsConfig: (0, typecheck_target_1.selectTypecheckTsConfig)(siblingFiles.filter((file) => /^tsconfig.*\.json$/.test(file))),
283
303
  compiler,
304
+ typescriptAliases,
284
305
  // Like the framework targets it replaces: `{workspaceRoot}` inputs
285
306
  // would mark the project affected by any root tsconfig change.
286
307
  namedInputs,
@@ -975,6 +996,38 @@ function readTsConfig(tsConfigPath, workspaceRoot, cache) {
975
996
  // to identify the filenames included in the program, which we won't use
976
997
  return ts.parseJsonConfigFileContent(readResult.config, tsSys, (0, node_path_1.dirname)(tsConfigPath));
977
998
  }
999
+ /**
1000
+ * Root package.json dependencies that install `typescript` under another name,
1001
+ * such as `"@typescript/native": "npm:typescript@^7"`. Peer dependencies are
1002
+ * left out. Yarn doesn't install the root's own peers, so a graph node with
1003
+ * that name can come from another dependency.
1004
+ */
1005
+ function readRootTypeScriptAliases(workspaceRoot) {
1006
+ const packageJsonPath = (0, node_path_1.join)(workspaceRoot, 'package.json');
1007
+ if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
1008
+ return [];
1009
+ }
1010
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
1011
+ const catalogManager = (0, internal_1.getCatalogManager)(workspaceRoot);
1012
+ const aliases = new Set();
1013
+ for (const section of [
1014
+ 'dependencies',
1015
+ 'devDependencies',
1016
+ 'optionalDependencies',
1017
+ ]) {
1018
+ for (const [name, specifier] of Object.entries(packageJson[section] ?? {})) {
1019
+ const resolvedSpecifier = catalogManager?.isCatalogReference(specifier)
1020
+ ? catalogManager.resolveCatalogReference(workspaceRoot, name, specifier)
1021
+ : specifier;
1022
+ if (name !== 'typescript' &&
1023
+ resolvedSpecifier &&
1024
+ /^npm:typescript(@|$)/.test(resolvedSpecifier)) {
1025
+ aliases.add(name);
1026
+ }
1027
+ }
1028
+ }
1029
+ return [...aliases].sort();
1030
+ }
978
1031
  function normalizePluginOptions(pluginOptions = {}) {
979
1032
  const defaultCompiler = 'tsc';
980
1033
  const compiler = pluginOptions.compiler ?? defaultCompiler;
@@ -18,6 +18,12 @@ export interface TypecheckTargetOptions {
18
18
  * Defaults to `tsc`.
19
19
  */
20
20
  compiler?: string;
21
+ /**
22
+ * Names that install `typescript` through an npm alias, such as
23
+ * `@typescript/native` for `npm:typescript@^7`. The `tsc` binary can come
24
+ * from any of them, so the default inputs of a `tsc` target include them.
25
+ */
26
+ typescriptAliases?: string[];
21
27
  /**
22
28
  * Name of the typecheck target, for the dependency on referenced projects
23
29
  * in `build` mode. Defaults to `typecheck`.
@@ -19,7 +19,7 @@ function createTypecheckTarget(options) {
19
19
  options: { cwd: options.projectRoot },
20
20
  cache: true,
21
21
  inputs: options.inputs ??
22
- getDefaultTypecheckInputs(options.namedInputs ?? {}, compiler),
22
+ getDefaultTypecheckInputs(options.namedInputs ?? {}, compiler, options.typescriptAliases ?? []),
23
23
  metadata: {
24
24
  technologies: options.technologies ?? ['typescript'],
25
25
  description: 'Runs type-checking for the project.',
@@ -66,21 +66,23 @@ function isShellSafeTsConfigName(name) {
66
66
  function getTsConfigArg(tsConfig) {
67
67
  return !tsConfig || tsConfig === DEFAULT_TSCONFIG ? '' : ` ${tsConfig}`;
68
68
  }
69
- function getDefaultTypecheckInputs(namedInputs, compiler) {
69
+ function getDefaultTypecheckInputs(namedInputs, compiler, typescriptAliases) {
70
70
  return [
71
71
  ...('production' in namedInputs
72
72
  ? ['production', '^production']
73
73
  : ['default', '^default']),
74
- { externalDependencies: getCompilerPackages(compiler) },
74
+ {
75
+ externalDependencies: getCompilerPackages(compiler, typescriptAliases),
76
+ },
75
77
  ];
76
78
  }
77
- function getCompilerPackages(compiler) {
79
+ function getCompilerPackages(compiler, typescriptAliases) {
78
80
  switch (compiler) {
79
81
  case 'tsgo':
80
82
  return ['@typescript/native-preview'];
81
83
  case 'vue-tsc':
82
84
  return ['vue-tsc', 'typescript'];
83
85
  default:
84
- return ['typescript'];
86
+ return ['typescript', ...typescriptAliases];
85
87
  }
86
88
  }
@@ -205,6 +205,12 @@ class JsVersionActions extends release_1.VersionActions {
205
205
  let version = dependenciesToUpdate[targetProject.projectName];
206
206
  if (version !== undefined) {
207
207
  if (catalogManager?.isCatalogReference(currentVersion)) {
208
+ const catalogVersion = catalogManager.resolveCatalogReference(tree, dependencyName, currentVersion);
209
+ if (manifestToUpdate.preserveLocalDependencyProtocols &&
210
+ typeof catalogVersion === 'string' &&
211
+ this.isLocalDependencyProtocol(catalogVersion)) {
212
+ continue;
213
+ }
208
214
  // collect the catalog updates so we can update the catalog definitions later
209
215
  const catalogRef = catalogManager.parseCatalogReference(currentVersion);
210
216
  catalogUpdates.push({