nx 23.3.0-beta.6 → 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.
@@ -19,7 +19,7 @@ function applyIoSnapshotOutputs(projectGraph, taskGraph, snapshots) {
19
19
  }
20
20
  // Same walk as hashing, already confined to the workspace and outside
21
21
  // node_modules/.nx/.git; ineligible tasks are absent.
22
- const observed = (0, native_1.getObservedIoSnapshotOutputs)(snapshots, taskGraph, (0, overrides_1.ioSnapshotEligibilityOptions)(projectGraph, taskGraph));
22
+ const observed = (0, native_1.getObservedIoSnapshotOutputs)(snapshots, (0, overrides_1.getUltraCacheConfig)(taskGraph), (0, overrides_1.ioSnapshotEligibilityOptions)(projectGraph, taskGraph));
23
23
  for (const [taskId, outputs] of Object.entries(observed)) {
24
24
  const task = taskGraph.tasks[taskId];
25
25
  if (task) {
@@ -1,6 +1,11 @@
1
1
  import type { ProjectGraph } from '../config/project-graph';
2
2
  import type { TaskGraph } from '../config/task-graph';
3
- import { type IoSnapshotEligibilityOptions, type IoSnapshotReport, type IoSnapshots } from '../native';
3
+ import { type IoSnapshotEligibilityOptions, type IoSnapshotReport, type IoSnapshots, type TaskUltracacheConfiguration } from '../native';
4
+ /**
5
+ * Each task's ultracache configuration: all the native eligibility walk reads
6
+ * from a task. `null`, not `undefined`: the native map drops `undefined` keys.
7
+ */
8
+ export declare function getUltraCacheConfig(taskGraph: TaskGraph): Record<string, TaskUltracacheConfiguration | null>;
4
9
  /** The eligibility walk's view of the run's tasks, as JS resolves it. */
5
10
  export declare function ioSnapshotEligibilityOptions(projectGraph: ProjectGraph, taskGraph: TaskGraph): IoSnapshotEligibilityOptions;
6
11
  /**
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUltraCacheConfig = getUltraCacheConfig;
3
4
  exports.ioSnapshotEligibilityOptions = ioSnapshotEligibilityOptions;
4
5
  exports.buildIoSnapshotOverrides = buildIoSnapshotOverrides;
5
6
  const native_1 = require("../native");
@@ -32,6 +33,16 @@ function customHasherTaskIds(projectGraph, taskGraph) {
32
33
  customHasherMemo.set(taskGraph, ids);
33
34
  return ids;
34
35
  }
36
+ /**
37
+ * Each task's ultracache configuration: all the native eligibility walk reads
38
+ * from a task. `null`, not `undefined`: the native map drops `undefined` keys.
39
+ */
40
+ function getUltraCacheConfig(taskGraph) {
41
+ return Object.fromEntries(Object.entries(taskGraph.tasks).map(([id, task]) => [
42
+ id,
43
+ task.ultracache ?? null,
44
+ ]));
45
+ }
35
46
  /** The eligibility walk's view of the run's tasks, as JS resolves it. */
36
47
  function ioSnapshotEligibilityOptions(projectGraph, taskGraph) {
37
48
  return {
@@ -45,5 +56,5 @@ function ioSnapshotEligibilityOptions(projectGraph, taskGraph) {
45
56
  * the `--verbose` run summary.
46
57
  */
47
58
  function buildIoSnapshotOverrides(projectGraph, taskGraph, snapshots) {
48
- return (0, native_1.getIoSnapshotReport)(snapshots, taskGraph, ioSnapshotEligibilityOptions(projectGraph, taskGraph));
59
+ return (0, native_1.getIoSnapshotReport)(snapshots, getUltraCacheConfig(taskGraph), ioSnapshotEligibilityOptions(projectGraph, taskGraph));
49
60
  }
@@ -722,7 +722,7 @@ export declare function getHardcodedIgnorePatterns(): Array<string>
722
722
  export declare function getIoSnapshotDeferredTaskIds(snapshots: IoSnapshots, taskGraph: TaskGraph): Array<string>
723
723
 
724
724
  /** The eligibility report, for the run summary. */
725
- export declare function getIoSnapshotReport(snapshots: IoSnapshots, taskGraph: TaskGraph, options?: IoSnapshotEligibilityOptions | undefined | null): IoSnapshotReport
725
+ export declare function getIoSnapshotReport(snapshots: IoSnapshots, tasks: Record<string, TaskUltracacheConfiguration | null>, options?: IoSnapshotEligibilityOptions | undefined | null): IoSnapshotReport
726
726
 
727
727
  /**
728
728
  * If `workspace_root` is inside a git worktree, returns the main repo root.
@@ -734,7 +734,7 @@ export declare function getMainWorktreeRoot(workspaceRoot: string): string | nul
734
734
  * Observed outputs per eligible task, for the runner to union into
735
735
  * `task.outputs`.
736
736
  */
737
- export declare function getObservedIoSnapshotOutputs(snapshots: IoSnapshots, taskGraph: TaskGraph, options?: IoSnapshotEligibilityOptions | undefined | null): Record<string, Array<string>>
737
+ export declare function getObservedIoSnapshotOutputs(snapshots: IoSnapshots, tasks: Record<string, TaskUltracacheConfiguration | null>, options?: IoSnapshotEligibilityOptions | undefined | null): Record<string, Array<string>>
738
738
 
739
739
  export declare function getTransformableOutputs(outputs: Array<string>): Array<string>
740
740
 
Binary file
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "23.3.0-beta.6",
3
+ "version": "23.3.0-beta.7",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
@@ -185,16 +185,16 @@
185
185
  }
186
186
  },
187
187
  "optionalDependencies": {
188
- "@nx/nx-darwin-arm64": "23.3.0-beta.6",
189
- "@nx/nx-darwin-x64": "23.3.0-beta.6",
190
- "@nx/nx-freebsd-x64": "23.3.0-beta.6",
191
- "@nx/nx-linux-arm-gnueabihf": "23.3.0-beta.6",
192
- "@nx/nx-linux-arm64-gnu": "23.3.0-beta.6",
193
- "@nx/nx-linux-arm64-musl": "23.3.0-beta.6",
194
- "@nx/nx-linux-x64-gnu": "23.3.0-beta.6",
195
- "@nx/nx-linux-x64-musl": "23.3.0-beta.6",
196
- "@nx/nx-win32-arm64-msvc": "23.3.0-beta.6",
197
- "@nx/nx-win32-x64-msvc": "23.3.0-beta.6"
188
+ "@nx/nx-darwin-arm64": "23.3.0-beta.7",
189
+ "@nx/nx-darwin-x64": "23.3.0-beta.7",
190
+ "@nx/nx-freebsd-x64": "23.3.0-beta.7",
191
+ "@nx/nx-linux-arm-gnueabihf": "23.3.0-beta.7",
192
+ "@nx/nx-linux-arm64-gnu": "23.3.0-beta.7",
193
+ "@nx/nx-linux-arm64-musl": "23.3.0-beta.7",
194
+ "@nx/nx-linux-x64-gnu": "23.3.0-beta.7",
195
+ "@nx/nx-linux-x64-musl": "23.3.0-beta.7",
196
+ "@nx/nx-win32-arm64-msvc": "23.3.0-beta.7",
197
+ "@nx/nx-win32-x64-msvc": "23.3.0-beta.7"
198
198
  },
199
199
  "nx-migrations": {
200
200
  "migrations": "./migrations.json",