nx 23.3.0-beta.5 → 23.3.0-beta.7

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 (112) hide show
  1. package/dist/nx-cloud-internals.d.ts +1 -0
  2. package/dist/nx-cloud-internals.js +9 -0
  3. package/dist/src/command-line/affected/affected.js +51 -9
  4. package/dist/src/command-line/graph/graph.d.ts +31 -0
  5. package/dist/src/command-line/graph/graph.js +71 -17
  6. package/dist/src/command-line/release/publish.js +7 -11
  7. package/dist/src/command-line/release/utils/get-touched-projects-for-group.js +3 -3
  8. package/dist/src/command-line/run/run-one.js +5 -1
  9. package/dist/src/command-line/run-many/run-many.js +6 -12
  10. package/dist/src/command-line/show/projects.js +30 -1
  11. package/dist/src/config/task-graph.d.ts +1 -1
  12. package/dist/src/config/workspace-json-project-json.d.ts +21 -1
  13. package/dist/src/core/graph/main.js +1 -1
  14. package/dist/src/core/graph/runtime.js +1 -1
  15. package/dist/src/core/graph/styles.js +1 -1
  16. package/dist/src/daemon/client/client.d.ts +7 -2
  17. package/dist/src/daemon/client/client.js +15 -2
  18. package/dist/src/daemon/message-types/io-snapshot-version.d.ts +5 -0
  19. package/dist/src/daemon/message-types/io-snapshot-version.js +2 -0
  20. package/dist/src/daemon/message-types/select-affected-tasks.d.ts +18 -0
  21. package/dist/src/daemon/message-types/select-affected-tasks.js +11 -0
  22. package/dist/src/daemon/server/handle-hash-tasks.d.ts +2 -0
  23. package/dist/src/daemon/server/handle-hash-tasks.js +5 -3
  24. package/dist/src/daemon/server/handle-select-affected-tasks.d.ts +3 -0
  25. package/dist/src/daemon/server/handle-select-affected-tasks.js +23 -0
  26. package/dist/src/daemon/server/io-snapshots-state.d.ts +7 -0
  27. package/dist/src/daemon/server/io-snapshots-state.js +35 -0
  28. package/dist/src/daemon/server/planning-context.d.ts +8 -0
  29. package/dist/src/daemon/server/planning-context.js +18 -0
  30. package/dist/src/daemon/server/server.d.ts +1 -0
  31. package/dist/src/daemon/server/server.js +6 -0
  32. package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -1
  33. package/dist/src/executors/run-commands/run-commands.impl.js +19 -5
  34. package/dist/src/executors/run-commands/running-tasks.d.ts +5 -4
  35. package/dist/src/executors/run-commands/running-tasks.js +13 -13
  36. package/dist/src/hasher/create-task-hasher.d.ts +8 -1
  37. package/dist/src/hasher/create-task-hasher.js +13 -3
  38. package/dist/src/hasher/hash-plan-inspector.js +2 -2
  39. package/dist/src/hasher/hash-task.d.ts +2 -2
  40. package/dist/src/hasher/hash-task.js +7 -1
  41. package/dist/src/hasher/native-task-hasher-impl.d.ts +13 -5
  42. package/dist/src/hasher/native-task-hasher-impl.js +38 -15
  43. package/dist/src/hasher/task-hasher.d.ts +17 -9
  44. package/dist/src/hasher/task-hasher.js +16 -11
  45. package/dist/src/hasher/task-planning-context.d.ts +13 -0
  46. package/dist/src/hasher/task-planning-context.js +12 -0
  47. package/dist/src/io-snapshots/config.d.ts +23 -0
  48. package/dist/src/io-snapshots/config.js +32 -0
  49. package/dist/src/io-snapshots/fetch.d.ts +21 -0
  50. package/dist/src/io-snapshots/fetch.js +43 -0
  51. package/dist/src/io-snapshots/outputs.d.ts +12 -0
  52. package/dist/src/io-snapshots/outputs.js +33 -0
  53. package/dist/src/io-snapshots/overrides.d.ts +17 -0
  54. package/dist/src/io-snapshots/overrides.js +60 -0
  55. package/dist/src/io-snapshots/report.d.ts +13 -0
  56. package/dist/src/io-snapshots/report.js +68 -0
  57. package/dist/src/io-snapshots/store.d.ts +37 -0
  58. package/dist/src/io-snapshots/store.js +162 -0
  59. package/dist/src/native/index.d.ts +264 -2
  60. package/dist/src/native/native-bindings.js +10 -0
  61. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  62. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  63. package/dist/src/native/transform-objects.d.ts +11 -2
  64. package/dist/src/native/transform-objects.js +46 -0
  65. package/dist/src/nx-cloud/update-manager.d.ts +3 -0
  66. package/dist/src/plugins/js/index.js +45 -64
  67. package/dist/src/plugins/js/lock-file/lock-file.d.ts +4 -4
  68. package/dist/src/plugins/js/lock-file/lock-file.js +6 -7
  69. package/dist/src/plugins/js/project-graph/affected/lock-file-changes.d.ts +10 -2
  70. package/dist/src/plugins/js/project-graph/affected/lock-file-changes.js +51 -29
  71. package/dist/src/plugins/js/project-graph/affected/npm-packages.d.ts +10 -2
  72. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +32 -11
  73. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +14 -0
  74. package/dist/src/project-graph/affected/affected-project-graph.js +5 -18
  75. package/dist/src/project-graph/affected/affected-projects.d.ts +7 -0
  76. package/dist/src/project-graph/affected/affected-projects.js +42 -0
  77. package/dist/src/project-graph/affected/affected-tasks.d.ts +90 -0
  78. package/dist/src/project-graph/affected/affected-tasks.js +214 -0
  79. package/dist/src/project-graph/file-utils.js +6 -2
  80. package/dist/src/project-graph/utils/project-configuration/target-merging.js +67 -0
  81. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +83 -0
  82. package/dist/src/project-graph/utils/project-configuration/utils.d.ts +1 -0
  83. package/dist/src/project-graph/utils/project-configuration/utils.js +1 -0
  84. package/dist/src/tasks-runner/create-task-graph.d.ts +24 -1
  85. package/dist/src/tasks-runner/create-task-graph.js +56 -2
  86. package/dist/src/tasks-runner/forked-process-task-runner.js +3 -3
  87. package/dist/src/tasks-runner/init-tasks-runner.d.ts +7 -2
  88. package/dist/src/tasks-runner/init-tasks-runner.js +17 -6
  89. package/dist/src/tasks-runner/run-command.d.ts +41 -5
  90. package/dist/src/tasks-runner/run-command.js +84 -18
  91. package/dist/src/tasks-runner/task-io-service.d.ts +11 -3
  92. package/dist/src/tasks-runner/task-io-service.js +14 -5
  93. package/dist/src/tasks-runner/task-orchestrator.js +1 -1
  94. package/dist/src/tasks-runner/utils.d.ts +5 -0
  95. package/dist/src/tasks-runner/utils.js +9 -0
  96. package/dist/src/utils/db-connection.d.ts +1 -0
  97. package/dist/src/utils/db-connection.js +1 -0
  98. package/dist/src/utils/json-diff.d.ts +4 -2
  99. package/dist/src/utils/json-diff.js +6 -94
  100. package/dist/src/utils/nx-cloud-utils.d.ts +2 -0
  101. package/dist/src/utils/nx-cloud-utils.js +6 -1
  102. package/dist/src/utils/project-graph-utils.d.ts +2 -0
  103. package/dist/src/utils/project-graph-utils.js +12 -0
  104. package/package.json +22 -13
  105. package/schemas/nx-schema.json +34 -0
  106. package/schemas/project-schema.json +31 -0
  107. package/dist/src/project-graph/affected/locators/project-glob-changes.d.ts +0 -2
  108. package/dist/src/project-graph/affected/locators/project-glob-changes.js +0 -40
  109. package/dist/src/project-graph/affected/locators/workspace-json-changes.d.ts +0 -4
  110. package/dist/src/project-graph/affected/locators/workspace-json-changes.js +0 -47
  111. package/dist/src/project-graph/affected/locators/workspace-projects.d.ts +0 -3
  112. package/dist/src/project-graph/affected/locators/workspace-projects.js +0 -74
@@ -1,7 +1,52 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformProjectGraphForRust = transformProjectGraphForRust;
4
+ exports.transformProjectGraphForLocators = transformProjectGraphForLocators;
5
+ exports.toRustProjectGraph = toRustProjectGraph;
6
+ const index_1 = require("./index");
7
+ /**
8
+ * Keyed by graph identity, but weak so a replaced graph is collectable. A run's
9
+ * hasher reuses what affected's planner already copied.
10
+ */
11
+ const transferred = new WeakMap();
12
+ /** The graph copied into Rust, once per graph. */
4
13
  function transformProjectGraphForRust(graph) {
14
+ let ref = transferred.get(graph);
15
+ if (!ref) {
16
+ ref = (0, index_1.transferProjectGraph)(toRustProjectGraph(graph));
17
+ transferred.set(graph, ref);
18
+ }
19
+ return ref;
20
+ }
21
+ /** Per graph like `transferred`: `nx release` runs the locators once per commit. */
22
+ const transferredForLocators = new WeakMap();
23
+ /**
24
+ * Only what the touched-project locators read: project roots, named inputs and
25
+ * target inputs. Copying target options and every edge costs several times
26
+ * what the locators themselves do on a large workspace.
27
+ */
28
+ function transformProjectGraphForLocators(graph) {
29
+ let ref = transferredForLocators.get(graph);
30
+ if (!ref) {
31
+ const nodes = {};
32
+ for (const [name, node] of Object.entries(graph.nodes)) {
33
+ const targets = {};
34
+ for (const [target, config] of Object.entries(node.data.targets ?? {})) {
35
+ targets[target] = { inputs: config.inputs };
36
+ }
37
+ nodes[name] = {
38
+ root: node.data.root,
39
+ namedInputs: node.data.namedInputs,
40
+ targets,
41
+ };
42
+ }
43
+ ref = (0, index_1.transferProjectGraph)({ nodes, externalNodes: {}, dependencies: {} });
44
+ transferredForLocators.set(graph, ref);
45
+ }
46
+ return ref;
47
+ }
48
+ /** The graph in Rust's shape, still a JS object. Uncached, so safe to edit. */
49
+ function toRustProjectGraph(graph) {
5
50
  const dependencies = {};
6
51
  const nodes = {};
7
52
  const externalNodes = {};
@@ -32,6 +77,7 @@ function transformProjectGraphForRust(graph) {
32
77
  }
33
78
  for (const [projectName, externalNode] of Object.entries(graph.externalNodes ?? {})) {
34
79
  externalNodes[projectName] = {
80
+ type: externalNode.type,
35
81
  packageName: externalNode.data.packageName,
36
82
  hash: externalNode.data.hash,
37
83
  version: externalNode.data.version,
@@ -1,4 +1,5 @@
1
1
  import type { CloudTaskRunnerOptions } from './nx-cloud-tasks-runner-shell';
2
+ import type { ReadIoSnapshotsOptions, ReadIoSnapshotsResult } from '../io-snapshots/fetch';
2
3
  import { TasksRunner } from '../tasks-runner/tasks-runner';
3
4
  import { RemoteCacheV2 } from '../tasks-runner/default-tasks-runner';
4
5
  export declare class NxCloudEnterpriseOutdatedError extends Error {
@@ -12,6 +13,8 @@ export interface NxCloudClient {
12
13
  commands: Record<string, () => Promise<void>>;
13
14
  nxCloudTasksRunner: TasksRunner<CloudTaskRunnerOptions>;
14
15
  getRemoteCache: () => RemoteCacheV2;
16
+ /** Clients that expose I/O snapshots; see `fetchIoSnapshots`. */
17
+ readIoSnapshots?: (options: ReadIoSnapshotsOptions) => Promise<ReadIoSnapshotsResult | null>;
15
18
  }
16
19
  export declare function verifyOrUpdateNxCloudClient(options?: {
17
20
  url?: string;
@@ -18,12 +18,16 @@ const lock_file_1 = require("./lock-file/lock-file");
18
18
  const build_dependencies_1 = require("./project-graph/build-dependencies/build-dependencies");
19
19
  const config_1 = require("./utils/config");
20
20
  exports.name = 'nx/js/dependencies-and-lockfile';
21
- // Separate in-memory caches
22
- let cachedExternalNodes;
21
+ // An install can rewrite the lockfile between createNodes and
22
+ // createDependencies, so both parse the one createNodes read.
23
+ let cachedLockFile;
23
24
  let cachedKeyMap;
24
25
  exports.createNodes = [
25
26
  (0, globs_1.combineGlobPatterns)(lock_file_1.LOCKFILES),
26
27
  (files, _, context) => {
28
+ // A long-lived process must not reuse a lockfile this computation skipped.
29
+ cachedLockFile = undefined;
30
+ cachedKeyMap = undefined;
27
31
  return (0, plugins_1.createNodesFromFiles)(internalCreateNodes, files, _, context);
28
32
  },
29
33
  ];
@@ -42,41 +46,45 @@ function internalCreateNodes(lockFile, _, context) {
42
46
  ? (0, fs_1.readFileSync)(lockFilePath, 'utf-8')
43
47
  : (0, bun_parser_1.readBunLockFile)(lockFilePath);
44
48
  const lockFileHash = getLockFileHash(lockFileContents);
45
- if (!lockFileNeedsReprocessing(lockFileHash, externalNodesHashFile)) {
46
- const { nodes, keyMap } = readCachedExternalNodes();
47
- cachedExternalNodes = nodes;
48
- cachedKeyMap = keyMap;
49
+ cachedLockFile = { packageManager, lockFile, lockFileContents, lockFileHash };
50
+ const cached = readCache(externalNodesCache, lockFileHash);
51
+ if (cached) {
52
+ cachedKeyMap = deserializeKeyMap(cached.keyMap, cached.nodes);
49
53
  return {
50
- externalNodes: nodes,
54
+ externalNodes: cached.nodes,
51
55
  };
52
56
  }
53
- const { nodes: externalNodes, keyMap } = (0, lock_file_1.getLockFileNodes)(packageManager, lockFileContents, lockFileHash, context);
54
- cachedExternalNodes = externalNodes;
57
+ const { nodes: externalNodes, keyMap } = (0, lock_file_1.getLockFileNodes)(packageManager, lockFile, lockFileContents, lockFileHash, context);
55
58
  cachedKeyMap = keyMap;
56
- writeExternalNodesCache(lockFileHash, externalNodes, keyMap);
59
+ writeCache(externalNodesCache, lockFileHash, {
60
+ nodes: externalNodes,
61
+ keyMap: serializeKeyMap(keyMap),
62
+ });
57
63
  return {
58
64
  externalNodes,
59
65
  };
60
66
  }
61
67
  const createDependencies = (_, ctx) => {
62
68
  const pluginConfig = (0, config_1.jsPluginConfig)(ctx.nxJsonConfiguration);
63
- const packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot);
64
69
  let lockfileDependencies = [];
65
70
  // lockfile may not exist yet
66
71
  if (pluginConfig.analyzeLockfile &&
67
- (0, lock_file_1.lockFileExists)(packageManager) &&
68
- cachedExternalNodes) {
69
- const lockFilePath = (0, path_1.join)(workspace_root_1.workspaceRoot, (0, lock_file_1.getLockFileName)(packageManager));
70
- const lockFileContents = packageManager !== 'bun'
71
- ? (0, fs_1.readFileSync)(lockFilePath, 'utf-8')
72
- : (0, bun_parser_1.readBunLockFile)(lockFilePath);
73
- const lockFileHash = getLockFileHash(lockFileContents);
74
- if (!lockFileNeedsReprocessing(lockFileHash, dependenciesHashFile)) {
75
- lockfileDependencies = readCachedDependencies();
72
+ cachedLockFile &&
73
+ (0, lock_file_1.lockFileExists)(cachedLockFile.packageManager)) {
74
+ const { packageManager, lockFile, lockFileContents, lockFileHash } = cachedLockFile;
75
+ // Cached dependencies name their external nodes, and those names also
76
+ // depend on node_modules hoisting.
77
+ const dependenciesHash = (0, file_hasher_1.hashArray)([
78
+ lockFileHash,
79
+ ...Object.keys(ctx.externalNodes),
80
+ ]);
81
+ const cachedDependencies = readCache(dependenciesCache, dependenciesHash);
82
+ if (cachedDependencies) {
83
+ lockfileDependencies = cachedDependencies;
76
84
  }
77
85
  else {
78
- lockfileDependencies = (0, lock_file_1.getLockFileDependencies)(packageManager, lockFileContents, lockFileHash, ctx, cachedKeyMap);
79
- writeDependenciesCache(lockFileHash, lockfileDependencies);
86
+ lockfileDependencies = (0, lock_file_1.getLockFileDependencies)(packageManager, lockFile, lockFileContents, lockFileHash, ctx, cachedKeyMap);
87
+ writeCache(dependenciesCache, dependenciesHash, lockfileDependencies);
80
88
  }
81
89
  }
82
90
  perf_hooks_1.performance.mark('build typescript dependencies - start');
@@ -107,7 +115,7 @@ function serializeKeyMap(keyMap) {
107
115
  }
108
116
  return serialized;
109
117
  }
110
- // Deserialize keyMap from JSON format using ctx.externalNodes
118
+ // Deserialize keyMap from JSON format
111
119
  function deserializeKeyMap(serialized, externalNodes) {
112
120
  const keyMap = new Map();
113
121
  for (const [key, value] of Object.entries(serialized)) {
@@ -131,47 +139,24 @@ function deserializeKeyMap(serialized, externalNodes) {
131
139
  }
132
140
  return keyMap;
133
141
  }
134
- function lockFileNeedsReprocessing(lockHash, hashFilePath) {
142
+ function readCache(path, key) {
135
143
  try {
136
- return (0, fs_1.readFileSync)(hashFilePath).toString() !== lockHash;
144
+ const cache = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
145
+ return cache.key === key ? cache.data : undefined;
137
146
  }
138
147
  catch {
139
- return true;
140
- }
141
- }
142
- // External nodes cache functions
143
- function writeExternalNodesCache(hash, nodes, keyMap) {
144
- const serializedKeyMap = serializeKeyMap(keyMap);
145
- const cacheData = { nodes, keyMap: serializedKeyMap };
146
- const content = safeStringify(cacheData);
147
- if (content === undefined) {
148
- logger_1.logger.warn(`Failed to serialize external nodes cache. Skipping cache write.`);
149
- tryRemoveFile(externalNodesCache);
150
- tryRemoveFile(externalNodesHashFile);
151
- return;
152
- }
153
- (0, plugin_cache_utils_1.safeWriteFileCache)(externalNodesCache, content);
154
- if ((0, fs_1.existsSync)(externalNodesCache)) {
155
- (0, plugin_cache_utils_1.safeWriteFileCache)(externalNodesHashFile, hash);
148
+ // Another process can be mid-write, so an unreadable cache is a miss.
149
+ return undefined;
156
150
  }
157
151
  }
158
- function readCachedExternalNodes() {
159
- const { nodes, keyMap } = JSON.parse((0, fs_1.readFileSync)(externalNodesCache, 'utf-8'));
160
- return { nodes, keyMap: deserializeKeyMap(keyMap, nodes) };
161
- }
162
- // Dependencies cache functions
163
- function writeDependenciesCache(hash, dependencies) {
164
- const content = safeStringify(dependencies);
152
+ function writeCache(path, key, data) {
153
+ const content = safeStringify({ key, data });
165
154
  if (content === undefined) {
166
- logger_1.logger.warn(`Failed to serialize dependencies cache. Skipping cache write.`);
167
- tryRemoveFile(dependenciesCache);
168
- tryRemoveFile(dependenciesHashFile);
155
+ logger_1.logger.warn(`Failed to serialize ${path}. Skipping cache write.`);
156
+ tryRemoveFile(path);
169
157
  return;
170
158
  }
171
- (0, plugin_cache_utils_1.safeWriteFileCache)(dependenciesCache, content);
172
- if ((0, fs_1.existsSync)(dependenciesCache)) {
173
- (0, plugin_cache_utils_1.safeWriteFileCache)(dependenciesHashFile, hash);
174
- }
159
+ (0, plugin_cache_utils_1.safeWriteFileCache)(path, content);
175
160
  }
176
161
  function safeStringify(data) {
177
162
  try {
@@ -191,11 +176,7 @@ function tryRemoveFile(path) {
191
176
  // Best effort
192
177
  }
193
178
  }
194
- function readCachedDependencies() {
195
- return JSON.parse((0, fs_1.readFileSync)(dependenciesCache).toString());
196
- }
197
- // Cache file paths
198
- const externalNodesHashFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-nodes.hash');
199
- const dependenciesHashFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-dependencies.hash');
200
- const externalNodesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'parsed-lock-file.nodes.json');
201
- const dependenciesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'parsed-lock-file.dependencies.json');
179
+ // Each cache file holds its key, so key and data come from one write.
180
+ // Older Nx versions read other names with a hash file; keep these distinct.
181
+ const externalNodesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-nodes.json');
182
+ const dependenciesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-dependencies.json');
@@ -10,9 +10,9 @@ import { PackageManager } from '../../../utils/package-manager';
10
10
  export declare const LOCKFILES: string[];
11
11
  export declare const AUTO_AFFECTED_LOCK_FILES: readonly ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "pnpm-lock.yml", "bun.lockb", "bun.lock"];
12
12
  /**
13
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
13
+ * Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
14
14
  */
15
- export declare function getLockFileNodes(packageManager: PackageManager, contents: string, lockFileHash: string, context: CreateNodesContext): {
15
+ export declare function getLockFileNodes(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateNodesContext): {
16
16
  nodes: Record<string, ProjectGraphExternalNode>;
17
17
  keyMap: Map<string, any>;
18
18
  };
@@ -21,9 +21,9 @@ export declare function getLockFileNodesForName(lockFile: string, contents: stri
21
21
  keyMap: Map<string, any>;
22
22
  };
23
23
  /**
24
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
24
+ * Parses the lockfile into dependencies between external nodes.
25
25
  */
26
- export declare function getLockFileDependencies(packageManager: PackageManager, contents: string, lockFileHash: string, context: CreateDependenciesContext, keyMap: Map<string, any>): RawProjectGraphDependency[];
26
+ export declare function getLockFileDependencies(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateDependenciesContext, keyMap: Map<string, any>): RawProjectGraphDependency[];
27
27
  export declare function lockFileExists(packageManager: PackageManager): boolean;
28
28
  /**
29
29
  * Returns lock file name based on the detected package manager in the root
@@ -54,14 +54,14 @@ const PNPM_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, PNP
54
54
  const BUN_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, bun_parser_1.BUN_LOCK_FILE);
55
55
  const BUN_TEXT_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, bun_parser_1.BUN_TEXT_LOCK_FILE);
56
56
  /**
57
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
57
+ * Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
58
58
  */
59
- function getLockFileNodes(packageManager, contents, lockFileHash, context) {
59
+ function getLockFileNodes(packageManager, lockFile, contents, lockFileHash, context) {
60
60
  try {
61
61
  const packageJson = packageManager === 'yarn' || packageManager === 'bun'
62
62
  ? (0, fileutils_1.readJsonFile)((0, node_path_1.join)(context.workspaceRoot, 'package.json'))
63
63
  : undefined;
64
- return getLockFileNodesForName(getLockFileName(packageManager), contents, lockFileHash, packageJson);
64
+ return getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson);
65
65
  }
66
66
  catch (e) {
67
67
  if (!isPostInstallProcess()) {
@@ -94,9 +94,9 @@ function getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson)
94
94
  throw new Error(`Unknown lock file: ${lockFile}`);
95
95
  }
96
96
  /**
97
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
97
+ * Parses the lockfile into dependencies between external nodes.
98
98
  */
99
- function getLockFileDependencies(packageManager, contents, lockFileHash, context, keyMap) {
99
+ function getLockFileDependencies(packageManager, lockFile, contents, lockFileHash, context, keyMap) {
100
100
  try {
101
101
  if (packageManager === 'yarn') {
102
102
  return (0, yarn_parser_1.getYarnLockfileDependencies)(contents, lockFileHash, context, keyMap);
@@ -108,8 +108,7 @@ function getLockFileDependencies(packageManager, contents, lockFileHash, context
108
108
  return (0, npm_parser_1.getNpmLockfileDependencies)(contents, lockFileHash, context, keyMap);
109
109
  }
110
110
  if (packageManager === 'bun') {
111
- const lockFilePath = getLockFilePath(packageManager);
112
- if (lockFilePath.endsWith(bun_parser_1.BUN_TEXT_LOCK_FILE)) {
111
+ if (lockFile === bun_parser_1.BUN_TEXT_LOCK_FILE) {
113
112
  // Bun parser doesn't use keyMap
114
113
  return (0, bun_parser_1.getBunTextLockfileDependencies)(contents, lockFileHash, context);
115
114
  }
@@ -1,3 +1,11 @@
1
- import { TouchedProjectLocator } from '../../../../project-graph/affected/affected-project-graph-models';
2
- import { LockFileChange, WholeFileChange } from '../../../../project-graph/file-utils';
1
+ import { DependencyChanges, TouchedProjectLocator } from '../../../../project-graph/affected/affected-project-graph-models';
2
+ import { FileChange, LockFileChange, WholeFileChange } from '../../../../project-graph/file-utils';
3
+ import { ProjectGraph, ProjectGraphProjectNode } from '../../../../config/project-graph';
4
+ import { NxJsonConfiguration } from '../../../../config/nx-json';
5
+ import { PackageJson } from '../../../../utils/package-json';
3
6
  export declare const getTouchedProjectsFromLockFile: TouchedProjectLocator<WholeFileChange | LockFileChange>;
7
+ /**
8
+ * The same change as task selection consumes it: the packages that moved,
9
+ * which a plan names as `External`, rather than the projects depending on them.
10
+ */
11
+ export declare function lockFileDependencyChanges(fileChanges: FileChange<WholeFileChange | LockFileChange>[], projectGraphNodes: Record<string, ProjectGraphProjectNode>, nxJson: NxJsonConfiguration, packageJson: PackageJson | undefined, projectGraph: ProjectGraph): DependencyChanges;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTouchedProjectsFromLockFile = void 0;
4
+ exports.lockFileDependencyChanges = lockFileDependencyChanges;
4
5
  const file_utils_1 = require("../../../../project-graph/file-utils");
5
6
  const config_1 = require("../../utils/config");
6
7
  const find_matching_projects_1 = require("../../../../utils/find-matching-projects");
@@ -9,61 +10,82 @@ const output_1 = require("../../../../utils/output");
9
10
  const lock_file_1 = require("../../lock-file/lock-file");
10
11
  const getTouchedProjectsFromLockFile = (fileChanges, projectGraphNodes, nxJson, packageJson, projectGraph) => {
11
12
  const { projectsAffectedByDependencyUpdates } = (0, config_1.jsPluginConfig)(nxJson);
12
- const changedLockFile = fileChanges.find((f) => lock_file_1.AUTO_AFFECTED_LOCK_FILES.includes(f.file));
13
+ const changedLockFile = findChangedLockFile(fileChanges);
14
+ const allProjectNames = Object.values(projectGraphNodes).map((p) => p.name);
13
15
  if (projectsAffectedByDependencyUpdates === 'auto') {
14
- return getAutoAffected(changedLockFile, projectGraphNodes, projectGraph, packageJson);
16
+ if (!changedLockFile) {
17
+ return [];
18
+ }
19
+ // External node names, which the reverse walk in filterAffected carries
20
+ // back to the projects depending on them.
21
+ return (changedExternalNodes(changedLockFile, projectGraph, packageJson) ??
22
+ allProjectNames);
15
23
  }
16
24
  else if (Array.isArray(projectsAffectedByDependencyUpdates)) {
17
25
  return (0, find_matching_projects_1.findMatchingProjects)(projectsAffectedByDependencyUpdates, projectGraphNodes);
18
26
  }
19
- if (changedLockFile) {
20
- return Object.values(projectGraphNodes).map((p) => p.name);
21
- }
22
- return [];
27
+ return changedLockFile ? allProjectNames : [];
23
28
  };
24
29
  exports.getTouchedProjectsFromLockFile = getTouchedProjectsFromLockFile;
25
30
  /**
26
- * In auto mode, parse the lock file at the base and head revisions
27
- * using Nx's existing lock file parsers, then diff the resulting
28
- * external-node maps to determine which packages actually changed.
29
- *
30
- * Returns external node names (e.g. "npm:lodash@4.17.21") so the
31
- * graph reversal in filterAffected can walk back to workspace projects.
31
+ * The same change as task selection consumes it: the packages that moved,
32
+ * which a plan names as `External`, rather than the projects depending on them.
32
33
  */
33
- function getAutoAffected(changedLockFile, projectGraphNodes, projectGraph, packageJson) {
34
- const allProjectNames = Object.values(projectGraphNodes).map((p) => p.name);
34
+ function lockFileDependencyChanges(fileChanges, projectGraphNodes, nxJson, packageJson, projectGraph) {
35
+ const none = {
36
+ externals: [],
37
+ changedExternalTypes: [],
38
+ projects: [],
39
+ };
40
+ const changedLockFile = findChangedLockFile(fileChanges);
35
41
  if (!changedLockFile) {
36
- return [];
42
+ return none;
43
+ }
44
+ const { projectsAffectedByDependencyUpdates } = (0, config_1.jsPluginConfig)(nxJson);
45
+ if (Array.isArray(projectsAffectedByDependencyUpdates)) {
46
+ return {
47
+ ...none,
48
+ projects: (0, find_matching_projects_1.findMatchingProjects)(projectsAffectedByDependencyUpdates, projectGraphNodes),
49
+ };
37
50
  }
51
+ const externals = projectsAffectedByDependencyUpdates === 'auto'
52
+ ? changedExternalNodes(changedLockFile, projectGraph, packageJson)
53
+ : null;
54
+ return externals
55
+ ? { ...none, externals }
56
+ : { ...none, changedExternalTypes: ['npm'] };
57
+ }
58
+ function findChangedLockFile(fileChanges) {
59
+ return fileChanges.find((f) => lock_file_1.AUTO_AFFECTED_LOCK_FILES.includes(f.file));
60
+ }
61
+ /**
62
+ * Diffs the lock file's base and head revisions with the parsers the project
63
+ * graph is built from, and names the external nodes whose package changed.
64
+ *
65
+ * Null when the diff cannot be pinned to packages: a WholeFileChange (a
66
+ * revision could not be read), a parse failure, or a changed package with no
67
+ * external node in the head graph.
68
+ */
69
+ function changedExternalNodes(changedLockFile, projectGraph, packageJson) {
38
70
  const changes = changedLockFile.getChanges();
39
- // A WholeFileChange means we were unable to read both revisions of
40
- // the lock file (e.g. missing base revision, git error). Fall back
41
- // to marking all projects affected.
42
71
  if (!changes.every(file_utils_1.isLockFileChange)) {
43
- return allProjectNames;
72
+ return null;
44
73
  }
45
74
  const changedPackageNames = getChangedPackageNames(changedLockFile.file, changes, packageJson);
46
75
  if (changedPackageNames === null) {
47
- return allProjectNames;
76
+ return null;
48
77
  }
49
78
  if (changedPackageNames.size === 0) {
50
79
  return [];
51
80
  }
52
- // Look up the changed packages in the project graph's external nodes
53
- // and return the external node names. The graph reversal in
54
- // filterAffected walks from these nodes to workspace projects.
55
81
  const { touchedNodeNames, missingPackageNames } = findExternalNodesByPackageName(changedPackageNames, projectGraph.externalNodes ?? {});
56
- if (missingPackageNames.size > 0) {
57
- return allProjectNames;
58
- }
59
- return touchedNodeNames;
82
+ return missingPackageNames.size > 0 ? null : touchedNodeNames;
60
83
  }
61
84
  /**
62
85
  * Parse the base and head revisions of the lock file with Nx's
63
86
  * existing parsers and diff the resulting package -> version maps.
64
87
  *
65
- * Returns the set of changed package names, or null if parsing
66
- * failed (in which case the caller should fall back to all projects).
88
+ * Returns the set of changed package names, or null if parsing failed.
67
89
  */
68
90
  function getChangedPackageNames(file, changes, packageJson) {
69
91
  try {
@@ -1,4 +1,12 @@
1
- import { WholeFileChange } from '../../../../project-graph/file-utils';
1
+ import { FileChange, WholeFileChange } from '../../../../project-graph/file-utils';
2
2
  import { JsonChange } from '../../../../utils/json-diff';
3
- import { TouchedProjectLocator } from '../../../../project-graph/affected/affected-project-graph-models';
3
+ import { DependencyChanges, TouchedProjectLocator } from '../../../../project-graph/affected/affected-project-graph-models';
4
+ import { ProjectGraph } from '../../../../config/project-graph';
5
+ import { NxJsonConfiguration } from '../../../../config/nx-json';
4
6
  export declare const getTouchedNpmPackages: TouchedProjectLocator<WholeFileChange | JsonChange>;
7
+ /**
8
+ * The same change as task selection consumes it: the packages that moved,
9
+ * which a plan names as `External`, and the workspace projects the root
10
+ * package.json depends on directly.
11
+ */
12
+ export declare function packageJsonDependencyChanges(touchedFiles: FileChange<WholeFileChange | JsonChange>[], nxJson: NxJsonConfiguration, projectGraph: ProjectGraph): DependencyChanges;
@@ -1,11 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTouchedNpmPackages = void 0;
4
+ exports.packageJsonDependencyChanges = packageJsonDependencyChanges;
4
5
  const file_utils_1 = require("../../../../project-graph/file-utils");
5
6
  const json_diff_1 = require("../../../../utils/json-diff");
6
7
  const logger_1 = require("../../../../utils/logger");
7
8
  const get_package_name_from_import_path_1 = require("../../../../utils/get-package-name-from-import-path");
8
- const getTouchedNpmPackages = (touchedFiles, _, nxJson, packageJson, projectGraph) => {
9
+ const getTouchedNpmPackages = (touchedFiles, _nodes, nxJson, _packageJson, projectGraph) => touchedNpmPackages(touchedFiles, nxJson, projectGraph) ??
10
+ Object.keys(projectGraph.nodes);
11
+ exports.getTouchedNpmPackages = getTouchedNpmPackages;
12
+ /**
13
+ * The same change as task selection consumes it: the packages that moved,
14
+ * which a plan names as `External`, and the workspace projects the root
15
+ * package.json depends on directly.
16
+ */
17
+ function packageJsonDependencyChanges(touchedFiles, nxJson, projectGraph) {
18
+ const touched = touchedNpmPackages(touchedFiles, nxJson, projectGraph);
19
+ if (touched === null) {
20
+ return { externals: [], changedExternalTypes: ['npm'], projects: [] };
21
+ }
22
+ return {
23
+ externals: touched.filter((name) => name in projectGraph.externalNodes),
24
+ changedExternalTypes: [],
25
+ projects: touched.filter((name) => name in projectGraph.nodes),
26
+ };
27
+ }
28
+ /**
29
+ * External nodes and workspace projects the root package.json change names,
30
+ * or null when it cannot be pinned to them: a removed dependency, a global
31
+ * package, or an override selector matching nothing in the graph.
32
+ */
33
+ function touchedNpmPackages(touchedFiles, nxJson, projectGraph) {
9
34
  const packageJsonChange = touchedFiles.find((f) => f.file === 'package.json');
10
35
  if (!packageJsonChange)
11
36
  return [];
@@ -19,10 +44,8 @@ const getTouchedNpmPackages = (touchedFiles, _, nxJson, packageJson, projectGrap
19
44
  if ((0, json_diff_1.isJsonChange)(c) &&
20
45
  (c.path[0] === 'dependencies' || c.path[0] === 'devDependencies') &&
21
46
  c.path.length === 2) {
22
- // A package was deleted so mark all workspace projects as touched.
23
47
  if (c.type === json_diff_1.JsonDiffType.Deleted) {
24
- touched = Object.keys(projectGraph.nodes);
25
- break;
48
+ return null;
26
49
  }
27
50
  else {
28
51
  let npmPackage = npmPackages.find((pkg) => pkg.data.packageName === c.path[1]);
@@ -45,7 +68,7 @@ const getTouchedNpmPackages = (touchedFiles, _, nxJson, packageJson, projectGrap
45
68
  }
46
69
  if ('packageName' in npmPackage.data) {
47
70
  if (globalPackages.has(npmPackage.data.packageName)) {
48
- return Object.keys(projectGraph.nodes);
71
+ return null;
49
72
  }
50
73
  }
51
74
  }
@@ -59,13 +82,12 @@ const getTouchedNpmPackages = (touchedFiles, _, nxJson, packageJson, projectGrap
59
82
  continue;
60
83
  packagesByName ??= groupPackagesByName(npmPackages);
61
84
  const matchingNpmPackages = findPackagesForSelector(packageSelector, packagesByName, c.path[0] === 'pnpm');
62
- // An unresolved selector can still target a transitive dependency,
63
- // so fall back to marking every project affected.
85
+ // An unresolved selector can still target a transitive dependency.
64
86
  if (!matchingNpmPackages.length) {
65
- return Object.keys(projectGraph.nodes);
87
+ return null;
66
88
  }
67
89
  if (matchingNpmPackages.some((pkg) => globalPackages.has(pkg.data.packageName))) {
68
- return Object.keys(projectGraph.nodes);
90
+ return null;
69
91
  }
70
92
  touched.push(...matchingNpmPackages.map((pkg) => pkg.name));
71
93
  }
@@ -79,8 +101,7 @@ const getTouchedNpmPackages = (touchedFiles, _, nxJson, packageJson, projectGrap
79
101
  logger_1.logger.warn(`The affected projects might have not been identified properly. The package(s) ${missingTouchedNpmPackages.join(', ')} were not found. Please open an issue in GitHub including the package.json file.`);
80
102
  }
81
103
  return [...new Set(touched)];
82
- };
83
- exports.getTouchedNpmPackages = getTouchedNpmPackages;
104
+ }
84
105
  function getPackageSelector(change) {
85
106
  if (typeof change.value.lhs !== 'string' &&
86
107
  typeof change.value.rhs !== 'string') {
@@ -6,6 +6,20 @@ export interface AffectedProjectGraphContext {
6
6
  nxJson: NxJsonConfiguration<any>;
7
7
  touchedProjects: string[];
8
8
  }
9
+ /**
10
+ * What a lockfile or package.json change moved, before it is projected onto
11
+ * projects (the reverse walk) or tasks (matched against each plan's externals).
12
+ */
13
+ export interface DependencyChanges {
14
+ /** External node names whose version or integrity moved. */
15
+ externals: string[];
16
+ /** Ecosystems whose manifest changed without the change being pinnable to
17
+ * packages, so every node of that type counts as moved. A locator names the
18
+ * ecosystem it reads, since a change to one cannot move another's nodes. */
19
+ changedExternalTypes: string[];
20
+ /** Workspace projects the change names outright. */
21
+ projects: string[];
22
+ }
9
23
  export interface TouchedProjectLocator<T extends Change = Change> {
10
24
  (fileChanges: FileChange<T>[], projectGraphNodes?: Record<string, ProjectGraphProjectNode>, nxJson?: NxJsonConfiguration<any>, packageJson?: any, projectGraph?: ProjectGraph, projectDeletionAffectsAllProjects?: boolean): string[] | Promise<string[]>;
11
25
  }
@@ -2,27 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterAffected = filterAffected;
4
4
  const file_utils_1 = require("../file-utils");
5
- const workspace_projects_1 = require("./locators/workspace-projects");
6
- const touched_projects_1 = require("../../plugins/js/project-graph/affected/touched-projects");
7
5
  const operators_1 = require("../operators");
8
6
  const configuration_1 = require("../../config/configuration");
9
- const project_glob_changes_1 = require("./locators/project-glob-changes");
7
+ const affected_projects_1 = require("./affected-projects");
10
8
  async function filterAffected(graph, touchedFiles, nxJson = (0, configuration_1.readNxJson)(), packageJson = (0, file_utils_1.readPackageJson)(), projectDeletionAffectsAllProjects = true) {
11
- // Additional affected logic should be in this array.
12
- const touchedProjectLocators = [
13
- workspace_projects_1.getTouchedProjects,
14
- workspace_projects_1.getImplicitlyTouchedProjects,
15
- project_glob_changes_1.getTouchedProjectsFromProjectGlobChanges,
16
- touched_projects_1.getTouchedProjects,
17
- ];
18
- const touchedProjects = [];
19
- for (const locator of touchedProjectLocators) {
20
- performance.mark(locator.name + ':start');
21
- const projects = await locator(touchedFiles, graph.nodes, nxJson, packageJson, graph, projectDeletionAffectsAllProjects);
22
- performance.mark(locator.name + ':end');
23
- performance.measure(locator.name, locator.name + ':start', locator.name + ':end');
24
- touchedProjects.push(...projects);
25
- }
9
+ performance.mark('locateTouchedProjects:start');
10
+ const touchedProjects = await (0, affected_projects_1.runTouchedProjectLocators)(graph, touchedFiles, nxJson, packageJson, projectDeletionAffectsAllProjects);
11
+ performance.mark('locateTouchedProjects:end');
12
+ performance.measure('locateTouchedProjects', 'locateTouchedProjects:start', 'locateTouchedProjects:end');
26
13
  return filterAffectedProjects(graph, {
27
14
  projectGraphNodes: graph.nodes,
28
15
  nxJson,
@@ -0,0 +1,7 @@
1
+ import { NxJsonConfiguration } from '../../config/nx-json';
2
+ import { ProjectGraph } from '../../config/project-graph';
3
+ import { FileChange } from '../file-utils';
4
+ /** Runs every locator and returns what each one marked, duplicates included. */
5
+ export declare function runTouchedProjectLocators(graph: ProjectGraph, touchedFiles: FileChange[], nxJson: NxJsonConfiguration, packageJson?: any, projectDeletionAffectsAllProjects?: boolean): Promise<string[]>;
6
+ /** Resolved here because the native side takes the patterns, not the plugins. */
7
+ export declare function getProjectGlobPatterns(nxJson: NxJsonConfiguration): Promise<string[]>;