diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 091b7d0169510e..4a7cb7e3383cd9 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -81,6 +81,22 @@ "defaultProject": { "type": "string", "description": "Default project. When project isn't provided, the default project will be used." + }, + "accessToken": { + "type": "string", + "description": "The access token to use for nx-cloud. If set, the default tasks runner will be nx-cloud." + }, + "parallel": { + "type": "number", + "description": "Specifies how many tasks are ran in parallel by Nx for the default tasks runner." + }, + "cacheDirectory": { + "type": "string", + "description": "Specifies the default location of the cache directory." + }, + "useDaemonProcess": { + "type": "boolean", + "description": "Specifies whether the daemon should be used for the default tasks runner." } }, "definitions": { diff --git a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts index 578dd5704ad344..afb0329cbea9fd 100644 --- a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts +++ b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts @@ -35,7 +35,7 @@ export async function connectToNxCloudIfExplicitlyAsked(opts: { export async function connectToNxCloudCommand( promptOverride?: string ): Promise { - if (isNxCloudUsed()) { + if (isNxCloudUsed(readNxJson())) { output.log({ title: '✅ This workspace is already connected to Nx Cloud.', bodyLines: [ diff --git a/packages/nx/src/command-line/connect/view-logs.ts b/packages/nx/src/command-line/connect/view-logs.ts index f4eda36ca691ca..3fc3df8d08da9d 100644 --- a/packages/nx/src/command-line/connect/view-logs.ts +++ b/packages/nx/src/command-line/connect/view-logs.ts @@ -3,9 +3,10 @@ import { execSync } from 'child_process'; import { isNxCloudUsed } from '../../utils/nx-cloud-utils'; import { output } from '../../utils/output'; import { runNxSync } from '../../utils/child-process'; +import { readNxJson } from '../../config/nx-json'; export async function viewLogs(): Promise { - const cloudUsed = isNxCloudUsed(); + const cloudUsed = isNxCloudUsed(readNxJson()); if (cloudUsed) { output.error({ title: 'Your workspace is already connected to Nx Cloud', diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index 57889a93ac56d1..7e94a001760aa4 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1203,16 +1203,17 @@ async function generateMigrationsJsonAndUpdatePackageJson( let originalPackageJson = existsSync(rootPkgJsonPath) ? readJsonFile(rootPkgJsonPath) : null; - const originalNxInstallation = readNxJson().installation; + const originalNxJson = readNxJson(); const from = - originalNxInstallation?.version ?? readNxVersion(originalPackageJson); + originalNxJson.installation?.version ?? + readNxVersion(originalPackageJson); try { if ( ['nx', '@nrwl/workspace'].includes(opts.targetPackage) && (await isMigratingToNewMajor(from, opts.targetVersion)) && !isCI() && - !isNxCloudUsed() + !isNxCloudUsed(originalNxJson) ) { const useCloud = await connectToNxCloudCommand( messages.getPromptMessage('nxCloudMigration') @@ -1237,7 +1238,7 @@ async function generateMigrationsJsonAndUpdatePackageJson( const migrator = new Migrator({ packageJson: originalPackageJson, - nxInstallation: originalNxInstallation, + nxInstallation: originalNxJson.installation, getInstalledPackageVersion: createInstalledPackageVersionsResolver(root), fetch: createFetcher(), from: opts.from, diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index 778df66051a13e..9c49fa724e8f79 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -64,6 +64,7 @@ export class DaemonClient { enabled() { if (this._enabled === undefined) { + // TODO: Add migration to move it out of existing configs and remove the ?? here. const useDaemonProcessOption = this.nxJson.useDaemonProcess ?? this.nxJson.tasksRunnerOptions?.['default']?.options?.useDaemonProcess; diff --git a/packages/nx/src/tasks-runner/life-cycles/view-logs-utils.ts b/packages/nx/src/tasks-runner/life-cycles/view-logs-utils.ts index 5c5ef847d8e6be..5ac0c5a0ef0ab8 100644 --- a/packages/nx/src/tasks-runner/life-cycles/view-logs-utils.ts +++ b/packages/nx/src/tasks-runner/life-cycles/view-logs-utils.ts @@ -1,10 +1,11 @@ +import { readNxJson } from '../../config/nx-json'; import { isNxCloudUsed } from '../../utils/nx-cloud-utils'; import { output } from '../../utils/output'; const VIEW_LOGS_MESSAGE = `Hint: Try "nx view-logs" to get structured, searchable errors logs in your browser.`; export function viewLogsFooterRows(failedTasks: number) { - if (failedTasks >= 2 && !isNxCloudUsed()) { + if (failedTasks >= 2 && !isNxCloudUsed(readNxJson())) { return [``, output.dim(`${output.X_PADDING} ${VIEW_LOGS_MESSAGE}`)]; } else { return []; diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index 1fbc629363bca7..5866e683725aa0 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -403,7 +403,7 @@ export function getRunner( let runner = nxArgs.runner; runner = runner || 'default'; - if (runner !== 'default' && !nxJson.tasksRunnerOptions[runner]) { + if (runner !== 'default' && !nxJson.tasksRunnerOptions?.[runner]) { throw new Error(`Could not find runner configuration for ${runner}`); } diff --git a/packages/nx/src/tasks-runner/utils.ts b/packages/nx/src/tasks-runner/utils.ts index 722d9f3c8f048f..0be79f270f7c8b 100644 --- a/packages/nx/src/tasks-runner/utils.ts +++ b/packages/nx/src/tasks-runner/utils.ts @@ -345,7 +345,8 @@ export function isCacheableTask( ): boolean { if ( task.cache !== undefined && - process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true' + process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true' && + !longRunningTask(task) ) { return task.cache; } diff --git a/packages/nx/src/utils/nx-cloud-utils.ts b/packages/nx/src/utils/nx-cloud-utils.ts index ded0d079992e50..175463e5212794 100644 --- a/packages/nx/src/utils/nx-cloud-utils.ts +++ b/packages/nx/src/utils/nx-cloud-utils.ts @@ -1,6 +1,6 @@ -import { readNxJson } from '../config/configuration'; +import { NxJsonConfiguration, readNxJson } from '../config/nx-json'; -export function isNxCloudUsed(nxJson = readNxJson()) { +export function isNxCloudUsed(nxJson: NxJsonConfiguration) { return ( !!nxJson.accessToken || Object.values(nxJson.tasksRunnerOptions ?? {}).find( @@ -10,7 +10,7 @@ export function isNxCloudUsed(nxJson = readNxJson()) { } export function getNxCloudUrl(): string { - const taskRunner = isNxCloudUsed(); + const taskRunner = isNxCloudUsed(readNxJson()); if (!taskRunner) throw new Error('nx-cloud runner not find in nx.json'); return ( (typeof taskRunner === 'object' ? taskRunner.options.url : null) ??