diff --git a/docs/generated/devkit/NxJsonConfiguration.md b/docs/generated/devkit/NxJsonConfiguration.md index d3eb55cdb5..e1752312e1 100644 --- a/docs/generated/devkit/NxJsonConfiguration.md +++ b/docs/generated/devkit/NxJsonConfiguration.md @@ -223,7 +223,7 @@ Available Task Runners #### Index signature -▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` } +▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` } --- diff --git a/docs/generated/devkit/Workspace.md b/docs/generated/devkit/Workspace.md index b06dd75003..989510615d 100644 --- a/docs/generated/devkit/Workspace.md +++ b/docs/generated/devkit/Workspace.md @@ -303,7 +303,7 @@ Available Task Runners #### Index signature -▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` } +▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` } #### Inherited from diff --git a/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts b/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts new file mode 100644 index 0000000000..ef1903eb5a --- /dev/null +++ b/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts @@ -0,0 +1,70 @@ +import { onlyDefaultRunnerIsUsed } from './connect-to-nx-cloud'; + +describe('connect-to-nx-cloud', () => { + describe('onlyDefaultRunnerIsUsed', () => { + it('should say no if tasks runner options is undefined and nxCloudAccessToken is set', () => { + expect( + onlyDefaultRunnerIsUsed({ + nxCloudAccessToken: 'xxx-xx-xxx', + }) + ).toBe(false); + }); + + it('should say yes if tasks runner options is undefined and nxCloudAccessToken is not set', () => { + expect(onlyDefaultRunnerIsUsed({})).toBe(true); + }); + + it('should say yes if tasks runner options is set to default runner', () => { + expect( + onlyDefaultRunnerIsUsed({ + tasksRunnerOptions: { + default: { + runner: 'nx/tasks-runners/default', + }, + }, + }) + ).toBeTruthy(); + }); + + it('should say no if tasks runner is set to a custom runner', () => { + expect( + onlyDefaultRunnerIsUsed({ + tasksRunnerOptions: { + default: { + runner: 'custom-runner', + }, + }, + }) + ).toBeFalsy(); + }); + + it('should say yes if tasks runner has options, but no runner and not using cloud', () => { + expect( + onlyDefaultRunnerIsUsed({ + tasksRunnerOptions: { + default: { + options: { + foo: 'bar', + }, + }, + }, + }) + ).toBeTruthy(); + }); + + it('should say no if tasks runner has options, but no runner and using cloud', () => { + expect( + onlyDefaultRunnerIsUsed({ + tasksRunnerOptions: { + default: { + options: { + foo: 'bar', + }, + }, + }, + nxCloudAccessToken: 'xxx-xx-xxx', + }) + ).toBeFalsy(); + }); + }); +}); 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 ba0c1c26ad..eacf10c5a2 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 @@ -10,20 +10,16 @@ import { NxJsonConfiguration } from '../../config/nx-json'; import { NxArgs } from '../../utils/command-line-utils'; export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) { - if (!nxJson.tasksRunnerOptions) { - // No tasks runner options: + const defaultRunner = nxJson.tasksRunnerOptions?.default?.runner; + + if (!defaultRunner) { + // No tasks runner options OR no default runner defined: // - If access token defined, uses cloud runner // - If no access token defined, uses default return !nxJson.nxCloudAccessToken; } - const defaultRunner = nxJson.tasksRunnerOptions?.default; - if ( - !defaultRunner.runner || - defaultRunner.runner === 'nx/tasks-runners/default' - ) { - return true; - } - return false; + + return defaultRunner === 'nx/tasks-runners/default'; } export async function connectToNxCloudIfExplicitlyAsked( diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 44035c755a..1acda2fd88 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -121,7 +121,7 @@ export interface NxJsonConfiguration { /** * Path to resolve the runner */ - runner: string; + runner?: string; /** * Default options for the runner */