Skip to content

Commit

Permalink
feat(core): support both @nrwl/nx-cloud and nx-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Apr 13, 2023
1 parent cfaf649 commit 1fb9edc
Show file tree
Hide file tree
Showing 34 changed files with 119 additions and 77 deletions.
2 changes: 1 addition & 1 deletion docs/nx-cloud/account/access-tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you open your `nx.json`, you will see something like this:
{
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"runner": "nx-cloud",
"options": {
"accessToken": "SOMETOKEN",
"cacheableOperations": ["build", "test", "lint", "e2e"]
Expand Down
2 changes: 1 addition & 1 deletion docs/nx-cloud/private/kubernetes-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ spec:

### Step 5: Connect Your Workspace

Run `NX_CLOUD_API=https://nx-cloud.myorg.com nx g @nrwl/nx-cloud:init`. Click on the link to connect the workspace
Run `NX_CLOUD_API=https://nx-cloud.myorg.com nx connect`. Click on the link to connect the workspace
to your admin account.

## Variations
Expand Down
2 changes: 1 addition & 1 deletion docs/nx-cloud/private/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ using `admin/ADMIN_PASSWORD`.

### Step 4: Connect Your Workspace

Run `NX_CLOUD_API=https://nxcloud.privateurl.com` nx g @nrwl/nx-cloud:init. Click on the link to connect the workspace
Run `NX_CLOUD_API=https://nxcloud.privateurl.com` nx connect. Click on the link to connect the workspace
to your admin account.

### Optional step 5: set up GitHub auth
Expand Down
4 changes: 2 additions & 2 deletions docs/nx-cloud/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Nx Cloud runner is configured in `nx.json`.
{
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"runner": "nx-cloud",
"options": {
"accessToken": "SOMETOKEN",
"cacheableOperations": ["build", "test", "lint", "e2e"]
Expand Down Expand Up @@ -52,7 +52,7 @@ In `nx.json`, locate the `taskRunnerOptions` property. It will look something li
{
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"runner": "nx-cloud",
"options": {
"accessToken": "SOMETOKEN",
"cacheableOperations": ["build", "test", "lint", "e2e"],
Expand Down
2 changes: 1 addition & 1 deletion docs/nx-cloud/reference/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ job where the `NX_CI_EXECUTION_ENV` is set to, say, `macos`, will connect to the

#### NX_RUN_GROUP

Older versions of `@nrwl/nx-cloud` used `NX_RUN_GROUP` instead of `NX_CI_EXECUTION_ID` and `NX_CI_EXECUTION_ENV`. It
Older versions of `nx-cloud` used `NX_RUN_GROUP` instead of `NX_CI_EXECUTION_ID` and `NX_CI_EXECUTION_ENV`. It
served the same purpose.

### NX_CLOUD_ACCESS_TOKEN
Expand Down
2 changes: 1 addition & 1 deletion docs/nx-cloud/reference/nx-cloud-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ run.
You can fix it by telling Nx Cloud that it can terminate agents after it sees a certain
target: `npx nx-cloud start-ci-run --stop-agents-after=e2e`.

> Earlier versions of `@nrwl/nx-cloud` required you to set the `NX_CLOUD_DISTRIBUTED_EXECUTION` env variable to `true`
> Earlier versions of `nx-cloud` required you to set the `NX_CLOUD_DISTRIBUTED_EXECUTION` env variable to `true`
> to
> enable DTE, but in the latest version `npx nx-cloud start-ci-run` does it automatically.
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/core-features/distribute-task-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ nx connect
```

{% callout type="note" title="Use the latest version of Nx Cloud" %}
This command installs the latest version of `@nrwl/nx-cloud`. The latest version works with any version of Nx >= 13.0.
This command installs the latest version of `nx-cloud`. The latest version works with any version of Nx >= 13.0.
{% /callout %}

If you have a new workspace, you can generate the CI configuration as follows:
Expand Down
4 changes: 0 additions & 4 deletions docs/shared/core-features/share-your-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ npx nx connect-to-nx-cloud
```{% command="npx nx connect-to-nx-cloud"%}
✔ Enable distributed caching to make your CI faster · Yes
> NX Generating @nrwl/nx-cloud:init
UPDATE nx.json
> NX Distributed caching via Nx Cloud has been enabled
In addition to the caching, Nx Cloud provides config-free distributed execution,
Expand Down
4 changes: 2 additions & 2 deletions docs/shared/mental-model/large-tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -22861,7 +22861,7 @@
{
"file": "packages/nx/src/command-line/run-many.spec.ts",
"hash": "84ef3acaa7671c0b3507df3d0ac82d252d59ed68",
"deps": ["npm:@nrwl/nx-cloud"]
"deps": ["npm:nx-cloud"]
},
{
"file": "packages/nx/src/command-line/run-many.ts",
Expand Down Expand Up @@ -27012,7 +27012,7 @@
"js",
"linter",
"next",
"npm:@nrwl/nx-cloud",
"npm:nx-cloud",
"react",
"storybook",
"web",
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/migration/migration-angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ When you click this button, we’ll run the `nx init` command to set up the Nx C
The script will make the following changes:

- Installs the `@nrwl/workspace` and `nx` packages.
- If you opted into Nx Cloud, `@nrwl/nx-cloud` will be installed as well.
- If you opted into Nx Cloud, `nx-cloud` will be installed as well.
- If your project's Angular version is greater than or equal to version 13, then the `@nrwl/angular` package will be installed as well.
- Creates an `nx.json` file in the root of your workspace.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"npm:@nrwl/js",
"npm:@nrwl/linter",
"npm:@nrwl/node",
"npm:@nrwl/nx-cloud",
"npm:nx-cloud",
"npm:@nrwl/workspace",
"npm:@types/express",
"npm:@types/jest",
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/node-server-tutorial/final-project-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"npm:@nrwl/jest",
"npm:@nrwl/linter",
"npm:@nrwl/node",
"npm:@nrwl/nx-cloud",
"npm:nx-cloud",
"npm:@nrwl/workspace",
"npm:@types/express",
"npm:@types/jest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"npm:@nrwl/jest",
"npm:@nrwl/linter",
"npm:@nrwl/node",
"npm:@nrwl/nx-cloud",
"npm:nx-cloud",
"npm:@nrwl/workspace",
"npm:@types/express",
"npm:@types/jest",
Expand Down
22 changes: 11 additions & 11 deletions docs/shared/reference/nx-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ Tasks runners are invoked when you run `nx test`, `nx build`, `nx run-many`, `nx
named "default" is used by default. Specify a different one like this `nx run-many -t build --all --runner=another`.

Tasks runners can accept different options. The following are the options supported
by `"nx/tasks-runners/default"` and `"@nrwl/nx-cloud"`.

| Property | Description |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cacheableOperations | defines the list of targets/operations that are cached by Nx |
| parallel | defines the max number of targets ran in parallel (in older versions of Nx you had to pass `--parallel --maxParallel=3` instead of `--parallel=3`) |
| captureStderr | defines whether the cache captures stderr or just stdout |
| skipNxCache | defines whether the Nx Cache should be skipped (defaults to `false`) |
| cacheDirectory | defines where the local cache is stored (defaults to `node_modules/.cache/nx`) |
| encryptionKey | (when using `"@nrwl/nx-cloud"` only) defines an encryption key to support end-to-end encryption of your cloud cache. You may also provide an environment variable with the key `NX_CLOUD_ENCRYPTION_KEY` that contains an encryption key as its value. The Nx Cloud task runner normalizes the key length, so any length of key is acceptable |
| selectivelyHashTsConfig | only hash the path mapping of the active project in the `tsconfig.base.json` (e.g., adding/removing projects doesn't affect the hash of existing projects) (defaults to `false`) |
by `"nx/tasks-runners/default"` and `"nx-cloud"`.

| Property | Description |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cacheableOperations | defines the list of targets/operations that are cached by Nx |
| parallel | defines the max number of targets ran in parallel (in older versions of Nx you had to pass `--parallel --maxParallel=3` instead of `--parallel=3`) |
| captureStderr | defines whether the cache captures stderr or just stdout |
| skipNxCache | defines whether the Nx Cache should be skipped (defaults to `false`) |
| cacheDirectory | defines where the local cache is stored (defaults to `node_modules/.cache/nx`) |
| encryptionKey | (when using `"nx-cloud"` only) defines an encryption key to support end-to-end encryption of your cloud cache. You may also provide an environment variable with the key `NX_CLOUD_ENCRYPTION_KEY` that contains an encryption key as its value. The Nx Cloud task runner normalizes the key length, so any length of key is acceptable |
| selectivelyHashTsConfig | only hash the path mapping of the active project in the `tsconfig.base.json` (e.g., adding/removing projects doesn't affect the hash of existing projects) (defaults to `false`) |

You can configure `parallel` in `nx.json`, but you can also pass them in the
terminal `nx run-many -t test --parallel=5`.
2 changes: 1 addition & 1 deletion nx-dev/nx-dev-e2e/src/e2e/nx-cloud-documentation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('nx-dev: Nx Cloud section', () => {
path: '/nx-cloud/reference/server-api',
},
{
title: '@nrwl/nx-cloud - Release notes',
title: 'nx-cloud - Release notes',
path: '/nx-cloud/reference/release-notes',
},
]).forEach((page) => assertTextOnPage(page.path, page.title));
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"runner": "nx-cloud",
"options": {
"accessToken": "NDg1NTA3MTAtOGFmZC00YmIwLTk2Y2MtOTkzNzc4ZTczYTlkfHJlYWQtb25seQ==",
"cacheableOperations": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@nrwl/js": "16.0.0-beta.0",
"@nrwl/linter": "16.0.0-beta.0",
"@nrwl/next": "16.0.0-beta.0",
"@nrwl/nx-cloud": "15.3.5",
"nx-cloud": "16.0.0-beta.8",
"@nrwl/react": "16.0.0-beta.0",
"@nrwl/storybook": "16.0.0-beta.0",
"@nrwl/web": "16.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-nx-workspace/src/utils/nx/nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function setupNxCloud(
try {
const pmc = getPackageManagerCommand(packageManager);
const res = await execAndWait(
`${pmc.exec} nx g @nrwl/nx-cloud:init --no-analytics --installationSource=create-nx-workspace`,
`${pmc.exec} nx g nx-cloud:init --no-analytics --installationSource=create-nx-workspace`,
join(process.cwd(), getFileName(name))
);
nxCloudSpinner.succeed('NxCloud has been set up successfully');
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"version": "16.0.0-beta.0",
"description": "Replace `dependsOn.projects` with {self} or {dependencies} tokens so that it matches the new expected formatting.",
"implementation": "./src/migrations/update-16-0-0/update-depends-on-to-tokens"
},
"16.0.0-update-nx-cloud-runner": {
"cli": "nx",
"version": "16.0.0-beta.0",
"description": "Replace @nrwl/nx-cloud with nx-cloud",
"implementation": "./src/migrations/update-16-0-0/update-nx-cloud-runner"
}
}
}
4 changes: 4 additions & 0 deletions packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
{
"package": "@nrwl/nx-cloud",
"version": "latest"
},
{
"package": "nx-cloud",
"version": "latest"
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/command-line/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ export async function connectToNxCloudCommand(
if (!res) return false;
const pmc = getPackageManagerCommand();
if (pmc) {
execSync(`${pmc.addDev} @nrwl/nx-cloud@latest`);
execSync(`${pmc.addDev} nx-cloud@latest`);
} else {
const nxJson = readNxJson();
if (nxJson.installation) {
nxJson.installation.plugins ??= {};
nxJson.installation.plugins['@nrwl/nx-cloud'] = execSync(
`npm view @nrwl/nx-cloud@latest version`
nxJson.installation.plugins['nx-cloud'] = execSync(
`npm view nx-cloud@latest version`
).toString();
}
}
runNxSync(`g @nrwl/nx-cloud:init`, {
runNxSync(`g nx-cloud:init`, {
stdio: [0, 1, 2],
});
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ const LEGACY_NRWL_PACKAGE_GROUP: ArrayPackageGroup = [
{ package: '@nrwl/storybook', version: '*' },
{ package: '@nrwl/web', version: '*' },
{ package: '@nrwl/js', version: '*' },
{ package: '@nrwl/nx-cloud', version: 'latest' },
{ package: 'nx-cloud', version: 'latest' },
{ package: '@nrwl/react-native', version: '*' },
{ package: '@nrwl/detox', version: '*' },
{ package: '@nrwl/expo', version: '*' },
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/command-line/run-many.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProjectGraph } from '@nrwl/nx-cloud/lib/core/models/run-context.model';
import { projectsToRun } from './run-many';
import { performance } from 'perf_hooks';
import { ProjectGraph } from '../config/project-graph';

describe('run-many', () => {
describe('projectsToRun', () => {
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('run-many', () => {
},
},
},
},
} as any,
dependencies: {},
};
});
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('run-many', () => {
targets: {
test: {},
},
},
} as any,
};
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/command-line/view-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export async function viewLogs(): Promise<number> {

try {
output.log({
title: 'Installing @nrwl/nx-cloud',
title: 'Installing nx-cloud',
});
execSync(`${pmc.addDev} @nrwl/nx-cloud@latest`, { stdio: 'ignore' });
execSync(`${pmc.addDev} nx-cloud@latest`, { stdio: 'ignore' });
} catch (e) {
output.log({
title: 'Installation failed',
Expand All @@ -49,7 +49,7 @@ export async function viewLogs(): Promise<number> {
output.log({
title: 'Connecting to Nx Cloud',
});
runNxSync(`g @nrwl/nx-cloud:init --installation-source=view-logs`, {
runNxSync(`g nx-cloud:init --installation-source=view-logs`, {
stdio: 'ignore',
});
} catch (e) {
Expand Down
31 changes: 31 additions & 0 deletions packages/nx/src/migrations/update-16-0-0/update-nx-cloud-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
readNxJson,
updateNxJson,
} from '../../generators/utils/project-configuration';
import { Tree } from '../../generators/tree';
import { updateJson } from '../../generators/utils/json';

export default async function (tree: Tree) {
updateJson(tree, 'package.json', (json) => {
if (json.dependencies && json.dependencies['@nrwl/nx-cloud']) {
json.dependencies['nx-cloud'] = json.dependencies['@nrwl/nx-cloud'];
delete json.dependencies['@nrwl/nx-cloud'];
}

if (json.devDependencies && json.devDependencies['@nrwl/nx-cloud']) {
json.devDependencies['nx-cloud'] = json.devDependencies['@nrwl/nx-cloud'];
delete json.devDependencies['@nrwl/nx-cloud'];
}

return json;
});

const nxJson = readNxJson(tree);
if (!nxJson) return;
for (let opts of Object.values(nxJson.tasksRunnerOptions)) {
if (opts.runner === '@nrwl/nx-cloud') {
opts.runner = 'nx-cloud';
}
}
updateNxJson(tree, nxJson);
}
6 changes: 3 additions & 3 deletions packages/nx/src/nx-init/angular/legacy-angular-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ async function installDependencies(
}

if (useNxCloud) {
// get the latest @nrwl/nx-cloud version compatible with the Nx major
// get the latest nx-cloud version compatible with the Nx major
// version being installed
json.devDependencies['@nrwl/nx-cloud'] = await resolvePackageVersion(
'@nrwl/nx-cloud',
json.devDependencies['nx-cloud'] = await resolvePackageVersion(
'nx-cloud',
`^${major(pkgVersion)}.0.0`
);
}
Expand Down
13 changes: 5 additions & 8 deletions packages/nx/src/nx-init/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function addDepsToPackageJson(repoRoot: string, useCloud: boolean) {
if (!json.devDependencies) json.devDependencies = {};
json.devDependencies['nx'] = require('../../package.json').version;
if (useCloud) {
json.devDependencies['@nrwl/nx-cloud'] = 'latest';
json.devDependencies['nx-cloud'] = 'latest';
}
writeJsonFile(path, json);
}
Expand All @@ -130,13 +130,10 @@ export function initCloud(
| 'nx-init-nest'
| 'nx-init-npm-repo'
) {
runNxSync(
`g @nrwl/nx-cloud:init --installationSource=${installationSource}`,
{
stdio: [0, 1, 2],
cwd: repoRoot,
}
);
runNxSync(`g nx-cloud:init --installationSource=${installationSource}`, {
stdio: [0, 1, 2],
cwd: repoRoot,
});
}

export function addVsCodeRecommendedExtensions(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/tasks-runner/tasks-runner-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const tasksRunnerV2 = (
): any => {
if (!options.lifeCycle.startCommand) {
throw new Error(
`If you are using Nx Cloud, update the version of @nrwl/nx-cloud to >=13.0.0`
`If you are using Nx Cloud, update the version of nx-cloud to >=13.0.0`
);
}

Expand Down
Loading

1 comment on commit 1fb9edc

@vercel
Copy link

@vercel vercel bot commented on 1fb9edc Apr 13, 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-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.