nx 20.6.0-beta.0 → 20.6.0-beta.1

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,10 +131,8 @@
131
131
  "@nx/nx-win32-arm64-msvc",
132
132
  "@nx/nx-freebsd-x64",
133
133
  "@nx/powerpack-license",
134
- "@nx/key",
135
134
  // Powerpack plugin conditionally available dynamically at runtime
136
- "@nx/powerpack-conformance",
137
- "@nx/conformance"
135
+ "@nx/powerpack-conformance"
138
136
  ]
139
137
  }
140
138
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.6.0-beta.0",
3
+ "version": "20.6.0-beta.1",
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": {
@@ -38,7 +38,7 @@
38
38
  "@yarnpkg/lockfile": "^1.1.0",
39
39
  "@yarnpkg/parsers": "3.0.2",
40
40
  "@zkochan/js-yaml": "0.0.7",
41
- "axios": "^1.7.4",
41
+ "axios": "^1.8.3",
42
42
  "chalk": "^4.1.0",
43
43
  "cli-cursor": "3.1.0",
44
44
  "cli-spinners": "2.6.1",
@@ -82,16 +82,16 @@
82
82
  }
83
83
  },
84
84
  "optionalDependencies": {
85
- "@nx/nx-darwin-arm64": "20.6.0-beta.0",
86
- "@nx/nx-darwin-x64": "20.6.0-beta.0",
87
- "@nx/nx-freebsd-x64": "20.6.0-beta.0",
88
- "@nx/nx-linux-arm-gnueabihf": "20.6.0-beta.0",
89
- "@nx/nx-linux-arm64-gnu": "20.6.0-beta.0",
90
- "@nx/nx-linux-arm64-musl": "20.6.0-beta.0",
91
- "@nx/nx-linux-x64-gnu": "20.6.0-beta.0",
92
- "@nx/nx-linux-x64-musl": "20.6.0-beta.0",
93
- "@nx/nx-win32-arm64-msvc": "20.6.0-beta.0",
94
- "@nx/nx-win32-x64-msvc": "20.6.0-beta.0"
85
+ "@nx/nx-darwin-arm64": "20.6.0-beta.1",
86
+ "@nx/nx-darwin-x64": "20.6.0-beta.1",
87
+ "@nx/nx-freebsd-x64": "20.6.0-beta.1",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.6.0-beta.1",
89
+ "@nx/nx-linux-arm64-gnu": "20.6.0-beta.1",
90
+ "@nx/nx-linux-arm64-musl": "20.6.0-beta.1",
91
+ "@nx/nx-linux-x64-gnu": "20.6.0-beta.1",
92
+ "@nx/nx-linux-x64-musl": "20.6.0-beta.1",
93
+ "@nx/nx-win32-arm64-msvc": "20.6.0-beta.1",
94
+ "@nx/nx-win32-x64-msvc": "20.6.0-beta.1"
95
95
  },
96
96
  "nx-migrations": {
97
97
  "migrations": "./migrations.json",
@@ -0,0 +1,2 @@
1
+ import { ActivatePowerpackOptions } from './command-object';
2
+ export declare function handleActivatePowerpack(options: ActivatePowerpackOptions): Promise<void>;
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ import { CommandModule } from 'yargs';
2
+ export interface ActivatePowerpackOptions {
3
+ license: string;
4
+ verbose: boolean;
5
+ }
6
+ export declare const yargsActivatePowerpackCommand: CommandModule<{}, ActivatePowerpackOptions>;
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.yargsRegisterCommand = void 0;
3
+ exports.yargsActivatePowerpackCommand = 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.yargsRegisterCommand = {
7
- command: 'register <key>',
8
- aliases: ['activate-powerpack'],
6
+ exports.yargsActivatePowerpackCommand = {
7
+ command: 'activate-powerpack <license>',
9
8
  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('key', {
15
+ .positional('license', {
16
16
  type: 'string',
17
- description: 'This is a key for Nx.',
17
+ description: 'This is a License Key for Nx Powerpack.',
18
18
  })
19
- .example('$0 register <key>', 'Register a Nx key'),
19
+ .example('$0 activate-powerpack <license key>', 'Activate a Nx Powerpack license'),
20
20
  handler: async (args) => {
21
- const exitCode = await (0, handle_errors_1.handleErrors)(args.verbose ?? false, async () => {
22
- return (await Promise.resolve().then(() => require('./register'))).handleRegister(args);
21
+ const exitCode = await (0, handle_errors_1.handleErrors)(args.verbose, async () => {
22
+ return (await Promise.resolve().then(() => require('./activate-powerpack'))).handleActivatePowerpack(args);
23
23
  });
24
24
  process.exit(exitCode);
25
25
  },
@@ -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,
@@ -156,6 +156,7 @@ const npmPackageToPluginMap = {
156
156
  'react-native': '@nx/react-native',
157
157
  '@remix-run/dev': '@nx/remix',
158
158
  '@rsbuild/core': '@nx/rsbuild',
159
+ '@react-router/dev': '@nx/react',
159
160
  };
160
161
  async function detectPlugins(nxJson, interactive, includeAngularCli) {
161
162
  let files = ['package.json'].concat((0, workspace_context_1.globWithWorkspaceContextSync)(process.cwd(), ['**/*/package.json']));
@@ -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("./register/command-object");
6
+ const command_object_1 = require("./activate-powerpack/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.yargsRegisterCommand)
49
+ .command(command_object_1.yargsActivatePowerpackCommand)
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 Nx key and the \`@nx/conformance\` plugin installed.`,
102
+ `In order to use the \`nx ${command}\` command you must have an active Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
103
103
  '',
104
104
  'To learn more, visit https://nx.dev/nx-enterprise/powerpack/conformance',
105
105
  ],
@@ -110,14 +110,7 @@ function createMissingConformanceCommand(command) {
110
110
  }
111
111
  function resolveConformanceCommandObject() {
112
112
  try {
113
- const { yargsConformanceCommand } = (() => {
114
- try {
115
- return require('@nx/powerpack-conformance');
116
- }
117
- catch {
118
- return require('@nx/conformance');
119
- }
120
- })();
113
+ const { yargsConformanceCommand } = require('@nx/powerpack-conformance');
121
114
  return yargsConformanceCommand;
122
115
  }
123
116
  catch {
@@ -126,14 +119,7 @@ function resolveConformanceCommandObject() {
126
119
  }
127
120
  function resolveConformanceCheckCommandObject() {
128
121
  try {
129
- const { yargsConformanceCheckCommand } = (() => {
130
- try {
131
- return require('@nx/powerpack-conformance');
132
- }
133
- catch {
134
- return require('@nx/conformance');
135
- }
136
- })();
122
+ const { yargsConformanceCheckCommand, } = require('@nx/powerpack-conformance');
137
123
  return yargsConformanceCheckCommand;
138
124
  }
139
125
  catch {
@@ -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 NxKey } from '@nx/key';
4
+ import type { PowerpackLicense } from '@nx/powerpack-license';
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
- nxKey: NxKey | null;
20
- nxKeyError: Error | null;
19
+ powerpackLicense: PowerpackLicense | null;
20
+ powerpackError: 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 nx_key_1 = require("../../utils/nx-key");
24
+ const powerpack_1 = require("../../utils/powerpack");
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, nxKey, nxKeyError, localPlugins, powerpackPlugins, communityPlugins, registeredPlugins, packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, nativeTarget, } = await getReportData();
52
+ const { pm, pmVersion, powerpackLicense, powerpackError, 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 (nxKey) {
67
+ if (powerpackLicense) {
65
68
  bodyLines.push('');
66
69
  bodyLines.push(LINE_SEPARATOR);
67
- bodyLines.push(chalk.green('Nx key licensed packages'));
68
- bodyLines.push((0, nx_key_1.createNxKeyLicenseeInformation)(nxKey));
69
- if (nxKey.realExpiresAt || nxKey.expiresAt) {
70
- const licenseExpiryDate = new Date((nxKey.realExpiresAt ?? nxKey.expiresAt) * 1000);
71
- // license is not expired
72
- if (licenseExpiryDate.getTime() >= Date.now()) {
73
- if ('perpetualNxVersion' in nxKey) {
74
- bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${nxKey.perpetualNxVersion} and below.`);
75
- }
76
- else {
77
- bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}.`);
78
- }
70
+ bodyLines.push(chalk.green('Nx Powerpack'));
71
+ const licenseExpiryDate = new Date((powerpackLicense.realExpiresAt ?? powerpackLicense.expiresAt) * 1000);
72
+ bodyLines.push(`Licensed to ${powerpackLicense.organizationName} for ${powerpackLicense.seatCount} user${powerpackLicense.seatCount > 1 ? 's' : ''} in ${powerpackLicense.workspaceCount === 9999
73
+ ? 'an unlimited number of'
74
+ : powerpackLicense.workspaceCount} workspace${powerpackLicense.workspaceCount > 1 ? 's' : ''}.`);
75
+ // license is not expired
76
+ if (licenseExpiryDate.getTime() >= Date.now()) {
77
+ if ('perpetualNxVersion' in powerpackLicense) {
78
+ bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${powerpackLicense.perpetualNxVersion} and below.`);
79
79
  }
80
80
  else {
81
- if ('perpetualNxVersion' in nxKey) {
82
- bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${nxKey.perpetualNxVersion} and below.`);
83
- }
84
- else {
85
- bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}.`);
86
- }
81
+ bodyLines.push(`License expires on ${licenseExpiryDate.toLocaleDateString()}.`);
82
+ }
83
+ }
84
+ else {
85
+ if ('perpetualNxVersion' in powerpackLicense) {
86
+ bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${powerpackLicense.perpetualNxVersion} and below.`);
87
+ }
88
+ else {
89
+ bodyLines.push(`License expired on ${licenseExpiryDate.toLocaleDateString()}.`);
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 (nxKeyError) {
100
+ else if (powerpackError) {
98
101
  bodyLines.push('');
99
- bodyLines.push(chalk.red('Nx key'));
102
+ bodyLines.push(chalk.red('Nx Powerpack'));
100
103
  bodyLines.push(LINE_SEPARATOR);
101
- bodyLines.push(nxKeyError.message);
104
+ bodyLines.push(powerpackError.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 nxKey = null;
169
- let nxKeyError = null;
175
+ let powerpackLicense = null;
176
+ let powerpackError = null;
170
177
  try {
171
- nxKey = await (0, nx_key_1.getNxKeyInformation)();
178
+ powerpackLicense = await (0, powerpack_1.getPowerpackLicenseInformation)();
172
179
  }
173
180
  catch (e) {
174
- if (!(e instanceof nx_key_1.NxKeyNotInstalledError)) {
175
- nxKeyError = e;
181
+ if (!(e instanceof powerpack_1.NxPowerpackNotInstalledError)) {
182
+ powerpackError = 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
- nxKey,
181
- nxKeyError,
195
+ powerpackLicense,
196
+ powerpackError,
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*|@nx/(.+)-cache|@nx/(conformance|owners|enterprise*)').test(dep.name));
275
+ return installedPlugins.filter((dep) => new RegExp('@nx/powerpack*').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 getS3Cache;
37
- private getSharedCache;
38
- private getGcsCache;
39
- private getAzureCache;
40
- private resolveRemoteCache;
37
+ private getPowerpackS3Cache;
38
+ private getPowerpackSharedCache;
39
+ private getPowerpackGcsCache;
40
+ private getPowerpackAzureCache;
41
+ private getPowerpackCache;
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,38 +163,26 @@ class DbCache {
157
163
  }
158
164
  }
159
165
  else {
160
- return ((await this.getS3Cache()) ??
161
- (await this.getSharedCache()) ??
162
- (await this.getGcsCache()) ??
163
- (await this.getAzureCache()) ??
166
+ return ((await this.getPowerpackS3Cache()) ??
167
+ (await this.getPowerpackSharedCache()) ??
168
+ (await this.getPowerpackGcsCache()) ??
169
+ (await this.getPowerpackAzureCache()) ??
164
170
  null);
165
171
  }
166
172
  }
167
- async getS3Cache() {
168
- const cache = await this.resolveRemoteCache('@nx/s3-cache');
169
- if (cache)
170
- return cache;
171
- return this.resolveRemoteCache('@nx/powerpack-s3-cache');
172
- }
173
- async getSharedCache() {
174
- const cache = await this.resolveRemoteCache('@nx/shared-fs-cache');
175
- if (cache)
176
- return cache;
177
- return this.resolveRemoteCache('@nx/powerpack-shared-fs-cache');
178
- }
179
- async getGcsCache() {
180
- const cache = await this.resolveRemoteCache('@nx/gcs-cache');
181
- if (cache)
182
- return cache;
183
- return this.resolveRemoteCache('@nx/powerpack-gcs-cache');
184
- }
185
- async getAzureCache() {
186
- const cache = await this.resolveRemoteCache('@nx/azure-cache');
187
- if (cache)
188
- return cache;
189
- return this.resolveRemoteCache('@nx/powerpack-azure-cache');
190
- }
191
- async resolveRemoteCache(pkg) {
173
+ getPowerpackS3Cache() {
174
+ return this.getPowerpackCache('@nx/powerpack-s3-cache');
175
+ }
176
+ getPowerpackSharedCache() {
177
+ return this.getPowerpackCache('@nx/powerpack-shared-fs-cache');
178
+ }
179
+ getPowerpackGcsCache() {
180
+ return this.getPowerpackCache('@nx/powerpack-gcs-cache');
181
+ }
182
+ getPowerpackAzureCache() {
183
+ return this.getPowerpackCache('@nx/powerpack-azure-cache');
184
+ }
185
+ async getPowerpackCache(pkg) {
192
186
  let getRemoteCache = null;
193
187
  try {
194
188
  getRemoteCache = (await Promise.resolve(`${this.resolvePackage(pkg)}`).then(s => require(s))).getRemoteCache;
@@ -479,10 +473,14 @@ function tryAndRetry(fn) {
479
473
  * @param maxCacheSize Max cache size as specified in nx.json
480
474
  */
481
475
  function parseMaxCacheSize(maxCacheSize) {
482
- if (!maxCacheSize) {
476
+ if (maxCacheSize === null || maxCacheSize === undefined) {
483
477
  return undefined;
484
478
  }
485
- let regexResult = maxCacheSize.match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
479
+ let regexResult = maxCacheSize
480
+ // Covers folks who accidentally specify as a number rather than a string
481
+ .toString()
482
+ // Match a number followed by an optional unit (KB, MB, GB), with optional whitespace between the number and unit
483
+ .match(/^(?<size>[\d|.]+)\s?((?<unit>[KMG]?B)?)$/);
486
484
  if (!regexResult) {
487
485
  throw new Error(`Invalid max cache size specified in nx.json: ${maxCacheSize}. Must be a number followed by an optional unit (KB, MB, GB)`);
488
486
  }
@@ -506,3 +504,13 @@ function parseMaxCacheSize(maxCacheSize) {
506
504
  return size;
507
505
  }
508
506
  }
507
+ function formatCacheSize(maxCacheSize, decimals = 2) {
508
+ const exponents = ['B', 'KB', 'MB', 'GB'];
509
+ let exponent = 0;
510
+ let size = maxCacheSize;
511
+ while (size >= 1024 && exponent < exponents.length - 1) {
512
+ size /= 1024;
513
+ exponent++;
514
+ }
515
+ return `${size.toFixed(decimals)} ${exponents[exponent]}`;
516
+ }
@@ -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 nx_key_1 = require("../utils/nx-key");
39
+ const powerpack_1 = require("../utils/powerpack");
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, nx_key_1.printNxKey)();
144
+ await (0, powerpack_1.printPowerpackLicense)();
145
145
  return taskResults;
146
146
  }
147
147
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
@@ -0,0 +1,5 @@
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
+ }
@@ -0,0 +1,33 @@
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;
@@ -1,6 +0,0 @@
1
- import { CommandModule } from 'yargs';
2
- export interface RegisterOptions {
3
- key?: string;
4
- verbose?: boolean;
5
- }
6
- export declare const yargsRegisterCommand: CommandModule<{}, RegisterOptions>;
@@ -1,2 +0,0 @@
1
- import { RegisterOptions } from './command-object';
2
- export declare function handleRegister(options: RegisterOptions): Promise<import("@nx/key").NxKey>;
@@ -1,25 +0,0 @@
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 +0,0 @@
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
- }
@@ -1,52 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export declare function requireNxKey(): Promise<typeof import('@nx/key')>;
@@ -1,22 +0,0 @@
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
- }