nx 24.1.0-beta.1 → 24.1.0-beta.2

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 (48) hide show
  1. package/dist/src/command-line/release/utils/repository-git-tags.js +3 -3
  2. package/dist/src/command-line/reset/reset.js +51 -2
  3. package/dist/src/daemon/client/daemon-environment.js +15 -0
  4. package/dist/src/devkit-internals.d.ts +3 -3
  5. package/dist/src/devkit-internals.js +6 -3
  6. package/dist/src/generators/utils/glob.js +3 -3
  7. package/dist/src/hasher/hash-task.d.ts +3 -1
  8. package/dist/src/hasher/hash-task.js +3 -2
  9. package/dist/src/native/index.d.ts +0 -4
  10. package/dist/src/native/index.js +13 -0
  11. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  12. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  13. package/dist/src/plugins/js/index.js +24 -9
  14. package/dist/src/plugins/js/lock-file/bun-parser.d.ts +74 -2
  15. package/dist/src/plugins/js/lock-file/bun-parser.js +971 -139
  16. package/dist/src/plugins/js/lock-file/lock-file.d.ts +32 -12
  17. package/dist/src/plugins/js/lock-file/lock-file.js +189 -43
  18. package/dist/src/plugins/js/lock-file/npm-parser.d.ts +1 -0
  19. package/dist/src/plugins/js/lock-file/npm-parser.js +66 -2
  20. package/dist/src/plugins/js/lock-file/pnpm-parser.d.ts +5 -1
  21. package/dist/src/plugins/js/lock-file/pnpm-parser.js +107 -54
  22. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +52 -10
  23. package/dist/src/plugins/js/lock-file/pruned-output.js +132 -66
  24. package/dist/src/plugins/js/lock-file/utils/local-path-hashes.d.ts +27 -0
  25. package/dist/src/plugins/js/lock-file/utils/local-path-hashes.js +155 -0
  26. package/dist/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  27. package/dist/src/plugins/js/lock-file/utils/package-json.js +2 -1
  28. package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -0
  29. package/dist/src/plugins/js/package-json/create-package-json.js +197 -8
  30. package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  31. package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -2
  32. package/dist/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +16 -9
  33. package/dist/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +17 -28
  34. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +47 -1
  35. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +261 -15
  36. package/dist/src/project-graph/error-types.d.ts +2 -2
  37. package/dist/src/project-graph/error-types.js +2 -2
  38. package/dist/src/tasks-runner/init-tasks-runner.js +23 -17
  39. package/dist/src/tasks-runner/task-orchestrator.js +16 -2
  40. package/dist/src/tasks-runner/tasks-schedule.js +1 -1
  41. package/dist/src/tasks-runner/utils.d.ts +2 -1
  42. package/dist/src/tasks-runner/utils.js +2 -1
  43. package/dist/src/utils/find-matching-projects.js +7 -9
  44. package/dist/src/utils/handle-import.js +8 -2
  45. package/dist/src/utils/json.js +5 -0
  46. package/dist/src/utils/package-json.d.ts +7 -0
  47. package/dist/src/utils/package-json.js +9 -0
  48. package/package.json +13 -12
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TargetProjectLocator = void 0;
4
4
  exports.isBuiltinModuleImport = isBuiltinModuleImport;
5
+ const node_fs_1 = require("node:fs");
5
6
  const node_module_1 = require("node:module");
6
7
  const node_path_1 = require("node:path");
7
8
  const semver_1 = require("semver");
@@ -13,11 +14,16 @@ const workspace_root_1 = require("../../../../utils/workspace-root");
13
14
  const packages_1 = require("../../utils/packages");
14
15
  const resolve_relative_to_dir_1 = require("../../utils/resolve-relative-to-dir");
15
16
  const typescript_1 = require("../../utils/typescript");
17
+ function isLinkedProjectTarget(target) {
18
+ return typeof target === 'object' && target !== null;
19
+ }
16
20
  /**
17
21
  * Use a shared cache to avoid repeated npm package resolution work within the TargetProjectLocator.
18
22
  */
19
23
  const defaultNpmResolutionCache = new Map();
20
24
  const defaultPackageJsonResolutionCache = new Map();
25
+ // Locators on the default cache share the local-path resolutions of one record
26
+ let defaultLocalPathNpmResolutionCache;
21
27
  const experimentalNodeModules = new Set(['node:sqlite']);
22
28
  /**
23
29
  * Package root for a file that Node resolved inside `node_modules/<name>/`.
@@ -39,6 +45,9 @@ function installedPackageJsonFromResolvedFile(resolvedFile, packageName) {
39
45
  function isNestedPackageName(manifestName, packageName) {
40
46
  return !!manifestName && manifestName.startsWith(`${packageName}/`);
41
47
  }
48
+ function isInNodeModules(path) {
49
+ return path.startsWith('node_modules/') || path.includes('/node_modules/');
50
+ }
42
51
  // Node's isBuiltin is false for Bun's runtime modules (`bun`, `bun:*`).
43
52
  function isBunModuleImport(importExpr) {
44
53
  return importExpr === 'bun' || importExpr.startsWith('bun:');
@@ -56,15 +65,39 @@ function startsWithConfigDirTemplate(value) {
56
65
  return value.toLowerCase().startsWith(configDirTemplate.toLowerCase());
57
66
  }
58
67
  class TargetProjectLocator {
59
- constructor(nodes, externalNodes = {}, npmResolutionCache = defaultNpmResolutionCache, packageJsonResolutionCache = defaultPackageJsonResolutionCache) {
68
+ constructor(nodes, externalNodes = {}, npmResolutionCache = defaultNpmResolutionCache, packageJsonResolutionCache = defaultPackageJsonResolutionCache,
69
+ // The local-path node each importer installs per package name, keyed by
70
+ // the importer's workspace-relative root ('.' for the workspace root).
71
+ // Without it, a vendored package resolves by version and name.
72
+ installedLocalPathNodes = {}) {
60
73
  this.nodes = nodes;
61
74
  this.externalNodes = externalNodes;
62
75
  this.npmResolutionCache = npmResolutionCache;
63
76
  this.packageJsonResolutionCache = packageJsonResolutionCache;
77
+ this.installedLocalPathNodes = installedLocalPathNodes;
64
78
  this.projectRootMappings = (0, find_project_for_path_1.createProjectRootMappings)(this.nodes);
79
+ this.packageNamesWithLocalPathNodes = new Set();
80
+ // Resolutions of packageNamesWithLocalPathNodes depend on this locator's
81
+ // installedLocalPathNodes, so they stay out of the shared cache
82
+ this.localPathNpmResolutionCache = new Map();
65
83
  this.tsConfig = this.getRootTsConfig();
66
84
  this.paths = this.tsConfig.config?.compilerOptions?.paths;
67
85
  this.typescriptResolutionCache = new Map();
86
+ this.linkedProjectCache = new Map();
87
+ for (const installed of Object.values(this.installedLocalPathNodes)) {
88
+ for (const packageName of Object.keys(installed)) {
89
+ this.packageNamesWithLocalPathNodes.add(packageName);
90
+ }
91
+ }
92
+ if (this.packageNamesWithLocalPathNodes.size &&
93
+ this.npmResolutionCache === defaultNpmResolutionCache) {
94
+ const recordKey = JSON.stringify(this.installedLocalPathNodes);
95
+ if (defaultLocalPathNpmResolutionCache?.recordKey !== recordKey) {
96
+ defaultLocalPathNpmResolutionCache = { recordKey, cache: new Map() };
97
+ }
98
+ this.localPathNpmResolutionCache =
99
+ defaultLocalPathNpmResolutionCache.cache;
100
+ }
68
101
  /**
69
102
  * Only the npm external nodes should be included.
70
103
  *
@@ -96,6 +129,22 @@ class TargetProjectLocator {
96
129
  * @param filePath
97
130
  */
98
131
  findProjectFromImport(importExpr, filePath) {
132
+ const target = this.resolveImportTarget(importExpr, filePath);
133
+ return isLinkedProjectTarget(target) ? target.project : target;
134
+ }
135
+ /**
136
+ * The targets of an import's dependencies: the one `findProjectFromImport`
137
+ * returns, plus the external node of the `link:` package that resolved the
138
+ * import to that project.
139
+ */
140
+ findDependencyTargetsFromImport(importExpr, filePath) {
141
+ const target = this.resolveImportTarget(importExpr, filePath);
142
+ if (isLinkedProjectTarget(target)) {
143
+ return [target.project, target.externalNode];
144
+ }
145
+ return target ? [target] : [];
146
+ }
147
+ resolveImportTarget(importExpr, filePath) {
99
148
  if ((0, fileutils_1.isRelativePath)(importExpr)) {
100
149
  const resolvedModule = node_path_1.posix.join((0, node_path_1.dirname)(filePath), importExpr);
101
150
  return this.findProjectOfResolvedModule(resolvedModule);
@@ -124,7 +173,10 @@ class TargetProjectLocator {
124
173
  // try to find npm package before using expensive typescript resolution
125
174
  const externalProject = this.findNpmProjectFromImport(importExpr, filePath);
126
175
  if (externalProject) {
127
- return externalProject;
176
+ const project = this.findLinkedProject(externalProject, importExpr, filePath);
177
+ return project
178
+ ? { project, externalNode: externalProject }
179
+ : externalProject;
128
180
  }
129
181
  if (this.tsConfig.config) {
130
182
  // TODO: this can be removed once we rework resolveImportWithRequire below
@@ -150,7 +202,7 @@ class TargetProjectLocator {
150
202
  const dirPath = (0, node_path_1.dirname)(filePath.startsWith(workspace_root_1.workspaceRoot)
151
203
  ? filePath.replace(workspace_root_1.workspaceRoot, '')
152
204
  : filePath);
153
- this.npmResolutionCache.set(`${packageName}__${dirPath}`, null);
205
+ this.getNpmResolutionCache(packageName).set(`${packageName}__${dirPath}`, null);
154
206
  return null;
155
207
  }
156
208
  /**
@@ -173,34 +225,54 @@ class TargetProjectLocator {
173
225
  const fullDirPath = (0, node_path_1.dirname)(fullFilePath);
174
226
  const workspaceRelativeDirPath = (0, node_path_1.dirname)(workspaceRelativeFilePath);
175
227
  const npmImportForProject = `${packageName}__${workspaceRelativeDirPath}`;
176
- if (this.npmResolutionCache.has(npmImportForProject)) {
177
- return this.npmResolutionCache.get(npmImportForProject);
228
+ const npmResolutionCache = this.getNpmResolutionCache(packageName);
229
+ if (npmResolutionCache.has(npmImportForProject)) {
230
+ return npmResolutionCache.get(npmImportForProject);
178
231
  }
179
232
  try {
180
233
  // package.json refers to an external package, we do not match against the version found in there, we instead try and resolve the relevant package how node would
181
234
  const externalPackageJson = this.readPackageJson(packageName, fullDirPath);
182
235
  // The external package.json path might be not be resolvable, e.g. if a reference has been added to a project package.json, but the install command has not been run yet.
183
236
  if (!externalPackageJson) {
237
+ // A local package whose target is missing, such as a `link:` to
238
+ // output that isn't built yet, keeps the node the lockfile records
239
+ const installedNodeName = this.packageNamesWithLocalPathNodes.has(packageName)
240
+ ? this.findUnreadableLocalPathNpmProjectFromDir(packageName, fullDirPath)
241
+ : null;
184
242
  // Try and fall back to resolving an external node from the graph by name
185
243
  const externalNode = this.npmProjects[`npm:${packageName}`];
186
- const externalNodeName = externalNode?.name || null;
187
- this.npmResolutionCache.set(npmImportForProject, externalNodeName);
244
+ const externalNodeName = installedNodeName ?? (externalNode?.name || null);
245
+ npmResolutionCache.set(npmImportForProject, externalNodeName);
188
246
  return externalNodeName;
189
247
  }
190
248
  const version = (0, semver_1.clean)(externalPackageJson.version);
191
249
  const isAliasImport = packageName !== externalPackageJson.name;
192
250
  let matchingExternalNode = null;
193
251
  if (isAliasImport) {
252
+ // A local package installed under another name gets the node the
253
+ // lockfile records for that name
254
+ const installedNodeName = this.packageNamesWithLocalPathNodes.has(packageName)
255
+ ? this.findInstalledLocalPathNpmProjectFromDir(packageName, fullDirPath)
256
+ : null;
194
257
  // Prefer the alias node when both the alias import and the resolved package
195
258
  // exist in the graph, otherwise generated package.json files lose the alias key.
196
259
  const aliasNpmProjectKey = `npm:${packageName}@npm:${externalPackageJson.name}@${version}`;
197
- matchingExternalNode =
198
- this.npmProjects[aliasNpmProjectKey] ??
199
- this.npmProjects[`npm:${packageName}`];
260
+ matchingExternalNode = installedNodeName
261
+ ? this.npmProjects[installedNodeName]
262
+ : (this.npmProjects[aliasNpmProjectKey] ??
263
+ this.npmProjects[`npm:${packageName}`]);
200
264
  }
201
265
  if (!matchingExternalNode) {
202
- matchingExternalNode =
203
- this.npmProjects[`npm:${externalPackageJson.name}@${version}`];
266
+ const versionedNode = this.npmProjects[`npm:${externalPackageJson.name}@${version}`];
267
+ // A vendored copy can share its name and version with a registry
268
+ // package, so the lockfile's record of what was installed decides
269
+ const installedNodeName = this.packageNamesWithLocalPathNodes.has(packageName) &&
270
+ (!versionedNode || this.hasSeveralNodes(externalPackageJson.name))
271
+ ? this.findInstalledLocalPathNpmProjectFromDir(packageName, fullDirPath)
272
+ : null;
273
+ matchingExternalNode = installedNodeName
274
+ ? this.npmProjects[installedNodeName]
275
+ : versionedNode;
204
276
  }
205
277
  if (!matchingExternalNode) {
206
278
  // Fallback to package name as key. This can happen if the version in project graph is not the same as in the resolved package.json.
@@ -211,7 +283,7 @@ class TargetProjectLocator {
211
283
  if (!matchingExternalNode) {
212
284
  return null;
213
285
  }
214
- this.npmResolutionCache.set(npmImportForProject, matchingExternalNode.name);
286
+ npmResolutionCache.set(npmImportForProject, matchingExternalNode.name);
215
287
  return matchingExternalNode.name;
216
288
  }
217
289
  catch (e) {
@@ -221,6 +293,144 @@ class TargetProjectLocator {
221
293
  return null;
222
294
  }
223
295
  }
296
+ /**
297
+ * The external node of the local package that the importer at
298
+ * `importerRoot` installs for `packageName`, as the lockfile records it. An
299
+ * override can replace the copy a `file:` or `link:` spec names, so the spec
300
+ * alone does not tell.
301
+ *
302
+ * @param importerRoot the importer's workspace-relative root, '.' for the
303
+ * workspace root
304
+ */
305
+ findInstalledLocalPathNpmProject(packageName, importerRoot) {
306
+ const nodeName = this.installedLocalPathNodes[importerRoot]?.[packageName];
307
+ return (nodeName && this.npmProjects[nodeName]?.name) ?? null;
308
+ }
309
+ /**
310
+ * The external node of the local package behind the copy an import resolves
311
+ * to: the record of the nearest importer up to the workspace root, unless a
312
+ * directory on the way has its own copy, which the import loads instead.
313
+ */
314
+ findInstalledLocalPathNpmProjectFromDir(packageName, fromDirPath) {
315
+ for (let dir = fromDirPath;; dir = (0, node_path_1.dirname)(dir)) {
316
+ const relativeDir = (0, node_path_1.relative)(workspace_root_1.workspaceRoot, dir);
317
+ if (relativeDir && !(0, path_1.isContainedRelativePath)(relativeDir)) {
318
+ return null;
319
+ }
320
+ const installed = this.findInstalledLocalPathNpmProject(packageName, relativeDir ? (0, path_1.normalizePath)(relativeDir) : '.');
321
+ if (installed) {
322
+ return installed;
323
+ }
324
+ if (!relativeDir ||
325
+ (0, node_fs_1.existsSync)((0, node_path_1.join)(dir, 'node_modules', packageName, 'package.json'))) {
326
+ return null;
327
+ }
328
+ }
329
+ }
330
+ /**
331
+ * The node an unreadable import gets once its package can be read: the
332
+ * record of the nearest importer up to the directory that installs the
333
+ * package. Null when no directory installs it.
334
+ */
335
+ findUnreadableLocalPathNpmProjectFromDir(packageName, fromDirPath) {
336
+ let installed = null;
337
+ for (let dir = fromDirPath;; dir = (0, node_path_1.dirname)(dir)) {
338
+ const relativeDir = (0, node_path_1.relative)(workspace_root_1.workspaceRoot, dir);
339
+ if (relativeDir && !(0, path_1.isContainedRelativePath)(relativeDir)) {
340
+ return null;
341
+ }
342
+ installed ??= this.findInstalledLocalPathNpmProject(packageName, relativeDir ? (0, path_1.normalizePath)(relativeDir) : '.');
343
+ if (hasEntry((0, node_path_1.join)(dir, 'node_modules', packageName))) {
344
+ return installed;
345
+ }
346
+ if (!relativeDir) {
347
+ return null;
348
+ }
349
+ }
350
+ }
351
+ /**
352
+ * The project that holds the target of the importer's installed `link:`
353
+ * package.
354
+ * pnpm and Bun give such a link an external node, which would otherwise
355
+ * shadow the project. Importers can share that node with different targets,
356
+ * so the link the importer installs decides.
357
+ */
358
+ findLinkedProject(externalNodeName, importExpr, fromFilePath) {
359
+ const version = this.npmProjects[externalNodeName]?.data.version;
360
+ if (typeof version !== 'string' || !version.startsWith('link:')) {
361
+ return null;
362
+ }
363
+ const packageName = (0, get_package_name_from_import_path_1.getPackageNameFromImportPath)(importExpr);
364
+ const fullDirPath = (0, node_path_1.dirname)(fromFilePath.startsWith(workspace_root_1.workspaceRoot)
365
+ ? fromFilePath
366
+ : (0, node_path_1.join)(workspace_root_1.workspaceRoot, fromFilePath));
367
+ const cacheKey = `${packageName}__${fullDirPath}`;
368
+ if (!this.linkedProjectCache.has(cacheKey)) {
369
+ this.linkedProjectCache.set(cacheKey, this.findLinkedProjectFromDir(packageName, fullDirPath));
370
+ }
371
+ return this.linkedProjectCache.get(cacheKey);
372
+ }
373
+ // Node loads the nearest node_modules copy, so that one decides. A link
374
+ // whose target isn't built yet decides only when no copy is installed above
375
+ // it, so the edge doesn't depend on whether the target was built.
376
+ findLinkedProjectFromDir(packageName, fromDirPath) {
377
+ let unbuiltTarget;
378
+ for (let dir = fromDirPath;; dir = (0, node_path_1.dirname)(dir)) {
379
+ const relativeDir = (0, node_path_1.relative)(workspace_root_1.workspaceRoot, dir);
380
+ if (relativeDir && !(0, path_1.isContainedRelativePath)(relativeDir)) {
381
+ break;
382
+ }
383
+ const installedPath = (0, node_path_1.join)(dir, 'node_modules', packageName);
384
+ if ((0, node_fs_1.existsSync)(installedPath)) {
385
+ let target;
386
+ try {
387
+ target = (0, node_fs_1.realpathSync)(installedPath);
388
+ }
389
+ catch {
390
+ return null;
391
+ }
392
+ return this.findProjectHoldingLinkTarget(target);
393
+ }
394
+ unbuiltTarget ??= resolveDanglingLink(installedPath);
395
+ if (!relativeDir) {
396
+ break;
397
+ }
398
+ }
399
+ return unbuiltTarget
400
+ ? this.findProjectHoldingLinkTarget(unbuiltTarget)
401
+ : null;
402
+ }
403
+ findProjectHoldingLinkTarget(target) {
404
+ const path = (0, path_1.normalizePath)((0, node_path_1.relative)(workspace_root_1.workspaceRoot, target));
405
+ if (isInNodeModules(path)) {
406
+ return null;
407
+ }
408
+ const project = (0, find_project_for_path_1.findProjectForPath)(path, this.projectRootMappings);
409
+ // A root project holds every path, so it doesn't claim a link
410
+ return project && this.nodes[project].data.root !== '.' ? project : null;
411
+ }
412
+ getNpmResolutionCache(packageName) {
413
+ return this.packageNamesWithLocalPathNodes.has(packageName)
414
+ ? this.localPathNpmResolutionCache
415
+ : this.npmResolutionCache;
416
+ }
417
+ // Built on first use, since only names with a local-path node need it
418
+ hasSeveralNodes(packageName) {
419
+ if (!this.packageNamesWithSeveralNodes) {
420
+ this.packageNamesWithSeveralNodes = new Set();
421
+ const seenPackageNames = new Set();
422
+ for (const node of Object.values(this.externalNodes)) {
423
+ if (node.type !== 'npm') {
424
+ continue;
425
+ }
426
+ if (seenPackageNames.has(node.data.packageName)) {
427
+ this.packageNamesWithSeveralNodes.add(node.data.packageName);
428
+ }
429
+ seenPackageNames.add(node.data.packageName);
430
+ }
431
+ }
432
+ return this.packageNamesWithSeveralNodes.has(packageName);
433
+ }
224
434
  /**
225
435
  * Return file paths matching the import relative to the repo root
226
436
  * @param normalizedImportExpr
@@ -374,8 +584,7 @@ class TargetProjectLocator {
374
584
  }
375
585
  findProjectOfResolvedModule(resolvedModule) {
376
586
  resolvedModule = (0, path_1.normalizePath)(resolvedModule);
377
- if (resolvedModule.startsWith('node_modules/') ||
378
- resolvedModule.includes('/node_modules/')) {
587
+ if (isInNodeModules(resolvedModule)) {
379
588
  return undefined;
380
589
  }
381
590
  let normalizedResolvedModule = resolvedModule.startsWith('./')
@@ -534,3 +743,40 @@ class TargetProjectLocator {
534
743
  }
535
744
  }
536
745
  exports.TargetProjectLocator = TargetProjectLocator;
746
+ // A link counts even when its target is missing
747
+ function hasEntry(path) {
748
+ try {
749
+ return (0, node_fs_1.lstatSync)(path, { throwIfNoEntry: false }) !== undefined;
750
+ }
751
+ catch {
752
+ return false;
753
+ }
754
+ }
755
+ // Where a chain of links ends when its last target doesn't exist, in the
756
+ // canonical form `realpathSync` gives once it does
757
+ function resolveDanglingLink(path) {
758
+ try {
759
+ if (!(0, node_fs_1.lstatSync)(path, { throwIfNoEntry: false })?.isSymbolicLink()) {
760
+ return undefined;
761
+ }
762
+ let link = path;
763
+ let target = path;
764
+ for (let hops = 0; hops < 40; hops++) {
765
+ target = (0, node_path_1.join)((0, node_path_1.resolve)((0, node_fs_1.realpathSync)((0, node_path_1.dirname)(link)), (0, node_fs_1.readlinkSync)(link)), (0, node_path_1.relative)(link, target));
766
+ // The target can be missing because a link above it dangles
767
+ link = target;
768
+ while (!(0, node_fs_1.lstatSync)(link, { throwIfNoEntry: false })?.isSymbolicLink()) {
769
+ if ((0, node_fs_1.existsSync)(link)) {
770
+ return (0, node_path_1.join)((0, node_fs_1.realpathSync)(link), (0, node_path_1.relative)(link, target));
771
+ }
772
+ // A missing Windows drive or share is its own parent
773
+ if ((0, node_path_1.dirname)(link) === link) {
774
+ return undefined;
775
+ }
776
+ link = (0, node_path_1.dirname)(link);
777
+ }
778
+ }
779
+ }
780
+ catch { }
781
+ return undefined;
782
+ }
@@ -72,14 +72,14 @@ export declare function formatProjectGraphError(error: ProjectGraphError | Proje
72
72
  };
73
73
  /**
74
74
  * This error should be thrown when a `createNodesV2` function hits a recoverable error.
75
- * It allows Nx to recieve partial results and continue processing for better UX.
75
+ * It allows Nx to receive partial results and continue processing for better UX.
76
76
  */
77
77
  export declare class AggregateCreateNodesError extends Error {
78
78
  readonly errors: Array<[file: string | null, error: Error]>;
79
79
  readonly partialResults: Awaited<ReturnType<CreateNodesFunction>>;
80
80
  pluginIndex: number | undefined;
81
81
  /**
82
- * Throwing this error from a `createNodesV2` function will allow Nx to continue processing and recieve partial results from your plugin.
82
+ * Throwing this error from a `createNodesV2` function will allow Nx to continue processing and receive partial results from your plugin.
83
83
  * @example
84
84
  * export async function createNodesV2(
85
85
  * files: string[],
@@ -247,11 +247,11 @@ function formatProjectGraphError(error, isVerbose) {
247
247
  }
248
248
  /**
249
249
  * This error should be thrown when a `createNodesV2` function hits a recoverable error.
250
- * It allows Nx to recieve partial results and continue processing for better UX.
250
+ * It allows Nx to receive partial results and continue processing for better UX.
251
251
  */
252
252
  class AggregateCreateNodesError extends Error {
253
253
  /**
254
- * Throwing this error from a `createNodesV2` function will allow Nx to continue processing and recieve partial results from your plugin.
254
+ * Throwing this error from a `createNodesV2` function will allow Nx to continue processing and receive partial results from your plugin.
255
255
  * @example
256
256
  * export async function createNodesV2(
257
257
  * files: string[],
@@ -8,10 +8,12 @@ const dotenv_1 = require("../utils/dotenv");
8
8
  const life_cycle_1 = require("./life-cycle");
9
9
  const task_orchestrator_1 = require("./task-orchestrator");
10
10
  const create_task_hasher_1 = require("../hasher/create-task-hasher");
11
+ const hash_task_1 = require("../hasher/hash-task");
11
12
  const client_1 = require("../daemon/client/client");
12
13
  const shared_running_task_1 = require("./running-tasks/shared-running-task");
13
14
  const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
14
- function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations) {
15
+ const utils_1 = require("./utils");
16
+ async function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations) {
15
17
  (0, dotenv_1.loadRootEnvFiles)();
16
18
  fullTaskGraph = withEdgeObjects(fullTaskGraph);
17
19
  const invokeRunnerTerminalLifecycle = new invoke_runner_terminal_output_life_cycle_1.InvokeRunnerTerminalOutputLifeCycle(tasks);
@@ -22,20 +24,15 @@ function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycl
22
24
  lifeCycle,
23
25
  ]);
24
26
  const { runnerOptions: options } = (0, run_command_1.getRunner)({}, nxJson);
27
+ // A dependency outside the call has already run, or is running if continuous,
28
+ // so the call's task graph keeps only the edges between its own tasks.
29
+ const { roots, dependencies, continuousDependencies } = (0, utils_1.pruneToSelectedTasks)(fullTaskGraph, tasks.map((task) => task.id));
25
30
  const taskGraph = {
26
- roots: tasks.map((task) => task.id),
27
- tasks: tasks.reduce((acc, task) => {
28
- acc[task.id] = task;
29
- return acc;
30
- }, {}),
31
- dependencies: tasks.reduce((acc, task) => {
32
- acc[task.id] = [];
33
- return acc;
34
- }, {}),
35
- continuousDependencies: tasks.reduce((acc, task) => {
36
- acc[task.id] = [];
37
- return acc;
38
- }, {}),
31
+ roots,
32
+ // The caller's own tasks: it reads each hash off the task it passed in
33
+ tasks: Object.fromEntries(tasks.map((task) => [task.id, task])),
34
+ dependencies,
35
+ continuousDependencies,
39
36
  };
40
37
  const hasher = (0, create_task_hasher_1.createTaskHasher)(projectGraph, nxJson, options, ultracacheConfigurations);
41
38
  const nxArgs = {
@@ -43,12 +40,19 @@ function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycl
43
40
  parallel: tasks.length,
44
41
  lifeCycle: compositedLifeCycle,
45
42
  };
43
+ // Before hashing: task envs load .env files only once NX_LOAD_DOT_ENV_FILES is set
46
44
  (0, run_command_1.setEnvVarsBasedOnArgs)(nxArgs, true);
45
+ // A task that reads the outputs of a task in the same call hashes after that
46
+ // task has run. Tasks that do not depend on each other hash as before.
47
+ const tasksDependOnEachOther = Object.values(dependencies).some((edges) => edges.length > 0);
48
+ const hashingDeferredTaskIds = tasksDependOnEachOther
49
+ ? await (0, hash_task_1.hashTasksThatDoNotDependOnOutputsOfOtherTasks)(hasher, projectGraph, fullTaskGraph, nxJson, (0, hash_task_1.getTaskDetails)(), ultracacheConfigurations, tasks)
50
+ : undefined;
47
51
  return new task_orchestrator_1.TaskOrchestrator(hasher, null, tasks, projectGraph, taskGraph, nxJson, nxArgs, false, client_1.daemonClient,
48
52
  // No argv on this path, so the output-style middleware never ran and both
49
53
  // fields are unset - this always renders `static-failures-only`. `nx.json`'s
50
54
  // `outputStyle` does not reach them; it merges under its own name.
51
- nxArgs.specifiedOutputStyle, nxArgs.resolvedOutputStyle ?? 'static-failures-only', fullTaskGraph);
55
+ nxArgs.specifiedOutputStyle, nxArgs.resolvedOutputStyle ?? 'static-failures-only', fullTaskGraph, hashingDeferredTaskIds);
52
56
  }
53
57
  // A client bundle built before edges became objects hands plain task ids
54
58
  function withEdgeObjects(taskGraph) {
@@ -87,7 +91,9 @@ function reserveProcessListeners(tasks) {
87
91
  async function runDiscreteTasks(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle,
88
92
  /** The set to hash from, e.g. from `importUltracacheConfigurations`; omitted hashes natively. */
89
93
  ultracacheConfigurations) {
90
- const orchestrator = createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
94
+ // Only a batch runs its tasks in dependency order. A task outside a batch
95
+ // starts now, so callers pass dependent tasks only when they batch together.
96
+ const orchestrator = await createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
91
97
  const releaseProcessListeners = reserveProcessListeners(tasks);
92
98
  const batchResults = [];
93
99
  try {
@@ -144,7 +150,7 @@ ultracacheConfigurations) {
144
150
  async function runContinuousTasks(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle,
145
151
  /** The set to hash from, e.g. from `importUltracacheConfigurations`; omitted hashes natively. */
146
152
  ultracacheConfigurations) {
147
- const orchestrator = createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
153
+ const orchestrator = await createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
148
154
  const releaseProcessListeners = reserveProcessListeners(tasks);
149
155
  try {
150
156
  await orchestrator.init();
@@ -728,6 +728,20 @@ class TaskOrchestrator {
728
728
  this.forkedProcessTaskRunner.cleanUpBatchProcesses();
729
729
  taskGraph = (0, utils_1.removeTasksFromTaskGraph)(taskGraph, Object.keys(taskGraph.tasks).filter((id) => this.completedTasks.has(id)));
730
730
  }
731
+ // A member skipped outside a wave's run (a dependency failed) gets no result
732
+ // from it; agents expect one per task, as runTaskDirectly returns.
733
+ const returned = new Set(results.map((result) => result.task.id));
734
+ for (const taskId of taskIds) {
735
+ if (!returned.has(taskId) &&
736
+ this.completedTasks.get(taskId) === 'skipped') {
737
+ results.push({
738
+ task: batch.taskGraph.tasks[taskId],
739
+ code: 1,
740
+ status: 'skipped',
741
+ terminalOutput: '',
742
+ });
743
+ }
744
+ }
731
745
  // Once, after every wave: an earlier status would end the batch in the TUI.
732
746
  const hasFailures = taskIds.some((taskId) => {
733
747
  const status = this.completedTasks.get(taskId);
@@ -1630,7 +1644,7 @@ class TaskOrchestrator {
1630
1644
  continue;
1631
1645
  }
1632
1646
  // A producer in this task graph is held by dispatch and settled by its
1633
- // probe or row poll; one outside it (an agent's flat graph) has only its row
1647
+ // probe or row poll; one outside it (on an agent, another call's) has only its row
1634
1648
  if (this.taskGraph.tasks[producerId]) {
1635
1649
  await this.readinessOf(producerId).promise;
1636
1650
  }
@@ -1749,7 +1763,7 @@ class TaskOrchestrator {
1749
1763
  }
1750
1764
  state.reject(e);
1751
1765
  }
1752
- // On an agent the waiter runs in another process with its own flat graph
1766
+ // On an agent the waiter may run in another process, outside this task graph
1753
1767
  hasReadyWaiter(producerId) {
1754
1768
  return Object.values(this.fullTaskGraph.tasks).some((task) => (0, ready_when_1.getReadyProducerIds)(task, this.fullTaskGraph).includes(producerId));
1755
1769
  }
@@ -26,7 +26,7 @@ class TasksSchedule {
26
26
  this.pendingStart = new Set();
27
27
  this.completedTasks = new Set();
28
28
  this.readiness = new Map();
29
- // Read from the full graph: an agent worker's own graph has no edges
29
+ // Read from the full graph: an agent's own graph lacks edges outside its call
30
30
  this.probedProducers = (0, ready_when_1.getReadyDependencies)(this.fullTaskGraph, this.projectGraph);
31
31
  this.scheduleRequestsExecutionChain = Promise.resolve();
32
32
  this.estimatedTaskTimings = {};
@@ -64,7 +64,8 @@ export declare function getCustomHasher(task: Task, projects: Record<string, Pro
64
64
  /** Test-only: forget which executors have been warned about. */
65
65
  export declare function resetCustomHasherDeprecationWarnings(): void;
66
66
  /**
67
- * `taskGraph` pruned to `required`, which must already hold its dependencies.
67
+ * `taskGraph` pruned to `required`. Edges to tasks outside it are dropped, so
68
+ * `required` must hold its dependencies unless they have already run.
68
69
  * Unknown ids are ignored: a sync generator can remove a task after selection.
69
70
  */
70
71
  export declare function pruneToSelectedTasks(taskGraph: TaskGraph, required: Iterable<string>): TaskGraph;
@@ -397,7 +397,8 @@ function resetCustomHasherDeprecationWarnings() {
397
397
  customHasherDeprecationWarned.clear();
398
398
  }
399
399
  /**
400
- * `taskGraph` pruned to `required`, which must already hold its dependencies.
400
+ * `taskGraph` pruned to `required`. Edges to tasks outside it are dropped, so
401
+ * `required` must hold its dependencies unless they have already run.
401
402
  * Unknown ids are ignored: a sync generator can remove a task after selection.
402
403
  */
403
404
  function pruneToSelectedTasks(taskGraph, required) {
@@ -197,26 +197,24 @@ function isValidPatternType(type) {
197
197
  exports.getMatchingStringsWithCache = (() => {
198
198
  // Map< Pattern, Map< Item, Result >>
199
199
  const minimatchCache = new Map();
200
- const regexCache = new Map();
200
+ const matcherCache = new Map();
201
201
  return (pattern, items) => {
202
202
  if (!minimatchCache.has(pattern)) {
203
203
  minimatchCache.set(pattern, new Map());
204
204
  }
205
205
  const patternCache = minimatchCache.get(pattern);
206
- if (!regexCache.has(pattern)) {
207
- const regex = minimatch_1.minimatch.makeRe(pattern, { dot: true });
208
- if (regex) {
209
- regexCache.set(pattern, regex);
210
- }
211
- else {
206
+ if (!matcherCache.has(pattern)) {
207
+ const matcher = new minimatch_1.Minimatch(pattern, { dot: true });
208
+ if (matcher.set.length === 0) {
212
209
  throw new Error('Invalid glob pattern ' + pattern);
213
210
  }
211
+ matcherCache.set(pattern, matcher);
214
212
  }
215
- const matcher = regexCache.get(pattern);
213
+ const matcher = matcherCache.get(pattern);
216
214
  return items.filter((item) => {
217
215
  let entry = patternCache.get(item);
218
216
  if (entry === undefined || entry === null) {
219
- entry = item === pattern ? true : matcher.test(item);
217
+ entry = item === pattern ? true : matcher.match(item);
220
218
  patternCache.set(item, entry);
221
219
  }
222
220
  return entry;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleImport = handleImport;
4
4
  const path_1 = require("path");
5
5
  const node_module_1 = require("node:module");
6
+ const url_1 = require("url");
6
7
  // Node passes a stand-in require, without a cache, require.extensions or
7
8
  // Module._load, when an ESM loader hook supplies this module's source, as
8
9
  // Yarn PnP does.
@@ -40,7 +41,7 @@ async function handleImport(modulePath, relativeTo) {
40
41
  // the import() path, so this recovers TLA plugin entry points without
41
42
  // requiring swc-node or ts-node to be installed.
42
43
  if (e.code === 'ERR_REQUIRE_ESM' || e.code === 'ERR_REQUIRE_ASYNC_MODULE') {
43
- return import(resolvedPath);
44
+ return dynamicImport(resolvedPath);
44
45
  }
45
46
  // Mirror `loadTsFile`'s fallback set (register.ts). Plugin loads hit a
46
47
  // wider failure surface than .ts config loads because plugin sources are
@@ -76,7 +77,7 @@ async function handleImport(modulePath, relativeTo) {
76
77
  // loading.
77
78
  if (retryErr?.code === 'ERR_REQUIRE_ESM' ||
78
79
  retryErr?.code === 'ERR_REQUIRE_ASYNC_MODULE') {
79
- return import(resolvedPath);
80
+ return dynamicImport(resolvedPath);
80
81
  }
81
82
  if (retryErr instanceof Error) {
82
83
  // Lazy-require NX_PREFIX so we don't pull logger -> daemon into
@@ -90,3 +91,8 @@ async function handleImport(modulePath, relativeTo) {
90
91
  throw e;
91
92
  }
92
93
  }
94
+ // import() parses a path as a URL (a drive letter reads as a scheme, `#` as a
95
+ // fragment), so absolute paths go through a file URL. Package names stay bare.
96
+ function dynamicImport(resolvedPath) {
97
+ return import((0, path_1.isAbsolute)(resolvedPath) ? (0, url_1.pathToFileURL)(resolvedPath).href : resolvedPath);
98
+ }
@@ -17,6 +17,11 @@ const code_frames_1 = require("./code-frames");
17
17
  * @returns Object the JSON content represents
18
18
  */
19
19
  function parseJson(input, options) {
20
+ // npm and Node's require() strip a UTF-8 BOM from JSON files; JSON.parse and
21
+ // jsonc-parser both reject it.
22
+ if (typeof input === 'string' && input.charCodeAt(0) === 0xfeff) {
23
+ input = input.slice(1);
24
+ }
20
25
  try {
21
26
  if (options?.expectComments !== true) {
22
27
  return JSON.parse(input);