Skip to content

Commit

Permalink
fix(core): only show cloud messaging when migrating if not using cloud (
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Oct 18, 2023
1 parent f98ab3f commit 024abd2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Available Task Runners

#### Index signature

[tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` }
[tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` }

---

Expand Down
2 changes: 1 addition & 1 deletion docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Available Task Runners

#### Index signature

[tasksRunnerName: `string`]: { `options?`: `any` ; `runner`: `string` }
[tasksRunnerName: `string`]: { `options?`: `any` ; `runner?`: `string` }

#### Inherited from

Expand Down
70 changes: 70 additions & 0 deletions packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
16 changes: 6 additions & 10 deletions packages/nx/src/command-line/connect/connect-to-nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
/**
* Path to resolve the runner
*/
runner: string;
runner?: string;
/**
* Default options for the runner
*/
Expand Down

1 comment on commit 024abd2

@vercel
Copy link

@vercel vercel bot commented on 024abd2 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.