nx 20.6.0-canary.20250313-7f1e1cf → 20.6.0-canary.20250314-beb1784

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/.eslintrc.json CHANGED
@@ -131,8 +131,10 @@
131
131
  "@nx/nx-win32-arm64-msvc",
132
132
  "@nx/nx-freebsd-x64",
133
133
  "@nx/powerpack-license",
134
+ "@nx/key",
134
135
  // Powerpack plugin conditionally available dynamically at runtime
135
- "@nx/powerpack-conformance"
136
+ "@nx/powerpack-conformance",
137
+ "@nx/conformance"
136
138
  ]
137
139
  }
138
140
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.6.0-canary.20250313-7f1e1cf",
3
+ "version": "20.6.0-canary.20250314-beb1784",
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.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"
85
+ "@nx/nx-darwin-arm64": "20.6.0-canary.20250314-beb1784",
86
+ "@nx/nx-darwin-x64": "20.6.0-canary.20250314-beb1784",
87
+ "@nx/nx-freebsd-x64": "20.6.0-canary.20250314-beb1784",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.6.0-canary.20250314-beb1784",
89
+ "@nx/nx-linux-arm64-gnu": "20.6.0-canary.20250314-beb1784",
90
+ "@nx/nx-linux-arm64-musl": "20.6.0-canary.20250314-beb1784",
91
+ "@nx/nx-linux-x64-gnu": "20.6.0-canary.20250314-beb1784",
92
+ "@nx/nx-linux-x64-musl": "20.6.0-canary.20250314-beb1784",
93
+ "@nx/nx-win32-arm64-msvc": "20.6.0-canary.20250314-beb1784",
94
+ "@nx/nx-win32-x64-msvc": "20.6.0-canary.20250314-beb1784"
95
95
  },
96
96
  "nx-migrations": {
97
97
  "migrations": "./migrations.json",
@@ -33,8 +33,15 @@ function runPackageManagerInstallPlugins(repoRoot, pmc = (0, package_manager_1.g
33
33
  */
34
34
  async function installPlugin(plugin, repoRoot = workspace_root_1.workspaceRoot, updatePackageScripts = false, verbose = false, pmc = (0, package_manager_1.getPackageManagerCommand)()) {
35
35
  try {
36
- (0, generator_utils_1.getGeneratorInformation)(plugin, 'init', workspace_root_1.workspaceRoot, {});
37
- (0, child_process_1.execSync)(`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${updatePackageScripts ? '--updatePackageScripts' : ''} ${verbose ? '--verbose' : ''}`, {
36
+ const { schema } = (0, generator_utils_1.getGeneratorInformation)(plugin, 'init', workspace_root_1.workspaceRoot, {});
37
+ let command = `${pmc.exec} nx g ${plugin}:init ${verbose ? '--verbose' : ''}`;
38
+ if (!!schema.properties['keepExistingVersions']) {
39
+ command += ` --keepExistingVersions`;
40
+ }
41
+ if (updatePackageScripts && !!schema.properties['updatePackageScripts']) {
42
+ command += ` --updatePackageScripts`;
43
+ }
44
+ (0, child_process_1.execSync)(command, {
38
45
  stdio: [0, 1, 2],
39
46
  cwd: repoRoot,
40
47
  windowsHide: false,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commandsObject = exports.parserConfiguration = void 0;
4
4
  const chalk = require("chalk");
5
5
  const yargs = require("yargs");
6
- const command_object_1 = require("./activate-powerpack/command-object");
6
+ const command_object_1 = require("./register/command-object");
7
7
  const command_object_2 = require("./affected/command-object");
8
8
  const command_object_3 = require("./connect/command-object");
9
9
  const command_object_4 = require("./daemon/command-object");
@@ -46,7 +46,7 @@ exports.commandsObject = yargs
46
46
  .parserConfiguration(exports.parserConfiguration)
47
47
  .usage(chalk.bold('Smart Monorepos · Fast CI'))
48
48
  .demandCommand(1, '')
49
- .command(command_object_1.yargsActivatePowerpackCommand)
49
+ .command(command_object_1.yargsRegisterCommand)
50
50
  .command(command_object_22.yargsAddCommand)
51
51
  .command(command_object_2.yargsAffectedBuildCommand)
52
52
  .command(command_object_2.yargsAffectedCommand)
@@ -99,7 +99,7 @@ function createMissingConformanceCommand(command) {
99
99
  output_1.output.error({
100
100
  title: `${command} is not available`,
101
101
  bodyLines: [
102
- `In order to use the \`nx ${command}\` command you must have an active Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
102
+ `In order to use the \`nx ${command}\` command you must have an active Nx key and the \`@nx/conformance\` plugin installed.`,
103
103
  '',
104
104
  'To learn more, visit https://nx.dev/nx-enterprise/powerpack/conformance',
105
105
  ],
@@ -110,7 +110,14 @@ function createMissingConformanceCommand(command) {
110
110
  }
111
111
  function resolveConformanceCommandObject() {
112
112
  try {
113
- const { yargsConformanceCommand } = require('@nx/powerpack-conformance');
113
+ const { yargsConformanceCommand } = (() => {
114
+ try {
115
+ return require('@nx/powerpack-conformance');
116
+ }
117
+ catch {
118
+ return require('@nx/conformance');
119
+ }
120
+ })();
114
121
  return yargsConformanceCommand;
115
122
  }
116
123
  catch {
@@ -119,7 +126,14 @@ function resolveConformanceCommandObject() {
119
126
  }
120
127
  function resolveConformanceCheckCommandObject() {
121
128
  try {
122
- const { yargsConformanceCheckCommand, } = require('@nx/powerpack-conformance');
129
+ const { yargsConformanceCheckCommand } = (() => {
130
+ try {
131
+ return require('@nx/powerpack-conformance');
132
+ }
133
+ catch {
134
+ return require('@nx/conformance');
135
+ }
136
+ })();
123
137
  return yargsConformanceCheckCommand;
124
138
  }
125
139
  catch {
@@ -0,0 +1,6 @@
1
+ import { CommandModule } from 'yargs';
2
+ export interface RegisterOptions {
3
+ key?: string;
4
+ verbose?: boolean;
5
+ }
6
+ export declare const yargsRegisterCommand: CommandModule<{}, RegisterOptions>;
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.yargsActivatePowerpackCommand = void 0;
3
+ exports.yargsRegisterCommand = void 0;
4
4
  const shared_options_1 = require("../yargs-utils/shared-options");
5
5
  const handle_errors_1 = require("../../utils/handle-errors");
6
- exports.yargsActivatePowerpackCommand = {
7
- command: 'activate-powerpack <license>',
6
+ exports.yargsRegisterCommand = {
7
+ command: 'register [key]',
8
+ aliases: ['activate-powerpack'],
8
9
  describe: false,
9
- // describe: 'Activate a Nx Powerpack license.',
10
10
  builder: (yargs) => (0, shared_options_1.withVerbose)(yargs)
11
11
  .parserConfiguration({
12
12
  'strip-dashed': true,
13
13
  'unknown-options-as-args': true,
14
14
  })
15
- .positional('license', {
15
+ .positional('key', {
16
16
  type: 'string',
17
- description: 'This is a License Key for Nx Powerpack.',
17
+ description: 'This is a key for Nx.',
18
18
  })
19
- .example('$0 activate-powerpack <license key>', 'Activate a Nx Powerpack license'),
19
+ .example('$0 register <key>', 'Register a Nx key'),
20
20
  handler: async (args) => {
21
- const exitCode = await (0, handle_errors_1.handleErrors)(args.verbose, async () => {
22
- return (await Promise.resolve().then(() => require('./activate-powerpack'))).handleActivatePowerpack(args);
21
+ const exitCode = await (0, handle_errors_1.handleErrors)(args.verbose ?? false, async () => {
22
+ return (await Promise.resolve().then(() => require('./register'))).handleRegister(args);
23
23
  });
24
24
  process.exit(exitCode);
25
25
  },
@@ -0,0 +1,2 @@
1
+ import { RegisterOptions } from './command-object';
2
+ export declare function handleRegister(options: RegisterOptions): Promise<import("@nx/key").NxKey>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRegister = handleRegister;
4
+ const workspace_root_1 = require("../../utils/workspace-root");
5
+ const enquirer_1 = require("enquirer");
6
+ const require_nx_key_1 = require("../../utils/require-nx-key");
7
+ async function handleRegister(options) {
8
+ const nxKey = await (0, require_nx_key_1.requireNxKey)();
9
+ // If a key was provided through options, activate it directly
10
+ if (options.key) {
11
+ return nxKey.activateNxKey(workspace_root_1.workspaceRoot, options.key);
12
+ }
13
+ // Try to auto-register a key
14
+ const generatedKey = await nxKey.autoRegisterNxKey(workspace_root_1.workspaceRoot);
15
+ if (generatedKey) {
16
+ return;
17
+ }
18
+ // If auto-registration was skipped, prompt for a key
19
+ const { key } = await (0, enquirer_1.prompt)({
20
+ type: 'input',
21
+ name: 'key',
22
+ message: 'Enter your key',
23
+ });
24
+ return nxKey.activateNxKey(workspace_root_1.workspaceRoot, key);
25
+ }
@@ -1,7 +1,7 @@
1
1
  import { PackageManager } from '../../utils/package-manager';
2
2
  import { PackageJson } from '../../utils/package-json';
3
3
  import { NxJsonConfiguration } from '../../config/nx-json';
4
- import type { PowerpackLicense } from '@nx/powerpack-license';
4
+ import { type NxKey } from '@nx/key';
5
5
  export declare const packagesWeCareAbout: string[];
6
6
  export declare const patternsWeIgnoreInCommunityReport: Array<string | RegExp>;
7
7
  /**
@@ -16,8 +16,8 @@ export declare function reportHandler(): Promise<void>;
16
16
  export interface ReportData {
17
17
  pm: PackageManager;
18
18
  pmVersion: string;
19
- powerpackLicense: PowerpackLicense | null;
20
- powerpackError: Error | null;
19
+ nxKey: NxKey | null;
20
+ nxKeyError: Error | null;
21
21
  powerpackPlugins: PackageJson[];
22
22
  localPlugins: string[];
23
23
  communityPlugins: PackageJson[];
@@ -36,6 +36,10 @@ export interface ReportData {
36
36
  };
37
37
  projectGraphError?: Error | null;
38
38
  nativeTarget: string | null;
39
+ cache: {
40
+ max: number;
41
+ used: number;
42
+ } | null;
39
43
  }
40
44
  export declare function getReportData(): Promise<ReportData>;
41
45
  interface OutOfSyncPackageGroup {
@@ -21,7 +21,10 @@ const installed_plugins_1 = require("../../utils/plugins/installed-plugins");
21
21
  const installation_directory_1 = require("../../utils/installation-directory");
22
22
  const nx_json_1 = require("../../config/nx-json");
23
23
  const error_types_1 = require("../../project-graph/error-types");
24
- const powerpack_1 = require("../../utils/powerpack");
24
+ const nx_key_1 = require("../../utils/nx-key");
25
+ const cache_1 = require("../../tasks-runner/cache");
26
+ const native_1 = require("../../native");
27
+ const cache_directory_1 = require("../../utils/cache-directory");
25
28
  const nxPackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(__dirname, '../../../package.json'));
26
29
  exports.packagesWeCareAbout = [
27
30
  'lerna',
@@ -46,7 +49,7 @@ const LINE_SEPARATOR = '---------------------------------------';
46
49
  *
47
50
  */
48
51
  async function reportHandler() {
49
- const { pm, pmVersion, powerpackLicense, powerpackError, localPlugins, powerpackPlugins, communityPlugins, registeredPlugins, packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, nativeTarget, } = await getReportData();
52
+ const { pm, pmVersion, nxKey, nxKeyError, localPlugins, powerpackPlugins, communityPlugins, registeredPlugins, packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, nativeTarget, cache, } = await getReportData();
50
53
  const fields = [
51
54
  ['Node', process.versions.node],
52
55
  ['OS', `${process.platform}-${process.arch}`],
@@ -61,29 +64,29 @@ async function reportHandler() {
61
64
  packageVersionsWeCareAbout.forEach((p) => {
62
65
  bodyLines.push(`${chalk.green(p.package.padEnd(padding))} : ${chalk.bold(p.version)}`);
63
66
  });
64
- if (powerpackLicense) {
67
+ if (nxKey) {
65
68
  bodyLines.push('');
66
69
  bodyLines.push(LINE_SEPARATOR);
67
- bodyLines.push(chalk.green('Nx Powerpack'));
68
- const licenseExpiryDate = new Date((powerpackLicense.realExpiresAt ?? powerpackLicense.expiresAt) * 1000);
69
- bodyLines.push(`Licensed to ${powerpackLicense.organizationName} for ${powerpackLicense.seatCount} user${powerpackLicense.seatCount > 1 ? 's' : ''} in ${powerpackLicense.workspaceCount === 9999
70
- ? 'an unlimited number of'
71
- : powerpackLicense.workspaceCount} workspace${powerpackLicense.workspaceCount > 1 ? 's' : ''}.`);
72
- // license is not expired
73
- if (licenseExpiryDate.getTime() >= Date.now()) {
74
- if ('perpetualNxVersion' in powerpackLicense) {
75
- bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${powerpackLicense.perpetualNxVersion} and below.`);
76
- }
77
- else {
78
- bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}.`);
79
- }
80
- }
81
- else {
82
- if ('perpetualNxVersion' in powerpackLicense) {
83
- bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${powerpackLicense.perpetualNxVersion} and below.`);
70
+ bodyLines.push(chalk.green('Nx key licensed packages'));
71
+ bodyLines.push((0, nx_key_1.createNxKeyLicenseeInformation)(nxKey));
72
+ if (nxKey.realExpiresAt || nxKey.expiresAt) {
73
+ const licenseExpiryDate = new Date((nxKey.realExpiresAt ?? nxKey.expiresAt) * 1000);
74
+ // license is not expired
75
+ if (licenseExpiryDate.getTime() >= Date.now()) {
76
+ if ('perpetualNxVersion' in nxKey) {
77
+ bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${nxKey.perpetualNxVersion} and below.`);
78
+ }
79
+ else {
80
+ bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}.`);
81
+ }
84
82
  }
85
83
  else {
86
- bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}.`);
84
+ if ('perpetualNxVersion' in nxKey) {
85
+ bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${nxKey.perpetualNxVersion} and below.`);
86
+ }
87
+ else {
88
+ bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}.`);
89
+ }
87
90
  }
88
91
  }
89
92
  bodyLines.push('');
@@ -94,11 +97,11 @@ async function reportHandler() {
94
97
  }
95
98
  bodyLines.push('');
96
99
  }
97
- else if (powerpackError) {
100
+ else if (nxKeyError) {
98
101
  bodyLines.push('');
99
- bodyLines.push(chalk.red('Nx Powerpack'));
102
+ bodyLines.push(chalk.red('Nx key'));
100
103
  bodyLines.push(LINE_SEPARATOR);
101
- bodyLines.push(powerpackError.message);
104
+ bodyLines.push(nxKeyError.message);
102
105
  bodyLines.push('');
103
106
  }
104
107
  if (registeredPlugins.length) {
@@ -123,6 +126,10 @@ async function reportHandler() {
123
126
  bodyLines.push(`\t ${chalk.green(plugin)}`);
124
127
  }
125
128
  }
129
+ if (cache) {
130
+ bodyLines.push(LINE_SEPARATOR);
131
+ bodyLines.push(`Cache Usage: ${(0, cache_1.formatCacheSize)(cache.used)} / ${cache.max === 0 ? '∞' : (0, cache_1.formatCacheSize)(cache.max)}`);
132
+ }
126
133
  if (outOfSyncPackageGroup) {
127
134
  bodyLines.push(LINE_SEPARATOR);
128
135
  bodyLines.push(`The following packages should match the installed version of ${outOfSyncPackageGroup.basePackage}`);
@@ -165,20 +172,28 @@ async function getReportData() {
165
172
  }
166
173
  const outOfSyncPackageGroup = findMisalignedPackagesForPackage(nxPackageJson);
167
174
  const native = isNativeAvailable();
168
- let powerpackLicense = null;
169
- let powerpackError = null;
175
+ let nxKey = null;
176
+ let nxKeyError = null;
170
177
  try {
171
- powerpackLicense = await (0, powerpack_1.getPowerpackLicenseInformation)();
178
+ nxKey = await (0, nx_key_1.getNxKeyInformation)();
172
179
  }
173
180
  catch (e) {
174
- if (!(e instanceof powerpack_1.NxPowerpackNotInstalledError)) {
175
- powerpackError = e;
181
+ if (!(e instanceof nx_key_1.NxKeyNotInstalledError)) {
182
+ nxKeyError = e;
176
183
  }
177
184
  }
185
+ let cache = (0, cache_1.dbCacheEnabled)(nxJson)
186
+ ? {
187
+ max: nxJson.maxCacheSize !== undefined
188
+ ? (0, cache_1.parseMaxCacheSize)(nxJson.maxCacheSize)
189
+ : (0, native_1.getDefaultMaxCacheSize)(cache_directory_1.cacheDir),
190
+ used: new cache_1.DbCache({ nxCloudRemoteCache: null }).getUsedCacheSpace(),
191
+ }
192
+ : null;
178
193
  return {
179
194
  pm,
180
- powerpackLicense,
181
- powerpackError,
195
+ nxKey,
196
+ nxKeyError,
182
197
  powerpackPlugins,
183
198
  pmVersion,
184
199
  localPlugins,
@@ -188,6 +203,7 @@ async function getReportData() {
188
203
  outOfSyncPackageGroup,
189
204
  projectGraphError,
190
205
  nativeTarget: native ? native.getBinaryTarget() : null,
206
+ cache,
191
207
  };
192
208
  }
193
209
  async function tryGetProjectGraph() {
@@ -256,7 +272,7 @@ function findMisalignedPackagesForPackage(base) {
256
272
  }
257
273
  function findInstalledPowerpackPlugins() {
258
274
  const installedPlugins = (0, installed_plugins_1.findInstalledPlugins)();
259
- return installedPlugins.filter((dep) => new RegExp('@nx/powerpack*').test(dep.name));
275
+ return installedPlugins.filter((dep) => new RegExp('@nx/powerpack*|@nx/(.+)-cache|@nx/(conformance|owners|enterprise*)').test(dep.name));
260
276
  }
261
277
  function findInstalledCommunityPlugins() {
262
278
  const installedPlugins = (0, installed_plugins_1.findInstalledPlugins)();
@@ -42,6 +42,7 @@ export declare class NxCache {
42
42
  put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
43
43
  applyRemoteCacheResults(hash: string, result: CachedResult, outputs: Array<string>): void
44
44
  getTaskOutputsPath(hash: string): string
45
+ getCacheSize(): number
45
46
  copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): number
46
47
  removeOldCacheRecords(): void
47
48
  checkCacheFsInSync(): boolean
@@ -166,6 +167,8 @@ export declare export function findImports(projectFileMap: Record<string, Array<
166
167
 
167
168
  export declare export function getBinaryTarget(): string
168
169
 
170
+ export declare export function getDefaultMaxCacheSize(cachePath: string): number
171
+
169
172
  /**
170
173
  * Expands the given outputs into a list of existing files.
171
174
  * This is used when hashing outputs
@@ -379,6 +379,7 @@ module.exports.EventType = nativeBinding.EventType
379
379
  module.exports.expandOutputs = nativeBinding.expandOutputs
380
380
  module.exports.findImports = nativeBinding.findImports
381
381
  module.exports.getBinaryTarget = nativeBinding.getBinaryTarget
382
+ module.exports.getDefaultMaxCacheSize = nativeBinding.getDefaultMaxCacheSize
382
383
  module.exports.getFilesForOutputs = nativeBinding.getFilesForOutputs
383
384
  module.exports.getTransformableOutputs = nativeBinding.getTransformableOutputs
384
385
  module.exports.hashArray = nativeBinding.hashArray
Binary file
@@ -26,6 +26,7 @@ export declare class DbCache {
26
26
  });
27
27
  init(): Promise<void>;
28
28
  get(task: Task): Promise<CachedResult | null>;
29
+ getUsedCacheSpace(): number;
29
30
  private applyRemoteCacheResults;
30
31
  put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
31
32
  copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<number>;
@@ -33,11 +34,11 @@ export declare class DbCache {
33
34
  temporaryOutputPath(task: Task): string;
34
35
  private getRemoteCache;
35
36
  private _getRemoteCache;
36
- private getPowerpackS3Cache;
37
- private getPowerpackSharedCache;
38
- private getPowerpackGcsCache;
39
- private getPowerpackAzureCache;
40
- private getPowerpackCache;
37
+ private getS3Cache;
38
+ private getSharedCache;
39
+ private getGcsCache;
40
+ private getAzureCache;
41
+ private resolveRemoteCache;
41
42
  private resolvePackage;
42
43
  private assertCacheIsValid;
43
44
  }
@@ -76,4 +77,5 @@ export declare class Cache {
76
77
  *
77
78
  * @param maxCacheSize Max cache size as specified in nx.json
78
79
  */
79
- export declare function parseMaxCacheSize(maxCacheSize: string): number | undefined;
80
+ export declare function parseMaxCacheSize(maxCacheSize: string | number): number | undefined;
81
+ export declare function formatCacheSize(maxCacheSize: number, decimals?: number): string;
@@ -4,6 +4,7 @@ exports.Cache = exports.DbCache = void 0;
4
4
  exports.dbCacheEnabled = dbCacheEnabled;
5
5
  exports.getCache = getCache;
6
6
  exports.parseMaxCacheSize = parseMaxCacheSize;
7
+ exports.formatCacheSize = formatCacheSize;
7
8
  const workspace_root_1 = require("../utils/workspace-root");
8
9
  const path_1 = require("path");
9
10
  const perf_hooks_1 = require("perf_hooks");
@@ -70,7 +71,9 @@ class DbCache {
70
71
  constructor(options) {
71
72
  this.options = options;
72
73
  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));
74
+ this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)(), undefined, this.nxJson.maxCacheSize !== undefined
75
+ ? parseMaxCacheSize(this.nxJson.maxCacheSize)
76
+ : (0, native_1.getDefaultMaxCacheSize)(cache_directory_1.cacheDir));
74
77
  this.isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
75
78
  }
76
79
  async init() {
@@ -107,6 +110,9 @@ class DbCache {
107
110
  return null;
108
111
  }
109
112
  }
113
+ getUsedCacheSpace() {
114
+ return this.cache.getCacheSize();
115
+ }
110
116
  applyRemoteCacheResults(hash, res, outputs) {
111
117
  return this.cache.applyRemoteCacheResults(hash, res, outputs);
112
118
  }
@@ -157,26 +163,38 @@ class DbCache {
157
163
  }
158
164
  }
159
165
  else {
160
- return ((await this.getPowerpackS3Cache()) ??
161
- (await this.getPowerpackSharedCache()) ??
162
- (await this.getPowerpackGcsCache()) ??
163
- (await this.getPowerpackAzureCache()) ??
166
+ return ((await this.getS3Cache()) ??
167
+ (await this.getSharedCache()) ??
168
+ (await this.getGcsCache()) ??
169
+ (await this.getAzureCache()) ??
164
170
  null);
165
171
  }
166
172
  }
167
- getPowerpackS3Cache() {
168
- return this.getPowerpackCache('@nx/powerpack-s3-cache');
169
- }
170
- getPowerpackSharedCache() {
171
- return this.getPowerpackCache('@nx/powerpack-shared-fs-cache');
172
- }
173
- getPowerpackGcsCache() {
174
- return this.getPowerpackCache('@nx/powerpack-gcs-cache');
175
- }
176
- getPowerpackAzureCache() {
177
- return this.getPowerpackCache('@nx/powerpack-azure-cache');
178
- }
179
- async getPowerpackCache(pkg) {
173
+ async getS3Cache() {
174
+ const cache = await this.resolveRemoteCache('@nx/s3-cache');
175
+ if (cache)
176
+ return cache;
177
+ return this.resolveRemoteCache('@nx/powerpack-s3-cache');
178
+ }
179
+ async getSharedCache() {
180
+ const cache = await this.resolveRemoteCache('@nx/shared-fs-cache');
181
+ if (cache)
182
+ return cache;
183
+ return this.resolveRemoteCache('@nx/powerpack-shared-fs-cache');
184
+ }
185
+ async getGcsCache() {
186
+ const cache = await this.resolveRemoteCache('@nx/gcs-cache');
187
+ if (cache)
188
+ return cache;
189
+ return this.resolveRemoteCache('@nx/powerpack-gcs-cache');
190
+ }
191
+ async getAzureCache() {
192
+ const cache = await this.resolveRemoteCache('@nx/azure-cache');
193
+ if (cache)
194
+ return cache;
195
+ return this.resolveRemoteCache('@nx/powerpack-azure-cache');
196
+ }
197
+ async resolveRemoteCache(pkg) {
180
198
  let getRemoteCache = null;
181
199
  try {
182
200
  getRemoteCache = (await Promise.resolve(`${this.resolvePackage(pkg)}`).then(s => require(s))).getRemoteCache;
@@ -467,10 +485,14 @@ function tryAndRetry(fn) {
467
485
  * @param maxCacheSize Max cache size as specified in nx.json
468
486
  */
469
487
  function parseMaxCacheSize(maxCacheSize) {
470
- if (!maxCacheSize) {
488
+ if (maxCacheSize === null || maxCacheSize === undefined) {
471
489
  return undefined;
472
490
  }
473
- let regexResult = maxCacheSize.match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
491
+ let regexResult = maxCacheSize
492
+ // Covers folks who accidentally specify as a number rather than a string
493
+ .toString()
494
+ // Match a number followed by an optional unit (KB, MB, GB), with optional whitespace between the number and unit
495
+ .match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
474
496
  if (!regexResult) {
475
497
  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
498
  }
@@ -494,3 +516,13 @@ function parseMaxCacheSize(maxCacheSize) {
494
516
  return size;
495
517
  }
496
518
  }
519
+ function formatCacheSize(maxCacheSize, decimals = 2) {
520
+ const exponents = ['B', 'KB', 'MB', 'GB'];
521
+ let exponent = 0;
522
+ let size = maxCacheSize;
523
+ while (size >= 1024 && exponent < exponents.length - 1) {
524
+ size /= 1024;
525
+ exponent++;
526
+ }
527
+ return `${size.toFixed(decimals)} ${exponents[exponent]}`;
528
+ }
@@ -36,7 +36,7 @@ const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle
36
36
  const task_graph_utils_1 = require("./task-graph-utils");
37
37
  const utils_1 = require("./utils");
38
38
  const chalk = require("chalk");
39
- const powerpack_1 = require("../utils/powerpack");
39
+ const nx_key_1 = require("../utils/nx-key");
40
40
  const tasks_execution_hooks_1 = require("../project-graph/plugins/tasks-execution-hooks");
41
41
  async function getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides) {
42
42
  const { runnerOptions } = getRunner(nxArgs, nxJson);
@@ -141,7 +141,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
141
141
  initiatingProject,
142
142
  });
143
143
  await renderIsDone;
144
- await (0, powerpack_1.printPowerpackLicense)();
144
+ await (0, nx_key_1.printNxKey)();
145
145
  return taskResults;
146
146
  }
147
147
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
@@ -0,0 +1,7 @@
1
+ import type { NxKey } from '@nx/key';
2
+ export declare function createNxKeyLicenseeInformation(nxKey: NxKey): string;
3
+ export declare function printNxKey(): Promise<void>;
4
+ export declare function getNxKeyInformation(): Promise<NxKey | null>;
5
+ export declare class NxKeyNotInstalledError extends Error {
6
+ constructor(e: Error);
7
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxKeyNotInstalledError = void 0;
4
+ exports.createNxKeyLicenseeInformation = createNxKeyLicenseeInformation;
5
+ exports.printNxKey = printNxKey;
6
+ exports.getNxKeyInformation = getNxKeyInformation;
7
+ const logger_1 = require("./logger");
8
+ const package_manager_1 = require("./package-manager");
9
+ const workspace_root_1 = require("./workspace-root");
10
+ function createNxKeyLicenseeInformation(nxKey) {
11
+ if ('isPowerpack' in nxKey && nxKey.isPowerpack) {
12
+ return `Licensed to ${nxKey.organizationName} for ${nxKey.seatCount} user${nxKey.seatCount > 1 ? 's' : ''} in ${nxKey.workspaceCount === 9999
13
+ ? 'an unlimited number of'
14
+ : nxKey.workspaceCount} workspace${nxKey.workspaceCount > 1 ? 's' : ''}.`;
15
+ }
16
+ else {
17
+ return `Licensed to ${nxKey.organizationName}.`;
18
+ }
19
+ }
20
+ async function printNxKey() {
21
+ try {
22
+ const key = await getNxKeyInformation();
23
+ if (key) {
24
+ logger_1.logger.log(createNxKeyLicenseeInformation(key));
25
+ }
26
+ }
27
+ catch { }
28
+ }
29
+ async function getNxKeyInformation() {
30
+ try {
31
+ const { getPowerpackLicenseInformation, getPowerpackLicenseInformationAsync, } = (await Promise.resolve().then(() => require('@nx/powerpack-license')));
32
+ return (getPowerpackLicenseInformationAsync ?? getPowerpackLicenseInformation)(workspace_root_1.workspaceRoot);
33
+ }
34
+ catch (e) {
35
+ try {
36
+ const { getNxKeyInformationAsync } = (await Promise.resolve().then(() => require('@nx/key')));
37
+ return getNxKeyInformationAsync(workspace_root_1.workspaceRoot);
38
+ }
39
+ catch (e) {
40
+ if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
41
+ throw new NxKeyNotInstalledError(e);
42
+ }
43
+ throw e;
44
+ }
45
+ }
46
+ }
47
+ class NxKeyNotInstalledError extends Error {
48
+ constructor(e) {
49
+ super(`The "@nx/key" package is needed to use Nx key enabled features. Please install it with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/key`, { cause: e });
50
+ }
51
+ }
52
+ exports.NxKeyNotInstalledError = NxKeyNotInstalledError;
@@ -0,0 +1 @@
1
+ export declare function requireNxKey(): Promise<typeof import('@nx/key')>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireNxKey = requireNxKey;
4
+ const child_process_1 = require("child_process");
5
+ const package_manager_1 = require("./package-manager");
6
+ async function requireNxKey() {
7
+ // @ts-ignore
8
+ return Promise.resolve().then(() => require('@nx/key')).catch(async (e) => {
9
+ if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
10
+ try {
11
+ (0, child_process_1.execSync)(`${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/key@latest`, {
12
+ windowsHide: false,
13
+ });
14
+ // @ts-ignore
15
+ return await Promise.resolve().then(() => require('@nx/key'));
16
+ }
17
+ catch (e) {
18
+ throw new Error('Failed to install @nx/key. Please install @nx/key and try again.');
19
+ }
20
+ }
21
+ });
22
+ }
@@ -1,2 +0,0 @@
1
- import { ActivatePowerpackOptions } from './command-object';
2
- export declare function handleActivatePowerpack(options: ActivatePowerpackOptions): Promise<void>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleActivatePowerpack = handleActivatePowerpack;
4
- const workspace_root_1 = require("../../utils/workspace-root");
5
- const enquirer_1 = require("enquirer");
6
- const child_process_1 = require("child_process");
7
- const package_manager_1 = require("../../utils/package-manager");
8
- async function handleActivatePowerpack(options) {
9
- const license = options.license ??
10
- (await (0, enquirer_1.prompt)({
11
- type: 'input',
12
- name: 'license',
13
- message: 'Enter your License Key',
14
- }));
15
- const { activatePowerpack } = await requirePowerpack();
16
- activatePowerpack(workspace_root_1.workspaceRoot, license);
17
- }
18
- async function requirePowerpack() {
19
- // @ts-ignore
20
- return Promise.resolve().then(() => require('@nx/powerpack-license')).catch(async (e) => {
21
- if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
22
- try {
23
- (0, child_process_1.execSync)(`${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/powerpack-license@latest`, {
24
- windowsHide: false,
25
- });
26
- // @ts-ignore
27
- return await Promise.resolve().then(() => require('@nx/powerpack-license'));
28
- }
29
- catch (e) {
30
- throw new Error('Failed to install @nx/powerpack-license. Please install @nx/powerpack-license and try again.');
31
- }
32
- }
33
- });
34
- }
@@ -1,6 +0,0 @@
1
- import { CommandModule } from 'yargs';
2
- export interface ActivatePowerpackOptions {
3
- license: string;
4
- verbose: boolean;
5
- }
6
- export declare const yargsActivatePowerpackCommand: CommandModule<{}, ActivatePowerpackOptions>;
@@ -1,5 +0,0 @@
1
- export declare function printPowerpackLicense(): Promise<void>;
2
- export declare function getPowerpackLicenseInformation(): Promise<import("@nx/powerpack-license").PowerpackLicense>;
3
- export declare class NxPowerpackNotInstalledError extends Error {
4
- constructor(e: Error);
5
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NxPowerpackNotInstalledError = void 0;
4
- exports.printPowerpackLicense = printPowerpackLicense;
5
- exports.getPowerpackLicenseInformation = getPowerpackLicenseInformation;
6
- const logger_1 = require("./logger");
7
- const package_manager_1 = require("./package-manager");
8
- const workspace_root_1 = require("./workspace-root");
9
- async function printPowerpackLicense() {
10
- try {
11
- const { organizationName, seatCount, workspaceCount } = await getPowerpackLicenseInformation();
12
- logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? 's' : ''} in ${workspaceCount === 9999 ? 'an unlimited number of' : workspaceCount} workspace${workspaceCount > 1 ? 's' : ''}`);
13
- }
14
- catch { }
15
- }
16
- async function getPowerpackLicenseInformation() {
17
- try {
18
- const { getPowerpackLicenseInformation, getPowerpackLicenseInformationAsync, } = (await Promise.resolve().then(() => require('@nx/powerpack-license')));
19
- return (getPowerpackLicenseInformationAsync ?? getPowerpackLicenseInformation)(workspace_root_1.workspaceRoot);
20
- }
21
- catch (e) {
22
- if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
23
- throw new NxPowerpackNotInstalledError(e);
24
- }
25
- throw e;
26
- }
27
- }
28
- class NxPowerpackNotInstalledError extends Error {
29
- constructor(e) {
30
- super(`The "@nx/powerpack-license" package is needed to use Nx Powerpack enabled features. Please install the @nx/powerpack-license with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/powerpack-license`, { cause: e });
31
- }
32
- }
33
- exports.NxPowerpackNotInstalledError = NxPowerpackNotInstalledError;