-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nx-cloud): fallback to nx-cloud bin if enterprise is outdated and… (
- Loading branch information
1 parent
15b5cce
commit c2d63af
Showing
3 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,11 @@ async function invokeCommandWithNxCloudClient(options: CloudTaskRunnerOptions) { | |
const body = ['Cannot run commands from the `nx-cloud` CLI.']; | ||
|
||
if (e instanceof NxCloudEnterpriseOutdatedError) { | ||
try { | ||
// TODO: Remove this when all enterprise customers have updated. | ||
// Try requiring the bin from the `nx-cloud` package. | ||
return require('nx-cloud/bin/nx-cloud'); | ||
} catch {} | ||
body.push( | ||
'If you are an Nx Enterprise customer, please reach out to your assigned Developer Productivity Engineer.', | ||
'If you are NOT an Nx Enterprise customer but are seeing this message, please reach out to [email protected].' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,28 @@ import { Tree } from '../../generators/tree'; | |
import { NxJsonConfiguration } from '../../config/nx-json'; | ||
import { PackageJson } from '../../utils/package-json'; | ||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; | ||
import { readNxJson } from '../../generators/utils/nx-json'; | ||
import { | ||
NxCloudEnterpriseOutdatedError, | ||
verifyOrUpdateNxCloudClient, | ||
} from '../../nx-cloud/update-manager'; | ||
import { getRunnerOptions } from '../../tasks-runner/run-command'; | ||
import { output } from '../../utils/output'; | ||
|
||
export default async function migrate(tree: Tree) { | ||
if (!tree.exists('nx.json')) { | ||
return; | ||
} | ||
updateJson<NxJsonConfiguration>(tree, 'nx.json', (nxJson) => { | ||
// Already migrated | ||
if (!nxJson.tasksRunnerOptions?.default) { | ||
return nxJson; | ||
} | ||
|
||
const nxJson = readNxJson(tree); | ||
|
||
// Already migrated | ||
if (!nxJson.tasksRunnerOptions?.default) { | ||
return; | ||
} | ||
|
||
const nxCloudClientSupported = await isNxCloudClientSupported(nxJson); | ||
updateJson<NxJsonConfiguration>(tree, 'nx.json', (nxJson) => { | ||
const { runner, options } = nxJson.tasksRunnerOptions.default; | ||
|
||
// This property shouldn't ever be part of tasks runner options. | ||
|
@@ -35,19 +46,12 @@ export default async function migrate(tree: Tree) { | |
if (options.url) { | ||
nxJson.nxCloudUrl = options.url; | ||
delete options.url; | ||
} | ||
|
||
if ( | ||
[ | ||
'https://nx.app', | ||
'https://cloud.nx.app', | ||
'https://staging.nx.app', | ||
'https://snapshot.nx.app', | ||
].includes(nxJson.nxCloudUrl) | ||
) { | ||
removeNxCloudDependency(tree); | ||
} | ||
} else { | ||
if (nxCloudClientSupported) { | ||
removeNxCloudDependency(tree); | ||
} else { | ||
options.useLightClient = false; | ||
} | ||
if (options.encryptionKey) { | ||
nxJson.nxCloudEncryptionKey = options.encryptionKey; | ||
|
@@ -88,6 +92,46 @@ export default async function migrate(tree: Tree) { | |
await formatChangedFilesWithPrettierIfAvailable(tree); | ||
} | ||
|
||
async function isNxCloudClientSupported(nxJson: NxJsonConfiguration) { | ||
const nxCloudOptions = getRunnerOptions('default', nxJson, {}, true); | ||
|
||
// Non enterprise workspaces support the Nx Cloud Client | ||
if (!isNxCloudEnterpriseWorkspace(nxJson)) { | ||
return true; | ||
} | ||
|
||
// If we can get the nx cloud client, it's supported | ||
try { | ||
await verifyOrUpdateNxCloudClient(nxCloudOptions); | ||
return true; | ||
} catch (e) { | ||
if (e instanceof NxCloudEnterpriseOutdatedError) { | ||
output.warn({ | ||
title: 'Nx Cloud Instance is outdated.', | ||
bodyLines: [ | ||
'If you are an Nx Enterprise customer, please reach out to your assigned Developer Productivity Engineer.', | ||
'If you are NOT an Nx Enterprise customer but are seeing this message, please reach out to [email protected].', | ||
], | ||
}); | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
function isNxCloudEnterpriseWorkspace(nxJson: NxJsonConfiguration) { | ||
const { runner, options } = nxJson.tasksRunnerOptions.default; | ||
return ( | ||
(runner === 'nx-cloud' || runner === '@nrwl/nx-cloud') && | ||
options.url && | ||
![ | ||
'https://nx.app', | ||
'https://cloud.nx.app', | ||
'https://staging.nx.app', | ||
'https://snapshot.nx.app', | ||
].includes(options.url) | ||
); | ||
} | ||
|
||
function removeNxCloudDependency(tree: Tree) { | ||
if (tree.exists('package.json')) { | ||
updateJson<PackageJson>(tree, 'package.json', (packageJson) => { | ||
|
c2d63af
There was a problem hiding this comment.
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-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app