diff --git a/docs/generated/devkit/NxJsonConfiguration.md b/docs/generated/devkit/NxJsonConfiguration.md index 1eb7add2993ab..482fc35f64e90 100644 --- a/docs/generated/devkit/NxJsonConfiguration.md +++ b/docs/generated/devkit/NxJsonConfiguration.md @@ -29,6 +29,7 @@ Nx.json configuration - [namedInputs](../../devkit/documents/NxJsonConfiguration#namedinputs): Object - [npmScope](../../devkit/documents/NxJsonConfiguration#npmscope): string - [nxCloudAccessToken](../../devkit/documents/NxJsonConfiguration#nxcloudaccesstoken): string +- [nxCloudUrl](../../devkit/documents/NxJsonConfiguration#nxcloudurl): string - [parallel](../../devkit/documents/NxJsonConfiguration#parallel): number - [plugins](../../devkit/documents/NxJsonConfiguration#plugins): string[] - [pluginsConfig](../../devkit/documents/NxJsonConfiguration#pluginsconfig): Record<string, unknown> @@ -169,6 +170,15 @@ To use a different runner that accepts an access token, define it in [tasksRunne --- +### nxCloudUrl + +• `Optional` **nxCloudUrl**: `string` + +Specifies the url pointing to an instance of nx cloud. Used for remote +caching and displaying run links. + +--- + ### parallel • `Optional` **parallel**: `number` diff --git a/docs/generated/devkit/Workspace.md b/docs/generated/devkit/Workspace.md index 9e8d8639c28ce..e3002f3e6c72f 100644 --- a/docs/generated/devkit/Workspace.md +++ b/docs/generated/devkit/Workspace.md @@ -27,6 +27,7 @@ use ProjectsConfigurations or NxJsonConfiguration - [namedInputs](../../devkit/documents/Workspace#namedinputs): Object - [npmScope](../../devkit/documents/Workspace#npmscope): string - [nxCloudAccessToken](../../devkit/documents/Workspace#nxcloudaccesstoken): string +- [nxCloudUrl](../../devkit/documents/Workspace#nxcloudurl): string - [parallel](../../devkit/documents/Workspace#parallel): number - [plugins](../../devkit/documents/Workspace#plugins): string[] - [pluginsConfig](../../devkit/documents/Workspace#pluginsconfig): Record<string, unknown> @@ -213,6 +214,19 @@ To use a different runner that accepts an access token, define it in [tasksRunne --- +### nxCloudUrl + +• `Optional` **nxCloudUrl**: `string` + +Specifies the url pointing to an instance of nx cloud. Used for remote +caching and displaying run links. + +#### Inherited from + +[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[nxCloudUrl](../../devkit/documents/NxJsonConfiguration#nxcloudurl) + +--- + ### parallel • `Optional` **parallel**: `number` diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 4a7cb7e3383cd..ed186db20ab5c 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -82,10 +82,14 @@ "type": "string", "description": "Default project. When project isn't provided, the default project will be used." }, - "accessToken": { + "nxCloudAccessToken": { "type": "string", "description": "The access token to use for nx-cloud. If set, the default tasks runner will be nx-cloud." }, + "nxCloudUrl": { + "type": "string", + "description": "Specifies the url pointing to an instance of nx cloud. Used for remote caching and displaying run links." + }, "parallel": { "type": "number", "description": "Specifies how many tasks are ran in parallel by Nx for the default tasks runner." diff --git a/packages/nx/src/adapter/compat.ts b/packages/nx/src/adapter/compat.ts index 7853a9bd8f256..d07b48c10788c 100644 --- a/packages/nx/src/adapter/compat.ts +++ b/packages/nx/src/adapter/compat.ts @@ -2,7 +2,10 @@ import { createProjectGraphAsync, readProjectsConfigurationFromProjectGraph, } from '../project-graph/project-graph'; -import { ProjectsConfigurations } from '../config/workspace-json-project-json'; +import { + ProjectConfiguration, + ProjectsConfigurations, +} from '../config/workspace-json-project-json'; import { readNxJson } from '../config/configuration'; import { NxJsonConfiguration } from '../config/nx-json'; import { toOldFormat } from './angular-json'; @@ -13,7 +16,21 @@ const originalRequire: NodeRequire = Module.prototype.require; let patched = false; -const allowedProjectExtensions = [ +// Checks that a given const array has all keys in the union provided as T2, +// and marks it mutable. In this case, this is useful s.t. we can ensure the +// arrays we pass to angular for allowedProjectExtensions and allowedWorkspaceExtensions +// contain all of the keys which we may be passing through. +type CheckHasKeys = { + -readonly [P in keyof Arr]: Arr[P]; +}; + +// If we pass props on a project that angular doesn't know about, +// it throws a warning that users see. We want to pass them still, +// so older plugins writtin in Ng Devkit can update these. +// +// There are some props in here (root) that angular already knows about, +// but it doesn't hurt to have them in here as well to help static analysis. +export const allowedProjectExtensions = [ 'tags', 'implicitDependencies', 'configFilePath', @@ -22,9 +39,18 @@ const allowedProjectExtensions = [ 'namedInputs', 'name', 'files', -]; + 'root', + 'sourceRoot', + 'projectType', +] as const; -const allowedWorkspaceExtensions = [ +// If we pass props on the workspace that angular doesn't know about, +// it throws a warning that users see. We want to pass them still, +// so older plugins writtin in Ng Devkit can update these. +// +// There are some props in here (root) that angular already knows about, +// but it doesn't hurt to have them in here as well to help static analysis. +export const allowedWorkspaceExtensions = [ 'implicitDependencies', 'affected', 'npmScope', @@ -35,7 +61,18 @@ const allowedWorkspaceExtensions = [ 'files', 'generators', 'namedInputs', -]; + 'extends', + 'cli', + 'pluginsConfig', + 'defaultProject', + 'installation', + 'release', + 'nxCloudAccessToken', + 'nxCloudUrl', + 'parallel', + 'cacheDirectory', + 'useDaemonProcess', +] as const; if (!patched) { Module.prototype.require = function () { @@ -93,8 +130,14 @@ function mockReadJsonWorkspace( (originalReadJsonWorkspace) => async (path, host, options) => { const modifiedOptions = { ...options, - allowedProjectExtensions, - allowedWorkspaceExtensions, + allowedProjectExtensions: allowedProjectExtensions as CheckHasKeys< + typeof allowedProjectExtensions, + keyof Omit + >, + allowedWorkspaceExtensions: allowedWorkspaceExtensions as CheckHasKeys< + typeof allowedWorkspaceExtensions, + keyof NxJsonConfiguration + >, }; try { // Attempt angular CLI default behaviour diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 8df96cad87a17..0a1800e203580 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -207,6 +207,12 @@ export interface NxJsonConfiguration { */ nxCloudAccessToken?: string; + /** + * Specifies the url pointing to an instance of nx cloud. Used for remote + * caching and displaying run links. + */ + nxCloudUrl?: string; + /** * Specifies how many tasks can be run in parallel. */ diff --git a/packages/nx/src/generators/utils/deprecated.ts b/packages/nx/src/generators/utils/deprecated.ts index 0f57cbc5d1ca2..0a3e782fabbdd 100644 --- a/packages/nx/src/generators/utils/deprecated.ts +++ b/packages/nx/src/generators/utils/deprecated.ts @@ -44,6 +44,7 @@ export function updateWorkspaceConfiguration( cacheDirectory, parallel, useDaemonProcess, + nxCloudUrl, } = workspaceConfig; const nxJson: Required = { @@ -66,6 +67,7 @@ export function updateWorkspaceConfiguration( cacheDirectory, parallel, useDaemonProcess, + nxCloudUrl, }; updateNxJson(tree, nxJson); diff --git a/packages/nx/src/tasks-runner/run-command.spec.ts b/packages/nx/src/tasks-runner/run-command.spec.ts index 4ad8f025029b8..2357806099c9c 100644 --- a/packages/nx/src/tasks-runner/run-command.spec.ts +++ b/packages/nx/src/tasks-runner/run-command.spec.ts @@ -86,14 +86,21 @@ describe('getRunner', () => { it('uses nx-cloud when no tasksRunnerOptions are present and accessToken is specified', () => { jest.mock('nx-cloud', () => mockRunner); - const { tasksRunner } = getRunner( + const { tasksRunner, runnerOptions } = getRunner( {}, { nxCloudAccessToken: 'XXXX-XXX-XXXX', + nxCloudUrl: 'https://my-nx-cloud.app', } ); expect(tasksRunner).toEqual(mockRunner); + expect(runnerOptions).toMatchInlineSnapshot(` + { + "accessToken": "XXXX-XXX-XXXX", + "url": "https://my-nx-cloud.app", + } + `); }); it('reads options from base properties if no runner options provided', () => { diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index c68467fae9058..4b8b3c07371d8 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -470,6 +470,10 @@ function getRunnerOptions( result.accessToken ??= nxJson.nxCloudAccessToken; } + if (nxJson.nxCloudUrl && isCloudDefault) { + result.url ??= nxJson.nxCloudUrl; + } + if (nxJson.parallel) { result.parallel ??= nxJson.parallel; }