nx 20.6.0-canary.20250311-d1a7ac9 → 20.6.0-canary.20250313-7f1e1cf

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.6.0-canary.20250311-d1a7ac9",
3
+ "version": "20.6.0-canary.20250313-7f1e1cf",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -82,16 +82,16 @@
82
82
  }
83
83
  },
84
84
  "optionalDependencies": {
85
- "@nx/nx-darwin-arm64": "20.6.0-canary.20250311-d1a7ac9",
86
- "@nx/nx-darwin-x64": "20.6.0-canary.20250311-d1a7ac9",
87
- "@nx/nx-freebsd-x64": "20.6.0-canary.20250311-d1a7ac9",
88
- "@nx/nx-linux-arm-gnueabihf": "20.6.0-canary.20250311-d1a7ac9",
89
- "@nx/nx-linux-arm64-gnu": "20.6.0-canary.20250311-d1a7ac9",
90
- "@nx/nx-linux-arm64-musl": "20.6.0-canary.20250311-d1a7ac9",
91
- "@nx/nx-linux-x64-gnu": "20.6.0-canary.20250311-d1a7ac9",
92
- "@nx/nx-linux-x64-musl": "20.6.0-canary.20250311-d1a7ac9",
93
- "@nx/nx-win32-arm64-msvc": "20.6.0-canary.20250311-d1a7ac9",
94
- "@nx/nx-win32-x64-msvc": "20.6.0-canary.20250311-d1a7ac9"
85
+ "@nx/nx-darwin-arm64": "20.6.0-canary.20250313-7f1e1cf",
86
+ "@nx/nx-darwin-x64": "20.6.0-canary.20250313-7f1e1cf",
87
+ "@nx/nx-freebsd-x64": "20.6.0-canary.20250313-7f1e1cf",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.6.0-canary.20250313-7f1e1cf",
89
+ "@nx/nx-linux-arm64-gnu": "20.6.0-canary.20250313-7f1e1cf",
90
+ "@nx/nx-linux-arm64-musl": "20.6.0-canary.20250313-7f1e1cf",
91
+ "@nx/nx-linux-x64-gnu": "20.6.0-canary.20250313-7f1e1cf",
92
+ "@nx/nx-linux-x64-musl": "20.6.0-canary.20250313-7f1e1cf",
93
+ "@nx/nx-win32-arm64-msvc": "20.6.0-canary.20250313-7f1e1cf",
94
+ "@nx/nx-win32-x64-msvc": "20.6.0-canary.20250313-7f1e1cf"
95
95
  },
96
96
  "nx-migrations": {
97
97
  "migrations": "./migrations.json",
@@ -1,2 +1,2 @@
1
1
  export declare const allowedProjectExtensions: readonly ["tags", "implicitDependencies", "configFilePath", "$schema", "generators", "namedInputs", "name", "files", "root", "sourceRoot", "projectType", "release", "includedScripts", "metadata"];
2
- export declare const allowedWorkspaceExtensions: readonly ["$schema", "implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud", "sync", "useLegacyCache"];
2
+ export declare const allowedWorkspaceExtensions: readonly ["$schema", "implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud", "sync", "useLegacyCache", "maxCacheSize"];
@@ -65,6 +65,7 @@ exports.allowedWorkspaceExtensions = [
65
65
  'neverConnectToCloud',
66
66
  'sync',
67
67
  'useLegacyCache',
68
+ 'maxCacheSize',
68
69
  ];
69
70
  if (!patched) {
70
71
  Module.prototype.require = function () {
@@ -490,6 +490,10 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
490
490
  * Use the legacy file system cache instead of the db cache
491
491
  */
492
492
  useLegacyCache?: boolean;
493
+ /**
494
+ * Sets the maximum size of the local cache. Accepts a number followed by a unit (e.g. 100MB). Accepted units are B, KB, MB, and GB.
495
+ */
496
+ maxCacheSize?: string;
493
497
  }
494
498
  export type PluginConfiguration = string | ExpandedPluginConfiguration;
495
499
  export type ExpandedPluginConfiguration<T = unknown> = {
@@ -37,12 +37,12 @@ export declare class ImportResult {
37
37
 
38
38
  export declare class NxCache {
39
39
  cacheDirectory: string
40
- constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<NxDbConnection>, linkTaskDetails?: boolean | undefined | null)
40
+ constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<NxDbConnection>, linkTaskDetails?: boolean | undefined | null, maxCacheSize?: number | undefined | null)
41
41
  get(hash: string): CachedResult | null
42
42
  put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
43
- applyRemoteCacheResults(hash: string, result: CachedResult): void
43
+ applyRemoteCacheResults(hash: string, result: CachedResult, outputs: Array<string>): void
44
44
  getTaskOutputsPath(hash: string): string
45
- copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): void
45
+ copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): number
46
46
  removeOldCacheRecords(): void
47
47
  checkCacheFsInSync(): boolean
48
48
  }
@@ -112,13 +112,14 @@ export interface CachedResult {
112
112
  code: number
113
113
  terminalOutput: string
114
114
  outputsPath: string
115
+ size?: number
115
116
  }
116
117
 
117
118
  export declare export function closeDbConnection(connection: ExternalObject<NxDbConnection>): void
118
119
 
119
120
  export declare export function connectToNxDb(cacheDir: string, nxVersion: string, dbName?: string | undefined | null): ExternalObject<NxDbConnection>
120
121
 
121
- export declare export function copy(src: string, dest: string): void
122
+ export declare export function copy(src: string, dest: string): number
122
123
 
123
124
  export interface DepsOutputsInput {
124
125
  dependentTasksOutputFiles: string
Binary file
@@ -15,6 +15,7 @@ export declare function dbCacheEnabled(nxJson?: NxJsonConfiguration): boolean;
15
15
  export declare function getCache(options: DefaultTasksRunnerOptions): DbCache | Cache;
16
16
  export declare class DbCache {
17
17
  private readonly options;
18
+ private nxJson;
18
19
  private cache;
19
20
  private remoteCache;
20
21
  private remoteCachePromise;
@@ -27,7 +28,7 @@ export declare class DbCache {
27
28
  get(task: Task): Promise<CachedResult | null>;
28
29
  private applyRemoteCacheResults;
29
30
  put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
30
- copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<void>;
31
+ copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<number>;
31
32
  removeOldCacheRecords(): void;
32
33
  temporaryOutputPath(task: Task): string;
33
34
  private getRemoteCache;
@@ -66,3 +67,13 @@ export declare class Cache {
66
67
  private createCacheDir;
67
68
  private createTerminalOutputsDir;
68
69
  }
70
+ /**
71
+ * Converts a string representation of a max cache size to a number.
72
+ *
73
+ * e.g. '1GB' -> 1024 * 1024 * 1024
74
+ * '1MB' -> 1024 * 1024
75
+ * '1KB' -> 1024
76
+ *
77
+ * @param maxCacheSize Max cache size as specified in nx.json
78
+ */
79
+ export declare function parseMaxCacheSize(maxCacheSize: string): number | undefined;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cache = exports.DbCache = void 0;
4
4
  exports.dbCacheEnabled = dbCacheEnabled;
5
5
  exports.getCache = getCache;
6
+ exports.parseMaxCacheSize = parseMaxCacheSize;
6
7
  const workspace_root_1 = require("../utils/workspace-root");
7
8
  const path_1 = require("path");
8
9
  const perf_hooks_1 = require("perf_hooks");
@@ -68,7 +69,8 @@ function getCache(options) {
68
69
  class DbCache {
69
70
  constructor(options) {
70
71
  this.options = options;
71
- this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)());
72
+ this.nxJson = (0, nx_json_1.readNxJson)();
73
+ this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)(), undefined, parseMaxCacheSize(this.nxJson.maxCacheSize));
72
74
  this.isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
73
75
  }
74
76
  async init() {
@@ -91,7 +93,7 @@ class DbCache {
91
93
  // attempt remote cache
92
94
  const res = await this.remoteCache.retrieve(task.hash, this.cache.cacheDirectory);
93
95
  if (res) {
94
- this.applyRemoteCacheResults(task.hash, res);
96
+ this.applyRemoteCacheResults(task.hash, res, task.outputs);
95
97
  return {
96
98
  ...res,
97
99
  remote: true,
@@ -105,8 +107,8 @@ class DbCache {
105
107
  return null;
106
108
  }
107
109
  }
108
- applyRemoteCacheResults(hash, res) {
109
- return this.cache.applyRemoteCacheResults(hash, res);
110
+ applyRemoteCacheResults(hash, res, outputs) {
111
+ return this.cache.applyRemoteCacheResults(hash, res, outputs);
110
112
  }
111
113
  async put(task, terminalOutput, outputs, code) {
112
114
  return tryAndRetry(async () => {
@@ -455,3 +457,40 @@ function tryAndRetry(fn) {
455
457
  };
456
458
  return _try();
457
459
  }
460
+ /**
461
+ * Converts a string representation of a max cache size to a number.
462
+ *
463
+ * e.g. '1GB' -> 1024 * 1024 * 1024
464
+ * '1MB' -> 1024 * 1024
465
+ * '1KB' -> 1024
466
+ *
467
+ * @param maxCacheSize Max cache size as specified in nx.json
468
+ */
469
+ function parseMaxCacheSize(maxCacheSize) {
470
+ if (!maxCacheSize) {
471
+ return undefined;
472
+ }
473
+ let regexResult = maxCacheSize.match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
474
+ if (!regexResult) {
475
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize}. Must be a number followed by an optional unit (KB, MB, GB)`);
476
+ }
477
+ let sizeString = regexResult.groups.size;
478
+ let unit = regexResult.groups.unit;
479
+ if ([...sizeString].filter((c) => c === '.').length > 1) {
480
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize} (multiple decimal points in size)`);
481
+ }
482
+ let size = parseFloat(sizeString);
483
+ if (isNaN(size)) {
484
+ throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize} (${sizeString} is not a number)`);
485
+ }
486
+ switch (unit) {
487
+ case 'KB':
488
+ return size * 1024;
489
+ case 'MB':
490
+ return size * 1024 * 1024;
491
+ case 'GB':
492
+ return size * 1024 * 1024 * 1024;
493
+ default:
494
+ return size;
495
+ }
496
+ }
@@ -131,7 +131,12 @@ class TaskOrchestrator {
131
131
  if (!cachedResult || cachedResult.code !== 0)
132
132
  return null;
133
133
  const outputs = task.outputs;
134
- const shouldCopyOutputsFromCache = !!outputs.length &&
134
+ const shouldCopyOutputsFromCache =
135
+ // No output files to restore
136
+ !!outputs.length &&
137
+ // Remote caches are restored to output dirs when applied
138
+ !cachedResult.remote &&
139
+ // Output files have not been touched since last run
135
140
  (await this.shouldCopyOutputsFromCache(outputs, task.hash));
136
141
  if (shouldCopyOutputsFromCache) {
137
142
  await this.cache.copyFilesFromCache(task.hash, cachedResult, outputs);