Skip to content

Commit 442058a

Browse files
authored
Revert "feat(core): add activate key (#30250)" (#30295)
1 parent 2057df5 commit 442058a

File tree

11 files changed

+259
-289
lines changed

11 files changed

+259
-289
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@
7878
"@nx/eslint-plugin": "20.5.0-rc.3",
7979
"@nx/jest": "20.5.0-rc.3",
8080
"@nx/js": "20.5.0-rc.3",
81-
"@nx/key": "1.3.0-beta.1",
8281
"@nx/next": "20.5.0-rc.3",
8382
"@nx/playwright": "20.5.0-rc.3",
84-
"@nx/powerpack-conformance": "1.3.0-beta.1",
85-
"@nx/powerpack-enterprise-cloud": "1.3.0-beta.1",
86-
"@nx/powerpack-license": "1.3.0-beta.1",
83+
"@nx/powerpack-conformance": "1.2.5",
84+
"@nx/powerpack-enterprise-cloud": "1.2.5",
85+
"@nx/powerpack-license": "1.2.5",
8786
"@nx/react": "20.5.0-rc.3",
8887
"@nx/rsbuild": "20.5.0-rc.3",
8988
"@nx/rspack": "20.5.0-rc.3",

packages/nx/.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
"@nx/nx-win32-arm64-msvc",
132132
"@nx/nx-freebsd-x64",
133133
"@nx/powerpack-license",
134-
"@nx/key",
135134
// Powerpack plugin conditionally available dynamically at runtime
136135
"@nx/powerpack-conformance"
137136
]

packages/nx/src/command-line/activate-key/activate-key.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { workspaceRoot } from '../../utils/workspace-root';
2+
import { ActivatePowerpackOptions } from './command-object';
3+
import { prompt } from 'enquirer';
4+
import { execSync } from 'child_process';
5+
import { getPackageManagerCommand } from '../../utils/package-manager';
6+
7+
export async function handleActivatePowerpack(
8+
options: ActivatePowerpackOptions
9+
) {
10+
const license =
11+
options.license ??
12+
(await prompt({
13+
type: 'input',
14+
name: 'license',
15+
message: 'Enter your License Key',
16+
}));
17+
const { activatePowerpack } = await requirePowerpack();
18+
activatePowerpack(workspaceRoot, license);
19+
}
20+
21+
async function requirePowerpack(): Promise<any> {
22+
// @ts-ignore
23+
return import('@nx/powerpack-license').catch(async (e) => {
24+
if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
25+
try {
26+
execSync(
27+
`${getPackageManagerCommand().addDev} @nx/powerpack-license@latest`,
28+
{
29+
windowsHide: false,
30+
}
31+
);
32+
33+
// @ts-ignore
34+
return await import('@nx/powerpack-license');
35+
} catch (e) {
36+
throw new Error(
37+
'Failed to install @nx/powerpack-license. Please install @nx/powerpack-license and try again.'
38+
);
39+
}
40+
}
41+
});
42+
}

packages/nx/src/command-line/activate-key/command-object.ts renamed to packages/nx/src/command-line/activate-powerpack/command-object.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { CommandModule } from 'yargs';
22
import { withVerbose } from '../yargs-utils/shared-options';
33
import { handleErrors } from '../../utils/handle-errors';
44

5-
export interface ActivateKeyOptions {
6-
key: string;
5+
export interface ActivatePowerpackOptions {
6+
license: string;
77
verbose: boolean;
88
}
99

10-
export const yargsActivateKeyCommand: CommandModule<{}, ActivateKeyOptions> = {
11-
command: 'activate-key <key>',
12-
aliases: ['activate-powerpack'],
10+
export const yargsActivatePowerpackCommand: CommandModule<
11+
{},
12+
ActivatePowerpackOptions
13+
> = {
14+
command: 'activate-powerpack <license>',
1315
describe: false,
1416
// describe: 'Activate a Nx Powerpack license.',
1517
builder: (yargs) =>
@@ -18,14 +20,19 @@ export const yargsActivateKeyCommand: CommandModule<{}, ActivateKeyOptions> = {
1820
'strip-dashed': true,
1921
'unknown-options-as-args': true,
2022
})
21-
.positional('key', {
23+
.positional('license', {
2224
type: 'string',
23-
description: 'This is a key for Nx.',
25+
description: 'This is a License Key for Nx Powerpack.',
2426
})
25-
.example('$0 activate-key <key>', 'Activate a Nx key'),
27+
.example(
28+
'$0 activate-powerpack <license key>',
29+
'Activate a Nx Powerpack license'
30+
),
2631
handler: async (args) => {
2732
const exitCode = await handleErrors(args.verbose as boolean, async () => {
28-
return (await import('./activate-key')).handleActivateKey(args);
33+
return (await import('./activate-powerpack')).handleActivatePowerpack(
34+
args
35+
);
2936
});
3037
process.exit(exitCode);
3138
},

packages/nx/src/command-line/nx-commands.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chalk from 'chalk';
22
import * as yargs from 'yargs';
33

4-
import { yargsActivateKeyCommand } from './activate-key/command-object';
4+
import { yargsActivatePowerpackCommand } from './activate-powerpack/command-object';
55
import {
66
yargsAffectedBuildCommand,
77
yargsAffectedCommand,
@@ -65,7 +65,7 @@ export const commandsObject = yargs
6565
.parserConfiguration(parserConfiguration)
6666
.usage(chalk.bold('Smart Monorepos · Fast CI'))
6767
.demandCommand(1, '')
68-
.command(yargsActivateKeyCommand)
68+
.command(yargsActivatePowerpackCommand)
6969
.command(yargsAddCommand)
7070
.command(yargsAffectedBuildCommand)
7171
.command(yargsAffectedCommand)
@@ -121,7 +121,7 @@ function createMissingConformanceCommand(
121121
output.error({
122122
title: `${command} is not available`,
123123
bodyLines: [
124-
`In order to use the \`nx ${command}\` command you must have an active Nx key and the \`@nx/conformance\` plugin installed.`,
124+
`In order to use the \`nx ${command}\` command you must have an active Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
125125
'',
126126
'To learn more, visit https://nx.dev/nx-enterprise/powerpack/conformance',
127127
],
@@ -133,13 +133,7 @@ function createMissingConformanceCommand(
133133

134134
function resolveConformanceCommandObject() {
135135
try {
136-
const { yargsConformanceCommand } = (() => {
137-
try {
138-
return require('@nx/powerpack-conformance');
139-
} catch {
140-
return require('@nx/conformance');
141-
}
142-
})();
136+
const { yargsConformanceCommand } = require('@nx/powerpack-conformance');
143137
return yargsConformanceCommand;
144138
} catch {
145139
return createMissingConformanceCommand('conformance');
@@ -148,13 +142,9 @@ function resolveConformanceCommandObject() {
148142

149143
function resolveConformanceCheckCommandObject() {
150144
try {
151-
const { yargsConformanceCheckCommand } = (() => {
152-
try {
153-
return require('@nx/powerpack-conformance');
154-
} catch {
155-
return require('@nx/conformance');
156-
}
157-
})();
145+
const {
146+
yargsConformanceCheckCommand,
147+
} = require('@nx/powerpack-conformance');
158148
return yargsConformanceCheckCommand;
159149
} catch {
160150
return createMissingConformanceCommand('conformance:check');

packages/nx/src/command-line/report/report.ts

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import { NxJsonConfiguration, readNxJson } from '../../config/nx-json';
2424
import { ProjectGraph } from '../../config/project-graph';
2525
import { ProjectGraphError } from '../../project-graph/error-types';
2626
import {
27-
getNxKeyInformation,
28-
NxKeyNotInstalledError,
29-
} from '../../utils/nx-key';
30-
import { type NxKey } from '@nx/key';
27+
getPowerpackLicenseInformation,
28+
NxPowerpackNotInstalledError,
29+
} from '../../utils/powerpack';
30+
import type { PowerpackLicense } from '@nx/powerpack-license';
3131

3232
const nxPackageJson = readJsonFile<typeof import('../../../package.json')>(
3333
join(__dirname, '../../../package.json')
@@ -64,8 +64,8 @@ export async function reportHandler() {
6464
const {
6565
pm,
6666
pmVersion,
67-
nxKey,
68-
nxKeyError,
67+
powerpackLicense,
68+
powerpackError,
6969
localPlugins,
7070
powerpackPlugins,
7171
communityPlugins,
@@ -97,51 +97,49 @@ export async function reportHandler() {
9797
);
9898
});
9999

100-
if (nxKey) {
100+
if (powerpackLicense) {
101101
bodyLines.push('');
102102
bodyLines.push(LINE_SEPARATOR);
103-
bodyLines.push(chalk.green('Nx key licensed packages'));
103+
bodyLines.push(chalk.green('Nx Powerpack'));
104+
105+
const licenseExpiryDate = new Date(
106+
(powerpackLicense.realExpiresAt ?? powerpackLicense.expiresAt) * 1000
107+
);
104108

105109
bodyLines.push(
106-
`Licensed to ${nxKey.organizationName} for ${nxKey.seatCount} user${
107-
nxKey.seatCount > 1 ? 's' : ''
108-
} in ${
109-
nxKey.workspaceCount === 9999
110+
`Licensed to ${powerpackLicense.organizationName} for ${
111+
powerpackLicense.seatCount
112+
} user${powerpackLicense.seatCount > 1 ? 's' : ''} in ${
113+
powerpackLicense.workspaceCount === 9999
110114
? 'an unlimited number of'
111-
: nxKey.workspaceCount
112-
} workspace${nxKey.workspaceCount > 1 ? 's' : ''}.`
115+
: powerpackLicense.workspaceCount
116+
} workspace${powerpackLicense.workspaceCount > 1 ? 's' : ''}.`
113117
);
114118

115-
if (nxKey.realExpiresAt || nxKey.expiresAt) {
116-
const licenseExpiryDate = new Date(
117-
(nxKey.realExpiresAt ?? nxKey.expiresAt) * 1000
118-
);
119-
120-
// license is not expired
121-
if (licenseExpiryDate.getTime() >= Date.now()) {
122-
if ('perpetualNxVersion' in nxKey) {
123-
bodyLines.push(
124-
`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${
125-
nxKey.perpetualNxVersion
126-
} and below.`
127-
);
128-
} else {
129-
bodyLines.push(
130-
`License expires on ${licenseExpiryDate.toLocaleDateString()}.`
131-
);
132-
}
119+
// license is not expired
120+
if (licenseExpiryDate.getTime() >= Date.now()) {
121+
if ('perpetualNxVersion' in powerpackLicense) {
122+
bodyLines.push(
123+
`License expires on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${
124+
powerpackLicense.perpetualNxVersion
125+
} and below.`
126+
);
133127
} else {
134-
if ('perpetualNxVersion' in nxKey) {
135-
bodyLines.push(
136-
`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${
137-
nxKey.perpetualNxVersion
138-
} and below.`
139-
);
140-
} else {
141-
bodyLines.push(
142-
`License expired on ${licenseExpiryDate.toLocaleDateString()}.`
143-
);
144-
}
128+
bodyLines.push(
129+
`License expires on ${licenseExpiryDate.toLocaleDateString()}.`
130+
);
131+
}
132+
} else {
133+
if ('perpetualNxVersion' in powerpackLicense) {
134+
bodyLines.push(
135+
`License expired on ${licenseExpiryDate.toLocaleDateString()}, but will continue to work with Nx ${
136+
powerpackLicense.perpetualNxVersion
137+
} and below.`
138+
);
139+
} else {
140+
bodyLines.push(
141+
`License expired on ${licenseExpiryDate.toLocaleDateString()}.`
142+
);
145143
}
146144
}
147145

@@ -161,11 +159,11 @@ export async function reportHandler() {
161159
);
162160
}
163161
bodyLines.push('');
164-
} else if (nxKeyError) {
162+
} else if (powerpackError) {
165163
bodyLines.push('');
166-
bodyLines.push(chalk.red('Nx key'));
164+
bodyLines.push(chalk.red('Nx Powerpack'));
167165
bodyLines.push(LINE_SEPARATOR);
168-
bodyLines.push(nxKeyError.message);
166+
bodyLines.push(powerpackError.message);
169167
bodyLines.push('');
170168
}
171169

@@ -228,8 +226,8 @@ export async function reportHandler() {
228226
export interface ReportData {
229227
pm: PackageManager;
230228
pmVersion: string;
231-
nxKey: NxKey | null;
232-
nxKeyError: Error | null;
229+
powerpackLicense: PowerpackLicense | null;
230+
powerpackError: Error | null;
233231
powerpackPlugins: PackageJson[];
234232
localPlugins: string[];
235233
communityPlugins: PackageJson[];
@@ -278,20 +276,20 @@ export async function getReportData(): Promise<ReportData> {
278276

279277
const native = isNativeAvailable();
280278

281-
let nxKey = null;
282-
let nxKeyError = null;
279+
let powerpackLicense = null;
280+
let powerpackError = null;
283281
try {
284-
nxKey = await getNxKeyInformation();
282+
powerpackLicense = await getPowerpackLicenseInformation();
285283
} catch (e) {
286-
if (!(e instanceof NxKeyNotInstalledError)) {
287-
nxKeyError = e;
284+
if (!(e instanceof NxPowerpackNotInstalledError)) {
285+
powerpackError = e;
288286
}
289287
}
290288

291289
return {
292290
pm,
293-
nxKey,
294-
nxKeyError,
291+
powerpackLicense,
292+
powerpackError,
295293
powerpackPlugins,
296294
pmVersion,
297295
localPlugins,
@@ -395,9 +393,7 @@ export function findMisalignedPackagesForPackage(
395393
export function findInstalledPowerpackPlugins(): PackageJson[] {
396394
const installedPlugins = findInstalledPlugins();
397395
return installedPlugins.filter((dep) =>
398-
new RegExp(
399-
'@nx/powerpack*|@nx/(.+)-cache|@nx/(conformance|owners|enterprise*)'
400-
).test(dep.name)
396+
new RegExp('@nx/powerpack*').test(dep.name)
401397
);
402398
}
403399

0 commit comments

Comments
 (0)