Skip to content

Commit e41ba65

Browse files
authored
fix(nx-cloud): download light client to tmp dir when outside nx workspace (#34805)
## Current Behavior When running nx commands outside of an Nx workspace (no nx.json), the light client is downloaded to .nx/cache/cloud relative to process.cwd(). This creates an unwanted .nx folder in whatever directory the user happens to be in. ## Expected Behavior When outside an Nx workspace, the light client is downloaded to a temp directory (os.tmpdir()/nx-cloud-client/hash) where hash is derived from the NX_CLOUD_API URL. This avoids polluting arbitrary directories with .nx folders while ensuring different cloud instances get separate directories. When inside an Nx workspace, behavior is unchanged.
1 parent 6b8d5c9 commit e41ba65

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/nx/src/nx-cloud/update-manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'fs';
1212
import { createGunzip } from 'zlib';
1313
import { join } from 'path';
14+
import { tmpdir } from 'os';
1415
import { createApiAxiosInstance } from './utilities/axios';
1516
import { debugLog } from './debug-logger';
1617
import type { CloudTaskRunnerOptions } from './nx-cloud-tasks-runner-shell';
@@ -156,6 +157,18 @@ export async function verifyOrUpdateNxCloudClient(options?: {
156157
}
157158

158159
export function getBundleInstallDefaultLocation() {
160+
// When not in an Nx workspace (no nx.json), avoid creating a .nx folder
161+
// in the current directory. Instead, use a temp directory unique to the
162+
// NX_CLOUD_API URL so different cloud instances don't conflict.
163+
if (!existsSync(join(workspaceRoot, 'nx.json'))) {
164+
const apiUrl = process.env.NX_CLOUD_API || 'https://cloud.nx.app';
165+
const apiHash = createHash('sha256')
166+
.update(apiUrl)
167+
.digest('hex')
168+
.slice(0, 16);
169+
return join(tmpdir(), 'nx-cloud-client', apiHash);
170+
}
171+
159172
const legacyPath = join(
160173
workspaceRoot,
161174
'node_modules',

0 commit comments

Comments
 (0)