Skip to content

Commit 9838313

Browse files
authored
fix(core): allow nx-cloud commands to run without local Nx installation (#31974)
## Current Behavior When running nx-cloud commands like `nx start-ci-run` in environments without local Nx installation, users get this error: ``` NX Could not find Nx modules at "/path/to/workspace". Have you run npm/yarn install? ``` This prevents legitimate use of nx-cloud commands in CI environments that don't have local Nx modules installed. ## Expected Behavior nx-cloud commands should be able to run using the global Nx installation without requiring local Nx modules, since they're designed to work independently of the local workspace setup. ## Related Issue(s) This fixes scenarios where users run `nx start-ci-run` in CI environments without local Nx installation. ## Changes Made - Added `isNxCloudCommand()` function to identify nx-cloud commands: `start-ci-run`, `login`, `logout`, `connect`, `view-logs`, `fix-ci`, `record` - Modified the missing local installation check to exclude nx-cloud commands - Added execution path for nx-cloud commands when no local Nx is available - they now run via the global nx-commands module - Preserves the error check for regular Nx commands that require local installation ## Testing - Verified that nx-cloud commands are properly identified - Confirmed that regular Nx commands still show the error when local Nx is missing - Ensured nx-cloud commands can run without local Nx installation
1 parent 2f2764d commit 9838313

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/nx/bin/nx.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ async function main() {
8989
handleNoWorkspace(GLOBAL_NX_VERSION);
9090
}
9191

92-
if (!localNx) {
92+
if (!localNx && !isNxCloudCommand(process.argv[2])) {
9393
handleMissingLocalInstallation(workspace ? workspace.dir : null);
9494
}
9595

9696
// this file is already in the local workspace
9797
if (isLocalInstall) {
9898
await initLocal(workspace);
99-
} else {
99+
} else if (localNx) {
100100
// Nx is being run from globally installed CLI - hand off to the local
101101
warnIfUsingOutdatedGlobalInstall(GLOBAL_NX_VERSION, LOCAL_NX_VERSION);
102102
if (localNx.includes('.nx')) {
@@ -105,6 +105,10 @@ async function main() {
105105
} else {
106106
require(localNx);
107107
}
108+
} else if (isNxCloudCommand(process.argv[2])) {
109+
// nx-cloud commands can run without local Nx installation
110+
process.env.NX_DAEMON = 'false';
111+
require('nx/src/command-line/nx-commands').commandsObject.argv;
108112
}
109113
}
110114
}
@@ -173,6 +177,19 @@ function resolveNx(workspace: WorkspaceTypeAndRoot | null) {
173177
});
174178
}
175179

180+
function isNxCloudCommand(command: string): boolean {
181+
const nxCloudCommands = [
182+
'start-ci-run',
183+
'login',
184+
'logout',
185+
'connect',
186+
'view-logs',
187+
'fix-ci',
188+
'record',
189+
];
190+
return nxCloudCommands.includes(command);
191+
}
192+
176193
function handleMissingLocalInstallation(detectedWorkspaceRoot: string | null) {
177194
output.error({
178195
title: detectedWorkspaceRoot

0 commit comments

Comments
 (0)