Skip to content

Commit a2e05c9

Browse files
committed
Reapply "feat(core): add nx register (#30321)"
This reverts commit 50e990c.
1 parent 50e990c commit a2e05c9

File tree

15 files changed

+461
-337
lines changed

15 files changed

+461
-337
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,20 @@
7171
"@nuxt/kit": "^3.10.0",
7272
"@nuxt/schema": "^3.10.0",
7373
"@nx/angular": "20.5.0-rc.4",
74+
"@nx/conformance": "1.3.0-beta.7",
7475
"@nx/cypress": "20.5.0-rc.4",
7576
"@nx/devkit": "20.5.0-rc.4",
7677
"@nx/esbuild": "20.5.0-rc.4",
7778
"@nx/eslint": "20.5.0-rc.4",
7879
"@nx/eslint-plugin": "20.5.0-rc.4",
7980
"@nx/jest": "20.5.0-rc.4",
8081
"@nx/js": "20.5.0-rc.4",
82+
"@nx/key": "1.3.0-beta.7",
8183
"@nx/next": "20.5.0-rc.4",
8284
"@nx/playwright": "20.5.0-rc.4",
83-
"@nx/powerpack-conformance": "1.2.5",
84-
"@nx/powerpack-enterprise-cloud": "1.2.5",
85-
"@nx/powerpack-license": "1.2.5",
85+
"@nx/powerpack-conformance": "1.3.0-beta.7",
86+
"@nx/powerpack-enterprise-cloud": "1.3.0-beta.7",
87+
"@nx/powerpack-license": "1.3.0-beta.7",
8688
"@nx/react": "20.5.0-rc.4",
8789
"@nx/rsbuild": "20.5.0-rc.4",
8890
"@nx/rspack": "20.5.0-rc.4",

packages/nx/.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@
131131
"@nx/nx-win32-arm64-msvc",
132132
"@nx/nx-freebsd-x64",
133133
"@nx/powerpack-license",
134+
"@nx/key",
134135
// Powerpack plugin conditionally available dynamically at runtime
135-
"@nx/powerpack-conformance"
136+
"@nx/powerpack-conformance",
137+
"@nx/conformance"
136138
]
137139
}
138140
]

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

Lines changed: 0 additions & 42 deletions
This file was deleted.

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

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

Lines changed: 17 additions & 7 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 { yargsActivatePowerpackCommand } from './activate-powerpack/command-object';
4+
import { yargsRegisterCommand } from './register/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(yargsActivatePowerpackCommand)
68+
.command(yargsRegisterCommand)
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 Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
124+
`In order to use the \`nx ${command}\` command you must have an active Nx key and the \`@nx/conformance\` plugin installed.`,
125125
'',
126126
'To learn more, visit https://nx.dev/nx-enterprise/powerpack/conformance',
127127
],
@@ -133,7 +133,13 @@ function createMissingConformanceCommand(
133133

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

143149
function resolveConformanceCheckCommandObject() {
144150
try {
145-
const {
146-
yargsConformanceCheckCommand,
147-
} = require('@nx/powerpack-conformance');
151+
const { yargsConformanceCheckCommand } = (() => {
152+
try {
153+
return require('@nx/powerpack-conformance');
154+
} catch {
155+
return require('@nx/conformance');
156+
}
157+
})();
148158
return yargsConformanceCheckCommand;
149159
} catch {
150160
return createMissingConformanceCommand('conformance:check');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { CommandModule } from 'yargs';
2+
import { withVerbose } from '../yargs-utils/shared-options';
3+
import { handleErrors } from '../../utils/handle-errors';
4+
5+
export interface RegisterOptions {
6+
key?: string;
7+
verbose?: boolean;
8+
}
9+
10+
export const yargsRegisterCommand: CommandModule<{}, RegisterOptions> = {
11+
command: 'register <key>',
12+
aliases: ['activate-powerpack'],
13+
describe: false,
14+
builder: (yargs) =>
15+
withVerbose(yargs)
16+
.parserConfiguration({
17+
'strip-dashed': true,
18+
'unknown-options-as-args': true,
19+
})
20+
.positional('key', {
21+
type: 'string',
22+
description: 'This is a key for Nx.',
23+
})
24+
.example('$0 register <key>', 'Register a Nx key'),
25+
handler: async (args) => {
26+
const exitCode = await handleErrors(args.verbose ?? false, async () => {
27+
return (await import('./register')).handleRegister(args);
28+
});
29+
process.exit(exitCode);
30+
},
31+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { workspaceRoot } from '../../utils/workspace-root';
2+
import { RegisterOptions } from './command-object';
3+
import { prompt } from 'enquirer';
4+
import { requireNxKey } from '../../utils/require-nx-key';
5+
6+
export async function handleRegister(options: RegisterOptions) {
7+
const nxKey = await requireNxKey();
8+
9+
// If a key was provided through options, activate it directly
10+
if (options.key) {
11+
return nxKey.activateNxKey(workspaceRoot, options.key);
12+
}
13+
14+
// Try to auto-register a key
15+
const generatedKey = await nxKey.autoRegisterNxKey(workspaceRoot);
16+
if (generatedKey) {
17+
return;
18+
}
19+
20+
// If auto-registration was skipped, prompt for a key
21+
const { key } = await prompt<{ key: string }>({
22+
type: 'input',
23+
name: 'key',
24+
message: 'Enter your key',
25+
});
26+
27+
return nxKey.activateNxKey(workspaceRoot, key);
28+
}

0 commit comments

Comments
 (0)