fix(core): only show cloud messaging when migrating if not using cloud (#19709)

This commit is contained in:
Craigory Coppola 2023-10-18 19:20:47 -04:00 committed by GitHub
parent f98ab3f820
commit 024abd2cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 13 deletions

View File

@ -223,7 +223,7 @@ Available Task Runners
#### Index signature #### Index signature
▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` } ▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` }
--- ---

View File

@ -303,7 +303,7 @@ Available Task Runners
#### Index signature #### Index signature
▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` } ▪ [tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` }
#### Inherited from #### Inherited from

View File

@ -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();
});
});
});

View File

@ -10,20 +10,16 @@ import { NxJsonConfiguration } from '../../config/nx-json';
import { NxArgs } from '../../utils/command-line-utils'; import { NxArgs } from '../../utils/command-line-utils';
export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) { export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) {
if (!nxJson.tasksRunnerOptions) { const defaultRunner = nxJson.tasksRunnerOptions?.default?.runner;
// No tasks runner options:
if (!defaultRunner) {
// No tasks runner options OR no default runner defined:
// - If access token defined, uses cloud runner // - If access token defined, uses cloud runner
// - If no access token defined, uses default // - If no access token defined, uses default
return !nxJson.nxCloudAccessToken; return !nxJson.nxCloudAccessToken;
} }
const defaultRunner = nxJson.tasksRunnerOptions?.default;
if ( return defaultRunner === 'nx/tasks-runners/default';
!defaultRunner.runner ||
defaultRunner.runner === 'nx/tasks-runners/default'
) {
return true;
}
return false;
} }
export async function connectToNxCloudIfExplicitlyAsked( export async function connectToNxCloudIfExplicitlyAsked(

View File

@ -121,7 +121,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
/** /**
* Path to resolve the runner * Path to resolve the runner
*/ */
runner: string; runner?: string;
/** /**
* Default options for the runner * Default options for the runner
*/ */